blob: a3c9ee42e05241c159fe17efc0c5b6a151c41378 [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"
Dan Sinclair3b71d262017-04-19 08:58:54 -040016#include "core/fxcrt/fx_codepage.h"
Dan Sinclaircfb19442017-04-20 13:13:04 -040017#include "core/fxcrt/fx_extension.h"
Dan Sinclair0d86ecb2017-04-19 09:19:57 -040018#include "core/fxcrt/xml/cfx_xmlelement.h"
19#include "core/fxcrt/xml/cfx_xmlnode.h"
20#include "core/fxcrt/xml/cfx_xmltext.h"
dsinclair43554682016-09-29 17:29:48 -070021#include "fxjs/cfxjse_value.h"
tsepeza9caab92016-12-14 05:57:10 -080022#include "third_party/base/ptr_util.h"
tsepezaadedf92016-05-12 10:08:06 -070023#include "third_party/base/stl_util.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 Sinclair0d86ecb2017-04-19 09:19:57 -0400520 std::unique_ptr<CFX_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 Sinclair0d86ecb2017-04-19 09:19:57 -0400524 auto pCloneXMLElement = pdfium::MakeUnique<CFX_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 Sinclair0d86ecb2017-04-19 09:19:57 -04001287 CFX_XMLNode* pXMLNode = pParser->ParseXMLData(wsExpression, nullptr);
Dan Sinclairfdf7d402017-04-18 15:25:58 -04001288 if (!pXMLNode)
weili44f8faf2016-06-01 14:03:56 -07001289 return;
dsinclairae95f762016-03-29 16:58:29 -07001290 if (bIgnoreRoot &&
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04001291 (pXMLNode->GetType() != FX_XMLNODE_Element ||
1292 XFA_RecognizeRichText(static_cast<CFX_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
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04001302 std::unique_ptr<CFX_XMLNode> pFakeXMLRoot(pFakeRoot->GetXMLMappingNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001303 if (!pFakeXMLRoot) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04001304 CFX_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 =
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04001309 pdfium::MakeUnique<CFX_XMLElement>(CFX_WideString(GetClassName()));
Dan Sinclair93bfc262017-04-04 15:10:00 -04001310 }
dsinclair017052a2016-06-28 07:43:51 -07001311
Dan Sinclair1770c022016-03-14 14:14:16 -04001312 if (bIgnoreRoot) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04001313 CFX_XMLNode* pXMLChild = pXMLNode->GetNodeItem(CFX_XMLNode::FirstChild);
Dan Sinclair1770c022016-03-14 14:14:16 -04001314 while (pXMLChild) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04001315 CFX_XMLNode* pXMLSibling =
1316 pXMLChild->GetNodeItem(CFX_XMLNode::NextSibling);
Dan Sinclair1770c022016-03-14 14:14:16 -04001317 pXMLNode->RemoveChildNode(pXMLChild);
1318 pFakeXMLRoot->InsertChildNode(pXMLChild);
1319 pXMLChild = pXMLSibling;
1320 }
1321 } else {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04001322 CFX_XMLNode* pXMLParent = pXMLNode->GetNodeItem(CFX_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) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04001352 CFX_XMLNode* pTempXMLNode = GetXMLMappingNode();
Dan Sinclair93bfc262017-04-04 15:10:00 -04001353 SetXMLMappingNode(pFakeXMLRoot.release());
1354 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04001355 if (pTempXMLNode && !pTempXMLNode->GetNodeItem(CFX_XMLNode::Parent))
Dan Sinclair93bfc262017-04-04 15:10:00 -04001356 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) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04001399 CFX_XMLNode* pElement = nullptr;
weili65be4b12016-05-25 15:47:43 -07001400 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
1401 pElement = GetXMLMappingNode();
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04001402 if (!pElement || pElement->GetType() != FX_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 Sinclair3b71d262017-04-19 08:58:54 -04001411 auto pStream =
1412 pdfium::MakeRetain<CFX_SeekableStreamProxy>(pMemoryStream, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001413 pStream->SetCodePage(FX_CODEPAGE_UTF8);
Dan Sinclair5ae87922017-04-18 11:54:04 -04001414 pStream->WriteString(bsXMLHeader.AsStringC());
1415
weili65be4b12016-05-25 15:47:43 -07001416 if (GetPacketID() == XFA_XDPPACKET_Form)
tsepez7cda31a2016-12-07 12:10:20 -08001417 XFA_DataExporter_RegenerateFormFile(this, pStream, nullptr, true);
weili65be4b12016-05-25 15:47:43 -07001418 else
tsepez7cda31a2016-12-07 12:10:20 -08001419 pElement->SaveXMLNode(pStream);
weili65be4b12016-05-25 15:47:43 -07001420 // TODO(weili): Check whether we need to save pretty print XML, pdfium:501.
1421 // For now, just put it here to avoid unused variable warning.
1422 (void)bPrettyMode;
dsinclairf27aeec2016-06-07 19:36:18 -07001423 pArguments->GetReturnValue()->SetString(
Dan Sinclair1770c022016-03-14 14:14:16 -04001424 CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001425 return;
1426 }
dsinclairf27aeec2016-06-07 19:36:18 -07001427 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04001428}
1429
1430void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) {
1431 int32_t iLength = pArguments->GetLength();
1432 if (iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001433 ThrowParamCountMismatchException(L"setAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001434 return;
1435 }
tsepez6fe7d212016-04-06 10:51:14 -07001436 CFX_WideString wsAttributeValue =
tsepez4c3debb2016-04-08 12:20:38 -07001437 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
tsepez6fe7d212016-04-06 10:51:14 -07001438 CFX_WideString wsAttribute =
tsepez4c3debb2016-04-08 12:20:38 -07001439 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili44f8faf2016-06-01 14:03:56 -07001440 SetAttribute(wsAttribute.AsStringC(), wsAttributeValue.AsStringC(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001441}
weili60607c32016-05-26 11:53:12 -07001442
Dan Sinclair1770c022016-03-14 14:14:16 -04001443void CXFA_Node::Script_NodeClass_SetElement(CFXJSE_Arguments* pArguments) {
1444 int32_t iLength = pArguments->GetLength();
1445 if (iLength != 1 && iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001446 ThrowParamCountMismatchException(L"setElement");
Dan Sinclair1770c022016-03-14 14:14:16 -04001447 return;
1448 }
weili60607c32016-05-26 11:53:12 -07001449 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001450 CFX_WideString wsName;
weili44f8faf2016-06-01 14:03:56 -07001451 pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
1452 if (iLength == 2)
weili60607c32016-05-26 11:53:12 -07001453 wsName = CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili60607c32016-05-26 11:53:12 -07001454 // TODO(weili): check whether we need to implement this, pdfium:501.
1455 // For now, just put the variables here to avoid unused variable warning.
1456 (void)pNode;
1457 (void)wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04001458}
weili60607c32016-05-26 11:53:12 -07001459
dsinclair12a6b0c2016-05-26 11:14:08 -07001460void CXFA_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001461 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001462 XFA_ATTRIBUTE eAttribute) {
1463 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001464 ThrowInvalidPropertyException();
1465 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001466 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001467
1468 CFX_WideString wsNameSpace;
1469 TryNamespace(wsNameSpace);
Tom Sepezf0b65542017-02-13 10:26:01 -08001470 pValue->SetString(wsNameSpace.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001471}
weili44f8faf2016-06-01 14:03:56 -07001472
dsinclair12a6b0c2016-05-26 11:14:08 -07001473void CXFA_Node::Script_NodeClass_Model(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001474 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001475 XFA_ATTRIBUTE eAttribute) {
1476 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001477 ThrowInvalidPropertyException();
1478 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001479 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001480 pValue->Assign(
1481 m_pDocument->GetScriptContext()->GetJSValueFromMap(GetModelNode()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001482}
weili44f8faf2016-06-01 14:03:56 -07001483
dsinclair12a6b0c2016-05-26 11:14:08 -07001484void CXFA_Node::Script_NodeClass_IsContainer(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001485 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001486 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001487 if (bSetting) {
1488 ThrowInvalidPropertyException();
1489 return;
1490 }
1491 pValue->SetBoolean(IsContainerNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001492}
weili44f8faf2016-06-01 14:03:56 -07001493
dsinclair12a6b0c2016-05-26 11:14:08 -07001494void CXFA_Node::Script_NodeClass_IsNull(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001495 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001496 XFA_ATTRIBUTE eAttribute) {
1497 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001498 ThrowInvalidPropertyException();
1499 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001500 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001501 if (GetElementType() == XFA_Element::Subform) {
1502 pValue->SetBoolean(false);
1503 return;
1504 }
1505 CFX_WideString strValue;
1506 pValue->SetBoolean(!TryContent(strValue) || strValue.IsEmpty());
Dan Sinclair1770c022016-03-14 14:14:16 -04001507}
weili44f8faf2016-06-01 14:03:56 -07001508
dsinclair12a6b0c2016-05-26 11:14:08 -07001509void CXFA_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001510 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001511 XFA_ATTRIBUTE eAttribute) {
1512 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001513 ThrowInvalidPropertyException();
1514 return;
1515 }
Tom Sepezf8a94392017-03-14 12:13:22 -07001516 std::vector<CXFA_Node*> properties =
1517 GetNodeList(XFA_NODEFILTER_OneOfProperty);
1518 if (!properties.empty()) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001519 pValue->Assign(
Tom Sepezf8a94392017-03-14 12:13:22 -07001520 m_pDocument->GetScriptContext()->GetJSValueFromMap(properties.front()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001521 }
1522}
weili44f8faf2016-06-01 14:03:56 -07001523
Dan Sinclair1770c022016-03-14 14:14:16 -04001524void CXFA_Node::Script_ContainerClass_GetDelta(CFXJSE_Arguments* pArguments) {}
dsinclairf27aeec2016-06-07 19:36:18 -07001525
Dan Sinclair1770c022016-03-14 14:14:16 -04001526void CXFA_Node::Script_ContainerClass_GetDeltas(CFXJSE_Arguments* pArguments) {
1527 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
dsinclairf27aeec2016-06-07 19:36:18 -07001528 pArguments->GetReturnValue()->SetObject(
1529 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001530}
1531void CXFA_Node::Script_ModelClass_ClearErrorList(CFXJSE_Arguments* pArguments) {
1532}
dsinclair5b36f0a2016-07-19 10:56:23 -07001533
Dan Sinclair1770c022016-03-14 14:14:16 -04001534void CXFA_Node::Script_ModelClass_CreateNode(CFXJSE_Arguments* pArguments) {
1535 Script_Template_CreateNode(pArguments);
1536}
dsinclair5b36f0a2016-07-19 10:56:23 -07001537
Dan Sinclair1770c022016-03-14 14:14:16 -04001538void CXFA_Node::Script_ModelClass_IsCompatibleNS(CFXJSE_Arguments* pArguments) {
1539 int32_t iLength = pArguments->GetLength();
1540 if (iLength < 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001541 ThrowParamCountMismatchException(L"isCompatibleNS");
Dan Sinclair1770c022016-03-14 14:14:16 -04001542 return;
1543 }
1544 CFX_WideString wsNameSpace;
1545 if (iLength >= 1) {
1546 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07001547 wsNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001548 }
1549 CFX_WideString wsNodeNameSpace;
1550 TryNamespace(wsNodeNameSpace);
dsinclair12a6b0c2016-05-26 11:14:08 -07001551 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07001552 if (pValue)
1553 pValue->SetBoolean(wsNodeNameSpace == wsNameSpace);
Dan Sinclair1770c022016-03-14 14:14:16 -04001554}
dsinclair5b36f0a2016-07-19 10:56:23 -07001555
dsinclair12a6b0c2016-05-26 11:14:08 -07001556void CXFA_Node::Script_ModelClass_Context(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001557 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001558 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001559
dsinclair12a6b0c2016-05-26 11:14:08 -07001560void CXFA_Node::Script_ModelClass_AliasNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001561 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001562 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001563
dsinclair12a6b0c2016-05-26 11:14:08 -07001564void CXFA_Node::Script_Attribute_Integer(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001565 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001566 XFA_ATTRIBUTE eAttribute) {
1567 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001568 SetInteger(eAttribute, pValue->ToInteger(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001569 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001570 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001571 }
1572}
dsinclair5b36f0a2016-07-19 10:56:23 -07001573
dsinclair12a6b0c2016-05-26 11:14:08 -07001574void CXFA_Node::Script_Attribute_IntegerRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001575 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001576 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001577 if (bSetting) {
1578 ThrowInvalidPropertyException();
1579 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001580 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001581 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001582}
dsinclair5b36f0a2016-07-19 10:56:23 -07001583
dsinclair12a6b0c2016-05-26 11:14:08 -07001584void CXFA_Node::Script_Attribute_BOOL(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001585 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001586 XFA_ATTRIBUTE eAttribute) {
1587 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001588 SetBoolean(eAttribute, pValue->ToBoolean(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001589 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001590 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001591 }
1592}
dsinclair5b36f0a2016-07-19 10:56:23 -07001593
dsinclair12a6b0c2016-05-26 11:14:08 -07001594void CXFA_Node::Script_Attribute_BOOLRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001595 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001596 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001597 if (bSetting) {
1598 ThrowInvalidPropertyException();
1599 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001600 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001601 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001602}
thestigb1a59592016-04-14 18:29:56 -07001603
Dan Sinclair1770c022016-03-14 14:14:16 -04001604void CXFA_Node::Script_Attribute_SendAttributeChangeMessage(
thestigb1a59592016-04-14 18:29:56 -07001605 XFA_ATTRIBUTE eAttribute,
tsepezd19e9122016-11-02 15:43:18 -07001606 bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001607 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
thestigb1a59592016-04-14 18:29:56 -07001608 if (!pLayoutPro)
Dan Sinclair1770c022016-03-14 14:14:16 -04001609 return;
thestigb1a59592016-04-14 18:29:56 -07001610
dsinclaira1b07722016-07-11 08:20:58 -07001611 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07001612 if (!pNotify)
1613 return;
1614
1615 uint32_t dwPacket = GetPacketID();
1616 if (!(dwPacket & XFA_XDPPACKET_Form)) {
1617 pNotify->OnValueChanged(this, eAttribute, this, this);
Dan Sinclair1770c022016-03-14 14:14:16 -04001618 return;
1619 }
thestigb1a59592016-04-14 18:29:56 -07001620
1621 bool bNeedFindContainer = false;
dsinclair41cb62e2016-06-23 09:20:32 -07001622 switch (GetElementType()) {
dsinclair56a8b192016-06-21 14:15:25 -07001623 case XFA_Element::Caption:
thestigb1a59592016-04-14 18:29:56 -07001624 bNeedFindContainer = true;
1625 pNotify->OnValueChanged(this, eAttribute, this,
1626 GetNodeItem(XFA_NODEITEM_Parent));
1627 break;
dsinclair56a8b192016-06-21 14:15:25 -07001628 case XFA_Element::Font:
1629 case XFA_Element::Para: {
thestigb1a59592016-04-14 18:29:56 -07001630 bNeedFindContainer = true;
1631 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001632 if (pParentNode->GetElementType() == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001633 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1634 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1635 } else {
1636 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
1637 }
1638 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001639 case XFA_Element::Margin: {
thestigb1a59592016-04-14 18:29:56 -07001640 bNeedFindContainer = true;
1641 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001642 XFA_Element eParentType = pParentNode->GetElementType();
thestigb1a59592016-04-14 18:29:56 -07001643 if (pParentNode->IsContainerNode()) {
1644 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
dsinclair56a8b192016-06-21 14:15:25 -07001645 } else if (eParentType == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001646 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1647 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1648 } else {
1649 CXFA_Node* pNode = pParentNode->GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001650 if (pNode && pNode->GetElementType() == XFA_Element::Ui) {
thestigb1a59592016-04-14 18:29:56 -07001651 pNotify->OnValueChanged(this, eAttribute, pNode,
1652 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001653 }
thestigb1a59592016-04-14 18:29:56 -07001654 }
1655 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001656 case XFA_Element::Comb: {
thestigb1a59592016-04-14 18:29:56 -07001657 CXFA_Node* pEditNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001658 XFA_Element eUIType = pEditNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07001659 if (pEditNode && (eUIType == XFA_Element::DateTimeEdit ||
1660 eUIType == XFA_Element::NumericEdit ||
1661 eUIType == XFA_Element::TextEdit)) {
thestigb1a59592016-04-14 18:29:56 -07001662 CXFA_Node* pUINode = pEditNode->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001663 if (pUINode) {
thestigb1a59592016-04-14 18:29:56 -07001664 pNotify->OnValueChanged(this, eAttribute, pUINode,
1665 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001666 }
thestigb1a59592016-04-14 18:29:56 -07001667 }
1668 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001669 case XFA_Element::Button:
1670 case XFA_Element::Barcode:
1671 case XFA_Element::ChoiceList:
1672 case XFA_Element::DateTimeEdit:
1673 case XFA_Element::NumericEdit:
1674 case XFA_Element::PasswordEdit:
1675 case XFA_Element::TextEdit: {
thestigb1a59592016-04-14 18:29:56 -07001676 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1677 if (pUINode) {
1678 pNotify->OnValueChanged(this, eAttribute, pUINode,
1679 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1680 }
1681 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001682 case XFA_Element::CheckButton: {
thestigb1a59592016-04-14 18:29:56 -07001683 bNeedFindContainer = true;
1684 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1685 if (pUINode) {
1686 pNotify->OnValueChanged(this, eAttribute, pUINode,
1687 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1688 }
1689 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001690 case XFA_Element::Keep:
1691 case XFA_Element::Bookend:
1692 case XFA_Element::Break:
1693 case XFA_Element::BreakAfter:
1694 case XFA_Element::BreakBefore:
1695 case XFA_Element::Overflow:
thestigb1a59592016-04-14 18:29:56 -07001696 bNeedFindContainer = true;
1697 break;
dsinclair56a8b192016-06-21 14:15:25 -07001698 case XFA_Element::Area:
1699 case XFA_Element::Draw:
1700 case XFA_Element::ExclGroup:
1701 case XFA_Element::Field:
1702 case XFA_Element::Subform:
1703 case XFA_Element::SubformSet:
thestigb1a59592016-04-14 18:29:56 -07001704 pLayoutPro->AddChangedContainer(this);
1705 pNotify->OnValueChanged(this, eAttribute, this, this);
1706 break;
dsinclair56a8b192016-06-21 14:15:25 -07001707 case XFA_Element::Sharptext:
1708 case XFA_Element::Sharpxml:
1709 case XFA_Element::SharpxHTML: {
thestigb1a59592016-04-14 18:29:56 -07001710 CXFA_Node* pTextNode = GetNodeItem(XFA_NODEITEM_Parent);
1711 if (!pTextNode) {
1712 return;
1713 }
1714 CXFA_Node* pValueNode = pTextNode->GetNodeItem(XFA_NODEITEM_Parent);
1715 if (!pValueNode) {
1716 return;
1717 }
dsinclair41cb62e2016-06-23 09:20:32 -07001718 XFA_Element eType = pValueNode->GetElementType();
1719 if (eType == XFA_Element::Value) {
thestigb1a59592016-04-14 18:29:56 -07001720 bNeedFindContainer = true;
1721 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1722 if (pNode && pNode->IsContainerNode()) {
1723 if (bScriptModify) {
1724 pValueNode = pNode;
1725 }
1726 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
1727 } else {
1728 pNotify->OnValueChanged(this, eAttribute, pNode,
1729 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001730 }
thestigb1a59592016-04-14 18:29:56 -07001731 } else {
dsinclair41cb62e2016-06-23 09:20:32 -07001732 if (eType == XFA_Element::Items) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001733 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1734 if (pNode && pNode->IsContainerNode()) {
thestigb1a59592016-04-14 18:29:56 -07001735 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04001736 }
1737 }
thestigb1a59592016-04-14 18:29:56 -07001738 }
1739 } break;
1740 default:
1741 break;
1742 }
1743 if (bNeedFindContainer) {
1744 CXFA_Node* pParent = this;
1745 while (pParent) {
1746 if (pParent->IsContainerNode())
Dan Sinclair1770c022016-03-14 14:14:16 -04001747 break;
thestigb1a59592016-04-14 18:29:56 -07001748
1749 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001750 }
thestigb1a59592016-04-14 18:29:56 -07001751 if (pParent) {
1752 pLayoutPro->AddChangedContainer(pParent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001753 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001754 }
1755}
thestigb1a59592016-04-14 18:29:56 -07001756
dsinclair12a6b0c2016-05-26 11:14:08 -07001757void CXFA_Node::Script_Attribute_String(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001758 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001759 XFA_ATTRIBUTE eAttribute) {
1760 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001761 CFX_WideString wsValue = pValue->ToWideString();
thestigb1a59592016-04-14 18:29:56 -07001762 SetAttribute(eAttribute, wsValue.AsStringC(), true);
dsinclair070fcdf2016-06-22 22:04:54 -07001763 if (eAttribute == XFA_ATTRIBUTE_Use &&
1764 GetElementType() == XFA_Element::Desc) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001765 CXFA_Node* pTemplateNode =
1766 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
1767 CXFA_Node* pProtoRoot =
dsinclair56a8b192016-06-21 14:15:25 -07001768 pTemplateNode->GetFirstChildByClass(XFA_Element::Subform)
1769 ->GetFirstChildByClass(XFA_Element::Proto);
dsinclair2f5582f2016-06-09 11:48:23 -07001770
1771 CFX_WideString wsID;
1772 CFX_WideString wsSOM;
1773 if (!wsValue.IsEmpty()) {
1774 if (wsValue[0] == '#') {
1775 wsID = CFX_WideString(wsValue.c_str() + 1, wsValue.GetLength() - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04001776 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07001777 wsSOM = wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04001778 }
1779 }
weili44f8faf2016-06-01 14:03:56 -07001780 CXFA_Node* pProtoNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001781 if (!wsSOM.IsEmpty()) {
tsepez736f28a2016-03-25 14:19:51 -07001782 uint32_t dwFlag = XFA_RESOLVENODE_Children |
Dan Sinclair1770c022016-03-14 14:14:16 -04001783 XFA_RESOLVENODE_Attributes |
1784 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1785 XFA_RESOLVENODE_Siblings;
1786 XFA_RESOLVENODE_RS resoveNodeRS;
1787 int32_t iRet = m_pDocument->GetScriptContext()->ResolveObjects(
tsepez4c3debb2016-04-08 12:20:38 -07001788 pProtoRoot, wsSOM.AsStringC(), resoveNodeRS, dwFlag);
Tom Sepezf8a94392017-03-14 12:13:22 -07001789 if (iRet > 0 && resoveNodeRS.objects.front()->IsNode()) {
1790 pProtoNode = resoveNodeRS.objects.front()->AsNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04001791 }
1792 } else if (!wsID.IsEmpty()) {
tsepez4c3debb2016-04-08 12:20:38 -07001793 pProtoNode = m_pDocument->GetNodeByID(pProtoRoot, wsID.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001794 }
1795 if (pProtoNode) {
1796 CXFA_Node* pHeadChild = GetNodeItem(XFA_NODEITEM_FirstChild);
1797 while (pHeadChild) {
1798 CXFA_Node* pSibling =
1799 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1800 RemoveChild(pHeadChild);
1801 pHeadChild = pSibling;
1802 }
tsepezd19e9122016-11-02 15:43:18 -07001803 CXFA_Node* pProtoForm = pProtoNode->CloneTemplateToForm(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001804 pHeadChild = pProtoForm->GetNodeItem(XFA_NODEITEM_FirstChild);
1805 while (pHeadChild) {
1806 CXFA_Node* pSibling =
1807 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1808 pProtoForm->RemoveChild(pHeadChild);
1809 InsertChild(pHeadChild);
1810 pHeadChild = pSibling;
1811 }
1812 m_pDocument->RemovePurgeNode(pProtoForm);
1813 delete pProtoForm;
1814 }
1815 }
1816 } else {
1817 CFX_WideString wsValue;
1818 GetAttribute(eAttribute, wsValue);
Tom Sepezf0b65542017-02-13 10:26:01 -08001819 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001820 }
1821}
dsinclair5b36f0a2016-07-19 10:56:23 -07001822
dsinclair12a6b0c2016-05-26 11:14:08 -07001823void CXFA_Node::Script_Attribute_StringRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001824 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001825 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001826 if (bSetting) {
1827 ThrowInvalidPropertyException();
1828 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001829 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001830
1831 CFX_WideString wsValue;
1832 GetAttribute(eAttribute, wsValue);
Tom Sepezf0b65542017-02-13 10:26:01 -08001833 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001834}
dsinclair5b36f0a2016-07-19 10:56:23 -07001835
Dan Sinclair1770c022016-03-14 14:14:16 -04001836void CXFA_Node::Script_WsdlConnection_Execute(CFXJSE_Arguments* pArguments) {
1837 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001838 if (argc != 0 && argc != 1) {
1839 ThrowParamCountMismatchException(L"execute");
1840 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001841 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001842 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001843}
dsinclair5b36f0a2016-07-19 10:56:23 -07001844
Dan Sinclair1770c022016-03-14 14:14:16 -04001845void CXFA_Node::Script_Delta_Restore(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001846 if (pArguments->GetLength() != 0)
1847 ThrowParamCountMismatchException(L"restore");
Dan Sinclair1770c022016-03-14 14:14:16 -04001848}
dsinclair5b36f0a2016-07-19 10:56:23 -07001849
dsinclair12a6b0c2016-05-26 11:14:08 -07001850void CXFA_Node::Script_Delta_CurrentValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001851 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001852 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001853
dsinclair12a6b0c2016-05-26 11:14:08 -07001854void CXFA_Node::Script_Delta_SavedValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001855 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001856 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001857
dsinclair12a6b0c2016-05-26 11:14:08 -07001858void CXFA_Node::Script_Delta_Target(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001859 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001860 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001861
dsinclair12a6b0c2016-05-26 11:14:08 -07001862void CXFA_Node::Script_Som_Message(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001863 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001864 XFA_SOM_MESSAGETYPE iMessageType) {
1865 CXFA_WidgetData* pWidgetData = GetWidgetData();
1866 if (!pWidgetData) {
1867 return;
1868 }
tsepezd19e9122016-11-02 15:43:18 -07001869 bool bNew = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001870 CXFA_Validate validate = pWidgetData->GetValidate();
1871 if (!validate) {
tsepezd19e9122016-11-02 15:43:18 -07001872 validate = pWidgetData->GetValidate(true);
1873 bNew = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001874 }
1875 if (bSetting) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001876 switch (iMessageType) {
1877 case XFA_SOM_ValidationMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001878 validate.SetScriptMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001879 break;
1880 case XFA_SOM_FormatMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001881 validate.SetFormatMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001882 break;
1883 case XFA_SOM_MandatoryMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001884 validate.SetNullMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001885 break;
1886 default:
1887 break;
1888 }
1889 if (!bNew) {
dsinclaira1b07722016-07-11 08:20:58 -07001890 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04001891 if (!pNotify) {
1892 return;
1893 }
1894 pNotify->AddCalcValidate(this);
1895 }
1896 } else {
1897 CFX_WideString wsMessage;
1898 switch (iMessageType) {
1899 case XFA_SOM_ValidationMessage:
1900 validate.GetScriptMessageText(wsMessage);
1901 break;
1902 case XFA_SOM_FormatMessage:
1903 validate.GetFormatMessageText(wsMessage);
1904 break;
1905 case XFA_SOM_MandatoryMessage:
1906 validate.GetNullMessageText(wsMessage);
1907 break;
1908 default:
1909 break;
1910 }
Tom Sepezf0b65542017-02-13 10:26:01 -08001911 pValue->SetString(wsMessage.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001912 }
1913}
dsinclair5b36f0a2016-07-19 10:56:23 -07001914
dsinclair12a6b0c2016-05-26 11:14:08 -07001915void CXFA_Node::Script_Som_ValidationMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001916 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001917 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001918 Script_Som_Message(pValue, bSetting, XFA_SOM_ValidationMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04001919}
dsinclair5b36f0a2016-07-19 10:56:23 -07001920
dsinclair12a6b0c2016-05-26 11:14:08 -07001921void CXFA_Node::Script_Field_Length(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001922 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001923 XFA_ATTRIBUTE eAttribute) {
1924 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001925 ThrowInvalidPropertyException();
1926 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001927 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001928
1929 CXFA_WidgetData* pWidgetData = GetWidgetData();
1930 if (!pWidgetData) {
1931 pValue->SetInteger(0);
1932 return;
1933 }
1934 pValue->SetInteger(pWidgetData->CountChoiceListItems(true));
Dan Sinclair1770c022016-03-14 14:14:16 -04001935}
dsinclair5b36f0a2016-07-19 10:56:23 -07001936
dsinclair12a6b0c2016-05-26 11:14:08 -07001937void CXFA_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001938 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001939 XFA_ATTRIBUTE eAttribute) {
dsinclair41cb62e2016-06-23 09:20:32 -07001940 XFA_Element eType = GetElementType();
1941 if (eType == XFA_Element::Field) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001942 Script_Field_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001943 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001944 }
1945 if (eType == XFA_Element::Draw) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001946 Script_Draw_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001947 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001948 }
1949 if (eType == XFA_Element::Boolean) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001950 Script_Boolean_Value(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001951 return;
1952 }
1953 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001954 CFX_WideString wsNewValue;
dsinclair769b1372016-06-08 13:12:41 -07001955 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07001956 wsNewValue = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07001957
Dan Sinclair1770c022016-03-14 14:14:16 -04001958 CFX_WideString wsFormatValue(wsNewValue);
weili44f8faf2016-06-01 14:03:56 -07001959 CXFA_WidgetData* pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001960 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001961 CFX_WideString wsPicture;
Tom Sepezf8a94392017-03-14 12:13:22 -07001962 for (CXFA_Node* pFormNode : GetBindItems()) {
1963 if (!pFormNode || pFormNode->HasRemovedChildren())
Dan Sinclair1770c022016-03-14 14:14:16 -04001964 continue;
Dan Sinclair1770c022016-03-14 14:14:16 -04001965 pContainerWidgetData = pFormNode->GetContainerWidgetData();
1966 if (pContainerWidgetData) {
1967 pContainerWidgetData->GetPictureContent(wsPicture,
1968 XFA_VALUEPICTURE_DataBind);
1969 }
Tom Sepezf8a94392017-03-14 12:13:22 -07001970 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -04001971 break;
weili44f8faf2016-06-01 14:03:56 -07001972 pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001973 }
1974 } else if (GetPacketID() == XFA_XDPPACKET_Form) {
1975 pContainerWidgetData = GetContainerWidgetData();
1976 }
1977 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07001978 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04001979 }
tsepezd19e9122016-11-02 15:43:18 -07001980 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001981 } else {
tsepezd19e9122016-11-02 15:43:18 -07001982 CFX_WideString content = GetScriptContent(true);
dsinclair41cb62e2016-06-23 09:20:32 -07001983 if (content.IsEmpty() && eType != XFA_Element::Text &&
1984 eType != XFA_Element::SubmitUrl) {
dsinclairf27aeec2016-06-07 19:36:18 -07001985 pValue->SetNull();
dsinclair41cb62e2016-06-23 09:20:32 -07001986 } else if (eType == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07001987 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair41cb62e2016-06-23 09:20:32 -07001988 } else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) {
tsepez4c3debb2016-04-08 12:20:38 -07001989 CFX_Decimal decimal(content.AsStringC());
Dan Sinclair05df0752017-03-14 14:43:42 -04001990 pValue->SetFloat((float)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04001991 } else {
Tom Sepezf0b65542017-02-13 10:26:01 -08001992 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001993 }
1994 }
1995}
dsinclair5b36f0a2016-07-19 10:56:23 -07001996
dsinclair12a6b0c2016-05-26 11:14:08 -07001997void CXFA_Node::Script_Som_DefaultValue_Read(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001998 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001999 XFA_ATTRIBUTE eAttribute) {
2000 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002001 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002002 return;
2003 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002004
tsepezd19e9122016-11-02 15:43:18 -07002005 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002006 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002007 pValue->SetNull();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002008 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002009 }
Tom Sepezf0b65542017-02-13 10:26:01 -08002010 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002011}
dsinclair5b36f0a2016-07-19 10:56:23 -07002012
dsinclair12a6b0c2016-05-26 11:14:08 -07002013void CXFA_Node::Script_Boolean_Value(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002014 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002015 XFA_ATTRIBUTE eAttribute) {
2016 if (bSetting) {
2017 CFX_ByteString newValue;
dsinclair769b1372016-06-08 13:12:41 -07002018 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002019 newValue = pValue->ToString();
dsinclairf27aeec2016-06-07 19:36:18 -07002020
tsepezb4c9f3f2016-04-13 15:41:21 -07002021 int32_t iValue = FXSYS_atoi(newValue.c_str());
tsepezafe94302016-05-13 17:21:31 -07002022 CFX_WideString wsNewValue(iValue == 0 ? L"0" : L"1");
Dan Sinclair1770c022016-03-14 14:14:16 -04002023 CFX_WideString wsFormatValue(wsNewValue);
2024 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2025 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002026 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002027 }
tsepezd19e9122016-11-02 15:43:18 -07002028 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002029 } else {
tsepezd19e9122016-11-02 15:43:18 -07002030 CFX_WideString wsValue = GetScriptContent(true);
dan sinclair65c7c232017-02-02 14:05:30 -08002031 pValue->SetBoolean(wsValue == L"1");
Dan Sinclair1770c022016-03-14 14:14:16 -04002032 }
2033}
dsinclair2f5582f2016-06-09 11:48:23 -07002034
dsinclair12a6b0c2016-05-26 11:14:08 -07002035void CXFA_Node::Script_Som_BorderColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002036 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002037 XFA_ATTRIBUTE eAttribute) {
2038 CXFA_WidgetData* pWidgetData = GetWidgetData();
2039 if (!pWidgetData) {
2040 return;
2041 }
tsepezd19e9122016-11-02 15:43:18 -07002042 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002043 int32_t iSize = border.CountEdges();
Dan Sinclair1770c022016-03-14 14:14:16 -04002044 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002045 int32_t r = 0;
2046 int32_t g = 0;
2047 int32_t b = 0;
dsinclair5b36f0a2016-07-19 10:56:23 -07002048 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002049 FX_ARGB rgb = ArgbEncode(100, r, g, b);
2050 for (int32_t i = 0; i < iSize; ++i) {
2051 CXFA_Edge edge = border.GetEdge(i);
2052 edge.SetColor(rgb);
2053 }
2054 } else {
2055 CXFA_Edge edge = border.GetEdge(0);
2056 FX_ARGB color = edge.GetColor();
2057 int32_t a, r, g, b;
2058 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002059 CFX_WideString strColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002060 strColor.Format(L"%d,%d,%d", r, g, b);
Tom Sepezf0b65542017-02-13 10:26:01 -08002061 pValue->SetString(strColor.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002062 }
2063}
dsinclair5b36f0a2016-07-19 10:56:23 -07002064
dsinclair12a6b0c2016-05-26 11:14:08 -07002065void CXFA_Node::Script_Som_BorderWidth(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002066 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002067 XFA_ATTRIBUTE eAttribute) {
2068 CXFA_WidgetData* pWidgetData = GetWidgetData();
2069 if (!pWidgetData) {
2070 return;
2071 }
tsepezd19e9122016-11-02 15:43:18 -07002072 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002073 int32_t iSize = border.CountEdges();
2074 CFX_WideString wsThickness;
2075 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002076 wsThickness = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002077 for (int32_t i = 0; i < iSize; ++i) {
2078 CXFA_Edge edge = border.GetEdge(i);
tsepez4c3debb2016-04-08 12:20:38 -07002079 CXFA_Measurement thickness(wsThickness.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002080 edge.SetMSThickness(thickness);
2081 }
2082 } else {
2083 CXFA_Edge edge = border.GetEdge(0);
2084 CXFA_Measurement thickness = edge.GetMSThickness();
2085 thickness.ToString(wsThickness);
Tom Sepezf0b65542017-02-13 10:26:01 -08002086 pValue->SetString(wsThickness.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002087 }
2088}
dsinclair5b36f0a2016-07-19 10:56:23 -07002089
dsinclair12a6b0c2016-05-26 11:14:08 -07002090void CXFA_Node::Script_Som_FillColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002091 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002092 XFA_ATTRIBUTE eAttribute) {
2093 CXFA_WidgetData* pWidgetData = GetWidgetData();
2094 if (!pWidgetData) {
2095 return;
2096 }
tsepezd19e9122016-11-02 15:43:18 -07002097 CXFA_Border border = pWidgetData->GetBorder(true);
2098 CXFA_Fill borderfill = border.GetFill(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002099 CXFA_Node* pNode = borderfill.GetNode();
2100 if (!pNode) {
2101 return;
2102 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002103 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002104 int32_t r;
2105 int32_t g;
2106 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002107 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002108 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2109 borderfill.SetColor(color);
2110 } else {
2111 FX_ARGB color = borderfill.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002112 int32_t a;
2113 int32_t r;
2114 int32_t g;
2115 int32_t b;
Dan Sinclair1770c022016-03-14 14:14:16 -04002116 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002117 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002118 wsColor.Format(L"%d,%d,%d", r, g, b);
Tom Sepezf0b65542017-02-13 10:26:01 -08002119 pValue->SetString(wsColor.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002120 }
2121}
dsinclair5b36f0a2016-07-19 10:56:23 -07002122
dsinclair12a6b0c2016-05-26 11:14:08 -07002123void CXFA_Node::Script_Som_DataNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002124 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002125 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002126 if (bSetting) {
2127 ThrowInvalidPropertyException();
2128 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002129 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002130
2131 CXFA_Node* pDataNode = GetBindData();
2132 if (!pDataNode) {
2133 pValue->SetNull();
2134 return;
2135 }
2136
2137 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pDataNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002138}
dsinclair5b36f0a2016-07-19 10:56:23 -07002139
dsinclair12a6b0c2016-05-26 11:14:08 -07002140void CXFA_Node::Script_Draw_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002141 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002142 XFA_ATTRIBUTE eAttribute) {
2143 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002144 if (pValue && pValue->IsString()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002145 CXFA_WidgetData* pWidgetData = GetWidgetData();
dsinclair43854a52016-04-27 12:26:00 -07002146 ASSERT(pWidgetData);
dsinclair56a8b192016-06-21 14:15:25 -07002147 XFA_Element uiType = pWidgetData->GetUIType();
2148 if (uiType == XFA_Element::Text) {
dsinclair2f5582f2016-06-09 11:48:23 -07002149 CFX_WideString wsNewValue = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002150 CFX_WideString wsFormatValue(wsNewValue);
tsepezd19e9122016-11-02 15:43:18 -07002151 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002152 }
2153 }
2154 } else {
tsepezd19e9122016-11-02 15:43:18 -07002155 CFX_WideString content = GetScriptContent(true);
Tom Sepezf0b65542017-02-13 10:26:01 -08002156 if (content.IsEmpty())
dsinclairf27aeec2016-06-07 19:36:18 -07002157 pValue->SetNull();
Tom Sepezf0b65542017-02-13 10:26:01 -08002158 else
2159 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002160 }
2161}
dsinclair5b36f0a2016-07-19 10:56:23 -07002162
dsinclair12a6b0c2016-05-26 11:14:08 -07002163void CXFA_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002164 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002165 XFA_ATTRIBUTE eAttribute) {
2166 CXFA_WidgetData* pWidgetData = GetWidgetData();
2167 if (!pWidgetData) {
2168 return;
2169 }
2170 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002171 if (pValue && pValue->IsNull()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002172 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002173 pWidgetData->m_bIsNull = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04002174 } else {
2175 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002176 pWidgetData->m_bIsNull = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04002177 }
dsinclair2f5582f2016-06-09 11:48:23 -07002178 CFX_WideString wsNewText;
dsinclair769b1372016-06-08 13:12:41 -07002179 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002180 wsNewText = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07002181
Dan Sinclair1770c022016-03-14 14:14:16 -04002182 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07002183 if (pUIChild->GetElementType() == XFA_Element::NumericEdit) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002184 int32_t iLeadDigits = 0;
2185 int32_t iFracDigits = 0;
2186 pWidgetData->GetLeadDigits(iLeadDigits);
2187 pWidgetData->GetFracDigits(iFracDigits);
dsinclair44d054c2016-04-06 10:23:46 -07002188 wsNewText =
2189 pWidgetData->NumericLimit(wsNewText, iLeadDigits, iFracDigits);
Dan Sinclair1770c022016-03-14 14:14:16 -04002190 }
2191 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2192 CFX_WideString wsFormatText(wsNewText);
2193 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002194 pContainerWidgetData->GetFormatDataValue(wsNewText, wsFormatText);
Dan Sinclair1770c022016-03-14 14:14:16 -04002195 }
tsepezd19e9122016-11-02 15:43:18 -07002196 SetScriptContent(wsNewText, wsFormatText, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002197 } else {
tsepezd19e9122016-11-02 15:43:18 -07002198 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002199 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002200 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002201 } else {
2202 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
Dan Sinclair1770c022016-03-14 14:14:16 -04002203 CXFA_Value defVal = pWidgetData->GetFormValue();
2204 CXFA_Node* pNode = defVal.GetNode()->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair070fcdf2016-06-22 22:04:54 -07002205 if (pNode && pNode->GetElementType() == XFA_Element::Decimal) {
dsinclair41cb62e2016-06-23 09:20:32 -07002206 if (pUIChild->GetElementType() == XFA_Element::NumericEdit &&
Dan Sinclair1770c022016-03-14 14:14:16 -04002207 (pNode->GetInteger(XFA_ATTRIBUTE_FracDigits) == -1)) {
Tom Sepezf0b65542017-02-13 10:26:01 -08002208 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002209 } else {
tsepez4c3debb2016-04-08 12:20:38 -07002210 CFX_Decimal decimal(content.AsStringC());
Dan Sinclair05df0752017-03-14 14:43:42 -04002211 pValue->SetFloat((float)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002212 }
dsinclair070fcdf2016-06-22 22:04:54 -07002213 } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07002214 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair070fcdf2016-06-22 22:04:54 -07002215 } else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) {
tsepezd19e9122016-11-02 15:43:18 -07002216 pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? false : true);
dsinclair070fcdf2016-06-22 22:04:54 -07002217 } else if (pNode && pNode->GetElementType() == XFA_Element::Float) {
tsepez4c3debb2016-04-08 12:20:38 -07002218 CFX_Decimal decimal(content.AsStringC());
Dan Sinclair05df0752017-03-14 14:43:42 -04002219 pValue->SetFloat((float)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002220 } else {
Tom Sepezf0b65542017-02-13 10:26:01 -08002221 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002222 }
2223 }
2224 }
2225}
dsinclair5b36f0a2016-07-19 10:56:23 -07002226
dsinclair12a6b0c2016-05-26 11:14:08 -07002227void CXFA_Node::Script_Field_EditValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002228 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002229 XFA_ATTRIBUTE eAttribute) {
2230 CXFA_WidgetData* pWidgetData = GetWidgetData();
2231 if (!pWidgetData) {
2232 return;
2233 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002234 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002235 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Edit);
Dan Sinclair1770c022016-03-14 14:14:16 -04002236 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002237 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002238 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Edit);
Tom Sepezf0b65542017-02-13 10:26:01 -08002239 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002240 }
2241}
dsinclair5b36f0a2016-07-19 10:56:23 -07002242
dsinclair12a6b0c2016-05-26 11:14:08 -07002243void CXFA_Node::Script_Som_FontColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002244 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002245 XFA_ATTRIBUTE eAttribute) {
2246 CXFA_WidgetData* pWidgetData = GetWidgetData();
2247 if (!pWidgetData) {
2248 return;
2249 }
tsepezd19e9122016-11-02 15:43:18 -07002250 CXFA_Font font = pWidgetData->GetFont(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002251 CXFA_Node* pNode = font.GetNode();
2252 if (!pNode) {
2253 return;
2254 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002255 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002256 int32_t r;
2257 int32_t g;
2258 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002259 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002260 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2261 font.SetColor(color);
2262 } else {
2263 FX_ARGB color = font.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002264 int32_t a;
2265 int32_t r;
2266 int32_t g;
2267 int32_t b;
Dan Sinclair1770c022016-03-14 14:14:16 -04002268 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002269 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002270 wsColor.Format(L"%d,%d,%d", r, g, b);
Tom Sepezf0b65542017-02-13 10:26:01 -08002271 pValue->SetString(wsColor.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002272 }
2273}
dsinclair5b36f0a2016-07-19 10:56:23 -07002274
dsinclair12a6b0c2016-05-26 11:14:08 -07002275void CXFA_Node::Script_Field_FormatMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002276 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002277 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002278 Script_Som_Message(pValue, bSetting, XFA_SOM_FormatMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002279}
dsinclair5b36f0a2016-07-19 10:56:23 -07002280
dsinclair12a6b0c2016-05-26 11:14:08 -07002281void CXFA_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002282 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002283 XFA_ATTRIBUTE eAttribute) {
2284 CXFA_WidgetData* pWidgetData = GetWidgetData();
2285 if (!pWidgetData) {
2286 return;
2287 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002288 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002289 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Display);
Dan Sinclair1770c022016-03-14 14:14:16 -04002290 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002291 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002292 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Display);
Tom Sepezf0b65542017-02-13 10:26:01 -08002293 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002294 }
2295}
dsinclair5b36f0a2016-07-19 10:56:23 -07002296
dsinclair12a6b0c2016-05-26 11:14:08 -07002297void CXFA_Node::Script_Som_Mandatory(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002298 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002299 XFA_ATTRIBUTE eAttribute) {
2300 CXFA_WidgetData* pWidgetData = GetWidgetData();
2301 if (!pWidgetData) {
2302 return;
2303 }
tsepezd19e9122016-11-02 15:43:18 -07002304 CXFA_Validate validate = pWidgetData->GetValidate(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002305 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002306 validate.SetNullTest(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04002307 } else {
2308 int32_t iValue = validate.GetNullTest();
2309 const XFA_ATTRIBUTEENUMINFO* pInfo =
dsinclair9eb0db12016-07-21 12:01:39 -07002310 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)iValue);
dsinclair2f5582f2016-06-09 11:48:23 -07002311 CFX_WideString wsValue;
2312 if (pInfo)
Dan Sinclair1770c022016-03-14 14:14:16 -04002313 wsValue = pInfo->pName;
Tom Sepezf0b65542017-02-13 10:26:01 -08002314 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002315 }
2316}
dsinclair5b36f0a2016-07-19 10:56:23 -07002317
dsinclair12a6b0c2016-05-26 11:14:08 -07002318void CXFA_Node::Script_Som_MandatoryMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002319 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002320 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002321 Script_Som_Message(pValue, bSetting, XFA_SOM_MandatoryMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002322}
dsinclair5b36f0a2016-07-19 10:56:23 -07002323
dsinclair12a6b0c2016-05-26 11:14:08 -07002324void CXFA_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002325 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002326 XFA_ATTRIBUTE eAttribute) {
2327 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002328 ThrowInvalidPropertyException();
2329 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002330 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002331 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002332}
dsinclair5b36f0a2016-07-19 10:56:23 -07002333
dsinclair12a6b0c2016-05-26 11:14:08 -07002334void CXFA_Node::Script_Field_SelectedIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002335 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002336 XFA_ATTRIBUTE eAttribute) {
2337 CXFA_WidgetData* pWidgetData = GetWidgetData();
2338 if (!pWidgetData) {
2339 return;
2340 }
2341 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002342 int32_t iIndex = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002343 if (iIndex == -1) {
2344 pWidgetData->ClearAllSelections();
2345 return;
2346 }
tsepezd19e9122016-11-02 15:43:18 -07002347 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002348 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002349 pValue->SetInteger(pWidgetData->GetSelectedItem());
Dan Sinclair1770c022016-03-14 14:14:16 -04002350 }
2351}
dsinclair5b36f0a2016-07-19 10:56:23 -07002352
Dan Sinclair1770c022016-03-14 14:14:16 -04002353void CXFA_Node::Script_Field_ClearItems(CFXJSE_Arguments* pArguments) {
2354 CXFA_WidgetData* pWidgetData = GetWidgetData();
2355 if (!pWidgetData) {
2356 return;
2357 }
tsepezd19e9122016-11-02 15:43:18 -07002358 pWidgetData->DeleteItem(-1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002359}
dsinclair5b36f0a2016-07-19 10:56:23 -07002360
Dan Sinclair1770c022016-03-14 14:14:16 -04002361void CXFA_Node::Script_Field_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002362 if (pArguments->GetLength() != 1) {
2363 ThrowParamCountMismatchException(L"execEvent");
2364 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002365 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002366
2367 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2368 int32_t iRet = execSingleEventByName(
2369 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2370 XFA_Element::Field);
2371 if (eventString != "validate")
2372 return;
2373
2374 pArguments->GetReturnValue()->SetBoolean(
2375 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002376}
dsinclair5b36f0a2016-07-19 10:56:23 -07002377
Dan Sinclair1770c022016-03-14 14:14:16 -04002378void CXFA_Node::Script_Field_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002379 if (pArguments->GetLength() != 0) {
2380 ThrowParamCountMismatchException(L"execInitialize");
2381 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002382 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002383
2384 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2385 if (!pNotify)
2386 return;
2387
2388 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002389}
dsinclair5b36f0a2016-07-19 10:56:23 -07002390
Dan Sinclair1770c022016-03-14 14:14:16 -04002391void CXFA_Node::Script_Field_DeleteItem(CFXJSE_Arguments* pArguments) {
2392 int32_t iLength = pArguments->GetLength();
2393 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002394 ThrowParamCountMismatchException(L"deleteItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002395 return;
2396 }
2397 CXFA_WidgetData* pWidgetData = GetWidgetData();
2398 if (!pWidgetData) {
2399 return;
2400 }
2401 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002402 bool bValue = pWidgetData->DeleteItem(iIndex, true, true);
dsinclair12a6b0c2016-05-26 11:14:08 -07002403 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002404 if (pValue)
2405 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002406}
dsinclair5b36f0a2016-07-19 10:56:23 -07002407
Dan Sinclair1770c022016-03-14 14:14:16 -04002408void CXFA_Node::Script_Field_GetSaveItem(CFXJSE_Arguments* pArguments) {
2409 int32_t iLength = pArguments->GetLength();
2410 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002411 ThrowParamCountMismatchException(L"getSaveItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002412 return;
2413 }
2414 int32_t iIndex = pArguments->GetInt32(0);
2415 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002416 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002417 return;
2418 }
2419 CXFA_WidgetData* pWidgetData = GetWidgetData();
2420 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002421 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002422 return;
2423 }
2424 CFX_WideString wsValue;
Tom Sepezf0b65542017-02-13 10:26:01 -08002425 if (!pWidgetData->GetChoiceListItem(wsValue, iIndex, true)) {
dsinclairf27aeec2016-06-07 19:36:18 -07002426 pArguments->GetReturnValue()->SetNull();
Tom Sepezf0b65542017-02-13 10:26:01 -08002427 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002428 }
Tom Sepezf0b65542017-02-13 10:26:01 -08002429 pArguments->GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002430}
dsinclair5b36f0a2016-07-19 10:56:23 -07002431
Dan Sinclair1770c022016-03-14 14:14:16 -04002432void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments) {
2433 int32_t iLength = pArguments->GetLength();
2434 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002435 ThrowParamCountMismatchException(L"boundItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002436 return;
2437 }
2438 CXFA_WidgetData* pWidgetData = GetWidgetData();
2439 if (!pWidgetData) {
2440 return;
2441 }
2442 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002443 CFX_WideString wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002444 CFX_WideString wsBoundValue;
tsepez4c3debb2016-04-08 12:20:38 -07002445 pWidgetData->GetItemValue(wsValue.AsStringC(), wsBoundValue);
dsinclair12a6b0c2016-05-26 11:14:08 -07002446 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002447 if (pValue)
Tom Sepezf0b65542017-02-13 10:26:01 -08002448 pValue->SetString(wsBoundValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002449}
dsinclair5b36f0a2016-07-19 10:56:23 -07002450
Dan Sinclair1770c022016-03-14 14:14:16 -04002451void CXFA_Node::Script_Field_GetItemState(CFXJSE_Arguments* pArguments) {
2452 int32_t iLength = pArguments->GetLength();
2453 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002454 ThrowParamCountMismatchException(L"getItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002455 return;
2456 }
2457 CXFA_WidgetData* pWidgetData = GetWidgetData();
2458 if (!pWidgetData) {
2459 return;
2460 }
2461 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002462 bool bValue = pWidgetData->GetItemState(iIndex);
dsinclair12a6b0c2016-05-26 11:14:08 -07002463 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002464 if (pValue)
2465 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002466}
dsinclair5b36f0a2016-07-19 10:56:23 -07002467
Dan Sinclair1770c022016-03-14 14:14:16 -04002468void CXFA_Node::Script_Field_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002469 if (pArguments->GetLength() != 0) {
2470 ThrowParamCountMismatchException(L"execCalculate");
2471 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002472 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002473
2474 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2475 if (!pNotify)
2476 return;
2477
2478 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002479}
dsinclair5b36f0a2016-07-19 10:56:23 -07002480
Dan Sinclair1770c022016-03-14 14:14:16 -04002481void CXFA_Node::Script_Field_SetItems(CFXJSE_Arguments* pArguments) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002482
Dan Sinclair1770c022016-03-14 14:14:16 -04002483void CXFA_Node::Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments) {
2484 int32_t iLength = pArguments->GetLength();
2485 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002486 ThrowParamCountMismatchException(L"getDisplayItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002487 return;
2488 }
2489 int32_t iIndex = pArguments->GetInt32(0);
2490 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002491 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002492 return;
2493 }
2494 CXFA_WidgetData* pWidgetData = GetWidgetData();
2495 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002496 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002497 return;
2498 }
2499 CFX_WideString wsValue;
Tom Sepezf0b65542017-02-13 10:26:01 -08002500 if (!pWidgetData->GetChoiceListItem(wsValue, iIndex, false)) {
dsinclairf27aeec2016-06-07 19:36:18 -07002501 pArguments->GetReturnValue()->SetNull();
Tom Sepezf0b65542017-02-13 10:26:01 -08002502 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002503 }
Tom Sepezf0b65542017-02-13 10:26:01 -08002504 pArguments->GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002505}
dsinclair5b36f0a2016-07-19 10:56:23 -07002506
Dan Sinclair1770c022016-03-14 14:14:16 -04002507void CXFA_Node::Script_Field_SetItemState(CFXJSE_Arguments* pArguments) {
2508 int32_t iLength = pArguments->GetLength();
2509 if (iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002510 ThrowParamCountMismatchException(L"setItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002511 return;
2512 }
2513 CXFA_WidgetData* pWidgetData = GetWidgetData();
thestig800222e2016-05-26 22:00:29 -07002514 if (!pWidgetData)
Dan Sinclair1770c022016-03-14 14:14:16 -04002515 return;
thestig800222e2016-05-26 22:00:29 -07002516
Dan Sinclair1770c022016-03-14 14:14:16 -04002517 int32_t iIndex = pArguments->GetInt32(0);
2518 if (pArguments->GetInt32(1) != 0) {
tsepezd19e9122016-11-02 15:43:18 -07002519 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002520 } else {
thestig800222e2016-05-26 22:00:29 -07002521 if (pWidgetData->GetItemState(iIndex))
tsepezd19e9122016-11-02 15:43:18 -07002522 pWidgetData->SetItemState(iIndex, false, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002523 }
2524}
dsinclair5b36f0a2016-07-19 10:56:23 -07002525
Dan Sinclair1770c022016-03-14 14:14:16 -04002526void CXFA_Node::Script_Field_AddItem(CFXJSE_Arguments* pArguments) {
2527 int32_t iLength = pArguments->GetLength();
2528 if (iLength < 1 || iLength > 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002529 ThrowParamCountMismatchException(L"addItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002530 return;
2531 }
2532 CXFA_WidgetData* pWidgetData = GetWidgetData();
2533 if (!pWidgetData) {
2534 return;
2535 }
2536 CFX_WideString wsLabel;
2537 CFX_WideString wsValue;
2538 if (iLength >= 1) {
tsepez6fe7d212016-04-06 10:51:14 -07002539 CFX_ByteString bsLabel = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002540 wsLabel = CFX_WideString::FromUTF8(bsLabel.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002541 }
2542 if (iLength >= 2) {
2543 CFX_ByteString bsValue = pArguments->GetUTF8String(1);
tsepez4c3debb2016-04-08 12:20:38 -07002544 wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002545 }
tsepezd19e9122016-11-02 15:43:18 -07002546 pWidgetData->InsertItem(wsLabel, wsValue, -1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002547}
dsinclair5b36f0a2016-07-19 10:56:23 -07002548
Dan Sinclair1770c022016-03-14 14:14:16 -04002549void CXFA_Node::Script_Field_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002550 if (pArguments->GetLength() != 0) {
2551 ThrowParamCountMismatchException(L"execValidate");
2552 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002553 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002554
2555 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2556 if (!pNotify) {
2557 pArguments->GetReturnValue()->SetBoolean(false);
2558 return;
2559 }
2560
2561 int32_t iRet =
2562 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate, false, false);
2563 pArguments->GetReturnValue()->SetBoolean(
2564 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002565}
dsinclair5b36f0a2016-07-19 10:56:23 -07002566
dsinclair12a6b0c2016-05-26 11:14:08 -07002567void CXFA_Node::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002568 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002569 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002570 if (bSetting)
2571 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002572}
dsinclair5b36f0a2016-07-19 10:56:23 -07002573
dsinclair12a6b0c2016-05-26 11:14:08 -07002574void CXFA_Node::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002575 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002576 XFA_ATTRIBUTE eAttribute) {
2577 CXFA_WidgetData* pWidgetData = GetWidgetData();
2578 if (!pWidgetData) {
2579 return;
2580 }
2581 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002582 pWidgetData->SetSelectedMemberByValue(pValue->ToWideString().AsStringC(),
tsepezd19e9122016-11-02 15:43:18 -07002583 true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002584 } else {
tsepezd19e9122016-11-02 15:43:18 -07002585 CFX_WideString wsValue = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002586 XFA_VERSION curVersion = GetDocument()->GetCurVersionMode();
2587 if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) {
dsinclairf27aeec2016-06-07 19:36:18 -07002588 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002589 } else {
Tom Sepezf0b65542017-02-13 10:26:01 -08002590 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002591 }
2592 }
2593}
dsinclair5b36f0a2016-07-19 10:56:23 -07002594
dsinclair12a6b0c2016-05-26 11:14:08 -07002595void CXFA_Node::Script_ExclGroup_Transient(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002596 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002597 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002598
Dan Sinclair1770c022016-03-14 14:14:16 -04002599void CXFA_Node::Script_ExclGroup_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002600 if (pArguments->GetLength() != 1) {
2601 ThrowParamCountMismatchException(L"execEvent");
2602 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002603 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002604
2605 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2606 execSingleEventByName(
2607 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2608 XFA_Element::ExclGroup);
Dan Sinclair1770c022016-03-14 14:14:16 -04002609}
thestig800222e2016-05-26 22:00:29 -07002610
Dan Sinclair1770c022016-03-14 14:14:16 -04002611void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments) {
2612 int32_t argc = pArguments->GetLength();
thestig800222e2016-05-26 22:00:29 -07002613 if (argc < 0 || argc > 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002614 ThrowParamCountMismatchException(L"selectedMember");
thestig800222e2016-05-26 22:00:29 -07002615 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002616 }
thestig800222e2016-05-26 22:00:29 -07002617
2618 CXFA_WidgetData* pWidgetData = GetWidgetData();
2619 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002620 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002621 return;
2622 }
2623
2624 CXFA_Node* pReturnNode = nullptr;
2625 if (argc == 0) {
2626 pReturnNode = pWidgetData->GetSelectedMember();
2627 } else {
2628 CFX_ByteString szName;
2629 szName = pArguments->GetUTF8String(0);
2630 pReturnNode = pWidgetData->SetSelectedMember(
2631 CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC(), true);
2632 }
2633 if (!pReturnNode) {
dsinclairf27aeec2016-06-07 19:36:18 -07002634 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002635 return;
2636 }
dsinclairf27aeec2016-06-07 19:36:18 -07002637 pArguments->GetReturnValue()->Assign(
thestig800222e2016-05-26 22:00:29 -07002638 m_pDocument->GetScriptContext()->GetJSValueFromMap(pReturnNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002639}
thestig800222e2016-05-26 22:00:29 -07002640
Dan Sinclair1770c022016-03-14 14:14:16 -04002641void CXFA_Node::Script_ExclGroup_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002642 if (pArguments->GetLength() != 0) {
2643 ThrowParamCountMismatchException(L"execInitialize");
2644 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002645 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002646
2647 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2648 if (!pNotify)
2649 return;
2650
2651 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04002652}
dsinclair5b36f0a2016-07-19 10:56:23 -07002653
Dan Sinclair1770c022016-03-14 14:14:16 -04002654void CXFA_Node::Script_ExclGroup_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002655 if (pArguments->GetLength() != 0) {
2656 ThrowParamCountMismatchException(L"execCalculate");
2657 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002658 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002659
2660 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2661 if (!pNotify)
2662 return;
2663
2664 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04002665}
dsinclair5b36f0a2016-07-19 10:56:23 -07002666
Dan Sinclair1770c022016-03-14 14:14:16 -04002667void CXFA_Node::Script_ExclGroup_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002668 if (pArguments->GetLength() != 0) {
2669 ThrowParamCountMismatchException(L"execValidate");
2670 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002671 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002672
2673 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2674 if (!pNotify) {
2675 pArguments->GetReturnValue()->SetBoolean(false);
2676 return;
2677 }
2678
2679 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
2680 pArguments->GetReturnValue()->SetBoolean(
2681 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002682}
dsinclair5b36f0a2016-07-19 10:56:23 -07002683
dsinclair12a6b0c2016-05-26 11:14:08 -07002684void CXFA_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002685 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002686 XFA_ATTRIBUTE eAttribute) {
2687 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002688 int32_t iTo = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002689 int32_t iFrom = Subform_and_SubformSet_InstanceIndex();
weili44f8faf2016-06-01 14:03:56 -07002690 CXFA_Node* pManagerNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002691 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2692 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002693 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002694 pManagerNode = pNode;
2695 break;
2696 }
2697 }
2698 if (pManagerNode) {
2699 pManagerNode->InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07002700 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002701 if (!pNotify) {
2702 return;
2703 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002704 CXFA_Node* pToInstance = GetItem(pManagerNode, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07002705 if (pToInstance &&
2706 pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002707 pNotify->RunSubformIndexChange(pToInstance);
2708 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002709 CXFA_Node* pFromInstance = GetItem(pManagerNode, iFrom);
dsinclair56a8b192016-06-21 14:15:25 -07002710 if (pFromInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07002711 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002712 pNotify->RunSubformIndexChange(pFromInstance);
2713 }
2714 }
2715 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002716 pValue->SetInteger(Subform_and_SubformSet_InstanceIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04002717 }
2718}
dsinclair5b36f0a2016-07-19 10:56:23 -07002719
dsinclair12a6b0c2016-05-26 11:14:08 -07002720void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002721 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002722 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002723 if (bSetting) {
2724 ThrowInvalidPropertyException();
2725 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002726 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002727
2728 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
2729 CXFA_Node* pInstanceMgr = nullptr;
2730 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2731 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
2732 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
2733 CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name);
2734 if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' &&
2735 wsInstMgrName.Mid(1) == wsName) {
2736 pInstanceMgr = pNode;
2737 }
2738 break;
2739 }
2740 }
2741 if (!pInstanceMgr) {
2742 pValue->SetNull();
2743 return;
2744 }
2745
2746 pValue->Assign(
2747 m_pDocument->GetScriptContext()->GetJSValueFromMap(pInstanceMgr));
Dan Sinclair1770c022016-03-14 14:14:16 -04002748}
dsinclair5b36f0a2016-07-19 10:56:23 -07002749
dsinclair12a6b0c2016-05-26 11:14:08 -07002750void CXFA_Node::Script_Subform_Locale(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002751 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002752 XFA_ATTRIBUTE eAttribute) {
2753 if (bSetting) {
tsepezd19e9122016-11-02 15:43:18 -07002754 SetCData(XFA_ATTRIBUTE_Locale, pValue->ToWideString(), true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002755 } else {
2756 CFX_WideString wsLocaleName;
2757 GetLocaleName(wsLocaleName);
Tom Sepezf0b65542017-02-13 10:26:01 -08002758 pValue->SetString(wsLocaleName.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002759 }
2760}
dsinclair5b36f0a2016-07-19 10:56:23 -07002761
Dan Sinclair1770c022016-03-14 14:14:16 -04002762void CXFA_Node::Script_Subform_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002763 if (pArguments->GetLength() != 1) {
2764 ThrowParamCountMismatchException(L"execEvent");
2765 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002766 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002767
2768 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2769 execSingleEventByName(
2770 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2771 XFA_Element::Subform);
Dan Sinclair1770c022016-03-14 14:14:16 -04002772}
dsinclair5b36f0a2016-07-19 10:56:23 -07002773
Dan Sinclair1770c022016-03-14 14:14:16 -04002774void CXFA_Node::Script_Subform_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002775 if (pArguments->GetLength() != 0) {
2776 ThrowParamCountMismatchException(L"execInitialize");
2777 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002778 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002779
2780 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2781 if (!pNotify)
2782 return;
2783
2784 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04002785}
dsinclair5b36f0a2016-07-19 10:56:23 -07002786
Dan Sinclair1770c022016-03-14 14:14:16 -04002787void CXFA_Node::Script_Subform_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002788 if (pArguments->GetLength() != 0) {
2789 ThrowParamCountMismatchException(L"execCalculate");
2790 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002791 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002792
2793 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2794 if (!pNotify)
2795 return;
2796
2797 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04002798}
dsinclair5b36f0a2016-07-19 10:56:23 -07002799
Dan Sinclair1770c022016-03-14 14:14:16 -04002800void CXFA_Node::Script_Subform_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002801 if (pArguments->GetLength() != 0) {
2802 ThrowParamCountMismatchException(L"execValidate");
2803 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002804 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002805
2806 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2807 if (!pNotify) {
2808 pArguments->GetReturnValue()->SetBoolean(false);
2809 return;
2810 }
2811
2812 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
2813 pArguments->GetReturnValue()->SetBoolean(
2814 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002815}
dsinclair5b36f0a2016-07-19 10:56:23 -07002816
Dan Sinclair1770c022016-03-14 14:14:16 -04002817void CXFA_Node::Script_Subform_GetInvalidObjects(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002818 if (pArguments->GetLength() != 0)
2819 ThrowParamCountMismatchException(L"getInvalidObjects");
Dan Sinclair1770c022016-03-14 14:14:16 -04002820}
dsinclair5b36f0a2016-07-19 10:56:23 -07002821
Dan Sinclair1770c022016-03-14 14:14:16 -04002822int32_t CXFA_Node::Subform_and_SubformSet_InstanceIndex() {
2823 int32_t index = 0;
2824 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2825 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002826 if ((pNode->GetElementType() == XFA_Element::Subform) ||
2827 (pNode->GetElementType() == XFA_Element::SubformSet)) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002828 index++;
2829 } else {
2830 break;
2831 }
2832 }
2833 return index;
2834}
dsinclair5b36f0a2016-07-19 10:56:23 -07002835
Dan Sinclair1770c022016-03-14 14:14:16 -04002836void CXFA_Node::Script_Template_FormNodes(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002837 if (pArguments->GetLength() != 1) {
2838 ThrowParamCountMismatchException(L"formNodes");
2839 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002840 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002841 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002842}
dsinclair5b36f0a2016-07-19 10:56:23 -07002843
Dan Sinclair1770c022016-03-14 14:14:16 -04002844void CXFA_Node::Script_Template_Remerge(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002845 if (pArguments->GetLength() != 0) {
2846 ThrowParamCountMismatchException(L"remerge");
2847 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002848 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002849 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002850}
dsinclair5b36f0a2016-07-19 10:56:23 -07002851
Dan Sinclair1770c022016-03-14 14:14:16 -04002852void CXFA_Node::Script_Template_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002853 if (pArguments->GetLength() != 0) {
2854 ThrowParamCountMismatchException(L"execInitialize");
2855 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002856 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002857
2858 CXFA_WidgetData* pWidgetData = GetWidgetData();
2859 if (!pWidgetData) {
2860 pArguments->GetReturnValue()->SetBoolean(false);
2861 return;
2862 }
2863 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002864}
dsinclair5b36f0a2016-07-19 10:56:23 -07002865
Dan Sinclair1770c022016-03-14 14:14:16 -04002866void CXFA_Node::Script_Template_CreateNode(CFXJSE_Arguments* pArguments) {
2867 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002868 if (argc <= 0 || argc >= 4) {
2869 ThrowParamCountMismatchException(L"createNode");
2870 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002871 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002872
2873 CFX_WideString strName;
2874 CFX_WideString strNameSpace;
2875 CFX_ByteString bsTagName = pArguments->GetUTF8String(0);
2876 CFX_WideString strTagName = CFX_WideString::FromUTF8(bsTagName.AsStringC());
2877 if (argc > 1) {
2878 CFX_ByteString bsName = pArguments->GetUTF8String(1);
2879 strName = CFX_WideString::FromUTF8(bsName.AsStringC());
2880 if (argc == 3) {
2881 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(2);
2882 strNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
2883 }
2884 }
2885
2886 XFA_Element eType = XFA_GetElementTypeForName(strTagName.AsStringC());
2887 CXFA_Node* pNewNode = CreateSamePacketNode(eType);
2888 if (!pNewNode) {
2889 pArguments->GetReturnValue()->SetNull();
2890 return;
2891 }
2892
2893 if (strName.IsEmpty()) {
2894 pArguments->GetReturnValue()->Assign(
2895 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
2896 return;
2897 }
2898
2899 if (!GetAttributeOfElement(eType, XFA_ATTRIBUTE_Name,
2900 XFA_XDPPACKET_UNKNOWN)) {
2901 ThrowMissingPropertyException(strTagName, L"name");
2902 return;
2903 }
2904
2905 pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, strName.AsStringC(), true);
2906 if (pNewNode->GetPacketID() == XFA_XDPPACKET_Datasets)
2907 pNewNode->CreateXMLMappingNode();
2908
2909 pArguments->GetReturnValue()->Assign(
2910 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002911}
dsinclair5b36f0a2016-07-19 10:56:23 -07002912
Dan Sinclair1770c022016-03-14 14:14:16 -04002913void CXFA_Node::Script_Template_Recalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002914 if (pArguments->GetLength() != 1) {
2915 ThrowParamCountMismatchException(L"recalculate");
2916 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002917 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002918 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002919}
dsinclair5b36f0a2016-07-19 10:56:23 -07002920
Dan Sinclair1770c022016-03-14 14:14:16 -04002921void CXFA_Node::Script_Template_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002922 if (pArguments->GetLength() != 0) {
2923 ThrowParamCountMismatchException(L"execCalculate");
2924 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002925 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002926
2927 CXFA_WidgetData* pWidgetData = GetWidgetData();
2928 if (!pWidgetData) {
2929 pArguments->GetReturnValue()->SetBoolean(false);
2930 return;
2931 }
2932 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002933}
dsinclair5b36f0a2016-07-19 10:56:23 -07002934
Dan Sinclair1770c022016-03-14 14:14:16 -04002935void CXFA_Node::Script_Template_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002936 if (pArguments->GetLength() != 0) {
2937 ThrowParamCountMismatchException(L"execValidate");
2938 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002939 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002940 CXFA_WidgetData* pWidgetData = GetWidgetData();
2941 if (!pWidgetData) {
2942 pArguments->GetReturnValue()->SetBoolean(false);
2943 return;
2944 }
2945 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002946}
dsinclair5b36f0a2016-07-19 10:56:23 -07002947
Dan Sinclair1770c022016-03-14 14:14:16 -04002948void CXFA_Node::Script_Manifest_Evaluate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002949 if (pArguments->GetLength() != 0) {
2950 ThrowParamCountMismatchException(L"evaluate");
2951 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002952 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002953
2954 CXFA_WidgetData* pWidgetData = GetWidgetData();
2955 if (!pWidgetData) {
2956 pArguments->GetReturnValue()->SetBoolean(false);
2957 return;
2958 }
2959 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002960}
dsinclair5b36f0a2016-07-19 10:56:23 -07002961
dsinclair12a6b0c2016-05-26 11:14:08 -07002962void CXFA_Node::Script_InstanceManager_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002963 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002964 XFA_ATTRIBUTE eAttribute) {
2965 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002966 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002967 return;
2968 }
2969 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07002970 pValue->SetInteger(nodeOccur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04002971}
dsinclair5b36f0a2016-07-19 10:56:23 -07002972
dsinclair12a6b0c2016-05-26 11:14:08 -07002973void CXFA_Node::Script_InstanceManager_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002974 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002975 XFA_ATTRIBUTE eAttribute) {
2976 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002977 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002978 return;
2979 }
2980 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07002981 pValue->SetInteger(nodeOccur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04002982}
tsepezaadedf92016-05-12 10:08:06 -07002983
dsinclair12a6b0c2016-05-26 11:14:08 -07002984void CXFA_Node::Script_InstanceManager_Count(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002985 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002986 XFA_ATTRIBUTE eAttribute) {
2987 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002988 int32_t iDesired = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002989 InstanceManager_SetInstances(iDesired);
2990 } else {
dsinclair5b36f0a2016-07-19 10:56:23 -07002991 pValue->SetInteger(GetCount(this));
Dan Sinclair1770c022016-03-14 14:14:16 -04002992 }
2993}
dsinclair5b36f0a2016-07-19 10:56:23 -07002994
Dan Sinclair1770c022016-03-14 14:14:16 -04002995void CXFA_Node::Script_InstanceManager_MoveInstance(
2996 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002997 if (pArguments->GetLength() != 2) {
dsinclairf27aeec2016-06-07 19:36:18 -07002998 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04002999 return;
3000 }
3001 int32_t iFrom = pArguments->GetInt32(0);
3002 int32_t iTo = pArguments->GetInt32(1);
3003 InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07003004 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003005 if (!pNotify) {
3006 return;
3007 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003008 CXFA_Node* pToInstance = GetItem(this, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07003009 if (pToInstance && pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003010 pNotify->RunSubformIndexChange(pToInstance);
3011 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003012 CXFA_Node* pFromInstance = GetItem(this, iFrom);
dsinclair070fcdf2016-06-22 22:04:54 -07003013 if (pFromInstance &&
3014 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003015 pNotify->RunSubformIndexChange(pFromInstance);
3016 }
3017}
dsinclair5b36f0a2016-07-19 10:56:23 -07003018
Dan Sinclair1770c022016-03-14 14:14:16 -04003019void CXFA_Node::Script_InstanceManager_RemoveInstance(
3020 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003021 if (pArguments->GetLength() != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003022 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003023 return;
3024 }
3025 int32_t iIndex = pArguments->GetInt32(0);
dsinclair5b36f0a2016-07-19 10:56:23 -07003026 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003027 if (iIndex < 0 || iIndex >= iCount) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003028 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003029 return;
3030 }
3031 CXFA_Occur nodeOccur(GetOccurNode());
3032 int32_t iMin = nodeOccur.GetMin();
3033 if (iCount - 1 < iMin) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003034 ThrowTooManyOccurancesException(L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003035 return;
3036 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003037 CXFA_Node* pRemoveInstance = GetItem(this, iIndex);
3038 RemoveItem(this, pRemoveInstance);
dsinclaira1b07722016-07-11 08:20:58 -07003039 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003040 if (pNotify) {
3041 for (int32_t i = iIndex; i < iCount - 1; i++) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003042 CXFA_Node* pSubformInstance = GetItem(this, i);
Dan Sinclair1770c022016-03-14 14:14:16 -04003043 if (pSubformInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07003044 pSubformInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003045 pNotify->RunSubformIndexChange(pSubformInstance);
3046 }
3047 }
3048 }
3049 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3050 if (!pLayoutPro) {
3051 return;
3052 }
3053 pLayoutPro->AddChangedContainer(
3054 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3055}
dsinclair5b36f0a2016-07-19 10:56:23 -07003056
Dan Sinclair1770c022016-03-14 14:14:16 -04003057void CXFA_Node::Script_InstanceManager_SetInstances(
3058 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003059 if (pArguments->GetLength() != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003060 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003061 return;
3062 }
3063 int32_t iDesired = pArguments->GetInt32(0);
3064 InstanceManager_SetInstances(iDesired);
3065}
dsinclair5b36f0a2016-07-19 10:56:23 -07003066
Dan Sinclair1770c022016-03-14 14:14:16 -04003067void CXFA_Node::Script_InstanceManager_AddInstance(
3068 CFXJSE_Arguments* pArguments) {
3069 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003070 if (argc != 0 && argc != 1) {
3071 ThrowParamCountMismatchException(L"addInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003072 return;
3073 }
tsepezd19e9122016-11-02 15:43:18 -07003074 bool fFlags = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003075 if (argc == 1) {
tsepezd19e9122016-11-02 15:43:18 -07003076 fFlags = pArguments->GetInt32(0) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003077 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003078 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003079 CXFA_Occur nodeOccur(GetOccurNode());
3080 int32_t iMax = nodeOccur.GetMax();
3081 if (iMax >= 0 && iCount >= iMax) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003082 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003083 return;
3084 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003085 CXFA_Node* pNewInstance = CreateInstance(this, fFlags);
tsepezd19e9122016-11-02 15:43:18 -07003086 InsertItem(this, pNewInstance, iCount, iCount, false);
dsinclairf27aeec2016-06-07 19:36:18 -07003087 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003088 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003089 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003090 if (!pNotify) {
3091 return;
3092 }
3093 pNotify->RunNodeInitialize(pNewInstance);
3094 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3095 if (!pLayoutPro) {
3096 return;
3097 }
3098 pLayoutPro->AddChangedContainer(
3099 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3100}
dsinclair5b36f0a2016-07-19 10:56:23 -07003101
Dan Sinclair1770c022016-03-14 14:14:16 -04003102void CXFA_Node::Script_InstanceManager_InsertInstance(
3103 CFXJSE_Arguments* pArguments) {
3104 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003105 if (argc != 1 && argc != 2) {
3106 ThrowParamCountMismatchException(L"insertInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003107 return;
3108 }
3109 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07003110 bool bBind = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003111 if (argc == 2) {
tsepezd19e9122016-11-02 15:43:18 -07003112 bBind = pArguments->GetInt32(1) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003113 }
3114 CXFA_Occur nodeOccur(GetOccurNode());
dsinclair5b36f0a2016-07-19 10:56:23 -07003115 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003116 if (iIndex < 0 || iIndex > iCount) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003117 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003118 return;
3119 }
3120 int32_t iMax = nodeOccur.GetMax();
3121 if (iMax >= 0 && iCount >= iMax) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003122 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003123 return;
3124 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003125 CXFA_Node* pNewInstance = CreateInstance(this, bBind);
tsepezd19e9122016-11-02 15:43:18 -07003126 InsertItem(this, pNewInstance, iIndex, iCount, true);
dsinclairf27aeec2016-06-07 19:36:18 -07003127 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003128 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003129 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003130 if (!pNotify) {
3131 return;
3132 }
3133 pNotify->RunNodeInitialize(pNewInstance);
3134 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3135 if (!pLayoutPro) {
3136 return;
3137 }
3138 pLayoutPro->AddChangedContainer(
3139 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3140}
dsinclair5b36f0a2016-07-19 10:56:23 -07003141
Dan Sinclair1770c022016-03-14 14:14:16 -04003142int32_t CXFA_Node::InstanceManager_SetInstances(int32_t iDesired) {
3143 CXFA_Occur nodeOccur(GetOccurNode());
3144 int32_t iMax = nodeOccur.GetMax();
3145 int32_t iMin = nodeOccur.GetMin();
3146 if (iDesired < iMin) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003147 ThrowTooManyOccurancesException(L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003148 return 1;
3149 }
3150 if ((iMax >= 0) && (iDesired > iMax)) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003151 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003152 return 2;
3153 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003154 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003155 if (iDesired == iCount) {
3156 return 0;
3157 }
3158 if (iDesired < iCount) {
3159 CFX_WideStringC wsInstManagerName = GetCData(XFA_ATTRIBUTE_Name);
tsepezafe94302016-05-13 17:21:31 -07003160 CFX_WideString wsInstanceName =
3161 CFX_WideString(wsInstManagerName.IsEmpty() ? wsInstManagerName
3162 : wsInstManagerName.Mid(1));
tsepez736f28a2016-03-25 14:19:51 -07003163 uint32_t dInstanceNameHash =
tsepezb6853cf2016-04-25 11:23:43 -07003164 FX_HashCode_GetW(wsInstanceName.AsStringC(), false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003165 CXFA_Node* pPrevSibling =
dsinclair5b36f0a2016-07-19 10:56:23 -07003166 (iDesired == 0) ? this : GetItem(this, iDesired - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04003167 while (iCount > iDesired) {
3168 CXFA_Node* pRemoveInstance =
3169 pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling);
dsinclair070fcdf2016-06-22 22:04:54 -07003170 if (pRemoveInstance->GetElementType() != XFA_Element::Subform &&
3171 pRemoveInstance->GetElementType() != XFA_Element::SubformSet) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003172 continue;
3173 }
dsinclair070fcdf2016-06-22 22:04:54 -07003174 if (pRemoveInstance->GetElementType() == XFA_Element::InstanceManager) {
tsepezd19e9122016-11-02 15:43:18 -07003175 ASSERT(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003176 break;
3177 }
3178 if (pRemoveInstance->GetNameHash() == dInstanceNameHash) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003179 RemoveItem(this, pRemoveInstance);
Dan Sinclair1770c022016-03-14 14:14:16 -04003180 iCount--;
3181 }
3182 }
3183 } else if (iDesired > iCount) {
3184 while (iCount < iDesired) {
tsepezd19e9122016-11-02 15:43:18 -07003185 CXFA_Node* pNewInstance = CreateInstance(this, true);
3186 InsertItem(this, pNewInstance, iCount, iCount, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003187 iCount++;
dsinclaira1b07722016-07-11 08:20:58 -07003188 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003189 if (!pNotify) {
3190 return 0;
3191 }
3192 pNotify->RunNodeInitialize(pNewInstance);
3193 }
3194 }
3195 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3196 if (pLayoutPro) {
3197 pLayoutPro->AddChangedContainer(
3198 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3199 }
3200 return 0;
3201}
dsinclair5b36f0a2016-07-19 10:56:23 -07003202
Dan Sinclair1770c022016-03-14 14:14:16 -04003203int32_t CXFA_Node::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003204 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003205 if (iFrom > iCount || iTo > iCount - 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003206 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003207 return 1;
3208 }
3209 if (iFrom < 0 || iTo < 0 || iFrom == iTo) {
3210 return 0;
3211 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003212 CXFA_Node* pMoveInstance = GetItem(this, iFrom);
tsepezd19e9122016-11-02 15:43:18 -07003213 RemoveItem(this, pMoveInstance, false);
3214 InsertItem(this, pMoveInstance, iTo, iCount - 1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003215 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3216 if (pLayoutPro) {
3217 pLayoutPro->AddChangedContainer(
3218 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3219 }
3220 return 0;
3221}
dsinclair5b36f0a2016-07-19 10:56:23 -07003222
dsinclair12a6b0c2016-05-26 11:14:08 -07003223void CXFA_Node::Script_Occur_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003224 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003225 XFA_ATTRIBUTE eAttribute) {
3226 CXFA_Occur occur(this);
3227 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003228 int32_t iMax = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003229 occur.SetMax(iMax);
3230 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003231 pValue->SetInteger(occur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04003232 }
3233}
dsinclair5b36f0a2016-07-19 10:56:23 -07003234
dsinclair12a6b0c2016-05-26 11:14:08 -07003235void CXFA_Node::Script_Occur_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003236 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003237 XFA_ATTRIBUTE eAttribute) {
3238 CXFA_Occur occur(this);
3239 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003240 int32_t iMin = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003241 occur.SetMin(iMin);
3242 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003243 pValue->SetInteger(occur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04003244 }
3245}
dsinclair5b36f0a2016-07-19 10:56:23 -07003246
Dan Sinclair1770c022016-03-14 14:14:16 -04003247void CXFA_Node::Script_Desc_Metadata(CFXJSE_Arguments* pArguments) {
3248 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003249 if (argc != 0 && argc != 1) {
3250 ThrowParamCountMismatchException(L"metadata");
3251 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003252 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003253 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04003254}
dsinclair5b36f0a2016-07-19 10:56:23 -07003255
Dan Sinclair1770c022016-03-14 14:14:16 -04003256void CXFA_Node::Script_Form_FormNodes(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003257 if (pArguments->GetLength() != 1) {
3258 ThrowParamCountMismatchException(L"formNodes");
3259 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003260 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003261
3262 CXFA_Node* pDataNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
3263 if (!pDataNode) {
3264 ThrowArgumentMismatchException();
3265 return;
3266 }
3267
Tom Sepezf8a94392017-03-14 12:13:22 -07003268 std::vector<CXFA_Node*> formItems;
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003269 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
3270 pFormNodes->SetArrayNodeList(formItems);
3271 pArguments->GetReturnValue()->SetObject(
3272 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04003273}
dsinclair5b36f0a2016-07-19 10:56:23 -07003274
Dan Sinclair1770c022016-03-14 14:14:16 -04003275void CXFA_Node::Script_Form_Remerge(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003276 if (pArguments->GetLength() != 0) {
3277 ThrowParamCountMismatchException(L"remerge");
3278 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003279 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003280
3281 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003282}
dsinclair5b36f0a2016-07-19 10:56:23 -07003283
Dan Sinclair1770c022016-03-14 14:14:16 -04003284void CXFA_Node::Script_Form_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003285 if (pArguments->GetLength() != 0) {
3286 ThrowParamCountMismatchException(L"execInitialize");
3287 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003288 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003289
3290 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3291 if (!pNotify)
3292 return;
3293
3294 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04003295}
dsinclair5b36f0a2016-07-19 10:56:23 -07003296
Dan Sinclair1770c022016-03-14 14:14:16 -04003297void CXFA_Node::Script_Form_Recalculate(CFXJSE_Arguments* pArguments) {
3298 CXFA_EventParam* pEventParam =
3299 m_pDocument->GetScriptContext()->GetEventParam();
3300 if (pEventParam->m_eType == XFA_EVENT_Calculate ||
3301 pEventParam->m_eType == XFA_EVENT_InitCalculate) {
3302 return;
3303 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003304 if (pArguments->GetLength() != 1) {
3305 ThrowParamCountMismatchException(L"recalculate");
3306 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003307 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003308
3309 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3310 if (!pNotify)
3311 return;
3312 if (pArguments->GetInt32(0) != 0)
3313 return;
3314
3315 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
3316 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
3317 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Ready, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003318}
dsinclair5b36f0a2016-07-19 10:56:23 -07003319
Dan Sinclair1770c022016-03-14 14:14:16 -04003320void CXFA_Node::Script_Form_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003321 if (pArguments->GetLength() != 0) {
3322 ThrowParamCountMismatchException(L"execCalculate");
3323 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003324 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003325
3326 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3327 if (!pNotify)
3328 return;
3329
3330 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04003331}
dsinclair5b36f0a2016-07-19 10:56:23 -07003332
Dan Sinclair1770c022016-03-14 14:14:16 -04003333void CXFA_Node::Script_Form_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003334 if (pArguments->GetLength() != 0) {
3335 ThrowParamCountMismatchException(L"execValidate");
3336 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003337 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003338
3339 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3340 if (!pNotify) {
3341 pArguments->GetReturnValue()->SetBoolean(false);
3342 return;
3343 }
3344
3345 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
3346 pArguments->GetReturnValue()->SetBoolean(
3347 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003348}
dsinclair5b36f0a2016-07-19 10:56:23 -07003349
dsinclair12a6b0c2016-05-26 11:14:08 -07003350void CXFA_Node::Script_Form_Checksum(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003351 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003352 XFA_ATTRIBUTE eAttribute) {
3353 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07003354 SetAttribute(XFA_ATTRIBUTE_Checksum, pValue->ToWideString().AsStringC());
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003355 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003356 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003357 CFX_WideString wsChecksum;
3358 GetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum, false);
Tom Sepezf0b65542017-02-13 10:26:01 -08003359 pValue->SetString(wsChecksum.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003360}
dsinclair5b36f0a2016-07-19 10:56:23 -07003361
Dan Sinclair1770c022016-03-14 14:14:16 -04003362void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003363 if (pArguments->GetLength() != 1) {
3364 ThrowParamCountMismatchException(L"getAttribute");
3365 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003366 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003367 CFX_ByteString bsAttributeName = pArguments->GetUTF8String(0);
3368 CFX_WideString wsAttributeValue;
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003369 CFX_XMLNode* pXMLNode = GetXMLMappingNode();
3370 if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) {
3371 wsAttributeValue = static_cast<CFX_XMLElement*>(pXMLNode)->GetString(
Dan Sinclair5fa4e982017-04-05 11:48:21 -04003372 CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str());
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003373 }
3374 pArguments->GetReturnValue()->SetString(
Tom Sepezf0b65542017-02-13 10:26:01 -08003375 wsAttributeValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003376}
dsinclair5b36f0a2016-07-19 10:56:23 -07003377
Dan Sinclair1770c022016-03-14 14:14:16 -04003378void CXFA_Node::Script_Packet_SetAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003379 if (pArguments->GetLength() != 2) {
3380 ThrowParamCountMismatchException(L"setAttribute");
3381 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003382 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003383 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
3384 CFX_ByteString bsName = pArguments->GetUTF8String(1);
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003385 CFX_XMLNode* pXMLNode = GetXMLMappingNode();
3386 if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) {
3387 static_cast<CFX_XMLElement*>(pXMLNode)->SetString(
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003388 CFX_WideString::FromUTF8(bsName.AsStringC()),
3389 CFX_WideString::FromUTF8(bsValue.AsStringC()));
3390 }
3391 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003392}
dsinclair5b36f0a2016-07-19 10:56:23 -07003393
Dan Sinclair1770c022016-03-14 14:14:16 -04003394void CXFA_Node::Script_Packet_RemoveAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003395 if (pArguments->GetLength() != 1) {
3396 ThrowParamCountMismatchException(L"removeAttribute");
3397 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003398 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003399
3400 CFX_ByteString bsName = pArguments->GetUTF8String(0);
3401 CFX_WideString wsName = CFX_WideString::FromUTF8(bsName.AsStringC());
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003402 CFX_XMLNode* pXMLNode = GetXMLMappingNode();
3403 if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) {
3404 CFX_XMLElement* pXMLElement = static_cast<CFX_XMLElement*>(pXMLNode);
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003405 if (pXMLElement->HasAttribute(wsName.c_str())) {
3406 pXMLElement->RemoveAttribute(wsName.c_str());
3407 }
3408 }
3409 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003410}
dsinclair5b36f0a2016-07-19 10:56:23 -07003411
dsinclair12a6b0c2016-05-26 11:14:08 -07003412void CXFA_Node::Script_Packet_Content(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003413 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003414 XFA_ATTRIBUTE eAttribute) {
3415 if (bSetting) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003416 CFX_XMLNode* pXMLNode = GetXMLMappingNode();
3417 if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) {
3418 CFX_XMLElement* pXMLElement = static_cast<CFX_XMLElement*>(pXMLNode);
dsinclair2f5582f2016-06-09 11:48:23 -07003419 pXMLElement->SetTextData(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04003420 }
3421 } else {
3422 CFX_WideString wsTextData;
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003423 CFX_XMLNode* pXMLNode = GetXMLMappingNode();
3424 if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) {
3425 CFX_XMLElement* pXMLElement = static_cast<CFX_XMLElement*>(pXMLNode);
Dan Sinclair5fa4e982017-04-05 11:48:21 -04003426 wsTextData = pXMLElement->GetTextData();
Dan Sinclair1770c022016-03-14 14:14:16 -04003427 }
Tom Sepezf0b65542017-02-13 10:26:01 -08003428 pValue->SetString(wsTextData.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003429 }
3430}
dsinclair5b36f0a2016-07-19 10:56:23 -07003431
Dan Sinclair1770c022016-03-14 14:14:16 -04003432void CXFA_Node::Script_Source_Next(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003433 if (pArguments->GetLength() != 0)
3434 ThrowParamCountMismatchException(L"next");
Dan Sinclair1770c022016-03-14 14:14:16 -04003435}
dsinclair5b36f0a2016-07-19 10:56:23 -07003436
Dan Sinclair1770c022016-03-14 14:14:16 -04003437void CXFA_Node::Script_Source_CancelBatch(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003438 if (pArguments->GetLength() != 0)
3439 ThrowParamCountMismatchException(L"cancelBatch");
Dan Sinclair1770c022016-03-14 14:14:16 -04003440}
dsinclair5b36f0a2016-07-19 10:56:23 -07003441
Dan Sinclair1770c022016-03-14 14:14:16 -04003442void CXFA_Node::Script_Source_First(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003443 if (pArguments->GetLength() != 0)
3444 ThrowParamCountMismatchException(L"first");
Dan Sinclair1770c022016-03-14 14:14:16 -04003445}
dsinclair5b36f0a2016-07-19 10:56:23 -07003446
Dan Sinclair1770c022016-03-14 14:14:16 -04003447void CXFA_Node::Script_Source_UpdateBatch(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003448 if (pArguments->GetLength() != 0)
3449 ThrowParamCountMismatchException(L"updateBatch");
Dan Sinclair1770c022016-03-14 14:14:16 -04003450}
dsinclair5b36f0a2016-07-19 10:56:23 -07003451
Dan Sinclair1770c022016-03-14 14:14:16 -04003452void CXFA_Node::Script_Source_Previous(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003453 if (pArguments->GetLength() != 0)
3454 ThrowParamCountMismatchException(L"previous");
Dan Sinclair1770c022016-03-14 14:14:16 -04003455}
dsinclair5b36f0a2016-07-19 10:56:23 -07003456
Dan Sinclair1770c022016-03-14 14:14:16 -04003457void CXFA_Node::Script_Source_IsBOF(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003458 if (pArguments->GetLength() != 0)
3459 ThrowParamCountMismatchException(L"isBOF");
Dan Sinclair1770c022016-03-14 14:14:16 -04003460}
dsinclair5b36f0a2016-07-19 10:56:23 -07003461
Dan Sinclair1770c022016-03-14 14:14:16 -04003462void CXFA_Node::Script_Source_IsEOF(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003463 if (pArguments->GetLength() != 0)
3464 ThrowParamCountMismatchException(L"isEOF");
Dan Sinclair1770c022016-03-14 14:14:16 -04003465}
dsinclair5b36f0a2016-07-19 10:56:23 -07003466
Dan Sinclair1770c022016-03-14 14:14:16 -04003467void CXFA_Node::Script_Source_Cancel(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003468 if (pArguments->GetLength() != 0)
3469 ThrowParamCountMismatchException(L"cancel");
Dan Sinclair1770c022016-03-14 14:14:16 -04003470}
dsinclair5b36f0a2016-07-19 10:56:23 -07003471
Dan Sinclair1770c022016-03-14 14:14:16 -04003472void CXFA_Node::Script_Source_Update(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003473 if (pArguments->GetLength() != 0)
3474 ThrowParamCountMismatchException(L"update");
Dan Sinclair1770c022016-03-14 14:14:16 -04003475}
dsinclair5b36f0a2016-07-19 10:56:23 -07003476
Dan Sinclair1770c022016-03-14 14:14:16 -04003477void CXFA_Node::Script_Source_Open(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003478 if (pArguments->GetLength() != 0)
3479 ThrowParamCountMismatchException(L"open");
Dan Sinclair1770c022016-03-14 14:14:16 -04003480}
dsinclair5b36f0a2016-07-19 10:56:23 -07003481
Dan Sinclair1770c022016-03-14 14:14:16 -04003482void CXFA_Node::Script_Source_Delete(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003483 if (pArguments->GetLength() != 0)
3484 ThrowParamCountMismatchException(L"delete");
Dan Sinclair1770c022016-03-14 14:14:16 -04003485}
dsinclair5b36f0a2016-07-19 10:56:23 -07003486
Dan Sinclair1770c022016-03-14 14:14:16 -04003487void CXFA_Node::Script_Source_AddNew(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003488 if (pArguments->GetLength() != 0)
3489 ThrowParamCountMismatchException(L"addNew");
Dan Sinclair1770c022016-03-14 14:14:16 -04003490}
dsinclair5b36f0a2016-07-19 10:56:23 -07003491
Dan Sinclair1770c022016-03-14 14:14:16 -04003492void CXFA_Node::Script_Source_Requery(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003493 if (pArguments->GetLength() != 0)
3494 ThrowParamCountMismatchException(L"requery");
Dan Sinclair1770c022016-03-14 14:14:16 -04003495}
dsinclair5b36f0a2016-07-19 10:56:23 -07003496
Dan Sinclair1770c022016-03-14 14:14:16 -04003497void CXFA_Node::Script_Source_Resync(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003498 if (pArguments->GetLength() != 0)
3499 ThrowParamCountMismatchException(L"resync");
Dan Sinclair1770c022016-03-14 14:14:16 -04003500}
dsinclair5b36f0a2016-07-19 10:56:23 -07003501
Dan Sinclair1770c022016-03-14 14:14:16 -04003502void CXFA_Node::Script_Source_Close(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003503 if (pArguments->GetLength() != 0)
3504 ThrowParamCountMismatchException(L"close");
Dan Sinclair1770c022016-03-14 14:14:16 -04003505}
dsinclair5b36f0a2016-07-19 10:56:23 -07003506
Dan Sinclair1770c022016-03-14 14:14:16 -04003507void CXFA_Node::Script_Source_Last(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003508 if (pArguments->GetLength() != 0)
3509 ThrowParamCountMismatchException(L"last");
Dan Sinclair1770c022016-03-14 14:14:16 -04003510}
dsinclair5b36f0a2016-07-19 10:56:23 -07003511
Dan Sinclair1770c022016-03-14 14:14:16 -04003512void CXFA_Node::Script_Source_HasDataChanged(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003513 if (pArguments->GetLength() != 0)
3514 ThrowParamCountMismatchException(L"hasDataChanged");
Dan Sinclair1770c022016-03-14 14:14:16 -04003515}
dsinclair5b36f0a2016-07-19 10:56:23 -07003516
dsinclair12a6b0c2016-05-26 11:14:08 -07003517void CXFA_Node::Script_Source_Db(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003518 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003519 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003520
dsinclair12a6b0c2016-05-26 11:14:08 -07003521void CXFA_Node::Script_Xfa_This(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003522 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003523 XFA_ATTRIBUTE eAttribute) {
3524 if (!bSetting) {
3525 CXFA_Object* pThis = m_pDocument->GetScriptContext()->GetThisObject();
dsinclair43854a52016-04-27 12:26:00 -07003526 ASSERT(pThis);
dsinclairf27aeec2016-06-07 19:36:18 -07003527 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pThis));
Dan Sinclair1770c022016-03-14 14:14:16 -04003528 }
3529}
dsinclair5b36f0a2016-07-19 10:56:23 -07003530
dsinclair12a6b0c2016-05-26 11:14:08 -07003531void CXFA_Node::Script_Handler_Version(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003532 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003533 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003534
dsinclair12a6b0c2016-05-26 11:14:08 -07003535void CXFA_Node::Script_SubmitFormat_Mode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003536 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003537 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003538
dsinclair12a6b0c2016-05-26 11:14:08 -07003539void CXFA_Node::Script_Extras_Type(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003540 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003541 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003542
dsinclair12a6b0c2016-05-26 11:14:08 -07003543void CXFA_Node::Script_Script_Stateless(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003544 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003545 XFA_ATTRIBUTE eAttribute) {
3546 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003547 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003548 return;
3549 }
dan sinclair65c7c232017-02-02 14:05:30 -08003550 pValue->SetString(FX_UTF8Encode(CFX_WideStringC(L"0", 1)).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003551}
dsinclair5b36f0a2016-07-19 10:56:23 -07003552
dsinclair12a6b0c2016-05-26 11:14:08 -07003553void CXFA_Node::Script_Encrypt_Format(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003554 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003555 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003556
tsepezd19e9122016-11-02 15:43:18 -07003557bool CXFA_Node::HasAttribute(XFA_ATTRIBUTE eAttr, bool bCanInherit) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003558 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003559 return HasMapModuleKey(pKey, bCanInherit);
3560}
dsinclair5b36f0a2016-07-19 10:56:23 -07003561
tsepezd19e9122016-11-02 15:43:18 -07003562bool CXFA_Node::SetAttribute(XFA_ATTRIBUTE eAttr,
3563 const CFX_WideStringC& wsValue,
3564 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003565 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003566 if (!pAttr)
tsepezd19e9122016-11-02 15:43:18 -07003567 return false;
weili44f8faf2016-06-01 14:03:56 -07003568
Dan Sinclair1770c022016-03-14 14:14:16 -04003569 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3570 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3571 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003572 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003573 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3574 }
3575 switch (eType) {
3576 case XFA_ATTRIBUTETYPE_Enum: {
3577 const XFA_ATTRIBUTEENUMINFO* pEnum = XFA_GetAttributeEnumByName(wsValue);
3578 return SetEnum(pAttr->eName,
3579 pEnum ? pEnum->eName
3580 : (XFA_ATTRIBUTEENUM)(intptr_t)(pAttr->pDefValue),
3581 bNotify);
3582 } break;
3583 case XFA_ATTRIBUTETYPE_Cdata:
tsepezafe94302016-05-13 17:21:31 -07003584 return SetCData(pAttr->eName, CFX_WideString(wsValue), bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003585 case XFA_ATTRIBUTETYPE_Boolean:
dan sinclair65c7c232017-02-02 14:05:30 -08003586 return SetBoolean(pAttr->eName, wsValue != L"0", bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003587 case XFA_ATTRIBUTETYPE_Integer:
dsinclaire0347a62016-08-11 11:24:11 -07003588 return SetInteger(pAttr->eName,
3589 FXSYS_round(FXSYS_wcstof(wsValue.c_str(),
3590 wsValue.GetLength(), nullptr)),
3591 bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003592 case XFA_ATTRIBUTETYPE_Measure:
3593 return SetMeasure(pAttr->eName, CXFA_Measurement(wsValue), bNotify);
3594 default:
3595 break;
3596 }
tsepezd19e9122016-11-02 15:43:18 -07003597 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003598}
dsinclair5b36f0a2016-07-19 10:56:23 -07003599
tsepezd19e9122016-11-02 15:43:18 -07003600bool CXFA_Node::GetAttribute(XFA_ATTRIBUTE eAttr,
3601 CFX_WideString& wsValue,
3602 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003603 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003604 if (!pAttr) {
tsepezd19e9122016-11-02 15:43:18 -07003605 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003606 }
3607 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3608 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3609 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003610 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003611 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3612 }
3613 switch (eType) {
3614 case XFA_ATTRIBUTETYPE_Enum: {
3615 XFA_ATTRIBUTEENUM eValue;
3616 if (!TryEnum(pAttr->eName, eValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003617 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003618 }
dsinclair9eb0db12016-07-21 12:01:39 -07003619 wsValue = GetAttributeEnumByID(eValue)->pName;
tsepezd19e9122016-11-02 15:43:18 -07003620 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003621 } break;
3622 case XFA_ATTRIBUTETYPE_Cdata: {
3623 CFX_WideStringC wsValueC;
3624 if (!TryCData(pAttr->eName, wsValueC, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003625 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003626 }
3627 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07003628 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003629 } break;
3630 case XFA_ATTRIBUTETYPE_Boolean: {
tsepezd19e9122016-11-02 15:43:18 -07003631 bool bValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04003632 if (!TryBoolean(pAttr->eName, bValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003633 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003634 }
dan sinclair65c7c232017-02-02 14:05:30 -08003635 wsValue = bValue ? L"1" : L"0";
tsepezd19e9122016-11-02 15:43:18 -07003636 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003637 } break;
3638 case XFA_ATTRIBUTETYPE_Integer: {
3639 int32_t iValue;
3640 if (!TryInteger(pAttr->eName, iValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003641 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003642 }
3643 wsValue.Format(L"%d", iValue);
tsepezd19e9122016-11-02 15:43:18 -07003644 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003645 } break;
3646 case XFA_ATTRIBUTETYPE_Measure: {
3647 CXFA_Measurement mValue;
3648 if (!TryMeasure(pAttr->eName, mValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003649 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003650 }
3651 mValue.ToString(wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003652 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003653 } break;
3654 default:
3655 break;
3656 }
tsepezd19e9122016-11-02 15:43:18 -07003657 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003658}
dsinclair5b36f0a2016-07-19 10:56:23 -07003659
tsepezd19e9122016-11-02 15:43:18 -07003660bool CXFA_Node::SetAttribute(const CFX_WideStringC& wsAttr,
3661 const CFX_WideStringC& wsValue,
3662 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003663 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsValue);
3664 if (pAttributeInfo) {
3665 return SetAttribute(pAttributeInfo->eName, wsValue, bNotify);
3666 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003667 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003668 SetMapModuleString(pKey, wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003669 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003670}
dsinclair5b36f0a2016-07-19 10:56:23 -07003671
tsepezd19e9122016-11-02 15:43:18 -07003672bool CXFA_Node::GetAttribute(const CFX_WideStringC& wsAttr,
3673 CFX_WideString& wsValue,
3674 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003675 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsAttr);
3676 if (pAttributeInfo) {
3677 return GetAttribute(pAttributeInfo->eName, wsValue, bUseDefault);
3678 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003679 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003680 CFX_WideStringC wsValueC;
3681 if (GetMapModuleString(pKey, wsValueC)) {
3682 wsValue = wsValueC;
3683 }
tsepezd19e9122016-11-02 15:43:18 -07003684 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003685}
dsinclair5b36f0a2016-07-19 10:56:23 -07003686
tsepezd19e9122016-11-02 15:43:18 -07003687bool CXFA_Node::RemoveAttribute(const CFX_WideStringC& wsAttr) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003688 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003689 RemoveMapModuleKey(pKey);
tsepezd19e9122016-11-02 15:43:18 -07003690 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003691}
dsinclair5b36f0a2016-07-19 10:56:23 -07003692
tsepezd19e9122016-11-02 15:43:18 -07003693bool CXFA_Node::TryBoolean(XFA_ATTRIBUTE eAttr,
3694 bool& bValue,
3695 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003696 void* pValue = nullptr;
3697 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Boolean, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003698 return false;
tsepez478ed622016-10-27 14:32:33 -07003699 bValue = !!pValue;
tsepezd19e9122016-11-02 15:43:18 -07003700 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003701}
dsinclair5b36f0a2016-07-19 10:56:23 -07003702
tsepezd19e9122016-11-02 15:43:18 -07003703bool CXFA_Node::TryInteger(XFA_ATTRIBUTE eAttr,
3704 int32_t& iValue,
3705 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003706 void* pValue = nullptr;
3707 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Integer, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003708 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003709 iValue = (int32_t)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003710 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003711}
dsinclair5b36f0a2016-07-19 10:56:23 -07003712
tsepezd19e9122016-11-02 15:43:18 -07003713bool CXFA_Node::TryEnum(XFA_ATTRIBUTE eAttr,
3714 XFA_ATTRIBUTEENUM& eValue,
3715 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003716 void* pValue = nullptr;
3717 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Enum, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003718 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003719 eValue = (XFA_ATTRIBUTEENUM)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003720 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003721}
thestigb1a59592016-04-14 18:29:56 -07003722
tsepezd19e9122016-11-02 15:43:18 -07003723bool CXFA_Node::SetMeasure(XFA_ATTRIBUTE eAttr,
3724 CXFA_Measurement mValue,
3725 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003726 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003727 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003728 SetMapModuleBuffer(pKey, &mValue, sizeof(CXFA_Measurement));
tsepezd19e9122016-11-02 15:43:18 -07003729 OnChanged(eAttr, bNotify, false);
3730 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003731}
thestigb1a59592016-04-14 18:29:56 -07003732
tsepezd19e9122016-11-02 15:43:18 -07003733bool CXFA_Node::TryMeasure(XFA_ATTRIBUTE eAttr,
3734 CXFA_Measurement& mValue,
3735 bool bUseDefault) const {
dsinclair5b36f0a2016-07-19 10:56:23 -07003736 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003737 void* pValue;
3738 int32_t iBytes;
3739 if (GetMapModuleBuffer(pKey, pValue, iBytes) && iBytes == sizeof(mValue)) {
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04003740 memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003741 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003742 }
3743 if (bUseDefault &&
dsinclair070fcdf2016-06-22 22:04:54 -07003744 XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003745 XFA_ATTRIBUTETYPE_Measure, m_ePacket)) {
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04003746 memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003747 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003748 }
tsepezd19e9122016-11-02 15:43:18 -07003749 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003750}
3751
3752CXFA_Measurement CXFA_Node::GetMeasure(XFA_ATTRIBUTE eAttr) const {
3753 CXFA_Measurement mValue;
tsepezd19e9122016-11-02 15:43:18 -07003754 return TryMeasure(eAttr, mValue, true) ? mValue : CXFA_Measurement();
Dan Sinclair1770c022016-03-14 14:14:16 -04003755}
3756
tsepezd19e9122016-11-02 15:43:18 -07003757bool CXFA_Node::SetCData(XFA_ATTRIBUTE eAttr,
3758 const CFX_WideString& wsValue,
3759 bool bNotify,
3760 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003761 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003762 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003763 if (eAttr == XFA_ATTRIBUTE_Value) {
3764 CFX_WideString* pClone = new CFX_WideString(wsValue);
3765 SetUserData(pKey, pClone, &deleteWideStringCallBack);
3766 } else {
tsepez4c3debb2016-04-08 12:20:38 -07003767 SetMapModuleString(pKey, wsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003768 if (eAttr == XFA_ATTRIBUTE_Name)
3769 UpdateNameHash();
3770 }
thestigb1a59592016-04-14 18:29:56 -07003771 OnChanged(eAttr, bNotify, bScriptModify);
3772
3773 if (!IsNeedSavingXMLNode() || eAttr == XFA_ATTRIBUTE_QualifiedName ||
3774 eAttr == XFA_ATTRIBUTE_BindingNode) {
tsepezd19e9122016-11-02 15:43:18 -07003775 return true;
thestigb1a59592016-04-14 18:29:56 -07003776 }
3777
dsinclair070fcdf2016-06-22 22:04:54 -07003778 if (eAttr == XFA_ATTRIBUTE_Name &&
3779 (m_elementType == XFA_Element::DataValue ||
3780 m_elementType == XFA_Element::DataGroup)) {
tsepezd19e9122016-11-02 15:43:18 -07003781 return true;
thestigb1a59592016-04-14 18:29:56 -07003782 }
3783
3784 if (eAttr == XFA_ATTRIBUTE_Value) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003785 FX_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
thestigb1a59592016-04-14 18:29:56 -07003786 switch (eXMLType) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003787 case FX_XMLNODE_Element:
thestigb1a59592016-04-14 18:29:56 -07003788 if (IsAttributeInXML()) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003789 static_cast<CFX_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003790 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3791 wsValue);
thestigb1a59592016-04-14 18:29:56 -07003792 } else {
tsepezd19e9122016-11-02 15:43:18 -07003793 bool bDeleteChildren = true;
thestigb1a59592016-04-14 18:29:56 -07003794 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3795 for (CXFA_Node* pChildDataNode =
3796 GetNodeItem(XFA_NODEITEM_FirstChild);
3797 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3798 XFA_NODEITEM_NextSibling)) {
Tom Sepezf8a94392017-03-14 12:13:22 -07003799 if (!pChildDataNode->GetBindItems().empty()) {
tsepezd19e9122016-11-02 15:43:18 -07003800 bDeleteChildren = false;
thestigb1a59592016-04-14 18:29:56 -07003801 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04003802 }
3803 }
Dan Sinclair1770c022016-03-14 14:14:16 -04003804 }
thestigb1a59592016-04-14 18:29:56 -07003805 if (bDeleteChildren) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003806 static_cast<CFX_XMLElement*>(m_pXMLNode)->DeleteChildren();
thestigb1a59592016-04-14 18:29:56 -07003807 }
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003808 static_cast<CFX_XMLElement*>(m_pXMLNode)->SetTextData(wsValue);
thestigb1a59592016-04-14 18:29:56 -07003809 }
3810 break;
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003811 case FX_XMLNODE_Text:
3812 static_cast<CFX_XMLText*>(m_pXMLNode)->SetText(wsValue);
thestigb1a59592016-04-14 18:29:56 -07003813 break;
3814 default:
dsinclair43854a52016-04-27 12:26:00 -07003815 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003816 }
tsepezd19e9122016-11-02 15:43:18 -07003817 return true;
thestigb1a59592016-04-14 18:29:56 -07003818 }
3819
3820 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
3821 if (pInfo) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003822 ASSERT(m_pXMLNode->GetType() == FX_XMLNODE_Element);
thestigb1a59592016-04-14 18:29:56 -07003823 CFX_WideString wsAttrName = pInfo->pName;
3824 if (pInfo->eName == XFA_ATTRIBUTE_ContentType) {
dan sinclair65c7c232017-02-02 14:05:30 -08003825 wsAttrName = L"xfa:" + wsAttrName;
Dan Sinclair1770c022016-03-14 14:14:16 -04003826 }
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003827 static_cast<CFX_XMLElement*>(m_pXMLNode)->SetString(wsAttrName, wsValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003828 }
tsepezd19e9122016-11-02 15:43:18 -07003829 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003830}
thestigb1a59592016-04-14 18:29:56 -07003831
tsepezd19e9122016-11-02 15:43:18 -07003832bool CXFA_Node::SetAttributeValue(const CFX_WideString& wsValue,
3833 const CFX_WideString& wsXMLValue,
3834 bool bNotify,
3835 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003836 void* pKey = GetMapKey_Element(GetElementType(), XFA_ATTRIBUTE_Value);
thestigb1a59592016-04-14 18:29:56 -07003837 OnChanging(XFA_ATTRIBUTE_Value, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003838 CFX_WideString* pClone = new CFX_WideString(wsValue);
3839 SetUserData(pKey, pClone, &deleteWideStringCallBack);
thestigb1a59592016-04-14 18:29:56 -07003840 OnChanged(XFA_ATTRIBUTE_Value, bNotify, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003841 if (IsNeedSavingXMLNode()) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003842 FX_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
Dan Sinclair1770c022016-03-14 14:14:16 -04003843 switch (eXMLType) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003844 case FX_XMLNODE_Element:
Dan Sinclair1770c022016-03-14 14:14:16 -04003845 if (IsAttributeInXML()) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003846 static_cast<CFX_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003847 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3848 wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003849 } else {
tsepezd19e9122016-11-02 15:43:18 -07003850 bool bDeleteChildren = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003851 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3852 for (CXFA_Node* pChildDataNode =
3853 GetNodeItem(XFA_NODEITEM_FirstChild);
3854 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3855 XFA_NODEITEM_NextSibling)) {
Tom Sepezf8a94392017-03-14 12:13:22 -07003856 if (!pChildDataNode->GetBindItems().empty()) {
tsepezd19e9122016-11-02 15:43:18 -07003857 bDeleteChildren = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003858 break;
3859 }
3860 }
3861 }
3862 if (bDeleteChildren) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003863 static_cast<CFX_XMLElement*>(m_pXMLNode)->DeleteChildren();
Dan Sinclair1770c022016-03-14 14:14:16 -04003864 }
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003865 static_cast<CFX_XMLElement*>(m_pXMLNode)->SetTextData(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003866 }
3867 break;
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003868 case FX_XMLNODE_Text:
3869 static_cast<CFX_XMLText*>(m_pXMLNode)->SetText(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003870 break;
3871 default:
dsinclair43854a52016-04-27 12:26:00 -07003872 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003873 }
3874 }
tsepezd19e9122016-11-02 15:43:18 -07003875 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003876}
dsinclair5b36f0a2016-07-19 10:56:23 -07003877
tsepezd19e9122016-11-02 15:43:18 -07003878bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3879 CFX_WideString& wsValue,
3880 bool bUseDefault,
3881 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003882 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003883 if (eAttr == XFA_ATTRIBUTE_Value) {
3884 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
3885 if (pStr) {
3886 wsValue = *pStr;
tsepezd19e9122016-11-02 15:43:18 -07003887 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003888 }
3889 } else {
3890 CFX_WideStringC wsValueC;
3891 if (GetMapModuleString(pKey, wsValueC)) {
3892 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07003893 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003894 }
3895 }
3896 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07003897 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003898 }
weili44f8faf2016-06-01 14:03:56 -07003899 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07003900 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003901 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
Dan Sinclair812e96c2017-03-13 16:43:37 -04003902 wsValue = (const wchar_t*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003903 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003904 }
tsepezd19e9122016-11-02 15:43:18 -07003905 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003906}
dsinclair5b36f0a2016-07-19 10:56:23 -07003907
tsepezd19e9122016-11-02 15:43:18 -07003908bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3909 CFX_WideStringC& wsValue,
3910 bool bUseDefault,
3911 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003912 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003913 if (eAttr == XFA_ATTRIBUTE_Value) {
3914 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
3915 if (pStr) {
tsepez4d31d0c2016-04-19 14:11:59 -07003916 wsValue = pStr->AsStringC();
tsepezd19e9122016-11-02 15:43:18 -07003917 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003918 }
3919 } else {
3920 if (GetMapModuleString(pKey, wsValue)) {
tsepezd19e9122016-11-02 15:43:18 -07003921 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003922 }
3923 }
3924 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07003925 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003926 }
weili44f8faf2016-06-01 14:03:56 -07003927 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07003928 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003929 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
Dan Sinclair812e96c2017-03-13 16:43:37 -04003930 wsValue = (CFX_WideStringC)(const wchar_t*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003931 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003932 }
tsepezd19e9122016-11-02 15:43:18 -07003933 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003934}
dsinclair5b36f0a2016-07-19 10:56:23 -07003935
tsepezd19e9122016-11-02 15:43:18 -07003936bool CXFA_Node::SetObject(XFA_ATTRIBUTE eAttr,
3937 void* pData,
3938 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003939 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003940 return SetUserData(pKey, pData, pCallbackInfo);
3941}
dsinclair5b36f0a2016-07-19 10:56:23 -07003942
tsepezd19e9122016-11-02 15:43:18 -07003943bool CXFA_Node::TryObject(XFA_ATTRIBUTE eAttr, void*& pData) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003944 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003945 pData = GetUserData(pKey);
dsinclair85d1f2c2016-06-23 12:40:16 -07003946 return !!pData;
Dan Sinclair1770c022016-03-14 14:14:16 -04003947}
dsinclair5b36f0a2016-07-19 10:56:23 -07003948
tsepezd19e9122016-11-02 15:43:18 -07003949bool CXFA_Node::SetValue(XFA_ATTRIBUTE eAttr,
3950 XFA_ATTRIBUTETYPE eType,
3951 void* pValue,
3952 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003953 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003954 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003955 SetMapModuleValue(pKey, pValue);
tsepezd19e9122016-11-02 15:43:18 -07003956 OnChanged(eAttr, bNotify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003957 if (IsNeedSavingXMLNode()) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003958 ASSERT(m_pXMLNode->GetType() == FX_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04003959 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
3960 if (pInfo) {
3961 switch (eType) {
3962 case XFA_ATTRIBUTETYPE_Enum:
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003963 static_cast<CFX_XMLElement*>(m_pXMLNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04003964 ->SetString(
3965 pInfo->pName,
dsinclair9eb0db12016-07-21 12:01:39 -07003966 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)(uintptr_t)pValue)
Dan Sinclair1770c022016-03-14 14:14:16 -04003967 ->pName);
3968 break;
3969 case XFA_ATTRIBUTETYPE_Boolean:
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003970 static_cast<CFX_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003971 ->SetString(pInfo->pName, pValue ? L"1" : L"0");
Dan Sinclair1770c022016-03-14 14:14:16 -04003972 break;
Dan Sinclair5fa4e982017-04-05 11:48:21 -04003973 case XFA_ATTRIBUTETYPE_Integer: {
3974 CFX_WideString wsValue;
3975 wsValue.Format(
3976 L"%d", static_cast<int32_t>(reinterpret_cast<uintptr_t>(pValue)));
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003977 static_cast<CFX_XMLElement*>(m_pXMLNode)
Dan Sinclair5fa4e982017-04-05 11:48:21 -04003978 ->SetString(pInfo->pName, wsValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003979 break;
Dan Sinclair5fa4e982017-04-05 11:48:21 -04003980 }
Dan Sinclair1770c022016-03-14 14:14:16 -04003981 default:
dsinclair43854a52016-04-27 12:26:00 -07003982 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003983 }
3984 }
3985 }
tsepezd19e9122016-11-02 15:43:18 -07003986 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003987}
dsinclair5b36f0a2016-07-19 10:56:23 -07003988
tsepezd19e9122016-11-02 15:43:18 -07003989bool CXFA_Node::GetValue(XFA_ATTRIBUTE eAttr,
3990 XFA_ATTRIBUTETYPE eType,
3991 bool bUseDefault,
3992 void*& pValue) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003993 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003994 if (GetMapModuleValue(pKey, pValue)) {
tsepezd19e9122016-11-02 15:43:18 -07003995 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003996 }
3997 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07003998 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003999 }
dsinclair070fcdf2016-06-22 22:04:54 -07004000 return XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, eType,
Dan Sinclair1770c022016-03-14 14:14:16 -04004001 m_ePacket);
4002}
dsinclair5b36f0a2016-07-19 10:56:23 -07004003
tsepezd19e9122016-11-02 15:43:18 -07004004bool CXFA_Node::SetUserData(void* pKey,
4005 void* pData,
4006 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004007 SetMapModuleBuffer(pKey, &pData, sizeof(void*),
4008 pCallbackInfo ? pCallbackInfo : &gs_XFADefaultFreeData);
tsepezd19e9122016-11-02 15:43:18 -07004009 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004010}
dsinclair5b36f0a2016-07-19 10:56:23 -07004011
tsepezd19e9122016-11-02 15:43:18 -07004012bool CXFA_Node::TryUserData(void* pKey, void*& pData, bool bProtoAlso) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004013 int32_t iBytes = 0;
4014 if (!GetMapModuleBuffer(pKey, pData, iBytes, bProtoAlso)) {
tsepezd19e9122016-11-02 15:43:18 -07004015 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004016 }
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04004017 return iBytes == sizeof(void*) && memcpy(&pData, pData, iBytes);
Dan Sinclair1770c022016-03-14 14:14:16 -04004018}
dsinclair5b36f0a2016-07-19 10:56:23 -07004019
tsepezd19e9122016-11-02 15:43:18 -07004020bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent,
4021 const CFX_WideString& wsXMLValue,
4022 bool bNotify,
4023 bool bScriptModify,
4024 bool bSyncData) {
weili44f8faf2016-06-01 14:03:56 -07004025 CXFA_Node* pNode = nullptr;
4026 CXFA_Node* pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004027 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004028 case XFA_ObjectType::ContainerNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004029 if (XFA_FieldIsMultiListBox(this)) {
dsinclair56a8b192016-06-21 14:15:25 -07004030 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004031 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004032 ASSERT(pChildValue);
tsepezafe94302016-05-13 17:21:31 -07004033 pChildValue->SetCData(XFA_ATTRIBUTE_ContentType, L"text/xml");
Dan Sinclair1770c022016-03-14 14:14:16 -04004034 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004035 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004036 CXFA_Node* pBind = GetBindData();
4037 if (bSyncData && pBind) {
tsepez51709be2016-12-08 10:55:57 -08004038 std::vector<CFX_WideString> wsSaveTextArray;
Tom Sepezf8a94392017-03-14 12:13:22 -07004039 size_t iSize = 0;
Dan Sinclair1770c022016-03-14 14:14:16 -04004040 if (!wsContent.IsEmpty()) {
4041 int32_t iStart = 0;
4042 int32_t iLength = wsContent.GetLength();
4043 int32_t iEnd = wsContent.Find(L'\n', iStart);
4044 iEnd = (iEnd == -1) ? iLength : iEnd;
4045 while (iEnd >= iStart) {
tsepez51709be2016-12-08 10:55:57 -08004046 wsSaveTextArray.push_back(wsContent.Mid(iStart, iEnd - iStart));
Dan Sinclair1770c022016-03-14 14:14:16 -04004047 iStart = iEnd + 1;
4048 if (iStart >= iLength) {
4049 break;
4050 }
4051 iEnd = wsContent.Find(L'\n', iStart);
4052 if (iEnd < 0) {
tsepez51709be2016-12-08 10:55:57 -08004053 wsSaveTextArray.push_back(
4054 wsContent.Mid(iStart, iLength - iStart));
Dan Sinclair1770c022016-03-14 14:14:16 -04004055 }
4056 }
Tom Sepezf8a94392017-03-14 12:13:22 -07004057 iSize = wsSaveTextArray.size();
Dan Sinclair1770c022016-03-14 14:14:16 -04004058 }
4059 if (iSize == 0) {
4060 while (CXFA_Node* pChildNode =
4061 pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) {
4062 pBind->RemoveChild(pChildNode);
4063 }
4064 } else {
Tom Sepezf8a94392017-03-14 12:13:22 -07004065 std::vector<CXFA_Node*> valueNodes = pBind->GetNodeList(
4066 XFA_NODEFILTER_Children, XFA_Element::DataValue);
4067 size_t iDatas = valueNodes.size();
Dan Sinclair1770c022016-03-14 14:14:16 -04004068 if (iDatas < iSize) {
Tom Sepezf8a94392017-03-14 12:13:22 -07004069 size_t iAddNodes = iSize - iDatas;
weili44f8faf2016-06-01 14:03:56 -07004070 CXFA_Node* pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004071 while (iAddNodes-- > 0) {
4072 pValueNodes =
dsinclair56a8b192016-06-21 14:15:25 -07004073 pBind->CreateSamePacketNode(XFA_Element::DataValue);
tsepezafe94302016-05-13 17:21:31 -07004074 pValueNodes->SetCData(XFA_ATTRIBUTE_Name, L"value");
Dan Sinclair1770c022016-03-14 14:14:16 -04004075 pValueNodes->CreateXMLMappingNode();
4076 pBind->InsertChild(pValueNodes);
4077 }
weili44f8faf2016-06-01 14:03:56 -07004078 pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004079 } else if (iDatas > iSize) {
Tom Sepezf8a94392017-03-14 12:13:22 -07004080 size_t iDelNodes = iDatas - iSize;
Dan Sinclair1770c022016-03-14 14:14:16 -04004081 while (iDelNodes-- > 0) {
4082 pBind->RemoveChild(pBind->GetNodeItem(XFA_NODEITEM_FirstChild));
4083 }
4084 }
4085 int32_t i = 0;
4086 for (CXFA_Node* pValueNode =
4087 pBind->GetNodeItem(XFA_NODEITEM_FirstChild);
4088 pValueNode; pValueNode = pValueNode->GetNodeItem(
4089 XFA_NODEITEM_NextSibling)) {
4090 pValueNode->SetAttributeValue(wsSaveTextArray[i],
tsepezd19e9122016-11-02 15:43:18 -07004091 wsSaveTextArray[i], false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004092 i++;
4093 }
4094 }
Tom Sepezf8a94392017-03-14 12:13:22 -07004095 for (CXFA_Node* pArrayNode : pBind->GetBindItems()) {
4096 if (pArrayNode != this) {
4097 pArrayNode->SetScriptContent(wsContent, wsContent, bNotify,
4098 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004099 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004100 }
4101 }
4102 break;
dsinclair070fcdf2016-06-22 22:04:54 -07004103 } else if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004104 pNode = this;
4105 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004106 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004107 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004108 ASSERT(pChildValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04004109 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004110 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004111 }
4112 pBindNode = GetBindData();
4113 if (pBindNode && bSyncData) {
4114 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004115 bScriptModify, false);
Tom Sepezf8a94392017-03-14 12:13:22 -07004116 for (CXFA_Node* pArrayNode : pBindNode->GetBindItems()) {
4117 if (pArrayNode != this) {
4118 pArrayNode->SetScriptContent(wsContent, wsContent, bNotify, true,
4119 false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004120 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004121 }
4122 }
weili44f8faf2016-06-01 14:03:56 -07004123 pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004124 break;
4125 }
dsinclairc5a8f212016-06-20 11:11:12 -07004126 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004127 CFX_WideString wsContentType;
dsinclair070fcdf2016-06-22 22:04:54 -07004128 if (GetElementType() == XFA_Element::ExData) {
tsepezd19e9122016-11-02 15:43:18 -07004129 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
dan sinclair65c7c232017-02-02 14:05:30 -08004130 if (wsContentType == L"text/html") {
4131 wsContentType = L"";
tsepez4c3debb2016-04-08 12:20:38 -07004132 SetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04004133 }
4134 }
4135 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4136 if (!pContentRawDataNode) {
tsepez9f2970c2016-04-01 10:23:04 -07004137 pContentRawDataNode = CreateSamePacketNode(
dan sinclair65c7c232017-02-02 14:05:30 -08004138 (wsContentType == L"text/xml") ? XFA_Element::Sharpxml
4139 : XFA_Element::Sharptext);
Dan Sinclair1770c022016-03-14 14:14:16 -04004140 InsertChild(pContentRawDataNode);
4141 }
4142 return pContentRawDataNode->SetScriptContent(
4143 wsContent, wsXMLValue, bNotify, bScriptModify, bSyncData);
4144 } break;
dsinclairc5a8f212016-06-20 11:11:12 -07004145 case XFA_ObjectType::NodeC:
4146 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004147 pNode = this;
4148 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004149 case XFA_ObjectType::NodeV:
Dan Sinclair1770c022016-03-14 14:14:16 -04004150 pNode = this;
4151 if (bSyncData && GetPacketID() == XFA_XDPPACKET_Form) {
4152 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
4153 if (pParent) {
4154 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4155 }
dsinclair070fcdf2016-06-22 22:04:54 -07004156 if (pParent && pParent->GetElementType() == XFA_Element::Value) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004157 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4158 if (pParent && pParent->IsContainerNode()) {
4159 pBindNode = pParent->GetBindData();
4160 if (pBindNode) {
4161 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004162 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004163 }
4164 }
4165 }
4166 }
4167 break;
4168 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004169 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004170 pNode = this;
4171 pBindNode = this;
4172 }
4173 break;
4174 }
4175 if (pNode) {
4176 SetAttributeValue(wsContent, wsXMLValue, bNotify, bScriptModify);
4177 if (pBindNode && bSyncData) {
Tom Sepezf8a94392017-03-14 12:13:22 -07004178 for (CXFA_Node* pArrayNode : pBindNode->GetBindItems()) {
4179 pArrayNode->SetScriptContent(wsContent, wsContent, bNotify,
4180 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004181 }
4182 }
tsepezd19e9122016-11-02 15:43:18 -07004183 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004184 }
tsepezd19e9122016-11-02 15:43:18 -07004185 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004186}
dsinclair5b36f0a2016-07-19 10:56:23 -07004187
tsepezd19e9122016-11-02 15:43:18 -07004188bool CXFA_Node::SetContent(const CFX_WideString& wsContent,
4189 const CFX_WideString& wsXMLValue,
4190 bool bNotify,
4191 bool bScriptModify,
4192 bool bSyncData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004193 return SetScriptContent(wsContent, wsXMLValue, bNotify, bScriptModify,
4194 bSyncData);
4195}
dsinclair5b36f0a2016-07-19 10:56:23 -07004196
tsepezd19e9122016-11-02 15:43:18 -07004197CFX_WideString CXFA_Node::GetScriptContent(bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004198 CFX_WideString wsContent;
4199 return TryContent(wsContent, bScriptModify) ? wsContent : CFX_WideString();
4200}
dsinclair5b36f0a2016-07-19 10:56:23 -07004201
Dan Sinclair1770c022016-03-14 14:14:16 -04004202CFX_WideString CXFA_Node::GetContent() {
4203 return GetScriptContent();
4204}
dsinclair5b36f0a2016-07-19 10:56:23 -07004205
tsepezd19e9122016-11-02 15:43:18 -07004206bool CXFA_Node::TryContent(CFX_WideString& wsContent,
4207 bool bScriptModify,
4208 bool bProto) {
weili44f8faf2016-06-01 14:03:56 -07004209 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004210 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004211 case XFA_ObjectType::ContainerNode:
dsinclair070fcdf2016-06-22 22:04:54 -07004212 if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004213 pNode = this;
4214 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004215 CXFA_Node* pValue = GetChild(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004216 if (!pValue) {
tsepezd19e9122016-11-02 15:43:18 -07004217 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004218 }
4219 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
4220 if (pChildValue && XFA_FieldIsMultiListBox(this)) {
dan sinclair65c7c232017-02-02 14:05:30 -08004221 pChildValue->SetAttribute(XFA_ATTRIBUTE_ContentType, L"text/xml");
Dan Sinclair1770c022016-03-14 14:14:16 -04004222 }
4223 return pChildValue
4224 ? pChildValue->TryContent(wsContent, bScriptModify, bProto)
tsepezd19e9122016-11-02 15:43:18 -07004225 : false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004226 }
4227 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004228 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004229 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4230 if (!pContentRawDataNode) {
dsinclair56a8b192016-06-21 14:15:25 -07004231 XFA_Element element = XFA_Element::Sharptext;
dsinclair070fcdf2016-06-22 22:04:54 -07004232 if (GetElementType() == XFA_Element::ExData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004233 CFX_WideString wsContentType;
tsepezd19e9122016-11-02 15:43:18 -07004234 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
dan sinclair65c7c232017-02-02 14:05:30 -08004235 if (wsContentType == L"text/html") {
dsinclair56a8b192016-06-21 14:15:25 -07004236 element = XFA_Element::SharpxHTML;
dan sinclair65c7c232017-02-02 14:05:30 -08004237 } else if (wsContentType == L"text/xml") {
dsinclair56a8b192016-06-21 14:15:25 -07004238 element = XFA_Element::Sharpxml;
Dan Sinclair1770c022016-03-14 14:14:16 -04004239 }
4240 }
4241 pContentRawDataNode = CreateSamePacketNode(element);
4242 InsertChild(pContentRawDataNode);
4243 }
4244 return pContentRawDataNode->TryContent(wsContent, bScriptModify, bProto);
4245 }
dsinclairc5a8f212016-06-20 11:11:12 -07004246 case XFA_ObjectType::NodeC:
4247 case XFA_ObjectType::NodeV:
4248 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004249 pNode = this;
4250 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004251 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004252 pNode = this;
4253 }
4254 break;
4255 }
4256 if (pNode) {
4257 if (bScriptModify) {
dsinclairdf4bc592016-03-31 20:34:43 -07004258 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004259 if (pScriptContext) {
4260 m_pDocument->GetScriptContext()->AddNodesOfRunScript(this);
4261 }
4262 }
tsepezd19e9122016-11-02 15:43:18 -07004263 return TryCData(XFA_ATTRIBUTE_Value, wsContent, false, bProto);
Dan Sinclair1770c022016-03-14 14:14:16 -04004264 }
tsepezd19e9122016-11-02 15:43:18 -07004265 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004266}
dsinclair5b36f0a2016-07-19 10:56:23 -07004267
Dan Sinclair1770c022016-03-14 14:14:16 -04004268CXFA_Node* CXFA_Node::GetModelNode() {
4269 switch (GetPacketID()) {
4270 case XFA_XDPPACKET_XDP:
4271 return m_pDocument->GetRoot();
4272 case XFA_XDPPACKET_Config:
4273 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config));
4274 case XFA_XDPPACKET_Template:
4275 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
4276 case XFA_XDPPACKET_Form:
4277 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form));
4278 case XFA_XDPPACKET_Datasets:
4279 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets));
4280 case XFA_XDPPACKET_LocaleSet:
4281 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_LocaleSet));
4282 case XFA_XDPPACKET_ConnectionSet:
4283 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_ConnectionSet));
4284 case XFA_XDPPACKET_SourceSet:
4285 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_SourceSet));
4286 case XFA_XDPPACKET_Xdc:
4287 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Xdc));
4288 default:
4289 return this;
4290 }
4291}
dsinclair5b36f0a2016-07-19 10:56:23 -07004292
tsepezd19e9122016-11-02 15:43:18 -07004293bool CXFA_Node::TryNamespace(CFX_WideString& wsNamespace) {
tsepez774bdde2016-04-14 09:49:44 -07004294 wsNamespace.clear();
dsinclair070fcdf2016-06-22 22:04:54 -07004295 if (IsModelNode() || GetElementType() == XFA_Element::Packet) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004296 CFX_XMLNode* pXMLNode = GetXMLMappingNode();
4297 if (!pXMLNode || pXMLNode->GetType() != FX_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004298 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004299 }
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004300 wsNamespace = static_cast<CFX_XMLElement*>(pXMLNode)->GetNamespaceURI();
tsepezd19e9122016-11-02 15:43:18 -07004301 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004302 } else if (GetPacketID() == XFA_XDPPACKET_Datasets) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004303 CFX_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004304 if (!pXMLNode) {
tsepezd19e9122016-11-02 15:43:18 -07004305 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004306 }
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004307 if (pXMLNode->GetType() != FX_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004308 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004309 }
dsinclair070fcdf2016-06-22 22:04:54 -07004310 if (GetElementType() == XFA_Element::DataValue &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004311 GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData) {
4312 return XFA_FDEExtension_ResolveNamespaceQualifier(
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004313 static_cast<CFX_XMLElement*>(pXMLNode),
Dan Sinclair5fa4e982017-04-05 11:48:21 -04004314 GetCData(XFA_ATTRIBUTE_QualifiedName), &wsNamespace);
Dan Sinclair1770c022016-03-14 14:14:16 -04004315 }
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004316 wsNamespace = static_cast<CFX_XMLElement*>(pXMLNode)->GetNamespaceURI();
tsepezd19e9122016-11-02 15:43:18 -07004317 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004318 } else {
4319 CXFA_Node* pModelNode = GetModelNode();
4320 return pModelNode->TryNamespace(wsNamespace);
4321 }
4322}
dsinclair5b36f0a2016-07-19 10:56:23 -07004323
Dan Sinclair1770c022016-03-14 14:14:16 -04004324CXFA_Node* CXFA_Node::GetProperty(int32_t index,
dsinclair56a8b192016-06-21 14:15:25 -07004325 XFA_Element eProperty,
tsepezd19e9122016-11-02 15:43:18 -07004326 bool bCreateProperty) {
dsinclair41cb62e2016-06-23 09:20:32 -07004327 XFA_Element eType = GetElementType();
tsepez736f28a2016-03-25 14:19:51 -07004328 uint32_t dwPacket = GetPacketID();
Dan Sinclair1770c022016-03-14 14:14:16 -04004329 const XFA_PROPERTY* pProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004330 XFA_GetPropertyOfElement(eType, eProperty, dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004331 if (!pProperty || index >= pProperty->uOccur)
4332 return nullptr;
4333
Dan Sinclair1770c022016-03-14 14:14:16 -04004334 CXFA_Node* pNode = m_pChild;
4335 int32_t iCount = 0;
4336 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004337 if (pNode->GetElementType() == eProperty) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004338 iCount++;
4339 if (iCount > index) {
4340 return pNode;
4341 }
4342 }
4343 }
weili44f8faf2016-06-01 14:03:56 -07004344 if (!bCreateProperty)
4345 return nullptr;
4346
Dan Sinclair1770c022016-03-14 14:14:16 -04004347 if (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf) {
4348 pNode = m_pChild;
4349 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4350 const XFA_PROPERTY* pExistProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004351 XFA_GetPropertyOfElement(eType, pNode->GetElementType(), dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004352 if (pExistProperty && (pExistProperty->uFlags & XFA_PROPERTYFLAG_OneOf))
4353 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004354 }
4355 }
dsinclaira1b07722016-07-11 08:20:58 -07004356
Dan Sinclair1770c022016-03-14 14:14:16 -04004357 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(dwPacket);
weili038aa532016-05-20 15:38:29 -07004358 CXFA_Node* pNewNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004359 for (; iCount <= index; iCount++) {
dsinclaira1b07722016-07-11 08:20:58 -07004360 pNewNode = m_pDocument->CreateNode(pPacket, eProperty);
weili44f8faf2016-06-01 14:03:56 -07004361 if (!pNewNode)
4362 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004363 InsertChild(pNewNode, nullptr);
dsinclairc5a8f212016-06-20 11:11:12 -07004364 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004365 }
4366 return pNewNode;
4367}
dsinclair5b36f0a2016-07-19 10:56:23 -07004368
tsepezd19e9122016-11-02 15:43:18 -07004369int32_t CXFA_Node::CountChildren(XFA_Element eType, bool bOnlyChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004370 CXFA_Node* pNode = m_pChild;
4371 int32_t iCount = 0;
4372 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004373 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004374 if (bOnlyChild) {
4375 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004376 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004377 if (pProperty) {
4378 continue;
4379 }
4380 }
4381 iCount++;
4382 }
4383 }
4384 return iCount;
4385}
dsinclair5b36f0a2016-07-19 10:56:23 -07004386
Dan Sinclair1770c022016-03-14 14:14:16 -04004387CXFA_Node* CXFA_Node::GetChild(int32_t index,
dsinclair41cb62e2016-06-23 09:20:32 -07004388 XFA_Element eType,
tsepezd19e9122016-11-02 15:43:18 -07004389 bool bOnlyChild) {
dsinclair43854a52016-04-27 12:26:00 -07004390 ASSERT(index > -1);
Dan Sinclair1770c022016-03-14 14:14:16 -04004391 CXFA_Node* pNode = m_pChild;
4392 int32_t iCount = 0;
4393 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004394 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004395 if (bOnlyChild) {
4396 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004397 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004398 if (pProperty) {
4399 continue;
4400 }
4401 }
4402 iCount++;
4403 if (iCount > index) {
4404 return pNode;
4405 }
4406 }
4407 }
weili44f8faf2016-06-01 14:03:56 -07004408 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004409}
dsinclair5b36f0a2016-07-19 10:56:23 -07004410
Dan Sinclair1770c022016-03-14 14:14:16 -04004411int32_t CXFA_Node::InsertChild(int32_t index, CXFA_Node* pNode) {
4412 ASSERT(!pNode->m_pNext);
4413 pNode->m_pParent = this;
tsepezd19e9122016-11-02 15:43:18 -07004414 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004415 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004416 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004417
weili44f8faf2016-06-01 14:03:56 -07004418 if (!m_pChild || index == 0) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004419 if (index > 0) {
4420 return -1;
4421 }
4422 pNode->m_pNext = m_pChild;
4423 m_pChild = pNode;
4424 index = 0;
4425 } else if (index < 0) {
4426 m_pLastChild->m_pNext = pNode;
4427 } else {
4428 CXFA_Node* pPrev = m_pChild;
4429 int32_t iCount = 0;
4430 while (++iCount != index && pPrev->m_pNext) {
4431 pPrev = pPrev->m_pNext;
4432 }
4433 if (index > 0 && index != iCount) {
4434 return -1;
4435 }
4436 pNode->m_pNext = pPrev->m_pNext;
4437 pPrev->m_pNext = pNode;
4438 index = iCount;
4439 }
weili44f8faf2016-06-01 14:03:56 -07004440 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004441 m_pLastChild = pNode;
4442 }
4443 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004444 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004445 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004446 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004447 if (pNotify)
4448 pNotify->OnChildAdded(this);
4449
Dan Sinclair1770c022016-03-14 14:14:16 -04004450 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004451 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFX_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004452 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, index);
dsinclairc5a8f212016-06-20 11:11:12 -07004453 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004454 }
4455 return index;
4456}
weili6e1ae862016-05-04 18:25:27 -07004457
tsepezd19e9122016-11-02 15:43:18 -07004458bool CXFA_Node::InsertChild(CXFA_Node* pNode, CXFA_Node* pBeforeNode) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004459 if (!pNode || pNode->m_pParent ||
4460 (pBeforeNode && pBeforeNode->m_pParent != this)) {
dsinclair43854a52016-04-27 12:26:00 -07004461 ASSERT(false);
tsepezd19e9122016-11-02 15:43:18 -07004462 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004463 }
tsepezd19e9122016-11-02 15:43:18 -07004464 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004465 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004466 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004467
4468 int32_t nIndex = -1;
4469 pNode->m_pParent = this;
weili44f8faf2016-06-01 14:03:56 -07004470 if (!m_pChild || pBeforeNode == m_pChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004471 pNode->m_pNext = m_pChild;
4472 m_pChild = pNode;
4473 nIndex = 0;
4474 } else if (!pBeforeNode) {
4475 pNode->m_pNext = m_pLastChild->m_pNext;
4476 m_pLastChild->m_pNext = pNode;
4477 } else {
4478 nIndex = 1;
4479 CXFA_Node* pPrev = m_pChild;
4480 while (pPrev->m_pNext != pBeforeNode) {
4481 pPrev = pPrev->m_pNext;
4482 nIndex++;
4483 }
4484 pNode->m_pNext = pPrev->m_pNext;
4485 pPrev->m_pNext = pNode;
4486 }
weili44f8faf2016-06-01 14:03:56 -07004487 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004488 m_pLastChild = pNode;
4489 }
4490 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004491 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004492 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004493 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004494 if (pNotify)
4495 pNotify->OnChildAdded(this);
4496
Dan Sinclair1770c022016-03-14 14:14:16 -04004497 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004498 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFX_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004499 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, nIndex);
dsinclairc5a8f212016-06-20 11:11:12 -07004500 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004501 }
tsepezd19e9122016-11-02 15:43:18 -07004502 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004503}
dsinclair5b36f0a2016-07-19 10:56:23 -07004504
Dan Sinclair1770c022016-03-14 14:14:16 -04004505CXFA_Node* CXFA_Node::Deprecated_GetPrevSibling() {
4506 if (!m_pParent) {
weili44f8faf2016-06-01 14:03:56 -07004507 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004508 }
4509 for (CXFA_Node* pSibling = m_pParent->m_pChild; pSibling;
4510 pSibling = pSibling->m_pNext) {
4511 if (pSibling->m_pNext == this) {
4512 return pSibling;
4513 }
4514 }
weili44f8faf2016-06-01 14:03:56 -07004515 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004516}
dsinclair5b36f0a2016-07-19 10:56:23 -07004517
tsepezd19e9122016-11-02 15:43:18 -07004518bool CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) {
weili44f8faf2016-06-01 14:03:56 -07004519 if (!pNode || pNode->m_pParent != this) {
tsepezd19e9122016-11-02 15:43:18 -07004520 ASSERT(false);
4521 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004522 }
4523 if (m_pChild == pNode) {
4524 m_pChild = pNode->m_pNext;
4525 if (m_pLastChild == pNode) {
4526 m_pLastChild = pNode->m_pNext;
4527 }
weili44f8faf2016-06-01 14:03:56 -07004528 pNode->m_pNext = nullptr;
4529 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004530 } else {
4531 CXFA_Node* pPrev = pNode->Deprecated_GetPrevSibling();
4532 pPrev->m_pNext = pNode->m_pNext;
4533 if (m_pLastChild == pNode) {
4534 m_pLastChild = pNode->m_pNext ? pNode->m_pNext : pPrev;
4535 }
weili44f8faf2016-06-01 14:03:56 -07004536 pNode->m_pNext = nullptr;
4537 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004538 }
weili44f8faf2016-06-01 14:03:56 -07004539 ASSERT(!m_pLastChild || !m_pLastChild->m_pNext);
thestigb1a59592016-04-14 18:29:56 -07004540 OnRemoved(bNotify);
dsinclairc5a8f212016-06-20 11:11:12 -07004541 pNode->SetFlag(XFA_NodeFlag_HasRemovedChildren, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004542 m_pDocument->AddPurgeNode(pNode);
4543 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
4544 if (pNode->IsAttributeInXML()) {
dsinclair43854a52016-04-27 12:26:00 -07004545 ASSERT(pNode->m_pXMLNode == m_pXMLNode &&
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004546 m_pXMLNode->GetType() == FX_XMLNODE_Element);
4547 if (pNode->m_pXMLNode->GetType() == FX_XMLNODE_Element) {
4548 CFX_XMLElement* pXMLElement =
4549 static_cast<CFX_XMLElement*>(pNode->m_pXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004550 CFX_WideStringC wsAttributeName =
4551 pNode->GetCData(XFA_ATTRIBUTE_QualifiedName);
tsepez660956f2016-04-06 06:27:29 -07004552 pXMLElement->RemoveAttribute(wsAttributeName.c_str());
Dan Sinclair1770c022016-03-14 14:14:16 -04004553 }
4554 CFX_WideString wsName;
tsepezd19e9122016-11-02 15:43:18 -07004555 pNode->GetAttribute(XFA_ATTRIBUTE_Name, wsName, false);
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004556 CFX_XMLElement* pNewXMLElement = new CFX_XMLElement(wsName);
Dan Sinclair1770c022016-03-14 14:14:16 -04004557 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
4558 if (!wsValue.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07004559 pNewXMLElement->SetTextData(CFX_WideString(wsValue));
Dan Sinclair1770c022016-03-14 14:14:16 -04004560 }
4561 pNode->m_pXMLNode = pNewXMLElement;
4562 pNode->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
4563 } else {
4564 m_pXMLNode->RemoveChildNode(pNode->m_pXMLNode);
4565 }
dsinclairc5a8f212016-06-20 11:11:12 -07004566 pNode->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004567 }
tsepezd19e9122016-11-02 15:43:18 -07004568 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004569}
dsinclair5b36f0a2016-07-19 10:56:23 -07004570
Dan Sinclair1770c022016-03-14 14:14:16 -04004571CXFA_Node* CXFA_Node::GetFirstChildByName(const CFX_WideStringC& wsName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004572 return GetFirstChildByName(FX_HashCode_GetW(wsName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004573}
dsinclair5b36f0a2016-07-19 10:56:23 -07004574
tsepez736f28a2016-03-25 14:19:51 -07004575CXFA_Node* CXFA_Node::GetFirstChildByName(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004576 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4577 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4578 if (pNode->GetNameHash() == dwNameHash) {
4579 return pNode;
4580 }
4581 }
weili44f8faf2016-06-01 14:03:56 -07004582 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004583}
dsinclair5b36f0a2016-07-19 10:56:23 -07004584
dsinclair41cb62e2016-06-23 09:20:32 -07004585CXFA_Node* CXFA_Node::GetFirstChildByClass(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004586 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4587 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004588 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004589 return pNode;
4590 }
4591 }
weili44f8faf2016-06-01 14:03:56 -07004592 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004593}
dsinclair5b36f0a2016-07-19 10:56:23 -07004594
tsepez736f28a2016-03-25 14:19:51 -07004595CXFA_Node* CXFA_Node::GetNextSameNameSibling(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004596 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4597 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4598 if (pNode->GetNameHash() == dwNameHash) {
4599 return pNode;
4600 }
4601 }
weili44f8faf2016-06-01 14:03:56 -07004602 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004603}
dsinclair5b36f0a2016-07-19 10:56:23 -07004604
Dan Sinclair1770c022016-03-14 14:14:16 -04004605CXFA_Node* CXFA_Node::GetNextSameNameSibling(
4606 const CFX_WideStringC& wsNodeName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004607 return GetNextSameNameSibling(FX_HashCode_GetW(wsNodeName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004608}
dsinclair5b36f0a2016-07-19 10:56:23 -07004609
dsinclair41cb62e2016-06-23 09:20:32 -07004610CXFA_Node* CXFA_Node::GetNextSameClassSibling(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004611 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4612 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004613 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004614 return pNode;
4615 }
4616 }
weili44f8faf2016-06-01 14:03:56 -07004617 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004618}
dsinclair5b36f0a2016-07-19 10:56:23 -07004619
Dan Sinclair1770c022016-03-14 14:14:16 -04004620int32_t CXFA_Node::GetNodeSameNameIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004621 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004622 if (!pScriptContext) {
4623 return -1;
4624 }
4625 return pScriptContext->GetIndexByName(const_cast<CXFA_Node*>(this));
4626}
dsinclair5b36f0a2016-07-19 10:56:23 -07004627
Dan Sinclair1770c022016-03-14 14:14:16 -04004628int32_t CXFA_Node::GetNodeSameClassIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004629 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004630 if (!pScriptContext) {
4631 return -1;
4632 }
4633 return pScriptContext->GetIndexByClassName(const_cast<CXFA_Node*>(this));
4634}
dsinclair5b36f0a2016-07-19 10:56:23 -07004635
Dan Sinclair1770c022016-03-14 14:14:16 -04004636void CXFA_Node::GetSOMExpression(CFX_WideString& wsSOMExpression) {
dsinclairdf4bc592016-03-31 20:34:43 -07004637 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004638 if (!pScriptContext) {
4639 return;
4640 }
4641 pScriptContext->GetSomExpression(this, wsSOMExpression);
4642}
dsinclair5b36f0a2016-07-19 10:56:23 -07004643
Dan Sinclair1770c022016-03-14 14:14:16 -04004644CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() {
weili44f8faf2016-06-01 14:03:56 -07004645 CXFA_Node* pInstanceMgr = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004646 if (m_ePacket == XFA_XDPPACKET_Form) {
4647 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07004648 if (!pParentNode || pParentNode->GetElementType() == XFA_Element::Area) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004649 return pInstanceMgr;
4650 }
4651 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
4652 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004653 XFA_Element eType = pNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07004654 if ((eType == XFA_Element::Subform || eType == XFA_Element::SubformSet) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004655 pNode->m_dwNameHash != m_dwNameHash) {
4656 break;
4657 }
dsinclair56a8b192016-06-21 14:15:25 -07004658 if (eType == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004659 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
4660 CFX_WideStringC wsInstName = pNode->GetCData(XFA_ATTRIBUTE_Name);
4661 if (wsInstName.GetLength() > 0 && wsInstName.GetAt(0) == '_' &&
4662 wsInstName.Mid(1) == wsName) {
4663 pInstanceMgr = pNode;
4664 }
4665 break;
4666 }
4667 }
4668 }
4669 return pInstanceMgr;
4670}
dsinclair5b36f0a2016-07-19 10:56:23 -07004671
Dan Sinclair1770c022016-03-14 14:14:16 -04004672CXFA_Node* CXFA_Node::GetOccurNode() {
dsinclair56a8b192016-06-21 14:15:25 -07004673 return GetFirstChildByClass(XFA_Element::Occur);
Dan Sinclair1770c022016-03-14 14:14:16 -04004674}
dsinclair5b36f0a2016-07-19 10:56:23 -07004675
dsinclairc5a8f212016-06-20 11:11:12 -07004676bool CXFA_Node::HasFlag(XFA_NodeFlag dwFlag) const {
4677 if (m_uNodeFlags & dwFlag)
4678 return true;
4679 if (dwFlag == XFA_NodeFlag_HasRemovedChildren)
4680 return m_pParent && m_pParent->HasFlag(dwFlag);
4681 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004682}
thestigb1a59592016-04-14 18:29:56 -07004683
4684void CXFA_Node::SetFlag(uint32_t dwFlag, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004685 if (dwFlag == XFA_NodeFlag_Initialized && bNotify && !IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004686 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004687 if (pNotify) {
4688 pNotify->OnNodeReady(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04004689 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004690 }
dsinclairc5a8f212016-06-20 11:11:12 -07004691 m_uNodeFlags |= dwFlag;
Dan Sinclair1770c022016-03-14 14:14:16 -04004692}
thestigb1a59592016-04-14 18:29:56 -07004693
4694void CXFA_Node::ClearFlag(uint32_t dwFlag) {
dsinclairc5a8f212016-06-20 11:11:12 -07004695 m_uNodeFlags &= ~dwFlag;
thestigb1a59592016-04-14 18:29:56 -07004696}
4697
tsepezd19e9122016-11-02 15:43:18 -07004698bool CXFA_Node::IsAttributeInXML() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004699 return GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData;
4700}
thestigb1a59592016-04-14 18:29:56 -07004701
4702void CXFA_Node::OnRemoved(bool bNotify) {
4703 if (!bNotify)
4704 return;
4705
dsinclaira1b07722016-07-11 08:20:58 -07004706 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004707 if (pNotify)
4708 pNotify->OnChildRemoved();
Dan Sinclair1770c022016-03-14 14:14:16 -04004709}
thestigb1a59592016-04-14 18:29:56 -07004710
4711void CXFA_Node::OnChanging(XFA_ATTRIBUTE eAttr, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004712 if (bNotify && IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004713 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004714 if (pNotify) {
thestigb1a59592016-04-14 18:29:56 -07004715 pNotify->OnValueChanging(this, eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004716 }
4717 }
4718}
thestigb1a59592016-04-14 18:29:56 -07004719
Dan Sinclair1770c022016-03-14 14:14:16 -04004720void CXFA_Node::OnChanged(XFA_ATTRIBUTE eAttr,
thestigb1a59592016-04-14 18:29:56 -07004721 bool bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004722 bool bScriptModify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004723 if (bNotify && IsInitialized()) {
thestigb1a59592016-04-14 18:29:56 -07004724 Script_Attribute_SendAttributeChangeMessage(eAttr, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04004725 }
4726}
thestigb1a59592016-04-14 18:29:56 -07004727
Dan Sinclair1770c022016-03-14 14:14:16 -04004728int32_t CXFA_Node::execSingleEventByName(const CFX_WideStringC& wsEventName,
dsinclair41cb62e2016-06-23 09:20:32 -07004729 XFA_Element eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004730 int32_t iRet = XFA_EVENTERROR_NotExist;
4731 const XFA_ExecEventParaInfo* eventParaInfo =
4732 GetEventParaInfoByName(wsEventName);
4733 if (eventParaInfo) {
4734 uint32_t validFlags = eventParaInfo->m_validFlags;
dsinclaira1b07722016-07-11 08:20:58 -07004735 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004736 if (!pNotify) {
4737 return iRet;
4738 }
4739 if (validFlags == 1) {
4740 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType);
4741 } else if (validFlags == 2) {
4742 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004743 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004744 } else if (validFlags == 3) {
dsinclair41cb62e2016-06-23 09:20:32 -07004745 if (eType == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004746 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004747 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004748 }
4749 } else if (validFlags == 4) {
dsinclair41cb62e2016-06-23 09:20:32 -07004750 if (eType == XFA_Element::ExclGroup || eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004751 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair56a8b192016-06-21 14:15:25 -07004752 if (pParentNode &&
dsinclair070fcdf2016-06-22 22:04:54 -07004753 pParentNode->GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004754 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004755 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004756 }
4757 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004758 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004759 }
4760 } else if (validFlags == 5) {
dsinclair41cb62e2016-06-23 09:20:32 -07004761 if (eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004762 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004763 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004764 }
4765 } else if (validFlags == 6) {
4766 CXFA_WidgetData* pWidgetData = GetWidgetData();
4767 if (pWidgetData) {
4768 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004769 if (pUINode->m_elementType == XFA_Element::Signature) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004770 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004771 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004772 }
4773 }
4774 } else if (validFlags == 7) {
4775 CXFA_WidgetData* pWidgetData = GetWidgetData();
4776 if (pWidgetData) {
4777 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004778 if ((pUINode->m_elementType == XFA_Element::ChoiceList) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004779 (!pWidgetData->IsListBox())) {
4780 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004781 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004782 }
4783 }
4784 }
4785 }
4786 return iRet;
4787}
dsinclair5b36f0a2016-07-19 10:56:23 -07004788
Dan Sinclair1770c022016-03-14 14:14:16 -04004789void CXFA_Node::UpdateNameHash() {
4790 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07004791 XFA_GetNotsureAttribute(GetElementType(), XFA_ATTRIBUTE_Name);
tsepezb6853cf2016-04-25 11:23:43 -07004792 CFX_WideStringC wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04004793 if (!pNotsure || pNotsure->eType == XFA_ATTRIBUTETYPE_Cdata) {
tsepezb6853cf2016-04-25 11:23:43 -07004794 wsName = GetCData(XFA_ATTRIBUTE_Name);
4795 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004796 } else if (pNotsure->eType == XFA_ATTRIBUTETYPE_Enum) {
dsinclair9eb0db12016-07-21 12:01:39 -07004797 wsName = GetAttributeEnumByID(GetEnum(XFA_ATTRIBUTE_Name))->pName;
tsepezb6853cf2016-04-25 11:23:43 -07004798 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004799 }
4800}
dsinclair5b36f0a2016-07-19 10:56:23 -07004801
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004802CFX_XMLNode* CXFA_Node::CreateXMLMappingNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004803 if (!m_pXMLNode) {
tsepezafe94302016-05-13 17:21:31 -07004804 CFX_WideString wsTag(GetCData(XFA_ATTRIBUTE_Name));
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004805 m_pXMLNode = new CFX_XMLElement(wsTag);
dsinclairc5a8f212016-06-20 11:11:12 -07004806 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004807 }
4808 return m_pXMLNode;
4809}
dsinclair5b36f0a2016-07-19 10:56:23 -07004810
tsepezd19e9122016-11-02 15:43:18 -07004811bool CXFA_Node::IsNeedSavingXMLNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004812 return m_pXMLNode && (GetPacketID() == XFA_XDPPACKET_Datasets ||
dsinclair070fcdf2016-06-22 22:04:54 -07004813 GetElementType() == XFA_Element::Xfa);
Dan Sinclair1770c022016-03-14 14:14:16 -04004814}
4815
4816XFA_MAPMODULEDATA* CXFA_Node::CreateMapModuleData() {
4817 if (!m_pMapModuleData)
4818 m_pMapModuleData = new XFA_MAPMODULEDATA;
4819 return m_pMapModuleData;
4820}
4821
4822XFA_MAPMODULEDATA* CXFA_Node::GetMapModuleData() const {
4823 return m_pMapModuleData;
4824}
4825
4826void CXFA_Node::SetMapModuleValue(void* pKey, void* pValue) {
4827 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004828 pModule->m_ValueMap[pKey] = pValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04004829}
4830
tsepezd19e9122016-11-02 15:43:18 -07004831bool CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) {
tsepez6bb3b892017-01-05 12:18:41 -08004832 for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004833 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004834 if (pModule) {
4835 auto it = pModule->m_ValueMap.find(pKey);
4836 if (it != pModule->m_ValueMap.end()) {
4837 pValue = it->second;
4838 return true;
4839 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004840 }
tsepez6bb3b892017-01-05 12:18:41 -08004841 if (pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4842 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004843 }
tsepezd19e9122016-11-02 15:43:18 -07004844 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004845}
dsinclair5b36f0a2016-07-19 10:56:23 -07004846
Dan Sinclair1770c022016-03-14 14:14:16 -04004847void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) {
tsepez660956f2016-04-06 06:27:29 -07004848 SetMapModuleBuffer(pKey, (void*)wsValue.c_str(),
Dan Sinclair812e96c2017-03-13 16:43:37 -04004849 wsValue.GetLength() * sizeof(wchar_t));
Dan Sinclair1770c022016-03-14 14:14:16 -04004850}
dsinclair5b36f0a2016-07-19 10:56:23 -07004851
tsepezd19e9122016-11-02 15:43:18 -07004852bool CXFA_Node::GetMapModuleString(void* pKey, CFX_WideStringC& wsValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004853 void* pValue;
4854 int32_t iBytes;
4855 if (!GetMapModuleBuffer(pKey, pValue, iBytes)) {
tsepezd19e9122016-11-02 15:43:18 -07004856 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004857 }
Dan Sinclair812e96c2017-03-13 16:43:37 -04004858 wsValue = CFX_WideStringC((const wchar_t*)pValue, iBytes / sizeof(wchar_t));
tsepezd19e9122016-11-02 15:43:18 -07004859 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004860}
dsinclair5b36f0a2016-07-19 10:56:23 -07004861
Dan Sinclair1770c022016-03-14 14:14:16 -04004862void CXFA_Node::SetMapModuleBuffer(
4863 void* pKey,
4864 void* pValue,
4865 int32_t iBytes,
4866 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
4867 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
4868 XFA_MAPDATABLOCK*& pBuffer = pModule->m_BufferMap[pKey];
weili44f8faf2016-06-01 14:03:56 -07004869 if (!pBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004870 pBuffer =
4871 (XFA_MAPDATABLOCK*)FX_Alloc(uint8_t, sizeof(XFA_MAPDATABLOCK) + iBytes);
4872 } else if (pBuffer->iBytes != iBytes) {
4873 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4874 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4875 }
4876 pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(uint8_t, pBuffer,
4877 sizeof(XFA_MAPDATABLOCK) + iBytes);
4878 } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4879 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4880 }
weili44f8faf2016-06-01 14:03:56 -07004881 if (!pBuffer)
Dan Sinclair1770c022016-03-14 14:14:16 -04004882 return;
weili44f8faf2016-06-01 14:03:56 -07004883
Dan Sinclair1770c022016-03-14 14:14:16 -04004884 pBuffer->pCallbackInfo = pCallbackInfo;
4885 pBuffer->iBytes = iBytes;
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04004886 memcpy(pBuffer->GetData(), pValue, iBytes);
Dan Sinclair1770c022016-03-14 14:14:16 -04004887}
dsinclair5b36f0a2016-07-19 10:56:23 -07004888
tsepezd19e9122016-11-02 15:43:18 -07004889bool CXFA_Node::GetMapModuleBuffer(void* pKey,
4890 void*& pValue,
4891 int32_t& iBytes,
4892 bool bProtoAlso) const {
weili44f8faf2016-06-01 14:03:56 -07004893 XFA_MAPDATABLOCK* pBuffer = nullptr;
tsepez6bb3b892017-01-05 12:18:41 -08004894 for (const CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004895 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004896 if (pModule) {
4897 auto it = pModule->m_BufferMap.find(pKey);
4898 if (it != pModule->m_BufferMap.end()) {
4899 pBuffer = it->second;
4900 break;
4901 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004902 }
tsepez6bb3b892017-01-05 12:18:41 -08004903 if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4904 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004905 }
tsepez6bb3b892017-01-05 12:18:41 -08004906 if (!pBuffer)
tsepezd19e9122016-11-02 15:43:18 -07004907 return false;
tsepez6bb3b892017-01-05 12:18:41 -08004908
Dan Sinclair1770c022016-03-14 14:14:16 -04004909 pValue = pBuffer->GetData();
4910 iBytes = pBuffer->iBytes;
tsepezd19e9122016-11-02 15:43:18 -07004911 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004912}
dsinclair5b36f0a2016-07-19 10:56:23 -07004913
tsepezd19e9122016-11-02 15:43:18 -07004914bool CXFA_Node::HasMapModuleKey(void* pKey, bool bProtoAlso) {
tsepez6bb3b892017-01-05 12:18:41 -08004915 for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004916 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004917 if (pModule) {
4918 auto it1 = pModule->m_ValueMap.find(pKey);
4919 if (it1 != pModule->m_ValueMap.end())
4920 return true;
4921
4922 auto it2 = pModule->m_BufferMap.find(pKey);
4923 if (it2 != pModule->m_BufferMap.end())
4924 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004925 }
tsepez6bb3b892017-01-05 12:18:41 -08004926 if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4927 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004928 }
tsepezd19e9122016-11-02 15:43:18 -07004929 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004930}
dsinclair5b36f0a2016-07-19 10:56:23 -07004931
Dan Sinclair1770c022016-03-14 14:14:16 -04004932void CXFA_Node::RemoveMapModuleKey(void* pKey) {
4933 XFA_MAPMODULEDATA* pModule = GetMapModuleData();
4934 if (!pModule)
4935 return;
4936
4937 if (pKey) {
tsepez6bb3b892017-01-05 12:18:41 -08004938 auto it = pModule->m_BufferMap.find(pKey);
4939 if (it != pModule->m_BufferMap.end()) {
4940 XFA_MAPDATABLOCK* pBuffer = it->second;
Dan Sinclair1770c022016-03-14 14:14:16 -04004941 if (pBuffer) {
tsepez6bb3b892017-01-05 12:18:41 -08004942 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree)
Dan Sinclair1770c022016-03-14 14:14:16 -04004943 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04004944 FX_Free(pBuffer);
4945 }
tsepez6bb3b892017-01-05 12:18:41 -08004946 pModule->m_BufferMap.erase(it);
Dan Sinclair1770c022016-03-14 14:14:16 -04004947 }
tsepez6bb3b892017-01-05 12:18:41 -08004948 pModule->m_ValueMap.erase(pKey);
4949 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04004950 }
tsepez6bb3b892017-01-05 12:18:41 -08004951
4952 for (auto& pair : pModule->m_BufferMap) {
4953 XFA_MAPDATABLOCK* pBuffer = pair.second;
4954 if (pBuffer) {
4955 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree)
4956 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4957 FX_Free(pBuffer);
4958 }
4959 }
4960 pModule->m_BufferMap.clear();
4961 pModule->m_ValueMap.clear();
4962 delete pModule;
Dan Sinclair1770c022016-03-14 14:14:16 -04004963}
dsinclair5b36f0a2016-07-19 10:56:23 -07004964
tsepez6bb3b892017-01-05 12:18:41 -08004965void CXFA_Node::MergeAllData(void* pDstModule) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004966 XFA_MAPMODULEDATA* pDstModuleData =
4967 static_cast<CXFA_Node*>(pDstModule)->CreateMapModuleData();
4968 XFA_MAPMODULEDATA* pSrcModuleData = GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004969 if (!pSrcModuleData)
Dan Sinclair1770c022016-03-14 14:14:16 -04004970 return;
tsepez6bb3b892017-01-05 12:18:41 -08004971
4972 for (const auto& pair : pSrcModuleData->m_ValueMap)
4973 pDstModuleData->m_ValueMap[pair.first] = pair.second;
4974
4975 for (const auto& pair : pSrcModuleData->m_BufferMap) {
4976 XFA_MAPDATABLOCK* pSrcBuffer = pair.second;
4977 XFA_MAPDATABLOCK*& pDstBuffer = pDstModuleData->m_BufferMap[pair.first];
Dan Sinclair1770c022016-03-14 14:14:16 -04004978 if (pSrcBuffer->pCallbackInfo && pSrcBuffer->pCallbackInfo->pFree &&
4979 !pSrcBuffer->pCallbackInfo->pCopy) {
tsepez6bb3b892017-01-05 12:18:41 -08004980 if (pDstBuffer) {
4981 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
4982 pDstModuleData->m_BufferMap.erase(pair.first);
Dan Sinclair1770c022016-03-14 14:14:16 -04004983 }
4984 continue;
4985 }
tsepez6bb3b892017-01-05 12:18:41 -08004986 if (!pDstBuffer) {
4987 pDstBuffer = (XFA_MAPDATABLOCK*)FX_Alloc(
Dan Sinclair1770c022016-03-14 14:14:16 -04004988 uint8_t, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
tsepez6bb3b892017-01-05 12:18:41 -08004989 } else if (pDstBuffer->iBytes != pSrcBuffer->iBytes) {
4990 if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) {
4991 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04004992 }
tsepez6bb3b892017-01-05 12:18:41 -08004993 pDstBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(
4994 uint8_t, pDstBuffer, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
4995 } else if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) {
4996 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04004997 }
tsepez6bb3b892017-01-05 12:18:41 -08004998 if (!pDstBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004999 continue;
5000 }
tsepez6bb3b892017-01-05 12:18:41 -08005001 pDstBuffer->pCallbackInfo = pSrcBuffer->pCallbackInfo;
5002 pDstBuffer->iBytes = pSrcBuffer->iBytes;
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04005003 memcpy(pDstBuffer->GetData(), pSrcBuffer->GetData(), pSrcBuffer->iBytes);
tsepez6bb3b892017-01-05 12:18:41 -08005004 if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pCopy) {
5005 pDstBuffer->pCallbackInfo->pCopy(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005006 }
5007 }
5008}
dsinclair5b36f0a2016-07-19 10:56:23 -07005009
Dan Sinclair1770c022016-03-14 14:14:16 -04005010void CXFA_Node::MoveBufferMapData(CXFA_Node* pDstModule, void* pKey) {
5011 if (!pDstModule) {
5012 return;
5013 }
tsepezd19e9122016-11-02 15:43:18 -07005014 bool bNeedMove = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04005015 if (!pKey) {
tsepezd19e9122016-11-02 15:43:18 -07005016 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005017 }
dsinclair070fcdf2016-06-22 22:04:54 -07005018 if (pDstModule->GetElementType() != GetElementType()) {
tsepezd19e9122016-11-02 15:43:18 -07005019 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005020 }
weili44f8faf2016-06-01 14:03:56 -07005021 XFA_MAPMODULEDATA* pSrcModuleData = nullptr;
5022 XFA_MAPMODULEDATA* pDstModuleData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005023 if (bNeedMove) {
5024 pSrcModuleData = GetMapModuleData();
5025 if (!pSrcModuleData) {
tsepezd19e9122016-11-02 15:43:18 -07005026 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005027 }
5028 pDstModuleData = pDstModule->CreateMapModuleData();
5029 }
5030 if (bNeedMove) {
tsepez6bb3b892017-01-05 12:18:41 -08005031 auto it = pSrcModuleData->m_BufferMap.find(pKey);
5032 if (it != pSrcModuleData->m_BufferMap.end()) {
5033 XFA_MAPDATABLOCK* pBufferBlockData = it->second;
5034 if (pBufferBlockData) {
5035 pSrcModuleData->m_BufferMap.erase(pKey);
5036 pDstModuleData->m_BufferMap[pKey] = pBufferBlockData;
5037 }
Dan Sinclair1770c022016-03-14 14:14:16 -04005038 }
5039 }
dsinclairc5a8f212016-06-20 11:11:12 -07005040 if (pDstModule->IsNodeV()) {
tsepezd19e9122016-11-02 15:43:18 -07005041 CFX_WideString wsValue = pDstModule->GetScriptContent(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04005042 CFX_WideString wsFormatValue(wsValue);
5043 CXFA_WidgetData* pWidgetData = pDstModule->GetContainerWidgetData();
5044 if (pWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07005045 pWidgetData->GetFormatDataValue(wsValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04005046 }
tsepezd19e9122016-11-02 15:43:18 -07005047 pDstModule->SetScriptContent(wsValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005048 }
5049}
dsinclair5b36f0a2016-07-19 10:56:23 -07005050
Dan Sinclair1770c022016-03-14 14:14:16 -04005051void CXFA_Node::MoveBufferMapData(CXFA_Node* pSrcModule,
5052 CXFA_Node* pDstModule,
5053 void* pKey,
tsepezd19e9122016-11-02 15:43:18 -07005054 bool bRecursive) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005055 if (!pSrcModule || !pDstModule || !pKey) {
5056 return;
5057 }
5058 if (bRecursive) {
5059 CXFA_Node* pSrcChild = pSrcModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5060 CXFA_Node* pDstChild = pDstModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5061 for (; pSrcChild && pDstChild;
5062 pSrcChild = pSrcChild->GetNodeItem(XFA_NODEITEM_NextSibling),
5063 pDstChild = pDstChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
tsepezd19e9122016-11-02 15:43:18 -07005064 MoveBufferMapData(pSrcChild, pDstChild, pKey, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005065 }
5066 }
5067 pSrcModule->MoveBufferMapData(pDstModule, pKey);
5068}
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05005069
5070void CXFA_Node::ThrowMissingPropertyException(
5071 const CFX_WideString& obj,
5072 const CFX_WideString& prop) const {
5073 ThrowException(L"'%s' doesn't have property '%s'.", obj.c_str(),
5074 prop.c_str());
5075}
5076
5077void CXFA_Node::ThrowTooManyOccurancesException(
5078 const CFX_WideString& obj) const {
5079 ThrowException(
5080 L"The element [%s] has violated its allowable number of occurrences.",
5081 obj.c_str());
5082}