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