blob: 2828c983433a3fecb5629a124cc55f12805fad77 [file] [log] [blame]
dsinclair5b36f0a2016-07-19 10:56:23 -07001// Copyright 2016 PDFium Authors. All rights reserved.
Dan Sinclair1770c022016-03-14 14:14:16 -04002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Dan Sinclairefcae5d2017-03-29 14:47:46 -04007#include "xfa/fxfa/parser/cxfa_node.h"
Dan Sinclair1770c022016-03-14 14:14:16 -04008
dsinclair5b36f0a2016-07-19 10:56:23 -07009#include <map>
tsepezaadedf92016-05-12 10:08:06 -070010#include <memory>
Tom Sepezd4db58f2017-03-02 14:57:59 -080011#include <unordered_set>
Dan Sinclair85c8e7f2016-11-21 13:50:32 -050012#include <utility>
tsepez51709be2016-12-08 10:55:57 -080013#include <vector>
tsepezaadedf92016-05-12 10:08:06 -070014
Dan Sinclairb929ab02017-03-29 15:18:16 -040015#include "core/fxcrt/cfx_decimal.h"
dsinclaira52ab742016-09-29 13:59:29 -070016#include "core/fxcrt/fx_ext.h"
dsinclair43554682016-09-29 17:29:48 -070017#include "fxjs/cfxjse_value.h"
tsepeza9caab92016-12-14 05:57:10 -080018#include "third_party/base/ptr_util.h"
tsepezaadedf92016-05-12 10:08:06 -070019#include "third_party/base/stl_util.h"
dsinclairae95f762016-03-29 16:58:29 -070020#include "xfa/fde/xml/fde_xml_imp.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040021#include "xfa/fgas/crt/fgas_codepage.h"
dsinclairdf4bc592016-03-31 20:34:43 -070022#include "xfa/fxfa/app/xfa_ffnotify.h"
dsinclair5b493092016-09-29 20:20:24 -070023#include "xfa/fxfa/cxfa_eventparam.h"
Dan Sinclairefcae5d2017-03-29 14:47:46 -040024#include "xfa/fxfa/cxfa_ffwidget.h"
25#include "xfa/fxfa/parser/cxfa_arraynodelist.h"
26#include "xfa/fxfa/parser/cxfa_attachnodelist.h"
dsinclair16280242016-07-21 12:03:47 -070027#include "xfa/fxfa/parser/cxfa_document.h"
dsinclair0b851ff2016-07-21 12:03:01 -070028#include "xfa/fxfa/parser/cxfa_layoutprocessor.h"
dsinclair9eb0db12016-07-21 12:01:39 -070029#include "xfa/fxfa/parser/cxfa_measurement.h"
dsinclair44d054c2016-04-06 10:23:46 -070030#include "xfa/fxfa/parser/cxfa_occur.h"
dsinclair31f87402016-07-20 06:34:45 -070031#include "xfa/fxfa/parser/cxfa_scriptcontext.h"
dsinclair34f86b02016-07-11 08:42:33 -070032#include "xfa/fxfa/parser/cxfa_simple_parser.h"
Dan Sinclairefcae5d2017-03-29 14:47:46 -040033#include "xfa/fxfa/parser/cxfa_traversestrategy_xfacontainernode.h"
dsinclair5b36f0a2016-07-19 10:56:23 -070034#include "xfa/fxfa/parser/xfa_basic_data.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040035
weili44f8faf2016-06-01 14:03:56 -070036namespace {
37
38void XFA_DeleteWideString(void* pData) {
39 delete static_cast<CFX_WideString*>(pData);
40}
41
42void XFA_CopyWideString(void*& pData) {
43 if (pData) {
44 CFX_WideString* pNewData = new CFX_WideString(*(CFX_WideString*)pData);
45 pData = pNewData;
46 }
47}
48
49XFA_MAPDATABLOCKCALLBACKINFO deleteWideStringCallBack = {XFA_DeleteWideString,
50 XFA_CopyWideString};
51
weili44f8faf2016-06-01 14:03:56 -070052void XFA_DataNodeDeleteBindItem(void* pData) {
Tom Sepezf8a94392017-03-14 12:13:22 -070053 delete static_cast<std::vector<CXFA_Node*>*>(pData);
weili44f8faf2016-06-01 14:03:56 -070054}
55
56XFA_MAPDATABLOCKCALLBACKINFO deleteBindItemCallBack = {
57 XFA_DataNodeDeleteBindItem, nullptr};
58
dsinclair5b36f0a2016-07-19 10:56:23 -070059int32_t GetCount(CXFA_Node* pInstMgrNode) {
60 ASSERT(pInstMgrNode);
61 int32_t iCount = 0;
62 uint32_t dwNameHash = 0;
63 for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
64 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
65 XFA_Element eCurType = pNode->GetElementType();
66 if (eCurType == XFA_Element::InstanceManager)
67 break;
68 if ((eCurType != XFA_Element::Subform) &&
69 (eCurType != XFA_Element::SubformSet)) {
70 continue;
71 }
72 if (iCount == 0) {
73 CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
74 CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
75 if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
76 wsInstName.Mid(1) != wsName) {
77 return iCount;
78 }
79 dwNameHash = pNode->GetNameHash();
80 }
81 if (dwNameHash != pNode->GetNameHash())
82 break;
weili44f8faf2016-06-01 14:03:56 -070083
dsinclair5b36f0a2016-07-19 10:56:23 -070084 iCount++;
85 }
86 return iCount;
Dan Sinclair1770c022016-03-14 14:14:16 -040087}
weili44f8faf2016-06-01 14:03:56 -070088
Tom Sepez7cdc6602017-03-28 09:56:48 -070089std::vector<CXFA_Node*> NodesSortedByDocumentIdx(
90 const std::unordered_set<CXFA_Node*>& rgNodeSet) {
91 if (rgNodeSet.empty())
92 return std::vector<CXFA_Node*>();
weili44f8faf2016-06-01 14:03:56 -070093
Tom Sepez7cdc6602017-03-28 09:56:48 -070094 std::vector<CXFA_Node*> rgNodeArray;
dsinclair5b36f0a2016-07-19 10:56:23 -070095 CXFA_Node* pCommonParent =
96 (*rgNodeSet.begin())->GetNodeItem(XFA_NODEITEM_Parent);
97 for (CXFA_Node* pNode = pCommonParent->GetNodeItem(XFA_NODEITEM_FirstChild);
Tom Sepez7cdc6602017-03-28 09:56:48 -070098 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
99 if (pdfium::ContainsValue(rgNodeSet, pNode))
100 rgNodeArray.push_back(pNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400101 }
Tom Sepez7cdc6602017-03-28 09:56:48 -0700102 return rgNodeArray;
Dan Sinclair1770c022016-03-14 14:14:16 -0400103}
weili44f8faf2016-06-01 14:03:56 -0700104
Tom Sepezd4db58f2017-03-02 14:57:59 -0800105using CXFA_NodeSetPair =
106 std::pair<std::unordered_set<CXFA_Node*>, std::unordered_set<CXFA_Node*>>;
dsinclair5b36f0a2016-07-19 10:56:23 -0700107using CXFA_NodeSetPairMap =
108 std::map<uint32_t, std::unique_ptr<CXFA_NodeSetPair>>;
109using CXFA_NodeSetPairMapMap =
110 std::map<CXFA_Node*, std::unique_ptr<CXFA_NodeSetPairMap>>;
111
112CXFA_NodeSetPair* NodeSetPairForNode(CXFA_Node* pNode,
113 CXFA_NodeSetPairMapMap* pMap) {
114 CXFA_Node* pParentNode = pNode->GetNodeItem(XFA_NODEITEM_Parent);
115 uint32_t dwNameHash = pNode->GetNameHash();
116 if (!pParentNode || !dwNameHash)
117 return nullptr;
118
119 if (!(*pMap)[pParentNode])
tsepeza9caab92016-12-14 05:57:10 -0800120 (*pMap)[pParentNode] = pdfium::MakeUnique<CXFA_NodeSetPairMap>();
dsinclair5b36f0a2016-07-19 10:56:23 -0700121
122 CXFA_NodeSetPairMap* pNodeSetPairMap = (*pMap)[pParentNode].get();
123 if (!(*pNodeSetPairMap)[dwNameHash])
tsepeza9caab92016-12-14 05:57:10 -0800124 (*pNodeSetPairMap)[dwNameHash] = pdfium::MakeUnique<CXFA_NodeSetPair>();
dsinclair5b36f0a2016-07-19 10:56:23 -0700125
126 return (*pNodeSetPairMap)[dwNameHash].get();
Dan Sinclair1770c022016-03-14 14:14:16 -0400127}
128
Tom Sepezd4db58f2017-03-02 14:57:59 -0800129void ReorderDataNodes(const std::unordered_set<CXFA_Node*>& sSet1,
130 const std::unordered_set<CXFA_Node*>& sSet2,
tsepezd19e9122016-11-02 15:43:18 -0700131 bool bInsertBefore) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700132 CXFA_NodeSetPairMapMap rgMap;
133 for (CXFA_Node* pNode : sSet1) {
134 CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap);
135 if (pNodeSetPair)
136 pNodeSetPair->first.insert(pNode);
137 }
138 for (CXFA_Node* pNode : sSet2) {
139 CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap);
140 if (pNodeSetPair) {
141 if (pdfium::ContainsValue(pNodeSetPair->first, pNode))
142 pNodeSetPair->first.erase(pNode);
143 else
144 pNodeSetPair->second.insert(pNode);
145 }
146 }
147 for (const auto& iter1 : rgMap) {
148 CXFA_NodeSetPairMap* pNodeSetPairMap = iter1.second.get();
149 if (!pNodeSetPairMap)
150 continue;
151
152 for (const auto& iter2 : *pNodeSetPairMap) {
153 CXFA_NodeSetPair* pNodeSetPair = iter2.second.get();
154 if (!pNodeSetPair)
155 continue;
156 if (!pNodeSetPair->first.empty() && !pNodeSetPair->second.empty()) {
Tom Sepez7cdc6602017-03-28 09:56:48 -0700157 std::vector<CXFA_Node*> rgNodeArray1 =
158 NodesSortedByDocumentIdx(pNodeSetPair->first);
159 std::vector<CXFA_Node*> rgNodeArray2 =
160 NodesSortedByDocumentIdx(pNodeSetPair->second);
dsinclair5b36f0a2016-07-19 10:56:23 -0700161 CXFA_Node* pParentNode = nullptr;
162 CXFA_Node* pBeforeNode = nullptr;
163 if (bInsertBefore) {
Tom Sepez7cdc6602017-03-28 09:56:48 -0700164 pBeforeNode = rgNodeArray2.front();
dsinclair5b36f0a2016-07-19 10:56:23 -0700165 pParentNode = pBeforeNode->GetNodeItem(XFA_NODEITEM_Parent);
166 } else {
Tom Sepez7cdc6602017-03-28 09:56:48 -0700167 CXFA_Node* pLastNode = rgNodeArray2.back();
dsinclair5b36f0a2016-07-19 10:56:23 -0700168 pParentNode = pLastNode->GetNodeItem(XFA_NODEITEM_Parent);
169 pBeforeNode = pLastNode->GetNodeItem(XFA_NODEITEM_NextSibling);
170 }
Tom Sepez7cdc6602017-03-28 09:56:48 -0700171 for (auto* pCurNode : rgNodeArray1) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700172 pParentNode->RemoveChild(pCurNode);
173 pParentNode->InsertChild(pCurNode, pBeforeNode);
174 }
175 }
176 }
177 pNodeSetPairMap->clear();
178 }
179}
180
181CXFA_Node* GetItem(CXFA_Node* pInstMgrNode, int32_t iIndex) {
182 ASSERT(pInstMgrNode);
183 int32_t iCount = 0;
184 uint32_t dwNameHash = 0;
185 for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
186 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
187 XFA_Element eCurType = pNode->GetElementType();
188 if (eCurType == XFA_Element::InstanceManager)
189 break;
190 if ((eCurType != XFA_Element::Subform) &&
191 (eCurType != XFA_Element::SubformSet)) {
192 continue;
193 }
194 if (iCount == 0) {
195 CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
196 CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
197 if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
198 wsInstName.Mid(1) != wsName) {
199 return nullptr;
200 }
201 dwNameHash = pNode->GetNameHash();
202 }
203 if (dwNameHash != pNode->GetNameHash())
204 break;
205
206 iCount++;
207 if (iCount > iIndex)
208 return pNode;
209 }
210 return nullptr;
211}
212
213void InsertItem(CXFA_Node* pInstMgrNode,
214 CXFA_Node* pNewInstance,
215 int32_t iPos,
216 int32_t iCount = -1,
tsepezd19e9122016-11-02 15:43:18 -0700217 bool bMoveDataBindingNodes = true) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700218 if (iCount < 0)
219 iCount = GetCount(pInstMgrNode);
220 if (iPos < 0)
221 iPos = iCount;
222 if (iPos == iCount) {
223 CXFA_Node* pNextSibling =
224 iCount > 0
225 ? GetItem(pInstMgrNode, iCount - 1)
226 ->GetNodeItem(XFA_NODEITEM_NextSibling)
227 : pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
228 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)
229 ->InsertChild(pNewInstance, pNextSibling);
230 if (bMoveDataBindingNodes) {
Tom Sepezd4db58f2017-03-02 14:57:59 -0800231 std::unordered_set<CXFA_Node*> sNew;
232 std::unordered_set<CXFA_Node*> sAfter;
dsinclair5b36f0a2016-07-19 10:56:23 -0700233 CXFA_NodeIteratorTemplate<CXFA_Node,
234 CXFA_TraverseStrategy_XFAContainerNode>
235 sIteratorNew(pNewInstance);
236 for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode;
237 pNode = sIteratorNew.MoveToNext()) {
238 CXFA_Node* pDataNode = pNode->GetBindData();
239 if (!pDataNode)
240 continue;
241
242 sNew.insert(pDataNode);
243 }
244 CXFA_NodeIteratorTemplate<CXFA_Node,
245 CXFA_TraverseStrategy_XFAContainerNode>
246 sIteratorAfter(pNextSibling);
247 for (CXFA_Node* pNode = sIteratorAfter.GetCurrent(); pNode;
248 pNode = sIteratorAfter.MoveToNext()) {
249 CXFA_Node* pDataNode = pNode->GetBindData();
250 if (!pDataNode)
251 continue;
252
253 sAfter.insert(pDataNode);
254 }
tsepezd19e9122016-11-02 15:43:18 -0700255 ReorderDataNodes(sNew, sAfter, false);
dsinclair5b36f0a2016-07-19 10:56:23 -0700256 }
257 } else {
258 CXFA_Node* pBeforeInstance = GetItem(pInstMgrNode, iPos);
259 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)
260 ->InsertChild(pNewInstance, pBeforeInstance);
261 if (bMoveDataBindingNodes) {
Tom Sepezd4db58f2017-03-02 14:57:59 -0800262 std::unordered_set<CXFA_Node*> sNew;
263 std::unordered_set<CXFA_Node*> sBefore;
dsinclair5b36f0a2016-07-19 10:56:23 -0700264 CXFA_NodeIteratorTemplate<CXFA_Node,
265 CXFA_TraverseStrategy_XFAContainerNode>
266 sIteratorNew(pNewInstance);
267 for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode;
268 pNode = sIteratorNew.MoveToNext()) {
269 CXFA_Node* pDataNode = pNode->GetBindData();
270 if (!pDataNode)
271 continue;
272
273 sNew.insert(pDataNode);
274 }
275 CXFA_NodeIteratorTemplate<CXFA_Node,
276 CXFA_TraverseStrategy_XFAContainerNode>
277 sIteratorBefore(pBeforeInstance);
278 for (CXFA_Node* pNode = sIteratorBefore.GetCurrent(); pNode;
279 pNode = sIteratorBefore.MoveToNext()) {
280 CXFA_Node* pDataNode = pNode->GetBindData();
281 if (!pDataNode)
282 continue;
283
284 sBefore.insert(pDataNode);
285 }
tsepezd19e9122016-11-02 15:43:18 -0700286 ReorderDataNodes(sNew, sBefore, true);
dsinclair5b36f0a2016-07-19 10:56:23 -0700287 }
288 }
289}
290
291void RemoveItem(CXFA_Node* pInstMgrNode,
292 CXFA_Node* pRemoveInstance,
tsepezd19e9122016-11-02 15:43:18 -0700293 bool bRemoveDataBinding = true) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700294 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)->RemoveChild(pRemoveInstance);
295 if (!bRemoveDataBinding)
296 return;
297
298 CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFAContainerNode>
299 sIterator(pRemoveInstance);
300 for (CXFA_Node* pFormNode = sIterator.GetCurrent(); pFormNode;
301 pFormNode = sIterator.MoveToNext()) {
302 CXFA_Node* pDataNode = pFormNode->GetBindData();
303 if (!pDataNode)
304 continue;
305
306 if (pDataNode->RemoveBindItem(pFormNode) == 0) {
307 if (CXFA_Node* pDataParent =
308 pDataNode->GetNodeItem(XFA_NODEITEM_Parent)) {
309 pDataParent->RemoveChild(pDataNode);
310 }
311 }
312 pFormNode->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
313 }
314}
315
tsepezd19e9122016-11-02 15:43:18 -0700316CXFA_Node* CreateInstance(CXFA_Node* pInstMgrNode, bool bDataMerge) {
dsinclair5b36f0a2016-07-19 10:56:23 -0700317 CXFA_Document* pDocument = pInstMgrNode->GetDocument();
318 CXFA_Node* pTemplateNode = pInstMgrNode->GetTemplateNode();
319 CXFA_Node* pFormParent = pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent);
320 CXFA_Node* pDataScope = nullptr;
321 for (CXFA_Node* pRootBoundNode = pFormParent;
322 pRootBoundNode && pRootBoundNode->IsContainerNode();
323 pRootBoundNode = pRootBoundNode->GetNodeItem(XFA_NODEITEM_Parent)) {
324 pDataScope = pRootBoundNode->GetBindData();
325 if (pDataScope)
326 break;
327 }
328 if (!pDataScope) {
329 pDataScope = ToNode(pDocument->GetXFAObject(XFA_HASHCODE_Record));
330 ASSERT(pDataScope);
331 }
332 CXFA_Node* pInstance = pDocument->DataMerge_CopyContainer(
tsepezd19e9122016-11-02 15:43:18 -0700333 pTemplateNode, pFormParent, pDataScope, true, bDataMerge, true);
dsinclair5b36f0a2016-07-19 10:56:23 -0700334 if (pInstance) {
335 pDocument->DataMerge_UpdateBindingRelations(pInstance);
336 pFormParent->RemoveChild(pInstance);
337 }
338 return pInstance;
339}
340
341struct XFA_ExecEventParaInfo {
342 public:
343 uint32_t m_uHash;
Dan Sinclair812e96c2017-03-13 16:43:37 -0400344 const wchar_t* m_lpcEventName;
dsinclair5b36f0a2016-07-19 10:56:23 -0700345 XFA_EVENTTYPE m_eventType;
346 uint32_t m_validFlags;
347};
348static const XFA_ExecEventParaInfo gs_eventParaInfos[] = {
349 {0x02a6c55a, L"postSubmit", XFA_EVENT_PostSubmit, 0},
350 {0x0ab466bb, L"preSubmit", XFA_EVENT_PreSubmit, 0},
351 {0x109d7ce7, L"mouseEnter", XFA_EVENT_MouseEnter, 5},
352 {0x17fad373, L"postPrint", XFA_EVENT_PostPrint, 0},
353 {0x1bfc72d9, L"preOpen", XFA_EVENT_PreOpen, 7},
354 {0x2196a452, L"initialize", XFA_EVENT_Initialize, 1},
355 {0x27410f03, L"mouseExit", XFA_EVENT_MouseExit, 5},
356 {0x33c43dec, L"docClose", XFA_EVENT_DocClose, 0},
357 {0x361fa1b6, L"preSave", XFA_EVENT_PreSave, 0},
358 {0x36f1c6d8, L"preSign", XFA_EVENT_PreSign, 6},
359 {0x4731d6ba, L"exit", XFA_EVENT_Exit, 2},
360 {0x56bf456b, L"docReady", XFA_EVENT_DocReady, 0},
361 {0x7233018a, L"validate", XFA_EVENT_Validate, 1},
362 {0x8808385e, L"indexChange", XFA_EVENT_IndexChange, 3},
363 {0x891f4606, L"change", XFA_EVENT_Change, 4},
364 {0x9528a7b4, L"prePrint", XFA_EVENT_PrePrint, 0},
365 {0x9f693b21, L"mouseDown", XFA_EVENT_MouseDown, 5},
366 {0xcdce56b3, L"full", XFA_EVENT_Full, 4},
367 {0xd576d08e, L"mouseUp", XFA_EVENT_MouseUp, 5},
368 {0xd95657a6, L"click", XFA_EVENT_Click, 4},
369 {0xdbfbe02e, L"calculate", XFA_EVENT_Calculate, 1},
370 {0xe25fa7b8, L"postOpen", XFA_EVENT_PostOpen, 7},
371 {0xe28dce7e, L"enter", XFA_EVENT_Enter, 2},
372 {0xfc82d695, L"postSave", XFA_EVENT_PostSave, 0},
373 {0xfd54fbb7, L"postSign", XFA_EVENT_PostSign, 6},
374};
375
376const XFA_ExecEventParaInfo* GetEventParaInfoByName(
377 const CFX_WideStringC& wsEventName) {
378 uint32_t uHash = FX_HashCode_GetW(wsEventName, false);
379 int32_t iStart = 0;
380 int32_t iEnd = (sizeof(gs_eventParaInfos) / sizeof(gs_eventParaInfos[0])) - 1;
381 do {
382 int32_t iMid = (iStart + iEnd) / 2;
383 const XFA_ExecEventParaInfo* eventParaInfo = &gs_eventParaInfos[iMid];
384 if (uHash == eventParaInfo->m_uHash)
385 return eventParaInfo;
386 if (uHash < eventParaInfo->m_uHash)
387 iEnd = iMid - 1;
388 else
389 iStart = iMid + 1;
390 } while (iStart <= iEnd);
391 return nullptr;
392}
393
394void StrToRGB(const CFX_WideString& strRGB,
395 int32_t& r,
396 int32_t& g,
397 int32_t& b) {
398 r = 0;
399 g = 0;
400 b = 0;
401
Dan Sinclair812e96c2017-03-13 16:43:37 -0400402 wchar_t zero = '0';
dsinclair5b36f0a2016-07-19 10:56:23 -0700403 int32_t iIndex = 0;
404 int32_t iLen = strRGB.GetLength();
405 for (int32_t i = 0; i < iLen; ++i) {
Dan Sinclair812e96c2017-03-13 16:43:37 -0400406 wchar_t ch = strRGB.GetAt(i);
dsinclair5b36f0a2016-07-19 10:56:23 -0700407 if (ch == L',')
408 ++iIndex;
409 if (iIndex > 2)
410 break;
411
412 int32_t iValue = ch - zero;
413 if (iValue >= 0 && iValue <= 9) {
414 switch (iIndex) {
415 case 0:
416 r = r * 10 + iValue;
417 break;
418 case 1:
419 g = g * 10 + iValue;
420 break;
421 default:
422 b = b * 10 + iValue;
423 break;
424 }
425 }
426 }
427}
428
429enum XFA_KEYTYPE {
430 XFA_KEYTYPE_Custom,
431 XFA_KEYTYPE_Element,
432};
433
434void* GetMapKey_Custom(const CFX_WideStringC& wsKey) {
435 uint32_t dwKey = FX_HashCode_GetW(wsKey, false);
436 return (void*)(uintptr_t)((dwKey << 1) | XFA_KEYTYPE_Custom);
437}
438
439void* GetMapKey_Element(XFA_Element eType, XFA_ATTRIBUTE eAttribute) {
440 return (void*)(uintptr_t)((static_cast<int32_t>(eType) << 16) |
441 (eAttribute << 8) | XFA_KEYTYPE_Element);
442}
443
dsinclair9eb0db12016-07-21 12:01:39 -0700444const XFA_ATTRIBUTEINFO* GetAttributeOfElement(XFA_Element eElement,
445 XFA_ATTRIBUTE eAttribute,
446 uint32_t dwPacket) {
447 int32_t iCount = 0;
448 const uint8_t* pAttr = XFA_GetElementAttributes(eElement, iCount);
449 if (!pAttr || iCount < 1)
450 return nullptr;
451
452 if (!std::binary_search(pAttr, pAttr + iCount, eAttribute))
453 return nullptr;
454
455 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttribute);
456 ASSERT(pInfo);
457 if (dwPacket == XFA_XDPPACKET_UNKNOWN)
458 return pInfo;
459 return (dwPacket & pInfo->dwPackets) ? pInfo : nullptr;
460}
461
462const XFA_ATTRIBUTEENUMINFO* GetAttributeEnumByID(XFA_ATTRIBUTEENUM eName) {
463 return g_XFAEnumData + eName;
464}
465
dsinclair5b36f0a2016-07-19 10:56:23 -0700466} // namespace
467
468static void XFA_DefaultFreeData(void* pData) {}
469
470static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADefaultFreeData = {
471 XFA_DefaultFreeData, nullptr};
472
weili47bcd4c2016-06-16 08:00:06 -0700473XFA_MAPMODULEDATA::XFA_MAPMODULEDATA() {}
474
475XFA_MAPMODULEDATA::~XFA_MAPMODULEDATA() {}
476
dsinclairb9778472016-06-23 13:34:10 -0700477CXFA_Node::CXFA_Node(CXFA_Document* pDoc,
478 uint16_t ePacket,
479 XFA_ObjectType oType,
dsinclairc1df5d42016-07-18 06:36:51 -0700480 XFA_Element eType,
481 const CFX_WideStringC& elementName)
482 : CXFA_Object(pDoc, oType, eType, elementName),
Dan Sinclair1770c022016-03-14 14:14:16 -0400483 m_pNext(nullptr),
484 m_pChild(nullptr),
485 m_pLastChild(nullptr),
486 m_pParent(nullptr),
487 m_pXMLNode(nullptr),
Dan Sinclair1770c022016-03-14 14:14:16 -0400488 m_ePacket(ePacket),
dsinclairc5a8f212016-06-20 11:11:12 -0700489 m_uNodeFlags(XFA_NodeFlag_None),
Dan Sinclair1770c022016-03-14 14:14:16 -0400490 m_dwNameHash(0),
491 m_pAuxNode(nullptr),
492 m_pMapModuleData(nullptr) {
493 ASSERT(m_pDocument);
494}
weili44f8faf2016-06-01 14:03:56 -0700495
Dan Sinclair1770c022016-03-14 14:14:16 -0400496CXFA_Node::~CXFA_Node() {
weili44f8faf2016-06-01 14:03:56 -0700497 ASSERT(!m_pParent);
Dan Sinclair1770c022016-03-14 14:14:16 -0400498 RemoveMapModuleKey();
weili44f8faf2016-06-01 14:03:56 -0700499 CXFA_Node* pNode = m_pChild;
Dan Sinclair1770c022016-03-14 14:14:16 -0400500 while (pNode) {
weili44f8faf2016-06-01 14:03:56 -0700501 CXFA_Node* pNext = pNode->m_pNext;
502 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400503 delete pNode;
504 pNode = pNext;
505 }
dsinclairc5a8f212016-06-20 11:11:12 -0700506 if (m_pXMLNode && IsOwnXMLNode())
tsepezc757d9a2017-01-23 11:01:42 -0800507 delete m_pXMLNode;
Dan Sinclair1770c022016-03-14 14:14:16 -0400508}
weili44f8faf2016-06-01 14:03:56 -0700509
tsepezd19e9122016-11-02 15:43:18 -0700510CXFA_Node* CXFA_Node::Clone(bool bRecursive) {
dsinclaira1b07722016-07-11 08:20:58 -0700511 CXFA_Node* pClone = m_pDocument->CreateNode(m_ePacket, m_elementType);
weili44f8faf2016-06-01 14:03:56 -0700512 if (!pClone)
513 return nullptr;
514
Dan Sinclair1770c022016-03-14 14:14:16 -0400515 MergeAllData(pClone);
516 pClone->UpdateNameHash();
517 if (IsNeedSavingXMLNode()) {
weili44f8faf2016-06-01 14:03:56 -0700518 CFDE_XMLNode* pCloneXML = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400519 if (IsAttributeInXML()) {
520 CFX_WideString wsName;
tsepezd19e9122016-11-02 15:43:18 -0700521 GetAttribute(XFA_ATTRIBUTE_Name, wsName, false);
dsinclairae95f762016-03-29 16:58:29 -0700522 CFDE_XMLElement* pCloneXMLElement = new CFDE_XMLElement(wsName);
Dan Sinclair1770c022016-03-14 14:14:16 -0400523 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
524 if (!wsValue.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -0700525 pCloneXMLElement->SetTextData(CFX_WideString(wsValue));
Dan Sinclair1770c022016-03-14 14:14:16 -0400526 }
527 pCloneXML = pCloneXMLElement;
weili44f8faf2016-06-01 14:03:56 -0700528 pCloneXMLElement = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400529 pClone->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
530 } else {
tsepezd19e9122016-11-02 15:43:18 -0700531 pCloneXML = m_pXMLNode->Clone(false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400532 }
533 pClone->SetXMLMappingNode(pCloneXML);
dsinclairc5a8f212016-06-20 11:11:12 -0700534 pClone->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400535 }
536 if (bRecursive) {
537 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
538 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
539 pClone->InsertChild(pChild->Clone(bRecursive));
540 }
541 }
dsinclairc5a8f212016-06-20 11:11:12 -0700542 pClone->SetFlag(XFA_NodeFlag_Initialized, true);
weili44f8faf2016-06-01 14:03:56 -0700543 pClone->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
Dan Sinclair1770c022016-03-14 14:14:16 -0400544 return pClone;
545}
weili44f8faf2016-06-01 14:03:56 -0700546
Dan Sinclair1770c022016-03-14 14:14:16 -0400547CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem) const {
548 switch (eItem) {
549 case XFA_NODEITEM_NextSibling:
550 return m_pNext;
551 case XFA_NODEITEM_FirstChild:
552 return m_pChild;
553 case XFA_NODEITEM_Parent:
554 return m_pParent;
555 case XFA_NODEITEM_PrevSibling:
556 if (m_pParent) {
557 CXFA_Node* pSibling = m_pParent->m_pChild;
weili44f8faf2016-06-01 14:03:56 -0700558 CXFA_Node* pPrev = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400559 while (pSibling && pSibling != this) {
560 pPrev = pSibling;
561 pSibling = pSibling->m_pNext;
562 }
563 return pPrev;
564 }
weili44f8faf2016-06-01 14:03:56 -0700565 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400566 default:
567 break;
568 }
weili44f8faf2016-06-01 14:03:56 -0700569 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400570}
weili44f8faf2016-06-01 14:03:56 -0700571
Dan Sinclair1770c022016-03-14 14:14:16 -0400572CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem,
dsinclairc5a8f212016-06-20 11:11:12 -0700573 XFA_ObjectType eType) const {
weili44f8faf2016-06-01 14:03:56 -0700574 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400575 switch (eItem) {
576 case XFA_NODEITEM_NextSibling:
577 pNode = m_pNext;
dsinclairc5a8f212016-06-20 11:11:12 -0700578 while (pNode && pNode->GetObjectType() != eType)
579 pNode = pNode->m_pNext;
Dan Sinclair1770c022016-03-14 14:14:16 -0400580 break;
581 case XFA_NODEITEM_FirstChild:
582 pNode = m_pChild;
dsinclairc5a8f212016-06-20 11:11:12 -0700583 while (pNode && pNode->GetObjectType() != eType)
584 pNode = pNode->m_pNext;
Dan Sinclair1770c022016-03-14 14:14:16 -0400585 break;
586 case XFA_NODEITEM_Parent:
587 pNode = m_pParent;
dsinclairc5a8f212016-06-20 11:11:12 -0700588 while (pNode && pNode->GetObjectType() != eType)
589 pNode = pNode->m_pParent;
Dan Sinclair1770c022016-03-14 14:14:16 -0400590 break;
591 case XFA_NODEITEM_PrevSibling:
592 if (m_pParent) {
593 CXFA_Node* pSibling = m_pParent->m_pChild;
594 while (pSibling && pSibling != this) {
dsinclairc5a8f212016-06-20 11:11:12 -0700595 if (eType == pSibling->GetObjectType())
Dan Sinclair1770c022016-03-14 14:14:16 -0400596 pNode = pSibling;
dsinclairc5a8f212016-06-20 11:11:12 -0700597
Dan Sinclair1770c022016-03-14 14:14:16 -0400598 pSibling = pSibling->m_pNext;
599 }
600 }
601 break;
602 default:
603 break;
604 }
605 return pNode;
606}
weili44f8faf2016-06-01 14:03:56 -0700607
Tom Sepezf8a94392017-03-14 12:13:22 -0700608std::vector<CXFA_Node*> CXFA_Node::GetNodeList(uint32_t dwTypeFilter,
609 XFA_Element eTypeFilter) {
610 std::vector<CXFA_Node*> nodes;
dsinclair41cb62e2016-06-23 09:20:32 -0700611 if (eTypeFilter != XFA_Element::Unknown) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700612 for (CXFA_Node* pChild = m_pChild; pChild; pChild = pChild->m_pNext) {
613 if (pChild->GetElementType() == eTypeFilter)
614 nodes.push_back(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400615 }
616 } else if (dwTypeFilter ==
617 (XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties)) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700618 for (CXFA_Node* pChild = m_pChild; pChild; pChild = pChild->m_pNext)
619 nodes.push_back(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400620 } else if (dwTypeFilter != 0) {
weili44f8faf2016-06-01 14:03:56 -0700621 bool bFilterChildren = !!(dwTypeFilter & XFA_NODEFILTER_Children);
622 bool bFilterProperties = !!(dwTypeFilter & XFA_NODEFILTER_Properties);
623 bool bFilterOneOfProperties =
624 !!(dwTypeFilter & XFA_NODEFILTER_OneOfProperty);
Dan Sinclair1770c022016-03-14 14:14:16 -0400625 CXFA_Node* pChild = m_pChild;
626 while (pChild) {
627 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -0700628 GetElementType(), pChild->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -0400629 if (pProperty) {
630 if (bFilterProperties) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700631 nodes.push_back(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400632 } else if (bFilterOneOfProperties &&
633 (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700634 nodes.push_back(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400635 } else if (bFilterChildren &&
dsinclair070fcdf2016-06-22 22:04:54 -0700636 (pChild->GetElementType() == XFA_Element::Variables ||
637 pChild->GetElementType() == XFA_Element::PageSet)) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700638 nodes.push_back(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400639 }
weili44f8faf2016-06-01 14:03:56 -0700640 } else if (bFilterChildren) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700641 nodes.push_back(pChild);
Dan Sinclair1770c022016-03-14 14:14:16 -0400642 }
643 pChild = pChild->m_pNext;
644 }
Tom Sepezf8a94392017-03-14 12:13:22 -0700645 if (bFilterOneOfProperties && nodes.empty()) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400646 int32_t iProperties = 0;
647 const XFA_PROPERTY* pProperty =
dsinclair070fcdf2016-06-22 22:04:54 -0700648 XFA_GetElementProperties(GetElementType(), iProperties);
weili44f8faf2016-06-01 14:03:56 -0700649 if (!pProperty || iProperties < 1)
Tom Sepezf8a94392017-03-14 12:13:22 -0700650 return nodes;
Dan Sinclair1770c022016-03-14 14:14:16 -0400651 for (int32_t i = 0; i < iProperties; i++) {
652 if (pProperty[i].uFlags & XFA_PROPERTYFLAG_DefaultOneOf) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400653 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(GetPacketID());
654 CXFA_Node* pNewNode =
dsinclaira1b07722016-07-11 08:20:58 -0700655 m_pDocument->CreateNode(pPacket, pProperty[i].eName);
weili44f8faf2016-06-01 14:03:56 -0700656 if (!pNewNode)
Dan Sinclair1770c022016-03-14 14:14:16 -0400657 break;
weili44f8faf2016-06-01 14:03:56 -0700658 InsertChild(pNewNode, nullptr);
dsinclairc5a8f212016-06-20 11:11:12 -0700659 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
Tom Sepezf8a94392017-03-14 12:13:22 -0700660 nodes.push_back(pNewNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400661 break;
662 }
663 }
664 }
665 }
Tom Sepezf8a94392017-03-14 12:13:22 -0700666 return nodes;
Dan Sinclair1770c022016-03-14 14:14:16 -0400667}
weili44f8faf2016-06-01 14:03:56 -0700668
dsinclair41cb62e2016-06-23 09:20:32 -0700669CXFA_Node* CXFA_Node::CreateSamePacketNode(XFA_Element eType,
tsepez736f28a2016-03-25 14:19:51 -0700670 uint32_t dwFlags) {
dsinclaira1b07722016-07-11 08:20:58 -0700671 CXFA_Node* pNode = m_pDocument->CreateNode(m_ePacket, eType);
thestigb1a59592016-04-14 18:29:56 -0700672 pNode->SetFlag(dwFlags, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400673 return pNode;
674}
weili44f8faf2016-06-01 14:03:56 -0700675
tsepezd19e9122016-11-02 15:43:18 -0700676CXFA_Node* CXFA_Node::CloneTemplateToForm(bool bRecursive) {
dsinclair43854a52016-04-27 12:26:00 -0700677 ASSERT(m_ePacket == XFA_XDPPACKET_Template);
dsinclaira1b07722016-07-11 08:20:58 -0700678 CXFA_Node* pClone =
679 m_pDocument->CreateNode(XFA_XDPPACKET_Form, m_elementType);
weili44f8faf2016-06-01 14:03:56 -0700680 if (!pClone)
681 return nullptr;
682
Dan Sinclair1770c022016-03-14 14:14:16 -0400683 pClone->SetTemplateNode(this);
684 pClone->UpdateNameHash();
685 pClone->SetXMLMappingNode(GetXMLMappingNode());
686 if (bRecursive) {
687 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
688 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
689 pClone->InsertChild(pChild->CloneTemplateToForm(bRecursive));
690 }
691 }
dsinclairc5a8f212016-06-20 11:11:12 -0700692 pClone->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -0400693 return pClone;
694}
695
696CXFA_Node* CXFA_Node::GetTemplateNode() const {
697 return m_pAuxNode;
698}
699
700void CXFA_Node::SetTemplateNode(CXFA_Node* pTemplateNode) {
701 m_pAuxNode = pTemplateNode;
702}
weili44f8faf2016-06-01 14:03:56 -0700703
Dan Sinclair1770c022016-03-14 14:14:16 -0400704CXFA_Node* CXFA_Node::GetBindData() {
705 ASSERT(GetPacketID() == XFA_XDPPACKET_Form);
706 return static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
707}
weili44f8faf2016-06-01 14:03:56 -0700708
Tom Sepezf8a94392017-03-14 12:13:22 -0700709std::vector<CXFA_Node*> CXFA_Node::GetBindItems() {
dsinclairc5a8f212016-06-20 11:11:12 -0700710 if (BindsFormItems()) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700711 void* pBinding = nullptr;
712 TryObject(XFA_ATTRIBUTE_BindingNode, pBinding);
713 return *static_cast<std::vector<CXFA_Node*>*>(pBinding);
Dan Sinclair1770c022016-03-14 14:14:16 -0400714 }
Tom Sepezf8a94392017-03-14 12:13:22 -0700715 std::vector<CXFA_Node*> result;
Dan Sinclair1770c022016-03-14 14:14:16 -0400716 CXFA_Node* pFormNode =
717 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
weili44f8faf2016-06-01 14:03:56 -0700718 if (pFormNode)
Tom Sepezf8a94392017-03-14 12:13:22 -0700719 result.push_back(pFormNode);
720 return result;
Dan Sinclair1770c022016-03-14 14:14:16 -0400721}
722
Dan Sinclair1770c022016-03-14 14:14:16 -0400723int32_t CXFA_Node::AddBindItem(CXFA_Node* pFormNode) {
724 ASSERT(pFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700725 if (BindsFormItems()) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700726 void* pBinding = nullptr;
727 TryObject(XFA_ATTRIBUTE_BindingNode, pBinding);
728 auto* pItems = static_cast<std::vector<CXFA_Node*>*>(pBinding);
729 if (!pdfium::ContainsValue(*pItems, pFormNode))
730 pItems->push_back(pFormNode);
731 return pdfium::CollectionSize<int32_t>(*pItems);
Dan Sinclair1770c022016-03-14 14:14:16 -0400732 }
733 CXFA_Node* pOldFormItem =
734 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
735 if (!pOldFormItem) {
736 SetObject(XFA_ATTRIBUTE_BindingNode, pFormNode);
737 return 1;
Dan Sinclair1770c022016-03-14 14:14:16 -0400738 }
Tom Sepezf8a94392017-03-14 12:13:22 -0700739 if (pOldFormItem == pFormNode)
740 return 1;
741
742 std::vector<CXFA_Node*>* pItems = new std::vector<CXFA_Node*>;
Dan Sinclair1770c022016-03-14 14:14:16 -0400743 SetObject(XFA_ATTRIBUTE_BindingNode, pItems, &deleteBindItemCallBack);
Tom Sepezf8a94392017-03-14 12:13:22 -0700744 pItems->push_back(pOldFormItem);
745 pItems->push_back(pFormNode);
dsinclairc5a8f212016-06-20 11:11:12 -0700746 m_uNodeFlags |= XFA_NodeFlag_BindFormItems;
Dan Sinclair1770c022016-03-14 14:14:16 -0400747 return 2;
748}
weili44f8faf2016-06-01 14:03:56 -0700749
Dan Sinclair1770c022016-03-14 14:14:16 -0400750int32_t CXFA_Node::RemoveBindItem(CXFA_Node* pFormNode) {
dsinclairc5a8f212016-06-20 11:11:12 -0700751 if (BindsFormItems()) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700752 void* pBinding = nullptr;
753 TryObject(XFA_ATTRIBUTE_BindingNode, pBinding);
754 auto* pItems = static_cast<std::vector<CXFA_Node*>*>(pBinding);
755 auto iter = std::find(pItems->begin(), pItems->end(), pFormNode);
756 if (iter != pItems->end()) {
757 *iter = pItems->back();
758 pItems->pop_back();
759 if (pItems->size() == 1) {
760 SetObject(XFA_ATTRIBUTE_BindingNode,
761 (*pItems)[0]); // Invalidates pItems.
dsinclairc5a8f212016-06-20 11:11:12 -0700762 m_uNodeFlags &= ~XFA_NodeFlag_BindFormItems;
Tom Sepezf8a94392017-03-14 12:13:22 -0700763 return 1;
Dan Sinclair1770c022016-03-14 14:14:16 -0400764 }
Dan Sinclair1770c022016-03-14 14:14:16 -0400765 }
Tom Sepezf8a94392017-03-14 12:13:22 -0700766 return pdfium::CollectionSize<int32_t>(*pItems);
Dan Sinclair1770c022016-03-14 14:14:16 -0400767 }
768 CXFA_Node* pOldFormItem =
769 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
Tom Sepezf8a94392017-03-14 12:13:22 -0700770 if (pOldFormItem != pFormNode)
771 return pOldFormItem ? 1 : 0;
772
773 SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
774 return 0;
Dan Sinclair1770c022016-03-14 14:14:16 -0400775}
weili44f8faf2016-06-01 14:03:56 -0700776
tsepezd19e9122016-11-02 15:43:18 -0700777bool CXFA_Node::HasBindItem() {
weili44f8faf2016-06-01 14:03:56 -0700778 return GetPacketID() == XFA_XDPPACKET_Datasets &&
779 GetObject(XFA_ATTRIBUTE_BindingNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400780}
weili44f8faf2016-06-01 14:03:56 -0700781
Dan Sinclair1770c022016-03-14 14:14:16 -0400782CXFA_WidgetData* CXFA_Node::GetWidgetData() {
783 return (CXFA_WidgetData*)GetObject(XFA_ATTRIBUTE_WidgetData);
784}
weili44f8faf2016-06-01 14:03:56 -0700785
Dan Sinclair1770c022016-03-14 14:14:16 -0400786CXFA_WidgetData* CXFA_Node::GetContainerWidgetData() {
weili44f8faf2016-06-01 14:03:56 -0700787 if (GetPacketID() != XFA_XDPPACKET_Form)
788 return nullptr;
dsinclair41cb62e2016-06-23 09:20:32 -0700789 XFA_Element eType = GetElementType();
790 if (eType == XFA_Element::ExclGroup)
weili44f8faf2016-06-01 14:03:56 -0700791 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400792 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -0700793 if (pParentNode && pParentNode->GetElementType() == XFA_Element::ExclGroup)
weili44f8faf2016-06-01 14:03:56 -0700794 return nullptr;
795
dsinclair41cb62e2016-06-23 09:20:32 -0700796 if (eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400797 CXFA_WidgetData* pFieldWidgetData = GetWidgetData();
798 if (pFieldWidgetData &&
799 pFieldWidgetData->GetChoiceListOpen() ==
800 XFA_ATTRIBUTEENUM_MultiSelect) {
weili44f8faf2016-06-01 14:03:56 -0700801 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400802 } else {
803 CFX_WideString wsPicture;
804 if (pFieldWidgetData) {
805 pFieldWidgetData->GetPictureContent(wsPicture,
806 XFA_VALUEPICTURE_DataBind);
807 }
weili44f8faf2016-06-01 14:03:56 -0700808 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -0400809 return pFieldWidgetData;
Dan Sinclair1770c022016-03-14 14:14:16 -0400810 CXFA_Node* pDataNode = GetBindData();
weili44f8faf2016-06-01 14:03:56 -0700811 if (!pDataNode)
812 return nullptr;
813 pFieldWidgetData = nullptr;
Tom Sepezf8a94392017-03-14 12:13:22 -0700814 for (CXFA_Node* pFormNode : pDataNode->GetBindItems()) {
dsinclairc5a8f212016-06-20 11:11:12 -0700815 if (!pFormNode || pFormNode->HasRemovedChildren())
Dan Sinclair1770c022016-03-14 14:14:16 -0400816 continue;
Dan Sinclair1770c022016-03-14 14:14:16 -0400817 pFieldWidgetData = pFormNode->GetWidgetData();
818 if (pFieldWidgetData) {
819 pFieldWidgetData->GetPictureContent(wsPicture,
820 XFA_VALUEPICTURE_DataBind);
821 }
weili44f8faf2016-06-01 14:03:56 -0700822 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -0400823 break;
weili44f8faf2016-06-01 14:03:56 -0700824 pFieldWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400825 }
826 return pFieldWidgetData;
827 }
828 }
829 CXFA_Node* pGrandNode =
weili44f8faf2016-06-01 14:03:56 -0700830 pParentNode ? pParentNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400831 CXFA_Node* pValueNode =
dsinclair070fcdf2016-06-22 22:04:54 -0700832 (pParentNode && pParentNode->GetElementType() == XFA_Element::Value)
Dan Sinclair1770c022016-03-14 14:14:16 -0400833 ? pParentNode
weili44f8faf2016-06-01 14:03:56 -0700834 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400835 if (!pValueNode) {
dsinclair070fcdf2016-06-22 22:04:54 -0700836 pValueNode =
837 (pGrandNode && pGrandNode->GetElementType() == XFA_Element::Value)
838 ? pGrandNode
839 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400840 }
841 CXFA_Node* pParentOfValueNode =
weili44f8faf2016-06-01 14:03:56 -0700842 pValueNode ? pValueNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400843 return pParentOfValueNode ? pParentOfValueNode->GetContainerWidgetData()
weili44f8faf2016-06-01 14:03:56 -0700844 : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400845}
weili44f8faf2016-06-01 14:03:56 -0700846
tsepezd19e9122016-11-02 15:43:18 -0700847bool CXFA_Node::GetLocaleName(CFX_WideString& wsLocaleName) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400848 CXFA_Node* pForm = GetDocument()->GetXFAObject(XFA_HASHCODE_Form)->AsNode();
dsinclair56a8b192016-06-21 14:15:25 -0700849 CXFA_Node* pTopSubform = pForm->GetFirstChildByClass(XFA_Element::Subform);
dsinclair43854a52016-04-27 12:26:00 -0700850 ASSERT(pTopSubform);
Dan Sinclair1770c022016-03-14 14:14:16 -0400851 CXFA_Node* pLocaleNode = this;
tsepezd19e9122016-11-02 15:43:18 -0700852 bool bLocale = false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400853 do {
tsepezd19e9122016-11-02 15:43:18 -0700854 bLocale = pLocaleNode->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400855 if (!bLocale) {
856 pLocaleNode = pLocaleNode->GetNodeItem(XFA_NODEITEM_Parent);
857 }
858 } while (pLocaleNode && pLocaleNode != pTopSubform && !bLocale);
weili44f8faf2016-06-01 14:03:56 -0700859 if (bLocale)
tsepezd19e9122016-11-02 15:43:18 -0700860 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400861 CXFA_Node* pConfig = ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Config));
862 wsLocaleName = GetDocument()->GetLocalMgr()->GetConfigLocaleName(pConfig);
weili44f8faf2016-06-01 14:03:56 -0700863 if (!wsLocaleName.IsEmpty())
tsepezd19e9122016-11-02 15:43:18 -0700864 return true;
weili44f8faf2016-06-01 14:03:56 -0700865 if (pTopSubform &&
tsepezd19e9122016-11-02 15:43:18 -0700866 pTopSubform->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false)) {
867 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400868 }
869 IFX_Locale* pLocale = GetDocument()->GetLocalMgr()->GetDefLocale();
870 if (pLocale) {
871 wsLocaleName = pLocale->GetName();
tsepezd19e9122016-11-02 15:43:18 -0700872 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400873 }
tsepezd19e9122016-11-02 15:43:18 -0700874 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400875}
weili44f8faf2016-06-01 14:03:56 -0700876
Dan Sinclair1770c022016-03-14 14:14:16 -0400877XFA_ATTRIBUTEENUM CXFA_Node::GetIntact() {
dsinclair56a8b192016-06-21 14:15:25 -0700878 CXFA_Node* pKeep = GetFirstChildByClass(XFA_Element::Keep);
Dan Sinclair1770c022016-03-14 14:14:16 -0400879 XFA_ATTRIBUTEENUM eLayoutType = GetEnum(XFA_ATTRIBUTE_Layout);
880 if (pKeep) {
881 XFA_ATTRIBUTEENUM eIntact;
tsepezd19e9122016-11-02 15:43:18 -0700882 if (pKeep->TryEnum(XFA_ATTRIBUTE_Intact, eIntact, false)) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400883 if (eIntact == XFA_ATTRIBUTEENUM_None &&
884 eLayoutType == XFA_ATTRIBUTEENUM_Row &&
885 m_pDocument->GetCurVersionMode() < XFA_VERSION_208) {
dsinclairc5a8f212016-06-20 11:11:12 -0700886 CXFA_Node* pPreviewRow = GetNodeItem(XFA_NODEITEM_PrevSibling,
887 XFA_ObjectType::ContainerNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400888 if (pPreviewRow &&
889 pPreviewRow->GetEnum(XFA_ATTRIBUTE_Layout) ==
890 XFA_ATTRIBUTEENUM_Row) {
891 XFA_ATTRIBUTEENUM eValue;
tsepezd19e9122016-11-02 15:43:18 -0700892 if (pKeep->TryEnum(XFA_ATTRIBUTE_Previous, eValue, false) &&
weili44f8faf2016-06-01 14:03:56 -0700893 (eValue == XFA_ATTRIBUTEENUM_ContentArea ||
894 eValue == XFA_ATTRIBUTEENUM_PageArea)) {
895 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400896 }
weili44f8faf2016-06-01 14:03:56 -0700897 CXFA_Node* pNode =
dsinclair56a8b192016-06-21 14:15:25 -0700898 pPreviewRow->GetFirstChildByClass(XFA_Element::Keep);
tsepezd19e9122016-11-02 15:43:18 -0700899 if (pNode && pNode->TryEnum(XFA_ATTRIBUTE_Next, eValue, false) &&
weili44f8faf2016-06-01 14:03:56 -0700900 (eValue == XFA_ATTRIBUTEENUM_ContentArea ||
901 eValue == XFA_ATTRIBUTEENUM_PageArea)) {
902 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400903 }
904 }
905 }
906 return eIntact;
907 }
908 }
dsinclair41cb62e2016-06-23 09:20:32 -0700909 switch (GetElementType()) {
dsinclair56a8b192016-06-21 14:15:25 -0700910 case XFA_Element::Subform:
Dan Sinclair1770c022016-03-14 14:14:16 -0400911 switch (eLayoutType) {
912 case XFA_ATTRIBUTEENUM_Position:
913 case XFA_ATTRIBUTEENUM_Row:
914 return XFA_ATTRIBUTEENUM_ContentArea;
915 case XFA_ATTRIBUTEENUM_Tb:
916 case XFA_ATTRIBUTEENUM_Table:
917 case XFA_ATTRIBUTEENUM_Lr_tb:
918 case XFA_ATTRIBUTEENUM_Rl_tb:
919 return XFA_ATTRIBUTEENUM_None;
920 default:
921 break;
922 }
923 break;
dsinclair56a8b192016-06-21 14:15:25 -0700924 case XFA_Element::Field: {
Dan Sinclair1770c022016-03-14 14:14:16 -0400925 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -0700926 if (!pParentNode ||
927 pParentNode->GetElementType() == XFA_Element::PageArea)
Dan Sinclair1770c022016-03-14 14:14:16 -0400928 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400929 if (pParentNode->GetIntact() == XFA_ATTRIBUTEENUM_None) {
930 XFA_ATTRIBUTEENUM eParLayout =
931 pParentNode->GetEnum(XFA_ATTRIBUTE_Layout);
932 if (eParLayout == XFA_ATTRIBUTEENUM_Position ||
933 eParLayout == XFA_ATTRIBUTEENUM_Row ||
934 eParLayout == XFA_ATTRIBUTEENUM_Table) {
935 return XFA_ATTRIBUTEENUM_None;
936 }
937 XFA_VERSION version = m_pDocument->GetCurVersionMode();
938 if (eParLayout == XFA_ATTRIBUTEENUM_Tb && version < XFA_VERSION_208) {
939 CXFA_Measurement measureH;
tsepezd19e9122016-11-02 15:43:18 -0700940 if (TryMeasure(XFA_ATTRIBUTE_H, measureH, false))
Dan Sinclair1770c022016-03-14 14:14:16 -0400941 return XFA_ATTRIBUTEENUM_ContentArea;
Dan Sinclair1770c022016-03-14 14:14:16 -0400942 }
943 return XFA_ATTRIBUTEENUM_None;
944 }
945 return XFA_ATTRIBUTEENUM_ContentArea;
946 }
dsinclair56a8b192016-06-21 14:15:25 -0700947 case XFA_Element::Draw:
Dan Sinclair1770c022016-03-14 14:14:16 -0400948 return XFA_ATTRIBUTEENUM_ContentArea;
949 default:
950 break;
951 }
952 return XFA_ATTRIBUTEENUM_None;
953}
weili44f8faf2016-06-01 14:03:56 -0700954
Dan Sinclair1770c022016-03-14 14:14:16 -0400955CXFA_Node* CXFA_Node::GetDataDescriptionNode() {
weili44f8faf2016-06-01 14:03:56 -0700956 if (m_ePacket == XFA_XDPPACKET_Datasets)
Dan Sinclair1770c022016-03-14 14:14:16 -0400957 return m_pAuxNode;
weili44f8faf2016-06-01 14:03:56 -0700958 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400959}
weili44f8faf2016-06-01 14:03:56 -0700960
Dan Sinclair1770c022016-03-14 14:14:16 -0400961void CXFA_Node::SetDataDescriptionNode(CXFA_Node* pDataDescriptionNode) {
dsinclair43854a52016-04-27 12:26:00 -0700962 ASSERT(m_ePacket == XFA_XDPPACKET_Datasets);
Dan Sinclair1770c022016-03-14 14:14:16 -0400963 m_pAuxNode = pDataDescriptionNode;
964}
weili44f8faf2016-06-01 14:03:56 -0700965
Dan Sinclair1770c022016-03-14 14:14:16 -0400966void CXFA_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments) {
967 int32_t iLength = pArguments->GetLength();
968 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -0500969 ThrowParamCountMismatchException(L"resolveNode");
Dan Sinclair1770c022016-03-14 14:14:16 -0400970 return;
971 }
tsepez6fe7d212016-04-06 10:51:14 -0700972 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -0700973 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
dsinclairdf4bc592016-03-31 20:34:43 -0700974 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -0700975 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -0400976 return;
Dan Sinclair1770c022016-03-14 14:14:16 -0400977 CXFA_Node* refNode = this;
dsinclair070fcdf2016-06-22 22:04:54 -0700978 if (refNode->GetElementType() == XFA_Element::Xfa)
Dan Sinclair1770c022016-03-14 14:14:16 -0400979 refNode = ToNode(pScriptContext->GetThisObject());
tsepez736f28a2016-03-25 14:19:51 -0700980 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
Dan Sinclair1770c022016-03-14 14:14:16 -0400981 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
982 XFA_RESOLVENODE_Siblings;
983 XFA_RESOLVENODE_RS resoveNodeRS;
tsepezfc58ad12016-04-05 12:22:15 -0700984 int32_t iRet = pScriptContext->ResolveObjects(
tsepez4c3debb2016-04-08 12:20:38 -0700985 refNode, wsExpression.AsStringC(), resoveNodeRS, dwFlag);
dsinclairf27aeec2016-06-07 19:36:18 -0700986 if (iRet < 1) {
987 pArguments->GetReturnValue()->SetNull();
988 return;
989 }
Dan Sinclair1770c022016-03-14 14:14:16 -0400990 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
Tom Sepezf8a94392017-03-14 12:13:22 -0700991 CXFA_Object* pObject = resoveNodeRS.objects.front();
dsinclairf27aeec2016-06-07 19:36:18 -0700992 pArguments->GetReturnValue()->Assign(
Tom Sepezf8a94392017-03-14 12:13:22 -0700993 pScriptContext->GetJSValueFromMap(pObject));
Dan Sinclair1770c022016-03-14 14:14:16 -0400994 } else {
995 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo =
996 resoveNodeRS.pScriptAttribute;
997 if (lpAttributeInfo && lpAttributeInfo->eValueType == XFA_SCRIPT_Object) {
dsinclair86fad992016-05-31 11:34:04 -0700998 std::unique_ptr<CFXJSE_Value> pValue(
999 new CFXJSE_Value(pScriptContext->GetRuntime()));
Tom Sepezf8a94392017-03-14 12:13:22 -07001000 (resoveNodeRS.objects.front()->*(lpAttributeInfo->lpfnCallback))(
tsepezd19e9122016-11-02 15:43:18 -07001001 pValue.get(), false, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute);
dsinclairf27aeec2016-06-07 19:36:18 -07001002 pArguments->GetReturnValue()->Assign(pValue.get());
Dan Sinclair1770c022016-03-14 14:14:16 -04001003 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001004 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04001005 }
1006 }
1007}
weili44f8faf2016-06-01 14:03:56 -07001008
Dan Sinclair1770c022016-03-14 14:14:16 -04001009void CXFA_Node::Script_TreeClass_ResolveNodes(CFXJSE_Arguments* pArguments) {
1010 int32_t iLength = pArguments->GetLength();
1011 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001012 ThrowParamCountMismatchException(L"resolveNodes");
Dan Sinclair1770c022016-03-14 14:14:16 -04001013 return;
1014 }
tsepez6fe7d212016-04-06 10:51:14 -07001015 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001016 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
dsinclair12a6b0c2016-05-26 11:14:08 -07001017 CFXJSE_Value* pValue = pArguments->GetReturnValue();
weili44f8faf2016-06-01 14:03:56 -07001018 if (!pValue)
Dan Sinclair1770c022016-03-14 14:14:16 -04001019 return;
tsepez736f28a2016-03-25 14:19:51 -07001020 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
Dan Sinclair1770c022016-03-14 14:14:16 -04001021 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1022 XFA_RESOLVENODE_Siblings;
1023 CXFA_Node* refNode = this;
dsinclair070fcdf2016-06-22 22:04:54 -07001024 if (refNode->GetElementType() == XFA_Element::Xfa)
Dan Sinclair1770c022016-03-14 14:14:16 -04001025 refNode = ToNode(m_pDocument->GetScriptContext()->GetThisObject());
dsinclair12a6b0c2016-05-26 11:14:08 -07001026 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag, refNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04001027}
weili44f8faf2016-06-01 14:03:56 -07001028
dsinclair12a6b0c2016-05-26 11:14:08 -07001029void CXFA_Node::Script_Som_ResolveNodeList(CFXJSE_Value* pValue,
Dan Sinclair1770c022016-03-14 14:14:16 -04001030 CFX_WideString wsExpression,
tsepez736f28a2016-03-25 14:19:51 -07001031 uint32_t dwFlag,
Dan Sinclair1770c022016-03-14 14:14:16 -04001032 CXFA_Node* refNode) {
dsinclairdf4bc592016-03-31 20:34:43 -07001033 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001034 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001035 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001036 XFA_RESOLVENODE_RS resoveNodeRS;
weili44f8faf2016-06-01 14:03:56 -07001037 if (!refNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04001038 refNode = this;
tsepez4c3debb2016-04-08 12:20:38 -07001039 pScriptContext->ResolveObjects(refNode, wsExpression.AsStringC(),
tsepezfc58ad12016-04-05 12:22:15 -07001040 resoveNodeRS, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001041 CXFA_ArrayNodeList* pNodeList = new CXFA_ArrayNodeList(m_pDocument);
1042 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
Tom Sepezf8a94392017-03-14 12:13:22 -07001043 for (CXFA_Object* pObject : resoveNodeRS.objects) {
1044 if (pObject->IsNode())
1045 pNodeList->Append(pObject->AsNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001046 }
1047 } else {
dsinclair12a6b0c2016-05-26 11:14:08 -07001048 CXFA_ValueArray valueArray(pScriptContext->GetRuntime());
Tom Sepez369fe1f2017-03-27 16:03:43 -07001049 if (resoveNodeRS.GetAttributeResult(&valueArray) > 0) {
Tom Sepezf8a94392017-03-14 12:13:22 -07001050 for (CXFA_Object* pObject : valueArray.GetAttributeObject()) {
1051 if (pObject->IsNode())
1052 pNodeList->Append(pObject->AsNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001053 }
1054 }
1055 }
dsinclairf27aeec2016-06-07 19:36:18 -07001056 pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001057}
weili44f8faf2016-06-01 14:03:56 -07001058
dsinclair12a6b0c2016-05-26 11:14:08 -07001059void CXFA_Node::Script_TreeClass_All(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001060 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001061 XFA_ATTRIBUTE eAttribute) {
1062 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001063 ThrowInvalidPropertyException();
1064 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001065 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001066
1067 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
1068 CFX_WideString wsName;
1069 GetAttribute(XFA_ATTRIBUTE_Name, wsName);
dan sinclair65c7c232017-02-02 14:05:30 -08001070 CFX_WideString wsExpression = wsName + L"[*]";
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001071 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001072}
weili44f8faf2016-06-01 14:03:56 -07001073
dsinclair12a6b0c2016-05-26 11:14:08 -07001074void CXFA_Node::Script_TreeClass_Nodes(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001075 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001076 XFA_ATTRIBUTE eAttribute) {
dsinclairdf4bc592016-03-31 20:34:43 -07001077 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
weili44f8faf2016-06-01 14:03:56 -07001078 if (!pScriptContext)
Dan Sinclair1770c022016-03-14 14:14:16 -04001079 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001080 if (bSetting) {
Dan Sinclairc8fd3312017-01-02 17:17:02 -05001081 CFX_WideString wsMessage = L"Unable to set ";
Tom Sepezf0b65542017-02-13 10:26:01 -08001082 FXJSE_ThrowMessage(wsMessage.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001083 } else {
1084 CXFA_AttachNodeList* pNodeList = new CXFA_AttachNodeList(m_pDocument, this);
dsinclairf27aeec2016-06-07 19:36:18 -07001085 pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001086 }
1087}
weili44f8faf2016-06-01 14:03:56 -07001088
dsinclair12a6b0c2016-05-26 11:14:08 -07001089void CXFA_Node::Script_TreeClass_ClassAll(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001090 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001091 XFA_ATTRIBUTE eAttribute) {
1092 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001093 ThrowInvalidPropertyException();
1094 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001095 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001096 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
dan sinclair65c7c232017-02-02 14:05:30 -08001097 CFX_WideString wsExpression = L"#" + GetClassName() + L"[*]";
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001098 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
Dan Sinclair1770c022016-03-14 14:14:16 -04001099}
weili44f8faf2016-06-01 14:03:56 -07001100
dsinclair12a6b0c2016-05-26 11:14:08 -07001101void CXFA_Node::Script_TreeClass_Parent(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001102 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001103 XFA_ATTRIBUTE eAttribute) {
1104 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001105 ThrowInvalidPropertyException();
1106 return;
1107 }
1108 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
1109 if (pParent) {
1110 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pParent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001111 } else {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001112 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04001113 }
1114}
weili44f8faf2016-06-01 14:03:56 -07001115
dsinclair12a6b0c2016-05-26 11:14:08 -07001116void CXFA_Node::Script_TreeClass_Index(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001117 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001118 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001119 if (bSetting) {
1120 ThrowInvalidPropertyException();
1121 return;
1122 }
1123 pValue->SetInteger(GetNodeSameNameIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04001124}
weili44f8faf2016-06-01 14:03:56 -07001125
dsinclair12a6b0c2016-05-26 11:14:08 -07001126void CXFA_Node::Script_TreeClass_ClassIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001127 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001128 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001129 if (bSetting) {
1130 ThrowInvalidPropertyException();
1131 return;
1132 }
1133 pValue->SetInteger(GetNodeSameClassIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04001134}
weili44f8faf2016-06-01 14:03:56 -07001135
dsinclair12a6b0c2016-05-26 11:14:08 -07001136void CXFA_Node::Script_TreeClass_SomExpression(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001137 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001138 XFA_ATTRIBUTE eAttribute) {
1139 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001140 ThrowInvalidPropertyException();
1141 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001142 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001143 CFX_WideString wsSOMExpression;
1144 GetSOMExpression(wsSOMExpression);
Tom Sepezf0b65542017-02-13 10:26:01 -08001145 pValue->SetString(wsSOMExpression.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001146}
weili44f8faf2016-06-01 14:03:56 -07001147
Dan Sinclair1770c022016-03-14 14:14:16 -04001148void CXFA_Node::Script_NodeClass_ApplyXSL(CFXJSE_Arguments* pArguments) {
1149 int32_t iLength = pArguments->GetLength();
1150 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001151 ThrowParamCountMismatchException(L"applyXSL");
Dan Sinclair1770c022016-03-14 14:14:16 -04001152 return;
1153 }
tsepez6fe7d212016-04-06 10:51:14 -07001154 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001155 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
weili60607c32016-05-26 11:53:12 -07001156 // TODO(weili): check whether we need to implement this, pdfium:501.
1157 // For now, just put the variables here to avoid unused variable warning.
1158 (void)wsExpression;
Dan Sinclair1770c022016-03-14 14:14:16 -04001159}
weili60607c32016-05-26 11:53:12 -07001160
Dan Sinclair1770c022016-03-14 14:14:16 -04001161void CXFA_Node::Script_NodeClass_AssignNode(CFXJSE_Arguments* pArguments) {
1162 int32_t iLength = pArguments->GetLength();
1163 if (iLength < 1 || iLength > 3) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001164 ThrowParamCountMismatchException(L"assignNode");
Dan Sinclair1770c022016-03-14 14:14:16 -04001165 return;
1166 }
1167 CFX_WideString wsExpression;
1168 CFX_WideString wsValue;
1169 int32_t iAction = 0;
weili44f8faf2016-06-01 14:03:56 -07001170 wsExpression =
1171 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001172 if (iLength >= 2) {
weili60607c32016-05-26 11:53:12 -07001173 wsValue =
1174 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001175 }
weili60607c32016-05-26 11:53:12 -07001176 if (iLength >= 3)
Dan Sinclair1770c022016-03-14 14:14:16 -04001177 iAction = pArguments->GetInt32(2);
weili60607c32016-05-26 11:53:12 -07001178 // TODO(weili): check whether we need to implement this, pdfium:501.
1179 // For now, just put the variables here to avoid unused variable warning.
1180 (void)wsExpression;
1181 (void)wsValue;
1182 (void)iAction;
Dan Sinclair1770c022016-03-14 14:14:16 -04001183}
weili60607c32016-05-26 11:53:12 -07001184
Dan Sinclair1770c022016-03-14 14:14:16 -04001185void CXFA_Node::Script_NodeClass_Clone(CFXJSE_Arguments* pArguments) {
1186 int32_t iLength = pArguments->GetLength();
1187 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001188 ThrowParamCountMismatchException(L"clone");
Dan Sinclair1770c022016-03-14 14:14:16 -04001189 return;
1190 }
weili44f8faf2016-06-01 14:03:56 -07001191 bool bClone = !!pArguments->GetInt32(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04001192 CXFA_Node* pCloneNode = Clone(bClone);
dsinclairf27aeec2016-06-07 19:36:18 -07001193 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04001194 m_pDocument->GetScriptContext()->GetJSValueFromMap(pCloneNode));
1195}
weili44f8faf2016-06-01 14:03:56 -07001196
Dan Sinclair1770c022016-03-14 14:14:16 -04001197void CXFA_Node::Script_NodeClass_GetAttribute(CFXJSE_Arguments* pArguments) {
1198 int32_t iLength = pArguments->GetLength();
1199 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001200 ThrowParamCountMismatchException(L"getAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001201 return;
1202 }
tsepez6fe7d212016-04-06 10:51:14 -07001203 CFX_WideString wsExpression =
tsepez4c3debb2016-04-08 12:20:38 -07001204 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001205 CFX_WideString wsValue;
tsepez4c3debb2016-04-08 12:20:38 -07001206 GetAttribute(wsExpression.AsStringC(), wsValue);
dsinclair12a6b0c2016-05-26 11:14:08 -07001207 CFXJSE_Value* pValue = pArguments->GetReturnValue();
weili44f8faf2016-06-01 14:03:56 -07001208 if (pValue)
Tom Sepezf0b65542017-02-13 10:26:01 -08001209 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001210}
weili44f8faf2016-06-01 14:03:56 -07001211
Dan Sinclair1770c022016-03-14 14:14:16 -04001212void CXFA_Node::Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments) {
1213 int32_t iLength = pArguments->GetLength();
1214 if (iLength < 1 || iLength > 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001215 ThrowParamCountMismatchException(L"getElement");
Dan Sinclair1770c022016-03-14 14:14:16 -04001216 return;
1217 }
1218 CFX_WideString wsExpression;
1219 int32_t iValue = 0;
weili44f8faf2016-06-01 14:03:56 -07001220 wsExpression =
1221 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
1222 if (iLength >= 2)
Dan Sinclair1770c022016-03-14 14:14:16 -04001223 iValue = pArguments->GetInt32(1);
dsinclair6e124782016-06-23 12:14:55 -07001224 CXFA_Node* pNode =
1225 GetProperty(iValue, XFA_GetElementTypeForName(wsExpression.AsStringC()));
dsinclairf27aeec2016-06-07 19:36:18 -07001226 pArguments->GetReturnValue()->Assign(
1227 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04001228}
weili65be4b12016-05-25 15:47:43 -07001229
Dan Sinclair1770c022016-03-14 14:14:16 -04001230void CXFA_Node::Script_NodeClass_IsPropertySpecified(
1231 CFXJSE_Arguments* pArguments) {
1232 int32_t iLength = pArguments->GetLength();
1233 if (iLength < 1 || iLength > 3) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001234 ThrowParamCountMismatchException(L"isPropertySpecified");
Dan Sinclair1770c022016-03-14 14:14:16 -04001235 return;
1236 }
1237 CFX_WideString wsExpression;
weili44f8faf2016-06-01 14:03:56 -07001238 bool bParent = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001239 int32_t iIndex = 0;
weili44f8faf2016-06-01 14:03:56 -07001240 wsExpression =
1241 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
weili65be4b12016-05-25 15:47:43 -07001242 if (iLength >= 2)
weili44f8faf2016-06-01 14:03:56 -07001243 bParent = !!pArguments->GetInt32(1);
weili65be4b12016-05-25 15:47:43 -07001244 if (iLength >= 3)
Dan Sinclair1770c022016-03-14 14:14:16 -04001245 iIndex = pArguments->GetInt32(2);
tsepezd19e9122016-11-02 15:43:18 -07001246 bool bHas = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001247 const XFA_ATTRIBUTEINFO* pAttributeInfo =
tsepez4c3debb2016-04-08 12:20:38 -07001248 XFA_GetAttributeByName(wsExpression.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001249 CFX_WideString wsValue;
weili65be4b12016-05-25 15:47:43 -07001250 if (pAttributeInfo)
Dan Sinclair1770c022016-03-14 14:14:16 -04001251 bHas = HasAttribute(pAttributeInfo->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04001252 if (!bHas) {
dsinclair6e124782016-06-23 12:14:55 -07001253 XFA_Element eType = XFA_GetElementTypeForName(wsExpression.AsStringC());
1254 bHas = !!GetProperty(iIndex, eType);
weili65be4b12016-05-25 15:47:43 -07001255 if (!bHas && bParent && m_pParent) {
1256 // Also check on the parent.
1257 bHas = m_pParent->HasAttribute(pAttributeInfo->eName);
1258 if (!bHas)
dsinclair6e124782016-06-23 12:14:55 -07001259 bHas = !!m_pParent->GetProperty(iIndex, eType);
weili65be4b12016-05-25 15:47:43 -07001260 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001261 }
dsinclair12a6b0c2016-05-26 11:14:08 -07001262 CFXJSE_Value* pValue = pArguments->GetReturnValue();
1263 if (pValue)
dsinclairf27aeec2016-06-07 19:36:18 -07001264 pValue->SetBoolean(bHas);
Dan Sinclair1770c022016-03-14 14:14:16 -04001265}
weili65be4b12016-05-25 15:47:43 -07001266
Dan Sinclair1770c022016-03-14 14:14:16 -04001267void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) {
1268 int32_t iLength = pArguments->GetLength();
1269 if (iLength < 1 || iLength > 3) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001270 ThrowParamCountMismatchException(L"loadXML");
Dan Sinclair1770c022016-03-14 14:14:16 -04001271 return;
1272 }
1273 CFX_WideString wsExpression;
weili44f8faf2016-06-01 14:03:56 -07001274 bool bIgnoreRoot = true;
1275 bool bOverwrite = 0;
1276 wsExpression =
1277 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
1278 if (wsExpression.IsEmpty())
Tom Sepezd3743ea2016-05-16 15:56:53 -07001279 return;
weili44f8faf2016-06-01 14:03:56 -07001280 if (iLength >= 2)
1281 bIgnoreRoot = !!pArguments->GetInt32(1);
1282 if (iLength >= 3)
1283 bOverwrite = !!pArguments->GetInt32(2);
dsinclaira1b07722016-07-11 08:20:58 -07001284 std::unique_ptr<CXFA_SimpleParser> pParser(
1285 new CXFA_SimpleParser(m_pDocument, false));
weili44f8faf2016-06-01 14:03:56 -07001286 if (!pParser)
Dan Sinclair1770c022016-03-14 14:14:16 -04001287 return;
weili44f8faf2016-06-01 14:03:56 -07001288 CFDE_XMLNode* pXMLNode = nullptr;
1289 int32_t iParserStatus =
1290 pParser->ParseXMLData(wsExpression, pXMLNode, nullptr);
1291 if (iParserStatus != XFA_PARSESTATUS_Done || !pXMLNode)
1292 return;
dsinclairae95f762016-03-29 16:58:29 -07001293 if (bIgnoreRoot &&
1294 (pXMLNode->GetType() != FDE_XMLNODE_Element ||
1295 XFA_RecognizeRichText(static_cast<CFDE_XMLElement*>(pXMLNode)))) {
weili44f8faf2016-06-01 14:03:56 -07001296 bIgnoreRoot = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001297 }
tsepezd19e9122016-11-02 15:43:18 -07001298 CXFA_Node* pFakeRoot = Clone(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001299 CFX_WideStringC wsContentType = GetCData(XFA_ATTRIBUTE_ContentType);
1300 if (!wsContentType.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07001301 pFakeRoot->SetCData(XFA_ATTRIBUTE_ContentType,
1302 CFX_WideString(wsContentType));
Dan Sinclair1770c022016-03-14 14:14:16 -04001303 }
dsinclairae95f762016-03-29 16:58:29 -07001304 CFDE_XMLNode* pFakeXMLRoot = pFakeRoot->GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04001305 if (!pFakeXMLRoot) {
dsinclairae95f762016-03-29 16:58:29 -07001306 CFDE_XMLNode* pThisXMLRoot = GetXMLMappingNode();
tsepezd19e9122016-11-02 15:43:18 -07001307 pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone(false) : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001308 }
dsinclair017052a2016-06-28 07:43:51 -07001309 if (!pFakeXMLRoot)
1310 pFakeXMLRoot = new CFDE_XMLElement(CFX_WideString(GetClassName()));
1311
Dan Sinclair1770c022016-03-14 14:14:16 -04001312 if (bIgnoreRoot) {
dsinclairae95f762016-03-29 16:58:29 -07001313 CFDE_XMLNode* pXMLChild = pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild);
Dan Sinclair1770c022016-03-14 14:14:16 -04001314 while (pXMLChild) {
dsinclairae95f762016-03-29 16:58:29 -07001315 CFDE_XMLNode* pXMLSibling =
1316 pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling);
Dan Sinclair1770c022016-03-14 14:14:16 -04001317 pXMLNode->RemoveChildNode(pXMLChild);
1318 pFakeXMLRoot->InsertChildNode(pXMLChild);
1319 pXMLChild = pXMLSibling;
1320 }
1321 } else {
dsinclairae95f762016-03-29 16:58:29 -07001322 CFDE_XMLNode* pXMLParent = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001323 if (pXMLParent) {
1324 pXMLParent->RemoveChildNode(pXMLNode);
1325 }
1326 pFakeXMLRoot->InsertChildNode(pXMLNode);
1327 }
1328 pParser->ConstructXFANode(pFakeRoot, pFakeXMLRoot);
1329 pFakeRoot = pParser->GetRootNode();
1330 if (pFakeRoot) {
1331 if (bOverwrite) {
1332 CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild);
1333 CXFA_Node* pNewChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
1334 int32_t index = 0;
1335 while (pNewChild) {
1336 CXFA_Node* pItem = pNewChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1337 pFakeRoot->RemoveChild(pNewChild);
1338 InsertChild(index++, pNewChild);
dsinclairc5a8f212016-06-20 11:11:12 -07001339 pNewChild->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001340 pNewChild = pItem;
1341 }
1342 while (pChild) {
1343 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1344 RemoveChild(pChild);
1345 pFakeRoot->InsertChild(pChild);
1346 pChild = pItem;
1347 }
1348 if (GetPacketID() == XFA_XDPPACKET_Form &&
dsinclair070fcdf2016-06-22 22:04:54 -07001349 GetElementType() == XFA_Element::ExData) {
dsinclairae95f762016-03-29 16:58:29 -07001350 CFDE_XMLNode* pTempXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04001351 SetXMLMappingNode(pFakeXMLRoot);
dsinclairc5a8f212016-06-20 11:11:12 -07001352 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
weili44f8faf2016-06-01 14:03:56 -07001353 if (pTempXMLNode && !pTempXMLNode->GetNodeItem(CFDE_XMLNode::Parent)) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001354 pFakeXMLRoot = pTempXMLNode;
1355 } else {
weili44f8faf2016-06-01 14:03:56 -07001356 pFakeXMLRoot = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001357 }
1358 }
tsepezd19e9122016-11-02 15:43:18 -07001359 MoveBufferMapData(pFakeRoot, this, XFA_CalcData, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001360 } else {
1361 CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
1362 while (pChild) {
1363 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1364 pFakeRoot->RemoveChild(pChild);
1365 InsertChild(pChild);
dsinclairc5a8f212016-06-20 11:11:12 -07001366 pChild->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001367 pChild = pItem;
1368 }
1369 }
1370 if (pFakeXMLRoot) {
1371 pFakeRoot->SetXMLMappingNode(pFakeXMLRoot);
dsinclairc5a8f212016-06-20 11:11:12 -07001372 pFakeRoot->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001373 }
dsinclairc5a8f212016-06-20 11:11:12 -07001374 pFakeRoot->SetFlag(XFA_NodeFlag_HasRemovedChildren, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001375 } else {
tsepezc757d9a2017-01-23 11:01:42 -08001376 delete pFakeXMLRoot;
1377 pFakeXMLRoot = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001378 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001379}
weili44f8faf2016-06-01 14:03:56 -07001380
Dan Sinclair1770c022016-03-14 14:14:16 -04001381void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) {
weili44f8faf2016-06-01 14:03:56 -07001382 // TODO(weili): Check whether we need to implement this, pdfium:501.
Dan Sinclair1770c022016-03-14 14:14:16 -04001383}
1384
1385void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) {
1386 int32_t iLength = pArguments->GetLength();
1387 if (iLength < 0 || iLength > 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001388 ThrowParamCountMismatchException(L"saveXML");
Dan Sinclair1770c022016-03-14 14:14:16 -04001389 return;
1390 }
weili44f8faf2016-06-01 14:03:56 -07001391 bool bPrettyMode = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001392 if (iLength == 1) {
weili65be4b12016-05-25 15:47:43 -07001393 if (pArguments->GetUTF8String(0) != "pretty") {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001394 ThrowArgumentMismatchException();
Dan Sinclair1770c022016-03-14 14:14:16 -04001395 return;
1396 }
weili44f8faf2016-06-01 14:03:56 -07001397 bPrettyMode = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001398 }
1399 CFX_ByteStringC bsXMLHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
weili65be4b12016-05-25 15:47:43 -07001400 if (GetPacketID() == XFA_XDPPACKET_Form ||
1401 GetPacketID() == XFA_XDPPACKET_Datasets) {
1402 CFDE_XMLNode* pElement = nullptr;
1403 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
1404 pElement = GetXMLMappingNode();
1405 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) {
dsinclairf27aeec2016-06-07 19:36:18 -07001406 pArguments->GetReturnValue()->SetString(bsXMLHeader);
weili65be4b12016-05-25 15:47:43 -07001407 return;
1408 }
1409 XFA_DataExporter_DealWithDataGroupNode(this);
1410 }
tsepez833619b2016-12-07 09:21:17 -08001411 CFX_RetainPtr<IFX_MemoryStream> pMemoryStream =
1412 IFX_MemoryStream::Create(true);
1413
1414 // Note: ambiguious below without static_cast.
tsepez7cda31a2016-12-07 12:10:20 -08001415 CFX_RetainPtr<IFGAS_Stream> pStream = IFGAS_Stream::CreateStream(
1416 CFX_RetainPtr<IFX_SeekableWriteStream>(pMemoryStream),
1417 FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append);
tsepez833619b2016-12-07 09:21:17 -08001418
Dan Sinclair1770c022016-03-14 14:14:16 -04001419 if (!pStream) {
dsinclairf27aeec2016-06-07 19:36:18 -07001420 pArguments->GetReturnValue()->SetString(bsXMLHeader);
Dan Sinclair1770c022016-03-14 14:14:16 -04001421 return;
1422 }
1423 pStream->SetCodePage(FX_CODEPAGE_UTF8);
dsinclair179bebb2016-04-05 11:02:18 -07001424 pStream->WriteData(bsXMLHeader.raw_str(), bsXMLHeader.GetLength());
weili65be4b12016-05-25 15:47:43 -07001425 if (GetPacketID() == XFA_XDPPACKET_Form)
tsepez7cda31a2016-12-07 12:10:20 -08001426 XFA_DataExporter_RegenerateFormFile(this, pStream, nullptr, true);
weili65be4b12016-05-25 15:47:43 -07001427 else
tsepez7cda31a2016-12-07 12:10:20 -08001428 pElement->SaveXMLNode(pStream);
weili65be4b12016-05-25 15:47:43 -07001429 // TODO(weili): Check whether we need to save pretty print XML, pdfium:501.
1430 // For now, just put it here to avoid unused variable warning.
1431 (void)bPrettyMode;
dsinclairf27aeec2016-06-07 19:36:18 -07001432 pArguments->GetReturnValue()->SetString(
Dan Sinclair1770c022016-03-14 14:14:16 -04001433 CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001434 return;
1435 }
dsinclairf27aeec2016-06-07 19:36:18 -07001436 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04001437}
1438
1439void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) {
1440 int32_t iLength = pArguments->GetLength();
1441 if (iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001442 ThrowParamCountMismatchException(L"setAttribute");
Dan Sinclair1770c022016-03-14 14:14:16 -04001443 return;
1444 }
tsepez6fe7d212016-04-06 10:51:14 -07001445 CFX_WideString wsAttributeValue =
tsepez4c3debb2016-04-08 12:20:38 -07001446 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
tsepez6fe7d212016-04-06 10:51:14 -07001447 CFX_WideString wsAttribute =
tsepez4c3debb2016-04-08 12:20:38 -07001448 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili44f8faf2016-06-01 14:03:56 -07001449 SetAttribute(wsAttribute.AsStringC(), wsAttributeValue.AsStringC(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001450}
weili60607c32016-05-26 11:53:12 -07001451
Dan Sinclair1770c022016-03-14 14:14:16 -04001452void CXFA_Node::Script_NodeClass_SetElement(CFXJSE_Arguments* pArguments) {
1453 int32_t iLength = pArguments->GetLength();
1454 if (iLength != 1 && iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001455 ThrowParamCountMismatchException(L"setElement");
Dan Sinclair1770c022016-03-14 14:14:16 -04001456 return;
1457 }
weili60607c32016-05-26 11:53:12 -07001458 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001459 CFX_WideString wsName;
weili44f8faf2016-06-01 14:03:56 -07001460 pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
1461 if (iLength == 2)
weili60607c32016-05-26 11:53:12 -07001462 wsName = CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
weili60607c32016-05-26 11:53:12 -07001463 // TODO(weili): check whether we need to implement this, pdfium:501.
1464 // For now, just put the variables here to avoid unused variable warning.
1465 (void)pNode;
1466 (void)wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04001467}
weili60607c32016-05-26 11:53:12 -07001468
dsinclair12a6b0c2016-05-26 11:14:08 -07001469void CXFA_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001470 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001471 XFA_ATTRIBUTE eAttribute) {
1472 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001473 ThrowInvalidPropertyException();
1474 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001475 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001476
1477 CFX_WideString wsNameSpace;
1478 TryNamespace(wsNameSpace);
Tom Sepezf0b65542017-02-13 10:26:01 -08001479 pValue->SetString(wsNameSpace.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001480}
weili44f8faf2016-06-01 14:03:56 -07001481
dsinclair12a6b0c2016-05-26 11:14:08 -07001482void CXFA_Node::Script_NodeClass_Model(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001483 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001484 XFA_ATTRIBUTE eAttribute) {
1485 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001486 ThrowInvalidPropertyException();
1487 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001488 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001489 pValue->Assign(
1490 m_pDocument->GetScriptContext()->GetJSValueFromMap(GetModelNode()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001491}
weili44f8faf2016-06-01 14:03:56 -07001492
dsinclair12a6b0c2016-05-26 11:14:08 -07001493void CXFA_Node::Script_NodeClass_IsContainer(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001494 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001495 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001496 if (bSetting) {
1497 ThrowInvalidPropertyException();
1498 return;
1499 }
1500 pValue->SetBoolean(IsContainerNode());
Dan Sinclair1770c022016-03-14 14:14:16 -04001501}
weili44f8faf2016-06-01 14:03:56 -07001502
dsinclair12a6b0c2016-05-26 11:14:08 -07001503void CXFA_Node::Script_NodeClass_IsNull(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001504 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001505 XFA_ATTRIBUTE eAttribute) {
1506 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001507 ThrowInvalidPropertyException();
1508 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001509 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001510 if (GetElementType() == XFA_Element::Subform) {
1511 pValue->SetBoolean(false);
1512 return;
1513 }
1514 CFX_WideString strValue;
1515 pValue->SetBoolean(!TryContent(strValue) || strValue.IsEmpty());
Dan Sinclair1770c022016-03-14 14:14:16 -04001516}
weili44f8faf2016-06-01 14:03:56 -07001517
dsinclair12a6b0c2016-05-26 11:14:08 -07001518void CXFA_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001519 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001520 XFA_ATTRIBUTE eAttribute) {
1521 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001522 ThrowInvalidPropertyException();
1523 return;
1524 }
Tom Sepezf8a94392017-03-14 12:13:22 -07001525 std::vector<CXFA_Node*> properties =
1526 GetNodeList(XFA_NODEFILTER_OneOfProperty);
1527 if (!properties.empty()) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001528 pValue->Assign(
Tom Sepezf8a94392017-03-14 12:13:22 -07001529 m_pDocument->GetScriptContext()->GetJSValueFromMap(properties.front()));
Dan Sinclair1770c022016-03-14 14:14:16 -04001530 }
1531}
weili44f8faf2016-06-01 14:03:56 -07001532
Dan Sinclair1770c022016-03-14 14:14:16 -04001533void CXFA_Node::Script_ContainerClass_GetDelta(CFXJSE_Arguments* pArguments) {}
dsinclairf27aeec2016-06-07 19:36:18 -07001534
Dan Sinclair1770c022016-03-14 14:14:16 -04001535void CXFA_Node::Script_ContainerClass_GetDeltas(CFXJSE_Arguments* pArguments) {
1536 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
dsinclairf27aeec2016-06-07 19:36:18 -07001537 pArguments->GetReturnValue()->SetObject(
1538 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04001539}
1540void CXFA_Node::Script_ModelClass_ClearErrorList(CFXJSE_Arguments* pArguments) {
1541}
dsinclair5b36f0a2016-07-19 10:56:23 -07001542
Dan Sinclair1770c022016-03-14 14:14:16 -04001543void CXFA_Node::Script_ModelClass_CreateNode(CFXJSE_Arguments* pArguments) {
1544 Script_Template_CreateNode(pArguments);
1545}
dsinclair5b36f0a2016-07-19 10:56:23 -07001546
Dan Sinclair1770c022016-03-14 14:14:16 -04001547void CXFA_Node::Script_ModelClass_IsCompatibleNS(CFXJSE_Arguments* pArguments) {
1548 int32_t iLength = pArguments->GetLength();
1549 if (iLength < 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001550 ThrowParamCountMismatchException(L"isCompatibleNS");
Dan Sinclair1770c022016-03-14 14:14:16 -04001551 return;
1552 }
1553 CFX_WideString wsNameSpace;
1554 if (iLength >= 1) {
1555 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07001556 wsNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001557 }
1558 CFX_WideString wsNodeNameSpace;
1559 TryNamespace(wsNodeNameSpace);
dsinclair12a6b0c2016-05-26 11:14:08 -07001560 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07001561 if (pValue)
1562 pValue->SetBoolean(wsNodeNameSpace == wsNameSpace);
Dan Sinclair1770c022016-03-14 14:14:16 -04001563}
dsinclair5b36f0a2016-07-19 10:56:23 -07001564
dsinclair12a6b0c2016-05-26 11:14:08 -07001565void CXFA_Node::Script_ModelClass_Context(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001566 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001567 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001568
dsinclair12a6b0c2016-05-26 11:14:08 -07001569void CXFA_Node::Script_ModelClass_AliasNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001570 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001571 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001572
dsinclair12a6b0c2016-05-26 11:14:08 -07001573void CXFA_Node::Script_Attribute_Integer(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001574 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001575 XFA_ATTRIBUTE eAttribute) {
1576 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001577 SetInteger(eAttribute, pValue->ToInteger(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001578 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001579 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001580 }
1581}
dsinclair5b36f0a2016-07-19 10:56:23 -07001582
dsinclair12a6b0c2016-05-26 11:14:08 -07001583void CXFA_Node::Script_Attribute_IntegerRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001584 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001585 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001586 if (bSetting) {
1587 ThrowInvalidPropertyException();
1588 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001589 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001590 pValue->SetInteger(GetInteger(eAttribute));
Dan Sinclair1770c022016-03-14 14:14:16 -04001591}
dsinclair5b36f0a2016-07-19 10:56:23 -07001592
dsinclair12a6b0c2016-05-26 11:14:08 -07001593void CXFA_Node::Script_Attribute_BOOL(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001594 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001595 XFA_ATTRIBUTE eAttribute) {
1596 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07001597 SetBoolean(eAttribute, pValue->ToBoolean(), true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001598 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07001599 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001600 }
1601}
dsinclair5b36f0a2016-07-19 10:56:23 -07001602
dsinclair12a6b0c2016-05-26 11:14:08 -07001603void CXFA_Node::Script_Attribute_BOOLRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001604 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001605 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001606 if (bSetting) {
1607 ThrowInvalidPropertyException();
1608 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001609 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001610 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
Dan Sinclair1770c022016-03-14 14:14:16 -04001611}
thestigb1a59592016-04-14 18:29:56 -07001612
Dan Sinclair1770c022016-03-14 14:14:16 -04001613void CXFA_Node::Script_Attribute_SendAttributeChangeMessage(
thestigb1a59592016-04-14 18:29:56 -07001614 XFA_ATTRIBUTE eAttribute,
tsepezd19e9122016-11-02 15:43:18 -07001615 bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001616 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
thestigb1a59592016-04-14 18:29:56 -07001617 if (!pLayoutPro)
Dan Sinclair1770c022016-03-14 14:14:16 -04001618 return;
thestigb1a59592016-04-14 18:29:56 -07001619
dsinclaira1b07722016-07-11 08:20:58 -07001620 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07001621 if (!pNotify)
1622 return;
1623
1624 uint32_t dwPacket = GetPacketID();
1625 if (!(dwPacket & XFA_XDPPACKET_Form)) {
1626 pNotify->OnValueChanged(this, eAttribute, this, this);
Dan Sinclair1770c022016-03-14 14:14:16 -04001627 return;
1628 }
thestigb1a59592016-04-14 18:29:56 -07001629
1630 bool bNeedFindContainer = false;
dsinclair41cb62e2016-06-23 09:20:32 -07001631 switch (GetElementType()) {
dsinclair56a8b192016-06-21 14:15:25 -07001632 case XFA_Element::Caption:
thestigb1a59592016-04-14 18:29:56 -07001633 bNeedFindContainer = true;
1634 pNotify->OnValueChanged(this, eAttribute, this,
1635 GetNodeItem(XFA_NODEITEM_Parent));
1636 break;
dsinclair56a8b192016-06-21 14:15:25 -07001637 case XFA_Element::Font:
1638 case XFA_Element::Para: {
thestigb1a59592016-04-14 18:29:56 -07001639 bNeedFindContainer = true;
1640 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001641 if (pParentNode->GetElementType() == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001642 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1643 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1644 } else {
1645 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
1646 }
1647 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001648 case XFA_Element::Margin: {
thestigb1a59592016-04-14 18:29:56 -07001649 bNeedFindContainer = true;
1650 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001651 XFA_Element eParentType = pParentNode->GetElementType();
thestigb1a59592016-04-14 18:29:56 -07001652 if (pParentNode->IsContainerNode()) {
1653 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
dsinclair56a8b192016-06-21 14:15:25 -07001654 } else if (eParentType == XFA_Element::Caption) {
thestigb1a59592016-04-14 18:29:56 -07001655 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1656 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1657 } else {
1658 CXFA_Node* pNode = pParentNode->GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001659 if (pNode && pNode->GetElementType() == XFA_Element::Ui) {
thestigb1a59592016-04-14 18:29:56 -07001660 pNotify->OnValueChanged(this, eAttribute, pNode,
1661 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001662 }
thestigb1a59592016-04-14 18:29:56 -07001663 }
1664 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001665 case XFA_Element::Comb: {
thestigb1a59592016-04-14 18:29:56 -07001666 CXFA_Node* pEditNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07001667 XFA_Element eUIType = pEditNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07001668 if (pEditNode && (eUIType == XFA_Element::DateTimeEdit ||
1669 eUIType == XFA_Element::NumericEdit ||
1670 eUIType == XFA_Element::TextEdit)) {
thestigb1a59592016-04-14 18:29:56 -07001671 CXFA_Node* pUINode = pEditNode->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001672 if (pUINode) {
thestigb1a59592016-04-14 18:29:56 -07001673 pNotify->OnValueChanged(this, eAttribute, pUINode,
1674 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001675 }
thestigb1a59592016-04-14 18:29:56 -07001676 }
1677 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001678 case XFA_Element::Button:
1679 case XFA_Element::Barcode:
1680 case XFA_Element::ChoiceList:
1681 case XFA_Element::DateTimeEdit:
1682 case XFA_Element::NumericEdit:
1683 case XFA_Element::PasswordEdit:
1684 case XFA_Element::TextEdit: {
thestigb1a59592016-04-14 18:29:56 -07001685 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1686 if (pUINode) {
1687 pNotify->OnValueChanged(this, eAttribute, pUINode,
1688 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1689 }
1690 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001691 case XFA_Element::CheckButton: {
thestigb1a59592016-04-14 18:29:56 -07001692 bNeedFindContainer = true;
1693 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1694 if (pUINode) {
1695 pNotify->OnValueChanged(this, eAttribute, pUINode,
1696 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1697 }
1698 } break;
dsinclair56a8b192016-06-21 14:15:25 -07001699 case XFA_Element::Keep:
1700 case XFA_Element::Bookend:
1701 case XFA_Element::Break:
1702 case XFA_Element::BreakAfter:
1703 case XFA_Element::BreakBefore:
1704 case XFA_Element::Overflow:
thestigb1a59592016-04-14 18:29:56 -07001705 bNeedFindContainer = true;
1706 break;
dsinclair56a8b192016-06-21 14:15:25 -07001707 case XFA_Element::Area:
1708 case XFA_Element::Draw:
1709 case XFA_Element::ExclGroup:
1710 case XFA_Element::Field:
1711 case XFA_Element::Subform:
1712 case XFA_Element::SubformSet:
thestigb1a59592016-04-14 18:29:56 -07001713 pLayoutPro->AddChangedContainer(this);
1714 pNotify->OnValueChanged(this, eAttribute, this, this);
1715 break;
dsinclair56a8b192016-06-21 14:15:25 -07001716 case XFA_Element::Sharptext:
1717 case XFA_Element::Sharpxml:
1718 case XFA_Element::SharpxHTML: {
thestigb1a59592016-04-14 18:29:56 -07001719 CXFA_Node* pTextNode = GetNodeItem(XFA_NODEITEM_Parent);
1720 if (!pTextNode) {
1721 return;
1722 }
1723 CXFA_Node* pValueNode = pTextNode->GetNodeItem(XFA_NODEITEM_Parent);
1724 if (!pValueNode) {
1725 return;
1726 }
dsinclair41cb62e2016-06-23 09:20:32 -07001727 XFA_Element eType = pValueNode->GetElementType();
1728 if (eType == XFA_Element::Value) {
thestigb1a59592016-04-14 18:29:56 -07001729 bNeedFindContainer = true;
1730 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1731 if (pNode && pNode->IsContainerNode()) {
1732 if (bScriptModify) {
1733 pValueNode = pNode;
1734 }
1735 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
1736 } else {
1737 pNotify->OnValueChanged(this, eAttribute, pNode,
1738 pNode->GetNodeItem(XFA_NODEITEM_Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04001739 }
thestigb1a59592016-04-14 18:29:56 -07001740 } else {
dsinclair41cb62e2016-06-23 09:20:32 -07001741 if (eType == XFA_Element::Items) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001742 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1743 if (pNode && pNode->IsContainerNode()) {
thestigb1a59592016-04-14 18:29:56 -07001744 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04001745 }
1746 }
thestigb1a59592016-04-14 18:29:56 -07001747 }
1748 } break;
1749 default:
1750 break;
1751 }
1752 if (bNeedFindContainer) {
1753 CXFA_Node* pParent = this;
1754 while (pParent) {
1755 if (pParent->IsContainerNode())
Dan Sinclair1770c022016-03-14 14:14:16 -04001756 break;
thestigb1a59592016-04-14 18:29:56 -07001757
1758 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001759 }
thestigb1a59592016-04-14 18:29:56 -07001760 if (pParent) {
1761 pLayoutPro->AddChangedContainer(pParent);
Dan Sinclair1770c022016-03-14 14:14:16 -04001762 }
Dan Sinclair1770c022016-03-14 14:14:16 -04001763 }
1764}
thestigb1a59592016-04-14 18:29:56 -07001765
dsinclair12a6b0c2016-05-26 11:14:08 -07001766void CXFA_Node::Script_Attribute_String(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001767 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001768 XFA_ATTRIBUTE eAttribute) {
1769 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001770 CFX_WideString wsValue = pValue->ToWideString();
thestigb1a59592016-04-14 18:29:56 -07001771 SetAttribute(eAttribute, wsValue.AsStringC(), true);
dsinclair070fcdf2016-06-22 22:04:54 -07001772 if (eAttribute == XFA_ATTRIBUTE_Use &&
1773 GetElementType() == XFA_Element::Desc) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001774 CXFA_Node* pTemplateNode =
1775 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
1776 CXFA_Node* pProtoRoot =
dsinclair56a8b192016-06-21 14:15:25 -07001777 pTemplateNode->GetFirstChildByClass(XFA_Element::Subform)
1778 ->GetFirstChildByClass(XFA_Element::Proto);
dsinclair2f5582f2016-06-09 11:48:23 -07001779
1780 CFX_WideString wsID;
1781 CFX_WideString wsSOM;
1782 if (!wsValue.IsEmpty()) {
1783 if (wsValue[0] == '#') {
1784 wsID = CFX_WideString(wsValue.c_str() + 1, wsValue.GetLength() - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04001785 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07001786 wsSOM = wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04001787 }
1788 }
weili44f8faf2016-06-01 14:03:56 -07001789 CXFA_Node* pProtoNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001790 if (!wsSOM.IsEmpty()) {
tsepez736f28a2016-03-25 14:19:51 -07001791 uint32_t dwFlag = XFA_RESOLVENODE_Children |
Dan Sinclair1770c022016-03-14 14:14:16 -04001792 XFA_RESOLVENODE_Attributes |
1793 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1794 XFA_RESOLVENODE_Siblings;
1795 XFA_RESOLVENODE_RS resoveNodeRS;
1796 int32_t iRet = m_pDocument->GetScriptContext()->ResolveObjects(
tsepez4c3debb2016-04-08 12:20:38 -07001797 pProtoRoot, wsSOM.AsStringC(), resoveNodeRS, dwFlag);
Tom Sepezf8a94392017-03-14 12:13:22 -07001798 if (iRet > 0 && resoveNodeRS.objects.front()->IsNode()) {
1799 pProtoNode = resoveNodeRS.objects.front()->AsNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04001800 }
1801 } else if (!wsID.IsEmpty()) {
tsepez4c3debb2016-04-08 12:20:38 -07001802 pProtoNode = m_pDocument->GetNodeByID(pProtoRoot, wsID.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001803 }
1804 if (pProtoNode) {
1805 CXFA_Node* pHeadChild = GetNodeItem(XFA_NODEITEM_FirstChild);
1806 while (pHeadChild) {
1807 CXFA_Node* pSibling =
1808 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1809 RemoveChild(pHeadChild);
1810 pHeadChild = pSibling;
1811 }
tsepezd19e9122016-11-02 15:43:18 -07001812 CXFA_Node* pProtoForm = pProtoNode->CloneTemplateToForm(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001813 pHeadChild = pProtoForm->GetNodeItem(XFA_NODEITEM_FirstChild);
1814 while (pHeadChild) {
1815 CXFA_Node* pSibling =
1816 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1817 pProtoForm->RemoveChild(pHeadChild);
1818 InsertChild(pHeadChild);
1819 pHeadChild = pSibling;
1820 }
1821 m_pDocument->RemovePurgeNode(pProtoForm);
1822 delete pProtoForm;
1823 }
1824 }
1825 } else {
1826 CFX_WideString wsValue;
1827 GetAttribute(eAttribute, wsValue);
Tom Sepezf0b65542017-02-13 10:26:01 -08001828 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001829 }
1830}
dsinclair5b36f0a2016-07-19 10:56:23 -07001831
dsinclair12a6b0c2016-05-26 11:14:08 -07001832void CXFA_Node::Script_Attribute_StringRead(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001833 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001834 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001835 if (bSetting) {
1836 ThrowInvalidPropertyException();
1837 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001838 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001839
1840 CFX_WideString wsValue;
1841 GetAttribute(eAttribute, wsValue);
Tom Sepezf0b65542017-02-13 10:26:01 -08001842 pValue->SetString(wsValue.UTF8Encode().AsStringC());
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_WsdlConnection_Execute(CFXJSE_Arguments* pArguments) {
1846 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001847 if (argc != 0 && argc != 1) {
1848 ThrowParamCountMismatchException(L"execute");
1849 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001850 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001851 pArguments->GetReturnValue()->SetBoolean(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04001852}
dsinclair5b36f0a2016-07-19 10:56:23 -07001853
Dan Sinclair1770c022016-03-14 14:14:16 -04001854void CXFA_Node::Script_Delta_Restore(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001855 if (pArguments->GetLength() != 0)
1856 ThrowParamCountMismatchException(L"restore");
Dan Sinclair1770c022016-03-14 14:14:16 -04001857}
dsinclair5b36f0a2016-07-19 10:56:23 -07001858
dsinclair12a6b0c2016-05-26 11:14:08 -07001859void CXFA_Node::Script_Delta_CurrentValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001860 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001861 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001862
dsinclair12a6b0c2016-05-26 11:14:08 -07001863void CXFA_Node::Script_Delta_SavedValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001864 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001865 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001866
dsinclair12a6b0c2016-05-26 11:14:08 -07001867void CXFA_Node::Script_Delta_Target(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001868 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001869 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07001870
dsinclair12a6b0c2016-05-26 11:14:08 -07001871void CXFA_Node::Script_Som_Message(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001872 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001873 XFA_SOM_MESSAGETYPE iMessageType) {
1874 CXFA_WidgetData* pWidgetData = GetWidgetData();
1875 if (!pWidgetData) {
1876 return;
1877 }
tsepezd19e9122016-11-02 15:43:18 -07001878 bool bNew = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04001879 CXFA_Validate validate = pWidgetData->GetValidate();
1880 if (!validate) {
tsepezd19e9122016-11-02 15:43:18 -07001881 validate = pWidgetData->GetValidate(true);
1882 bNew = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04001883 }
1884 if (bSetting) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001885 switch (iMessageType) {
1886 case XFA_SOM_ValidationMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001887 validate.SetScriptMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001888 break;
1889 case XFA_SOM_FormatMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001890 validate.SetFormatMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001891 break;
1892 case XFA_SOM_MandatoryMessage:
dsinclair2f5582f2016-06-09 11:48:23 -07001893 validate.SetNullMessageText(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04001894 break;
1895 default:
1896 break;
1897 }
1898 if (!bNew) {
dsinclaira1b07722016-07-11 08:20:58 -07001899 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04001900 if (!pNotify) {
1901 return;
1902 }
1903 pNotify->AddCalcValidate(this);
1904 }
1905 } else {
1906 CFX_WideString wsMessage;
1907 switch (iMessageType) {
1908 case XFA_SOM_ValidationMessage:
1909 validate.GetScriptMessageText(wsMessage);
1910 break;
1911 case XFA_SOM_FormatMessage:
1912 validate.GetFormatMessageText(wsMessage);
1913 break;
1914 case XFA_SOM_MandatoryMessage:
1915 validate.GetNullMessageText(wsMessage);
1916 break;
1917 default:
1918 break;
1919 }
Tom Sepezf0b65542017-02-13 10:26:01 -08001920 pValue->SetString(wsMessage.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04001921 }
1922}
dsinclair5b36f0a2016-07-19 10:56:23 -07001923
dsinclair12a6b0c2016-05-26 11:14:08 -07001924void CXFA_Node::Script_Som_ValidationMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001925 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001926 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001927 Script_Som_Message(pValue, bSetting, XFA_SOM_ValidationMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04001928}
dsinclair5b36f0a2016-07-19 10:56:23 -07001929
dsinclair12a6b0c2016-05-26 11:14:08 -07001930void CXFA_Node::Script_Field_Length(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001931 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001932 XFA_ATTRIBUTE eAttribute) {
1933 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001934 ThrowInvalidPropertyException();
1935 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04001936 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05001937
1938 CXFA_WidgetData* pWidgetData = GetWidgetData();
1939 if (!pWidgetData) {
1940 pValue->SetInteger(0);
1941 return;
1942 }
1943 pValue->SetInteger(pWidgetData->CountChoiceListItems(true));
Dan Sinclair1770c022016-03-14 14:14:16 -04001944}
dsinclair5b36f0a2016-07-19 10:56:23 -07001945
dsinclair12a6b0c2016-05-26 11:14:08 -07001946void CXFA_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07001947 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04001948 XFA_ATTRIBUTE eAttribute) {
dsinclair41cb62e2016-06-23 09:20:32 -07001949 XFA_Element eType = GetElementType();
1950 if (eType == XFA_Element::Field) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001951 Script_Field_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001952 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001953 }
1954 if (eType == XFA_Element::Draw) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001955 Script_Draw_DefaultValue(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001956 return;
dsinclair41cb62e2016-06-23 09:20:32 -07001957 }
1958 if (eType == XFA_Element::Boolean) {
dsinclair12a6b0c2016-05-26 11:14:08 -07001959 Script_Boolean_Value(pValue, bSetting, eAttribute);
Dan Sinclair1770c022016-03-14 14:14:16 -04001960 return;
1961 }
1962 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07001963 CFX_WideString wsNewValue;
dsinclair769b1372016-06-08 13:12:41 -07001964 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07001965 wsNewValue = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07001966
Dan Sinclair1770c022016-03-14 14:14:16 -04001967 CFX_WideString wsFormatValue(wsNewValue);
weili44f8faf2016-06-01 14:03:56 -07001968 CXFA_WidgetData* pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001969 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
Dan Sinclair1770c022016-03-14 14:14:16 -04001970 CFX_WideString wsPicture;
Tom Sepezf8a94392017-03-14 12:13:22 -07001971 for (CXFA_Node* pFormNode : GetBindItems()) {
1972 if (!pFormNode || pFormNode->HasRemovedChildren())
Dan Sinclair1770c022016-03-14 14:14:16 -04001973 continue;
Dan Sinclair1770c022016-03-14 14:14:16 -04001974 pContainerWidgetData = pFormNode->GetContainerWidgetData();
1975 if (pContainerWidgetData) {
1976 pContainerWidgetData->GetPictureContent(wsPicture,
1977 XFA_VALUEPICTURE_DataBind);
1978 }
Tom Sepezf8a94392017-03-14 12:13:22 -07001979 if (!wsPicture.IsEmpty())
Dan Sinclair1770c022016-03-14 14:14:16 -04001980 break;
weili44f8faf2016-06-01 14:03:56 -07001981 pContainerWidgetData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04001982 }
1983 } else if (GetPacketID() == XFA_XDPPACKET_Form) {
1984 pContainerWidgetData = GetContainerWidgetData();
1985 }
1986 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07001987 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04001988 }
tsepezd19e9122016-11-02 15:43:18 -07001989 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04001990 } else {
tsepezd19e9122016-11-02 15:43:18 -07001991 CFX_WideString content = GetScriptContent(true);
dsinclair41cb62e2016-06-23 09:20:32 -07001992 if (content.IsEmpty() && eType != XFA_Element::Text &&
1993 eType != XFA_Element::SubmitUrl) {
dsinclairf27aeec2016-06-07 19:36:18 -07001994 pValue->SetNull();
dsinclair41cb62e2016-06-23 09:20:32 -07001995 } else if (eType == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07001996 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair41cb62e2016-06-23 09:20:32 -07001997 } else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) {
tsepez4c3debb2016-04-08 12:20:38 -07001998 CFX_Decimal decimal(content.AsStringC());
Dan Sinclair05df0752017-03-14 14:43:42 -04001999 pValue->SetFloat((float)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002000 } else {
Tom Sepezf0b65542017-02-13 10:26:01 -08002001 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002002 }
2003 }
2004}
dsinclair5b36f0a2016-07-19 10:56:23 -07002005
dsinclair12a6b0c2016-05-26 11:14:08 -07002006void CXFA_Node::Script_Som_DefaultValue_Read(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002007 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002008 XFA_ATTRIBUTE eAttribute) {
2009 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002010 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002011 return;
2012 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002013
tsepezd19e9122016-11-02 15:43:18 -07002014 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002015 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002016 pValue->SetNull();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002017 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002018 }
Tom Sepezf0b65542017-02-13 10:26:01 -08002019 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002020}
dsinclair5b36f0a2016-07-19 10:56:23 -07002021
dsinclair12a6b0c2016-05-26 11:14:08 -07002022void CXFA_Node::Script_Boolean_Value(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002023 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002024 XFA_ATTRIBUTE eAttribute) {
2025 if (bSetting) {
2026 CFX_ByteString newValue;
dsinclair769b1372016-06-08 13:12:41 -07002027 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002028 newValue = pValue->ToString();
dsinclairf27aeec2016-06-07 19:36:18 -07002029
tsepezb4c9f3f2016-04-13 15:41:21 -07002030 int32_t iValue = FXSYS_atoi(newValue.c_str());
tsepezafe94302016-05-13 17:21:31 -07002031 CFX_WideString wsNewValue(iValue == 0 ? L"0" : L"1");
Dan Sinclair1770c022016-03-14 14:14:16 -04002032 CFX_WideString wsFormatValue(wsNewValue);
2033 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2034 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002035 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002036 }
tsepezd19e9122016-11-02 15:43:18 -07002037 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002038 } else {
tsepezd19e9122016-11-02 15:43:18 -07002039 CFX_WideString wsValue = GetScriptContent(true);
dan sinclair65c7c232017-02-02 14:05:30 -08002040 pValue->SetBoolean(wsValue == L"1");
Dan Sinclair1770c022016-03-14 14:14:16 -04002041 }
2042}
dsinclair2f5582f2016-06-09 11:48:23 -07002043
dsinclair12a6b0c2016-05-26 11:14:08 -07002044void CXFA_Node::Script_Som_BorderColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002045 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002046 XFA_ATTRIBUTE eAttribute) {
2047 CXFA_WidgetData* pWidgetData = GetWidgetData();
2048 if (!pWidgetData) {
2049 return;
2050 }
tsepezd19e9122016-11-02 15:43:18 -07002051 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002052 int32_t iSize = border.CountEdges();
Dan Sinclair1770c022016-03-14 14:14:16 -04002053 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002054 int32_t r = 0;
2055 int32_t g = 0;
2056 int32_t b = 0;
dsinclair5b36f0a2016-07-19 10:56:23 -07002057 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002058 FX_ARGB rgb = ArgbEncode(100, r, g, b);
2059 for (int32_t i = 0; i < iSize; ++i) {
2060 CXFA_Edge edge = border.GetEdge(i);
2061 edge.SetColor(rgb);
2062 }
2063 } else {
2064 CXFA_Edge edge = border.GetEdge(0);
2065 FX_ARGB color = edge.GetColor();
2066 int32_t a, r, g, b;
2067 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002068 CFX_WideString strColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002069 strColor.Format(L"%d,%d,%d", r, g, b);
Tom Sepezf0b65542017-02-13 10:26:01 -08002070 pValue->SetString(strColor.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002071 }
2072}
dsinclair5b36f0a2016-07-19 10:56:23 -07002073
dsinclair12a6b0c2016-05-26 11:14:08 -07002074void CXFA_Node::Script_Som_BorderWidth(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002075 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002076 XFA_ATTRIBUTE eAttribute) {
2077 CXFA_WidgetData* pWidgetData = GetWidgetData();
2078 if (!pWidgetData) {
2079 return;
2080 }
tsepezd19e9122016-11-02 15:43:18 -07002081 CXFA_Border border = pWidgetData->GetBorder(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002082 int32_t iSize = border.CountEdges();
2083 CFX_WideString wsThickness;
2084 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002085 wsThickness = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002086 for (int32_t i = 0; i < iSize; ++i) {
2087 CXFA_Edge edge = border.GetEdge(i);
tsepez4c3debb2016-04-08 12:20:38 -07002088 CXFA_Measurement thickness(wsThickness.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002089 edge.SetMSThickness(thickness);
2090 }
2091 } else {
2092 CXFA_Edge edge = border.GetEdge(0);
2093 CXFA_Measurement thickness = edge.GetMSThickness();
2094 thickness.ToString(wsThickness);
Tom Sepezf0b65542017-02-13 10:26:01 -08002095 pValue->SetString(wsThickness.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002096 }
2097}
dsinclair5b36f0a2016-07-19 10:56:23 -07002098
dsinclair12a6b0c2016-05-26 11:14:08 -07002099void CXFA_Node::Script_Som_FillColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002100 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002101 XFA_ATTRIBUTE eAttribute) {
2102 CXFA_WidgetData* pWidgetData = GetWidgetData();
2103 if (!pWidgetData) {
2104 return;
2105 }
tsepezd19e9122016-11-02 15:43:18 -07002106 CXFA_Border border = pWidgetData->GetBorder(true);
2107 CXFA_Fill borderfill = border.GetFill(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002108 CXFA_Node* pNode = borderfill.GetNode();
2109 if (!pNode) {
2110 return;
2111 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002112 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002113 int32_t r;
2114 int32_t g;
2115 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002116 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002117 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2118 borderfill.SetColor(color);
2119 } else {
2120 FX_ARGB color = borderfill.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002121 int32_t a;
2122 int32_t r;
2123 int32_t g;
2124 int32_t b;
Dan Sinclair1770c022016-03-14 14:14:16 -04002125 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002126 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002127 wsColor.Format(L"%d,%d,%d", r, g, b);
Tom Sepezf0b65542017-02-13 10:26:01 -08002128 pValue->SetString(wsColor.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002129 }
2130}
dsinclair5b36f0a2016-07-19 10:56:23 -07002131
dsinclair12a6b0c2016-05-26 11:14:08 -07002132void CXFA_Node::Script_Som_DataNode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002133 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002134 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002135 if (bSetting) {
2136 ThrowInvalidPropertyException();
2137 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002138 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002139
2140 CXFA_Node* pDataNode = GetBindData();
2141 if (!pDataNode) {
2142 pValue->SetNull();
2143 return;
2144 }
2145
2146 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pDataNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002147}
dsinclair5b36f0a2016-07-19 10:56:23 -07002148
dsinclair12a6b0c2016-05-26 11:14:08 -07002149void CXFA_Node::Script_Draw_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002150 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002151 XFA_ATTRIBUTE eAttribute) {
2152 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002153 if (pValue && pValue->IsString()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002154 CXFA_WidgetData* pWidgetData = GetWidgetData();
dsinclair43854a52016-04-27 12:26:00 -07002155 ASSERT(pWidgetData);
dsinclair56a8b192016-06-21 14:15:25 -07002156 XFA_Element uiType = pWidgetData->GetUIType();
2157 if (uiType == XFA_Element::Text) {
dsinclair2f5582f2016-06-09 11:48:23 -07002158 CFX_WideString wsNewValue = pValue->ToWideString();
Dan Sinclair1770c022016-03-14 14:14:16 -04002159 CFX_WideString wsFormatValue(wsNewValue);
tsepezd19e9122016-11-02 15:43:18 -07002160 SetScriptContent(wsNewValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002161 }
2162 }
2163 } else {
tsepezd19e9122016-11-02 15:43:18 -07002164 CFX_WideString content = GetScriptContent(true);
Tom Sepezf0b65542017-02-13 10:26:01 -08002165 if (content.IsEmpty())
dsinclairf27aeec2016-06-07 19:36:18 -07002166 pValue->SetNull();
Tom Sepezf0b65542017-02-13 10:26:01 -08002167 else
2168 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002169 }
2170}
dsinclair5b36f0a2016-07-19 10:56:23 -07002171
dsinclair12a6b0c2016-05-26 11:14:08 -07002172void CXFA_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002173 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002174 XFA_ATTRIBUTE eAttribute) {
2175 CXFA_WidgetData* pWidgetData = GetWidgetData();
2176 if (!pWidgetData) {
2177 return;
2178 }
2179 if (bSetting) {
dsinclair769b1372016-06-08 13:12:41 -07002180 if (pValue && pValue->IsNull()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002181 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002182 pWidgetData->m_bIsNull = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04002183 } else {
2184 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
tsepezd19e9122016-11-02 15:43:18 -07002185 pWidgetData->m_bIsNull = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04002186 }
dsinclair2f5582f2016-06-09 11:48:23 -07002187 CFX_WideString wsNewText;
dsinclair769b1372016-06-08 13:12:41 -07002188 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
dsinclair2f5582f2016-06-09 11:48:23 -07002189 wsNewText = pValue->ToWideString();
dsinclairf27aeec2016-06-07 19:36:18 -07002190
Dan Sinclair1770c022016-03-14 14:14:16 -04002191 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07002192 if (pUIChild->GetElementType() == XFA_Element::NumericEdit) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002193 int32_t iLeadDigits = 0;
2194 int32_t iFracDigits = 0;
2195 pWidgetData->GetLeadDigits(iLeadDigits);
2196 pWidgetData->GetFracDigits(iFracDigits);
dsinclair44d054c2016-04-06 10:23:46 -07002197 wsNewText =
2198 pWidgetData->NumericLimit(wsNewText, iLeadDigits, iFracDigits);
Dan Sinclair1770c022016-03-14 14:14:16 -04002199 }
2200 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
2201 CFX_WideString wsFormatText(wsNewText);
2202 if (pContainerWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07002203 pContainerWidgetData->GetFormatDataValue(wsNewText, wsFormatText);
Dan Sinclair1770c022016-03-14 14:14:16 -04002204 }
tsepezd19e9122016-11-02 15:43:18 -07002205 SetScriptContent(wsNewText, wsFormatText, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002206 } else {
tsepezd19e9122016-11-02 15:43:18 -07002207 CFX_WideString content = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002208 if (content.IsEmpty()) {
dsinclairf27aeec2016-06-07 19:36:18 -07002209 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002210 } else {
2211 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
Dan Sinclair1770c022016-03-14 14:14:16 -04002212 CXFA_Value defVal = pWidgetData->GetFormValue();
2213 CXFA_Node* pNode = defVal.GetNode()->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair070fcdf2016-06-22 22:04:54 -07002214 if (pNode && pNode->GetElementType() == XFA_Element::Decimal) {
dsinclair41cb62e2016-06-23 09:20:32 -07002215 if (pUIChild->GetElementType() == XFA_Element::NumericEdit &&
Dan Sinclair1770c022016-03-14 14:14:16 -04002216 (pNode->GetInteger(XFA_ATTRIBUTE_FracDigits) == -1)) {
Tom Sepezf0b65542017-02-13 10:26:01 -08002217 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002218 } else {
tsepez4c3debb2016-04-08 12:20:38 -07002219 CFX_Decimal decimal(content.AsStringC());
Dan Sinclair05df0752017-03-14 14:43:42 -04002220 pValue->SetFloat((float)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002221 }
dsinclair070fcdf2016-06-22 22:04:54 -07002222 } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) {
dsinclairf27aeec2016-06-07 19:36:18 -07002223 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
dsinclair070fcdf2016-06-22 22:04:54 -07002224 } else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) {
tsepezd19e9122016-11-02 15:43:18 -07002225 pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? false : true);
dsinclair070fcdf2016-06-22 22:04:54 -07002226 } else if (pNode && pNode->GetElementType() == XFA_Element::Float) {
tsepez4c3debb2016-04-08 12:20:38 -07002227 CFX_Decimal decimal(content.AsStringC());
Dan Sinclair05df0752017-03-14 14:43:42 -04002228 pValue->SetFloat((float)(double)decimal);
Dan Sinclair1770c022016-03-14 14:14:16 -04002229 } else {
Tom Sepezf0b65542017-02-13 10:26:01 -08002230 pValue->SetString(content.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002231 }
2232 }
2233 }
2234}
dsinclair5b36f0a2016-07-19 10:56:23 -07002235
dsinclair12a6b0c2016-05-26 11:14:08 -07002236void CXFA_Node::Script_Field_EditValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002237 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002238 XFA_ATTRIBUTE eAttribute) {
2239 CXFA_WidgetData* pWidgetData = GetWidgetData();
2240 if (!pWidgetData) {
2241 return;
2242 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002243 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002244 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Edit);
Dan Sinclair1770c022016-03-14 14:14:16 -04002245 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002246 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002247 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Edit);
Tom Sepezf0b65542017-02-13 10:26:01 -08002248 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002249 }
2250}
dsinclair5b36f0a2016-07-19 10:56:23 -07002251
dsinclair12a6b0c2016-05-26 11:14:08 -07002252void CXFA_Node::Script_Som_FontColor(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002253 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002254 XFA_ATTRIBUTE eAttribute) {
2255 CXFA_WidgetData* pWidgetData = GetWidgetData();
2256 if (!pWidgetData) {
2257 return;
2258 }
tsepezd19e9122016-11-02 15:43:18 -07002259 CXFA_Font font = pWidgetData->GetFont(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002260 CXFA_Node* pNode = font.GetNode();
2261 if (!pNode) {
2262 return;
2263 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002264 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002265 int32_t r;
2266 int32_t g;
2267 int32_t b;
dsinclair5b36f0a2016-07-19 10:56:23 -07002268 StrToRGB(pValue->ToWideString(), r, g, b);
Dan Sinclair1770c022016-03-14 14:14:16 -04002269 FX_ARGB color = ArgbEncode(0xff, r, g, b);
2270 font.SetColor(color);
2271 } else {
2272 FX_ARGB color = font.GetColor();
dsinclair2f5582f2016-06-09 11:48:23 -07002273 int32_t a;
2274 int32_t r;
2275 int32_t g;
2276 int32_t b;
Dan Sinclair1770c022016-03-14 14:14:16 -04002277 ArgbDecode(color, a, r, g, b);
dsinclair2f5582f2016-06-09 11:48:23 -07002278 CFX_WideString wsColor;
Dan Sinclair1770c022016-03-14 14:14:16 -04002279 wsColor.Format(L"%d,%d,%d", r, g, b);
Tom Sepezf0b65542017-02-13 10:26:01 -08002280 pValue->SetString(wsColor.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002281 }
2282}
dsinclair5b36f0a2016-07-19 10:56:23 -07002283
dsinclair12a6b0c2016-05-26 11:14:08 -07002284void CXFA_Node::Script_Field_FormatMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002285 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002286 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002287 Script_Som_Message(pValue, bSetting, XFA_SOM_FormatMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002288}
dsinclair5b36f0a2016-07-19 10:56:23 -07002289
dsinclair12a6b0c2016-05-26 11:14:08 -07002290void CXFA_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002291 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002292 XFA_ATTRIBUTE eAttribute) {
2293 CXFA_WidgetData* pWidgetData = GetWidgetData();
2294 if (!pWidgetData) {
2295 return;
2296 }
Dan Sinclair1770c022016-03-14 14:14:16 -04002297 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002298 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Display);
Dan Sinclair1770c022016-03-14 14:14:16 -04002299 } else {
dsinclair2f5582f2016-06-09 11:48:23 -07002300 CFX_WideString wsValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04002301 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Display);
Tom Sepezf0b65542017-02-13 10:26:01 -08002302 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002303 }
2304}
dsinclair5b36f0a2016-07-19 10:56:23 -07002305
dsinclair12a6b0c2016-05-26 11:14:08 -07002306void CXFA_Node::Script_Som_Mandatory(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002307 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002308 XFA_ATTRIBUTE eAttribute) {
2309 CXFA_WidgetData* pWidgetData = GetWidgetData();
2310 if (!pWidgetData) {
2311 return;
2312 }
tsepezd19e9122016-11-02 15:43:18 -07002313 CXFA_Validate validate = pWidgetData->GetValidate(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002314 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002315 validate.SetNullTest(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04002316 } else {
2317 int32_t iValue = validate.GetNullTest();
2318 const XFA_ATTRIBUTEENUMINFO* pInfo =
dsinclair9eb0db12016-07-21 12:01:39 -07002319 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)iValue);
dsinclair2f5582f2016-06-09 11:48:23 -07002320 CFX_WideString wsValue;
2321 if (pInfo)
Dan Sinclair1770c022016-03-14 14:14:16 -04002322 wsValue = pInfo->pName;
Tom Sepezf0b65542017-02-13 10:26:01 -08002323 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002324 }
2325}
dsinclair5b36f0a2016-07-19 10:56:23 -07002326
dsinclair12a6b0c2016-05-26 11:14:08 -07002327void CXFA_Node::Script_Som_MandatoryMessage(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002328 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002329 XFA_ATTRIBUTE eAttribute) {
dsinclair12a6b0c2016-05-26 11:14:08 -07002330 Script_Som_Message(pValue, bSetting, XFA_SOM_MandatoryMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -04002331}
dsinclair5b36f0a2016-07-19 10:56:23 -07002332
dsinclair12a6b0c2016-05-26 11:14:08 -07002333void CXFA_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002334 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002335 XFA_ATTRIBUTE eAttribute) {
2336 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002337 ThrowInvalidPropertyException();
2338 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002339 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002340 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002341}
dsinclair5b36f0a2016-07-19 10:56:23 -07002342
dsinclair12a6b0c2016-05-26 11:14:08 -07002343void CXFA_Node::Script_Field_SelectedIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002344 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002345 XFA_ATTRIBUTE eAttribute) {
2346 CXFA_WidgetData* pWidgetData = GetWidgetData();
2347 if (!pWidgetData) {
2348 return;
2349 }
2350 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002351 int32_t iIndex = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002352 if (iIndex == -1) {
2353 pWidgetData->ClearAllSelections();
2354 return;
2355 }
tsepezd19e9122016-11-02 15:43:18 -07002356 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002357 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002358 pValue->SetInteger(pWidgetData->GetSelectedItem());
Dan Sinclair1770c022016-03-14 14:14:16 -04002359 }
2360}
dsinclair5b36f0a2016-07-19 10:56:23 -07002361
Dan Sinclair1770c022016-03-14 14:14:16 -04002362void CXFA_Node::Script_Field_ClearItems(CFXJSE_Arguments* pArguments) {
2363 CXFA_WidgetData* pWidgetData = GetWidgetData();
2364 if (!pWidgetData) {
2365 return;
2366 }
tsepezd19e9122016-11-02 15:43:18 -07002367 pWidgetData->DeleteItem(-1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002368}
dsinclair5b36f0a2016-07-19 10:56:23 -07002369
Dan Sinclair1770c022016-03-14 14:14:16 -04002370void CXFA_Node::Script_Field_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002371 if (pArguments->GetLength() != 1) {
2372 ThrowParamCountMismatchException(L"execEvent");
2373 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002374 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002375
2376 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2377 int32_t iRet = execSingleEventByName(
2378 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2379 XFA_Element::Field);
2380 if (eventString != "validate")
2381 return;
2382
2383 pArguments->GetReturnValue()->SetBoolean(
2384 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002385}
dsinclair5b36f0a2016-07-19 10:56:23 -07002386
Dan Sinclair1770c022016-03-14 14:14:16 -04002387void CXFA_Node::Script_Field_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002388 if (pArguments->GetLength() != 0) {
2389 ThrowParamCountMismatchException(L"execInitialize");
2390 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002391 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002392
2393 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2394 if (!pNotify)
2395 return;
2396
2397 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002398}
dsinclair5b36f0a2016-07-19 10:56:23 -07002399
Dan Sinclair1770c022016-03-14 14:14:16 -04002400void CXFA_Node::Script_Field_DeleteItem(CFXJSE_Arguments* pArguments) {
2401 int32_t iLength = pArguments->GetLength();
2402 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002403 ThrowParamCountMismatchException(L"deleteItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002404 return;
2405 }
2406 CXFA_WidgetData* pWidgetData = GetWidgetData();
2407 if (!pWidgetData) {
2408 return;
2409 }
2410 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002411 bool bValue = pWidgetData->DeleteItem(iIndex, true, true);
dsinclair12a6b0c2016-05-26 11:14:08 -07002412 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002413 if (pValue)
2414 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002415}
dsinclair5b36f0a2016-07-19 10:56:23 -07002416
Dan Sinclair1770c022016-03-14 14:14:16 -04002417void CXFA_Node::Script_Field_GetSaveItem(CFXJSE_Arguments* pArguments) {
2418 int32_t iLength = pArguments->GetLength();
2419 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002420 ThrowParamCountMismatchException(L"getSaveItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002421 return;
2422 }
2423 int32_t iIndex = pArguments->GetInt32(0);
2424 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002425 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002426 return;
2427 }
2428 CXFA_WidgetData* pWidgetData = GetWidgetData();
2429 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002430 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002431 return;
2432 }
2433 CFX_WideString wsValue;
Tom Sepezf0b65542017-02-13 10:26:01 -08002434 if (!pWidgetData->GetChoiceListItem(wsValue, iIndex, true)) {
dsinclairf27aeec2016-06-07 19:36:18 -07002435 pArguments->GetReturnValue()->SetNull();
Tom Sepezf0b65542017-02-13 10:26:01 -08002436 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002437 }
Tom Sepezf0b65542017-02-13 10:26:01 -08002438 pArguments->GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002439}
dsinclair5b36f0a2016-07-19 10:56:23 -07002440
Dan Sinclair1770c022016-03-14 14:14:16 -04002441void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments) {
2442 int32_t iLength = pArguments->GetLength();
2443 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002444 ThrowParamCountMismatchException(L"boundItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002445 return;
2446 }
2447 CXFA_WidgetData* pWidgetData = GetWidgetData();
2448 if (!pWidgetData) {
2449 return;
2450 }
2451 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002452 CFX_WideString wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002453 CFX_WideString wsBoundValue;
tsepez4c3debb2016-04-08 12:20:38 -07002454 pWidgetData->GetItemValue(wsValue.AsStringC(), wsBoundValue);
dsinclair12a6b0c2016-05-26 11:14:08 -07002455 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002456 if (pValue)
Tom Sepezf0b65542017-02-13 10:26:01 -08002457 pValue->SetString(wsBoundValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002458}
dsinclair5b36f0a2016-07-19 10:56:23 -07002459
Dan Sinclair1770c022016-03-14 14:14:16 -04002460void CXFA_Node::Script_Field_GetItemState(CFXJSE_Arguments* pArguments) {
2461 int32_t iLength = pArguments->GetLength();
2462 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002463 ThrowParamCountMismatchException(L"getItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002464 return;
2465 }
2466 CXFA_WidgetData* pWidgetData = GetWidgetData();
2467 if (!pWidgetData) {
2468 return;
2469 }
2470 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07002471 bool bValue = pWidgetData->GetItemState(iIndex);
dsinclair12a6b0c2016-05-26 11:14:08 -07002472 CFXJSE_Value* pValue = pArguments->GetReturnValue();
dsinclairf27aeec2016-06-07 19:36:18 -07002473 if (pValue)
2474 pValue->SetBoolean(bValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04002475}
dsinclair5b36f0a2016-07-19 10:56:23 -07002476
Dan Sinclair1770c022016-03-14 14:14:16 -04002477void CXFA_Node::Script_Field_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002478 if (pArguments->GetLength() != 0) {
2479 ThrowParamCountMismatchException(L"execCalculate");
2480 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002481 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002482
2483 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2484 if (!pNotify)
2485 return;
2486
2487 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate, false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04002488}
dsinclair5b36f0a2016-07-19 10:56:23 -07002489
Dan Sinclair1770c022016-03-14 14:14:16 -04002490void CXFA_Node::Script_Field_SetItems(CFXJSE_Arguments* pArguments) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002491
Dan Sinclair1770c022016-03-14 14:14:16 -04002492void CXFA_Node::Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments) {
2493 int32_t iLength = pArguments->GetLength();
2494 if (iLength != 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002495 ThrowParamCountMismatchException(L"getDisplayItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002496 return;
2497 }
2498 int32_t iIndex = pArguments->GetInt32(0);
2499 if (iIndex < 0) {
dsinclairf27aeec2016-06-07 19:36:18 -07002500 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002501 return;
2502 }
2503 CXFA_WidgetData* pWidgetData = GetWidgetData();
2504 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002505 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002506 return;
2507 }
2508 CFX_WideString wsValue;
Tom Sepezf0b65542017-02-13 10:26:01 -08002509 if (!pWidgetData->GetChoiceListItem(wsValue, iIndex, false)) {
dsinclairf27aeec2016-06-07 19:36:18 -07002510 pArguments->GetReturnValue()->SetNull();
Tom Sepezf0b65542017-02-13 10:26:01 -08002511 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002512 }
Tom Sepezf0b65542017-02-13 10:26:01 -08002513 pArguments->GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002514}
dsinclair5b36f0a2016-07-19 10:56:23 -07002515
Dan Sinclair1770c022016-03-14 14:14:16 -04002516void CXFA_Node::Script_Field_SetItemState(CFXJSE_Arguments* pArguments) {
2517 int32_t iLength = pArguments->GetLength();
2518 if (iLength != 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002519 ThrowParamCountMismatchException(L"setItemState");
Dan Sinclair1770c022016-03-14 14:14:16 -04002520 return;
2521 }
2522 CXFA_WidgetData* pWidgetData = GetWidgetData();
thestig800222e2016-05-26 22:00:29 -07002523 if (!pWidgetData)
Dan Sinclair1770c022016-03-14 14:14:16 -04002524 return;
thestig800222e2016-05-26 22:00:29 -07002525
Dan Sinclair1770c022016-03-14 14:14:16 -04002526 int32_t iIndex = pArguments->GetInt32(0);
2527 if (pArguments->GetInt32(1) != 0) {
tsepezd19e9122016-11-02 15:43:18 -07002528 pWidgetData->SetItemState(iIndex, true, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002529 } else {
thestig800222e2016-05-26 22:00:29 -07002530 if (pWidgetData->GetItemState(iIndex))
tsepezd19e9122016-11-02 15:43:18 -07002531 pWidgetData->SetItemState(iIndex, false, true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002532 }
2533}
dsinclair5b36f0a2016-07-19 10:56:23 -07002534
Dan Sinclair1770c022016-03-14 14:14:16 -04002535void CXFA_Node::Script_Field_AddItem(CFXJSE_Arguments* pArguments) {
2536 int32_t iLength = pArguments->GetLength();
2537 if (iLength < 1 || iLength > 2) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002538 ThrowParamCountMismatchException(L"addItem");
Dan Sinclair1770c022016-03-14 14:14:16 -04002539 return;
2540 }
2541 CXFA_WidgetData* pWidgetData = GetWidgetData();
2542 if (!pWidgetData) {
2543 return;
2544 }
2545 CFX_WideString wsLabel;
2546 CFX_WideString wsValue;
2547 if (iLength >= 1) {
tsepez6fe7d212016-04-06 10:51:14 -07002548 CFX_ByteString bsLabel = pArguments->GetUTF8String(0);
tsepez4c3debb2016-04-08 12:20:38 -07002549 wsLabel = CFX_WideString::FromUTF8(bsLabel.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002550 }
2551 if (iLength >= 2) {
2552 CFX_ByteString bsValue = pArguments->GetUTF8String(1);
tsepez4c3debb2016-04-08 12:20:38 -07002553 wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002554 }
tsepezd19e9122016-11-02 15:43:18 -07002555 pWidgetData->InsertItem(wsLabel, wsValue, -1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002556}
dsinclair5b36f0a2016-07-19 10:56:23 -07002557
Dan Sinclair1770c022016-03-14 14:14:16 -04002558void CXFA_Node::Script_Field_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002559 if (pArguments->GetLength() != 0) {
2560 ThrowParamCountMismatchException(L"execValidate");
2561 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002562 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002563
2564 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2565 if (!pNotify) {
2566 pArguments->GetReturnValue()->SetBoolean(false);
2567 return;
2568 }
2569
2570 int32_t iRet =
2571 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate, false, false);
2572 pArguments->GetReturnValue()->SetBoolean(
2573 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002574}
dsinclair5b36f0a2016-07-19 10:56:23 -07002575
dsinclair12a6b0c2016-05-26 11:14:08 -07002576void CXFA_Node::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002577 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002578 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002579 if (bSetting)
2580 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002581}
dsinclair5b36f0a2016-07-19 10:56:23 -07002582
dsinclair12a6b0c2016-05-26 11:14:08 -07002583void CXFA_Node::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002584 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002585 XFA_ATTRIBUTE eAttribute) {
2586 CXFA_WidgetData* pWidgetData = GetWidgetData();
2587 if (!pWidgetData) {
2588 return;
2589 }
2590 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07002591 pWidgetData->SetSelectedMemberByValue(pValue->ToWideString().AsStringC(),
tsepezd19e9122016-11-02 15:43:18 -07002592 true, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002593 } else {
tsepezd19e9122016-11-02 15:43:18 -07002594 CFX_WideString wsValue = GetScriptContent(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002595 XFA_VERSION curVersion = GetDocument()->GetCurVersionMode();
2596 if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) {
dsinclairf27aeec2016-06-07 19:36:18 -07002597 pValue->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04002598 } else {
Tom Sepezf0b65542017-02-13 10:26:01 -08002599 pValue->SetString(wsValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002600 }
2601 }
2602}
dsinclair5b36f0a2016-07-19 10:56:23 -07002603
dsinclair12a6b0c2016-05-26 11:14:08 -07002604void CXFA_Node::Script_ExclGroup_Transient(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002605 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002606 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07002607
Dan Sinclair1770c022016-03-14 14:14:16 -04002608void CXFA_Node::Script_ExclGroup_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002609 if (pArguments->GetLength() != 1) {
2610 ThrowParamCountMismatchException(L"execEvent");
2611 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002612 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002613
2614 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2615 execSingleEventByName(
2616 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2617 XFA_Element::ExclGroup);
Dan Sinclair1770c022016-03-14 14:14:16 -04002618}
thestig800222e2016-05-26 22:00:29 -07002619
Dan Sinclair1770c022016-03-14 14:14:16 -04002620void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments) {
2621 int32_t argc = pArguments->GetLength();
thestig800222e2016-05-26 22:00:29 -07002622 if (argc < 0 || argc > 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002623 ThrowParamCountMismatchException(L"selectedMember");
thestig800222e2016-05-26 22:00:29 -07002624 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002625 }
thestig800222e2016-05-26 22:00:29 -07002626
2627 CXFA_WidgetData* pWidgetData = GetWidgetData();
2628 if (!pWidgetData) {
dsinclairf27aeec2016-06-07 19:36:18 -07002629 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002630 return;
2631 }
2632
2633 CXFA_Node* pReturnNode = nullptr;
2634 if (argc == 0) {
2635 pReturnNode = pWidgetData->GetSelectedMember();
2636 } else {
2637 CFX_ByteString szName;
2638 szName = pArguments->GetUTF8String(0);
2639 pReturnNode = pWidgetData->SetSelectedMember(
2640 CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC(), true);
2641 }
2642 if (!pReturnNode) {
dsinclairf27aeec2016-06-07 19:36:18 -07002643 pArguments->GetReturnValue()->SetNull();
thestig800222e2016-05-26 22:00:29 -07002644 return;
2645 }
dsinclairf27aeec2016-06-07 19:36:18 -07002646 pArguments->GetReturnValue()->Assign(
thestig800222e2016-05-26 22:00:29 -07002647 m_pDocument->GetScriptContext()->GetJSValueFromMap(pReturnNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002648}
thestig800222e2016-05-26 22:00:29 -07002649
Dan Sinclair1770c022016-03-14 14:14:16 -04002650void CXFA_Node::Script_ExclGroup_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002651 if (pArguments->GetLength() != 0) {
2652 ThrowParamCountMismatchException(L"execInitialize");
2653 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002654 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002655
2656 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2657 if (!pNotify)
2658 return;
2659
2660 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04002661}
dsinclair5b36f0a2016-07-19 10:56:23 -07002662
Dan Sinclair1770c022016-03-14 14:14:16 -04002663void CXFA_Node::Script_ExclGroup_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002664 if (pArguments->GetLength() != 0) {
2665 ThrowParamCountMismatchException(L"execCalculate");
2666 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002667 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002668
2669 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2670 if (!pNotify)
2671 return;
2672
2673 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04002674}
dsinclair5b36f0a2016-07-19 10:56:23 -07002675
Dan Sinclair1770c022016-03-14 14:14:16 -04002676void CXFA_Node::Script_ExclGroup_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002677 if (pArguments->GetLength() != 0) {
2678 ThrowParamCountMismatchException(L"execValidate");
2679 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002680 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002681
2682 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2683 if (!pNotify) {
2684 pArguments->GetReturnValue()->SetBoolean(false);
2685 return;
2686 }
2687
2688 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
2689 pArguments->GetReturnValue()->SetBoolean(
2690 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002691}
dsinclair5b36f0a2016-07-19 10:56:23 -07002692
dsinclair12a6b0c2016-05-26 11:14:08 -07002693void CXFA_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002694 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002695 XFA_ATTRIBUTE eAttribute) {
2696 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002697 int32_t iTo = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002698 int32_t iFrom = Subform_and_SubformSet_InstanceIndex();
weili44f8faf2016-06-01 14:03:56 -07002699 CXFA_Node* pManagerNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04002700 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2701 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002702 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002703 pManagerNode = pNode;
2704 break;
2705 }
2706 }
2707 if (pManagerNode) {
2708 pManagerNode->InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07002709 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04002710 if (!pNotify) {
2711 return;
2712 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002713 CXFA_Node* pToInstance = GetItem(pManagerNode, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07002714 if (pToInstance &&
2715 pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002716 pNotify->RunSubformIndexChange(pToInstance);
2717 }
dsinclair5b36f0a2016-07-19 10:56:23 -07002718 CXFA_Node* pFromInstance = GetItem(pManagerNode, iFrom);
dsinclair56a8b192016-06-21 14:15:25 -07002719 if (pFromInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07002720 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002721 pNotify->RunSubformIndexChange(pFromInstance);
2722 }
2723 }
2724 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07002725 pValue->SetInteger(Subform_and_SubformSet_InstanceIndex());
Dan Sinclair1770c022016-03-14 14:14:16 -04002726 }
2727}
dsinclair5b36f0a2016-07-19 10:56:23 -07002728
dsinclair12a6b0c2016-05-26 11:14:08 -07002729void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002730 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002731 XFA_ATTRIBUTE eAttribute) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002732 if (bSetting) {
2733 ThrowInvalidPropertyException();
2734 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002735 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002736
2737 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
2738 CXFA_Node* pInstanceMgr = nullptr;
2739 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2740 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
2741 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
2742 CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name);
2743 if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' &&
2744 wsInstMgrName.Mid(1) == wsName) {
2745 pInstanceMgr = pNode;
2746 }
2747 break;
2748 }
2749 }
2750 if (!pInstanceMgr) {
2751 pValue->SetNull();
2752 return;
2753 }
2754
2755 pValue->Assign(
2756 m_pDocument->GetScriptContext()->GetJSValueFromMap(pInstanceMgr));
Dan Sinclair1770c022016-03-14 14:14:16 -04002757}
dsinclair5b36f0a2016-07-19 10:56:23 -07002758
dsinclair12a6b0c2016-05-26 11:14:08 -07002759void CXFA_Node::Script_Subform_Locale(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002760 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002761 XFA_ATTRIBUTE eAttribute) {
2762 if (bSetting) {
tsepezd19e9122016-11-02 15:43:18 -07002763 SetCData(XFA_ATTRIBUTE_Locale, pValue->ToWideString(), true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002764 } else {
2765 CFX_WideString wsLocaleName;
2766 GetLocaleName(wsLocaleName);
Tom Sepezf0b65542017-02-13 10:26:01 -08002767 pValue->SetString(wsLocaleName.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04002768 }
2769}
dsinclair5b36f0a2016-07-19 10:56:23 -07002770
Dan Sinclair1770c022016-03-14 14:14:16 -04002771void CXFA_Node::Script_Subform_ExecEvent(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002772 if (pArguments->GetLength() != 1) {
2773 ThrowParamCountMismatchException(L"execEvent");
2774 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002775 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002776
2777 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2778 execSingleEventByName(
2779 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2780 XFA_Element::Subform);
Dan Sinclair1770c022016-03-14 14:14:16 -04002781}
dsinclair5b36f0a2016-07-19 10:56:23 -07002782
Dan Sinclair1770c022016-03-14 14:14:16 -04002783void CXFA_Node::Script_Subform_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002784 if (pArguments->GetLength() != 0) {
2785 ThrowParamCountMismatchException(L"execInitialize");
2786 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002787 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002788
2789 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2790 if (!pNotify)
2791 return;
2792
2793 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04002794}
dsinclair5b36f0a2016-07-19 10:56:23 -07002795
Dan Sinclair1770c022016-03-14 14:14:16 -04002796void CXFA_Node::Script_Subform_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002797 if (pArguments->GetLength() != 0) {
2798 ThrowParamCountMismatchException(L"execCalculate");
2799 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002800 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002801
2802 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2803 if (!pNotify)
2804 return;
2805
2806 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04002807}
dsinclair5b36f0a2016-07-19 10:56:23 -07002808
Dan Sinclair1770c022016-03-14 14:14:16 -04002809void CXFA_Node::Script_Subform_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002810 if (pArguments->GetLength() != 0) {
2811 ThrowParamCountMismatchException(L"execValidate");
2812 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002813 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002814
2815 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2816 if (!pNotify) {
2817 pArguments->GetReturnValue()->SetBoolean(false);
2818 return;
2819 }
2820
2821 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
2822 pArguments->GetReturnValue()->SetBoolean(
2823 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002824}
dsinclair5b36f0a2016-07-19 10:56:23 -07002825
Dan Sinclair1770c022016-03-14 14:14:16 -04002826void CXFA_Node::Script_Subform_GetInvalidObjects(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002827 if (pArguments->GetLength() != 0)
2828 ThrowParamCountMismatchException(L"getInvalidObjects");
Dan Sinclair1770c022016-03-14 14:14:16 -04002829}
dsinclair5b36f0a2016-07-19 10:56:23 -07002830
Dan Sinclair1770c022016-03-14 14:14:16 -04002831int32_t CXFA_Node::Subform_and_SubformSet_InstanceIndex() {
2832 int32_t index = 0;
2833 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2834 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07002835 if ((pNode->GetElementType() == XFA_Element::Subform) ||
2836 (pNode->GetElementType() == XFA_Element::SubformSet)) {
Dan Sinclair1770c022016-03-14 14:14:16 -04002837 index++;
2838 } else {
2839 break;
2840 }
2841 }
2842 return index;
2843}
dsinclair5b36f0a2016-07-19 10:56:23 -07002844
Dan Sinclair1770c022016-03-14 14:14:16 -04002845void CXFA_Node::Script_Template_FormNodes(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002846 if (pArguments->GetLength() != 1) {
2847 ThrowParamCountMismatchException(L"formNodes");
2848 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002849 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002850 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002851}
dsinclair5b36f0a2016-07-19 10:56:23 -07002852
Dan Sinclair1770c022016-03-14 14:14:16 -04002853void CXFA_Node::Script_Template_Remerge(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002854 if (pArguments->GetLength() != 0) {
2855 ThrowParamCountMismatchException(L"remerge");
2856 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002857 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002858 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002859}
dsinclair5b36f0a2016-07-19 10:56:23 -07002860
Dan Sinclair1770c022016-03-14 14:14:16 -04002861void CXFA_Node::Script_Template_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002862 if (pArguments->GetLength() != 0) {
2863 ThrowParamCountMismatchException(L"execInitialize");
2864 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002865 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002866
2867 CXFA_WidgetData* pWidgetData = GetWidgetData();
2868 if (!pWidgetData) {
2869 pArguments->GetReturnValue()->SetBoolean(false);
2870 return;
2871 }
2872 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002873}
dsinclair5b36f0a2016-07-19 10:56:23 -07002874
Dan Sinclair1770c022016-03-14 14:14:16 -04002875void CXFA_Node::Script_Template_CreateNode(CFXJSE_Arguments* pArguments) {
2876 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002877 if (argc <= 0 || argc >= 4) {
2878 ThrowParamCountMismatchException(L"createNode");
2879 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002880 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002881
2882 CFX_WideString strName;
2883 CFX_WideString strNameSpace;
2884 CFX_ByteString bsTagName = pArguments->GetUTF8String(0);
2885 CFX_WideString strTagName = CFX_WideString::FromUTF8(bsTagName.AsStringC());
2886 if (argc > 1) {
2887 CFX_ByteString bsName = pArguments->GetUTF8String(1);
2888 strName = CFX_WideString::FromUTF8(bsName.AsStringC());
2889 if (argc == 3) {
2890 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(2);
2891 strNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
2892 }
2893 }
2894
2895 XFA_Element eType = XFA_GetElementTypeForName(strTagName.AsStringC());
2896 CXFA_Node* pNewNode = CreateSamePacketNode(eType);
2897 if (!pNewNode) {
2898 pArguments->GetReturnValue()->SetNull();
2899 return;
2900 }
2901
2902 if (strName.IsEmpty()) {
2903 pArguments->GetReturnValue()->Assign(
2904 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
2905 return;
2906 }
2907
2908 if (!GetAttributeOfElement(eType, XFA_ATTRIBUTE_Name,
2909 XFA_XDPPACKET_UNKNOWN)) {
2910 ThrowMissingPropertyException(strTagName, L"name");
2911 return;
2912 }
2913
2914 pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, strName.AsStringC(), true);
2915 if (pNewNode->GetPacketID() == XFA_XDPPACKET_Datasets)
2916 pNewNode->CreateXMLMappingNode();
2917
2918 pArguments->GetReturnValue()->Assign(
2919 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
Dan Sinclair1770c022016-03-14 14:14:16 -04002920}
dsinclair5b36f0a2016-07-19 10:56:23 -07002921
Dan Sinclair1770c022016-03-14 14:14:16 -04002922void CXFA_Node::Script_Template_Recalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002923 if (pArguments->GetLength() != 1) {
2924 ThrowParamCountMismatchException(L"recalculate");
2925 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002926 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002927 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002928}
dsinclair5b36f0a2016-07-19 10:56:23 -07002929
Dan Sinclair1770c022016-03-14 14:14:16 -04002930void CXFA_Node::Script_Template_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002931 if (pArguments->GetLength() != 0) {
2932 ThrowParamCountMismatchException(L"execCalculate");
2933 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002934 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002935
2936 CXFA_WidgetData* pWidgetData = GetWidgetData();
2937 if (!pWidgetData) {
2938 pArguments->GetReturnValue()->SetBoolean(false);
2939 return;
2940 }
2941 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002942}
dsinclair5b36f0a2016-07-19 10:56:23 -07002943
Dan Sinclair1770c022016-03-14 14:14:16 -04002944void CXFA_Node::Script_Template_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002945 if (pArguments->GetLength() != 0) {
2946 ThrowParamCountMismatchException(L"execValidate");
2947 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002948 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002949 CXFA_WidgetData* pWidgetData = GetWidgetData();
2950 if (!pWidgetData) {
2951 pArguments->GetReturnValue()->SetBoolean(false);
2952 return;
2953 }
2954 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002955}
dsinclair5b36f0a2016-07-19 10:56:23 -07002956
Dan Sinclair1770c022016-03-14 14:14:16 -04002957void CXFA_Node::Script_Manifest_Evaluate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002958 if (pArguments->GetLength() != 0) {
2959 ThrowParamCountMismatchException(L"evaluate");
2960 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04002961 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002962
2963 CXFA_WidgetData* pWidgetData = GetWidgetData();
2964 if (!pWidgetData) {
2965 pArguments->GetReturnValue()->SetBoolean(false);
2966 return;
2967 }
2968 pArguments->GetReturnValue()->SetBoolean(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04002969}
dsinclair5b36f0a2016-07-19 10:56:23 -07002970
dsinclair12a6b0c2016-05-26 11:14:08 -07002971void CXFA_Node::Script_InstanceManager_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002972 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002973 XFA_ATTRIBUTE eAttribute) {
2974 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002975 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002976 return;
2977 }
2978 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07002979 pValue->SetInteger(nodeOccur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04002980}
dsinclair5b36f0a2016-07-19 10:56:23 -07002981
dsinclair12a6b0c2016-05-26 11:14:08 -07002982void CXFA_Node::Script_InstanceManager_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002983 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002984 XFA_ATTRIBUTE eAttribute) {
2985 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05002986 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04002987 return;
2988 }
2989 CXFA_Occur nodeOccur(GetOccurNode());
dsinclairf27aeec2016-06-07 19:36:18 -07002990 pValue->SetInteger(nodeOccur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04002991}
tsepezaadedf92016-05-12 10:08:06 -07002992
dsinclair12a6b0c2016-05-26 11:14:08 -07002993void CXFA_Node::Script_InstanceManager_Count(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07002994 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04002995 XFA_ATTRIBUTE eAttribute) {
2996 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07002997 int32_t iDesired = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04002998 InstanceManager_SetInstances(iDesired);
2999 } else {
dsinclair5b36f0a2016-07-19 10:56:23 -07003000 pValue->SetInteger(GetCount(this));
Dan Sinclair1770c022016-03-14 14:14:16 -04003001 }
3002}
dsinclair5b36f0a2016-07-19 10:56:23 -07003003
Dan Sinclair1770c022016-03-14 14:14:16 -04003004void CXFA_Node::Script_InstanceManager_MoveInstance(
3005 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003006 if (pArguments->GetLength() != 2) {
dsinclairf27aeec2016-06-07 19:36:18 -07003007 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003008 return;
3009 }
3010 int32_t iFrom = pArguments->GetInt32(0);
3011 int32_t iTo = pArguments->GetInt32(1);
3012 InstanceManager_MoveInstance(iTo, iFrom);
dsinclaira1b07722016-07-11 08:20:58 -07003013 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003014 if (!pNotify) {
3015 return;
3016 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003017 CXFA_Node* pToInstance = GetItem(this, iTo);
dsinclair070fcdf2016-06-22 22:04:54 -07003018 if (pToInstance && pToInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003019 pNotify->RunSubformIndexChange(pToInstance);
3020 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003021 CXFA_Node* pFromInstance = GetItem(this, iFrom);
dsinclair070fcdf2016-06-22 22:04:54 -07003022 if (pFromInstance &&
3023 pFromInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003024 pNotify->RunSubformIndexChange(pFromInstance);
3025 }
3026}
dsinclair5b36f0a2016-07-19 10:56:23 -07003027
Dan Sinclair1770c022016-03-14 14:14:16 -04003028void CXFA_Node::Script_InstanceManager_RemoveInstance(
3029 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003030 if (pArguments->GetLength() != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003031 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003032 return;
3033 }
3034 int32_t iIndex = pArguments->GetInt32(0);
dsinclair5b36f0a2016-07-19 10:56:23 -07003035 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003036 if (iIndex < 0 || iIndex >= iCount) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003037 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003038 return;
3039 }
3040 CXFA_Occur nodeOccur(GetOccurNode());
3041 int32_t iMin = nodeOccur.GetMin();
3042 if (iCount - 1 < iMin) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003043 ThrowTooManyOccurancesException(L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003044 return;
3045 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003046 CXFA_Node* pRemoveInstance = GetItem(this, iIndex);
3047 RemoveItem(this, pRemoveInstance);
dsinclaira1b07722016-07-11 08:20:58 -07003048 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003049 if (pNotify) {
3050 for (int32_t i = iIndex; i < iCount - 1; i++) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003051 CXFA_Node* pSubformInstance = GetItem(this, i);
Dan Sinclair1770c022016-03-14 14:14:16 -04003052 if (pSubformInstance &&
dsinclair070fcdf2016-06-22 22:04:54 -07003053 pSubformInstance->GetElementType() == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003054 pNotify->RunSubformIndexChange(pSubformInstance);
3055 }
3056 }
3057 }
3058 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3059 if (!pLayoutPro) {
3060 return;
3061 }
3062 pLayoutPro->AddChangedContainer(
3063 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3064}
dsinclair5b36f0a2016-07-19 10:56:23 -07003065
Dan Sinclair1770c022016-03-14 14:14:16 -04003066void CXFA_Node::Script_InstanceManager_SetInstances(
3067 CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003068 if (pArguments->GetLength() != 1) {
dsinclairf27aeec2016-06-07 19:36:18 -07003069 pArguments->GetReturnValue()->SetUndefined();
Dan Sinclair1770c022016-03-14 14:14:16 -04003070 return;
3071 }
3072 int32_t iDesired = pArguments->GetInt32(0);
3073 InstanceManager_SetInstances(iDesired);
3074}
dsinclair5b36f0a2016-07-19 10:56:23 -07003075
Dan Sinclair1770c022016-03-14 14:14:16 -04003076void CXFA_Node::Script_InstanceManager_AddInstance(
3077 CFXJSE_Arguments* pArguments) {
3078 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003079 if (argc != 0 && argc != 1) {
3080 ThrowParamCountMismatchException(L"addInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003081 return;
3082 }
tsepezd19e9122016-11-02 15:43:18 -07003083 bool fFlags = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003084 if (argc == 1) {
tsepezd19e9122016-11-02 15:43:18 -07003085 fFlags = pArguments->GetInt32(0) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003086 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003087 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003088 CXFA_Occur nodeOccur(GetOccurNode());
3089 int32_t iMax = nodeOccur.GetMax();
3090 if (iMax >= 0 && iCount >= iMax) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003091 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003092 return;
3093 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003094 CXFA_Node* pNewInstance = CreateInstance(this, fFlags);
tsepezd19e9122016-11-02 15:43:18 -07003095 InsertItem(this, pNewInstance, iCount, iCount, false);
dsinclairf27aeec2016-06-07 19:36:18 -07003096 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003097 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003098 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003099 if (!pNotify) {
3100 return;
3101 }
3102 pNotify->RunNodeInitialize(pNewInstance);
3103 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3104 if (!pLayoutPro) {
3105 return;
3106 }
3107 pLayoutPro->AddChangedContainer(
3108 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3109}
dsinclair5b36f0a2016-07-19 10:56:23 -07003110
Dan Sinclair1770c022016-03-14 14:14:16 -04003111void CXFA_Node::Script_InstanceManager_InsertInstance(
3112 CFXJSE_Arguments* pArguments) {
3113 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003114 if (argc != 1 && argc != 2) {
3115 ThrowParamCountMismatchException(L"insertInstance");
Dan Sinclair1770c022016-03-14 14:14:16 -04003116 return;
3117 }
3118 int32_t iIndex = pArguments->GetInt32(0);
tsepezd19e9122016-11-02 15:43:18 -07003119 bool bBind = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003120 if (argc == 2) {
tsepezd19e9122016-11-02 15:43:18 -07003121 bBind = pArguments->GetInt32(1) == 0 ? false : true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003122 }
3123 CXFA_Occur nodeOccur(GetOccurNode());
dsinclair5b36f0a2016-07-19 10:56:23 -07003124 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003125 if (iIndex < 0 || iIndex > iCount) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003126 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003127 return;
3128 }
3129 int32_t iMax = nodeOccur.GetMax();
3130 if (iMax >= 0 && iCount >= iMax) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003131 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003132 return;
3133 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003134 CXFA_Node* pNewInstance = CreateInstance(this, bBind);
tsepezd19e9122016-11-02 15:43:18 -07003135 InsertItem(this, pNewInstance, iIndex, iCount, true);
dsinclairf27aeec2016-06-07 19:36:18 -07003136 pArguments->GetReturnValue()->Assign(
Dan Sinclair1770c022016-03-14 14:14:16 -04003137 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
dsinclaira1b07722016-07-11 08:20:58 -07003138 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003139 if (!pNotify) {
3140 return;
3141 }
3142 pNotify->RunNodeInitialize(pNewInstance);
3143 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3144 if (!pLayoutPro) {
3145 return;
3146 }
3147 pLayoutPro->AddChangedContainer(
3148 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3149}
dsinclair5b36f0a2016-07-19 10:56:23 -07003150
Dan Sinclair1770c022016-03-14 14:14:16 -04003151int32_t CXFA_Node::InstanceManager_SetInstances(int32_t iDesired) {
3152 CXFA_Occur nodeOccur(GetOccurNode());
3153 int32_t iMax = nodeOccur.GetMax();
3154 int32_t iMin = nodeOccur.GetMin();
3155 if (iDesired < iMin) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003156 ThrowTooManyOccurancesException(L"min");
Dan Sinclair1770c022016-03-14 14:14:16 -04003157 return 1;
3158 }
3159 if ((iMax >= 0) && (iDesired > iMax)) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003160 ThrowTooManyOccurancesException(L"max");
Dan Sinclair1770c022016-03-14 14:14:16 -04003161 return 2;
3162 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003163 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003164 if (iDesired == iCount) {
3165 return 0;
3166 }
3167 if (iDesired < iCount) {
3168 CFX_WideStringC wsInstManagerName = GetCData(XFA_ATTRIBUTE_Name);
tsepezafe94302016-05-13 17:21:31 -07003169 CFX_WideString wsInstanceName =
3170 CFX_WideString(wsInstManagerName.IsEmpty() ? wsInstManagerName
3171 : wsInstManagerName.Mid(1));
tsepez736f28a2016-03-25 14:19:51 -07003172 uint32_t dInstanceNameHash =
tsepezb6853cf2016-04-25 11:23:43 -07003173 FX_HashCode_GetW(wsInstanceName.AsStringC(), false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003174 CXFA_Node* pPrevSibling =
dsinclair5b36f0a2016-07-19 10:56:23 -07003175 (iDesired == 0) ? this : GetItem(this, iDesired - 1);
Dan Sinclair1770c022016-03-14 14:14:16 -04003176 while (iCount > iDesired) {
3177 CXFA_Node* pRemoveInstance =
3178 pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling);
dsinclair070fcdf2016-06-22 22:04:54 -07003179 if (pRemoveInstance->GetElementType() != XFA_Element::Subform &&
3180 pRemoveInstance->GetElementType() != XFA_Element::SubformSet) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003181 continue;
3182 }
dsinclair070fcdf2016-06-22 22:04:54 -07003183 if (pRemoveInstance->GetElementType() == XFA_Element::InstanceManager) {
tsepezd19e9122016-11-02 15:43:18 -07003184 ASSERT(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003185 break;
3186 }
3187 if (pRemoveInstance->GetNameHash() == dInstanceNameHash) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003188 RemoveItem(this, pRemoveInstance);
Dan Sinclair1770c022016-03-14 14:14:16 -04003189 iCount--;
3190 }
3191 }
3192 } else if (iDesired > iCount) {
3193 while (iCount < iDesired) {
tsepezd19e9122016-11-02 15:43:18 -07003194 CXFA_Node* pNewInstance = CreateInstance(this, true);
3195 InsertItem(this, pNewInstance, iCount, iCount, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003196 iCount++;
dsinclaira1b07722016-07-11 08:20:58 -07003197 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04003198 if (!pNotify) {
3199 return 0;
3200 }
3201 pNotify->RunNodeInitialize(pNewInstance);
3202 }
3203 }
3204 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3205 if (pLayoutPro) {
3206 pLayoutPro->AddChangedContainer(
3207 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3208 }
3209 return 0;
3210}
dsinclair5b36f0a2016-07-19 10:56:23 -07003211
Dan Sinclair1770c022016-03-14 14:14:16 -04003212int32_t CXFA_Node::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003213 int32_t iCount = GetCount(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04003214 if (iFrom > iCount || iTo > iCount - 1) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003215 ThrowIndexOutOfBoundsException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003216 return 1;
3217 }
3218 if (iFrom < 0 || iTo < 0 || iFrom == iTo) {
3219 return 0;
3220 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003221 CXFA_Node* pMoveInstance = GetItem(this, iFrom);
tsepezd19e9122016-11-02 15:43:18 -07003222 RemoveItem(this, pMoveInstance, false);
3223 InsertItem(this, pMoveInstance, iTo, iCount - 1, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003224 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3225 if (pLayoutPro) {
3226 pLayoutPro->AddChangedContainer(
3227 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3228 }
3229 return 0;
3230}
dsinclair5b36f0a2016-07-19 10:56:23 -07003231
dsinclair12a6b0c2016-05-26 11:14:08 -07003232void CXFA_Node::Script_Occur_Max(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003233 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003234 XFA_ATTRIBUTE eAttribute) {
3235 CXFA_Occur occur(this);
3236 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003237 int32_t iMax = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003238 occur.SetMax(iMax);
3239 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003240 pValue->SetInteger(occur.GetMax());
Dan Sinclair1770c022016-03-14 14:14:16 -04003241 }
3242}
dsinclair5b36f0a2016-07-19 10:56:23 -07003243
dsinclair12a6b0c2016-05-26 11:14:08 -07003244void CXFA_Node::Script_Occur_Min(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003245 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003246 XFA_ATTRIBUTE eAttribute) {
3247 CXFA_Occur occur(this);
3248 if (bSetting) {
dsinclairf27aeec2016-06-07 19:36:18 -07003249 int32_t iMin = pValue->ToInteger();
Dan Sinclair1770c022016-03-14 14:14:16 -04003250 occur.SetMin(iMin);
3251 } else {
dsinclairf27aeec2016-06-07 19:36:18 -07003252 pValue->SetInteger(occur.GetMin());
Dan Sinclair1770c022016-03-14 14:14:16 -04003253 }
3254}
dsinclair5b36f0a2016-07-19 10:56:23 -07003255
Dan Sinclair1770c022016-03-14 14:14:16 -04003256void CXFA_Node::Script_Desc_Metadata(CFXJSE_Arguments* pArguments) {
3257 int32_t argc = pArguments->GetLength();
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003258 if (argc != 0 && argc != 1) {
3259 ThrowParamCountMismatchException(L"metadata");
3260 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003261 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003262 pArguments->GetReturnValue()->SetString("");
Dan Sinclair1770c022016-03-14 14:14:16 -04003263}
dsinclair5b36f0a2016-07-19 10:56:23 -07003264
Dan Sinclair1770c022016-03-14 14:14:16 -04003265void CXFA_Node::Script_Form_FormNodes(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003266 if (pArguments->GetLength() != 1) {
3267 ThrowParamCountMismatchException(L"formNodes");
3268 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003269 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003270
3271 CXFA_Node* pDataNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
3272 if (!pDataNode) {
3273 ThrowArgumentMismatchException();
3274 return;
3275 }
3276
Tom Sepezf8a94392017-03-14 12:13:22 -07003277 std::vector<CXFA_Node*> formItems;
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003278 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
3279 pFormNodes->SetArrayNodeList(formItems);
3280 pArguments->GetReturnValue()->SetObject(
3281 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
Dan Sinclair1770c022016-03-14 14:14:16 -04003282}
dsinclair5b36f0a2016-07-19 10:56:23 -07003283
Dan Sinclair1770c022016-03-14 14:14:16 -04003284void CXFA_Node::Script_Form_Remerge(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003285 if (pArguments->GetLength() != 0) {
3286 ThrowParamCountMismatchException(L"remerge");
3287 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003288 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003289
3290 m_pDocument->DoDataRemerge(true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003291}
dsinclair5b36f0a2016-07-19 10:56:23 -07003292
Dan Sinclair1770c022016-03-14 14:14:16 -04003293void CXFA_Node::Script_Form_ExecInitialize(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003294 if (pArguments->GetLength() != 0) {
3295 ThrowParamCountMismatchException(L"execInitialize");
3296 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003297 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003298
3299 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3300 if (!pNotify)
3301 return;
3302
3303 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
Dan Sinclair1770c022016-03-14 14:14:16 -04003304}
dsinclair5b36f0a2016-07-19 10:56:23 -07003305
Dan Sinclair1770c022016-03-14 14:14:16 -04003306void CXFA_Node::Script_Form_Recalculate(CFXJSE_Arguments* pArguments) {
3307 CXFA_EventParam* pEventParam =
3308 m_pDocument->GetScriptContext()->GetEventParam();
3309 if (pEventParam->m_eType == XFA_EVENT_Calculate ||
3310 pEventParam->m_eType == XFA_EVENT_InitCalculate) {
3311 return;
3312 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003313 if (pArguments->GetLength() != 1) {
3314 ThrowParamCountMismatchException(L"recalculate");
3315 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003316 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003317
3318 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3319 if (!pNotify)
3320 return;
3321 if (pArguments->GetInt32(0) != 0)
3322 return;
3323
3324 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
3325 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
3326 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Ready, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003327}
dsinclair5b36f0a2016-07-19 10:56:23 -07003328
Dan Sinclair1770c022016-03-14 14:14:16 -04003329void CXFA_Node::Script_Form_ExecCalculate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003330 if (pArguments->GetLength() != 0) {
3331 ThrowParamCountMismatchException(L"execCalculate");
3332 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003333 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003334
3335 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3336 if (!pNotify)
3337 return;
3338
3339 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
Dan Sinclair1770c022016-03-14 14:14:16 -04003340}
dsinclair5b36f0a2016-07-19 10:56:23 -07003341
Dan Sinclair1770c022016-03-14 14:14:16 -04003342void CXFA_Node::Script_Form_ExecValidate(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003343 if (pArguments->GetLength() != 0) {
3344 ThrowParamCountMismatchException(L"execValidate");
3345 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003346 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003347
3348 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3349 if (!pNotify) {
3350 pArguments->GetReturnValue()->SetBoolean(false);
3351 return;
3352 }
3353
3354 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
3355 pArguments->GetReturnValue()->SetBoolean(
3356 (iRet == XFA_EVENTERROR_Error) ? false : true);
Dan Sinclair1770c022016-03-14 14:14:16 -04003357}
dsinclair5b36f0a2016-07-19 10:56:23 -07003358
dsinclair12a6b0c2016-05-26 11:14:08 -07003359void CXFA_Node::Script_Form_Checksum(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003360 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003361 XFA_ATTRIBUTE eAttribute) {
3362 if (bSetting) {
dsinclair2f5582f2016-06-09 11:48:23 -07003363 SetAttribute(XFA_ATTRIBUTE_Checksum, pValue->ToWideString().AsStringC());
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003364 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003365 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003366 CFX_WideString wsChecksum;
3367 GetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum, false);
Tom Sepezf0b65542017-02-13 10:26:01 -08003368 pValue->SetString(wsChecksum.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003369}
dsinclair5b36f0a2016-07-19 10:56:23 -07003370
Dan Sinclair1770c022016-03-14 14:14:16 -04003371void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003372 if (pArguments->GetLength() != 1) {
3373 ThrowParamCountMismatchException(L"getAttribute");
3374 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003375 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003376 CFX_ByteString bsAttributeName = pArguments->GetUTF8String(0);
3377 CFX_WideString wsAttributeValue;
3378 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3379 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3380 static_cast<CFDE_XMLElement*>(pXMLNode)->GetString(
3381 CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str(),
3382 wsAttributeValue);
3383 }
3384 pArguments->GetReturnValue()->SetString(
Tom Sepezf0b65542017-02-13 10:26:01 -08003385 wsAttributeValue.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003386}
dsinclair5b36f0a2016-07-19 10:56:23 -07003387
Dan Sinclair1770c022016-03-14 14:14:16 -04003388void CXFA_Node::Script_Packet_SetAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003389 if (pArguments->GetLength() != 2) {
3390 ThrowParamCountMismatchException(L"setAttribute");
3391 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003392 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003393 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
3394 CFX_ByteString bsName = pArguments->GetUTF8String(1);
3395 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3396 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3397 static_cast<CFDE_XMLElement*>(pXMLNode)->SetString(
3398 CFX_WideString::FromUTF8(bsName.AsStringC()),
3399 CFX_WideString::FromUTF8(bsValue.AsStringC()));
3400 }
3401 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003402}
dsinclair5b36f0a2016-07-19 10:56:23 -07003403
Dan Sinclair1770c022016-03-14 14:14:16 -04003404void CXFA_Node::Script_Packet_RemoveAttribute(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003405 if (pArguments->GetLength() != 1) {
3406 ThrowParamCountMismatchException(L"removeAttribute");
3407 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04003408 }
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003409
3410 CFX_ByteString bsName = pArguments->GetUTF8String(0);
3411 CFX_WideString wsName = CFX_WideString::FromUTF8(bsName.AsStringC());
3412 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3413 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3414 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
3415 if (pXMLElement->HasAttribute(wsName.c_str())) {
3416 pXMLElement->RemoveAttribute(wsName.c_str());
3417 }
3418 }
3419 pArguments->GetReturnValue()->SetNull();
Dan Sinclair1770c022016-03-14 14:14:16 -04003420}
dsinclair5b36f0a2016-07-19 10:56:23 -07003421
dsinclair12a6b0c2016-05-26 11:14:08 -07003422void CXFA_Node::Script_Packet_Content(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003423 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003424 XFA_ATTRIBUTE eAttribute) {
3425 if (bSetting) {
dsinclairae95f762016-03-29 16:58:29 -07003426 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003427 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003428 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
dsinclair2f5582f2016-06-09 11:48:23 -07003429 pXMLElement->SetTextData(pValue->ToWideString());
Dan Sinclair1770c022016-03-14 14:14:16 -04003430 }
3431 } else {
3432 CFX_WideString wsTextData;
dsinclairae95f762016-03-29 16:58:29 -07003433 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04003434 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07003435 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04003436 pXMLElement->GetTextData(wsTextData);
3437 }
Tom Sepezf0b65542017-02-13 10:26:01 -08003438 pValue->SetString(wsTextData.UTF8Encode().AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003439 }
3440}
dsinclair5b36f0a2016-07-19 10:56:23 -07003441
Dan Sinclair1770c022016-03-14 14:14:16 -04003442void CXFA_Node::Script_Source_Next(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003443 if (pArguments->GetLength() != 0)
3444 ThrowParamCountMismatchException(L"next");
Dan Sinclair1770c022016-03-14 14:14:16 -04003445}
dsinclair5b36f0a2016-07-19 10:56:23 -07003446
Dan Sinclair1770c022016-03-14 14:14:16 -04003447void CXFA_Node::Script_Source_CancelBatch(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003448 if (pArguments->GetLength() != 0)
3449 ThrowParamCountMismatchException(L"cancelBatch");
Dan Sinclair1770c022016-03-14 14:14:16 -04003450}
dsinclair5b36f0a2016-07-19 10:56:23 -07003451
Dan Sinclair1770c022016-03-14 14:14:16 -04003452void CXFA_Node::Script_Source_First(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003453 if (pArguments->GetLength() != 0)
3454 ThrowParamCountMismatchException(L"first");
Dan Sinclair1770c022016-03-14 14:14:16 -04003455}
dsinclair5b36f0a2016-07-19 10:56:23 -07003456
Dan Sinclair1770c022016-03-14 14:14:16 -04003457void CXFA_Node::Script_Source_UpdateBatch(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003458 if (pArguments->GetLength() != 0)
3459 ThrowParamCountMismatchException(L"updateBatch");
Dan Sinclair1770c022016-03-14 14:14:16 -04003460}
dsinclair5b36f0a2016-07-19 10:56:23 -07003461
Dan Sinclair1770c022016-03-14 14:14:16 -04003462void CXFA_Node::Script_Source_Previous(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003463 if (pArguments->GetLength() != 0)
3464 ThrowParamCountMismatchException(L"previous");
Dan Sinclair1770c022016-03-14 14:14:16 -04003465}
dsinclair5b36f0a2016-07-19 10:56:23 -07003466
Dan Sinclair1770c022016-03-14 14:14:16 -04003467void CXFA_Node::Script_Source_IsBOF(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003468 if (pArguments->GetLength() != 0)
3469 ThrowParamCountMismatchException(L"isBOF");
Dan Sinclair1770c022016-03-14 14:14:16 -04003470}
dsinclair5b36f0a2016-07-19 10:56:23 -07003471
Dan Sinclair1770c022016-03-14 14:14:16 -04003472void CXFA_Node::Script_Source_IsEOF(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003473 if (pArguments->GetLength() != 0)
3474 ThrowParamCountMismatchException(L"isEOF");
Dan Sinclair1770c022016-03-14 14:14:16 -04003475}
dsinclair5b36f0a2016-07-19 10:56:23 -07003476
Dan Sinclair1770c022016-03-14 14:14:16 -04003477void CXFA_Node::Script_Source_Cancel(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003478 if (pArguments->GetLength() != 0)
3479 ThrowParamCountMismatchException(L"cancel");
Dan Sinclair1770c022016-03-14 14:14:16 -04003480}
dsinclair5b36f0a2016-07-19 10:56:23 -07003481
Dan Sinclair1770c022016-03-14 14:14:16 -04003482void CXFA_Node::Script_Source_Update(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003483 if (pArguments->GetLength() != 0)
3484 ThrowParamCountMismatchException(L"update");
Dan Sinclair1770c022016-03-14 14:14:16 -04003485}
dsinclair5b36f0a2016-07-19 10:56:23 -07003486
Dan Sinclair1770c022016-03-14 14:14:16 -04003487void CXFA_Node::Script_Source_Open(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003488 if (pArguments->GetLength() != 0)
3489 ThrowParamCountMismatchException(L"open");
Dan Sinclair1770c022016-03-14 14:14:16 -04003490}
dsinclair5b36f0a2016-07-19 10:56:23 -07003491
Dan Sinclair1770c022016-03-14 14:14:16 -04003492void CXFA_Node::Script_Source_Delete(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003493 if (pArguments->GetLength() != 0)
3494 ThrowParamCountMismatchException(L"delete");
Dan Sinclair1770c022016-03-14 14:14:16 -04003495}
dsinclair5b36f0a2016-07-19 10:56:23 -07003496
Dan Sinclair1770c022016-03-14 14:14:16 -04003497void CXFA_Node::Script_Source_AddNew(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003498 if (pArguments->GetLength() != 0)
3499 ThrowParamCountMismatchException(L"addNew");
Dan Sinclair1770c022016-03-14 14:14:16 -04003500}
dsinclair5b36f0a2016-07-19 10:56:23 -07003501
Dan Sinclair1770c022016-03-14 14:14:16 -04003502void CXFA_Node::Script_Source_Requery(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003503 if (pArguments->GetLength() != 0)
3504 ThrowParamCountMismatchException(L"requery");
Dan Sinclair1770c022016-03-14 14:14:16 -04003505}
dsinclair5b36f0a2016-07-19 10:56:23 -07003506
Dan Sinclair1770c022016-03-14 14:14:16 -04003507void CXFA_Node::Script_Source_Resync(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003508 if (pArguments->GetLength() != 0)
3509 ThrowParamCountMismatchException(L"resync");
Dan Sinclair1770c022016-03-14 14:14:16 -04003510}
dsinclair5b36f0a2016-07-19 10:56:23 -07003511
Dan Sinclair1770c022016-03-14 14:14:16 -04003512void CXFA_Node::Script_Source_Close(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003513 if (pArguments->GetLength() != 0)
3514 ThrowParamCountMismatchException(L"close");
Dan Sinclair1770c022016-03-14 14:14:16 -04003515}
dsinclair5b36f0a2016-07-19 10:56:23 -07003516
Dan Sinclair1770c022016-03-14 14:14:16 -04003517void CXFA_Node::Script_Source_Last(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003518 if (pArguments->GetLength() != 0)
3519 ThrowParamCountMismatchException(L"last");
Dan Sinclair1770c022016-03-14 14:14:16 -04003520}
dsinclair5b36f0a2016-07-19 10:56:23 -07003521
Dan Sinclair1770c022016-03-14 14:14:16 -04003522void CXFA_Node::Script_Source_HasDataChanged(CFXJSE_Arguments* pArguments) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003523 if (pArguments->GetLength() != 0)
3524 ThrowParamCountMismatchException(L"hasDataChanged");
Dan Sinclair1770c022016-03-14 14:14:16 -04003525}
dsinclair5b36f0a2016-07-19 10:56:23 -07003526
dsinclair12a6b0c2016-05-26 11:14:08 -07003527void CXFA_Node::Script_Source_Db(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003528 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003529 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003530
dsinclair12a6b0c2016-05-26 11:14:08 -07003531void CXFA_Node::Script_Xfa_This(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003532 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003533 XFA_ATTRIBUTE eAttribute) {
3534 if (!bSetting) {
3535 CXFA_Object* pThis = m_pDocument->GetScriptContext()->GetThisObject();
dsinclair43854a52016-04-27 12:26:00 -07003536 ASSERT(pThis);
dsinclairf27aeec2016-06-07 19:36:18 -07003537 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pThis));
Dan Sinclair1770c022016-03-14 14:14:16 -04003538 }
3539}
dsinclair5b36f0a2016-07-19 10:56:23 -07003540
dsinclair12a6b0c2016-05-26 11:14:08 -07003541void CXFA_Node::Script_Handler_Version(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003542 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003543 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003544
dsinclair12a6b0c2016-05-26 11:14:08 -07003545void CXFA_Node::Script_SubmitFormat_Mode(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003546 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003547 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003548
dsinclair12a6b0c2016-05-26 11:14:08 -07003549void CXFA_Node::Script_Extras_Type(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003550 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003551 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003552
dsinclair12a6b0c2016-05-26 11:14:08 -07003553void CXFA_Node::Script_Script_Stateless(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003554 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003555 XFA_ATTRIBUTE eAttribute) {
3556 if (bSetting) {
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05003557 ThrowInvalidPropertyException();
Dan Sinclair1770c022016-03-14 14:14:16 -04003558 return;
3559 }
dan sinclair65c7c232017-02-02 14:05:30 -08003560 pValue->SetString(FX_UTF8Encode(CFX_WideStringC(L"0", 1)).AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003561}
dsinclair5b36f0a2016-07-19 10:56:23 -07003562
dsinclair12a6b0c2016-05-26 11:14:08 -07003563void CXFA_Node::Script_Encrypt_Format(CFXJSE_Value* pValue,
tsepezd19e9122016-11-02 15:43:18 -07003564 bool bSetting,
Dan Sinclair1770c022016-03-14 14:14:16 -04003565 XFA_ATTRIBUTE eAttribute) {}
dsinclair5b36f0a2016-07-19 10:56:23 -07003566
tsepezd19e9122016-11-02 15:43:18 -07003567bool CXFA_Node::HasAttribute(XFA_ATTRIBUTE eAttr, bool bCanInherit) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003568 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003569 return HasMapModuleKey(pKey, bCanInherit);
3570}
dsinclair5b36f0a2016-07-19 10:56:23 -07003571
tsepezd19e9122016-11-02 15:43:18 -07003572bool CXFA_Node::SetAttribute(XFA_ATTRIBUTE eAttr,
3573 const CFX_WideStringC& wsValue,
3574 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003575 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003576 if (!pAttr)
tsepezd19e9122016-11-02 15:43:18 -07003577 return false;
weili44f8faf2016-06-01 14:03:56 -07003578
Dan Sinclair1770c022016-03-14 14:14:16 -04003579 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3580 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3581 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003582 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003583 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3584 }
3585 switch (eType) {
3586 case XFA_ATTRIBUTETYPE_Enum: {
3587 const XFA_ATTRIBUTEENUMINFO* pEnum = XFA_GetAttributeEnumByName(wsValue);
3588 return SetEnum(pAttr->eName,
3589 pEnum ? pEnum->eName
3590 : (XFA_ATTRIBUTEENUM)(intptr_t)(pAttr->pDefValue),
3591 bNotify);
3592 } break;
3593 case XFA_ATTRIBUTETYPE_Cdata:
tsepezafe94302016-05-13 17:21:31 -07003594 return SetCData(pAttr->eName, CFX_WideString(wsValue), bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003595 case XFA_ATTRIBUTETYPE_Boolean:
dan sinclair65c7c232017-02-02 14:05:30 -08003596 return SetBoolean(pAttr->eName, wsValue != L"0", bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003597 case XFA_ATTRIBUTETYPE_Integer:
dsinclaire0347a62016-08-11 11:24:11 -07003598 return SetInteger(pAttr->eName,
3599 FXSYS_round(FXSYS_wcstof(wsValue.c_str(),
3600 wsValue.GetLength(), nullptr)),
3601 bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003602 case XFA_ATTRIBUTETYPE_Measure:
3603 return SetMeasure(pAttr->eName, CXFA_Measurement(wsValue), bNotify);
3604 default:
3605 break;
3606 }
tsepezd19e9122016-11-02 15:43:18 -07003607 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003608}
dsinclair5b36f0a2016-07-19 10:56:23 -07003609
tsepezd19e9122016-11-02 15:43:18 -07003610bool CXFA_Node::GetAttribute(XFA_ATTRIBUTE eAttr,
3611 CFX_WideString& wsValue,
3612 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003613 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
weili44f8faf2016-06-01 14:03:56 -07003614 if (!pAttr) {
tsepezd19e9122016-11-02 15:43:18 -07003615 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003616 }
3617 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3618 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3619 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07003620 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
Dan Sinclair1770c022016-03-14 14:14:16 -04003621 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3622 }
3623 switch (eType) {
3624 case XFA_ATTRIBUTETYPE_Enum: {
3625 XFA_ATTRIBUTEENUM eValue;
3626 if (!TryEnum(pAttr->eName, eValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003627 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003628 }
dsinclair9eb0db12016-07-21 12:01:39 -07003629 wsValue = GetAttributeEnumByID(eValue)->pName;
tsepezd19e9122016-11-02 15:43:18 -07003630 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003631 } break;
3632 case XFA_ATTRIBUTETYPE_Cdata: {
3633 CFX_WideStringC wsValueC;
3634 if (!TryCData(pAttr->eName, wsValueC, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003635 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003636 }
3637 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07003638 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003639 } break;
3640 case XFA_ATTRIBUTETYPE_Boolean: {
tsepezd19e9122016-11-02 15:43:18 -07003641 bool bValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04003642 if (!TryBoolean(pAttr->eName, bValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003643 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003644 }
dan sinclair65c7c232017-02-02 14:05:30 -08003645 wsValue = bValue ? L"1" : L"0";
tsepezd19e9122016-11-02 15:43:18 -07003646 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003647 } break;
3648 case XFA_ATTRIBUTETYPE_Integer: {
3649 int32_t iValue;
3650 if (!TryInteger(pAttr->eName, iValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003651 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003652 }
3653 wsValue.Format(L"%d", iValue);
tsepezd19e9122016-11-02 15:43:18 -07003654 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003655 } break;
3656 case XFA_ATTRIBUTETYPE_Measure: {
3657 CXFA_Measurement mValue;
3658 if (!TryMeasure(pAttr->eName, mValue, bUseDefault)) {
tsepezd19e9122016-11-02 15:43:18 -07003659 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003660 }
3661 mValue.ToString(wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003662 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003663 } break;
3664 default:
3665 break;
3666 }
tsepezd19e9122016-11-02 15:43:18 -07003667 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003668}
dsinclair5b36f0a2016-07-19 10:56:23 -07003669
tsepezd19e9122016-11-02 15:43:18 -07003670bool CXFA_Node::SetAttribute(const CFX_WideStringC& wsAttr,
3671 const CFX_WideStringC& wsValue,
3672 bool bNotify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003673 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsValue);
3674 if (pAttributeInfo) {
3675 return SetAttribute(pAttributeInfo->eName, wsValue, bNotify);
3676 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003677 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003678 SetMapModuleString(pKey, wsValue);
tsepezd19e9122016-11-02 15:43:18 -07003679 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003680}
dsinclair5b36f0a2016-07-19 10:56:23 -07003681
tsepezd19e9122016-11-02 15:43:18 -07003682bool CXFA_Node::GetAttribute(const CFX_WideStringC& wsAttr,
3683 CFX_WideString& wsValue,
3684 bool bUseDefault) {
Dan Sinclair1770c022016-03-14 14:14:16 -04003685 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsAttr);
3686 if (pAttributeInfo) {
3687 return GetAttribute(pAttributeInfo->eName, wsValue, bUseDefault);
3688 }
dsinclair5b36f0a2016-07-19 10:56:23 -07003689 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003690 CFX_WideStringC wsValueC;
3691 if (GetMapModuleString(pKey, wsValueC)) {
3692 wsValue = wsValueC;
3693 }
tsepezd19e9122016-11-02 15:43:18 -07003694 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003695}
dsinclair5b36f0a2016-07-19 10:56:23 -07003696
tsepezd19e9122016-11-02 15:43:18 -07003697bool CXFA_Node::RemoveAttribute(const CFX_WideStringC& wsAttr) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003698 void* pKey = GetMapKey_Custom(wsAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003699 RemoveMapModuleKey(pKey);
tsepezd19e9122016-11-02 15:43:18 -07003700 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003701}
dsinclair5b36f0a2016-07-19 10:56:23 -07003702
tsepezd19e9122016-11-02 15:43:18 -07003703bool CXFA_Node::TryBoolean(XFA_ATTRIBUTE eAttr,
3704 bool& bValue,
3705 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003706 void* pValue = nullptr;
3707 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Boolean, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003708 return false;
tsepez478ed622016-10-27 14:32:33 -07003709 bValue = !!pValue;
tsepezd19e9122016-11-02 15:43:18 -07003710 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003711}
dsinclair5b36f0a2016-07-19 10:56:23 -07003712
tsepezd19e9122016-11-02 15:43:18 -07003713bool CXFA_Node::TryInteger(XFA_ATTRIBUTE eAttr,
3714 int32_t& iValue,
3715 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003716 void* pValue = nullptr;
3717 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Integer, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003718 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003719 iValue = (int32_t)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003720 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003721}
dsinclair5b36f0a2016-07-19 10:56:23 -07003722
tsepezd19e9122016-11-02 15:43:18 -07003723bool CXFA_Node::TryEnum(XFA_ATTRIBUTE eAttr,
3724 XFA_ATTRIBUTEENUM& eValue,
3725 bool bUseDefault) {
weili44f8faf2016-06-01 14:03:56 -07003726 void* pValue = nullptr;
3727 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Enum, bUseDefault, pValue))
tsepezd19e9122016-11-02 15:43:18 -07003728 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003729 eValue = (XFA_ATTRIBUTEENUM)(uintptr_t)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003730 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003731}
thestigb1a59592016-04-14 18:29:56 -07003732
tsepezd19e9122016-11-02 15:43:18 -07003733bool CXFA_Node::SetMeasure(XFA_ATTRIBUTE eAttr,
3734 CXFA_Measurement mValue,
3735 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003736 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003737 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003738 SetMapModuleBuffer(pKey, &mValue, sizeof(CXFA_Measurement));
tsepezd19e9122016-11-02 15:43:18 -07003739 OnChanged(eAttr, bNotify, false);
3740 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003741}
thestigb1a59592016-04-14 18:29:56 -07003742
tsepezd19e9122016-11-02 15:43:18 -07003743bool CXFA_Node::TryMeasure(XFA_ATTRIBUTE eAttr,
3744 CXFA_Measurement& mValue,
3745 bool bUseDefault) const {
dsinclair5b36f0a2016-07-19 10:56:23 -07003746 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003747 void* pValue;
3748 int32_t iBytes;
3749 if (GetMapModuleBuffer(pKey, pValue, iBytes) && iBytes == sizeof(mValue)) {
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04003750 memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003751 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003752 }
3753 if (bUseDefault &&
dsinclair070fcdf2016-06-22 22:04:54 -07003754 XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003755 XFA_ATTRIBUTETYPE_Measure, m_ePacket)) {
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04003756 memcpy(&mValue, pValue, sizeof(mValue));
tsepezd19e9122016-11-02 15:43:18 -07003757 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003758 }
tsepezd19e9122016-11-02 15:43:18 -07003759 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003760}
3761
3762CXFA_Measurement CXFA_Node::GetMeasure(XFA_ATTRIBUTE eAttr) const {
3763 CXFA_Measurement mValue;
tsepezd19e9122016-11-02 15:43:18 -07003764 return TryMeasure(eAttr, mValue, true) ? mValue : CXFA_Measurement();
Dan Sinclair1770c022016-03-14 14:14:16 -04003765}
3766
tsepezd19e9122016-11-02 15:43:18 -07003767bool CXFA_Node::SetCData(XFA_ATTRIBUTE eAttr,
3768 const CFX_WideString& wsValue,
3769 bool bNotify,
3770 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003771 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003772 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003773 if (eAttr == XFA_ATTRIBUTE_Value) {
3774 CFX_WideString* pClone = new CFX_WideString(wsValue);
3775 SetUserData(pKey, pClone, &deleteWideStringCallBack);
3776 } else {
tsepez4c3debb2016-04-08 12:20:38 -07003777 SetMapModuleString(pKey, wsValue.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04003778 if (eAttr == XFA_ATTRIBUTE_Name)
3779 UpdateNameHash();
3780 }
thestigb1a59592016-04-14 18:29:56 -07003781 OnChanged(eAttr, bNotify, bScriptModify);
3782
3783 if (!IsNeedSavingXMLNode() || eAttr == XFA_ATTRIBUTE_QualifiedName ||
3784 eAttr == XFA_ATTRIBUTE_BindingNode) {
tsepezd19e9122016-11-02 15:43:18 -07003785 return true;
thestigb1a59592016-04-14 18:29:56 -07003786 }
3787
dsinclair070fcdf2016-06-22 22:04:54 -07003788 if (eAttr == XFA_ATTRIBUTE_Name &&
3789 (m_elementType == XFA_Element::DataValue ||
3790 m_elementType == XFA_Element::DataGroup)) {
tsepezd19e9122016-11-02 15:43:18 -07003791 return true;
thestigb1a59592016-04-14 18:29:56 -07003792 }
3793
3794 if (eAttr == XFA_ATTRIBUTE_Value) {
3795 FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
3796 switch (eXMLType) {
3797 case FDE_XMLNODE_Element:
3798 if (IsAttributeInXML()) {
3799 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003800 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3801 wsValue);
thestigb1a59592016-04-14 18:29:56 -07003802 } else {
tsepezd19e9122016-11-02 15:43:18 -07003803 bool bDeleteChildren = true;
thestigb1a59592016-04-14 18:29:56 -07003804 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3805 for (CXFA_Node* pChildDataNode =
3806 GetNodeItem(XFA_NODEITEM_FirstChild);
3807 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3808 XFA_NODEITEM_NextSibling)) {
Tom Sepezf8a94392017-03-14 12:13:22 -07003809 if (!pChildDataNode->GetBindItems().empty()) {
tsepezd19e9122016-11-02 15:43:18 -07003810 bDeleteChildren = false;
thestigb1a59592016-04-14 18:29:56 -07003811 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04003812 }
3813 }
Dan Sinclair1770c022016-03-14 14:14:16 -04003814 }
thestigb1a59592016-04-14 18:29:56 -07003815 if (bDeleteChildren) {
3816 static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren();
3817 }
3818 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsValue);
3819 }
3820 break;
3821 case FDE_XMLNODE_Text:
3822 static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsValue);
3823 break;
3824 default:
dsinclair43854a52016-04-27 12:26:00 -07003825 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003826 }
tsepezd19e9122016-11-02 15:43:18 -07003827 return true;
thestigb1a59592016-04-14 18:29:56 -07003828 }
3829
3830 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
3831 if (pInfo) {
dsinclair43854a52016-04-27 12:26:00 -07003832 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element);
thestigb1a59592016-04-14 18:29:56 -07003833 CFX_WideString wsAttrName = pInfo->pName;
3834 if (pInfo->eName == XFA_ATTRIBUTE_ContentType) {
dan sinclair65c7c232017-02-02 14:05:30 -08003835 wsAttrName = L"xfa:" + wsAttrName;
Dan Sinclair1770c022016-03-14 14:14:16 -04003836 }
thestigb1a59592016-04-14 18:29:56 -07003837 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetString(wsAttrName, wsValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003838 }
tsepezd19e9122016-11-02 15:43:18 -07003839 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003840}
thestigb1a59592016-04-14 18:29:56 -07003841
tsepezd19e9122016-11-02 15:43:18 -07003842bool CXFA_Node::SetAttributeValue(const CFX_WideString& wsValue,
3843 const CFX_WideString& wsXMLValue,
3844 bool bNotify,
3845 bool bScriptModify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003846 void* pKey = GetMapKey_Element(GetElementType(), XFA_ATTRIBUTE_Value);
thestigb1a59592016-04-14 18:29:56 -07003847 OnChanging(XFA_ATTRIBUTE_Value, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003848 CFX_WideString* pClone = new CFX_WideString(wsValue);
3849 SetUserData(pKey, pClone, &deleteWideStringCallBack);
thestigb1a59592016-04-14 18:29:56 -07003850 OnChanged(XFA_ATTRIBUTE_Value, bNotify, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003851 if (IsNeedSavingXMLNode()) {
3852 FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
3853 switch (eXMLType) {
3854 case FDE_XMLNODE_Element:
3855 if (IsAttributeInXML()) {
dsinclairae95f762016-03-29 16:58:29 -07003856 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003857 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3858 wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003859 } else {
tsepezd19e9122016-11-02 15:43:18 -07003860 bool bDeleteChildren = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003861 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3862 for (CXFA_Node* pChildDataNode =
3863 GetNodeItem(XFA_NODEITEM_FirstChild);
3864 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3865 XFA_NODEITEM_NextSibling)) {
Tom Sepezf8a94392017-03-14 12:13:22 -07003866 if (!pChildDataNode->GetBindItems().empty()) {
tsepezd19e9122016-11-02 15:43:18 -07003867 bDeleteChildren = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003868 break;
3869 }
3870 }
3871 }
3872 if (bDeleteChildren) {
dsinclairae95f762016-03-29 16:58:29 -07003873 static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren();
Dan Sinclair1770c022016-03-14 14:14:16 -04003874 }
dsinclairae95f762016-03-29 16:58:29 -07003875 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003876 }
3877 break;
3878 case FDE_XMLNODE_Text:
dsinclairae95f762016-03-29 16:58:29 -07003879 static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsXMLValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04003880 break;
3881 default:
dsinclair43854a52016-04-27 12:26:00 -07003882 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003883 }
3884 }
tsepezd19e9122016-11-02 15:43:18 -07003885 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003886}
dsinclair5b36f0a2016-07-19 10:56:23 -07003887
tsepezd19e9122016-11-02 15:43:18 -07003888bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3889 CFX_WideString& wsValue,
3890 bool bUseDefault,
3891 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003892 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003893 if (eAttr == XFA_ATTRIBUTE_Value) {
3894 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
3895 if (pStr) {
3896 wsValue = *pStr;
tsepezd19e9122016-11-02 15:43:18 -07003897 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003898 }
3899 } else {
3900 CFX_WideStringC wsValueC;
3901 if (GetMapModuleString(pKey, wsValueC)) {
3902 wsValue = wsValueC;
tsepezd19e9122016-11-02 15:43:18 -07003903 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003904 }
3905 }
3906 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07003907 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003908 }
weili44f8faf2016-06-01 14:03:56 -07003909 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07003910 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003911 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
Dan Sinclair812e96c2017-03-13 16:43:37 -04003912 wsValue = (const wchar_t*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003913 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003914 }
tsepezd19e9122016-11-02 15:43:18 -07003915 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003916}
dsinclair5b36f0a2016-07-19 10:56:23 -07003917
tsepezd19e9122016-11-02 15:43:18 -07003918bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3919 CFX_WideStringC& wsValue,
3920 bool bUseDefault,
3921 bool bProto) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003922 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003923 if (eAttr == XFA_ATTRIBUTE_Value) {
3924 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
3925 if (pStr) {
tsepez4d31d0c2016-04-19 14:11:59 -07003926 wsValue = pStr->AsStringC();
tsepezd19e9122016-11-02 15:43:18 -07003927 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003928 }
3929 } else {
3930 if (GetMapModuleString(pKey, wsValue)) {
tsepezd19e9122016-11-02 15:43:18 -07003931 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003932 }
3933 }
3934 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07003935 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003936 }
weili44f8faf2016-06-01 14:03:56 -07003937 void* pValue = nullptr;
dsinclair070fcdf2016-06-22 22:04:54 -07003938 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
Dan Sinclair1770c022016-03-14 14:14:16 -04003939 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
Dan Sinclair812e96c2017-03-13 16:43:37 -04003940 wsValue = (CFX_WideStringC)(const wchar_t*)pValue;
tsepezd19e9122016-11-02 15:43:18 -07003941 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003942 }
tsepezd19e9122016-11-02 15:43:18 -07003943 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04003944}
dsinclair5b36f0a2016-07-19 10:56:23 -07003945
tsepezd19e9122016-11-02 15:43:18 -07003946bool CXFA_Node::SetObject(XFA_ATTRIBUTE eAttr,
3947 void* pData,
3948 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003949 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003950 return SetUserData(pKey, pData, pCallbackInfo);
3951}
dsinclair5b36f0a2016-07-19 10:56:23 -07003952
tsepezd19e9122016-11-02 15:43:18 -07003953bool CXFA_Node::TryObject(XFA_ATTRIBUTE eAttr, void*& pData) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003954 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04003955 pData = GetUserData(pKey);
dsinclair85d1f2c2016-06-23 12:40:16 -07003956 return !!pData;
Dan Sinclair1770c022016-03-14 14:14:16 -04003957}
dsinclair5b36f0a2016-07-19 10:56:23 -07003958
tsepezd19e9122016-11-02 15:43:18 -07003959bool CXFA_Node::SetValue(XFA_ATTRIBUTE eAttr,
3960 XFA_ATTRIBUTETYPE eType,
3961 void* pValue,
3962 bool bNotify) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003963 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
thestigb1a59592016-04-14 18:29:56 -07003964 OnChanging(eAttr, bNotify);
Dan Sinclair1770c022016-03-14 14:14:16 -04003965 SetMapModuleValue(pKey, pValue);
tsepezd19e9122016-11-02 15:43:18 -07003966 OnChanged(eAttr, bNotify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04003967 if (IsNeedSavingXMLNode()) {
dsinclair43854a52016-04-27 12:26:00 -07003968 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04003969 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
3970 if (pInfo) {
3971 switch (eType) {
3972 case XFA_ATTRIBUTETYPE_Enum:
dsinclairae95f762016-03-29 16:58:29 -07003973 static_cast<CFDE_XMLElement*>(m_pXMLNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04003974 ->SetString(
3975 pInfo->pName,
dsinclair9eb0db12016-07-21 12:01:39 -07003976 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)(uintptr_t)pValue)
Dan Sinclair1770c022016-03-14 14:14:16 -04003977 ->pName);
3978 break;
3979 case XFA_ATTRIBUTETYPE_Boolean:
dsinclairae95f762016-03-29 16:58:29 -07003980 static_cast<CFDE_XMLElement*>(m_pXMLNode)
tsepezafe94302016-05-13 17:21:31 -07003981 ->SetString(pInfo->pName, pValue ? L"1" : L"0");
Dan Sinclair1770c022016-03-14 14:14:16 -04003982 break;
3983 case XFA_ATTRIBUTETYPE_Integer:
dsinclairae95f762016-03-29 16:58:29 -07003984 static_cast<CFDE_XMLElement*>(m_pXMLNode)
Dan Sinclair1770c022016-03-14 14:14:16 -04003985 ->SetInteger(pInfo->pName, (int32_t)(uintptr_t)pValue);
3986 break;
3987 default:
dsinclair43854a52016-04-27 12:26:00 -07003988 ASSERT(0);
Dan Sinclair1770c022016-03-14 14:14:16 -04003989 }
3990 }
3991 }
tsepezd19e9122016-11-02 15:43:18 -07003992 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04003993}
dsinclair5b36f0a2016-07-19 10:56:23 -07003994
tsepezd19e9122016-11-02 15:43:18 -07003995bool CXFA_Node::GetValue(XFA_ATTRIBUTE eAttr,
3996 XFA_ATTRIBUTETYPE eType,
3997 bool bUseDefault,
3998 void*& pValue) {
dsinclair5b36f0a2016-07-19 10:56:23 -07003999 void* pKey = GetMapKey_Element(GetElementType(), eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004000 if (GetMapModuleValue(pKey, pValue)) {
tsepezd19e9122016-11-02 15:43:18 -07004001 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004002 }
4003 if (!bUseDefault) {
tsepezd19e9122016-11-02 15:43:18 -07004004 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004005 }
dsinclair070fcdf2016-06-22 22:04:54 -07004006 return XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, eType,
Dan Sinclair1770c022016-03-14 14:14:16 -04004007 m_ePacket);
4008}
dsinclair5b36f0a2016-07-19 10:56:23 -07004009
tsepezd19e9122016-11-02 15:43:18 -07004010bool CXFA_Node::SetUserData(void* pKey,
4011 void* pData,
4012 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004013 SetMapModuleBuffer(pKey, &pData, sizeof(void*),
4014 pCallbackInfo ? pCallbackInfo : &gs_XFADefaultFreeData);
tsepezd19e9122016-11-02 15:43:18 -07004015 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004016}
dsinclair5b36f0a2016-07-19 10:56:23 -07004017
tsepezd19e9122016-11-02 15:43:18 -07004018bool CXFA_Node::TryUserData(void* pKey, void*& pData, bool bProtoAlso) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004019 int32_t iBytes = 0;
4020 if (!GetMapModuleBuffer(pKey, pData, iBytes, bProtoAlso)) {
tsepezd19e9122016-11-02 15:43:18 -07004021 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004022 }
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04004023 return iBytes == sizeof(void*) && memcpy(&pData, pData, iBytes);
Dan Sinclair1770c022016-03-14 14:14:16 -04004024}
dsinclair5b36f0a2016-07-19 10:56:23 -07004025
tsepezd19e9122016-11-02 15:43:18 -07004026bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent,
4027 const CFX_WideString& wsXMLValue,
4028 bool bNotify,
4029 bool bScriptModify,
4030 bool bSyncData) {
weili44f8faf2016-06-01 14:03:56 -07004031 CXFA_Node* pNode = nullptr;
4032 CXFA_Node* pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004033 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004034 case XFA_ObjectType::ContainerNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004035 if (XFA_FieldIsMultiListBox(this)) {
dsinclair56a8b192016-06-21 14:15:25 -07004036 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004037 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004038 ASSERT(pChildValue);
tsepezafe94302016-05-13 17:21:31 -07004039 pChildValue->SetCData(XFA_ATTRIBUTE_ContentType, L"text/xml");
Dan Sinclair1770c022016-03-14 14:14:16 -04004040 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004041 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004042 CXFA_Node* pBind = GetBindData();
4043 if (bSyncData && pBind) {
tsepez51709be2016-12-08 10:55:57 -08004044 std::vector<CFX_WideString> wsSaveTextArray;
Tom Sepezf8a94392017-03-14 12:13:22 -07004045 size_t iSize = 0;
Dan Sinclair1770c022016-03-14 14:14:16 -04004046 if (!wsContent.IsEmpty()) {
4047 int32_t iStart = 0;
4048 int32_t iLength = wsContent.GetLength();
4049 int32_t iEnd = wsContent.Find(L'\n', iStart);
4050 iEnd = (iEnd == -1) ? iLength : iEnd;
4051 while (iEnd >= iStart) {
tsepez51709be2016-12-08 10:55:57 -08004052 wsSaveTextArray.push_back(wsContent.Mid(iStart, iEnd - iStart));
Dan Sinclair1770c022016-03-14 14:14:16 -04004053 iStart = iEnd + 1;
4054 if (iStart >= iLength) {
4055 break;
4056 }
4057 iEnd = wsContent.Find(L'\n', iStart);
4058 if (iEnd < 0) {
tsepez51709be2016-12-08 10:55:57 -08004059 wsSaveTextArray.push_back(
4060 wsContent.Mid(iStart, iLength - iStart));
Dan Sinclair1770c022016-03-14 14:14:16 -04004061 }
4062 }
Tom Sepezf8a94392017-03-14 12:13:22 -07004063 iSize = wsSaveTextArray.size();
Dan Sinclair1770c022016-03-14 14:14:16 -04004064 }
4065 if (iSize == 0) {
4066 while (CXFA_Node* pChildNode =
4067 pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) {
4068 pBind->RemoveChild(pChildNode);
4069 }
4070 } else {
Tom Sepezf8a94392017-03-14 12:13:22 -07004071 std::vector<CXFA_Node*> valueNodes = pBind->GetNodeList(
4072 XFA_NODEFILTER_Children, XFA_Element::DataValue);
4073 size_t iDatas = valueNodes.size();
Dan Sinclair1770c022016-03-14 14:14:16 -04004074 if (iDatas < iSize) {
Tom Sepezf8a94392017-03-14 12:13:22 -07004075 size_t iAddNodes = iSize - iDatas;
weili44f8faf2016-06-01 14:03:56 -07004076 CXFA_Node* pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004077 while (iAddNodes-- > 0) {
4078 pValueNodes =
dsinclair56a8b192016-06-21 14:15:25 -07004079 pBind->CreateSamePacketNode(XFA_Element::DataValue);
tsepezafe94302016-05-13 17:21:31 -07004080 pValueNodes->SetCData(XFA_ATTRIBUTE_Name, L"value");
Dan Sinclair1770c022016-03-14 14:14:16 -04004081 pValueNodes->CreateXMLMappingNode();
4082 pBind->InsertChild(pValueNodes);
4083 }
weili44f8faf2016-06-01 14:03:56 -07004084 pValueNodes = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004085 } else if (iDatas > iSize) {
Tom Sepezf8a94392017-03-14 12:13:22 -07004086 size_t iDelNodes = iDatas - iSize;
Dan Sinclair1770c022016-03-14 14:14:16 -04004087 while (iDelNodes-- > 0) {
4088 pBind->RemoveChild(pBind->GetNodeItem(XFA_NODEITEM_FirstChild));
4089 }
4090 }
4091 int32_t i = 0;
4092 for (CXFA_Node* pValueNode =
4093 pBind->GetNodeItem(XFA_NODEITEM_FirstChild);
4094 pValueNode; pValueNode = pValueNode->GetNodeItem(
4095 XFA_NODEITEM_NextSibling)) {
4096 pValueNode->SetAttributeValue(wsSaveTextArray[i],
tsepezd19e9122016-11-02 15:43:18 -07004097 wsSaveTextArray[i], false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004098 i++;
4099 }
4100 }
Tom Sepezf8a94392017-03-14 12:13:22 -07004101 for (CXFA_Node* pArrayNode : pBind->GetBindItems()) {
4102 if (pArrayNode != this) {
4103 pArrayNode->SetScriptContent(wsContent, wsContent, bNotify,
4104 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004105 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004106 }
4107 }
4108 break;
dsinclair070fcdf2016-06-22 22:04:54 -07004109 } else if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004110 pNode = this;
4111 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004112 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004113 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
dsinclair43854a52016-04-27 12:26:00 -07004114 ASSERT(pChildValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04004115 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004116 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004117 }
4118 pBindNode = GetBindData();
4119 if (pBindNode && bSyncData) {
4120 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004121 bScriptModify, false);
Tom Sepezf8a94392017-03-14 12:13:22 -07004122 for (CXFA_Node* pArrayNode : pBindNode->GetBindItems()) {
4123 if (pArrayNode != this) {
4124 pArrayNode->SetScriptContent(wsContent, wsContent, bNotify, true,
4125 false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004126 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004127 }
4128 }
weili44f8faf2016-06-01 14:03:56 -07004129 pBindNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004130 break;
4131 }
dsinclairc5a8f212016-06-20 11:11:12 -07004132 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004133 CFX_WideString wsContentType;
dsinclair070fcdf2016-06-22 22:04:54 -07004134 if (GetElementType() == XFA_Element::ExData) {
tsepezd19e9122016-11-02 15:43:18 -07004135 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
dan sinclair65c7c232017-02-02 14:05:30 -08004136 if (wsContentType == L"text/html") {
4137 wsContentType = L"";
tsepez4c3debb2016-04-08 12:20:38 -07004138 SetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -04004139 }
4140 }
4141 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4142 if (!pContentRawDataNode) {
tsepez9f2970c2016-04-01 10:23:04 -07004143 pContentRawDataNode = CreateSamePacketNode(
dan sinclair65c7c232017-02-02 14:05:30 -08004144 (wsContentType == L"text/xml") ? XFA_Element::Sharpxml
4145 : XFA_Element::Sharptext);
Dan Sinclair1770c022016-03-14 14:14:16 -04004146 InsertChild(pContentRawDataNode);
4147 }
4148 return pContentRawDataNode->SetScriptContent(
4149 wsContent, wsXMLValue, bNotify, bScriptModify, bSyncData);
4150 } break;
dsinclairc5a8f212016-06-20 11:11:12 -07004151 case XFA_ObjectType::NodeC:
4152 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004153 pNode = this;
4154 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004155 case XFA_ObjectType::NodeV:
Dan Sinclair1770c022016-03-14 14:14:16 -04004156 pNode = this;
4157 if (bSyncData && GetPacketID() == XFA_XDPPACKET_Form) {
4158 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
4159 if (pParent) {
4160 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4161 }
dsinclair070fcdf2016-06-22 22:04:54 -07004162 if (pParent && pParent->GetElementType() == XFA_Element::Value) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004163 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4164 if (pParent && pParent->IsContainerNode()) {
4165 pBindNode = pParent->GetBindData();
4166 if (pBindNode) {
4167 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004168 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004169 }
4170 }
4171 }
4172 }
4173 break;
4174 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004175 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004176 pNode = this;
4177 pBindNode = this;
4178 }
4179 break;
4180 }
4181 if (pNode) {
4182 SetAttributeValue(wsContent, wsXMLValue, bNotify, bScriptModify);
4183 if (pBindNode && bSyncData) {
Tom Sepezf8a94392017-03-14 12:13:22 -07004184 for (CXFA_Node* pArrayNode : pBindNode->GetBindItems()) {
4185 pArrayNode->SetScriptContent(wsContent, wsContent, bNotify,
4186 bScriptModify, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004187 }
4188 }
tsepezd19e9122016-11-02 15:43:18 -07004189 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004190 }
tsepezd19e9122016-11-02 15:43:18 -07004191 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004192}
dsinclair5b36f0a2016-07-19 10:56:23 -07004193
tsepezd19e9122016-11-02 15:43:18 -07004194bool CXFA_Node::SetContent(const CFX_WideString& wsContent,
4195 const CFX_WideString& wsXMLValue,
4196 bool bNotify,
4197 bool bScriptModify,
4198 bool bSyncData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004199 return SetScriptContent(wsContent, wsXMLValue, bNotify, bScriptModify,
4200 bSyncData);
4201}
dsinclair5b36f0a2016-07-19 10:56:23 -07004202
tsepezd19e9122016-11-02 15:43:18 -07004203CFX_WideString CXFA_Node::GetScriptContent(bool bScriptModify) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004204 CFX_WideString wsContent;
4205 return TryContent(wsContent, bScriptModify) ? wsContent : CFX_WideString();
4206}
dsinclair5b36f0a2016-07-19 10:56:23 -07004207
Dan Sinclair1770c022016-03-14 14:14:16 -04004208CFX_WideString CXFA_Node::GetContent() {
4209 return GetScriptContent();
4210}
dsinclair5b36f0a2016-07-19 10:56:23 -07004211
tsepezd19e9122016-11-02 15:43:18 -07004212bool CXFA_Node::TryContent(CFX_WideString& wsContent,
4213 bool bScriptModify,
4214 bool bProto) {
weili44f8faf2016-06-01 14:03:56 -07004215 CXFA_Node* pNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004216 switch (GetObjectType()) {
dsinclairc5a8f212016-06-20 11:11:12 -07004217 case XFA_ObjectType::ContainerNode:
dsinclair070fcdf2016-06-22 22:04:54 -07004218 if (GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004219 pNode = this;
4220 } else {
dsinclair56a8b192016-06-21 14:15:25 -07004221 CXFA_Node* pValue = GetChild(0, XFA_Element::Value);
Dan Sinclair1770c022016-03-14 14:14:16 -04004222 if (!pValue) {
tsepezd19e9122016-11-02 15:43:18 -07004223 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004224 }
4225 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
4226 if (pChildValue && XFA_FieldIsMultiListBox(this)) {
dan sinclair65c7c232017-02-02 14:05:30 -08004227 pChildValue->SetAttribute(XFA_ATTRIBUTE_ContentType, L"text/xml");
Dan Sinclair1770c022016-03-14 14:14:16 -04004228 }
4229 return pChildValue
4230 ? pChildValue->TryContent(wsContent, bScriptModify, bProto)
tsepezd19e9122016-11-02 15:43:18 -07004231 : false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004232 }
4233 break;
dsinclairc5a8f212016-06-20 11:11:12 -07004234 case XFA_ObjectType::ContentNode: {
Dan Sinclair1770c022016-03-14 14:14:16 -04004235 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4236 if (!pContentRawDataNode) {
dsinclair56a8b192016-06-21 14:15:25 -07004237 XFA_Element element = XFA_Element::Sharptext;
dsinclair070fcdf2016-06-22 22:04:54 -07004238 if (GetElementType() == XFA_Element::ExData) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004239 CFX_WideString wsContentType;
tsepezd19e9122016-11-02 15:43:18 -07004240 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false);
dan sinclair65c7c232017-02-02 14:05:30 -08004241 if (wsContentType == L"text/html") {
dsinclair56a8b192016-06-21 14:15:25 -07004242 element = XFA_Element::SharpxHTML;
dan sinclair65c7c232017-02-02 14:05:30 -08004243 } else if (wsContentType == L"text/xml") {
dsinclair56a8b192016-06-21 14:15:25 -07004244 element = XFA_Element::Sharpxml;
Dan Sinclair1770c022016-03-14 14:14:16 -04004245 }
4246 }
4247 pContentRawDataNode = CreateSamePacketNode(element);
4248 InsertChild(pContentRawDataNode);
4249 }
4250 return pContentRawDataNode->TryContent(wsContent, bScriptModify, bProto);
4251 }
dsinclairc5a8f212016-06-20 11:11:12 -07004252 case XFA_ObjectType::NodeC:
4253 case XFA_ObjectType::NodeV:
4254 case XFA_ObjectType::TextNode:
Dan Sinclair1770c022016-03-14 14:14:16 -04004255 pNode = this;
4256 default:
dsinclair070fcdf2016-06-22 22:04:54 -07004257 if (GetElementType() == XFA_Element::DataValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004258 pNode = this;
4259 }
4260 break;
4261 }
4262 if (pNode) {
4263 if (bScriptModify) {
dsinclairdf4bc592016-03-31 20:34:43 -07004264 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004265 if (pScriptContext) {
4266 m_pDocument->GetScriptContext()->AddNodesOfRunScript(this);
4267 }
4268 }
tsepezd19e9122016-11-02 15:43:18 -07004269 return TryCData(XFA_ATTRIBUTE_Value, wsContent, false, bProto);
Dan Sinclair1770c022016-03-14 14:14:16 -04004270 }
tsepezd19e9122016-11-02 15:43:18 -07004271 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004272}
dsinclair5b36f0a2016-07-19 10:56:23 -07004273
Dan Sinclair1770c022016-03-14 14:14:16 -04004274CXFA_Node* CXFA_Node::GetModelNode() {
4275 switch (GetPacketID()) {
4276 case XFA_XDPPACKET_XDP:
4277 return m_pDocument->GetRoot();
4278 case XFA_XDPPACKET_Config:
4279 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config));
4280 case XFA_XDPPACKET_Template:
4281 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
4282 case XFA_XDPPACKET_Form:
4283 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form));
4284 case XFA_XDPPACKET_Datasets:
4285 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets));
4286 case XFA_XDPPACKET_LocaleSet:
4287 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_LocaleSet));
4288 case XFA_XDPPACKET_ConnectionSet:
4289 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_ConnectionSet));
4290 case XFA_XDPPACKET_SourceSet:
4291 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_SourceSet));
4292 case XFA_XDPPACKET_Xdc:
4293 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Xdc));
4294 default:
4295 return this;
4296 }
4297}
dsinclair5b36f0a2016-07-19 10:56:23 -07004298
tsepezd19e9122016-11-02 15:43:18 -07004299bool CXFA_Node::TryNamespace(CFX_WideString& wsNamespace) {
tsepez774bdde2016-04-14 09:49:44 -07004300 wsNamespace.clear();
dsinclair070fcdf2016-06-22 22:04:54 -07004301 if (IsModelNode() || GetElementType() == XFA_Element::Packet) {
dsinclairae95f762016-03-29 16:58:29 -07004302 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004303 if (!pXMLNode || pXMLNode->GetType() != FDE_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004304 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004305 }
dsinclairae95f762016-03-29 16:58:29 -07004306 static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace);
tsepezd19e9122016-11-02 15:43:18 -07004307 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004308 } else if (GetPacketID() == XFA_XDPPACKET_Datasets) {
dsinclairae95f762016-03-29 16:58:29 -07004309 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
Dan Sinclair1770c022016-03-14 14:14:16 -04004310 if (!pXMLNode) {
tsepezd19e9122016-11-02 15:43:18 -07004311 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004312 }
4313 if (pXMLNode->GetType() != FDE_XMLNODE_Element) {
tsepezd19e9122016-11-02 15:43:18 -07004314 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004315 }
dsinclair070fcdf2016-06-22 22:04:54 -07004316 if (GetElementType() == XFA_Element::DataValue &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004317 GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData) {
4318 return XFA_FDEExtension_ResolveNamespaceQualifier(
dsinclairae95f762016-03-29 16:58:29 -07004319 static_cast<CFDE_XMLElement*>(pXMLNode),
4320 GetCData(XFA_ATTRIBUTE_QualifiedName), wsNamespace);
Dan Sinclair1770c022016-03-14 14:14:16 -04004321 }
dsinclairae95f762016-03-29 16:58:29 -07004322 static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace);
tsepezd19e9122016-11-02 15:43:18 -07004323 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004324 } else {
4325 CXFA_Node* pModelNode = GetModelNode();
4326 return pModelNode->TryNamespace(wsNamespace);
4327 }
4328}
dsinclair5b36f0a2016-07-19 10:56:23 -07004329
Dan Sinclair1770c022016-03-14 14:14:16 -04004330CXFA_Node* CXFA_Node::GetProperty(int32_t index,
dsinclair56a8b192016-06-21 14:15:25 -07004331 XFA_Element eProperty,
tsepezd19e9122016-11-02 15:43:18 -07004332 bool bCreateProperty) {
dsinclair41cb62e2016-06-23 09:20:32 -07004333 XFA_Element eType = GetElementType();
tsepez736f28a2016-03-25 14:19:51 -07004334 uint32_t dwPacket = GetPacketID();
Dan Sinclair1770c022016-03-14 14:14:16 -04004335 const XFA_PROPERTY* pProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004336 XFA_GetPropertyOfElement(eType, eProperty, dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004337 if (!pProperty || index >= pProperty->uOccur)
4338 return nullptr;
4339
Dan Sinclair1770c022016-03-14 14:14:16 -04004340 CXFA_Node* pNode = m_pChild;
4341 int32_t iCount = 0;
4342 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004343 if (pNode->GetElementType() == eProperty) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004344 iCount++;
4345 if (iCount > index) {
4346 return pNode;
4347 }
4348 }
4349 }
weili44f8faf2016-06-01 14:03:56 -07004350 if (!bCreateProperty)
4351 return nullptr;
4352
Dan Sinclair1770c022016-03-14 14:14:16 -04004353 if (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf) {
4354 pNode = m_pChild;
4355 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4356 const XFA_PROPERTY* pExistProperty =
dsinclair41cb62e2016-06-23 09:20:32 -07004357 XFA_GetPropertyOfElement(eType, pNode->GetElementType(), dwPacket);
weili44f8faf2016-06-01 14:03:56 -07004358 if (pExistProperty && (pExistProperty->uFlags & XFA_PROPERTYFLAG_OneOf))
4359 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004360 }
4361 }
dsinclaira1b07722016-07-11 08:20:58 -07004362
Dan Sinclair1770c022016-03-14 14:14:16 -04004363 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(dwPacket);
weili038aa532016-05-20 15:38:29 -07004364 CXFA_Node* pNewNode = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004365 for (; iCount <= index; iCount++) {
dsinclaira1b07722016-07-11 08:20:58 -07004366 pNewNode = m_pDocument->CreateNode(pPacket, eProperty);
weili44f8faf2016-06-01 14:03:56 -07004367 if (!pNewNode)
4368 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004369 InsertChild(pNewNode, nullptr);
dsinclairc5a8f212016-06-20 11:11:12 -07004370 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004371 }
4372 return pNewNode;
4373}
dsinclair5b36f0a2016-07-19 10:56:23 -07004374
tsepezd19e9122016-11-02 15:43:18 -07004375int32_t CXFA_Node::CountChildren(XFA_Element eType, bool bOnlyChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004376 CXFA_Node* pNode = m_pChild;
4377 int32_t iCount = 0;
4378 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004379 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004380 if (bOnlyChild) {
4381 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004382 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004383 if (pProperty) {
4384 continue;
4385 }
4386 }
4387 iCount++;
4388 }
4389 }
4390 return iCount;
4391}
dsinclair5b36f0a2016-07-19 10:56:23 -07004392
Dan Sinclair1770c022016-03-14 14:14:16 -04004393CXFA_Node* CXFA_Node::GetChild(int32_t index,
dsinclair41cb62e2016-06-23 09:20:32 -07004394 XFA_Element eType,
tsepezd19e9122016-11-02 15:43:18 -07004395 bool bOnlyChild) {
dsinclair43854a52016-04-27 12:26:00 -07004396 ASSERT(index > -1);
Dan Sinclair1770c022016-03-14 14:14:16 -04004397 CXFA_Node* pNode = m_pChild;
4398 int32_t iCount = 0;
4399 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004400 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004401 if (bOnlyChild) {
4402 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
dsinclair070fcdf2016-06-22 22:04:54 -07004403 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
Dan Sinclair1770c022016-03-14 14:14:16 -04004404 if (pProperty) {
4405 continue;
4406 }
4407 }
4408 iCount++;
4409 if (iCount > index) {
4410 return pNode;
4411 }
4412 }
4413 }
weili44f8faf2016-06-01 14:03:56 -07004414 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004415}
dsinclair5b36f0a2016-07-19 10:56:23 -07004416
Dan Sinclair1770c022016-03-14 14:14:16 -04004417int32_t CXFA_Node::InsertChild(int32_t index, CXFA_Node* pNode) {
4418 ASSERT(!pNode->m_pNext);
4419 pNode->m_pParent = this;
tsepezd19e9122016-11-02 15:43:18 -07004420 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004421 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004422 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004423
weili44f8faf2016-06-01 14:03:56 -07004424 if (!m_pChild || index == 0) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004425 if (index > 0) {
4426 return -1;
4427 }
4428 pNode->m_pNext = m_pChild;
4429 m_pChild = pNode;
4430 index = 0;
4431 } else if (index < 0) {
4432 m_pLastChild->m_pNext = pNode;
4433 } else {
4434 CXFA_Node* pPrev = m_pChild;
4435 int32_t iCount = 0;
4436 while (++iCount != index && pPrev->m_pNext) {
4437 pPrev = pPrev->m_pNext;
4438 }
4439 if (index > 0 && index != iCount) {
4440 return -1;
4441 }
4442 pNode->m_pNext = pPrev->m_pNext;
4443 pPrev->m_pNext = pNode;
4444 index = iCount;
4445 }
weili44f8faf2016-06-01 14:03:56 -07004446 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004447 m_pLastChild = pNode;
4448 }
4449 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004450 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004451 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004452 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004453 if (pNotify)
4454 pNotify->OnChildAdded(this);
4455
Dan Sinclair1770c022016-03-14 14:14:16 -04004456 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
weili44f8faf2016-06-01 14:03:56 -07004457 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004458 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, index);
dsinclairc5a8f212016-06-20 11:11:12 -07004459 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004460 }
4461 return index;
4462}
weili6e1ae862016-05-04 18:25:27 -07004463
tsepezd19e9122016-11-02 15:43:18 -07004464bool CXFA_Node::InsertChild(CXFA_Node* pNode, CXFA_Node* pBeforeNode) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004465 if (!pNode || pNode->m_pParent ||
4466 (pBeforeNode && pBeforeNode->m_pParent != this)) {
dsinclair43854a52016-04-27 12:26:00 -07004467 ASSERT(false);
tsepezd19e9122016-11-02 15:43:18 -07004468 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004469 }
tsepezd19e9122016-11-02 15:43:18 -07004470 bool ret = m_pDocument->RemovePurgeNode(pNode);
Wei Li5fe7ae72016-05-04 21:13:15 -07004471 ASSERT(ret);
Wei Li439bb9e2016-05-05 00:35:26 -07004472 (void)ret; // Avoid unused variable warning.
Dan Sinclair1770c022016-03-14 14:14:16 -04004473
4474 int32_t nIndex = -1;
4475 pNode->m_pParent = this;
weili44f8faf2016-06-01 14:03:56 -07004476 if (!m_pChild || pBeforeNode == m_pChild) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004477 pNode->m_pNext = m_pChild;
4478 m_pChild = pNode;
4479 nIndex = 0;
4480 } else if (!pBeforeNode) {
4481 pNode->m_pNext = m_pLastChild->m_pNext;
4482 m_pLastChild->m_pNext = pNode;
4483 } else {
4484 nIndex = 1;
4485 CXFA_Node* pPrev = m_pChild;
4486 while (pPrev->m_pNext != pBeforeNode) {
4487 pPrev = pPrev->m_pNext;
4488 nIndex++;
4489 }
4490 pNode->m_pNext = pPrev->m_pNext;
4491 pPrev->m_pNext = pNode;
4492 }
weili44f8faf2016-06-01 14:03:56 -07004493 if (!pNode->m_pNext) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004494 m_pLastChild = pNode;
4495 }
4496 ASSERT(m_pLastChild);
weili44f8faf2016-06-01 14:03:56 -07004497 ASSERT(!m_pLastChild->m_pNext);
dsinclairc5a8f212016-06-20 11:11:12 -07004498 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
dsinclaira1b07722016-07-11 08:20:58 -07004499 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004500 if (pNotify)
4501 pNotify->OnChildAdded(this);
4502
Dan Sinclair1770c022016-03-14 14:14:16 -04004503 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
weili44f8faf2016-06-01 14:03:56 -07004504 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
Dan Sinclair1770c022016-03-14 14:14:16 -04004505 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, nIndex);
dsinclairc5a8f212016-06-20 11:11:12 -07004506 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004507 }
tsepezd19e9122016-11-02 15:43:18 -07004508 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004509}
dsinclair5b36f0a2016-07-19 10:56:23 -07004510
Dan Sinclair1770c022016-03-14 14:14:16 -04004511CXFA_Node* CXFA_Node::Deprecated_GetPrevSibling() {
4512 if (!m_pParent) {
weili44f8faf2016-06-01 14:03:56 -07004513 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004514 }
4515 for (CXFA_Node* pSibling = m_pParent->m_pChild; pSibling;
4516 pSibling = pSibling->m_pNext) {
4517 if (pSibling->m_pNext == this) {
4518 return pSibling;
4519 }
4520 }
weili44f8faf2016-06-01 14:03:56 -07004521 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004522}
dsinclair5b36f0a2016-07-19 10:56:23 -07004523
tsepezd19e9122016-11-02 15:43:18 -07004524bool CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) {
weili44f8faf2016-06-01 14:03:56 -07004525 if (!pNode || pNode->m_pParent != this) {
tsepezd19e9122016-11-02 15:43:18 -07004526 ASSERT(false);
4527 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004528 }
4529 if (m_pChild == pNode) {
4530 m_pChild = pNode->m_pNext;
4531 if (m_pLastChild == pNode) {
4532 m_pLastChild = pNode->m_pNext;
4533 }
weili44f8faf2016-06-01 14:03:56 -07004534 pNode->m_pNext = nullptr;
4535 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004536 } else {
4537 CXFA_Node* pPrev = pNode->Deprecated_GetPrevSibling();
4538 pPrev->m_pNext = pNode->m_pNext;
4539 if (m_pLastChild == pNode) {
4540 m_pLastChild = pNode->m_pNext ? pNode->m_pNext : pPrev;
4541 }
weili44f8faf2016-06-01 14:03:56 -07004542 pNode->m_pNext = nullptr;
4543 pNode->m_pParent = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004544 }
weili44f8faf2016-06-01 14:03:56 -07004545 ASSERT(!m_pLastChild || !m_pLastChild->m_pNext);
thestigb1a59592016-04-14 18:29:56 -07004546 OnRemoved(bNotify);
dsinclairc5a8f212016-06-20 11:11:12 -07004547 pNode->SetFlag(XFA_NodeFlag_HasRemovedChildren, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04004548 m_pDocument->AddPurgeNode(pNode);
4549 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
4550 if (pNode->IsAttributeInXML()) {
dsinclair43854a52016-04-27 12:26:00 -07004551 ASSERT(pNode->m_pXMLNode == m_pXMLNode &&
4552 m_pXMLNode->GetType() == FDE_XMLNODE_Element);
Dan Sinclair1770c022016-03-14 14:14:16 -04004553 if (pNode->m_pXMLNode->GetType() == FDE_XMLNODE_Element) {
dsinclairae95f762016-03-29 16:58:29 -07004554 CFDE_XMLElement* pXMLElement =
4555 static_cast<CFDE_XMLElement*>(pNode->m_pXMLNode);
Dan Sinclair1770c022016-03-14 14:14:16 -04004556 CFX_WideStringC wsAttributeName =
4557 pNode->GetCData(XFA_ATTRIBUTE_QualifiedName);
tsepez660956f2016-04-06 06:27:29 -07004558 pXMLElement->RemoveAttribute(wsAttributeName.c_str());
Dan Sinclair1770c022016-03-14 14:14:16 -04004559 }
4560 CFX_WideString wsName;
tsepezd19e9122016-11-02 15:43:18 -07004561 pNode->GetAttribute(XFA_ATTRIBUTE_Name, wsName, false);
dsinclairae95f762016-03-29 16:58:29 -07004562 CFDE_XMLElement* pNewXMLElement = new CFDE_XMLElement(wsName);
Dan Sinclair1770c022016-03-14 14:14:16 -04004563 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
4564 if (!wsValue.IsEmpty()) {
tsepezafe94302016-05-13 17:21:31 -07004565 pNewXMLElement->SetTextData(CFX_WideString(wsValue));
Dan Sinclair1770c022016-03-14 14:14:16 -04004566 }
4567 pNode->m_pXMLNode = pNewXMLElement;
4568 pNode->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
4569 } else {
4570 m_pXMLNode->RemoveChildNode(pNode->m_pXMLNode);
4571 }
dsinclairc5a8f212016-06-20 11:11:12 -07004572 pNode->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004573 }
tsepezd19e9122016-11-02 15:43:18 -07004574 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004575}
dsinclair5b36f0a2016-07-19 10:56:23 -07004576
Dan Sinclair1770c022016-03-14 14:14:16 -04004577CXFA_Node* CXFA_Node::GetFirstChildByName(const CFX_WideStringC& wsName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004578 return GetFirstChildByName(FX_HashCode_GetW(wsName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004579}
dsinclair5b36f0a2016-07-19 10:56:23 -07004580
tsepez736f28a2016-03-25 14:19:51 -07004581CXFA_Node* CXFA_Node::GetFirstChildByName(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004582 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4583 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4584 if (pNode->GetNameHash() == dwNameHash) {
4585 return pNode;
4586 }
4587 }
weili44f8faf2016-06-01 14:03:56 -07004588 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004589}
dsinclair5b36f0a2016-07-19 10:56:23 -07004590
dsinclair41cb62e2016-06-23 09:20:32 -07004591CXFA_Node* CXFA_Node::GetFirstChildByClass(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004592 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4593 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004594 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004595 return pNode;
4596 }
4597 }
weili44f8faf2016-06-01 14:03:56 -07004598 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004599}
dsinclair5b36f0a2016-07-19 10:56:23 -07004600
tsepez736f28a2016-03-25 14:19:51 -07004601CXFA_Node* CXFA_Node::GetNextSameNameSibling(uint32_t dwNameHash) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004602 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4603 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4604 if (pNode->GetNameHash() == dwNameHash) {
4605 return pNode;
4606 }
4607 }
weili44f8faf2016-06-01 14:03:56 -07004608 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004609}
dsinclair5b36f0a2016-07-19 10:56:23 -07004610
Dan Sinclair1770c022016-03-14 14:14:16 -04004611CXFA_Node* CXFA_Node::GetNextSameNameSibling(
4612 const CFX_WideStringC& wsNodeName) const {
tsepezb6853cf2016-04-25 11:23:43 -07004613 return GetNextSameNameSibling(FX_HashCode_GetW(wsNodeName, false));
Dan Sinclair1770c022016-03-14 14:14:16 -04004614}
dsinclair5b36f0a2016-07-19 10:56:23 -07004615
dsinclair41cb62e2016-06-23 09:20:32 -07004616CXFA_Node* CXFA_Node::GetNextSameClassSibling(XFA_Element eType) const {
Dan Sinclair1770c022016-03-14 14:14:16 -04004617 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4618 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
dsinclair41cb62e2016-06-23 09:20:32 -07004619 if (pNode->GetElementType() == eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004620 return pNode;
4621 }
4622 }
weili44f8faf2016-06-01 14:03:56 -07004623 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004624}
dsinclair5b36f0a2016-07-19 10:56:23 -07004625
Dan Sinclair1770c022016-03-14 14:14:16 -04004626int32_t CXFA_Node::GetNodeSameNameIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004627 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004628 if (!pScriptContext) {
4629 return -1;
4630 }
4631 return pScriptContext->GetIndexByName(const_cast<CXFA_Node*>(this));
4632}
dsinclair5b36f0a2016-07-19 10:56:23 -07004633
Dan Sinclair1770c022016-03-14 14:14:16 -04004634int32_t CXFA_Node::GetNodeSameClassIndex() const {
dsinclairdf4bc592016-03-31 20:34:43 -07004635 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004636 if (!pScriptContext) {
4637 return -1;
4638 }
4639 return pScriptContext->GetIndexByClassName(const_cast<CXFA_Node*>(this));
4640}
dsinclair5b36f0a2016-07-19 10:56:23 -07004641
Dan Sinclair1770c022016-03-14 14:14:16 -04004642void CXFA_Node::GetSOMExpression(CFX_WideString& wsSOMExpression) {
dsinclairdf4bc592016-03-31 20:34:43 -07004643 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
Dan Sinclair1770c022016-03-14 14:14:16 -04004644 if (!pScriptContext) {
4645 return;
4646 }
4647 pScriptContext->GetSomExpression(this, wsSOMExpression);
4648}
dsinclair5b36f0a2016-07-19 10:56:23 -07004649
Dan Sinclair1770c022016-03-14 14:14:16 -04004650CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() {
weili44f8faf2016-06-01 14:03:56 -07004651 CXFA_Node* pInstanceMgr = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04004652 if (m_ePacket == XFA_XDPPACKET_Form) {
4653 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair070fcdf2016-06-22 22:04:54 -07004654 if (!pParentNode || pParentNode->GetElementType() == XFA_Element::Area) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004655 return pInstanceMgr;
4656 }
4657 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
4658 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
dsinclair070fcdf2016-06-22 22:04:54 -07004659 XFA_Element eType = pNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -07004660 if ((eType == XFA_Element::Subform || eType == XFA_Element::SubformSet) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004661 pNode->m_dwNameHash != m_dwNameHash) {
4662 break;
4663 }
dsinclair56a8b192016-06-21 14:15:25 -07004664 if (eType == XFA_Element::InstanceManager) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004665 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
4666 CFX_WideStringC wsInstName = pNode->GetCData(XFA_ATTRIBUTE_Name);
4667 if (wsInstName.GetLength() > 0 && wsInstName.GetAt(0) == '_' &&
4668 wsInstName.Mid(1) == wsName) {
4669 pInstanceMgr = pNode;
4670 }
4671 break;
4672 }
4673 }
4674 }
4675 return pInstanceMgr;
4676}
dsinclair5b36f0a2016-07-19 10:56:23 -07004677
Dan Sinclair1770c022016-03-14 14:14:16 -04004678CXFA_Node* CXFA_Node::GetOccurNode() {
dsinclair56a8b192016-06-21 14:15:25 -07004679 return GetFirstChildByClass(XFA_Element::Occur);
Dan Sinclair1770c022016-03-14 14:14:16 -04004680}
dsinclair5b36f0a2016-07-19 10:56:23 -07004681
dsinclairc5a8f212016-06-20 11:11:12 -07004682bool CXFA_Node::HasFlag(XFA_NodeFlag dwFlag) const {
4683 if (m_uNodeFlags & dwFlag)
4684 return true;
4685 if (dwFlag == XFA_NodeFlag_HasRemovedChildren)
4686 return m_pParent && m_pParent->HasFlag(dwFlag);
4687 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004688}
thestigb1a59592016-04-14 18:29:56 -07004689
4690void CXFA_Node::SetFlag(uint32_t dwFlag, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004691 if (dwFlag == XFA_NodeFlag_Initialized && bNotify && !IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004692 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004693 if (pNotify) {
4694 pNotify->OnNodeReady(this);
Dan Sinclair1770c022016-03-14 14:14:16 -04004695 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004696 }
dsinclairc5a8f212016-06-20 11:11:12 -07004697 m_uNodeFlags |= dwFlag;
Dan Sinclair1770c022016-03-14 14:14:16 -04004698}
thestigb1a59592016-04-14 18:29:56 -07004699
4700void CXFA_Node::ClearFlag(uint32_t dwFlag) {
dsinclairc5a8f212016-06-20 11:11:12 -07004701 m_uNodeFlags &= ~dwFlag;
thestigb1a59592016-04-14 18:29:56 -07004702}
4703
tsepezd19e9122016-11-02 15:43:18 -07004704bool CXFA_Node::IsAttributeInXML() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004705 return GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData;
4706}
thestigb1a59592016-04-14 18:29:56 -07004707
4708void CXFA_Node::OnRemoved(bool bNotify) {
4709 if (!bNotify)
4710 return;
4711
dsinclaira1b07722016-07-11 08:20:58 -07004712 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
thestigb1a59592016-04-14 18:29:56 -07004713 if (pNotify)
4714 pNotify->OnChildRemoved();
Dan Sinclair1770c022016-03-14 14:14:16 -04004715}
thestigb1a59592016-04-14 18:29:56 -07004716
4717void CXFA_Node::OnChanging(XFA_ATTRIBUTE eAttr, bool bNotify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004718 if (bNotify && IsInitialized()) {
dsinclaira1b07722016-07-11 08:20:58 -07004719 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004720 if (pNotify) {
thestigb1a59592016-04-14 18:29:56 -07004721 pNotify->OnValueChanging(this, eAttr);
Dan Sinclair1770c022016-03-14 14:14:16 -04004722 }
4723 }
4724}
thestigb1a59592016-04-14 18:29:56 -07004725
Dan Sinclair1770c022016-03-14 14:14:16 -04004726void CXFA_Node::OnChanged(XFA_ATTRIBUTE eAttr,
thestigb1a59592016-04-14 18:29:56 -07004727 bool bNotify,
tsepezd19e9122016-11-02 15:43:18 -07004728 bool bScriptModify) {
dsinclairc5a8f212016-06-20 11:11:12 -07004729 if (bNotify && IsInitialized()) {
thestigb1a59592016-04-14 18:29:56 -07004730 Script_Attribute_SendAttributeChangeMessage(eAttr, bScriptModify);
Dan Sinclair1770c022016-03-14 14:14:16 -04004731 }
4732}
thestigb1a59592016-04-14 18:29:56 -07004733
Dan Sinclair1770c022016-03-14 14:14:16 -04004734int32_t CXFA_Node::execSingleEventByName(const CFX_WideStringC& wsEventName,
dsinclair41cb62e2016-06-23 09:20:32 -07004735 XFA_Element eType) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004736 int32_t iRet = XFA_EVENTERROR_NotExist;
4737 const XFA_ExecEventParaInfo* eventParaInfo =
4738 GetEventParaInfoByName(wsEventName);
4739 if (eventParaInfo) {
4740 uint32_t validFlags = eventParaInfo->m_validFlags;
dsinclaira1b07722016-07-11 08:20:58 -07004741 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
Dan Sinclair1770c022016-03-14 14:14:16 -04004742 if (!pNotify) {
4743 return iRet;
4744 }
4745 if (validFlags == 1) {
4746 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType);
4747 } else if (validFlags == 2) {
4748 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004749 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004750 } else if (validFlags == 3) {
dsinclair41cb62e2016-06-23 09:20:32 -07004751 if (eType == XFA_Element::Subform) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004752 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004753 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004754 }
4755 } else if (validFlags == 4) {
dsinclair41cb62e2016-06-23 09:20:32 -07004756 if (eType == XFA_Element::ExclGroup || eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004757 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
dsinclair56a8b192016-06-21 14:15:25 -07004758 if (pParentNode &&
dsinclair070fcdf2016-06-22 22:04:54 -07004759 pParentNode->GetElementType() == XFA_Element::ExclGroup) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004760 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 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004764 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004765 }
4766 } else if (validFlags == 5) {
dsinclair41cb62e2016-06-23 09:20:32 -07004767 if (eType == XFA_Element::Field) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004768 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004769 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004770 }
4771 } else if (validFlags == 6) {
4772 CXFA_WidgetData* pWidgetData = GetWidgetData();
4773 if (pWidgetData) {
4774 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004775 if (pUINode->m_elementType == XFA_Element::Signature) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004776 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004777 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004778 }
4779 }
4780 } else if (validFlags == 7) {
4781 CXFA_WidgetData* pWidgetData = GetWidgetData();
4782 if (pWidgetData) {
4783 CXFA_Node* pUINode = pWidgetData->GetUIChild();
dsinclair070fcdf2016-06-22 22:04:54 -07004784 if ((pUINode->m_elementType == XFA_Element::ChoiceList) &&
Dan Sinclair1770c022016-03-14 14:14:16 -04004785 (!pWidgetData->IsListBox())) {
4786 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
tsepezd19e9122016-11-02 15:43:18 -07004787 false, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004788 }
4789 }
4790 }
4791 }
4792 return iRet;
4793}
dsinclair5b36f0a2016-07-19 10:56:23 -07004794
Dan Sinclair1770c022016-03-14 14:14:16 -04004795void CXFA_Node::UpdateNameHash() {
4796 const XFA_NOTSUREATTRIBUTE* pNotsure =
dsinclair070fcdf2016-06-22 22:04:54 -07004797 XFA_GetNotsureAttribute(GetElementType(), XFA_ATTRIBUTE_Name);
tsepezb6853cf2016-04-25 11:23:43 -07004798 CFX_WideStringC wsName;
Dan Sinclair1770c022016-03-14 14:14:16 -04004799 if (!pNotsure || pNotsure->eType == XFA_ATTRIBUTETYPE_Cdata) {
tsepezb6853cf2016-04-25 11:23:43 -07004800 wsName = GetCData(XFA_ATTRIBUTE_Name);
4801 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004802 } else if (pNotsure->eType == XFA_ATTRIBUTETYPE_Enum) {
dsinclair9eb0db12016-07-21 12:01:39 -07004803 wsName = GetAttributeEnumByID(GetEnum(XFA_ATTRIBUTE_Name))->pName;
tsepezb6853cf2016-04-25 11:23:43 -07004804 m_dwNameHash = FX_HashCode_GetW(wsName, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004805 }
4806}
dsinclair5b36f0a2016-07-19 10:56:23 -07004807
dsinclairae95f762016-03-29 16:58:29 -07004808CFDE_XMLNode* CXFA_Node::CreateXMLMappingNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004809 if (!m_pXMLNode) {
tsepezafe94302016-05-13 17:21:31 -07004810 CFX_WideString wsTag(GetCData(XFA_ATTRIBUTE_Name));
dsinclairae95f762016-03-29 16:58:29 -07004811 m_pXMLNode = new CFDE_XMLElement(wsTag);
dsinclairc5a8f212016-06-20 11:11:12 -07004812 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
Dan Sinclair1770c022016-03-14 14:14:16 -04004813 }
4814 return m_pXMLNode;
4815}
dsinclair5b36f0a2016-07-19 10:56:23 -07004816
tsepezd19e9122016-11-02 15:43:18 -07004817bool CXFA_Node::IsNeedSavingXMLNode() {
Dan Sinclair1770c022016-03-14 14:14:16 -04004818 return m_pXMLNode && (GetPacketID() == XFA_XDPPACKET_Datasets ||
dsinclair070fcdf2016-06-22 22:04:54 -07004819 GetElementType() == XFA_Element::Xfa);
Dan Sinclair1770c022016-03-14 14:14:16 -04004820}
4821
4822XFA_MAPMODULEDATA* CXFA_Node::CreateMapModuleData() {
4823 if (!m_pMapModuleData)
4824 m_pMapModuleData = new XFA_MAPMODULEDATA;
4825 return m_pMapModuleData;
4826}
4827
4828XFA_MAPMODULEDATA* CXFA_Node::GetMapModuleData() const {
4829 return m_pMapModuleData;
4830}
4831
4832void CXFA_Node::SetMapModuleValue(void* pKey, void* pValue) {
4833 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004834 pModule->m_ValueMap[pKey] = pValue;
Dan Sinclair1770c022016-03-14 14:14:16 -04004835}
4836
tsepezd19e9122016-11-02 15:43:18 -07004837bool CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) {
tsepez6bb3b892017-01-05 12:18:41 -08004838 for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004839 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004840 if (pModule) {
4841 auto it = pModule->m_ValueMap.find(pKey);
4842 if (it != pModule->m_ValueMap.end()) {
4843 pValue = it->second;
4844 return true;
4845 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004846 }
tsepez6bb3b892017-01-05 12:18:41 -08004847 if (pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4848 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004849 }
tsepezd19e9122016-11-02 15:43:18 -07004850 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004851}
dsinclair5b36f0a2016-07-19 10:56:23 -07004852
Dan Sinclair1770c022016-03-14 14:14:16 -04004853void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) {
tsepez660956f2016-04-06 06:27:29 -07004854 SetMapModuleBuffer(pKey, (void*)wsValue.c_str(),
Dan Sinclair812e96c2017-03-13 16:43:37 -04004855 wsValue.GetLength() * sizeof(wchar_t));
Dan Sinclair1770c022016-03-14 14:14:16 -04004856}
dsinclair5b36f0a2016-07-19 10:56:23 -07004857
tsepezd19e9122016-11-02 15:43:18 -07004858bool CXFA_Node::GetMapModuleString(void* pKey, CFX_WideStringC& wsValue) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004859 void* pValue;
4860 int32_t iBytes;
4861 if (!GetMapModuleBuffer(pKey, pValue, iBytes)) {
tsepezd19e9122016-11-02 15:43:18 -07004862 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004863 }
Dan Sinclair812e96c2017-03-13 16:43:37 -04004864 wsValue = CFX_WideStringC((const wchar_t*)pValue, iBytes / sizeof(wchar_t));
tsepezd19e9122016-11-02 15:43:18 -07004865 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004866}
dsinclair5b36f0a2016-07-19 10:56:23 -07004867
Dan Sinclair1770c022016-03-14 14:14:16 -04004868void CXFA_Node::SetMapModuleBuffer(
4869 void* pKey,
4870 void* pValue,
4871 int32_t iBytes,
4872 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
4873 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
4874 XFA_MAPDATABLOCK*& pBuffer = pModule->m_BufferMap[pKey];
weili44f8faf2016-06-01 14:03:56 -07004875 if (!pBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004876 pBuffer =
4877 (XFA_MAPDATABLOCK*)FX_Alloc(uint8_t, sizeof(XFA_MAPDATABLOCK) + iBytes);
4878 } else if (pBuffer->iBytes != iBytes) {
4879 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4880 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4881 }
4882 pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(uint8_t, pBuffer,
4883 sizeof(XFA_MAPDATABLOCK) + iBytes);
4884 } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4885 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4886 }
weili44f8faf2016-06-01 14:03:56 -07004887 if (!pBuffer)
Dan Sinclair1770c022016-03-14 14:14:16 -04004888 return;
weili44f8faf2016-06-01 14:03:56 -07004889
Dan Sinclair1770c022016-03-14 14:14:16 -04004890 pBuffer->pCallbackInfo = pCallbackInfo;
4891 pBuffer->iBytes = iBytes;
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04004892 memcpy(pBuffer->GetData(), pValue, iBytes);
Dan Sinclair1770c022016-03-14 14:14:16 -04004893}
dsinclair5b36f0a2016-07-19 10:56:23 -07004894
tsepezd19e9122016-11-02 15:43:18 -07004895bool CXFA_Node::GetMapModuleBuffer(void* pKey,
4896 void*& pValue,
4897 int32_t& iBytes,
4898 bool bProtoAlso) const {
weili44f8faf2016-06-01 14:03:56 -07004899 XFA_MAPDATABLOCK* pBuffer = nullptr;
tsepez6bb3b892017-01-05 12:18:41 -08004900 for (const CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004901 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004902 if (pModule) {
4903 auto it = pModule->m_BufferMap.find(pKey);
4904 if (it != pModule->m_BufferMap.end()) {
4905 pBuffer = it->second;
4906 break;
4907 }
Dan Sinclair1770c022016-03-14 14:14:16 -04004908 }
tsepez6bb3b892017-01-05 12:18:41 -08004909 if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4910 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004911 }
tsepez6bb3b892017-01-05 12:18:41 -08004912 if (!pBuffer)
tsepezd19e9122016-11-02 15:43:18 -07004913 return false;
tsepez6bb3b892017-01-05 12:18:41 -08004914
Dan Sinclair1770c022016-03-14 14:14:16 -04004915 pValue = pBuffer->GetData();
4916 iBytes = pBuffer->iBytes;
tsepezd19e9122016-11-02 15:43:18 -07004917 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004918}
dsinclair5b36f0a2016-07-19 10:56:23 -07004919
tsepezd19e9122016-11-02 15:43:18 -07004920bool CXFA_Node::HasMapModuleKey(void* pKey, bool bProtoAlso) {
tsepez6bb3b892017-01-05 12:18:41 -08004921 for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004922 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004923 if (pModule) {
4924 auto it1 = pModule->m_ValueMap.find(pKey);
4925 if (it1 != pModule->m_ValueMap.end())
4926 return true;
4927
4928 auto it2 = pModule->m_BufferMap.find(pKey);
4929 if (it2 != pModule->m_BufferMap.end())
4930 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -04004931 }
tsepez6bb3b892017-01-05 12:18:41 -08004932 if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets)
4933 break;
Dan Sinclair1770c022016-03-14 14:14:16 -04004934 }
tsepezd19e9122016-11-02 15:43:18 -07004935 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -04004936}
dsinclair5b36f0a2016-07-19 10:56:23 -07004937
Dan Sinclair1770c022016-03-14 14:14:16 -04004938void CXFA_Node::RemoveMapModuleKey(void* pKey) {
4939 XFA_MAPMODULEDATA* pModule = GetMapModuleData();
4940 if (!pModule)
4941 return;
4942
4943 if (pKey) {
tsepez6bb3b892017-01-05 12:18:41 -08004944 auto it = pModule->m_BufferMap.find(pKey);
4945 if (it != pModule->m_BufferMap.end()) {
4946 XFA_MAPDATABLOCK* pBuffer = it->second;
Dan Sinclair1770c022016-03-14 14:14:16 -04004947 if (pBuffer) {
tsepez6bb3b892017-01-05 12:18:41 -08004948 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree)
Dan Sinclair1770c022016-03-14 14:14:16 -04004949 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04004950 FX_Free(pBuffer);
4951 }
tsepez6bb3b892017-01-05 12:18:41 -08004952 pModule->m_BufferMap.erase(it);
Dan Sinclair1770c022016-03-14 14:14:16 -04004953 }
tsepez6bb3b892017-01-05 12:18:41 -08004954 pModule->m_ValueMap.erase(pKey);
4955 return;
Dan Sinclair1770c022016-03-14 14:14:16 -04004956 }
tsepez6bb3b892017-01-05 12:18:41 -08004957
4958 for (auto& pair : pModule->m_BufferMap) {
4959 XFA_MAPDATABLOCK* pBuffer = pair.second;
4960 if (pBuffer) {
4961 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree)
4962 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4963 FX_Free(pBuffer);
4964 }
4965 }
4966 pModule->m_BufferMap.clear();
4967 pModule->m_ValueMap.clear();
4968 delete pModule;
Dan Sinclair1770c022016-03-14 14:14:16 -04004969}
dsinclair5b36f0a2016-07-19 10:56:23 -07004970
tsepez6bb3b892017-01-05 12:18:41 -08004971void CXFA_Node::MergeAllData(void* pDstModule) {
Dan Sinclair1770c022016-03-14 14:14:16 -04004972 XFA_MAPMODULEDATA* pDstModuleData =
4973 static_cast<CXFA_Node*>(pDstModule)->CreateMapModuleData();
4974 XFA_MAPMODULEDATA* pSrcModuleData = GetMapModuleData();
tsepez6bb3b892017-01-05 12:18:41 -08004975 if (!pSrcModuleData)
Dan Sinclair1770c022016-03-14 14:14:16 -04004976 return;
tsepez6bb3b892017-01-05 12:18:41 -08004977
4978 for (const auto& pair : pSrcModuleData->m_ValueMap)
4979 pDstModuleData->m_ValueMap[pair.first] = pair.second;
4980
4981 for (const auto& pair : pSrcModuleData->m_BufferMap) {
4982 XFA_MAPDATABLOCK* pSrcBuffer = pair.second;
4983 XFA_MAPDATABLOCK*& pDstBuffer = pDstModuleData->m_BufferMap[pair.first];
Dan Sinclair1770c022016-03-14 14:14:16 -04004984 if (pSrcBuffer->pCallbackInfo && pSrcBuffer->pCallbackInfo->pFree &&
4985 !pSrcBuffer->pCallbackInfo->pCopy) {
tsepez6bb3b892017-01-05 12:18:41 -08004986 if (pDstBuffer) {
4987 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
4988 pDstModuleData->m_BufferMap.erase(pair.first);
Dan Sinclair1770c022016-03-14 14:14:16 -04004989 }
4990 continue;
4991 }
tsepez6bb3b892017-01-05 12:18:41 -08004992 if (!pDstBuffer) {
4993 pDstBuffer = (XFA_MAPDATABLOCK*)FX_Alloc(
Dan Sinclair1770c022016-03-14 14:14:16 -04004994 uint8_t, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
tsepez6bb3b892017-01-05 12:18:41 -08004995 } else if (pDstBuffer->iBytes != pSrcBuffer->iBytes) {
4996 if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) {
4997 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04004998 }
tsepez6bb3b892017-01-05 12:18:41 -08004999 pDstBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(
5000 uint8_t, pDstBuffer, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
5001 } else if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) {
5002 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005003 }
tsepez6bb3b892017-01-05 12:18:41 -08005004 if (!pDstBuffer) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005005 continue;
5006 }
tsepez6bb3b892017-01-05 12:18:41 -08005007 pDstBuffer->pCallbackInfo = pSrcBuffer->pCallbackInfo;
5008 pDstBuffer->iBytes = pSrcBuffer->iBytes;
Dan Sinclair1c5d0b42017-04-03 15:05:11 -04005009 memcpy(pDstBuffer->GetData(), pSrcBuffer->GetData(), pSrcBuffer->iBytes);
tsepez6bb3b892017-01-05 12:18:41 -08005010 if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pCopy) {
5011 pDstBuffer->pCallbackInfo->pCopy(*(void**)pDstBuffer->GetData());
Dan Sinclair1770c022016-03-14 14:14:16 -04005012 }
5013 }
5014}
dsinclair5b36f0a2016-07-19 10:56:23 -07005015
Dan Sinclair1770c022016-03-14 14:14:16 -04005016void CXFA_Node::MoveBufferMapData(CXFA_Node* pDstModule, void* pKey) {
5017 if (!pDstModule) {
5018 return;
5019 }
tsepezd19e9122016-11-02 15:43:18 -07005020 bool bNeedMove = true;
Dan Sinclair1770c022016-03-14 14:14:16 -04005021 if (!pKey) {
tsepezd19e9122016-11-02 15:43:18 -07005022 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005023 }
dsinclair070fcdf2016-06-22 22:04:54 -07005024 if (pDstModule->GetElementType() != GetElementType()) {
tsepezd19e9122016-11-02 15:43:18 -07005025 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005026 }
weili44f8faf2016-06-01 14:03:56 -07005027 XFA_MAPMODULEDATA* pSrcModuleData = nullptr;
5028 XFA_MAPMODULEDATA* pDstModuleData = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -04005029 if (bNeedMove) {
5030 pSrcModuleData = GetMapModuleData();
5031 if (!pSrcModuleData) {
tsepezd19e9122016-11-02 15:43:18 -07005032 bNeedMove = false;
Dan Sinclair1770c022016-03-14 14:14:16 -04005033 }
5034 pDstModuleData = pDstModule->CreateMapModuleData();
5035 }
5036 if (bNeedMove) {
tsepez6bb3b892017-01-05 12:18:41 -08005037 auto it = pSrcModuleData->m_BufferMap.find(pKey);
5038 if (it != pSrcModuleData->m_BufferMap.end()) {
5039 XFA_MAPDATABLOCK* pBufferBlockData = it->second;
5040 if (pBufferBlockData) {
5041 pSrcModuleData->m_BufferMap.erase(pKey);
5042 pDstModuleData->m_BufferMap[pKey] = pBufferBlockData;
5043 }
Dan Sinclair1770c022016-03-14 14:14:16 -04005044 }
5045 }
dsinclairc5a8f212016-06-20 11:11:12 -07005046 if (pDstModule->IsNodeV()) {
tsepezd19e9122016-11-02 15:43:18 -07005047 CFX_WideString wsValue = pDstModule->GetScriptContent(false);
Dan Sinclair1770c022016-03-14 14:14:16 -04005048 CFX_WideString wsFormatValue(wsValue);
5049 CXFA_WidgetData* pWidgetData = pDstModule->GetContainerWidgetData();
5050 if (pWidgetData) {
tsepez6f167c32016-04-14 15:46:27 -07005051 pWidgetData->GetFormatDataValue(wsValue, wsFormatValue);
Dan Sinclair1770c022016-03-14 14:14:16 -04005052 }
tsepezd19e9122016-11-02 15:43:18 -07005053 pDstModule->SetScriptContent(wsValue, wsFormatValue, true, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005054 }
5055}
dsinclair5b36f0a2016-07-19 10:56:23 -07005056
Dan Sinclair1770c022016-03-14 14:14:16 -04005057void CXFA_Node::MoveBufferMapData(CXFA_Node* pSrcModule,
5058 CXFA_Node* pDstModule,
5059 void* pKey,
tsepezd19e9122016-11-02 15:43:18 -07005060 bool bRecursive) {
Dan Sinclair1770c022016-03-14 14:14:16 -04005061 if (!pSrcModule || !pDstModule || !pKey) {
5062 return;
5063 }
5064 if (bRecursive) {
5065 CXFA_Node* pSrcChild = pSrcModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5066 CXFA_Node* pDstChild = pDstModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5067 for (; pSrcChild && pDstChild;
5068 pSrcChild = pSrcChild->GetNodeItem(XFA_NODEITEM_NextSibling),
5069 pDstChild = pDstChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
tsepezd19e9122016-11-02 15:43:18 -07005070 MoveBufferMapData(pSrcChild, pDstChild, pKey, true);
Dan Sinclair1770c022016-03-14 14:14:16 -04005071 }
5072 }
5073 pSrcModule->MoveBufferMapData(pDstModule, pKey);
5074}
Dan Sinclair3cdcfeb2017-01-03 15:45:10 -05005075
5076void CXFA_Node::ThrowMissingPropertyException(
5077 const CFX_WideString& obj,
5078 const CFX_WideString& prop) const {
5079 ThrowException(L"'%s' doesn't have property '%s'.", obj.c_str(),
5080 prop.c_str());
5081}
5082
5083void CXFA_Node::ThrowTooManyOccurancesException(
5084 const CFX_WideString& obj) const {
5085 ThrowException(
5086 L"The element [%s] has violated its allowable number of occurrences.",
5087 obj.c_str());
5088}