Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: xfa/fxfa/parser/xfa_object_imp.cpp

Issue 2159973003: Split xfa_object_imp into individual class files. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase to master Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fxfa/parser/cxfa_thisproxy.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // 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
7 #include "xfa/fxfa/parser/xfa_object.h"
8
9 #include <memory>
10
11 #include "core/fxcrt/include/fx_ext.h"
12 #include "fxjs/include/cfxjse_arguments.h"
13 #include "third_party/base/stl_util.h"
14 #include "xfa/fde/xml/fde_xml_imp.h"
15 #include "xfa/fgas/crt/fgas_codepage.h"
16 #include "xfa/fgas/crt/fgas_system.h"
17 #include "xfa/fxfa/app/xfa_ffnotify.h"
18 #include "xfa/fxfa/parser/cxfa_occur.h"
19 #include "xfa/fxfa/parser/cxfa_simple_parser.h"
20 #include "xfa/fxfa/parser/xfa_basic_imp.h"
21 #include "xfa/fxfa/parser/xfa_doclayout.h"
22 #include "xfa/fxfa/parser/xfa_document.h"
23 #include "xfa/fxfa/parser/xfa_document_layout_imp.h"
24 #include "xfa/fxfa/parser/xfa_localemgr.h"
25 #include "xfa/fxfa/parser/xfa_script.h"
26 #include "xfa/fxfa/parser/xfa_script_imp.h"
27 #include "xfa/fxfa/parser/xfa_utils.h"
28
29 namespace {
30
31 void XFA_DeleteWideString(void* pData) {
32 delete static_cast<CFX_WideString*>(pData);
33 }
34
35 void XFA_CopyWideString(void*& pData) {
36 if (pData) {
37 CFX_WideString* pNewData = new CFX_WideString(*(CFX_WideString*)pData);
38 pData = pNewData;
39 }
40 }
41
42 XFA_MAPDATABLOCKCALLBACKINFO deleteWideStringCallBack = {XFA_DeleteWideString,
43 XFA_CopyWideString};
44
45 void XFA_DataNodeDeleteBindItem(void* pData) {
46 delete static_cast<CXFA_NodeArray*>(pData);
47 }
48
49 XFA_MAPDATABLOCKCALLBACKINFO deleteBindItemCallBack = {
50 XFA_DataNodeDeleteBindItem, nullptr};
51
52 } // namespace
53
54 CXFA_Object::CXFA_Object(CXFA_Document* pDocument,
55 XFA_ObjectType objectType,
56 XFA_Element elementType,
57 const CFX_WideStringC& elementName)
58 : m_pDocument(pDocument),
59 m_objectType(objectType),
60 m_elementType(elementType),
61 m_elementNameHash(FX_HashCode_GetW(elementName, false)),
62 m_elementName(elementName) {}
63
64 CXFA_Object::~CXFA_Object() {}
65
66 CFX_WideStringC CXFA_Object::GetClassName() const {
67 return m_elementName;
68 }
69
70 uint32_t CXFA_Object::GetClassHashCode() const {
71 return m_elementNameHash;
72 }
73
74 XFA_Element CXFA_Object::GetElementType() const {
75 return m_elementType;
76 }
77
78 void CXFA_Object::Script_ObjectClass_ClassName(CFXJSE_Value* pValue,
79 FX_BOOL bSetting,
80 XFA_ATTRIBUTE eAttribute) {
81 if (!bSetting) {
82 CFX_WideStringC className = GetClassName();
83 pValue->SetString(
84 FX_UTF8Encode(className.c_str(), className.GetLength()).AsStringC());
85 } else {
86 ThrowException(XFA_IDS_INVAlID_PROP_SET);
87 }
88 }
89
90 void CXFA_Object::ThrowException(int32_t iStringID, ...) {
91 IXFA_AppProvider* pAppProvider = m_pDocument->GetNotify()->GetAppProvider();
92 ASSERT(pAppProvider);
93 CFX_WideString wsFormat;
94 pAppProvider->LoadString(iStringID, wsFormat);
95 CFX_WideString wsMessage;
96 va_list arg_ptr;
97 va_start(arg_ptr, iStringID);
98 wsMessage.FormatV(wsFormat.c_str(), arg_ptr);
99 va_end(arg_ptr);
100 FXJSE_ThrowMessage(
101 FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC());
102 }
103
104 XFA_MAPMODULEDATA::XFA_MAPMODULEDATA() {}
105
106 XFA_MAPMODULEDATA::~XFA_MAPMODULEDATA() {}
107
108 CXFA_Node::CXFA_Node(CXFA_Document* pDoc,
109 uint16_t ePacket,
110 XFA_ObjectType oType,
111 XFA_Element eType,
112 const CFX_WideStringC& elementName)
113 : CXFA_Object(pDoc, oType, eType, elementName),
114 m_pNext(nullptr),
115 m_pChild(nullptr),
116 m_pLastChild(nullptr),
117 m_pParent(nullptr),
118 m_pXMLNode(nullptr),
119 m_ePacket(ePacket),
120 m_uNodeFlags(XFA_NodeFlag_None),
121 m_dwNameHash(0),
122 m_pAuxNode(nullptr),
123 m_pMapModuleData(nullptr) {
124 ASSERT(m_pDocument);
125 }
126
127 CXFA_Node::~CXFA_Node() {
128 ASSERT(!m_pParent);
129 RemoveMapModuleKey();
130 CXFA_Node* pNode = m_pChild;
131 while (pNode) {
132 CXFA_Node* pNext = pNode->m_pNext;
133 pNode->m_pParent = nullptr;
134 delete pNode;
135 pNode = pNext;
136 }
137 if (m_pXMLNode && IsOwnXMLNode())
138 m_pXMLNode->Release();
139 }
140
141 CXFA_Node* CXFA_Node::Clone(FX_BOOL bRecursive) {
142 CXFA_Node* pClone = m_pDocument->CreateNode(m_ePacket, m_elementType);
143 if (!pClone)
144 return nullptr;
145
146 MergeAllData(pClone);
147 pClone->UpdateNameHash();
148 if (IsNeedSavingXMLNode()) {
149 CFDE_XMLNode* pCloneXML = nullptr;
150 if (IsAttributeInXML()) {
151 CFX_WideString wsName;
152 GetAttribute(XFA_ATTRIBUTE_Name, wsName, FALSE);
153 CFDE_XMLElement* pCloneXMLElement = new CFDE_XMLElement(wsName);
154 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
155 if (!wsValue.IsEmpty()) {
156 pCloneXMLElement->SetTextData(CFX_WideString(wsValue));
157 }
158 pCloneXML = pCloneXMLElement;
159 pCloneXMLElement = nullptr;
160 pClone->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
161 } else {
162 pCloneXML = m_pXMLNode->Clone(FALSE);
163 }
164 pClone->SetXMLMappingNode(pCloneXML);
165 pClone->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
166 }
167 if (bRecursive) {
168 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
169 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
170 pClone->InsertChild(pChild->Clone(bRecursive));
171 }
172 }
173 pClone->SetFlag(XFA_NodeFlag_Initialized, true);
174 pClone->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
175 return pClone;
176 }
177
178 CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem) const {
179 switch (eItem) {
180 case XFA_NODEITEM_NextSibling:
181 return m_pNext;
182 case XFA_NODEITEM_FirstChild:
183 return m_pChild;
184 case XFA_NODEITEM_Parent:
185 return m_pParent;
186 case XFA_NODEITEM_PrevSibling:
187 if (m_pParent) {
188 CXFA_Node* pSibling = m_pParent->m_pChild;
189 CXFA_Node* pPrev = nullptr;
190 while (pSibling && pSibling != this) {
191 pPrev = pSibling;
192 pSibling = pSibling->m_pNext;
193 }
194 return pPrev;
195 }
196 return nullptr;
197 default:
198 break;
199 }
200 return nullptr;
201 }
202
203 CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem,
204 XFA_ObjectType eType) const {
205 CXFA_Node* pNode = nullptr;
206 switch (eItem) {
207 case XFA_NODEITEM_NextSibling:
208 pNode = m_pNext;
209 while (pNode && pNode->GetObjectType() != eType)
210 pNode = pNode->m_pNext;
211 break;
212 case XFA_NODEITEM_FirstChild:
213 pNode = m_pChild;
214 while (pNode && pNode->GetObjectType() != eType)
215 pNode = pNode->m_pNext;
216 break;
217 case XFA_NODEITEM_Parent:
218 pNode = m_pParent;
219 while (pNode && pNode->GetObjectType() != eType)
220 pNode = pNode->m_pParent;
221 break;
222 case XFA_NODEITEM_PrevSibling:
223 if (m_pParent) {
224 CXFA_Node* pSibling = m_pParent->m_pChild;
225 while (pSibling && pSibling != this) {
226 if (eType == pSibling->GetObjectType())
227 pNode = pSibling;
228
229 pSibling = pSibling->m_pNext;
230 }
231 }
232 break;
233 default:
234 break;
235 }
236 return pNode;
237 }
238
239 int32_t CXFA_Node::GetNodeList(CXFA_NodeArray& nodes,
240 uint32_t dwTypeFilter,
241 XFA_Element eTypeFilter,
242 int32_t iLevel) {
243 if (--iLevel < 0) {
244 return nodes.GetSize();
245 }
246 if (eTypeFilter != XFA_Element::Unknown) {
247 CXFA_Node* pChild = m_pChild;
248 while (pChild) {
249 if (pChild->GetElementType() == eTypeFilter) {
250 nodes.Add(pChild);
251 if (iLevel > 0) {
252 GetNodeList(nodes, dwTypeFilter, eTypeFilter, iLevel);
253 }
254 }
255 pChild = pChild->m_pNext;
256 }
257 } else if (dwTypeFilter ==
258 (XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties)) {
259 CXFA_Node* pChild = m_pChild;
260 while (pChild) {
261 nodes.Add(pChild);
262 if (iLevel > 0) {
263 GetNodeList(nodes, dwTypeFilter, eTypeFilter, iLevel);
264 }
265 pChild = pChild->m_pNext;
266 }
267 } else if (dwTypeFilter != 0) {
268 bool bFilterChildren = !!(dwTypeFilter & XFA_NODEFILTER_Children);
269 bool bFilterProperties = !!(dwTypeFilter & XFA_NODEFILTER_Properties);
270 bool bFilterOneOfProperties =
271 !!(dwTypeFilter & XFA_NODEFILTER_OneOfProperty);
272 CXFA_Node* pChild = m_pChild;
273 while (pChild) {
274 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
275 GetElementType(), pChild->GetElementType(), XFA_XDPPACKET_UNKNOWN);
276 if (pProperty) {
277 if (bFilterProperties) {
278 nodes.Add(pChild);
279 } else if (bFilterOneOfProperties &&
280 (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) {
281 nodes.Add(pChild);
282 } else if (bFilterChildren &&
283 (pChild->GetElementType() == XFA_Element::Variables ||
284 pChild->GetElementType() == XFA_Element::PageSet)) {
285 nodes.Add(pChild);
286 }
287 } else if (bFilterChildren) {
288 nodes.Add(pChild);
289 }
290 pChild = pChild->m_pNext;
291 }
292 if (bFilterOneOfProperties && nodes.GetSize() < 1) {
293 int32_t iProperties = 0;
294 const XFA_PROPERTY* pProperty =
295 XFA_GetElementProperties(GetElementType(), iProperties);
296 if (!pProperty || iProperties < 1)
297 return 0;
298 for (int32_t i = 0; i < iProperties; i++) {
299 if (pProperty[i].uFlags & XFA_PROPERTYFLAG_DefaultOneOf) {
300 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(GetPacketID());
301 CXFA_Node* pNewNode =
302 m_pDocument->CreateNode(pPacket, pProperty[i].eName);
303 if (!pNewNode)
304 break;
305 InsertChild(pNewNode, nullptr);
306 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
307 nodes.Add(pNewNode);
308 break;
309 }
310 }
311 }
312 }
313 return nodes.GetSize();
314 }
315
316 CXFA_Node* CXFA_Node::CreateSamePacketNode(XFA_Element eType,
317 uint32_t dwFlags) {
318 CXFA_Node* pNode = m_pDocument->CreateNode(m_ePacket, eType);
319 pNode->SetFlag(dwFlags, true);
320 return pNode;
321 }
322
323 CXFA_Node* CXFA_Node::CloneTemplateToForm(FX_BOOL bRecursive) {
324 ASSERT(m_ePacket == XFA_XDPPACKET_Template);
325 CXFA_Node* pClone =
326 m_pDocument->CreateNode(XFA_XDPPACKET_Form, m_elementType);
327 if (!pClone)
328 return nullptr;
329
330 pClone->SetTemplateNode(this);
331 pClone->UpdateNameHash();
332 pClone->SetXMLMappingNode(GetXMLMappingNode());
333 if (bRecursive) {
334 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
335 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
336 pClone->InsertChild(pChild->CloneTemplateToForm(bRecursive));
337 }
338 }
339 pClone->SetFlag(XFA_NodeFlag_Initialized, true);
340 return pClone;
341 }
342
343 CXFA_Node* CXFA_Node::GetTemplateNode() const {
344 return m_pAuxNode;
345 }
346
347 void CXFA_Node::SetTemplateNode(CXFA_Node* pTemplateNode) {
348 m_pAuxNode = pTemplateNode;
349 }
350
351 CXFA_Node* CXFA_Node::GetBindData() {
352 ASSERT(GetPacketID() == XFA_XDPPACKET_Form);
353 return static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
354 }
355
356 int32_t CXFA_Node::GetBindItems(CXFA_NodeArray& formItems) {
357 if (BindsFormItems()) {
358 CXFA_NodeArray* pItems = nullptr;
359 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
360 formItems.Copy(*pItems);
361 return formItems.GetSize();
362 }
363 CXFA_Node* pFormNode =
364 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
365 if (pFormNode)
366 formItems.Add(pFormNode);
367 return formItems.GetSize();
368 }
369
370 int32_t CXFA_Node::AddBindItem(CXFA_Node* pFormNode) {
371 ASSERT(pFormNode);
372 if (BindsFormItems()) {
373 CXFA_NodeArray* pItems = nullptr;
374 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
375 ASSERT(pItems);
376 if (pItems->Find(pFormNode) < 0) {
377 pItems->Add(pFormNode);
378 }
379 return pItems->GetSize();
380 }
381 CXFA_Node* pOldFormItem =
382 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
383 if (!pOldFormItem) {
384 SetObject(XFA_ATTRIBUTE_BindingNode, pFormNode);
385 return 1;
386 } else if (pOldFormItem == pFormNode) {
387 return 1;
388 }
389 CXFA_NodeArray* pItems = new CXFA_NodeArray;
390 SetObject(XFA_ATTRIBUTE_BindingNode, pItems, &deleteBindItemCallBack);
391 pItems->Add(pOldFormItem);
392 pItems->Add(pFormNode);
393 m_uNodeFlags |= XFA_NodeFlag_BindFormItems;
394 return 2;
395 }
396
397 int32_t CXFA_Node::RemoveBindItem(CXFA_Node* pFormNode) {
398 if (BindsFormItems()) {
399 CXFA_NodeArray* pItems = nullptr;
400 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
401 ASSERT(pItems);
402 int32_t iIndex = pItems->Find(pFormNode);
403 int32_t iCount = pItems->GetSize();
404 if (iIndex >= 0) {
405 if (iIndex != iCount - 1)
406 pItems->SetAt(iIndex, pItems->GetAt(iCount - 1));
407 pItems->RemoveAt(iCount - 1);
408 if (iCount == 2) {
409 CXFA_Node* pLastFormNode = pItems->GetAt(0);
410 SetObject(XFA_ATTRIBUTE_BindingNode, pLastFormNode);
411 m_uNodeFlags &= ~XFA_NodeFlag_BindFormItems;
412 }
413 iCount--;
414 }
415 return iCount;
416 }
417 CXFA_Node* pOldFormItem =
418 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
419 if (pOldFormItem == pFormNode) {
420 SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
421 pOldFormItem = nullptr;
422 }
423 return pOldFormItem ? 1 : 0;
424 }
425
426 FX_BOOL CXFA_Node::HasBindItem() {
427 return GetPacketID() == XFA_XDPPACKET_Datasets &&
428 GetObject(XFA_ATTRIBUTE_BindingNode);
429 }
430
431 CXFA_WidgetData* CXFA_Node::GetWidgetData() {
432 return (CXFA_WidgetData*)GetObject(XFA_ATTRIBUTE_WidgetData);
433 }
434
435 CXFA_WidgetData* CXFA_Node::GetContainerWidgetData() {
436 if (GetPacketID() != XFA_XDPPACKET_Form)
437 return nullptr;
438 XFA_Element eType = GetElementType();
439 if (eType == XFA_Element::ExclGroup)
440 return nullptr;
441 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
442 if (pParentNode && pParentNode->GetElementType() == XFA_Element::ExclGroup)
443 return nullptr;
444
445 if (eType == XFA_Element::Field) {
446 CXFA_WidgetData* pFieldWidgetData = GetWidgetData();
447 if (pFieldWidgetData &&
448 pFieldWidgetData->GetChoiceListOpen() ==
449 XFA_ATTRIBUTEENUM_MultiSelect) {
450 return nullptr;
451 } else {
452 CFX_WideString wsPicture;
453 if (pFieldWidgetData) {
454 pFieldWidgetData->GetPictureContent(wsPicture,
455 XFA_VALUEPICTURE_DataBind);
456 }
457 if (!wsPicture.IsEmpty())
458 return pFieldWidgetData;
459 CXFA_Node* pDataNode = GetBindData();
460 if (!pDataNode)
461 return nullptr;
462 pFieldWidgetData = nullptr;
463 CXFA_NodeArray formNodes;
464 pDataNode->GetBindItems(formNodes);
465 for (int32_t i = 0; i < formNodes.GetSize(); i++) {
466 CXFA_Node* pFormNode = formNodes.GetAt(i);
467 if (!pFormNode || pFormNode->HasRemovedChildren())
468 continue;
469 pFieldWidgetData = pFormNode->GetWidgetData();
470 if (pFieldWidgetData) {
471 pFieldWidgetData->GetPictureContent(wsPicture,
472 XFA_VALUEPICTURE_DataBind);
473 }
474 if (!wsPicture.IsEmpty())
475 break;
476 pFieldWidgetData = nullptr;
477 }
478 return pFieldWidgetData;
479 }
480 }
481 CXFA_Node* pGrandNode =
482 pParentNode ? pParentNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
483 CXFA_Node* pValueNode =
484 (pParentNode && pParentNode->GetElementType() == XFA_Element::Value)
485 ? pParentNode
486 : nullptr;
487 if (!pValueNode) {
488 pValueNode =
489 (pGrandNode && pGrandNode->GetElementType() == XFA_Element::Value)
490 ? pGrandNode
491 : nullptr;
492 }
493 CXFA_Node* pParentOfValueNode =
494 pValueNode ? pValueNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
495 return pParentOfValueNode ? pParentOfValueNode->GetContainerWidgetData()
496 : nullptr;
497 }
498
499 FX_BOOL CXFA_Node::GetLocaleName(CFX_WideString& wsLocaleName) {
500 CXFA_Node* pForm = GetDocument()->GetXFAObject(XFA_HASHCODE_Form)->AsNode();
501 CXFA_Node* pTopSubform = pForm->GetFirstChildByClass(XFA_Element::Subform);
502 ASSERT(pTopSubform);
503 CXFA_Node* pLocaleNode = this;
504 FX_BOOL bLocale = FALSE;
505 do {
506 bLocale = pLocaleNode->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, FALSE);
507 if (!bLocale) {
508 pLocaleNode = pLocaleNode->GetNodeItem(XFA_NODEITEM_Parent);
509 }
510 } while (pLocaleNode && pLocaleNode != pTopSubform && !bLocale);
511 if (bLocale)
512 return TRUE;
513 CXFA_Node* pConfig = ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Config));
514 wsLocaleName = GetDocument()->GetLocalMgr()->GetConfigLocaleName(pConfig);
515 if (!wsLocaleName.IsEmpty())
516 return TRUE;
517 if (pTopSubform &&
518 pTopSubform->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, FALSE)) {
519 return TRUE;
520 }
521 IFX_Locale* pLocale = GetDocument()->GetLocalMgr()->GetDefLocale();
522 if (pLocale) {
523 wsLocaleName = pLocale->GetName();
524 return TRUE;
525 }
526 return FALSE;
527 }
528
529 XFA_ATTRIBUTEENUM CXFA_Node::GetIntact() {
530 CXFA_Node* pKeep = GetFirstChildByClass(XFA_Element::Keep);
531 XFA_ATTRIBUTEENUM eLayoutType = GetEnum(XFA_ATTRIBUTE_Layout);
532 if (pKeep) {
533 XFA_ATTRIBUTEENUM eIntact;
534 if (pKeep->TryEnum(XFA_ATTRIBUTE_Intact, eIntact, FALSE)) {
535 if (eIntact == XFA_ATTRIBUTEENUM_None &&
536 eLayoutType == XFA_ATTRIBUTEENUM_Row &&
537 m_pDocument->GetCurVersionMode() < XFA_VERSION_208) {
538 CXFA_Node* pPreviewRow = GetNodeItem(XFA_NODEITEM_PrevSibling,
539 XFA_ObjectType::ContainerNode);
540 if (pPreviewRow &&
541 pPreviewRow->GetEnum(XFA_ATTRIBUTE_Layout) ==
542 XFA_ATTRIBUTEENUM_Row) {
543 XFA_ATTRIBUTEENUM eValue;
544 if (pKeep->TryEnum(XFA_ATTRIBUTE_Previous, eValue, FALSE) &&
545 (eValue == XFA_ATTRIBUTEENUM_ContentArea ||
546 eValue == XFA_ATTRIBUTEENUM_PageArea)) {
547 return XFA_ATTRIBUTEENUM_ContentArea;
548 }
549 CXFA_Node* pNode =
550 pPreviewRow->GetFirstChildByClass(XFA_Element::Keep);
551 if (pNode && pNode->TryEnum(XFA_ATTRIBUTE_Next, eValue, FALSE) &&
552 (eValue == XFA_ATTRIBUTEENUM_ContentArea ||
553 eValue == XFA_ATTRIBUTEENUM_PageArea)) {
554 return XFA_ATTRIBUTEENUM_ContentArea;
555 }
556 }
557 }
558 return eIntact;
559 }
560 }
561 switch (GetElementType()) {
562 case XFA_Element::Subform:
563 switch (eLayoutType) {
564 case XFA_ATTRIBUTEENUM_Position:
565 case XFA_ATTRIBUTEENUM_Row:
566 return XFA_ATTRIBUTEENUM_ContentArea;
567 case XFA_ATTRIBUTEENUM_Tb:
568 case XFA_ATTRIBUTEENUM_Table:
569 case XFA_ATTRIBUTEENUM_Lr_tb:
570 case XFA_ATTRIBUTEENUM_Rl_tb:
571 return XFA_ATTRIBUTEENUM_None;
572 default:
573 break;
574 }
575 break;
576 case XFA_Element::Field: {
577 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
578 if (!pParentNode ||
579 pParentNode->GetElementType() == XFA_Element::PageArea)
580 return XFA_ATTRIBUTEENUM_ContentArea;
581 if (pParentNode->GetIntact() == XFA_ATTRIBUTEENUM_None) {
582 XFA_ATTRIBUTEENUM eParLayout =
583 pParentNode->GetEnum(XFA_ATTRIBUTE_Layout);
584 if (eParLayout == XFA_ATTRIBUTEENUM_Position ||
585 eParLayout == XFA_ATTRIBUTEENUM_Row ||
586 eParLayout == XFA_ATTRIBUTEENUM_Table) {
587 return XFA_ATTRIBUTEENUM_None;
588 }
589 XFA_VERSION version = m_pDocument->GetCurVersionMode();
590 if (eParLayout == XFA_ATTRIBUTEENUM_Tb && version < XFA_VERSION_208) {
591 CXFA_Measurement measureH;
592 if (TryMeasure(XFA_ATTRIBUTE_H, measureH, FALSE))
593 return XFA_ATTRIBUTEENUM_ContentArea;
594 }
595 return XFA_ATTRIBUTEENUM_None;
596 }
597 return XFA_ATTRIBUTEENUM_ContentArea;
598 }
599 case XFA_Element::Draw:
600 return XFA_ATTRIBUTEENUM_ContentArea;
601 default:
602 break;
603 }
604 return XFA_ATTRIBUTEENUM_None;
605 }
606
607 CXFA_Node* CXFA_Node::GetDataDescriptionNode() {
608 if (m_ePacket == XFA_XDPPACKET_Datasets)
609 return m_pAuxNode;
610 return nullptr;
611 }
612
613 void CXFA_Node::SetDataDescriptionNode(CXFA_Node* pDataDescriptionNode) {
614 ASSERT(m_ePacket == XFA_XDPPACKET_Datasets);
615 m_pAuxNode = pDataDescriptionNode;
616 }
617
618 void CXFA_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments) {
619 int32_t iLength = pArguments->GetLength();
620 if (iLength != 1) {
621 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resolveNode");
622 return;
623 }
624 CFX_WideString wsExpression =
625 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
626 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
627 if (!pScriptContext)
628 return;
629 CXFA_Node* refNode = this;
630 if (refNode->GetElementType() == XFA_Element::Xfa)
631 refNode = ToNode(pScriptContext->GetThisObject());
632 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
633 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
634 XFA_RESOLVENODE_Siblings;
635 XFA_RESOLVENODE_RS resoveNodeRS;
636 int32_t iRet = pScriptContext->ResolveObjects(
637 refNode, wsExpression.AsStringC(), resoveNodeRS, dwFlag);
638 if (iRet < 1) {
639 pArguments->GetReturnValue()->SetNull();
640 return;
641 }
642 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
643 CXFA_Object* pNode = resoveNodeRS.nodes[0];
644 pArguments->GetReturnValue()->Assign(
645 pScriptContext->GetJSValueFromMap(pNode));
646 } else {
647 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo =
648 resoveNodeRS.pScriptAttribute;
649 if (lpAttributeInfo && lpAttributeInfo->eValueType == XFA_SCRIPT_Object) {
650 std::unique_ptr<CFXJSE_Value> pValue(
651 new CFXJSE_Value(pScriptContext->GetRuntime()));
652 (resoveNodeRS.nodes[0]->*(lpAttributeInfo->lpfnCallback))(
653 pValue.get(), FALSE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute);
654 pArguments->GetReturnValue()->Assign(pValue.get());
655 } else {
656 pArguments->GetReturnValue()->SetNull();
657 }
658 }
659 }
660
661 void CXFA_Node::Script_TreeClass_ResolveNodes(CFXJSE_Arguments* pArguments) {
662 int32_t iLength = pArguments->GetLength();
663 if (iLength != 1) {
664 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resolveNodes");
665 return;
666 }
667 CFX_WideString wsExpression =
668 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
669 CFXJSE_Value* pValue = pArguments->GetReturnValue();
670 if (!pValue)
671 return;
672 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
673 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
674 XFA_RESOLVENODE_Siblings;
675 CXFA_Node* refNode = this;
676 if (refNode->GetElementType() == XFA_Element::Xfa)
677 refNode = ToNode(m_pDocument->GetScriptContext()->GetThisObject());
678 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag, refNode);
679 }
680
681 void CXFA_Node::Script_Som_ResolveNodeList(CFXJSE_Value* pValue,
682 CFX_WideString wsExpression,
683 uint32_t dwFlag,
684 CXFA_Node* refNode) {
685 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
686 if (!pScriptContext)
687 return;
688 XFA_RESOLVENODE_RS resoveNodeRS;
689 if (!refNode)
690 refNode = this;
691 pScriptContext->ResolveObjects(refNode, wsExpression.AsStringC(),
692 resoveNodeRS, dwFlag);
693 CXFA_ArrayNodeList* pNodeList = new CXFA_ArrayNodeList(m_pDocument);
694 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
695 for (int32_t i = 0; i < resoveNodeRS.nodes.GetSize(); i++) {
696 if (resoveNodeRS.nodes[i]->IsNode())
697 pNodeList->Append(resoveNodeRS.nodes[i]->AsNode());
698 }
699 } else {
700 CXFA_ValueArray valueArray(pScriptContext->GetRuntime());
701 if (resoveNodeRS.GetAttributeResult(valueArray) > 0) {
702 CXFA_ObjArray objectArray;
703 valueArray.GetAttributeObject(objectArray);
704 for (int32_t i = 0; i < objectArray.GetSize(); i++) {
705 if (objectArray[i]->IsNode())
706 pNodeList->Append(objectArray[i]->AsNode());
707 }
708 }
709 }
710 pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
711 }
712
713 void CXFA_Node::Script_TreeClass_All(CFXJSE_Value* pValue,
714 FX_BOOL bSetting,
715 XFA_ATTRIBUTE eAttribute) {
716 if (bSetting) {
717 ThrowException(XFA_IDS_INVAlID_PROP_SET);
718 } else {
719 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
720 CFX_WideString wsName;
721 GetAttribute(XFA_ATTRIBUTE_Name, wsName);
722 CFX_WideString wsExpression = wsName + FX_WSTRC(L"[*]");
723 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
724 }
725 }
726
727 void CXFA_Node::Script_TreeClass_Nodes(CFXJSE_Value* pValue,
728 FX_BOOL bSetting,
729 XFA_ATTRIBUTE eAttribute) {
730 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
731 if (!pScriptContext)
732 return;
733 if (bSetting) {
734 IXFA_AppProvider* pAppProvider = m_pDocument->GetNotify()->GetAppProvider();
735 ASSERT(pAppProvider);
736 CFX_WideString wsMessage;
737 pAppProvider->LoadString(XFA_IDS_Unable_TO_SET, wsMessage);
738 FXJSE_ThrowMessage(
739 FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC());
740 } else {
741 CXFA_AttachNodeList* pNodeList = new CXFA_AttachNodeList(m_pDocument, this);
742 pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
743 }
744 }
745
746 void CXFA_Node::Script_TreeClass_ClassAll(CFXJSE_Value* pValue,
747 FX_BOOL bSetting,
748 XFA_ATTRIBUTE eAttribute) {
749 if (bSetting) {
750 ThrowException(XFA_IDS_INVAlID_PROP_SET);
751 } else {
752 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
753 CFX_WideString wsExpression =
754 FX_WSTRC(L"#") + GetClassName() + FX_WSTRC(L"[*]");
755 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
756 }
757 }
758
759 void CXFA_Node::Script_TreeClass_Parent(CFXJSE_Value* pValue,
760 FX_BOOL bSetting,
761 XFA_ATTRIBUTE eAttribute) {
762 if (bSetting) {
763 ThrowException(XFA_IDS_INVAlID_PROP_SET);
764 } else {
765 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
766 if (pParent) {
767 pValue->Assign(
768 m_pDocument->GetScriptContext()->GetJSValueFromMap(pParent));
769 } else {
770 pValue->SetNull();
771 }
772 }
773 }
774
775 void CXFA_Node::Script_TreeClass_Index(CFXJSE_Value* pValue,
776 FX_BOOL bSetting,
777 XFA_ATTRIBUTE eAttribute) {
778 if (bSetting)
779 ThrowException(XFA_IDS_INVAlID_PROP_SET);
780 else
781 pValue->SetInteger(GetNodeSameNameIndex());
782 }
783
784 void CXFA_Node::Script_TreeClass_ClassIndex(CFXJSE_Value* pValue,
785 FX_BOOL bSetting,
786 XFA_ATTRIBUTE eAttribute) {
787 if (bSetting)
788 ThrowException(XFA_IDS_INVAlID_PROP_SET);
789 else
790 pValue->SetInteger(GetNodeSameClassIndex());
791 }
792
793 void CXFA_Node::Script_TreeClass_SomExpression(CFXJSE_Value* pValue,
794 FX_BOOL bSetting,
795 XFA_ATTRIBUTE eAttribute) {
796 if (bSetting) {
797 ThrowException(XFA_IDS_INVAlID_PROP_SET);
798 } else {
799 CFX_WideString wsSOMExpression;
800 GetSOMExpression(wsSOMExpression);
801 pValue->SetString(FX_UTF8Encode(wsSOMExpression).AsStringC());
802 }
803 }
804
805 void CXFA_Node::Script_NodeClass_ApplyXSL(CFXJSE_Arguments* pArguments) {
806 int32_t iLength = pArguments->GetLength();
807 if (iLength != 1) {
808 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"applyXSL");
809 return;
810 }
811 CFX_WideString wsExpression =
812 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
813 // TODO(weili): check whether we need to implement this, pdfium:501.
814 // For now, just put the variables here to avoid unused variable warning.
815 (void)wsExpression;
816 }
817
818 void CXFA_Node::Script_NodeClass_AssignNode(CFXJSE_Arguments* pArguments) {
819 int32_t iLength = pArguments->GetLength();
820 if (iLength < 1 || iLength > 3) {
821 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"assignNode");
822 return;
823 }
824 CFX_WideString wsExpression;
825 CFX_WideString wsValue;
826 int32_t iAction = 0;
827 wsExpression =
828 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
829 if (iLength >= 2) {
830 wsValue =
831 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
832 }
833 if (iLength >= 3)
834 iAction = pArguments->GetInt32(2);
835 // TODO(weili): check whether we need to implement this, pdfium:501.
836 // For now, just put the variables here to avoid unused variable warning.
837 (void)wsExpression;
838 (void)wsValue;
839 (void)iAction;
840 }
841
842 void CXFA_Node::Script_NodeClass_Clone(CFXJSE_Arguments* pArguments) {
843 int32_t iLength = pArguments->GetLength();
844 if (iLength != 1) {
845 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"clone");
846 return;
847 }
848 bool bClone = !!pArguments->GetInt32(0);
849 CXFA_Node* pCloneNode = Clone(bClone);
850 pArguments->GetReturnValue()->Assign(
851 m_pDocument->GetScriptContext()->GetJSValueFromMap(pCloneNode));
852 }
853
854 void CXFA_Node::Script_NodeClass_GetAttribute(CFXJSE_Arguments* pArguments) {
855 int32_t iLength = pArguments->GetLength();
856 if (iLength != 1) {
857 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getAttribute");
858 return;
859 }
860 CFX_WideString wsExpression =
861 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
862 CFX_WideString wsValue;
863 GetAttribute(wsExpression.AsStringC(), wsValue);
864 CFXJSE_Value* pValue = pArguments->GetReturnValue();
865 if (pValue)
866 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
867 }
868
869 void CXFA_Node::Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments) {
870 int32_t iLength = pArguments->GetLength();
871 if (iLength < 1 || iLength > 2) {
872 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getElement");
873 return;
874 }
875 CFX_WideString wsExpression;
876 int32_t iValue = 0;
877 wsExpression =
878 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
879 if (iLength >= 2)
880 iValue = pArguments->GetInt32(1);
881 CXFA_Node* pNode =
882 GetProperty(iValue, XFA_GetElementTypeForName(wsExpression.AsStringC()));
883 pArguments->GetReturnValue()->Assign(
884 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode));
885 }
886
887 void CXFA_Node::Script_NodeClass_IsPropertySpecified(
888 CFXJSE_Arguments* pArguments) {
889 int32_t iLength = pArguments->GetLength();
890 if (iLength < 1 || iLength > 3) {
891 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isPropertySpecified");
892 return;
893 }
894 CFX_WideString wsExpression;
895 bool bParent = true;
896 int32_t iIndex = 0;
897 wsExpression =
898 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
899 if (iLength >= 2)
900 bParent = !!pArguments->GetInt32(1);
901 if (iLength >= 3)
902 iIndex = pArguments->GetInt32(2);
903 FX_BOOL bHas = FALSE;
904 const XFA_ATTRIBUTEINFO* pAttributeInfo =
905 XFA_GetAttributeByName(wsExpression.AsStringC());
906 CFX_WideString wsValue;
907 if (pAttributeInfo)
908 bHas = HasAttribute(pAttributeInfo->eName);
909 if (!bHas) {
910 XFA_Element eType = XFA_GetElementTypeForName(wsExpression.AsStringC());
911 bHas = !!GetProperty(iIndex, eType);
912 if (!bHas && bParent && m_pParent) {
913 // Also check on the parent.
914 bHas = m_pParent->HasAttribute(pAttributeInfo->eName);
915 if (!bHas)
916 bHas = !!m_pParent->GetProperty(iIndex, eType);
917 }
918 }
919 CFXJSE_Value* pValue = pArguments->GetReturnValue();
920 if (pValue)
921 pValue->SetBoolean(bHas);
922 }
923
924 void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) {
925 int32_t iLength = pArguments->GetLength();
926 if (iLength < 1 || iLength > 3) {
927 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"loadXML");
928 return;
929 }
930 CFX_WideString wsExpression;
931 bool bIgnoreRoot = true;
932 bool bOverwrite = 0;
933 wsExpression =
934 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
935 if (wsExpression.IsEmpty())
936 return;
937 if (iLength >= 2)
938 bIgnoreRoot = !!pArguments->GetInt32(1);
939 if (iLength >= 3)
940 bOverwrite = !!pArguments->GetInt32(2);
941 std::unique_ptr<CXFA_SimpleParser> pParser(
942 new CXFA_SimpleParser(m_pDocument, false));
943 if (!pParser)
944 return;
945 CFDE_XMLNode* pXMLNode = nullptr;
946 int32_t iParserStatus =
947 pParser->ParseXMLData(wsExpression, pXMLNode, nullptr);
948 if (iParserStatus != XFA_PARSESTATUS_Done || !pXMLNode)
949 return;
950 if (bIgnoreRoot &&
951 (pXMLNode->GetType() != FDE_XMLNODE_Element ||
952 XFA_RecognizeRichText(static_cast<CFDE_XMLElement*>(pXMLNode)))) {
953 bIgnoreRoot = false;
954 }
955 CXFA_Node* pFakeRoot = Clone(FALSE);
956 CFX_WideStringC wsContentType = GetCData(XFA_ATTRIBUTE_ContentType);
957 if (!wsContentType.IsEmpty()) {
958 pFakeRoot->SetCData(XFA_ATTRIBUTE_ContentType,
959 CFX_WideString(wsContentType));
960 }
961 CFDE_XMLNode* pFakeXMLRoot = pFakeRoot->GetXMLMappingNode();
962 if (!pFakeXMLRoot) {
963 CFDE_XMLNode* pThisXMLRoot = GetXMLMappingNode();
964 pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone(FALSE) : nullptr;
965 }
966 if (!pFakeXMLRoot)
967 pFakeXMLRoot = new CFDE_XMLElement(CFX_WideString(GetClassName()));
968
969 if (bIgnoreRoot) {
970 CFDE_XMLNode* pXMLChild = pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild);
971 while (pXMLChild) {
972 CFDE_XMLNode* pXMLSibling =
973 pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling);
974 pXMLNode->RemoveChildNode(pXMLChild);
975 pFakeXMLRoot->InsertChildNode(pXMLChild);
976 pXMLChild = pXMLSibling;
977 }
978 } else {
979 CFDE_XMLNode* pXMLParent = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent);
980 if (pXMLParent) {
981 pXMLParent->RemoveChildNode(pXMLNode);
982 }
983 pFakeXMLRoot->InsertChildNode(pXMLNode);
984 }
985 pParser->ConstructXFANode(pFakeRoot, pFakeXMLRoot);
986 pFakeRoot = pParser->GetRootNode();
987 if (pFakeRoot) {
988 if (bOverwrite) {
989 CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild);
990 CXFA_Node* pNewChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
991 int32_t index = 0;
992 while (pNewChild) {
993 CXFA_Node* pItem = pNewChild->GetNodeItem(XFA_NODEITEM_NextSibling);
994 pFakeRoot->RemoveChild(pNewChild);
995 InsertChild(index++, pNewChild);
996 pNewChild->SetFlag(XFA_NodeFlag_Initialized, true);
997 pNewChild = pItem;
998 }
999 while (pChild) {
1000 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1001 RemoveChild(pChild);
1002 pFakeRoot->InsertChild(pChild);
1003 pChild = pItem;
1004 }
1005 if (GetPacketID() == XFA_XDPPACKET_Form &&
1006 GetElementType() == XFA_Element::ExData) {
1007 CFDE_XMLNode* pTempXMLNode = GetXMLMappingNode();
1008 SetXMLMappingNode(pFakeXMLRoot);
1009 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
1010 if (pTempXMLNode && !pTempXMLNode->GetNodeItem(CFDE_XMLNode::Parent)) {
1011 pFakeXMLRoot = pTempXMLNode;
1012 } else {
1013 pFakeXMLRoot = nullptr;
1014 }
1015 }
1016 MoveBufferMapData(pFakeRoot, this, XFA_CalcData, TRUE);
1017 } else {
1018 CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
1019 while (pChild) {
1020 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1021 pFakeRoot->RemoveChild(pChild);
1022 InsertChild(pChild);
1023 pChild->SetFlag(XFA_NodeFlag_Initialized, true);
1024 pChild = pItem;
1025 }
1026 }
1027 if (pFakeXMLRoot) {
1028 pFakeRoot->SetXMLMappingNode(pFakeXMLRoot);
1029 pFakeRoot->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
1030 }
1031 pFakeRoot->SetFlag(XFA_NodeFlag_HasRemovedChildren, false);
1032 } else {
1033 if (pFakeXMLRoot) {
1034 pFakeXMLRoot->Release();
1035 pFakeXMLRoot = nullptr;
1036 }
1037 }
1038 }
1039
1040 void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) {
1041 // TODO(weili): Check whether we need to implement this, pdfium:501.
1042 }
1043
1044 void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) {
1045 int32_t iLength = pArguments->GetLength();
1046 if (iLength < 0 || iLength > 1) {
1047 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"saveXML");
1048 return;
1049 }
1050 bool bPrettyMode = false;
1051 if (iLength == 1) {
1052 if (pArguments->GetUTF8String(0) != "pretty") {
1053 ThrowException(XFA_IDS_ARGUMENT_MISMATCH);
1054 return;
1055 }
1056 bPrettyMode = true;
1057 }
1058 CFX_ByteStringC bsXMLHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
1059 if (GetPacketID() == XFA_XDPPACKET_Form ||
1060 GetPacketID() == XFA_XDPPACKET_Datasets) {
1061 CFDE_XMLNode* pElement = nullptr;
1062 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
1063 pElement = GetXMLMappingNode();
1064 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) {
1065 pArguments->GetReturnValue()->SetString(bsXMLHeader);
1066 return;
1067 }
1068 XFA_DataExporter_DealWithDataGroupNode(this);
1069 }
1070 std::unique_ptr<IFX_MemoryStream, ReleaseDeleter<IFX_MemoryStream>>
1071 pMemoryStream(FX_CreateMemoryStream(TRUE));
1072 std::unique_ptr<IFX_Stream, ReleaseDeleter<IFX_Stream>> pStream(
1073 IFX_Stream::CreateStream(
1074 static_cast<IFX_FileWrite*>(pMemoryStream.get()),
1075 FX_STREAMACCESS_Text | FX_STREAMACCESS_Write |
1076 FX_STREAMACCESS_Append));
1077 if (!pStream) {
1078 pArguments->GetReturnValue()->SetString(bsXMLHeader);
1079 return;
1080 }
1081 pStream->SetCodePage(FX_CODEPAGE_UTF8);
1082 pStream->WriteData(bsXMLHeader.raw_str(), bsXMLHeader.GetLength());
1083 if (GetPacketID() == XFA_XDPPACKET_Form)
1084 XFA_DataExporter_RegenerateFormFile(this, pStream.get(), nullptr, TRUE);
1085 else
1086 pElement->SaveXMLNode(pStream.get());
1087 // TODO(weili): Check whether we need to save pretty print XML, pdfium:501.
1088 // For now, just put it here to avoid unused variable warning.
1089 (void)bPrettyMode;
1090 pArguments->GetReturnValue()->SetString(
1091 CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize()));
1092 return;
1093 }
1094 pArguments->GetReturnValue()->SetString("");
1095 }
1096
1097 void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) {
1098 int32_t iLength = pArguments->GetLength();
1099 if (iLength != 2) {
1100 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setAttribute");
1101 return;
1102 }
1103 CFX_WideString wsAttributeValue =
1104 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
1105 CFX_WideString wsAttribute =
1106 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
1107 SetAttribute(wsAttribute.AsStringC(), wsAttributeValue.AsStringC(), true);
1108 }
1109
1110 void CXFA_Node::Script_NodeClass_SetElement(CFXJSE_Arguments* pArguments) {
1111 int32_t iLength = pArguments->GetLength();
1112 if (iLength != 1 && iLength != 2) {
1113 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setElement");
1114 return;
1115 }
1116 CXFA_Node* pNode = nullptr;
1117 CFX_WideString wsName;
1118 pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
1119 if (iLength == 2)
1120 wsName = CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
1121 // TODO(weili): check whether we need to implement this, pdfium:501.
1122 // For now, just put the variables here to avoid unused variable warning.
1123 (void)pNode;
1124 (void)wsName;
1125 }
1126
1127 void CXFA_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue,
1128 FX_BOOL bSetting,
1129 XFA_ATTRIBUTE eAttribute) {
1130 if (bSetting) {
1131 ThrowException(XFA_IDS_INVAlID_PROP_SET);
1132 } else {
1133 CFX_WideString wsNameSpace;
1134 TryNamespace(wsNameSpace);
1135 pValue->SetString(FX_UTF8Encode(wsNameSpace).AsStringC());
1136 }
1137 }
1138
1139 void CXFA_Node::Script_NodeClass_Model(CFXJSE_Value* pValue,
1140 FX_BOOL bSetting,
1141 XFA_ATTRIBUTE eAttribute) {
1142 if (bSetting) {
1143 ThrowException(XFA_IDS_INVAlID_PROP_SET);
1144 } else {
1145 pValue->Assign(
1146 m_pDocument->GetScriptContext()->GetJSValueFromMap(GetModelNode()));
1147 }
1148 }
1149
1150 void CXFA_Node::Script_NodeClass_IsContainer(CFXJSE_Value* pValue,
1151 FX_BOOL bSetting,
1152 XFA_ATTRIBUTE eAttribute) {
1153 if (bSetting)
1154 ThrowException(XFA_IDS_INVAlID_PROP_SET);
1155 else
1156 pValue->SetBoolean(IsContainerNode());
1157 }
1158
1159 void CXFA_Node::Script_NodeClass_IsNull(CFXJSE_Value* pValue,
1160 FX_BOOL bSetting,
1161 XFA_ATTRIBUTE eAttribute) {
1162 if (bSetting) {
1163 ThrowException(XFA_IDS_INVAlID_PROP_SET);
1164 } else {
1165 if (GetElementType() == XFA_Element::Subform) {
1166 pValue->SetBoolean(FALSE);
1167 return;
1168 }
1169 CFX_WideString strValue;
1170 pValue->SetBoolean(!TryContent(strValue) || strValue.IsEmpty());
1171 }
1172 }
1173
1174 void CXFA_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue,
1175 FX_BOOL bSetting,
1176 XFA_ATTRIBUTE eAttribute) {
1177 if (bSetting) {
1178 ThrowException(XFA_IDS_INVAlID_PROP_SET);
1179 } else {
1180 CXFA_NodeArray properts;
1181 int32_t iSize = GetNodeList(properts, XFA_NODEFILTER_OneOfProperty);
1182 if (iSize > 0) {
1183 pValue->Assign(
1184 m_pDocument->GetScriptContext()->GetJSValueFromMap(properts[0]));
1185 }
1186 }
1187 }
1188
1189 void CXFA_Node::Script_ContainerClass_GetDelta(CFXJSE_Arguments* pArguments) {}
1190
1191 void CXFA_Node::Script_ContainerClass_GetDeltas(CFXJSE_Arguments* pArguments) {
1192 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
1193 pArguments->GetReturnValue()->SetObject(
1194 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
1195 }
1196 void CXFA_Node::Script_ModelClass_ClearErrorList(CFXJSE_Arguments* pArguments) {
1197 }
1198 void CXFA_Node::Script_ModelClass_CreateNode(CFXJSE_Arguments* pArguments) {
1199 Script_Template_CreateNode(pArguments);
1200 }
1201 void CXFA_Node::Script_ModelClass_IsCompatibleNS(CFXJSE_Arguments* pArguments) {
1202 int32_t iLength = pArguments->GetLength();
1203 if (iLength < 1) {
1204 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isCompatibleNS");
1205 return;
1206 }
1207 CFX_WideString wsNameSpace;
1208 if (iLength >= 1) {
1209 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(0);
1210 wsNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
1211 }
1212 CFX_WideString wsNodeNameSpace;
1213 TryNamespace(wsNodeNameSpace);
1214 CFXJSE_Value* pValue = pArguments->GetReturnValue();
1215 if (pValue)
1216 pValue->SetBoolean(wsNodeNameSpace == wsNameSpace);
1217 }
1218 void CXFA_Node::Script_ModelClass_Context(CFXJSE_Value* pValue,
1219 FX_BOOL bSetting,
1220 XFA_ATTRIBUTE eAttribute) {}
1221 void CXFA_Node::Script_ModelClass_AliasNode(CFXJSE_Value* pValue,
1222 FX_BOOL bSetting,
1223 XFA_ATTRIBUTE eAttribute) {}
1224 void CXFA_Node::Script_Attribute_Integer(CFXJSE_Value* pValue,
1225 FX_BOOL bSetting,
1226 XFA_ATTRIBUTE eAttribute) {
1227 if (bSetting) {
1228 SetInteger(eAttribute, pValue->ToInteger(), true);
1229 } else {
1230 pValue->SetInteger(GetInteger(eAttribute));
1231 }
1232 }
1233 void CXFA_Node::Script_Attribute_IntegerRead(CFXJSE_Value* pValue,
1234 FX_BOOL bSetting,
1235 XFA_ATTRIBUTE eAttribute) {
1236 if (!bSetting) {
1237 pValue->SetInteger(GetInteger(eAttribute));
1238 } else {
1239 ThrowException(XFA_IDS_INVAlID_PROP_SET);
1240 }
1241 }
1242 void CXFA_Node::Script_Attribute_BOOL(CFXJSE_Value* pValue,
1243 FX_BOOL bSetting,
1244 XFA_ATTRIBUTE eAttribute) {
1245 if (bSetting) {
1246 SetBoolean(eAttribute, pValue->ToBoolean(), true);
1247 } else {
1248 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
1249 }
1250 }
1251 void CXFA_Node::Script_Attribute_BOOLRead(CFXJSE_Value* pValue,
1252 FX_BOOL bSetting,
1253 XFA_ATTRIBUTE eAttribute) {
1254 if (!bSetting) {
1255 pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
1256 } else {
1257 ThrowException(XFA_IDS_INVAlID_PROP_SET);
1258 }
1259 }
1260
1261 void CXFA_Node::Script_Attribute_SendAttributeChangeMessage(
1262 XFA_ATTRIBUTE eAttribute,
1263 FX_BOOL bScriptModify) {
1264 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
1265 if (!pLayoutPro)
1266 return;
1267
1268 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
1269 if (!pNotify)
1270 return;
1271
1272 uint32_t dwPacket = GetPacketID();
1273 if (!(dwPacket & XFA_XDPPACKET_Form)) {
1274 pNotify->OnValueChanged(this, eAttribute, this, this);
1275 return;
1276 }
1277
1278 bool bNeedFindContainer = false;
1279 switch (GetElementType()) {
1280 case XFA_Element::Caption:
1281 bNeedFindContainer = true;
1282 pNotify->OnValueChanged(this, eAttribute, this,
1283 GetNodeItem(XFA_NODEITEM_Parent));
1284 break;
1285 case XFA_Element::Font:
1286 case XFA_Element::Para: {
1287 bNeedFindContainer = true;
1288 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
1289 if (pParentNode->GetElementType() == XFA_Element::Caption) {
1290 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1291 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1292 } else {
1293 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
1294 }
1295 } break;
1296 case XFA_Element::Margin: {
1297 bNeedFindContainer = true;
1298 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
1299 XFA_Element eParentType = pParentNode->GetElementType();
1300 if (pParentNode->IsContainerNode()) {
1301 pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
1302 } else if (eParentType == XFA_Element::Caption) {
1303 pNotify->OnValueChanged(this, eAttribute, pParentNode,
1304 pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
1305 } else {
1306 CXFA_Node* pNode = pParentNode->GetNodeItem(XFA_NODEITEM_Parent);
1307 if (pNode && pNode->GetElementType() == XFA_Element::Ui) {
1308 pNotify->OnValueChanged(this, eAttribute, pNode,
1309 pNode->GetNodeItem(XFA_NODEITEM_Parent));
1310 }
1311 }
1312 } break;
1313 case XFA_Element::Comb: {
1314 CXFA_Node* pEditNode = GetNodeItem(XFA_NODEITEM_Parent);
1315 XFA_Element eUIType = pEditNode->GetElementType();
1316 if (pEditNode && (eUIType == XFA_Element::DateTimeEdit ||
1317 eUIType == XFA_Element::NumericEdit ||
1318 eUIType == XFA_Element::TextEdit)) {
1319 CXFA_Node* pUINode = pEditNode->GetNodeItem(XFA_NODEITEM_Parent);
1320 if (pUINode) {
1321 pNotify->OnValueChanged(this, eAttribute, pUINode,
1322 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1323 }
1324 }
1325 } break;
1326 case XFA_Element::Button:
1327 case XFA_Element::Barcode:
1328 case XFA_Element::ChoiceList:
1329 case XFA_Element::DateTimeEdit:
1330 case XFA_Element::NumericEdit:
1331 case XFA_Element::PasswordEdit:
1332 case XFA_Element::TextEdit: {
1333 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1334 if (pUINode) {
1335 pNotify->OnValueChanged(this, eAttribute, pUINode,
1336 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1337 }
1338 } break;
1339 case XFA_Element::CheckButton: {
1340 bNeedFindContainer = true;
1341 CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
1342 if (pUINode) {
1343 pNotify->OnValueChanged(this, eAttribute, pUINode,
1344 pUINode->GetNodeItem(XFA_NODEITEM_Parent));
1345 }
1346 } break;
1347 case XFA_Element::Keep:
1348 case XFA_Element::Bookend:
1349 case XFA_Element::Break:
1350 case XFA_Element::BreakAfter:
1351 case XFA_Element::BreakBefore:
1352 case XFA_Element::Overflow:
1353 bNeedFindContainer = true;
1354 break;
1355 case XFA_Element::Area:
1356 case XFA_Element::Draw:
1357 case XFA_Element::ExclGroup:
1358 case XFA_Element::Field:
1359 case XFA_Element::Subform:
1360 case XFA_Element::SubformSet:
1361 pLayoutPro->AddChangedContainer(this);
1362 pNotify->OnValueChanged(this, eAttribute, this, this);
1363 break;
1364 case XFA_Element::Sharptext:
1365 case XFA_Element::Sharpxml:
1366 case XFA_Element::SharpxHTML: {
1367 CXFA_Node* pTextNode = GetNodeItem(XFA_NODEITEM_Parent);
1368 if (!pTextNode) {
1369 return;
1370 }
1371 CXFA_Node* pValueNode = pTextNode->GetNodeItem(XFA_NODEITEM_Parent);
1372 if (!pValueNode) {
1373 return;
1374 }
1375 XFA_Element eType = pValueNode->GetElementType();
1376 if (eType == XFA_Element::Value) {
1377 bNeedFindContainer = true;
1378 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1379 if (pNode && pNode->IsContainerNode()) {
1380 if (bScriptModify) {
1381 pValueNode = pNode;
1382 }
1383 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
1384 } else {
1385 pNotify->OnValueChanged(this, eAttribute, pNode,
1386 pNode->GetNodeItem(XFA_NODEITEM_Parent));
1387 }
1388 } else {
1389 if (eType == XFA_Element::Items) {
1390 CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
1391 if (pNode && pNode->IsContainerNode()) {
1392 pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
1393 }
1394 }
1395 }
1396 } break;
1397 default:
1398 break;
1399 }
1400 if (bNeedFindContainer) {
1401 CXFA_Node* pParent = this;
1402 while (pParent) {
1403 if (pParent->IsContainerNode())
1404 break;
1405
1406 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
1407 }
1408 if (pParent) {
1409 pLayoutPro->AddChangedContainer(pParent);
1410 }
1411 }
1412 }
1413
1414 void CXFA_Node::Script_Attribute_String(CFXJSE_Value* pValue,
1415 FX_BOOL bSetting,
1416 XFA_ATTRIBUTE eAttribute) {
1417 if (bSetting) {
1418 CFX_WideString wsValue = pValue->ToWideString();
1419 SetAttribute(eAttribute, wsValue.AsStringC(), true);
1420 if (eAttribute == XFA_ATTRIBUTE_Use &&
1421 GetElementType() == XFA_Element::Desc) {
1422 CXFA_Node* pTemplateNode =
1423 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
1424 CXFA_Node* pProtoRoot =
1425 pTemplateNode->GetFirstChildByClass(XFA_Element::Subform)
1426 ->GetFirstChildByClass(XFA_Element::Proto);
1427
1428 CFX_WideString wsID;
1429 CFX_WideString wsSOM;
1430 if (!wsValue.IsEmpty()) {
1431 if (wsValue[0] == '#') {
1432 wsID = CFX_WideString(wsValue.c_str() + 1, wsValue.GetLength() - 1);
1433 } else {
1434 wsSOM = wsValue;
1435 }
1436 }
1437 CXFA_Node* pProtoNode = nullptr;
1438 if (!wsSOM.IsEmpty()) {
1439 uint32_t dwFlag = XFA_RESOLVENODE_Children |
1440 XFA_RESOLVENODE_Attributes |
1441 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1442 XFA_RESOLVENODE_Siblings;
1443 XFA_RESOLVENODE_RS resoveNodeRS;
1444 int32_t iRet = m_pDocument->GetScriptContext()->ResolveObjects(
1445 pProtoRoot, wsSOM.AsStringC(), resoveNodeRS, dwFlag);
1446 if (iRet > 0 && resoveNodeRS.nodes[0]->IsNode()) {
1447 pProtoNode = resoveNodeRS.nodes[0]->AsNode();
1448 }
1449 } else if (!wsID.IsEmpty()) {
1450 pProtoNode = m_pDocument->GetNodeByID(pProtoRoot, wsID.AsStringC());
1451 }
1452 if (pProtoNode) {
1453 CXFA_Node* pHeadChild = GetNodeItem(XFA_NODEITEM_FirstChild);
1454 while (pHeadChild) {
1455 CXFA_Node* pSibling =
1456 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1457 RemoveChild(pHeadChild);
1458 pHeadChild = pSibling;
1459 }
1460 CXFA_Node* pProtoForm = pProtoNode->CloneTemplateToForm(TRUE);
1461 pHeadChild = pProtoForm->GetNodeItem(XFA_NODEITEM_FirstChild);
1462 while (pHeadChild) {
1463 CXFA_Node* pSibling =
1464 pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1465 pProtoForm->RemoveChild(pHeadChild);
1466 InsertChild(pHeadChild);
1467 pHeadChild = pSibling;
1468 }
1469 m_pDocument->RemovePurgeNode(pProtoForm);
1470 delete pProtoForm;
1471 }
1472 }
1473 } else {
1474 CFX_WideString wsValue;
1475 GetAttribute(eAttribute, wsValue);
1476 pValue->SetString(
1477 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
1478 }
1479 }
1480 void CXFA_Node::Script_Attribute_StringRead(CFXJSE_Value* pValue,
1481 FX_BOOL bSetting,
1482 XFA_ATTRIBUTE eAttribute) {
1483 if (!bSetting) {
1484 CFX_WideString wsValue;
1485 GetAttribute(eAttribute, wsValue);
1486 pValue->SetString(
1487 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
1488 } else {
1489 ThrowException(XFA_IDS_INVAlID_PROP_SET);
1490 }
1491 }
1492 void CXFA_Node::Script_WsdlConnection_Execute(CFXJSE_Arguments* pArguments) {
1493 int32_t argc = pArguments->GetLength();
1494 if ((argc == 0) || (argc == 1)) {
1495 pArguments->GetReturnValue()->SetBoolean(FALSE);
1496 } else {
1497 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execute");
1498 }
1499 }
1500 void CXFA_Node::Script_Delta_Restore(CFXJSE_Arguments* pArguments) {
1501 int32_t argc = pArguments->GetLength();
1502 if (argc == 0) {
1503 } else {
1504 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"restore");
1505 }
1506 }
1507 void CXFA_Node::Script_Delta_CurrentValue(CFXJSE_Value* pValue,
1508 FX_BOOL bSetting,
1509 XFA_ATTRIBUTE eAttribute) {}
1510 void CXFA_Node::Script_Delta_SavedValue(CFXJSE_Value* pValue,
1511 FX_BOOL bSetting,
1512 XFA_ATTRIBUTE eAttribute) {}
1513 void CXFA_Node::Script_Delta_Target(CFXJSE_Value* pValue,
1514 FX_BOOL bSetting,
1515 XFA_ATTRIBUTE eAttribute) {}
1516 void CXFA_Node::Script_Som_Message(CFXJSE_Value* pValue,
1517 FX_BOOL bSetting,
1518 XFA_SOM_MESSAGETYPE iMessageType) {
1519 CXFA_WidgetData* pWidgetData = GetWidgetData();
1520 if (!pWidgetData) {
1521 return;
1522 }
1523 FX_BOOL bNew = FALSE;
1524 CXFA_Validate validate = pWidgetData->GetValidate();
1525 if (!validate) {
1526 validate = pWidgetData->GetValidate(TRUE);
1527 bNew = TRUE;
1528 }
1529 if (bSetting) {
1530 switch (iMessageType) {
1531 case XFA_SOM_ValidationMessage:
1532 validate.SetScriptMessageText(pValue->ToWideString());
1533 break;
1534 case XFA_SOM_FormatMessage:
1535 validate.SetFormatMessageText(pValue->ToWideString());
1536 break;
1537 case XFA_SOM_MandatoryMessage:
1538 validate.SetNullMessageText(pValue->ToWideString());
1539 break;
1540 default:
1541 break;
1542 }
1543 if (!bNew) {
1544 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
1545 if (!pNotify) {
1546 return;
1547 }
1548 pNotify->AddCalcValidate(this);
1549 }
1550 } else {
1551 CFX_WideString wsMessage;
1552 switch (iMessageType) {
1553 case XFA_SOM_ValidationMessage:
1554 validate.GetScriptMessageText(wsMessage);
1555 break;
1556 case XFA_SOM_FormatMessage:
1557 validate.GetFormatMessageText(wsMessage);
1558 break;
1559 case XFA_SOM_MandatoryMessage:
1560 validate.GetNullMessageText(wsMessage);
1561 break;
1562 default:
1563 break;
1564 }
1565 pValue->SetString(FX_UTF8Encode(wsMessage).AsStringC());
1566 }
1567 }
1568 void CXFA_Node::Script_Som_ValidationMessage(CFXJSE_Value* pValue,
1569 FX_BOOL bSetting,
1570 XFA_ATTRIBUTE eAttribute) {
1571 Script_Som_Message(pValue, bSetting, XFA_SOM_ValidationMessage);
1572 }
1573 void CXFA_Node::Script_Field_Length(CFXJSE_Value* pValue,
1574 FX_BOOL bSetting,
1575 XFA_ATTRIBUTE eAttribute) {
1576 if (bSetting) {
1577 ThrowException(XFA_IDS_INVAlID_PROP_SET);
1578 } else {
1579 CXFA_WidgetData* pWidgetData = GetWidgetData();
1580 if (!pWidgetData) {
1581 pValue->SetInteger(0);
1582 return;
1583 }
1584 pValue->SetInteger(pWidgetData->CountChoiceListItems(TRUE));
1585 }
1586 }
1587 void CXFA_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue,
1588 FX_BOOL bSetting,
1589 XFA_ATTRIBUTE eAttribute) {
1590 XFA_Element eType = GetElementType();
1591 if (eType == XFA_Element::Field) {
1592 Script_Field_DefaultValue(pValue, bSetting, eAttribute);
1593 return;
1594 }
1595 if (eType == XFA_Element::Draw) {
1596 Script_Draw_DefaultValue(pValue, bSetting, eAttribute);
1597 return;
1598 }
1599 if (eType == XFA_Element::Boolean) {
1600 Script_Boolean_Value(pValue, bSetting, eAttribute);
1601 return;
1602 }
1603 if (bSetting) {
1604 CFX_WideString wsNewValue;
1605 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
1606 wsNewValue = pValue->ToWideString();
1607
1608 CFX_WideString wsFormatValue(wsNewValue);
1609 CXFA_WidgetData* pContainerWidgetData = nullptr;
1610 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
1611 CXFA_NodeArray formNodes;
1612 GetBindItems(formNodes);
1613 CFX_WideString wsPicture;
1614 for (int32_t i = 0; i < formNodes.GetSize(); i++) {
1615 CXFA_Node* pFormNode = formNodes.GetAt(i);
1616 if (!pFormNode || pFormNode->HasRemovedChildren()) {
1617 continue;
1618 }
1619 pContainerWidgetData = pFormNode->GetContainerWidgetData();
1620 if (pContainerWidgetData) {
1621 pContainerWidgetData->GetPictureContent(wsPicture,
1622 XFA_VALUEPICTURE_DataBind);
1623 }
1624 if (!wsPicture.IsEmpty()) {
1625 break;
1626 }
1627 pContainerWidgetData = nullptr;
1628 }
1629 } else if (GetPacketID() == XFA_XDPPACKET_Form) {
1630 pContainerWidgetData = GetContainerWidgetData();
1631 }
1632 if (pContainerWidgetData) {
1633 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
1634 }
1635 SetScriptContent(wsNewValue, wsFormatValue, true, TRUE);
1636 } else {
1637 CFX_WideString content = GetScriptContent(TRUE);
1638 if (content.IsEmpty() && eType != XFA_Element::Text &&
1639 eType != XFA_Element::SubmitUrl) {
1640 pValue->SetNull();
1641 } else if (eType == XFA_Element::Integer) {
1642 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
1643 } else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) {
1644 CFX_Decimal decimal(content.AsStringC());
1645 pValue->SetFloat((FX_FLOAT)(double)decimal);
1646 } else {
1647 pValue->SetString(
1648 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
1649 }
1650 }
1651 }
1652 void CXFA_Node::Script_Som_DefaultValue_Read(CFXJSE_Value* pValue,
1653 FX_BOOL bSetting,
1654 XFA_ATTRIBUTE eAttribute) {
1655 if (bSetting) {
1656 ThrowException(XFA_IDS_INVAlID_PROP_SET);
1657 return;
1658 }
1659 CFX_WideString content = GetScriptContent(TRUE);
1660 if (content.IsEmpty()) {
1661 pValue->SetNull();
1662 } else {
1663 pValue->SetString(
1664 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
1665 }
1666 }
1667 void CXFA_Node::Script_Boolean_Value(CFXJSE_Value* pValue,
1668 FX_BOOL bSetting,
1669 XFA_ATTRIBUTE eAttribute) {
1670 if (bSetting) {
1671 CFX_ByteString newValue;
1672 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
1673 newValue = pValue->ToString();
1674
1675 int32_t iValue = FXSYS_atoi(newValue.c_str());
1676 CFX_WideString wsNewValue(iValue == 0 ? L"0" : L"1");
1677 CFX_WideString wsFormatValue(wsNewValue);
1678 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
1679 if (pContainerWidgetData) {
1680 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
1681 }
1682 SetScriptContent(wsNewValue, wsFormatValue, true, TRUE);
1683 } else {
1684 CFX_WideString wsValue = GetScriptContent(TRUE);
1685 pValue->SetBoolean(wsValue == FX_WSTRC(L"1"));
1686 }
1687 }
1688 struct XFA_ExecEventParaInfo {
1689 public:
1690 uint32_t m_uHash;
1691 const FX_WCHAR* m_lpcEventName;
1692 XFA_EVENTTYPE m_eventType;
1693 uint32_t m_validFlags;
1694 };
1695 static const XFA_ExecEventParaInfo gs_eventParaInfos[] = {
1696 {0x02a6c55a, L"postSubmit", XFA_EVENT_PostSubmit, 0},
1697 {0x0ab466bb, L"preSubmit", XFA_EVENT_PreSubmit, 0},
1698 {0x109d7ce7, L"mouseEnter", XFA_EVENT_MouseEnter, 5},
1699 {0x17fad373, L"postPrint", XFA_EVENT_PostPrint, 0},
1700 {0x1bfc72d9, L"preOpen", XFA_EVENT_PreOpen, 7},
1701 {0x2196a452, L"initialize", XFA_EVENT_Initialize, 1},
1702 {0x27410f03, L"mouseExit", XFA_EVENT_MouseExit, 5},
1703 {0x33c43dec, L"docClose", XFA_EVENT_DocClose, 0},
1704 {0x361fa1b6, L"preSave", XFA_EVENT_PreSave, 0},
1705 {0x36f1c6d8, L"preSign", XFA_EVENT_PreSign, 6},
1706 {0x4731d6ba, L"exit", XFA_EVENT_Exit, 2},
1707 {0x56bf456b, L"docReady", XFA_EVENT_DocReady, 0},
1708 {0x7233018a, L"validate", XFA_EVENT_Validate, 1},
1709 {0x8808385e, L"indexChange", XFA_EVENT_IndexChange, 3},
1710 {0x891f4606, L"change", XFA_EVENT_Change, 4},
1711 {0x9528a7b4, L"prePrint", XFA_EVENT_PrePrint, 0},
1712 {0x9f693b21, L"mouseDown", XFA_EVENT_MouseDown, 5},
1713 {0xcdce56b3, L"full", XFA_EVENT_Full, 4},
1714 {0xd576d08e, L"mouseUp", XFA_EVENT_MouseUp, 5},
1715 {0xd95657a6, L"click", XFA_EVENT_Click, 4},
1716 {0xdbfbe02e, L"calculate", XFA_EVENT_Calculate, 1},
1717 {0xe25fa7b8, L"postOpen", XFA_EVENT_PostOpen, 7},
1718 {0xe28dce7e, L"enter", XFA_EVENT_Enter, 2},
1719 {0xfc82d695, L"postSave", XFA_EVENT_PostSave, 0},
1720 {0xfd54fbb7, L"postSign", XFA_EVENT_PostSign, 6},
1721 };
1722 const XFA_ExecEventParaInfo* GetEventParaInfoByName(
1723 const CFX_WideStringC& wsEventName) {
1724 uint32_t uHash = FX_HashCode_GetW(wsEventName, false);
1725 int32_t iStart = 0;
1726 int32_t iEnd = (sizeof(gs_eventParaInfos) / sizeof(gs_eventParaInfos[0])) - 1;
1727 do {
1728 int32_t iMid = (iStart + iEnd) / 2;
1729 const XFA_ExecEventParaInfo* eventParaInfo = &gs_eventParaInfos[iMid];
1730 if (uHash == eventParaInfo->m_uHash) {
1731 return eventParaInfo;
1732 }
1733 if (uHash < eventParaInfo->m_uHash) {
1734 iEnd = iMid - 1;
1735 } else {
1736 iStart = iMid + 1;
1737 }
1738 } while (iStart <= iEnd);
1739 return nullptr;
1740 }
1741 void XFA_STRING_TO_RGB(const CFX_WideString& strRGB,
1742 int32_t& r,
1743 int32_t& g,
1744 int32_t& b) {
1745 r = 0;
1746 g = 0;
1747 b = 0;
1748
1749 FX_WCHAR zero = '0';
1750 int32_t iIndex = 0;
1751 int32_t iLen = strRGB.GetLength();
1752 for (int32_t i = 0; i < iLen; ++i) {
1753 FX_WCHAR ch = strRGB.GetAt(i);
1754 if (ch == L',') {
1755 ++iIndex;
1756 }
1757 if (iIndex > 2) {
1758 break;
1759 }
1760 int32_t iValue = ch - zero;
1761 if (iValue >= 0 && iValue <= 9) {
1762 switch (iIndex) {
1763 case 0:
1764 r = r * 10 + iValue;
1765 break;
1766 case 1:
1767 g = g * 10 + iValue;
1768 break;
1769 default:
1770 b = b * 10 + iValue;
1771 break;
1772 }
1773 }
1774 }
1775 }
1776 void CXFA_Node::Script_Som_BorderColor(CFXJSE_Value* pValue,
1777 FX_BOOL bSetting,
1778 XFA_ATTRIBUTE eAttribute) {
1779 CXFA_WidgetData* pWidgetData = GetWidgetData();
1780 if (!pWidgetData) {
1781 return;
1782 }
1783 CXFA_Border border = pWidgetData->GetBorder(TRUE);
1784 int32_t iSize = border.CountEdges();
1785 if (bSetting) {
1786 int32_t r = 0;
1787 int32_t g = 0;
1788 int32_t b = 0;
1789 XFA_STRING_TO_RGB(pValue->ToWideString(), r, g, b);
1790 FX_ARGB rgb = ArgbEncode(100, r, g, b);
1791 for (int32_t i = 0; i < iSize; ++i) {
1792 CXFA_Edge edge = border.GetEdge(i);
1793 edge.SetColor(rgb);
1794 }
1795 } else {
1796 CXFA_Edge edge = border.GetEdge(0);
1797 FX_ARGB color = edge.GetColor();
1798 int32_t a, r, g, b;
1799 ArgbDecode(color, a, r, g, b);
1800 CFX_WideString strColor;
1801 strColor.Format(L"%d,%d,%d", r, g, b);
1802 pValue->SetString(FX_UTF8Encode(strColor).AsStringC());
1803 }
1804 }
1805 void CXFA_Node::Script_Som_BorderWidth(CFXJSE_Value* pValue,
1806 FX_BOOL bSetting,
1807 XFA_ATTRIBUTE eAttribute) {
1808 CXFA_WidgetData* pWidgetData = GetWidgetData();
1809 if (!pWidgetData) {
1810 return;
1811 }
1812 CXFA_Border border = pWidgetData->GetBorder(TRUE);
1813 int32_t iSize = border.CountEdges();
1814 CFX_WideString wsThickness;
1815 if (bSetting) {
1816 wsThickness = pValue->ToWideString();
1817 for (int32_t i = 0; i < iSize; ++i) {
1818 CXFA_Edge edge = border.GetEdge(i);
1819 CXFA_Measurement thickness(wsThickness.AsStringC());
1820 edge.SetMSThickness(thickness);
1821 }
1822 } else {
1823 CXFA_Edge edge = border.GetEdge(0);
1824 CXFA_Measurement thickness = edge.GetMSThickness();
1825 thickness.ToString(wsThickness);
1826 pValue->SetString(FX_UTF8Encode(wsThickness).AsStringC());
1827 }
1828 }
1829 void CXFA_Node::Script_Som_FillColor(CFXJSE_Value* pValue,
1830 FX_BOOL bSetting,
1831 XFA_ATTRIBUTE eAttribute) {
1832 CXFA_WidgetData* pWidgetData = GetWidgetData();
1833 if (!pWidgetData) {
1834 return;
1835 }
1836 CXFA_Border border = pWidgetData->GetBorder(TRUE);
1837 CXFA_Fill borderfill = border.GetFill(TRUE);
1838 CXFA_Node* pNode = borderfill.GetNode();
1839 if (!pNode) {
1840 return;
1841 }
1842 if (bSetting) {
1843 int32_t r;
1844 int32_t g;
1845 int32_t b;
1846 XFA_STRING_TO_RGB(pValue->ToWideString(), r, g, b);
1847 FX_ARGB color = ArgbEncode(0xff, r, g, b);
1848 borderfill.SetColor(color);
1849 } else {
1850 FX_ARGB color = borderfill.GetColor();
1851 int32_t a;
1852 int32_t r;
1853 int32_t g;
1854 int32_t b;
1855 ArgbDecode(color, a, r, g, b);
1856 CFX_WideString wsColor;
1857 wsColor.Format(L"%d,%d,%d", r, g, b);
1858 pValue->SetString(FX_UTF8Encode(wsColor).AsStringC());
1859 }
1860 }
1861 void CXFA_Node::Script_Som_DataNode(CFXJSE_Value* pValue,
1862 FX_BOOL bSetting,
1863 XFA_ATTRIBUTE eAttribute) {
1864 if (!bSetting) {
1865 CXFA_Node* pDataNode = GetBindData();
1866 if (pDataNode) {
1867 pValue->Assign(
1868 m_pDocument->GetScriptContext()->GetJSValueFromMap(pDataNode));
1869 } else {
1870 pValue->SetNull();
1871 }
1872 } else {
1873 ThrowException(XFA_IDS_INVAlID_PROP_SET);
1874 }
1875 }
1876 void CXFA_Node::Script_Draw_DefaultValue(CFXJSE_Value* pValue,
1877 FX_BOOL bSetting,
1878 XFA_ATTRIBUTE eAttribute) {
1879 if (bSetting) {
1880 if (pValue && pValue->IsString()) {
1881 CXFA_WidgetData* pWidgetData = GetWidgetData();
1882 ASSERT(pWidgetData);
1883 XFA_Element uiType = pWidgetData->GetUIType();
1884 if (uiType == XFA_Element::Text) {
1885 CFX_WideString wsNewValue = pValue->ToWideString();
1886 CFX_WideString wsFormatValue(wsNewValue);
1887 SetScriptContent(wsNewValue, wsFormatValue, true, TRUE);
1888 }
1889 }
1890 } else {
1891 CFX_WideString content = GetScriptContent(TRUE);
1892 if (content.IsEmpty()) {
1893 pValue->SetNull();
1894 } else {
1895 pValue->SetString(
1896 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
1897 }
1898 }
1899 }
1900 void CXFA_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue,
1901 FX_BOOL bSetting,
1902 XFA_ATTRIBUTE eAttribute) {
1903 CXFA_WidgetData* pWidgetData = GetWidgetData();
1904 if (!pWidgetData) {
1905 return;
1906 }
1907 if (bSetting) {
1908 if (pValue && pValue->IsNull()) {
1909 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
1910 pWidgetData->m_bIsNull = TRUE;
1911 } else {
1912 pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
1913 pWidgetData->m_bIsNull = FALSE;
1914 }
1915 CFX_WideString wsNewText;
1916 if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
1917 wsNewText = pValue->ToWideString();
1918
1919 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
1920 if (pUIChild->GetElementType() == XFA_Element::NumericEdit) {
1921 int32_t iLeadDigits = 0;
1922 int32_t iFracDigits = 0;
1923 pWidgetData->GetLeadDigits(iLeadDigits);
1924 pWidgetData->GetFracDigits(iFracDigits);
1925 wsNewText =
1926 pWidgetData->NumericLimit(wsNewText, iLeadDigits, iFracDigits);
1927 }
1928 CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
1929 CFX_WideString wsFormatText(wsNewText);
1930 if (pContainerWidgetData) {
1931 pContainerWidgetData->GetFormatDataValue(wsNewText, wsFormatText);
1932 }
1933 SetScriptContent(wsNewText, wsFormatText, true, TRUE);
1934 } else {
1935 CFX_WideString content = GetScriptContent(TRUE);
1936 if (content.IsEmpty()) {
1937 pValue->SetNull();
1938 } else {
1939 CXFA_Node* pUIChild = pWidgetData->GetUIChild();
1940 CXFA_Value defVal = pWidgetData->GetFormValue();
1941 CXFA_Node* pNode = defVal.GetNode()->GetNodeItem(XFA_NODEITEM_FirstChild);
1942 if (pNode && pNode->GetElementType() == XFA_Element::Decimal) {
1943 if (pUIChild->GetElementType() == XFA_Element::NumericEdit &&
1944 (pNode->GetInteger(XFA_ATTRIBUTE_FracDigits) == -1)) {
1945 pValue->SetString(
1946 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
1947 } else {
1948 CFX_Decimal decimal(content.AsStringC());
1949 pValue->SetFloat((FX_FLOAT)(double)decimal);
1950 }
1951 } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) {
1952 pValue->SetInteger(FXSYS_wtoi(content.c_str()));
1953 } else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) {
1954 pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? FALSE : TRUE);
1955 } else if (pNode && pNode->GetElementType() == XFA_Element::Float) {
1956 CFX_Decimal decimal(content.AsStringC());
1957 pValue->SetFloat((FX_FLOAT)(double)decimal);
1958 } else {
1959 pValue->SetString(
1960 FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
1961 }
1962 }
1963 }
1964 }
1965 void CXFA_Node::Script_Field_EditValue(CFXJSE_Value* pValue,
1966 FX_BOOL bSetting,
1967 XFA_ATTRIBUTE eAttribute) {
1968 CXFA_WidgetData* pWidgetData = GetWidgetData();
1969 if (!pWidgetData) {
1970 return;
1971 }
1972 if (bSetting) {
1973 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Edit);
1974 } else {
1975 CFX_WideString wsValue;
1976 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Edit);
1977 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
1978 }
1979 }
1980 void CXFA_Node::Script_Som_FontColor(CFXJSE_Value* pValue,
1981 FX_BOOL bSetting,
1982 XFA_ATTRIBUTE eAttribute) {
1983 CXFA_WidgetData* pWidgetData = GetWidgetData();
1984 if (!pWidgetData) {
1985 return;
1986 }
1987 CXFA_Font font = pWidgetData->GetFont(TRUE);
1988 CXFA_Node* pNode = font.GetNode();
1989 if (!pNode) {
1990 return;
1991 }
1992 if (bSetting) {
1993 int32_t r;
1994 int32_t g;
1995 int32_t b;
1996 XFA_STRING_TO_RGB(pValue->ToWideString(), r, g, b);
1997 FX_ARGB color = ArgbEncode(0xff, r, g, b);
1998 font.SetColor(color);
1999 } else {
2000 FX_ARGB color = font.GetColor();
2001 int32_t a;
2002 int32_t r;
2003 int32_t g;
2004 int32_t b;
2005 ArgbDecode(color, a, r, g, b);
2006 CFX_WideString wsColor;
2007 wsColor.Format(L"%d,%d,%d", r, g, b);
2008 pValue->SetString(FX_UTF8Encode(wsColor).AsStringC());
2009 }
2010 }
2011 void CXFA_Node::Script_Field_FormatMessage(CFXJSE_Value* pValue,
2012 FX_BOOL bSetting,
2013 XFA_ATTRIBUTE eAttribute) {
2014 Script_Som_Message(pValue, bSetting, XFA_SOM_FormatMessage);
2015 }
2016 void CXFA_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue,
2017 FX_BOOL bSetting,
2018 XFA_ATTRIBUTE eAttribute) {
2019 CXFA_WidgetData* pWidgetData = GetWidgetData();
2020 if (!pWidgetData) {
2021 return;
2022 }
2023 if (bSetting) {
2024 pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Display);
2025 } else {
2026 CFX_WideString wsValue;
2027 pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Display);
2028 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
2029 }
2030 }
2031 void CXFA_Node::Script_Som_Mandatory(CFXJSE_Value* pValue,
2032 FX_BOOL bSetting,
2033 XFA_ATTRIBUTE eAttribute) {
2034 CXFA_WidgetData* pWidgetData = GetWidgetData();
2035 if (!pWidgetData) {
2036 return;
2037 }
2038 CXFA_Validate validate = pWidgetData->GetValidate(TRUE);
2039 if (bSetting) {
2040 validate.SetNullTest(pValue->ToWideString());
2041 } else {
2042 int32_t iValue = validate.GetNullTest();
2043 const XFA_ATTRIBUTEENUMINFO* pInfo =
2044 XFA_GetAttributeEnumByID((XFA_ATTRIBUTEENUM)iValue);
2045 CFX_WideString wsValue;
2046 if (pInfo)
2047 wsValue = pInfo->pName;
2048 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
2049 }
2050 }
2051 void CXFA_Node::Script_Som_MandatoryMessage(CFXJSE_Value* pValue,
2052 FX_BOOL bSetting,
2053 XFA_ATTRIBUTE eAttribute) {
2054 Script_Som_Message(pValue, bSetting, XFA_SOM_MandatoryMessage);
2055 }
2056 void CXFA_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue,
2057 FX_BOOL bSetting,
2058 XFA_ATTRIBUTE eAttribute) {
2059 if (bSetting) {
2060 ThrowException(XFA_IDS_INVAlID_PROP_SET);
2061 } else {
2062 pValue->SetNull();
2063 }
2064 }
2065 void CXFA_Node::Script_Field_SelectedIndex(CFXJSE_Value* pValue,
2066 FX_BOOL bSetting,
2067 XFA_ATTRIBUTE eAttribute) {
2068 CXFA_WidgetData* pWidgetData = GetWidgetData();
2069 if (!pWidgetData) {
2070 return;
2071 }
2072 if (bSetting) {
2073 int32_t iIndex = pValue->ToInteger();
2074 if (iIndex == -1) {
2075 pWidgetData->ClearAllSelections();
2076 return;
2077 }
2078 pWidgetData->SetItemState(iIndex, TRUE, true, TRUE, TRUE);
2079 } else {
2080 pValue->SetInteger(pWidgetData->GetSelectedItem());
2081 }
2082 }
2083 void CXFA_Node::Script_Field_ClearItems(CFXJSE_Arguments* pArguments) {
2084 CXFA_WidgetData* pWidgetData = GetWidgetData();
2085 if (!pWidgetData) {
2086 return;
2087 }
2088 pWidgetData->DeleteItem(-1, TRUE);
2089 }
2090 void CXFA_Node::Script_Field_ExecEvent(CFXJSE_Arguments* pArguments) {
2091 int32_t argc = pArguments->GetLength();
2092 if (argc == 1) {
2093 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2094 int32_t iRet = execSingleEventByName(
2095 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2096 XFA_Element::Field);
2097 if (eventString == "validate") {
2098 pArguments->GetReturnValue()->SetBoolean(
2099 (iRet == XFA_EVENTERROR_Error) ? FALSE : TRUE);
2100 }
2101 } else {
2102 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent");
2103 }
2104 }
2105 void CXFA_Node::Script_Field_ExecInitialize(CFXJSE_Arguments* pArguments) {
2106 int32_t argc = pArguments->GetLength();
2107 if (argc == 0) {
2108 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2109 if (!pNotify) {
2110 return;
2111 }
2112 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize, FALSE, FALSE);
2113 } else {
2114 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");
2115 }
2116 }
2117 void CXFA_Node::Script_Field_DeleteItem(CFXJSE_Arguments* pArguments) {
2118 int32_t iLength = pArguments->GetLength();
2119 if (iLength != 1) {
2120 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"deleteItem");
2121 return;
2122 }
2123 CXFA_WidgetData* pWidgetData = GetWidgetData();
2124 if (!pWidgetData) {
2125 return;
2126 }
2127 int32_t iIndex = pArguments->GetInt32(0);
2128 FX_BOOL bValue = pWidgetData->DeleteItem(iIndex, TRUE, TRUE);
2129 CFXJSE_Value* pValue = pArguments->GetReturnValue();
2130 if (pValue)
2131 pValue->SetBoolean(bValue);
2132 }
2133 void CXFA_Node::Script_Field_GetSaveItem(CFXJSE_Arguments* pArguments) {
2134 int32_t iLength = pArguments->GetLength();
2135 if (iLength != 1) {
2136 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getSaveItem");
2137 return;
2138 }
2139 int32_t iIndex = pArguments->GetInt32(0);
2140 if (iIndex < 0) {
2141 pArguments->GetReturnValue()->SetNull();
2142 return;
2143 }
2144 CXFA_WidgetData* pWidgetData = GetWidgetData();
2145 if (!pWidgetData) {
2146 pArguments->GetReturnValue()->SetNull();
2147 return;
2148 }
2149 CFX_WideString wsValue;
2150 FX_BOOL bHasItem = pWidgetData->GetChoiceListItem(wsValue, iIndex, TRUE);
2151 if (bHasItem) {
2152 pArguments->GetReturnValue()->SetString(
2153 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
2154 } else {
2155 pArguments->GetReturnValue()->SetNull();
2156 }
2157 }
2158 void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments) {
2159 int32_t iLength = pArguments->GetLength();
2160 if (iLength != 1) {
2161 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"boundItem");
2162 return;
2163 }
2164 CXFA_WidgetData* pWidgetData = GetWidgetData();
2165 if (!pWidgetData) {
2166 return;
2167 }
2168 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
2169 CFX_WideString wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
2170 CFX_WideString wsBoundValue;
2171 pWidgetData->GetItemValue(wsValue.AsStringC(), wsBoundValue);
2172 CFXJSE_Value* pValue = pArguments->GetReturnValue();
2173 if (pValue)
2174 pValue->SetString(FX_UTF8Encode(wsBoundValue).AsStringC());
2175 }
2176 void CXFA_Node::Script_Field_GetItemState(CFXJSE_Arguments* pArguments) {
2177 int32_t iLength = pArguments->GetLength();
2178 if (iLength != 1) {
2179 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getItemState");
2180 return;
2181 }
2182 CXFA_WidgetData* pWidgetData = GetWidgetData();
2183 if (!pWidgetData) {
2184 return;
2185 }
2186 int32_t iIndex = pArguments->GetInt32(0);
2187 FX_BOOL bValue = pWidgetData->GetItemState(iIndex);
2188 CFXJSE_Value* pValue = pArguments->GetReturnValue();
2189 if (pValue)
2190 pValue->SetBoolean(bValue);
2191 }
2192 void CXFA_Node::Script_Field_ExecCalculate(CFXJSE_Arguments* pArguments) {
2193 int32_t argc = pArguments->GetLength();
2194 if (argc == 0) {
2195 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2196 if (!pNotify) {
2197 return;
2198 }
2199 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate, FALSE, FALSE);
2200 } else {
2201 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");
2202 }
2203 }
2204 void CXFA_Node::Script_Field_SetItems(CFXJSE_Arguments* pArguments) {}
2205 void CXFA_Node::Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments) {
2206 int32_t iLength = pArguments->GetLength();
2207 if (iLength != 1) {
2208 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getDisplayItem");
2209 return;
2210 }
2211 int32_t iIndex = pArguments->GetInt32(0);
2212 if (iIndex < 0) {
2213 pArguments->GetReturnValue()->SetNull();
2214 return;
2215 }
2216 CXFA_WidgetData* pWidgetData = GetWidgetData();
2217 if (!pWidgetData) {
2218 pArguments->GetReturnValue()->SetNull();
2219 return;
2220 }
2221 CFX_WideString wsValue;
2222 FX_BOOL bHasItem = pWidgetData->GetChoiceListItem(wsValue, iIndex, FALSE);
2223 if (bHasItem) {
2224 pArguments->GetReturnValue()->SetString(
2225 FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
2226 } else {
2227 pArguments->GetReturnValue()->SetNull();
2228 }
2229 }
2230 void CXFA_Node::Script_Field_SetItemState(CFXJSE_Arguments* pArguments) {
2231 int32_t iLength = pArguments->GetLength();
2232 if (iLength != 2) {
2233 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setItemState");
2234 return;
2235 }
2236 CXFA_WidgetData* pWidgetData = GetWidgetData();
2237 if (!pWidgetData)
2238 return;
2239
2240 int32_t iIndex = pArguments->GetInt32(0);
2241 if (pArguments->GetInt32(1) != 0) {
2242 pWidgetData->SetItemState(iIndex, TRUE, true, TRUE, TRUE);
2243 } else {
2244 if (pWidgetData->GetItemState(iIndex))
2245 pWidgetData->SetItemState(iIndex, FALSE, true, TRUE, TRUE);
2246 }
2247 }
2248 void CXFA_Node::Script_Field_AddItem(CFXJSE_Arguments* pArguments) {
2249 int32_t iLength = pArguments->GetLength();
2250 if (iLength < 1 || iLength > 2) {
2251 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"addItem");
2252 return;
2253 }
2254 CXFA_WidgetData* pWidgetData = GetWidgetData();
2255 if (!pWidgetData) {
2256 return;
2257 }
2258 CFX_WideString wsLabel;
2259 CFX_WideString wsValue;
2260 if (iLength >= 1) {
2261 CFX_ByteString bsLabel = pArguments->GetUTF8String(0);
2262 wsLabel = CFX_WideString::FromUTF8(bsLabel.AsStringC());
2263 }
2264 if (iLength >= 2) {
2265 CFX_ByteString bsValue = pArguments->GetUTF8String(1);
2266 wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
2267 }
2268 pWidgetData->InsertItem(wsLabel, wsValue, -1, TRUE);
2269 }
2270 void CXFA_Node::Script_Field_ExecValidate(CFXJSE_Arguments* pArguments) {
2271 int32_t argc = pArguments->GetLength();
2272 if (argc == 0) {
2273 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2274 if (!pNotify) {
2275 pArguments->GetReturnValue()->SetBoolean(FALSE);
2276 } else {
2277 int32_t iRet =
2278 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate, FALSE, FALSE);
2279 pArguments->GetReturnValue()->SetBoolean(
2280 (iRet == XFA_EVENTERROR_Error) ? FALSE : TRUE);
2281 }
2282 } else {
2283 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");
2284 }
2285 }
2286 void CXFA_Node::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue,
2287 FX_BOOL bSetting,
2288 XFA_ATTRIBUTE eAttribute) {
2289 if (!bSetting) {
2290 } else {
2291 ThrowException(XFA_IDS_INVAlID_PROP_SET);
2292 }
2293 }
2294 void CXFA_Node::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue,
2295 FX_BOOL bSetting,
2296 XFA_ATTRIBUTE eAttribute) {
2297 CXFA_WidgetData* pWidgetData = GetWidgetData();
2298 if (!pWidgetData) {
2299 return;
2300 }
2301 if (bSetting) {
2302 pWidgetData->SetSelectedMemberByValue(pValue->ToWideString().AsStringC(),
2303 true, TRUE, TRUE);
2304 } else {
2305 CFX_WideString wsValue = GetScriptContent(TRUE);
2306 XFA_VERSION curVersion = GetDocument()->GetCurVersionMode();
2307 if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) {
2308 pValue->SetNull();
2309 } else {
2310 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
2311 }
2312 }
2313 }
2314 void CXFA_Node::Script_ExclGroup_Transient(CFXJSE_Value* pValue,
2315 FX_BOOL bSetting,
2316 XFA_ATTRIBUTE eAttribute) {}
2317 void CXFA_Node::Script_ExclGroup_ExecEvent(CFXJSE_Arguments* pArguments) {
2318 int32_t argc = pArguments->GetLength();
2319 if (argc == 1) {
2320 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2321 execSingleEventByName(
2322 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2323 XFA_Element::ExclGroup);
2324 } else {
2325 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent");
2326 }
2327 }
2328
2329 void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments) {
2330 int32_t argc = pArguments->GetLength();
2331 if (argc < 0 || argc > 1) {
2332 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"selectedMember");
2333 return;
2334 }
2335
2336 CXFA_WidgetData* pWidgetData = GetWidgetData();
2337 if (!pWidgetData) {
2338 pArguments->GetReturnValue()->SetNull();
2339 return;
2340 }
2341
2342 CXFA_Node* pReturnNode = nullptr;
2343 if (argc == 0) {
2344 pReturnNode = pWidgetData->GetSelectedMember();
2345 } else {
2346 CFX_ByteString szName;
2347 szName = pArguments->GetUTF8String(0);
2348 pReturnNode = pWidgetData->SetSelectedMember(
2349 CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC(), true);
2350 }
2351 if (!pReturnNode) {
2352 pArguments->GetReturnValue()->SetNull();
2353 return;
2354 }
2355 pArguments->GetReturnValue()->Assign(
2356 m_pDocument->GetScriptContext()->GetJSValueFromMap(pReturnNode));
2357 }
2358
2359 void CXFA_Node::Script_ExclGroup_ExecInitialize(CFXJSE_Arguments* pArguments) {
2360 int32_t argc = pArguments->GetLength();
2361 if (argc == 0) {
2362 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2363 if (!pNotify) {
2364 return;
2365 }
2366 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
2367 } else {
2368 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");
2369 }
2370 }
2371 void CXFA_Node::Script_ExclGroup_ExecCalculate(CFXJSE_Arguments* pArguments) {
2372 int32_t argc = pArguments->GetLength();
2373 if (argc == 0) {
2374 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2375 if (!pNotify) {
2376 return;
2377 }
2378 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
2379 } else {
2380 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");
2381 }
2382 }
2383 void CXFA_Node::Script_ExclGroup_ExecValidate(CFXJSE_Arguments* pArguments) {
2384 int32_t argc = pArguments->GetLength();
2385 if (argc == 0) {
2386 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2387 if (!pNotify) {
2388 pArguments->GetReturnValue()->SetBoolean(FALSE);
2389 } else {
2390 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
2391 pArguments->GetReturnValue()->SetBoolean(
2392 (iRet == XFA_EVENTERROR_Error) ? FALSE : TRUE);
2393 }
2394 } else {
2395 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");
2396 }
2397 }
2398 static CXFA_Node* XFA_ScriptInstanceManager_GetItem(CXFA_Node* pInstMgrNode,
2399 int32_t iIndex) {
2400 ASSERT(pInstMgrNode);
2401 int32_t iCount = 0;
2402 uint32_t dwNameHash = 0;
2403 for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
2404 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
2405 XFA_Element eCurType = pNode->GetElementType();
2406 if (eCurType == XFA_Element::InstanceManager) {
2407 break;
2408 }
2409 if ((eCurType != XFA_Element::Subform) &&
2410 (eCurType != XFA_Element::SubformSet)) {
2411 continue;
2412 }
2413 if (iCount == 0) {
2414 CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
2415 CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
2416 if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
2417 wsInstName.Mid(1) != wsName) {
2418 return nullptr;
2419 }
2420 dwNameHash = pNode->GetNameHash();
2421 }
2422 if (dwNameHash != pNode->GetNameHash()) {
2423 break;
2424 }
2425 iCount++;
2426 if (iCount > iIndex) {
2427 return pNode;
2428 }
2429 }
2430 return nullptr;
2431 }
2432 void CXFA_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue,
2433 FX_BOOL bSetting,
2434 XFA_ATTRIBUTE eAttribute) {
2435 if (bSetting) {
2436 int32_t iTo = pValue->ToInteger();
2437 int32_t iFrom = Subform_and_SubformSet_InstanceIndex();
2438 CXFA_Node* pManagerNode = nullptr;
2439 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2440 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
2441 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
2442 pManagerNode = pNode;
2443 break;
2444 }
2445 }
2446 if (pManagerNode) {
2447 pManagerNode->InstanceManager_MoveInstance(iTo, iFrom);
2448 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2449 if (!pNotify) {
2450 return;
2451 }
2452 CXFA_Node* pToInstance =
2453 XFA_ScriptInstanceManager_GetItem(pManagerNode, iTo);
2454 if (pToInstance &&
2455 pToInstance->GetElementType() == XFA_Element::Subform) {
2456 pNotify->RunSubformIndexChange(pToInstance);
2457 }
2458 CXFA_Node* pFromInstance =
2459 XFA_ScriptInstanceManager_GetItem(pManagerNode, iFrom);
2460 if (pFromInstance &&
2461 pFromInstance->GetElementType() == XFA_Element::Subform) {
2462 pNotify->RunSubformIndexChange(pFromInstance);
2463 }
2464 }
2465 } else {
2466 pValue->SetInteger(Subform_and_SubformSet_InstanceIndex());
2467 }
2468 }
2469 void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue,
2470 FX_BOOL bSetting,
2471 XFA_ATTRIBUTE eAttribute) {
2472 if (!bSetting) {
2473 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
2474 CXFA_Node* pInstanceMgr = nullptr;
2475 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2476 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
2477 if (pNode->GetElementType() == XFA_Element::InstanceManager) {
2478 CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name);
2479 if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' &&
2480 wsInstMgrName.Mid(1) == wsName) {
2481 pInstanceMgr = pNode;
2482 }
2483 break;
2484 }
2485 }
2486 if (pInstanceMgr) {
2487 pValue->Assign(
2488 m_pDocument->GetScriptContext()->GetJSValueFromMap(pInstanceMgr));
2489 } else {
2490 pValue->SetNull();
2491 }
2492 } else {
2493 ThrowException(XFA_IDS_INVAlID_PROP_SET);
2494 }
2495 }
2496 void CXFA_Node::Script_Subform_Locale(CFXJSE_Value* pValue,
2497 FX_BOOL bSetting,
2498 XFA_ATTRIBUTE eAttribute) {
2499 if (bSetting) {
2500 SetCData(XFA_ATTRIBUTE_Locale, pValue->ToWideString(), true, TRUE);
2501 } else {
2502 CFX_WideString wsLocaleName;
2503 GetLocaleName(wsLocaleName);
2504 pValue->SetString(
2505 FX_UTF8Encode(wsLocaleName.c_str(), wsLocaleName.GetLength())
2506 .AsStringC());
2507 }
2508 }
2509 void CXFA_Node::Script_Subform_ExecEvent(CFXJSE_Arguments* pArguments) {
2510 int32_t argc = pArguments->GetLength();
2511 if (argc == 1) {
2512 CFX_ByteString eventString = pArguments->GetUTF8String(0);
2513 execSingleEventByName(
2514 CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
2515 XFA_Element::Subform);
2516 } else {
2517 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent");
2518 }
2519 }
2520 void CXFA_Node::Script_Subform_ExecInitialize(CFXJSE_Arguments* pArguments) {
2521 int32_t argc = pArguments->GetLength();
2522 if (argc == 0) {
2523 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2524 if (!pNotify) {
2525 return;
2526 }
2527 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
2528 } else {
2529 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");
2530 }
2531 }
2532 void CXFA_Node::Script_Subform_ExecCalculate(CFXJSE_Arguments* pArguments) {
2533 int32_t argc = pArguments->GetLength();
2534 if (argc == 0) {
2535 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2536 if (!pNotify) {
2537 return;
2538 }
2539 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
2540 } else {
2541 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");
2542 }
2543 }
2544 void CXFA_Node::Script_Subform_ExecValidate(CFXJSE_Arguments* pArguments) {
2545 int32_t argc = pArguments->GetLength();
2546 if (argc == 0) {
2547 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
2548 if (!pNotify) {
2549 pArguments->GetReturnValue()->SetBoolean(FALSE);
2550 } else {
2551 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
2552 pArguments->GetReturnValue()->SetBoolean(
2553 (iRet == XFA_EVENTERROR_Error) ? FALSE : TRUE);
2554 }
2555 } else {
2556 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");
2557 }
2558 }
2559 void CXFA_Node::Script_Subform_GetInvalidObjects(CFXJSE_Arguments* pArguments) {
2560 int32_t argc = pArguments->GetLength();
2561 if (argc == 0) {
2562 } else {
2563 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getInvalidObjects");
2564 }
2565 }
2566 int32_t CXFA_Node::Subform_and_SubformSet_InstanceIndex() {
2567 int32_t index = 0;
2568 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2569 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
2570 if ((pNode->GetElementType() == XFA_Element::Subform) ||
2571 (pNode->GetElementType() == XFA_Element::SubformSet)) {
2572 index++;
2573 } else {
2574 break;
2575 }
2576 }
2577 return index;
2578 }
2579 void CXFA_Node::Script_Template_FormNodes(CFXJSE_Arguments* pArguments) {
2580 int32_t argc = pArguments->GetLength();
2581 if (argc == 1) {
2582 pArguments->GetReturnValue()->SetBoolean(TRUE);
2583 } else {
2584 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"formNodes");
2585 }
2586 }
2587 void CXFA_Node::Script_Template_Remerge(CFXJSE_Arguments* pArguments) {
2588 int32_t argc = pArguments->GetLength();
2589 if (argc == 0) {
2590 m_pDocument->DoDataRemerge(TRUE);
2591 } else {
2592 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"remerge");
2593 }
2594 }
2595 void CXFA_Node::Script_Template_ExecInitialize(CFXJSE_Arguments* pArguments) {
2596 int32_t argc = pArguments->GetLength();
2597 if (argc == 0) {
2598 CXFA_WidgetData* pWidgetData = GetWidgetData();
2599 if (!pWidgetData) {
2600 pArguments->GetReturnValue()->SetBoolean(FALSE);
2601 } else {
2602 pArguments->GetReturnValue()->SetBoolean(TRUE);
2603 }
2604 } else {
2605 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");
2606 }
2607 }
2608 void CXFA_Node::Script_Template_CreateNode(CFXJSE_Arguments* pArguments) {
2609 int32_t argc = pArguments->GetLength();
2610 if ((argc > 0) && (argc < 4)) {
2611 CFX_WideString strTagName;
2612 CFX_WideString strName;
2613 CFX_WideString strNameSpace;
2614 CFX_ByteString bsTagName = pArguments->GetUTF8String(0);
2615 strTagName = CFX_WideString::FromUTF8(bsTagName.AsStringC());
2616 if (argc > 1) {
2617 CFX_ByteString bsName = pArguments->GetUTF8String(1);
2618 strName = CFX_WideString::FromUTF8(bsName.AsStringC());
2619 if (argc == 3) {
2620 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(2);
2621 strNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
2622 }
2623 }
2624 XFA_Element eType = XFA_GetElementTypeForName(strTagName.AsStringC());
2625 CXFA_Node* pNewNode = CreateSamePacketNode(eType);
2626 if (!pNewNode) {
2627 pArguments->GetReturnValue()->SetNull();
2628 } else {
2629 if (!strName.IsEmpty()) {
2630 if (XFA_GetAttributeOfElement(eType, XFA_ATTRIBUTE_Name,
2631 XFA_XDPPACKET_UNKNOWN)) {
2632 pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, strName.AsStringC(), true);
2633 if (pNewNode->GetPacketID() == XFA_XDPPACKET_Datasets) {
2634 pNewNode->CreateXMLMappingNode();
2635 }
2636 pArguments->GetReturnValue()->Assign(
2637 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
2638 } else {
2639 ThrowException(XFA_IDS_NOT_HAVE_PROPERTY, strTagName.c_str(),
2640 L"name");
2641 }
2642 } else {
2643 pArguments->GetReturnValue()->Assign(
2644 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));
2645 }
2646 }
2647 } else {
2648 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"createNode");
2649 }
2650 }
2651 void CXFA_Node::Script_Template_Recalculate(CFXJSE_Arguments* pArguments) {
2652 if (pArguments->GetLength() == 1) {
2653 pArguments->GetReturnValue()->SetBoolean(TRUE);
2654 } else {
2655 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"recalculate");
2656 }
2657 }
2658 void CXFA_Node::Script_Template_ExecCalculate(CFXJSE_Arguments* pArguments) {
2659 int32_t argc = pArguments->GetLength();
2660 if (argc == 0) {
2661 CXFA_WidgetData* pWidgetData = GetWidgetData();
2662 if (!pWidgetData) {
2663 pArguments->GetReturnValue()->SetBoolean(FALSE);
2664 } else {
2665 pArguments->GetReturnValue()->SetBoolean(TRUE);
2666 }
2667 } else {
2668 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");
2669 }
2670 }
2671 void CXFA_Node::Script_Template_ExecValidate(CFXJSE_Arguments* pArguments) {
2672 int32_t argc = pArguments->GetLength();
2673 if (argc == 0) {
2674 CXFA_WidgetData* pWidgetData = GetWidgetData();
2675 if (!pWidgetData) {
2676 pArguments->GetReturnValue()->SetBoolean(FALSE);
2677 } else {
2678 pArguments->GetReturnValue()->SetBoolean(TRUE);
2679 }
2680 } else {
2681 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");
2682 }
2683 }
2684 void CXFA_Node::Script_Manifest_Evaluate(CFXJSE_Arguments* pArguments) {
2685 int32_t argc = pArguments->GetLength();
2686 if (argc == 0) {
2687 CXFA_WidgetData* pWidgetData = GetWidgetData();
2688 if (!pWidgetData) {
2689 pArguments->GetReturnValue()->SetBoolean(FALSE);
2690 } else {
2691 pArguments->GetReturnValue()->SetBoolean(TRUE);
2692 }
2693 } else {
2694 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"evaluate");
2695 }
2696 }
2697 void CXFA_Node::Script_InstanceManager_Max(CFXJSE_Value* pValue,
2698 FX_BOOL bSetting,
2699 XFA_ATTRIBUTE eAttribute) {
2700 if (bSetting) {
2701 ThrowException(XFA_IDS_INVAlID_PROP_SET);
2702 return;
2703 }
2704 CXFA_Occur nodeOccur(GetOccurNode());
2705 pValue->SetInteger(nodeOccur.GetMax());
2706 }
2707 void CXFA_Node::Script_InstanceManager_Min(CFXJSE_Value* pValue,
2708 FX_BOOL bSetting,
2709 XFA_ATTRIBUTE eAttribute) {
2710 if (bSetting) {
2711 ThrowException(XFA_IDS_INVAlID_PROP_SET);
2712 return;
2713 }
2714 CXFA_Occur nodeOccur(GetOccurNode());
2715 pValue->SetInteger(nodeOccur.GetMin());
2716 }
2717 static int32_t XFA_ScriptInstanceManager_GetCount(CXFA_Node* pInstMgrNode) {
2718 ASSERT(pInstMgrNode);
2719 int32_t iCount = 0;
2720 uint32_t dwNameHash = 0;
2721 for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
2722 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
2723 XFA_Element eCurType = pNode->GetElementType();
2724 if (eCurType == XFA_Element::InstanceManager) {
2725 break;
2726 }
2727 if ((eCurType != XFA_Element::Subform) &&
2728 (eCurType != XFA_Element::SubformSet)) {
2729 continue;
2730 }
2731 if (iCount == 0) {
2732 CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
2733 CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
2734 if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
2735 wsInstName.Mid(1) != wsName) {
2736 return iCount;
2737 }
2738 dwNameHash = pNode->GetNameHash();
2739 }
2740 if (dwNameHash != pNode->GetNameHash()) {
2741 break;
2742 }
2743 iCount++;
2744 }
2745 return iCount;
2746 }
2747 static void
2748 XFA_ScriptInstanceManager_ReorderDataNodes_SortNodeArrayByDocumentIdx(
2749 const CXFA_NodeSet& rgNodeSet,
2750 CXFA_NodeArray& rgNodeArray,
2751 CFX_ArrayTemplate<int32_t>& rgIdxArray) {
2752 int32_t iCount = pdfium::CollectionSize<int32_t>(rgNodeSet);
2753 rgNodeArray.SetSize(iCount);
2754 rgIdxArray.SetSize(iCount);
2755 if (iCount == 0)
2756 return;
2757
2758 int32_t iIndex = -1;
2759 int32_t iTotalIndex = -1;
2760 CXFA_Node* pCommonParent =
2761 (*rgNodeSet.begin())->GetNodeItem(XFA_NODEITEM_Parent);
2762 for (CXFA_Node* pNode = pCommonParent->GetNodeItem(XFA_NODEITEM_FirstChild);
2763 pNode && iIndex < iCount;
2764 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
2765 iTotalIndex++;
2766 if (pdfium::ContainsValue(rgNodeSet, pNode)) {
2767 iIndex++;
2768 rgNodeArray[iIndex] = pNode;
2769 rgIdxArray[iIndex] = iTotalIndex;
2770 }
2771 }
2772 }
2773
2774 using CXFA_NodeSetPair = std::pair<CXFA_NodeSet, CXFA_NodeSet>;
2775 using CXFA_NodeSetPairMap =
2776 std::map<uint32_t, std::unique_ptr<CXFA_NodeSetPair>>;
2777 using CXFA_NodeSetPairMapMap =
2778 std::map<CXFA_Node*, std::unique_ptr<CXFA_NodeSetPairMap>>;
2779
2780 static CXFA_NodeSetPair* NodeSetPairForNode(CXFA_Node* pNode,
2781 CXFA_NodeSetPairMapMap* pMap) {
2782 CXFA_Node* pParentNode = pNode->GetNodeItem(XFA_NODEITEM_Parent);
2783 uint32_t dwNameHash = pNode->GetNameHash();
2784 if (!pParentNode || !dwNameHash)
2785 return nullptr;
2786
2787 if (!(*pMap)[pParentNode])
2788 (*pMap)[pParentNode].reset(new CXFA_NodeSetPairMap);
2789
2790 CXFA_NodeSetPairMap* pNodeSetPairMap = (*pMap)[pParentNode].get();
2791 if (!(*pNodeSetPairMap)[dwNameHash])
2792 (*pNodeSetPairMap)[dwNameHash].reset(new CXFA_NodeSetPair);
2793
2794 return (*pNodeSetPairMap)[dwNameHash].get();
2795 }
2796
2797 static void XFA_ScriptInstanceManager_ReorderDataNodes(
2798 const CXFA_NodeSet& sSet1,
2799 const CXFA_NodeSet& sSet2,
2800 FX_BOOL bInsertBefore) {
2801 CXFA_NodeSetPairMapMap rgMap;
2802 for (CXFA_Node* pNode : sSet1) {
2803 CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap);
2804 if (pNodeSetPair)
2805 pNodeSetPair->first.insert(pNode);
2806 }
2807 for (CXFA_Node* pNode : sSet2) {
2808 CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap);
2809 if (pNodeSetPair) {
2810 if (pdfium::ContainsValue(pNodeSetPair->first, pNode))
2811 pNodeSetPair->first.erase(pNode);
2812 else
2813 pNodeSetPair->second.insert(pNode);
2814 }
2815 }
2816 for (const auto& iter1 : rgMap) {
2817 CXFA_NodeSetPairMap* pNodeSetPairMap = iter1.second.get();
2818 if (!pNodeSetPairMap) {
2819 continue;
2820 }
2821 for (const auto& iter2 : *pNodeSetPairMap) {
2822 CXFA_NodeSetPair* pNodeSetPair = iter2.second.get();
2823 if (!pNodeSetPair) {
2824 continue;
2825 }
2826 if (!pNodeSetPair->first.empty() && !pNodeSetPair->second.empty()) {
2827 CXFA_NodeArray rgNodeArray1;
2828 CXFA_NodeArray rgNodeArray2;
2829 CFX_ArrayTemplate<int32_t> rgIdxArray1;
2830 CFX_ArrayTemplate<int32_t> rgIdxArray2;
2831 XFA_ScriptInstanceManager_ReorderDataNodes_SortNodeArrayByDocumentIdx(
2832 pNodeSetPair->first, rgNodeArray1, rgIdxArray1);
2833 XFA_ScriptInstanceManager_ReorderDataNodes_SortNodeArrayByDocumentIdx(
2834 pNodeSetPair->second, rgNodeArray2, rgIdxArray2);
2835 CXFA_Node* pParentNode = nullptr;
2836 CXFA_Node* pBeforeNode = nullptr;
2837 if (bInsertBefore) {
2838 pBeforeNode = rgNodeArray2[0];
2839 pParentNode = pBeforeNode->GetNodeItem(XFA_NODEITEM_Parent);
2840 } else {
2841 CXFA_Node* pLastNode = rgNodeArray2[rgIdxArray2.GetSize() - 1];
2842 pParentNode = pLastNode->GetNodeItem(XFA_NODEITEM_Parent);
2843 pBeforeNode = pLastNode->GetNodeItem(XFA_NODEITEM_NextSibling);
2844 }
2845 for (int32_t iIdx = 0; iIdx < rgIdxArray1.GetSize(); iIdx++) {
2846 CXFA_Node* pCurNode = rgNodeArray1[iIdx];
2847 pParentNode->RemoveChild(pCurNode);
2848 pParentNode->InsertChild(pCurNode, pBeforeNode);
2849 }
2850 }
2851 }
2852 pNodeSetPairMap->clear();
2853 }
2854 }
2855
2856 static void XFA_ScriptInstanceManager_InsertItem(
2857 CXFA_Node* pInstMgrNode,
2858 CXFA_Node* pNewInstance,
2859 int32_t iPos,
2860 int32_t iCount = -1,
2861 FX_BOOL bMoveDataBindingNodes = TRUE) {
2862 if (iCount < 0) {
2863 iCount = XFA_ScriptInstanceManager_GetCount(pInstMgrNode);
2864 }
2865 if (iPos < 0) {
2866 iPos = iCount;
2867 }
2868 if (iPos == iCount) {
2869 CXFA_Node* pNextSibling =
2870 iCount > 0
2871 ? XFA_ScriptInstanceManager_GetItem(pInstMgrNode, iCount - 1)
2872 ->GetNodeItem(XFA_NODEITEM_NextSibling)
2873 : pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
2874 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)
2875 ->InsertChild(pNewInstance, pNextSibling);
2876 if (bMoveDataBindingNodes) {
2877 CXFA_NodeSet sNew;
2878 CXFA_NodeSet sAfter;
2879 CXFA_NodeIteratorTemplate<CXFA_Node,
2880 CXFA_TraverseStrategy_XFAContainerNode>
2881 sIteratorNew(pNewInstance);
2882 for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode;
2883 pNode = sIteratorNew.MoveToNext()) {
2884 CXFA_Node* pDataNode = pNode->GetBindData();
2885 if (!pDataNode) {
2886 continue;
2887 }
2888 sNew.insert(pDataNode);
2889 }
2890 CXFA_NodeIteratorTemplate<CXFA_Node,
2891 CXFA_TraverseStrategy_XFAContainerNode>
2892 sIteratorAfter(pNextSibling);
2893 for (CXFA_Node* pNode = sIteratorAfter.GetCurrent(); pNode;
2894 pNode = sIteratorAfter.MoveToNext()) {
2895 CXFA_Node* pDataNode = pNode->GetBindData();
2896 if (!pDataNode) {
2897 continue;
2898 }
2899 sAfter.insert(pDataNode);
2900 }
2901 XFA_ScriptInstanceManager_ReorderDataNodes(sNew, sAfter, FALSE);
2902 }
2903 } else {
2904 CXFA_Node* pBeforeInstance =
2905 XFA_ScriptInstanceManager_GetItem(pInstMgrNode, iPos);
2906 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)
2907 ->InsertChild(pNewInstance, pBeforeInstance);
2908 if (bMoveDataBindingNodes) {
2909 CXFA_NodeSet sNew;
2910 CXFA_NodeSet sBefore;
2911 CXFA_NodeIteratorTemplate<CXFA_Node,
2912 CXFA_TraverseStrategy_XFAContainerNode>
2913 sIteratorNew(pNewInstance);
2914 for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode;
2915 pNode = sIteratorNew.MoveToNext()) {
2916 CXFA_Node* pDataNode = pNode->GetBindData();
2917 if (!pDataNode) {
2918 continue;
2919 }
2920 sNew.insert(pDataNode);
2921 }
2922 CXFA_NodeIteratorTemplate<CXFA_Node,
2923 CXFA_TraverseStrategy_XFAContainerNode>
2924 sIteratorBefore(pBeforeInstance);
2925 for (CXFA_Node* pNode = sIteratorBefore.GetCurrent(); pNode;
2926 pNode = sIteratorBefore.MoveToNext()) {
2927 CXFA_Node* pDataNode = pNode->GetBindData();
2928 if (!pDataNode) {
2929 continue;
2930 }
2931 sBefore.insert(pDataNode);
2932 }
2933 XFA_ScriptInstanceManager_ReorderDataNodes(sNew, sBefore, TRUE);
2934 }
2935 }
2936 }
2937 static void XFA_ScriptInstanceManager_RemoveItem(
2938 CXFA_Node* pInstMgrNode,
2939 CXFA_Node* pRemoveInstance,
2940 FX_BOOL bRemoveDataBinding = TRUE) {
2941 pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)->RemoveChild(pRemoveInstance);
2942 if (!bRemoveDataBinding) {
2943 return;
2944 }
2945 CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFAContainerNode>
2946 sIterator(pRemoveInstance);
2947 for (CXFA_Node* pFormNode = sIterator.GetCurrent(); pFormNode;
2948 pFormNode = sIterator.MoveToNext()) {
2949 CXFA_Node* pDataNode = pFormNode->GetBindData();
2950 if (!pDataNode) {
2951 continue;
2952 }
2953 if (pDataNode->RemoveBindItem(pFormNode) == 0) {
2954 if (CXFA_Node* pDataParent =
2955 pDataNode->GetNodeItem(XFA_NODEITEM_Parent)) {
2956 pDataParent->RemoveChild(pDataNode);
2957 }
2958 }
2959 pFormNode->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
2960 }
2961 }
2962 static CXFA_Node* XFA_ScriptInstanceManager_CreateInstance(
2963 CXFA_Node* pInstMgrNode,
2964 FX_BOOL bDataMerge) {
2965 CXFA_Document* pDocument = pInstMgrNode->GetDocument();
2966 CXFA_Node* pTemplateNode = pInstMgrNode->GetTemplateNode();
2967 CXFA_Node* pFormParent = pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent);
2968 CXFA_Node* pDataScope = nullptr;
2969 for (CXFA_Node* pRootBoundNode = pFormParent;
2970 pRootBoundNode && pRootBoundNode->IsContainerNode();
2971 pRootBoundNode = pRootBoundNode->GetNodeItem(XFA_NODEITEM_Parent)) {
2972 pDataScope = pRootBoundNode->GetBindData();
2973 if (pDataScope) {
2974 break;
2975 }
2976 }
2977 if (!pDataScope) {
2978 pDataScope = ToNode(pDocument->GetXFAObject(XFA_HASHCODE_Record));
2979 ASSERT(pDataScope);
2980 }
2981 CXFA_Node* pInstance = pDocument->DataMerge_CopyContainer(
2982 pTemplateNode, pFormParent, pDataScope, TRUE, bDataMerge, TRUE);
2983 if (pInstance) {
2984 pDocument->DataMerge_UpdateBindingRelations(pInstance);
2985 pFormParent->RemoveChild(pInstance);
2986 }
2987 return pInstance;
2988 }
2989 void CXFA_Node::Script_InstanceManager_Count(CFXJSE_Value* pValue,
2990 FX_BOOL bSetting,
2991 XFA_ATTRIBUTE eAttribute) {
2992 if (bSetting) {
2993 int32_t iDesired = pValue->ToInteger();
2994 InstanceManager_SetInstances(iDesired);
2995 } else {
2996 pValue->SetInteger(XFA_ScriptInstanceManager_GetCount(this));
2997 }
2998 }
2999 void CXFA_Node::Script_InstanceManager_MoveInstance(
3000 CFXJSE_Arguments* pArguments) {
3001 int32_t argc = pArguments->GetLength();
3002 if (argc != 2) {
3003 pArguments->GetReturnValue()->SetUndefined();
3004 return;
3005 }
3006 int32_t iFrom = pArguments->GetInt32(0);
3007 int32_t iTo = pArguments->GetInt32(1);
3008 InstanceManager_MoveInstance(iTo, iFrom);
3009 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3010 if (!pNotify) {
3011 return;
3012 }
3013 CXFA_Node* pToInstance = XFA_ScriptInstanceManager_GetItem(this, iTo);
3014 if (pToInstance && pToInstance->GetElementType() == XFA_Element::Subform) {
3015 pNotify->RunSubformIndexChange(pToInstance);
3016 }
3017 CXFA_Node* pFromInstance = XFA_ScriptInstanceManager_GetItem(this, iFrom);
3018 if (pFromInstance &&
3019 pFromInstance->GetElementType() == XFA_Element::Subform) {
3020 pNotify->RunSubformIndexChange(pFromInstance);
3021 }
3022 }
3023 void CXFA_Node::Script_InstanceManager_RemoveInstance(
3024 CFXJSE_Arguments* pArguments) {
3025 int32_t argc = pArguments->GetLength();
3026 if (argc != 1) {
3027 pArguments->GetReturnValue()->SetUndefined();
3028 return;
3029 }
3030 int32_t iIndex = pArguments->GetInt32(0);
3031 int32_t iCount = XFA_ScriptInstanceManager_GetCount(this);
3032 if (iIndex < 0 || iIndex >= iCount) {
3033 ThrowException(XFA_IDS_INDEX_OUT_OF_BOUNDS);
3034 return;
3035 }
3036 CXFA_Occur nodeOccur(GetOccurNode());
3037 int32_t iMin = nodeOccur.GetMin();
3038 if (iCount - 1 < iMin) {
3039 ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"min");
3040 return;
3041 }
3042 CXFA_Node* pRemoveInstance = XFA_ScriptInstanceManager_GetItem(this, iIndex);
3043 XFA_ScriptInstanceManager_RemoveItem(this, pRemoveInstance);
3044 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3045 if (pNotify) {
3046 for (int32_t i = iIndex; i < iCount - 1; i++) {
3047 CXFA_Node* pSubformInstance = XFA_ScriptInstanceManager_GetItem(this, i);
3048 if (pSubformInstance &&
3049 pSubformInstance->GetElementType() == XFA_Element::Subform) {
3050 pNotify->RunSubformIndexChange(pSubformInstance);
3051 }
3052 }
3053 }
3054 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3055 if (!pLayoutPro) {
3056 return;
3057 }
3058 pLayoutPro->AddChangedContainer(
3059 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3060 }
3061 void CXFA_Node::Script_InstanceManager_SetInstances(
3062 CFXJSE_Arguments* pArguments) {
3063 int32_t argc = pArguments->GetLength();
3064 if (argc != 1) {
3065 pArguments->GetReturnValue()->SetUndefined();
3066 return;
3067 }
3068 int32_t iDesired = pArguments->GetInt32(0);
3069 InstanceManager_SetInstances(iDesired);
3070 }
3071 void CXFA_Node::Script_InstanceManager_AddInstance(
3072 CFXJSE_Arguments* pArguments) {
3073 int32_t argc = pArguments->GetLength();
3074 if ((argc != 0) && (argc != 1)) {
3075 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"addInstance");
3076 return;
3077 }
3078 FX_BOOL fFlags = TRUE;
3079 if (argc == 1) {
3080 fFlags = pArguments->GetInt32(0) == 0 ? FALSE : TRUE;
3081 }
3082 int32_t iCount = XFA_ScriptInstanceManager_GetCount(this);
3083 CXFA_Occur nodeOccur(GetOccurNode());
3084 int32_t iMax = nodeOccur.GetMax();
3085 if (iMax >= 0 && iCount >= iMax) {
3086 ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"max");
3087 return;
3088 }
3089 CXFA_Node* pNewInstance =
3090 XFA_ScriptInstanceManager_CreateInstance(this, fFlags);
3091 XFA_ScriptInstanceManager_InsertItem(this, pNewInstance, iCount, iCount,
3092 FALSE);
3093 pArguments->GetReturnValue()->Assign(
3094 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
3095 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3096 if (!pNotify) {
3097 return;
3098 }
3099 pNotify->RunNodeInitialize(pNewInstance);
3100 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3101 if (!pLayoutPro) {
3102 return;
3103 }
3104 pLayoutPro->AddChangedContainer(
3105 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3106 }
3107 void CXFA_Node::Script_InstanceManager_InsertInstance(
3108 CFXJSE_Arguments* pArguments) {
3109 int32_t argc = pArguments->GetLength();
3110 if ((argc != 1) && (argc != 2)) {
3111 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"insertInstance");
3112 return;
3113 }
3114 int32_t iIndex = pArguments->GetInt32(0);
3115 FX_BOOL bBind = FALSE;
3116 if (argc == 2) {
3117 bBind = pArguments->GetInt32(1) == 0 ? FALSE : TRUE;
3118 }
3119 CXFA_Occur nodeOccur(GetOccurNode());
3120 int32_t iCount = XFA_ScriptInstanceManager_GetCount(this);
3121 if (iIndex < 0 || iIndex > iCount) {
3122 ThrowException(XFA_IDS_INDEX_OUT_OF_BOUNDS);
3123 return;
3124 }
3125 int32_t iMax = nodeOccur.GetMax();
3126 if (iMax >= 0 && iCount >= iMax) {
3127 ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"max");
3128 return;
3129 }
3130 CXFA_Node* pNewInstance =
3131 XFA_ScriptInstanceManager_CreateInstance(this, bBind);
3132 XFA_ScriptInstanceManager_InsertItem(this, pNewInstance, iIndex, iCount,
3133 TRUE);
3134 pArguments->GetReturnValue()->Assign(
3135 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance));
3136 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3137 if (!pNotify) {
3138 return;
3139 }
3140 pNotify->RunNodeInitialize(pNewInstance);
3141 CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
3142 if (!pLayoutPro) {
3143 return;
3144 }
3145 pLayoutPro->AddChangedContainer(
3146 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)));
3147 }
3148 int32_t CXFA_Node::InstanceManager_SetInstances(int32_t iDesired) {
3149 CXFA_Occur nodeOccur(GetOccurNode());
3150 int32_t iMax = nodeOccur.GetMax();
3151 int32_t iMin = nodeOccur.GetMin();
3152 if (iDesired < iMin) {
3153 ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"min");
3154 return 1;
3155 }
3156 if ((iMax >= 0) && (iDesired > iMax)) {
3157 ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"max");
3158 return 2;
3159 }
3160 int32_t iCount = XFA_ScriptInstanceManager_GetCount(this);
3161 if (iDesired == iCount) {
3162 return 0;
3163 }
3164 if (iDesired < iCount) {
3165 CFX_WideStringC wsInstManagerName = GetCData(XFA_ATTRIBUTE_Name);
3166 CFX_WideString wsInstanceName =
3167 CFX_WideString(wsInstManagerName.IsEmpty() ? wsInstManagerName
3168 : wsInstManagerName.Mid(1));
3169 uint32_t dInstanceNameHash =
3170 FX_HashCode_GetW(wsInstanceName.AsStringC(), false);
3171 CXFA_Node* pPrevSibling =
3172 (iDesired == 0) ? this
3173 : XFA_ScriptInstanceManager_GetItem(this, iDesired - 1);
3174 while (iCount > iDesired) {
3175 CXFA_Node* pRemoveInstance =
3176 pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling);
3177 if (pRemoveInstance->GetElementType() != XFA_Element::Subform &&
3178 pRemoveInstance->GetElementType() != XFA_Element::SubformSet) {
3179 continue;
3180 }
3181 if (pRemoveInstance->GetElementType() == XFA_Element::InstanceManager) {
3182 ASSERT(FALSE);
3183 break;
3184 }
3185 if (pRemoveInstance->GetNameHash() == dInstanceNameHash) {
3186 XFA_ScriptInstanceManager_RemoveItem(this, pRemoveInstance);
3187 iCount--;
3188 }
3189 }
3190 } else if (iDesired > iCount) {
3191 while (iCount < iDesired) {
3192 CXFA_Node* pNewInstance =
3193 XFA_ScriptInstanceManager_CreateInstance(this, TRUE);
3194 XFA_ScriptInstanceManager_InsertItem(this, pNewInstance, iCount, iCount,
3195 FALSE);
3196 iCount++;
3197 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3198 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 }
3211 int32_t CXFA_Node::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) {
3212 int32_t iCount = XFA_ScriptInstanceManager_GetCount(this);
3213 if (iFrom > iCount || iTo > iCount - 1) {
3214 ThrowException(XFA_IDS_INDEX_OUT_OF_BOUNDS);
3215 return 1;
3216 }
3217 if (iFrom < 0 || iTo < 0 || iFrom == iTo) {
3218 return 0;
3219 }
3220 CXFA_Node* pMoveInstance = XFA_ScriptInstanceManager_GetItem(this, iFrom);
3221 XFA_ScriptInstanceManager_RemoveItem(this, pMoveInstance, FALSE);
3222 XFA_ScriptInstanceManager_InsertItem(this, pMoveInstance, iTo, iCount - 1,
3223 TRUE);
3224 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 }
3231 void CXFA_Node::Script_Occur_Max(CFXJSE_Value* pValue,
3232 FX_BOOL bSetting,
3233 XFA_ATTRIBUTE eAttribute) {
3234 CXFA_Occur occur(this);
3235 if (bSetting) {
3236 int32_t iMax = pValue->ToInteger();
3237 occur.SetMax(iMax);
3238 } else {
3239 pValue->SetInteger(occur.GetMax());
3240 }
3241 }
3242 void CXFA_Node::Script_Occur_Min(CFXJSE_Value* pValue,
3243 FX_BOOL bSetting,
3244 XFA_ATTRIBUTE eAttribute) {
3245 CXFA_Occur occur(this);
3246 if (bSetting) {
3247 int32_t iMin = pValue->ToInteger();
3248 occur.SetMin(iMin);
3249 } else {
3250 pValue->SetInteger(occur.GetMin());
3251 }
3252 }
3253 void CXFA_Node::Script_Desc_Metadata(CFXJSE_Arguments* pArguments) {
3254 int32_t argc = pArguments->GetLength();
3255 if ((argc == 0) || (argc == 1)) {
3256 pArguments->GetReturnValue()->SetString("");
3257 } else {
3258 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"metadata");
3259 }
3260 }
3261 void CXFA_Node::Script_Form_FormNodes(CFXJSE_Arguments* pArguments) {
3262 int32_t argc = pArguments->GetLength();
3263 if (argc == 1) {
3264 CXFA_Node* pDataNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
3265 if (pDataNode) {
3266 CXFA_NodeArray formItems;
3267 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
3268 pFormNodes->SetArrayNodeList(formItems);
3269 pArguments->GetReturnValue()->SetObject(
3270 pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
3271 } else {
3272 ThrowException(XFA_IDS_ARGUMENT_MISMATCH);
3273 }
3274 } else {
3275 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"formNodes");
3276 }
3277 }
3278 void CXFA_Node::Script_Form_Remerge(CFXJSE_Arguments* pArguments) {
3279 int32_t argc = pArguments->GetLength();
3280 if (argc == 0) {
3281 m_pDocument->DoDataRemerge(TRUE);
3282 } else {
3283 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"remerge");
3284 }
3285 }
3286 void CXFA_Node::Script_Form_ExecInitialize(CFXJSE_Arguments* pArguments) {
3287 int32_t argc = pArguments->GetLength();
3288 if (argc == 0) {
3289 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3290 if (!pNotify) {
3291 return;
3292 }
3293 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
3294 } else {
3295 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");
3296 }
3297 }
3298 void CXFA_Node::Script_Form_Recalculate(CFXJSE_Arguments* pArguments) {
3299 CXFA_EventParam* pEventParam =
3300 m_pDocument->GetScriptContext()->GetEventParam();
3301 if (pEventParam->m_eType == XFA_EVENT_Calculate ||
3302 pEventParam->m_eType == XFA_EVENT_InitCalculate) {
3303 return;
3304 }
3305 int32_t argc = pArguments->GetLength();
3306 if (argc == 1) {
3307 const bool bScriptFlags = pArguments->GetInt32(0) != 0;
3308 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3309 if (!pNotify) {
3310 return;
3311 }
3312 if (bScriptFlags) {
3313 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
3314 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
3315 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Ready, TRUE);
3316 } else {
3317 }
3318 } else {
3319 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"recalculate");
3320 }
3321 }
3322 void CXFA_Node::Script_Form_ExecCalculate(CFXJSE_Arguments* pArguments) {
3323 int32_t argc = pArguments->GetLength();
3324 if (argc == 0) {
3325 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3326 if (!pNotify) {
3327 return;
3328 }
3329 pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
3330 } else {
3331 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");
3332 }
3333 }
3334 void CXFA_Node::Script_Form_ExecValidate(CFXJSE_Arguments* pArguments) {
3335 int32_t argc = pArguments->GetLength();
3336 if (argc == 0) {
3337 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
3338 if (!pNotify) {
3339 pArguments->GetReturnValue()->SetBoolean(FALSE);
3340 } else {
3341 int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
3342 pArguments->GetReturnValue()->SetBoolean(
3343 (iRet == XFA_EVENTERROR_Error) ? FALSE : TRUE);
3344 }
3345 } else {
3346 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");
3347 }
3348 }
3349 void CXFA_Node::Script_Form_Checksum(CFXJSE_Value* pValue,
3350 FX_BOOL bSetting,
3351 XFA_ATTRIBUTE eAttribute) {
3352 if (bSetting) {
3353 SetAttribute(XFA_ATTRIBUTE_Checksum, pValue->ToWideString().AsStringC());
3354 } else {
3355 CFX_WideString wsChecksum;
3356 GetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum, FALSE);
3357 pValue->SetString(
3358 FX_UTF8Encode(wsChecksum.c_str(), wsChecksum.GetLength()).AsStringC());
3359 }
3360 }
3361 void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) {
3362 int32_t argc = pArguments->GetLength();
3363 if (argc == 1) {
3364 CFX_ByteString bsAttributeName = pArguments->GetUTF8String(0);
3365 CFX_WideString wsAttributeValue;
3366 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3367 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3368 static_cast<CFDE_XMLElement*>(pXMLNode)->GetString(
3369 CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str(),
3370 wsAttributeValue);
3371 }
3372 pArguments->GetReturnValue()->SetString(
3373 FX_UTF8Encode(wsAttributeValue.c_str(), wsAttributeValue.GetLength())
3374 .AsStringC());
3375 } else {
3376 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getAttribute");
3377 }
3378 }
3379 void CXFA_Node::Script_Packet_SetAttribute(CFXJSE_Arguments* pArguments) {
3380 int32_t argc = pArguments->GetLength();
3381 if (argc == 2) {
3382 CFX_ByteString bsValue = pArguments->GetUTF8String(0);
3383 CFX_ByteString bsName = pArguments->GetUTF8String(1);
3384 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3385 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3386 static_cast<CFDE_XMLElement*>(pXMLNode)
3387 ->SetString(CFX_WideString::FromUTF8(bsName.AsStringC()),
3388 CFX_WideString::FromUTF8(bsValue.AsStringC()));
3389 }
3390 pArguments->GetReturnValue()->SetNull();
3391 } else {
3392 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setAttribute");
3393 }
3394 }
3395 void CXFA_Node::Script_Packet_RemoveAttribute(CFXJSE_Arguments* pArguments) {
3396 int32_t argc = pArguments->GetLength();
3397 if (argc == 1) {
3398 CFX_ByteString bsName = pArguments->GetUTF8String(0);
3399 CFX_WideString wsName = CFX_WideString::FromUTF8(bsName.AsStringC());
3400 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3401 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3402 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
3403 if (pXMLElement->HasAttribute(wsName.c_str())) {
3404 pXMLElement->RemoveAttribute(wsName.c_str());
3405 }
3406 }
3407 pArguments->GetReturnValue()->SetNull();
3408 } else {
3409 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"removeAttribute");
3410 }
3411 }
3412 void CXFA_Node::Script_Packet_Content(CFXJSE_Value* pValue,
3413 FX_BOOL bSetting,
3414 XFA_ATTRIBUTE eAttribute) {
3415 if (bSetting) {
3416 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3417 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3418 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
3419 pXMLElement->SetTextData(pValue->ToWideString());
3420 }
3421 } else {
3422 CFX_WideString wsTextData;
3423 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
3424 if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) {
3425 CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode);
3426 pXMLElement->GetTextData(wsTextData);
3427 }
3428 pValue->SetString(
3429 FX_UTF8Encode(wsTextData.c_str(), wsTextData.GetLength()).AsStringC());
3430 }
3431 }
3432 void CXFA_Node::Script_Source_Next(CFXJSE_Arguments* pArguments) {
3433 int32_t argc = pArguments->GetLength();
3434 if (argc == 0) {
3435 } else {
3436 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"next");
3437 }
3438 }
3439 void CXFA_Node::Script_Source_CancelBatch(CFXJSE_Arguments* pArguments) {
3440 int32_t argc = pArguments->GetLength();
3441 if (argc == 0) {
3442 } else {
3443 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"cancelBatch");
3444 }
3445 }
3446 void CXFA_Node::Script_Source_First(CFXJSE_Arguments* pArguments) {
3447 int32_t argc = pArguments->GetLength();
3448 if (argc == 0) {
3449 } else {
3450 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"first");
3451 }
3452 }
3453 void CXFA_Node::Script_Source_UpdateBatch(CFXJSE_Arguments* pArguments) {
3454 int32_t argc = pArguments->GetLength();
3455 if (argc == 0) {
3456 } else {
3457 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"updateBatch");
3458 }
3459 }
3460 void CXFA_Node::Script_Source_Previous(CFXJSE_Arguments* pArguments) {
3461 int32_t argc = pArguments->GetLength();
3462 if (argc == 0) {
3463 } else {
3464 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"previous");
3465 }
3466 }
3467 void CXFA_Node::Script_Source_IsBOF(CFXJSE_Arguments* pArguments) {
3468 int32_t argc = pArguments->GetLength();
3469 if (argc == 0) {
3470 } else {
3471 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isBOF");
3472 }
3473 }
3474 void CXFA_Node::Script_Source_IsEOF(CFXJSE_Arguments* pArguments) {
3475 int32_t argc = pArguments->GetLength();
3476 if (argc == 0) {
3477 } else {
3478 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isEOF");
3479 }
3480 }
3481 void CXFA_Node::Script_Source_Cancel(CFXJSE_Arguments* pArguments) {
3482 int32_t argc = pArguments->GetLength();
3483 if (argc == 0) {
3484 } else {
3485 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"cancel");
3486 }
3487 }
3488 void CXFA_Node::Script_Source_Update(CFXJSE_Arguments* pArguments) {
3489 int32_t argc = pArguments->GetLength();
3490 if (argc == 0) {
3491 } else {
3492 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"update");
3493 }
3494 }
3495 void CXFA_Node::Script_Source_Open(CFXJSE_Arguments* pArguments) {
3496 int32_t argc = pArguments->GetLength();
3497 if (argc == 0) {
3498 } else {
3499 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"open");
3500 }
3501 }
3502 void CXFA_Node::Script_Source_Delete(CFXJSE_Arguments* pArguments) {
3503 int32_t argc = pArguments->GetLength();
3504 if (argc == 0) {
3505 } else {
3506 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"delete");
3507 }
3508 }
3509 void CXFA_Node::Script_Source_AddNew(CFXJSE_Arguments* pArguments) {
3510 int32_t argc = pArguments->GetLength();
3511 if (argc == 0) {
3512 } else {
3513 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"addNew");
3514 }
3515 }
3516 void CXFA_Node::Script_Source_Requery(CFXJSE_Arguments* pArguments) {
3517 int32_t argc = pArguments->GetLength();
3518 if (argc == 0) {
3519 } else {
3520 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"requery");
3521 }
3522 }
3523 void CXFA_Node::Script_Source_Resync(CFXJSE_Arguments* pArguments) {
3524 int32_t argc = pArguments->GetLength();
3525 if (argc == 0) {
3526 } else {
3527 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resync");
3528 }
3529 }
3530 void CXFA_Node::Script_Source_Close(CFXJSE_Arguments* pArguments) {
3531 int32_t argc = pArguments->GetLength();
3532 if (argc == 0) {
3533 } else {
3534 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"close");
3535 }
3536 }
3537 void CXFA_Node::Script_Source_Last(CFXJSE_Arguments* pArguments) {
3538 int32_t argc = pArguments->GetLength();
3539 if (argc == 0) {
3540 } else {
3541 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"last");
3542 }
3543 }
3544 void CXFA_Node::Script_Source_HasDataChanged(CFXJSE_Arguments* pArguments) {
3545 int32_t argc = pArguments->GetLength();
3546 if (argc == 0) {
3547 } else {
3548 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"hasDataChanged");
3549 }
3550 }
3551 void CXFA_Node::Script_Source_Db(CFXJSE_Value* pValue,
3552 FX_BOOL bSetting,
3553 XFA_ATTRIBUTE eAttribute) {}
3554 void CXFA_Node::Script_Xfa_This(CFXJSE_Value* pValue,
3555 FX_BOOL bSetting,
3556 XFA_ATTRIBUTE eAttribute) {
3557 if (!bSetting) {
3558 CXFA_Object* pThis = m_pDocument->GetScriptContext()->GetThisObject();
3559 ASSERT(pThis);
3560 pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pThis));
3561 }
3562 }
3563 void CXFA_Node::Script_Handler_Version(CFXJSE_Value* pValue,
3564 FX_BOOL bSetting,
3565 XFA_ATTRIBUTE eAttribute) {}
3566 void CXFA_Node::Script_SubmitFormat_Mode(CFXJSE_Value* pValue,
3567 FX_BOOL bSetting,
3568 XFA_ATTRIBUTE eAttribute) {}
3569 void CXFA_Node::Script_Extras_Type(CFXJSE_Value* pValue,
3570 FX_BOOL bSetting,
3571 XFA_ATTRIBUTE eAttribute) {}
3572 void CXFA_Node::Script_Script_Stateless(CFXJSE_Value* pValue,
3573 FX_BOOL bSetting,
3574 XFA_ATTRIBUTE eAttribute) {
3575 if (bSetting) {
3576 ThrowException(XFA_IDS_INVAlID_PROP_SET);
3577 return;
3578 }
3579 pValue->SetString(FX_UTF8Encode(FX_WSTRC(L"0")).AsStringC());
3580 }
3581 void CXFA_Node::Script_Encrypt_Format(CFXJSE_Value* pValue,
3582 FX_BOOL bSetting,
3583 XFA_ATTRIBUTE eAttribute) {}
3584 enum XFA_KEYTYPE {
3585 XFA_KEYTYPE_Custom,
3586 XFA_KEYTYPE_Element,
3587 };
3588 void* XFA_GetMapKey_Custom(const CFX_WideStringC& wsKey) {
3589 uint32_t dwKey = FX_HashCode_GetW(wsKey, false);
3590 return (void*)(uintptr_t)((dwKey << 1) | XFA_KEYTYPE_Custom);
3591 }
3592 void* XFA_GetMapKey_Element(XFA_Element eType, XFA_ATTRIBUTE eAttribute) {
3593 return (void*)(uintptr_t)((static_cast<int32_t>(eType) << 16) |
3594 (eAttribute << 8) | XFA_KEYTYPE_Element);
3595 }
3596 FX_BOOL CXFA_Node::HasAttribute(XFA_ATTRIBUTE eAttr, FX_BOOL bCanInherit) {
3597 void* pKey = XFA_GetMapKey_Element(GetElementType(), eAttr);
3598 return HasMapModuleKey(pKey, bCanInherit);
3599 }
3600 FX_BOOL CXFA_Node::SetAttribute(XFA_ATTRIBUTE eAttr,
3601 const CFX_WideStringC& wsValue,
3602 bool bNotify) {
3603 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
3604 if (!pAttr)
3605 return FALSE;
3606
3607 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3608 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3609 const XFA_NOTSUREATTRIBUTE* pNotsure =
3610 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
3611 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3612 }
3613 switch (eType) {
3614 case XFA_ATTRIBUTETYPE_Enum: {
3615 const XFA_ATTRIBUTEENUMINFO* pEnum = XFA_GetAttributeEnumByName(wsValue);
3616 return SetEnum(pAttr->eName,
3617 pEnum ? pEnum->eName
3618 : (XFA_ATTRIBUTEENUM)(intptr_t)(pAttr->pDefValue),
3619 bNotify);
3620 } break;
3621 case XFA_ATTRIBUTETYPE_Cdata:
3622 return SetCData(pAttr->eName, CFX_WideString(wsValue), bNotify);
3623 case XFA_ATTRIBUTETYPE_Boolean:
3624 return SetBoolean(pAttr->eName, wsValue != FX_WSTRC(L"0"), bNotify);
3625 case XFA_ATTRIBUTETYPE_Integer:
3626 return SetInteger(
3627 pAttr->eName,
3628 FXSYS_round(FX_wcstof(wsValue.c_str(), wsValue.GetLength(), nullptr)),
3629 bNotify);
3630 case XFA_ATTRIBUTETYPE_Measure:
3631 return SetMeasure(pAttr->eName, CXFA_Measurement(wsValue), bNotify);
3632 default:
3633 break;
3634 }
3635 return FALSE;
3636 }
3637 FX_BOOL CXFA_Node::GetAttribute(XFA_ATTRIBUTE eAttr,
3638 CFX_WideString& wsValue,
3639 FX_BOOL bUseDefault) {
3640 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
3641 if (!pAttr) {
3642 return FALSE;
3643 }
3644 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3645 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3646 const XFA_NOTSUREATTRIBUTE* pNotsure =
3647 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName);
3648 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3649 }
3650 switch (eType) {
3651 case XFA_ATTRIBUTETYPE_Enum: {
3652 XFA_ATTRIBUTEENUM eValue;
3653 if (!TryEnum(pAttr->eName, eValue, bUseDefault)) {
3654 return FALSE;
3655 }
3656 wsValue = XFA_GetAttributeEnumByID(eValue)->pName;
3657 return TRUE;
3658 } break;
3659 case XFA_ATTRIBUTETYPE_Cdata: {
3660 CFX_WideStringC wsValueC;
3661 if (!TryCData(pAttr->eName, wsValueC, bUseDefault)) {
3662 return FALSE;
3663 }
3664 wsValue = wsValueC;
3665 return TRUE;
3666 } break;
3667 case XFA_ATTRIBUTETYPE_Boolean: {
3668 FX_BOOL bValue;
3669 if (!TryBoolean(pAttr->eName, bValue, bUseDefault)) {
3670 return FALSE;
3671 }
3672 wsValue = bValue ? FX_WSTRC(L"1") : FX_WSTRC(L"0");
3673 return TRUE;
3674 } break;
3675 case XFA_ATTRIBUTETYPE_Integer: {
3676 int32_t iValue;
3677 if (!TryInteger(pAttr->eName, iValue, bUseDefault)) {
3678 return FALSE;
3679 }
3680 wsValue.Format(L"%d", iValue);
3681 return TRUE;
3682 } break;
3683 case XFA_ATTRIBUTETYPE_Measure: {
3684 CXFA_Measurement mValue;
3685 if (!TryMeasure(pAttr->eName, mValue, bUseDefault)) {
3686 return FALSE;
3687 }
3688 mValue.ToString(wsValue);
3689 return TRUE;
3690 } break;
3691 default:
3692 break;
3693 }
3694 return FALSE;
3695 }
3696 FX_BOOL CXFA_Node::SetAttribute(const CFX_WideStringC& wsAttr,
3697 const CFX_WideStringC& wsValue,
3698 bool bNotify) {
3699 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsValue);
3700 if (pAttributeInfo) {
3701 return SetAttribute(pAttributeInfo->eName, wsValue, bNotify);
3702 }
3703 void* pKey = XFA_GetMapKey_Custom(wsAttr);
3704 SetMapModuleString(pKey, wsValue);
3705 return TRUE;
3706 }
3707 FX_BOOL CXFA_Node::GetAttribute(const CFX_WideStringC& wsAttr,
3708 CFX_WideString& wsValue,
3709 FX_BOOL bUseDefault) {
3710 const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsAttr);
3711 if (pAttributeInfo) {
3712 return GetAttribute(pAttributeInfo->eName, wsValue, bUseDefault);
3713 }
3714 void* pKey = XFA_GetMapKey_Custom(wsAttr);
3715 CFX_WideStringC wsValueC;
3716 if (GetMapModuleString(pKey, wsValueC)) {
3717 wsValue = wsValueC;
3718 }
3719 return TRUE;
3720 }
3721 FX_BOOL CXFA_Node::RemoveAttribute(const CFX_WideStringC& wsAttr) {
3722 void* pKey = XFA_GetMapKey_Custom(wsAttr);
3723 RemoveMapModuleKey(pKey);
3724 return TRUE;
3725 }
3726 FX_BOOL CXFA_Node::TryBoolean(XFA_ATTRIBUTE eAttr,
3727 FX_BOOL& bValue,
3728 FX_BOOL bUseDefault) {
3729 void* pValue = nullptr;
3730 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Boolean, bUseDefault, pValue))
3731 return FALSE;
3732 bValue = (FX_BOOL)(uintptr_t)pValue;
3733 return TRUE;
3734 }
3735 FX_BOOL CXFA_Node::TryInteger(XFA_ATTRIBUTE eAttr,
3736 int32_t& iValue,
3737 FX_BOOL bUseDefault) {
3738 void* pValue = nullptr;
3739 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Integer, bUseDefault, pValue))
3740 return FALSE;
3741 iValue = (int32_t)(uintptr_t)pValue;
3742 return TRUE;
3743 }
3744 FX_BOOL CXFA_Node::TryEnum(XFA_ATTRIBUTE eAttr,
3745 XFA_ATTRIBUTEENUM& eValue,
3746 FX_BOOL bUseDefault) {
3747 void* pValue = nullptr;
3748 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Enum, bUseDefault, pValue))
3749 return FALSE;
3750 eValue = (XFA_ATTRIBUTEENUM)(uintptr_t)pValue;
3751 return TRUE;
3752 }
3753
3754 FX_BOOL CXFA_Node::SetMeasure(XFA_ATTRIBUTE eAttr,
3755 CXFA_Measurement mValue,
3756 bool bNotify) {
3757 void* pKey = XFA_GetMapKey_Element(GetElementType(), eAttr);
3758 OnChanging(eAttr, bNotify);
3759 SetMapModuleBuffer(pKey, &mValue, sizeof(CXFA_Measurement));
3760 OnChanged(eAttr, bNotify, FALSE);
3761 return TRUE;
3762 }
3763
3764 FX_BOOL CXFA_Node::TryMeasure(XFA_ATTRIBUTE eAttr,
3765 CXFA_Measurement& mValue,
3766 FX_BOOL bUseDefault) const {
3767 void* pKey = XFA_GetMapKey_Element(GetElementType(), eAttr);
3768 void* pValue;
3769 int32_t iBytes;
3770 if (GetMapModuleBuffer(pKey, pValue, iBytes) && iBytes == sizeof(mValue)) {
3771 FXSYS_memcpy(&mValue, pValue, sizeof(mValue));
3772 return TRUE;
3773 }
3774 if (bUseDefault &&
3775 XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
3776 XFA_ATTRIBUTETYPE_Measure, m_ePacket)) {
3777 FXSYS_memcpy(&mValue, pValue, sizeof(mValue));
3778 return TRUE;
3779 }
3780 return FALSE;
3781 }
3782
3783 CXFA_Measurement CXFA_Node::GetMeasure(XFA_ATTRIBUTE eAttr) const {
3784 CXFA_Measurement mValue;
3785 return TryMeasure(eAttr, mValue, TRUE) ? mValue : CXFA_Measurement();
3786 }
3787
3788 FX_BOOL CXFA_Node::SetCData(XFA_ATTRIBUTE eAttr,
3789 const CFX_WideString& wsValue,
3790 bool bNotify,
3791 FX_BOOL bScriptModify) {
3792 void* pKey = XFA_GetMapKey_Element(GetElementType(), eAttr);
3793 OnChanging(eAttr, bNotify);
3794 if (eAttr == XFA_ATTRIBUTE_Value) {
3795 CFX_WideString* pClone = new CFX_WideString(wsValue);
3796 SetUserData(pKey, pClone, &deleteWideStringCallBack);
3797 } else {
3798 SetMapModuleString(pKey, wsValue.AsStringC());
3799 if (eAttr == XFA_ATTRIBUTE_Name)
3800 UpdateNameHash();
3801 }
3802 OnChanged(eAttr, bNotify, bScriptModify);
3803
3804 if (!IsNeedSavingXMLNode() || eAttr == XFA_ATTRIBUTE_QualifiedName ||
3805 eAttr == XFA_ATTRIBUTE_BindingNode) {
3806 return TRUE;
3807 }
3808
3809 if (eAttr == XFA_ATTRIBUTE_Name &&
3810 (m_elementType == XFA_Element::DataValue ||
3811 m_elementType == XFA_Element::DataGroup)) {
3812 return TRUE;
3813 }
3814
3815 if (eAttr == XFA_ATTRIBUTE_Value) {
3816 FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
3817 switch (eXMLType) {
3818 case FDE_XMLNODE_Element:
3819 if (IsAttributeInXML()) {
3820 static_cast<CFDE_XMLElement*>(m_pXMLNode)
3821 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3822 wsValue);
3823 } else {
3824 FX_BOOL bDeleteChildren = TRUE;
3825 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3826 for (CXFA_Node* pChildDataNode =
3827 GetNodeItem(XFA_NODEITEM_FirstChild);
3828 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3829 XFA_NODEITEM_NextSibling)) {
3830 CXFA_NodeArray formNodes;
3831 if (pChildDataNode->GetBindItems(formNodes) > 0) {
3832 bDeleteChildren = FALSE;
3833 break;
3834 }
3835 }
3836 }
3837 if (bDeleteChildren) {
3838 static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren();
3839 }
3840 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsValue);
3841 }
3842 break;
3843 case FDE_XMLNODE_Text:
3844 static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsValue);
3845 break;
3846 default:
3847 ASSERT(0);
3848 }
3849 return TRUE;
3850 }
3851
3852 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
3853 if (pInfo) {
3854 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element);
3855 CFX_WideString wsAttrName = pInfo->pName;
3856 if (pInfo->eName == XFA_ATTRIBUTE_ContentType) {
3857 wsAttrName = FX_WSTRC(L"xfa:") + wsAttrName;
3858 }
3859 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetString(wsAttrName, wsValue);
3860 }
3861 return TRUE;
3862 }
3863
3864 FX_BOOL CXFA_Node::SetAttributeValue(const CFX_WideString& wsValue,
3865 const CFX_WideString& wsXMLValue,
3866 bool bNotify,
3867 FX_BOOL bScriptModify) {
3868 void* pKey = XFA_GetMapKey_Element(GetElementType(), XFA_ATTRIBUTE_Value);
3869 OnChanging(XFA_ATTRIBUTE_Value, bNotify);
3870 CFX_WideString* pClone = new CFX_WideString(wsValue);
3871 SetUserData(pKey, pClone, &deleteWideStringCallBack);
3872 OnChanged(XFA_ATTRIBUTE_Value, bNotify, bScriptModify);
3873 if (IsNeedSavingXMLNode()) {
3874 FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType();
3875 switch (eXMLType) {
3876 case FDE_XMLNODE_Element:
3877 if (IsAttributeInXML()) {
3878 static_cast<CFDE_XMLElement*>(m_pXMLNode)
3879 ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)),
3880 wsXMLValue);
3881 } else {
3882 FX_BOOL bDeleteChildren = TRUE;
3883 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
3884 for (CXFA_Node* pChildDataNode =
3885 GetNodeItem(XFA_NODEITEM_FirstChild);
3886 pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem(
3887 XFA_NODEITEM_NextSibling)) {
3888 CXFA_NodeArray formNodes;
3889 if (pChildDataNode->GetBindItems(formNodes) > 0) {
3890 bDeleteChildren = FALSE;
3891 break;
3892 }
3893 }
3894 }
3895 if (bDeleteChildren) {
3896 static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren();
3897 }
3898 static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsXMLValue);
3899 }
3900 break;
3901 case FDE_XMLNODE_Text:
3902 static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsXMLValue);
3903 break;
3904 default:
3905 ASSERT(0);
3906 }
3907 }
3908 return TRUE;
3909 }
3910 FX_BOOL CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3911 CFX_WideString& wsValue,
3912 FX_BOOL bUseDefault,
3913 FX_BOOL bProto) {
3914 void* pKey = XFA_GetMapKey_Element(GetElementType(), eAttr);
3915 if (eAttr == XFA_ATTRIBUTE_Value) {
3916 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
3917 if (pStr) {
3918 wsValue = *pStr;
3919 return TRUE;
3920 }
3921 } else {
3922 CFX_WideStringC wsValueC;
3923 if (GetMapModuleString(pKey, wsValueC)) {
3924 wsValue = wsValueC;
3925 return TRUE;
3926 }
3927 }
3928 if (!bUseDefault) {
3929 return FALSE;
3930 }
3931 void* pValue = nullptr;
3932 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
3933 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
3934 wsValue = (const FX_WCHAR*)pValue;
3935 return TRUE;
3936 }
3937 return FALSE;
3938 }
3939 FX_BOOL CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
3940 CFX_WideStringC& wsValue,
3941 FX_BOOL bUseDefault,
3942 FX_BOOL bProto) {
3943 void* pKey = XFA_GetMapKey_Element(GetElementType(), eAttr);
3944 if (eAttr == XFA_ATTRIBUTE_Value) {
3945 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
3946 if (pStr) {
3947 wsValue = pStr->AsStringC();
3948 return TRUE;
3949 }
3950 } else {
3951 if (GetMapModuleString(pKey, wsValue)) {
3952 return TRUE;
3953 }
3954 }
3955 if (!bUseDefault) {
3956 return FALSE;
3957 }
3958 void* pValue = nullptr;
3959 if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr,
3960 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
3961 wsValue = (CFX_WideStringC)(const FX_WCHAR*)pValue;
3962 return TRUE;
3963 }
3964 return FALSE;
3965 }
3966 FX_BOOL CXFA_Node::SetObject(XFA_ATTRIBUTE eAttr,
3967 void* pData,
3968 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
3969 void* pKey = XFA_GetMapKey_Element(GetElementType(), eAttr);
3970 return SetUserData(pKey, pData, pCallbackInfo);
3971 }
3972 FX_BOOL CXFA_Node::TryObject(XFA_ATTRIBUTE eAttr, void*& pData) {
3973 void* pKey = XFA_GetMapKey_Element(GetElementType(), eAttr);
3974 pData = GetUserData(pKey);
3975 return !!pData;
3976 }
3977 FX_BOOL CXFA_Node::SetValue(XFA_ATTRIBUTE eAttr,
3978 XFA_ATTRIBUTETYPE eType,
3979 void* pValue,
3980 bool bNotify) {
3981 void* pKey = XFA_GetMapKey_Element(GetElementType(), eAttr);
3982 OnChanging(eAttr, bNotify);
3983 SetMapModuleValue(pKey, pValue);
3984 OnChanged(eAttr, bNotify, FALSE);
3985 if (IsNeedSavingXMLNode()) {
3986 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element);
3987 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr);
3988 if (pInfo) {
3989 switch (eType) {
3990 case XFA_ATTRIBUTETYPE_Enum:
3991 static_cast<CFDE_XMLElement*>(m_pXMLNode)
3992 ->SetString(
3993 pInfo->pName,
3994 XFA_GetAttributeEnumByID((XFA_ATTRIBUTEENUM)(uintptr_t)pValue)
3995 ->pName);
3996 break;
3997 case XFA_ATTRIBUTETYPE_Boolean:
3998 static_cast<CFDE_XMLElement*>(m_pXMLNode)
3999 ->SetString(pInfo->pName, pValue ? L"1" : L"0");
4000 break;
4001 case XFA_ATTRIBUTETYPE_Integer:
4002 static_cast<CFDE_XMLElement*>(m_pXMLNode)
4003 ->SetInteger(pInfo->pName, (int32_t)(uintptr_t)pValue);
4004 break;
4005 default:
4006 ASSERT(0);
4007 }
4008 }
4009 }
4010 return TRUE;
4011 }
4012 FX_BOOL CXFA_Node::GetValue(XFA_ATTRIBUTE eAttr,
4013 XFA_ATTRIBUTETYPE eType,
4014 FX_BOOL bUseDefault,
4015 void*& pValue) {
4016 void* pKey = XFA_GetMapKey_Element(GetElementType(), eAttr);
4017 if (GetMapModuleValue(pKey, pValue)) {
4018 return TRUE;
4019 }
4020 if (!bUseDefault) {
4021 return FALSE;
4022 }
4023 return XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, eType,
4024 m_ePacket);
4025 }
4026 static void XFA_DefaultFreeData(void* pData) {}
4027 static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADefaultFreeData = {
4028 XFA_DefaultFreeData, nullptr};
4029 FX_BOOL CXFA_Node::SetUserData(void* pKey,
4030 void* pData,
4031 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
4032 SetMapModuleBuffer(pKey, &pData, sizeof(void*),
4033 pCallbackInfo ? pCallbackInfo : &gs_XFADefaultFreeData);
4034 return TRUE;
4035 }
4036 FX_BOOL CXFA_Node::TryUserData(void* pKey, void*& pData, FX_BOOL bProtoAlso) {
4037 int32_t iBytes = 0;
4038 if (!GetMapModuleBuffer(pKey, pData, iBytes, bProtoAlso)) {
4039 return FALSE;
4040 }
4041 return iBytes == sizeof(void*) && FXSYS_memcpy(&pData, pData, iBytes);
4042 }
4043 FX_BOOL CXFA_Node::SetScriptContent(const CFX_WideString& wsContent,
4044 const CFX_WideString& wsXMLValue,
4045 bool bNotify,
4046 FX_BOOL bScriptModify,
4047 FX_BOOL bSyncData) {
4048 CXFA_Node* pNode = nullptr;
4049 CXFA_Node* pBindNode = nullptr;
4050 switch (GetObjectType()) {
4051 case XFA_ObjectType::ContainerNode: {
4052 if (XFA_FieldIsMultiListBox(this)) {
4053 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
4054 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
4055 ASSERT(pChildValue);
4056 pChildValue->SetCData(XFA_ATTRIBUTE_ContentType, L"text/xml");
4057 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
4058 bScriptModify, FALSE);
4059 CXFA_Node* pBind = GetBindData();
4060 if (bSyncData && pBind) {
4061 CFX_WideStringArray wsSaveTextArray;
4062 int32_t iSize = 0;
4063 if (!wsContent.IsEmpty()) {
4064 int32_t iStart = 0;
4065 int32_t iLength = wsContent.GetLength();
4066 int32_t iEnd = wsContent.Find(L'\n', iStart);
4067 iEnd = (iEnd == -1) ? iLength : iEnd;
4068 while (iEnd >= iStart) {
4069 wsSaveTextArray.Add(wsContent.Mid(iStart, iEnd - iStart));
4070 iStart = iEnd + 1;
4071 if (iStart >= iLength) {
4072 break;
4073 }
4074 iEnd = wsContent.Find(L'\n', iStart);
4075 if (iEnd < 0) {
4076 wsSaveTextArray.Add(wsContent.Mid(iStart, iLength - iStart));
4077 }
4078 }
4079 iSize = wsSaveTextArray.GetSize();
4080 }
4081 if (iSize == 0) {
4082 while (CXFA_Node* pChildNode =
4083 pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) {
4084 pBind->RemoveChild(pChildNode);
4085 }
4086 } else {
4087 CXFA_NodeArray valueNodes;
4088 int32_t iDatas = pBind->GetNodeList(
4089 valueNodes, XFA_NODEFILTER_Children, XFA_Element::DataValue);
4090 if (iDatas < iSize) {
4091 int32_t iAddNodes = iSize - iDatas;
4092 CXFA_Node* pValueNodes = nullptr;
4093 while (iAddNodes-- > 0) {
4094 pValueNodes =
4095 pBind->CreateSamePacketNode(XFA_Element::DataValue);
4096 pValueNodes->SetCData(XFA_ATTRIBUTE_Name, L"value");
4097 pValueNodes->CreateXMLMappingNode();
4098 pBind->InsertChild(pValueNodes);
4099 }
4100 pValueNodes = nullptr;
4101 } else if (iDatas > iSize) {
4102 int32_t iDelNodes = iDatas - iSize;
4103 while (iDelNodes-- > 0) {
4104 pBind->RemoveChild(pBind->GetNodeItem(XFA_NODEITEM_FirstChild));
4105 }
4106 }
4107 int32_t i = 0;
4108 for (CXFA_Node* pValueNode =
4109 pBind->GetNodeItem(XFA_NODEITEM_FirstChild);
4110 pValueNode; pValueNode = pValueNode->GetNodeItem(
4111 XFA_NODEITEM_NextSibling)) {
4112 pValueNode->SetAttributeValue(wsSaveTextArray[i],
4113 wsSaveTextArray[i], FALSE);
4114 i++;
4115 }
4116 }
4117 CXFA_NodeArray nodeArray;
4118 pBind->GetBindItems(nodeArray);
4119 for (int32_t i = 0; i < nodeArray.GetSize(); i++) {
4120 if (nodeArray[i] != this) {
4121 nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify,
4122 bScriptModify, FALSE);
4123 }
4124 }
4125 }
4126 break;
4127 } else if (GetElementType() == XFA_Element::ExclGroup) {
4128 pNode = this;
4129 } else {
4130 CXFA_Node* pValue = GetProperty(0, XFA_Element::Value);
4131 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
4132 ASSERT(pChildValue);
4133 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
4134 bScriptModify, FALSE);
4135 }
4136 pBindNode = GetBindData();
4137 if (pBindNode && bSyncData) {
4138 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
4139 bScriptModify, FALSE);
4140 CXFA_NodeArray nodeArray;
4141 pBindNode->GetBindItems(nodeArray);
4142 for (int32_t i = 0; i < nodeArray.GetSize(); i++) {
4143 if (nodeArray[i] != this) {
4144 nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify, true,
4145 FALSE);
4146 }
4147 }
4148 }
4149 pBindNode = nullptr;
4150 break;
4151 }
4152 case XFA_ObjectType::ContentNode: {
4153 CFX_WideString wsContentType;
4154 if (GetElementType() == XFA_Element::ExData) {
4155 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, FALSE);
4156 if (wsContentType == FX_WSTRC(L"text/html")) {
4157 wsContentType = FX_WSTRC(L"");
4158 SetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType.AsStringC());
4159 }
4160 }
4161 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4162 if (!pContentRawDataNode) {
4163 pContentRawDataNode = CreateSamePacketNode(
4164 (wsContentType == FX_WSTRC(L"text/xml")) ? XFA_Element::Sharpxml
4165 : XFA_Element::Sharptext);
4166 InsertChild(pContentRawDataNode);
4167 }
4168 return pContentRawDataNode->SetScriptContent(
4169 wsContent, wsXMLValue, bNotify, bScriptModify, bSyncData);
4170 } break;
4171 case XFA_ObjectType::NodeC:
4172 case XFA_ObjectType::TextNode:
4173 pNode = this;
4174 break;
4175 case XFA_ObjectType::NodeV:
4176 pNode = this;
4177 if (bSyncData && GetPacketID() == XFA_XDPPACKET_Form) {
4178 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
4179 if (pParent) {
4180 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4181 }
4182 if (pParent && pParent->GetElementType() == XFA_Element::Value) {
4183 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
4184 if (pParent && pParent->IsContainerNode()) {
4185 pBindNode = pParent->GetBindData();
4186 if (pBindNode) {
4187 pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify,
4188 bScriptModify, FALSE);
4189 }
4190 }
4191 }
4192 }
4193 break;
4194 default:
4195 if (GetElementType() == XFA_Element::DataValue) {
4196 pNode = this;
4197 pBindNode = this;
4198 }
4199 break;
4200 }
4201 if (pNode) {
4202 SetAttributeValue(wsContent, wsXMLValue, bNotify, bScriptModify);
4203 if (pBindNode && bSyncData) {
4204 CXFA_NodeArray nodeArray;
4205 pBindNode->GetBindItems(nodeArray);
4206 for (int32_t i = 0; i < nodeArray.GetSize(); i++) {
4207 nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify,
4208 bScriptModify, FALSE);
4209 }
4210 }
4211 return TRUE;
4212 }
4213 return FALSE;
4214 }
4215 FX_BOOL CXFA_Node::SetContent(const CFX_WideString& wsContent,
4216 const CFX_WideString& wsXMLValue,
4217 bool bNotify,
4218 FX_BOOL bScriptModify,
4219 FX_BOOL bSyncData) {
4220 return SetScriptContent(wsContent, wsXMLValue, bNotify, bScriptModify,
4221 bSyncData);
4222 }
4223 CFX_WideString CXFA_Node::GetScriptContent(FX_BOOL bScriptModify) {
4224 CFX_WideString wsContent;
4225 return TryContent(wsContent, bScriptModify) ? wsContent : CFX_WideString();
4226 }
4227 CFX_WideString CXFA_Node::GetContent() {
4228 return GetScriptContent();
4229 }
4230 FX_BOOL CXFA_Node::TryContent(CFX_WideString& wsContent,
4231 FX_BOOL bScriptModify,
4232 FX_BOOL bProto) {
4233 CXFA_Node* pNode = nullptr;
4234 switch (GetObjectType()) {
4235 case XFA_ObjectType::ContainerNode:
4236 if (GetElementType() == XFA_Element::ExclGroup) {
4237 pNode = this;
4238 } else {
4239 CXFA_Node* pValue = GetChild(0, XFA_Element::Value);
4240 if (!pValue) {
4241 return FALSE;
4242 }
4243 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
4244 if (pChildValue && XFA_FieldIsMultiListBox(this)) {
4245 pChildValue->SetAttribute(XFA_ATTRIBUTE_ContentType,
4246 FX_WSTRC(L"text/xml"));
4247 }
4248 return pChildValue
4249 ? pChildValue->TryContent(wsContent, bScriptModify, bProto)
4250 : FALSE;
4251 }
4252 break;
4253 case XFA_ObjectType::ContentNode: {
4254 CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild);
4255 if (!pContentRawDataNode) {
4256 XFA_Element element = XFA_Element::Sharptext;
4257 if (GetElementType() == XFA_Element::ExData) {
4258 CFX_WideString wsContentType;
4259 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, FALSE);
4260 if (wsContentType == FX_WSTRC(L"text/html")) {
4261 element = XFA_Element::SharpxHTML;
4262 } else if (wsContentType == FX_WSTRC(L"text/xml")) {
4263 element = XFA_Element::Sharpxml;
4264 }
4265 }
4266 pContentRawDataNode = CreateSamePacketNode(element);
4267 InsertChild(pContentRawDataNode);
4268 }
4269 return pContentRawDataNode->TryContent(wsContent, bScriptModify, bProto);
4270 }
4271 case XFA_ObjectType::NodeC:
4272 case XFA_ObjectType::NodeV:
4273 case XFA_ObjectType::TextNode:
4274 pNode = this;
4275 default:
4276 if (GetElementType() == XFA_Element::DataValue) {
4277 pNode = this;
4278 }
4279 break;
4280 }
4281 if (pNode) {
4282 if (bScriptModify) {
4283 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
4284 if (pScriptContext) {
4285 m_pDocument->GetScriptContext()->AddNodesOfRunScript(this);
4286 }
4287 }
4288 return TryCData(XFA_ATTRIBUTE_Value, wsContent, FALSE, bProto);
4289 }
4290 return FALSE;
4291 }
4292 CXFA_Node* CXFA_Node::GetModelNode() {
4293 switch (GetPacketID()) {
4294 case XFA_XDPPACKET_XDP:
4295 return m_pDocument->GetRoot();
4296 case XFA_XDPPACKET_Config:
4297 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config));
4298 case XFA_XDPPACKET_Template:
4299 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
4300 case XFA_XDPPACKET_Form:
4301 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form));
4302 case XFA_XDPPACKET_Datasets:
4303 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets));
4304 case XFA_XDPPACKET_LocaleSet:
4305 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_LocaleSet));
4306 case XFA_XDPPACKET_ConnectionSet:
4307 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_ConnectionSet));
4308 case XFA_XDPPACKET_SourceSet:
4309 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_SourceSet));
4310 case XFA_XDPPACKET_Xdc:
4311 return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Xdc));
4312 default:
4313 return this;
4314 }
4315 }
4316 FX_BOOL CXFA_Node::TryNamespace(CFX_WideString& wsNamespace) {
4317 wsNamespace.clear();
4318 if (IsModelNode() || GetElementType() == XFA_Element::Packet) {
4319 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
4320 if (!pXMLNode || pXMLNode->GetType() != FDE_XMLNODE_Element) {
4321 return FALSE;
4322 }
4323 static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace);
4324 return TRUE;
4325 } else if (GetPacketID() == XFA_XDPPACKET_Datasets) {
4326 CFDE_XMLNode* pXMLNode = GetXMLMappingNode();
4327 if (!pXMLNode) {
4328 return FALSE;
4329 }
4330 if (pXMLNode->GetType() != FDE_XMLNODE_Element) {
4331 return TRUE;
4332 }
4333 if (GetElementType() == XFA_Element::DataValue &&
4334 GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData) {
4335 return XFA_FDEExtension_ResolveNamespaceQualifier(
4336 static_cast<CFDE_XMLElement*>(pXMLNode),
4337 GetCData(XFA_ATTRIBUTE_QualifiedName), wsNamespace);
4338 }
4339 static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace);
4340 return TRUE;
4341 } else {
4342 CXFA_Node* pModelNode = GetModelNode();
4343 return pModelNode->TryNamespace(wsNamespace);
4344 }
4345 }
4346 CXFA_Node* CXFA_Node::GetProperty(int32_t index,
4347 XFA_Element eProperty,
4348 FX_BOOL bCreateProperty) {
4349 XFA_Element eType = GetElementType();
4350 uint32_t dwPacket = GetPacketID();
4351 const XFA_PROPERTY* pProperty =
4352 XFA_GetPropertyOfElement(eType, eProperty, dwPacket);
4353 if (!pProperty || index >= pProperty->uOccur)
4354 return nullptr;
4355
4356 CXFA_Node* pNode = m_pChild;
4357 int32_t iCount = 0;
4358 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4359 if (pNode->GetElementType() == eProperty) {
4360 iCount++;
4361 if (iCount > index) {
4362 return pNode;
4363 }
4364 }
4365 }
4366 if (!bCreateProperty)
4367 return nullptr;
4368
4369 if (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf) {
4370 pNode = m_pChild;
4371 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4372 const XFA_PROPERTY* pExistProperty =
4373 XFA_GetPropertyOfElement(eType, pNode->GetElementType(), dwPacket);
4374 if (pExistProperty && (pExistProperty->uFlags & XFA_PROPERTYFLAG_OneOf))
4375 return nullptr;
4376 }
4377 }
4378
4379 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(dwPacket);
4380 CXFA_Node* pNewNode = nullptr;
4381 for (; iCount <= index; iCount++) {
4382 pNewNode = m_pDocument->CreateNode(pPacket, eProperty);
4383 if (!pNewNode)
4384 return nullptr;
4385 InsertChild(pNewNode, nullptr);
4386 pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
4387 }
4388 return pNewNode;
4389 }
4390 int32_t CXFA_Node::CountChildren(XFA_Element eType, FX_BOOL bOnlyChild) {
4391 CXFA_Node* pNode = m_pChild;
4392 int32_t iCount = 0;
4393 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4394 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
4395 if (bOnlyChild) {
4396 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
4397 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
4398 if (pProperty) {
4399 continue;
4400 }
4401 }
4402 iCount++;
4403 }
4404 }
4405 return iCount;
4406 }
4407 CXFA_Node* CXFA_Node::GetChild(int32_t index,
4408 XFA_Element eType,
4409 FX_BOOL bOnlyChild) {
4410 ASSERT(index > -1);
4411 CXFA_Node* pNode = m_pChild;
4412 int32_t iCount = 0;
4413 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4414 if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) {
4415 if (bOnlyChild) {
4416 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
4417 GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN);
4418 if (pProperty) {
4419 continue;
4420 }
4421 }
4422 iCount++;
4423 if (iCount > index) {
4424 return pNode;
4425 }
4426 }
4427 }
4428 return nullptr;
4429 }
4430 int32_t CXFA_Node::InsertChild(int32_t index, CXFA_Node* pNode) {
4431 ASSERT(!pNode->m_pNext);
4432 pNode->m_pParent = this;
4433 FX_BOOL ret = m_pDocument->RemovePurgeNode(pNode);
4434 ASSERT(ret);
4435 (void)ret; // Avoid unused variable warning.
4436
4437 if (!m_pChild || index == 0) {
4438 if (index > 0) {
4439 return -1;
4440 }
4441 pNode->m_pNext = m_pChild;
4442 m_pChild = pNode;
4443 index = 0;
4444 } else if (index < 0) {
4445 m_pLastChild->m_pNext = pNode;
4446 } else {
4447 CXFA_Node* pPrev = m_pChild;
4448 int32_t iCount = 0;
4449 while (++iCount != index && pPrev->m_pNext) {
4450 pPrev = pPrev->m_pNext;
4451 }
4452 if (index > 0 && index != iCount) {
4453 return -1;
4454 }
4455 pNode->m_pNext = pPrev->m_pNext;
4456 pPrev->m_pNext = pNode;
4457 index = iCount;
4458 }
4459 if (!pNode->m_pNext) {
4460 m_pLastChild = pNode;
4461 }
4462 ASSERT(m_pLastChild);
4463 ASSERT(!m_pLastChild->m_pNext);
4464 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
4465 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
4466 if (pNotify)
4467 pNotify->OnChildAdded(this);
4468
4469 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
4470 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
4471 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, index);
4472 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
4473 }
4474 return index;
4475 }
4476
4477 FX_BOOL CXFA_Node::InsertChild(CXFA_Node* pNode, CXFA_Node* pBeforeNode) {
4478 if (!pNode || pNode->m_pParent ||
4479 (pBeforeNode && pBeforeNode->m_pParent != this)) {
4480 ASSERT(false);
4481 return FALSE;
4482 }
4483 FX_BOOL ret = m_pDocument->RemovePurgeNode(pNode);
4484 ASSERT(ret);
4485 (void)ret; // Avoid unused variable warning.
4486
4487 int32_t nIndex = -1;
4488 pNode->m_pParent = this;
4489 if (!m_pChild || pBeforeNode == m_pChild) {
4490 pNode->m_pNext = m_pChild;
4491 m_pChild = pNode;
4492 nIndex = 0;
4493 } else if (!pBeforeNode) {
4494 pNode->m_pNext = m_pLastChild->m_pNext;
4495 m_pLastChild->m_pNext = pNode;
4496 } else {
4497 nIndex = 1;
4498 CXFA_Node* pPrev = m_pChild;
4499 while (pPrev->m_pNext != pBeforeNode) {
4500 pPrev = pPrev->m_pNext;
4501 nIndex++;
4502 }
4503 pNode->m_pNext = pPrev->m_pNext;
4504 pPrev->m_pNext = pNode;
4505 }
4506 if (!pNode->m_pNext) {
4507 m_pLastChild = pNode;
4508 }
4509 ASSERT(m_pLastChild);
4510 ASSERT(!m_pLastChild->m_pNext);
4511 pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren);
4512 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
4513 if (pNotify)
4514 pNotify->OnChildAdded(this);
4515
4516 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
4517 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
4518 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, nIndex);
4519 pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode);
4520 }
4521 return TRUE;
4522 }
4523 CXFA_Node* CXFA_Node::Deprecated_GetPrevSibling() {
4524 if (!m_pParent) {
4525 return nullptr;
4526 }
4527 for (CXFA_Node* pSibling = m_pParent->m_pChild; pSibling;
4528 pSibling = pSibling->m_pNext) {
4529 if (pSibling->m_pNext == this) {
4530 return pSibling;
4531 }
4532 }
4533 return nullptr;
4534 }
4535 FX_BOOL CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) {
4536 if (!pNode || pNode->m_pParent != this) {
4537 ASSERT(FALSE);
4538 return FALSE;
4539 }
4540 if (m_pChild == pNode) {
4541 m_pChild = pNode->m_pNext;
4542 if (m_pLastChild == pNode) {
4543 m_pLastChild = pNode->m_pNext;
4544 }
4545 pNode->m_pNext = nullptr;
4546 pNode->m_pParent = nullptr;
4547 } else {
4548 CXFA_Node* pPrev = pNode->Deprecated_GetPrevSibling();
4549 pPrev->m_pNext = pNode->m_pNext;
4550 if (m_pLastChild == pNode) {
4551 m_pLastChild = pNode->m_pNext ? pNode->m_pNext : pPrev;
4552 }
4553 pNode->m_pNext = nullptr;
4554 pNode->m_pParent = nullptr;
4555 }
4556 ASSERT(!m_pLastChild || !m_pLastChild->m_pNext);
4557 OnRemoved(bNotify);
4558 pNode->SetFlag(XFA_NodeFlag_HasRemovedChildren, true);
4559 m_pDocument->AddPurgeNode(pNode);
4560 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
4561 if (pNode->IsAttributeInXML()) {
4562 ASSERT(pNode->m_pXMLNode == m_pXMLNode &&
4563 m_pXMLNode->GetType() == FDE_XMLNODE_Element);
4564 if (pNode->m_pXMLNode->GetType() == FDE_XMLNODE_Element) {
4565 CFDE_XMLElement* pXMLElement =
4566 static_cast<CFDE_XMLElement*>(pNode->m_pXMLNode);
4567 CFX_WideStringC wsAttributeName =
4568 pNode->GetCData(XFA_ATTRIBUTE_QualifiedName);
4569 pXMLElement->RemoveAttribute(wsAttributeName.c_str());
4570 }
4571 CFX_WideString wsName;
4572 pNode->GetAttribute(XFA_ATTRIBUTE_Name, wsName, FALSE);
4573 CFDE_XMLElement* pNewXMLElement = new CFDE_XMLElement(wsName);
4574 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
4575 if (!wsValue.IsEmpty()) {
4576 pNewXMLElement->SetTextData(CFX_WideString(wsValue));
4577 }
4578 pNode->m_pXMLNode = pNewXMLElement;
4579 pNode->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
4580 } else {
4581 m_pXMLNode->RemoveChildNode(pNode->m_pXMLNode);
4582 }
4583 pNode->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
4584 }
4585 return TRUE;
4586 }
4587 CXFA_Node* CXFA_Node::GetFirstChildByName(const CFX_WideStringC& wsName) const {
4588 return GetFirstChildByName(FX_HashCode_GetW(wsName, false));
4589 }
4590 CXFA_Node* CXFA_Node::GetFirstChildByName(uint32_t dwNameHash) const {
4591 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4592 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4593 if (pNode->GetNameHash() == dwNameHash) {
4594 return pNode;
4595 }
4596 }
4597 return nullptr;
4598 }
4599 CXFA_Node* CXFA_Node::GetFirstChildByClass(XFA_Element eType) const {
4600 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4601 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4602 if (pNode->GetElementType() == eType) {
4603 return pNode;
4604 }
4605 }
4606 return nullptr;
4607 }
4608 CXFA_Node* CXFA_Node::GetNextSameNameSibling(uint32_t dwNameHash) const {
4609 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4610 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4611 if (pNode->GetNameHash() == dwNameHash) {
4612 return pNode;
4613 }
4614 }
4615 return nullptr;
4616 }
4617 CXFA_Node* CXFA_Node::GetNextSameNameSibling(
4618 const CFX_WideStringC& wsNodeName) const {
4619 return GetNextSameNameSibling(FX_HashCode_GetW(wsNodeName, false));
4620 }
4621 CXFA_Node* CXFA_Node::GetNextSameClassSibling(XFA_Element eType) const {
4622 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4623 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4624 if (pNode->GetElementType() == eType) {
4625 return pNode;
4626 }
4627 }
4628 return nullptr;
4629 }
4630 int32_t CXFA_Node::GetNodeSameNameIndex() const {
4631 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
4632 if (!pScriptContext) {
4633 return -1;
4634 }
4635 return pScriptContext->GetIndexByName(const_cast<CXFA_Node*>(this));
4636 }
4637 int32_t CXFA_Node::GetNodeSameClassIndex() const {
4638 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
4639 if (!pScriptContext) {
4640 return -1;
4641 }
4642 return pScriptContext->GetIndexByClassName(const_cast<CXFA_Node*>(this));
4643 }
4644 void CXFA_Node::GetSOMExpression(CFX_WideString& wsSOMExpression) {
4645 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
4646 if (!pScriptContext) {
4647 return;
4648 }
4649 pScriptContext->GetSomExpression(this, wsSOMExpression);
4650 }
4651 CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() {
4652 CXFA_Node* pInstanceMgr = nullptr;
4653 if (m_ePacket == XFA_XDPPACKET_Form) {
4654 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
4655 if (!pParentNode || pParentNode->GetElementType() == XFA_Element::Area) {
4656 return pInstanceMgr;
4657 }
4658 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
4659 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
4660 XFA_Element eType = pNode->GetElementType();
4661 if ((eType == XFA_Element::Subform || eType == XFA_Element::SubformSet) &&
4662 pNode->m_dwNameHash != m_dwNameHash) {
4663 break;
4664 }
4665 if (eType == XFA_Element::InstanceManager) {
4666 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
4667 CFX_WideStringC wsInstName = pNode->GetCData(XFA_ATTRIBUTE_Name);
4668 if (wsInstName.GetLength() > 0 && wsInstName.GetAt(0) == '_' &&
4669 wsInstName.Mid(1) == wsName) {
4670 pInstanceMgr = pNode;
4671 }
4672 break;
4673 }
4674 }
4675 }
4676 return pInstanceMgr;
4677 }
4678 CXFA_Node* CXFA_Node::GetOccurNode() {
4679 return GetFirstChildByClass(XFA_Element::Occur);
4680 }
4681 bool CXFA_Node::HasFlag(XFA_NodeFlag dwFlag) const {
4682 if (m_uNodeFlags & dwFlag)
4683 return true;
4684 if (dwFlag == XFA_NodeFlag_HasRemovedChildren)
4685 return m_pParent && m_pParent->HasFlag(dwFlag);
4686 return false;
4687 }
4688
4689 void CXFA_Node::SetFlag(uint32_t dwFlag, bool bNotify) {
4690 if (dwFlag == XFA_NodeFlag_Initialized && bNotify && !IsInitialized()) {
4691 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
4692 if (pNotify) {
4693 pNotify->OnNodeReady(this);
4694 }
4695 }
4696 m_uNodeFlags |= dwFlag;
4697 }
4698
4699 void CXFA_Node::ClearFlag(uint32_t dwFlag) {
4700 m_uNodeFlags &= ~dwFlag;
4701 }
4702
4703 FX_BOOL CXFA_Node::IsAttributeInXML() {
4704 return GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData;
4705 }
4706
4707 void CXFA_Node::OnRemoved(bool bNotify) {
4708 if (!bNotify)
4709 return;
4710
4711 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
4712 if (pNotify)
4713 pNotify->OnChildRemoved();
4714 }
4715
4716 void CXFA_Node::OnChanging(XFA_ATTRIBUTE eAttr, bool bNotify) {
4717 if (bNotify && IsInitialized()) {
4718 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
4719 if (pNotify) {
4720 pNotify->OnValueChanging(this, eAttr);
4721 }
4722 }
4723 }
4724
4725 void CXFA_Node::OnChanged(XFA_ATTRIBUTE eAttr,
4726 bool bNotify,
4727 FX_BOOL bScriptModify) {
4728 if (bNotify && IsInitialized()) {
4729 Script_Attribute_SendAttributeChangeMessage(eAttr, bScriptModify);
4730 }
4731 }
4732
4733 int32_t CXFA_Node::execSingleEventByName(const CFX_WideStringC& wsEventName,
4734 XFA_Element eType) {
4735 int32_t iRet = XFA_EVENTERROR_NotExist;
4736 const XFA_ExecEventParaInfo* eventParaInfo =
4737 GetEventParaInfoByName(wsEventName);
4738 if (eventParaInfo) {
4739 uint32_t validFlags = eventParaInfo->m_validFlags;
4740 CXFA_FFNotify* pNotify = m_pDocument->GetNotify();
4741 if (!pNotify) {
4742 return iRet;
4743 }
4744 if (validFlags == 1) {
4745 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType);
4746 } else if (validFlags == 2) {
4747 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
4748 FALSE, FALSE);
4749 } else if (validFlags == 3) {
4750 if (eType == XFA_Element::Subform) {
4751 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
4752 FALSE, FALSE);
4753 }
4754 } else if (validFlags == 4) {
4755 if (eType == XFA_Element::ExclGroup || eType == XFA_Element::Field) {
4756 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
4757 if (pParentNode &&
4758 pParentNode->GetElementType() == XFA_Element::ExclGroup) {
4759 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
4760 FALSE, FALSE);
4761 }
4762 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
4763 FALSE, FALSE);
4764 }
4765 } else if (validFlags == 5) {
4766 if (eType == XFA_Element::Field) {
4767 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
4768 FALSE, FALSE);
4769 }
4770 } else if (validFlags == 6) {
4771 CXFA_WidgetData* pWidgetData = GetWidgetData();
4772 if (pWidgetData) {
4773 CXFA_Node* pUINode = pWidgetData->GetUIChild();
4774 if (pUINode->m_elementType == XFA_Element::Signature) {
4775 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
4776 FALSE, FALSE);
4777 }
4778 }
4779 } else if (validFlags == 7) {
4780 CXFA_WidgetData* pWidgetData = GetWidgetData();
4781 if (pWidgetData) {
4782 CXFA_Node* pUINode = pWidgetData->GetUIChild();
4783 if ((pUINode->m_elementType == XFA_Element::ChoiceList) &&
4784 (!pWidgetData->IsListBox())) {
4785 iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType,
4786 FALSE, FALSE);
4787 }
4788 }
4789 }
4790 }
4791 return iRet;
4792 }
4793 void CXFA_Node::UpdateNameHash() {
4794 const XFA_NOTSUREATTRIBUTE* pNotsure =
4795 XFA_GetNotsureAttribute(GetElementType(), XFA_ATTRIBUTE_Name);
4796 CFX_WideStringC wsName;
4797 if (!pNotsure || pNotsure->eType == XFA_ATTRIBUTETYPE_Cdata) {
4798 wsName = GetCData(XFA_ATTRIBUTE_Name);
4799 m_dwNameHash = FX_HashCode_GetW(wsName, false);
4800 } else if (pNotsure->eType == XFA_ATTRIBUTETYPE_Enum) {
4801 wsName = XFA_GetAttributeEnumByID(GetEnum(XFA_ATTRIBUTE_Name))->pName;
4802 m_dwNameHash = FX_HashCode_GetW(wsName, false);
4803 }
4804 }
4805 CFDE_XMLNode* CXFA_Node::CreateXMLMappingNode() {
4806 if (!m_pXMLNode) {
4807 CFX_WideString wsTag(GetCData(XFA_ATTRIBUTE_Name));
4808 m_pXMLNode = new CFDE_XMLElement(wsTag);
4809 SetFlag(XFA_NodeFlag_OwnXMLNode, false);
4810 }
4811 return m_pXMLNode;
4812 }
4813 FX_BOOL CXFA_Node::IsNeedSavingXMLNode() {
4814 return m_pXMLNode && (GetPacketID() == XFA_XDPPACKET_Datasets ||
4815 GetElementType() == XFA_Element::Xfa);
4816 }
4817
4818 XFA_MAPMODULEDATA* CXFA_Node::CreateMapModuleData() {
4819 if (!m_pMapModuleData)
4820 m_pMapModuleData = new XFA_MAPMODULEDATA;
4821 return m_pMapModuleData;
4822 }
4823
4824 XFA_MAPMODULEDATA* CXFA_Node::GetMapModuleData() const {
4825 return m_pMapModuleData;
4826 }
4827
4828 void CXFA_Node::SetMapModuleValue(void* pKey, void* pValue) {
4829 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
4830 pModule->m_ValueMap.SetAt(pKey, pValue);
4831 }
4832
4833 FX_BOOL CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) {
4834 CXFA_Node* pNode = this;
4835 while (pNode) {
4836 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
4837 if (pModule && pModule->m_ValueMap.Lookup(pKey, pValue)) {
4838 return TRUE;
4839 }
4840 pNode = pNode->GetPacketID() != XFA_XDPPACKET_Datasets
4841 ? pNode->GetTemplateNode()
4842 : nullptr;
4843 }
4844 return FALSE;
4845 }
4846 void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) {
4847 SetMapModuleBuffer(pKey, (void*)wsValue.c_str(),
4848 wsValue.GetLength() * sizeof(FX_WCHAR));
4849 }
4850 FX_BOOL CXFA_Node::GetMapModuleString(void* pKey, CFX_WideStringC& wsValue) {
4851 void* pValue;
4852 int32_t iBytes;
4853 if (!GetMapModuleBuffer(pKey, pValue, iBytes)) {
4854 return FALSE;
4855 }
4856 wsValue = CFX_WideStringC((const FX_WCHAR*)pValue, iBytes / sizeof(FX_WCHAR));
4857 return TRUE;
4858 }
4859 void CXFA_Node::SetMapModuleBuffer(
4860 void* pKey,
4861 void* pValue,
4862 int32_t iBytes,
4863 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
4864 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
4865 XFA_MAPDATABLOCK*& pBuffer = pModule->m_BufferMap[pKey];
4866 if (!pBuffer) {
4867 pBuffer =
4868 (XFA_MAPDATABLOCK*)FX_Alloc(uint8_t, sizeof(XFA_MAPDATABLOCK) + iBytes);
4869 } else if (pBuffer->iBytes != iBytes) {
4870 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4871 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4872 }
4873 pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(uint8_t, pBuffer,
4874 sizeof(XFA_MAPDATABLOCK) + iBytes);
4875 } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4876 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4877 }
4878 if (!pBuffer)
4879 return;
4880
4881 pBuffer->pCallbackInfo = pCallbackInfo;
4882 pBuffer->iBytes = iBytes;
4883 FXSYS_memcpy(pBuffer->GetData(), pValue, iBytes);
4884 }
4885 FX_BOOL CXFA_Node::GetMapModuleBuffer(void* pKey,
4886 void*& pValue,
4887 int32_t& iBytes,
4888 FX_BOOL bProtoAlso) const {
4889 XFA_MAPDATABLOCK* pBuffer = nullptr;
4890 const CXFA_Node* pNode = this;
4891 while (pNode) {
4892 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
4893 if (pModule && pModule->m_BufferMap.Lookup(pKey, pBuffer)) {
4894 break;
4895 }
4896 pNode = (bProtoAlso && pNode->GetPacketID() != XFA_XDPPACKET_Datasets)
4897 ? pNode->GetTemplateNode()
4898 : nullptr;
4899 }
4900 if (!pBuffer) {
4901 return FALSE;
4902 }
4903 pValue = pBuffer->GetData();
4904 iBytes = pBuffer->iBytes;
4905 return TRUE;
4906 }
4907 FX_BOOL CXFA_Node::HasMapModuleKey(void* pKey, FX_BOOL bProtoAlso) {
4908 CXFA_Node* pNode = this;
4909 while (pNode) {
4910 void* pVal;
4911 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
4912 if (pModule &&
4913 (pModule->m_ValueMap.Lookup(pKey, pVal) ||
4914 pModule->m_BufferMap.Lookup(pKey, (XFA_MAPDATABLOCK*&)pVal))) {
4915 return TRUE;
4916 }
4917 pNode = (bProtoAlso && pNode->GetPacketID() != XFA_XDPPACKET_Datasets)
4918 ? pNode->GetTemplateNode()
4919 : nullptr;
4920 }
4921 return FALSE;
4922 }
4923 void CXFA_Node::RemoveMapModuleKey(void* pKey) {
4924 XFA_MAPMODULEDATA* pModule = GetMapModuleData();
4925 if (!pModule)
4926 return;
4927
4928 if (pKey) {
4929 XFA_MAPDATABLOCK* pBuffer = nullptr;
4930 pModule->m_BufferMap.Lookup(pKey, pBuffer);
4931 if (pBuffer) {
4932 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4933 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4934 }
4935 FX_Free(pBuffer);
4936 }
4937 pModule->m_BufferMap.RemoveKey(pKey);
4938 pModule->m_ValueMap.RemoveKey(pKey);
4939 } else {
4940 XFA_MAPDATABLOCK* pBuffer;
4941 FX_POSITION posBuffer = pModule->m_BufferMap.GetStartPosition();
4942 while (posBuffer) {
4943 pModule->m_BufferMap.GetNextAssoc(posBuffer, pKey, pBuffer);
4944 if (pBuffer) {
4945 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4946 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4947 }
4948 FX_Free(pBuffer);
4949 }
4950 }
4951 pModule->m_BufferMap.RemoveAll();
4952 pModule->m_ValueMap.RemoveAll();
4953 delete pModule;
4954 }
4955 }
4956 void CXFA_Node::MergeAllData(void* pDstModule, FX_BOOL bUseSrcAttr) {
4957 XFA_MAPMODULEDATA* pDstModuleData =
4958 static_cast<CXFA_Node*>(pDstModule)->CreateMapModuleData();
4959 XFA_MAPMODULEDATA* pSrcModuleData = GetMapModuleData();
4960 if (!pSrcModuleData) {
4961 return;
4962 }
4963 FX_POSITION psValue = pSrcModuleData->m_ValueMap.GetStartPosition();
4964 while (psValue) {
4965 void* pKey;
4966 void* pValue;
4967 pSrcModuleData->m_ValueMap.GetNextAssoc(psValue, pKey, pValue);
4968 if (bUseSrcAttr || !pDstModuleData->m_ValueMap.GetValueAt(pKey)) {
4969 pDstModuleData->m_ValueMap.SetAt(pKey, pValue);
4970 }
4971 }
4972 FX_POSITION psBuffer = pSrcModuleData->m_BufferMap.GetStartPosition();
4973 while (psBuffer) {
4974 void* pKey;
4975 XFA_MAPDATABLOCK* pSrcBuffer;
4976 pSrcModuleData->m_BufferMap.GetNextAssoc(psBuffer, pKey, pSrcBuffer);
4977 XFA_MAPDATABLOCK*& pBuffer = pDstModuleData->m_BufferMap[pKey];
4978 if (pBuffer && !bUseSrcAttr) {
4979 continue;
4980 }
4981 if (pSrcBuffer->pCallbackInfo && pSrcBuffer->pCallbackInfo->pFree &&
4982 !pSrcBuffer->pCallbackInfo->pCopy) {
4983 if (pBuffer) {
4984 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4985 pDstModuleData->m_BufferMap.RemoveKey(pKey);
4986 }
4987 continue;
4988 }
4989 if (!pBuffer) {
4990 pBuffer = (XFA_MAPDATABLOCK*)FX_Alloc(
4991 uint8_t, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
4992 } else if (pBuffer->iBytes != pSrcBuffer->iBytes) {
4993 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4994 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
4995 }
4996 pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(
4997 uint8_t, pBuffer, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
4998 } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
4999 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5000 }
5001 if (!pBuffer) {
5002 continue;
5003 }
5004 pBuffer->pCallbackInfo = pSrcBuffer->pCallbackInfo;
5005 pBuffer->iBytes = pSrcBuffer->iBytes;
5006 FXSYS_memcpy(pBuffer->GetData(), pSrcBuffer->GetData(), pSrcBuffer->iBytes);
5007 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pCopy) {
5008 pBuffer->pCallbackInfo->pCopy(*(void**)pBuffer->GetData());
5009 }
5010 }
5011 }
5012 void CXFA_Node::MoveBufferMapData(CXFA_Node* pDstModule, void* pKey) {
5013 if (!pDstModule) {
5014 return;
5015 }
5016 FX_BOOL bNeedMove = TRUE;
5017 if (!pKey) {
5018 bNeedMove = FALSE;
5019 }
5020 if (pDstModule->GetElementType() != GetElementType()) {
5021 bNeedMove = FALSE;
5022 }
5023 XFA_MAPMODULEDATA* pSrcModuleData = nullptr;
5024 XFA_MAPMODULEDATA* pDstModuleData = nullptr;
5025 if (bNeedMove) {
5026 pSrcModuleData = GetMapModuleData();
5027 if (!pSrcModuleData) {
5028 bNeedMove = FALSE;
5029 }
5030 pDstModuleData = pDstModule->CreateMapModuleData();
5031 }
5032 if (bNeedMove) {
5033 void* pBufferBlockData = pSrcModuleData->m_BufferMap.GetValueAt(pKey);
5034 if (pBufferBlockData) {
5035 pSrcModuleData->m_BufferMap.RemoveKey(pKey);
5036 pDstModuleData->m_BufferMap.RemoveKey(pKey);
5037 pDstModuleData->m_BufferMap.SetAt(pKey,
5038 (XFA_MAPDATABLOCK*)pBufferBlockData);
5039 }
5040 }
5041 if (pDstModule->IsNodeV()) {
5042 CFX_WideString wsValue = pDstModule->GetScriptContent(FALSE);
5043 CFX_WideString wsFormatValue(wsValue);
5044 CXFA_WidgetData* pWidgetData = pDstModule->GetContainerWidgetData();
5045 if (pWidgetData) {
5046 pWidgetData->GetFormatDataValue(wsValue, wsFormatValue);
5047 }
5048 pDstModule->SetScriptContent(wsValue, wsFormatValue, true, TRUE);
5049 }
5050 }
5051 void CXFA_Node::MoveBufferMapData(CXFA_Node* pSrcModule,
5052 CXFA_Node* pDstModule,
5053 void* pKey,
5054 FX_BOOL bRecursive) {
5055 if (!pSrcModule || !pDstModule || !pKey) {
5056 return;
5057 }
5058 if (bRecursive) {
5059 CXFA_Node* pSrcChild = pSrcModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5060 CXFA_Node* pDstChild = pDstModule->GetNodeItem(XFA_NODEITEM_FirstChild);
5061 for (; pSrcChild && pDstChild;
5062 pSrcChild = pSrcChild->GetNodeItem(XFA_NODEITEM_NextSibling),
5063 pDstChild = pDstChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
5064 MoveBufferMapData(pSrcChild, pDstChild, pKey, TRUE);
5065 }
5066 }
5067 pSrcModule->MoveBufferMapData(pDstModule, pKey);
5068 }
5069
5070 CXFA_ThisProxy::CXFA_ThisProxy(CXFA_Node* pThisNode, CXFA_Node* pScriptNode)
5071 : CXFA_Object(pThisNode->GetDocument(),
5072 XFA_ObjectType::VariablesThis,
5073 XFA_Element::Unknown,
5074 CFX_WideStringC()),
5075 m_pThisNode(nullptr),
5076 m_pScriptNode(nullptr) {
5077 m_pThisNode = pThisNode;
5078 m_pScriptNode = pScriptNode;
5079 }
5080
5081 CXFA_ThisProxy::~CXFA_ThisProxy() {}
5082
5083 CXFA_Node* CXFA_ThisProxy::GetThisNode() const {
5084 return m_pThisNode;
5085 }
5086
5087 CXFA_Node* CXFA_ThisProxy::GetScriptNode() const {
5088 return m_pScriptNode;
5089 }
5090
5091 CXFA_NodeList::CXFA_NodeList(CXFA_Document* pDocument)
5092 : CXFA_Object(pDocument,
5093 XFA_ObjectType::NodeList,
5094 XFA_Element::NodeList,
5095 CFX_WideStringC(L"nodeList")) {
5096 m_pDocument->GetScriptContext()->AddToCacheList(
5097 std::unique_ptr<CXFA_NodeList>(this));
5098 }
5099
5100 CXFA_NodeList::~CXFA_NodeList() {}
5101
5102 CXFA_Node* CXFA_NodeList::NamedItem(const CFX_WideStringC& wsName) {
5103 uint32_t dwHashCode = FX_HashCode_GetW(wsName, false);
5104 int32_t iCount = GetLength();
5105 for (int32_t i = 0; i < iCount; i++) {
5106 CXFA_Node* ret = Item(i);
5107 if (dwHashCode == ret->GetNameHash())
5108 return ret;
5109 }
5110 return nullptr;
5111 }
5112 void CXFA_NodeList::Script_ListClass_Append(CFXJSE_Arguments* pArguments) {
5113 int32_t argc = pArguments->GetLength();
5114 if (argc == 1) {
5115 CXFA_Node* pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
5116 if (pNode) {
5117 Append(pNode);
5118 } else {
5119 ThrowException(XFA_IDS_ARGUMENT_MISMATCH);
5120 }
5121 } else {
5122 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"append");
5123 }
5124 }
5125 void CXFA_NodeList::Script_ListClass_Insert(CFXJSE_Arguments* pArguments) {
5126 int32_t argc = pArguments->GetLength();
5127 if (argc == 2) {
5128 CXFA_Node* pNewNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
5129 CXFA_Node* pBeforeNode = static_cast<CXFA_Node*>(pArguments->GetObject(1));
5130 if (pNewNode) {
5131 Insert(pNewNode, pBeforeNode);
5132 } else {
5133 ThrowException(XFA_IDS_ARGUMENT_MISMATCH);
5134 }
5135 } else {
5136 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"insert");
5137 }
5138 }
5139 void CXFA_NodeList::Script_ListClass_Remove(CFXJSE_Arguments* pArguments) {
5140 int32_t argc = pArguments->GetLength();
5141 if (argc == 1) {
5142 CXFA_Node* pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
5143 if (pNode) {
5144 Remove(pNode);
5145 } else {
5146 ThrowException(XFA_IDS_ARGUMENT_MISMATCH);
5147 }
5148 } else {
5149 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"remove");
5150 }
5151 }
5152 void CXFA_NodeList::Script_ListClass_Item(CFXJSE_Arguments* pArguments) {
5153 int32_t argc = pArguments->GetLength();
5154 if (argc == 1) {
5155 int32_t iIndex = pArguments->GetInt32(0);
5156 if ((iIndex >= 0) && (iIndex + 1 <= GetLength())) {
5157 pArguments->GetReturnValue()->Assign(
5158 m_pDocument->GetScriptContext()->GetJSValueFromMap(Item(iIndex)));
5159 } else {
5160 ThrowException(XFA_IDS_INDEX_OUT_OF_BOUNDS);
5161 }
5162 } else {
5163 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"item");
5164 }
5165 }
5166 void CXFA_NodeList::Script_TreelistClass_NamedItem(
5167 CFXJSE_Arguments* pArguments) {
5168 int32_t argc = pArguments->GetLength();
5169 if (argc == 1) {
5170 CFX_ByteString szName = pArguments->GetUTF8String(0);
5171 CXFA_Node* pNode =
5172 NamedItem(CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC());
5173 if (!pNode) {
5174 return;
5175 }
5176 pArguments->GetReturnValue()->Assign(
5177 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode));
5178 } else {
5179 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"namedItem");
5180 }
5181 }
5182 void CXFA_NodeList::Script_ListClass_Length(CFXJSE_Value* pValue,
5183 FX_BOOL bSetting,
5184 XFA_ATTRIBUTE eAttribute) {
5185 if (!bSetting) {
5186 pValue->SetInteger(GetLength());
5187 } else {
5188 ThrowException(XFA_IDS_INVAlID_PROP_SET);
5189 }
5190 }
5191 CXFA_ArrayNodeList::CXFA_ArrayNodeList(CXFA_Document* pDocument)
5192 : CXFA_NodeList(pDocument) {}
5193
5194 CXFA_ArrayNodeList::~CXFA_ArrayNodeList() {}
5195
5196 void CXFA_ArrayNodeList::SetArrayNodeList(const CXFA_NodeArray& srcArray) {
5197 if (srcArray.GetSize() > 0) {
5198 m_array.Copy(srcArray);
5199 }
5200 }
5201 int32_t CXFA_ArrayNodeList::GetLength() {
5202 return m_array.GetSize();
5203 }
5204 FX_BOOL CXFA_ArrayNodeList::Append(CXFA_Node* pNode) {
5205 m_array.Add(pNode);
5206 return TRUE;
5207 }
5208 FX_BOOL CXFA_ArrayNodeList::Insert(CXFA_Node* pNewNode,
5209 CXFA_Node* pBeforeNode) {
5210 if (!pBeforeNode) {
5211 m_array.Add(pNewNode);
5212 } else {
5213 int32_t iSize = m_array.GetSize();
5214 for (int32_t i = 0; i < iSize; ++i) {
5215 if (m_array[i] == pBeforeNode) {
5216 m_array.InsertAt(i, pNewNode);
5217 break;
5218 }
5219 }
5220 }
5221 return TRUE;
5222 }
5223 FX_BOOL CXFA_ArrayNodeList::Remove(CXFA_Node* pNode) {
5224 int32_t iSize = m_array.GetSize();
5225 for (int32_t i = 0; i < iSize; ++i) {
5226 if (m_array[i] == pNode) {
5227 m_array.RemoveAt(i);
5228 break;
5229 }
5230 }
5231 return TRUE;
5232 }
5233 CXFA_Node* CXFA_ArrayNodeList::Item(int32_t iIndex) {
5234 int32_t iSize = m_array.GetSize();
5235 if (iIndex >= 0 && iIndex < iSize) {
5236 return m_array[iIndex];
5237 }
5238 return nullptr;
5239 }
5240 CXFA_AttachNodeList::CXFA_AttachNodeList(CXFA_Document* pDocument,
5241 CXFA_Node* pAttachNode)
5242 : CXFA_NodeList(pDocument) {
5243 m_pAttachNode = pAttachNode;
5244 }
5245 int32_t CXFA_AttachNodeList::GetLength() {
5246 return m_pAttachNode->CountChildren(
5247 XFA_Element::Unknown,
5248 m_pAttachNode->GetElementType() == XFA_Element::Subform);
5249 }
5250 FX_BOOL CXFA_AttachNodeList::Append(CXFA_Node* pNode) {
5251 CXFA_Node* pParent = pNode->GetNodeItem(XFA_NODEITEM_Parent);
5252 if (pParent) {
5253 pParent->RemoveChild(pNode);
5254 }
5255 return m_pAttachNode->InsertChild(pNode);
5256 }
5257 FX_BOOL CXFA_AttachNodeList::Insert(CXFA_Node* pNewNode,
5258 CXFA_Node* pBeforeNode) {
5259 CXFA_Node* pParent = pNewNode->GetNodeItem(XFA_NODEITEM_Parent);
5260 if (pParent) {
5261 pParent->RemoveChild(pNewNode);
5262 }
5263 return m_pAttachNode->InsertChild(pNewNode, pBeforeNode);
5264 }
5265 FX_BOOL CXFA_AttachNodeList::Remove(CXFA_Node* pNode) {
5266 return m_pAttachNode->RemoveChild(pNode);
5267 }
5268 CXFA_Node* CXFA_AttachNodeList::Item(int32_t iIndex) {
5269 return m_pAttachNode->GetChild(
5270 iIndex, XFA_Element::Unknown,
5271 m_pAttachNode->GetElementType() == XFA_Element::Subform);
5272 }
OLDNEW
« no previous file with comments | « xfa/fxfa/parser/cxfa_thisproxy.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698