blob: 9fae4a43aaaa1342f8f8d02eaf6ea8a5c4f94a6c [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 Sepeze47e0c92017-04-26 10:55:54 -070011#include <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 Sinclair283a0432017-04-20 14:11:21 -040016#include "core/fxcrt/cfx_memorystream.h"
Dan Sinclair3b71d262017-04-19 08:58:54 -040017#include "core/fxcrt/fx_codepage.h"
Dan Sinclaircfb19442017-04-20 13:13:04 -040018#include "core/fxcrt/fx_extension.h"
Dan Sinclair0d86ecb2017-04-19 09:19:57 -040019#include "core/fxcrt/xml/cfx_xmlelement.h"
20#include "core/fxcrt/xml/cfx_xmlnode.h"
21#include "core/fxcrt/xml/cfx_xmltext.h"
dsinclair43554682016-09-29 17:29:48 -070022#include "fxjs/cfxjse_value.h"
tsepeza9caab92016-12-14 05:57:10 -080023#include "third_party/base/ptr_util.h"
tsepezaadedf92016-05-12 10:08:06 -070024#include "third_party/base/stl_util.h"
dsinclairdf4bc592016-03-31 20:34:43 -070025#include "xfa/fxfa/app/xfa_ffnotify.h"
dsinclair5b493092016-09-29 20:20:24 -070026#include "xfa/fxfa/cxfa_eventparam.h"
Dan Sinclairefcae5d2017-03-29 14:47:46 -040027#include "xfa/fxfa/cxfa_ffwidget.h"
28#include "xfa/fxfa/parser/cxfa_arraynodelist.h"
29#include "xfa/fxfa/parser/cxfa_attachnodelist.h"
dsinclair16280242016-07-21 12:03:47 -070030#include "xfa/fxfa/parser/cxfa_document.h"
dsinclair0b851ff2016-07-21 12:03:01 -070031#include "xfa/fxfa/parser/cxfa_layoutprocessor.h"
dsinclair9eb0db12016-07-21 12:01:39 -070032#include "xfa/fxfa/parser/cxfa_measurement.h"
dsinclair44d054c2016-04-06 10:23:46 -070033#include "xfa/fxfa/parser/cxfa_occur.h"
dsinclair31f87402016-07-20 06:34:45 -070034#include "xfa/fxfa/parser/cxfa_scriptcontext.h"
dsinclair34f86b02016-07-11 08:42:33 -070035#include "xfa/fxfa/parser/cxfa_simple_parser.h"
Dan Sinclairefcae5d2017-03-29 14:47:46 -040036#include "xfa/fxfa/parser/cxfa_traversestrategy_xfacontainernode.h"
dsinclair5b36f0a2016-07-19 10:56:23 -070037#include "xfa/fxfa/parser/xfa_basic_data.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040038
weili44f8faf2016-06-01 14:03:56 -070039namespace {
40
41void XFA_DeleteWideString(void* pData) {
42 delete static_cast<CFX_WideString*>(pData);
43}
44
45void XFA_CopyWideString(void*& pData) {
46 if (pData) {
47 CFX_WideString* pNewData = new CFX_WideString(*(CFX_WideString*)pData);
48 pData = pNewData;
49 }
50}
51
52XFA_MAPDATABLOCKCALLBACKINFO deleteWideStringCallBack = {XFA_DeleteWideString,
53 XFA_CopyWideString};
54
weili44f8faf2016-06-01 14:03:56 -070055void XFA_DataNodeDeleteBindItem(void* pData) {
Tom Sepezf8a94392017-03-14 12:13:22 -070056 delete static_cast<std::vector<CXFA_Node*>*>(pData);
weili44f8faf2016-06-01 14:03:56 -070057}
58
59XFA_MAPDATABLOCKCALLBACKINFO deleteBindItemCallBack = {
60 XFA_DataNodeDeleteBindItem, nullptr};
61
dsinclair5b36f0a2016-07-19 10:56:23 -070062int32_t GetCount(CXFA_Node* pInstMgrNode) {
63 ASSERT(pInstMgrNode);
64 int32_t iCount = 0;
65 uint32_t dwNameHash = 0;
66 for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
67 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
68 XFA_Element eCurType = pNode->GetElementType();
69 if (eCurType == XFA_Element::InstanceManager)
70 break;
71 if ((eCurType != XFA_Element::Subform) &&
72 (eCurType != XFA_Element::SubformSet)) {
73 continue;
74 }
75 if (iCount == 0) {
76 CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
77 CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
78 if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
79 wsInstName.Mid(1) != wsName) {
80 return iCount;
81 }
82 dwNameHash = pNode->GetNameHash();
83 }
84 if (dwNameHash != pNode->GetNameHash())
85 break;
weili44f8faf2016-06-01 14:03:56 -070086
dsinclair5b36f0a2016-07-19 10:56:23 -070087 iCount++;
88 }
89 return iCount;
Dan Sinclair1770c022016-03-14 14:14:16 -040090}
weili44f8faf2016-06-01 14:03:56 -070091
Tom Sepez7cdc6602017-03-28 09:56:48 -070092std::vector<CXFA_Node*> NodesSortedByDocumentIdx(
Tom Sepeze47e0c92017-04-26 10:55:54 -070093 const std::set<CXFA_Node*>& rgNodeSet) {
Tom Sepez7cdc6602017-03-28 09:56:48 -070094 if (rgNodeSet.empty())
95 return std::vector<CXFA_Node*>();
weili44f8faf2016-06-01 14:03:56 -070096
Tom Sepez7cdc6602017-03-28 09:56:48 -070097 std::vector<CXFA_Node*> rgNodeArray;
dsinclair5b36f0a2016-07-19 10:56:23 -070098 CXFA_Node* pCommonParent =
99 (*rgNodeSet.begin())->GetNodeItem(XFA_NODEITEM_Parent);
100 for (CXFA_Node* pNode = pCommonParent->GetNodeItem(XFA_NODEITEM_FirstChild);
Tom Sepez7cdc6602017-03-28 09:56:48 -0700101 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
102 if (pdfium::ContainsValue(rgNodeSet, pNode))
103 rgNodeArray.push_back(pNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400104 }
Tom Sepez7cdc6602017-03-28 09:56:48 -0700105 return rgNodeArray;
Dan Sinclair1770c022016-03-14 14:14:16 -0400106}
weili44f8faf2016-06-01 14:03:56 -0700107
Tom Sepeze47e0c92017-04-26 10:55:54 -0700108using CXFA_NodeSetPair = std::pair<std::set<CXFA_Node*>, std::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 Sepeze47e0c92017-04-26 10:55:54 -0700131void ReorderDataNodes(const std::set<CXFA_Node*>& sSet1,
132 const std::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 Sepeze47e0c92017-04-26 10:55:54 -0700233 std::set<CXFA_Node*> sNew;
234 std::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 Sepeze47e0c92017-04-26 10:55:54 -0700264 std::set<CXFA_Node*> sNew;
265 std::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 }
Dan Sinclair283a0432017-04-20 14:11:21 -04001409 auto pMemoryStream = pdfium::MakeRetain<CFX_MemoryStream>(true);
Dan Sinclair3b71d262017-04-19 08:58:54 -04001410 auto pStream =
1411 pdfium::MakeRetain<CFX_SeekableStreamProxy>(pMemoryStream, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001412 pStream->SetCodePage(FX_CODEPAGE_UTF8);
Dan Sinclair5ae87922017-04-18 11:54:04 -04001413 pStream->WriteString(bsXMLHeader.AsStringC());
1414
weili65be4b12016-05-25 15:47:43 -07001415 if (GetPacketID() == XFA_XDPPACKET_Form)
tsepez7cda31a2016-12-07 12:10:20 -08001416 XFA_DataExporter_RegenerateFormFile(this, pStream, nullptr, true);
weili65be4b12016-05-25 15:47:43 -07001417 else
tsepez7cda31a2016-12-07 12:10:20 -08001418 pElement->SaveXMLNode(pStream);
weili65be4b12016-05-25 15:47:43 -07001419 // TODO(weili): Check whether we need to save pretty print XML, pdfium:501.
1420 // For now, just put it here to avoid unused variable warning.
1421 (void)bPrettyMode;
dsinclairf27aeec2016-06-07 19:36:18 -07001422 pArguments->GetReturnValue()->SetString(
Dan Sinclair1770c022016-03-14 14:14:16 -04001423 CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001424 return;
1425 }
dsinclairf27aeec2016-06-07 19:36:18 -07001426 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04001427}
1428
1429void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) {
1430 int32_t iLength = pArguments->GetLength();
1431 if (iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001432 ThrowParamCountMismatchException(L"setAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001433 return;
1434 }
tsepez6fe7d212016-04-06 10:51:14 -07001435 CFX_WideString wsAttributeValue =
tsepez4c3debb2016-04-08 12:20:38 -07001436 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
tsepez6fe7d212016-04-06 10:51:14 -07001437 CFX_WideString wsAttribute =
tsepez4c3debb2016-04-08 12:20:38 -07001438 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili44f8faf2016-06-01 14:03:56 -07001439 SetAttribute(wsAttribute.AsStringC(), wsAttributeValue.AsStringC(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001440}
weili60607c32016-05-26 11:53:12 -07001441
Dan Sinclair1770c022016-03-14 14:14:16 -04001442void CXFA_Node::Script_NodeClass_SetElement(CFXJSE_Arguments* pArguments) {
1443 int32_t iLength = pArguments->GetLength();
1444 if (iLength != 1 && iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001445 ThrowParamCountMismatchException(L"setElement");
Dan Sinclair1770c022016-03-14 14:14:16 -04001446 return;
1447 }
weili60607c32016-05-26 11:53:12 -07001448 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001449 CFX_WideString wsName;
weili44f8faf2016-06-01 14:03:56 -07001450 pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
1451 if (iLength == 2)
weili60607c32016-05-26 11:53:12 -07001452 wsName = CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili60607c32016-05-26 11:53:12 -07001453 // TODO(weili): check whether we need to implement this, pdfium:501.
1454 // For now, just put the variables here to avoid unused variable warning.
1455 (void)pNode;
1456 (void)wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04001457}
weili60607c32016-05-26 11:53:12 -07001458
dsinclair12a6b0c2016-05-26 11:14:08 -07001459void CXFA_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001460 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001461 XFA_ATTRIBUTE eAttribute) {
1462 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001463 ThrowInvalidPropertyException();
1464 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001465 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001466
1467 CFX_WideString wsNameSpace;
1468 TryNamespace(wsNameSpace);
Tom Sepezf0b65542017-02-13 10:26:01 -08001469 pValue->SetString(wsNameSpace.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001470}
weili44f8faf2016-06-01 14:03:56 -07001471
dsinclair12a6b0c2016-05-26 11:14:08 -07001472void CXFA_Node::Script_NodeClass_Model(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001473 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001474 XFA_ATTRIBUTE eAttribute) {
1475 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001476 ThrowInvalidPropertyException();
1477 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001478 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001479 pValue->Assign(
1480 m_pDocument->GetScriptContext()->GetJSValueFromMap(GetModelNode()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001481}
weili44f8faf2016-06-01 14:03:56 -07001482
dsinclair12a6b0c2016-05-26 11:14:08 -07001483void CXFA_Node::Script_NodeClass_IsContainer(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001484 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001485 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001486 if (bSetting) {
1487 ThrowInvalidPropertyException();
1488 return;
1489 }
1490 pValue->SetBoolean(IsContainerNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001491}
weili44f8faf2016-06-01 14:03:56 -07001492
dsinclair12a6b0c2016-05-26 11:14:08 -07001493void CXFA_Node::Script_NodeClass_IsNull(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001494 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001495 XFA_ATTRIBUTE eAttribute) {
1496 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001497 ThrowInvalidPropertyException();
1498 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001499 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001500 if (GetElementType() == XFA_Element::Subform) {
1501 pValue->SetBoolean(false);
1502 return;
1503 }
1504 CFX_WideString strValue;
1505 pValue->SetBoolean(!TryContent(strValue) || strValue.IsEmpty());
Dan Sinclair1770c022016-03-14 14:14:16 -04001506}
weili44f8faf2016-06-01 14:03:56 -07001507
dsinclair12a6b0c2016-05-26 11:14:08 -07001508void CXFA_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001509 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001510 XFA_ATTRIBUTE eAttribute) {
1511 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001512 ThrowInvalidPropertyException();
1513 return;
1514 }
Tom Sepezf8a94392017-03-14 12:13:22 -07001515 std::vector<CXFA_Node*> properties =
1516 GetNodeList(XFA_NODEFILTER_OneOfProperty);
1517 if (!properties.empty()) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001518 pValue->Assign(
Tom Sepezf8a94392017-03-14 12:13:22 -07001519 m_pDocument->GetScriptContext()->GetJSValueFromMap(properties.front()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001520 }
1521}
weili44f8faf2016-06-01 14:03:56 -07001522
Dan Sinclair1770c022016-03-14 14:14:16 -04001523void CXFA_Node::Script_ContainerClass_GetDelta(CFXJSE_Arguments* pArguments) {}
dsinclairf27aeec2016-06-07 19:36:18 -07001524
Dan Sinclair1770c022016-03-14 14:14:16 -04001525void CXFA_Node::Script_ContainerClass_GetDeltas(CFXJSE_Arguments* pArguments) {
1526 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
dsinclairf27aeec2016-06-07 19:36:18 -07001527 pArguments->GetReturnValue()->SetObject(
1528 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001529}
1530void CXFA_Node::Script_ModelClass_ClearErrorList(CFXJSE_Arguments* pArguments) {
1531}
dsinclair5b36f0a2016-07-19 10:56:23 -07001532
Dan Sinclair1770c022016-03-14 14:14:16 -04001533void CXFA_Node::Script_ModelClass_CreateNode(CFXJSE_Arguments* pArguments) {
1534 Script_Template_CreateNode(pArguments);
1535}
dsinclair5b36f0a2016-07-19 10:56:23 -07001536
Dan Sinclair1770c022016-03-14 14:14:16 -04001537void CXFA_Node::Script_ModelClass_IsCompatibleNS(CFXJSE_Arguments* pArguments) {
1538 int32_t iLength = pArguments->GetLength();
1539 if (iLength < 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001540 ThrowParamCountMismatchException(L"isCompatibleNS");
Dan Sinclair1770c022016-03-14 14:14:16 -04001541 return;
1542 }
1543 CFX_WideString wsNameSpace;
1544 if (iLength >= 1) {
1545 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07001546 wsNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001547 }
1548 CFX_WideString wsNodeNameSpace;
1549 TryNamespace(wsNodeNameSpace);
dsinclair12a6b0c2016-05-26 11:14:08 -07001550 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07001551 if (pValue)
1552 pValue->SetBoolean(wsNodeNameSpace == wsNameSpace);
Dan Sinclair1770c022016-03-14 14:14:16 -04001553}
dsinclair5b36f0a2016-07-19 10:56:23 -07001554
dsinclair12a6b0c2016-05-26 11:14:08 -07001555void CXFA_Node::Script_ModelClass_Context(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001556 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001557 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001558
dsinclair12a6b0c2016-05-26 11:14:08 -07001559void CXFA_Node::Script_ModelClass_AliasNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001560 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001561 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001562
dsinclair12a6b0c2016-05-26 11:14:08 -07001563void CXFA_Node::Script_Attribute_Integer(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001564 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001565 XFA_ATTRIBUTE eAttribute) {
1566 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001567 SetInteger(eAttribute, pValue->ToInteger(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001568 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001569 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001570 }
1571}
dsinclair5b36f0a2016-07-19 10:56:23 -07001572
dsinclair12a6b0c2016-05-26 11:14:08 -07001573void CXFA_Node::Script_Attribute_IntegerRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001574 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001575 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001576 if (bSetting) {
1577 ThrowInvalidPropertyException();
1578 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001579 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001580 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001581}
dsinclair5b36f0a2016-07-19 10:56:23 -07001582
dsinclair12a6b0c2016-05-26 11:14:08 -07001583void CXFA_Node::Script_Attribute_BOOL(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001584 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001585 XFA_ATTRIBUTE eAttribute) {
1586 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001587 SetBoolean(eAttribute, pValue->ToBoolean(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001588 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001589 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001590 }
1591}
dsinclair5b36f0a2016-07-19 10:56:23 -07001592
dsinclair12a6b0c2016-05-26 11:14:08 -07001593void CXFA_Node::Script_Attribute_BOOLRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001594 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001595 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001596 if (bSetting) {
1597 ThrowInvalidPropertyException();
1598 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001599 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001600 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001601}
thestigb1a59592016-04-14 18:29:56 -07001602
Dan Sinclair1770c022016-03-14 14:14:16 -04001603void CXFA_Node::Script_Attribute_SendAttributeChangeMessage(
thestigb1a59592016-04-14 18:29:56 -07001604 XFA_ATTRIBUTE eAttribute,
tsepezd19e9122016-11-02 15:43:18 -07001605 bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001606 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
thestigb1a59592016-04-14 18:29:56 -07001607 if (!pLayoutPro)
Dan Sinclair1770c022016-03-14 14:14:16 -04001608 return;
thestigb1a59592016-04-14 18:29:56 -07001609
dsinclaira1b07722016-07-11 08:20:58 -07001610 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07001611 if (!pNotify)
1612 return;
1613
1614 uint32_t dwPacket = GetPacketID();
1615 if (!(dwPacket & XFA_XDPPACKET_Form)) {
1616 pNotify->OnValueChanged(this, eAttribute, this, this);
Dan Sinclair1770c022016-03-14 14:14:16 -04001617 return;
1618 }
thestigb1a59592016-04-14 18:29:56 -07001619
1620 bool bNeedFindContainer = false;
dsinclair41cb62e2016-06-23 09:20:32 -07001621 switch (GetElementType()) {
dsinclair56a8b192016-06-21 14:15:25 -07001622 case XFA_Element::Caption:
thestigb1a59592016-04-14 18:29:56 -07001623 bNeedFindContainer = true;
1624 pNotify->OnValueChanged(this, eAttribute, this,
1625 GetNodeItem(XFA_NODEITEM_Parent));
1626 break;
dsinclair56a8b192016-06-21 14:15:25 -07001627 case XFA_Element::Font:
1628 case XFA_Element::Para: {
thestigb1a59592016-04-14 18:29:56 -07001629 bNeedFindContainer = true;
1630 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001631 if (pParentNode->GetElementType() == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001632 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1633 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1634 } else {
1635 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
1636 }
1637 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001638 case XFA_Element::Margin: {
thestigb1a59592016-04-14 18:29:56 -07001639 bNeedFindContainer = true;
1640 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001641 XFA_Element eParentType = pParentNode->GetElementType();
thestigb1a59592016-04-14 18:29:56 -07001642 if (pParentNode->IsContainerNode()) {
1643 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
dsinclair56a8b192016-06-21 14:15:25 -07001644 } else if (eParentType == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001645 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1646 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1647 } else {
1648 CXFA_Node* pNode = pParentNode->GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001649 if (pNode && pNode->GetElementType() == XFA_Element::Ui) {
thestigb1a59592016-04-14 18:29:56 -07001650 pNotify->OnValueChanged(this, eAttribute, pNode,
1651 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001652 }
thestigb1a59592016-04-14 18:29:56 -07001653 }
1654 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001655 case XFA_Element::Comb: {
thestigb1a59592016-04-14 18:29:56 -07001656 CXFA_Node* pEditNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001657 XFA_Element eUIType = pEditNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07001658 if (pEditNode && (eUIType == XFA_Element::DateTimeEdit ||
1659 eUIType == XFA_Element::NumericEdit ||
1660 eUIType == XFA_Element::TextEdit)) {
thestigb1a59592016-04-14 18:29:56 -07001661 CXFA_Node* pUINode = pEditNode->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001662 if (pUINode) {
thestigb1a59592016-04-14 18:29:56 -07001663 pNotify->OnValueChanged(this, eAttribute, pUINode,
1664 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001665 }
thestigb1a59592016-04-14 18:29:56 -07001666 }
1667 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001668 case XFA_Element::Button:
1669 case XFA_Element::Barcode:
1670 case XFA_Element::ChoiceList:
1671 case XFA_Element::DateTimeEdit:
1672 case XFA_Element::NumericEdit:
1673 case XFA_Element::PasswordEdit:
1674 case XFA_Element::TextEdit: {
thestigb1a59592016-04-14 18:29:56 -07001675 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1676 if (pUINode) {
1677 pNotify->OnValueChanged(this, eAttribute, pUINode,
1678 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1679 }
1680 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001681 case XFA_Element::CheckButton: {
thestigb1a59592016-04-14 18:29:56 -07001682 bNeedFindContainer = true;
1683 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1684 if (pUINode) {
1685 pNotify->OnValueChanged(this, eAttribute, pUINode,
1686 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1687 }
1688 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001689 case XFA_Element::Keep:
1690 case XFA_Element::Bookend:
1691 case XFA_Element::Break:
1692 case XFA_Element::BreakAfter:
1693 case XFA_Element::BreakBefore:
1694 case XFA_Element::Overflow:
thestigb1a59592016-04-14 18:29:56 -07001695 bNeedFindContainer = true;
1696 break;
dsinclair56a8b192016-06-21 14:15:25 -07001697 case XFA_Element::Area:
1698 case XFA_Element::Draw:
1699 case XFA_Element::ExclGroup:
1700 case XFA_Element::Field:
1701 case XFA_Element::Subform:
1702 case XFA_Element::SubformSet:
thestigb1a59592016-04-14 18:29:56 -07001703 pLayoutPro->AddChangedContainer(this);
1704 pNotify->OnValueChanged(this, eAttribute, this, this);
1705 break;
dsinclair56a8b192016-06-21 14:15:25 -07001706 case XFA_Element::Sharptext:
1707 case XFA_Element::Sharpxml:
1708 case XFA_Element::SharpxHTML: {
thestigb1a59592016-04-14 18:29:56 -07001709 CXFA_Node* pTextNode = GetNodeItem(XFA_NODEITEM_Parent);
1710 if (!pTextNode) {
1711 return;
1712 }
1713 CXFA_Node* pValueNode = pTextNode->GetNodeItem(XFA_NODEITEM_Parent);
1714 if (!pValueNode) {
1715 return;
1716 }
dsinclair41cb62e2016-06-23 09:20:32 -07001717 XFA_Element eType = pValueNode->GetElementType();
1718 if (eType == XFA_Element::Value) {
thestigb1a59592016-04-14 18:29:56 -07001719 bNeedFindContainer = true;
1720 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1721 if (pNode && pNode->IsContainerNode()) {
1722 if (bScriptModify) {
1723 pValueNode = pNode;
1724 }
1725 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
1726 } else {
1727 pNotify->OnValueChanged(this, eAttribute, pNode,
1728 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001729 }
thestigb1a59592016-04-14 18:29:56 -07001730 } else {
dsinclair41cb62e2016-06-23 09:20:32 -07001731 if (eType == XFA_Element::Items) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001732 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1733 if (pNode && pNode->IsContainerNode()) {
thestigb1a59592016-04-14 18:29:56 -07001734 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04001735 }
1736 }
thestigb1a59592016-04-14 18:29:56 -07001737 }
1738 } break;
1739 default:
1740 break;
1741 }
1742 if (bNeedFindContainer) {
1743 CXFA_Node* pParent = this;
1744 while (pParent) {
1745 if (pParent->IsContainerNode())
Dan Sinclair1770c022016-03-14 14:14:16 -04001746 break;
thestigb1a59592016-04-14 18:29:56 -07001747
1748 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001749 }
thestigb1a59592016-04-14 18:29:56 -07001750 if (pParent) {
1751 pLayoutPro->AddChangedContainer(pParent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001752 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001753 }
1754}
thestigb1a59592016-04-14 18:29:56 -07001755
dsinclair12a6b0c2016-05-26 11:14:08 -07001756void CXFA_Node::Script_Attribute_String(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001757 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001758 XFA_ATTRIBUTE eAttribute) {
1759 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001760 CFX_WideString wsValue = pValue->ToWideString();
thestigb1a59592016-04-14 18:29:56 -07001761 SetAttribute(eAttribute, wsValue.AsStringC(), true);
dsinclair070fcdf2016-06-22 22:04:54 -07001762 if (eAttribute == XFA_ATTRIBUTE_Use &&
1763 GetElementType() == XFA_Element::Desc) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001764 CXFA_Node* pTemplateNode =
1765 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
1766 CXFA_Node* pProtoRoot =
dsinclair56a8b192016-06-21 14:15:25 -07001767 pTemplateNode->GetFirstChildByClass(XFA_Element::Subform)
1768 ->GetFirstChildByClass(XFA_Element::Proto);
dsinclair2f5582f2016-06-09 11:48:23 -07001769
1770 CFX_WideString wsID;
1771 CFX_WideString wsSOM;
1772 if (!wsValue.IsEmpty()) {
1773 if (wsValue[0] == '#') {
1774 wsID = CFX_WideString(wsValue.c_str() + 1, wsValue.GetLength() - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04001775 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07001776 wsSOM = wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04001777 }
1778 }
weili44f8faf2016-06-01 14:03:56 -07001779 CXFA_Node* pProtoNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001780 if (!wsSOM.IsEmpty()) {
tsepez736f28a2016-03-25 14:19:51 -07001781 uint32_t dwFlag = XFA_RESOLVENODE_Children |
Dan Sinclair1770c022016-03-14 14:14:16 -04001782 XFA_RESOLVENODE_Attributes |
1783 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1784 XFA_RESOLVENODE_Siblings;
1785 XFA_RESOLVENODE_RS resoveNodeRS;
1786 int32_t iRet = m_pDocument->GetScriptContext()->ResolveObjects(
tsepez4c3debb2016-04-08 12:20:38 -07001787 pProtoRoot, wsSOM.AsStringC(), resoveNodeRS, dwFlag);
Tom Sepezf8a94392017-03-14 12:13:22 -07001788 if (iRet > 0 && resoveNodeRS.objects.front()->IsNode()) {
1789 pProtoNode = resoveNodeRS.objects.front()->AsNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04001790 }
1791 } else if (!wsID.IsEmpty()) {
tsepez4c3debb2016-04-08 12:20:38 -07001792 pProtoNode = m_pDocument->GetNodeByID(pProtoRoot, wsID.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001793 }
1794 if (pProtoNode) {
1795 CXFA_Node* pHeadChild = GetNodeItem(XFA_NODEITEM_FirstChild);
1796 while (pHeadChild) {
1797 CXFA_Node* pSibling =
1798 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1799 RemoveChild(pHeadChild);
1800 pHeadChild = pSibling;
1801 }
tsepezd19e9122016-11-02 15:43:18 -07001802 CXFA_Node* pProtoForm = pProtoNode->CloneTemplateToForm(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001803 pHeadChild = pProtoForm->GetNodeItem(XFA_NODEITEM_FirstChild);
1804 while (pHeadChild) {
1805 CXFA_Node* pSibling =
1806 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1807 pProtoForm->RemoveChild(pHeadChild);
1808 InsertChild(pHeadChild);
1809 pHeadChild = pSibling;
1810 }
1811 m_pDocument->RemovePurgeNode(pProtoForm);
1812 delete pProtoForm;
1813 }
1814 }
1815 } else {
1816 CFX_WideString wsValue;
1817 GetAttribute(eAttribute, wsValue);
Tom Sepezf0b65542017-02-13 10:26:01 -08001818 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001819 }
1820}
dsinclair5b36f0a2016-07-19 10:56:23 -07001821
dsinclair12a6b0c2016-05-26 11:14:08 -07001822void CXFA_Node::Script_Attribute_StringRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001823 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001824 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001825 if (bSetting) {
1826 ThrowInvalidPropertyException();
1827 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001828 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001829
1830 CFX_WideString wsValue;
1831 GetAttribute(eAttribute, wsValue);
Tom Sepezf0b65542017-02-13 10:26:01 -08001832 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001833}
dsinclair5b36f0a2016-07-19 10:56:23 -07001834
Dan Sinclair1770c022016-03-14 14:14:16 -04001835void CXFA_Node::Script_WsdlConnection_Execute(CFXJSE_Arguments* pArguments) {
1836 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001837 if (argc != 0 && argc != 1) {
1838 ThrowParamCountMismatchException(L"execute");
1839 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001840 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001841 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001842}
dsinclair5b36f0a2016-07-19 10:56:23 -07001843
Dan Sinclair1770c022016-03-14 14:14:16 -04001844void CXFA_Node::Script_Delta_Restore(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001845 if (pArguments->GetLength() != 0)
1846 ThrowParamCountMismatchException(L"restore");
Dan Sinclair1770c022016-03-14 14:14:16 -04001847}
dsinclair5b36f0a2016-07-19 10:56:23 -07001848
dsinclair12a6b0c2016-05-26 11:14:08 -07001849void CXFA_Node::Script_Delta_CurrentValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001850 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001851 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001852
dsinclair12a6b0c2016-05-26 11:14:08 -07001853void CXFA_Node::Script_Delta_SavedValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001854 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001855 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001856
dsinclair12a6b0c2016-05-26 11:14:08 -07001857void CXFA_Node::Script_Delta_Target(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001858 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001859 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001860
dsinclair12a6b0c2016-05-26 11:14:08 -07001861void CXFA_Node::Script_Som_Message(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001862 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001863 XFA_SOM_MESSAGETYPE iMessageType) {
1864 CXFA_WidgetData* pWidgetData = GetWidgetData();
1865 if (!pWidgetData) {
1866 return;
1867 }
tsepezd19e9122016-11-02 15:43:18 -07001868 bool bNew = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001869 CXFA_Validate validate = pWidgetData->GetValidate();
1870 if (!validate) {
tsepezd19e9122016-11-02 15:43:18 -07001871 validate = pWidgetData->GetValidate(true);
1872 bNew = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001873 }
1874 if (bSetting) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001875 switch (iMessageType) {
1876 case XFA_SOM_ValidationMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001877 validate.SetScriptMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001878 break;
1879 case XFA_SOM_FormatMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001880 validate.SetFormatMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001881 break;
1882 case XFA_SOM_MandatoryMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001883 validate.SetNullMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001884 break;
1885 default:
1886 break;
1887 }
1888 if (!bNew) {
dsinclaira1b07722016-07-11 08:20:58 -07001889 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04001890 if (!pNotify) {
1891 return;
1892 }
1893 pNotify->AddCalcValidate(this);
1894 }
1895 } else {
1896 CFX_WideString wsMessage;
1897 switch (iMessageType) {
1898 case XFA_SOM_ValidationMessage:
1899 validate.GetScriptMessageText(wsMessage);
1900 break;
1901 case XFA_SOM_FormatMessage:
1902 validate.GetFormatMessageText(wsMessage);
1903 break;
1904 case XFA_SOM_MandatoryMessage:
1905 validate.GetNullMessageText(wsMessage);
1906 break;
1907 default:
1908 break;
1909 }
Tom Sepezf0b65542017-02-13 10:26:01 -08001910 pValue->SetString(wsMessage.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001911 }
1912}
dsinclair5b36f0a2016-07-19 10:56:23 -07001913
dsinclair12a6b0c2016-05-26 11:14:08 -07001914void CXFA_Node::Script_Som_ValidationMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001915 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001916 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001917 Script_Som_Message(pValue, bSetting, XFA_SOM_ValidationMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04001918}
dsinclair5b36f0a2016-07-19 10:56:23 -07001919
dsinclair12a6b0c2016-05-26 11:14:08 -07001920void CXFA_Node::Script_Field_Length(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001921 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001922 XFA_ATTRIBUTE eAttribute) {
1923 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001924 ThrowInvalidPropertyException();
1925 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001926 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001927
1928 CXFA_WidgetData* pWidgetData = GetWidgetData();
1929 if (!pWidgetData) {
1930 pValue->SetInteger(0);
1931 return;
1932 }
1933 pValue->SetInteger(pWidgetData->CountChoiceListItems(true));
Dan Sinclair1770c022016-03-14 14:14:16 -04001934}
dsinclair5b36f0a2016-07-19 10:56:23 -07001935
dsinclair12a6b0c2016-05-26 11:14:08 -07001936void CXFA_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001937 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001938 XFA_ATTRIBUTE eAttribute) {
dsinclair41cb62e2016-06-23 09:20:32 -07001939 XFA_Element eType = GetElementType();
1940 if (eType == XFA_Element::Field) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001941 Script_Field_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001942 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001943 }
1944 if (eType == XFA_Element::Draw) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001945 Script_Draw_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001946 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001947 }
1948 if (eType == XFA_Element::Boolean) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001949 Script_Boolean_Value(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001950 return;
1951 }
1952 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001953 CFX_WideString wsNewValue;
dsinclair769b1372016-06-08 13:12:41 -07001954 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07001955 wsNewValue = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07001956
Dan Sinclair1770c022016-03-14 14:14:16 -04001957 CFX_WideString wsFormatValue(wsNewValue);
weili44f8faf2016-06-01 14:03:56 -07001958 CXFA_WidgetData* pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001959 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001960 CFX_WideString wsPicture;
Tom Sepezf8a94392017-03-14 12:13:22 -07001961 for (CXFA_Node* pFormNode : GetBindItems()) {
1962 if (!pFormNode || pFormNode->HasRemovedChildren())
Dan Sinclair1770c022016-03-14 14:14:16 -04001963 continue;
Dan Sinclair1770c022016-03-14 14:14:16 -04001964 pContainerWidgetData = pFormNode->GetContainerWidgetData();
1965 if (pContainerWidgetData) {
1966 pContainerWidgetData->GetPictureContent(wsPicture,
1967 XFA_VALUEPICTURE_DataBind);
1968 }
Tom Sepezf8a94392017-03-14 12:13:22 -07001969 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -04001970 break;
weili44f8faf2016-06-01 14:03:56 -07001971 pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001972 }
1973 } else if (GetPacketID() == XFA_XDPPACKET_Form) {
1974 pContainerWidgetData = GetContainerWidgetData();
1975 }
1976 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07001977 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04001978 }
tsepezd19e9122016-11-02 15:43:18 -07001979 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001980 } else {
tsepezd19e9122016-11-02 15:43:18 -07001981 CFX_WideString content = GetScriptContent(true);
dsinclair41cb62e2016-06-23 09:20:32 -07001982 if (content.IsEmpty() && eType != XFA_Element::Text &&
1983 eType != XFA_Element::SubmitUrl) {
dsinclairf27aeec2016-06-07 19:36:18 -07001984 pValue->SetNull();
dsinclair41cb62e2016-06-23 09:20:32 -07001985 } else if (eType == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07001986 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair41cb62e2016-06-23 09:20:32 -07001987 } else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) {
tsepez4c3debb2016-04-08 12:20:38 -07001988 CFX_Decimal decimal(content.AsStringC());
Dan Sinclair05df0752017-03-14 14:43:42 -04001989 pValue->SetFloat((float)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04001990 } else {
Tom Sepezf0b65542017-02-13 10:26:01 -08001991 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001992 }
1993 }
1994}
dsinclair5b36f0a2016-07-19 10:56:23 -07001995
dsinclair12a6b0c2016-05-26 11:14:08 -07001996void CXFA_Node::Script_Som_DefaultValue_Read(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001997 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001998 XFA_ATTRIBUTE eAttribute) {
1999 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002000 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002001 return;
2002 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002003
tsepezd19e9122016-11-02 15:43:18 -07002004 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002005 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002006 pValue->SetNull();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002007 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002008 }
Tom Sepezf0b65542017-02-13 10:26:01 -08002009 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002010}
dsinclair5b36f0a2016-07-19 10:56:23 -07002011
dsinclair12a6b0c2016-05-26 11:14:08 -07002012void CXFA_Node::Script_Boolean_Value(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002013 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002014 XFA_ATTRIBUTE eAttribute) {
2015 if (bSetting) {
2016 CFX_ByteString newValue;
dsinclair769b1372016-06-08 13:12:41 -07002017 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002018 newValue = pValue->ToString();
dsinclairf27aeec2016-06-07 19:36:18 -07002019
tsepezb4c9f3f2016-04-13 15:41:21 -07002020 int32_t iValue = FXSYS_atoi(newValue.c_str());
tsepezafe94302016-05-13 17:21:31 -07002021 CFX_WideString wsNewValue(iValue == 0 ? L"0" : L"1");
Dan Sinclair1770c022016-03-14 14:14:16 -04002022 CFX_WideString wsFormatValue(wsNewValue);
2023 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2024 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002025 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002026 }
tsepezd19e9122016-11-02 15:43:18 -07002027 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002028 } else {
tsepezd19e9122016-11-02 15:43:18 -07002029 CFX_WideString wsValue = GetScriptContent(true);
dan sinclair65c7c232017-02-02 14:05:30 -08002030 pValue->SetBoolean(wsValue == L"1");
Dan Sinclair1770c022016-03-14 14:14:16 -04002031 }
2032}
dsinclair2f5582f2016-06-09 11:48:23 -07002033
dsinclair12a6b0c2016-05-26 11:14:08 -07002034void CXFA_Node::Script_Som_BorderColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002035 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002036 XFA_ATTRIBUTE eAttribute) {
2037 CXFA_WidgetData* pWidgetData = GetWidgetData();
2038 if (!pWidgetData) {
2039 return;
2040 }
tsepezd19e9122016-11-02 15:43:18 -07002041 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002042 int32_t iSize = border.CountEdges();
Dan Sinclair1770c022016-03-14 14:14:16 -04002043 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002044 int32_t r = 0;
2045 int32_t g = 0;
2046 int32_t b = 0;
dsinclair5b36f0a2016-07-19 10:56:23 -07002047 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002048 FX_ARGB rgb = ArgbEncode(100, r, g, b);
2049 for (int32_t i = 0; i < iSize; ++i) {
2050 CXFA_Edge edge = border.GetEdge(i);
2051 edge.SetColor(rgb);
2052 }
2053 } else {
2054 CXFA_Edge edge = border.GetEdge(0);
2055 FX_ARGB color = edge.GetColor();
Nicolas Penaddfc3dc2017-04-20 15:29:25 -04002056 int32_t a;
2057 int32_t r;
2058 int32_t g;
2059 int32_t b;
2060 std::tie(a, r, g, b) = ArgbDecode(color);
dsinclair2f5582f2016-06-09 11:48:23 -07002061 CFX_WideString strColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002062 strColor.Format(L"%d,%d,%d", r, g, b);
Tom Sepezf0b65542017-02-13 10:26:01 -08002063 pValue->SetString(strColor.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002064 }
2065}
dsinclair5b36f0a2016-07-19 10:56:23 -07002066
dsinclair12a6b0c2016-05-26 11:14:08 -07002067void CXFA_Node::Script_Som_BorderWidth(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002068 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002069 XFA_ATTRIBUTE eAttribute) {
2070 CXFA_WidgetData* pWidgetData = GetWidgetData();
2071 if (!pWidgetData) {
2072 return;
2073 }
tsepezd19e9122016-11-02 15:43:18 -07002074 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002075 int32_t iSize = border.CountEdges();
2076 CFX_WideString wsThickness;
2077 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002078 wsThickness = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002079 for (int32_t i = 0; i < iSize; ++i) {
2080 CXFA_Edge edge = border.GetEdge(i);
tsepez4c3debb2016-04-08 12:20:38 -07002081 CXFA_Measurement thickness(wsThickness.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002082 edge.SetMSThickness(thickness);
2083 }
2084 } else {
2085 CXFA_Edge edge = border.GetEdge(0);
2086 CXFA_Measurement thickness = edge.GetMSThickness();
2087 thickness.ToString(wsThickness);
Tom Sepezf0b65542017-02-13 10:26:01 -08002088 pValue->SetString(wsThickness.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002089 }
2090}
dsinclair5b36f0a2016-07-19 10:56:23 -07002091
dsinclair12a6b0c2016-05-26 11:14:08 -07002092void CXFA_Node::Script_Som_FillColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002093 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002094 XFA_ATTRIBUTE eAttribute) {
2095 CXFA_WidgetData* pWidgetData = GetWidgetData();
2096 if (!pWidgetData) {
2097 return;
2098 }
tsepezd19e9122016-11-02 15:43:18 -07002099 CXFA_Border border = pWidgetData->GetBorder(true);
2100 CXFA_Fill borderfill = border.GetFill(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002101 CXFA_Node* pNode = borderfill.GetNode();
2102 if (!pNode) {
2103 return;
2104 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002105 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002106 int32_t r;
2107 int32_t g;
2108 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002109 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002110 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2111 borderfill.SetColor(color);
2112 } else {
2113 FX_ARGB color = borderfill.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002114 int32_t a;
2115 int32_t r;
2116 int32_t g;
2117 int32_t b;
Nicolas Penaddfc3dc2017-04-20 15:29:25 -04002118 std::tie(a, r, g, b) = ArgbDecode(color);
dsinclair2f5582f2016-06-09 11:48:23 -07002119 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002120 wsColor.Format(L"%d,%d,%d", r, g, b);
Tom Sepezf0b65542017-02-13 10:26:01 -08002121 pValue->SetString(wsColor.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002122 }
2123}
dsinclair5b36f0a2016-07-19 10:56:23 -07002124
dsinclair12a6b0c2016-05-26 11:14:08 -07002125void CXFA_Node::Script_Som_DataNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002126 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002127 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002128 if (bSetting) {
2129 ThrowInvalidPropertyException();
2130 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002131 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002132
2133 CXFA_Node* pDataNode = GetBindData();
2134 if (!pDataNode) {
2135 pValue->SetNull();
2136 return;
2137 }
2138
2139 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pDataNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002140}
dsinclair5b36f0a2016-07-19 10:56:23 -07002141
dsinclair12a6b0c2016-05-26 11:14:08 -07002142void CXFA_Node::Script_Draw_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002143 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002144 XFA_ATTRIBUTE eAttribute) {
2145 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002146 if (pValue && pValue->IsString()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002147 CXFA_WidgetData* pWidgetData = GetWidgetData();
dsinclair43854a52016-04-27 12:26:00 -07002148 ASSERT(pWidgetData);
dsinclair56a8b192016-06-21 14:15:25 -07002149 XFA_Element uiType = pWidgetData->GetUIType();
2150 if (uiType == XFA_Element::Text) {
dsinclair2f5582f2016-06-09 11:48:23 -07002151 CFX_WideString wsNewValue = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002152 CFX_WideString wsFormatValue(wsNewValue);
tsepezd19e9122016-11-02 15:43:18 -07002153 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002154 }
2155 }
2156 } else {
tsepezd19e9122016-11-02 15:43:18 -07002157 CFX_WideString content = GetScriptContent(true);
Tom Sepezf0b65542017-02-13 10:26:01 -08002158 if (content.IsEmpty())
dsinclairf27aeec2016-06-07 19:36:18 -07002159 pValue->SetNull();
Tom Sepezf0b65542017-02-13 10:26:01 -08002160 else
2161 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002162 }
2163}
dsinclair5b36f0a2016-07-19 10:56:23 -07002164
dsinclair12a6b0c2016-05-26 11:14:08 -07002165void CXFA_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002166 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002167 XFA_ATTRIBUTE eAttribute) {
2168 CXFA_WidgetData* pWidgetData = GetWidgetData();
2169 if (!pWidgetData) {
2170 return;
2171 }
2172 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002173 if (pValue && pValue->IsNull()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002174 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002175 pWidgetData->m_bIsNull = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04002176 } else {
2177 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002178 pWidgetData->m_bIsNull = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04002179 }
dsinclair2f5582f2016-06-09 11:48:23 -07002180 CFX_WideString wsNewText;
dsinclair769b1372016-06-08 13:12:41 -07002181 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002182 wsNewText = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07002183
Dan Sinclair1770c022016-03-14 14:14:16 -04002184 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07002185 if (pUIChild->GetElementType() == XFA_Element::NumericEdit) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002186 int32_t iLeadDigits = 0;
2187 int32_t iFracDigits = 0;
2188 pWidgetData->GetLeadDigits(iLeadDigits);
2189 pWidgetData->GetFracDigits(iFracDigits);
dsinclair44d054c2016-04-06 10:23:46 -07002190 wsNewText =
2191 pWidgetData->NumericLimit(wsNewText, iLeadDigits, iFracDigits);
Dan Sinclair1770c022016-03-14 14:14:16 -04002192 }
2193 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2194 CFX_WideString wsFormatText(wsNewText);
2195 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002196 pContainerWidgetData->GetFormatDataValue(wsNewText, wsFormatText);
Dan Sinclair1770c022016-03-14 14:14:16 -04002197 }
tsepezd19e9122016-11-02 15:43:18 -07002198 SetScriptContent(wsNewText, wsFormatText, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002199 } else {
tsepezd19e9122016-11-02 15:43:18 -07002200 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002201 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002202 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002203 } else {
2204 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
Dan Sinclair1770c022016-03-14 14:14:16 -04002205 CXFA_Value defVal = pWidgetData->GetFormValue();
2206 CXFA_Node* pNode = defVal.GetNode()->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair070fcdf2016-06-22 22:04:54 -07002207 if (pNode && pNode->GetElementType() == XFA_Element::Decimal) {
dsinclair41cb62e2016-06-23 09:20:32 -07002208 if (pUIChild->GetElementType() == XFA_Element::NumericEdit &&
Dan Sinclair1770c022016-03-14 14:14:16 -04002209 (pNode->GetInteger(XFA_ATTRIBUTE_FracDigits) == -1)) {
Tom Sepezf0b65542017-02-13 10:26:01 -08002210 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002211 } else {
tsepez4c3debb2016-04-08 12:20:38 -07002212 CFX_Decimal decimal(content.AsStringC());
Dan Sinclair05df0752017-03-14 14:43:42 -04002213 pValue->SetFloat((float)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002214 }
dsinclair070fcdf2016-06-22 22:04:54 -07002215 } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07002216 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair070fcdf2016-06-22 22:04:54 -07002217 } else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) {
tsepezd19e9122016-11-02 15:43:18 -07002218 pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? false : true);
dsinclair070fcdf2016-06-22 22:04:54 -07002219 } else if (pNode && pNode->GetElementType() == XFA_Element::Float) {
tsepez4c3debb2016-04-08 12:20:38 -07002220 CFX_Decimal decimal(content.AsStringC());
Dan Sinclair05df0752017-03-14 14:43:42 -04002221 pValue->SetFloat((float)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002222 } else {
Tom Sepezf0b65542017-02-13 10:26:01 -08002223 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002224 }
2225 }
2226 }
2227}
dsinclair5b36f0a2016-07-19 10:56:23 -07002228
dsinclair12a6b0c2016-05-26 11:14:08 -07002229void CXFA_Node::Script_Field_EditValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002230 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002231 XFA_ATTRIBUTE eAttribute) {
2232 CXFA_WidgetData* pWidgetData = GetWidgetData();
2233 if (!pWidgetData) {
2234 return;
2235 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002236 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002237 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Edit);
Dan Sinclair1770c022016-03-14 14:14:16 -04002238 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002239 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002240 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Edit);
Tom Sepezf0b65542017-02-13 10:26:01 -08002241 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002242 }
2243}
dsinclair5b36f0a2016-07-19 10:56:23 -07002244
dsinclair12a6b0c2016-05-26 11:14:08 -07002245void CXFA_Node::Script_Som_FontColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002246 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002247 XFA_ATTRIBUTE eAttribute) {
2248 CXFA_WidgetData* pWidgetData = GetWidgetData();
2249 if (!pWidgetData) {
2250 return;
2251 }
tsepezd19e9122016-11-02 15:43:18 -07002252 CXFA_Font font = pWidgetData->GetFont(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002253 CXFA_Node* pNode = font.GetNode();
2254 if (!pNode) {
2255 return;
2256 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002257 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002258 int32_t r;
2259 int32_t g;
2260 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002261 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002262 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2263 font.SetColor(color);
2264 } else {
2265 FX_ARGB color = font.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002266 int32_t a;
2267 int32_t r;
2268 int32_t g;
2269 int32_t b;
Nicolas Penaddfc3dc2017-04-20 15:29:25 -04002270 std::tie(a, r, g, b) = ArgbDecode(color);
dsinclair2f5582f2016-06-09 11:48:23 -07002271 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002272 wsColor.Format(L"%d,%d,%d", r, g, b);
Tom Sepezf0b65542017-02-13 10:26:01 -08002273 pValue->SetString(wsColor.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002274 }
2275}
dsinclair5b36f0a2016-07-19 10:56:23 -07002276
dsinclair12a6b0c2016-05-26 11:14:08 -07002277void CXFA_Node::Script_Field_FormatMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002278 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002279 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002280 Script_Som_Message(pValue, bSetting, XFA_SOM_FormatMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002281}
dsinclair5b36f0a2016-07-19 10:56:23 -07002282
dsinclair12a6b0c2016-05-26 11:14:08 -07002283void CXFA_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002284 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002285 XFA_ATTRIBUTE eAttribute) {
2286 CXFA_WidgetData* pWidgetData = GetWidgetData();
2287 if (!pWidgetData) {
2288 return;
2289 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002290 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002291 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Display);
Dan Sinclair1770c022016-03-14 14:14:16 -04002292 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002293 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002294 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Display);
Tom Sepezf0b65542017-02-13 10:26:01 -08002295 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002296 }
2297}
dsinclair5b36f0a2016-07-19 10:56:23 -07002298
dsinclair12a6b0c2016-05-26 11:14:08 -07002299void CXFA_Node::Script_Som_Mandatory(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002300 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002301 XFA_ATTRIBUTE eAttribute) {
2302 CXFA_WidgetData* pWidgetData = GetWidgetData();
2303 if (!pWidgetData) {
2304 return;
2305 }
tsepezd19e9122016-11-02 15:43:18 -07002306 CXFA_Validate validate = pWidgetData->GetValidate(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002307 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002308 validate.SetNullTest(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04002309 } else {
2310 int32_t iValue = validate.GetNullTest();
2311 const XFA_ATTRIBUTEENUMINFO* pInfo =
dsinclair9eb0db12016-07-21 12:01:39 -07002312 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)iValue);
dsinclair2f5582f2016-06-09 11:48:23 -07002313 CFX_WideString wsValue;
2314 if (pInfo)
Dan Sinclair1770c022016-03-14 14:14:16 -04002315 wsValue = pInfo->pName;
Tom Sepezf0b65542017-02-13 10:26:01 -08002316 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002317 }
2318}
dsinclair5b36f0a2016-07-19 10:56:23 -07002319
dsinclair12a6b0c2016-05-26 11:14:08 -07002320void CXFA_Node::Script_Som_MandatoryMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002321 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002322 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002323 Script_Som_Message(pValue, bSetting, XFA_SOM_MandatoryMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002324}
dsinclair5b36f0a2016-07-19 10:56:23 -07002325
dsinclair12a6b0c2016-05-26 11:14:08 -07002326void CXFA_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002327 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002328 XFA_ATTRIBUTE eAttribute) {
2329 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002330 ThrowInvalidPropertyException();
2331 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002332 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002333 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002334}
dsinclair5b36f0a2016-07-19 10:56:23 -07002335
dsinclair12a6b0c2016-05-26 11:14:08 -07002336void CXFA_Node::Script_Field_SelectedIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002337 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002338 XFA_ATTRIBUTE eAttribute) {
2339 CXFA_WidgetData* pWidgetData = GetWidgetData();
2340 if (!pWidgetData) {
2341 return;
2342 }
2343 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002344 int32_t iIndex = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002345 if (iIndex == -1) {
2346 pWidgetData->ClearAllSelections();
2347 return;
2348 }
tsepezd19e9122016-11-02 15:43:18 -07002349 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002350 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002351 pValue->SetInteger(pWidgetData->GetSelectedItem());
Dan Sinclair1770c022016-03-14 14:14:16 -04002352 }
2353}
dsinclair5b36f0a2016-07-19 10:56:23 -07002354
Dan Sinclair1770c022016-03-14 14:14:16 -04002355void CXFA_Node::Script_Field_ClearItems(CFXJSE_Arguments* pArguments) {
2356 CXFA_WidgetData* pWidgetData = GetWidgetData();
2357 if (!pWidgetData) {
2358 return;
2359 }
tsepezd19e9122016-11-02 15:43:18 -07002360 pWidgetData->DeleteItem(-1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002361}
dsinclair5b36f0a2016-07-19 10:56:23 -07002362
Dan Sinclair1770c022016-03-14 14:14:16 -04002363void CXFA_Node::Script_Field_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002364 if (pArguments->GetLength() != 1) {
2365 ThrowParamCountMismatchException(L"execEvent");
2366 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002367 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002368
2369 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2370 int32_t iRet = execSingleEventByName(
2371 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2372 XFA_Element::Field);
2373 if (eventString != "validate")
2374 return;
2375
2376 pArguments->GetReturnValue()->SetBoolean(
2377 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002378}
dsinclair5b36f0a2016-07-19 10:56:23 -07002379
Dan Sinclair1770c022016-03-14 14:14:16 -04002380void CXFA_Node::Script_Field_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002381 if (pArguments->GetLength() != 0) {
2382 ThrowParamCountMismatchException(L"execInitialize");
2383 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002384 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002385
2386 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2387 if (!pNotify)
2388 return;
2389
2390 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002391}
dsinclair5b36f0a2016-07-19 10:56:23 -07002392
Dan Sinclair1770c022016-03-14 14:14:16 -04002393void CXFA_Node::Script_Field_DeleteItem(CFXJSE_Arguments* pArguments) {
2394 int32_t iLength = pArguments->GetLength();
2395 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002396 ThrowParamCountMismatchException(L"deleteItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002397 return;
2398 }
2399 CXFA_WidgetData* pWidgetData = GetWidgetData();
2400 if (!pWidgetData) {
2401 return;
2402 }
2403 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002404 bool bValue = pWidgetData->DeleteItem(iIndex, true, true);
dsinclair12a6b0c2016-05-26 11:14:08 -07002405 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002406 if (pValue)
2407 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002408}
dsinclair5b36f0a2016-07-19 10:56:23 -07002409
Dan Sinclair1770c022016-03-14 14:14:16 -04002410void CXFA_Node::Script_Field_GetSaveItem(CFXJSE_Arguments* pArguments) {
2411 int32_t iLength = pArguments->GetLength();
2412 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002413 ThrowParamCountMismatchException(L"getSaveItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002414 return;
2415 }
2416 int32_t iIndex = pArguments->GetInt32(0);
2417 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002418 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002419 return;
2420 }
2421 CXFA_WidgetData* pWidgetData = GetWidgetData();
2422 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002423 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002424 return;
2425 }
2426 CFX_WideString wsValue;
Tom Sepezf0b65542017-02-13 10:26:01 -08002427 if (!pWidgetData->GetChoiceListItem(wsValue, iIndex, true)) {
dsinclairf27aeec2016-06-07 19:36:18 -07002428 pArguments->GetReturnValue()->SetNull();
Tom Sepezf0b65542017-02-13 10:26:01 -08002429 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002430 }
Tom Sepezf0b65542017-02-13 10:26:01 -08002431 pArguments->GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002432}
dsinclair5b36f0a2016-07-19 10:56:23 -07002433
Dan Sinclair1770c022016-03-14 14:14:16 -04002434void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments) {
2435 int32_t iLength = pArguments->GetLength();
2436 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002437 ThrowParamCountMismatchException(L"boundItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002438 return;
2439 }
2440 CXFA_WidgetData* pWidgetData = GetWidgetData();
2441 if (!pWidgetData) {
2442 return;
2443 }
2444 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002445 CFX_WideString wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002446 CFX_WideString wsBoundValue;
tsepez4c3debb2016-04-08 12:20:38 -07002447 pWidgetData->GetItemValue(wsValue.AsStringC(), wsBoundValue);
dsinclair12a6b0c2016-05-26 11:14:08 -07002448 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002449 if (pValue)
Tom Sepezf0b65542017-02-13 10:26:01 -08002450 pValue->SetString(wsBoundValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002451}
dsinclair5b36f0a2016-07-19 10:56:23 -07002452
Dan Sinclair1770c022016-03-14 14:14:16 -04002453void CXFA_Node::Script_Field_GetItemState(CFXJSE_Arguments* pArguments) {
2454 int32_t iLength = pArguments->GetLength();
2455 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002456 ThrowParamCountMismatchException(L"getItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002457 return;
2458 }
2459 CXFA_WidgetData* pWidgetData = GetWidgetData();
2460 if (!pWidgetData) {
2461 return;
2462 }
2463 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002464 bool bValue = pWidgetData->GetItemState(iIndex);
dsinclair12a6b0c2016-05-26 11:14:08 -07002465 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002466 if (pValue)
2467 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002468}
dsinclair5b36f0a2016-07-19 10:56:23 -07002469
Dan Sinclair1770c022016-03-14 14:14:16 -04002470void CXFA_Node::Script_Field_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002471 if (pArguments->GetLength() != 0) {
2472 ThrowParamCountMismatchException(L"execCalculate");
2473 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002474 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002475
2476 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2477 if (!pNotify)
2478 return;
2479
2480 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002481}
dsinclair5b36f0a2016-07-19 10:56:23 -07002482
Dan Sinclair1770c022016-03-14 14:14:16 -04002483void CXFA_Node::Script_Field_SetItems(CFXJSE_Arguments* pArguments) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002484
Dan Sinclair1770c022016-03-14 14:14:16 -04002485void CXFA_Node::Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments) {
2486 int32_t iLength = pArguments->GetLength();
2487 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002488 ThrowParamCountMismatchException(L"getDisplayItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002489 return;
2490 }
2491 int32_t iIndex = pArguments->GetInt32(0);
2492 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002493 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002494 return;
2495 }
2496 CXFA_WidgetData* pWidgetData = GetWidgetData();
2497 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002498 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002499 return;
2500 }
2501 CFX_WideString wsValue;
Tom Sepezf0b65542017-02-13 10:26:01 -08002502 if (!pWidgetData->GetChoiceListItem(wsValue, iIndex, false)) {
dsinclairf27aeec2016-06-07 19:36:18 -07002503 pArguments->GetReturnValue()->SetNull();
Tom Sepezf0b65542017-02-13 10:26:01 -08002504 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002505 }
Tom Sepezf0b65542017-02-13 10:26:01 -08002506 pArguments->GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002507}
dsinclair5b36f0a2016-07-19 10:56:23 -07002508
Dan Sinclair1770c022016-03-14 14:14:16 -04002509void CXFA_Node::Script_Field_SetItemState(CFXJSE_Arguments* pArguments) {
2510 int32_t iLength = pArguments->GetLength();
2511 if (iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002512 ThrowParamCountMismatchException(L"setItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002513 return;
2514 }
2515 CXFA_WidgetData* pWidgetData = GetWidgetData();
thestig800222e2016-05-26 22:00:29 -07002516 if (!pWidgetData)
Dan Sinclair1770c022016-03-14 14:14:16 -04002517 return;
thestig800222e2016-05-26 22:00:29 -07002518
Dan Sinclair1770c022016-03-14 14:14:16 -04002519 int32_t iIndex = pArguments->GetInt32(0);
2520 if (pArguments->GetInt32(1) != 0) {
tsepezd19e9122016-11-02 15:43:18 -07002521 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002522 } else {
thestig800222e2016-05-26 22:00:29 -07002523 if (pWidgetData->GetItemState(iIndex))
tsepezd19e9122016-11-02 15:43:18 -07002524 pWidgetData->SetItemState(iIndex, false, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002525 }
2526}
dsinclair5b36f0a2016-07-19 10:56:23 -07002527
Dan Sinclair1770c022016-03-14 14:14:16 -04002528void CXFA_Node::Script_Field_AddItem(CFXJSE_Arguments* pArguments) {
2529 int32_t iLength = pArguments->GetLength();
2530 if (iLength < 1 || iLength > 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002531 ThrowParamCountMismatchException(L"addItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002532 return;
2533 }
2534 CXFA_WidgetData* pWidgetData = GetWidgetData();
2535 if (!pWidgetData) {
2536 return;
2537 }
2538 CFX_WideString wsLabel;
2539 CFX_WideString wsValue;
2540 if (iLength >= 1) {
tsepez6fe7d212016-04-06 10:51:14 -07002541 CFX_ByteString bsLabel = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002542 wsLabel = CFX_WideString::FromUTF8(bsLabel.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002543 }
2544 if (iLength >= 2) {
2545 CFX_ByteString bsValue = pArguments->GetUTF8String(1);
tsepez4c3debb2016-04-08 12:20:38 -07002546 wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002547 }
tsepezd19e9122016-11-02 15:43:18 -07002548 pWidgetData->InsertItem(wsLabel, wsValue, -1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002549}
dsinclair5b36f0a2016-07-19 10:56:23 -07002550
Dan Sinclair1770c022016-03-14 14:14:16 -04002551void CXFA_Node::Script_Field_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002552 if (pArguments->GetLength() != 0) {
2553 ThrowParamCountMismatchException(L"execValidate");
2554 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002555 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002556
2557 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2558 if (!pNotify) {
2559 pArguments->GetReturnValue()->SetBoolean(false);
2560 return;
2561 }
2562
2563 int32_t iRet =
2564 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate, false, false);
2565 pArguments->GetReturnValue()->SetBoolean(
2566 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002567}
dsinclair5b36f0a2016-07-19 10:56:23 -07002568
dsinclair12a6b0c2016-05-26 11:14:08 -07002569void CXFA_Node::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002570 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002571 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002572 if (bSetting)
2573 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002574}
dsinclair5b36f0a2016-07-19 10:56:23 -07002575
dsinclair12a6b0c2016-05-26 11:14:08 -07002576void CXFA_Node::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002577 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002578 XFA_ATTRIBUTE eAttribute) {
2579 CXFA_WidgetData* pWidgetData = GetWidgetData();
2580 if (!pWidgetData) {
2581 return;
2582 }
2583 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002584 pWidgetData->SetSelectedMemberByValue(pValue->ToWideString().AsStringC(),
tsepezd19e9122016-11-02 15:43:18 -07002585 true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002586 } else {
tsepezd19e9122016-11-02 15:43:18 -07002587 CFX_WideString wsValue = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002588 XFA_VERSION curVersion = GetDocument()->GetCurVersionMode();
2589 if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) {
dsinclairf27aeec2016-06-07 19:36:18 -07002590 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002591 } else {
Tom Sepezf0b65542017-02-13 10:26:01 -08002592 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002593 }
2594 }
2595}
dsinclair5b36f0a2016-07-19 10:56:23 -07002596
dsinclair12a6b0c2016-05-26 11:14:08 -07002597void CXFA_Node::Script_ExclGroup_Transient(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002598 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002599 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002600
Dan Sinclair1770c022016-03-14 14:14:16 -04002601void CXFA_Node::Script_ExclGroup_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002602 if (pArguments->GetLength() != 1) {
2603 ThrowParamCountMismatchException(L"execEvent");
2604 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002605 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002606
2607 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2608 execSingleEventByName(
2609 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2610 XFA_Element::ExclGroup);
Dan Sinclair1770c022016-03-14 14:14:16 -04002611}
thestig800222e2016-05-26 22:00:29 -07002612
Dan Sinclair1770c022016-03-14 14:14:16 -04002613void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments) {
2614 int32_t argc = pArguments->GetLength();
thestig800222e2016-05-26 22:00:29 -07002615 if (argc < 0 || argc > 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002616 ThrowParamCountMismatchException(L"selectedMember");
thestig800222e2016-05-26 22:00:29 -07002617 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002618 }
thestig800222e2016-05-26 22:00:29 -07002619
2620 CXFA_WidgetData* pWidgetData = GetWidgetData();
2621 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002622 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002623 return;
2624 }
2625
2626 CXFA_Node* pReturnNode = nullptr;
2627 if (argc == 0) {
2628 pReturnNode = pWidgetData->GetSelectedMember();
2629 } else {
2630 CFX_ByteString szName;
2631 szName = pArguments->GetUTF8String(0);
2632 pReturnNode = pWidgetData->SetSelectedMember(
2633 CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC(), true);
2634 }
2635 if (!pReturnNode) {
dsinclairf27aeec2016-06-07 19:36:18 -07002636 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002637 return;
2638 }
dsinclairf27aeec2016-06-07 19:36:18 -07002639 pArguments->GetReturnValue()->Assign(
thestig800222e2016-05-26 22:00:29 -07002640 m_pDocument->GetScriptContext()->GetJSValueFromMap(pReturnNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002641}
thestig800222e2016-05-26 22:00:29 -07002642
Dan Sinclair1770c022016-03-14 14:14:16 -04002643void CXFA_Node::Script_ExclGroup_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002644 if (pArguments->GetLength() != 0) {
2645 ThrowParamCountMismatchException(L"execInitialize");
2646 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002647 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002648
2649 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2650 if (!pNotify)
2651 return;
2652
2653 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04002654}
dsinclair5b36f0a2016-07-19 10:56:23 -07002655
Dan Sinclair1770c022016-03-14 14:14:16 -04002656void CXFA_Node::Script_ExclGroup_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002657 if (pArguments->GetLength() != 0) {
2658 ThrowParamCountMismatchException(L"execCalculate");
2659 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002660 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002661
2662 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2663 if (!pNotify)
2664 return;
2665
2666 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04002667}
dsinclair5b36f0a2016-07-19 10:56:23 -07002668
Dan Sinclair1770c022016-03-14 14:14:16 -04002669void CXFA_Node::Script_ExclGroup_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002670 if (pArguments->GetLength() != 0) {
2671 ThrowParamCountMismatchException(L"execValidate");
2672 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002673 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002674
2675 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2676 if (!pNotify) {
2677 pArguments->GetReturnValue()->SetBoolean(false);
2678 return;
2679 }
2680
2681 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
2682 pArguments->GetReturnValue()->SetBoolean(
2683 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002684}
dsinclair5b36f0a2016-07-19 10:56:23 -07002685
dsinclair12a6b0c2016-05-26 11:14:08 -07002686void CXFA_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002687 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002688 XFA_ATTRIBUTE eAttribute) {
2689 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002690 int32_t iTo = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002691 int32_t iFrom = Subform_and_SubformSet_InstanceIndex();
weili44f8faf2016-06-01 14:03:56 -07002692 CXFA_Node* pManagerNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002693 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2694 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002695 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002696 pManagerNode = pNode;
2697 break;
2698 }
2699 }
2700 if (pManagerNode) {
2701 pManagerNode->InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07002702 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002703 if (!pNotify) {
2704 return;
2705 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002706 CXFA_Node* pToInstance = GetItem(pManagerNode, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07002707 if (pToInstance &&
2708 pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002709 pNotify->RunSubformIndexChange(pToInstance);
2710 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002711 CXFA_Node* pFromInstance = GetItem(pManagerNode, iFrom);
dsinclair56a8b192016-06-21 14:15:25 -07002712 if (pFromInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07002713 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002714 pNotify->RunSubformIndexChange(pFromInstance);
2715 }
2716 }
2717 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002718 pValue->SetInteger(Subform_and_SubformSet_InstanceIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04002719 }
2720}
dsinclair5b36f0a2016-07-19 10:56:23 -07002721
dsinclair12a6b0c2016-05-26 11:14:08 -07002722void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002723 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002724 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002725 if (bSetting) {
2726 ThrowInvalidPropertyException();
2727 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002728 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002729
2730 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
2731 CXFA_Node* pInstanceMgr = nullptr;
2732 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2733 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
2734 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
2735 CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name);
2736 if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' &&
2737 wsInstMgrName.Mid(1) == wsName) {
2738 pInstanceMgr = pNode;
2739 }
2740 break;
2741 }
2742 }
2743 if (!pInstanceMgr) {
2744 pValue->SetNull();
2745 return;
2746 }
2747
2748 pValue->Assign(
2749 m_pDocument->GetScriptContext()->GetJSValueFromMap(pInstanceMgr));
Dan Sinclair1770c022016-03-14 14:14:16 -04002750}
dsinclair5b36f0a2016-07-19 10:56:23 -07002751
dsinclair12a6b0c2016-05-26 11:14:08 -07002752void CXFA_Node::Script_Subform_Locale(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002753 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002754 XFA_ATTRIBUTE eAttribute) {
2755 if (bSetting) {
tsepezd19e9122016-11-02 15:43:18 -07002756 SetCData(XFA_ATTRIBUTE_Locale, pValue->ToWideString(), true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002757 } else {
2758 CFX_WideString wsLocaleName;
2759 GetLocaleName(wsLocaleName);
Tom Sepezf0b65542017-02-13 10:26:01 -08002760 pValue->SetString(wsLocaleName.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002761 }
2762}
dsinclair5b36f0a2016-07-19 10:56:23 -07002763
Dan Sinclair1770c022016-03-14 14:14:16 -04002764void CXFA_Node::Script_Subform_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002765 if (pArguments->GetLength() != 1) {
2766 ThrowParamCountMismatchException(L"execEvent");
2767 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002768 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002769
2770 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2771 execSingleEventByName(
2772 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2773 XFA_Element::Subform);
Dan Sinclair1770c022016-03-14 14:14:16 -04002774}
dsinclair5b36f0a2016-07-19 10:56:23 -07002775
Dan Sinclair1770c022016-03-14 14:14:16 -04002776void CXFA_Node::Script_Subform_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002777 if (pArguments->GetLength() != 0) {
2778 ThrowParamCountMismatchException(L"execInitialize");
2779 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002780 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002781
2782 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2783 if (!pNotify)
2784 return;
2785
2786 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04002787}
dsinclair5b36f0a2016-07-19 10:56:23 -07002788
Dan Sinclair1770c022016-03-14 14:14:16 -04002789void CXFA_Node::Script_Subform_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002790 if (pArguments->GetLength() != 0) {
2791 ThrowParamCountMismatchException(L"execCalculate");
2792 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002793 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002794
2795 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2796 if (!pNotify)
2797 return;
2798
2799 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04002800}
dsinclair5b36f0a2016-07-19 10:56:23 -07002801
Dan Sinclair1770c022016-03-14 14:14:16 -04002802void CXFA_Node::Script_Subform_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002803 if (pArguments->GetLength() != 0) {
2804 ThrowParamCountMismatchException(L"execValidate");
2805 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002806 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002807
2808 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2809 if (!pNotify) {
2810 pArguments->GetReturnValue()->SetBoolean(false);
2811 return;
2812 }
2813
2814 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
2815 pArguments->GetReturnValue()->SetBoolean(
2816 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002817}
dsinclair5b36f0a2016-07-19 10:56:23 -07002818
Dan Sinclair1770c022016-03-14 14:14:16 -04002819void CXFA_Node::Script_Subform_GetInvalidObjects(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002820 if (pArguments->GetLength() != 0)
2821 ThrowParamCountMismatchException(L"getInvalidObjects");
Dan Sinclair1770c022016-03-14 14:14:16 -04002822}
dsinclair5b36f0a2016-07-19 10:56:23 -07002823
Dan Sinclair1770c022016-03-14 14:14:16 -04002824int32_t CXFA_Node::Subform_and_SubformSet_InstanceIndex() {
2825 int32_t index = 0;
2826 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2827 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002828 if ((pNode->GetElementType() == XFA_Element::Subform) ||
2829 (pNode->GetElementType() == XFA_Element::SubformSet)) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002830 index++;
2831 } else {
2832 break;
2833 }
2834 }
2835 return index;
2836}
dsinclair5b36f0a2016-07-19 10:56:23 -07002837
Dan Sinclair1770c022016-03-14 14:14:16 -04002838void CXFA_Node::Script_Template_FormNodes(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002839 if (pArguments->GetLength() != 1) {
2840 ThrowParamCountMismatchException(L"formNodes");
2841 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002842 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002843 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002844}
dsinclair5b36f0a2016-07-19 10:56:23 -07002845
Dan Sinclair1770c022016-03-14 14:14:16 -04002846void CXFA_Node::Script_Template_Remerge(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002847 if (pArguments->GetLength() != 0) {
2848 ThrowParamCountMismatchException(L"remerge");
2849 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002850 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002851 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002852}
dsinclair5b36f0a2016-07-19 10:56:23 -07002853
Dan Sinclair1770c022016-03-14 14:14:16 -04002854void CXFA_Node::Script_Template_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002855 if (pArguments->GetLength() != 0) {
2856 ThrowParamCountMismatchException(L"execInitialize");
2857 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002858 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002859
2860 CXFA_WidgetData* pWidgetData = GetWidgetData();
2861 if (!pWidgetData) {
2862 pArguments->GetReturnValue()->SetBoolean(false);
2863 return;
2864 }
2865 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002866}
dsinclair5b36f0a2016-07-19 10:56:23 -07002867
Dan Sinclair1770c022016-03-14 14:14:16 -04002868void CXFA_Node::Script_Template_CreateNode(CFXJSE_Arguments* pArguments) {
2869 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002870 if (argc <= 0 || argc >= 4) {
2871 ThrowParamCountMismatchException(L"createNode");
2872 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002873 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002874
2875 CFX_WideString strName;
2876 CFX_WideString strNameSpace;
2877 CFX_ByteString bsTagName = pArguments->GetUTF8String(0);
2878 CFX_WideString strTagName = CFX_WideString::FromUTF8(bsTagName.AsStringC());
2879 if (argc > 1) {
2880 CFX_ByteString bsName = pArguments->GetUTF8String(1);
2881 strName = CFX_WideString::FromUTF8(bsName.AsStringC());
2882 if (argc == 3) {
2883 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(2);
2884 strNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
2885 }
2886 }
2887
2888 XFA_Element eType = XFA_GetElementTypeForName(strTagName.AsStringC());
2889 CXFA_Node* pNewNode = CreateSamePacketNode(eType);
2890 if (!pNewNode) {
2891 pArguments->GetReturnValue()->SetNull();
2892 return;
2893 }
2894
2895 if (strName.IsEmpty()) {
2896 pArguments->GetReturnValue()->Assign(
2897 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
2898 return;
2899 }
2900
2901 if (!GetAttributeOfElement(eType, XFA_ATTRIBUTE_Name,
2902 XFA_XDPPACKET_UNKNOWN)) {
2903 ThrowMissingPropertyException(strTagName, L"name");
2904 return;
2905 }
2906
2907 pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, strName.AsStringC(), true);
2908 if (pNewNode->GetPacketID() == XFA_XDPPACKET_Datasets)
2909 pNewNode->CreateXMLMappingNode();
2910
2911 pArguments->GetReturnValue()->Assign(
2912 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002913}
dsinclair5b36f0a2016-07-19 10:56:23 -07002914
Dan Sinclair1770c022016-03-14 14:14:16 -04002915void CXFA_Node::Script_Template_Recalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002916 if (pArguments->GetLength() != 1) {
2917 ThrowParamCountMismatchException(L"recalculate");
2918 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002919 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002920 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002921}
dsinclair5b36f0a2016-07-19 10:56:23 -07002922
Dan Sinclair1770c022016-03-14 14:14:16 -04002923void CXFA_Node::Script_Template_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002924 if (pArguments->GetLength() != 0) {
2925 ThrowParamCountMismatchException(L"execCalculate");
2926 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002927 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002928
2929 CXFA_WidgetData* pWidgetData = GetWidgetData();
2930 if (!pWidgetData) {
2931 pArguments->GetReturnValue()->SetBoolean(false);
2932 return;
2933 }
2934 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002935}
dsinclair5b36f0a2016-07-19 10:56:23 -07002936
Dan Sinclair1770c022016-03-14 14:14:16 -04002937void CXFA_Node::Script_Template_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002938 if (pArguments->GetLength() != 0) {
2939 ThrowParamCountMismatchException(L"execValidate");
2940 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002941 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002942 CXFA_WidgetData* pWidgetData = GetWidgetData();
2943 if (!pWidgetData) {
2944 pArguments->GetReturnValue()->SetBoolean(false);
2945 return;
2946 }
2947 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002948}
dsinclair5b36f0a2016-07-19 10:56:23 -07002949
Dan Sinclair1770c022016-03-14 14:14:16 -04002950void CXFA_Node::Script_Manifest_Evaluate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002951 if (pArguments->GetLength() != 0) {
2952 ThrowParamCountMismatchException(L"evaluate");
2953 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002954 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002955
2956 CXFA_WidgetData* pWidgetData = GetWidgetData();
2957 if (!pWidgetData) {
2958 pArguments->GetReturnValue()->SetBoolean(false);
2959 return;
2960 }
2961 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002962}
dsinclair5b36f0a2016-07-19 10:56:23 -07002963
dsinclair12a6b0c2016-05-26 11:14:08 -07002964void CXFA_Node::Script_InstanceManager_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002965 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002966 XFA_ATTRIBUTE eAttribute) {
2967 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002968 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002969 return;
2970 }
2971 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07002972 pValue->SetInteger(nodeOccur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04002973}
dsinclair5b36f0a2016-07-19 10:56:23 -07002974
dsinclair12a6b0c2016-05-26 11:14:08 -07002975void CXFA_Node::Script_InstanceManager_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002976 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002977 XFA_ATTRIBUTE eAttribute) {
2978 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002979 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002980 return;
2981 }
2982 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07002983 pValue->SetInteger(nodeOccur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04002984}
tsepezaadedf92016-05-12 10:08:06 -07002985
dsinclair12a6b0c2016-05-26 11:14:08 -07002986void CXFA_Node::Script_InstanceManager_Count(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002987 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002988 XFA_ATTRIBUTE eAttribute) {
2989 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002990 int32_t iDesired = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002991 InstanceManager_SetInstances(iDesired);
2992 } else {
dsinclair5b36f0a2016-07-19 10:56:23 -07002993 pValue->SetInteger(GetCount(this));
Dan Sinclair1770c022016-03-14 14:14:16 -04002994 }
2995}
dsinclair5b36f0a2016-07-19 10:56:23 -07002996
Dan Sinclair1770c022016-03-14 14:14:16 -04002997void CXFA_Node::Script_InstanceManager_MoveInstance(
2998 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002999 if (pArguments->GetLength() != 2) {
dsinclairf27aeec2016-06-07 19:36:18 -07003000 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003001 return;
3002 }
3003 int32_t iFrom = pArguments->GetInt32(0);
3004 int32_t iTo = pArguments->GetInt32(1);
3005 InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07003006 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003007 if (!pNotify) {
3008 return;
3009 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003010 CXFA_Node* pToInstance = GetItem(this, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07003011 if (pToInstance && pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003012 pNotify->RunSubformIndexChange(pToInstance);
3013 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003014 CXFA_Node* pFromInstance = GetItem(this, iFrom);
dsinclair070fcdf2016-06-22 22:04:54 -07003015 if (pFromInstance &&
3016 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003017 pNotify->RunSubformIndexChange(pFromInstance);
3018 }
3019}
dsinclair5b36f0a2016-07-19 10:56:23 -07003020
Dan Sinclair1770c022016-03-14 14:14:16 -04003021void CXFA_Node::Script_InstanceManager_RemoveInstance(
3022 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003023 if (pArguments->GetLength() != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003024 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003025 return;
3026 }
3027 int32_t iIndex = pArguments->GetInt32(0);
dsinclair5b36f0a2016-07-19 10:56:23 -07003028 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003029 if (iIndex < 0 || iIndex >= iCount) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003030 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003031 return;
3032 }
3033 CXFA_Occur nodeOccur(GetOccurNode());
3034 int32_t iMin = nodeOccur.GetMin();
3035 if (iCount - 1 < iMin) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003036 ThrowTooManyOccurancesException(L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003037 return;
3038 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003039 CXFA_Node* pRemoveInstance = GetItem(this, iIndex);
3040 RemoveItem(this, pRemoveInstance);
dsinclaira1b07722016-07-11 08:20:58 -07003041 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003042 if (pNotify) {
3043 for (int32_t i = iIndex; i < iCount - 1; i++) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003044 CXFA_Node* pSubformInstance = GetItem(this, i);
Dan Sinclair1770c022016-03-14 14:14:16 -04003045 if (pSubformInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07003046 pSubformInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003047 pNotify->RunSubformIndexChange(pSubformInstance);
3048 }
3049 }
3050 }
3051 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3052 if (!pLayoutPro) {
3053 return;
3054 }
3055 pLayoutPro->AddChangedContainer(
3056 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3057}
dsinclair5b36f0a2016-07-19 10:56:23 -07003058
Dan Sinclair1770c022016-03-14 14:14:16 -04003059void CXFA_Node::Script_InstanceManager_SetInstances(
3060 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003061 if (pArguments->GetLength() != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003062 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003063 return;
3064 }
3065 int32_t iDesired = pArguments->GetInt32(0);
3066 InstanceManager_SetInstances(iDesired);
3067}
dsinclair5b36f0a2016-07-19 10:56:23 -07003068
Dan Sinclair1770c022016-03-14 14:14:16 -04003069void CXFA_Node::Script_InstanceManager_AddInstance(
3070 CFXJSE_Arguments* pArguments) {
3071 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003072 if (argc != 0 && argc != 1) {
3073 ThrowParamCountMismatchException(L"addInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003074 return;
3075 }
tsepezd19e9122016-11-02 15:43:18 -07003076 bool fFlags = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003077 if (argc == 1) {
tsepezd19e9122016-11-02 15:43:18 -07003078 fFlags = pArguments->GetInt32(0) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003079 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003080 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003081 CXFA_Occur nodeOccur(GetOccurNode());
3082 int32_t iMax = nodeOccur.GetMax();
3083 if (iMax >= 0 && iCount >= iMax) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003084 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003085 return;
3086 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003087 CXFA_Node* pNewInstance = CreateInstance(this, fFlags);
tsepezd19e9122016-11-02 15:43:18 -07003088 InsertItem(this, pNewInstance, iCount, iCount, false);
dsinclairf27aeec2016-06-07 19:36:18 -07003089 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003090 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003091 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003092 if (!pNotify) {
3093 return;
3094 }
3095 pNotify->RunNodeInitialize(pNewInstance);
3096 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3097 if (!pLayoutPro) {
3098 return;
3099 }
3100 pLayoutPro->AddChangedContainer(
3101 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3102}
dsinclair5b36f0a2016-07-19 10:56:23 -07003103
Dan Sinclair1770c022016-03-14 14:14:16 -04003104void CXFA_Node::Script_InstanceManager_InsertInstance(
3105 CFXJSE_Arguments* pArguments) {
3106 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003107 if (argc != 1 && argc != 2) {
3108 ThrowParamCountMismatchException(L"insertInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003109 return;
3110 }
3111 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07003112 bool bBind = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003113 if (argc == 2) {
tsepezd19e9122016-11-02 15:43:18 -07003114 bBind = pArguments->GetInt32(1) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003115 }
3116 CXFA_Occur nodeOccur(GetOccurNode());
dsinclair5b36f0a2016-07-19 10:56:23 -07003117 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003118 if (iIndex < 0 || iIndex > iCount) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003119 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003120 return;
3121 }
3122 int32_t iMax = nodeOccur.GetMax();
3123 if (iMax >= 0 && iCount >= iMax) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003124 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003125 return;
3126 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003127 CXFA_Node* pNewInstance = CreateInstance(this, bBind);
tsepezd19e9122016-11-02 15:43:18 -07003128 InsertItem(this, pNewInstance, iIndex, iCount, true);
dsinclairf27aeec2016-06-07 19:36:18 -07003129 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003130 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003131 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003132 if (!pNotify) {
3133 return;
3134 }
3135 pNotify->RunNodeInitialize(pNewInstance);
3136 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3137 if (!pLayoutPro) {
3138 return;
3139 }
3140 pLayoutPro->AddChangedContainer(
3141 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3142}
dsinclair5b36f0a2016-07-19 10:56:23 -07003143
Dan Sinclair1770c022016-03-14 14:14:16 -04003144int32_t CXFA_Node::InstanceManager_SetInstances(int32_t iDesired) {
3145 CXFA_Occur nodeOccur(GetOccurNode());
3146 int32_t iMax = nodeOccur.GetMax();
3147 int32_t iMin = nodeOccur.GetMin();
3148 if (iDesired < iMin) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003149 ThrowTooManyOccurancesException(L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003150 return 1;
3151 }
3152 if ((iMax >= 0) && (iDesired > iMax)) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003153 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003154 return 2;
3155 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003156 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003157 if (iDesired == iCount) {
3158 return 0;
3159 }
3160 if (iDesired < iCount) {
3161 CFX_WideStringC wsInstManagerName = GetCData(XFA_ATTRIBUTE_Name);
tsepezafe94302016-05-13 17:21:31 -07003162 CFX_WideString wsInstanceName =
3163 CFX_WideString(wsInstManagerName.IsEmpty() ? wsInstManagerName
3164 : wsInstManagerName.Mid(1));
tsepez736f28a2016-03-25 14:19:51 -07003165 uint32_t dInstanceNameHash =
tsepezb6853cf2016-04-25 11:23:43 -07003166 FX_HashCode_GetW(wsInstanceName.AsStringC(), false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003167 CXFA_Node* pPrevSibling =
dsinclair5b36f0a2016-07-19 10:56:23 -07003168 (iDesired == 0) ? this : GetItem(this, iDesired - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04003169 while (iCount > iDesired) {
3170 CXFA_Node* pRemoveInstance =
3171 pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling);
dsinclair070fcdf2016-06-22 22:04:54 -07003172 if (pRemoveInstance->GetElementType() != XFA_Element::Subform &&
3173 pRemoveInstance->GetElementType() != XFA_Element::SubformSet) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003174 continue;
3175 }
dsinclair070fcdf2016-06-22 22:04:54 -07003176 if (pRemoveInstance->GetElementType() == XFA_Element::InstanceManager) {
tsepezd19e9122016-11-02 15:43:18 -07003177 ASSERT(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003178 break;
3179 }
3180 if (pRemoveInstance->GetNameHash() == dInstanceNameHash) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003181 RemoveItem(this, pRemoveInstance);
Dan Sinclair1770c022016-03-14 14:14:16 -04003182 iCount--;
3183 }
3184 }
3185 } else if (iDesired > iCount) {
3186 while (iCount < iDesired) {
tsepezd19e9122016-11-02 15:43:18 -07003187 CXFA_Node* pNewInstance = CreateInstance(this, true);
3188 InsertItem(this, pNewInstance, iCount, iCount, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003189 iCount++;
dsinclaira1b07722016-07-11 08:20:58 -07003190 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003191 if (!pNotify) {
3192 return 0;
3193 }
3194 pNotify->RunNodeInitialize(pNewInstance);
3195 }
3196 }
3197 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3198 if (pLayoutPro) {
3199 pLayoutPro->AddChangedContainer(
3200 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3201 }
3202 return 0;
3203}
dsinclair5b36f0a2016-07-19 10:56:23 -07003204
Dan Sinclair1770c022016-03-14 14:14:16 -04003205int32_t CXFA_Node::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003206 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003207 if (iFrom > iCount || iTo > iCount - 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003208 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003209 return 1;
3210 }
3211 if (iFrom < 0 || iTo < 0 || iFrom == iTo) {
3212 return 0;
3213 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003214 CXFA_Node* pMoveInstance = GetItem(this, iFrom);
tsepezd19e9122016-11-02 15:43:18 -07003215 RemoveItem(this, pMoveInstance, false);
3216 InsertItem(this, pMoveInstance, iTo, iCount - 1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003217 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3218 if (pLayoutPro) {
3219 pLayoutPro->AddChangedContainer(
3220 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3221 }
3222 return 0;
3223}
dsinclair5b36f0a2016-07-19 10:56:23 -07003224
dsinclair12a6b0c2016-05-26 11:14:08 -07003225void CXFA_Node::Script_Occur_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003226 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003227 XFA_ATTRIBUTE eAttribute) {
3228 CXFA_Occur occur(this);
3229 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003230 int32_t iMax = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003231 occur.SetMax(iMax);
3232 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003233 pValue->SetInteger(occur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04003234 }
3235}
dsinclair5b36f0a2016-07-19 10:56:23 -07003236
dsinclair12a6b0c2016-05-26 11:14:08 -07003237void CXFA_Node::Script_Occur_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003238 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003239 XFA_ATTRIBUTE eAttribute) {
3240 CXFA_Occur occur(this);
3241 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003242 int32_t iMin = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003243 occur.SetMin(iMin);
3244 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003245 pValue->SetInteger(occur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04003246 }
3247}
dsinclair5b36f0a2016-07-19 10:56:23 -07003248
Dan Sinclair1770c022016-03-14 14:14:16 -04003249void CXFA_Node::Script_Desc_Metadata(CFXJSE_Arguments* pArguments) {
3250 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003251 if (argc != 0 && argc != 1) {
3252 ThrowParamCountMismatchException(L"metadata");
3253 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003254 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003255 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04003256}
dsinclair5b36f0a2016-07-19 10:56:23 -07003257
Dan Sinclair1770c022016-03-14 14:14:16 -04003258void CXFA_Node::Script_Form_FormNodes(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003259 if (pArguments->GetLength() != 1) {
3260 ThrowParamCountMismatchException(L"formNodes");
3261 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003262 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003263
3264 CXFA_Node* pDataNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
3265 if (!pDataNode) {
3266 ThrowArgumentMismatchException();
3267 return;
3268 }
3269
Tom Sepezf8a94392017-03-14 12:13:22 -07003270 std::vector<CXFA_Node*> formItems;
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003271 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
3272 pFormNodes->SetArrayNodeList(formItems);
3273 pArguments->GetReturnValue()->SetObject(
3274 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04003275}
dsinclair5b36f0a2016-07-19 10:56:23 -07003276
Dan Sinclair1770c022016-03-14 14:14:16 -04003277void CXFA_Node::Script_Form_Remerge(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003278 if (pArguments->GetLength() != 0) {
3279 ThrowParamCountMismatchException(L"remerge");
3280 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003281 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003282
3283 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003284}
dsinclair5b36f0a2016-07-19 10:56:23 -07003285
Dan Sinclair1770c022016-03-14 14:14:16 -04003286void CXFA_Node::Script_Form_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003287 if (pArguments->GetLength() != 0) {
3288 ThrowParamCountMismatchException(L"execInitialize");
3289 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003290 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003291
3292 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3293 if (!pNotify)
3294 return;
3295
3296 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04003297}
dsinclair5b36f0a2016-07-19 10:56:23 -07003298
Dan Sinclair1770c022016-03-14 14:14:16 -04003299void CXFA_Node::Script_Form_Recalculate(CFXJSE_Arguments* pArguments) {
3300 CXFA_EventParam* pEventParam =
3301 m_pDocument->GetScriptContext()->GetEventParam();
3302 if (pEventParam->m_eType == XFA_EVENT_Calculate ||
3303 pEventParam->m_eType == XFA_EVENT_InitCalculate) {
3304 return;
3305 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003306 if (pArguments->GetLength() != 1) {
3307 ThrowParamCountMismatchException(L"recalculate");
3308 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003309 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003310
3311 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3312 if (!pNotify)
3313 return;
3314 if (pArguments->GetInt32(0) != 0)
3315 return;
3316
3317 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
3318 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
3319 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Ready, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003320}
dsinclair5b36f0a2016-07-19 10:56:23 -07003321
Dan Sinclair1770c022016-03-14 14:14:16 -04003322void CXFA_Node::Script_Form_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003323 if (pArguments->GetLength() != 0) {
3324 ThrowParamCountMismatchException(L"execCalculate");
3325 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003326 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003327
3328 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3329 if (!pNotify)
3330 return;
3331
3332 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04003333}
dsinclair5b36f0a2016-07-19 10:56:23 -07003334
Dan Sinclair1770c022016-03-14 14:14:16 -04003335void CXFA_Node::Script_Form_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003336 if (pArguments->GetLength() != 0) {
3337 ThrowParamCountMismatchException(L"execValidate");
3338 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003339 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003340
3341 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3342 if (!pNotify) {
3343 pArguments->GetReturnValue()->SetBoolean(false);
3344 return;
3345 }
3346
3347 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
3348 pArguments->GetReturnValue()->SetBoolean(
3349 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003350}
dsinclair5b36f0a2016-07-19 10:56:23 -07003351
dsinclair12a6b0c2016-05-26 11:14:08 -07003352void CXFA_Node::Script_Form_Checksum(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003353 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003354 XFA_ATTRIBUTE eAttribute) {
3355 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07003356 SetAttribute(XFA_ATTRIBUTE_Checksum, pValue->ToWideString().AsStringC());
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003357 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003358 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003359 CFX_WideString wsChecksum;
3360 GetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum, false);
Tom Sepezf0b65542017-02-13 10:26:01 -08003361 pValue->SetString(wsChecksum.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003362}
dsinclair5b36f0a2016-07-19 10:56:23 -07003363
Dan Sinclair1770c022016-03-14 14:14:16 -04003364void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003365 if (pArguments->GetLength() != 1) {
3366 ThrowParamCountMismatchException(L"getAttribute");
3367 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003368 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003369 CFX_ByteString bsAttributeName = pArguments->GetUTF8String(0);
3370 CFX_WideString wsAttributeValue;
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003371 CFX_XMLNode* pXMLNode = GetXMLMappingNode();
3372 if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) {
3373 wsAttributeValue = static_cast<CFX_XMLElement*>(pXMLNode)->GetString(
Dan Sinclair5fa4e982017-04-05 11:48:21 -04003374 CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str());
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003375 }
3376 pArguments->GetReturnValue()->SetString(
Tom Sepezf0b65542017-02-13 10:26:01 -08003377 wsAttributeValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003378}
dsinclair5b36f0a2016-07-19 10:56:23 -07003379
Dan Sinclair1770c022016-03-14 14:14:16 -04003380void CXFA_Node::Script_Packet_SetAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003381 if (pArguments->GetLength() != 2) {
3382 ThrowParamCountMismatchException(L"setAttribute");
3383 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003384 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003385 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
3386 CFX_ByteString bsName = pArguments->GetUTF8String(1);
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003387 CFX_XMLNode* pXMLNode = GetXMLMappingNode();
3388 if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) {
3389 static_cast<CFX_XMLElement*>(pXMLNode)->SetString(
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003390 CFX_WideString::FromUTF8(bsName.AsStringC()),
3391 CFX_WideString::FromUTF8(bsValue.AsStringC()));
3392 }
3393 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003394}
dsinclair5b36f0a2016-07-19 10:56:23 -07003395
Dan Sinclair1770c022016-03-14 14:14:16 -04003396void CXFA_Node::Script_Packet_RemoveAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003397 if (pArguments->GetLength() != 1) {
3398 ThrowParamCountMismatchException(L"removeAttribute");
3399 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003400 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003401
3402 CFX_ByteString bsName = pArguments->GetUTF8String(0);
3403 CFX_WideString wsName = CFX_WideString::FromUTF8(bsName.AsStringC());
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003404 CFX_XMLNode* pXMLNode = GetXMLMappingNode();
3405 if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) {
3406 CFX_XMLElement* pXMLElement = static_cast<CFX_XMLElement*>(pXMLNode);
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003407 if (pXMLElement->HasAttribute(wsName.c_str())) {
3408 pXMLElement->RemoveAttribute(wsName.c_str());
3409 }
3410 }
3411 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003412}
dsinclair5b36f0a2016-07-19 10:56:23 -07003413
dsinclair12a6b0c2016-05-26 11:14:08 -07003414void CXFA_Node::Script_Packet_Content(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003415 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003416 XFA_ATTRIBUTE eAttribute) {
3417 if (bSetting) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003418 CFX_XMLNode* pXMLNode = GetXMLMappingNode();
3419 if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) {
3420 CFX_XMLElement* pXMLElement = static_cast<CFX_XMLElement*>(pXMLNode);
dsinclair2f5582f2016-06-09 11:48:23 -07003421 pXMLElement->SetTextData(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04003422 }
3423 } else {
3424 CFX_WideString wsTextData;
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003425 CFX_XMLNode* pXMLNode = GetXMLMappingNode();
3426 if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) {
3427 CFX_XMLElement* pXMLElement = static_cast<CFX_XMLElement*>(pXMLNode);
Dan Sinclair5fa4e982017-04-05 11:48:21 -04003428 wsTextData = pXMLElement->GetTextData();
Dan Sinclair1770c022016-03-14 14:14:16 -04003429 }
Tom Sepezf0b65542017-02-13 10:26:01 -08003430 pValue->SetString(wsTextData.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003431 }
3432}
dsinclair5b36f0a2016-07-19 10:56:23 -07003433
Dan Sinclair1770c022016-03-14 14:14:16 -04003434void CXFA_Node::Script_Source_Next(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003435 if (pArguments->GetLength() != 0)
3436 ThrowParamCountMismatchException(L"next");
Dan Sinclair1770c022016-03-14 14:14:16 -04003437}
dsinclair5b36f0a2016-07-19 10:56:23 -07003438
Dan Sinclair1770c022016-03-14 14:14:16 -04003439void CXFA_Node::Script_Source_CancelBatch(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003440 if (pArguments->GetLength() != 0)
3441 ThrowParamCountMismatchException(L"cancelBatch");
Dan Sinclair1770c022016-03-14 14:14:16 -04003442}
dsinclair5b36f0a2016-07-19 10:56:23 -07003443
Dan Sinclair1770c022016-03-14 14:14:16 -04003444void CXFA_Node::Script_Source_First(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003445 if (pArguments->GetLength() != 0)
3446 ThrowParamCountMismatchException(L"first");
Dan Sinclair1770c022016-03-14 14:14:16 -04003447}
dsinclair5b36f0a2016-07-19 10:56:23 -07003448
Dan Sinclair1770c022016-03-14 14:14:16 -04003449void CXFA_Node::Script_Source_UpdateBatch(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003450 if (pArguments->GetLength() != 0)
3451 ThrowParamCountMismatchException(L"updateBatch");
Dan Sinclair1770c022016-03-14 14:14:16 -04003452}
dsinclair5b36f0a2016-07-19 10:56:23 -07003453
Dan Sinclair1770c022016-03-14 14:14:16 -04003454void CXFA_Node::Script_Source_Previous(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003455 if (pArguments->GetLength() != 0)
3456 ThrowParamCountMismatchException(L"previous");
Dan Sinclair1770c022016-03-14 14:14:16 -04003457}
dsinclair5b36f0a2016-07-19 10:56:23 -07003458
Dan Sinclair1770c022016-03-14 14:14:16 -04003459void CXFA_Node::Script_Source_IsBOF(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003460 if (pArguments->GetLength() != 0)
3461 ThrowParamCountMismatchException(L"isBOF");
Dan Sinclair1770c022016-03-14 14:14:16 -04003462}
dsinclair5b36f0a2016-07-19 10:56:23 -07003463
Dan Sinclair1770c022016-03-14 14:14:16 -04003464void CXFA_Node::Script_Source_IsEOF(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003465 if (pArguments->GetLength() != 0)
3466 ThrowParamCountMismatchException(L"isEOF");
Dan Sinclair1770c022016-03-14 14:14:16 -04003467}
dsinclair5b36f0a2016-07-19 10:56:23 -07003468
Dan Sinclair1770c022016-03-14 14:14:16 -04003469void CXFA_Node::Script_Source_Cancel(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003470 if (pArguments->GetLength() != 0)
3471 ThrowParamCountMismatchException(L"cancel");
Dan Sinclair1770c022016-03-14 14:14:16 -04003472}
dsinclair5b36f0a2016-07-19 10:56:23 -07003473
Dan Sinclair1770c022016-03-14 14:14:16 -04003474void CXFA_Node::Script_Source_Update(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003475 if (pArguments->GetLength() != 0)
3476 ThrowParamCountMismatchException(L"update");
Dan Sinclair1770c022016-03-14 14:14:16 -04003477}
dsinclair5b36f0a2016-07-19 10:56:23 -07003478
Dan Sinclair1770c022016-03-14 14:14:16 -04003479void CXFA_Node::Script_Source_Open(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003480 if (pArguments->GetLength() != 0)
3481 ThrowParamCountMismatchException(L"open");
Dan Sinclair1770c022016-03-14 14:14:16 -04003482}
dsinclair5b36f0a2016-07-19 10:56:23 -07003483
Dan Sinclair1770c022016-03-14 14:14:16 -04003484void CXFA_Node::Script_Source_Delete(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003485 if (pArguments->GetLength() != 0)
3486 ThrowParamCountMismatchException(L"delete");
Dan Sinclair1770c022016-03-14 14:14:16 -04003487}
dsinclair5b36f0a2016-07-19 10:56:23 -07003488
Dan Sinclair1770c022016-03-14 14:14:16 -04003489void CXFA_Node::Script_Source_AddNew(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003490 if (pArguments->GetLength() != 0)
3491 ThrowParamCountMismatchException(L"addNew");
Dan Sinclair1770c022016-03-14 14:14:16 -04003492}
dsinclair5b36f0a2016-07-19 10:56:23 -07003493
Dan Sinclair1770c022016-03-14 14:14:16 -04003494void CXFA_Node::Script_Source_Requery(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003495 if (pArguments->GetLength() != 0)
3496 ThrowParamCountMismatchException(L"requery");
Dan Sinclair1770c022016-03-14 14:14:16 -04003497}
dsinclair5b36f0a2016-07-19 10:56:23 -07003498
Dan Sinclair1770c022016-03-14 14:14:16 -04003499void CXFA_Node::Script_Source_Resync(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003500 if (pArguments->GetLength() != 0)
3501 ThrowParamCountMismatchException(L"resync");
Dan Sinclair1770c022016-03-14 14:14:16 -04003502}
dsinclair5b36f0a2016-07-19 10:56:23 -07003503
Dan Sinclair1770c022016-03-14 14:14:16 -04003504void CXFA_Node::Script_Source_Close(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003505 if (pArguments->GetLength() != 0)
3506 ThrowParamCountMismatchException(L"close");
Dan Sinclair1770c022016-03-14 14:14:16 -04003507}
dsinclair5b36f0a2016-07-19 10:56:23 -07003508
Dan Sinclair1770c022016-03-14 14:14:16 -04003509void CXFA_Node::Script_Source_Last(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003510 if (pArguments->GetLength() != 0)
3511 ThrowParamCountMismatchException(L"last");
Dan Sinclair1770c022016-03-14 14:14:16 -04003512}
dsinclair5b36f0a2016-07-19 10:56:23 -07003513
Dan Sinclair1770c022016-03-14 14:14:16 -04003514void CXFA_Node::Script_Source_HasDataChanged(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003515 if (pArguments->GetLength() != 0)
3516 ThrowParamCountMismatchException(L"hasDataChanged");
Dan Sinclair1770c022016-03-14 14:14:16 -04003517}
dsinclair5b36f0a2016-07-19 10:56:23 -07003518
dsinclair12a6b0c2016-05-26 11:14:08 -07003519void CXFA_Node::Script_Source_Db(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003520 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003521 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003522
dsinclair12a6b0c2016-05-26 11:14:08 -07003523void CXFA_Node::Script_Xfa_This(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003524 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003525 XFA_ATTRIBUTE eAttribute) {
3526 if (!bSetting) {
3527 CXFA_Object* pThis = m_pDocument->GetScriptContext()->GetThisObject();
dsinclair43854a52016-04-27 12:26:00 -07003528 ASSERT(pThis);
dsinclairf27aeec2016-06-07 19:36:18 -07003529 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pThis));
Dan Sinclair1770c022016-03-14 14:14:16 -04003530 }
3531}
dsinclair5b36f0a2016-07-19 10:56:23 -07003532
dsinclair12a6b0c2016-05-26 11:14:08 -07003533void CXFA_Node::Script_Handler_Version(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003534 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003535 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003536
dsinclair12a6b0c2016-05-26 11:14:08 -07003537void CXFA_Node::Script_SubmitFormat_Mode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003538 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003539 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003540
dsinclair12a6b0c2016-05-26 11:14:08 -07003541void CXFA_Node::Script_Extras_Type(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003542 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003543 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003544
dsinclair12a6b0c2016-05-26 11:14:08 -07003545void CXFA_Node::Script_Script_Stateless(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003546 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003547 XFA_ATTRIBUTE eAttribute) {
3548 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003549 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003550 return;
3551 }
dan sinclair65c7c232017-02-02 14:05:30 -08003552 pValue->SetString(FX_UTF8Encode(CFX_WideStringC(L"0", 1)).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003553}
dsinclair5b36f0a2016-07-19 10:56:23 -07003554
dsinclair12a6b0c2016-05-26 11:14:08 -07003555void CXFA_Node::Script_Encrypt_Format(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003556 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003557 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003558
tsepezd19e9122016-11-02 15:43:18 -07003559bool CXFA_Node::HasAttribute(XFA_ATTRIBUTE eAttr, bool bCanInherit) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003560 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003561 return HasMapModuleKey(pKey, bCanInherit);
3562}
dsinclair5b36f0a2016-07-19 10:56:23 -07003563
tsepezd19e9122016-11-02 15:43:18 -07003564bool CXFA_Node::SetAttribute(XFA_ATTRIBUTE eAttr,
3565 const CFX_WideStringC& wsValue,
3566 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003567 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003568 if (!pAttr)
tsepezd19e9122016-11-02 15:43:18 -07003569 return false;
weili44f8faf2016-06-01 14:03:56 -07003570
Dan Sinclair1770c022016-03-14 14:14:16 -04003571 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3572 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3573 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003574 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003575 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3576 }
3577 switch (eType) {
3578 case XFA_ATTRIBUTETYPE_Enum: {
3579 const XFA_ATTRIBUTEENUMINFO* pEnum = XFA_GetAttributeEnumByName(wsValue);
3580 return SetEnum(pAttr->eName,
3581 pEnum ? pEnum->eName
3582 : (XFA_ATTRIBUTEENUM)(intptr_t)(pAttr->pDefValue),
3583 bNotify);
3584 } break;
3585 case XFA_ATTRIBUTETYPE_Cdata:
tsepezafe94302016-05-13 17:21:31 -07003586 return SetCData(pAttr->eName, CFX_WideString(wsValue), bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003587 case XFA_ATTRIBUTETYPE_Boolean:
dan sinclair65c7c232017-02-02 14:05:30 -08003588 return SetBoolean(pAttr->eName, wsValue != L"0", bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003589 case XFA_ATTRIBUTETYPE_Integer:
dsinclaire0347a62016-08-11 11:24:11 -07003590 return SetInteger(pAttr->eName,
3591 FXSYS_round(FXSYS_wcstof(wsValue.c_str(),
3592 wsValue.GetLength(), nullptr)),
3593 bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003594 case XFA_ATTRIBUTETYPE_Measure:
3595 return SetMeasure(pAttr->eName, CXFA_Measurement(wsValue), bNotify);
3596 default:
3597 break;
3598 }
tsepezd19e9122016-11-02 15:43:18 -07003599 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003600}
dsinclair5b36f0a2016-07-19 10:56:23 -07003601
tsepezd19e9122016-11-02 15:43:18 -07003602bool CXFA_Node::GetAttribute(XFA_ATTRIBUTE eAttr,
3603 CFX_WideString& wsValue,
3604 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003605 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003606 if (!pAttr) {
tsepezd19e9122016-11-02 15:43:18 -07003607 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003608 }
3609 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3610 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3611 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003612 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003613 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3614 }
3615 switch (eType) {
3616 case XFA_ATTRIBUTETYPE_Enum: {
3617 XFA_ATTRIBUTEENUM eValue;
3618 if (!TryEnum(pAttr->eName, eValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003619 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003620 }
dsinclair9eb0db12016-07-21 12:01:39 -07003621 wsValue = GetAttributeEnumByID(eValue)->pName;
tsepezd19e9122016-11-02 15:43:18 -07003622 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003623 } break;
3624 case XFA_ATTRIBUTETYPE_Cdata: {
3625 CFX_WideStringC wsValueC;
3626 if (!TryCData(pAttr->eName, wsValueC, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003627 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003628 }
3629 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07003630 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003631 } break;
3632 case XFA_ATTRIBUTETYPE_Boolean: {
tsepezd19e9122016-11-02 15:43:18 -07003633 bool bValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04003634 if (!TryBoolean(pAttr->eName, bValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003635 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003636 }
dan sinclair65c7c232017-02-02 14:05:30 -08003637 wsValue = bValue ? L"1" : L"0";
tsepezd19e9122016-11-02 15:43:18 -07003638 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003639 } break;
3640 case XFA_ATTRIBUTETYPE_Integer: {
3641 int32_t iValue;
3642 if (!TryInteger(pAttr->eName, iValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003643 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003644 }
3645 wsValue.Format(L"%d", iValue);
tsepezd19e9122016-11-02 15:43:18 -07003646 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003647 } break;
3648 case XFA_ATTRIBUTETYPE_Measure: {
3649 CXFA_Measurement mValue;
3650 if (!TryMeasure(pAttr->eName, mValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003651 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003652 }
3653 mValue.ToString(wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003654 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003655 } break;
3656 default:
3657 break;
3658 }
tsepezd19e9122016-11-02 15:43:18 -07003659 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003660}
dsinclair5b36f0a2016-07-19 10:56:23 -07003661
tsepezd19e9122016-11-02 15:43:18 -07003662bool CXFA_Node::SetAttribute(const CFX_WideStringC& wsAttr,
3663 const CFX_WideStringC& wsValue,
3664 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003665 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsValue);
3666 if (pAttributeInfo) {
3667 return SetAttribute(pAttributeInfo->eName, wsValue, bNotify);
3668 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003669 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003670 SetMapModuleString(pKey, wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003671 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003672}
dsinclair5b36f0a2016-07-19 10:56:23 -07003673
tsepezd19e9122016-11-02 15:43:18 -07003674bool CXFA_Node::GetAttribute(const CFX_WideStringC& wsAttr,
3675 CFX_WideString& wsValue,
3676 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003677 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsAttr);
3678 if (pAttributeInfo) {
3679 return GetAttribute(pAttributeInfo->eName, wsValue, bUseDefault);
3680 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003681 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003682 CFX_WideStringC wsValueC;
3683 if (GetMapModuleString(pKey, wsValueC)) {
3684 wsValue = wsValueC;
3685 }
tsepezd19e9122016-11-02 15:43:18 -07003686 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003687}
dsinclair5b36f0a2016-07-19 10:56:23 -07003688
tsepezd19e9122016-11-02 15:43:18 -07003689bool CXFA_Node::RemoveAttribute(const CFX_WideStringC& wsAttr) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003690 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003691 RemoveMapModuleKey(pKey);
tsepezd19e9122016-11-02 15:43:18 -07003692 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003693}
dsinclair5b36f0a2016-07-19 10:56:23 -07003694
tsepezd19e9122016-11-02 15:43:18 -07003695bool CXFA_Node::TryBoolean(XFA_ATTRIBUTE eAttr,
3696 bool& bValue,
3697 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003698 void* pValue = nullptr;
3699 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Boolean, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003700 return false;
tsepez478ed622016-10-27 14:32:33 -07003701 bValue = !!pValue;
tsepezd19e9122016-11-02 15:43:18 -07003702 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003703}
dsinclair5b36f0a2016-07-19 10:56:23 -07003704
tsepezd19e9122016-11-02 15:43:18 -07003705bool CXFA_Node::TryInteger(XFA_ATTRIBUTE eAttr,
3706 int32_t& iValue,
3707 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003708 void* pValue = nullptr;
3709 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Integer, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003710 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003711 iValue = (int32_t)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003712 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003713}
dsinclair5b36f0a2016-07-19 10:56:23 -07003714
tsepezd19e9122016-11-02 15:43:18 -07003715bool CXFA_Node::TryEnum(XFA_ATTRIBUTE eAttr,
3716 XFA_ATTRIBUTEENUM& eValue,
3717 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003718 void* pValue = nullptr;
3719 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Enum, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003720 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003721 eValue = (XFA_ATTRIBUTEENUM)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003722 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003723}
thestigb1a59592016-04-14 18:29:56 -07003724
tsepezd19e9122016-11-02 15:43:18 -07003725bool CXFA_Node::SetMeasure(XFA_ATTRIBUTE eAttr,
3726 CXFA_Measurement mValue,
3727 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003728 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003729 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003730 SetMapModuleBuffer(pKey, &mValue, sizeof(CXFA_Measurement));
tsepezd19e9122016-11-02 15:43:18 -07003731 OnChanged(eAttr, bNotify, false);
3732 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003733}
thestigb1a59592016-04-14 18:29:56 -07003734
tsepezd19e9122016-11-02 15:43:18 -07003735bool CXFA_Node::TryMeasure(XFA_ATTRIBUTE eAttr,
3736 CXFA_Measurement& mValue,
3737 bool bUseDefault) const {
dsinclair5b36f0a2016-07-19 10:56:23 -07003738 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003739 void* pValue;
3740 int32_t iBytes;
3741 if (GetMapModuleBuffer(pKey, pValue, iBytes) && iBytes == sizeof(mValue)) {
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04003742 memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003743 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003744 }
3745 if (bUseDefault &&
dsinclair070fcdf2016-06-22 22:04:54 -07003746 XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003747 XFA_ATTRIBUTETYPE_Measure, m_ePacket)) {
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04003748 memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003749 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003750 }
tsepezd19e9122016-11-02 15:43:18 -07003751 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003752}
3753
3754CXFA_Measurement CXFA_Node::GetMeasure(XFA_ATTRIBUTE eAttr) const {
3755 CXFA_Measurement mValue;
tsepezd19e9122016-11-02 15:43:18 -07003756 return TryMeasure(eAttr, mValue, true) ? mValue : CXFA_Measurement();
Dan Sinclair1770c022016-03-14 14:14:16 -04003757}
3758
tsepezd19e9122016-11-02 15:43:18 -07003759bool CXFA_Node::SetCData(XFA_ATTRIBUTE eAttr,
3760 const CFX_WideString& wsValue,
3761 bool bNotify,
3762 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003763 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003764 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003765 if (eAttr == XFA_ATTRIBUTE_Value) {
3766 CFX_WideString* pClone = new CFX_WideString(wsValue);
3767 SetUserData(pKey, pClone, &deleteWideStringCallBack);
3768 } else {
tsepez4c3debb2016-04-08 12:20:38 -07003769 SetMapModuleString(pKey, wsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003770 if (eAttr == XFA_ATTRIBUTE_Name)
3771 UpdateNameHash();
3772 }
thestigb1a59592016-04-14 18:29:56 -07003773 OnChanged(eAttr, bNotify, bScriptModify);
3774
3775 if (!IsNeedSavingXMLNode() || eAttr == XFA_ATTRIBUTE_QualifiedName ||
3776 eAttr == XFA_ATTRIBUTE_BindingNode) {
tsepezd19e9122016-11-02 15:43:18 -07003777 return true;
thestigb1a59592016-04-14 18:29:56 -07003778 }
3779
dsinclair070fcdf2016-06-22 22:04:54 -07003780 if (eAttr == XFA_ATTRIBUTE_Name &&
3781 (m_elementType == XFA_Element::DataValue ||
3782 m_elementType == XFA_Element::DataGroup)) {
tsepezd19e9122016-11-02 15:43:18 -07003783 return true;
thestigb1a59592016-04-14 18:29:56 -07003784 }
3785
3786 if (eAttr == XFA_ATTRIBUTE_Value) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003787 FX_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
thestigb1a59592016-04-14 18:29:56 -07003788 switch (eXMLType) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003789 case FX_XMLNODE_Element:
thestigb1a59592016-04-14 18:29:56 -07003790 if (IsAttributeInXML()) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003791 static_cast<CFX_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003792 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3793 wsValue);
thestigb1a59592016-04-14 18:29:56 -07003794 } else {
tsepezd19e9122016-11-02 15:43:18 -07003795 bool bDeleteChildren = true;
thestigb1a59592016-04-14 18:29:56 -07003796 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3797 for (CXFA_Node* pChildDataNode =
3798 GetNodeItem(XFA_NODEITEM_FirstChild);
3799 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3800 XFA_NODEITEM_NextSibling)) {
Tom Sepezf8a94392017-03-14 12:13:22 -07003801 if (!pChildDataNode->GetBindItems().empty()) {
tsepezd19e9122016-11-02 15:43:18 -07003802 bDeleteChildren = false;
thestigb1a59592016-04-14 18:29:56 -07003803 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04003804 }
3805 }
Dan Sinclair1770c022016-03-14 14:14:16 -04003806 }
thestigb1a59592016-04-14 18:29:56 -07003807 if (bDeleteChildren) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003808 static_cast<CFX_XMLElement*>(m_pXMLNode)->DeleteChildren();
thestigb1a59592016-04-14 18:29:56 -07003809 }
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003810 static_cast<CFX_XMLElement*>(m_pXMLNode)->SetTextData(wsValue);
thestigb1a59592016-04-14 18:29:56 -07003811 }
3812 break;
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003813 case FX_XMLNODE_Text:
3814 static_cast<CFX_XMLText*>(m_pXMLNode)->SetText(wsValue);
thestigb1a59592016-04-14 18:29:56 -07003815 break;
3816 default:
dsinclair43854a52016-04-27 12:26:00 -07003817 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003818 }
tsepezd19e9122016-11-02 15:43:18 -07003819 return true;
thestigb1a59592016-04-14 18:29:56 -07003820 }
3821
3822 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
3823 if (pInfo) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003824 ASSERT(m_pXMLNode->GetType() == FX_XMLNODE_Element);
thestigb1a59592016-04-14 18:29:56 -07003825 CFX_WideString wsAttrName = pInfo->pName;
3826 if (pInfo->eName == XFA_ATTRIBUTE_ContentType) {
dan sinclair65c7c232017-02-02 14:05:30 -08003827 wsAttrName = L"xfa:" + wsAttrName;
Dan Sinclair1770c022016-03-14 14:14:16 -04003828 }
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003829 static_cast<CFX_XMLElement*>(m_pXMLNode)->SetString(wsAttrName, wsValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003830 }
tsepezd19e9122016-11-02 15:43:18 -07003831 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003832}
thestigb1a59592016-04-14 18:29:56 -07003833
tsepezd19e9122016-11-02 15:43:18 -07003834bool CXFA_Node::SetAttributeValue(const CFX_WideString& wsValue,
3835 const CFX_WideString& wsXMLValue,
3836 bool bNotify,
3837 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003838 void* pKey = GetMapKey_Element(GetElementType(), XFA_ATTRIBUTE_Value);
thestigb1a59592016-04-14 18:29:56 -07003839 OnChanging(XFA_ATTRIBUTE_Value, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003840 CFX_WideString* pClone = new CFX_WideString(wsValue);
3841 SetUserData(pKey, pClone, &deleteWideStringCallBack);
thestigb1a59592016-04-14 18:29:56 -07003842 OnChanged(XFA_ATTRIBUTE_Value, bNotify, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003843 if (IsNeedSavingXMLNode()) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003844 FX_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
Dan Sinclair1770c022016-03-14 14:14:16 -04003845 switch (eXMLType) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003846 case FX_XMLNODE_Element:
Dan Sinclair1770c022016-03-14 14:14:16 -04003847 if (IsAttributeInXML()) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003848 static_cast<CFX_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003849 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3850 wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003851 } else {
tsepezd19e9122016-11-02 15:43:18 -07003852 bool bDeleteChildren = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003853 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3854 for (CXFA_Node* pChildDataNode =
3855 GetNodeItem(XFA_NODEITEM_FirstChild);
3856 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3857 XFA_NODEITEM_NextSibling)) {
Tom Sepezf8a94392017-03-14 12:13:22 -07003858 if (!pChildDataNode->GetBindItems().empty()) {
tsepezd19e9122016-11-02 15:43:18 -07003859 bDeleteChildren = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003860 break;
3861 }
3862 }
3863 }
3864 if (bDeleteChildren) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003865 static_cast<CFX_XMLElement*>(m_pXMLNode)->DeleteChildren();
Dan Sinclair1770c022016-03-14 14:14:16 -04003866 }
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003867 static_cast<CFX_XMLElement*>(m_pXMLNode)->SetTextData(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003868 }
3869 break;
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003870 case FX_XMLNODE_Text:
3871 static_cast<CFX_XMLText*>(m_pXMLNode)->SetText(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003872 break;
3873 default:
dsinclair43854a52016-04-27 12:26:00 -07003874 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003875 }
3876 }
tsepezd19e9122016-11-02 15:43:18 -07003877 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003878}
dsinclair5b36f0a2016-07-19 10:56:23 -07003879
tsepezd19e9122016-11-02 15:43:18 -07003880bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3881 CFX_WideString& wsValue,
3882 bool bUseDefault,
3883 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003884 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003885 if (eAttr == XFA_ATTRIBUTE_Value) {
3886 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
3887 if (pStr) {
3888 wsValue = *pStr;
tsepezd19e9122016-11-02 15:43:18 -07003889 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003890 }
3891 } else {
3892 CFX_WideStringC wsValueC;
3893 if (GetMapModuleString(pKey, wsValueC)) {
3894 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07003895 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003896 }
3897 }
3898 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07003899 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003900 }
weili44f8faf2016-06-01 14:03:56 -07003901 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07003902 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003903 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
Dan Sinclair812e96c2017-03-13 16:43:37 -04003904 wsValue = (const wchar_t*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003905 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003906 }
tsepezd19e9122016-11-02 15:43:18 -07003907 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003908}
dsinclair5b36f0a2016-07-19 10:56:23 -07003909
tsepezd19e9122016-11-02 15:43:18 -07003910bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3911 CFX_WideStringC& wsValue,
3912 bool bUseDefault,
3913 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003914 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003915 if (eAttr == XFA_ATTRIBUTE_Value) {
3916 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
3917 if (pStr) {
tsepez4d31d0c2016-04-19 14:11:59 -07003918 wsValue = pStr->AsStringC();
tsepezd19e9122016-11-02 15:43:18 -07003919 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003920 }
3921 } else {
3922 if (GetMapModuleString(pKey, wsValue)) {
tsepezd19e9122016-11-02 15:43:18 -07003923 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003924 }
3925 }
3926 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07003927 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003928 }
weili44f8faf2016-06-01 14:03:56 -07003929 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07003930 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003931 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
Dan Sinclair812e96c2017-03-13 16:43:37 -04003932 wsValue = (CFX_WideStringC)(const wchar_t*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003933 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003934 }
tsepezd19e9122016-11-02 15:43:18 -07003935 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003936}
dsinclair5b36f0a2016-07-19 10:56:23 -07003937
tsepezd19e9122016-11-02 15:43:18 -07003938bool CXFA_Node::SetObject(XFA_ATTRIBUTE eAttr,
3939 void* pData,
3940 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003941 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003942 return SetUserData(pKey, pData, pCallbackInfo);
3943}
dsinclair5b36f0a2016-07-19 10:56:23 -07003944
tsepezd19e9122016-11-02 15:43:18 -07003945bool CXFA_Node::TryObject(XFA_ATTRIBUTE eAttr, void*& pData) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003946 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003947 pData = GetUserData(pKey);
dsinclair85d1f2c2016-06-23 12:40:16 -07003948 return !!pData;
Dan Sinclair1770c022016-03-14 14:14:16 -04003949}
dsinclair5b36f0a2016-07-19 10:56:23 -07003950
tsepezd19e9122016-11-02 15:43:18 -07003951bool CXFA_Node::SetValue(XFA_ATTRIBUTE eAttr,
3952 XFA_ATTRIBUTETYPE eType,
3953 void* pValue,
3954 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003955 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003956 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003957 SetMapModuleValue(pKey, pValue);
tsepezd19e9122016-11-02 15:43:18 -07003958 OnChanged(eAttr, bNotify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003959 if (IsNeedSavingXMLNode()) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003960 ASSERT(m_pXMLNode->GetType() == FX_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04003961 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
3962 if (pInfo) {
3963 switch (eType) {
3964 case XFA_ATTRIBUTETYPE_Enum:
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003965 static_cast<CFX_XMLElement*>(m_pXMLNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04003966 ->SetString(
3967 pInfo->pName,
dsinclair9eb0db12016-07-21 12:01:39 -07003968 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)(uintptr_t)pValue)
Dan Sinclair1770c022016-03-14 14:14:16 -04003969 ->pName);
3970 break;
3971 case XFA_ATTRIBUTETYPE_Boolean:
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003972 static_cast<CFX_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003973 ->SetString(pInfo->pName, pValue ? L"1" : L"0");
Dan Sinclair1770c022016-03-14 14:14:16 -04003974 break;
Dan Sinclair5fa4e982017-04-05 11:48:21 -04003975 case XFA_ATTRIBUTETYPE_Integer: {
3976 CFX_WideString wsValue;
3977 wsValue.Format(
3978 L"%d", static_cast<int32_t>(reinterpret_cast<uintptr_t>(pValue)));
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003979 static_cast<CFX_XMLElement*>(m_pXMLNode)
Dan Sinclair5fa4e982017-04-05 11:48:21 -04003980 ->SetString(pInfo->pName, wsValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003981 break;
Dan Sinclair5fa4e982017-04-05 11:48:21 -04003982 }
Dan Sinclair1770c022016-03-14 14:14:16 -04003983 default:
dsinclair43854a52016-04-27 12:26:00 -07003984 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003985 }
3986 }
3987 }
tsepezd19e9122016-11-02 15:43:18 -07003988 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003989}
dsinclair5b36f0a2016-07-19 10:56:23 -07003990
tsepezd19e9122016-11-02 15:43:18 -07003991bool CXFA_Node::GetValue(XFA_ATTRIBUTE eAttr,
3992 XFA_ATTRIBUTETYPE eType,
3993 bool bUseDefault,
3994 void*& pValue) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003995 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003996 if (GetMapModuleValue(pKey, pValue)) {
tsepezd19e9122016-11-02 15:43:18 -07003997 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003998 }
3999 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07004000 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004001 }
dsinclair070fcdf2016-06-22 22:04:54 -07004002 return XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, eType,
Dan Sinclair1770c022016-03-14 14:14:16 -04004003 m_ePacket);
4004}
dsinclair5b36f0a2016-07-19 10:56:23 -07004005
tsepezd19e9122016-11-02 15:43:18 -07004006bool CXFA_Node::SetUserData(void* pKey,
4007 void* pData,
4008 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004009 SetMapModuleBuffer(pKey, &pData, sizeof(void*),
4010 pCallbackInfo ? pCallbackInfo : &gs_XFADefaultFreeData);
tsepezd19e9122016-11-02 15:43:18 -07004011 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004012}
dsinclair5b36f0a2016-07-19 10:56:23 -07004013
tsepezd19e9122016-11-02 15:43:18 -07004014bool CXFA_Node::TryUserData(void* pKey, void*& pData, bool bProtoAlso) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004015 int32_t iBytes = 0;
4016 if (!GetMapModuleBuffer(pKey, pData, iBytes, bProtoAlso)) {
tsepezd19e9122016-11-02 15:43:18 -07004017 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004018 }
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04004019 return iBytes == sizeof(void*) && memcpy(&pData, pData, iBytes);
Dan Sinclair1770c022016-03-14 14:14:16 -04004020}
dsinclair5b36f0a2016-07-19 10:56:23 -07004021
tsepezd19e9122016-11-02 15:43:18 -07004022bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent,
4023 const CFX_WideString& wsXMLValue,
4024 bool bNotify,
4025 bool bScriptModify,
4026 bool bSyncData) {
weili44f8faf2016-06-01 14:03:56 -07004027 CXFA_Node* pNode = nullptr;
4028 CXFA_Node* pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004029 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004030 case XFA_ObjectType::ContainerNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004031 if (XFA_FieldIsMultiListBox(this)) {
dsinclair56a8b192016-06-21 14:15:25 -07004032 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004033 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004034 ASSERT(pChildValue);
tsepezafe94302016-05-13 17:21:31 -07004035 pChildValue->SetCData(XFA_ATTRIBUTE_ContentType, L"text/xml");
Dan Sinclair1770c022016-03-14 14:14:16 -04004036 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004037 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004038 CXFA_Node* pBind = GetBindData();
4039 if (bSyncData && pBind) {
tsepez51709be2016-12-08 10:55:57 -08004040 std::vector<CFX_WideString> wsSaveTextArray;
Tom Sepezf8a94392017-03-14 12:13:22 -07004041 size_t iSize = 0;
Dan Sinclair1770c022016-03-14 14:14:16 -04004042 if (!wsContent.IsEmpty()) {
4043 int32_t iStart = 0;
4044 int32_t iLength = wsContent.GetLength();
4045 int32_t iEnd = wsContent.Find(L'\n', iStart);
4046 iEnd = (iEnd == -1) ? iLength : iEnd;
4047 while (iEnd >= iStart) {
tsepez51709be2016-12-08 10:55:57 -08004048 wsSaveTextArray.push_back(wsContent.Mid(iStart, iEnd - iStart));
Dan Sinclair1770c022016-03-14 14:14:16 -04004049 iStart = iEnd + 1;
4050 if (iStart >= iLength) {
4051 break;
4052 }
4053 iEnd = wsContent.Find(L'\n', iStart);
4054 if (iEnd < 0) {
tsepez51709be2016-12-08 10:55:57 -08004055 wsSaveTextArray.push_back(
4056 wsContent.Mid(iStart, iLength - iStart));
Dan Sinclair1770c022016-03-14 14:14:16 -04004057 }
4058 }
Tom Sepezf8a94392017-03-14 12:13:22 -07004059 iSize = wsSaveTextArray.size();
Dan Sinclair1770c022016-03-14 14:14:16 -04004060 }
4061 if (iSize == 0) {
4062 while (CXFA_Node* pChildNode =
4063 pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) {
4064 pBind->RemoveChild(pChildNode);
4065 }
4066 } else {
Tom Sepezf8a94392017-03-14 12:13:22 -07004067 std::vector<CXFA_Node*> valueNodes = pBind->GetNodeList(
4068 XFA_NODEFILTER_Children, XFA_Element::DataValue);
4069 size_t iDatas = valueNodes.size();
Dan Sinclair1770c022016-03-14 14:14:16 -04004070 if (iDatas < iSize) {
Tom Sepezf8a94392017-03-14 12:13:22 -07004071 size_t iAddNodes = iSize - iDatas;
weili44f8faf2016-06-01 14:03:56 -07004072 CXFA_Node* pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004073 while (iAddNodes-- > 0) {
4074 pValueNodes =
dsinclair56a8b192016-06-21 14:15:25 -07004075 pBind->CreateSamePacketNode(XFA_Element::DataValue);
tsepezafe94302016-05-13 17:21:31 -07004076 pValueNodes->SetCData(XFA_ATTRIBUTE_Name, L"value");
Dan Sinclair1770c022016-03-14 14:14:16 -04004077 pValueNodes->CreateXMLMappingNode();
4078 pBind->InsertChild(pValueNodes);
4079 }
weili44f8faf2016-06-01 14:03:56 -07004080 pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004081 } else if (iDatas > iSize) {
Tom Sepezf8a94392017-03-14 12:13:22 -07004082 size_t iDelNodes = iDatas - iSize;
Dan Sinclair1770c022016-03-14 14:14:16 -04004083 while (iDelNodes-- > 0) {
4084 pBind->RemoveChild(pBind->GetNodeItem(XFA_NODEITEM_FirstChild));
4085 }
4086 }
4087 int32_t i = 0;
4088 for (CXFA_Node* pValueNode =
4089 pBind->GetNodeItem(XFA_NODEITEM_FirstChild);
4090 pValueNode; pValueNode = pValueNode->GetNodeItem(
4091 XFA_NODEITEM_NextSibling)) {
4092 pValueNode->SetAttributeValue(wsSaveTextArray[i],
tsepezd19e9122016-11-02 15:43:18 -07004093 wsSaveTextArray[i], false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004094 i++;
4095 }
4096 }
Tom Sepezf8a94392017-03-14 12:13:22 -07004097 for (CXFA_Node* pArrayNode : pBind->GetBindItems()) {
4098 if (pArrayNode != this) {
4099 pArrayNode->SetScriptContent(wsContent, wsContent, bNotify,
4100 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004101 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004102 }
4103 }
4104 break;
dsinclair070fcdf2016-06-22 22:04:54 -07004105 } else if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004106 pNode = this;
4107 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004108 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004109 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004110 ASSERT(pChildValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04004111 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004112 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004113 }
4114 pBindNode = GetBindData();
4115 if (pBindNode && bSyncData) {
4116 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004117 bScriptModify, false);
Tom Sepezf8a94392017-03-14 12:13:22 -07004118 for (CXFA_Node* pArrayNode : pBindNode->GetBindItems()) {
4119 if (pArrayNode != this) {
4120 pArrayNode->SetScriptContent(wsContent, wsContent, bNotify, true,
4121 false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004122 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004123 }
4124 }
weili44f8faf2016-06-01 14:03:56 -07004125 pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004126 break;
4127 }
dsinclairc5a8f212016-06-20 11:11:12 -07004128 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004129 CFX_WideString wsContentType;
dsinclair070fcdf2016-06-22 22:04:54 -07004130 if (GetElementType() == XFA_Element::ExData) {
tsepezd19e9122016-11-02 15:43:18 -07004131 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
dan sinclair65c7c232017-02-02 14:05:30 -08004132 if (wsContentType == L"text/html") {
4133 wsContentType = L"";
tsepez4c3debb2016-04-08 12:20:38 -07004134 SetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04004135 }
4136 }
4137 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4138 if (!pContentRawDataNode) {
tsepez9f2970c2016-04-01 10:23:04 -07004139 pContentRawDataNode = CreateSamePacketNode(
dan sinclair65c7c232017-02-02 14:05:30 -08004140 (wsContentType == L"text/xml") ? XFA_Element::Sharpxml
4141 : XFA_Element::Sharptext);
Dan Sinclair1770c022016-03-14 14:14:16 -04004142 InsertChild(pContentRawDataNode);
4143 }
4144 return pContentRawDataNode->SetScriptContent(
4145 wsContent, wsXMLValue, bNotify, bScriptModify, bSyncData);
4146 } break;
dsinclairc5a8f212016-06-20 11:11:12 -07004147 case XFA_ObjectType::NodeC:
4148 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004149 pNode = this;
4150 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004151 case XFA_ObjectType::NodeV:
Dan Sinclair1770c022016-03-14 14:14:16 -04004152 pNode = this;
4153 if (bSyncData && GetPacketID() == XFA_XDPPACKET_Form) {
4154 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
4155 if (pParent) {
4156 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4157 }
dsinclair070fcdf2016-06-22 22:04:54 -07004158 if (pParent && pParent->GetElementType() == XFA_Element::Value) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004159 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4160 if (pParent && pParent->IsContainerNode()) {
4161 pBindNode = pParent->GetBindData();
4162 if (pBindNode) {
4163 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004164 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004165 }
4166 }
4167 }
4168 }
4169 break;
4170 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004171 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004172 pNode = this;
4173 pBindNode = this;
4174 }
4175 break;
4176 }
4177 if (pNode) {
4178 SetAttributeValue(wsContent, wsXMLValue, bNotify, bScriptModify);
4179 if (pBindNode && bSyncData) {
Tom Sepezf8a94392017-03-14 12:13:22 -07004180 for (CXFA_Node* pArrayNode : pBindNode->GetBindItems()) {
4181 pArrayNode->SetScriptContent(wsContent, wsContent, bNotify,
4182 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004183 }
4184 }
tsepezd19e9122016-11-02 15:43:18 -07004185 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004186 }
tsepezd19e9122016-11-02 15:43:18 -07004187 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004188}
dsinclair5b36f0a2016-07-19 10:56:23 -07004189
tsepezd19e9122016-11-02 15:43:18 -07004190bool CXFA_Node::SetContent(const CFX_WideString& wsContent,
4191 const CFX_WideString& wsXMLValue,
4192 bool bNotify,
4193 bool bScriptModify,
4194 bool bSyncData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004195 return SetScriptContent(wsContent, wsXMLValue, bNotify, bScriptModify,
4196 bSyncData);
4197}
dsinclair5b36f0a2016-07-19 10:56:23 -07004198
tsepezd19e9122016-11-02 15:43:18 -07004199CFX_WideString CXFA_Node::GetScriptContent(bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004200 CFX_WideString wsContent;
4201 return TryContent(wsContent, bScriptModify) ? wsContent : CFX_WideString();
4202}
dsinclair5b36f0a2016-07-19 10:56:23 -07004203
Dan Sinclair1770c022016-03-14 14:14:16 -04004204CFX_WideString CXFA_Node::GetContent() {
4205 return GetScriptContent();
4206}
dsinclair5b36f0a2016-07-19 10:56:23 -07004207
tsepezd19e9122016-11-02 15:43:18 -07004208bool CXFA_Node::TryContent(CFX_WideString& wsContent,
4209 bool bScriptModify,
4210 bool bProto) {
weili44f8faf2016-06-01 14:03:56 -07004211 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004212 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004213 case XFA_ObjectType::ContainerNode:
dsinclair070fcdf2016-06-22 22:04:54 -07004214 if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004215 pNode = this;
4216 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004217 CXFA_Node* pValue = GetChild(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004218 if (!pValue) {
tsepezd19e9122016-11-02 15:43:18 -07004219 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004220 }
4221 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
4222 if (pChildValue && XFA_FieldIsMultiListBox(this)) {
dan sinclair65c7c232017-02-02 14:05:30 -08004223 pChildValue->SetAttribute(XFA_ATTRIBUTE_ContentType, L"text/xml");
Dan Sinclair1770c022016-03-14 14:14:16 -04004224 }
4225 return pChildValue
4226 ? pChildValue->TryContent(wsContent, bScriptModify, bProto)
tsepezd19e9122016-11-02 15:43:18 -07004227 : false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004228 }
4229 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004230 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004231 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4232 if (!pContentRawDataNode) {
dsinclair56a8b192016-06-21 14:15:25 -07004233 XFA_Element element = XFA_Element::Sharptext;
dsinclair070fcdf2016-06-22 22:04:54 -07004234 if (GetElementType() == XFA_Element::ExData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004235 CFX_WideString wsContentType;
tsepezd19e9122016-11-02 15:43:18 -07004236 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
dan sinclair65c7c232017-02-02 14:05:30 -08004237 if (wsContentType == L"text/html") {
dsinclair56a8b192016-06-21 14:15:25 -07004238 element = XFA_Element::SharpxHTML;
dan sinclair65c7c232017-02-02 14:05:30 -08004239 } else if (wsContentType == L"text/xml") {
dsinclair56a8b192016-06-21 14:15:25 -07004240 element = XFA_Element::Sharpxml;
Dan Sinclair1770c022016-03-14 14:14:16 -04004241 }
4242 }
4243 pContentRawDataNode = CreateSamePacketNode(element);
4244 InsertChild(pContentRawDataNode);
4245 }
4246 return pContentRawDataNode->TryContent(wsContent, bScriptModify, bProto);
4247 }
dsinclairc5a8f212016-06-20 11:11:12 -07004248 case XFA_ObjectType::NodeC:
4249 case XFA_ObjectType::NodeV:
4250 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004251 pNode = this;
4252 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004253 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004254 pNode = this;
4255 }
4256 break;
4257 }
4258 if (pNode) {
4259 if (bScriptModify) {
dsinclairdf4bc592016-03-31 20:34:43 -07004260 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004261 if (pScriptContext) {
4262 m_pDocument->GetScriptContext()->AddNodesOfRunScript(this);
4263 }
4264 }
tsepezd19e9122016-11-02 15:43:18 -07004265 return TryCData(XFA_ATTRIBUTE_Value, wsContent, false, bProto);
Dan Sinclair1770c022016-03-14 14:14:16 -04004266 }
tsepezd19e9122016-11-02 15:43:18 -07004267 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004268}
dsinclair5b36f0a2016-07-19 10:56:23 -07004269
Dan Sinclair1770c022016-03-14 14:14:16 -04004270CXFA_Node* CXFA_Node::GetModelNode() {
4271 switch (GetPacketID()) {
4272 case XFA_XDPPACKET_XDP:
4273 return m_pDocument->GetRoot();
4274 case XFA_XDPPACKET_Config:
4275 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config));
4276 case XFA_XDPPACKET_Template:
4277 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
4278 case XFA_XDPPACKET_Form:
4279 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form));
4280 case XFA_XDPPACKET_Datasets:
4281 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets));
4282 case XFA_XDPPACKET_LocaleSet:
4283 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_LocaleSet));
4284 case XFA_XDPPACKET_ConnectionSet:
4285 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_ConnectionSet));
4286 case XFA_XDPPACKET_SourceSet:
4287 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_SourceSet));
4288 case XFA_XDPPACKET_Xdc:
4289 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Xdc));
4290 default:
4291 return this;
4292 }
4293}
dsinclair5b36f0a2016-07-19 10:56:23 -07004294
tsepezd19e9122016-11-02 15:43:18 -07004295bool CXFA_Node::TryNamespace(CFX_WideString& wsNamespace) {
tsepez774bdde2016-04-14 09:49:44 -07004296 wsNamespace.clear();
dsinclair070fcdf2016-06-22 22:04:54 -07004297 if (IsModelNode() || GetElementType() == XFA_Element::Packet) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004298 CFX_XMLNode* pXMLNode = GetXMLMappingNode();
4299 if (!pXMLNode || pXMLNode->GetType() != FX_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004300 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004301 }
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004302 wsNamespace = static_cast<CFX_XMLElement*>(pXMLNode)->GetNamespaceURI();
tsepezd19e9122016-11-02 15:43:18 -07004303 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004304 } else if (GetPacketID() == XFA_XDPPACKET_Datasets) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004305 CFX_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004306 if (!pXMLNode) {
tsepezd19e9122016-11-02 15:43:18 -07004307 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004308 }
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004309 if (pXMLNode->GetType() != FX_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004310 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004311 }
dsinclair070fcdf2016-06-22 22:04:54 -07004312 if (GetElementType() == XFA_Element::DataValue &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004313 GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData) {
4314 return XFA_FDEExtension_ResolveNamespaceQualifier(
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004315 static_cast<CFX_XMLElement*>(pXMLNode),
Dan Sinclair5fa4e982017-04-05 11:48:21 -04004316 GetCData(XFA_ATTRIBUTE_QualifiedName), &wsNamespace);
Dan Sinclair1770c022016-03-14 14:14:16 -04004317 }
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004318 wsNamespace = static_cast<CFX_XMLElement*>(pXMLNode)->GetNamespaceURI();
tsepezd19e9122016-11-02 15:43:18 -07004319 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004320 } else {
4321 CXFA_Node* pModelNode = GetModelNode();
4322 return pModelNode->TryNamespace(wsNamespace);
4323 }
4324}
dsinclair5b36f0a2016-07-19 10:56:23 -07004325
Dan Sinclair1770c022016-03-14 14:14:16 -04004326CXFA_Node* CXFA_Node::GetProperty(int32_t index,
dsinclair56a8b192016-06-21 14:15:25 -07004327 XFA_Element eProperty,
tsepezd19e9122016-11-02 15:43:18 -07004328 bool bCreateProperty) {
dsinclair41cb62e2016-06-23 09:20:32 -07004329 XFA_Element eType = GetElementType();
tsepez736f28a2016-03-25 14:19:51 -07004330 uint32_t dwPacket = GetPacketID();
Dan Sinclair1770c022016-03-14 14:14:16 -04004331 const XFA_PROPERTY* pProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004332 XFA_GetPropertyOfElement(eType, eProperty, dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004333 if (!pProperty || index >= pProperty->uOccur)
4334 return nullptr;
4335
Dan Sinclair1770c022016-03-14 14:14:16 -04004336 CXFA_Node* pNode = m_pChild;
4337 int32_t iCount = 0;
4338 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004339 if (pNode->GetElementType() == eProperty) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004340 iCount++;
4341 if (iCount > index) {
4342 return pNode;
4343 }
4344 }
4345 }
weili44f8faf2016-06-01 14:03:56 -07004346 if (!bCreateProperty)
4347 return nullptr;
4348
Dan Sinclair1770c022016-03-14 14:14:16 -04004349 if (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf) {
4350 pNode = m_pChild;
4351 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4352 const XFA_PROPERTY* pExistProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004353 XFA_GetPropertyOfElement(eType, pNode->GetElementType(), dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004354 if (pExistProperty && (pExistProperty->uFlags & XFA_PROPERTYFLAG_OneOf))
4355 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004356 }
4357 }
dsinclaira1b07722016-07-11 08:20:58 -07004358
Dan Sinclair1770c022016-03-14 14:14:16 -04004359 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(dwPacket);
weili038aa532016-05-20 15:38:29 -07004360 CXFA_Node* pNewNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004361 for (; iCount <= index; iCount++) {
dsinclaira1b07722016-07-11 08:20:58 -07004362 pNewNode = m_pDocument->CreateNode(pPacket, eProperty);
weili44f8faf2016-06-01 14:03:56 -07004363 if (!pNewNode)
4364 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004365 InsertChild(pNewNode, nullptr);
dsinclairc5a8f212016-06-20 11:11:12 -07004366 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004367 }
4368 return pNewNode;
4369}
dsinclair5b36f0a2016-07-19 10:56:23 -07004370
tsepezd19e9122016-11-02 15:43:18 -07004371int32_t CXFA_Node::CountChildren(XFA_Element eType, bool bOnlyChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004372 CXFA_Node* pNode = m_pChild;
4373 int32_t iCount = 0;
4374 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004375 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004376 if (bOnlyChild) {
4377 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004378 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004379 if (pProperty) {
4380 continue;
4381 }
4382 }
4383 iCount++;
4384 }
4385 }
4386 return iCount;
4387}
dsinclair5b36f0a2016-07-19 10:56:23 -07004388
Dan Sinclair1770c022016-03-14 14:14:16 -04004389CXFA_Node* CXFA_Node::GetChild(int32_t index,
dsinclair41cb62e2016-06-23 09:20:32 -07004390 XFA_Element eType,
tsepezd19e9122016-11-02 15:43:18 -07004391 bool bOnlyChild) {
dsinclair43854a52016-04-27 12:26:00 -07004392 ASSERT(index > -1);
Dan Sinclair1770c022016-03-14 14:14:16 -04004393 CXFA_Node* pNode = m_pChild;
4394 int32_t iCount = 0;
4395 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004396 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004397 if (bOnlyChild) {
4398 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004399 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004400 if (pProperty) {
4401 continue;
4402 }
4403 }
4404 iCount++;
4405 if (iCount > index) {
4406 return pNode;
4407 }
4408 }
4409 }
weili44f8faf2016-06-01 14:03:56 -07004410 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004411}
dsinclair5b36f0a2016-07-19 10:56:23 -07004412
Dan Sinclair1770c022016-03-14 14:14:16 -04004413int32_t CXFA_Node::InsertChild(int32_t index, CXFA_Node* pNode) {
4414 ASSERT(!pNode->m_pNext);
4415 pNode->m_pParent = this;
tsepezd19e9122016-11-02 15:43:18 -07004416 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004417 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004418 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004419
weili44f8faf2016-06-01 14:03:56 -07004420 if (!m_pChild || index == 0) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004421 if (index > 0) {
4422 return -1;
4423 }
4424 pNode->m_pNext = m_pChild;
4425 m_pChild = pNode;
4426 index = 0;
4427 } else if (index < 0) {
4428 m_pLastChild->m_pNext = pNode;
4429 } else {
4430 CXFA_Node* pPrev = m_pChild;
4431 int32_t iCount = 0;
4432 while (++iCount != index && pPrev->m_pNext) {
4433 pPrev = pPrev->m_pNext;
4434 }
4435 if (index > 0 && index != iCount) {
4436 return -1;
4437 }
4438 pNode->m_pNext = pPrev->m_pNext;
4439 pPrev->m_pNext = pNode;
4440 index = iCount;
4441 }
weili44f8faf2016-06-01 14:03:56 -07004442 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004443 m_pLastChild = pNode;
4444 }
4445 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004446 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004447 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004448 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004449 if (pNotify)
4450 pNotify->OnChildAdded(this);
4451
Dan Sinclair1770c022016-03-14 14:14:16 -04004452 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004453 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFX_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004454 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, index);
dsinclairc5a8f212016-06-20 11:11:12 -07004455 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004456 }
4457 return index;
4458}
weili6e1ae862016-05-04 18:25:27 -07004459
tsepezd19e9122016-11-02 15:43:18 -07004460bool CXFA_Node::InsertChild(CXFA_Node* pNode, CXFA_Node* pBeforeNode) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004461 if (!pNode || pNode->m_pParent ||
4462 (pBeforeNode && pBeforeNode->m_pParent != this)) {
dsinclair43854a52016-04-27 12:26:00 -07004463 ASSERT(false);
tsepezd19e9122016-11-02 15:43:18 -07004464 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004465 }
tsepezd19e9122016-11-02 15:43:18 -07004466 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004467 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004468 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004469
4470 int32_t nIndex = -1;
4471 pNode->m_pParent = this;
weili44f8faf2016-06-01 14:03:56 -07004472 if (!m_pChild || pBeforeNode == m_pChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004473 pNode->m_pNext = m_pChild;
4474 m_pChild = pNode;
4475 nIndex = 0;
4476 } else if (!pBeforeNode) {
4477 pNode->m_pNext = m_pLastChild->m_pNext;
4478 m_pLastChild->m_pNext = pNode;
4479 } else {
4480 nIndex = 1;
4481 CXFA_Node* pPrev = m_pChild;
4482 while (pPrev->m_pNext != pBeforeNode) {
4483 pPrev = pPrev->m_pNext;
4484 nIndex++;
4485 }
4486 pNode->m_pNext = pPrev->m_pNext;
4487 pPrev->m_pNext = pNode;
4488 }
weili44f8faf2016-06-01 14:03:56 -07004489 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004490 m_pLastChild = pNode;
4491 }
4492 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004493 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004494 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004495 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004496 if (pNotify)
4497 pNotify->OnChildAdded(this);
4498
Dan Sinclair1770c022016-03-14 14:14:16 -04004499 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004500 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFX_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004501 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, nIndex);
dsinclairc5a8f212016-06-20 11:11:12 -07004502 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004503 }
tsepezd19e9122016-11-02 15:43:18 -07004504 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004505}
dsinclair5b36f0a2016-07-19 10:56:23 -07004506
Dan Sinclair1770c022016-03-14 14:14:16 -04004507CXFA_Node* CXFA_Node::Deprecated_GetPrevSibling() {
4508 if (!m_pParent) {
weili44f8faf2016-06-01 14:03:56 -07004509 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004510 }
4511 for (CXFA_Node* pSibling = m_pParent->m_pChild; pSibling;
4512 pSibling = pSibling->m_pNext) {
4513 if (pSibling->m_pNext == this) {
4514 return pSibling;
4515 }
4516 }
weili44f8faf2016-06-01 14:03:56 -07004517 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004518}
dsinclair5b36f0a2016-07-19 10:56:23 -07004519
tsepezd19e9122016-11-02 15:43:18 -07004520bool CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) {
weili44f8faf2016-06-01 14:03:56 -07004521 if (!pNode || pNode->m_pParent != this) {
tsepezd19e9122016-11-02 15:43:18 -07004522 ASSERT(false);
4523 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004524 }
4525 if (m_pChild == pNode) {
4526 m_pChild = pNode->m_pNext;
4527 if (m_pLastChild == pNode) {
4528 m_pLastChild = pNode->m_pNext;
4529 }
weili44f8faf2016-06-01 14:03:56 -07004530 pNode->m_pNext = nullptr;
4531 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004532 } else {
4533 CXFA_Node* pPrev = pNode->Deprecated_GetPrevSibling();
4534 pPrev->m_pNext = pNode->m_pNext;
4535 if (m_pLastChild == pNode) {
4536 m_pLastChild = pNode->m_pNext ? pNode->m_pNext : pPrev;
4537 }
weili44f8faf2016-06-01 14:03:56 -07004538 pNode->m_pNext = nullptr;
4539 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004540 }
weili44f8faf2016-06-01 14:03:56 -07004541 ASSERT(!m_pLastChild || !m_pLastChild->m_pNext);
thestigb1a59592016-04-14 18:29:56 -07004542 OnRemoved(bNotify);
dsinclairc5a8f212016-06-20 11:11:12 -07004543 pNode->SetFlag(XFA_NodeFlag_HasRemovedChildren, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004544 m_pDocument->AddPurgeNode(pNode);
4545 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
4546 if (pNode->IsAttributeInXML()) {
dsinclair43854a52016-04-27 12:26:00 -07004547 ASSERT(pNode->m_pXMLNode == m_pXMLNode &&
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004548 m_pXMLNode->GetType() == FX_XMLNODE_Element);
4549 if (pNode->m_pXMLNode->GetType() == FX_XMLNODE_Element) {
4550 CFX_XMLElement* pXMLElement =
4551 static_cast<CFX_XMLElement*>(pNode->m_pXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004552 CFX_WideStringC wsAttributeName =
4553 pNode->GetCData(XFA_ATTRIBUTE_QualifiedName);
tsepez660956f2016-04-06 06:27:29 -07004554 pXMLElement->RemoveAttribute(wsAttributeName.c_str());
Dan Sinclair1770c022016-03-14 14:14:16 -04004555 }
4556 CFX_WideString wsName;
tsepezd19e9122016-11-02 15:43:18 -07004557 pNode->GetAttribute(XFA_ATTRIBUTE_Name, wsName, false);
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004558 CFX_XMLElement* pNewXMLElement = new CFX_XMLElement(wsName);
Dan Sinclair1770c022016-03-14 14:14:16 -04004559 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
4560 if (!wsValue.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07004561 pNewXMLElement->SetTextData(CFX_WideString(wsValue));
Dan Sinclair1770c022016-03-14 14:14:16 -04004562 }
4563 pNode->m_pXMLNode = pNewXMLElement;
4564 pNode->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
4565 } else {
4566 m_pXMLNode->RemoveChildNode(pNode->m_pXMLNode);
4567 }
dsinclairc5a8f212016-06-20 11:11:12 -07004568 pNode->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004569 }
tsepezd19e9122016-11-02 15:43:18 -07004570 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004571}
dsinclair5b36f0a2016-07-19 10:56:23 -07004572
Dan Sinclair1770c022016-03-14 14:14:16 -04004573CXFA_Node* CXFA_Node::GetFirstChildByName(const CFX_WideStringC& wsName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004574 return GetFirstChildByName(FX_HashCode_GetW(wsName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004575}
dsinclair5b36f0a2016-07-19 10:56:23 -07004576
tsepez736f28a2016-03-25 14:19:51 -07004577CXFA_Node* CXFA_Node::GetFirstChildByName(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004578 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4579 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4580 if (pNode->GetNameHash() == dwNameHash) {
4581 return pNode;
4582 }
4583 }
weili44f8faf2016-06-01 14:03:56 -07004584 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004585}
dsinclair5b36f0a2016-07-19 10:56:23 -07004586
dsinclair41cb62e2016-06-23 09:20:32 -07004587CXFA_Node* CXFA_Node::GetFirstChildByClass(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004588 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4589 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004590 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004591 return pNode;
4592 }
4593 }
weili44f8faf2016-06-01 14:03:56 -07004594 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004595}
dsinclair5b36f0a2016-07-19 10:56:23 -07004596
tsepez736f28a2016-03-25 14:19:51 -07004597CXFA_Node* CXFA_Node::GetNextSameNameSibling(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004598 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4599 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4600 if (pNode->GetNameHash() == dwNameHash) {
4601 return pNode;
4602 }
4603 }
weili44f8faf2016-06-01 14:03:56 -07004604 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004605}
dsinclair5b36f0a2016-07-19 10:56:23 -07004606
Dan Sinclair1770c022016-03-14 14:14:16 -04004607CXFA_Node* CXFA_Node::GetNextSameNameSibling(
4608 const CFX_WideStringC& wsNodeName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004609 return GetNextSameNameSibling(FX_HashCode_GetW(wsNodeName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004610}
dsinclair5b36f0a2016-07-19 10:56:23 -07004611
dsinclair41cb62e2016-06-23 09:20:32 -07004612CXFA_Node* CXFA_Node::GetNextSameClassSibling(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004613 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4614 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004615 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004616 return pNode;
4617 }
4618 }
weili44f8faf2016-06-01 14:03:56 -07004619 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004620}
dsinclair5b36f0a2016-07-19 10:56:23 -07004621
Dan Sinclair1770c022016-03-14 14:14:16 -04004622int32_t CXFA_Node::GetNodeSameNameIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004623 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004624 if (!pScriptContext) {
4625 return -1;
4626 }
4627 return pScriptContext->GetIndexByName(const_cast<CXFA_Node*>(this));
4628}
dsinclair5b36f0a2016-07-19 10:56:23 -07004629
Dan Sinclair1770c022016-03-14 14:14:16 -04004630int32_t CXFA_Node::GetNodeSameClassIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004631 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004632 if (!pScriptContext) {
4633 return -1;
4634 }
4635 return pScriptContext->GetIndexByClassName(const_cast<CXFA_Node*>(this));
4636}
dsinclair5b36f0a2016-07-19 10:56:23 -07004637
Dan Sinclair1770c022016-03-14 14:14:16 -04004638void CXFA_Node::GetSOMExpression(CFX_WideString& wsSOMExpression) {
dsinclairdf4bc592016-03-31 20:34:43 -07004639 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004640 if (!pScriptContext) {
4641 return;
4642 }
4643 pScriptContext->GetSomExpression(this, wsSOMExpression);
4644}
dsinclair5b36f0a2016-07-19 10:56:23 -07004645
Dan Sinclair1770c022016-03-14 14:14:16 -04004646CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() {
weili44f8faf2016-06-01 14:03:56 -07004647 CXFA_Node* pInstanceMgr = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004648 if (m_ePacket == XFA_XDPPACKET_Form) {
4649 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07004650 if (!pParentNode || pParentNode->GetElementType() == XFA_Element::Area) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004651 return pInstanceMgr;
4652 }
4653 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
4654 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004655 XFA_Element eType = pNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07004656 if ((eType == XFA_Element::Subform || eType == XFA_Element::SubformSet) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004657 pNode->m_dwNameHash != m_dwNameHash) {
4658 break;
4659 }
dsinclair56a8b192016-06-21 14:15:25 -07004660 if (eType == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004661 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
4662 CFX_WideStringC wsInstName = pNode->GetCData(XFA_ATTRIBUTE_Name);
4663 if (wsInstName.GetLength() > 0 && wsInstName.GetAt(0) == '_' &&
4664 wsInstName.Mid(1) == wsName) {
4665 pInstanceMgr = pNode;
4666 }
4667 break;
4668 }
4669 }
4670 }
4671 return pInstanceMgr;
4672}
dsinclair5b36f0a2016-07-19 10:56:23 -07004673
Dan Sinclair1770c022016-03-14 14:14:16 -04004674CXFA_Node* CXFA_Node::GetOccurNode() {
dsinclair56a8b192016-06-21 14:15:25 -07004675 return GetFirstChildByClass(XFA_Element::Occur);
Dan Sinclair1770c022016-03-14 14:14:16 -04004676}
dsinclair5b36f0a2016-07-19 10:56:23 -07004677
dsinclairc5a8f212016-06-20 11:11:12 -07004678bool CXFA_Node::HasFlag(XFA_NodeFlag dwFlag) const {
4679 if (m_uNodeFlags & dwFlag)
4680 return true;
4681 if (dwFlag == XFA_NodeFlag_HasRemovedChildren)
4682 return m_pParent && m_pParent->HasFlag(dwFlag);
4683 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004684}
thestigb1a59592016-04-14 18:29:56 -07004685
4686void CXFA_Node::SetFlag(uint32_t dwFlag, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004687 if (dwFlag == XFA_NodeFlag_Initialized && bNotify && !IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004688 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004689 if (pNotify) {
4690 pNotify->OnNodeReady(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04004691 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004692 }
dsinclairc5a8f212016-06-20 11:11:12 -07004693 m_uNodeFlags |= dwFlag;
Dan Sinclair1770c022016-03-14 14:14:16 -04004694}
thestigb1a59592016-04-14 18:29:56 -07004695
4696void CXFA_Node::ClearFlag(uint32_t dwFlag) {
dsinclairc5a8f212016-06-20 11:11:12 -07004697 m_uNodeFlags &= ~dwFlag;
thestigb1a59592016-04-14 18:29:56 -07004698}
4699
tsepezd19e9122016-11-02 15:43:18 -07004700bool CXFA_Node::IsAttributeInXML() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004701 return GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData;
4702}
thestigb1a59592016-04-14 18:29:56 -07004703
4704void CXFA_Node::OnRemoved(bool bNotify) {
4705 if (!bNotify)
4706 return;
4707
dsinclaira1b07722016-07-11 08:20:58 -07004708 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004709 if (pNotify)
4710 pNotify->OnChildRemoved();
Dan Sinclair1770c022016-03-14 14:14:16 -04004711}
thestigb1a59592016-04-14 18:29:56 -07004712
4713void CXFA_Node::OnChanging(XFA_ATTRIBUTE eAttr, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004714 if (bNotify && IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004715 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004716 if (pNotify) {
thestigb1a59592016-04-14 18:29:56 -07004717 pNotify->OnValueChanging(this, eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004718 }
4719 }
4720}
thestigb1a59592016-04-14 18:29:56 -07004721
Dan Sinclair1770c022016-03-14 14:14:16 -04004722void CXFA_Node::OnChanged(XFA_ATTRIBUTE eAttr,
thestigb1a59592016-04-14 18:29:56 -07004723 bool bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004724 bool bScriptModify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004725 if (bNotify && IsInitialized()) {
thestigb1a59592016-04-14 18:29:56 -07004726 Script_Attribute_SendAttributeChangeMessage(eAttr, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04004727 }
4728}
thestigb1a59592016-04-14 18:29:56 -07004729
Dan Sinclair1770c022016-03-14 14:14:16 -04004730int32_t CXFA_Node::execSingleEventByName(const CFX_WideStringC& wsEventName,
dsinclair41cb62e2016-06-23 09:20:32 -07004731 XFA_Element eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004732 int32_t iRet = XFA_EVENTERROR_NotExist;
4733 const XFA_ExecEventParaInfo* eventParaInfo =
4734 GetEventParaInfoByName(wsEventName);
4735 if (eventParaInfo) {
4736 uint32_t validFlags = eventParaInfo->m_validFlags;
dsinclaira1b07722016-07-11 08:20:58 -07004737 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004738 if (!pNotify) {
4739 return iRet;
4740 }
4741 if (validFlags == 1) {
4742 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType);
4743 } else if (validFlags == 2) {
4744 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004745 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004746 } else if (validFlags == 3) {
dsinclair41cb62e2016-06-23 09:20:32 -07004747 if (eType == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004748 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004749 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004750 }
4751 } else if (validFlags == 4) {
dsinclair41cb62e2016-06-23 09:20:32 -07004752 if (eType == XFA_Element::ExclGroup || eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004753 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair56a8b192016-06-21 14:15:25 -07004754 if (pParentNode &&
dsinclair070fcdf2016-06-22 22:04:54 -07004755 pParentNode->GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004756 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004757 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004758 }
4759 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004760 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004761 }
4762 } else if (validFlags == 5) {
dsinclair41cb62e2016-06-23 09:20:32 -07004763 if (eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004764 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004765 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004766 }
4767 } else if (validFlags == 6) {
4768 CXFA_WidgetData* pWidgetData = GetWidgetData();
4769 if (pWidgetData) {
4770 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004771 if (pUINode->m_elementType == XFA_Element::Signature) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004772 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004773 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004774 }
4775 }
4776 } else if (validFlags == 7) {
4777 CXFA_WidgetData* pWidgetData = GetWidgetData();
4778 if (pWidgetData) {
4779 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004780 if ((pUINode->m_elementType == XFA_Element::ChoiceList) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004781 (!pWidgetData->IsListBox())) {
4782 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004783 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004784 }
4785 }
4786 }
4787 }
4788 return iRet;
4789}
dsinclair5b36f0a2016-07-19 10:56:23 -07004790
Dan Sinclair1770c022016-03-14 14:14:16 -04004791void CXFA_Node::UpdateNameHash() {
4792 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07004793 XFA_GetNotsureAttribute(GetElementType(), XFA_ATTRIBUTE_Name);
tsepezb6853cf2016-04-25 11:23:43 -07004794 CFX_WideStringC wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04004795 if (!pNotsure || pNotsure->eType == XFA_ATTRIBUTETYPE_Cdata) {
tsepezb6853cf2016-04-25 11:23:43 -07004796 wsName = GetCData(XFA_ATTRIBUTE_Name);
4797 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004798 } else if (pNotsure->eType == XFA_ATTRIBUTETYPE_Enum) {
dsinclair9eb0db12016-07-21 12:01:39 -07004799 wsName = GetAttributeEnumByID(GetEnum(XFA_ATTRIBUTE_Name))->pName;
tsepezb6853cf2016-04-25 11:23:43 -07004800 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004801 }
4802}
dsinclair5b36f0a2016-07-19 10:56:23 -07004803
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004804CFX_XMLNode* CXFA_Node::CreateXMLMappingNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004805 if (!m_pXMLNode) {
tsepezafe94302016-05-13 17:21:31 -07004806 CFX_WideString wsTag(GetCData(XFA_ATTRIBUTE_Name));
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004807 m_pXMLNode = new CFX_XMLElement(wsTag);
dsinclairc5a8f212016-06-20 11:11:12 -07004808 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004809 }
4810 return m_pXMLNode;
4811}
dsinclair5b36f0a2016-07-19 10:56:23 -07004812
tsepezd19e9122016-11-02 15:43:18 -07004813bool CXFA_Node::IsNeedSavingXMLNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004814 return m_pXMLNode && (GetPacketID() == XFA_XDPPACKET_Datasets ||
dsinclair070fcdf2016-06-22 22:04:54 -07004815 GetElementType() == XFA_Element::Xfa);
Dan Sinclair1770c022016-03-14 14:14:16 -04004816}
4817
4818XFA_MAPMODULEDATA* CXFA_Node::CreateMapModuleData() {
4819 if (!m_pMapModuleData)
4820 m_pMapModuleData = new XFA_MAPMODULEDATA;
4821 return m_pMapModuleData;
4822}
4823
4824XFA_MAPMODULEDATA* CXFA_Node::GetMapModuleData() const {
4825 return m_pMapModuleData;
4826}
4827
4828void CXFA_Node::SetMapModuleValue(void* pKey, void* pValue) {
4829 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004830 pModule->m_ValueMap[pKey] = pValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04004831}
4832
tsepezd19e9122016-11-02 15:43:18 -07004833bool CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) {
tsepez6bb3b892017-01-05 12:18:41 -08004834 for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004835 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004836 if (pModule) {
4837 auto it = pModule->m_ValueMap.find(pKey);
4838 if (it != pModule->m_ValueMap.end()) {
4839 pValue = it->second;
4840 return true;
4841 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004842 }
tsepez6bb3b892017-01-05 12:18:41 -08004843 if (pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4844 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004845 }
tsepezd19e9122016-11-02 15:43:18 -07004846 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004847}
dsinclair5b36f0a2016-07-19 10:56:23 -07004848
Dan Sinclair1770c022016-03-14 14:14:16 -04004849void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) {
tsepez660956f2016-04-06 06:27:29 -07004850 SetMapModuleBuffer(pKey, (void*)wsValue.c_str(),
Dan Sinclair812e96c2017-03-13 16:43:37 -04004851 wsValue.GetLength() * sizeof(wchar_t));
Dan Sinclair1770c022016-03-14 14:14:16 -04004852}
dsinclair5b36f0a2016-07-19 10:56:23 -07004853
tsepezd19e9122016-11-02 15:43:18 -07004854bool CXFA_Node::GetMapModuleString(void* pKey, CFX_WideStringC& wsValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004855 void* pValue;
4856 int32_t iBytes;
4857 if (!GetMapModuleBuffer(pKey, pValue, iBytes)) {
tsepezd19e9122016-11-02 15:43:18 -07004858 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004859 }
Dan Sinclair812e96c2017-03-13 16:43:37 -04004860 wsValue = CFX_WideStringC((const wchar_t*)pValue, iBytes / sizeof(wchar_t));
tsepezd19e9122016-11-02 15:43:18 -07004861 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004862}
dsinclair5b36f0a2016-07-19 10:56:23 -07004863
Dan Sinclair1770c022016-03-14 14:14:16 -04004864void CXFA_Node::SetMapModuleBuffer(
4865 void* pKey,
4866 void* pValue,
4867 int32_t iBytes,
4868 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
4869 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
4870 XFA_MAPDATABLOCK*& pBuffer = pModule->m_BufferMap[pKey];
weili44f8faf2016-06-01 14:03:56 -07004871 if (!pBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004872 pBuffer =
4873 (XFA_MAPDATABLOCK*)FX_Alloc(uint8_t, sizeof(XFA_MAPDATABLOCK) + iBytes);
4874 } else if (pBuffer->iBytes != iBytes) {
4875 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4876 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4877 }
4878 pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(uint8_t, pBuffer,
4879 sizeof(XFA_MAPDATABLOCK) + iBytes);
4880 } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4881 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4882 }
weili44f8faf2016-06-01 14:03:56 -07004883 if (!pBuffer)
Dan Sinclair1770c022016-03-14 14:14:16 -04004884 return;
weili44f8faf2016-06-01 14:03:56 -07004885
Dan Sinclair1770c022016-03-14 14:14:16 -04004886 pBuffer->pCallbackInfo = pCallbackInfo;
4887 pBuffer->iBytes = iBytes;
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04004888 memcpy(pBuffer->GetData(), pValue, iBytes);
Dan Sinclair1770c022016-03-14 14:14:16 -04004889}
dsinclair5b36f0a2016-07-19 10:56:23 -07004890
tsepezd19e9122016-11-02 15:43:18 -07004891bool CXFA_Node::GetMapModuleBuffer(void* pKey,
4892 void*& pValue,
4893 int32_t& iBytes,
4894 bool bProtoAlso) const {
weili44f8faf2016-06-01 14:03:56 -07004895 XFA_MAPDATABLOCK* pBuffer = nullptr;
tsepez6bb3b892017-01-05 12:18:41 -08004896 for (const CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004897 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004898 if (pModule) {
4899 auto it = pModule->m_BufferMap.find(pKey);
4900 if (it != pModule->m_BufferMap.end()) {
4901 pBuffer = it->second;
4902 break;
4903 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004904 }
tsepez6bb3b892017-01-05 12:18:41 -08004905 if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4906 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004907 }
tsepez6bb3b892017-01-05 12:18:41 -08004908 if (!pBuffer)
tsepezd19e9122016-11-02 15:43:18 -07004909 return false;
tsepez6bb3b892017-01-05 12:18:41 -08004910
Dan Sinclair1770c022016-03-14 14:14:16 -04004911 pValue = pBuffer->GetData();
4912 iBytes = pBuffer->iBytes;
tsepezd19e9122016-11-02 15:43:18 -07004913 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004914}
dsinclair5b36f0a2016-07-19 10:56:23 -07004915
tsepezd19e9122016-11-02 15:43:18 -07004916bool CXFA_Node::HasMapModuleKey(void* pKey, bool bProtoAlso) {
tsepez6bb3b892017-01-05 12:18:41 -08004917 for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004918 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004919 if (pModule) {
4920 auto it1 = pModule->m_ValueMap.find(pKey);
4921 if (it1 != pModule->m_ValueMap.end())
4922 return true;
4923
4924 auto it2 = pModule->m_BufferMap.find(pKey);
4925 if (it2 != pModule->m_BufferMap.end())
4926 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004927 }
tsepez6bb3b892017-01-05 12:18:41 -08004928 if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4929 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004930 }
tsepezd19e9122016-11-02 15:43:18 -07004931 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004932}
dsinclair5b36f0a2016-07-19 10:56:23 -07004933
Dan Sinclair1770c022016-03-14 14:14:16 -04004934void CXFA_Node::RemoveMapModuleKey(void* pKey) {
4935 XFA_MAPMODULEDATA* pModule = GetMapModuleData();
4936 if (!pModule)
4937 return;
4938
4939 if (pKey) {
tsepez6bb3b892017-01-05 12:18:41 -08004940 auto it = pModule->m_BufferMap.find(pKey);
4941 if (it != pModule->m_BufferMap.end()) {
4942 XFA_MAPDATABLOCK* pBuffer = it->second;
Dan Sinclair1770c022016-03-14 14:14:16 -04004943 if (pBuffer) {
tsepez6bb3b892017-01-05 12:18:41 -08004944 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree)
Dan Sinclair1770c022016-03-14 14:14:16 -04004945 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04004946 FX_Free(pBuffer);
4947 }
tsepez6bb3b892017-01-05 12:18:41 -08004948 pModule->m_BufferMap.erase(it);
Dan Sinclair1770c022016-03-14 14:14:16 -04004949 }
tsepez6bb3b892017-01-05 12:18:41 -08004950 pModule->m_ValueMap.erase(pKey);
4951 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04004952 }
tsepez6bb3b892017-01-05 12:18:41 -08004953
4954 for (auto& pair : pModule->m_BufferMap) {
4955 XFA_MAPDATABLOCK* pBuffer = pair.second;
4956 if (pBuffer) {
4957 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree)
4958 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4959 FX_Free(pBuffer);
4960 }
4961 }
4962 pModule->m_BufferMap.clear();
4963 pModule->m_ValueMap.clear();
4964 delete pModule;
Dan Sinclair1770c022016-03-14 14:14:16 -04004965}
dsinclair5b36f0a2016-07-19 10:56:23 -07004966
tsepez6bb3b892017-01-05 12:18:41 -08004967void CXFA_Node::MergeAllData(void* pDstModule) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004968 XFA_MAPMODULEDATA* pDstModuleData =
4969 static_cast<CXFA_Node*>(pDstModule)->CreateMapModuleData();
4970 XFA_MAPMODULEDATA* pSrcModuleData = GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004971 if (!pSrcModuleData)
Dan Sinclair1770c022016-03-14 14:14:16 -04004972 return;
tsepez6bb3b892017-01-05 12:18:41 -08004973
4974 for (const auto& pair : pSrcModuleData->m_ValueMap)
4975 pDstModuleData->m_ValueMap[pair.first] = pair.second;
4976
4977 for (const auto& pair : pSrcModuleData->m_BufferMap) {
4978 XFA_MAPDATABLOCK* pSrcBuffer = pair.second;
4979 XFA_MAPDATABLOCK*& pDstBuffer = pDstModuleData->m_BufferMap[pair.first];
Dan Sinclair1770c022016-03-14 14:14:16 -04004980 if (pSrcBuffer->pCallbackInfo && pSrcBuffer->pCallbackInfo->pFree &&
4981 !pSrcBuffer->pCallbackInfo->pCopy) {
tsepez6bb3b892017-01-05 12:18:41 -08004982 if (pDstBuffer) {
4983 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
4984 pDstModuleData->m_BufferMap.erase(pair.first);
Dan Sinclair1770c022016-03-14 14:14:16 -04004985 }
4986 continue;
4987 }
tsepez6bb3b892017-01-05 12:18:41 -08004988 if (!pDstBuffer) {
4989 pDstBuffer = (XFA_MAPDATABLOCK*)FX_Alloc(
Dan Sinclair1770c022016-03-14 14:14:16 -04004990 uint8_t, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
tsepez6bb3b892017-01-05 12:18:41 -08004991 } else if (pDstBuffer->iBytes != pSrcBuffer->iBytes) {
4992 if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) {
4993 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04004994 }
tsepez6bb3b892017-01-05 12:18:41 -08004995 pDstBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(
4996 uint8_t, pDstBuffer, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
4997 } else if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) {
4998 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04004999 }
tsepez6bb3b892017-01-05 12:18:41 -08005000 if (!pDstBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005001 continue;
5002 }
tsepez6bb3b892017-01-05 12:18:41 -08005003 pDstBuffer->pCallbackInfo = pSrcBuffer->pCallbackInfo;
5004 pDstBuffer->iBytes = pSrcBuffer->iBytes;
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04005005 memcpy(pDstBuffer->GetData(), pSrcBuffer->GetData(), pSrcBuffer->iBytes);
tsepez6bb3b892017-01-05 12:18:41 -08005006 if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pCopy) {
5007 pDstBuffer->pCallbackInfo->pCopy(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005008 }
5009 }
5010}
dsinclair5b36f0a2016-07-19 10:56:23 -07005011
Dan Sinclair1770c022016-03-14 14:14:16 -04005012void CXFA_Node::MoveBufferMapData(CXFA_Node* pDstModule, void* pKey) {
5013 if (!pDstModule) {
5014 return;
5015 }
tsepezd19e9122016-11-02 15:43:18 -07005016 bool bNeedMove = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04005017 if (!pKey) {
tsepezd19e9122016-11-02 15:43:18 -07005018 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005019 }
dsinclair070fcdf2016-06-22 22:04:54 -07005020 if (pDstModule->GetElementType() != GetElementType()) {
tsepezd19e9122016-11-02 15:43:18 -07005021 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005022 }
weili44f8faf2016-06-01 14:03:56 -07005023 XFA_MAPMODULEDATA* pSrcModuleData = nullptr;
5024 XFA_MAPMODULEDATA* pDstModuleData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005025 if (bNeedMove) {
5026 pSrcModuleData = GetMapModuleData();
5027 if (!pSrcModuleData) {
tsepezd19e9122016-11-02 15:43:18 -07005028 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005029 }
5030 pDstModuleData = pDstModule->CreateMapModuleData();
5031 }
5032 if (bNeedMove) {
tsepez6bb3b892017-01-05 12:18:41 -08005033 auto it = pSrcModuleData->m_BufferMap.find(pKey);
5034 if (it != pSrcModuleData->m_BufferMap.end()) {
5035 XFA_MAPDATABLOCK* pBufferBlockData = it->second;
5036 if (pBufferBlockData) {
5037 pSrcModuleData->m_BufferMap.erase(pKey);
5038 pDstModuleData->m_BufferMap[pKey] = pBufferBlockData;
5039 }
Dan Sinclair1770c022016-03-14 14:14:16 -04005040 }
5041 }
dsinclairc5a8f212016-06-20 11:11:12 -07005042 if (pDstModule->IsNodeV()) {
tsepezd19e9122016-11-02 15:43:18 -07005043 CFX_WideString wsValue = pDstModule->GetScriptContent(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04005044 CFX_WideString wsFormatValue(wsValue);
5045 CXFA_WidgetData* pWidgetData = pDstModule->GetContainerWidgetData();
5046 if (pWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07005047 pWidgetData->GetFormatDataValue(wsValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04005048 }
tsepezd19e9122016-11-02 15:43:18 -07005049 pDstModule->SetScriptContent(wsValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005050 }
5051}
dsinclair5b36f0a2016-07-19 10:56:23 -07005052
Dan Sinclair1770c022016-03-14 14:14:16 -04005053void CXFA_Node::MoveBufferMapData(CXFA_Node* pSrcModule,
5054 CXFA_Node* pDstModule,
5055 void* pKey,
tsepezd19e9122016-11-02 15:43:18 -07005056 bool bRecursive) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005057 if (!pSrcModule || !pDstModule || !pKey) {
5058 return;
5059 }
5060 if (bRecursive) {
5061 CXFA_Node* pSrcChild = pSrcModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5062 CXFA_Node* pDstChild = pDstModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5063 for (; pSrcChild && pDstChild;
5064 pSrcChild = pSrcChild->GetNodeItem(XFA_NODEITEM_NextSibling),
5065 pDstChild = pDstChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
tsepezd19e9122016-11-02 15:43:18 -07005066 MoveBufferMapData(pSrcChild, pDstChild, pKey, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005067 }
5068 }
5069 pSrcModule->MoveBufferMapData(pDstModule, pKey);
5070}
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05005071
5072void CXFA_Node::ThrowMissingPropertyException(
5073 const CFX_WideString& obj,
5074 const CFX_WideString& prop) const {
5075 ThrowException(L"'%s' doesn't have property '%s'.", obj.c_str(),
5076 prop.c_str());
5077}
5078
5079void CXFA_Node::ThrowTooManyOccurancesException(
5080 const CFX_WideString& obj) const {
5081 ThrowException(
5082 L"The element [%s] has violated its allowable number of occurrences.",
5083 obj.c_str());
5084}