Merge to XFA: Use stdint.h types throughout PDFium.
[pdfium.git] / xfa / src / fxfa / src / parser / xfa_object_imp.cpp
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4 \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #include "../../../foxitlib.h"\r
8 #include "../common/xfa_utils.h"\r
9 #include "../common/xfa_object.h"\r
10 #include "../common/xfa_document.h"\r
11 #include "../common/xfa_parser.h"\r
12 #include "../common/xfa_script.h"\r
13 #include "../common/xfa_docdata.h"\r
14 #include "../common/xfa_doclayout.h"\r
15 #include "../common/xfa_debug.h"\r
16 #include "../common/xfa_localemgr.h"\r
17 #include "../common/xfa_fm2jsapi.h"\r
18 #include "xfa_debug_parser.h"\r
19 #include "xfa_basic_imp.h"\r
20 #include "xfa_document_layout_imp.h"\r
21 CXFA_Object::CXFA_Object(CXFA_Document* pDocument, FX_DWORD uFlags)\r
22     : m_pDocument(pDocument)\r
23     , m_uFlags(uFlags)\r
24 {\r
25 }\r
26 void CXFA_Object::GetClassName(CFX_WideStringC &wsName) const\r
27 {\r
28     XFA_LPCELEMENTINFO pElement = XFA_GetElementByID(GetClassID());\r
29     ASSERT(pElement != NULL);\r
30     wsName = pElement->pName;\r
31 }\r
32 uint32_t CXFA_Object::GetClassHashCode() const\r
33 {\r
34     XFA_LPCELEMENTINFO pElement = XFA_GetElementByID(GetClassID());\r
35     ASSERT(pElement != NULL);\r
36     return pElement->uHash;\r
37 }\r
38 XFA_ELEMENT CXFA_Object::GetClassID() const\r
39 {\r
40     if (IsNode()) {\r
41         return ((const CXFA_Node*)this)->GetClassID();\r
42     } else if(IsOrdinaryObject()) {\r
43         return ((const CXFA_OrdinaryObject*)this)->GetClassID();\r
44     } else if(IsNodeList()) {\r
45         return ((const CXFA_NodeList*)this)->GetClassID();\r
46     } else if(IsOrdinaryList()) {\r
47         return XFA_ELEMENT_List;\r
48     }\r
49     ASSERT(FALSE);\r
50     return (XFA_ELEMENT)0;\r
51 }\r
52 void CXFA_Object::Script_ObjectClass_ClassName(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
53 {\r
54     if (!bSetting) {\r
55         CFX_WideStringC className;\r
56         GetClassName(className);\r
57         FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(className.GetPtr(), className.GetLength()));\r
58     } else {\r
59         ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);\r
60     }\r
61 }\r
62 void CXFA_Object::ThrowScriptErrorMessage(int32_t iStringID, ...)\r
63 {\r
64     IXFA_AppProvider* pAppProvider = m_pDocument->GetNotify()->GetAppProvider();\r
65     FXSYS_assert(pAppProvider);\r
66     CFX_WideString wsFormat;\r
67     pAppProvider->LoadString(iStringID, wsFormat);\r
68     CFX_WideString wsMessage;\r
69     va_list arg_ptr;\r
70     va_start(arg_ptr, iStringID);\r
71     wsMessage.FormatV((FX_LPCWSTR)wsFormat, arg_ptr);\r
72     va_end(arg_ptr);\r
73     FXJSE_ThrowMessage(FX_BSTRC(""), FX_UTF8Encode(wsMessage, wsMessage.GetLength()));\r
74 }\r
75 static void XFA_DeleteWideString(FX_LPVOID pData)\r
76 {\r
77     if (pData) {\r
78         delete (CFX_WideString*)pData;\r
79     }\r
80 }\r
81 static void XFA_CopyWideString(FX_LPVOID& pData)\r
82 {\r
83     if (pData) {\r
84         CFX_WideString* pNewData = FX_NEW CFX_WideString(*(CFX_WideString*)pData);\r
85         pData = pNewData;\r
86     }\r
87 }\r
88 static XFA_MAPDATABLOCKCALLBACKINFO deleteWideStringCallBack = {XFA_DeleteWideString, XFA_CopyWideString};\r
89 static XFA_OBJECTTYPE XFA_GetElementObjectType(XFA_ELEMENT eElement)\r
90 {\r
91     XFA_LPCELEMENTINFO pElement = XFA_GetElementByID(eElement);\r
92     ASSERT(pElement != NULL);\r
93     return (XFA_OBJECTTYPE)pElement->eObjectType;\r
94 }\r
95 CXFA_Node::CXFA_Node(CXFA_Document *pDoc, FX_WORD ePacket, XFA_ELEMENT eElement)\r
96     : CXFA_Object(pDoc, XFA_GetElementObjectType(eElement))\r
97     , m_pParent(NULL)\r
98     , m_pNext(NULL)\r
99     , m_pChild(NULL)\r
100     , m_pLastChild(NULL)\r
101     , m_pXMLNode(NULL)\r
102     , m_ePacket(ePacket)\r
103     , m_eNodeClass(eElement)\r
104     , m_dwNameHash(0)\r
105     , m_pAuxNode(NULL)\r
106     , m_pMapModuleData(NULL)\r
107 {\r
108     ASSERT(m_pDocument != NULL);\r
109 }\r
110 CXFA_Node::~CXFA_Node()\r
111 {\r
112     FXSYS_assert(m_pParent == NULL);\r
113     RemoveMapModuleKey();\r
114     CXFA_Node *pNext, *pNode = m_pChild;\r
115     while (pNode) {\r
116         pNext = pNode->m_pNext;\r
117         pNode->m_pParent = NULL;\r
118         delete pNode;\r
119         pNode = pNext;\r
120     }\r
121     if (m_pXMLNode && HasFlag(XFA_NODEFLAG_OwnXMLNode)) {\r
122         m_pXMLNode->Release();\r
123     }\r
124 }\r
125 CXFA_Node* CXFA_Node::Clone(FX_BOOL bRecursive)\r
126 {\r
127     IXFA_ObjFactory *pFactory = m_pDocument->GetParser()->GetFactory();\r
128     CXFA_Node *pClone = pFactory->CreateNode(m_ePacket, m_eNodeClass);\r
129     if(!pClone) {\r
130         return NULL;\r
131     }\r
132     MergeAllData(pClone);\r
133     pClone->UpdateNameHash();\r
134     if (IsNeedSavingXMLNode()) {\r
135         IFDE_XMLNode* pCloneXML = NULL;\r
136         if (IsAttributeInXML()) {\r
137             CFX_WideString wsName;\r
138             this->GetAttribute(XFA_ATTRIBUTE_Name, wsName, FALSE);\r
139             IFDE_XMLElement* pCloneXMLElement = IFDE_XMLElement::Create(wsName);\r
140             CFX_WideStringC wsValue = this->GetCData(XFA_ATTRIBUTE_Value);\r
141             if (!wsValue.IsEmpty()) {\r
142                 pCloneXMLElement->SetTextData(wsValue);\r
143             }\r
144             pCloneXML = pCloneXMLElement;\r
145             pCloneXMLElement = NULL;\r
146             pClone->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);\r
147         } else {\r
148             pCloneXML = m_pXMLNode->Clone(FALSE);\r
149         }\r
150         pClone->SetXMLMappingNode(pCloneXML);\r
151         pClone->SetFlag(XFA_NODEFLAG_OwnXMLNode, TRUE, FALSE);\r
152     }\r
153     if (bRecursive) {\r
154         for(CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild; pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {\r
155             pClone->InsertChild(pChild->Clone(bRecursive));\r
156         }\r
157     }\r
158     pClone->SetFlag(XFA_NODEFLAG_Initialized);\r
159     pClone->SetObject(XFA_ATTRIBUTE_BindingNode, NULL);\r
160     return pClone;\r
161 }\r
162 CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem) const\r
163 {\r
164     switch (eItem) {\r
165         case XFA_NODEITEM_NextSibling:\r
166             return m_pNext;\r
167         case XFA_NODEITEM_FirstChild:\r
168             return m_pChild;\r
169         case XFA_NODEITEM_Parent:\r
170             return m_pParent;\r
171         case XFA_NODEITEM_PrevSibling:\r
172             if (m_pParent) {\r
173                 CXFA_Node *pSibling = m_pParent->m_pChild;\r
174                 CXFA_Node *pPrev = NULL;\r
175                 while (pSibling && pSibling != this) {\r
176                     pPrev = pSibling;\r
177                     pSibling = pSibling->m_pNext;\r
178                 }\r
179                 return pPrev;\r
180             }\r
181             return NULL;\r
182         default:\r
183             break;\r
184     }\r
185     return NULL;\r
186 }\r
187 CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem, XFA_OBJECTTYPE eType) const\r
188 {\r
189     CXFA_Node *pNode = NULL;\r
190     switch (eItem) {\r
191         case XFA_NODEITEM_NextSibling:\r
192             pNode = m_pNext;\r
193             if (eType != XFA_OBJECTTYPEMASK)\r
194                 while (pNode && pNode->GetObjectType() != eType) {\r
195                     pNode = pNode->m_pNext;\r
196                 }\r
197             break;\r
198         case XFA_NODEITEM_FirstChild:\r
199             pNode = m_pChild;\r
200             if (eType != XFA_OBJECTTYPEMASK)\r
201                 while (pNode && pNode->GetObjectType() != eType) {\r
202                     pNode = pNode->m_pNext;\r
203                 }\r
204             break;\r
205         case XFA_NODEITEM_Parent:\r
206             pNode = m_pParent;\r
207             if (eType != XFA_OBJECTTYPEMASK)\r
208                 while (pNode && pNode->GetObjectType() != eType) {\r
209                     pNode = pNode->m_pParent;\r
210                 }\r
211             break;\r
212         case XFA_NODEITEM_PrevSibling:\r
213             if (m_pParent) {\r
214                 CXFA_Node *pSibling = m_pParent->m_pChild;\r
215                 while (pSibling && pSibling != this) {\r
216                     if (eType == XFA_OBJECTTYPEMASK || eType == pSibling->GetObjectType()) {\r
217                         pNode = pSibling;\r
218                     }\r
219                     pSibling = pSibling->m_pNext;\r
220                 }\r
221             }\r
222             break;\r
223         default:\r
224             break;\r
225     }\r
226     return pNode;\r
227 }\r
228 int32_t CXFA_Node::GetNodeList(CXFA_NodeArray &nodes, FX_DWORD dwTypeFilter , XFA_ELEMENT eElementFilter , int32_t iLevel )\r
229 {\r
230     if (--iLevel < 0) {\r
231         return nodes.GetSize();\r
232     }\r
233     if (eElementFilter != XFA_ELEMENT_UNKNOWN) {\r
234         CXFA_Node *pChild = m_pChild;\r
235         while (pChild) {\r
236             if (pChild->GetClassID() == eElementFilter) {\r
237                 nodes.Add(pChild);\r
238                 if (iLevel > 0) {\r
239                     GetNodeList(nodes, dwTypeFilter, eElementFilter, iLevel);\r
240                 }\r
241             }\r
242             pChild = pChild->m_pNext;\r
243         }\r
244     } else if (dwTypeFilter == (XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties)) {\r
245         CXFA_Node *pChild = m_pChild;\r
246         while (pChild) {\r
247             nodes.Add(pChild);\r
248             if (iLevel > 0) {\r
249                 GetNodeList(nodes, dwTypeFilter, eElementFilter, iLevel);\r
250             }\r
251             pChild = pChild->m_pNext;\r
252         }\r
253     } else if (dwTypeFilter != 0) {\r
254         FX_BOOL bFilterChildren = (dwTypeFilter & XFA_NODEFILTER_Children) != 0;\r
255         FX_BOOL bFilterProperties = (dwTypeFilter & XFA_NODEFILTER_Properties) != 0;\r
256         FX_BOOL bFilterOneOfProperties = (dwTypeFilter & XFA_NODEFILTER_OneOfProperty) != 0;\r
257         CXFA_Node *pChild = m_pChild;\r
258         while (pChild) {\r
259             XFA_LPCPROPERTY pPropert = XFA_GetPropertyOfElement(GetClassID(), pChild->GetClassID(), XFA_XDPPACKET_UNKNOWN);\r
260             if (pPropert) {\r
261                 if (bFilterProperties) {\r
262                     nodes.Add(pChild);\r
263                 } else if (bFilterOneOfProperties && (pPropert->uFlags & XFA_PROPERTYFLAG_OneOf)) {\r
264                     nodes.Add(pChild);\r
265                 } else if(bFilterChildren && (pChild->GetClassID() == XFA_ELEMENT_Variables || pChild->GetClassID() == XFA_ELEMENT_PageSet)) {\r
266                     nodes.Add(pChild);\r
267                 }\r
268             } else {\r
269                 if (bFilterChildren) {\r
270                     nodes.Add(pChild);\r
271                 }\r
272             }\r
273             pChild = pChild->m_pNext;\r
274         }\r
275         if (bFilterOneOfProperties && nodes.GetSize() < 1) {\r
276             int32_t iProperties = 0;\r
277             XFA_LPCPROPERTY pProperty = XFA_GetElementProperties(GetClassID(), iProperties);\r
278             if (pProperty == NULL || iProperties < 1) {\r
279                 return 0;\r
280             }\r
281             for (int32_t i = 0; i < iProperties; i++) {\r
282                 if (pProperty[i].uFlags & XFA_PROPERTYFLAG_DefaultOneOf) {\r
283                     IXFA_ObjFactory *pFactory = m_pDocument->GetParser()->GetFactory();\r
284                     XFA_LPCPACKETINFO pPacket = XFA_GetPacketByID(GetPacketID());\r
285                     CXFA_Node* pNewNode = pFactory->CreateNode(pPacket, (XFA_ELEMENT)pProperty[i].eName);\r
286                     if(!pNewNode) {\r
287                         break;\r
288                     }\r
289                     InsertChild(pNewNode, NULL);\r
290                     pNewNode->SetFlag(XFA_NODEFLAG_Initialized);\r
291                     nodes.Add(pNewNode);\r
292                     break;\r
293                 }\r
294             }\r
295         }\r
296     }\r
297     return nodes.GetSize();\r
298 }\r
299 CXFA_Node* CXFA_Node::CreateSamePacketNode(XFA_ELEMENT eElement, FX_DWORD dwFlags)\r
300 {\r
301     IXFA_ObjFactory *pFactory = m_pDocument->GetParser()->GetFactory();\r
302     CXFA_Node* pNode = pFactory->CreateNode(m_ePacket, eElement);\r
303     pNode->SetFlag(dwFlags);\r
304     return pNode;\r
305 }\r
306 CXFA_Node* CXFA_Node::CloneTemplateToForm(FX_BOOL bRecursive)\r
307 {\r
308     FXSYS_assert(m_ePacket == XFA_XDPPACKET_Template);\r
309     IXFA_ObjFactory *pFactory = m_pDocument->GetParser()->GetFactory();\r
310     CXFA_Node *pClone = pFactory->CreateNode(XFA_XDPPACKET_Form, m_eNodeClass);\r
311     if(!pClone) {\r
312         return NULL;\r
313     }\r
314     pClone->SetTemplateNode(this);\r
315     pClone->UpdateNameHash();\r
316     pClone->SetXMLMappingNode(GetXMLMappingNode());\r
317     if (bRecursive) {\r
318         for(CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild; pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {\r
319             pClone->InsertChild(pChild->CloneTemplateToForm(bRecursive));\r
320         }\r
321     }\r
322     pClone->SetFlag(XFA_NODEFLAG_Initialized);\r
323     return pClone;\r
324 }\r
325 CXFA_Node* CXFA_Node::GetTemplateNode()\r
326 {\r
327     return m_pAuxNode;\r
328 }\r
329 void CXFA_Node::SetTemplateNode(CXFA_Node* pTemplateNode)\r
330 {\r
331     m_pAuxNode = pTemplateNode;\r
332 }\r
333 CXFA_Node* CXFA_Node::GetBindData()\r
334 {\r
335     ASSERT(GetPacketID() == XFA_XDPPACKET_Form);\r
336     return (CXFA_Node*)GetObject(XFA_ATTRIBUTE_BindingNode);\r
337 }\r
338 int32_t CXFA_Node::GetBindItems(CXFA_NodeArray& formItems)\r
339 {\r
340     if (m_uFlags & XFA_NODEFLAG_BindFormItems) {\r
341         CXFA_NodeArray* pItems = NULL;\r
342         TryObject(XFA_ATTRIBUTE_BindingNode, (FX_LPVOID&)pItems);\r
343         formItems.Copy(*pItems);\r
344         return formItems.GetSize();\r
345     }\r
346     CXFA_Node* pFormNode = (CXFA_Node*)GetObject(XFA_ATTRIBUTE_BindingNode);\r
347     if (pFormNode) {\r
348         formItems.Add(pFormNode);\r
349     }\r
350     return formItems.GetSize();\r
351 }\r
352 static void XFA_DataNodeDeleteBindItem(FX_LPVOID pData)\r
353 {\r
354     if (pData) {\r
355         delete ((CXFA_NodeArray*)pData);\r
356     }\r
357 }\r
358 static XFA_MAPDATABLOCKCALLBACKINFO deleteBindItemCallBack = {XFA_DataNodeDeleteBindItem, NULL};\r
359 int32_t CXFA_Node::AddBindItem(CXFA_Node* pFormNode)\r
360 {\r
361     ASSERT(pFormNode);\r
362     if (m_uFlags & XFA_NODEFLAG_BindFormItems) {\r
363         CXFA_NodeArray* pItems = NULL;\r
364         TryObject(XFA_ATTRIBUTE_BindingNode, (FX_LPVOID&)pItems);\r
365         ASSERT(pItems);\r
366         if (pItems->Find(pFormNode) < 0) {\r
367             pItems->Add(pFormNode);\r
368         }\r
369         return pItems->GetSize();\r
370     }\r
371     CXFA_Node* pOldFormItem = (CXFA_Node*)GetObject(XFA_ATTRIBUTE_BindingNode);\r
372     if (!pOldFormItem) {\r
373         SetObject(XFA_ATTRIBUTE_BindingNode, pFormNode);\r
374         return 1;\r
375     } else if (pOldFormItem == pFormNode) {\r
376         return 1;\r
377     }\r
378     CXFA_NodeArray* pItems = FX_NEW CXFA_NodeArray;\r
379     SetObject(XFA_ATTRIBUTE_BindingNode, pItems, &deleteBindItemCallBack);\r
380     pItems->Add(pOldFormItem);\r
381     pItems->Add(pFormNode);\r
382     m_uFlags |= XFA_NODEFLAG_BindFormItems;\r
383     return 2;\r
384 }\r
385 int32_t CXFA_Node::RemoveBindItem(CXFA_Node* pFormNode)\r
386 {\r
387     if (m_uFlags & XFA_NODEFLAG_BindFormItems) {\r
388         CXFA_NodeArray* pItems = NULL;\r
389         TryObject(XFA_ATTRIBUTE_BindingNode, (FX_LPVOID&)pItems);\r
390         ASSERT(pItems);\r
391         int32_t iIndex = pItems->Find(pFormNode);\r
392         int32_t iCount = pItems->GetSize();\r
393         if (iIndex >= 0) {\r
394             if (iIndex != iCount - 1) {\r
395                 pItems->SetAt(iIndex, pItems->GetAt(iCount - 1));\r
396             }\r
397             pItems->RemoveAt(iCount - 1);\r
398             if (iCount == 2) {\r
399                 CXFA_Node* pLastFormNode = pItems->GetAt(0);\r
400                 SetObject(XFA_ATTRIBUTE_BindingNode, pLastFormNode);\r
401                 m_uFlags &= ~XFA_NODEFLAG_BindFormItems;\r
402             }\r
403             iCount--;\r
404         }\r
405         return iCount;\r
406     }\r
407     CXFA_Node* pOldFormItem = (CXFA_Node*)GetObject(XFA_ATTRIBUTE_BindingNode);\r
408     if(pOldFormItem == pFormNode) {\r
409         SetObject(XFA_ATTRIBUTE_BindingNode, NULL);\r
410         pOldFormItem = NULL;\r
411     }\r
412     return pOldFormItem == NULL ? 0 : 1;\r
413 }\r
414 FX_BOOL CXFA_Node::HasBindItem()\r
415 {\r
416     return (GetPacketID() == XFA_XDPPACKET_Datasets) && GetObject(XFA_ATTRIBUTE_BindingNode) != NULL;\r
417 }\r
418 CXFA_WidgetData* CXFA_Node::GetWidgetData()\r
419 {\r
420     return (CXFA_WidgetData*)GetObject(XFA_ATTRIBUTE_WidgetData);\r
421 }\r
422 CXFA_WidgetData* CXFA_Node::GetContainerWidgetData()\r
423 {\r
424     if (GetPacketID() != XFA_XDPPACKET_Form) {\r
425         return NULL;\r
426     }\r
427     XFA_ELEMENT classID = GetClassID();\r
428     if (classID == XFA_ELEMENT_ExclGroup) {\r
429         return NULL;\r
430     }\r
431     CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);\r
432     if (pParentNode && pParentNode->GetClassID() == XFA_ELEMENT_ExclGroup) {\r
433         return NULL;\r
434     }\r
435     if (classID == XFA_ELEMENT_Field) {\r
436         CXFA_WidgetData* pFieldWidgetData = this->GetWidgetData();\r
437         if (pFieldWidgetData && pFieldWidgetData->GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) {\r
438             return NULL;\r
439         } else {\r
440             CFX_WideString wsPicture;\r
441             if (pFieldWidgetData) {\r
442                 pFieldWidgetData->GetPictureContent(wsPicture, XFA_VALUEPICTURE_DataBind);\r
443             }\r
444             if (!wsPicture.IsEmpty()) {\r
445                 return pFieldWidgetData;\r
446             }\r
447             CXFA_Node* pDataNode = this->GetBindData();\r
448             if (!pDataNode) {\r
449                 return NULL;\r
450             }\r
451             pFieldWidgetData = NULL;\r
452             CXFA_NodeArray formNodes;\r
453             pDataNode->GetBindItems(formNodes);\r
454             for (int32_t i = 0; i < formNodes.GetSize(); i++) {\r
455                 CXFA_Node* pFormNode = formNodes.GetAt(i);\r
456                 if (!pFormNode || pFormNode->HasFlag(XFA_NODEFLAG_HasRemoved)) {\r
457                     continue;\r
458                 }\r
459                 pFieldWidgetData = pFormNode->GetWidgetData();\r
460                 if (pFieldWidgetData) {\r
461                     pFieldWidgetData->GetPictureContent(wsPicture, XFA_VALUEPICTURE_DataBind);\r
462                 }\r
463                 if (!wsPicture.IsEmpty()) {\r
464                     break;\r
465                 }\r
466                 pFieldWidgetData = NULL;\r
467             }\r
468             return pFieldWidgetData;\r
469         }\r
470     }\r
471     CXFA_Node* pGrandNode = pParentNode ? pParentNode->GetNodeItem(XFA_NODEITEM_Parent) : NULL;\r
472     CXFA_Node* pValueNode = (pParentNode && pParentNode->GetClassID() == XFA_ELEMENT_Value) ? pParentNode : NULL;\r
473     if (!pValueNode) {\r
474         pValueNode = (pGrandNode && pGrandNode->GetClassID() == XFA_ELEMENT_Value) ? pGrandNode : NULL;\r
475     }\r
476     CXFA_Node* pParentOfValueNode = pValueNode ? pValueNode->GetNodeItem(XFA_NODEITEM_Parent) : NULL;\r
477     return pParentOfValueNode ? pParentOfValueNode->GetContainerWidgetData() : NULL;\r
478 }\r
479 FX_BOOL CXFA_Node::GetLocaleName(CFX_WideString& wsLocaleName)\r
480 {\r
481     CXFA_Node* pForm = (CXFA_Node*)GetDocument()->GetXFANode(XFA_HASHCODE_Form);\r
482     CXFA_Node* pTopSubform = pForm->GetFirstChildByClass(XFA_ELEMENT_Subform);\r
483     FXSYS_assert(pTopSubform);\r
484     CXFA_Node* pLocaleNode = this;\r
485     FX_BOOL bLocale = FALSE;\r
486     do {\r
487         bLocale = pLocaleNode->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, FALSE);\r
488         if (!bLocale) {\r
489             pLocaleNode = pLocaleNode->GetNodeItem(XFA_NODEITEM_Parent);\r
490         }\r
491     } while (pLocaleNode && pLocaleNode != pTopSubform && !bLocale);\r
492     if (bLocale) {\r
493         return bLocale;\r
494     }\r
495     CXFA_Node* pConfig = (CXFA_Node*)GetDocument()->GetXFANode(XFA_HASHCODE_Config);\r
496     wsLocaleName = GetDocument()->GetLocalMgr()->GetConfigLocaleName(pConfig);\r
497     if (!wsLocaleName.IsEmpty()) {\r
498         bLocale = TRUE;\r
499     }\r
500     if (bLocale) {\r
501         return bLocale;\r
502     }\r
503     if (pTopSubform) {\r
504         bLocale = pTopSubform->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, FALSE);\r
505     }\r
506     if (bLocale) {\r
507         return bLocale;\r
508     }\r
509     IFX_Locale* pLocale = GetDocument()->GetLocalMgr()->GetDefLocale();\r
510     if (pLocale) {\r
511         wsLocaleName = pLocale->GetName();\r
512         bLocale = TRUE;\r
513     }\r
514     return bLocale;\r
515 }\r
516 XFA_ATTRIBUTEENUM CXFA_Node::GetIntact()\r
517 {\r
518     XFA_ELEMENT eElement = GetClassID();\r
519     CXFA_Node* pKeep = GetFirstChildByClass(XFA_ELEMENT_Keep);\r
520     XFA_ATTRIBUTEENUM eLayoutType = GetEnum(XFA_ATTRIBUTE_Layout);\r
521     if (pKeep) {\r
522         XFA_ATTRIBUTEENUM eIntact;\r
523         if (pKeep->TryEnum(XFA_ATTRIBUTE_Intact, eIntact, FALSE)) {\r
524             if(eIntact == XFA_ATTRIBUTEENUM_None && eLayoutType == XFA_ATTRIBUTEENUM_Row &&  m_pDocument->GetCurVersionMode() < XFA_VERSION_208) {\r
525                 CXFA_Node* pPreviewRow = GetNodeItem(XFA_NODEITEM_PrevSibling, XFA_OBJECTTYPE_ContainerNode);\r
526                 if(pPreviewRow && pPreviewRow->GetEnum(XFA_ATTRIBUTE_Layout) == XFA_ATTRIBUTEENUM_Row) {\r
527                     XFA_ATTRIBUTEENUM eValue;\r
528                     if(pKeep->TryEnum(XFA_ATTRIBUTE_Previous, eValue, FALSE)) {\r
529                         if(eValue == XFA_ATTRIBUTEENUM_ContentArea || eValue == XFA_ATTRIBUTEENUM_PageArea) {\r
530                             return XFA_ATTRIBUTEENUM_ContentArea;\r
531                         }\r
532                     }\r
533                     CXFA_Node* pKeep = pPreviewRow->GetFirstChildByClass(XFA_ELEMENT_Keep);\r
534                     if (pKeep) {\r
535                         if (pKeep->TryEnum(XFA_ATTRIBUTE_Next, eValue, FALSE)) {\r
536                             if(eValue == XFA_ATTRIBUTEENUM_ContentArea || eValue == XFA_ATTRIBUTEENUM_PageArea) {\r
537                                 return XFA_ATTRIBUTEENUM_ContentArea;\r
538                             }\r
539                         }\r
540                     }\r
541                 }\r
542             }\r
543             return eIntact;\r
544         }\r
545     }\r
546     switch (eElement) {\r
547         case XFA_ELEMENT_Subform:\r
548             switch (eLayoutType) {\r
549                 case XFA_ATTRIBUTEENUM_Position:\r
550                 case XFA_ATTRIBUTEENUM_Row:\r
551                     return XFA_ATTRIBUTEENUM_ContentArea;\r
552                 case XFA_ATTRIBUTEENUM_Tb:\r
553                 case XFA_ATTRIBUTEENUM_Table:\r
554                 case XFA_ATTRIBUTEENUM_Lr_tb:\r
555                 case XFA_ATTRIBUTEENUM_Rl_tb:\r
556                     return XFA_ATTRIBUTEENUM_None;\r
557                 default:\r
558                     break;\r
559             }\r
560             break;\r
561         case XFA_ELEMENT_Field: {\r
562                 CXFA_Node* pParentNode = this->GetNodeItem(XFA_NODEITEM_Parent);\r
563                 if (!pParentNode || pParentNode->GetClassID() == XFA_ELEMENT_PageArea) {\r
564                     return XFA_ATTRIBUTEENUM_ContentArea;\r
565                 }\r
566                 if (pParentNode->GetIntact() == XFA_ATTRIBUTEENUM_None) {\r
567                     XFA_ATTRIBUTEENUM eParLayout = pParentNode->GetEnum(XFA_ATTRIBUTE_Layout);\r
568                     if (eParLayout == XFA_ATTRIBUTEENUM_Position || eParLayout == XFA_ATTRIBUTEENUM_Row || eParLayout == XFA_ATTRIBUTEENUM_Table) {\r
569                         return XFA_ATTRIBUTEENUM_None;\r
570                     }\r
571                     XFA_VERSION version = m_pDocument->GetCurVersionMode();\r
572                     if (eParLayout == XFA_ATTRIBUTEENUM_Tb && version < XFA_VERSION_208) {\r
573                         CXFA_Measurement measureH;\r
574                         if (this->TryMeasure(XFA_ATTRIBUTE_H, measureH, FALSE)) {\r
575                             return XFA_ATTRIBUTEENUM_ContentArea;\r
576                         }\r
577                     }\r
578                     return XFA_ATTRIBUTEENUM_None;\r
579                 }\r
580                 return XFA_ATTRIBUTEENUM_ContentArea;\r
581             }\r
582         case XFA_ELEMENT_Draw:\r
583             return XFA_ATTRIBUTEENUM_ContentArea;\r
584         default:\r
585             break;\r
586     }\r
587     return XFA_ATTRIBUTEENUM_None;\r
588 }\r
589 CXFA_Node* CXFA_Node::GetDataDescriptionNode()\r
590 {\r
591     if(m_ePacket == XFA_XDPPACKET_Datasets) {\r
592         return m_pAuxNode;\r
593     }\r
594     return NULL;\r
595 }\r
596 void CXFA_Node::SetDataDescriptionNode(CXFA_Node* pDataDescriptionNode)\r
597 {\r
598     FXSYS_assert(m_ePacket == XFA_XDPPACKET_Datasets);\r
599     m_pAuxNode = pDataDescriptionNode;\r
600 }\r
601 void CXFA_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments)\r
602 {\r
603     int32_t iLength = pArguments->GetLength();\r
604     if (iLength != 1) {\r
605         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resolveNode");\r
606         return;\r
607     }\r
608     CFX_WideString wsExpression;\r
609     CFX_ByteString bsExpression = pArguments->GetUTF8String(0);\r
610     wsExpression = CFX_WideString::FromUTF8(bsExpression, bsExpression.GetLength());\r
611     IXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();\r
612     if (!pScriptContext) {\r
613         return;\r
614     }\r
615     CXFA_Node* refNode = this;\r
616     if(refNode->GetClassID() == XFA_ELEMENT_Xfa) {\r
617         refNode = (CXFA_Node*)pScriptContext->GetThisObject();\r
618     }\r
619     FX_DWORD dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings;\r
620     XFA_RESOLVENODE_RS resoveNodeRS;\r
621     int32_t iRet = pScriptContext->ResolveObjects(refNode, wsExpression, resoveNodeRS, dwFlag);\r
622     if (iRet < 1) {\r
623         return FXJSE_Value_SetNull(pArguments->GetReturnValue());\r
624     }\r
625     FXJSE_HVALUE hValue = NULL;\r
626     if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {\r
627         CXFA_Object* pNode = resoveNodeRS.nodes[0];\r
628         hValue = pScriptContext->GetJSValueFromMap(pNode);\r
629         FXJSE_Value_Set(pArguments->GetReturnValue(), hValue);\r
630     } else {\r
631         XFA_LPCSCRIPTATTRIBUTEINFO lpAttributeInfo = resoveNodeRS.pScriptAttribute;\r
632         if (lpAttributeInfo && lpAttributeInfo->eValueType == XFA_SCRIPT_Object) {\r
633             hValue = FXJSE_Value_Create(pScriptContext->GetRuntime());\r
634             (resoveNodeRS.nodes[0]->*(lpAttributeInfo->lpfnCallback))(hValue, FALSE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute);\r
635             FXJSE_Value_Set(pArguments->GetReturnValue(), hValue);\r
636             FXJSE_Value_Release(hValue);\r
637         } else {\r
638             FXJSE_Value_SetNull(pArguments->GetReturnValue());\r
639         }\r
640     }\r
641 }\r
642 void CXFA_Node::Script_TreeClass_ResolveNodes(CFXJSE_Arguments* pArguments)\r
643 {\r
644     int32_t iLength = pArguments->GetLength();\r
645     if (iLength != 1) {\r
646         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resolveNodes");\r
647         return;\r
648     }\r
649     CFX_WideString wsExpression;\r
650     CFX_ByteString bsExpression = pArguments->GetUTF8String(0);\r
651     wsExpression = CFX_WideString::FromUTF8(bsExpression, bsExpression.GetLength());\r
652     FXJSE_HVALUE hValue =  pArguments->GetReturnValue();\r
653     if (!hValue) {\r
654         return;\r
655     }\r
656     FX_DWORD dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings;\r
657     CXFA_Node* refNode = this;\r
658     if(refNode->GetClassID() == XFA_ELEMENT_Xfa) {\r
659         refNode = (CXFA_Node*)m_pDocument->GetScriptContext()->GetThisObject();\r
660     }\r
661     Script_Som_ResolveNodeList(hValue, wsExpression, dwFlag, refNode);\r
662 }\r
663 void CXFA_Node::Script_Som_ResolveNodeList(FXJSE_HVALUE hValue, CFX_WideString wsExpression, FX_DWORD dwFlag, CXFA_Node* refNode)\r
664 {\r
665     IXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();\r
666     if (!pScriptContext) {\r
667         return;\r
668     }\r
669     XFA_RESOLVENODE_RS resoveNodeRS;\r
670     if(refNode == NULL) {\r
671         refNode = this;\r
672     }\r
673     int32_t iRet = pScriptContext->ResolveObjects(refNode, wsExpression, resoveNodeRS, dwFlag);\r
674     CXFA_ArrayNodeList* pNodeList = FX_NEW CXFA_ArrayNodeList(m_pDocument);\r
675     if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {\r
676         for (int32_t i = 0; i < resoveNodeRS.nodes.GetSize(); i++) {\r
677             if (resoveNodeRS.nodes[i]->IsNode()) {\r
678                 pNodeList->Append((CXFA_Node*)resoveNodeRS.nodes[i]);\r
679             }\r
680         }\r
681     } else {\r
682         CXFA_HVALUEArray hValueArray(pScriptContext->GetRuntime());\r
683         if (resoveNodeRS.GetAttributeResult(hValueArray) > 0) {\r
684             CXFA_ObjArray objectArray;\r
685             hValueArray.GetAttributeObject(objectArray);\r
686             for (int32_t i = 0; i < objectArray.GetSize(); i++) {\r
687                 if (objectArray[i]->IsNode()) {\r
688                     pNodeList->Append((CXFA_Node*)objectArray[i]);\r
689                 }\r
690             }\r
691         }\r
692     }\r
693     FXJSE_Value_SetObject(hValue, (CXFA_Object*)pNodeList, pScriptContext->GetJseNormalClass());\r
694 }\r
695 void CXFA_Node::Script_TreeClass_All(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
696 {\r
697     if (bSetting) {\r
698         ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);\r
699     } else {\r
700         FX_DWORD dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;\r
701         CFX_WideString wsName;\r
702         GetAttribute(XFA_ATTRIBUTE_Name, wsName);\r
703         CFX_WideString wsExpression = wsName + FX_WSTRC(L"[*]");\r
704         Script_Som_ResolveNodeList(hValue, wsExpression, dwFlag);\r
705     }\r
706 }\r
707 void CXFA_Node::Script_TreeClass_Nodes(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
708 {\r
709     IXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();\r
710     if (!pScriptContext) {\r
711         return;\r
712     }\r
713     if (bSetting) {\r
714         IXFA_AppProvider* pAppProvider = m_pDocument->GetNotify()->GetAppProvider();\r
715         FXSYS_assert(pAppProvider);\r
716         CFX_WideString wsMessage;\r
717         pAppProvider->LoadString(XFA_IDS_Unable_TO_SET, wsMessage);\r
718         FXJSE_ThrowMessage(FX_BSTRC(""), FX_UTF8Encode(wsMessage, wsMessage.GetLength()));\r
719     } else {\r
720         CXFA_AttachNodeList* pNodeList = FX_NEW CXFA_AttachNodeList(m_pDocument, this);\r
721         FXJSE_Value_SetObject(hValue, (CXFA_Object*)pNodeList, pScriptContext->GetJseNormalClass());\r
722     }\r
723 }\r
724 void CXFA_Node::Script_TreeClass_ClassAll(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
725 {\r
726     if (bSetting) {\r
727         ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);\r
728     } else {\r
729         FX_DWORD dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;\r
730         CFX_WideStringC wsName;\r
731         this->GetClassName(wsName);\r
732         CFX_WideString wsExpression = FX_WSTRC(L"#") + wsName + FX_WSTRC(L"[*]");\r
733         Script_Som_ResolveNodeList(hValue, wsExpression, dwFlag);\r
734     }\r
735 }\r
736 void CXFA_Node::Script_TreeClass_Parent(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
737 {\r
738     if (bSetting) {\r
739         ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);\r
740     } else {\r
741         CXFA_Node* pParent = this->GetNodeItem(XFA_NODEITEM_Parent);\r
742         if (pParent) {\r
743             FXJSE_Value_Set(hValue, m_pDocument->GetScriptContext()->GetJSValueFromMap(pParent));\r
744         } else {\r
745             FXJSE_Value_SetNull(hValue);\r
746         }\r
747     }\r
748 }\r
749 void CXFA_Node::Script_TreeClass_Index(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
750 {\r
751     if (bSetting) {\r
752         ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);\r
753     } else {\r
754         FXJSE_Value_SetInteger(hValue, GetNodeSameNameIndex());\r
755     }\r
756 }\r
757 void CXFA_Node::Script_TreeClass_ClassIndex(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
758 {\r
759     if (bSetting) {\r
760         ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);\r
761     } else {\r
762         FXJSE_Value_SetInteger(hValue, GetNodeSameClassIndex());\r
763     }\r
764 }\r
765 void CXFA_Node::Script_TreeClass_SomExpression(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
766 {\r
767     if (bSetting) {\r
768         ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);\r
769     } else {\r
770         CFX_WideString wsSOMExpression;\r
771         GetSOMExpression(wsSOMExpression);\r
772         FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsSOMExpression));\r
773     }\r
774 }\r
775 void CXFA_Node::Script_NodeClass_ApplyXSL(CFXJSE_Arguments* pArguments)\r
776 {\r
777     int32_t iLength = pArguments->GetLength();\r
778     if (iLength != 1) {\r
779         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"applyXSL");\r
780         return;\r
781     }\r
782     CFX_WideString wsExpression;\r
783     CFX_ByteString bsExpression = pArguments->GetUTF8String(0);\r
784     wsExpression = CFX_WideString::FromUTF8(bsExpression, bsExpression.GetLength());\r
785 }\r
786 void CXFA_Node::Script_NodeClass_AssignNode(CFXJSE_Arguments* pArguments)\r
787 {\r
788     int32_t iLength = pArguments->GetLength();\r
789     if (iLength < 1 || iLength > 3) {\r
790         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"assignNode");\r
791         return;\r
792     }\r
793     CFX_WideString wsExpression;\r
794     CFX_WideString wsValue;\r
795     int32_t iAction = 0;\r
796     if (iLength >= 1) {\r
797         CFX_ByteString bsExpression = pArguments->GetUTF8String(0);\r
798         wsExpression = CFX_WideString::FromUTF8(bsExpression, bsExpression.GetLength());\r
799     }\r
800     if (iLength >= 2) {\r
801         CFX_ByteString bsValue = pArguments->GetUTF8String(1);\r
802         wsValue = CFX_WideString::FromUTF8(bsValue, bsValue.GetLength());\r
803     }\r
804     if (iLength >= 3) {\r
805         iAction = pArguments->GetInt32(2);\r
806     }\r
807 }\r
808 void CXFA_Node::Script_NodeClass_Clone(CFXJSE_Arguments* pArguments)\r
809 {\r
810     int32_t iLength = pArguments->GetLength();\r
811     if (iLength != 1) {\r
812         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"clone");\r
813         return;\r
814     }\r
815     FX_BOOL bClone = TRUE;\r
816     bClone = pArguments->GetInt32(0) == 0 ? FALSE : TRUE;\r
817     CXFA_Node* pCloneNode = this->Clone(bClone);\r
818     FXJSE_Value_Set(pArguments->GetReturnValue(), m_pDocument->GetScriptContext()->GetJSValueFromMap(pCloneNode));\r
819 }\r
820 void CXFA_Node::Script_NodeClass_GetAttribute(CFXJSE_Arguments* pArguments)\r
821 {\r
822     int32_t iLength = pArguments->GetLength();\r
823     if (iLength != 1) {\r
824         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getAttribute");\r
825         return;\r
826     }\r
827     CFX_WideString wsExpression;\r
828     CFX_ByteString bsExpression = pArguments->GetUTF8String(0);\r
829     wsExpression = CFX_WideString::FromUTF8(bsExpression, bsExpression.GetLength());\r
830     CFX_WideString wsValue;\r
831     this->GetAttribute(wsExpression, wsValue);\r
832     FXJSE_HVALUE hValue = pArguments->GetReturnValue();\r
833     if (hValue) {\r
834         FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsValue));\r
835     }\r
836 }\r
837 void CXFA_Node::Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments)\r
838 {\r
839     int32_t iLength = pArguments->GetLength();\r
840     if (iLength < 1 || iLength > 2) {\r
841         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getElement");\r
842         return;\r
843     }\r
844     CFX_WideString wsExpression;\r
845     int32_t iValue = 0;\r
846     if (iLength >= 1) {\r
847         CFX_ByteString bsExpression = pArguments->GetUTF8String(0);\r
848         wsExpression = CFX_WideString::FromUTF8(bsExpression, bsExpression.GetLength());\r
849     }\r
850     if (iLength >= 2) {\r
851         iValue = pArguments->GetInt32(1);\r
852     }\r
853     XFA_LPCELEMENTINFO pElementInfo = XFA_GetElementByName(wsExpression);\r
854     CXFA_Node* pNode = this->GetProperty(iValue, pElementInfo->eName);\r
855     FXJSE_Value_Set(pArguments->GetReturnValue(), m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode));\r
856 }\r
857 void CXFA_Node::Script_NodeClass_IsPropertySpecified(CFXJSE_Arguments* pArguments)\r
858 {\r
859     int32_t iLength = pArguments->GetLength();\r
860     if (iLength < 1 || iLength > 3) {\r
861         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isPropertySpecified");\r
862         return;\r
863     }\r
864     CFX_WideString wsExpression;\r
865     FX_BOOL bParent = TRUE;\r
866     int32_t iIndex = 0;\r
867     if (iLength >= 1) {\r
868         CFX_ByteString bsExpression = pArguments->GetUTF8String(0);\r
869         wsExpression = CFX_WideString::FromUTF8(bsExpression, bsExpression.GetLength());\r
870     }\r
871     if (iLength >= 2) {\r
872         bParent = pArguments->GetInt32(1) == 0 ? FALSE : TRUE;\r
873     }\r
874     if (iLength >= 3) {\r
875         iIndex = pArguments->GetInt32(2);\r
876     }\r
877     FX_BOOL bHas = FALSE;\r
878     XFA_LPCATTRIBUTEINFO pAttributeInfo = XFA_GetAttributeByName(wsExpression);\r
879     CFX_WideString wsValue;\r
880     if(pAttributeInfo) {\r
881         bHas = this->HasAttribute(pAttributeInfo->eName);\r
882     }\r
883     if (!bHas) {\r
884         XFA_LPCELEMENTINFO pElementInfo = XFA_GetElementByName(wsExpression);\r
885         bHas = (this->GetProperty(iIndex, pElementInfo->eName) != NULL);\r
886     }\r
887     FXJSE_HVALUE hValue = pArguments->GetReturnValue();\r
888     if (hValue) {\r
889         FXJSE_Value_SetBoolean(hValue, bHas);\r
890     }\r
891 }\r
892 void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments)\r
893 {\r
894     int32_t iLength = pArguments->GetLength();\r
895     if (iLength < 1 || iLength > 3) {\r
896         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"loadXML");\r
897         return;\r
898     }\r
899     CFX_WideString wsExpression;\r
900     FX_BOOL bIgnoreRoot = TRUE;\r
901     FX_BOOL bOverwrite = 0;\r
902     if (iLength >= 1) {\r
903         CFX_ByteString bsExpression = pArguments->GetUTF8String(0);\r
904         wsExpression = CFX_WideString::FromUTF8(bsExpression, bsExpression.GetLength());\r
905         if (wsExpression.IsEmpty()) {\r
906             return;\r
907         }\r
908     }\r
909     if (iLength >= 2) {\r
910         bIgnoreRoot = pArguments->GetInt32(1) == 0 ? FALSE : TRUE;\r
911     }\r
912     if (iLength >= 3) {\r
913         bOverwrite = pArguments->GetInt32(2) == 0 ? FALSE : TRUE;\r
914     }\r
915     IXFA_Parser* pParser = IXFA_Parser::Create(m_pDocument);\r
916     if (!pParser) {\r
917         return;\r
918     }\r
919     IFDE_XMLNode* pXMLNode = NULL;\r
920     int32_t iParserStatus = pParser->ParseXMLData(wsExpression, pXMLNode, NULL);\r
921     if (iParserStatus != XFA_PARSESTATUS_Done || !pXMLNode) {\r
922         pParser->Release();\r
923         pParser = NULL;\r
924         return;\r
925     }\r
926     if (bIgnoreRoot && (pXMLNode->GetType() != FDE_XMLNODE_Element || XFA_RecognizeRichText((IFDE_XMLElement*)pXMLNode))) {\r
927         bIgnoreRoot = FALSE;\r
928     }\r
929     CXFA_Node* pFakeRoot = this->Clone(FALSE);\r
930     CFX_WideStringC wsContentType = this->GetCData(XFA_ATTRIBUTE_ContentType);\r
931     if (!wsContentType.IsEmpty()) {\r
932         pFakeRoot->SetCData(XFA_ATTRIBUTE_ContentType, wsContentType);\r
933     }\r
934     IFDE_XMLNode* pFakeXMLRoot = pFakeRoot->GetXMLMappingNode();\r
935     if (!pFakeXMLRoot) {\r
936         IFDE_XMLNode* pThisXMLRoot = this->GetXMLMappingNode();\r
937         pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone(FALSE) : NULL;\r
938     }\r
939     if (!pFakeXMLRoot) {\r
940         CFX_WideStringC wsClassName;\r
941         this->GetClassName(wsClassName);\r
942         pFakeXMLRoot = IFDE_XMLElement::Create(wsClassName);\r
943     }\r
944     if (bIgnoreRoot) {\r
945         IFDE_XMLNode *pXMLChild = pXMLNode->GetNodeItem(IFDE_XMLNode::FirstChild);\r
946         while (pXMLChild) {\r
947             IFDE_XMLNode * pXMLSibling = pXMLChild->GetNodeItem(IFDE_XMLNode::NextSibling);\r
948             pXMLNode->RemoveChildNode(pXMLChild);\r
949             pFakeXMLRoot->InsertChildNode(pXMLChild);\r
950             pXMLChild = pXMLSibling;\r
951         }\r
952     } else {\r
953         IFDE_XMLNode *pXMLParent = pXMLNode->GetNodeItem(IFDE_XMLNode::Parent);\r
954         if (pXMLParent) {\r
955             pXMLParent->RemoveChildNode(pXMLNode);\r
956         }\r
957         pFakeXMLRoot->InsertChildNode(pXMLNode);\r
958     }\r
959     pParser->ConstructXFANode(pFakeRoot, pFakeXMLRoot);\r
960     pFakeRoot = pParser->GetRootNode();\r
961     if (pFakeRoot) {\r
962         if (bOverwrite) {\r
963             CXFA_Node *pChild = this->GetNodeItem(XFA_NODEITEM_FirstChild);\r
964             CXFA_Node* pNewChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);\r
965             int32_t index = 0;\r
966             while (pNewChild) {\r
967                 CXFA_Node* pItem = pNewChild->GetNodeItem(XFA_NODEITEM_NextSibling);\r
968                 pFakeRoot->RemoveChild(pNewChild);\r
969                 this->InsertChild(index++, pNewChild);\r
970                 pNewChild->SetFlag(XFA_NODEFLAG_Initialized);\r
971                 pNewChild = pItem;\r
972             }\r
973             while (pChild) {\r
974                 CXFA_Node *pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);\r
975                 this->RemoveChild(pChild);\r
976                 pFakeRoot->InsertChild(pChild);\r
977                 pChild = pItem;\r
978             }\r
979             if (GetPacketID() == XFA_XDPPACKET_Form && GetClassID() == XFA_ELEMENT_ExData) {\r
980                 IFDE_XMLNode* pTempXMLNode = this->GetXMLMappingNode();\r
981                 this->SetXMLMappingNode(pFakeXMLRoot);\r
982                 this->SetFlag(XFA_NODEFLAG_OwnXMLNode, TRUE, FALSE);\r
983                 if (pTempXMLNode && pTempXMLNode->GetNodeItem(IFDE_XMLNode::Parent) == NULL) {\r
984                     pFakeXMLRoot = pTempXMLNode;\r
985                 } else {\r
986                     pFakeXMLRoot = NULL;\r
987                 }\r
988             }\r
989             MoveBufferMapData(pFakeRoot, this, XFA_CalcData, TRUE);\r
990         } else {\r
991             CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);\r
992             while (pChild) {\r
993                 CXFA_Node *pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);\r
994                 pFakeRoot->RemoveChild(pChild);\r
995                 this->InsertChild(pChild);\r
996                 pChild->SetFlag(XFA_NODEFLAG_Initialized);\r
997                 pChild = pItem;\r
998             }\r
999         }\r
1000         if (pFakeXMLRoot) {\r
1001             pFakeRoot->SetXMLMappingNode(pFakeXMLRoot);\r
1002             pFakeRoot->SetFlag(XFA_NODEFLAG_OwnXMLNode, TRUE, FALSE);\r
1003         }\r
1004         pFakeRoot->SetFlag(XFA_NODEFLAG_HasRemoved, TRUE, FALSE);\r
1005     } else {\r
1006         if (pFakeXMLRoot) {\r
1007             pFakeXMLRoot->Release();\r
1008             pFakeXMLRoot = NULL;\r
1009         }\r
1010     }\r
1011     pParser->Release();\r
1012     pParser = NULL;\r
1013 }\r
1014 void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments)\r
1015 {\r
1016 }\r
1017 void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments)\r
1018 {\r
1019     int32_t iLength = pArguments->GetLength();\r
1020     if (iLength < 0 || iLength > 1) {\r
1021         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"saveXML");\r
1022         return;\r
1023     }\r
1024     FX_BOOL bPrettyMode = FALSE;\r
1025     if (iLength == 1) {\r
1026         CFX_ByteString bsPretty = pArguments->GetUTF8String(0);\r
1027         if (bsPretty.Equal(FX_BSTRC("pretty"))) {\r
1028             bPrettyMode = TRUE;\r
1029         } else {\r
1030             ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH);\r
1031             return;\r
1032         }\r
1033     }\r
1034     CFX_ByteStringC bsXMLHeader = FX_BSTRC("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");\r
1035     if (GetPacketID() == XFA_XDPPACKET_Form) {\r
1036         IFX_MemoryStream* pMemoryStream = FX_CreateMemoryStream(TRUE);\r
1037         if (!pMemoryStream) {\r
1038             FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), bsXMLHeader);\r
1039             return;\r
1040         }\r
1041         IFX_Stream *pStream = IFX_Stream::CreateStream((IFX_FileWrite*)pMemoryStream, FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append);\r
1042         if (!pStream) {\r
1043             FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), bsXMLHeader);\r
1044             pMemoryStream->Release();\r
1045             pMemoryStream = NULL;\r
1046             return;\r
1047         }\r
1048         pStream->SetCodePage(FX_CODEPAGE_UTF8);\r
1049         pStream->WriteData(bsXMLHeader.GetPtr(), bsXMLHeader.GetLength());\r
1050         XFA_DataExporter_RegenerateFormFile(this, pStream, NULL, TRUE);\r
1051         FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize()));\r
1052         pStream->Release();\r
1053         pStream = NULL;\r
1054         if (pMemoryStream) {\r
1055             pMemoryStream->Release();\r
1056             pMemoryStream = NULL;\r
1057         }\r
1058         return;\r
1059     } else if (GetPacketID() == XFA_XDPPACKET_Datasets) {\r
1060         IFDE_XMLNode* pElement = this->GetXMLMappingNode();\r
1061         if(!pElement || pElement->GetType() != FDE_XMLNODE_Element) {\r
1062             FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), bsXMLHeader);\r
1063             return;\r
1064         }\r
1065         XFA_DataExporter_DealWithDataGroupNode(this);\r
1066         IFX_MemoryStream* pMemoryStream = FX_CreateMemoryStream(TRUE);\r
1067         if (!pMemoryStream) {\r
1068             FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), bsXMLHeader);\r
1069             return;\r
1070         }\r
1071         if (pMemoryStream) {\r
1072             IFX_Stream *pStream = IFX_Stream::CreateStream((IFX_FileWrite*)pMemoryStream, FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append);\r
1073             if (pStream) {\r
1074                 pStream->SetCodePage(FX_CODEPAGE_UTF8);\r
1075                 pStream->WriteData(bsXMLHeader.GetPtr(), bsXMLHeader.GetLength());\r
1076                 pElement->SaveXMLNode(pStream);\r
1077                 FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize()));\r
1078                 pStream->Release();\r
1079                 pStream = NULL;\r
1080             }\r
1081             if (pMemoryStream) {\r
1082                 pMemoryStream->Release();\r
1083                 pMemoryStream = NULL;\r
1084             }\r
1085             return;\r
1086         }\r
1087     } else {\r
1088         FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), FX_BSTRC(""));\r
1089     }\r
1090 }\r
1091 void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments)\r
1092 {\r
1093     int32_t iLength = pArguments->GetLength();\r
1094     if (iLength != 2) {\r
1095         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setAttribute");\r
1096         return;\r
1097     }\r
1098     CFX_WideString wsAttribute;\r
1099     CFX_WideString wsAttributeValue;\r
1100     CFX_ByteString bsAttributeValue = pArguments->GetUTF8String(0);\r
1101     CFX_ByteString bsAttribute = pArguments->GetUTF8String(1);\r
1102     wsAttributeValue = CFX_WideString::FromUTF8(bsAttributeValue, bsAttributeValue.GetLength());\r
1103     wsAttribute = CFX_WideString::FromUTF8(bsAttribute, bsAttribute.GetLength());\r
1104     this->SetAttribute(wsAttribute, wsAttributeValue, TRUE);\r
1105 }\r
1106 void CXFA_Node::Script_NodeClass_SetElement(CFXJSE_Arguments* pArguments)\r
1107 {\r
1108     int32_t iLength = pArguments->GetLength();\r
1109     if (iLength != 1 && iLength != 2) {\r
1110         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setElement");\r
1111         return;\r
1112     }\r
1113     CXFA_Node* pNode = NULL;\r
1114     CFX_WideString wsName;\r
1115     if (iLength >= 1) {\r
1116         pNode = (CXFA_Node*)pArguments->GetObject(0);\r
1117     }\r
1118     if (iLength >= 2) {\r
1119         CFX_ByteString bsName = pArguments->GetUTF8String(1);\r
1120         wsName = CFX_WideString::FromUTF8(bsName, bsName.GetLength());\r
1121     }\r
1122 }\r
1123 void CXFA_Node::Script_NodeClass_Ns(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1124 {\r
1125     if (bSetting) {\r
1126         ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);\r
1127     } else {\r
1128         CFX_WideString wsNameSpace;\r
1129         this->TryNamespace(wsNameSpace);\r
1130         FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsNameSpace));\r
1131     }\r
1132 }\r
1133 void CXFA_Node::Script_NodeClass_Model(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1134 {\r
1135     if (bSetting) {\r
1136         ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);\r
1137     } else {\r
1138         FXJSE_Value_Set(hValue, m_pDocument->GetScriptContext()->GetJSValueFromMap(this->GetModelNode()));\r
1139     }\r
1140 }\r
1141 void CXFA_Node::Script_NodeClass_IsContainer(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1142 {\r
1143     if (bSetting) {\r
1144         ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);\r
1145     } else {\r
1146         FXJSE_Value_SetBoolean(hValue, this->IsContainerNode());\r
1147     }\r
1148 }\r
1149 void CXFA_Node::Script_NodeClass_IsNull(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1150 {\r
1151     if (bSetting) {\r
1152         ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);\r
1153     } else {\r
1154         if (this->GetClassID() == XFA_ELEMENT_Subform) {\r
1155             FXJSE_Value_SetBoolean(hValue, FALSE);\r
1156             return;\r
1157         }\r
1158         CFX_WideString strValue;\r
1159         FXJSE_Value_SetBoolean(hValue, !TryContent(strValue) || strValue.IsEmpty());\r
1160     }\r
1161 }\r
1162 void CXFA_Node::Script_NodeClass_OneOfChild(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1163 {\r
1164     if (bSetting) {\r
1165         ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);\r
1166     } else {\r
1167         CXFA_NodeArray properts;\r
1168         int32_t iSize = this->GetNodeList(properts, XFA_NODEFILTER_OneOfProperty);\r
1169         if (iSize > 0) {\r
1170             FXJSE_Value_Set(hValue, m_pDocument->GetScriptContext()->GetJSValueFromMap(properts[0]));\r
1171         }\r
1172     }\r
1173 }\r
1174 void CXFA_Node::Script_ContainerClass_GetDelta(CFXJSE_Arguments* pArguments)\r
1175 {\r
1176 }\r
1177 void CXFA_Node::Script_ContainerClass_GetDeltas(CFXJSE_Arguments* pArguments)\r
1178 {\r
1179     CXFA_ArrayNodeList* pFormNodes = FX_NEW CXFA_ArrayNodeList(m_pDocument);\r
1180     FXJSE_Value_SetObject(pArguments->GetReturnValue(), (CXFA_Object*)pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());\r
1181 }\r
1182 void CXFA_Node::Script_ModelClass_ClearErrorList(CFXJSE_Arguments* pArguments)\r
1183 {\r
1184 }\r
1185 void CXFA_Node::Script_ModelClass_CreateNode(CFXJSE_Arguments* pArguments)\r
1186 {\r
1187     Script_Template_CreateNode(pArguments);\r
1188 }\r
1189 void CXFA_Node::Script_ModelClass_IsCompatibleNS(CFXJSE_Arguments* pArguments)\r
1190 {\r
1191     int32_t iLength = pArguments->GetLength();\r
1192     if (iLength < 1) {\r
1193         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isCompatibleNS");\r
1194         return;\r
1195     }\r
1196     CFX_WideString wsNameSpace;\r
1197     if (iLength >= 1) {\r
1198         CFX_ByteString bsNameSpace = pArguments->GetUTF8String(0);\r
1199         wsNameSpace = CFX_WideString::FromUTF8(bsNameSpace, bsNameSpace.GetLength());\r
1200     }\r
1201     CFX_WideString wsNodeNameSpace;\r
1202     this->TryNamespace(wsNodeNameSpace);\r
1203     FXJSE_HVALUE hValue = pArguments->GetReturnValue();\r
1204     if (hValue) {\r
1205         FXJSE_Value_SetBoolean(hValue, wsNodeNameSpace.Equal(wsNameSpace));\r
1206     }\r
1207 }\r
1208 void CXFA_Node::Script_ModelClass_Context(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1209 {\r
1210 }\r
1211 void CXFA_Node::Script_ModelClass_AliasNode(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1212 {\r
1213 }\r
1214 void CXFA_Node::Script_Attribute_Integer(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1215 {\r
1216     if (bSetting) {\r
1217         SetInteger(eAttribute, FXJSE_Value_ToInteger(hValue), TRUE);\r
1218     } else {\r
1219         FXJSE_Value_SetInteger(hValue, GetInteger(eAttribute));\r
1220     }\r
1221 }\r
1222 void CXFA_Node::Script_Attribute_IntegerRead(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1223 {\r
1224     if (!bSetting) {\r
1225         FXJSE_Value_SetInteger(hValue, GetInteger(eAttribute));\r
1226     } else {\r
1227         ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);\r
1228     }\r
1229 }\r
1230 void CXFA_Node::Script_Attribute_BOOL(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1231 {\r
1232     if (bSetting) {\r
1233         SetBoolean(eAttribute, FXJSE_Value_ToBoolean(hValue), TRUE);\r
1234     } else {\r
1235         FXJSE_Value_SetUTF8String(hValue, GetBoolean(eAttribute) ? FX_BSTRC("1") : FX_BSTRC("0"));\r
1236     }\r
1237 }\r
1238 void CXFA_Node::Script_Attribute_BOOLRead(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1239 {\r
1240     if (!bSetting) {\r
1241         FXJSE_Value_SetUTF8String(hValue, GetBoolean(eAttribute) ? FX_BSTRC("1") : FX_BSTRC("0"));\r
1242     } else {\r
1243         ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);\r
1244     }\r
1245 }\r
1246 void CXFA_Node::Script_Attribute_SendAttributeChangeMessage(FX_LPVOID eAttribute, FX_LPVOID eValue, FX_BOOL bScriptModify)\r
1247 {\r
1248     CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();\r
1249     if (!pLayoutPro) {\r
1250         return;\r
1251     }\r
1252     IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();\r
1253     if (!pNotify) {\r
1254         return;\r
1255     }\r
1256     FX_DWORD dwPacket = this->GetPacketID();\r
1257     if (dwPacket & XFA_XDPPACKET_Form) {\r
1258         FX_BOOL bNeedFindContainer = FALSE;\r
1259         XFA_ELEMENT eType = this->GetClassID();\r
1260         switch (eType) {\r
1261             case XFA_ELEMENT_Caption:\r
1262                 bNeedFindContainer = TRUE;\r
1263                 pNotify->OnNodeEvent(this, XFA_NODEEVENT_ValueChanged, eAttribute, eValue, this, this->GetNodeItem(XFA_NODEITEM_Parent));\r
1264                 break;\r
1265             case XFA_ELEMENT_Font:\r
1266             case XFA_ELEMENT_Para: {\r
1267                     bNeedFindContainer = TRUE;\r
1268                     CXFA_Node* pParentNode = this->GetNodeItem(XFA_NODEITEM_Parent);\r
1269                     if (pParentNode->GetClassID() == XFA_ELEMENT_Caption) {\r
1270                         pNotify->OnNodeEvent(this, XFA_NODEEVENT_ValueChanged, eAttribute, eValue, pParentNode, pParentNode->GetNodeItem(XFA_NODEITEM_Parent));\r
1271                     } else {\r
1272                         pNotify->OnNodeEvent(this, XFA_NODEEVENT_ValueChanged, eAttribute, eValue, this, pParentNode);\r
1273                     }\r
1274                 }\r
1275                 break;\r
1276             case XFA_ELEMENT_Margin: {\r
1277                     bNeedFindContainer = TRUE;\r
1278                     CXFA_Node* pParentNode = this->GetNodeItem(XFA_NODEITEM_Parent);\r
1279                     XFA_ELEMENT eParentType = pParentNode->GetClassID();\r
1280                     if (pParentNode->IsContainerNode()) {\r
1281                         pNotify->OnNodeEvent(this, XFA_NODEEVENT_ValueChanged, eAttribute, eValue, this, pParentNode);\r
1282                     } else if (eParentType == XFA_ELEMENT_Caption) {\r
1283                         pNotify->OnNodeEvent(this, XFA_NODEEVENT_ValueChanged, eAttribute, eValue, pParentNode, pParentNode->GetNodeItem(XFA_NODEITEM_Parent));\r
1284                     } else {\r
1285                         CXFA_Node* pNode = pParentNode->GetNodeItem(XFA_NODEITEM_Parent);\r
1286                         if (pNode && pNode->GetClassID() == XFA_ELEMENT_Ui) {\r
1287                             pNotify->OnNodeEvent(this, XFA_NODEEVENT_ValueChanged, eAttribute, eValue, pNode, pNode->GetNodeItem(XFA_NODEITEM_Parent));\r
1288                         }\r
1289                     }\r
1290                 }\r
1291                 break;\r
1292             case XFA_ELEMENT_Comb: {\r
1293                     CXFA_Node* pEditNode = this->GetNodeItem(XFA_NODEITEM_Parent);\r
1294                     XFA_ELEMENT eUIType = pEditNode->GetClassID();\r
1295                     if (pEditNode && (eUIType == XFA_ELEMENT_DateTimeEdit || eUIType == XFA_ELEMENT_NumericEdit || eUIType == XFA_ELEMENT_TextEdit)) {\r
1296                         CXFA_Node* pUINode = pEditNode->GetNodeItem(XFA_NODEITEM_Parent);\r
1297                         if (pUINode) {\r
1298                             pNotify->OnNodeEvent(this, XFA_NODEEVENT_ValueChanged, eAttribute, eValue, pUINode, pUINode->GetNodeItem(XFA_NODEITEM_Parent));\r
1299                         }\r
1300                     }\r
1301                 }\r
1302                 break;\r
1303             case XFA_ELEMENT_Button:\r
1304             case XFA_ELEMENT_Barcode:\r
1305             case XFA_ELEMENT_ChoiceList:\r
1306             case XFA_ELEMENT_DateTimeEdit:\r
1307             case XFA_ELEMENT_NumericEdit:\r
1308             case XFA_ELEMENT_PasswordEdit:\r
1309             case XFA_ELEMENT_TextEdit: {\r
1310                     CXFA_Node* pUINode = this->GetNodeItem(XFA_NODEITEM_Parent);\r
1311                     if (pUINode) {\r
1312                         pNotify->OnNodeEvent(this, XFA_NODEEVENT_ValueChanged, eAttribute, eValue, pUINode, pUINode->GetNodeItem(XFA_NODEITEM_Parent));\r
1313                     }\r
1314                 }\r
1315                 break;\r
1316             case XFA_ELEMENT_CheckButton: {\r
1317                     bNeedFindContainer = TRUE;\r
1318                     CXFA_Node* pUINode = this->GetNodeItem(XFA_NODEITEM_Parent);\r
1319                     if (pUINode) {\r
1320                         pNotify->OnNodeEvent(this, XFA_NODEEVENT_ValueChanged, eAttribute, eValue, pUINode, pUINode->GetNodeItem(XFA_NODEITEM_Parent));\r
1321                     }\r
1322                 }\r
1323                 break;\r
1324             case XFA_ELEMENT_Keep:\r
1325             case XFA_ELEMENT_Bookend:\r
1326             case XFA_ELEMENT_Break:\r
1327             case XFA_ELEMENT_BreakAfter:\r
1328             case XFA_ELEMENT_BreakBefore:\r
1329             case XFA_ELEMENT_Overflow:\r
1330                 bNeedFindContainer = TRUE;\r
1331                 break;\r
1332             case XFA_ELEMENT_Area:\r
1333             case XFA_ELEMENT_Draw:\r
1334             case XFA_ELEMENT_ExclGroup:\r
1335             case XFA_ELEMENT_Field:\r
1336             case XFA_ELEMENT_Subform:\r
1337             case XFA_ELEMENT_SubformSet:\r
1338                 pLayoutPro->AddChangedContainer(this);\r
1339                 pNotify->OnNodeEvent(this, XFA_NODEEVENT_ValueChanged, eAttribute, eValue, this, this);\r
1340                 break;\r
1341             case XFA_ELEMENT_Sharptext:\r
1342             case XFA_ELEMENT_Sharpxml:\r
1343             case XFA_ELEMENT_SharpxHTML: {\r
1344                     CXFA_Node* pTextNode = this->GetNodeItem(XFA_NODEITEM_Parent);\r
1345                     if (!pTextNode) {\r
1346                         return;\r
1347                     }\r
1348                     CXFA_Node* pValueNode = pTextNode->GetNodeItem(XFA_NODEITEM_Parent);\r
1349                     if (!pValueNode) {\r
1350                         return;\r
1351                     }\r
1352                     XFA_ELEMENT eType = pValueNode->GetClassID();\r
1353                     if (eType == XFA_ELEMENT_Value) {\r
1354                         bNeedFindContainer = TRUE;\r
1355                         CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);\r
1356                         if (pNode && pNode->IsContainerNode()) {\r
1357                             if (bScriptModify) {\r
1358                                 pValueNode = pNode;\r
1359                             }\r
1360                             pNotify->OnNodeEvent(this, XFA_NODEEVENT_ValueChanged, eAttribute, eValue, pValueNode, pNode);\r
1361                         } else {\r
1362                             pNotify->OnNodeEvent(this, XFA_NODEEVENT_ValueChanged, eAttribute, eValue, pNode, pNode->GetNodeItem(XFA_NODEITEM_Parent));\r
1363                         }\r
1364                     } else {\r
1365                         if (eType == XFA_ELEMENT_Items) {\r
1366                             CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);\r
1367                             if (pNode && pNode->IsContainerNode()) {\r
1368                                 pNotify->OnNodeEvent(this, XFA_NODEEVENT_ValueChanged, eAttribute, eValue, pValueNode, pNode);\r
1369                             }\r
1370                         }\r
1371                     }\r
1372                 }\r
1373                 break;\r
1374             default:\r
1375                 break;\r
1376         }\r
1377         if (bNeedFindContainer) {\r
1378             CXFA_Node* pParent = this;\r
1379             while (pParent) {\r
1380                 if (pParent->IsContainerNode()) {\r
1381                     break;\r
1382                 }\r
1383                 pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);\r
1384             }\r
1385             if (pParent) {\r
1386                 pLayoutPro->AddChangedContainer(pParent);\r
1387             }\r
1388         }\r
1389     } else {\r
1390         pNotify->OnNodeEvent(this, XFA_NODEEVENT_ValueChanged, eAttribute, eValue, this, this);\r
1391     }\r
1392 }\r
1393 void CXFA_Node::Script_Attribute_String(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1394 {\r
1395     if (bSetting) {\r
1396         CFX_ByteString szValue;\r
1397         FXJSE_Value_ToUTF8String(hValue, szValue);\r
1398         CFX_WideString wsValue = CFX_WideString::FromUTF8(szValue, szValue.GetLength());\r
1399         SetAttribute(eAttribute, wsValue, TRUE);\r
1400         if(eAttribute == XFA_ATTRIBUTE_Use && this->GetClassID() == XFA_ELEMENT_Desc) {\r
1401             CFX_WideString wsUseVal = wsValue, wsID, wsSOM;\r
1402             CXFA_Node* pTemplateNode = (CXFA_Node*)m_pDocument->GetXFANode(XFA_HASHCODE_Template);\r
1403             CXFA_Node* pProtoRoot = pTemplateNode->GetFirstChildByClass(XFA_ELEMENT_Subform)->GetFirstChildByClass(XFA_ELEMENT_Proto);\r
1404             if(!wsUseVal.IsEmpty()) {\r
1405                 if(wsUseVal[0] == '#') {\r
1406                     wsID = CFX_WideString((FX_LPCWSTR)wsUseVal + 1, wsUseVal.GetLength() - 1);\r
1407                 } else {\r
1408                     wsSOM = CFX_WideString((FX_LPCWSTR)wsUseVal, wsUseVal.GetLength());\r
1409                 }\r
1410             }\r
1411             CXFA_Node* pProtoNode = NULL;\r
1412             if(!wsSOM.IsEmpty()) {\r
1413                 FX_DWORD dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings;\r
1414                 XFA_RESOLVENODE_RS resoveNodeRS;\r
1415                 int32_t iRet = m_pDocument->GetScriptContext()->ResolveObjects(pProtoRoot, wsSOM, resoveNodeRS, dwFlag);\r
1416                 if(iRet > 0 && resoveNodeRS.nodes[0]->IsNode()) {\r
1417                     pProtoNode = (CXFA_Node*)resoveNodeRS.nodes[0];\r
1418                 }\r
1419             } else if(!wsID.IsEmpty()) {\r
1420                 pProtoNode = m_pDocument->GetNodeByID(pProtoRoot, wsID);\r
1421             }\r
1422             if(pProtoNode) {\r
1423                 CXFA_Node* pHeadChild = GetNodeItem(XFA_NODEITEM_FirstChild);\r
1424                 while (pHeadChild) {\r
1425                     CXFA_Node* pSibling = pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);\r
1426                     RemoveChild(pHeadChild);\r
1427                     pHeadChild = pSibling;\r
1428                 }\r
1429                 CXFA_Node* pProtoForm = pProtoNode->CloneTemplateToForm(TRUE);\r
1430                 pHeadChild = pProtoForm->GetNodeItem(XFA_NODEITEM_FirstChild);\r
1431                 while (pHeadChild) {\r
1432                     CXFA_Node* pSibling = pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);\r
1433                     pProtoForm->RemoveChild(pHeadChild);\r
1434                     InsertChild(pHeadChild);\r
1435                     pHeadChild = pSibling;\r
1436                 }\r
1437                 m_pDocument->RemovePurgeNode(pProtoForm);\r
1438                 delete pProtoForm;\r
1439             }\r
1440         }\r
1441     } else {\r
1442         CFX_WideString wsValue;\r
1443         GetAttribute(eAttribute, wsValue);\r
1444         FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsValue, wsValue.GetLength()));\r
1445     }\r
1446 }\r
1447 void CXFA_Node::Script_Attribute_StringRead(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1448 {\r
1449     if (!bSetting) {\r
1450         CFX_WideString wsValue;\r
1451         GetAttribute(eAttribute, wsValue);\r
1452         FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsValue, wsValue.GetLength()));\r
1453     } else {\r
1454         ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);\r
1455     }\r
1456 }\r
1457 void CXFA_Node::Script_WsdlConnection_Execute(CFXJSE_Arguments* pArguments)\r
1458 {\r
1459     int32_t argc = pArguments->GetLength();\r
1460     if ((argc == 0) || (argc == 1)) {\r
1461         FXJSE_Value_SetBoolean(pArguments->GetReturnValue(), FALSE);\r
1462     } else {\r
1463         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execute");\r
1464     }\r
1465 }\r
1466 void CXFA_Node::Script_Delta_Restore(CFXJSE_Arguments* pArguments)\r
1467 {\r
1468     int32_t argc = pArguments->GetLength();\r
1469     if (argc == 0) {\r
1470     } else {\r
1471         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"restore");\r
1472     }\r
1473 }\r
1474 void CXFA_Node::Script_Delta_CurrentValue(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1475 {\r
1476 }\r
1477 void CXFA_Node::Script_Delta_SavedValue(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1478 {\r
1479 }\r
1480 void CXFA_Node::Script_Delta_Target(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1481 {\r
1482 }\r
1483 void CXFA_Node::Script_Som_Message(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_SOM_MESSAGETYPE iMessageType)\r
1484 {\r
1485     CXFA_WidgetData *pWidgetData = GetWidgetData();\r
1486     if (!pWidgetData) {\r
1487         return;\r
1488     }\r
1489     FX_BOOL bNew = FALSE;\r
1490     CXFA_Validate validate = pWidgetData->GetValidate();\r
1491     if (!validate) {\r
1492         validate = pWidgetData->GetValidate(TRUE);\r
1493         bNew = TRUE;\r
1494     }\r
1495     if (bSetting) {\r
1496         CFX_ByteString bsMessage;\r
1497         FXJSE_Value_ToUTF8String(hValue, bsMessage);\r
1498         switch (iMessageType) {\r
1499             case XFA_SOM_ValidationMessage:\r
1500                 validate.SetScriptMessageText(CFX_WideString::FromUTF8(bsMessage, bsMessage.GetLength()));\r
1501                 break;\r
1502             case XFA_SOM_FormatMessage:\r
1503                 validate.SetFormatMessageText(CFX_WideString::FromUTF8(bsMessage, bsMessage.GetLength()));\r
1504                 break;\r
1505             case XFA_SOM_MandatoryMessage:\r
1506                 validate.SetNullMessageText(CFX_WideString::FromUTF8(bsMessage, bsMessage.GetLength()));\r
1507                 break;\r
1508             default:\r
1509                 break;\r
1510         }\r
1511         if (!bNew) {\r
1512             IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();\r
1513             if (!pNotify) {\r
1514                 return;\r
1515             }\r
1516             pNotify->AddCalcValidate(this);\r
1517         }\r
1518     } else {\r
1519         CFX_WideString wsMessage;\r
1520         switch (iMessageType) {\r
1521             case XFA_SOM_ValidationMessage:\r
1522                 validate.GetScriptMessageText(wsMessage);\r
1523                 break;\r
1524             case XFA_SOM_FormatMessage:\r
1525                 validate.GetFormatMessageText(wsMessage);\r
1526                 break;\r
1527             case XFA_SOM_MandatoryMessage:\r
1528                 validate.GetNullMessageText(wsMessage);\r
1529                 break;\r
1530             default:\r
1531                 break;\r
1532         }\r
1533         FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsMessage));\r
1534     }\r
1535 }\r
1536 void CXFA_Node::Script_Som_ValidationMessage(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1537 {\r
1538     Script_Som_Message(hValue, bSetting, XFA_SOM_ValidationMessage);\r
1539 }\r
1540 void CXFA_Node::Script_Field_Length(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1541 {\r
1542     if (bSetting) {\r
1543         ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);\r
1544     } else {\r
1545         CXFA_WidgetData *pWidgetData = GetWidgetData();\r
1546         if (!pWidgetData) {\r
1547             FXJSE_Value_SetInteger(hValue, 0);\r
1548             return;\r
1549         }\r
1550         FXJSE_Value_SetInteger(hValue, pWidgetData->CountChoiceListItems(TRUE));\r
1551     }\r
1552 }\r
1553 void CXFA_Node::Script_Som_DefaultValue(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1554 {\r
1555     XFA_ELEMENT classID = GetClassID();\r
1556     if(classID == XFA_ELEMENT_Field) {\r
1557         Script_Field_DefaultValue(hValue, bSetting, eAttribute);\r
1558         return;\r
1559     } else if(classID == XFA_ELEMENT_Draw) {\r
1560         Script_Draw_DefaultValue(hValue, bSetting, eAttribute);\r
1561         return;\r
1562     } else if (classID == XFA_ELEMENT_Boolean) {\r
1563         Script_Boolean_Value(hValue, bSetting, eAttribute);\r
1564         return;\r
1565     }\r
1566     if (bSetting) {\r
1567         CFX_ByteString newValue;\r
1568         if (!(FXJSE_Value_IsNull(hValue) || FXJSE_Value_IsUndefined(hValue))) {\r
1569             FXJSE_Value_ToUTF8String(hValue, newValue);\r
1570         }\r
1571         CFX_WideString wsNewValue = CFX_WideString::FromUTF8(newValue, newValue.GetLength());\r
1572         CFX_WideString wsFormatValue(wsNewValue);\r
1573         CXFA_WidgetData* pContainerWidgetData = NULL;\r
1574         if (GetPacketID() == XFA_XDPPACKET_Datasets) {\r
1575             CXFA_NodeArray formNodes;\r
1576             this->GetBindItems(formNodes);\r
1577             CFX_WideString wsPicture;\r
1578             for (int32_t i = 0; i < formNodes.GetSize(); i++) {\r
1579                 CXFA_Node* pFormNode = formNodes.GetAt(i);\r
1580                 if (!pFormNode || pFormNode->HasFlag(XFA_NODEFLAG_HasRemoved)) {\r
1581                     continue;\r
1582                 }\r
1583                 pContainerWidgetData = pFormNode->GetContainerWidgetData();\r
1584                 if (pContainerWidgetData) {\r
1585                     pContainerWidgetData->GetPictureContent(wsPicture, XFA_VALUEPICTURE_DataBind);\r
1586                 }\r
1587                 if (!wsPicture.IsEmpty()) {\r
1588                     break;\r
1589                 }\r
1590                 pContainerWidgetData = NULL;\r
1591             }\r
1592         } else if (GetPacketID() == XFA_XDPPACKET_Form) {\r
1593             pContainerWidgetData = GetContainerWidgetData();\r
1594         }\r
1595         if (pContainerWidgetData) {\r
1596             pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);\r
1597         }\r
1598         SetScriptContent(wsNewValue, wsFormatValue, TRUE, TRUE);\r
1599     } else {\r
1600         CFX_WideString content = GetScriptContent(TRUE);\r
1601         if(content.IsEmpty() && classID != XFA_ELEMENT_Text && classID != XFA_ELEMENT_SubmitUrl) {\r
1602             FXJSE_Value_SetNull(hValue);\r
1603         } else if (classID == XFA_ELEMENT_Integer) {\r
1604             FXJSE_Value_SetInteger(hValue, FXSYS_wtoi(content)) ;\r
1605         } else if (classID == XFA_ELEMENT_Float || classID == XFA_ELEMENT_Decimal) {\r
1606             CFX_Decimal decimal(content);\r
1607             FXJSE_Value_SetFloat(hValue, (FX_FLOAT)(double)decimal);\r
1608         } else {\r
1609             FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(content, content.GetLength()));\r
1610         }\r
1611     }\r
1612 }\r
1613 void CXFA_Node::Script_Som_DefaultValue_Read(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1614 {\r
1615     if (bSetting) {\r
1616         ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);\r
1617         return;\r
1618     }\r
1619     CFX_WideString content = GetScriptContent(TRUE);\r
1620     if (content.IsEmpty()) {\r
1621         FXJSE_Value_SetNull(hValue);\r
1622     } else {\r
1623         FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(content, content.GetLength()));\r
1624     }\r
1625 }\r
1626 void CXFA_Node::Script_Boolean_Value(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1627 {\r
1628     if (bSetting) {\r
1629         CFX_ByteString newValue;\r
1630         if (!(FXJSE_Value_IsNull(hValue) || FXJSE_Value_IsUndefined(hValue))) {\r
1631             FXJSE_Value_ToUTF8String(hValue, newValue);\r
1632         }\r
1633         int32_t iValue = FXSYS_atoi(newValue);\r
1634         CFX_WideString wsNewValue = (iValue == 0) ? FX_WSTRC(L"0") : FX_WSTRC(L"1");\r
1635         CFX_WideString wsFormatValue(wsNewValue);\r
1636         CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();\r
1637         if (pContainerWidgetData) {\r
1638             pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);\r
1639         }\r
1640         SetScriptContent(wsNewValue, wsFormatValue, TRUE, TRUE);\r
1641     } else {\r
1642         CFX_WideString wsValue = GetScriptContent(TRUE);\r
1643         FXJSE_Value_SetBoolean(hValue, wsValue.Equal(FX_WSTRC(L"1")) ? TRUE : FALSE);\r
1644     }\r
1645 }\r
1646 struct XFA_ExecEventParaInfo {\r
1647 public:\r
1648     uint32_t m_uHash;\r
1649     FX_LPCWSTR m_lpcEventName;\r
1650     XFA_EVENTTYPE m_eventType;\r
1651     uint32_t m_validFlags;\r
1652 };\r
1653 static const XFA_ExecEventParaInfo gs_eventParaInfos[] = {\r
1654     {0x02a6c55a, L"postSubmit", XFA_EVENT_PostSubmit,   0},\r
1655     {0x0ab466bb, L"preSubmit",  XFA_EVENT_PreSubmit,    0},\r
1656     {0x109d7ce7, L"mouseEnter", XFA_EVENT_MouseEnter,   5},\r
1657     {0x17fad373, L"postPrint",  XFA_EVENT_PostPrint,    0},\r
1658     {0x1bfc72d9, L"preOpen",    XFA_EVENT_PreOpen,              7},\r
1659     {0x2196a452, L"initialize", XFA_EVENT_Initialize,   1},\r
1660     {0x27410f03, L"mouseExit",  XFA_EVENT_MouseExit,    5},\r
1661     {0x33c43dec, L"docClose",   XFA_EVENT_DocClose,             0},\r
1662     {0x361fa1b6, L"preSave",    XFA_EVENT_PreSave,              0},\r
1663     {0x36f1c6d8, L"preSign",    XFA_EVENT_PreSign,              6},\r
1664     {0x4731d6ba, L"exit",               XFA_EVENT_Exit,                 2},\r
1665     {0x56bf456b, L"docReady",   XFA_EVENT_DocReady,             0},\r
1666     {0x7233018a, L"validate",   XFA_EVENT_Validate,             1},\r
1667     {0x8808385e, L"indexChange", XFA_EVENT_IndexChange, 3},\r
1668     {0x891f4606, L"change",             XFA_EVENT_Change,               4},\r
1669     {0x9528a7b4, L"prePrint",   XFA_EVENT_PrePrint,             0},\r
1670     {0x9f693b21, L"mouseDown",  XFA_EVENT_MouseDown,    5},\r
1671     {0xcdce56b3, L"full",               XFA_EVENT_Full,                 4},\r
1672     {0xd576d08e, L"mouseUp",    XFA_EVENT_MouseUp,              5},\r
1673     {0xd95657a6, L"click",              XFA_EVENT_Click,                4},\r
1674     {0xdbfbe02e, L"calculate",  XFA_EVENT_Calculate,    1},\r
1675     {0xe25fa7b8, L"postOpen",   XFA_EVENT_PostOpen,             7},\r
1676     {0xe28dce7e, L"enter",              XFA_EVENT_Enter,                2},\r
1677     {0xfc82d695, L"postSave",   XFA_EVENT_PostSave,             0},\r
1678     {0xfd54fbb7, L"postSign",   XFA_EVENT_PostSign,             6},\r
1679 };\r
1680 const XFA_ExecEventParaInfo* GetEventParaInfoByName(FX_WSTR wsEventName)\r
1681 {\r
1682     int32_t iLength = wsEventName.GetLength();\r
1683     uint32_t uHash = FX_HashCode_String_GetW(wsEventName.GetPtr(), iLength);\r
1684     const XFA_ExecEventParaInfo* eventParaInfo = NULL;\r
1685     int32_t iStart = 0, iEnd = (sizeof(gs_eventParaInfos) / sizeof(gs_eventParaInfos[0])) - 1;\r
1686     int32_t iMid = (iStart + iEnd) / 2;\r
1687     do {\r
1688         iMid = (iStart + iEnd) / 2;\r
1689         eventParaInfo = &gs_eventParaInfos[iMid];\r
1690         if (uHash == eventParaInfo->m_uHash) {\r
1691             return eventParaInfo;\r
1692         } else if (uHash < eventParaInfo->m_uHash) {\r
1693             iEnd = iMid - 1;\r
1694         } else {\r
1695             iStart = iMid + 1;\r
1696         }\r
1697     } while (iStart <= iEnd);\r
1698     return NULL;\r
1699 }\r
1700 void XFA_STRING_TO_RGB(CFX_WideString &strRGB, int32_t &r, int32_t &g, int32_t &b)\r
1701 {\r
1702     r = 0;\r
1703     g = 0;\r
1704     b = 0;\r
1705     FX_WCHAR zero = '0';\r
1706     int32_t iIndex = 0;\r
1707     int32_t iLen = strRGB.GetLength();\r
1708     for (int32_t i = 0; i < iLen; ++i) {\r
1709         FX_WCHAR ch = strRGB.GetAt(i);\r
1710         if (ch == L',') {\r
1711             ++iIndex;\r
1712         }\r
1713         if (iIndex > 2) {\r
1714             break;\r
1715         }\r
1716         int32_t iValue = ch - zero;\r
1717         if (iValue >= 0 && iValue <= 9) {\r
1718             switch (iIndex) {\r
1719                 case 0:\r
1720                     r = r * 10 + iValue;\r
1721                     break;\r
1722                 case 1:\r
1723                     g = g * 10 + iValue;\r
1724                     break;\r
1725                 default:\r
1726                     b = b * 10 + iValue;\r
1727                     break;\r
1728             }\r
1729         }\r
1730     }\r
1731 }\r
1732 void CXFA_Node::Script_Som_BorderColor(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1733 {\r
1734     CXFA_WidgetData* pWidgetData = GetWidgetData();\r
1735     if (!pWidgetData) {\r
1736         return;\r
1737     }\r
1738     CXFA_Border border = pWidgetData->GetBorder(TRUE);\r
1739     int32_t iSize = border.CountEdges();\r
1740     CFX_WideString strColor;\r
1741     if (bSetting) {\r
1742         CFX_ByteString bsValue;\r
1743         FXJSE_Value_ToUTF8String(hValue, bsValue);\r
1744         strColor = CFX_WideString::FromUTF8(bsValue, bsValue.GetLength());\r
1745         int32_t r = 0, g = 0, b = 0;\r
1746         XFA_STRING_TO_RGB(strColor, r, g, b);\r
1747         FX_ARGB rgb = ArgbEncode(100, r, g, b);\r
1748         for (int32_t i = 0; i < iSize; ++i) {\r
1749             CXFA_Edge edge = border.GetEdge(i);\r
1750             edge.SetColor(rgb);\r
1751         }\r
1752     } else {\r
1753         CXFA_Edge edge = border.GetEdge(0);\r
1754         FX_ARGB color = edge.GetColor();\r
1755         int32_t a, r, g, b;\r
1756         ArgbDecode(color, a, r, g, b);\r
1757         strColor.Format(L"%d,%d,%d", r, g, b);\r
1758         FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(strColor));\r
1759     }\r
1760 }\r
1761 void CXFA_Node::Script_Som_BorderWidth(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1762 {\r
1763     CXFA_WidgetData* pWidgetData = GetWidgetData();\r
1764     if (!pWidgetData) {\r
1765         return;\r
1766     }\r
1767     CXFA_Border border = pWidgetData->GetBorder(TRUE);\r
1768     int32_t iSize = border.CountEdges();\r
1769     CFX_WideString wsThickness;\r
1770     if (bSetting) {\r
1771         CFX_ByteString bsValue;\r
1772         FXJSE_Value_ToUTF8String(hValue, bsValue);\r
1773         wsThickness = CFX_WideString::FromUTF8(bsValue, bsValue.GetLength());\r
1774         for (int32_t i = 0; i < iSize; ++i) {\r
1775             CXFA_Edge edge = border.GetEdge(i);\r
1776             CXFA_Measurement thickness(wsThickness);\r
1777             edge.SetMSThickness(thickness);\r
1778         }\r
1779     } else {\r
1780         CXFA_Edge edge = border.GetEdge(0);\r
1781         CXFA_Measurement thickness = edge.GetMSThickness();\r
1782         thickness.ToString(wsThickness);\r
1783         FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsThickness));\r
1784     }\r
1785 }\r
1786 void CXFA_Node::Script_Som_FillColor(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1787 {\r
1788     CXFA_WidgetData* pWidgetData = GetWidgetData();\r
1789     if (!pWidgetData) {\r
1790         return;\r
1791     }\r
1792     CXFA_Border border = pWidgetData->GetBorder(TRUE);\r
1793     CXFA_Fill borderfill = border.GetFill(TRUE);\r
1794     CXFA_Node *pNode = (CXFA_Node*)borderfill;\r
1795     if (!pNode) {\r
1796         return;\r
1797     }\r
1798     CFX_WideString wsColor;\r
1799     if (bSetting) {\r
1800         CFX_ByteString bsValue;\r
1801         FXJSE_Value_ToUTF8String(hValue, bsValue);\r
1802         wsColor = CFX_WideString::FromUTF8(bsValue, bsValue.GetLength());\r
1803         int32_t r, g, b;\r
1804         XFA_STRING_TO_RGB(wsColor, r, g, b);\r
1805         FX_ARGB color = ArgbEncode(0xff, r, g, b);\r
1806         borderfill.SetColor(color);\r
1807     } else {\r
1808         FX_ARGB color = borderfill.GetColor();\r
1809         int32_t a, r, g, b;\r
1810         ArgbDecode(color, a, r, g, b);\r
1811         wsColor.Format(L"%d,%d,%d", r, g, b);\r
1812         FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsColor));\r
1813     }\r
1814 }\r
1815 void CXFA_Node::Script_Som_DataNode(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1816 {\r
1817     if (!bSetting) {\r
1818         CXFA_Node *pDataNode = GetBindData();\r
1819         if (pDataNode) {\r
1820             FXJSE_Value_Set(hValue, m_pDocument->GetScriptContext()->GetJSValueFromMap(pDataNode));\r
1821         } else {\r
1822             FXJSE_Value_SetNull(hValue);\r
1823         }\r
1824     } else {\r
1825         ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);\r
1826     }\r
1827 }\r
1828 void CXFA_Node::Script_Draw_DefaultValue(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1829 {\r
1830     if (bSetting) {\r
1831         if (FXJSE_Value_IsUTF8String(hValue)) {\r
1832             CXFA_WidgetData *pWidgetData = GetWidgetData();\r
1833             FXSYS_assert(pWidgetData);\r
1834             XFA_ELEMENT uiType = pWidgetData->GetUIType();\r
1835             if (uiType == XFA_ELEMENT_Text) {\r
1836                 CFX_ByteString newValue;\r
1837                 FXJSE_Value_ToUTF8String(hValue, newValue);\r
1838                 CFX_WideString wsNewValue = CFX_WideString::FromUTF8(newValue, newValue.GetLength());\r
1839                 CFX_WideString wsFormatValue(wsNewValue);\r
1840                 SetScriptContent(wsNewValue, wsFormatValue, TRUE, TRUE);\r
1841             } else if(uiType != XFA_ELEMENT_Image) {\r
1842             }\r
1843         }\r
1844     } else {\r
1845         CFX_WideString content = GetScriptContent(TRUE);\r
1846         if(content.IsEmpty()) {\r
1847             FXJSE_Value_SetNull(hValue);\r
1848         } else {\r
1849             FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(content, content.GetLength()));\r
1850         }\r
1851     }\r
1852 }\r
1853 void CXFA_Node::Script_Field_DefaultValue(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1854 {\r
1855     CXFA_WidgetData* pWidgetData = GetWidgetData();\r
1856     if (!pWidgetData) {\r
1857         return;\r
1858     }\r
1859     if (bSetting) {\r
1860         if (FXJSE_Value_IsNull(hValue)) {\r
1861             pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;\r
1862             pWidgetData->m_bIsNull = TRUE;\r
1863         } else {\r
1864             pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;\r
1865             pWidgetData->m_bIsNull = FALSE;\r
1866         }\r
1867         CFX_ByteString newValue;\r
1868         if (!(FXJSE_Value_IsNull(hValue) || FXJSE_Value_IsUndefined(hValue))) {\r
1869             FXJSE_Value_ToUTF8String(hValue, newValue);\r
1870         }\r
1871         CFX_WideString wsNewText = CFX_WideString::FromUTF8(newValue, newValue.GetLength());\r
1872         CXFA_Node *pUIChild = pWidgetData->GetUIChild();\r
1873         if (pUIChild->GetClassID() == XFA_ELEMENT_NumericEdit) {\r
1874             int32_t iLeadDigits = 0;\r
1875             int32_t iFracDigits = 0;\r
1876             pWidgetData->GetLeadDigits(iLeadDigits);\r
1877             pWidgetData->GetFracDigits(iFracDigits);\r
1878             wsNewText = XFA_NumericLimit(wsNewText, iLeadDigits, iFracDigits);\r
1879         }\r
1880         CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();\r
1881         CFX_WideString wsFormatText(wsNewText);\r
1882         if (pContainerWidgetData) {\r
1883             pContainerWidgetData->GetFormatDataValue(wsNewText, wsFormatText);\r
1884         }\r
1885         SetScriptContent(wsNewText, wsFormatText, TRUE, TRUE);\r
1886     } else {\r
1887         CFX_WideString content = GetScriptContent(TRUE);\r
1888         if(content.IsEmpty()) {\r
1889             FXJSE_Value_SetNull(hValue);\r
1890         } else {\r
1891             CXFA_Node *pUIChild = pWidgetData->GetUIChild();\r
1892             XFA_ELEMENT eUI = pUIChild->GetClassID();\r
1893             CXFA_Value defVal = pWidgetData->GetFormValue();\r
1894             CXFA_Node* pNode = defVal.GetNode()->GetNodeItem(XFA_NODEITEM_FirstChild);\r
1895             if (pNode && pNode->GetClassID() == XFA_ELEMENT_Decimal) {\r
1896                 if(eUI == XFA_ELEMENT_NumericEdit  && (pNode->GetInteger(XFA_ATTRIBUTE_FracDigits) == -1)) {\r
1897                     FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(content, content.GetLength()));\r
1898                 } else {\r
1899                     CFX_Decimal decimal(content);\r
1900                     FXJSE_Value_SetFloat(hValue, (FX_FLOAT)(double)decimal);\r
1901                 }\r
1902             } else if (pNode && pNode->GetClassID() == XFA_ELEMENT_Integer) {\r
1903                 FXJSE_Value_SetInteger(hValue, FXSYS_wtoi(content))     ;\r
1904             } else if (pNode && pNode->GetClassID() == XFA_ELEMENT_Boolean) {\r
1905                 FXJSE_Value_SetBoolean(hValue, FXSYS_wtoi(content) == 0 ? FALSE : TRUE);\r
1906             } else if (pNode && pNode->GetClassID() == XFA_ELEMENT_Float) {\r
1907                 CFX_Decimal decimal(content);\r
1908                 FXJSE_Value_SetFloat(hValue, (FX_FLOAT)(double)decimal);\r
1909             } else {\r
1910                 FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(content, content.GetLength()));\r
1911             }\r
1912         }\r
1913     }\r
1914 }\r
1915 void CXFA_Node::Script_Field_EditValue(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1916 {\r
1917     CXFA_WidgetData* pWidgetData = GetWidgetData();\r
1918     if (!pWidgetData) {\r
1919         return;\r
1920     }\r
1921     CFX_WideString wsValue;\r
1922     if (bSetting) {\r
1923         CFX_ByteString bsValue;\r
1924         FXJSE_Value_ToUTF8String(hValue, bsValue);\r
1925         wsValue = CFX_WideString::FromUTF8(bsValue, bsValue.GetLength());\r
1926         pWidgetData->SetValue(wsValue, XFA_VALUEPICTURE_Edit);\r
1927     } else {\r
1928         pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Edit);\r
1929         FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsValue));\r
1930     }\r
1931 }\r
1932 void CXFA_Node::Script_Som_FontColor(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1933 {\r
1934     CXFA_WidgetData* pWidgetData = GetWidgetData();\r
1935     if (!pWidgetData) {\r
1936         return;\r
1937     }\r
1938     CXFA_Font font = pWidgetData->GetFont(TRUE);\r
1939     CXFA_Node *pNode = (CXFA_Node*)font;\r
1940     if (!pNode) {\r
1941         return;\r
1942     }\r
1943     CFX_WideString wsColor;\r
1944     if (bSetting) {\r
1945         CFX_ByteString bsValue;\r
1946         FXJSE_Value_ToUTF8String(hValue, bsValue);\r
1947         wsColor = CFX_WideString::FromUTF8(bsValue, bsValue.GetLength());\r
1948         int32_t r, g, b;\r
1949         XFA_STRING_TO_RGB(wsColor, r, g, b);\r
1950         FX_ARGB color = ArgbEncode(0xff, r, g, b);\r
1951         font.SetColor(color);\r
1952     } else {\r
1953         FX_ARGB color = font.GetColor();\r
1954         int32_t a, r, g, b;\r
1955         ArgbDecode(color, a, r, g, b);\r
1956         wsColor.Format(L"%d,%d,%d", r, g, b);\r
1957         FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsColor));\r
1958     }\r
1959 }\r
1960 void CXFA_Node::Script_Field_FormatMessage(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1961 {\r
1962     Script_Som_Message(hValue, bSetting, XFA_SOM_FormatMessage);\r
1963 }\r
1964 void CXFA_Node::Script_Field_FormattedValue(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1965 {\r
1966     CXFA_WidgetData* pWidgetData = GetWidgetData();\r
1967     if (!pWidgetData) {\r
1968         return;\r
1969     }\r
1970     CFX_WideString wsValue;\r
1971     if (bSetting) {\r
1972         CFX_ByteString bsValue;\r
1973         FXJSE_Value_ToUTF8String(hValue, bsValue);\r
1974         wsValue = CFX_WideString::FromUTF8(bsValue, bsValue.GetLength());\r
1975         pWidgetData->SetValue(wsValue, XFA_VALUEPICTURE_Display);\r
1976     } else {\r
1977         pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Display);\r
1978         FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsValue));\r
1979     }\r
1980 }\r
1981 void CXFA_Node::Script_Som_Mandatory(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
1982 {\r
1983     CXFA_WidgetData* pWidgetData = GetWidgetData();\r
1984     if (!pWidgetData) {\r
1985         return;\r
1986     }\r
1987     CXFA_Validate validate = pWidgetData->GetValidate(TRUE);\r
1988     CFX_WideString wsValue;\r
1989     if (bSetting) {\r
1990         CFX_ByteString bsValue;\r
1991         FXJSE_Value_ToUTF8String(hValue, bsValue);\r
1992         wsValue = CFX_WideString::FromUTF8(bsValue, bsValue.GetLength());\r
1993         validate.SetNullTest(wsValue);\r
1994     } else {\r
1995         int32_t iValue = validate.GetNullTest();\r
1996         XFA_LPCATTRIBUTEENUMINFO pInfo = XFA_GetAttributeEnumByID((XFA_ATTRIBUTEENUM)iValue);\r
1997         if (pInfo) {\r
1998             wsValue = pInfo->pName;\r
1999         }\r
2000         FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsValue));\r
2001     }\r
2002 }\r
2003 void CXFA_Node::Script_Som_MandatoryMessage(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
2004 {\r
2005     Script_Som_Message(hValue, bSetting, XFA_SOM_MandatoryMessage);\r
2006 }\r
2007 void CXFA_Node::Script_Field_ParentSubform(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
2008 {\r
2009     if (bSetting) {\r
2010         ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);\r
2011     } else {\r
2012         FXJSE_Value_SetNull(hValue);\r
2013     }\r
2014 }\r
2015 void CXFA_Node::Script_Field_SelectedIndex(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
2016 {\r
2017     CXFA_WidgetData* pWidgetData = GetWidgetData();\r
2018     if (!pWidgetData) {\r
2019         return;\r
2020     }\r
2021     if (bSetting) {\r
2022         int32_t iIndex = FXJSE_Value_ToInteger(hValue);\r
2023         if (iIndex == -1) {\r
2024             pWidgetData->ClearAllSelections();\r
2025             return;\r
2026         }\r
2027         pWidgetData->SetItemState(iIndex, TRUE, TRUE, TRUE);\r
2028     } else {\r
2029         FXJSE_Value_SetInteger(hValue, pWidgetData->GetSelectedItem());\r
2030     }\r
2031 }\r
2032 void CXFA_Node::Script_Field_ClearItems(CFXJSE_Arguments* pArguments)\r
2033 {\r
2034     CXFA_WidgetData* pWidgetData = GetWidgetData();\r
2035     if (!pWidgetData) {\r
2036         return;\r
2037     }\r
2038     pWidgetData->DeleteItem(-1, TRUE);\r
2039 }\r
2040 void CXFA_Node::Script_Field_ExecEvent(CFXJSE_Arguments* pArguments)\r
2041 {\r
2042     int32_t argc = pArguments->GetLength();\r
2043     if (argc == 1) {\r
2044         CFX_ByteString eventString = pArguments->GetUTF8String(0);\r
2045         int32_t iRet = execSingleEventByName(CFX_WideString::FromUTF8(eventString, eventString.GetLength()), XFA_ELEMENT_Field);\r
2046         if (eventString == FX_BSTRC("validate")) {\r
2047             FXJSE_Value_SetBoolean(pArguments->GetReturnValue(), ((iRet == XFA_EVENTERROR_Error) ? FALSE : TRUE));\r
2048         }\r
2049     } else {\r
2050         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent");\r
2051     }\r
2052 }\r
2053 void CXFA_Node::Script_Field_ExecInitialize(CFXJSE_Arguments* pArguments)\r
2054 {\r
2055     int32_t argc = pArguments->GetLength();\r
2056     if (argc == 0) {\r
2057         IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();\r
2058         if (!pNotify) {\r
2059             return;\r
2060         }\r
2061         pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize, FALSE, FALSE);\r
2062     } else {\r
2063         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");\r
2064     }\r
2065 }\r
2066 void CXFA_Node::Script_Field_DeleteItem(CFXJSE_Arguments* pArguments)\r
2067 {\r
2068     int32_t iLength = pArguments->GetLength();\r
2069     if (iLength != 1) {\r
2070         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"deleteItem");\r
2071         return;\r
2072     }\r
2073     CXFA_WidgetData* pWidgetData = GetWidgetData();\r
2074     if (!pWidgetData) {\r
2075         return;\r
2076     }\r
2077     int32_t iIndex = pArguments->GetInt32(0);\r
2078     FX_BOOL bValue = pWidgetData->DeleteItem(iIndex, TRUE, TRUE);\r
2079     FXJSE_HVALUE hValue = pArguments->GetReturnValue();\r
2080     if (hValue) {\r
2081         FXJSE_Value_SetBoolean(hValue, bValue);\r
2082     }\r
2083 }\r
2084 void CXFA_Node::Script_Field_GetSaveItem(CFXJSE_Arguments* pArguments)\r
2085 {\r
2086     int32_t iLength = pArguments->GetLength();\r
2087     if (iLength != 1) {\r
2088         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getSaveItem");\r
2089         return;\r
2090     }\r
2091     int32_t iIndex = pArguments->GetInt32(0);\r
2092     if (iIndex < 0) {\r
2093         FXJSE_Value_SetNull(pArguments->GetReturnValue());\r
2094         return;\r
2095     }\r
2096     CXFA_WidgetData* pWidgetData = GetWidgetData();\r
2097     if (!pWidgetData) {\r
2098         FXJSE_Value_SetNull(pArguments->GetReturnValue());\r
2099         return;\r
2100     }\r
2101     CFX_WideString wsValue;\r
2102     FX_BOOL bHasItem = pWidgetData->GetChoiceListItem(wsValue, iIndex, TRUE);\r
2103     if (bHasItem) {\r
2104         FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), FX_UTF8Encode(wsValue, wsValue.GetLength()));\r
2105     } else {\r
2106         FXJSE_Value_SetNull(pArguments->GetReturnValue());\r
2107     }\r
2108 }\r
2109 void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments)\r
2110 {\r
2111     int32_t iLength = pArguments->GetLength();\r
2112     if (iLength != 1) {\r
2113         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"boundItem");\r
2114         return;\r
2115     }\r
2116     CXFA_WidgetData* pWidgetData = GetWidgetData();\r
2117     if (!pWidgetData) {\r
2118         return;\r
2119     }\r
2120     CFX_ByteString bsValue = pArguments->GetUTF8String(0);\r
2121     CFX_WideString wsValue = CFX_WideString::FromUTF8(bsValue, bsValue.GetLength());\r
2122     CFX_WideString wsBoundValue;\r
2123     pWidgetData->GetItemValue(wsValue, wsBoundValue);\r
2124     FXJSE_HVALUE hValue = pArguments->GetReturnValue();\r
2125     if (hValue) {\r
2126         FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsBoundValue));\r
2127     }\r
2128 }\r
2129 void CXFA_Node::Script_Field_GetItemState(CFXJSE_Arguments* pArguments)\r
2130 {\r
2131     int32_t iLength = pArguments->GetLength();\r
2132     if (iLength != 1) {\r
2133         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getItemState");\r
2134         return;\r
2135     }\r
2136     CXFA_WidgetData* pWidgetData = GetWidgetData();\r
2137     if (!pWidgetData) {\r
2138         return;\r
2139     }\r
2140     int32_t iIndex = pArguments->GetInt32(0);\r
2141     FX_BOOL bValue = pWidgetData->GetItemState(iIndex);\r
2142     FXJSE_HVALUE hValue = pArguments->GetReturnValue();\r
2143     if (hValue) {\r
2144         FXJSE_Value_SetBoolean(hValue, bValue);\r
2145     }\r
2146 }\r
2147 void CXFA_Node::Script_Field_ExecCalculate(CFXJSE_Arguments* pArguments)\r
2148 {\r
2149     int32_t argc = pArguments->GetLength();\r
2150     if (argc == 0) {\r
2151         IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();\r
2152         if (!pNotify) {\r
2153             return;\r
2154         }\r
2155         pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate, FALSE, FALSE);\r
2156     } else {\r
2157         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");\r
2158     }\r
2159 }\r
2160 void CXFA_Node::Script_Field_SetItems(CFXJSE_Arguments* pArguments)\r
2161 {\r
2162 }\r
2163 void CXFA_Node::Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments)\r
2164 {\r
2165     int32_t iLength = pArguments->GetLength();\r
2166     if (iLength != 1) {\r
2167         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getDisplayItem");\r
2168         return;\r
2169     }\r
2170     int32_t iIndex = pArguments->GetInt32(0);\r
2171     if (iIndex < 0) {\r
2172         FXJSE_Value_SetNull(pArguments->GetReturnValue());\r
2173         return;\r
2174     }\r
2175     CXFA_WidgetData* pWidgetData = GetWidgetData();\r
2176     if (!pWidgetData) {\r
2177         FXJSE_Value_SetNull(pArguments->GetReturnValue());\r
2178         return;\r
2179     }\r
2180     CFX_WideString wsValue;\r
2181     FX_BOOL bHasItem = pWidgetData->GetChoiceListItem(wsValue, iIndex, FALSE);\r
2182     if (bHasItem) {\r
2183         FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), FX_UTF8Encode(wsValue, wsValue.GetLength()));\r
2184     } else {\r
2185         FXJSE_Value_SetNull(pArguments->GetReturnValue());\r
2186     }\r
2187 }\r
2188 void CXFA_Node::Script_Field_SetItemState(CFXJSE_Arguments* pArguments)\r
2189 {\r
2190     int32_t iLength = pArguments->GetLength();\r
2191     if (iLength != 2) {\r
2192         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setItemState");\r
2193         return;\r
2194     }\r
2195     CXFA_WidgetData* pWidgetData = GetWidgetData();\r
2196     if (!pWidgetData) {\r
2197         return;\r
2198     }\r
2199     int32_t iIndex = pArguments->GetInt32(0);\r
2200     FX_BOOL bAdd = pArguments->GetInt32(1) == 0 ? FALSE : TRUE;\r
2201     if (bAdd) {\r
2202         pWidgetData->SetItemState(iIndex, TRUE, TRUE, TRUE);\r
2203     } else {\r
2204         if (pWidgetData->GetItemState(iIndex)) {\r
2205             pWidgetData->SetItemState(iIndex, FALSE, TRUE, TRUE);\r
2206         }\r
2207     }\r
2208 }\r
2209 void CXFA_Node::Script_Field_AddItem(CFXJSE_Arguments* pArguments)\r
2210 {\r
2211     int32_t iLength = pArguments->GetLength();\r
2212     if (iLength < 1 || iLength > 2) {\r
2213         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"addItem");\r
2214         return;\r
2215     }\r
2216     CXFA_WidgetData* pWidgetData = GetWidgetData();\r
2217     if (!pWidgetData) {\r
2218         return;\r
2219     }\r
2220     CFX_WideString wsLabel;\r
2221     CFX_WideString wsValue;\r
2222     if (iLength >= 1) {\r
2223         CFX_ByteString bsLable = pArguments->GetUTF8String(0);\r
2224         wsLabel = CFX_WideString::FromUTF8(bsLable, bsLable.GetLength());\r
2225     }\r
2226     if (iLength >= 2) {\r
2227         CFX_ByteString bsValue = pArguments->GetUTF8String(1);\r
2228         wsValue = CFX_WideString::FromUTF8(bsValue, bsValue.GetLength());\r
2229     }\r
2230     pWidgetData->InsertItem(wsLabel, wsValue, -1, TRUE);\r
2231 }\r
2232 void CXFA_Node::Script_Field_ExecValidate(CFXJSE_Arguments* pArguments)\r
2233 {\r
2234     int32_t argc = pArguments->GetLength();\r
2235     if (argc == 0) {\r
2236         IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();\r
2237         if (!pNotify) {\r
2238             FXJSE_Value_SetBoolean(pArguments->GetReturnValue(), FALSE);\r
2239         } else {\r
2240             int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate, FALSE, FALSE);\r
2241             FXJSE_Value_SetBoolean(pArguments->GetReturnValue(), ((iRet == XFA_EVENTERROR_Error) ? FALSE : TRUE));\r
2242         }\r
2243     } else {\r
2244         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");\r
2245     }\r
2246 }\r
2247 void CXFA_Node::Script_ExclGroup_ErrorText(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
2248 {\r
2249     if (!bSetting) {\r
2250     } else {\r
2251         ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);\r
2252     }\r
2253 }\r
2254 void CXFA_Node::Script_ExclGroup_DefaultAndRawValue(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
2255 {\r
2256     CXFA_WidgetData* pWidgetData = GetWidgetData();\r
2257     if(!pWidgetData) {\r
2258         return;\r
2259     }\r
2260     if (bSetting) {\r
2261         CFX_ByteString bsValue;\r
2262         FXJSE_Value_ToUTF8String(hValue, bsValue);\r
2263         pWidgetData->SetSelectedMemberByValue(CFX_WideString::FromUTF8(bsValue, bsValue.GetLength()), TRUE, TRUE);\r
2264     } else {\r
2265         CFX_WideString wsValue = GetScriptContent(TRUE);\r
2266         XFA_VERSION curVersion = GetDocument()->GetCurVersionMode();\r
2267         if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) {\r
2268             FXJSE_Value_SetNull(hValue);\r
2269         } else {\r
2270             FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsValue));\r
2271         }\r
2272     }\r
2273 }\r
2274 void CXFA_Node::Script_ExclGroup_Transient(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
2275 {\r
2276 }\r
2277 void CXFA_Node::Script_ExclGroup_ExecEvent(CFXJSE_Arguments* pArguments)\r
2278 {\r
2279     int32_t argc = pArguments->GetLength();\r
2280     if (argc == 1) {\r
2281         CFX_ByteString eventString = pArguments->GetUTF8String(0);\r
2282         execSingleEventByName(CFX_WideString::FromUTF8(eventString, eventString.GetLength()), XFA_ELEMENT_ExclGroup);\r
2283     } else {\r
2284         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent");\r
2285     }\r
2286 }\r
2287 void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments)\r
2288 {\r
2289     int32_t argc = pArguments->GetLength();\r
2290     if ((argc == 0) || (argc == 1)) {\r
2291         CXFA_WidgetData* pWidgetData = GetWidgetData();\r
2292         if (!pWidgetData) {\r
2293             FXJSE_Value_SetNull(pArguments->GetReturnValue());\r
2294         } else {\r
2295             CXFA_Node * pReturnNode = NULL;\r
2296             if (argc == 0) {\r
2297                 pReturnNode = pWidgetData->GetSelectedMember();\r
2298             } else {\r
2299                 CFX_ByteString szName;\r
2300                 szName = pArguments->GetUTF8String(0);\r
2301                 pReturnNode = pWidgetData->SetSelectedMember(CFX_WideString::FromUTF8(szName, szName.GetLength()));\r
2302             }\r
2303             if (pReturnNode) {\r
2304                 FXJSE_Value_Set(pArguments->GetReturnValue(), m_pDocument->GetScriptContext()->GetJSValueFromMap(pReturnNode));\r
2305             } else {\r
2306                 FXJSE_Value_SetNull(pArguments->GetReturnValue());\r
2307             }\r
2308         }\r
2309     } else {\r
2310         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"selectedMember");\r
2311     }\r
2312 }\r
2313 void CXFA_Node::Script_ExclGroup_ExecInitialize(CFXJSE_Arguments* pArguments)\r
2314 {\r
2315     int32_t argc = pArguments->GetLength();\r
2316     if (argc == 0) {\r
2317         IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();\r
2318         if (!pNotify) {\r
2319             return;\r
2320         }\r
2321         pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);\r
2322     } else {\r
2323         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");\r
2324     }\r
2325 }\r
2326 void CXFA_Node::Script_ExclGroup_ExecCalculate(CFXJSE_Arguments* pArguments)\r
2327 {\r
2328     int32_t argc = pArguments->GetLength();\r
2329     if (argc == 0) {\r
2330         IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();\r
2331         if (!pNotify) {\r
2332             return;\r
2333         }\r
2334         pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);\r
2335     } else {\r
2336         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");\r
2337     }\r
2338 }\r
2339 void CXFA_Node::Script_ExclGroup_ExecValidate(CFXJSE_Arguments* pArguments)\r
2340 {\r
2341     int32_t argc = pArguments->GetLength();\r
2342     if (argc == 0) {\r
2343         IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();\r
2344         if (!pNotify) {\r
2345             FXJSE_Value_SetBoolean(pArguments->GetReturnValue(), FALSE);\r
2346         } else {\r
2347             int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);\r
2348             FXJSE_Value_SetBoolean(pArguments->GetReturnValue(), ((iRet == XFA_EVENTERROR_Error) ? FALSE : TRUE));\r
2349         }\r
2350     } else {\r
2351         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");\r
2352     }\r
2353 }\r
2354 static CXFA_Node* XFA_ScriptInstanceManager_GetItem(CXFA_Node *pInstMgrNode, int32_t iIndex)\r
2355 {\r
2356     ASSERT(pInstMgrNode);\r
2357     int32_t iCount = 0;\r
2358     FX_DWORD dwNameHash = 0;\r
2359     for(CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling); pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {\r
2360         XFA_ELEMENT eCurType = pNode->GetClassID();\r
2361         if (eCurType == XFA_ELEMENT_InstanceManager) {\r
2362             break;\r
2363         }\r
2364         if ((eCurType != XFA_ELEMENT_Subform) && (eCurType != XFA_ELEMENT_SubformSet)) {\r
2365             continue;\r
2366         }\r
2367         if (iCount == 0) {\r
2368             CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);\r
2369             CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);\r
2370             if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' || wsInstName.Mid(1) != wsName) {\r
2371                 return NULL;\r
2372             }\r
2373             dwNameHash = pNode->GetNameHash();\r
2374         }\r
2375         if (dwNameHash != pNode->GetNameHash()) {\r
2376             break;\r
2377         }\r
2378         iCount ++;\r
2379         if (iCount > iIndex) {\r
2380             return pNode;\r
2381         }\r
2382     }\r
2383     return NULL;\r
2384 }\r
2385 void CXFA_Node::Script_Som_InstanceIndex(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
2386 {\r
2387     if (bSetting) {\r
2388         int32_t iTo = FXJSE_Value_ToInteger(hValue);\r
2389         int32_t iFrom = Subform_and_SubformSet_InstanceIndex();\r
2390         CXFA_Node *pManagerNode = NULL;\r
2391         for (CXFA_Node *pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode != NULL; pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {\r
2392             if (pNode->GetClassID() == XFA_ELEMENT_InstanceManager) {\r
2393                 pManagerNode = pNode;\r
2394                 break;\r
2395             }\r
2396         }\r
2397         if (pManagerNode) {\r
2398             pManagerNode->InstanceManager_MoveInstance(iTo, iFrom);\r
2399             IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();\r
2400             if (!pNotify) {\r
2401                 return;\r
2402             }\r
2403             CXFA_Node* pToInstance = XFA_ScriptInstanceManager_GetItem(pManagerNode, iTo);\r
2404             if (pToInstance && pToInstance->GetClassID() == XFA_ELEMENT_Subform) {\r
2405                 pNotify->RunSubformIndexChange(pToInstance);\r
2406             }\r
2407             CXFA_Node* pFromInstance = XFA_ScriptInstanceManager_GetItem(pManagerNode, iFrom);\r
2408             if (pFromInstance && pFromInstance->GetClassID() == XFA_ELEMENT_Subform) {\r
2409                 pNotify->RunSubformIndexChange(pFromInstance);\r
2410             }\r
2411         }\r
2412     } else {\r
2413         FXJSE_Value_SetInteger(hValue, Subform_and_SubformSet_InstanceIndex());\r
2414     }\r
2415 }\r
2416 void CXFA_Node::Script_Subform_InstanceManager(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
2417 {\r
2418     if (!bSetting) {\r
2419         CFX_WideStringC wsName = this->GetCData(XFA_ATTRIBUTE_Name);\r
2420         CXFA_Node* pInstanceMgr = NULL;\r
2421         for (CXFA_Node *pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode != NULL; pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {\r
2422             if (pNode->GetClassID() == XFA_ELEMENT_InstanceManager) {\r
2423                 CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name);\r
2424                 if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' && wsInstMgrName.Mid(1) == wsName) {\r
2425                     pInstanceMgr = pNode;\r
2426                 }\r
2427                 break;\r
2428             }\r
2429         }\r
2430         if (pInstanceMgr) {\r
2431             FXJSE_Value_Set(hValue, m_pDocument->GetScriptContext()->GetJSValueFromMap(pInstanceMgr));\r
2432         } else {\r
2433             FXJSE_Value_SetNull(hValue);\r
2434         }\r
2435     } else {\r
2436         ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);\r
2437     }\r
2438 }\r
2439 void CXFA_Node::Script_Subform_Locale(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
2440 {\r
2441     if (bSetting) {\r
2442         CFX_ByteString bsLocaleName;\r
2443         FXJSE_Value_ToUTF8String(hValue, bsLocaleName);\r
2444         this->SetCData(XFA_ATTRIBUTE_Locale, CFX_WideString::FromUTF8(bsLocaleName, bsLocaleName.GetLength()), TRUE, TRUE);\r
2445     } else {\r
2446         CFX_WideString wsLocaleName;\r
2447         GetLocaleName(wsLocaleName);\r
2448         FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(wsLocaleName, wsLocaleName.GetLength()));\r
2449     }\r
2450 }\r
2451 void CXFA_Node::Script_Subform_ExecEvent(CFXJSE_Arguments* pArguments)\r
2452 {\r
2453     int32_t argc = pArguments->GetLength();\r
2454     if (argc == 1) {\r
2455         CFX_ByteString eventString = pArguments->GetUTF8String(0);\r
2456         execSingleEventByName(CFX_WideString::FromUTF8(eventString, eventString.GetLength()), XFA_ELEMENT_Subform);\r
2457     } else {\r
2458         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent");\r
2459     }\r
2460 }\r
2461 void CXFA_Node::Script_Subform_ExecInitialize(CFXJSE_Arguments* pArguments)\r
2462 {\r
2463     int32_t argc = pArguments->GetLength();\r
2464     if (argc == 0) {\r
2465         IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();\r
2466         if (!pNotify) {\r
2467             return;\r
2468         }\r
2469         pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);\r
2470     } else {\r
2471         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");\r
2472     }\r
2473 }\r
2474 void CXFA_Node::Script_Subform_ExecCalculate(CFXJSE_Arguments* pArguments)\r
2475 {\r
2476     int32_t argc = pArguments->GetLength();\r
2477     if (argc == 0) {\r
2478         IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();\r
2479         if (!pNotify) {\r
2480             return;\r
2481         }\r
2482         pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);\r
2483     } else {\r
2484         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");\r
2485     }\r
2486 }\r
2487 void CXFA_Node::Script_Subform_ExecValidate(CFXJSE_Arguments* pArguments)\r
2488 {\r
2489     int32_t argc = pArguments->GetLength();\r
2490     if (argc == 0) {\r
2491         IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();\r
2492         if (!pNotify) {\r
2493             FXJSE_Value_SetBoolean(pArguments->GetReturnValue(), FALSE);\r
2494         } else {\r
2495             int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);\r
2496             FXJSE_Value_SetBoolean(pArguments->GetReturnValue(), ((iRet == XFA_EVENTERROR_Error) ? FALSE : TRUE));\r
2497         }\r
2498     } else {\r
2499         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");\r
2500     }\r
2501 }\r
2502 void CXFA_Node::Script_Subform_GetInvalidObjects(CFXJSE_Arguments* pArguments)\r
2503 {\r
2504     int32_t argc = pArguments->GetLength();\r
2505     if (argc == 0) {\r
2506     } else {\r
2507         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getInvalidObjects");\r
2508     }\r
2509 }\r
2510 int32_t CXFA_Node::Subform_and_SubformSet_InstanceIndex()\r
2511 {\r
2512     int32_t index = 0;\r
2513     for (CXFA_Node *pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode != NULL; pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {\r
2514         if ((pNode->GetClassID() == XFA_ELEMENT_Subform) || (pNode->GetClassID() == XFA_ELEMENT_SubformSet)) {\r
2515             index++;\r
2516         } else {\r
2517             break;\r
2518         }\r
2519     }\r
2520     return index;\r
2521 }\r
2522 void CXFA_Node::Script_Template_FormNodes(CFXJSE_Arguments* pArguments)\r
2523 {\r
2524     int32_t argc = pArguments->GetLength();\r
2525     if (argc == 1) {\r
2526         FXJSE_Value_SetBoolean(pArguments->GetReturnValue(), TRUE);\r
2527     } else {\r
2528         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"formNodes");\r
2529     }\r
2530 }\r
2531 void CXFA_Node::Script_Template_Remerge(CFXJSE_Arguments* pArguments)\r
2532 {\r
2533     int32_t argc = pArguments->GetLength();\r
2534     if (argc == 0) {\r
2535         m_pDocument->DoDataRemerge(TRUE);\r
2536     } else {\r
2537         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"remerge");\r
2538     }\r
2539 }\r
2540 void CXFA_Node::Script_Template_ExecInitialize(CFXJSE_Arguments* pArguments)\r
2541 {\r
2542     int32_t argc = pArguments->GetLength();\r
2543     if (argc == 0) {\r
2544         CXFA_WidgetData* pWidgetData = GetWidgetData();\r
2545         if (!pWidgetData) {\r
2546             FXJSE_Value_SetBoolean(pArguments->GetReturnValue(), FALSE);\r
2547         } else {\r
2548             FXJSE_Value_SetBoolean(pArguments->GetReturnValue(), TRUE);\r
2549         }\r
2550     } else {\r
2551         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");\r
2552     }\r
2553 }\r
2554 void CXFA_Node::Script_Template_CreateNode(CFXJSE_Arguments* pArguments)\r
2555 {\r
2556     int32_t argc = pArguments->GetLength();\r
2557     if ((argc > 0) && (argc < 4)) {\r
2558         CFX_WideString strTagName;\r
2559         CFX_WideString strName;\r
2560         CFX_WideString strNameSpace;\r
2561         CFX_ByteString bsTagName = pArguments->GetUTF8String(0);\r
2562         strTagName = CFX_WideString::FromUTF8(bsTagName, bsTagName.GetLength());\r
2563         if (argc > 1) {\r
2564             CFX_ByteString bsName = pArguments->GetUTF8String(1);\r
2565             strName = CFX_WideString::FromUTF8(bsName, bsName.GetLength());\r
2566             if (argc == 3) {\r
2567                 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(2);\r
2568                 strNameSpace = CFX_WideString::FromUTF8(bsNameSpace, bsNameSpace.GetLength());\r
2569             }\r
2570         }\r
2571         XFA_LPCELEMENTINFO pElement = XFA_GetElementByName(strTagName);\r
2572         CXFA_Node *pNewNode = CreateSamePacketNode(pElement->eName);\r
2573         if (!pNewNode) {\r
2574             FXJSE_Value_SetNull(pArguments->GetReturnValue());\r
2575         } else {\r
2576             if (!strName.IsEmpty()) {\r
2577                 if ( XFA_GetAttributeOfElement(pElement->eName, XFA_ATTRIBUTE_Name, XFA_XDPPACKET_UNKNOWN)) {\r
2578                     pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, strName, TRUE);\r
2579                     if (pNewNode->GetPacketID() == XFA_XDPPACKET_Datasets) {\r
2580                         pNewNode->CreateXMLMappingNode();\r
2581                     }\r
2582                     FXJSE_Value_Set(pArguments->GetReturnValue(), m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));\r
2583                 } else {\r
2584                     ThrowScriptErrorMessage(XFA_IDS_NOT_HAVE_PROPERTY, (FX_LPCWSTR)strTagName, L"name");\r
2585                 }\r
2586             } else {\r
2587                 FXJSE_Value_Set(pArguments->GetReturnValue(), m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode));\r
2588             }\r
2589         }\r
2590     } else {\r
2591         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"createNode");\r
2592     }\r
2593 }\r
2594 void CXFA_Node::Script_Template_Recalculate(CFXJSE_Arguments* pArguments)\r
2595 {\r
2596     int32_t argc = pArguments->GetLength();\r
2597     if (argc == 1) {\r
2598         FX_BOOL bScriptFlags = pArguments->GetInt32(0) == 0 ? FALSE : TRUE;\r
2599         FXJSE_Value_SetBoolean(pArguments->GetReturnValue(), TRUE);\r
2600     } else {\r
2601         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"recalculate");\r
2602     }\r
2603 }\r
2604 void CXFA_Node::Script_Template_ExecCalculate(CFXJSE_Arguments* pArguments)\r
2605 {\r
2606     int32_t argc = pArguments->GetLength();\r
2607     if (argc == 0) {\r
2608         CXFA_WidgetData* pWidgetData = GetWidgetData();\r
2609         if (!pWidgetData) {\r
2610             FXJSE_Value_SetBoolean(pArguments->GetReturnValue(), FALSE);\r
2611         } else {\r
2612             FXJSE_Value_SetBoolean(pArguments->GetReturnValue(), TRUE);\r
2613         }\r
2614     } else {\r
2615         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");\r
2616     }\r
2617 }\r
2618 void CXFA_Node::Script_Template_ExecValidate(CFXJSE_Arguments* pArguments)\r
2619 {\r
2620     int32_t argc = pArguments->GetLength();\r
2621     if (argc == 0) {\r
2622         CXFA_WidgetData* pWidgetData = GetWidgetData();\r
2623         if (!pWidgetData) {\r
2624             FXJSE_Value_SetBoolean(pArguments->GetReturnValue(), FALSE);\r
2625         } else {\r
2626             FXJSE_Value_SetBoolean(pArguments->GetReturnValue(), TRUE);\r
2627         }\r
2628     } else {\r
2629         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");\r
2630     }\r
2631 }\r
2632 void CXFA_Node::Script_Manifest_Evaluate(CFXJSE_Arguments* pArguments)\r
2633 {\r
2634     int32_t argc = pArguments->GetLength();\r
2635     if (argc == 0) {\r
2636         CXFA_WidgetData* pWidgetData = GetWidgetData();\r
2637         if (!pWidgetData) {\r
2638             FXJSE_Value_SetBoolean(pArguments->GetReturnValue(), FALSE);\r
2639         } else {\r
2640             FXJSE_Value_SetBoolean(pArguments->GetReturnValue(), TRUE);\r
2641         }\r
2642     } else {\r
2643         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"evaluate");\r
2644     }\r
2645 }\r
2646 void CXFA_Node::Script_InstanceManager_Max(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
2647 {\r
2648     if (bSetting) {\r
2649         ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);\r
2650         return;\r
2651     } else {\r
2652         CXFA_Occur nodeOccur = GetOccurNode();\r
2653         FXJSE_Value_SetInteger(hValue, nodeOccur.GetMax());\r
2654     }\r
2655 }\r
2656 void CXFA_Node::Script_InstanceManager_Min(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
2657 {\r
2658     if (bSetting) {\r
2659         ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);\r
2660         return;\r
2661     } else {\r
2662         CXFA_Occur nodeOccur = GetOccurNode();\r
2663         FXJSE_Value_SetInteger(hValue, nodeOccur.GetMin());\r
2664     }\r
2665 }\r
2666 static int32_t XFA_ScriptInstanceManager_GetCount(CXFA_Node *pInstMgrNode)\r
2667 {\r
2668     ASSERT(pInstMgrNode);\r
2669     int32_t iCount = 0;\r
2670     FX_DWORD dwNameHash = 0;\r
2671     for(CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling); pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {\r
2672         XFA_ELEMENT eCurType = pNode->GetClassID();\r
2673         if (eCurType == XFA_ELEMENT_InstanceManager) {\r
2674             break;\r
2675         }\r
2676         if ((eCurType != XFA_ELEMENT_Subform) && (eCurType != XFA_ELEMENT_SubformSet)) {\r
2677             continue;\r
2678         }\r
2679         if (iCount == 0) {\r
2680             CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);\r
2681             CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);\r
2682             if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' || wsInstName.Mid(1) != wsName) {\r
2683                 return iCount;\r
2684             }\r
2685             dwNameHash = pNode->GetNameHash();\r
2686         }\r
2687         if (dwNameHash != pNode->GetNameHash()) {\r
2688             break;\r
2689         }\r
2690         iCount ++;\r
2691     }\r
2692     return iCount;\r
2693 }\r
2694 static void XFA_ScriptInstanceManager_ReorderDataNodes_SortNodeArrayByDocumentIdx(const CXFA_NodeSet& rgNodeSet, CXFA_NodeArray& rgNodeArray, CFX_ArrayTemplate<int32_t>& rgIdxArray)\r
2695 {\r
2696     int32_t iCount = rgNodeSet.GetCount();\r
2697     rgNodeArray.SetSize(iCount);\r
2698     rgIdxArray.SetSize(iCount);\r
2699     if(iCount == 0) {\r
2700         return;\r
2701     }\r
2702     int32_t iIndex = -1, iTotalIndex = -1;\r
2703     CXFA_Node* pNode = NULL;\r
2704     FX_POSITION pos = rgNodeSet.GetStartPosition();\r
2705     rgNodeSet.GetNextAssoc(pos, pNode);\r
2706     for(pNode = pNode->GetNodeItem(XFA_NODEITEM_Parent)->GetNodeItem(XFA_NODEITEM_FirstChild);\r
2707             pNode && iIndex < iCount;\r
2708             pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {\r
2709         iTotalIndex++;\r
2710         if(rgNodeSet.Lookup(pNode)) {\r
2711             iIndex ++;\r
2712             rgNodeArray[iIndex] = pNode;\r
2713             rgIdxArray[iIndex] = iTotalIndex;\r
2714         }\r
2715     }\r
2716 }\r
2717 struct CXFA_DualNodeArray {\r
2718     CXFA_NodeSet firstNodeList;\r
2719     CXFA_NodeSet secondNodeList;\r
2720 };\r
2721 static void XFA_ScriptInstanceManager_ReorderDataNodes(CXFA_NodeSet& sSet1, CXFA_NodeSet& sSet2, FX_BOOL bInsertBefore)\r
2722 {\r
2723     CFX_MapPtrTemplate<CXFA_Node*, CFX_MapPtrTemplate<FX_DWORD, CXFA_DualNodeArray*>*> rgNodeListMap;\r
2724     FX_POSITION pos;\r
2725     pos = sSet1.GetStartPosition();\r
2726     while(pos) {\r
2727         CXFA_Node* pNode = NULL;\r
2728         sSet1.GetNextAssoc(pos, pNode);\r
2729         CXFA_Node* pParentNode = pNode->GetNodeItem(XFA_NODEITEM_Parent);\r
2730         FX_DWORD dwNameHash = pNode->GetNameHash();\r
2731         if(!pParentNode || !dwNameHash) {\r
2732             continue;\r
2733         }\r
2734         CFX_MapPtrTemplate<FX_DWORD, CXFA_DualNodeArray*>* pNodeListChildMap = rgNodeListMap[pParentNode];\r
2735         if(!pNodeListChildMap) {\r
2736             rgNodeListMap[pParentNode] = pNodeListChildMap = FX_NEW CFX_MapPtrTemplate<FX_DWORD, CXFA_DualNodeArray*>;\r
2737         }\r
2738         CXFA_DualNodeArray* pDualNodeArray = (*pNodeListChildMap)[dwNameHash];\r
2739         if(!pDualNodeArray) {\r
2740             (*pNodeListChildMap)[dwNameHash] = pDualNodeArray = FX_NEW CXFA_DualNodeArray;\r
2741         }\r
2742         pDualNodeArray->firstNodeList.Add(pNode);\r
2743     }\r
2744     pos = sSet2.GetStartPosition();\r
2745     while(pos) {\r
2746         CXFA_Node* pNode = NULL;\r
2747         sSet2.GetNextAssoc(pos, pNode);\r
2748         CXFA_Node* pParentNode = pNode->GetNodeItem(XFA_NODEITEM_Parent);\r
2749         FX_DWORD dwNameHash = pNode->GetNameHash();\r
2750         if(!pParentNode || !dwNameHash) {\r
2751             continue;\r
2752         }\r
2753         CFX_MapPtrTemplate<FX_DWORD, CXFA_DualNodeArray*>* pNodeListChildMap = rgNodeListMap[pParentNode];\r
2754         if(!pNodeListChildMap) {\r
2755             rgNodeListMap[pParentNode] = pNodeListChildMap = FX_NEW CFX_MapPtrTemplate<FX_DWORD, CXFA_DualNodeArray*>;\r
2756         }\r
2757         CXFA_DualNodeArray* pDualNodeArray = (*pNodeListChildMap)[dwNameHash];\r
2758         if(!pDualNodeArray) {\r
2759             (*pNodeListChildMap)[dwNameHash] = pDualNodeArray = FX_NEW CXFA_DualNodeArray;\r
2760         }\r
2761         if(pDualNodeArray->firstNodeList.Lookup(pNode)) {\r
2762             pDualNodeArray->firstNodeList.RemoveKey(pNode);\r
2763         } else {\r
2764             pDualNodeArray->secondNodeList.Add(pNode);\r
2765         }\r
2766     }\r
2767     pos = rgNodeListMap.GetStartPosition();\r
2768     while (pos) {\r
2769         CXFA_Node* pParentNode = NULL;\r
2770         CFX_MapPtrTemplate<FX_DWORD, CXFA_DualNodeArray*>* pNodeListChildMap = NULL;\r
2771         rgNodeListMap.GetNextAssoc(pos, pParentNode, pNodeListChildMap);\r
2772         if(!pNodeListChildMap) {\r
2773             continue;\r
2774         }\r
2775         FX_POSITION childpos = pNodeListChildMap->GetStartPosition();\r
2776         while(childpos) {\r
2777             FX_DWORD dwNameHash = 0;\r
2778             CXFA_DualNodeArray* pDualNodeArray = NULL;\r
2779             pNodeListChildMap->GetNextAssoc(childpos, dwNameHash, pDualNodeArray);\r
2780             if(!pDualNodeArray) {\r
2781                 continue;\r
2782             }\r
2783             if(pDualNodeArray->firstNodeList.GetCount() != 0 && pDualNodeArray->secondNodeList.GetCount() != 0) {\r
2784                 CXFA_NodeArray rgNodeArray1, rgNodeArray2;\r
2785                 CFX_ArrayTemplate<int32_t> rgIdxArray1, rgIdxArray2;\r
2786                 XFA_ScriptInstanceManager_ReorderDataNodes_SortNodeArrayByDocumentIdx(pDualNodeArray->firstNodeList, rgNodeArray1, rgIdxArray1);\r
2787                 XFA_ScriptInstanceManager_ReorderDataNodes_SortNodeArrayByDocumentIdx(pDualNodeArray->secondNodeList, rgNodeArray2, rgIdxArray2);\r
2788                 int32_t iLimit;\r
2789                 CXFA_Node *pParentNode = NULL, *pBeforeNode = NULL;\r
2790                 if(bInsertBefore) {\r
2791                     iLimit = rgIdxArray2[0];\r
2792                     pBeforeNode = rgNodeArray2[0];\r
2793                     pParentNode = pBeforeNode->GetNodeItem(XFA_NODEITEM_Parent);\r
2794                 } else {\r
2795                     iLimit = rgIdxArray2[rgIdxArray2.GetSize() - 1];\r
2796                     CXFA_Node *pLastNode = rgNodeArray2[rgIdxArray2.GetSize() - 1];\r
2797                     pParentNode = pLastNode->GetNodeItem(XFA_NODEITEM_Parent);\r
2798                     pBeforeNode = pLastNode->GetNodeItem(XFA_NODEITEM_NextSibling);\r
2799                 }\r
2800                 for(int32_t iIdx = 0, iCount = rgIdxArray1.GetSize(); iIdx < iCount; iIdx++) {\r
2801                     CXFA_Node* pCurNode = rgNodeArray1[iIdx];\r
2802                     pParentNode->RemoveChild(pCurNode);\r
2803                     pParentNode->InsertChild(pCurNode, pBeforeNode);\r
2804                 }\r
2805             }\r
2806             delete pDualNodeArray;\r
2807         }\r
2808         pNodeListChildMap->RemoveAll();\r
2809     }\r
2810     rgNodeListMap.RemoveAll();\r
2811 }\r
2812 static void XFA_ScriptInstanceManager_InsertItem(CXFA_Node *pInstMgrNode, CXFA_Node *pNewInstance, int32_t iPos, int32_t iCount = -1, FX_BOOL bMoveDataBindingNodes = TRUE)\r
2813 {\r
2814     if(iCount < 0) {\r
2815         iCount = XFA_ScriptInstanceManager_GetCount(pInstMgrNode);\r
2816     }\r
2817     if(iPos < 0) {\r
2818         iPos = iCount;\r
2819     }\r
2820     if(iPos == iCount) {\r
2821         CXFA_Node* pNextSibling = iCount > 0 ? XFA_ScriptInstanceManager_GetItem(pInstMgrNode, iCount - 1)->GetNodeItem(XFA_NODEITEM_NextSibling)\r
2822                                   : pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);\r
2823         pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)->InsertChild(pNewInstance, pNextSibling);\r
2824         if(bMoveDataBindingNodes) {\r
2825             CXFA_NodeSet sNew, sAfter;\r
2826             CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFAContainerNode> sIteratorNew(pNewInstance);\r
2827             for(CXFA_Node *pNode = sIteratorNew.GetCurrent(); pNode; pNode = sIteratorNew.MoveToNext()) {\r
2828                 CXFA_Node *pDataNode = pNode->GetBindData();\r
2829                 if(!pDataNode) {\r
2830                     continue;\r
2831                 }\r
2832                 sNew.Add(pDataNode);\r
2833             }\r
2834             CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFAContainerNode> sIteratorAfter(pNextSibling);\r
2835             for(CXFA_Node *pNode = sIteratorAfter.GetCurrent(); pNode; pNode = sIteratorAfter.MoveToNext()) {\r
2836                 CXFA_Node *pDataNode = pNode->GetBindData();\r
2837                 if(!pDataNode) {\r
2838                     continue;\r
2839                 }\r
2840                 sAfter.Add(pDataNode);\r
2841             }\r
2842             XFA_ScriptInstanceManager_ReorderDataNodes(sNew, sAfter, FALSE);\r
2843         }\r
2844     } else {\r
2845         CXFA_Node * pBeforeInstance = XFA_ScriptInstanceManager_GetItem(pInstMgrNode, iPos);\r
2846         pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)->InsertChild(pNewInstance, pBeforeInstance);\r
2847         if(bMoveDataBindingNodes) {\r
2848             CXFA_NodeSet sNew, sBefore;\r
2849             CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFAContainerNode> sIteratorNew(pNewInstance);\r
2850             for(CXFA_Node *pNode = sIteratorNew.GetCurrent(); pNode; pNode = sIteratorNew.MoveToNext()) {\r
2851                 CXFA_Node *pDataNode = pNode->GetBindData();\r
2852                 if(!pDataNode) {\r
2853                     continue;\r
2854                 }\r
2855                 sNew.Add(pDataNode);\r
2856             }\r
2857             CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFAContainerNode> sIteratorBefore(pBeforeInstance);\r
2858             for(CXFA_Node *pNode = sIteratorBefore.GetCurrent(); pNode; pNode = sIteratorBefore.MoveToNext()) {\r
2859                 CXFA_Node *pDataNode = pNode->GetBindData();\r
2860                 if(!pDataNode) {\r
2861                     continue;\r
2862                 }\r
2863                 sBefore.Add(pDataNode);\r
2864             }\r
2865             XFA_ScriptInstanceManager_ReorderDataNodes(sNew, sBefore, TRUE);\r
2866         }\r
2867     }\r
2868 }\r
2869 static void XFA_ScriptInstanceManager_RemoveItem(CXFA_Node *pInstMgrNode, CXFA_Node *pRemoveInstance, FX_BOOL bRemoveDataBinding = TRUE)\r
2870 {\r
2871     pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)->RemoveChild(pRemoveInstance);\r
2872     if(!bRemoveDataBinding) {\r
2873         return;\r
2874     }\r
2875     CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFAContainerNode> sIterator(pRemoveInstance);\r
2876     for(CXFA_Node* pFormNode = sIterator.GetCurrent(); pFormNode; pFormNode = sIterator.MoveToNext()) {\r
2877         CXFA_Node* pDataNode = pFormNode->GetBindData();\r
2878         if(!pDataNode) {\r
2879             continue;\r
2880         }\r
2881         if(pDataNode->RemoveBindItem(pFormNode) == 0) {\r
2882             if(CXFA_Node* pDataParent = pDataNode->GetNodeItem(XFA_NODEITEM_Parent)) {\r
2883                 pDataParent->RemoveChild(pDataNode);\r
2884             }\r
2885         }\r
2886         pFormNode->SetObject(XFA_ATTRIBUTE_BindingNode, NULL);\r
2887     }\r
2888 }\r
2889 static CXFA_Node* XFA_ScriptInstanceManager_CreateInstance(CXFA_Node *pInstMgrNode, FX_BOOL bDataMerge)\r
2890 {\r
2891     CXFA_Document* pDocument = pInstMgrNode->GetDocument();\r
2892     CXFA_Node* pTemplateNode = pInstMgrNode->GetTemplateNode();\r
2893     CXFA_Node* pFormParent = pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent);\r
2894     CXFA_Node* pDataScope = NULL;\r
2895     for(CXFA_Node* pRootBoundNode = pFormParent; pRootBoundNode && pRootBoundNode->GetObjectType() == XFA_OBJECTTYPE_ContainerNode; pRootBoundNode = pRootBoundNode->GetNodeItem(XFA_NODEITEM_Parent)) {\r
2896         pDataScope = pRootBoundNode->GetBindData();\r
2897         if(pDataScope) {\r
2898             break;\r
2899         }\r
2900     }\r
2901     if(!pDataScope) {\r
2902         pDataScope = (CXFA_Node*)pDocument->GetXFANode(XFA_HASHCODE_Record);\r
2903         ASSERT(pDataScope);\r
2904     }\r
2905     CXFA_Node *pInstance = pDocument->DataMerge_CopyContainer(pTemplateNode, pFormParent, pDataScope, TRUE, bDataMerge);\r
2906     if(pInstance) {\r
2907         pDocument->DataMerge_UpdateBindingRelations(pInstance);\r
2908         pFormParent->RemoveChild(pInstance);\r
2909     }\r
2910     return pInstance;\r
2911 }\r
2912 void CXFA_Node::Script_InstanceManager_Count(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
2913 {\r
2914     if (bSetting) {\r
2915         int32_t iDesired = FXJSE_Value_ToInteger(hValue);\r
2916         InstanceManager_SetInstances(iDesired);\r
2917     } else {\r
2918         FXJSE_Value_SetInteger(hValue, XFA_ScriptInstanceManager_GetCount(this));\r
2919     }\r
2920 }\r
2921 void CXFA_Node::Script_InstanceManager_MoveInstance(CFXJSE_Arguments* pArguments)\r
2922 {\r
2923     int32_t argc = pArguments->GetLength();\r
2924     if (argc != 2) {\r
2925         FXJSE_Value_SetUndefined(pArguments->GetReturnValue());\r
2926         return;\r
2927     }\r
2928     int32_t iFrom = pArguments->GetInt32(0);\r
2929     int32_t iTo = pArguments->GetInt32(1);\r
2930     InstanceManager_MoveInstance(iTo, iFrom);\r
2931     IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();\r
2932     if (!pNotify) {\r
2933         return;\r
2934     }\r
2935     CXFA_Node* pToInstance = XFA_ScriptInstanceManager_GetItem(this, iTo);\r
2936     if (pToInstance && pToInstance->GetClassID() == XFA_ELEMENT_Subform) {\r
2937         pNotify->RunSubformIndexChange(pToInstance);\r
2938     }\r
2939     CXFA_Node* pFromInstance = XFA_ScriptInstanceManager_GetItem(this, iFrom);\r
2940     if (pFromInstance && pFromInstance->GetClassID() == XFA_ELEMENT_Subform) {\r
2941         pNotify->RunSubformIndexChange(pFromInstance);\r
2942     }\r
2943 }\r
2944 void CXFA_Node::Script_InstanceManager_RemoveInstance(CFXJSE_Arguments* pArguments)\r
2945 {\r
2946     int32_t argc = pArguments->GetLength();\r
2947     if (argc != 1) {\r
2948         FXJSE_Value_SetUndefined(pArguments->GetReturnValue());\r
2949         return;\r
2950     }\r
2951     int32_t iIndex = pArguments->GetInt32(0);\r
2952     int32_t  iCount  = XFA_ScriptInstanceManager_GetCount(this);\r
2953     if (iIndex < 0 || iIndex >= iCount) {\r
2954         ThrowScriptErrorMessage(XFA_IDS_INDEX_OUT_OF_BOUNDS);\r
2955         return;\r
2956     }\r
2957     CXFA_Occur nodeOccur = GetOccurNode();\r
2958     int32_t  iMin = nodeOccur.GetMin();\r
2959     if (iCount - 1 < iMin) {\r
2960         ThrowScriptErrorMessage(XFA_IDS_VIOLATE_BOUNDARY, L"min");\r
2961         return;\r
2962     }\r
2963     CXFA_Node *pRemoveInstance = XFA_ScriptInstanceManager_GetItem(this, iIndex);\r
2964     XFA_ScriptInstanceManager_RemoveItem(this, pRemoveInstance);\r
2965     IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();\r
2966     if (pNotify) {\r
2967         for (int32_t i = iIndex; i < iCount - 1; i++) {\r
2968             CXFA_Node *pSubformInstance = XFA_ScriptInstanceManager_GetItem(this, i);\r
2969             if (pSubformInstance && pSubformInstance->GetClassID() == XFA_ELEMENT_Subform) {\r
2970                 pNotify->RunSubformIndexChange(pSubformInstance);\r
2971             }\r
2972         }\r
2973     }\r
2974     CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();\r
2975     if (!pLayoutPro) {\r
2976         return;\r
2977     }\r
2978     pLayoutPro->AddChangedContainer((CXFA_Node*)m_pDocument->GetXFANode(XFA_HASHCODE_Form));\r
2979 }\r
2980 void CXFA_Node::Script_InstanceManager_SetInstances(CFXJSE_Arguments* pArguments)\r
2981 {\r
2982     int32_t argc = pArguments->GetLength();\r
2983     if (argc != 1) {\r
2984         FXJSE_Value_SetUndefined(pArguments->GetReturnValue());\r
2985         return;\r
2986     }\r
2987     int32_t iDesired = pArguments->GetInt32(0);\r
2988     InstanceManager_SetInstances(iDesired);\r
2989 }\r
2990 void CXFA_Node::Script_InstanceManager_AddInstance(CFXJSE_Arguments* pArguments)\r
2991 {\r
2992     int32_t argc  = pArguments->GetLength();\r
2993     if ((argc != 0) && (argc != 1)) {\r
2994         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"addInstance");\r
2995         return;\r
2996     }\r
2997     FX_BOOL fFlags = TRUE;\r