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

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

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

Powered by Google App Engine
This is Rietveld 408576698