blob: e7ec4cf8903397a5edb5aebeea35944bad611fb4 [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"
Lei Zhangb45324b2017-05-22 17:05:40 -070023#include "third_party/base/logging.h"
tsepeza9caab92016-12-14 05:57:10 -080024#include "third_party/base/ptr_util.h"
tsepezaadedf92016-05-12 10:08:06 -070025#include "third_party/base/stl_util.h"
dsinclairdf4bc592016-03-31 20:34:43 -070026#include "xfa/fxfa/app/xfa_ffnotify.h"
dsinclair5b493092016-09-29 20:20:24 -070027#include "xfa/fxfa/cxfa_eventparam.h"
Dan Sinclairefcae5d2017-03-29 14:47:46 -040028#include "xfa/fxfa/cxfa_ffwidget.h"
29#include "xfa/fxfa/parser/cxfa_arraynodelist.h"
30#include "xfa/fxfa/parser/cxfa_attachnodelist.h"
dsinclair16280242016-07-21 12:03:47 -070031#include "xfa/fxfa/parser/cxfa_document.h"
dsinclair0b851ff2016-07-21 12:03:01 -070032#include "xfa/fxfa/parser/cxfa_layoutprocessor.h"
dsinclair9eb0db12016-07-21 12:01:39 -070033#include "xfa/fxfa/parser/cxfa_measurement.h"
dsinclair44d054c2016-04-06 10:23:46 -070034#include "xfa/fxfa/parser/cxfa_occur.h"
dsinclair31f87402016-07-20 06:34:45 -070035#include "xfa/fxfa/parser/cxfa_scriptcontext.h"
dsinclair34f86b02016-07-11 08:42:33 -070036#include "xfa/fxfa/parser/cxfa_simple_parser.h"
Dan Sinclairefcae5d2017-03-29 14:47:46 -040037#include "xfa/fxfa/parser/cxfa_traversestrategy_xfacontainernode.h"
dsinclair5b36f0a2016-07-19 10:56:23 -070038#include "xfa/fxfa/parser/xfa_basic_data.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040039
weili44f8faf2016-06-01 14:03:56 -070040namespace {
41
42void XFA_DeleteWideString(void* pData) {
43 delete static_cast<CFX_WideString*>(pData);
44}
45
46void XFA_CopyWideString(void*& pData) {
47 if (pData) {
48 CFX_WideString* pNewData = new CFX_WideString(*(CFX_WideString*)pData);
49 pData = pNewData;
50 }
51}
52
53XFA_MAPDATABLOCKCALLBACKINFO deleteWideStringCallBack = {XFA_DeleteWideString,
54 XFA_CopyWideString};
55
weili44f8faf2016-06-01 14:03:56 -070056void XFA_DataNodeDeleteBindItem(void* pData) {
Tom Sepezf8a94392017-03-14 12:13:22 -070057 delete static_cast<std::vector<CXFA_Node*>*>(pData);
weili44f8faf2016-06-01 14:03:56 -070058}
59
60XFA_MAPDATABLOCKCALLBACKINFO deleteBindItemCallBack = {
61 XFA_DataNodeDeleteBindItem, nullptr};
62
dsinclair5b36f0a2016-07-19 10:56:23 -070063int32_t GetCount(CXFA_Node* pInstMgrNode) {
64 ASSERT(pInstMgrNode);
65 int32_t iCount = 0;
66 uint32_t dwNameHash = 0;
67 for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
68 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
69 XFA_Element eCurType = pNode->GetElementType();
70 if (eCurType == XFA_Element::InstanceManager)
71 break;
72 if ((eCurType != XFA_Element::Subform) &&
73 (eCurType != XFA_Element::SubformSet)) {
74 continue;
75 }
76 if (iCount == 0) {
77 CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
78 CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
79 if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
80 wsInstName.Mid(1) != wsName) {
81 return iCount;
82 }
83 dwNameHash = pNode->GetNameHash();
84 }
85 if (dwNameHash != pNode->GetNameHash())
86 break;
weili44f8faf2016-06-01 14:03:56 -070087
dsinclair5b36f0a2016-07-19 10:56:23 -070088 iCount++;
89 }
90 return iCount;
Dan Sinclair1770c022016-03-14 14:14:16 -040091}
weili44f8faf2016-06-01 14:03:56 -070092
Tom Sepez7cdc6602017-03-28 09:56:48 -070093std::vector<CXFA_Node*> NodesSortedByDocumentIdx(
Tom Sepeze47e0c92017-04-26 10:55:54 -070094 const std::set<CXFA_Node*>& rgNodeSet) {
Tom Sepez7cdc6602017-03-28 09:56:48 -070095 if (rgNodeSet.empty())
96 return std::vector<CXFA_Node*>();
weili44f8faf2016-06-01 14:03:56 -070097
Tom Sepez7cdc6602017-03-28 09:56:48 -070098 std::vector<CXFA_Node*> rgNodeArray;
dsinclair5b36f0a2016-07-19 10:56:23 -070099 CXFA_Node* pCommonParent =
100 (*rgNodeSet.begin())->GetNodeItem(XFA_NODEITEM_Parent);
101 for (CXFA_Node* pNode = pCommonParent->GetNodeItem(XFA_NODEITEM_FirstChild);
Tom Sepez7cdc6602017-03-28 09:56:48 -0700102 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
103 if (pdfium::ContainsValue(rgNodeSet, pNode))
104 rgNodeArray.push_back(pNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400105 }
Tom Sepez7cdc6602017-03-28 09:56:48 -0700106 return rgNodeArray;
Dan Sinclair1770c022016-03-14 14:14:16 -0400107}
weili44f8faf2016-06-01 14:03:56 -0700108
Tom Sepeze47e0c92017-04-26 10:55:54 -0700109using CXFA_NodeSetPair = std::pair<std::set<CXFA_Node*>, std::set<CXFA_Node*>>;
dsinclair5b36f0a2016-07-19 10:56:23 -0700110using CXFA_NodeSetPairMap =
111 std::map<uint32_t, std::unique_ptr<CXFA_NodeSetPair>>;
112using CXFA_NodeSetPairMapMap =
113 std::map<CXFA_Node*, std::unique_ptr<CXFA_NodeSetPairMap>>;
114
115CXFA_NodeSetPair* NodeSetPairForNode(CXFA_Node* pNode,
116 CXFA_NodeSetPairMapMap* pMap) {
117 CXFA_Node* pParentNode = pNode->GetNodeItem(XFA_NODEITEM_Parent);
118 uint32_t dwNameHash = pNode->GetNameHash();
119 if (!pParentNode || !dwNameHash)
120 return nullptr;
121
122 if (!(*pMap)[pParentNode])
tsepeza9caab92016-12-14 05:57:10 -0800123 (*pMap)[pParentNode] = pdfium::MakeUnique<CXFA_NodeSetPairMap>();
dsinclair5b36f0a2016-07-19 10:56:23 -0700124
125 CXFA_NodeSetPairMap* pNodeSetPairMap = (*pMap)[pParentNode].get();
126 if (!(*pNodeSetPairMap)[dwNameHash])
tsepeza9caab92016-12-14 05:57:10 -0800127 (*pNodeSetPairMap)[dwNameHash] = pdfium::MakeUnique<CXFA_NodeSetPair>();
dsinclair5b36f0a2016-07-19 10:56:23 -0700128
129 return (*pNodeSetPairMap)[dwNameHash].get();
Dan Sinclair1770c022016-03-14 14:14:16 -0400130}
131
Tom Sepeze47e0c92017-04-26 10:55:54 -0700132void ReorderDataNodes(const std::set<CXFA_Node*>& sSet1,
133 const std::set<CXFA_Node*>& sSet2,
tsepezd19e9122016-11-02 15:43:18 -0700134 bool bInsertBefore) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700135 CXFA_NodeSetPairMapMap rgMap;
136 for (CXFA_Node* pNode : sSet1) {
137 CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap);
138 if (pNodeSetPair)
139 pNodeSetPair->first.insert(pNode);
140 }
141 for (CXFA_Node* pNode : sSet2) {
142 CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap);
143 if (pNodeSetPair) {
144 if (pdfium::ContainsValue(pNodeSetPair->first, pNode))
145 pNodeSetPair->first.erase(pNode);
146 else
147 pNodeSetPair->second.insert(pNode);
148 }
149 }
150 for (const auto& iter1 : rgMap) {
151 CXFA_NodeSetPairMap* pNodeSetPairMap = iter1.second.get();
152 if (!pNodeSetPairMap)
153 continue;
154
155 for (const auto& iter2 : *pNodeSetPairMap) {
156 CXFA_NodeSetPair* pNodeSetPair = iter2.second.get();
157 if (!pNodeSetPair)
158 continue;
159 if (!pNodeSetPair->first.empty() && !pNodeSetPair->second.empty()) {
Tom Sepez7cdc6602017-03-28 09:56:48 -0700160 std::vector<CXFA_Node*> rgNodeArray1 =
161 NodesSortedByDocumentIdx(pNodeSetPair->first);
162 std::vector<CXFA_Node*> rgNodeArray2 =
163 NodesSortedByDocumentIdx(pNodeSetPair->second);
dsinclair5b36f0a2016-07-19 10:56:23 -0700164 CXFA_Node* pParentNode = nullptr;
165 CXFA_Node* pBeforeNode = nullptr;
166 if (bInsertBefore) {
Tom Sepez7cdc6602017-03-28 09:56:48 -0700167 pBeforeNode = rgNodeArray2.front();
dsinclair5b36f0a2016-07-19 10:56:23 -0700168 pParentNode = pBeforeNode->GetNodeItem(XFA_NODEITEM_Parent);
169 } else {
Tom Sepez7cdc6602017-03-28 09:56:48 -0700170 CXFA_Node* pLastNode = rgNodeArray2.back();
dsinclair5b36f0a2016-07-19 10:56:23 -0700171 pParentNode = pLastNode->GetNodeItem(XFA_NODEITEM_Parent);
172 pBeforeNode = pLastNode->GetNodeItem(XFA_NODEITEM_NextSibling);
173 }
Tom Sepez7cdc6602017-03-28 09:56:48 -0700174 for (auto* pCurNode : rgNodeArray1) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700175 pParentNode->RemoveChild(pCurNode);
176 pParentNode->InsertChild(pCurNode, pBeforeNode);
177 }
178 }
179 }
180 pNodeSetPairMap->clear();
181 }
182}
183
184CXFA_Node* GetItem(CXFA_Node* pInstMgrNode, int32_t iIndex) {
185 ASSERT(pInstMgrNode);
186 int32_t iCount = 0;
187 uint32_t dwNameHash = 0;
188 for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
189 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
190 XFA_Element eCurType = pNode->GetElementType();
191 if (eCurType == XFA_Element::InstanceManager)
192 break;
193 if ((eCurType != XFA_Element::Subform) &&
194 (eCurType != XFA_Element::SubformSet)) {
195 continue;
196 }
197 if (iCount == 0) {
198 CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
199 CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
200 if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
201 wsInstName.Mid(1) != wsName) {
202 return nullptr;
203 }
204 dwNameHash = pNode->GetNameHash();
205 }
206 if (dwNameHash != pNode->GetNameHash())
207 break;
208
209 iCount++;
210 if (iCount > iIndex)
211 return pNode;
212 }
213 return nullptr;
214}
215
216void InsertItem(CXFA_Node* pInstMgrNode,
217 CXFA_Node* pNewInstance,
218 int32_t iPos,
219 int32_t iCount = -1,
tsepezd19e9122016-11-02 15:43:18 -0700220 bool bMoveDataBindingNodes = true) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700221 if (iCount < 0)
222 iCount = GetCount(pInstMgrNode);
223 if (iPos < 0)
224 iPos = iCount;
225 if (iPos == iCount) {
226 CXFA_Node* pNextSibling =
227 iCount > 0
228 ? GetItem(pInstMgrNode, iCount - 1)
229 ->GetNodeItem(XFA_NODEITEM_NextSibling)
230 : pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
231 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)
232 ->InsertChild(pNewInstance, pNextSibling);
233 if (bMoveDataBindingNodes) {
Tom Sepeze47e0c92017-04-26 10:55:54 -0700234 std::set<CXFA_Node*> sNew;
235 std::set<CXFA_Node*> sAfter;
dsinclair5b36f0a2016-07-19 10:56:23 -0700236 CXFA_NodeIteratorTemplate<CXFA_Node,
237 CXFA_TraverseStrategy_XFAContainerNode>
238 sIteratorNew(pNewInstance);
239 for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode;
240 pNode = sIteratorNew.MoveToNext()) {
241 CXFA_Node* pDataNode = pNode->GetBindData();
242 if (!pDataNode)
243 continue;
244
245 sNew.insert(pDataNode);
246 }
247 CXFA_NodeIteratorTemplate<CXFA_Node,
248 CXFA_TraverseStrategy_XFAContainerNode>
249 sIteratorAfter(pNextSibling);
250 for (CXFA_Node* pNode = sIteratorAfter.GetCurrent(); pNode;
251 pNode = sIteratorAfter.MoveToNext()) {
252 CXFA_Node* pDataNode = pNode->GetBindData();
253 if (!pDataNode)
254 continue;
255
256 sAfter.insert(pDataNode);
257 }
tsepezd19e9122016-11-02 15:43:18 -0700258 ReorderDataNodes(sNew, sAfter, false);
dsinclair5b36f0a2016-07-19 10:56:23 -0700259 }
260 } else {
261 CXFA_Node* pBeforeInstance = GetItem(pInstMgrNode, iPos);
262 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)
263 ->InsertChild(pNewInstance, pBeforeInstance);
264 if (bMoveDataBindingNodes) {
Tom Sepeze47e0c92017-04-26 10:55:54 -0700265 std::set<CXFA_Node*> sNew;
266 std::set<CXFA_Node*> sBefore;
dsinclair5b36f0a2016-07-19 10:56:23 -0700267 CXFA_NodeIteratorTemplate<CXFA_Node,
268 CXFA_TraverseStrategy_XFAContainerNode>
269 sIteratorNew(pNewInstance);
270 for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode;
271 pNode = sIteratorNew.MoveToNext()) {
272 CXFA_Node* pDataNode = pNode->GetBindData();
273 if (!pDataNode)
274 continue;
275
276 sNew.insert(pDataNode);
277 }
278 CXFA_NodeIteratorTemplate<CXFA_Node,
279 CXFA_TraverseStrategy_XFAContainerNode>
280 sIteratorBefore(pBeforeInstance);
281 for (CXFA_Node* pNode = sIteratorBefore.GetCurrent(); pNode;
282 pNode = sIteratorBefore.MoveToNext()) {
283 CXFA_Node* pDataNode = pNode->GetBindData();
284 if (!pDataNode)
285 continue;
286
287 sBefore.insert(pDataNode);
288 }
tsepezd19e9122016-11-02 15:43:18 -0700289 ReorderDataNodes(sNew, sBefore, true);
dsinclair5b36f0a2016-07-19 10:56:23 -0700290 }
291 }
292}
293
294void RemoveItem(CXFA_Node* pInstMgrNode,
295 CXFA_Node* pRemoveInstance,
tsepezd19e9122016-11-02 15:43:18 -0700296 bool bRemoveDataBinding = true) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700297 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)->RemoveChild(pRemoveInstance);
298 if (!bRemoveDataBinding)
299 return;
300
301 CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFAContainerNode>
302 sIterator(pRemoveInstance);
303 for (CXFA_Node* pFormNode = sIterator.GetCurrent(); pFormNode;
304 pFormNode = sIterator.MoveToNext()) {
305 CXFA_Node* pDataNode = pFormNode->GetBindData();
306 if (!pDataNode)
307 continue;
308
309 if (pDataNode->RemoveBindItem(pFormNode) == 0) {
310 if (CXFA_Node* pDataParent =
311 pDataNode->GetNodeItem(XFA_NODEITEM_Parent)) {
312 pDataParent->RemoveChild(pDataNode);
313 }
314 }
315 pFormNode->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
316 }
317}
318
tsepezd19e9122016-11-02 15:43:18 -0700319CXFA_Node* CreateInstance(CXFA_Node* pInstMgrNode, bool bDataMerge) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700320 CXFA_Document* pDocument = pInstMgrNode->GetDocument();
321 CXFA_Node* pTemplateNode = pInstMgrNode->GetTemplateNode();
322 CXFA_Node* pFormParent = pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent);
323 CXFA_Node* pDataScope = nullptr;
324 for (CXFA_Node* pRootBoundNode = pFormParent;
325 pRootBoundNode && pRootBoundNode->IsContainerNode();
326 pRootBoundNode = pRootBoundNode->GetNodeItem(XFA_NODEITEM_Parent)) {
327 pDataScope = pRootBoundNode->GetBindData();
328 if (pDataScope)
329 break;
330 }
331 if (!pDataScope) {
332 pDataScope = ToNode(pDocument->GetXFAObject(XFA_HASHCODE_Record));
333 ASSERT(pDataScope);
334 }
335 CXFA_Node* pInstance = pDocument->DataMerge_CopyContainer(
tsepezd19e9122016-11-02 15:43:18 -0700336 pTemplateNode, pFormParent, pDataScope, true, bDataMerge, true);
dsinclair5b36f0a2016-07-19 10:56:23 -0700337 if (pInstance) {
338 pDocument->DataMerge_UpdateBindingRelations(pInstance);
339 pFormParent->RemoveChild(pInstance);
340 }
341 return pInstance;
342}
343
344struct XFA_ExecEventParaInfo {
345 public:
346 uint32_t m_uHash;
Dan Sinclair812e96c2017-03-13 16:43:37 -0400347 const wchar_t* m_lpcEventName;
dsinclair5b36f0a2016-07-19 10:56:23 -0700348 XFA_EVENTTYPE m_eventType;
349 uint32_t m_validFlags;
350};
351static const XFA_ExecEventParaInfo gs_eventParaInfos[] = {
352 {0x02a6c55a, L"postSubmit", XFA_EVENT_PostSubmit, 0},
353 {0x0ab466bb, L"preSubmit", XFA_EVENT_PreSubmit, 0},
354 {0x109d7ce7, L"mouseEnter", XFA_EVENT_MouseEnter, 5},
355 {0x17fad373, L"postPrint", XFA_EVENT_PostPrint, 0},
356 {0x1bfc72d9, L"preOpen", XFA_EVENT_PreOpen, 7},
357 {0x2196a452, L"initialize", XFA_EVENT_Initialize, 1},
358 {0x27410f03, L"mouseExit", XFA_EVENT_MouseExit, 5},
359 {0x33c43dec, L"docClose", XFA_EVENT_DocClose, 0},
360 {0x361fa1b6, L"preSave", XFA_EVENT_PreSave, 0},
361 {0x36f1c6d8, L"preSign", XFA_EVENT_PreSign, 6},
362 {0x4731d6ba, L"exit", XFA_EVENT_Exit, 2},
363 {0x56bf456b, L"docReady", XFA_EVENT_DocReady, 0},
364 {0x7233018a, L"validate", XFA_EVENT_Validate, 1},
365 {0x8808385e, L"indexChange", XFA_EVENT_IndexChange, 3},
366 {0x891f4606, L"change", XFA_EVENT_Change, 4},
367 {0x9528a7b4, L"prePrint", XFA_EVENT_PrePrint, 0},
368 {0x9f693b21, L"mouseDown", XFA_EVENT_MouseDown, 5},
369 {0xcdce56b3, L"full", XFA_EVENT_Full, 4},
370 {0xd576d08e, L"mouseUp", XFA_EVENT_MouseUp, 5},
371 {0xd95657a6, L"click", XFA_EVENT_Click, 4},
372 {0xdbfbe02e, L"calculate", XFA_EVENT_Calculate, 1},
373 {0xe25fa7b8, L"postOpen", XFA_EVENT_PostOpen, 7},
374 {0xe28dce7e, L"enter", XFA_EVENT_Enter, 2},
375 {0xfc82d695, L"postSave", XFA_EVENT_PostSave, 0},
376 {0xfd54fbb7, L"postSign", XFA_EVENT_PostSign, 6},
377};
378
379const XFA_ExecEventParaInfo* GetEventParaInfoByName(
380 const CFX_WideStringC& wsEventName) {
381 uint32_t uHash = FX_HashCode_GetW(wsEventName, false);
382 int32_t iStart = 0;
383 int32_t iEnd = (sizeof(gs_eventParaInfos) / sizeof(gs_eventParaInfos[0])) - 1;
384 do {
385 int32_t iMid = (iStart + iEnd) / 2;
386 const XFA_ExecEventParaInfo* eventParaInfo = &gs_eventParaInfos[iMid];
387 if (uHash == eventParaInfo->m_uHash)
388 return eventParaInfo;
389 if (uHash < eventParaInfo->m_uHash)
390 iEnd = iMid - 1;
391 else
392 iStart = iMid + 1;
393 } while (iStart <= iEnd);
394 return nullptr;
395}
396
397void StrToRGB(const CFX_WideString& strRGB,
398 int32_t& r,
399 int32_t& g,
400 int32_t& b) {
401 r = 0;
402 g = 0;
403 b = 0;
404
Dan Sinclair812e96c2017-03-13 16:43:37 -0400405 wchar_t zero = '0';
dsinclair5b36f0a2016-07-19 10:56:23 -0700406 int32_t iIndex = 0;
407 int32_t iLen = strRGB.GetLength();
408 for (int32_t i = 0; i < iLen; ++i) {
Dan Sinclair812e96c2017-03-13 16:43:37 -0400409 wchar_t ch = strRGB.GetAt(i);
dsinclair5b36f0a2016-07-19 10:56:23 -0700410 if (ch == L',')
411 ++iIndex;
412 if (iIndex > 2)
413 break;
414
415 int32_t iValue = ch - zero;
416 if (iValue >= 0 && iValue <= 9) {
417 switch (iIndex) {
418 case 0:
419 r = r * 10 + iValue;
420 break;
421 case 1:
422 g = g * 10 + iValue;
423 break;
424 default:
425 b = b * 10 + iValue;
426 break;
427 }
428 }
429 }
430}
431
432enum XFA_KEYTYPE {
433 XFA_KEYTYPE_Custom,
434 XFA_KEYTYPE_Element,
435};
436
437void* GetMapKey_Custom(const CFX_WideStringC& wsKey) {
438 uint32_t dwKey = FX_HashCode_GetW(wsKey, false);
439 return (void*)(uintptr_t)((dwKey << 1) | XFA_KEYTYPE_Custom);
440}
441
442void* GetMapKey_Element(XFA_Element eType, XFA_ATTRIBUTE eAttribute) {
443 return (void*)(uintptr_t)((static_cast<int32_t>(eType) << 16) |
444 (eAttribute << 8) | XFA_KEYTYPE_Element);
445}
446
dsinclair9eb0db12016-07-21 12:01:39 -0700447const XFA_ATTRIBUTEINFO* GetAttributeOfElement(XFA_Element eElement,
448 XFA_ATTRIBUTE eAttribute,
449 uint32_t dwPacket) {
450 int32_t iCount = 0;
451 const uint8_t* pAttr = XFA_GetElementAttributes(eElement, iCount);
452 if (!pAttr || iCount < 1)
453 return nullptr;
454
455 if (!std::binary_search(pAttr, pAttr + iCount, eAttribute))
456 return nullptr;
457
458 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttribute);
459 ASSERT(pInfo);
460 if (dwPacket == XFA_XDPPACKET_UNKNOWN)
461 return pInfo;
462 return (dwPacket & pInfo->dwPackets) ? pInfo : nullptr;
463}
464
465const XFA_ATTRIBUTEENUMINFO* GetAttributeEnumByID(XFA_ATTRIBUTEENUM eName) {
466 return g_XFAEnumData + eName;
467}
468
dsinclair5b36f0a2016-07-19 10:56:23 -0700469} // namespace
470
471static void XFA_DefaultFreeData(void* pData) {}
472
473static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADefaultFreeData = {
474 XFA_DefaultFreeData, nullptr};
475
weili47bcd4c2016-06-16 08:00:06 -0700476XFA_MAPMODULEDATA::XFA_MAPMODULEDATA() {}
477
478XFA_MAPMODULEDATA::~XFA_MAPMODULEDATA() {}
479
dsinclairb9778472016-06-23 13:34:10 -0700480CXFA_Node::CXFA_Node(CXFA_Document* pDoc,
481 uint16_t ePacket,
482 XFA_ObjectType oType,
dsinclairc1df5d42016-07-18 06:36:51 -0700483 XFA_Element eType,
484 const CFX_WideStringC& elementName)
485 : CXFA_Object(pDoc, oType, eType, elementName),
Dan Sinclair1770c022016-03-14 14:14:16 -0400486 m_pNext(nullptr),
487 m_pChild(nullptr),
488 m_pLastChild(nullptr),
489 m_pParent(nullptr),
490 m_pXMLNode(nullptr),
Dan Sinclair1770c022016-03-14 14:14:16 -0400491 m_ePacket(ePacket),
dsinclairc5a8f212016-06-20 11:11:12 -0700492 m_uNodeFlags(XFA_NodeFlag_None),
Dan Sinclair1770c022016-03-14 14:14:16 -0400493 m_dwNameHash(0),
494 m_pAuxNode(nullptr),
495 m_pMapModuleData(nullptr) {
496 ASSERT(m_pDocument);
497}
weili44f8faf2016-06-01 14:03:56 -0700498
Dan Sinclair1770c022016-03-14 14:14:16 -0400499CXFA_Node::~CXFA_Node() {
weili44f8faf2016-06-01 14:03:56 -0700500 ASSERT(!m_pParent);
Dan Sinclair1770c022016-03-14 14:14:16 -0400501 RemoveMapModuleKey();
weili44f8faf2016-06-01 14:03:56 -0700502 CXFA_Node* pNode = m_pChild;
Dan Sinclair1770c022016-03-14 14:14:16 -0400503 while (pNode) {
weili44f8faf2016-06-01 14:03:56 -0700504 CXFA_Node* pNext = pNode->m_pNext;
505 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400506 delete pNode;
507 pNode = pNext;
508 }
dsinclairc5a8f212016-06-20 11:11:12 -0700509 if (m_pXMLNode && IsOwnXMLNode())
tsepezc757d9a2017-01-23 11:01:42 -0800510 delete m_pXMLNode;
Dan Sinclair1770c022016-03-14 14:14:16 -0400511}
weili44f8faf2016-06-01 14:03:56 -0700512
tsepezd19e9122016-11-02 15:43:18 -0700513CXFA_Node* CXFA_Node::Clone(bool bRecursive) {
dsinclaira1b07722016-07-11 08:20:58 -0700514 CXFA_Node* pClone = m_pDocument->CreateNode(m_ePacket, m_elementType);
weili44f8faf2016-06-01 14:03:56 -0700515 if (!pClone)
516 return nullptr;
517
Dan Sinclair1770c022016-03-14 14:14:16 -0400518 MergeAllData(pClone);
519 pClone->UpdateNameHash();
520 if (IsNeedSavingXMLNode()) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -0400521 std::unique_ptr<CFX_XMLNode> pCloneXML;
Dan Sinclair1770c022016-03-14 14:14:16 -0400522 if (IsAttributeInXML()) {
523 CFX_WideString wsName;
tsepezd19e9122016-11-02 15:43:18 -0700524 GetAttribute(XFA_ATTRIBUTE_Name, wsName, false);
Dan Sinclair0d86ecb2017-04-19 09:19:57 -0400525 auto pCloneXMLElement = pdfium::MakeUnique<CFX_XMLElement>(wsName);
Dan Sinclair1770c022016-03-14 14:14:16 -0400526 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
527 if (!wsValue.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -0700528 pCloneXMLElement->SetTextData(CFX_WideString(wsValue));
Dan Sinclair1770c022016-03-14 14:14:16 -0400529 }
Dan Sinclair93bfc262017-04-04 15:10:00 -0400530 pCloneXML.reset(pCloneXMLElement.release());
Dan Sinclair1770c022016-03-14 14:14:16 -0400531 pClone->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
532 } else {
Dan Sinclair93bfc262017-04-04 15:10:00 -0400533 pCloneXML = m_pXMLNode->Clone();
Dan Sinclair1770c022016-03-14 14:14:16 -0400534 }
Dan Sinclair93bfc262017-04-04 15:10:00 -0400535 pClone->SetXMLMappingNode(pCloneXML.release());
dsinclairc5a8f212016-06-20 11:11:12 -0700536 pClone->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400537 }
538 if (bRecursive) {
539 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
540 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
541 pClone->InsertChild(pChild->Clone(bRecursive));
542 }
543 }
dsinclairc5a8f212016-06-20 11:11:12 -0700544 pClone->SetFlag(XFA_NodeFlag_Initialized, true);
weili44f8faf2016-06-01 14:03:56 -0700545 pClone->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
Dan Sinclair1770c022016-03-14 14:14:16 -0400546 return pClone;
547}
weili44f8faf2016-06-01 14:03:56 -0700548
Dan Sinclair1770c022016-03-14 14:14:16 -0400549CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem) const {
550 switch (eItem) {
551 case XFA_NODEITEM_NextSibling:
552 return m_pNext;
553 case XFA_NODEITEM_FirstChild:
554 return m_pChild;
555 case XFA_NODEITEM_Parent:
556 return m_pParent;
557 case XFA_NODEITEM_PrevSibling:
558 if (m_pParent) {
559 CXFA_Node* pSibling = m_pParent->m_pChild;
weili44f8faf2016-06-01 14:03:56 -0700560 CXFA_Node* pPrev = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400561 while (pSibling && pSibling != this) {
562 pPrev = pSibling;
563 pSibling = pSibling->m_pNext;
564 }
565 return pPrev;
566 }
weili44f8faf2016-06-01 14:03:56 -0700567 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400568 default:
569 break;
570 }
weili44f8faf2016-06-01 14:03:56 -0700571 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400572}
weili44f8faf2016-06-01 14:03:56 -0700573
Dan Sinclair1770c022016-03-14 14:14:16 -0400574CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem,
dsinclairc5a8f212016-06-20 11:11:12 -0700575 XFA_ObjectType eType) const {
weili44f8faf2016-06-01 14:03:56 -0700576 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400577 switch (eItem) {
578 case XFA_NODEITEM_NextSibling:
579 pNode = m_pNext;
dsinclairc5a8f212016-06-20 11:11:12 -0700580 while (pNode && pNode->GetObjectType() != eType)
581 pNode = pNode->m_pNext;
Dan Sinclair1770c022016-03-14 14:14:16 -0400582 break;
583 case XFA_NODEITEM_FirstChild:
584 pNode = m_pChild;
dsinclairc5a8f212016-06-20 11:11:12 -0700585 while (pNode && pNode->GetObjectType() != eType)
586 pNode = pNode->m_pNext;
Dan Sinclair1770c022016-03-14 14:14:16 -0400587 break;
588 case XFA_NODEITEM_Parent:
589 pNode = m_pParent;
dsinclairc5a8f212016-06-20 11:11:12 -0700590 while (pNode && pNode->GetObjectType() != eType)
591 pNode = pNode->m_pParent;
Dan Sinclair1770c022016-03-14 14:14:16 -0400592 break;
593 case XFA_NODEITEM_PrevSibling:
594 if (m_pParent) {
595 CXFA_Node* pSibling = m_pParent->m_pChild;
596 while (pSibling && pSibling != this) {
dsinclairc5a8f212016-06-20 11:11:12 -0700597 if (eType == pSibling->GetObjectType())
Dan Sinclair1770c022016-03-14 14:14:16 -0400598 pNode = pSibling;
dsinclairc5a8f212016-06-20 11:11:12 -0700599
Dan Sinclair1770c022016-03-14 14:14:16 -0400600 pSibling = pSibling->m_pNext;
601 }
602 }
603 break;
604 default:
605 break;
606 }
607 return pNode;
608}
weili44f8faf2016-06-01 14:03:56 -0700609
Tom Sepezf8a94392017-03-14 12:13:22 -0700610std::vector<CXFA_Node*> CXFA_Node::GetNodeList(uint32_t dwTypeFilter,
611 XFA_Element eTypeFilter) {
612 std::vector<CXFA_Node*> nodes;
dsinclair41cb62e2016-06-23 09:20:32 -0700613 if (eTypeFilter != XFA_Element::Unknown) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700614 for (CXFA_Node* pChild = m_pChild; pChild; pChild = pChild->m_pNext) {
615 if (pChild->GetElementType() == eTypeFilter)
616 nodes.push_back(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400617 }
618 } else if (dwTypeFilter ==
619 (XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties)) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700620 for (CXFA_Node* pChild = m_pChild; pChild; pChild = pChild->m_pNext)
621 nodes.push_back(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400622 } else if (dwTypeFilter != 0) {
weili44f8faf2016-06-01 14:03:56 -0700623 bool bFilterChildren = !!(dwTypeFilter & XFA_NODEFILTER_Children);
624 bool bFilterProperties = !!(dwTypeFilter & XFA_NODEFILTER_Properties);
625 bool bFilterOneOfProperties =
626 !!(dwTypeFilter & XFA_NODEFILTER_OneOfProperty);
Dan Sinclair1770c022016-03-14 14:14:16 -0400627 CXFA_Node* pChild = m_pChild;
628 while (pChild) {
629 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -0700630 GetElementType(), pChild->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -0400631 if (pProperty) {
632 if (bFilterProperties) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700633 nodes.push_back(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400634 } else if (bFilterOneOfProperties &&
635 (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700636 nodes.push_back(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400637 } else if (bFilterChildren &&
dsinclair070fcdf2016-06-22 22:04:54 -0700638 (pChild->GetElementType() == XFA_Element::Variables ||
639 pChild->GetElementType() == XFA_Element::PageSet)) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700640 nodes.push_back(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400641 }
weili44f8faf2016-06-01 14:03:56 -0700642 } else if (bFilterChildren) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700643 nodes.push_back(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400644 }
645 pChild = pChild->m_pNext;
646 }
Tom Sepezf8a94392017-03-14 12:13:22 -0700647 if (bFilterOneOfProperties && nodes.empty()) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400648 int32_t iProperties = 0;
649 const XFA_PROPERTY* pProperty =
dsinclair070fcdf2016-06-22 22:04:54 -0700650 XFA_GetElementProperties(GetElementType(), iProperties);
weili44f8faf2016-06-01 14:03:56 -0700651 if (!pProperty || iProperties < 1)
Tom Sepezf8a94392017-03-14 12:13:22 -0700652 return nodes;
Dan Sinclair1770c022016-03-14 14:14:16 -0400653 for (int32_t i = 0; i < iProperties; i++) {
654 if (pProperty[i].uFlags & XFA_PROPERTYFLAG_DefaultOneOf) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400655 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(GetPacketID());
656 CXFA_Node* pNewNode =
dsinclaira1b07722016-07-11 08:20:58 -0700657 m_pDocument->CreateNode(pPacket, pProperty[i].eName);
weili44f8faf2016-06-01 14:03:56 -0700658 if (!pNewNode)
Dan Sinclair1770c022016-03-14 14:14:16 -0400659 break;
weili44f8faf2016-06-01 14:03:56 -0700660 InsertChild(pNewNode, nullptr);
dsinclairc5a8f212016-06-20 11:11:12 -0700661 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
Tom Sepezf8a94392017-03-14 12:13:22 -0700662 nodes.push_back(pNewNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400663 break;
664 }
665 }
666 }
667 }
Tom Sepezf8a94392017-03-14 12:13:22 -0700668 return nodes;
Dan Sinclair1770c022016-03-14 14:14:16 -0400669}
weili44f8faf2016-06-01 14:03:56 -0700670
dsinclair41cb62e2016-06-23 09:20:32 -0700671CXFA_Node* CXFA_Node::CreateSamePacketNode(XFA_Element eType,
tsepez736f28a2016-03-25 14:19:51 -0700672 uint32_t dwFlags) {
dsinclaira1b07722016-07-11 08:20:58 -0700673 CXFA_Node* pNode = m_pDocument->CreateNode(m_ePacket, eType);
thestigb1a59592016-04-14 18:29:56 -0700674 pNode->SetFlag(dwFlags, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400675 return pNode;
676}
weili44f8faf2016-06-01 14:03:56 -0700677
tsepezd19e9122016-11-02 15:43:18 -0700678CXFA_Node* CXFA_Node::CloneTemplateToForm(bool bRecursive) {
dsinclair43854a52016-04-27 12:26:00 -0700679 ASSERT(m_ePacket == XFA_XDPPACKET_Template);
dsinclaira1b07722016-07-11 08:20:58 -0700680 CXFA_Node* pClone =
681 m_pDocument->CreateNode(XFA_XDPPACKET_Form, m_elementType);
weili44f8faf2016-06-01 14:03:56 -0700682 if (!pClone)
683 return nullptr;
684
Dan Sinclair1770c022016-03-14 14:14:16 -0400685 pClone->SetTemplateNode(this);
686 pClone->UpdateNameHash();
687 pClone->SetXMLMappingNode(GetXMLMappingNode());
688 if (bRecursive) {
689 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
690 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
691 pClone->InsertChild(pChild->CloneTemplateToForm(bRecursive));
692 }
693 }
dsinclairc5a8f212016-06-20 11:11:12 -0700694 pClone->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400695 return pClone;
696}
697
698CXFA_Node* CXFA_Node::GetTemplateNode() const {
699 return m_pAuxNode;
700}
701
702void CXFA_Node::SetTemplateNode(CXFA_Node* pTemplateNode) {
703 m_pAuxNode = pTemplateNode;
704}
weili44f8faf2016-06-01 14:03:56 -0700705
Dan Sinclair1770c022016-03-14 14:14:16 -0400706CXFA_Node* CXFA_Node::GetBindData() {
707 ASSERT(GetPacketID() == XFA_XDPPACKET_Form);
708 return static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
709}
weili44f8faf2016-06-01 14:03:56 -0700710
Tom Sepezf8a94392017-03-14 12:13:22 -0700711std::vector<CXFA_Node*> CXFA_Node::GetBindItems() {
dsinclairc5a8f212016-06-20 11:11:12 -0700712 if (BindsFormItems()) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700713 void* pBinding = nullptr;
714 TryObject(XFA_ATTRIBUTE_BindingNode, pBinding);
715 return *static_cast<std::vector<CXFA_Node*>*>(pBinding);
Dan Sinclair1770c022016-03-14 14:14:16 -0400716 }
Tom Sepezf8a94392017-03-14 12:13:22 -0700717 std::vector<CXFA_Node*> result;
Dan Sinclair1770c022016-03-14 14:14:16 -0400718 CXFA_Node* pFormNode =
719 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
weili44f8faf2016-06-01 14:03:56 -0700720 if (pFormNode)
Tom Sepezf8a94392017-03-14 12:13:22 -0700721 result.push_back(pFormNode);
722 return result;
Dan Sinclair1770c022016-03-14 14:14:16 -0400723}
724
Dan Sinclair1770c022016-03-14 14:14:16 -0400725int32_t CXFA_Node::AddBindItem(CXFA_Node* pFormNode) {
726 ASSERT(pFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700727 if (BindsFormItems()) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700728 void* pBinding = nullptr;
729 TryObject(XFA_ATTRIBUTE_BindingNode, pBinding);
730 auto* pItems = static_cast<std::vector<CXFA_Node*>*>(pBinding);
731 if (!pdfium::ContainsValue(*pItems, pFormNode))
732 pItems->push_back(pFormNode);
733 return pdfium::CollectionSize<int32_t>(*pItems);
Dan Sinclair1770c022016-03-14 14:14:16 -0400734 }
735 CXFA_Node* pOldFormItem =
736 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
737 if (!pOldFormItem) {
738 SetObject(XFA_ATTRIBUTE_BindingNode, pFormNode);
739 return 1;
Dan Sinclair1770c022016-03-14 14:14:16 -0400740 }
Tom Sepezf8a94392017-03-14 12:13:22 -0700741 if (pOldFormItem == pFormNode)
742 return 1;
743
744 std::vector<CXFA_Node*>* pItems = new std::vector<CXFA_Node*>;
Dan Sinclair1770c022016-03-14 14:14:16 -0400745 SetObject(XFA_ATTRIBUTE_BindingNode, pItems, &deleteBindItemCallBack);
Tom Sepezf8a94392017-03-14 12:13:22 -0700746 pItems->push_back(pOldFormItem);
747 pItems->push_back(pFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700748 m_uNodeFlags |= XFA_NodeFlag_BindFormItems;
Dan Sinclair1770c022016-03-14 14:14:16 -0400749 return 2;
750}
weili44f8faf2016-06-01 14:03:56 -0700751
Dan Sinclair1770c022016-03-14 14:14:16 -0400752int32_t CXFA_Node::RemoveBindItem(CXFA_Node* pFormNode) {
dsinclairc5a8f212016-06-20 11:11:12 -0700753 if (BindsFormItems()) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700754 void* pBinding = nullptr;
755 TryObject(XFA_ATTRIBUTE_BindingNode, pBinding);
756 auto* pItems = static_cast<std::vector<CXFA_Node*>*>(pBinding);
757 auto iter = std::find(pItems->begin(), pItems->end(), pFormNode);
758 if (iter != pItems->end()) {
759 *iter = pItems->back();
760 pItems->pop_back();
761 if (pItems->size() == 1) {
762 SetObject(XFA_ATTRIBUTE_BindingNode,
763 (*pItems)[0]); // Invalidates pItems.
dsinclairc5a8f212016-06-20 11:11:12 -0700764 m_uNodeFlags &= ~XFA_NodeFlag_BindFormItems;
Tom Sepezf8a94392017-03-14 12:13:22 -0700765 return 1;
Dan Sinclair1770c022016-03-14 14:14:16 -0400766 }
Dan Sinclair1770c022016-03-14 14:14:16 -0400767 }
Tom Sepezf8a94392017-03-14 12:13:22 -0700768 return pdfium::CollectionSize<int32_t>(*pItems);
Dan Sinclair1770c022016-03-14 14:14:16 -0400769 }
770 CXFA_Node* pOldFormItem =
771 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
Tom Sepezf8a94392017-03-14 12:13:22 -0700772 if (pOldFormItem != pFormNode)
773 return pOldFormItem ? 1 : 0;
774
775 SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
776 return 0;
Dan Sinclair1770c022016-03-14 14:14:16 -0400777}
weili44f8faf2016-06-01 14:03:56 -0700778
tsepezd19e9122016-11-02 15:43:18 -0700779bool CXFA_Node::HasBindItem() {
weili44f8faf2016-06-01 14:03:56 -0700780 return GetPacketID() == XFA_XDPPACKET_Datasets &&
781 GetObject(XFA_ATTRIBUTE_BindingNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400782}
weili44f8faf2016-06-01 14:03:56 -0700783
Dan Sinclair1770c022016-03-14 14:14:16 -0400784CXFA_WidgetData* CXFA_Node::GetWidgetData() {
785 return (CXFA_WidgetData*)GetObject(XFA_ATTRIBUTE_WidgetData);
786}
weili44f8faf2016-06-01 14:03:56 -0700787
Dan Sinclair1770c022016-03-14 14:14:16 -0400788CXFA_WidgetData* CXFA_Node::GetContainerWidgetData() {
weili44f8faf2016-06-01 14:03:56 -0700789 if (GetPacketID() != XFA_XDPPACKET_Form)
790 return nullptr;
dsinclair41cb62e2016-06-23 09:20:32 -0700791 XFA_Element eType = GetElementType();
792 if (eType == XFA_Element::ExclGroup)
weili44f8faf2016-06-01 14:03:56 -0700793 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400794 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -0700795 if (pParentNode && pParentNode->GetElementType() == XFA_Element::ExclGroup)
weili44f8faf2016-06-01 14:03:56 -0700796 return nullptr;
797
dsinclair41cb62e2016-06-23 09:20:32 -0700798 if (eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400799 CXFA_WidgetData* pFieldWidgetData = GetWidgetData();
800 if (pFieldWidgetData &&
801 pFieldWidgetData->GetChoiceListOpen() ==
802 XFA_ATTRIBUTEENUM_MultiSelect) {
weili44f8faf2016-06-01 14:03:56 -0700803 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400804 } else {
805 CFX_WideString wsPicture;
806 if (pFieldWidgetData) {
807 pFieldWidgetData->GetPictureContent(wsPicture,
808 XFA_VALUEPICTURE_DataBind);
809 }
weili44f8faf2016-06-01 14:03:56 -0700810 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -0400811 return pFieldWidgetData;
Dan Sinclair1770c022016-03-14 14:14:16 -0400812 CXFA_Node* pDataNode = GetBindData();
weili44f8faf2016-06-01 14:03:56 -0700813 if (!pDataNode)
814 return nullptr;
815 pFieldWidgetData = nullptr;
Tom Sepezf8a94392017-03-14 12:13:22 -0700816 for (CXFA_Node* pFormNode : pDataNode->GetBindItems()) {
dsinclairc5a8f212016-06-20 11:11:12 -0700817 if (!pFormNode || pFormNode->HasRemovedChildren())
Dan Sinclair1770c022016-03-14 14:14:16 -0400818 continue;
Dan Sinclair1770c022016-03-14 14:14:16 -0400819 pFieldWidgetData = pFormNode->GetWidgetData();
820 if (pFieldWidgetData) {
821 pFieldWidgetData->GetPictureContent(wsPicture,
822 XFA_VALUEPICTURE_DataBind);
823 }
weili44f8faf2016-06-01 14:03:56 -0700824 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -0400825 break;
weili44f8faf2016-06-01 14:03:56 -0700826 pFieldWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400827 }
828 return pFieldWidgetData;
829 }
830 }
831 CXFA_Node* pGrandNode =
weili44f8faf2016-06-01 14:03:56 -0700832 pParentNode ? pParentNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400833 CXFA_Node* pValueNode =
dsinclair070fcdf2016-06-22 22:04:54 -0700834 (pParentNode && pParentNode->GetElementType() == XFA_Element::Value)
Dan Sinclair1770c022016-03-14 14:14:16 -0400835 ? pParentNode
weili44f8faf2016-06-01 14:03:56 -0700836 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400837 if (!pValueNode) {
dsinclair070fcdf2016-06-22 22:04:54 -0700838 pValueNode =
839 (pGrandNode && pGrandNode->GetElementType() == XFA_Element::Value)
840 ? pGrandNode
841 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400842 }
843 CXFA_Node* pParentOfValueNode =
weili44f8faf2016-06-01 14:03:56 -0700844 pValueNode ? pValueNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400845 return pParentOfValueNode ? pParentOfValueNode->GetContainerWidgetData()
weili44f8faf2016-06-01 14:03:56 -0700846 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400847}
weili44f8faf2016-06-01 14:03:56 -0700848
tsepezd19e9122016-11-02 15:43:18 -0700849bool CXFA_Node::GetLocaleName(CFX_WideString& wsLocaleName) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400850 CXFA_Node* pForm = GetDocument()->GetXFAObject(XFA_HASHCODE_Form)->AsNode();
dsinclair56a8b192016-06-21 14:15:25 -0700851 CXFA_Node* pTopSubform = pForm->GetFirstChildByClass(XFA_Element::Subform);
dsinclair43854a52016-04-27 12:26:00 -0700852 ASSERT(pTopSubform);
Dan Sinclair1770c022016-03-14 14:14:16 -0400853 CXFA_Node* pLocaleNode = this;
tsepezd19e9122016-11-02 15:43:18 -0700854 bool bLocale = false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400855 do {
tsepezd19e9122016-11-02 15:43:18 -0700856 bLocale = pLocaleNode->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400857 if (!bLocale) {
858 pLocaleNode = pLocaleNode->GetNodeItem(XFA_NODEITEM_Parent);
859 }
860 } while (pLocaleNode && pLocaleNode != pTopSubform && !bLocale);
weili44f8faf2016-06-01 14:03:56 -0700861 if (bLocale)
tsepezd19e9122016-11-02 15:43:18 -0700862 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400863 CXFA_Node* pConfig = ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Config));
864 wsLocaleName = GetDocument()->GetLocalMgr()->GetConfigLocaleName(pConfig);
weili44f8faf2016-06-01 14:03:56 -0700865 if (!wsLocaleName.IsEmpty())
tsepezd19e9122016-11-02 15:43:18 -0700866 return true;
weili44f8faf2016-06-01 14:03:56 -0700867 if (pTopSubform &&
tsepezd19e9122016-11-02 15:43:18 -0700868 pTopSubform->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false)) {
869 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400870 }
871 IFX_Locale* pLocale = GetDocument()->GetLocalMgr()->GetDefLocale();
872 if (pLocale) {
873 wsLocaleName = pLocale->GetName();
tsepezd19e9122016-11-02 15:43:18 -0700874 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400875 }
tsepezd19e9122016-11-02 15:43:18 -0700876 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400877}
weili44f8faf2016-06-01 14:03:56 -0700878
Dan Sinclair1770c022016-03-14 14:14:16 -0400879XFA_ATTRIBUTEENUM CXFA_Node::GetIntact() {
dsinclair56a8b192016-06-21 14:15:25 -0700880 CXFA_Node* pKeep = GetFirstChildByClass(XFA_Element::Keep);
Dan Sinclair1770c022016-03-14 14:14:16 -0400881 XFA_ATTRIBUTEENUM eLayoutType = GetEnum(XFA_ATTRIBUTE_Layout);
882 if (pKeep) {
883 XFA_ATTRIBUTEENUM eIntact;
tsepezd19e9122016-11-02 15:43:18 -0700884 if (pKeep->TryEnum(XFA_ATTRIBUTE_Intact, eIntact, false)) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400885 if (eIntact == XFA_ATTRIBUTEENUM_None &&
886 eLayoutType == XFA_ATTRIBUTEENUM_Row &&
887 m_pDocument->GetCurVersionMode() < XFA_VERSION_208) {
dsinclairc5a8f212016-06-20 11:11:12 -0700888 CXFA_Node* pPreviewRow = GetNodeItem(XFA_NODEITEM_PrevSibling,
889 XFA_ObjectType::ContainerNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400890 if (pPreviewRow &&
891 pPreviewRow->GetEnum(XFA_ATTRIBUTE_Layout) ==
892 XFA_ATTRIBUTEENUM_Row) {
893 XFA_ATTRIBUTEENUM eValue;
tsepezd19e9122016-11-02 15:43:18 -0700894 if (pKeep->TryEnum(XFA_ATTRIBUTE_Previous, eValue, false) &&
weili44f8faf2016-06-01 14:03:56 -0700895 (eValue == XFA_ATTRIBUTEENUM_ContentArea ||
896 eValue == XFA_ATTRIBUTEENUM_PageArea)) {
897 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400898 }
weili44f8faf2016-06-01 14:03:56 -0700899 CXFA_Node* pNode =
dsinclair56a8b192016-06-21 14:15:25 -0700900 pPreviewRow->GetFirstChildByClass(XFA_Element::Keep);
tsepezd19e9122016-11-02 15:43:18 -0700901 if (pNode && pNode->TryEnum(XFA_ATTRIBUTE_Next, eValue, false) &&
weili44f8faf2016-06-01 14:03:56 -0700902 (eValue == XFA_ATTRIBUTEENUM_ContentArea ||
903 eValue == XFA_ATTRIBUTEENUM_PageArea)) {
904 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400905 }
906 }
907 }
908 return eIntact;
909 }
910 }
dsinclair41cb62e2016-06-23 09:20:32 -0700911 switch (GetElementType()) {
dsinclair56a8b192016-06-21 14:15:25 -0700912 case XFA_Element::Subform:
Dan Sinclair1770c022016-03-14 14:14:16 -0400913 switch (eLayoutType) {
914 case XFA_ATTRIBUTEENUM_Position:
915 case XFA_ATTRIBUTEENUM_Row:
916 return XFA_ATTRIBUTEENUM_ContentArea;
917 case XFA_ATTRIBUTEENUM_Tb:
918 case XFA_ATTRIBUTEENUM_Table:
919 case XFA_ATTRIBUTEENUM_Lr_tb:
920 case XFA_ATTRIBUTEENUM_Rl_tb:
921 return XFA_ATTRIBUTEENUM_None;
922 default:
923 break;
924 }
925 break;
dsinclair56a8b192016-06-21 14:15:25 -0700926 case XFA_Element::Field: {
Dan Sinclair1770c022016-03-14 14:14:16 -0400927 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -0700928 if (!pParentNode ||
929 pParentNode->GetElementType() == XFA_Element::PageArea)
Dan Sinclair1770c022016-03-14 14:14:16 -0400930 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400931 if (pParentNode->GetIntact() == XFA_ATTRIBUTEENUM_None) {
932 XFA_ATTRIBUTEENUM eParLayout =
933 pParentNode->GetEnum(XFA_ATTRIBUTE_Layout);
934 if (eParLayout == XFA_ATTRIBUTEENUM_Position ||
935 eParLayout == XFA_ATTRIBUTEENUM_Row ||
936 eParLayout == XFA_ATTRIBUTEENUM_Table) {
937 return XFA_ATTRIBUTEENUM_None;
938 }
939 XFA_VERSION version = m_pDocument->GetCurVersionMode();
940 if (eParLayout == XFA_ATTRIBUTEENUM_Tb && version < XFA_VERSION_208) {
941 CXFA_Measurement measureH;
tsepezd19e9122016-11-02 15:43:18 -0700942 if (TryMeasure(XFA_ATTRIBUTE_H, measureH, false))
Dan Sinclair1770c022016-03-14 14:14:16 -0400943 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400944 }
945 return XFA_ATTRIBUTEENUM_None;
946 }
947 return XFA_ATTRIBUTEENUM_ContentArea;
948 }
dsinclair56a8b192016-06-21 14:15:25 -0700949 case XFA_Element::Draw:
Dan Sinclair1770c022016-03-14 14:14:16 -0400950 return XFA_ATTRIBUTEENUM_ContentArea;
951 default:
952 break;
953 }
954 return XFA_ATTRIBUTEENUM_None;
955}
weili44f8faf2016-06-01 14:03:56 -0700956
Dan Sinclair1770c022016-03-14 14:14:16 -0400957CXFA_Node* CXFA_Node::GetDataDescriptionNode() {
weili44f8faf2016-06-01 14:03:56 -0700958 if (m_ePacket == XFA_XDPPACKET_Datasets)
Dan Sinclair1770c022016-03-14 14:14:16 -0400959 return m_pAuxNode;
weili44f8faf2016-06-01 14:03:56 -0700960 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400961}
weili44f8faf2016-06-01 14:03:56 -0700962
Dan Sinclair1770c022016-03-14 14:14:16 -0400963void CXFA_Node::SetDataDescriptionNode(CXFA_Node* pDataDescriptionNode) {
dsinclair43854a52016-04-27 12:26:00 -0700964 ASSERT(m_ePacket == XFA_XDPPACKET_Datasets);
Dan Sinclair1770c022016-03-14 14:14:16 -0400965 m_pAuxNode = pDataDescriptionNode;
966}
weili44f8faf2016-06-01 14:03:56 -0700967
Dan Sinclair1770c022016-03-14 14:14:16 -0400968void CXFA_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments) {
969 int32_t iLength = pArguments->GetLength();
970 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -0500971 ThrowParamCountMismatchException(L"resolveNode");
Dan Sinclair1770c022016-03-14 14:14:16 -0400972 return;
973 }
tsepez6fe7d212016-04-06 10:51:14 -0700974 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -0700975 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
dsinclairdf4bc592016-03-31 20:34:43 -0700976 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -0700977 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -0400978 return;
Dan Sinclair1770c022016-03-14 14:14:16 -0400979 CXFA_Node* refNode = this;
dsinclair070fcdf2016-06-22 22:04:54 -0700980 if (refNode->GetElementType() == XFA_Element::Xfa)
Dan Sinclair1770c022016-03-14 14:14:16 -0400981 refNode = ToNode(pScriptContext->GetThisObject());
tsepez736f28a2016-03-25 14:19:51 -0700982 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
Dan Sinclair1770c022016-03-14 14:14:16 -0400983 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
984 XFA_RESOLVENODE_Siblings;
985 XFA_RESOLVENODE_RS resoveNodeRS;
tsepezfc58ad12016-04-05 12:22:15 -0700986 int32_t iRet = pScriptContext->ResolveObjects(
tsepez4c3debb2016-04-08 12:20:38 -0700987 refNode, wsExpression.AsStringC(), resoveNodeRS, dwFlag);
dsinclairf27aeec2016-06-07 19:36:18 -0700988 if (iRet < 1) {
989 pArguments->GetReturnValue()->SetNull();
990 return;
991 }
Dan Sinclair1770c022016-03-14 14:14:16 -0400992 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700993 CXFA_Object* pObject = resoveNodeRS.objects.front();
dsinclairf27aeec2016-06-07 19:36:18 -0700994 pArguments->GetReturnValue()->Assign(
Tom Sepezf8a94392017-03-14 12:13:22 -0700995 pScriptContext->GetJSValueFromMap(pObject));
Dan Sinclair1770c022016-03-14 14:14:16 -0400996 } else {
997 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo =
998 resoveNodeRS.pScriptAttribute;
999 if (lpAttributeInfo && lpAttributeInfo->eValueType == XFA_SCRIPT_Object) {
Dan Sinclairfdf7d402017-04-18 15:25:58 -04001000 auto pValue =
1001 pdfium::MakeUnique<CFXJSE_Value>(pScriptContext->GetRuntime());
Tom Sepezf8a94392017-03-14 12:13:22 -07001002 (resoveNodeRS.objects.front()->*(lpAttributeInfo->lpfnCallback))(
tsepezd19e9122016-11-02 15:43:18 -07001003 pValue.get(), false, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute);
dsinclairf27aeec2016-06-07 19:36:18 -07001004 pArguments->GetReturnValue()->Assign(pValue.get());
Dan Sinclair1770c022016-03-14 14:14:16 -04001005 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001006 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04001007 }
1008 }
1009}
weili44f8faf2016-06-01 14:03:56 -07001010
Dan Sinclair1770c022016-03-14 14:14:16 -04001011void CXFA_Node::Script_TreeClass_ResolveNodes(CFXJSE_Arguments* pArguments) {
1012 int32_t iLength = pArguments->GetLength();
1013 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001014 ThrowParamCountMismatchException(L"resolveNodes");
Dan Sinclair1770c022016-03-14 14:14:16 -04001015 return;
1016 }
tsepez6fe7d212016-04-06 10:51:14 -07001017 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001018 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
dsinclair12a6b0c2016-05-26 11:14:08 -07001019 CFXJSE_Value* pValue = pArguments->GetReturnValue();
weili44f8faf2016-06-01 14:03:56 -07001020 if (!pValue)
Dan Sinclair1770c022016-03-14 14:14:16 -04001021 return;
tsepez736f28a2016-03-25 14:19:51 -07001022 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
Dan Sinclair1770c022016-03-14 14:14:16 -04001023 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1024 XFA_RESOLVENODE_Siblings;
1025 CXFA_Node* refNode = this;
dsinclair070fcdf2016-06-22 22:04:54 -07001026 if (refNode->GetElementType() == XFA_Element::Xfa)
Dan Sinclair1770c022016-03-14 14:14:16 -04001027 refNode = ToNode(m_pDocument->GetScriptContext()->GetThisObject());
dsinclair12a6b0c2016-05-26 11:14:08 -07001028 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag, refNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04001029}
weili44f8faf2016-06-01 14:03:56 -07001030
dsinclair12a6b0c2016-05-26 11:14:08 -07001031void CXFA_Node::Script_Som_ResolveNodeList(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001032 CFX_WideString wsExpression,
tsepez736f28a2016-03-25 14:19:51 -07001033 uint32_t dwFlag,
Dan Sinclair1770c022016-03-14 14:14:16 -04001034 CXFA_Node* refNode) {
dsinclairdf4bc592016-03-31 20:34:43 -07001035 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001036 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001037 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001038 XFA_RESOLVENODE_RS resoveNodeRS;
weili44f8faf2016-06-01 14:03:56 -07001039 if (!refNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04001040 refNode = this;
tsepez4c3debb2016-04-08 12:20:38 -07001041 pScriptContext->ResolveObjects(refNode, wsExpression.AsStringC(),
tsepezfc58ad12016-04-05 12:22:15 -07001042 resoveNodeRS, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001043 CXFA_ArrayNodeList* pNodeList = new CXFA_ArrayNodeList(m_pDocument);
1044 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
Tom Sepezf8a94392017-03-14 12:13:22 -07001045 for (CXFA_Object* pObject : resoveNodeRS.objects) {
1046 if (pObject->IsNode())
1047 pNodeList->Append(pObject->AsNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001048 }
1049 } else {
dsinclair12a6b0c2016-05-26 11:14:08 -07001050 CXFA_ValueArray valueArray(pScriptContext->GetRuntime());
Tom Sepez369fe1f2017-03-27 16:03:43 -07001051 if (resoveNodeRS.GetAttributeResult(&valueArray) > 0) {
Tom Sepezf8a94392017-03-14 12:13:22 -07001052 for (CXFA_Object* pObject : valueArray.GetAttributeObject()) {
1053 if (pObject->IsNode())
1054 pNodeList->Append(pObject->AsNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001055 }
1056 }
1057 }
dsinclairf27aeec2016-06-07 19:36:18 -07001058 pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001059}
weili44f8faf2016-06-01 14:03:56 -07001060
dsinclair12a6b0c2016-05-26 11:14:08 -07001061void CXFA_Node::Script_TreeClass_All(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001062 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001063 XFA_ATTRIBUTE eAttribute) {
1064 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001065 ThrowInvalidPropertyException();
1066 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001067 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001068
1069 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
1070 CFX_WideString wsName;
1071 GetAttribute(XFA_ATTRIBUTE_Name, wsName);
dan sinclair65c7c232017-02-02 14:05:30 -08001072 CFX_WideString wsExpression = wsName + L"[*]";
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001073 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001074}
weili44f8faf2016-06-01 14:03:56 -07001075
dsinclair12a6b0c2016-05-26 11:14:08 -07001076void CXFA_Node::Script_TreeClass_Nodes(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001077 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001078 XFA_ATTRIBUTE eAttribute) {
dsinclairdf4bc592016-03-31 20:34:43 -07001079 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001080 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001081 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001082 if (bSetting) {
Dan Sinclairc8fd3312017-01-02 17:17:02 -05001083 CFX_WideString wsMessage = L"Unable to set ";
Tom Sepezf0b65542017-02-13 10:26:01 -08001084 FXJSE_ThrowMessage(wsMessage.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001085 } else {
1086 CXFA_AttachNodeList* pNodeList = new CXFA_AttachNodeList(m_pDocument, this);
dsinclairf27aeec2016-06-07 19:36:18 -07001087 pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001088 }
1089}
weili44f8faf2016-06-01 14:03:56 -07001090
dsinclair12a6b0c2016-05-26 11:14:08 -07001091void CXFA_Node::Script_TreeClass_ClassAll(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001092 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001093 XFA_ATTRIBUTE eAttribute) {
1094 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001095 ThrowInvalidPropertyException();
1096 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001097 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001098 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
dan sinclair65c7c232017-02-02 14:05:30 -08001099 CFX_WideString wsExpression = L"#" + GetClassName() + L"[*]";
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001100 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001101}
weili44f8faf2016-06-01 14:03:56 -07001102
dsinclair12a6b0c2016-05-26 11:14:08 -07001103void CXFA_Node::Script_TreeClass_Parent(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001104 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001105 XFA_ATTRIBUTE eAttribute) {
1106 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001107 ThrowInvalidPropertyException();
1108 return;
1109 }
1110 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
1111 if (pParent) {
1112 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pParent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001113 } else {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001114 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04001115 }
1116}
weili44f8faf2016-06-01 14:03:56 -07001117
dsinclair12a6b0c2016-05-26 11:14:08 -07001118void CXFA_Node::Script_TreeClass_Index(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001119 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001120 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001121 if (bSetting) {
1122 ThrowInvalidPropertyException();
1123 return;
1124 }
1125 pValue->SetInteger(GetNodeSameNameIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04001126}
weili44f8faf2016-06-01 14:03:56 -07001127
dsinclair12a6b0c2016-05-26 11:14:08 -07001128void CXFA_Node::Script_TreeClass_ClassIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001129 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001130 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001131 if (bSetting) {
1132 ThrowInvalidPropertyException();
1133 return;
1134 }
1135 pValue->SetInteger(GetNodeSameClassIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04001136}
weili44f8faf2016-06-01 14:03:56 -07001137
dsinclair12a6b0c2016-05-26 11:14:08 -07001138void CXFA_Node::Script_TreeClass_SomExpression(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001139 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001140 XFA_ATTRIBUTE eAttribute) {
1141 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001142 ThrowInvalidPropertyException();
1143 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001144 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001145 CFX_WideString wsSOMExpression;
1146 GetSOMExpression(wsSOMExpression);
Tom Sepezf0b65542017-02-13 10:26:01 -08001147 pValue->SetString(wsSOMExpression.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001148}
weili44f8faf2016-06-01 14:03:56 -07001149
Dan Sinclair1770c022016-03-14 14:14:16 -04001150void CXFA_Node::Script_NodeClass_ApplyXSL(CFXJSE_Arguments* pArguments) {
1151 int32_t iLength = pArguments->GetLength();
1152 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001153 ThrowParamCountMismatchException(L"applyXSL");
Dan Sinclair1770c022016-03-14 14:14:16 -04001154 return;
1155 }
tsepez6fe7d212016-04-06 10:51:14 -07001156 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001157 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
weili60607c32016-05-26 11:53:12 -07001158 // TODO(weili): check whether we need to implement this, pdfium:501.
1159 // For now, just put the variables here to avoid unused variable warning.
1160 (void)wsExpression;
Dan Sinclair1770c022016-03-14 14:14:16 -04001161}
weili60607c32016-05-26 11:53:12 -07001162
Dan Sinclair1770c022016-03-14 14:14:16 -04001163void CXFA_Node::Script_NodeClass_AssignNode(CFXJSE_Arguments* pArguments) {
1164 int32_t iLength = pArguments->GetLength();
1165 if (iLength < 1 || iLength > 3) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001166 ThrowParamCountMismatchException(L"assignNode");
Dan Sinclair1770c022016-03-14 14:14:16 -04001167 return;
1168 }
1169 CFX_WideString wsExpression;
1170 CFX_WideString wsValue;
1171 int32_t iAction = 0;
weili44f8faf2016-06-01 14:03:56 -07001172 wsExpression =
1173 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001174 if (iLength >= 2) {
weili60607c32016-05-26 11:53:12 -07001175 wsValue =
1176 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001177 }
weili60607c32016-05-26 11:53:12 -07001178 if (iLength >= 3)
Dan Sinclair1770c022016-03-14 14:14:16 -04001179 iAction = pArguments->GetInt32(2);
weili60607c32016-05-26 11:53:12 -07001180 // TODO(weili): check whether we need to implement this, pdfium:501.
1181 // For now, just put the variables here to avoid unused variable warning.
1182 (void)wsExpression;
1183 (void)wsValue;
1184 (void)iAction;
Dan Sinclair1770c022016-03-14 14:14:16 -04001185}
weili60607c32016-05-26 11:53:12 -07001186
Dan Sinclair1770c022016-03-14 14:14:16 -04001187void CXFA_Node::Script_NodeClass_Clone(CFXJSE_Arguments* pArguments) {
1188 int32_t iLength = pArguments->GetLength();
1189 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001190 ThrowParamCountMismatchException(L"clone");
Dan Sinclair1770c022016-03-14 14:14:16 -04001191 return;
1192 }
weili44f8faf2016-06-01 14:03:56 -07001193 bool bClone = !!pArguments->GetInt32(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04001194 CXFA_Node* pCloneNode = Clone(bClone);
dsinclairf27aeec2016-06-07 19:36:18 -07001195 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04001196 m_pDocument->GetScriptContext()->GetJSValueFromMap(pCloneNode));
1197}
weili44f8faf2016-06-01 14:03:56 -07001198
Dan Sinclair1770c022016-03-14 14:14:16 -04001199void CXFA_Node::Script_NodeClass_GetAttribute(CFXJSE_Arguments* pArguments) {
1200 int32_t iLength = pArguments->GetLength();
1201 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001202 ThrowParamCountMismatchException(L"getAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001203 return;
1204 }
tsepez6fe7d212016-04-06 10:51:14 -07001205 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001206 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001207 CFX_WideString wsValue;
tsepez4c3debb2016-04-08 12:20:38 -07001208 GetAttribute(wsExpression.AsStringC(), wsValue);
dsinclair12a6b0c2016-05-26 11:14:08 -07001209 CFXJSE_Value* pValue = pArguments->GetReturnValue();
weili44f8faf2016-06-01 14:03:56 -07001210 if (pValue)
Tom Sepezf0b65542017-02-13 10:26:01 -08001211 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001212}
weili44f8faf2016-06-01 14:03:56 -07001213
Dan Sinclair1770c022016-03-14 14:14:16 -04001214void CXFA_Node::Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments) {
1215 int32_t iLength = pArguments->GetLength();
1216 if (iLength < 1 || iLength > 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001217 ThrowParamCountMismatchException(L"getElement");
Dan Sinclair1770c022016-03-14 14:14:16 -04001218 return;
1219 }
1220 CFX_WideString wsExpression;
1221 int32_t iValue = 0;
weili44f8faf2016-06-01 14:03:56 -07001222 wsExpression =
1223 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
1224 if (iLength >= 2)
Dan Sinclair1770c022016-03-14 14:14:16 -04001225 iValue = pArguments->GetInt32(1);
dsinclair6e124782016-06-23 12:14:55 -07001226 CXFA_Node* pNode =
1227 GetProperty(iValue, XFA_GetElementTypeForName(wsExpression.AsStringC()));
dsinclairf27aeec2016-06-07 19:36:18 -07001228 pArguments->GetReturnValue()->Assign(
1229 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04001230}
weili65be4b12016-05-25 15:47:43 -07001231
Dan Sinclair1770c022016-03-14 14:14:16 -04001232void CXFA_Node::Script_NodeClass_IsPropertySpecified(
1233 CFXJSE_Arguments* pArguments) {
1234 int32_t iLength = pArguments->GetLength();
1235 if (iLength < 1 || iLength > 3) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001236 ThrowParamCountMismatchException(L"isPropertySpecified");
Dan Sinclair1770c022016-03-14 14:14:16 -04001237 return;
1238 }
1239 CFX_WideString wsExpression;
weili44f8faf2016-06-01 14:03:56 -07001240 bool bParent = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001241 int32_t iIndex = 0;
weili44f8faf2016-06-01 14:03:56 -07001242 wsExpression =
1243 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
weili65be4b12016-05-25 15:47:43 -07001244 if (iLength >= 2)
weili44f8faf2016-06-01 14:03:56 -07001245 bParent = !!pArguments->GetInt32(1);
weili65be4b12016-05-25 15:47:43 -07001246 if (iLength >= 3)
Dan Sinclair1770c022016-03-14 14:14:16 -04001247 iIndex = pArguments->GetInt32(2);
tsepezd19e9122016-11-02 15:43:18 -07001248 bool bHas = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001249 const XFA_ATTRIBUTEINFO* pAttributeInfo =
tsepez4c3debb2016-04-08 12:20:38 -07001250 XFA_GetAttributeByName(wsExpression.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001251 CFX_WideString wsValue;
weili65be4b12016-05-25 15:47:43 -07001252 if (pAttributeInfo)
Dan Sinclair1770c022016-03-14 14:14:16 -04001253 bHas = HasAttribute(pAttributeInfo->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04001254 if (!bHas) {
dsinclair6e124782016-06-23 12:14:55 -07001255 XFA_Element eType = XFA_GetElementTypeForName(wsExpression.AsStringC());
1256 bHas = !!GetProperty(iIndex, eType);
weili65be4b12016-05-25 15:47:43 -07001257 if (!bHas && bParent && m_pParent) {
1258 // Also check on the parent.
1259 bHas = m_pParent->HasAttribute(pAttributeInfo->eName);
1260 if (!bHas)
dsinclair6e124782016-06-23 12:14:55 -07001261 bHas = !!m_pParent->GetProperty(iIndex, eType);
weili65be4b12016-05-25 15:47:43 -07001262 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001263 }
dsinclair12a6b0c2016-05-26 11:14:08 -07001264 CFXJSE_Value* pValue = pArguments->GetReturnValue();
1265 if (pValue)
dsinclairf27aeec2016-06-07 19:36:18 -07001266 pValue->SetBoolean(bHas);
Dan Sinclair1770c022016-03-14 14:14:16 -04001267}
weili65be4b12016-05-25 15:47:43 -07001268
Dan Sinclair1770c022016-03-14 14:14:16 -04001269void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) {
1270 int32_t iLength = pArguments->GetLength();
1271 if (iLength < 1 || iLength > 3) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001272 ThrowParamCountMismatchException(L"loadXML");
Dan Sinclair1770c022016-03-14 14:14:16 -04001273 return;
1274 }
Dan Sinclairfdf7d402017-04-18 15:25:58 -04001275
weili44f8faf2016-06-01 14:03:56 -07001276 bool bIgnoreRoot = true;
1277 bool bOverwrite = 0;
Dan Sinclairfdf7d402017-04-18 15:25:58 -04001278 CFX_ByteString wsExpression = pArguments->GetUTF8String(0);
weili44f8faf2016-06-01 14:03:56 -07001279 if (wsExpression.IsEmpty())
Tom Sepezd3743ea2016-05-16 15:56:53 -07001280 return;
weili44f8faf2016-06-01 14:03:56 -07001281 if (iLength >= 2)
1282 bIgnoreRoot = !!pArguments->GetInt32(1);
1283 if (iLength >= 3)
1284 bOverwrite = !!pArguments->GetInt32(2);
Dan Sinclairfdf7d402017-04-18 15:25:58 -04001285 auto pParser = pdfium::MakeUnique<CXFA_SimpleParser>(m_pDocument, false);
weili44f8faf2016-06-01 14:03:56 -07001286 if (!pParser)
Dan Sinclair1770c022016-03-14 14:14:16 -04001287 return;
Dan Sinclairdf673c22017-05-04 12:09:52 -04001288 CFX_XMLNode* pXMLNode = pParser->ParseXMLData(wsExpression);
Dan Sinclairfdf7d402017-04-18 15:25:58 -04001289 if (!pXMLNode)
weili44f8faf2016-06-01 14:03:56 -07001290 return;
dsinclairae95f762016-03-29 16:58:29 -07001291 if (bIgnoreRoot &&
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04001292 (pXMLNode->GetType() != FX_XMLNODE_Element ||
1293 XFA_RecognizeRichText(static_cast<CFX_XMLElement*>(pXMLNode)))) {
weili44f8faf2016-06-01 14:03:56 -07001294 bIgnoreRoot = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001295 }
tsepezd19e9122016-11-02 15:43:18 -07001296 CXFA_Node* pFakeRoot = Clone(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001297 CFX_WideStringC wsContentType = GetCData(XFA_ATTRIBUTE_ContentType);
1298 if (!wsContentType.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07001299 pFakeRoot->SetCData(XFA_ATTRIBUTE_ContentType,
1300 CFX_WideString(wsContentType));
Dan Sinclair1770c022016-03-14 14:14:16 -04001301 }
Dan Sinclair93bfc262017-04-04 15:10:00 -04001302
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04001303 std::unique_ptr<CFX_XMLNode> pFakeXMLRoot(pFakeRoot->GetXMLMappingNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001304 if (!pFakeXMLRoot) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04001305 CFX_XMLNode* pThisXMLRoot = GetXMLMappingNode();
Dan Sinclair93bfc262017-04-04 15:10:00 -04001306 pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone() : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001307 }
Dan Sinclair93bfc262017-04-04 15:10:00 -04001308 if (!pFakeXMLRoot) {
1309 pFakeXMLRoot =
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04001310 pdfium::MakeUnique<CFX_XMLElement>(CFX_WideString(GetClassName()));
Dan Sinclair93bfc262017-04-04 15:10:00 -04001311 }
dsinclair017052a2016-06-28 07:43:51 -07001312
Dan Sinclair1770c022016-03-14 14:14:16 -04001313 if (bIgnoreRoot) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04001314 CFX_XMLNode* pXMLChild = pXMLNode->GetNodeItem(CFX_XMLNode::FirstChild);
Dan Sinclair1770c022016-03-14 14:14:16 -04001315 while (pXMLChild) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04001316 CFX_XMLNode* pXMLSibling =
1317 pXMLChild->GetNodeItem(CFX_XMLNode::NextSibling);
Dan Sinclair1770c022016-03-14 14:14:16 -04001318 pXMLNode->RemoveChildNode(pXMLChild);
1319 pFakeXMLRoot->InsertChildNode(pXMLChild);
1320 pXMLChild = pXMLSibling;
1321 }
1322 } else {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04001323 CFX_XMLNode* pXMLParent = pXMLNode->GetNodeItem(CFX_XMLNode::Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001324 if (pXMLParent) {
1325 pXMLParent->RemoveChildNode(pXMLNode);
1326 }
1327 pFakeXMLRoot->InsertChildNode(pXMLNode);
1328 }
Dan Sinclair93bfc262017-04-04 15:10:00 -04001329 pParser->ConstructXFANode(pFakeRoot, pFakeXMLRoot.get());
Dan Sinclair1770c022016-03-14 14:14:16 -04001330 pFakeRoot = pParser->GetRootNode();
Dan Sinclair93bfc262017-04-04 15:10:00 -04001331 if (!pFakeRoot)
1332 return;
1333
1334 if (bOverwrite) {
1335 CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild);
1336 CXFA_Node* pNewChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
1337 int32_t index = 0;
1338 while (pNewChild) {
1339 CXFA_Node* pItem = pNewChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1340 pFakeRoot->RemoveChild(pNewChild);
1341 InsertChild(index++, pNewChild);
1342 pNewChild->SetFlag(XFA_NodeFlag_Initialized, true);
1343 pNewChild = pItem;
Dan Sinclair1770c022016-03-14 14:14:16 -04001344 }
Dan Sinclair93bfc262017-04-04 15:10:00 -04001345 while (pChild) {
1346 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1347 RemoveChild(pChild);
1348 pFakeRoot->InsertChild(pChild);
1349 pChild = pItem;
Dan Sinclair1770c022016-03-14 14:14:16 -04001350 }
Dan Sinclair93bfc262017-04-04 15:10:00 -04001351 if (GetPacketID() == XFA_XDPPACKET_Form &&
1352 GetElementType() == XFA_Element::ExData) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04001353 CFX_XMLNode* pTempXMLNode = GetXMLMappingNode();
Dan Sinclair93bfc262017-04-04 15:10:00 -04001354 SetXMLMappingNode(pFakeXMLRoot.release());
1355 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04001356 if (pTempXMLNode && !pTempXMLNode->GetNodeItem(CFX_XMLNode::Parent))
Dan Sinclair93bfc262017-04-04 15:10:00 -04001357 pFakeXMLRoot.reset(pTempXMLNode);
1358 else
1359 pFakeXMLRoot = nullptr;
1360 }
1361 MoveBufferMapData(pFakeRoot, this, XFA_CalcData, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001362 } else {
Dan Sinclair93bfc262017-04-04 15:10:00 -04001363 CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
1364 while (pChild) {
1365 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1366 pFakeRoot->RemoveChild(pChild);
1367 InsertChild(pChild);
1368 pChild->SetFlag(XFA_NodeFlag_Initialized, true);
1369 pChild = pItem;
1370 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001371 }
Dan Sinclair93bfc262017-04-04 15:10:00 -04001372 if (pFakeXMLRoot) {
1373 pFakeRoot->SetXMLMappingNode(pFakeXMLRoot.release());
1374 pFakeRoot->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
1375 }
1376 pFakeRoot->SetFlag(XFA_NodeFlag_HasRemovedChildren, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001377}
weili44f8faf2016-06-01 14:03:56 -07001378
Dan Sinclair1770c022016-03-14 14:14:16 -04001379void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) {
weili44f8faf2016-06-01 14:03:56 -07001380 // TODO(weili): Check whether we need to implement this, pdfium:501.
Dan Sinclair1770c022016-03-14 14:14:16 -04001381}
1382
1383void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) {
1384 int32_t iLength = pArguments->GetLength();
1385 if (iLength < 0 || iLength > 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001386 ThrowParamCountMismatchException(L"saveXML");
Dan Sinclair1770c022016-03-14 14:14:16 -04001387 return;
1388 }
weili44f8faf2016-06-01 14:03:56 -07001389 bool bPrettyMode = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001390 if (iLength == 1) {
weili65be4b12016-05-25 15:47:43 -07001391 if (pArguments->GetUTF8String(0) != "pretty") {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001392 ThrowArgumentMismatchException();
Dan Sinclair1770c022016-03-14 14:14:16 -04001393 return;
1394 }
weili44f8faf2016-06-01 14:03:56 -07001395 bPrettyMode = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001396 }
Dan Sinclair5ae87922017-04-18 11:54:04 -04001397 CFX_WideString bsXMLHeader = L"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
weili65be4b12016-05-25 15:47:43 -07001398 if (GetPacketID() == XFA_XDPPACKET_Form ||
1399 GetPacketID() == XFA_XDPPACKET_Datasets) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04001400 CFX_XMLNode* pElement = nullptr;
weili65be4b12016-05-25 15:47:43 -07001401 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
1402 pElement = GetXMLMappingNode();
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04001403 if (!pElement || pElement->GetType() != FX_XMLNODE_Element) {
Dan Sinclair5ae87922017-04-18 11:54:04 -04001404 pArguments->GetReturnValue()->SetString(
1405 bsXMLHeader.UTF8Encode().AsStringC());
weili65be4b12016-05-25 15:47:43 -07001406 return;
1407 }
1408 XFA_DataExporter_DealWithDataGroupNode(this);
1409 }
Dan Sinclair283a0432017-04-20 14:11:21 -04001410 auto pMemoryStream = pdfium::MakeRetain<CFX_MemoryStream>(true);
Dan Sinclair3b71d262017-04-19 08:58:54 -04001411 auto pStream =
1412 pdfium::MakeRetain<CFX_SeekableStreamProxy>(pMemoryStream, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001413 pStream->SetCodePage(FX_CODEPAGE_UTF8);
Dan Sinclair5ae87922017-04-18 11:54:04 -04001414 pStream->WriteString(bsXMLHeader.AsStringC());
1415
weili65be4b12016-05-25 15:47:43 -07001416 if (GetPacketID() == XFA_XDPPACKET_Form)
tsepez7cda31a2016-12-07 12:10:20 -08001417 XFA_DataExporter_RegenerateFormFile(this, pStream, nullptr, true);
weili65be4b12016-05-25 15:47:43 -07001418 else
tsepez7cda31a2016-12-07 12:10:20 -08001419 pElement->SaveXMLNode(pStream);
weili65be4b12016-05-25 15:47:43 -07001420 // TODO(weili): Check whether we need to save pretty print XML, pdfium:501.
1421 // For now, just put it here to avoid unused variable warning.
1422 (void)bPrettyMode;
dsinclairf27aeec2016-06-07 19:36:18 -07001423 pArguments->GetReturnValue()->SetString(
Dan Sinclair1770c022016-03-14 14:14:16 -04001424 CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001425 return;
1426 }
dsinclairf27aeec2016-06-07 19:36:18 -07001427 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04001428}
1429
1430void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) {
1431 int32_t iLength = pArguments->GetLength();
1432 if (iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001433 ThrowParamCountMismatchException(L"setAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001434 return;
1435 }
tsepez6fe7d212016-04-06 10:51:14 -07001436 CFX_WideString wsAttributeValue =
tsepez4c3debb2016-04-08 12:20:38 -07001437 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
tsepez6fe7d212016-04-06 10:51:14 -07001438 CFX_WideString wsAttribute =
tsepez4c3debb2016-04-08 12:20:38 -07001439 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili44f8faf2016-06-01 14:03:56 -07001440 SetAttribute(wsAttribute.AsStringC(), wsAttributeValue.AsStringC(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001441}
weili60607c32016-05-26 11:53:12 -07001442
Dan Sinclair1770c022016-03-14 14:14:16 -04001443void CXFA_Node::Script_NodeClass_SetElement(CFXJSE_Arguments* pArguments) {
1444 int32_t iLength = pArguments->GetLength();
1445 if (iLength != 1 && iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001446 ThrowParamCountMismatchException(L"setElement");
Dan Sinclair1770c022016-03-14 14:14:16 -04001447 return;
1448 }
weili60607c32016-05-26 11:53:12 -07001449 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001450 CFX_WideString wsName;
weili44f8faf2016-06-01 14:03:56 -07001451 pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
1452 if (iLength == 2)
weili60607c32016-05-26 11:53:12 -07001453 wsName = CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili60607c32016-05-26 11:53:12 -07001454 // TODO(weili): check whether we need to implement this, pdfium:501.
1455 // For now, just put the variables here to avoid unused variable warning.
1456 (void)pNode;
1457 (void)wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04001458}
weili60607c32016-05-26 11:53:12 -07001459
dsinclair12a6b0c2016-05-26 11:14:08 -07001460void CXFA_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001461 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001462 XFA_ATTRIBUTE eAttribute) {
1463 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001464 ThrowInvalidPropertyException();
1465 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001466 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001467
1468 CFX_WideString wsNameSpace;
1469 TryNamespace(wsNameSpace);
Tom Sepezf0b65542017-02-13 10:26:01 -08001470 pValue->SetString(wsNameSpace.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001471}
weili44f8faf2016-06-01 14:03:56 -07001472
dsinclair12a6b0c2016-05-26 11:14:08 -07001473void CXFA_Node::Script_NodeClass_Model(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001474 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001475 XFA_ATTRIBUTE eAttribute) {
1476 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001477 ThrowInvalidPropertyException();
1478 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001479 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001480 pValue->Assign(
1481 m_pDocument->GetScriptContext()->GetJSValueFromMap(GetModelNode()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001482}
weili44f8faf2016-06-01 14:03:56 -07001483
dsinclair12a6b0c2016-05-26 11:14:08 -07001484void CXFA_Node::Script_NodeClass_IsContainer(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001485 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001486 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001487 if (bSetting) {
1488 ThrowInvalidPropertyException();
1489 return;
1490 }
1491 pValue->SetBoolean(IsContainerNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001492}
weili44f8faf2016-06-01 14:03:56 -07001493
dsinclair12a6b0c2016-05-26 11:14:08 -07001494void CXFA_Node::Script_NodeClass_IsNull(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001495 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001496 XFA_ATTRIBUTE eAttribute) {
1497 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001498 ThrowInvalidPropertyException();
1499 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001500 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001501 if (GetElementType() == XFA_Element::Subform) {
1502 pValue->SetBoolean(false);
1503 return;
1504 }
1505 CFX_WideString strValue;
1506 pValue->SetBoolean(!TryContent(strValue) || strValue.IsEmpty());
Dan Sinclair1770c022016-03-14 14:14:16 -04001507}
weili44f8faf2016-06-01 14:03:56 -07001508
dsinclair12a6b0c2016-05-26 11:14:08 -07001509void CXFA_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001510 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001511 XFA_ATTRIBUTE eAttribute) {
1512 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001513 ThrowInvalidPropertyException();
1514 return;
1515 }
Tom Sepezf8a94392017-03-14 12:13:22 -07001516 std::vector<CXFA_Node*> properties =
1517 GetNodeList(XFA_NODEFILTER_OneOfProperty);
1518 if (!properties.empty()) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001519 pValue->Assign(
Tom Sepezf8a94392017-03-14 12:13:22 -07001520 m_pDocument->GetScriptContext()->GetJSValueFromMap(properties.front()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001521 }
1522}
weili44f8faf2016-06-01 14:03:56 -07001523
Dan Sinclair1770c022016-03-14 14:14:16 -04001524void CXFA_Node::Script_ContainerClass_GetDelta(CFXJSE_Arguments* pArguments) {}
dsinclairf27aeec2016-06-07 19:36:18 -07001525
Dan Sinclair1770c022016-03-14 14:14:16 -04001526void CXFA_Node::Script_ContainerClass_GetDeltas(CFXJSE_Arguments* pArguments) {
1527 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
dsinclairf27aeec2016-06-07 19:36:18 -07001528 pArguments->GetReturnValue()->SetObject(
1529 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001530}
1531void CXFA_Node::Script_ModelClass_ClearErrorList(CFXJSE_Arguments* pArguments) {
1532}
dsinclair5b36f0a2016-07-19 10:56:23 -07001533
Dan Sinclair1770c022016-03-14 14:14:16 -04001534void CXFA_Node::Script_ModelClass_CreateNode(CFXJSE_Arguments* pArguments) {
1535 Script_Template_CreateNode(pArguments);
1536}
dsinclair5b36f0a2016-07-19 10:56:23 -07001537
Dan Sinclair1770c022016-03-14 14:14:16 -04001538void CXFA_Node::Script_ModelClass_IsCompatibleNS(CFXJSE_Arguments* pArguments) {
1539 int32_t iLength = pArguments->GetLength();
1540 if (iLength < 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001541 ThrowParamCountMismatchException(L"isCompatibleNS");
Dan Sinclair1770c022016-03-14 14:14:16 -04001542 return;
1543 }
1544 CFX_WideString wsNameSpace;
1545 if (iLength >= 1) {
1546 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07001547 wsNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001548 }
1549 CFX_WideString wsNodeNameSpace;
1550 TryNamespace(wsNodeNameSpace);
dsinclair12a6b0c2016-05-26 11:14:08 -07001551 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07001552 if (pValue)
1553 pValue->SetBoolean(wsNodeNameSpace == wsNameSpace);
Dan Sinclair1770c022016-03-14 14:14:16 -04001554}
dsinclair5b36f0a2016-07-19 10:56:23 -07001555
dsinclair12a6b0c2016-05-26 11:14:08 -07001556void CXFA_Node::Script_ModelClass_Context(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001557 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001558 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001559
dsinclair12a6b0c2016-05-26 11:14:08 -07001560void CXFA_Node::Script_ModelClass_AliasNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001561 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001562 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001563
dsinclair12a6b0c2016-05-26 11:14:08 -07001564void CXFA_Node::Script_Attribute_Integer(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001565 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001566 XFA_ATTRIBUTE eAttribute) {
1567 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001568 SetInteger(eAttribute, pValue->ToInteger(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001569 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001570 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001571 }
1572}
dsinclair5b36f0a2016-07-19 10:56:23 -07001573
dsinclair12a6b0c2016-05-26 11:14:08 -07001574void CXFA_Node::Script_Attribute_IntegerRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001575 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001576 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001577 if (bSetting) {
1578 ThrowInvalidPropertyException();
1579 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001580 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001581 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001582}
dsinclair5b36f0a2016-07-19 10:56:23 -07001583
dsinclair12a6b0c2016-05-26 11:14:08 -07001584void CXFA_Node::Script_Attribute_BOOL(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001585 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001586 XFA_ATTRIBUTE eAttribute) {
1587 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001588 SetBoolean(eAttribute, pValue->ToBoolean(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001589 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001590 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001591 }
1592}
dsinclair5b36f0a2016-07-19 10:56:23 -07001593
dsinclair12a6b0c2016-05-26 11:14:08 -07001594void CXFA_Node::Script_Attribute_BOOLRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001595 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001596 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001597 if (bSetting) {
1598 ThrowInvalidPropertyException();
1599 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001600 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001601 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001602}
thestigb1a59592016-04-14 18:29:56 -07001603
Dan Sinclair1770c022016-03-14 14:14:16 -04001604void CXFA_Node::Script_Attribute_SendAttributeChangeMessage(
thestigb1a59592016-04-14 18:29:56 -07001605 XFA_ATTRIBUTE eAttribute,
tsepezd19e9122016-11-02 15:43:18 -07001606 bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001607 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
thestigb1a59592016-04-14 18:29:56 -07001608 if (!pLayoutPro)
Dan Sinclair1770c022016-03-14 14:14:16 -04001609 return;
thestigb1a59592016-04-14 18:29:56 -07001610
dsinclaira1b07722016-07-11 08:20:58 -07001611 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07001612 if (!pNotify)
1613 return;
1614
1615 uint32_t dwPacket = GetPacketID();
1616 if (!(dwPacket & XFA_XDPPACKET_Form)) {
1617 pNotify->OnValueChanged(this, eAttribute, this, this);
Dan Sinclair1770c022016-03-14 14:14:16 -04001618 return;
1619 }
thestigb1a59592016-04-14 18:29:56 -07001620
1621 bool bNeedFindContainer = false;
dsinclair41cb62e2016-06-23 09:20:32 -07001622 switch (GetElementType()) {
dsinclair56a8b192016-06-21 14:15:25 -07001623 case XFA_Element::Caption:
thestigb1a59592016-04-14 18:29:56 -07001624 bNeedFindContainer = true;
1625 pNotify->OnValueChanged(this, eAttribute, this,
1626 GetNodeItem(XFA_NODEITEM_Parent));
1627 break;
dsinclair56a8b192016-06-21 14:15:25 -07001628 case XFA_Element::Font:
1629 case XFA_Element::Para: {
thestigb1a59592016-04-14 18:29:56 -07001630 bNeedFindContainer = true;
1631 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001632 if (pParentNode->GetElementType() == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001633 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1634 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1635 } else {
1636 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
1637 }
1638 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001639 case XFA_Element::Margin: {
thestigb1a59592016-04-14 18:29:56 -07001640 bNeedFindContainer = true;
1641 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001642 XFA_Element eParentType = pParentNode->GetElementType();
thestigb1a59592016-04-14 18:29:56 -07001643 if (pParentNode->IsContainerNode()) {
1644 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
dsinclair56a8b192016-06-21 14:15:25 -07001645 } else if (eParentType == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001646 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1647 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1648 } else {
1649 CXFA_Node* pNode = pParentNode->GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001650 if (pNode && pNode->GetElementType() == XFA_Element::Ui) {
thestigb1a59592016-04-14 18:29:56 -07001651 pNotify->OnValueChanged(this, eAttribute, pNode,
1652 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001653 }
thestigb1a59592016-04-14 18:29:56 -07001654 }
1655 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001656 case XFA_Element::Comb: {
thestigb1a59592016-04-14 18:29:56 -07001657 CXFA_Node* pEditNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001658 XFA_Element eUIType = pEditNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07001659 if (pEditNode && (eUIType == XFA_Element::DateTimeEdit ||
1660 eUIType == XFA_Element::NumericEdit ||
1661 eUIType == XFA_Element::TextEdit)) {
thestigb1a59592016-04-14 18:29:56 -07001662 CXFA_Node* pUINode = pEditNode->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001663 if (pUINode) {
thestigb1a59592016-04-14 18:29:56 -07001664 pNotify->OnValueChanged(this, eAttribute, pUINode,
1665 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001666 }
thestigb1a59592016-04-14 18:29:56 -07001667 }
1668 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001669 case XFA_Element::Button:
1670 case XFA_Element::Barcode:
1671 case XFA_Element::ChoiceList:
1672 case XFA_Element::DateTimeEdit:
1673 case XFA_Element::NumericEdit:
1674 case XFA_Element::PasswordEdit:
1675 case XFA_Element::TextEdit: {
thestigb1a59592016-04-14 18:29:56 -07001676 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1677 if (pUINode) {
1678 pNotify->OnValueChanged(this, eAttribute, pUINode,
1679 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1680 }
1681 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001682 case XFA_Element::CheckButton: {
thestigb1a59592016-04-14 18:29:56 -07001683 bNeedFindContainer = true;
1684 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1685 if (pUINode) {
1686 pNotify->OnValueChanged(this, eAttribute, pUINode,
1687 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1688 }
1689 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001690 case XFA_Element::Keep:
1691 case XFA_Element::Bookend:
1692 case XFA_Element::Break:
1693 case XFA_Element::BreakAfter:
1694 case XFA_Element::BreakBefore:
1695 case XFA_Element::Overflow:
thestigb1a59592016-04-14 18:29:56 -07001696 bNeedFindContainer = true;
1697 break;
dsinclair56a8b192016-06-21 14:15:25 -07001698 case XFA_Element::Area:
1699 case XFA_Element::Draw:
1700 case XFA_Element::ExclGroup:
1701 case XFA_Element::Field:
1702 case XFA_Element::Subform:
1703 case XFA_Element::SubformSet:
thestigb1a59592016-04-14 18:29:56 -07001704 pLayoutPro->AddChangedContainer(this);
1705 pNotify->OnValueChanged(this, eAttribute, this, this);
1706 break;
dsinclair56a8b192016-06-21 14:15:25 -07001707 case XFA_Element::Sharptext:
1708 case XFA_Element::Sharpxml:
1709 case XFA_Element::SharpxHTML: {
thestigb1a59592016-04-14 18:29:56 -07001710 CXFA_Node* pTextNode = GetNodeItem(XFA_NODEITEM_Parent);
1711 if (!pTextNode) {
1712 return;
1713 }
1714 CXFA_Node* pValueNode = pTextNode->GetNodeItem(XFA_NODEITEM_Parent);
1715 if (!pValueNode) {
1716 return;
1717 }
dsinclair41cb62e2016-06-23 09:20:32 -07001718 XFA_Element eType = pValueNode->GetElementType();
1719 if (eType == XFA_Element::Value) {
thestigb1a59592016-04-14 18:29:56 -07001720 bNeedFindContainer = true;
1721 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1722 if (pNode && pNode->IsContainerNode()) {
1723 if (bScriptModify) {
1724 pValueNode = pNode;
1725 }
1726 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
1727 } else {
1728 pNotify->OnValueChanged(this, eAttribute, pNode,
1729 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001730 }
thestigb1a59592016-04-14 18:29:56 -07001731 } else {
dsinclair41cb62e2016-06-23 09:20:32 -07001732 if (eType == XFA_Element::Items) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001733 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1734 if (pNode && pNode->IsContainerNode()) {
thestigb1a59592016-04-14 18:29:56 -07001735 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04001736 }
1737 }
thestigb1a59592016-04-14 18:29:56 -07001738 }
1739 } break;
1740 default:
1741 break;
1742 }
1743 if (bNeedFindContainer) {
1744 CXFA_Node* pParent = this;
1745 while (pParent) {
1746 if (pParent->IsContainerNode())
Dan Sinclair1770c022016-03-14 14:14:16 -04001747 break;
thestigb1a59592016-04-14 18:29:56 -07001748
1749 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001750 }
thestigb1a59592016-04-14 18:29:56 -07001751 if (pParent) {
1752 pLayoutPro->AddChangedContainer(pParent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001753 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001754 }
1755}
thestigb1a59592016-04-14 18:29:56 -07001756
dsinclair12a6b0c2016-05-26 11:14:08 -07001757void CXFA_Node::Script_Attribute_String(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001758 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001759 XFA_ATTRIBUTE eAttribute) {
1760 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001761 CFX_WideString wsValue = pValue->ToWideString();
thestigb1a59592016-04-14 18:29:56 -07001762 SetAttribute(eAttribute, wsValue.AsStringC(), true);
dsinclair070fcdf2016-06-22 22:04:54 -07001763 if (eAttribute == XFA_ATTRIBUTE_Use &&
1764 GetElementType() == XFA_Element::Desc) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001765 CXFA_Node* pTemplateNode =
1766 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
1767 CXFA_Node* pProtoRoot =
dsinclair56a8b192016-06-21 14:15:25 -07001768 pTemplateNode->GetFirstChildByClass(XFA_Element::Subform)
1769 ->GetFirstChildByClass(XFA_Element::Proto);
dsinclair2f5582f2016-06-09 11:48:23 -07001770
1771 CFX_WideString wsID;
1772 CFX_WideString wsSOM;
1773 if (!wsValue.IsEmpty()) {
1774 if (wsValue[0] == '#') {
1775 wsID = CFX_WideString(wsValue.c_str() + 1, wsValue.GetLength() - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04001776 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07001777 wsSOM = wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04001778 }
1779 }
weili44f8faf2016-06-01 14:03:56 -07001780 CXFA_Node* pProtoNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001781 if (!wsSOM.IsEmpty()) {
tsepez736f28a2016-03-25 14:19:51 -07001782 uint32_t dwFlag = XFA_RESOLVENODE_Children |
Dan Sinclair1770c022016-03-14 14:14:16 -04001783 XFA_RESOLVENODE_Attributes |
1784 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1785 XFA_RESOLVENODE_Siblings;
1786 XFA_RESOLVENODE_RS resoveNodeRS;
1787 int32_t iRet = m_pDocument->GetScriptContext()->ResolveObjects(
tsepez4c3debb2016-04-08 12:20:38 -07001788 pProtoRoot, wsSOM.AsStringC(), resoveNodeRS, dwFlag);
Tom Sepezf8a94392017-03-14 12:13:22 -07001789 if (iRet > 0 && resoveNodeRS.objects.front()->IsNode()) {
1790 pProtoNode = resoveNodeRS.objects.front()->AsNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04001791 }
1792 } else if (!wsID.IsEmpty()) {
tsepez4c3debb2016-04-08 12:20:38 -07001793 pProtoNode = m_pDocument->GetNodeByID(pProtoRoot, wsID.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001794 }
1795 if (pProtoNode) {
1796 CXFA_Node* pHeadChild = GetNodeItem(XFA_NODEITEM_FirstChild);
1797 while (pHeadChild) {
1798 CXFA_Node* pSibling =
1799 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1800 RemoveChild(pHeadChild);
1801 pHeadChild = pSibling;
1802 }
tsepezd19e9122016-11-02 15:43:18 -07001803 CXFA_Node* pProtoForm = pProtoNode->CloneTemplateToForm(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001804 pHeadChild = pProtoForm->GetNodeItem(XFA_NODEITEM_FirstChild);
1805 while (pHeadChild) {
1806 CXFA_Node* pSibling =
1807 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1808 pProtoForm->RemoveChild(pHeadChild);
1809 InsertChild(pHeadChild);
1810 pHeadChild = pSibling;
1811 }
1812 m_pDocument->RemovePurgeNode(pProtoForm);
1813 delete pProtoForm;
1814 }
1815 }
1816 } else {
1817 CFX_WideString wsValue;
1818 GetAttribute(eAttribute, wsValue);
Tom Sepezf0b65542017-02-13 10:26:01 -08001819 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001820 }
1821}
dsinclair5b36f0a2016-07-19 10:56:23 -07001822
dsinclair12a6b0c2016-05-26 11:14:08 -07001823void CXFA_Node::Script_Attribute_StringRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001824 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001825 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001826 if (bSetting) {
1827 ThrowInvalidPropertyException();
1828 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001829 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001830
1831 CFX_WideString wsValue;
1832 GetAttribute(eAttribute, wsValue);
Tom Sepezf0b65542017-02-13 10:26:01 -08001833 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001834}
dsinclair5b36f0a2016-07-19 10:56:23 -07001835
Dan Sinclair1770c022016-03-14 14:14:16 -04001836void CXFA_Node::Script_WsdlConnection_Execute(CFXJSE_Arguments* pArguments) {
1837 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001838 if (argc != 0 && argc != 1) {
1839 ThrowParamCountMismatchException(L"execute");
1840 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001841 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001842 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001843}
dsinclair5b36f0a2016-07-19 10:56:23 -07001844
Dan Sinclair1770c022016-03-14 14:14:16 -04001845void CXFA_Node::Script_Delta_Restore(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001846 if (pArguments->GetLength() != 0)
1847 ThrowParamCountMismatchException(L"restore");
Dan Sinclair1770c022016-03-14 14:14:16 -04001848}
dsinclair5b36f0a2016-07-19 10:56:23 -07001849
dsinclair12a6b0c2016-05-26 11:14:08 -07001850void CXFA_Node::Script_Delta_CurrentValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001851 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001852 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001853
dsinclair12a6b0c2016-05-26 11:14:08 -07001854void CXFA_Node::Script_Delta_SavedValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001855 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001856 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001857
dsinclair12a6b0c2016-05-26 11:14:08 -07001858void CXFA_Node::Script_Delta_Target(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001859 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001860 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001861
dsinclair12a6b0c2016-05-26 11:14:08 -07001862void CXFA_Node::Script_Som_Message(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001863 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001864 XFA_SOM_MESSAGETYPE iMessageType) {
1865 CXFA_WidgetData* pWidgetData = GetWidgetData();
1866 if (!pWidgetData) {
1867 return;
1868 }
tsepezd19e9122016-11-02 15:43:18 -07001869 bool bNew = false;
Dan Sinclairc4ecd7b2017-05-23 10:21:54 -04001870 CXFA_Validate validate = pWidgetData->GetValidate(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001871 if (!validate) {
tsepezd19e9122016-11-02 15:43:18 -07001872 validate = pWidgetData->GetValidate(true);
1873 bNew = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001874 }
1875 if (bSetting) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001876 switch (iMessageType) {
1877 case XFA_SOM_ValidationMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001878 validate.SetScriptMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001879 break;
1880 case XFA_SOM_FormatMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001881 validate.SetFormatMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001882 break;
1883 case XFA_SOM_MandatoryMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001884 validate.SetNullMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001885 break;
1886 default:
1887 break;
1888 }
1889 if (!bNew) {
dsinclaira1b07722016-07-11 08:20:58 -07001890 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04001891 if (!pNotify) {
1892 return;
1893 }
1894 pNotify->AddCalcValidate(this);
1895 }
1896 } else {
1897 CFX_WideString wsMessage;
1898 switch (iMessageType) {
1899 case XFA_SOM_ValidationMessage:
1900 validate.GetScriptMessageText(wsMessage);
1901 break;
1902 case XFA_SOM_FormatMessage:
1903 validate.GetFormatMessageText(wsMessage);
1904 break;
1905 case XFA_SOM_MandatoryMessage:
1906 validate.GetNullMessageText(wsMessage);
1907 break;
1908 default:
1909 break;
1910 }
Tom Sepezf0b65542017-02-13 10:26:01 -08001911 pValue->SetString(wsMessage.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001912 }
1913}
dsinclair5b36f0a2016-07-19 10:56:23 -07001914
dsinclair12a6b0c2016-05-26 11:14:08 -07001915void CXFA_Node::Script_Som_ValidationMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001916 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001917 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001918 Script_Som_Message(pValue, bSetting, XFA_SOM_ValidationMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04001919}
dsinclair5b36f0a2016-07-19 10:56:23 -07001920
dsinclair12a6b0c2016-05-26 11:14:08 -07001921void CXFA_Node::Script_Field_Length(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001922 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001923 XFA_ATTRIBUTE eAttribute) {
1924 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001925 ThrowInvalidPropertyException();
1926 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001927 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001928
1929 CXFA_WidgetData* pWidgetData = GetWidgetData();
1930 if (!pWidgetData) {
1931 pValue->SetInteger(0);
1932 return;
1933 }
1934 pValue->SetInteger(pWidgetData->CountChoiceListItems(true));
Dan Sinclair1770c022016-03-14 14:14:16 -04001935}
dsinclair5b36f0a2016-07-19 10:56:23 -07001936
dsinclair12a6b0c2016-05-26 11:14:08 -07001937void CXFA_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001938 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001939 XFA_ATTRIBUTE eAttribute) {
dsinclair41cb62e2016-06-23 09:20:32 -07001940 XFA_Element eType = GetElementType();
1941 if (eType == XFA_Element::Field) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001942 Script_Field_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001943 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001944 }
1945 if (eType == XFA_Element::Draw) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001946 Script_Draw_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001947 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001948 }
1949 if (eType == XFA_Element::Boolean) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001950 Script_Boolean_Value(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001951 return;
1952 }
1953 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001954 CFX_WideString wsNewValue;
dsinclair769b1372016-06-08 13:12:41 -07001955 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07001956 wsNewValue = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07001957
Dan Sinclair1770c022016-03-14 14:14:16 -04001958 CFX_WideString wsFormatValue(wsNewValue);
weili44f8faf2016-06-01 14:03:56 -07001959 CXFA_WidgetData* pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001960 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001961 CFX_WideString wsPicture;
Tom Sepezf8a94392017-03-14 12:13:22 -07001962 for (CXFA_Node* pFormNode : GetBindItems()) {
1963 if (!pFormNode || pFormNode->HasRemovedChildren())
Dan Sinclair1770c022016-03-14 14:14:16 -04001964 continue;
Dan Sinclair1770c022016-03-14 14:14:16 -04001965 pContainerWidgetData = pFormNode->GetContainerWidgetData();
1966 if (pContainerWidgetData) {
1967 pContainerWidgetData->GetPictureContent(wsPicture,
1968 XFA_VALUEPICTURE_DataBind);
1969 }
Tom Sepezf8a94392017-03-14 12:13:22 -07001970 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -04001971 break;
weili44f8faf2016-06-01 14:03:56 -07001972 pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001973 }
1974 } else if (GetPacketID() == XFA_XDPPACKET_Form) {
1975 pContainerWidgetData = GetContainerWidgetData();
1976 }
1977 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07001978 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04001979 }
tsepezd19e9122016-11-02 15:43:18 -07001980 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001981 } else {
tsepezd19e9122016-11-02 15:43:18 -07001982 CFX_WideString content = GetScriptContent(true);
dsinclair41cb62e2016-06-23 09:20:32 -07001983 if (content.IsEmpty() && eType != XFA_Element::Text &&
1984 eType != XFA_Element::SubmitUrl) {
dsinclairf27aeec2016-06-07 19:36:18 -07001985 pValue->SetNull();
dsinclair41cb62e2016-06-23 09:20:32 -07001986 } else if (eType == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07001987 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair41cb62e2016-06-23 09:20:32 -07001988 } else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) {
tsepez4c3debb2016-04-08 12:20:38 -07001989 CFX_Decimal decimal(content.AsStringC());
Dan Sinclair05df0752017-03-14 14:43:42 -04001990 pValue->SetFloat((float)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04001991 } else {
Tom Sepezf0b65542017-02-13 10:26:01 -08001992 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001993 }
1994 }
1995}
dsinclair5b36f0a2016-07-19 10:56:23 -07001996
dsinclair12a6b0c2016-05-26 11:14:08 -07001997void CXFA_Node::Script_Som_DefaultValue_Read(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001998 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001999 XFA_ATTRIBUTE eAttribute) {
2000 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002001 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002002 return;
2003 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002004
tsepezd19e9122016-11-02 15:43:18 -07002005 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002006 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002007 pValue->SetNull();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002008 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002009 }
Tom Sepezf0b65542017-02-13 10:26:01 -08002010 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002011}
dsinclair5b36f0a2016-07-19 10:56:23 -07002012
dsinclair12a6b0c2016-05-26 11:14:08 -07002013void CXFA_Node::Script_Boolean_Value(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002014 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002015 XFA_ATTRIBUTE eAttribute) {
2016 if (bSetting) {
2017 CFX_ByteString newValue;
dsinclair769b1372016-06-08 13:12:41 -07002018 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002019 newValue = pValue->ToString();
dsinclairf27aeec2016-06-07 19:36:18 -07002020
tsepezb4c9f3f2016-04-13 15:41:21 -07002021 int32_t iValue = FXSYS_atoi(newValue.c_str());
tsepezafe94302016-05-13 17:21:31 -07002022 CFX_WideString wsNewValue(iValue == 0 ? L"0" : L"1");
Dan Sinclair1770c022016-03-14 14:14:16 -04002023 CFX_WideString wsFormatValue(wsNewValue);
2024 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2025 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002026 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002027 }
tsepezd19e9122016-11-02 15:43:18 -07002028 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002029 } else {
tsepezd19e9122016-11-02 15:43:18 -07002030 CFX_WideString wsValue = GetScriptContent(true);
dan sinclair65c7c232017-02-02 14:05:30 -08002031 pValue->SetBoolean(wsValue == L"1");
Dan Sinclair1770c022016-03-14 14:14:16 -04002032 }
2033}
dsinclair2f5582f2016-06-09 11:48:23 -07002034
dsinclair12a6b0c2016-05-26 11:14:08 -07002035void CXFA_Node::Script_Som_BorderColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002036 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002037 XFA_ATTRIBUTE eAttribute) {
2038 CXFA_WidgetData* pWidgetData = GetWidgetData();
2039 if (!pWidgetData) {
2040 return;
2041 }
tsepezd19e9122016-11-02 15:43:18 -07002042 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002043 int32_t iSize = border.CountEdges();
Dan Sinclair1770c022016-03-14 14:14:16 -04002044 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002045 int32_t r = 0;
2046 int32_t g = 0;
2047 int32_t b = 0;
dsinclair5b36f0a2016-07-19 10:56:23 -07002048 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002049 FX_ARGB rgb = ArgbEncode(100, r, g, b);
2050 for (int32_t i = 0; i < iSize; ++i) {
2051 CXFA_Edge edge = border.GetEdge(i);
2052 edge.SetColor(rgb);
2053 }
2054 } else {
2055 CXFA_Edge edge = border.GetEdge(0);
2056 FX_ARGB color = edge.GetColor();
Nicolas Penaddfc3dc2017-04-20 15:29:25 -04002057 int32_t a;
2058 int32_t r;
2059 int32_t g;
2060 int32_t b;
2061 std::tie(a, r, g, b) = ArgbDecode(color);
dsinclair2f5582f2016-06-09 11:48:23 -07002062 CFX_WideString strColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002063 strColor.Format(L"%d,%d,%d", r, g, b);
Tom Sepezf0b65542017-02-13 10:26:01 -08002064 pValue->SetString(strColor.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002065 }
2066}
dsinclair5b36f0a2016-07-19 10:56:23 -07002067
dsinclair12a6b0c2016-05-26 11:14:08 -07002068void CXFA_Node::Script_Som_BorderWidth(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002069 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002070 XFA_ATTRIBUTE eAttribute) {
2071 CXFA_WidgetData* pWidgetData = GetWidgetData();
2072 if (!pWidgetData) {
2073 return;
2074 }
tsepezd19e9122016-11-02 15:43:18 -07002075 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002076 int32_t iSize = border.CountEdges();
2077 CFX_WideString wsThickness;
2078 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002079 wsThickness = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002080 for (int32_t i = 0; i < iSize; ++i) {
2081 CXFA_Edge edge = border.GetEdge(i);
tsepez4c3debb2016-04-08 12:20:38 -07002082 CXFA_Measurement thickness(wsThickness.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002083 edge.SetMSThickness(thickness);
2084 }
2085 } else {
2086 CXFA_Edge edge = border.GetEdge(0);
2087 CXFA_Measurement thickness = edge.GetMSThickness();
2088 thickness.ToString(wsThickness);
Tom Sepezf0b65542017-02-13 10:26:01 -08002089 pValue->SetString(wsThickness.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002090 }
2091}
dsinclair5b36f0a2016-07-19 10:56:23 -07002092
dsinclair12a6b0c2016-05-26 11:14:08 -07002093void CXFA_Node::Script_Som_FillColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002094 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002095 XFA_ATTRIBUTE eAttribute) {
2096 CXFA_WidgetData* pWidgetData = GetWidgetData();
2097 if (!pWidgetData) {
2098 return;
2099 }
tsepezd19e9122016-11-02 15:43:18 -07002100 CXFA_Border border = pWidgetData->GetBorder(true);
2101 CXFA_Fill borderfill = border.GetFill(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002102 CXFA_Node* pNode = borderfill.GetNode();
2103 if (!pNode) {
2104 return;
2105 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002106 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002107 int32_t r;
2108 int32_t g;
2109 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002110 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002111 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2112 borderfill.SetColor(color);
2113 } else {
2114 FX_ARGB color = borderfill.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002115 int32_t a;
2116 int32_t r;
2117 int32_t g;
2118 int32_t b;
Nicolas Penaddfc3dc2017-04-20 15:29:25 -04002119 std::tie(a, r, g, b) = ArgbDecode(color);
dsinclair2f5582f2016-06-09 11:48:23 -07002120 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002121 wsColor.Format(L"%d,%d,%d", r, g, b);
Tom Sepezf0b65542017-02-13 10:26:01 -08002122 pValue->SetString(wsColor.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002123 }
2124}
dsinclair5b36f0a2016-07-19 10:56:23 -07002125
dsinclair12a6b0c2016-05-26 11:14:08 -07002126void CXFA_Node::Script_Som_DataNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002127 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002128 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002129 if (bSetting) {
2130 ThrowInvalidPropertyException();
2131 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002132 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002133
2134 CXFA_Node* pDataNode = GetBindData();
2135 if (!pDataNode) {
2136 pValue->SetNull();
2137 return;
2138 }
2139
2140 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pDataNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002141}
dsinclair5b36f0a2016-07-19 10:56:23 -07002142
dsinclair12a6b0c2016-05-26 11:14:08 -07002143void CXFA_Node::Script_Draw_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002144 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002145 XFA_ATTRIBUTE eAttribute) {
2146 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002147 if (pValue && pValue->IsString()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002148 CXFA_WidgetData* pWidgetData = GetWidgetData();
dsinclair43854a52016-04-27 12:26:00 -07002149 ASSERT(pWidgetData);
dsinclair56a8b192016-06-21 14:15:25 -07002150 XFA_Element uiType = pWidgetData->GetUIType();
2151 if (uiType == XFA_Element::Text) {
dsinclair2f5582f2016-06-09 11:48:23 -07002152 CFX_WideString wsNewValue = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002153 CFX_WideString wsFormatValue(wsNewValue);
tsepezd19e9122016-11-02 15:43:18 -07002154 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002155 }
2156 }
2157 } else {
tsepezd19e9122016-11-02 15:43:18 -07002158 CFX_WideString content = GetScriptContent(true);
Tom Sepezf0b65542017-02-13 10:26:01 -08002159 if (content.IsEmpty())
dsinclairf27aeec2016-06-07 19:36:18 -07002160 pValue->SetNull();
Tom Sepezf0b65542017-02-13 10:26:01 -08002161 else
2162 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002163 }
2164}
dsinclair5b36f0a2016-07-19 10:56:23 -07002165
dsinclair12a6b0c2016-05-26 11:14:08 -07002166void CXFA_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002167 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002168 XFA_ATTRIBUTE eAttribute) {
2169 CXFA_WidgetData* pWidgetData = GetWidgetData();
2170 if (!pWidgetData) {
2171 return;
2172 }
2173 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002174 if (pValue && pValue->IsNull()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002175 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002176 pWidgetData->m_bIsNull = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04002177 } else {
2178 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002179 pWidgetData->m_bIsNull = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04002180 }
dsinclair2f5582f2016-06-09 11:48:23 -07002181 CFX_WideString wsNewText;
dsinclair769b1372016-06-08 13:12:41 -07002182 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002183 wsNewText = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07002184
Dan Sinclair1770c022016-03-14 14:14:16 -04002185 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07002186 if (pUIChild->GetElementType() == XFA_Element::NumericEdit) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002187 int32_t iLeadDigits = 0;
2188 int32_t iFracDigits = 0;
2189 pWidgetData->GetLeadDigits(iLeadDigits);
2190 pWidgetData->GetFracDigits(iFracDigits);
dsinclair44d054c2016-04-06 10:23:46 -07002191 wsNewText =
2192 pWidgetData->NumericLimit(wsNewText, iLeadDigits, iFracDigits);
Dan Sinclair1770c022016-03-14 14:14:16 -04002193 }
2194 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2195 CFX_WideString wsFormatText(wsNewText);
2196 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002197 pContainerWidgetData->GetFormatDataValue(wsNewText, wsFormatText);
Dan Sinclair1770c022016-03-14 14:14:16 -04002198 }
tsepezd19e9122016-11-02 15:43:18 -07002199 SetScriptContent(wsNewText, wsFormatText, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002200 } else {
tsepezd19e9122016-11-02 15:43:18 -07002201 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002202 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002203 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002204 } else {
2205 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
Dan Sinclair1770c022016-03-14 14:14:16 -04002206 CXFA_Value defVal = pWidgetData->GetFormValue();
2207 CXFA_Node* pNode = defVal.GetNode()->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair070fcdf2016-06-22 22:04:54 -07002208 if (pNode && pNode->GetElementType() == XFA_Element::Decimal) {
dsinclair41cb62e2016-06-23 09:20:32 -07002209 if (pUIChild->GetElementType() == XFA_Element::NumericEdit &&
Dan Sinclair1770c022016-03-14 14:14:16 -04002210 (pNode->GetInteger(XFA_ATTRIBUTE_FracDigits) == -1)) {
Tom Sepezf0b65542017-02-13 10:26:01 -08002211 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002212 } else {
tsepez4c3debb2016-04-08 12:20:38 -07002213 CFX_Decimal decimal(content.AsStringC());
Dan Sinclair05df0752017-03-14 14:43:42 -04002214 pValue->SetFloat((float)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002215 }
dsinclair070fcdf2016-06-22 22:04:54 -07002216 } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07002217 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair070fcdf2016-06-22 22:04:54 -07002218 } else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) {
tsepezd19e9122016-11-02 15:43:18 -07002219 pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? false : true);
dsinclair070fcdf2016-06-22 22:04:54 -07002220 } else if (pNode && pNode->GetElementType() == XFA_Element::Float) {
tsepez4c3debb2016-04-08 12:20:38 -07002221 CFX_Decimal decimal(content.AsStringC());
Dan Sinclair05df0752017-03-14 14:43:42 -04002222 pValue->SetFloat((float)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002223 } else {
Tom Sepezf0b65542017-02-13 10:26:01 -08002224 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002225 }
2226 }
2227 }
2228}
dsinclair5b36f0a2016-07-19 10:56:23 -07002229
dsinclair12a6b0c2016-05-26 11:14:08 -07002230void CXFA_Node::Script_Field_EditValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002231 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002232 XFA_ATTRIBUTE eAttribute) {
2233 CXFA_WidgetData* pWidgetData = GetWidgetData();
2234 if (!pWidgetData) {
2235 return;
2236 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002237 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002238 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Edit);
Dan Sinclair1770c022016-03-14 14:14:16 -04002239 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002240 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002241 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Edit);
Tom Sepezf0b65542017-02-13 10:26:01 -08002242 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002243 }
2244}
dsinclair5b36f0a2016-07-19 10:56:23 -07002245
dsinclair12a6b0c2016-05-26 11:14:08 -07002246void CXFA_Node::Script_Som_FontColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002247 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002248 XFA_ATTRIBUTE eAttribute) {
2249 CXFA_WidgetData* pWidgetData = GetWidgetData();
2250 if (!pWidgetData) {
2251 return;
2252 }
tsepezd19e9122016-11-02 15:43:18 -07002253 CXFA_Font font = pWidgetData->GetFont(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002254 CXFA_Node* pNode = font.GetNode();
2255 if (!pNode) {
2256 return;
2257 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002258 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002259 int32_t r;
2260 int32_t g;
2261 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002262 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002263 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2264 font.SetColor(color);
2265 } else {
2266 FX_ARGB color = font.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002267 int32_t a;
2268 int32_t r;
2269 int32_t g;
2270 int32_t b;
Nicolas Penaddfc3dc2017-04-20 15:29:25 -04002271 std::tie(a, r, g, b) = ArgbDecode(color);
dsinclair2f5582f2016-06-09 11:48:23 -07002272 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002273 wsColor.Format(L"%d,%d,%d", r, g, b);
Tom Sepezf0b65542017-02-13 10:26:01 -08002274 pValue->SetString(wsColor.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002275 }
2276}
dsinclair5b36f0a2016-07-19 10:56:23 -07002277
dsinclair12a6b0c2016-05-26 11:14:08 -07002278void CXFA_Node::Script_Field_FormatMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002279 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002280 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002281 Script_Som_Message(pValue, bSetting, XFA_SOM_FormatMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002282}
dsinclair5b36f0a2016-07-19 10:56:23 -07002283
dsinclair12a6b0c2016-05-26 11:14:08 -07002284void CXFA_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002285 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002286 XFA_ATTRIBUTE eAttribute) {
2287 CXFA_WidgetData* pWidgetData = GetWidgetData();
2288 if (!pWidgetData) {
2289 return;
2290 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002291 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002292 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Display);
Dan Sinclair1770c022016-03-14 14:14:16 -04002293 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002294 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002295 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Display);
Tom Sepezf0b65542017-02-13 10:26:01 -08002296 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002297 }
2298}
dsinclair5b36f0a2016-07-19 10:56:23 -07002299
dsinclair12a6b0c2016-05-26 11:14:08 -07002300void CXFA_Node::Script_Som_Mandatory(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002301 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002302 XFA_ATTRIBUTE eAttribute) {
2303 CXFA_WidgetData* pWidgetData = GetWidgetData();
2304 if (!pWidgetData) {
2305 return;
2306 }
tsepezd19e9122016-11-02 15:43:18 -07002307 CXFA_Validate validate = pWidgetData->GetValidate(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002308 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002309 validate.SetNullTest(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04002310 } else {
2311 int32_t iValue = validate.GetNullTest();
2312 const XFA_ATTRIBUTEENUMINFO* pInfo =
dsinclair9eb0db12016-07-21 12:01:39 -07002313 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)iValue);
dsinclair2f5582f2016-06-09 11:48:23 -07002314 CFX_WideString wsValue;
2315 if (pInfo)
Dan Sinclair1770c022016-03-14 14:14:16 -04002316 wsValue = pInfo->pName;
Tom Sepezf0b65542017-02-13 10:26:01 -08002317 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002318 }
2319}
dsinclair5b36f0a2016-07-19 10:56:23 -07002320
dsinclair12a6b0c2016-05-26 11:14:08 -07002321void CXFA_Node::Script_Som_MandatoryMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002322 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002323 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002324 Script_Som_Message(pValue, bSetting, XFA_SOM_MandatoryMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002325}
dsinclair5b36f0a2016-07-19 10:56:23 -07002326
dsinclair12a6b0c2016-05-26 11:14:08 -07002327void CXFA_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002328 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002329 XFA_ATTRIBUTE eAttribute) {
2330 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002331 ThrowInvalidPropertyException();
2332 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002333 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002334 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002335}
dsinclair5b36f0a2016-07-19 10:56:23 -07002336
dsinclair12a6b0c2016-05-26 11:14:08 -07002337void CXFA_Node::Script_Field_SelectedIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002338 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002339 XFA_ATTRIBUTE eAttribute) {
2340 CXFA_WidgetData* pWidgetData = GetWidgetData();
2341 if (!pWidgetData) {
2342 return;
2343 }
2344 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002345 int32_t iIndex = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002346 if (iIndex == -1) {
2347 pWidgetData->ClearAllSelections();
2348 return;
2349 }
tsepezd19e9122016-11-02 15:43:18 -07002350 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002351 } else {
Dan Sinclairc4ecd7b2017-05-23 10:21:54 -04002352 pValue->SetInteger(pWidgetData->GetSelectedItem(0));
Dan Sinclair1770c022016-03-14 14:14:16 -04002353 }
2354}
dsinclair5b36f0a2016-07-19 10:56:23 -07002355
Dan Sinclair1770c022016-03-14 14:14:16 -04002356void CXFA_Node::Script_Field_ClearItems(CFXJSE_Arguments* pArguments) {
2357 CXFA_WidgetData* pWidgetData = GetWidgetData();
2358 if (!pWidgetData) {
2359 return;
2360 }
Dan Sinclairc4ecd7b2017-05-23 10:21:54 -04002361 pWidgetData->DeleteItem(-1, true, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002362}
dsinclair5b36f0a2016-07-19 10:56:23 -07002363
Dan Sinclair1770c022016-03-14 14:14:16 -04002364void CXFA_Node::Script_Field_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002365 if (pArguments->GetLength() != 1) {
2366 ThrowParamCountMismatchException(L"execEvent");
2367 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002368 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002369
2370 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2371 int32_t iRet = execSingleEventByName(
2372 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2373 XFA_Element::Field);
2374 if (eventString != "validate")
2375 return;
2376
2377 pArguments->GetReturnValue()->SetBoolean(
2378 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002379}
dsinclair5b36f0a2016-07-19 10:56:23 -07002380
Dan Sinclair1770c022016-03-14 14:14:16 -04002381void CXFA_Node::Script_Field_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002382 if (pArguments->GetLength() != 0) {
2383 ThrowParamCountMismatchException(L"execInitialize");
2384 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002385 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002386
2387 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2388 if (!pNotify)
2389 return;
2390
2391 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002392}
dsinclair5b36f0a2016-07-19 10:56:23 -07002393
Dan Sinclair1770c022016-03-14 14:14:16 -04002394void CXFA_Node::Script_Field_DeleteItem(CFXJSE_Arguments* pArguments) {
2395 int32_t iLength = pArguments->GetLength();
2396 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002397 ThrowParamCountMismatchException(L"deleteItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002398 return;
2399 }
2400 CXFA_WidgetData* pWidgetData = GetWidgetData();
2401 if (!pWidgetData) {
2402 return;
2403 }
2404 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002405 bool bValue = pWidgetData->DeleteItem(iIndex, true, true);
dsinclair12a6b0c2016-05-26 11:14:08 -07002406 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002407 if (pValue)
2408 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002409}
dsinclair5b36f0a2016-07-19 10:56:23 -07002410
Dan Sinclair1770c022016-03-14 14:14:16 -04002411void CXFA_Node::Script_Field_GetSaveItem(CFXJSE_Arguments* pArguments) {
2412 int32_t iLength = pArguments->GetLength();
2413 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002414 ThrowParamCountMismatchException(L"getSaveItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002415 return;
2416 }
2417 int32_t iIndex = pArguments->GetInt32(0);
2418 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002419 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002420 return;
2421 }
2422 CXFA_WidgetData* pWidgetData = GetWidgetData();
2423 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002424 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002425 return;
2426 }
2427 CFX_WideString wsValue;
Tom Sepezf0b65542017-02-13 10:26:01 -08002428 if (!pWidgetData->GetChoiceListItem(wsValue, iIndex, true)) {
dsinclairf27aeec2016-06-07 19:36:18 -07002429 pArguments->GetReturnValue()->SetNull();
Tom Sepezf0b65542017-02-13 10:26:01 -08002430 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002431 }
Tom Sepezf0b65542017-02-13 10:26:01 -08002432 pArguments->GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002433}
dsinclair5b36f0a2016-07-19 10:56:23 -07002434
Dan Sinclair1770c022016-03-14 14:14:16 -04002435void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments) {
2436 int32_t iLength = pArguments->GetLength();
2437 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002438 ThrowParamCountMismatchException(L"boundItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002439 return;
2440 }
2441 CXFA_WidgetData* pWidgetData = GetWidgetData();
2442 if (!pWidgetData) {
2443 return;
2444 }
2445 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002446 CFX_WideString wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002447 CFX_WideString wsBoundValue;
tsepez4c3debb2016-04-08 12:20:38 -07002448 pWidgetData->GetItemValue(wsValue.AsStringC(), wsBoundValue);
dsinclair12a6b0c2016-05-26 11:14:08 -07002449 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002450 if (pValue)
Tom Sepezf0b65542017-02-13 10:26:01 -08002451 pValue->SetString(wsBoundValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002452}
dsinclair5b36f0a2016-07-19 10:56:23 -07002453
Dan Sinclair1770c022016-03-14 14:14:16 -04002454void CXFA_Node::Script_Field_GetItemState(CFXJSE_Arguments* pArguments) {
2455 int32_t iLength = pArguments->GetLength();
2456 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002457 ThrowParamCountMismatchException(L"getItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002458 return;
2459 }
2460 CXFA_WidgetData* pWidgetData = GetWidgetData();
2461 if (!pWidgetData) {
2462 return;
2463 }
2464 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002465 bool bValue = pWidgetData->GetItemState(iIndex);
dsinclair12a6b0c2016-05-26 11:14:08 -07002466 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002467 if (pValue)
2468 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002469}
dsinclair5b36f0a2016-07-19 10:56:23 -07002470
Dan Sinclair1770c022016-03-14 14:14:16 -04002471void CXFA_Node::Script_Field_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002472 if (pArguments->GetLength() != 0) {
2473 ThrowParamCountMismatchException(L"execCalculate");
2474 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002475 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002476
2477 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2478 if (!pNotify)
2479 return;
2480
2481 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002482}
dsinclair5b36f0a2016-07-19 10:56:23 -07002483
Dan Sinclair1770c022016-03-14 14:14:16 -04002484void CXFA_Node::Script_Field_SetItems(CFXJSE_Arguments* pArguments) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002485
Dan Sinclair1770c022016-03-14 14:14:16 -04002486void CXFA_Node::Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments) {
2487 int32_t iLength = pArguments->GetLength();
2488 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002489 ThrowParamCountMismatchException(L"getDisplayItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002490 return;
2491 }
2492 int32_t iIndex = pArguments->GetInt32(0);
2493 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002494 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002495 return;
2496 }
2497 CXFA_WidgetData* pWidgetData = GetWidgetData();
2498 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002499 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002500 return;
2501 }
2502 CFX_WideString wsValue;
Tom Sepezf0b65542017-02-13 10:26:01 -08002503 if (!pWidgetData->GetChoiceListItem(wsValue, iIndex, false)) {
dsinclairf27aeec2016-06-07 19:36:18 -07002504 pArguments->GetReturnValue()->SetNull();
Tom Sepezf0b65542017-02-13 10:26:01 -08002505 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002506 }
Tom Sepezf0b65542017-02-13 10:26:01 -08002507 pArguments->GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002508}
dsinclair5b36f0a2016-07-19 10:56:23 -07002509
Dan Sinclair1770c022016-03-14 14:14:16 -04002510void CXFA_Node::Script_Field_SetItemState(CFXJSE_Arguments* pArguments) {
2511 int32_t iLength = pArguments->GetLength();
2512 if (iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002513 ThrowParamCountMismatchException(L"setItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002514 return;
2515 }
2516 CXFA_WidgetData* pWidgetData = GetWidgetData();
thestig800222e2016-05-26 22:00:29 -07002517 if (!pWidgetData)
Dan Sinclair1770c022016-03-14 14:14:16 -04002518 return;
thestig800222e2016-05-26 22:00:29 -07002519
Dan Sinclair1770c022016-03-14 14:14:16 -04002520 int32_t iIndex = pArguments->GetInt32(0);
2521 if (pArguments->GetInt32(1) != 0) {
tsepezd19e9122016-11-02 15:43:18 -07002522 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002523 } else {
thestig800222e2016-05-26 22:00:29 -07002524 if (pWidgetData->GetItemState(iIndex))
tsepezd19e9122016-11-02 15:43:18 -07002525 pWidgetData->SetItemState(iIndex, false, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002526 }
2527}
dsinclair5b36f0a2016-07-19 10:56:23 -07002528
Dan Sinclair1770c022016-03-14 14:14:16 -04002529void CXFA_Node::Script_Field_AddItem(CFXJSE_Arguments* pArguments) {
2530 int32_t iLength = pArguments->GetLength();
2531 if (iLength < 1 || iLength > 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002532 ThrowParamCountMismatchException(L"addItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002533 return;
2534 }
2535 CXFA_WidgetData* pWidgetData = GetWidgetData();
2536 if (!pWidgetData) {
2537 return;
2538 }
2539 CFX_WideString wsLabel;
2540 CFX_WideString wsValue;
2541 if (iLength >= 1) {
tsepez6fe7d212016-04-06 10:51:14 -07002542 CFX_ByteString bsLabel = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002543 wsLabel = CFX_WideString::FromUTF8(bsLabel.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002544 }
2545 if (iLength >= 2) {
2546 CFX_ByteString bsValue = pArguments->GetUTF8String(1);
tsepez4c3debb2016-04-08 12:20:38 -07002547 wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002548 }
Dan Sinclairc4ecd7b2017-05-23 10:21:54 -04002549 pWidgetData->InsertItem(wsLabel, wsValue, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002550}
dsinclair5b36f0a2016-07-19 10:56:23 -07002551
Dan Sinclair1770c022016-03-14 14:14:16 -04002552void CXFA_Node::Script_Field_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002553 if (pArguments->GetLength() != 0) {
2554 ThrowParamCountMismatchException(L"execValidate");
2555 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002556 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002557
2558 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2559 if (!pNotify) {
2560 pArguments->GetReturnValue()->SetBoolean(false);
2561 return;
2562 }
2563
2564 int32_t iRet =
2565 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate, false, false);
2566 pArguments->GetReturnValue()->SetBoolean(
2567 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002568}
dsinclair5b36f0a2016-07-19 10:56:23 -07002569
dsinclair12a6b0c2016-05-26 11:14:08 -07002570void CXFA_Node::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002571 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002572 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002573 if (bSetting)
2574 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002575}
dsinclair5b36f0a2016-07-19 10:56:23 -07002576
dsinclair12a6b0c2016-05-26 11:14:08 -07002577void CXFA_Node::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002578 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002579 XFA_ATTRIBUTE eAttribute) {
2580 CXFA_WidgetData* pWidgetData = GetWidgetData();
2581 if (!pWidgetData) {
2582 return;
2583 }
2584 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002585 pWidgetData->SetSelectedMemberByValue(pValue->ToWideString().AsStringC(),
tsepezd19e9122016-11-02 15:43:18 -07002586 true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002587 } else {
tsepezd19e9122016-11-02 15:43:18 -07002588 CFX_WideString wsValue = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002589 XFA_VERSION curVersion = GetDocument()->GetCurVersionMode();
2590 if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) {
dsinclairf27aeec2016-06-07 19:36:18 -07002591 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002592 } else {
Tom Sepezf0b65542017-02-13 10:26:01 -08002593 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002594 }
2595 }
2596}
dsinclair5b36f0a2016-07-19 10:56:23 -07002597
dsinclair12a6b0c2016-05-26 11:14:08 -07002598void CXFA_Node::Script_ExclGroup_Transient(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002599 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002600 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002601
Dan Sinclair1770c022016-03-14 14:14:16 -04002602void CXFA_Node::Script_ExclGroup_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002603 if (pArguments->GetLength() != 1) {
2604 ThrowParamCountMismatchException(L"execEvent");
2605 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002606 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002607
2608 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2609 execSingleEventByName(
2610 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2611 XFA_Element::ExclGroup);
Dan Sinclair1770c022016-03-14 14:14:16 -04002612}
thestig800222e2016-05-26 22:00:29 -07002613
Dan Sinclair1770c022016-03-14 14:14:16 -04002614void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments) {
2615 int32_t argc = pArguments->GetLength();
thestig800222e2016-05-26 22:00:29 -07002616 if (argc < 0 || argc > 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002617 ThrowParamCountMismatchException(L"selectedMember");
thestig800222e2016-05-26 22:00:29 -07002618 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002619 }
thestig800222e2016-05-26 22:00:29 -07002620
2621 CXFA_WidgetData* pWidgetData = GetWidgetData();
2622 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002623 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002624 return;
2625 }
2626
2627 CXFA_Node* pReturnNode = nullptr;
2628 if (argc == 0) {
2629 pReturnNode = pWidgetData->GetSelectedMember();
2630 } else {
2631 CFX_ByteString szName;
2632 szName = pArguments->GetUTF8String(0);
2633 pReturnNode = pWidgetData->SetSelectedMember(
2634 CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC(), true);
2635 }
2636 if (!pReturnNode) {
dsinclairf27aeec2016-06-07 19:36:18 -07002637 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002638 return;
2639 }
dsinclairf27aeec2016-06-07 19:36:18 -07002640 pArguments->GetReturnValue()->Assign(
thestig800222e2016-05-26 22:00:29 -07002641 m_pDocument->GetScriptContext()->GetJSValueFromMap(pReturnNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002642}
thestig800222e2016-05-26 22:00:29 -07002643
Dan Sinclair1770c022016-03-14 14:14:16 -04002644void CXFA_Node::Script_ExclGroup_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002645 if (pArguments->GetLength() != 0) {
2646 ThrowParamCountMismatchException(L"execInitialize");
2647 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002648 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002649
2650 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2651 if (!pNotify)
2652 return;
2653
2654 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04002655}
dsinclair5b36f0a2016-07-19 10:56:23 -07002656
Dan Sinclair1770c022016-03-14 14:14:16 -04002657void CXFA_Node::Script_ExclGroup_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002658 if (pArguments->GetLength() != 0) {
2659 ThrowParamCountMismatchException(L"execCalculate");
2660 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002661 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002662
2663 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2664 if (!pNotify)
2665 return;
2666
2667 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04002668}
dsinclair5b36f0a2016-07-19 10:56:23 -07002669
Dan Sinclair1770c022016-03-14 14:14:16 -04002670void CXFA_Node::Script_ExclGroup_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002671 if (pArguments->GetLength() != 0) {
2672 ThrowParamCountMismatchException(L"execValidate");
2673 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002674 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002675
2676 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2677 if (!pNotify) {
2678 pArguments->GetReturnValue()->SetBoolean(false);
2679 return;
2680 }
2681
2682 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
2683 pArguments->GetReturnValue()->SetBoolean(
2684 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002685}
dsinclair5b36f0a2016-07-19 10:56:23 -07002686
dsinclair12a6b0c2016-05-26 11:14:08 -07002687void CXFA_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002688 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002689 XFA_ATTRIBUTE eAttribute) {
2690 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002691 int32_t iTo = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002692 int32_t iFrom = Subform_and_SubformSet_InstanceIndex();
weili44f8faf2016-06-01 14:03:56 -07002693 CXFA_Node* pManagerNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002694 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2695 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002696 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002697 pManagerNode = pNode;
2698 break;
2699 }
2700 }
2701 if (pManagerNode) {
2702 pManagerNode->InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07002703 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002704 if (!pNotify) {
2705 return;
2706 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002707 CXFA_Node* pToInstance = GetItem(pManagerNode, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07002708 if (pToInstance &&
2709 pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002710 pNotify->RunSubformIndexChange(pToInstance);
2711 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002712 CXFA_Node* pFromInstance = GetItem(pManagerNode, iFrom);
dsinclair56a8b192016-06-21 14:15:25 -07002713 if (pFromInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07002714 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002715 pNotify->RunSubformIndexChange(pFromInstance);
2716 }
2717 }
2718 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002719 pValue->SetInteger(Subform_and_SubformSet_InstanceIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04002720 }
2721}
dsinclair5b36f0a2016-07-19 10:56:23 -07002722
dsinclair12a6b0c2016-05-26 11:14:08 -07002723void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002724 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002725 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002726 if (bSetting) {
2727 ThrowInvalidPropertyException();
2728 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002729 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002730
2731 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
2732 CXFA_Node* pInstanceMgr = nullptr;
2733 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2734 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
2735 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
2736 CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name);
2737 if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' &&
2738 wsInstMgrName.Mid(1) == wsName) {
2739 pInstanceMgr = pNode;
2740 }
2741 break;
2742 }
2743 }
2744 if (!pInstanceMgr) {
2745 pValue->SetNull();
2746 return;
2747 }
2748
2749 pValue->Assign(
2750 m_pDocument->GetScriptContext()->GetJSValueFromMap(pInstanceMgr));
Dan Sinclair1770c022016-03-14 14:14:16 -04002751}
dsinclair5b36f0a2016-07-19 10:56:23 -07002752
dsinclair12a6b0c2016-05-26 11:14:08 -07002753void CXFA_Node::Script_Subform_Locale(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002754 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002755 XFA_ATTRIBUTE eAttribute) {
2756 if (bSetting) {
tsepezd19e9122016-11-02 15:43:18 -07002757 SetCData(XFA_ATTRIBUTE_Locale, pValue->ToWideString(), true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002758 } else {
2759 CFX_WideString wsLocaleName;
2760 GetLocaleName(wsLocaleName);
Tom Sepezf0b65542017-02-13 10:26:01 -08002761 pValue->SetString(wsLocaleName.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002762 }
2763}
dsinclair5b36f0a2016-07-19 10:56:23 -07002764
Dan Sinclair1770c022016-03-14 14:14:16 -04002765void CXFA_Node::Script_Subform_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002766 if (pArguments->GetLength() != 1) {
2767 ThrowParamCountMismatchException(L"execEvent");
2768 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002769 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002770
2771 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2772 execSingleEventByName(
2773 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2774 XFA_Element::Subform);
Dan Sinclair1770c022016-03-14 14:14:16 -04002775}
dsinclair5b36f0a2016-07-19 10:56:23 -07002776
Dan Sinclair1770c022016-03-14 14:14:16 -04002777void CXFA_Node::Script_Subform_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002778 if (pArguments->GetLength() != 0) {
2779 ThrowParamCountMismatchException(L"execInitialize");
2780 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002781 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002782
2783 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2784 if (!pNotify)
2785 return;
2786
2787 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04002788}
dsinclair5b36f0a2016-07-19 10:56:23 -07002789
Dan Sinclair1770c022016-03-14 14:14:16 -04002790void CXFA_Node::Script_Subform_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002791 if (pArguments->GetLength() != 0) {
2792 ThrowParamCountMismatchException(L"execCalculate");
2793 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002794 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002795
2796 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2797 if (!pNotify)
2798 return;
2799
2800 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04002801}
dsinclair5b36f0a2016-07-19 10:56:23 -07002802
Dan Sinclair1770c022016-03-14 14:14:16 -04002803void CXFA_Node::Script_Subform_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002804 if (pArguments->GetLength() != 0) {
2805 ThrowParamCountMismatchException(L"execValidate");
2806 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002807 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002808
2809 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2810 if (!pNotify) {
2811 pArguments->GetReturnValue()->SetBoolean(false);
2812 return;
2813 }
2814
2815 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
2816 pArguments->GetReturnValue()->SetBoolean(
2817 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002818}
dsinclair5b36f0a2016-07-19 10:56:23 -07002819
Dan Sinclair1770c022016-03-14 14:14:16 -04002820void CXFA_Node::Script_Subform_GetInvalidObjects(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002821 if (pArguments->GetLength() != 0)
2822 ThrowParamCountMismatchException(L"getInvalidObjects");
Dan Sinclair1770c022016-03-14 14:14:16 -04002823}
dsinclair5b36f0a2016-07-19 10:56:23 -07002824
Dan Sinclair1770c022016-03-14 14:14:16 -04002825int32_t CXFA_Node::Subform_and_SubformSet_InstanceIndex() {
2826 int32_t index = 0;
2827 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2828 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002829 if ((pNode->GetElementType() == XFA_Element::Subform) ||
2830 (pNode->GetElementType() == XFA_Element::SubformSet)) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002831 index++;
2832 } else {
2833 break;
2834 }
2835 }
2836 return index;
2837}
dsinclair5b36f0a2016-07-19 10:56:23 -07002838
Dan Sinclair1770c022016-03-14 14:14:16 -04002839void CXFA_Node::Script_Template_FormNodes(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002840 if (pArguments->GetLength() != 1) {
2841 ThrowParamCountMismatchException(L"formNodes");
2842 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002843 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002844 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002845}
dsinclair5b36f0a2016-07-19 10:56:23 -07002846
Dan Sinclair1770c022016-03-14 14:14:16 -04002847void CXFA_Node::Script_Template_Remerge(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002848 if (pArguments->GetLength() != 0) {
2849 ThrowParamCountMismatchException(L"remerge");
2850 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002851 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002852 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002853}
dsinclair5b36f0a2016-07-19 10:56:23 -07002854
Dan Sinclair1770c022016-03-14 14:14:16 -04002855void CXFA_Node::Script_Template_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002856 if (pArguments->GetLength() != 0) {
2857 ThrowParamCountMismatchException(L"execInitialize");
2858 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002859 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002860
2861 CXFA_WidgetData* pWidgetData = GetWidgetData();
2862 if (!pWidgetData) {
2863 pArguments->GetReturnValue()->SetBoolean(false);
2864 return;
2865 }
2866 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002867}
dsinclair5b36f0a2016-07-19 10:56:23 -07002868
Dan Sinclair1770c022016-03-14 14:14:16 -04002869void CXFA_Node::Script_Template_CreateNode(CFXJSE_Arguments* pArguments) {
2870 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002871 if (argc <= 0 || argc >= 4) {
2872 ThrowParamCountMismatchException(L"createNode");
2873 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002874 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002875
2876 CFX_WideString strName;
2877 CFX_WideString strNameSpace;
2878 CFX_ByteString bsTagName = pArguments->GetUTF8String(0);
2879 CFX_WideString strTagName = CFX_WideString::FromUTF8(bsTagName.AsStringC());
2880 if (argc > 1) {
2881 CFX_ByteString bsName = pArguments->GetUTF8String(1);
2882 strName = CFX_WideString::FromUTF8(bsName.AsStringC());
2883 if (argc == 3) {
2884 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(2);
2885 strNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
2886 }
2887 }
2888
2889 XFA_Element eType = XFA_GetElementTypeForName(strTagName.AsStringC());
2890 CXFA_Node* pNewNode = CreateSamePacketNode(eType);
2891 if (!pNewNode) {
2892 pArguments->GetReturnValue()->SetNull();
2893 return;
2894 }
2895
2896 if (strName.IsEmpty()) {
2897 pArguments->GetReturnValue()->Assign(
2898 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
2899 return;
2900 }
2901
2902 if (!GetAttributeOfElement(eType, XFA_ATTRIBUTE_Name,
2903 XFA_XDPPACKET_UNKNOWN)) {
2904 ThrowMissingPropertyException(strTagName, L"name");
2905 return;
2906 }
2907
2908 pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, strName.AsStringC(), true);
2909 if (pNewNode->GetPacketID() == XFA_XDPPACKET_Datasets)
2910 pNewNode->CreateXMLMappingNode();
2911
2912 pArguments->GetReturnValue()->Assign(
2913 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002914}
dsinclair5b36f0a2016-07-19 10:56:23 -07002915
Dan Sinclair1770c022016-03-14 14:14:16 -04002916void CXFA_Node::Script_Template_Recalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002917 if (pArguments->GetLength() != 1) {
2918 ThrowParamCountMismatchException(L"recalculate");
2919 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002920 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002921 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002922}
dsinclair5b36f0a2016-07-19 10:56:23 -07002923
Dan Sinclair1770c022016-03-14 14:14:16 -04002924void CXFA_Node::Script_Template_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002925 if (pArguments->GetLength() != 0) {
2926 ThrowParamCountMismatchException(L"execCalculate");
2927 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002928 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002929
2930 CXFA_WidgetData* pWidgetData = GetWidgetData();
2931 if (!pWidgetData) {
2932 pArguments->GetReturnValue()->SetBoolean(false);
2933 return;
2934 }
2935 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002936}
dsinclair5b36f0a2016-07-19 10:56:23 -07002937
Dan Sinclair1770c022016-03-14 14:14:16 -04002938void CXFA_Node::Script_Template_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002939 if (pArguments->GetLength() != 0) {
2940 ThrowParamCountMismatchException(L"execValidate");
2941 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002942 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002943 CXFA_WidgetData* pWidgetData = GetWidgetData();
2944 if (!pWidgetData) {
2945 pArguments->GetReturnValue()->SetBoolean(false);
2946 return;
2947 }
2948 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002949}
dsinclair5b36f0a2016-07-19 10:56:23 -07002950
Dan Sinclair1770c022016-03-14 14:14:16 -04002951void CXFA_Node::Script_Manifest_Evaluate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002952 if (pArguments->GetLength() != 0) {
2953 ThrowParamCountMismatchException(L"evaluate");
2954 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002955 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002956
2957 CXFA_WidgetData* pWidgetData = GetWidgetData();
2958 if (!pWidgetData) {
2959 pArguments->GetReturnValue()->SetBoolean(false);
2960 return;
2961 }
2962 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002963}
dsinclair5b36f0a2016-07-19 10:56:23 -07002964
dsinclair12a6b0c2016-05-26 11:14:08 -07002965void CXFA_Node::Script_InstanceManager_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002966 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002967 XFA_ATTRIBUTE eAttribute) {
2968 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002969 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002970 return;
2971 }
2972 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07002973 pValue->SetInteger(nodeOccur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04002974}
dsinclair5b36f0a2016-07-19 10:56:23 -07002975
dsinclair12a6b0c2016-05-26 11:14:08 -07002976void CXFA_Node::Script_InstanceManager_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002977 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002978 XFA_ATTRIBUTE eAttribute) {
2979 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002980 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002981 return;
2982 }
2983 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07002984 pValue->SetInteger(nodeOccur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04002985}
tsepezaadedf92016-05-12 10:08:06 -07002986
dsinclair12a6b0c2016-05-26 11:14:08 -07002987void CXFA_Node::Script_InstanceManager_Count(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002988 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002989 XFA_ATTRIBUTE eAttribute) {
2990 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002991 int32_t iDesired = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002992 InstanceManager_SetInstances(iDesired);
2993 } else {
dsinclair5b36f0a2016-07-19 10:56:23 -07002994 pValue->SetInteger(GetCount(this));
Dan Sinclair1770c022016-03-14 14:14:16 -04002995 }
2996}
dsinclair5b36f0a2016-07-19 10:56:23 -07002997
Dan Sinclair1770c022016-03-14 14:14:16 -04002998void CXFA_Node::Script_InstanceManager_MoveInstance(
2999 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003000 if (pArguments->GetLength() != 2) {
dsinclairf27aeec2016-06-07 19:36:18 -07003001 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003002 return;
3003 }
3004 int32_t iFrom = pArguments->GetInt32(0);
3005 int32_t iTo = pArguments->GetInt32(1);
3006 InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07003007 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003008 if (!pNotify) {
3009 return;
3010 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003011 CXFA_Node* pToInstance = GetItem(this, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07003012 if (pToInstance && pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003013 pNotify->RunSubformIndexChange(pToInstance);
3014 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003015 CXFA_Node* pFromInstance = GetItem(this, iFrom);
dsinclair070fcdf2016-06-22 22:04:54 -07003016 if (pFromInstance &&
3017 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003018 pNotify->RunSubformIndexChange(pFromInstance);
3019 }
3020}
dsinclair5b36f0a2016-07-19 10:56:23 -07003021
Dan Sinclair1770c022016-03-14 14:14:16 -04003022void CXFA_Node::Script_InstanceManager_RemoveInstance(
3023 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003024 if (pArguments->GetLength() != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003025 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003026 return;
3027 }
3028 int32_t iIndex = pArguments->GetInt32(0);
dsinclair5b36f0a2016-07-19 10:56:23 -07003029 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003030 if (iIndex < 0 || iIndex >= iCount) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003031 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003032 return;
3033 }
3034 CXFA_Occur nodeOccur(GetOccurNode());
3035 int32_t iMin = nodeOccur.GetMin();
3036 if (iCount - 1 < iMin) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003037 ThrowTooManyOccurancesException(L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003038 return;
3039 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003040 CXFA_Node* pRemoveInstance = GetItem(this, iIndex);
3041 RemoveItem(this, pRemoveInstance);
dsinclaira1b07722016-07-11 08:20:58 -07003042 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003043 if (pNotify) {
3044 for (int32_t i = iIndex; i < iCount - 1; i++) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003045 CXFA_Node* pSubformInstance = GetItem(this, i);
Dan Sinclair1770c022016-03-14 14:14:16 -04003046 if (pSubformInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07003047 pSubformInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003048 pNotify->RunSubformIndexChange(pSubformInstance);
3049 }
3050 }
3051 }
3052 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3053 if (!pLayoutPro) {
3054 return;
3055 }
3056 pLayoutPro->AddChangedContainer(
3057 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3058}
dsinclair5b36f0a2016-07-19 10:56:23 -07003059
Dan Sinclair1770c022016-03-14 14:14:16 -04003060void CXFA_Node::Script_InstanceManager_SetInstances(
3061 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003062 if (pArguments->GetLength() != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003063 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003064 return;
3065 }
3066 int32_t iDesired = pArguments->GetInt32(0);
3067 InstanceManager_SetInstances(iDesired);
3068}
dsinclair5b36f0a2016-07-19 10:56:23 -07003069
Dan Sinclair1770c022016-03-14 14:14:16 -04003070void CXFA_Node::Script_InstanceManager_AddInstance(
3071 CFXJSE_Arguments* pArguments) {
3072 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003073 if (argc != 0 && argc != 1) {
3074 ThrowParamCountMismatchException(L"addInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003075 return;
3076 }
tsepezd19e9122016-11-02 15:43:18 -07003077 bool fFlags = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003078 if (argc == 1) {
tsepezd19e9122016-11-02 15:43:18 -07003079 fFlags = pArguments->GetInt32(0) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003080 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003081 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003082 CXFA_Occur nodeOccur(GetOccurNode());
3083 int32_t iMax = nodeOccur.GetMax();
3084 if (iMax >= 0 && iCount >= iMax) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003085 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003086 return;
3087 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003088 CXFA_Node* pNewInstance = CreateInstance(this, fFlags);
tsepezd19e9122016-11-02 15:43:18 -07003089 InsertItem(this, pNewInstance, iCount, iCount, false);
dsinclairf27aeec2016-06-07 19:36:18 -07003090 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003091 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003092 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003093 if (!pNotify) {
3094 return;
3095 }
3096 pNotify->RunNodeInitialize(pNewInstance);
3097 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3098 if (!pLayoutPro) {
3099 return;
3100 }
3101 pLayoutPro->AddChangedContainer(
3102 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3103}
dsinclair5b36f0a2016-07-19 10:56:23 -07003104
Dan Sinclair1770c022016-03-14 14:14:16 -04003105void CXFA_Node::Script_InstanceManager_InsertInstance(
3106 CFXJSE_Arguments* pArguments) {
3107 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003108 if (argc != 1 && argc != 2) {
3109 ThrowParamCountMismatchException(L"insertInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003110 return;
3111 }
3112 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07003113 bool bBind = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003114 if (argc == 2) {
tsepezd19e9122016-11-02 15:43:18 -07003115 bBind = pArguments->GetInt32(1) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003116 }
3117 CXFA_Occur nodeOccur(GetOccurNode());
dsinclair5b36f0a2016-07-19 10:56:23 -07003118 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003119 if (iIndex < 0 || iIndex > iCount) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003120 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003121 return;
3122 }
3123 int32_t iMax = nodeOccur.GetMax();
3124 if (iMax >= 0 && iCount >= iMax) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003125 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003126 return;
3127 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003128 CXFA_Node* pNewInstance = CreateInstance(this, bBind);
tsepezd19e9122016-11-02 15:43:18 -07003129 InsertItem(this, pNewInstance, iIndex, iCount, true);
dsinclairf27aeec2016-06-07 19:36:18 -07003130 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003131 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003132 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003133 if (!pNotify) {
3134 return;
3135 }
3136 pNotify->RunNodeInitialize(pNewInstance);
3137 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3138 if (!pLayoutPro) {
3139 return;
3140 }
3141 pLayoutPro->AddChangedContainer(
3142 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3143}
dsinclair5b36f0a2016-07-19 10:56:23 -07003144
Dan Sinclair1770c022016-03-14 14:14:16 -04003145int32_t CXFA_Node::InstanceManager_SetInstances(int32_t iDesired) {
3146 CXFA_Occur nodeOccur(GetOccurNode());
3147 int32_t iMax = nodeOccur.GetMax();
3148 int32_t iMin = nodeOccur.GetMin();
3149 if (iDesired < iMin) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003150 ThrowTooManyOccurancesException(L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003151 return 1;
3152 }
3153 if ((iMax >= 0) && (iDesired > iMax)) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003154 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003155 return 2;
3156 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003157 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003158 if (iDesired == iCount) {
3159 return 0;
3160 }
3161 if (iDesired < iCount) {
3162 CFX_WideStringC wsInstManagerName = GetCData(XFA_ATTRIBUTE_Name);
tsepezafe94302016-05-13 17:21:31 -07003163 CFX_WideString wsInstanceName =
3164 CFX_WideString(wsInstManagerName.IsEmpty() ? wsInstManagerName
3165 : wsInstManagerName.Mid(1));
tsepez736f28a2016-03-25 14:19:51 -07003166 uint32_t dInstanceNameHash =
tsepezb6853cf2016-04-25 11:23:43 -07003167 FX_HashCode_GetW(wsInstanceName.AsStringC(), false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003168 CXFA_Node* pPrevSibling =
dsinclair5b36f0a2016-07-19 10:56:23 -07003169 (iDesired == 0) ? this : GetItem(this, iDesired - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04003170 while (iCount > iDesired) {
3171 CXFA_Node* pRemoveInstance =
3172 pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling);
dsinclair070fcdf2016-06-22 22:04:54 -07003173 if (pRemoveInstance->GetElementType() != XFA_Element::Subform &&
3174 pRemoveInstance->GetElementType() != XFA_Element::SubformSet) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003175 continue;
3176 }
dsinclair070fcdf2016-06-22 22:04:54 -07003177 if (pRemoveInstance->GetElementType() == XFA_Element::InstanceManager) {
Lei Zhangb45324b2017-05-22 17:05:40 -07003178 NOTREACHED();
Dan Sinclair1770c022016-03-14 14:14:16 -04003179 break;
3180 }
3181 if (pRemoveInstance->GetNameHash() == dInstanceNameHash) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003182 RemoveItem(this, pRemoveInstance);
Dan Sinclair1770c022016-03-14 14:14:16 -04003183 iCount--;
3184 }
3185 }
3186 } else if (iDesired > iCount) {
3187 while (iCount < iDesired) {
tsepezd19e9122016-11-02 15:43:18 -07003188 CXFA_Node* pNewInstance = CreateInstance(this, true);
3189 InsertItem(this, pNewInstance, iCount, iCount, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003190 iCount++;
dsinclaira1b07722016-07-11 08:20:58 -07003191 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003192 if (!pNotify) {
3193 return 0;
3194 }
3195 pNotify->RunNodeInitialize(pNewInstance);
3196 }
3197 }
3198 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3199 if (pLayoutPro) {
3200 pLayoutPro->AddChangedContainer(
3201 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3202 }
3203 return 0;
3204}
dsinclair5b36f0a2016-07-19 10:56:23 -07003205
Dan Sinclair1770c022016-03-14 14:14:16 -04003206int32_t CXFA_Node::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003207 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003208 if (iFrom > iCount || iTo > iCount - 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003209 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003210 return 1;
3211 }
3212 if (iFrom < 0 || iTo < 0 || iFrom == iTo) {
3213 return 0;
3214 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003215 CXFA_Node* pMoveInstance = GetItem(this, iFrom);
tsepezd19e9122016-11-02 15:43:18 -07003216 RemoveItem(this, pMoveInstance, false);
3217 InsertItem(this, pMoveInstance, iTo, iCount - 1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003218 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3219 if (pLayoutPro) {
3220 pLayoutPro->AddChangedContainer(
3221 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3222 }
3223 return 0;
3224}
dsinclair5b36f0a2016-07-19 10:56:23 -07003225
dsinclair12a6b0c2016-05-26 11:14:08 -07003226void CXFA_Node::Script_Occur_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003227 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003228 XFA_ATTRIBUTE eAttribute) {
3229 CXFA_Occur occur(this);
3230 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003231 int32_t iMax = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003232 occur.SetMax(iMax);
3233 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003234 pValue->SetInteger(occur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04003235 }
3236}
dsinclair5b36f0a2016-07-19 10:56:23 -07003237
dsinclair12a6b0c2016-05-26 11:14:08 -07003238void CXFA_Node::Script_Occur_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003239 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003240 XFA_ATTRIBUTE eAttribute) {
3241 CXFA_Occur occur(this);
3242 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003243 int32_t iMin = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003244 occur.SetMin(iMin);
3245 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003246 pValue->SetInteger(occur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04003247 }
3248}
dsinclair5b36f0a2016-07-19 10:56:23 -07003249
Dan Sinclair1770c022016-03-14 14:14:16 -04003250void CXFA_Node::Script_Desc_Metadata(CFXJSE_Arguments* pArguments) {
3251 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003252 if (argc != 0 && argc != 1) {
3253 ThrowParamCountMismatchException(L"metadata");
3254 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003255 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003256 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04003257}
dsinclair5b36f0a2016-07-19 10:56:23 -07003258
Dan Sinclair1770c022016-03-14 14:14:16 -04003259void CXFA_Node::Script_Form_FormNodes(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003260 if (pArguments->GetLength() != 1) {
3261 ThrowParamCountMismatchException(L"formNodes");
3262 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003263 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003264
3265 CXFA_Node* pDataNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
3266 if (!pDataNode) {
3267 ThrowArgumentMismatchException();
3268 return;
3269 }
3270
Tom Sepezf8a94392017-03-14 12:13:22 -07003271 std::vector<CXFA_Node*> formItems;
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003272 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
3273 pFormNodes->SetArrayNodeList(formItems);
3274 pArguments->GetReturnValue()->SetObject(
3275 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04003276}
dsinclair5b36f0a2016-07-19 10:56:23 -07003277
Dan Sinclair1770c022016-03-14 14:14:16 -04003278void CXFA_Node::Script_Form_Remerge(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003279 if (pArguments->GetLength() != 0) {
3280 ThrowParamCountMismatchException(L"remerge");
3281 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003282 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003283
3284 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003285}
dsinclair5b36f0a2016-07-19 10:56:23 -07003286
Dan Sinclair1770c022016-03-14 14:14:16 -04003287void CXFA_Node::Script_Form_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003288 if (pArguments->GetLength() != 0) {
3289 ThrowParamCountMismatchException(L"execInitialize");
3290 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003291 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003292
3293 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3294 if (!pNotify)
3295 return;
3296
3297 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04003298}
dsinclair5b36f0a2016-07-19 10:56:23 -07003299
Dan Sinclair1770c022016-03-14 14:14:16 -04003300void CXFA_Node::Script_Form_Recalculate(CFXJSE_Arguments* pArguments) {
3301 CXFA_EventParam* pEventParam =
3302 m_pDocument->GetScriptContext()->GetEventParam();
3303 if (pEventParam->m_eType == XFA_EVENT_Calculate ||
3304 pEventParam->m_eType == XFA_EVENT_InitCalculate) {
3305 return;
3306 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003307 if (pArguments->GetLength() != 1) {
3308 ThrowParamCountMismatchException(L"recalculate");
3309 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003310 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003311
3312 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3313 if (!pNotify)
3314 return;
3315 if (pArguments->GetInt32(0) != 0)
3316 return;
3317
3318 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
3319 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
3320 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Ready, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003321}
dsinclair5b36f0a2016-07-19 10:56:23 -07003322
Dan Sinclair1770c022016-03-14 14:14:16 -04003323void CXFA_Node::Script_Form_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003324 if (pArguments->GetLength() != 0) {
3325 ThrowParamCountMismatchException(L"execCalculate");
3326 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003327 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003328
3329 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3330 if (!pNotify)
3331 return;
3332
3333 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04003334}
dsinclair5b36f0a2016-07-19 10:56:23 -07003335
Dan Sinclair1770c022016-03-14 14:14:16 -04003336void CXFA_Node::Script_Form_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003337 if (pArguments->GetLength() != 0) {
3338 ThrowParamCountMismatchException(L"execValidate");
3339 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003340 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003341
3342 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3343 if (!pNotify) {
3344 pArguments->GetReturnValue()->SetBoolean(false);
3345 return;
3346 }
3347
3348 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
3349 pArguments->GetReturnValue()->SetBoolean(
3350 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003351}
dsinclair5b36f0a2016-07-19 10:56:23 -07003352
dsinclair12a6b0c2016-05-26 11:14:08 -07003353void CXFA_Node::Script_Form_Checksum(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003354 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003355 XFA_ATTRIBUTE eAttribute) {
3356 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07003357 SetAttribute(XFA_ATTRIBUTE_Checksum, pValue->ToWideString().AsStringC());
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003358 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003359 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003360 CFX_WideString wsChecksum;
3361 GetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum, false);
Tom Sepezf0b65542017-02-13 10:26:01 -08003362 pValue->SetString(wsChecksum.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003363}
dsinclair5b36f0a2016-07-19 10:56:23 -07003364
Dan Sinclair1770c022016-03-14 14:14:16 -04003365void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003366 if (pArguments->GetLength() != 1) {
3367 ThrowParamCountMismatchException(L"getAttribute");
3368 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003369 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003370 CFX_ByteString bsAttributeName = pArguments->GetUTF8String(0);
3371 CFX_WideString wsAttributeValue;
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003372 CFX_XMLNode* pXMLNode = GetXMLMappingNode();
3373 if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) {
3374 wsAttributeValue = static_cast<CFX_XMLElement*>(pXMLNode)->GetString(
Dan Sinclair5fa4e982017-04-05 11:48:21 -04003375 CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str());
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003376 }
3377 pArguments->GetReturnValue()->SetString(
Tom Sepezf0b65542017-02-13 10:26:01 -08003378 wsAttributeValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003379}
dsinclair5b36f0a2016-07-19 10:56:23 -07003380
Dan Sinclair1770c022016-03-14 14:14:16 -04003381void CXFA_Node::Script_Packet_SetAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003382 if (pArguments->GetLength() != 2) {
3383 ThrowParamCountMismatchException(L"setAttribute");
3384 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003385 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003386 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
3387 CFX_ByteString bsName = pArguments->GetUTF8String(1);
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003388 CFX_XMLNode* pXMLNode = GetXMLMappingNode();
3389 if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) {
3390 static_cast<CFX_XMLElement*>(pXMLNode)->SetString(
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003391 CFX_WideString::FromUTF8(bsName.AsStringC()),
3392 CFX_WideString::FromUTF8(bsValue.AsStringC()));
3393 }
3394 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003395}
dsinclair5b36f0a2016-07-19 10:56:23 -07003396
Dan Sinclair1770c022016-03-14 14:14:16 -04003397void CXFA_Node::Script_Packet_RemoveAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003398 if (pArguments->GetLength() != 1) {
3399 ThrowParamCountMismatchException(L"removeAttribute");
3400 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003401 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003402
3403 CFX_ByteString bsName = pArguments->GetUTF8String(0);
3404 CFX_WideString wsName = CFX_WideString::FromUTF8(bsName.AsStringC());
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003405 CFX_XMLNode* pXMLNode = GetXMLMappingNode();
3406 if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) {
3407 CFX_XMLElement* pXMLElement = static_cast<CFX_XMLElement*>(pXMLNode);
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003408 if (pXMLElement->HasAttribute(wsName.c_str())) {
3409 pXMLElement->RemoveAttribute(wsName.c_str());
3410 }
3411 }
3412 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003413}
dsinclair5b36f0a2016-07-19 10:56:23 -07003414
dsinclair12a6b0c2016-05-26 11:14:08 -07003415void CXFA_Node::Script_Packet_Content(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003416 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003417 XFA_ATTRIBUTE eAttribute) {
3418 if (bSetting) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003419 CFX_XMLNode* pXMLNode = GetXMLMappingNode();
3420 if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) {
3421 CFX_XMLElement* pXMLElement = static_cast<CFX_XMLElement*>(pXMLNode);
dsinclair2f5582f2016-06-09 11:48:23 -07003422 pXMLElement->SetTextData(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04003423 }
3424 } else {
3425 CFX_WideString wsTextData;
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003426 CFX_XMLNode* pXMLNode = GetXMLMappingNode();
3427 if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) {
3428 CFX_XMLElement* pXMLElement = static_cast<CFX_XMLElement*>(pXMLNode);
Dan Sinclair5fa4e982017-04-05 11:48:21 -04003429 wsTextData = pXMLElement->GetTextData();
Dan Sinclair1770c022016-03-14 14:14:16 -04003430 }
Tom Sepezf0b65542017-02-13 10:26:01 -08003431 pValue->SetString(wsTextData.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003432 }
3433}
dsinclair5b36f0a2016-07-19 10:56:23 -07003434
Dan Sinclair1770c022016-03-14 14:14:16 -04003435void CXFA_Node::Script_Source_Next(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003436 if (pArguments->GetLength() != 0)
3437 ThrowParamCountMismatchException(L"next");
Dan Sinclair1770c022016-03-14 14:14:16 -04003438}
dsinclair5b36f0a2016-07-19 10:56:23 -07003439
Dan Sinclair1770c022016-03-14 14:14:16 -04003440void CXFA_Node::Script_Source_CancelBatch(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003441 if (pArguments->GetLength() != 0)
3442 ThrowParamCountMismatchException(L"cancelBatch");
Dan Sinclair1770c022016-03-14 14:14:16 -04003443}
dsinclair5b36f0a2016-07-19 10:56:23 -07003444
Dan Sinclair1770c022016-03-14 14:14:16 -04003445void CXFA_Node::Script_Source_First(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003446 if (pArguments->GetLength() != 0)
3447 ThrowParamCountMismatchException(L"first");
Dan Sinclair1770c022016-03-14 14:14:16 -04003448}
dsinclair5b36f0a2016-07-19 10:56:23 -07003449
Dan Sinclair1770c022016-03-14 14:14:16 -04003450void CXFA_Node::Script_Source_UpdateBatch(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003451 if (pArguments->GetLength() != 0)
3452 ThrowParamCountMismatchException(L"updateBatch");
Dan Sinclair1770c022016-03-14 14:14:16 -04003453}
dsinclair5b36f0a2016-07-19 10:56:23 -07003454
Dan Sinclair1770c022016-03-14 14:14:16 -04003455void CXFA_Node::Script_Source_Previous(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003456 if (pArguments->GetLength() != 0)
3457 ThrowParamCountMismatchException(L"previous");
Dan Sinclair1770c022016-03-14 14:14:16 -04003458}
dsinclair5b36f0a2016-07-19 10:56:23 -07003459
Dan Sinclair1770c022016-03-14 14:14:16 -04003460void CXFA_Node::Script_Source_IsBOF(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003461 if (pArguments->GetLength() != 0)
3462 ThrowParamCountMismatchException(L"isBOF");
Dan Sinclair1770c022016-03-14 14:14:16 -04003463}
dsinclair5b36f0a2016-07-19 10:56:23 -07003464
Dan Sinclair1770c022016-03-14 14:14:16 -04003465void CXFA_Node::Script_Source_IsEOF(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003466 if (pArguments->GetLength() != 0)
3467 ThrowParamCountMismatchException(L"isEOF");
Dan Sinclair1770c022016-03-14 14:14:16 -04003468}
dsinclair5b36f0a2016-07-19 10:56:23 -07003469
Dan Sinclair1770c022016-03-14 14:14:16 -04003470void CXFA_Node::Script_Source_Cancel(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003471 if (pArguments->GetLength() != 0)
3472 ThrowParamCountMismatchException(L"cancel");
Dan Sinclair1770c022016-03-14 14:14:16 -04003473}
dsinclair5b36f0a2016-07-19 10:56:23 -07003474
Dan Sinclair1770c022016-03-14 14:14:16 -04003475void CXFA_Node::Script_Source_Update(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003476 if (pArguments->GetLength() != 0)
3477 ThrowParamCountMismatchException(L"update");
Dan Sinclair1770c022016-03-14 14:14:16 -04003478}
dsinclair5b36f0a2016-07-19 10:56:23 -07003479
Dan Sinclair1770c022016-03-14 14:14:16 -04003480void CXFA_Node::Script_Source_Open(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003481 if (pArguments->GetLength() != 0)
3482 ThrowParamCountMismatchException(L"open");
Dan Sinclair1770c022016-03-14 14:14:16 -04003483}
dsinclair5b36f0a2016-07-19 10:56:23 -07003484
Dan Sinclair1770c022016-03-14 14:14:16 -04003485void CXFA_Node::Script_Source_Delete(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003486 if (pArguments->GetLength() != 0)
3487 ThrowParamCountMismatchException(L"delete");
Dan Sinclair1770c022016-03-14 14:14:16 -04003488}
dsinclair5b36f0a2016-07-19 10:56:23 -07003489
Dan Sinclair1770c022016-03-14 14:14:16 -04003490void CXFA_Node::Script_Source_AddNew(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003491 if (pArguments->GetLength() != 0)
3492 ThrowParamCountMismatchException(L"addNew");
Dan Sinclair1770c022016-03-14 14:14:16 -04003493}
dsinclair5b36f0a2016-07-19 10:56:23 -07003494
Dan Sinclair1770c022016-03-14 14:14:16 -04003495void CXFA_Node::Script_Source_Requery(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003496 if (pArguments->GetLength() != 0)
3497 ThrowParamCountMismatchException(L"requery");
Dan Sinclair1770c022016-03-14 14:14:16 -04003498}
dsinclair5b36f0a2016-07-19 10:56:23 -07003499
Dan Sinclair1770c022016-03-14 14:14:16 -04003500void CXFA_Node::Script_Source_Resync(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003501 if (pArguments->GetLength() != 0)
3502 ThrowParamCountMismatchException(L"resync");
Dan Sinclair1770c022016-03-14 14:14:16 -04003503}
dsinclair5b36f0a2016-07-19 10:56:23 -07003504
Dan Sinclair1770c022016-03-14 14:14:16 -04003505void CXFA_Node::Script_Source_Close(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003506 if (pArguments->GetLength() != 0)
3507 ThrowParamCountMismatchException(L"close");
Dan Sinclair1770c022016-03-14 14:14:16 -04003508}
dsinclair5b36f0a2016-07-19 10:56:23 -07003509
Dan Sinclair1770c022016-03-14 14:14:16 -04003510void CXFA_Node::Script_Source_Last(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003511 if (pArguments->GetLength() != 0)
3512 ThrowParamCountMismatchException(L"last");
Dan Sinclair1770c022016-03-14 14:14:16 -04003513}
dsinclair5b36f0a2016-07-19 10:56:23 -07003514
Dan Sinclair1770c022016-03-14 14:14:16 -04003515void CXFA_Node::Script_Source_HasDataChanged(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003516 if (pArguments->GetLength() != 0)
3517 ThrowParamCountMismatchException(L"hasDataChanged");
Dan Sinclair1770c022016-03-14 14:14:16 -04003518}
dsinclair5b36f0a2016-07-19 10:56:23 -07003519
dsinclair12a6b0c2016-05-26 11:14:08 -07003520void CXFA_Node::Script_Source_Db(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003521 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003522 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003523
dsinclair12a6b0c2016-05-26 11:14:08 -07003524void CXFA_Node::Script_Xfa_This(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003525 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003526 XFA_ATTRIBUTE eAttribute) {
3527 if (!bSetting) {
3528 CXFA_Object* pThis = m_pDocument->GetScriptContext()->GetThisObject();
dsinclair43854a52016-04-27 12:26:00 -07003529 ASSERT(pThis);
dsinclairf27aeec2016-06-07 19:36:18 -07003530 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pThis));
Dan Sinclair1770c022016-03-14 14:14:16 -04003531 }
3532}
dsinclair5b36f0a2016-07-19 10:56:23 -07003533
dsinclair12a6b0c2016-05-26 11:14:08 -07003534void CXFA_Node::Script_Handler_Version(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003535 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003536 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003537
dsinclair12a6b0c2016-05-26 11:14:08 -07003538void CXFA_Node::Script_SubmitFormat_Mode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003539 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003540 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003541
dsinclair12a6b0c2016-05-26 11:14:08 -07003542void CXFA_Node::Script_Extras_Type(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003543 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003544 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003545
dsinclair12a6b0c2016-05-26 11:14:08 -07003546void CXFA_Node::Script_Script_Stateless(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003547 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003548 XFA_ATTRIBUTE eAttribute) {
3549 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003550 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003551 return;
3552 }
dan sinclair65c7c232017-02-02 14:05:30 -08003553 pValue->SetString(FX_UTF8Encode(CFX_WideStringC(L"0", 1)).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003554}
dsinclair5b36f0a2016-07-19 10:56:23 -07003555
dsinclair12a6b0c2016-05-26 11:14:08 -07003556void CXFA_Node::Script_Encrypt_Format(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003557 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003558 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003559
tsepezd19e9122016-11-02 15:43:18 -07003560bool CXFA_Node::HasAttribute(XFA_ATTRIBUTE eAttr, bool bCanInherit) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003561 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003562 return HasMapModuleKey(pKey, bCanInherit);
3563}
dsinclair5b36f0a2016-07-19 10:56:23 -07003564
tsepezd19e9122016-11-02 15:43:18 -07003565bool CXFA_Node::SetAttribute(XFA_ATTRIBUTE eAttr,
3566 const CFX_WideStringC& wsValue,
3567 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003568 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003569 if (!pAttr)
tsepezd19e9122016-11-02 15:43:18 -07003570 return false;
weili44f8faf2016-06-01 14:03:56 -07003571
Dan Sinclair1770c022016-03-14 14:14:16 -04003572 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3573 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3574 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003575 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003576 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3577 }
3578 switch (eType) {
3579 case XFA_ATTRIBUTETYPE_Enum: {
3580 const XFA_ATTRIBUTEENUMINFO* pEnum = XFA_GetAttributeEnumByName(wsValue);
3581 return SetEnum(pAttr->eName,
3582 pEnum ? pEnum->eName
3583 : (XFA_ATTRIBUTEENUM)(intptr_t)(pAttr->pDefValue),
3584 bNotify);
3585 } break;
3586 case XFA_ATTRIBUTETYPE_Cdata:
tsepezafe94302016-05-13 17:21:31 -07003587 return SetCData(pAttr->eName, CFX_WideString(wsValue), bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003588 case XFA_ATTRIBUTETYPE_Boolean:
dan sinclair65c7c232017-02-02 14:05:30 -08003589 return SetBoolean(pAttr->eName, wsValue != L"0", bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003590 case XFA_ATTRIBUTETYPE_Integer:
dsinclaire0347a62016-08-11 11:24:11 -07003591 return SetInteger(pAttr->eName,
3592 FXSYS_round(FXSYS_wcstof(wsValue.c_str(),
3593 wsValue.GetLength(), nullptr)),
3594 bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003595 case XFA_ATTRIBUTETYPE_Measure:
3596 return SetMeasure(pAttr->eName, CXFA_Measurement(wsValue), bNotify);
3597 default:
3598 break;
3599 }
tsepezd19e9122016-11-02 15:43:18 -07003600 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003601}
dsinclair5b36f0a2016-07-19 10:56:23 -07003602
tsepezd19e9122016-11-02 15:43:18 -07003603bool CXFA_Node::GetAttribute(XFA_ATTRIBUTE eAttr,
3604 CFX_WideString& wsValue,
3605 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003606 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003607 if (!pAttr) {
tsepezd19e9122016-11-02 15:43:18 -07003608 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003609 }
3610 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3611 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3612 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003613 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003614 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3615 }
3616 switch (eType) {
3617 case XFA_ATTRIBUTETYPE_Enum: {
3618 XFA_ATTRIBUTEENUM eValue;
3619 if (!TryEnum(pAttr->eName, eValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003620 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003621 }
dsinclair9eb0db12016-07-21 12:01:39 -07003622 wsValue = GetAttributeEnumByID(eValue)->pName;
tsepezd19e9122016-11-02 15:43:18 -07003623 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003624 } break;
3625 case XFA_ATTRIBUTETYPE_Cdata: {
3626 CFX_WideStringC wsValueC;
3627 if (!TryCData(pAttr->eName, wsValueC, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003628 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003629 }
3630 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07003631 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003632 } break;
3633 case XFA_ATTRIBUTETYPE_Boolean: {
tsepezd19e9122016-11-02 15:43:18 -07003634 bool bValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04003635 if (!TryBoolean(pAttr->eName, bValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003636 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003637 }
dan sinclair65c7c232017-02-02 14:05:30 -08003638 wsValue = bValue ? L"1" : L"0";
tsepezd19e9122016-11-02 15:43:18 -07003639 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003640 } break;
3641 case XFA_ATTRIBUTETYPE_Integer: {
3642 int32_t iValue;
3643 if (!TryInteger(pAttr->eName, iValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003644 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003645 }
3646 wsValue.Format(L"%d", iValue);
tsepezd19e9122016-11-02 15:43:18 -07003647 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003648 } break;
3649 case XFA_ATTRIBUTETYPE_Measure: {
3650 CXFA_Measurement mValue;
3651 if (!TryMeasure(pAttr->eName, mValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003652 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003653 }
3654 mValue.ToString(wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003655 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003656 } break;
3657 default:
3658 break;
3659 }
tsepezd19e9122016-11-02 15:43:18 -07003660 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003661}
dsinclair5b36f0a2016-07-19 10:56:23 -07003662
tsepezd19e9122016-11-02 15:43:18 -07003663bool CXFA_Node::SetAttribute(const CFX_WideStringC& wsAttr,
3664 const CFX_WideStringC& wsValue,
3665 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003666 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsValue);
3667 if (pAttributeInfo) {
3668 return SetAttribute(pAttributeInfo->eName, wsValue, bNotify);
3669 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003670 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003671 SetMapModuleString(pKey, wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003672 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003673}
dsinclair5b36f0a2016-07-19 10:56:23 -07003674
tsepezd19e9122016-11-02 15:43:18 -07003675bool CXFA_Node::GetAttribute(const CFX_WideStringC& wsAttr,
3676 CFX_WideString& wsValue,
3677 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003678 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsAttr);
3679 if (pAttributeInfo) {
3680 return GetAttribute(pAttributeInfo->eName, wsValue, bUseDefault);
3681 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003682 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003683 CFX_WideStringC wsValueC;
3684 if (GetMapModuleString(pKey, wsValueC)) {
3685 wsValue = wsValueC;
3686 }
tsepezd19e9122016-11-02 15:43:18 -07003687 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003688}
dsinclair5b36f0a2016-07-19 10:56:23 -07003689
tsepezd19e9122016-11-02 15:43:18 -07003690bool CXFA_Node::RemoveAttribute(const CFX_WideStringC& wsAttr) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003691 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003692 RemoveMapModuleKey(pKey);
tsepezd19e9122016-11-02 15:43:18 -07003693 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003694}
dsinclair5b36f0a2016-07-19 10:56:23 -07003695
tsepezd19e9122016-11-02 15:43:18 -07003696bool CXFA_Node::TryBoolean(XFA_ATTRIBUTE eAttr,
3697 bool& bValue,
3698 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003699 void* pValue = nullptr;
3700 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Boolean, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003701 return false;
tsepez478ed622016-10-27 14:32:33 -07003702 bValue = !!pValue;
tsepezd19e9122016-11-02 15:43:18 -07003703 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003704}
dsinclair5b36f0a2016-07-19 10:56:23 -07003705
tsepezd19e9122016-11-02 15:43:18 -07003706bool CXFA_Node::TryInteger(XFA_ATTRIBUTE eAttr,
3707 int32_t& iValue,
3708 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003709 void* pValue = nullptr;
3710 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Integer, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003711 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003712 iValue = (int32_t)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003713 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003714}
dsinclair5b36f0a2016-07-19 10:56:23 -07003715
tsepezd19e9122016-11-02 15:43:18 -07003716bool CXFA_Node::TryEnum(XFA_ATTRIBUTE eAttr,
3717 XFA_ATTRIBUTEENUM& eValue,
3718 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003719 void* pValue = nullptr;
3720 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Enum, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003721 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003722 eValue = (XFA_ATTRIBUTEENUM)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003723 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003724}
thestigb1a59592016-04-14 18:29:56 -07003725
tsepezd19e9122016-11-02 15:43:18 -07003726bool CXFA_Node::SetMeasure(XFA_ATTRIBUTE eAttr,
3727 CXFA_Measurement mValue,
3728 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003729 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003730 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003731 SetMapModuleBuffer(pKey, &mValue, sizeof(CXFA_Measurement));
tsepezd19e9122016-11-02 15:43:18 -07003732 OnChanged(eAttr, bNotify, false);
3733 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003734}
thestigb1a59592016-04-14 18:29:56 -07003735
tsepezd19e9122016-11-02 15:43:18 -07003736bool CXFA_Node::TryMeasure(XFA_ATTRIBUTE eAttr,
3737 CXFA_Measurement& mValue,
3738 bool bUseDefault) const {
dsinclair5b36f0a2016-07-19 10:56:23 -07003739 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003740 void* pValue;
3741 int32_t iBytes;
3742 if (GetMapModuleBuffer(pKey, pValue, iBytes) && iBytes == sizeof(mValue)) {
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04003743 memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003744 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003745 }
3746 if (bUseDefault &&
dsinclair070fcdf2016-06-22 22:04:54 -07003747 XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003748 XFA_ATTRIBUTETYPE_Measure, m_ePacket)) {
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04003749 memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003750 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003751 }
tsepezd19e9122016-11-02 15:43:18 -07003752 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003753}
3754
3755CXFA_Measurement CXFA_Node::GetMeasure(XFA_ATTRIBUTE eAttr) const {
3756 CXFA_Measurement mValue;
tsepezd19e9122016-11-02 15:43:18 -07003757 return TryMeasure(eAttr, mValue, true) ? mValue : CXFA_Measurement();
Dan Sinclair1770c022016-03-14 14:14:16 -04003758}
3759
tsepezd19e9122016-11-02 15:43:18 -07003760bool CXFA_Node::SetCData(XFA_ATTRIBUTE eAttr,
3761 const CFX_WideString& wsValue,
3762 bool bNotify,
3763 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003764 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003765 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003766 if (eAttr == XFA_ATTRIBUTE_Value) {
3767 CFX_WideString* pClone = new CFX_WideString(wsValue);
3768 SetUserData(pKey, pClone, &deleteWideStringCallBack);
3769 } else {
tsepez4c3debb2016-04-08 12:20:38 -07003770 SetMapModuleString(pKey, wsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003771 if (eAttr == XFA_ATTRIBUTE_Name)
3772 UpdateNameHash();
3773 }
thestigb1a59592016-04-14 18:29:56 -07003774 OnChanged(eAttr, bNotify, bScriptModify);
3775
3776 if (!IsNeedSavingXMLNode() || eAttr == XFA_ATTRIBUTE_QualifiedName ||
3777 eAttr == XFA_ATTRIBUTE_BindingNode) {
tsepezd19e9122016-11-02 15:43:18 -07003778 return true;
thestigb1a59592016-04-14 18:29:56 -07003779 }
3780
dsinclair070fcdf2016-06-22 22:04:54 -07003781 if (eAttr == XFA_ATTRIBUTE_Name &&
3782 (m_elementType == XFA_Element::DataValue ||
3783 m_elementType == XFA_Element::DataGroup)) {
tsepezd19e9122016-11-02 15:43:18 -07003784 return true;
thestigb1a59592016-04-14 18:29:56 -07003785 }
3786
3787 if (eAttr == XFA_ATTRIBUTE_Value) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003788 FX_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
thestigb1a59592016-04-14 18:29:56 -07003789 switch (eXMLType) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003790 case FX_XMLNODE_Element:
thestigb1a59592016-04-14 18:29:56 -07003791 if (IsAttributeInXML()) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003792 static_cast<CFX_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003793 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3794 wsValue);
thestigb1a59592016-04-14 18:29:56 -07003795 } else {
tsepezd19e9122016-11-02 15:43:18 -07003796 bool bDeleteChildren = true;
thestigb1a59592016-04-14 18:29:56 -07003797 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3798 for (CXFA_Node* pChildDataNode =
3799 GetNodeItem(XFA_NODEITEM_FirstChild);
3800 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3801 XFA_NODEITEM_NextSibling)) {
Tom Sepezf8a94392017-03-14 12:13:22 -07003802 if (!pChildDataNode->GetBindItems().empty()) {
tsepezd19e9122016-11-02 15:43:18 -07003803 bDeleteChildren = false;
thestigb1a59592016-04-14 18:29:56 -07003804 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04003805 }
3806 }
Dan Sinclair1770c022016-03-14 14:14:16 -04003807 }
thestigb1a59592016-04-14 18:29:56 -07003808 if (bDeleteChildren) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003809 static_cast<CFX_XMLElement*>(m_pXMLNode)->DeleteChildren();
thestigb1a59592016-04-14 18:29:56 -07003810 }
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003811 static_cast<CFX_XMLElement*>(m_pXMLNode)->SetTextData(wsValue);
thestigb1a59592016-04-14 18:29:56 -07003812 }
3813 break;
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003814 case FX_XMLNODE_Text:
3815 static_cast<CFX_XMLText*>(m_pXMLNode)->SetText(wsValue);
thestigb1a59592016-04-14 18:29:56 -07003816 break;
3817 default:
dsinclair43854a52016-04-27 12:26:00 -07003818 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003819 }
tsepezd19e9122016-11-02 15:43:18 -07003820 return true;
thestigb1a59592016-04-14 18:29:56 -07003821 }
3822
3823 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
3824 if (pInfo) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003825 ASSERT(m_pXMLNode->GetType() == FX_XMLNODE_Element);
thestigb1a59592016-04-14 18:29:56 -07003826 CFX_WideString wsAttrName = pInfo->pName;
3827 if (pInfo->eName == XFA_ATTRIBUTE_ContentType) {
dan sinclair65c7c232017-02-02 14:05:30 -08003828 wsAttrName = L"xfa:" + wsAttrName;
Dan Sinclair1770c022016-03-14 14:14:16 -04003829 }
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003830 static_cast<CFX_XMLElement*>(m_pXMLNode)->SetString(wsAttrName, wsValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003831 }
tsepezd19e9122016-11-02 15:43:18 -07003832 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003833}
thestigb1a59592016-04-14 18:29:56 -07003834
tsepezd19e9122016-11-02 15:43:18 -07003835bool CXFA_Node::SetAttributeValue(const CFX_WideString& wsValue,
3836 const CFX_WideString& wsXMLValue,
3837 bool bNotify,
3838 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003839 void* pKey = GetMapKey_Element(GetElementType(), XFA_ATTRIBUTE_Value);
thestigb1a59592016-04-14 18:29:56 -07003840 OnChanging(XFA_ATTRIBUTE_Value, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003841 CFX_WideString* pClone = new CFX_WideString(wsValue);
3842 SetUserData(pKey, pClone, &deleteWideStringCallBack);
thestigb1a59592016-04-14 18:29:56 -07003843 OnChanged(XFA_ATTRIBUTE_Value, bNotify, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003844 if (IsNeedSavingXMLNode()) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003845 FX_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
Dan Sinclair1770c022016-03-14 14:14:16 -04003846 switch (eXMLType) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003847 case FX_XMLNODE_Element:
Dan Sinclair1770c022016-03-14 14:14:16 -04003848 if (IsAttributeInXML()) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003849 static_cast<CFX_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003850 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3851 wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003852 } else {
tsepezd19e9122016-11-02 15:43:18 -07003853 bool bDeleteChildren = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003854 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3855 for (CXFA_Node* pChildDataNode =
3856 GetNodeItem(XFA_NODEITEM_FirstChild);
3857 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3858 XFA_NODEITEM_NextSibling)) {
Tom Sepezf8a94392017-03-14 12:13:22 -07003859 if (!pChildDataNode->GetBindItems().empty()) {
tsepezd19e9122016-11-02 15:43:18 -07003860 bDeleteChildren = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003861 break;
3862 }
3863 }
3864 }
3865 if (bDeleteChildren) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003866 static_cast<CFX_XMLElement*>(m_pXMLNode)->DeleteChildren();
Dan Sinclair1770c022016-03-14 14:14:16 -04003867 }
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003868 static_cast<CFX_XMLElement*>(m_pXMLNode)->SetTextData(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003869 }
3870 break;
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003871 case FX_XMLNODE_Text:
3872 static_cast<CFX_XMLText*>(m_pXMLNode)->SetText(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003873 break;
3874 default:
dsinclair43854a52016-04-27 12:26:00 -07003875 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003876 }
3877 }
tsepezd19e9122016-11-02 15:43:18 -07003878 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003879}
dsinclair5b36f0a2016-07-19 10:56:23 -07003880
tsepezd19e9122016-11-02 15:43:18 -07003881bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3882 CFX_WideString& wsValue,
3883 bool bUseDefault,
3884 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003885 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003886 if (eAttr == XFA_ATTRIBUTE_Value) {
3887 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
3888 if (pStr) {
3889 wsValue = *pStr;
tsepezd19e9122016-11-02 15:43:18 -07003890 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003891 }
3892 } else {
3893 CFX_WideStringC wsValueC;
3894 if (GetMapModuleString(pKey, wsValueC)) {
3895 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07003896 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003897 }
3898 }
3899 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07003900 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003901 }
weili44f8faf2016-06-01 14:03:56 -07003902 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07003903 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003904 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
Dan Sinclair812e96c2017-03-13 16:43:37 -04003905 wsValue = (const wchar_t*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003906 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003907 }
tsepezd19e9122016-11-02 15:43:18 -07003908 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003909}
dsinclair5b36f0a2016-07-19 10:56:23 -07003910
tsepezd19e9122016-11-02 15:43:18 -07003911bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3912 CFX_WideStringC& wsValue,
3913 bool bUseDefault,
3914 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003915 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003916 if (eAttr == XFA_ATTRIBUTE_Value) {
3917 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
3918 if (pStr) {
tsepez4d31d0c2016-04-19 14:11:59 -07003919 wsValue = pStr->AsStringC();
tsepezd19e9122016-11-02 15:43:18 -07003920 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003921 }
3922 } else {
3923 if (GetMapModuleString(pKey, wsValue)) {
tsepezd19e9122016-11-02 15:43:18 -07003924 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003925 }
3926 }
3927 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07003928 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003929 }
weili44f8faf2016-06-01 14:03:56 -07003930 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07003931 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003932 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
Dan Sinclair812e96c2017-03-13 16:43:37 -04003933 wsValue = (CFX_WideStringC)(const wchar_t*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003934 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003935 }
tsepezd19e9122016-11-02 15:43:18 -07003936 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003937}
dsinclair5b36f0a2016-07-19 10:56:23 -07003938
tsepezd19e9122016-11-02 15:43:18 -07003939bool CXFA_Node::SetObject(XFA_ATTRIBUTE eAttr,
3940 void* pData,
3941 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003942 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003943 return SetUserData(pKey, pData, pCallbackInfo);
3944}
dsinclair5b36f0a2016-07-19 10:56:23 -07003945
tsepezd19e9122016-11-02 15:43:18 -07003946bool CXFA_Node::TryObject(XFA_ATTRIBUTE eAttr, void*& pData) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003947 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003948 pData = GetUserData(pKey);
dsinclair85d1f2c2016-06-23 12:40:16 -07003949 return !!pData;
Dan Sinclair1770c022016-03-14 14:14:16 -04003950}
dsinclair5b36f0a2016-07-19 10:56:23 -07003951
tsepezd19e9122016-11-02 15:43:18 -07003952bool CXFA_Node::SetValue(XFA_ATTRIBUTE eAttr,
3953 XFA_ATTRIBUTETYPE eType,
3954 void* pValue,
3955 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003956 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003957 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003958 SetMapModuleValue(pKey, pValue);
tsepezd19e9122016-11-02 15:43:18 -07003959 OnChanged(eAttr, bNotify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003960 if (IsNeedSavingXMLNode()) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003961 ASSERT(m_pXMLNode->GetType() == FX_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04003962 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
3963 if (pInfo) {
3964 switch (eType) {
3965 case XFA_ATTRIBUTETYPE_Enum:
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003966 static_cast<CFX_XMLElement*>(m_pXMLNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04003967 ->SetString(
3968 pInfo->pName,
dsinclair9eb0db12016-07-21 12:01:39 -07003969 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)(uintptr_t)pValue)
Dan Sinclair1770c022016-03-14 14:14:16 -04003970 ->pName);
3971 break;
3972 case XFA_ATTRIBUTETYPE_Boolean:
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003973 static_cast<CFX_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003974 ->SetString(pInfo->pName, pValue ? L"1" : L"0");
Dan Sinclair1770c022016-03-14 14:14:16 -04003975 break;
Dan Sinclair5fa4e982017-04-05 11:48:21 -04003976 case XFA_ATTRIBUTETYPE_Integer: {
3977 CFX_WideString wsValue;
3978 wsValue.Format(
3979 L"%d", static_cast<int32_t>(reinterpret_cast<uintptr_t>(pValue)));
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04003980 static_cast<CFX_XMLElement*>(m_pXMLNode)
Dan Sinclair5fa4e982017-04-05 11:48:21 -04003981 ->SetString(pInfo->pName, wsValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003982 break;
Dan Sinclair5fa4e982017-04-05 11:48:21 -04003983 }
Dan Sinclair1770c022016-03-14 14:14:16 -04003984 default:
dsinclair43854a52016-04-27 12:26:00 -07003985 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003986 }
3987 }
3988 }
tsepezd19e9122016-11-02 15:43:18 -07003989 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003990}
dsinclair5b36f0a2016-07-19 10:56:23 -07003991
tsepezd19e9122016-11-02 15:43:18 -07003992bool CXFA_Node::GetValue(XFA_ATTRIBUTE eAttr,
3993 XFA_ATTRIBUTETYPE eType,
3994 bool bUseDefault,
3995 void*& pValue) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003996 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003997 if (GetMapModuleValue(pKey, pValue)) {
tsepezd19e9122016-11-02 15:43:18 -07003998 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003999 }
4000 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07004001 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004002 }
dsinclair070fcdf2016-06-22 22:04:54 -07004003 return XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, eType,
Dan Sinclair1770c022016-03-14 14:14:16 -04004004 m_ePacket);
4005}
dsinclair5b36f0a2016-07-19 10:56:23 -07004006
tsepezd19e9122016-11-02 15:43:18 -07004007bool CXFA_Node::SetUserData(void* pKey,
4008 void* pData,
4009 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004010 SetMapModuleBuffer(pKey, &pData, sizeof(void*),
4011 pCallbackInfo ? pCallbackInfo : &gs_XFADefaultFreeData);
tsepezd19e9122016-11-02 15:43:18 -07004012 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004013}
dsinclair5b36f0a2016-07-19 10:56:23 -07004014
tsepezd19e9122016-11-02 15:43:18 -07004015bool CXFA_Node::TryUserData(void* pKey, void*& pData, bool bProtoAlso) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004016 int32_t iBytes = 0;
4017 if (!GetMapModuleBuffer(pKey, pData, iBytes, bProtoAlso)) {
tsepezd19e9122016-11-02 15:43:18 -07004018 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004019 }
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04004020 return iBytes == sizeof(void*) && memcpy(&pData, pData, iBytes);
Dan Sinclair1770c022016-03-14 14:14:16 -04004021}
dsinclair5b36f0a2016-07-19 10:56:23 -07004022
tsepezd19e9122016-11-02 15:43:18 -07004023bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent,
4024 const CFX_WideString& wsXMLValue,
4025 bool bNotify,
4026 bool bScriptModify,
4027 bool bSyncData) {
weili44f8faf2016-06-01 14:03:56 -07004028 CXFA_Node* pNode = nullptr;
4029 CXFA_Node* pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004030 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004031 case XFA_ObjectType::ContainerNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004032 if (XFA_FieldIsMultiListBox(this)) {
dsinclair56a8b192016-06-21 14:15:25 -07004033 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004034 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004035 ASSERT(pChildValue);
tsepezafe94302016-05-13 17:21:31 -07004036 pChildValue->SetCData(XFA_ATTRIBUTE_ContentType, L"text/xml");
Dan Sinclair1770c022016-03-14 14:14:16 -04004037 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004038 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004039 CXFA_Node* pBind = GetBindData();
4040 if (bSyncData && pBind) {
tsepez51709be2016-12-08 10:55:57 -08004041 std::vector<CFX_WideString> wsSaveTextArray;
Tom Sepezf8a94392017-03-14 12:13:22 -07004042 size_t iSize = 0;
Dan Sinclair1770c022016-03-14 14:14:16 -04004043 if (!wsContent.IsEmpty()) {
4044 int32_t iStart = 0;
4045 int32_t iLength = wsContent.GetLength();
4046 int32_t iEnd = wsContent.Find(L'\n', iStart);
4047 iEnd = (iEnd == -1) ? iLength : iEnd;
4048 while (iEnd >= iStart) {
tsepez51709be2016-12-08 10:55:57 -08004049 wsSaveTextArray.push_back(wsContent.Mid(iStart, iEnd - iStart));
Dan Sinclair1770c022016-03-14 14:14:16 -04004050 iStart = iEnd + 1;
4051 if (iStart >= iLength) {
4052 break;
4053 }
4054 iEnd = wsContent.Find(L'\n', iStart);
4055 if (iEnd < 0) {
tsepez51709be2016-12-08 10:55:57 -08004056 wsSaveTextArray.push_back(
4057 wsContent.Mid(iStart, iLength - iStart));
Dan Sinclair1770c022016-03-14 14:14:16 -04004058 }
4059 }
Tom Sepezf8a94392017-03-14 12:13:22 -07004060 iSize = wsSaveTextArray.size();
Dan Sinclair1770c022016-03-14 14:14:16 -04004061 }
4062 if (iSize == 0) {
4063 while (CXFA_Node* pChildNode =
4064 pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) {
4065 pBind->RemoveChild(pChildNode);
4066 }
4067 } else {
Tom Sepezf8a94392017-03-14 12:13:22 -07004068 std::vector<CXFA_Node*> valueNodes = pBind->GetNodeList(
4069 XFA_NODEFILTER_Children, XFA_Element::DataValue);
4070 size_t iDatas = valueNodes.size();
Dan Sinclair1770c022016-03-14 14:14:16 -04004071 if (iDatas < iSize) {
Tom Sepezf8a94392017-03-14 12:13:22 -07004072 size_t iAddNodes = iSize - iDatas;
weili44f8faf2016-06-01 14:03:56 -07004073 CXFA_Node* pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004074 while (iAddNodes-- > 0) {
4075 pValueNodes =
dsinclair56a8b192016-06-21 14:15:25 -07004076 pBind->CreateSamePacketNode(XFA_Element::DataValue);
tsepezafe94302016-05-13 17:21:31 -07004077 pValueNodes->SetCData(XFA_ATTRIBUTE_Name, L"value");
Dan Sinclair1770c022016-03-14 14:14:16 -04004078 pValueNodes->CreateXMLMappingNode();
4079 pBind->InsertChild(pValueNodes);
4080 }
weili44f8faf2016-06-01 14:03:56 -07004081 pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004082 } else if (iDatas > iSize) {
Tom Sepezf8a94392017-03-14 12:13:22 -07004083 size_t iDelNodes = iDatas - iSize;
Dan Sinclair1770c022016-03-14 14:14:16 -04004084 while (iDelNodes-- > 0) {
4085 pBind->RemoveChild(pBind->GetNodeItem(XFA_NODEITEM_FirstChild));
4086 }
4087 }
4088 int32_t i = 0;
4089 for (CXFA_Node* pValueNode =
4090 pBind->GetNodeItem(XFA_NODEITEM_FirstChild);
4091 pValueNode; pValueNode = pValueNode->GetNodeItem(
4092 XFA_NODEITEM_NextSibling)) {
4093 pValueNode->SetAttributeValue(wsSaveTextArray[i],
tsepezd19e9122016-11-02 15:43:18 -07004094 wsSaveTextArray[i], false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004095 i++;
4096 }
4097 }
Tom Sepezf8a94392017-03-14 12:13:22 -07004098 for (CXFA_Node* pArrayNode : pBind->GetBindItems()) {
4099 if (pArrayNode != this) {
4100 pArrayNode->SetScriptContent(wsContent, wsContent, bNotify,
4101 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004102 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004103 }
4104 }
4105 break;
dsinclair070fcdf2016-06-22 22:04:54 -07004106 } else if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004107 pNode = this;
4108 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004109 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004110 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004111 ASSERT(pChildValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04004112 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004113 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004114 }
4115 pBindNode = GetBindData();
4116 if (pBindNode && bSyncData) {
4117 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004118 bScriptModify, false);
Tom Sepezf8a94392017-03-14 12:13:22 -07004119 for (CXFA_Node* pArrayNode : pBindNode->GetBindItems()) {
4120 if (pArrayNode != this) {
4121 pArrayNode->SetScriptContent(wsContent, wsContent, bNotify, true,
4122 false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004123 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004124 }
4125 }
weili44f8faf2016-06-01 14:03:56 -07004126 pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004127 break;
4128 }
dsinclairc5a8f212016-06-20 11:11:12 -07004129 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004130 CFX_WideString wsContentType;
dsinclair070fcdf2016-06-22 22:04:54 -07004131 if (GetElementType() == XFA_Element::ExData) {
tsepezd19e9122016-11-02 15:43:18 -07004132 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
dan sinclair65c7c232017-02-02 14:05:30 -08004133 if (wsContentType == L"text/html") {
4134 wsContentType = L"";
tsepez4c3debb2016-04-08 12:20:38 -07004135 SetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04004136 }
4137 }
4138 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4139 if (!pContentRawDataNode) {
tsepez9f2970c2016-04-01 10:23:04 -07004140 pContentRawDataNode = CreateSamePacketNode(
dan sinclair65c7c232017-02-02 14:05:30 -08004141 (wsContentType == L"text/xml") ? XFA_Element::Sharpxml
4142 : XFA_Element::Sharptext);
Dan Sinclair1770c022016-03-14 14:14:16 -04004143 InsertChild(pContentRawDataNode);
4144 }
4145 return pContentRawDataNode->SetScriptContent(
4146 wsContent, wsXMLValue, bNotify, bScriptModify, bSyncData);
4147 } break;
dsinclairc5a8f212016-06-20 11:11:12 -07004148 case XFA_ObjectType::NodeC:
4149 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004150 pNode = this;
4151 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004152 case XFA_ObjectType::NodeV:
Dan Sinclair1770c022016-03-14 14:14:16 -04004153 pNode = this;
4154 if (bSyncData && GetPacketID() == XFA_XDPPACKET_Form) {
4155 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
4156 if (pParent) {
4157 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4158 }
dsinclair070fcdf2016-06-22 22:04:54 -07004159 if (pParent && pParent->GetElementType() == XFA_Element::Value) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004160 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4161 if (pParent && pParent->IsContainerNode()) {
4162 pBindNode = pParent->GetBindData();
4163 if (pBindNode) {
4164 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004165 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004166 }
4167 }
4168 }
4169 }
4170 break;
4171 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004172 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004173 pNode = this;
4174 pBindNode = this;
4175 }
4176 break;
4177 }
4178 if (pNode) {
4179 SetAttributeValue(wsContent, wsXMLValue, bNotify, bScriptModify);
4180 if (pBindNode && bSyncData) {
Tom Sepezf8a94392017-03-14 12:13:22 -07004181 for (CXFA_Node* pArrayNode : pBindNode->GetBindItems()) {
4182 pArrayNode->SetScriptContent(wsContent, wsContent, bNotify,
4183 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004184 }
4185 }
tsepezd19e9122016-11-02 15:43:18 -07004186 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004187 }
tsepezd19e9122016-11-02 15:43:18 -07004188 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004189}
dsinclair5b36f0a2016-07-19 10:56:23 -07004190
tsepezd19e9122016-11-02 15:43:18 -07004191bool CXFA_Node::SetContent(const CFX_WideString& wsContent,
4192 const CFX_WideString& wsXMLValue,
4193 bool bNotify,
4194 bool bScriptModify,
4195 bool bSyncData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004196 return SetScriptContent(wsContent, wsXMLValue, bNotify, bScriptModify,
4197 bSyncData);
4198}
dsinclair5b36f0a2016-07-19 10:56:23 -07004199
tsepezd19e9122016-11-02 15:43:18 -07004200CFX_WideString CXFA_Node::GetScriptContent(bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004201 CFX_WideString wsContent;
4202 return TryContent(wsContent, bScriptModify) ? wsContent : CFX_WideString();
4203}
dsinclair5b36f0a2016-07-19 10:56:23 -07004204
Dan Sinclair1770c022016-03-14 14:14:16 -04004205CFX_WideString CXFA_Node::GetContent() {
4206 return GetScriptContent();
4207}
dsinclair5b36f0a2016-07-19 10:56:23 -07004208
tsepezd19e9122016-11-02 15:43:18 -07004209bool CXFA_Node::TryContent(CFX_WideString& wsContent,
4210 bool bScriptModify,
4211 bool bProto) {
weili44f8faf2016-06-01 14:03:56 -07004212 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004213 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004214 case XFA_ObjectType::ContainerNode:
dsinclair070fcdf2016-06-22 22:04:54 -07004215 if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004216 pNode = this;
4217 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004218 CXFA_Node* pValue = GetChild(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004219 if (!pValue) {
tsepezd19e9122016-11-02 15:43:18 -07004220 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004221 }
4222 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
4223 if (pChildValue && XFA_FieldIsMultiListBox(this)) {
dan sinclair65c7c232017-02-02 14:05:30 -08004224 pChildValue->SetAttribute(XFA_ATTRIBUTE_ContentType, L"text/xml");
Dan Sinclair1770c022016-03-14 14:14:16 -04004225 }
4226 return pChildValue
4227 ? pChildValue->TryContent(wsContent, bScriptModify, bProto)
tsepezd19e9122016-11-02 15:43:18 -07004228 : false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004229 }
4230 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004231 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004232 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4233 if (!pContentRawDataNode) {
dsinclair56a8b192016-06-21 14:15:25 -07004234 XFA_Element element = XFA_Element::Sharptext;
dsinclair070fcdf2016-06-22 22:04:54 -07004235 if (GetElementType() == XFA_Element::ExData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004236 CFX_WideString wsContentType;
tsepezd19e9122016-11-02 15:43:18 -07004237 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
dan sinclair65c7c232017-02-02 14:05:30 -08004238 if (wsContentType == L"text/html") {
dsinclair56a8b192016-06-21 14:15:25 -07004239 element = XFA_Element::SharpxHTML;
dan sinclair65c7c232017-02-02 14:05:30 -08004240 } else if (wsContentType == L"text/xml") {
dsinclair56a8b192016-06-21 14:15:25 -07004241 element = XFA_Element::Sharpxml;
Dan Sinclair1770c022016-03-14 14:14:16 -04004242 }
4243 }
4244 pContentRawDataNode = CreateSamePacketNode(element);
4245 InsertChild(pContentRawDataNode);
4246 }
4247 return pContentRawDataNode->TryContent(wsContent, bScriptModify, bProto);
4248 }
dsinclairc5a8f212016-06-20 11:11:12 -07004249 case XFA_ObjectType::NodeC:
4250 case XFA_ObjectType::NodeV:
4251 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004252 pNode = this;
4253 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004254 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004255 pNode = this;
4256 }
4257 break;
4258 }
4259 if (pNode) {
4260 if (bScriptModify) {
dsinclairdf4bc592016-03-31 20:34:43 -07004261 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004262 if (pScriptContext) {
4263 m_pDocument->GetScriptContext()->AddNodesOfRunScript(this);
4264 }
4265 }
tsepezd19e9122016-11-02 15:43:18 -07004266 return TryCData(XFA_ATTRIBUTE_Value, wsContent, false, bProto);
Dan Sinclair1770c022016-03-14 14:14:16 -04004267 }
tsepezd19e9122016-11-02 15:43:18 -07004268 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004269}
dsinclair5b36f0a2016-07-19 10:56:23 -07004270
Dan Sinclair1770c022016-03-14 14:14:16 -04004271CXFA_Node* CXFA_Node::GetModelNode() {
4272 switch (GetPacketID()) {
4273 case XFA_XDPPACKET_XDP:
4274 return m_pDocument->GetRoot();
4275 case XFA_XDPPACKET_Config:
4276 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config));
4277 case XFA_XDPPACKET_Template:
4278 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
4279 case XFA_XDPPACKET_Form:
4280 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form));
4281 case XFA_XDPPACKET_Datasets:
4282 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets));
4283 case XFA_XDPPACKET_LocaleSet:
4284 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_LocaleSet));
4285 case XFA_XDPPACKET_ConnectionSet:
4286 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_ConnectionSet));
4287 case XFA_XDPPACKET_SourceSet:
4288 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_SourceSet));
4289 case XFA_XDPPACKET_Xdc:
4290 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Xdc));
4291 default:
4292 return this;
4293 }
4294}
dsinclair5b36f0a2016-07-19 10:56:23 -07004295
tsepezd19e9122016-11-02 15:43:18 -07004296bool CXFA_Node::TryNamespace(CFX_WideString& wsNamespace) {
tsepez774bdde2016-04-14 09:49:44 -07004297 wsNamespace.clear();
dsinclair070fcdf2016-06-22 22:04:54 -07004298 if (IsModelNode() || GetElementType() == XFA_Element::Packet) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004299 CFX_XMLNode* pXMLNode = GetXMLMappingNode();
4300 if (!pXMLNode || pXMLNode->GetType() != FX_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004301 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004302 }
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004303 wsNamespace = static_cast<CFX_XMLElement*>(pXMLNode)->GetNamespaceURI();
tsepezd19e9122016-11-02 15:43:18 -07004304 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004305 } else if (GetPacketID() == XFA_XDPPACKET_Datasets) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004306 CFX_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004307 if (!pXMLNode) {
tsepezd19e9122016-11-02 15:43:18 -07004308 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004309 }
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004310 if (pXMLNode->GetType() != FX_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004311 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004312 }
dsinclair070fcdf2016-06-22 22:04:54 -07004313 if (GetElementType() == XFA_Element::DataValue &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004314 GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData) {
4315 return XFA_FDEExtension_ResolveNamespaceQualifier(
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004316 static_cast<CFX_XMLElement*>(pXMLNode),
Dan Sinclair5fa4e982017-04-05 11:48:21 -04004317 GetCData(XFA_ATTRIBUTE_QualifiedName), &wsNamespace);
Dan Sinclair1770c022016-03-14 14:14:16 -04004318 }
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004319 wsNamespace = static_cast<CFX_XMLElement*>(pXMLNode)->GetNamespaceURI();
tsepezd19e9122016-11-02 15:43:18 -07004320 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004321 } else {
4322 CXFA_Node* pModelNode = GetModelNode();
4323 return pModelNode->TryNamespace(wsNamespace);
4324 }
4325}
dsinclair5b36f0a2016-07-19 10:56:23 -07004326
Dan Sinclair1770c022016-03-14 14:14:16 -04004327CXFA_Node* CXFA_Node::GetProperty(int32_t index,
dsinclair56a8b192016-06-21 14:15:25 -07004328 XFA_Element eProperty,
tsepezd19e9122016-11-02 15:43:18 -07004329 bool bCreateProperty) {
dsinclair41cb62e2016-06-23 09:20:32 -07004330 XFA_Element eType = GetElementType();
tsepez736f28a2016-03-25 14:19:51 -07004331 uint32_t dwPacket = GetPacketID();
Dan Sinclair1770c022016-03-14 14:14:16 -04004332 const XFA_PROPERTY* pProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004333 XFA_GetPropertyOfElement(eType, eProperty, dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004334 if (!pProperty || index >= pProperty->uOccur)
4335 return nullptr;
4336
Dan Sinclair1770c022016-03-14 14:14:16 -04004337 CXFA_Node* pNode = m_pChild;
4338 int32_t iCount = 0;
4339 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004340 if (pNode->GetElementType() == eProperty) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004341 iCount++;
4342 if (iCount > index) {
4343 return pNode;
4344 }
4345 }
4346 }
weili44f8faf2016-06-01 14:03:56 -07004347 if (!bCreateProperty)
4348 return nullptr;
4349
Dan Sinclair1770c022016-03-14 14:14:16 -04004350 if (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf) {
4351 pNode = m_pChild;
4352 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4353 const XFA_PROPERTY* pExistProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004354 XFA_GetPropertyOfElement(eType, pNode->GetElementType(), dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004355 if (pExistProperty && (pExistProperty->uFlags & XFA_PROPERTYFLAG_OneOf))
4356 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004357 }
4358 }
dsinclaira1b07722016-07-11 08:20:58 -07004359
Dan Sinclair1770c022016-03-14 14:14:16 -04004360 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(dwPacket);
weili038aa532016-05-20 15:38:29 -07004361 CXFA_Node* pNewNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004362 for (; iCount <= index; iCount++) {
dsinclaira1b07722016-07-11 08:20:58 -07004363 pNewNode = m_pDocument->CreateNode(pPacket, eProperty);
weili44f8faf2016-06-01 14:03:56 -07004364 if (!pNewNode)
4365 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004366 InsertChild(pNewNode, nullptr);
dsinclairc5a8f212016-06-20 11:11:12 -07004367 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004368 }
4369 return pNewNode;
4370}
dsinclair5b36f0a2016-07-19 10:56:23 -07004371
tsepezd19e9122016-11-02 15:43:18 -07004372int32_t CXFA_Node::CountChildren(XFA_Element eType, bool bOnlyChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004373 CXFA_Node* pNode = m_pChild;
4374 int32_t iCount = 0;
4375 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004376 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004377 if (bOnlyChild) {
4378 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004379 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004380 if (pProperty) {
4381 continue;
4382 }
4383 }
4384 iCount++;
4385 }
4386 }
4387 return iCount;
4388}
dsinclair5b36f0a2016-07-19 10:56:23 -07004389
Dan Sinclair1770c022016-03-14 14:14:16 -04004390CXFA_Node* CXFA_Node::GetChild(int32_t index,
dsinclair41cb62e2016-06-23 09:20:32 -07004391 XFA_Element eType,
tsepezd19e9122016-11-02 15:43:18 -07004392 bool bOnlyChild) {
dsinclair43854a52016-04-27 12:26:00 -07004393 ASSERT(index > -1);
Dan Sinclair1770c022016-03-14 14:14:16 -04004394 CXFA_Node* pNode = m_pChild;
4395 int32_t iCount = 0;
4396 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004397 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004398 if (bOnlyChild) {
4399 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004400 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004401 if (pProperty) {
4402 continue;
4403 }
4404 }
4405 iCount++;
4406 if (iCount > index) {
4407 return pNode;
4408 }
4409 }
4410 }
weili44f8faf2016-06-01 14:03:56 -07004411 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004412}
dsinclair5b36f0a2016-07-19 10:56:23 -07004413
Dan Sinclair1770c022016-03-14 14:14:16 -04004414int32_t CXFA_Node::InsertChild(int32_t index, CXFA_Node* pNode) {
4415 ASSERT(!pNode->m_pNext);
4416 pNode->m_pParent = this;
tsepezd19e9122016-11-02 15:43:18 -07004417 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004418 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004419 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004420
weili44f8faf2016-06-01 14:03:56 -07004421 if (!m_pChild || index == 0) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004422 if (index > 0) {
4423 return -1;
4424 }
4425 pNode->m_pNext = m_pChild;
4426 m_pChild = pNode;
4427 index = 0;
4428 } else if (index < 0) {
4429 m_pLastChild->m_pNext = pNode;
4430 } else {
4431 CXFA_Node* pPrev = m_pChild;
4432 int32_t iCount = 0;
4433 while (++iCount != index && pPrev->m_pNext) {
4434 pPrev = pPrev->m_pNext;
4435 }
4436 if (index > 0 && index != iCount) {
4437 return -1;
4438 }
4439 pNode->m_pNext = pPrev->m_pNext;
4440 pPrev->m_pNext = pNode;
4441 index = iCount;
4442 }
weili44f8faf2016-06-01 14:03:56 -07004443 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004444 m_pLastChild = pNode;
4445 }
4446 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004447 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004448 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004449 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004450 if (pNotify)
4451 pNotify->OnChildAdded(this);
4452
Dan Sinclair1770c022016-03-14 14:14:16 -04004453 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004454 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFX_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004455 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, index);
dsinclairc5a8f212016-06-20 11:11:12 -07004456 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004457 }
4458 return index;
4459}
weili6e1ae862016-05-04 18:25:27 -07004460
tsepezd19e9122016-11-02 15:43:18 -07004461bool CXFA_Node::InsertChild(CXFA_Node* pNode, CXFA_Node* pBeforeNode) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004462 if (!pNode || pNode->m_pParent ||
4463 (pBeforeNode && pBeforeNode->m_pParent != this)) {
Lei Zhangb45324b2017-05-22 17:05:40 -07004464 NOTREACHED();
tsepezd19e9122016-11-02 15:43:18 -07004465 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004466 }
tsepezd19e9122016-11-02 15:43:18 -07004467 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004468 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004469 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004470
4471 int32_t nIndex = -1;
4472 pNode->m_pParent = this;
weili44f8faf2016-06-01 14:03:56 -07004473 if (!m_pChild || pBeforeNode == m_pChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004474 pNode->m_pNext = m_pChild;
4475 m_pChild = pNode;
4476 nIndex = 0;
4477 } else if (!pBeforeNode) {
4478 pNode->m_pNext = m_pLastChild->m_pNext;
4479 m_pLastChild->m_pNext = pNode;
4480 } else {
4481 nIndex = 1;
4482 CXFA_Node* pPrev = m_pChild;
4483 while (pPrev->m_pNext != pBeforeNode) {
4484 pPrev = pPrev->m_pNext;
4485 nIndex++;
4486 }
4487 pNode->m_pNext = pPrev->m_pNext;
4488 pPrev->m_pNext = pNode;
4489 }
weili44f8faf2016-06-01 14:03:56 -07004490 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004491 m_pLastChild = pNode;
4492 }
4493 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004494 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004495 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004496 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004497 if (pNotify)
4498 pNotify->OnChildAdded(this);
4499
Dan Sinclair1770c022016-03-14 14:14:16 -04004500 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004501 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFX_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004502 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, nIndex);
dsinclairc5a8f212016-06-20 11:11:12 -07004503 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004504 }
tsepezd19e9122016-11-02 15:43:18 -07004505 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004506}
dsinclair5b36f0a2016-07-19 10:56:23 -07004507
Dan Sinclair1770c022016-03-14 14:14:16 -04004508CXFA_Node* CXFA_Node::Deprecated_GetPrevSibling() {
4509 if (!m_pParent) {
weili44f8faf2016-06-01 14:03:56 -07004510 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004511 }
4512 for (CXFA_Node* pSibling = m_pParent->m_pChild; pSibling;
4513 pSibling = pSibling->m_pNext) {
4514 if (pSibling->m_pNext == this) {
4515 return pSibling;
4516 }
4517 }
weili44f8faf2016-06-01 14:03:56 -07004518 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004519}
dsinclair5b36f0a2016-07-19 10:56:23 -07004520
tsepezd19e9122016-11-02 15:43:18 -07004521bool CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) {
weili44f8faf2016-06-01 14:03:56 -07004522 if (!pNode || pNode->m_pParent != this) {
Lei Zhangb45324b2017-05-22 17:05:40 -07004523 NOTREACHED();
tsepezd19e9122016-11-02 15:43:18 -07004524 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004525 }
4526 if (m_pChild == pNode) {
4527 m_pChild = pNode->m_pNext;
4528 if (m_pLastChild == pNode) {
4529 m_pLastChild = pNode->m_pNext;
4530 }
weili44f8faf2016-06-01 14:03:56 -07004531 pNode->m_pNext = nullptr;
4532 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004533 } else {
4534 CXFA_Node* pPrev = pNode->Deprecated_GetPrevSibling();
4535 pPrev->m_pNext = pNode->m_pNext;
4536 if (m_pLastChild == pNode) {
4537 m_pLastChild = pNode->m_pNext ? pNode->m_pNext : pPrev;
4538 }
weili44f8faf2016-06-01 14:03:56 -07004539 pNode->m_pNext = nullptr;
4540 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004541 }
weili44f8faf2016-06-01 14:03:56 -07004542 ASSERT(!m_pLastChild || !m_pLastChild->m_pNext);
thestigb1a59592016-04-14 18:29:56 -07004543 OnRemoved(bNotify);
dsinclairc5a8f212016-06-20 11:11:12 -07004544 pNode->SetFlag(XFA_NodeFlag_HasRemovedChildren, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004545 m_pDocument->AddPurgeNode(pNode);
4546 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
4547 if (pNode->IsAttributeInXML()) {
dsinclair43854a52016-04-27 12:26:00 -07004548 ASSERT(pNode->m_pXMLNode == m_pXMLNode &&
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004549 m_pXMLNode->GetType() == FX_XMLNODE_Element);
4550 if (pNode->m_pXMLNode->GetType() == FX_XMLNODE_Element) {
4551 CFX_XMLElement* pXMLElement =
4552 static_cast<CFX_XMLElement*>(pNode->m_pXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004553 CFX_WideStringC wsAttributeName =
4554 pNode->GetCData(XFA_ATTRIBUTE_QualifiedName);
tsepez660956f2016-04-06 06:27:29 -07004555 pXMLElement->RemoveAttribute(wsAttributeName.c_str());
Dan Sinclair1770c022016-03-14 14:14:16 -04004556 }
4557 CFX_WideString wsName;
tsepezd19e9122016-11-02 15:43:18 -07004558 pNode->GetAttribute(XFA_ATTRIBUTE_Name, wsName, false);
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004559 CFX_XMLElement* pNewXMLElement = new CFX_XMLElement(wsName);
Dan Sinclair1770c022016-03-14 14:14:16 -04004560 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
4561 if (!wsValue.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07004562 pNewXMLElement->SetTextData(CFX_WideString(wsValue));
Dan Sinclair1770c022016-03-14 14:14:16 -04004563 }
4564 pNode->m_pXMLNode = pNewXMLElement;
4565 pNode->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
4566 } else {
4567 m_pXMLNode->RemoveChildNode(pNode->m_pXMLNode);
4568 }
dsinclairc5a8f212016-06-20 11:11:12 -07004569 pNode->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004570 }
tsepezd19e9122016-11-02 15:43:18 -07004571 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004572}
dsinclair5b36f0a2016-07-19 10:56:23 -07004573
Dan Sinclair1770c022016-03-14 14:14:16 -04004574CXFA_Node* CXFA_Node::GetFirstChildByName(const CFX_WideStringC& wsName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004575 return GetFirstChildByName(FX_HashCode_GetW(wsName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004576}
dsinclair5b36f0a2016-07-19 10:56:23 -07004577
tsepez736f28a2016-03-25 14:19:51 -07004578CXFA_Node* CXFA_Node::GetFirstChildByName(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004579 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4580 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4581 if (pNode->GetNameHash() == dwNameHash) {
4582 return pNode;
4583 }
4584 }
weili44f8faf2016-06-01 14:03:56 -07004585 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004586}
dsinclair5b36f0a2016-07-19 10:56:23 -07004587
dsinclair41cb62e2016-06-23 09:20:32 -07004588CXFA_Node* CXFA_Node::GetFirstChildByClass(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004589 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4590 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004591 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004592 return pNode;
4593 }
4594 }
weili44f8faf2016-06-01 14:03:56 -07004595 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004596}
dsinclair5b36f0a2016-07-19 10:56:23 -07004597
tsepez736f28a2016-03-25 14:19:51 -07004598CXFA_Node* CXFA_Node::GetNextSameNameSibling(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004599 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4600 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4601 if (pNode->GetNameHash() == dwNameHash) {
4602 return pNode;
4603 }
4604 }
weili44f8faf2016-06-01 14:03:56 -07004605 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004606}
dsinclair5b36f0a2016-07-19 10:56:23 -07004607
Dan Sinclair1770c022016-03-14 14:14:16 -04004608CXFA_Node* CXFA_Node::GetNextSameNameSibling(
4609 const CFX_WideStringC& wsNodeName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004610 return GetNextSameNameSibling(FX_HashCode_GetW(wsNodeName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004611}
dsinclair5b36f0a2016-07-19 10:56:23 -07004612
dsinclair41cb62e2016-06-23 09:20:32 -07004613CXFA_Node* CXFA_Node::GetNextSameClassSibling(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004614 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4615 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004616 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004617 return pNode;
4618 }
4619 }
weili44f8faf2016-06-01 14:03:56 -07004620 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004621}
dsinclair5b36f0a2016-07-19 10:56:23 -07004622
Dan Sinclair1770c022016-03-14 14:14:16 -04004623int32_t CXFA_Node::GetNodeSameNameIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004624 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004625 if (!pScriptContext) {
4626 return -1;
4627 }
4628 return pScriptContext->GetIndexByName(const_cast<CXFA_Node*>(this));
4629}
dsinclair5b36f0a2016-07-19 10:56:23 -07004630
Dan Sinclair1770c022016-03-14 14:14:16 -04004631int32_t CXFA_Node::GetNodeSameClassIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004632 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004633 if (!pScriptContext) {
4634 return -1;
4635 }
4636 return pScriptContext->GetIndexByClassName(const_cast<CXFA_Node*>(this));
4637}
dsinclair5b36f0a2016-07-19 10:56:23 -07004638
Dan Sinclair1770c022016-03-14 14:14:16 -04004639void CXFA_Node::GetSOMExpression(CFX_WideString& wsSOMExpression) {
dsinclairdf4bc592016-03-31 20:34:43 -07004640 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004641 if (!pScriptContext) {
4642 return;
4643 }
4644 pScriptContext->GetSomExpression(this, wsSOMExpression);
4645}
dsinclair5b36f0a2016-07-19 10:56:23 -07004646
Dan Sinclair1770c022016-03-14 14:14:16 -04004647CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() {
weili44f8faf2016-06-01 14:03:56 -07004648 CXFA_Node* pInstanceMgr = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004649 if (m_ePacket == XFA_XDPPACKET_Form) {
4650 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07004651 if (!pParentNode || pParentNode->GetElementType() == XFA_Element::Area) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004652 return pInstanceMgr;
4653 }
4654 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
4655 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004656 XFA_Element eType = pNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07004657 if ((eType == XFA_Element::Subform || eType == XFA_Element::SubformSet) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004658 pNode->m_dwNameHash != m_dwNameHash) {
4659 break;
4660 }
dsinclair56a8b192016-06-21 14:15:25 -07004661 if (eType == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004662 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
4663 CFX_WideStringC wsInstName = pNode->GetCData(XFA_ATTRIBUTE_Name);
4664 if (wsInstName.GetLength() > 0 && wsInstName.GetAt(0) == '_' &&
4665 wsInstName.Mid(1) == wsName) {
4666 pInstanceMgr = pNode;
4667 }
4668 break;
4669 }
4670 }
4671 }
4672 return pInstanceMgr;
4673}
dsinclair5b36f0a2016-07-19 10:56:23 -07004674
Dan Sinclair1770c022016-03-14 14:14:16 -04004675CXFA_Node* CXFA_Node::GetOccurNode() {
dsinclair56a8b192016-06-21 14:15:25 -07004676 return GetFirstChildByClass(XFA_Element::Occur);
Dan Sinclair1770c022016-03-14 14:14:16 -04004677}
dsinclair5b36f0a2016-07-19 10:56:23 -07004678
dsinclairc5a8f212016-06-20 11:11:12 -07004679bool CXFA_Node::HasFlag(XFA_NodeFlag dwFlag) const {
4680 if (m_uNodeFlags & dwFlag)
4681 return true;
4682 if (dwFlag == XFA_NodeFlag_HasRemovedChildren)
4683 return m_pParent && m_pParent->HasFlag(dwFlag);
4684 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004685}
thestigb1a59592016-04-14 18:29:56 -07004686
4687void CXFA_Node::SetFlag(uint32_t dwFlag, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004688 if (dwFlag == XFA_NodeFlag_Initialized && bNotify && !IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004689 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004690 if (pNotify) {
4691 pNotify->OnNodeReady(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04004692 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004693 }
dsinclairc5a8f212016-06-20 11:11:12 -07004694 m_uNodeFlags |= dwFlag;
Dan Sinclair1770c022016-03-14 14:14:16 -04004695}
thestigb1a59592016-04-14 18:29:56 -07004696
4697void CXFA_Node::ClearFlag(uint32_t dwFlag) {
dsinclairc5a8f212016-06-20 11:11:12 -07004698 m_uNodeFlags &= ~dwFlag;
thestigb1a59592016-04-14 18:29:56 -07004699}
4700
tsepezd19e9122016-11-02 15:43:18 -07004701bool CXFA_Node::IsAttributeInXML() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004702 return GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData;
4703}
thestigb1a59592016-04-14 18:29:56 -07004704
4705void CXFA_Node::OnRemoved(bool bNotify) {
4706 if (!bNotify)
4707 return;
4708
dsinclaira1b07722016-07-11 08:20:58 -07004709 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004710 if (pNotify)
4711 pNotify->OnChildRemoved();
Dan Sinclair1770c022016-03-14 14:14:16 -04004712}
thestigb1a59592016-04-14 18:29:56 -07004713
4714void CXFA_Node::OnChanging(XFA_ATTRIBUTE eAttr, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004715 if (bNotify && IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004716 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004717 if (pNotify) {
thestigb1a59592016-04-14 18:29:56 -07004718 pNotify->OnValueChanging(this, eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004719 }
4720 }
4721}
thestigb1a59592016-04-14 18:29:56 -07004722
Dan Sinclair1770c022016-03-14 14:14:16 -04004723void CXFA_Node::OnChanged(XFA_ATTRIBUTE eAttr,
thestigb1a59592016-04-14 18:29:56 -07004724 bool bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004725 bool bScriptModify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004726 if (bNotify && IsInitialized()) {
thestigb1a59592016-04-14 18:29:56 -07004727 Script_Attribute_SendAttributeChangeMessage(eAttr, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04004728 }
4729}
thestigb1a59592016-04-14 18:29:56 -07004730
Dan Sinclair1770c022016-03-14 14:14:16 -04004731int32_t CXFA_Node::execSingleEventByName(const CFX_WideStringC& wsEventName,
dsinclair41cb62e2016-06-23 09:20:32 -07004732 XFA_Element eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004733 int32_t iRet = XFA_EVENTERROR_NotExist;
4734 const XFA_ExecEventParaInfo* eventParaInfo =
4735 GetEventParaInfoByName(wsEventName);
4736 if (eventParaInfo) {
4737 uint32_t validFlags = eventParaInfo->m_validFlags;
dsinclaira1b07722016-07-11 08:20:58 -07004738 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004739 if (!pNotify) {
4740 return iRet;
4741 }
4742 if (validFlags == 1) {
4743 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType);
4744 } else if (validFlags == 2) {
4745 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004746 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004747 } else if (validFlags == 3) {
dsinclair41cb62e2016-06-23 09:20:32 -07004748 if (eType == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004749 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004750 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004751 }
4752 } else if (validFlags == 4) {
dsinclair41cb62e2016-06-23 09:20:32 -07004753 if (eType == XFA_Element::ExclGroup || eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004754 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair56a8b192016-06-21 14:15:25 -07004755 if (pParentNode &&
dsinclair070fcdf2016-06-22 22:04:54 -07004756 pParentNode->GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004757 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004758 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004759 }
4760 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004761 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004762 }
4763 } else if (validFlags == 5) {
dsinclair41cb62e2016-06-23 09:20:32 -07004764 if (eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004765 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004766 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004767 }
4768 } else if (validFlags == 6) {
4769 CXFA_WidgetData* pWidgetData = GetWidgetData();
4770 if (pWidgetData) {
4771 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004772 if (pUINode->m_elementType == XFA_Element::Signature) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004773 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004774 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004775 }
4776 }
4777 } else if (validFlags == 7) {
4778 CXFA_WidgetData* pWidgetData = GetWidgetData();
4779 if (pWidgetData) {
4780 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004781 if ((pUINode->m_elementType == XFA_Element::ChoiceList) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004782 (!pWidgetData->IsListBox())) {
4783 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004784 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004785 }
4786 }
4787 }
4788 }
4789 return iRet;
4790}
dsinclair5b36f0a2016-07-19 10:56:23 -07004791
Dan Sinclair1770c022016-03-14 14:14:16 -04004792void CXFA_Node::UpdateNameHash() {
4793 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07004794 XFA_GetNotsureAttribute(GetElementType(), XFA_ATTRIBUTE_Name);
tsepezb6853cf2016-04-25 11:23:43 -07004795 CFX_WideStringC wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04004796 if (!pNotsure || pNotsure->eType == XFA_ATTRIBUTETYPE_Cdata) {
tsepezb6853cf2016-04-25 11:23:43 -07004797 wsName = GetCData(XFA_ATTRIBUTE_Name);
4798 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004799 } else if (pNotsure->eType == XFA_ATTRIBUTETYPE_Enum) {
dsinclair9eb0db12016-07-21 12:01:39 -07004800 wsName = GetAttributeEnumByID(GetEnum(XFA_ATTRIBUTE_Name))->pName;
tsepezb6853cf2016-04-25 11:23:43 -07004801 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004802 }
4803}
dsinclair5b36f0a2016-07-19 10:56:23 -07004804
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004805CFX_XMLNode* CXFA_Node::CreateXMLMappingNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004806 if (!m_pXMLNode) {
tsepezafe94302016-05-13 17:21:31 -07004807 CFX_WideString wsTag(GetCData(XFA_ATTRIBUTE_Name));
Dan Sinclair0d86ecb2017-04-19 09:19:57 -04004808 m_pXMLNode = new CFX_XMLElement(wsTag);
dsinclairc5a8f212016-06-20 11:11:12 -07004809 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004810 }
4811 return m_pXMLNode;
4812}
dsinclair5b36f0a2016-07-19 10:56:23 -07004813
tsepezd19e9122016-11-02 15:43:18 -07004814bool CXFA_Node::IsNeedSavingXMLNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004815 return m_pXMLNode && (GetPacketID() == XFA_XDPPACKET_Datasets ||
dsinclair070fcdf2016-06-22 22:04:54 -07004816 GetElementType() == XFA_Element::Xfa);
Dan Sinclair1770c022016-03-14 14:14:16 -04004817}
4818
4819XFA_MAPMODULEDATA* CXFA_Node::CreateMapModuleData() {
4820 if (!m_pMapModuleData)
4821 m_pMapModuleData = new XFA_MAPMODULEDATA;
4822 return m_pMapModuleData;
4823}
4824
4825XFA_MAPMODULEDATA* CXFA_Node::GetMapModuleData() const {
4826 return m_pMapModuleData;
4827}
4828
4829void CXFA_Node::SetMapModuleValue(void* pKey, void* pValue) {
4830 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004831 pModule->m_ValueMap[pKey] = pValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04004832}
4833
tsepezd19e9122016-11-02 15:43:18 -07004834bool CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) {
tsepez6bb3b892017-01-05 12:18:41 -08004835 for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004836 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004837 if (pModule) {
4838 auto it = pModule->m_ValueMap.find(pKey);
4839 if (it != pModule->m_ValueMap.end()) {
4840 pValue = it->second;
4841 return true;
4842 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004843 }
tsepez6bb3b892017-01-05 12:18:41 -08004844 if (pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4845 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004846 }
tsepezd19e9122016-11-02 15:43:18 -07004847 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004848}
dsinclair5b36f0a2016-07-19 10:56:23 -07004849
Dan Sinclair1770c022016-03-14 14:14:16 -04004850void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) {
tsepez660956f2016-04-06 06:27:29 -07004851 SetMapModuleBuffer(pKey, (void*)wsValue.c_str(),
Dan Sinclair812e96c2017-03-13 16:43:37 -04004852 wsValue.GetLength() * sizeof(wchar_t));
Dan Sinclair1770c022016-03-14 14:14:16 -04004853}
dsinclair5b36f0a2016-07-19 10:56:23 -07004854
tsepezd19e9122016-11-02 15:43:18 -07004855bool CXFA_Node::GetMapModuleString(void* pKey, CFX_WideStringC& wsValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004856 void* pValue;
4857 int32_t iBytes;
Tom Sepez92c13a72017-05-19 10:43:06 -07004858 if (!GetMapModuleBuffer(pKey, pValue, iBytes))
tsepezd19e9122016-11-02 15:43:18 -07004859 return false;
Tom Sepez92c13a72017-05-19 10:43:06 -07004860 // Defensive measure: no out-of-bounds pointers even if zero length.
4861 int32_t iChars = iBytes / sizeof(wchar_t);
4862 wsValue = CFX_WideStringC(iChars ? (const wchar_t*)pValue : nullptr, iChars);
tsepezd19e9122016-11-02 15:43:18 -07004863 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004864}
dsinclair5b36f0a2016-07-19 10:56:23 -07004865
Dan Sinclair1770c022016-03-14 14:14:16 -04004866void CXFA_Node::SetMapModuleBuffer(
4867 void* pKey,
4868 void* pValue,
4869 int32_t iBytes,
4870 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
4871 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
4872 XFA_MAPDATABLOCK*& pBuffer = pModule->m_BufferMap[pKey];
weili44f8faf2016-06-01 14:03:56 -07004873 if (!pBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004874 pBuffer =
4875 (XFA_MAPDATABLOCK*)FX_Alloc(uint8_t, sizeof(XFA_MAPDATABLOCK) + iBytes);
4876 } else if (pBuffer->iBytes != iBytes) {
4877 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4878 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4879 }
4880 pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(uint8_t, pBuffer,
4881 sizeof(XFA_MAPDATABLOCK) + iBytes);
4882 } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4883 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4884 }
weili44f8faf2016-06-01 14:03:56 -07004885 if (!pBuffer)
Dan Sinclair1770c022016-03-14 14:14:16 -04004886 return;
weili44f8faf2016-06-01 14:03:56 -07004887
Dan Sinclair1770c022016-03-14 14:14:16 -04004888 pBuffer->pCallbackInfo = pCallbackInfo;
4889 pBuffer->iBytes = iBytes;
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04004890 memcpy(pBuffer->GetData(), pValue, iBytes);
Dan Sinclair1770c022016-03-14 14:14:16 -04004891}
dsinclair5b36f0a2016-07-19 10:56:23 -07004892
tsepezd19e9122016-11-02 15:43:18 -07004893bool CXFA_Node::GetMapModuleBuffer(void* pKey,
4894 void*& pValue,
4895 int32_t& iBytes,
4896 bool bProtoAlso) const {
weili44f8faf2016-06-01 14:03:56 -07004897 XFA_MAPDATABLOCK* pBuffer = nullptr;
tsepez6bb3b892017-01-05 12:18:41 -08004898 for (const CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004899 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004900 if (pModule) {
4901 auto it = pModule->m_BufferMap.find(pKey);
4902 if (it != pModule->m_BufferMap.end()) {
4903 pBuffer = it->second;
4904 break;
4905 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004906 }
tsepez6bb3b892017-01-05 12:18:41 -08004907 if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4908 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004909 }
tsepez6bb3b892017-01-05 12:18:41 -08004910 if (!pBuffer)
tsepezd19e9122016-11-02 15:43:18 -07004911 return false;
tsepez6bb3b892017-01-05 12:18:41 -08004912
Dan Sinclair1770c022016-03-14 14:14:16 -04004913 pValue = pBuffer->GetData();
4914 iBytes = pBuffer->iBytes;
tsepezd19e9122016-11-02 15:43:18 -07004915 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004916}
dsinclair5b36f0a2016-07-19 10:56:23 -07004917
tsepezd19e9122016-11-02 15:43:18 -07004918bool CXFA_Node::HasMapModuleKey(void* pKey, bool bProtoAlso) {
tsepez6bb3b892017-01-05 12:18:41 -08004919 for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004920 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004921 if (pModule) {
4922 auto it1 = pModule->m_ValueMap.find(pKey);
4923 if (it1 != pModule->m_ValueMap.end())
4924 return true;
4925
4926 auto it2 = pModule->m_BufferMap.find(pKey);
4927 if (it2 != pModule->m_BufferMap.end())
4928 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004929 }
tsepez6bb3b892017-01-05 12:18:41 -08004930 if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4931 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004932 }
tsepezd19e9122016-11-02 15:43:18 -07004933 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004934}
dsinclair5b36f0a2016-07-19 10:56:23 -07004935
Dan Sinclair1770c022016-03-14 14:14:16 -04004936void CXFA_Node::RemoveMapModuleKey(void* pKey) {
4937 XFA_MAPMODULEDATA* pModule = GetMapModuleData();
4938 if (!pModule)
4939 return;
4940
4941 if (pKey) {
tsepez6bb3b892017-01-05 12:18:41 -08004942 auto it = pModule->m_BufferMap.find(pKey);
4943 if (it != pModule->m_BufferMap.end()) {
4944 XFA_MAPDATABLOCK* pBuffer = it->second;
Dan Sinclair1770c022016-03-14 14:14:16 -04004945 if (pBuffer) {
tsepez6bb3b892017-01-05 12:18:41 -08004946 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree)
Dan Sinclair1770c022016-03-14 14:14:16 -04004947 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04004948 FX_Free(pBuffer);
4949 }
tsepez6bb3b892017-01-05 12:18:41 -08004950 pModule->m_BufferMap.erase(it);
Dan Sinclair1770c022016-03-14 14:14:16 -04004951 }
tsepez6bb3b892017-01-05 12:18:41 -08004952 pModule->m_ValueMap.erase(pKey);
4953 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04004954 }
tsepez6bb3b892017-01-05 12:18:41 -08004955
4956 for (auto& pair : pModule->m_BufferMap) {
4957 XFA_MAPDATABLOCK* pBuffer = pair.second;
4958 if (pBuffer) {
4959 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree)
4960 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4961 FX_Free(pBuffer);
4962 }
4963 }
4964 pModule->m_BufferMap.clear();
4965 pModule->m_ValueMap.clear();
4966 delete pModule;
Dan Sinclair1770c022016-03-14 14:14:16 -04004967}
dsinclair5b36f0a2016-07-19 10:56:23 -07004968
tsepez6bb3b892017-01-05 12:18:41 -08004969void CXFA_Node::MergeAllData(void* pDstModule) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004970 XFA_MAPMODULEDATA* pDstModuleData =
4971 static_cast<CXFA_Node*>(pDstModule)->CreateMapModuleData();
4972 XFA_MAPMODULEDATA* pSrcModuleData = GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004973 if (!pSrcModuleData)
Dan Sinclair1770c022016-03-14 14:14:16 -04004974 return;
tsepez6bb3b892017-01-05 12:18:41 -08004975
4976 for (const auto& pair : pSrcModuleData->m_ValueMap)
4977 pDstModuleData->m_ValueMap[pair.first] = pair.second;
4978
4979 for (const auto& pair : pSrcModuleData->m_BufferMap) {
4980 XFA_MAPDATABLOCK* pSrcBuffer = pair.second;
4981 XFA_MAPDATABLOCK*& pDstBuffer = pDstModuleData->m_BufferMap[pair.first];
Dan Sinclair1770c022016-03-14 14:14:16 -04004982 if (pSrcBuffer->pCallbackInfo && pSrcBuffer->pCallbackInfo->pFree &&
4983 !pSrcBuffer->pCallbackInfo->pCopy) {
tsepez6bb3b892017-01-05 12:18:41 -08004984 if (pDstBuffer) {
4985 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
4986 pDstModuleData->m_BufferMap.erase(pair.first);
Dan Sinclair1770c022016-03-14 14:14:16 -04004987 }
4988 continue;
4989 }
tsepez6bb3b892017-01-05 12:18:41 -08004990 if (!pDstBuffer) {
4991 pDstBuffer = (XFA_MAPDATABLOCK*)FX_Alloc(
Dan Sinclair1770c022016-03-14 14:14:16 -04004992 uint8_t, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
tsepez6bb3b892017-01-05 12:18:41 -08004993 } else if (pDstBuffer->iBytes != pSrcBuffer->iBytes) {
4994 if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) {
4995 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04004996 }
tsepez6bb3b892017-01-05 12:18:41 -08004997 pDstBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(
4998 uint8_t, pDstBuffer, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
4999 } else if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) {
5000 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005001 }
tsepez6bb3b892017-01-05 12:18:41 -08005002 if (!pDstBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005003 continue;
5004 }
tsepez6bb3b892017-01-05 12:18:41 -08005005 pDstBuffer->pCallbackInfo = pSrcBuffer->pCallbackInfo;
5006 pDstBuffer->iBytes = pSrcBuffer->iBytes;
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04005007 memcpy(pDstBuffer->GetData(), pSrcBuffer->GetData(), pSrcBuffer->iBytes);
tsepez6bb3b892017-01-05 12:18:41 -08005008 if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pCopy) {
5009 pDstBuffer->pCallbackInfo->pCopy(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005010 }
5011 }
5012}
dsinclair5b36f0a2016-07-19 10:56:23 -07005013
Dan Sinclair1770c022016-03-14 14:14:16 -04005014void CXFA_Node::MoveBufferMapData(CXFA_Node* pDstModule, void* pKey) {
5015 if (!pDstModule) {
5016 return;
5017 }
tsepezd19e9122016-11-02 15:43:18 -07005018 bool bNeedMove = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04005019 if (!pKey) {
tsepezd19e9122016-11-02 15:43:18 -07005020 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005021 }
dsinclair070fcdf2016-06-22 22:04:54 -07005022 if (pDstModule->GetElementType() != GetElementType()) {
tsepezd19e9122016-11-02 15:43:18 -07005023 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005024 }
weili44f8faf2016-06-01 14:03:56 -07005025 XFA_MAPMODULEDATA* pSrcModuleData = nullptr;
5026 XFA_MAPMODULEDATA* pDstModuleData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005027 if (bNeedMove) {
5028 pSrcModuleData = GetMapModuleData();
5029 if (!pSrcModuleData) {
tsepezd19e9122016-11-02 15:43:18 -07005030 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005031 }
5032 pDstModuleData = pDstModule->CreateMapModuleData();
5033 }
5034 if (bNeedMove) {
tsepez6bb3b892017-01-05 12:18:41 -08005035 auto it = pSrcModuleData->m_BufferMap.find(pKey);
5036 if (it != pSrcModuleData->m_BufferMap.end()) {
5037 XFA_MAPDATABLOCK* pBufferBlockData = it->second;
5038 if (pBufferBlockData) {
5039 pSrcModuleData->m_BufferMap.erase(pKey);
5040 pDstModuleData->m_BufferMap[pKey] = pBufferBlockData;
5041 }
Dan Sinclair1770c022016-03-14 14:14:16 -04005042 }
5043 }
dsinclairc5a8f212016-06-20 11:11:12 -07005044 if (pDstModule->IsNodeV()) {
tsepezd19e9122016-11-02 15:43:18 -07005045 CFX_WideString wsValue = pDstModule->GetScriptContent(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04005046 CFX_WideString wsFormatValue(wsValue);
5047 CXFA_WidgetData* pWidgetData = pDstModule->GetContainerWidgetData();
5048 if (pWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07005049 pWidgetData->GetFormatDataValue(wsValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04005050 }
tsepezd19e9122016-11-02 15:43:18 -07005051 pDstModule->SetScriptContent(wsValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005052 }
5053}
dsinclair5b36f0a2016-07-19 10:56:23 -07005054
Dan Sinclair1770c022016-03-14 14:14:16 -04005055void CXFA_Node::MoveBufferMapData(CXFA_Node* pSrcModule,
5056 CXFA_Node* pDstModule,
5057 void* pKey,
tsepezd19e9122016-11-02 15:43:18 -07005058 bool bRecursive) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005059 if (!pSrcModule || !pDstModule || !pKey) {
5060 return;
5061 }
5062 if (bRecursive) {
5063 CXFA_Node* pSrcChild = pSrcModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5064 CXFA_Node* pDstChild = pDstModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5065 for (; pSrcChild && pDstChild;
5066 pSrcChild = pSrcChild->GetNodeItem(XFA_NODEITEM_NextSibling),
5067 pDstChild = pDstChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
tsepezd19e9122016-11-02 15:43:18 -07005068 MoveBufferMapData(pSrcChild, pDstChild, pKey, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005069 }
5070 }
5071 pSrcModule->MoveBufferMapData(pDstModule, pKey);
5072}
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05005073
5074void CXFA_Node::ThrowMissingPropertyException(
5075 const CFX_WideString& obj,
5076 const CFX_WideString& prop) const {
5077 ThrowException(L"'%s' doesn't have property '%s'.", obj.c_str(),
5078 prop.c_str());
5079}
5080
5081void CXFA_Node::ThrowTooManyOccurancesException(
5082 const CFX_WideString& obj) const {
5083 ThrowException(
5084 L"The element [%s] has violated its allowable number of occurrences.",
5085 obj.c_str());
5086}