blob: 99198d24f5b532a3f353bc44b2b32efff3128295 [file] [log] [blame]
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "xfa/fxfa/parser/xfa_object.h"
#include <memory>
#include "core/fxcrt/include/fx_ext.h"
#include "fxjse/include/cfxjse_arguments.h"
#include "third_party/base/stl_util.h"
#include "xfa/fde/xml/fde_xml_imp.h"
#include "xfa/fgas/crt/fgas_codepage.h"
#include "xfa/fgas/crt/fgas_system.h"
#include "xfa/fxfa/app/xfa_ffnotify.h"
#include "xfa/fxfa/parser/cxfa_occur.h"
#include "xfa/fxfa/parser/xfa_basic_imp.h"
#include "xfa/fxfa/parser/xfa_doclayout.h"
#include "xfa/fxfa/parser/xfa_document.h"
#include "xfa/fxfa/parser/xfa_document_layout_imp.h"
#include "xfa/fxfa/parser/xfa_localemgr.h"
#include "xfa/fxfa/parser/xfa_parser.h"
#include "xfa/fxfa/parser/xfa_parser_imp.h"
#include "xfa/fxfa/parser/xfa_script.h"
#include "xfa/fxfa/parser/xfa_script_imp.h"
#include "xfa/fxfa/parser/xfa_utils.h"
namespace {
void XFA_DeleteWideString(void* pData) {
delete static_cast<CFX_WideString*>(pData);
}
void XFA_CopyWideString(void*& pData) {
if (pData) {
CFX_WideString* pNewData = new CFX_WideString(*(CFX_WideString*)pData);
pData = pNewData;
}
}
XFA_MAPDATABLOCKCALLBACKINFO deleteWideStringCallBack = {XFA_DeleteWideString,
XFA_CopyWideString};
void XFA_DataNodeDeleteBindItem(void* pData) {
delete static_cast<CXFA_NodeArray*>(pData);
}
XFA_MAPDATABLOCKCALLBACKINFO deleteBindItemCallBack = {
XFA_DataNodeDeleteBindItem, nullptr};
} // namespace
CXFA_Object::CXFA_Object(CXFA_Document* pDocument,
XFA_ObjectType objectType,
XFA_Element elementType)
: m_pDocument(pDocument),
m_objectType(objectType),
m_elementType(elementType) {}
CXFA_Object::~CXFA_Object() {}
CFX_WideStringC CXFA_Object::GetClassName() const {
return XFA_GetElementByID(GetElementType())->pName;
}
uint32_t CXFA_Object::GetClassHashCode() const {
return XFA_GetElementByID(GetElementType())->uHash;
}
XFA_Element CXFA_Object::GetElementType() const {
return m_elementType;
}
void CXFA_Object::Script_ObjectClass_ClassName(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
if (!bSetting) {
CFX_WideStringC className = GetClassName();
pValue->SetString(
FX_UTF8Encode(className.c_str(), className.GetLength()).AsStringC());
} else {
ThrowException(XFA_IDS_INVAlID_PROP_SET);
}
}
void CXFA_Object::ThrowException(int32_t iStringID, ...) {
IXFA_AppProvider* pAppProvider = m_pDocument->GetNotify()->GetAppProvider();
ASSERT(pAppProvider);
CFX_WideString wsFormat;
pAppProvider->LoadString(iStringID, wsFormat);
CFX_WideString wsMessage;
va_list arg_ptr;
va_start(arg_ptr, iStringID);
wsMessage.FormatV(wsFormat.c_str(), arg_ptr);
va_end(arg_ptr);
FXJSE_ThrowMessage(
FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC());
}
XFA_MAPMODULEDATA::XFA_MAPMODULEDATA() {}
XFA_MAPMODULEDATA::~XFA_MAPMODULEDATA() {}
CXFA_Node::CXFA_Node(CXFA_Document* pDoc,
uint16_t ePacket,
XFA_ObjectType oType,
XFA_Element eType)
: CXFA_Object(pDoc, oType, eType),
m_pNext(nullptr),
m_pChild(nullptr),
m_pLastChild(nullptr),
m_pParent(nullptr),
m_pXMLNode(nullptr),
m_ePacket(ePacket),
m_uNodeFlags(XFA_NodeFlag_None),
m_dwNameHash(0),
m_pAuxNode(nullptr),
m_pMapModuleData(nullptr) {
ASSERT(m_pDocument);
}
CXFA_Node::~CXFA_Node() {
ASSERT(!m_pParent);
RemoveMapModuleKey();
CXFA_Node* pNode = m_pChild;
while (pNode) {
CXFA_Node* pNext = pNode->m_pNext;
pNode->m_pParent = nullptr;
delete pNode;
pNode = pNext;
}
if (m_pXMLNode && IsOwnXMLNode())
m_pXMLNode->Release();
}
CXFA_Node* CXFA_Node::Clone(FX_BOOL bRecursive) {
CXFA_Document* pFactory = m_pDocument->GetParser()->GetFactory();
CXFA_Node* pClone = pFactory->CreateNode(m_ePacket, m_elementType);
if (!pClone)
return nullptr;
MergeAllData(pClone);
pClone->UpdateNameHash();
if (IsNeedSavingXMLNode()) {
CFDE_XMLNode* pCloneXML = nullptr;
if (IsAttributeInXML()) {
CFX_WideString wsName;
GetAttribute(XFA_ATTRIBUTE_Name, wsName, FALSE);
CFDE_XMLElement* pCloneXMLElement = new CFDE_XMLElement(wsName);
CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
if (!wsValue.IsEmpty()) {
pCloneXMLElement->SetTextData(CFX_WideString(wsValue));
}
pCloneXML = pCloneXMLElement;
pCloneXMLElement = nullptr;
pClone->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
} else {
pCloneXML = m_pXMLNode->Clone(FALSE);
}
pClone->SetXMLMappingNode(pCloneXML);
pClone->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
}
if (bRecursive) {
for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
pClone->InsertChild(pChild->Clone(bRecursive));
}
}
pClone->SetFlag(XFA_NodeFlag_Initialized, true);
pClone->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
return pClone;
}
CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem) const {
switch (eItem) {
case XFA_NODEITEM_NextSibling:
return m_pNext;
case XFA_NODEITEM_FirstChild:
return m_pChild;
case XFA_NODEITEM_Parent:
return m_pParent;
case XFA_NODEITEM_PrevSibling:
if (m_pParent) {
CXFA_Node* pSibling = m_pParent->m_pChild;
CXFA_Node* pPrev = nullptr;
while (pSibling && pSibling != this) {
pPrev = pSibling;
pSibling = pSibling->m_pNext;
}
return pPrev;
}
return nullptr;
default:
break;
}
return nullptr;
}
CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem,
XFA_ObjectType eType) const {
CXFA_Node* pNode = nullptr;
switch (eItem) {
case XFA_NODEITEM_NextSibling:
pNode = m_pNext;
while (pNode && pNode->GetObjectType() != eType)
pNode = pNode->m_pNext;
break;
case XFA_NODEITEM_FirstChild:
pNode = m_pChild;
while (pNode && pNode->GetObjectType() != eType)
pNode = pNode->m_pNext;
break;
case XFA_NODEITEM_Parent:
pNode = m_pParent;
while (pNode && pNode->GetObjectType() != eType)
pNode = pNode->m_pParent;
break;
case XFA_NODEITEM_PrevSibling:
if (m_pParent) {
CXFA_Node* pSibling = m_pParent->m_pChild;
while (pSibling && pSibling != this) {
if (eType == pSibling->GetObjectType())
pNode = pSibling;
pSibling = pSibling->m_pNext;
}
}
break;
default:
break;
}
return pNode;
}
int32_t CXFA_Node::GetNodeList(CXFA_NodeArray& nodes,
uint32_t dwTypeFilter,
XFA_Element eTypeFilter,
int32_t iLevel) {
if (--iLevel < 0) {
return nodes.GetSize();
}
if (eTypeFilter != XFA_Element::Unknown) {
CXFA_Node* pChild = m_pChild;
while (pChild) {
if (pChild->GetElementType() == eTypeFilter) {
nodes.Add(pChild);
if (iLevel > 0) {
GetNodeList(nodes, dwTypeFilter, eTypeFilter, iLevel);
}
}
pChild = pChild->m_pNext;
}
} else if (dwTypeFilter ==
(XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties)) {
CXFA_Node* pChild = m_pChild;
while (pChild) {
nodes.Add(pChild);
if (iLevel > 0) {
GetNodeList(nodes, dwTypeFilter, eTypeFilter, iLevel);
}
pChild = pChild->m_pNext;
}
} else if (dwTypeFilter != 0) {
bool bFilterChildren = !!(dwTypeFilter & XFA_NODEFILTER_Children);
bool bFilterProperties = !!(dwTypeFilter & XFA_NODEFILTER_Properties);
bool bFilterOneOfProperties =
!!(dwTypeFilter & XFA_NODEFILTER_OneOfProperty);
CXFA_Node* pChild = m_pChild;
while (pChild) {
const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
GetElementType(), pChild->GetElementType(), XFA_XDPPACKET_UNKNOWN);
if (pProperty) {
if (bFilterProperties) {
nodes.Add(pChild);
} else if (bFilterOneOfProperties &&
(pProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) {
nodes.Add(pChild);
} else if (bFilterChildren &&
(pChild->GetElementType() == XFA_Element::Variables ||
pChild->GetElementType() == XFA_Element::PageSet)) {
nodes.Add(pChild);
}
} else if (bFilterChildren) {
nodes.Add(pChild);
}
pChild = pChild->m_pNext;
}
if (bFilterOneOfProperties && nodes.GetSize() < 1) {
int32_t iProperties = 0;
const XFA_PROPERTY* pProperty =
XFA_GetElementProperties(GetElementType(), iProperties);
if (!pProperty || iProperties < 1)
return 0;
for (int32_t i = 0; i < iProperties; i++) {
if (pProperty[i].uFlags & XFA_PROPERTYFLAG_DefaultOneOf) {
CXFA_Document* pFactory = m_pDocument->GetParser()->GetFactory();
const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(GetPacketID());
CXFA_Node* pNewNode =
pFactory->CreateNode(pPacket, pProperty[i].eName);
if (!pNewNode)
break;
InsertChild(pNewNode, nullptr);
pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
nodes.Add(pNewNode);
break;
}
}
}
}
return nodes.GetSize();
}
CXFA_Node* CXFA_Node::CreateSamePacketNode(XFA_Element eType,
uint32_t dwFlags) {
CXFA_Document* pFactory = m_pDocument->GetParser()->GetFactory();
CXFA_Node* pNode = pFactory->CreateNode(m_ePacket, eType);
pNode->SetFlag(dwFlags, true);
return pNode;
}
CXFA_Node* CXFA_Node::CloneTemplateToForm(FX_BOOL bRecursive) {
ASSERT(m_ePacket == XFA_XDPPACKET_Template);
CXFA_Document* pFactory = m_pDocument->GetParser()->GetFactory();
CXFA_Node* pClone = pFactory->CreateNode(XFA_XDPPACKET_Form, m_elementType);
if (!pClone)
return nullptr;
pClone->SetTemplateNode(this);
pClone->UpdateNameHash();
pClone->SetXMLMappingNode(GetXMLMappingNode());
if (bRecursive) {
for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
pClone->InsertChild(pChild->CloneTemplateToForm(bRecursive));
}
}
pClone->SetFlag(XFA_NodeFlag_Initialized, true);
return pClone;
}
CXFA_Node* CXFA_Node::GetTemplateNode() const {
return m_pAuxNode;
}
void CXFA_Node::SetTemplateNode(CXFA_Node* pTemplateNode) {
m_pAuxNode = pTemplateNode;
}
CXFA_Node* CXFA_Node::GetBindData() {
ASSERT(GetPacketID() == XFA_XDPPACKET_Form);
return static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
}
int32_t CXFA_Node::GetBindItems(CXFA_NodeArray& formItems) {
if (BindsFormItems()) {
CXFA_NodeArray* pItems = nullptr;
TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
formItems.Copy(*pItems);
return formItems.GetSize();
}
CXFA_Node* pFormNode =
static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
if (pFormNode)
formItems.Add(pFormNode);
return formItems.GetSize();
}
int32_t CXFA_Node::AddBindItem(CXFA_Node* pFormNode) {
ASSERT(pFormNode);
if (BindsFormItems()) {
CXFA_NodeArray* pItems = nullptr;
TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
ASSERT(pItems);
if (pItems->Find(pFormNode) < 0) {
pItems->Add(pFormNode);
}
return pItems->GetSize();
}
CXFA_Node* pOldFormItem =
static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
if (!pOldFormItem) {
SetObject(XFA_ATTRIBUTE_BindingNode, pFormNode);
return 1;
} else if (pOldFormItem == pFormNode) {
return 1;
}
CXFA_NodeArray* pItems = new CXFA_NodeArray;
SetObject(XFA_ATTRIBUTE_BindingNode, pItems, &deleteBindItemCallBack);
pItems->Add(pOldFormItem);
pItems->Add(pFormNode);
m_uNodeFlags |= XFA_NodeFlag_BindFormItems;
return 2;
}
int32_t CXFA_Node::RemoveBindItem(CXFA_Node* pFormNode) {
if (BindsFormItems()) {
CXFA_NodeArray* pItems = nullptr;
TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
ASSERT(pItems);
int32_t iIndex = pItems->Find(pFormNode);
int32_t iCount = pItems->GetSize();
if (iIndex >= 0) {
if (iIndex != iCount - 1)
pItems->SetAt(iIndex, pItems->GetAt(iCount - 1));
pItems->RemoveAt(iCount - 1);
if (iCount == 2) {
CXFA_Node* pLastFormNode = pItems->GetAt(0);
SetObject(XFA_ATTRIBUTE_BindingNode, pLastFormNode);
m_uNodeFlags &= ~XFA_NodeFlag_BindFormItems;
}
iCount--;
}
return iCount;
}
CXFA_Node* pOldFormItem =
static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
if (pOldFormItem == pFormNode) {
SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
pOldFormItem = nullptr;
}
return pOldFormItem ? 1 : 0;
}
FX_BOOL CXFA_Node::HasBindItem() {
return GetPacketID() == XFA_XDPPACKET_Datasets &&
GetObject(XFA_ATTRIBUTE_BindingNode);
}
CXFA_WidgetData* CXFA_Node::GetWidgetData() {
return (CXFA_WidgetData*)GetObject(XFA_ATTRIBUTE_WidgetData);
}
CXFA_WidgetData* CXFA_Node::GetContainerWidgetData() {
if (GetPacketID() != XFA_XDPPACKET_Form)
return nullptr;
XFA_Element eType = GetElementType();
if (eType == XFA_Element::ExclGroup)
return nullptr;
CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
if (pParentNode && pParentNode->GetElementType() == XFA_Element::ExclGroup)
return nullptr;
if (eType == XFA_Element::Field) {
CXFA_WidgetData* pFieldWidgetData = GetWidgetData();
if (pFieldWidgetData &&
pFieldWidgetData->GetChoiceListOpen() ==
XFA_ATTRIBUTEENUM_MultiSelect) {
return nullptr;
} else {
CFX_WideString wsPicture;
if (pFieldWidgetData) {
pFieldWidgetData->GetPictureContent(wsPicture,
XFA_VALUEPICTURE_DataBind);
}
if (!wsPicture.IsEmpty())
return pFieldWidgetData;
CXFA_Node* pDataNode = GetBindData();
if (!pDataNode)
return nullptr;
pFieldWidgetData = nullptr;
CXFA_NodeArray formNodes;
pDataNode->GetBindItems(formNodes);
for (int32_t i = 0; i < formNodes.GetSize(); i++) {
CXFA_Node* pFormNode = formNodes.GetAt(i);
if (!pFormNode || pFormNode->HasRemovedChildren())
continue;
pFieldWidgetData = pFormNode->GetWidgetData();
if (pFieldWidgetData) {
pFieldWidgetData->GetPictureContent(wsPicture,
XFA_VALUEPICTURE_DataBind);
}
if (!wsPicture.IsEmpty())
break;
pFieldWidgetData = nullptr;
}
return pFieldWidgetData;
}
}
CXFA_Node* pGrandNode =
pParentNode ? pParentNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
CXFA_Node* pValueNode =
(pParentNode && pParentNode->GetElementType() == XFA_Element::Value)
? pParentNode
: nullptr;
if (!pValueNode) {
pValueNode =
(pGrandNode && pGrandNode->GetElementType() == XFA_Element::Value)
? pGrandNode
: nullptr;
}
CXFA_Node* pParentOfValueNode =
pValueNode ? pValueNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
return pParentOfValueNode ? pParentOfValueNode->GetContainerWidgetData()
: nullptr;
}
FX_BOOL CXFA_Node::GetLocaleName(CFX_WideString& wsLocaleName) {
CXFA_Node* pForm = GetDocument()->GetXFAObject(XFA_HASHCODE_Form)->AsNode();
CXFA_Node* pTopSubform = pForm->GetFirstChildByClass(XFA_Element::Subform);
ASSERT(pTopSubform);
CXFA_Node* pLocaleNode = this;
FX_BOOL bLocale = FALSE;
do {
bLocale = pLocaleNode->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, FALSE);
if (!bLocale) {
pLocaleNode = pLocaleNode->GetNodeItem(XFA_NODEITEM_Parent);
}
} while (pLocaleNode && pLocaleNode != pTopSubform && !bLocale);
if (bLocale)
return TRUE;
CXFA_Node* pConfig = ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Config));
wsLocaleName = GetDocument()->GetLocalMgr()->GetConfigLocaleName(pConfig);
if (!wsLocaleName.IsEmpty())
return TRUE;
if (pTopSubform &&
pTopSubform->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, FALSE)) {
return TRUE;
}
IFX_Locale* pLocale = GetDocument()->GetLocalMgr()->GetDefLocale();
if (pLocale) {
wsLocaleName = pLocale->GetName();
return TRUE;
}
return FALSE;
}
XFA_ATTRIBUTEENUM CXFA_Node::GetIntact() {
CXFA_Node* pKeep = GetFirstChildByClass(XFA_Element::Keep);
XFA_ATTRIBUTEENUM eLayoutType = GetEnum(XFA_ATTRIBUTE_Layout);
if (pKeep) {
XFA_ATTRIBUTEENUM eIntact;
if (pKeep->TryEnum(XFA_ATTRIBUTE_Intact, eIntact, FALSE)) {
if (eIntact == XFA_ATTRIBUTEENUM_None &&
eLayoutType == XFA_ATTRIBUTEENUM_Row &&
m_pDocument->GetCurVersionMode() < XFA_VERSION_208) {
CXFA_Node* pPreviewRow = GetNodeItem(XFA_NODEITEM_PrevSibling,
XFA_ObjectType::ContainerNode);
if (pPreviewRow &&
pPreviewRow->GetEnum(XFA_ATTRIBUTE_Layout) ==
XFA_ATTRIBUTEENUM_Row) {
XFA_ATTRIBUTEENUM eValue;
if (pKeep->TryEnum(XFA_ATTRIBUTE_Previous, eValue, FALSE) &&
(eValue == XFA_ATTRIBUTEENUM_ContentArea ||
eValue == XFA_ATTRIBUTEENUM_PageArea)) {
return XFA_ATTRIBUTEENUM_ContentArea;
}
CXFA_Node* pNode =
pPreviewRow->GetFirstChildByClass(XFA_Element::Keep);
if (pNode && pNode->TryEnum(XFA_ATTRIBUTE_Next, eValue, FALSE) &&
(eValue == XFA_ATTRIBUTEENUM_ContentArea ||
eValue == XFA_ATTRIBUTEENUM_PageArea)) {
return XFA_ATTRIBUTEENUM_ContentArea;
}
}
}
return eIntact;
}
}
switch (GetElementType()) {
case XFA_Element::Subform:
switch (eLayoutType) {
case XFA_ATTRIBUTEENUM_Position:
case XFA_ATTRIBUTEENUM_Row:
return XFA_ATTRIBUTEENUM_ContentArea;
case XFA_ATTRIBUTEENUM_Tb:
case XFA_ATTRIBUTEENUM_Table:
case XFA_ATTRIBUTEENUM_Lr_tb:
case XFA_ATTRIBUTEENUM_Rl_tb:
return XFA_ATTRIBUTEENUM_None;
default:
break;
}
break;
case XFA_Element::Field: {
CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
if (!pParentNode ||
pParentNode->GetElementType() == XFA_Element::PageArea)
return XFA_ATTRIBUTEENUM_ContentArea;
if (pParentNode->GetIntact() == XFA_ATTRIBUTEENUM_None) {
XFA_ATTRIBUTEENUM eParLayout =
pParentNode->GetEnum(XFA_ATTRIBUTE_Layout);
if (eParLayout == XFA_ATTRIBUTEENUM_Position ||
eParLayout == XFA_ATTRIBUTEENUM_Row ||
eParLayout == XFA_ATTRIBUTEENUM_Table) {
return XFA_ATTRIBUTEENUM_None;
}
XFA_VERSION version = m_pDocument->GetCurVersionMode();
if (eParLayout == XFA_ATTRIBUTEENUM_Tb && version < XFA_VERSION_208) {
CXFA_Measurement measureH;
if (TryMeasure(XFA_ATTRIBUTE_H, measureH, FALSE))
return XFA_ATTRIBUTEENUM_ContentArea;
}
return XFA_ATTRIBUTEENUM_None;
}
return XFA_ATTRIBUTEENUM_ContentArea;
}
case XFA_Element::Draw:
return XFA_ATTRIBUTEENUM_ContentArea;
default:
break;
}
return XFA_ATTRIBUTEENUM_None;
}
CXFA_Node* CXFA_Node::GetDataDescriptionNode() {
if (m_ePacket == XFA_XDPPACKET_Datasets)
return m_pAuxNode;
return nullptr;
}
void CXFA_Node::SetDataDescriptionNode(CXFA_Node* pDataDescriptionNode) {
ASSERT(m_ePacket == XFA_XDPPACKET_Datasets);
m_pAuxNode = pDataDescriptionNode;
}
void CXFA_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments) {
int32_t iLength = pArguments->GetLength();
if (iLength != 1) {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resolveNode");
return;
}
CFX_WideString wsExpression =
CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
if (!pScriptContext)
return;
CXFA_Node* refNode = this;
if (refNode->GetElementType() == XFA_Element::Xfa)
refNode = ToNode(pScriptContext->GetThisObject());
uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
XFA_RESOLVENODE_Siblings;
XFA_RESOLVENODE_RS resoveNodeRS;
int32_t iRet = pScriptContext->ResolveObjects(
refNode, wsExpression.AsStringC(), resoveNodeRS, dwFlag);
if (iRet < 1) {
pArguments->GetReturnValue()->SetNull();
return;
}
if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
CXFA_Object* pNode = resoveNodeRS.nodes[0];
pArguments->GetReturnValue()->Assign(
pScriptContext->GetJSValueFromMap(pNode));
} else {
const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo =
resoveNodeRS.pScriptAttribute;
if (lpAttributeInfo && lpAttributeInfo->eValueType == XFA_SCRIPT_Object) {
std::unique_ptr<CFXJSE_Value> pValue(
new CFXJSE_Value(pScriptContext->GetRuntime()));
(resoveNodeRS.nodes[0]->*(lpAttributeInfo->lpfnCallback))(
pValue.get(), FALSE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute);
pArguments->GetReturnValue()->Assign(pValue.get());
} else {
pArguments->GetReturnValue()->SetNull();
}
}
}
void CXFA_Node::Script_TreeClass_ResolveNodes(CFXJSE_Arguments* pArguments) {
int32_t iLength = pArguments->GetLength();
if (iLength != 1) {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resolveNodes");
return;
}
CFX_WideString wsExpression =
CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
CFXJSE_Value* pValue = pArguments->GetReturnValue();
if (!pValue)
return;
uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
XFA_RESOLVENODE_Siblings;
CXFA_Node* refNode = this;
if (refNode->GetElementType() == XFA_Element::Xfa)
refNode = ToNode(m_pDocument->GetScriptContext()->GetThisObject());
Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag, refNode);
}
void CXFA_Node::Script_Som_ResolveNodeList(CFXJSE_Value* pValue,
CFX_WideString wsExpression,
uint32_t dwFlag,
CXFA_Node* refNode) {
CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
if (!pScriptContext)
return;
XFA_RESOLVENODE_RS resoveNodeRS;
if (!refNode)
refNode = this;
pScriptContext->ResolveObjects(refNode, wsExpression.AsStringC(),
resoveNodeRS, dwFlag);
CXFA_ArrayNodeList* pNodeList = new CXFA_ArrayNodeList(m_pDocument);
if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
for (int32_t i = 0; i < resoveNodeRS.nodes.GetSize(); i++) {
if (resoveNodeRS.nodes[i]->IsNode())
pNodeList->Append(resoveNodeRS.nodes[i]->AsNode());
}
} else {
CXFA_ValueArray valueArray(pScriptContext->GetRuntime());
if (resoveNodeRS.GetAttributeResult(valueArray) > 0) {
CXFA_ObjArray objectArray;
valueArray.GetAttributeObject(objectArray);
for (int32_t i = 0; i < objectArray.GetSize(); i++) {
if (objectArray[i]->IsNode())
pNodeList->Append(objectArray[i]->AsNode());
}
}
}
pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
}
void CXFA_Node::Script_TreeClass_All(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
if (bSetting) {
ThrowException(XFA_IDS_INVAlID_PROP_SET);
} else {
uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
CFX_WideString wsName;
GetAttribute(XFA_ATTRIBUTE_Name, wsName);
CFX_WideString wsExpression = wsName + FX_WSTRC(L"[*]");
Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
}
}
void CXFA_Node::Script_TreeClass_Nodes(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
if (!pScriptContext)
return;
if (bSetting) {
IXFA_AppProvider* pAppProvider = m_pDocument->GetNotify()->GetAppProvider();
ASSERT(pAppProvider);
CFX_WideString wsMessage;
pAppProvider->LoadString(XFA_IDS_Unable_TO_SET, wsMessage);
FXJSE_ThrowMessage(
FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC());
} else {
CXFA_AttachNodeList* pNodeList = new CXFA_AttachNodeList(m_pDocument, this);
pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
}
}
void CXFA_Node::Script_TreeClass_ClassAll(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
if (bSetting) {
ThrowException(XFA_IDS_INVAlID_PROP_SET);
} else {
uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
CFX_WideString wsExpression =
FX_WSTRC(L"#") + GetClassName() + FX_WSTRC(L"[*]");
Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
}
}
void CXFA_Node::Script_TreeClass_Parent(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
if (bSetting) {
ThrowException(XFA_IDS_INVAlID_PROP_SET);
} else {
CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
if (pParent) {
pValue->Assign(
m_pDocument->GetScriptContext()->GetJSValueFromMap(pParent));
} else {
pValue->SetNull();
}
}
}
void CXFA_Node::Script_TreeClass_Index(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
if (bSetting)
ThrowException(XFA_IDS_INVAlID_PROP_SET);
else
pValue->SetInteger(GetNodeSameNameIndex());
}
void CXFA_Node::Script_TreeClass_ClassIndex(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
if (bSetting)
ThrowException(XFA_IDS_INVAlID_PROP_SET);
else
pValue->SetInteger(GetNodeSameClassIndex());
}
void CXFA_Node::Script_TreeClass_SomExpression(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
if (bSetting) {
ThrowException(XFA_IDS_INVAlID_PROP_SET);
} else {
CFX_WideString wsSOMExpression;
GetSOMExpression(wsSOMExpression);
pValue->SetString(FX_UTF8Encode(wsSOMExpression).AsStringC());
}
}
void CXFA_Node::Script_NodeClass_ApplyXSL(CFXJSE_Arguments* pArguments) {
int32_t iLength = pArguments->GetLength();
if (iLength != 1) {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"applyXSL");
return;
}
CFX_WideString wsExpression =
CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
// TODO(weili): check whether we need to implement this, pdfium:501.
// For now, just put the variables here to avoid unused variable warning.
(void)wsExpression;
}
void CXFA_Node::Script_NodeClass_AssignNode(CFXJSE_Arguments* pArguments) {
int32_t iLength = pArguments->GetLength();
if (iLength < 1 || iLength > 3) {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"assignNode");
return;
}
CFX_WideString wsExpression;
CFX_WideString wsValue;
int32_t iAction = 0;
wsExpression =
CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
if (iLength >= 2) {
wsValue =
CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
}
if (iLength >= 3)
iAction = pArguments->GetInt32(2);
// TODO(weili): check whether we need to implement this, pdfium:501.
// For now, just put the variables here to avoid unused variable warning.
(void)wsExpression;
(void)wsValue;
(void)iAction;
}
void CXFA_Node::Script_NodeClass_Clone(CFXJSE_Arguments* pArguments) {
int32_t iLength = pArguments->GetLength();
if (iLength != 1) {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"clone");
return;
}
bool bClone = !!pArguments->GetInt32(0);
CXFA_Node* pCloneNode = Clone(bClone);
pArguments->GetReturnValue()->Assign(
m_pDocument->GetScriptContext()->GetJSValueFromMap(pCloneNode));
}
void CXFA_Node::Script_NodeClass_GetAttribute(CFXJSE_Arguments* pArguments) {
int32_t iLength = pArguments->GetLength();
if (iLength != 1) {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getAttribute");
return;
}
CFX_WideString wsExpression =
CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
CFX_WideString wsValue;
GetAttribute(wsExpression.AsStringC(), wsValue);
CFXJSE_Value* pValue = pArguments->GetReturnValue();
if (pValue)
pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
}
void CXFA_Node::Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments) {
int32_t iLength = pArguments->GetLength();
if (iLength < 1 || iLength > 2) {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getElement");
return;
}
CFX_WideString wsExpression;
int32_t iValue = 0;
wsExpression =
CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
if (iLength >= 2)
iValue = pArguments->GetInt32(1);
CXFA_Node* pNode =
GetProperty(iValue, XFA_GetElementTypeForName(wsExpression.AsStringC()));
pArguments->GetReturnValue()->Assign(
m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode));
}
void CXFA_Node::Script_NodeClass_IsPropertySpecified(
CFXJSE_Arguments* pArguments) {
int32_t iLength = pArguments->GetLength();
if (iLength < 1 || iLength > 3) {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isPropertySpecified");
return;
}
CFX_WideString wsExpression;
bool bParent = true;
int32_t iIndex = 0;
wsExpression =
CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
if (iLength >= 2)
bParent = !!pArguments->GetInt32(1);
if (iLength >= 3)
iIndex = pArguments->GetInt32(2);
FX_BOOL bHas = FALSE;
const XFA_ATTRIBUTEINFO* pAttributeInfo =
XFA_GetAttributeByName(wsExpression.AsStringC());
CFX_WideString wsValue;
if (pAttributeInfo)
bHas = HasAttribute(pAttributeInfo->eName);
if (!bHas) {
XFA_Element eType = XFA_GetElementTypeForName(wsExpression.AsStringC());
bHas = !!GetProperty(iIndex, eType);
if (!bHas && bParent && m_pParent) {
// Also check on the parent.
bHas = m_pParent->HasAttribute(pAttributeInfo->eName);
if (!bHas)
bHas = !!m_pParent->GetProperty(iIndex, eType);
}
}
CFXJSE_Value* pValue = pArguments->GetReturnValue();
if (pValue)
pValue->SetBoolean(bHas);
}
void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) {
int32_t iLength = pArguments->GetLength();
if (iLength < 1 || iLength > 3) {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"loadXML");
return;
}
CFX_WideString wsExpression;
bool bIgnoreRoot = true;
bool bOverwrite = 0;
wsExpression =
CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
if (wsExpression.IsEmpty())
return;
if (iLength >= 2)
bIgnoreRoot = !!pArguments->GetInt32(1);
if (iLength >= 3)
bOverwrite = !!pArguments->GetInt32(2);
std::unique_ptr<IXFA_Parser, ReleaseDeleter<IXFA_Parser>> pParser(
IXFA_Parser::Create(m_pDocument));
if (!pParser)
return;
CFDE_XMLNode* pXMLNode = nullptr;
int32_t iParserStatus =
pParser->ParseXMLData(wsExpression, pXMLNode, nullptr);
if (iParserStatus != XFA_PARSESTATUS_Done || !pXMLNode)
return;
if (bIgnoreRoot &&
(pXMLNode->GetType() != FDE_XMLNODE_Element ||
XFA_RecognizeRichText(static_cast<CFDE_XMLElement*>(pXMLNode)))) {
bIgnoreRoot = false;
}
CXFA_Node* pFakeRoot = Clone(FALSE);
CFX_WideStringC wsContentType = GetCData(XFA_ATTRIBUTE_ContentType);
if (!wsContentType.IsEmpty()) {
pFakeRoot->SetCData(XFA_ATTRIBUTE_ContentType,
CFX_WideString(wsContentType));
}
CFDE_XMLNode* pFakeXMLRoot = pFakeRoot->GetXMLMappingNode();
if (!pFakeXMLRoot) {
CFDE_XMLNode* pThisXMLRoot = GetXMLMappingNode();
pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone(FALSE) : nullptr;
}
if (!pFakeXMLRoot)
pFakeXMLRoot = new CFDE_XMLElement(CFX_WideString(GetClassName()));
if (bIgnoreRoot) {
CFDE_XMLNode* pXMLChild = pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild);
while (pXMLChild) {
CFDE_XMLNode* pXMLSibling =
pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling);
pXMLNode->RemoveChildNode(pXMLChild);
pFakeXMLRoot->InsertChildNode(pXMLChild);
pXMLChild = pXMLSibling;
}
} else {
CFDE_XMLNode* pXMLParent = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent);
if (pXMLParent) {
pXMLParent->RemoveChildNode(pXMLNode);
}
pFakeXMLRoot->InsertChildNode(pXMLNode);
}
pParser->ConstructXFANode(pFakeRoot, pFakeXMLRoot);
pFakeRoot = pParser->GetRootNode();
if (pFakeRoot) {
if (bOverwrite) {
CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild);
CXFA_Node* pNewChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
int32_t index = 0;
while (pNewChild) {
CXFA_Node* pItem = pNewChild->GetNodeItem(XFA_NODEITEM_NextSibling);
pFakeRoot->RemoveChild(pNewChild);
InsertChild(index++, pNewChild);
pNewChild->SetFlag(XFA_NodeFlag_Initialized, true);
pNewChild = pItem;
}
while (pChild) {
CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
RemoveChild(pChild);
pFakeRoot->InsertChild(pChild);
pChild = pItem;
}
if (GetPacketID() == XFA_XDPPACKET_Form &&
GetElementType() == XFA_Element::ExData) {
CFDE_XMLNode* pTempXMLNode = GetXMLMappingNode();
SetXMLMappingNode(pFakeXMLRoot);
SetFlag(XFA_NodeFlag_OwnXMLNode, false);
if (pTempXMLNode && !pTempXMLNode->GetNodeItem(CFDE_XMLNode::Parent)) {
pFakeXMLRoot = pTempXMLNode;
} else {
pFakeXMLRoot = nullptr;
}
}
MoveBufferMapData(pFakeRoot, this, XFA_CalcData, TRUE);
} else {
CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
while (pChild) {
CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
pFakeRoot->RemoveChild(pChild);
InsertChild(pChild);
pChild->SetFlag(XFA_NodeFlag_Initialized, true);
pChild = pItem;
}
}
if (pFakeXMLRoot) {
pFakeRoot->SetXMLMappingNode(pFakeXMLRoot);
pFakeRoot->SetFlag(XFA_NodeFlag_OwnXMLNode, false);
}
pFakeRoot->SetFlag(XFA_NodeFlag_HasRemovedChildren, false);
} else {
if (pFakeXMLRoot) {
pFakeXMLRoot->Release();
pFakeXMLRoot = nullptr;
}
}
}
void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) {
// TODO(weili): Check whether we need to implement this, pdfium:501.
}
void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) {
int32_t iLength = pArguments->GetLength();
if (iLength < 0 || iLength > 1) {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"saveXML");
return;
}
bool bPrettyMode = false;
if (iLength == 1) {
if (pArguments->GetUTF8String(0) != "pretty") {
ThrowException(XFA_IDS_ARGUMENT_MISMATCH);
return;
}
bPrettyMode = true;
}
CFX_ByteStringC bsXMLHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
if (GetPacketID() == XFA_XDPPACKET_Form ||
GetPacketID() == XFA_XDPPACKET_Datasets) {
CFDE_XMLNode* pElement = nullptr;
if (GetPacketID() == XFA_XDPPACKET_Datasets) {
pElement = GetXMLMappingNode();
if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) {
pArguments->GetReturnValue()->SetString(bsXMLHeader);
return;
}
XFA_DataExporter_DealWithDataGroupNode(this);
}
std::unique_ptr<IFX_MemoryStream, ReleaseDeleter<IFX_MemoryStream>>
pMemoryStream(FX_CreateMemoryStream(TRUE));
std::unique_ptr<IFX_Stream, ReleaseDeleter<IFX_Stream>> pStream(
IFX_Stream::CreateStream(
static_cast<IFX_FileWrite*>(pMemoryStream.get()),
FX_STREAMACCESS_Text | FX_STREAMACCESS_Write |
FX_STREAMACCESS_Append));
if (!pStream) {
pArguments->GetReturnValue()->SetString(bsXMLHeader);
return;
}
pStream->SetCodePage(FX_CODEPAGE_UTF8);
pStream->WriteData(bsXMLHeader.raw_str(), bsXMLHeader.GetLength());
if (GetPacketID() == XFA_XDPPACKET_Form)
XFA_DataExporter_RegenerateFormFile(this, pStream.get(), nullptr, TRUE);
else
pElement->SaveXMLNode(pStream.get());
// TODO(weili): Check whether we need to save pretty print XML, pdfium:501.
// For now, just put it here to avoid unused variable warning.
(void)bPrettyMode;
pArguments->GetReturnValue()->SetString(
CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize()));
return;
}
pArguments->GetReturnValue()->SetString("");
}
void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) {
int32_t iLength = pArguments->GetLength();
if (iLength != 2) {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setAttribute");
return;
}
CFX_WideString wsAttributeValue =
CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
CFX_WideString wsAttribute =
CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
SetAttribute(wsAttribute.AsStringC(), wsAttributeValue.AsStringC(), true);
}
void CXFA_Node::Script_NodeClass_SetElement(CFXJSE_Arguments* pArguments) {
int32_t iLength = pArguments->GetLength();
if (iLength != 1 && iLength != 2) {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setElement");
return;
}
CXFA_Node* pNode = nullptr;
CFX_WideString wsName;
pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
if (iLength == 2)
wsName = CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
// TODO(weili): check whether we need to implement this, pdfium:501.
// For now, just put the variables here to avoid unused variable warning.
(void)pNode;
(void)wsName;
}
void CXFA_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
if (bSetting) {
ThrowException(XFA_IDS_INVAlID_PROP_SET);
} else {
CFX_WideString wsNameSpace;
TryNamespace(wsNameSpace);
pValue->SetString(FX_UTF8Encode(wsNameSpace).AsStringC());
}
}
void CXFA_Node::Script_NodeClass_Model(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
if (bSetting) {
ThrowException(XFA_IDS_INVAlID_PROP_SET);
} else {
pValue->Assign(
m_pDocument->GetScriptContext()->GetJSValueFromMap(GetModelNode()));
}
}
void CXFA_Node::Script_NodeClass_IsContainer(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
if (bSetting)
ThrowException(XFA_IDS_INVAlID_PROP_SET);
else
pValue->SetBoolean(IsContainerNode());
}
void CXFA_Node::Script_NodeClass_IsNull(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
if (bSetting) {
ThrowException(XFA_IDS_INVAlID_PROP_SET);
} else {
if (GetElementType() == XFA_Element::Subform) {
pValue->SetBoolean(FALSE);
return;
}
CFX_WideString strValue;
pValue->SetBoolean(!TryContent(strValue) || strValue.IsEmpty());
}
}
void CXFA_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
if (bSetting) {
ThrowException(XFA_IDS_INVAlID_PROP_SET);
} else {
CXFA_NodeArray properts;
int32_t iSize = GetNodeList(properts, XFA_NODEFILTER_OneOfProperty);
if (iSize > 0) {
pValue->Assign(
m_pDocument->GetScriptContext()->GetJSValueFromMap(properts[0]));
}
}
}
void CXFA_Node::Script_ContainerClass_GetDelta(CFXJSE_Arguments* pArguments) {}
void CXFA_Node::Script_ContainerClass_GetDeltas(CFXJSE_Arguments* pArguments) {
CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
pArguments->GetReturnValue()->SetObject(
pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass());
}
void CXFA_Node::Script_ModelClass_ClearErrorList(CFXJSE_Arguments* pArguments) {
}
void CXFA_Node::Script_ModelClass_CreateNode(CFXJSE_Arguments* pArguments) {
Script_Template_CreateNode(pArguments);
}
void CXFA_Node::Script_ModelClass_IsCompatibleNS(CFXJSE_Arguments* pArguments) {
int32_t iLength = pArguments->GetLength();
if (iLength < 1) {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isCompatibleNS");
return;
}
CFX_WideString wsNameSpace;
if (iLength >= 1) {
CFX_ByteString bsNameSpace = pArguments->GetUTF8String(0);
wsNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC());
}
CFX_WideString wsNodeNameSpace;
TryNamespace(wsNodeNameSpace);
CFXJSE_Value* pValue = pArguments->GetReturnValue();
if (pValue)
pValue->SetBoolean(wsNodeNameSpace == wsNameSpace);
}
void CXFA_Node::Script_ModelClass_Context(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {}
void CXFA_Node::Script_ModelClass_AliasNode(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {}
void CXFA_Node::Script_Attribute_Integer(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
if (bSetting) {
SetInteger(eAttribute, pValue->ToInteger(), true);
} else {
pValue->SetInteger(GetInteger(eAttribute));
}
}
void CXFA_Node::Script_Attribute_IntegerRead(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
if (!bSetting) {
pValue->SetInteger(GetInteger(eAttribute));
} else {
ThrowException(XFA_IDS_INVAlID_PROP_SET);
}
}
void CXFA_Node::Script_Attribute_BOOL(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
if (bSetting) {
SetBoolean(eAttribute, pValue->ToBoolean(), true);
} else {
pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
}
}
void CXFA_Node::Script_Attribute_BOOLRead(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
if (!bSetting) {
pValue->SetString(GetBoolean(eAttribute) ? "1" : "0");
} else {
ThrowException(XFA_IDS_INVAlID_PROP_SET);
}
}
void CXFA_Node::Script_Attribute_SendAttributeChangeMessage(
XFA_ATTRIBUTE eAttribute,
FX_BOOL bScriptModify) {
CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor();
if (!pLayoutPro)
return;
CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify();
if (!pNotify)
return;
uint32_t dwPacket = GetPacketID();
if (!(dwPacket & XFA_XDPPACKET_Form)) {
pNotify->OnValueChanged(this, eAttribute, this, this);
return;
}
bool bNeedFindContainer = false;
switch (GetElementType()) {
case XFA_Element::Caption:
bNeedFindContainer = true;
pNotify->OnValueChanged(this, eAttribute, this,
GetNodeItem(XFA_NODEITEM_Parent));
break;
case XFA_Element::Font:
case XFA_Element::Para: {
bNeedFindContainer = true;
CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
if (pParentNode->GetElementType() == XFA_Element::Caption) {
pNotify->OnValueChanged(this, eAttribute, pParentNode,
pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
} else {
pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
}
} break;
case XFA_Element::Margin: {
bNeedFindContainer = true;
CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
XFA_Element eParentType = pParentNode->GetElementType();
if (pParentNode->IsContainerNode()) {
pNotify->OnValueChanged(this, eAttribute, this, pParentNode);
} else if (eParentType == XFA_Element::Caption) {
pNotify->OnValueChanged(this, eAttribute, pParentNode,
pParentNode->GetNodeItem(XFA_NODEITEM_Parent));
} else {
CXFA_Node* pNode = pParentNode->GetNodeItem(XFA_NODEITEM_Parent);
if (pNode && pNode->GetElementType() == XFA_Element::Ui) {
pNotify->OnValueChanged(this, eAttribute, pNode,
pNode->GetNodeItem(XFA_NODEITEM_Parent));
}
}
} break;
case XFA_Element::Comb: {
CXFA_Node* pEditNode = GetNodeItem(XFA_NODEITEM_Parent);
XFA_Element eUIType = pEditNode->GetElementType();
if (pEditNode && (eUIType == XFA_Element::DateTimeEdit ||
eUIType == XFA_Element::NumericEdit ||
eUIType == XFA_Element::TextEdit)) {
CXFA_Node* pUINode = pEditNode->GetNodeItem(XFA_NODEITEM_Parent);
if (pUINode) {
pNotify->OnValueChanged(this, eAttribute, pUINode,
pUINode->GetNodeItem(XFA_NODEITEM_Parent));
}
}
} break;
case XFA_Element::Button:
case XFA_Element::Barcode:
case XFA_Element::ChoiceList:
case XFA_Element::DateTimeEdit:
case XFA_Element::NumericEdit:
case XFA_Element::PasswordEdit:
case XFA_Element::TextEdit: {
CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
if (pUINode) {
pNotify->OnValueChanged(this, eAttribute, pUINode,
pUINode->GetNodeItem(XFA_NODEITEM_Parent));
}
} break;
case XFA_Element::CheckButton: {
bNeedFindContainer = true;
CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent);
if (pUINode) {
pNotify->OnValueChanged(this, eAttribute, pUINode,
pUINode->GetNodeItem(XFA_NODEITEM_Parent));
}
} break;
case XFA_Element::Keep:
case XFA_Element::Bookend:
case XFA_Element::Break:
case XFA_Element::BreakAfter:
case XFA_Element::BreakBefore:
case XFA_Element::Overflow:
bNeedFindContainer = true;
break;
case XFA_Element::Area:
case XFA_Element::Draw:
case XFA_Element::ExclGroup:
case XFA_Element::Field:
case XFA_Element::Subform:
case XFA_Element::SubformSet:
pLayoutPro->AddChangedContainer(this);
pNotify->OnValueChanged(this, eAttribute, this, this);
break;
case XFA_Element::Sharptext:
case XFA_Element::Sharpxml:
case XFA_Element::SharpxHTML: {
CXFA_Node* pTextNode = GetNodeItem(XFA_NODEITEM_Parent);
if (!pTextNode) {
return;
}
CXFA_Node* pValueNode = pTextNode->GetNodeItem(XFA_NODEITEM_Parent);
if (!pValueNode) {
return;
}
XFA_Element eType = pValueNode->GetElementType();
if (eType == XFA_Element::Value) {
bNeedFindContainer = true;
CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
if (pNode && pNode->IsContainerNode()) {
if (bScriptModify) {
pValueNode = pNode;
}
pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
} else {
pNotify->OnValueChanged(this, eAttribute, pNode,
pNode->GetNodeItem(XFA_NODEITEM_Parent));
}
} else {
if (eType == XFA_Element::Items) {
CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent);
if (pNode && pNode->IsContainerNode()) {
pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode);
}
}
}
} break;
default:
break;
}
if (bNeedFindContainer) {
CXFA_Node* pParent = this;
while (pParent) {
if (pParent->IsContainerNode())
break;
pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent);
}
if (pParent) {
pLayoutPro->AddChangedContainer(pParent);
}
}
}
void CXFA_Node::Script_Attribute_String(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
if (bSetting) {
CFX_WideString wsValue = pValue->ToWideString();
SetAttribute(eAttribute, wsValue.AsStringC(), true);
if (eAttribute == XFA_ATTRIBUTE_Use &&
GetElementType() == XFA_Element::Desc) {
CXFA_Node* pTemplateNode =
ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template));
CXFA_Node* pProtoRoot =
pTemplateNode->GetFirstChildByClass(XFA_Element::Subform)
->GetFirstChildByClass(XFA_Element::Proto);
CFX_WideString wsID;
CFX_WideString wsSOM;
if (!wsValue.IsEmpty()) {
if (wsValue[0] == '#') {
wsID = CFX_WideString(wsValue.c_str() + 1, wsValue.GetLength() - 1);
} else {
wsSOM = wsValue;
}
}
CXFA_Node* pProtoNode = nullptr;
if (!wsSOM.IsEmpty()) {
uint32_t dwFlag = XFA_RESOLVENODE_Children |
XFA_RESOLVENODE_Attributes |
XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
XFA_RESOLVENODE_Siblings;
XFA_RESOLVENODE_RS resoveNodeRS;
int32_t iRet = m_pDocument->GetScriptContext()->ResolveObjects(
pProtoRoot, wsSOM.AsStringC(), resoveNodeRS, dwFlag);
if (iRet > 0 && resoveNodeRS.nodes[0]->IsNode()) {
pProtoNode = resoveNodeRS.nodes[0]->AsNode();
}
} else if (!wsID.IsEmpty()) {
pProtoNode = m_pDocument->GetNodeByID(pProtoRoot, wsID.AsStringC());
}
if (pProtoNode) {
CXFA_Node* pHeadChild = GetNodeItem(XFA_NODEITEM_FirstChild);
while (pHeadChild) {
CXFA_Node* pSibling =
pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
RemoveChild(pHeadChild);
pHeadChild = pSibling;
}
CXFA_Node* pProtoForm = pProtoNode->CloneTemplateToForm(TRUE);
pHeadChild = pProtoForm->GetNodeItem(XFA_NODEITEM_FirstChild);
while (pHeadChild) {
CXFA_Node* pSibling =
pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling);
pProtoForm->RemoveChild(pHeadChild);
InsertChild(pHeadChild);
pHeadChild = pSibling;
}
m_pDocument->RemovePurgeNode(pProtoForm);
delete pProtoForm;
}
}
} else {
CFX_WideString wsValue;
GetAttribute(eAttribute, wsValue);
pValue->SetString(
FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
}
}
void CXFA_Node::Script_Attribute_StringRead(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
if (!bSetting) {
CFX_WideString wsValue;
GetAttribute(eAttribute, wsValue);
pValue->SetString(
FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
} else {
ThrowException(XFA_IDS_INVAlID_PROP_SET);
}
}
void CXFA_Node::Script_WsdlConnection_Execute(CFXJSE_Arguments* pArguments) {
int32_t argc = pArguments->GetLength();
if ((argc == 0) || (argc == 1)) {
pArguments->GetReturnValue()->SetBoolean(FALSE);
} else {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execute");
}
}
void CXFA_Node::Script_Delta_Restore(CFXJSE_Arguments* pArguments) {
int32_t argc = pArguments->GetLength();
if (argc == 0) {
} else {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"restore");
}
}
void CXFA_Node::Script_Delta_CurrentValue(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {}
void CXFA_Node::Script_Delta_SavedValue(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {}
void CXFA_Node::Script_Delta_Target(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {}
void CXFA_Node::Script_Som_Message(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_SOM_MESSAGETYPE iMessageType) {
CXFA_WidgetData* pWidgetData = GetWidgetData();
if (!pWidgetData) {
return;
}
FX_BOOL bNew = FALSE;
CXFA_Validate validate = pWidgetData->GetValidate();
if (!validate) {
validate = pWidgetData->GetValidate(TRUE);
bNew = TRUE;
}
if (bSetting) {
switch (iMessageType) {
case XFA_SOM_ValidationMessage:
validate.SetScriptMessageText(pValue->ToWideString());
break;
case XFA_SOM_FormatMessage:
validate.SetFormatMessageText(pValue->ToWideString());
break;
case XFA_SOM_MandatoryMessage:
validate.SetNullMessageText(pValue->ToWideString());
break;
default:
break;
}
if (!bNew) {
CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify();
if (!pNotify) {
return;
}
pNotify->AddCalcValidate(this);
}
} else {
CFX_WideString wsMessage;
switch (iMessageType) {
case XFA_SOM_ValidationMessage:
validate.GetScriptMessageText(wsMessage);
break;
case XFA_SOM_FormatMessage:
validate.GetFormatMessageText(wsMessage);
break;
case XFA_SOM_MandatoryMessage:
validate.GetNullMessageText(wsMessage);
break;
default:
break;
}
pValue->SetString(FX_UTF8Encode(wsMessage).AsStringC());
}
}
void CXFA_Node::Script_Som_ValidationMessage(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
Script_Som_Message(pValue, bSetting, XFA_SOM_ValidationMessage);
}
void CXFA_Node::Script_Field_Length(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
if (bSetting) {
ThrowException(XFA_IDS_INVAlID_PROP_SET);
} else {
CXFA_WidgetData* pWidgetData = GetWidgetData();
if (!pWidgetData) {
pValue->SetInteger(0);
return;
}
pValue->SetInteger(pWidgetData->CountChoiceListItems(TRUE));
}
}
void CXFA_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
XFA_Element eType = GetElementType();
if (eType == XFA_Element::Field) {
Script_Field_DefaultValue(pValue, bSetting, eAttribute);
return;
}
if (eType == XFA_Element::Draw) {
Script_Draw_DefaultValue(pValue, bSetting, eAttribute);
return;
}
if (eType == XFA_Element::Boolean) {
Script_Boolean_Value(pValue, bSetting, eAttribute);
return;
}
if (bSetting) {
CFX_WideString wsNewValue;
if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
wsNewValue = pValue->ToWideString();
CFX_WideString wsFormatValue(wsNewValue);
CXFA_WidgetData* pContainerWidgetData = nullptr;
if (GetPacketID() == XFA_XDPPACKET_Datasets) {
CXFA_NodeArray formNodes;
GetBindItems(formNodes);
CFX_WideString wsPicture;
for (int32_t i = 0; i < formNodes.GetSize(); i++) {
CXFA_Node* pFormNode = formNodes.GetAt(i);
if (!pFormNode || pFormNode->HasRemovedChildren()) {
continue;
}
pContainerWidgetData = pFormNode->GetContainerWidgetData();
if (pContainerWidgetData) {
pContainerWidgetData->GetPictureContent(wsPicture,
XFA_VALUEPICTURE_DataBind);
}
if (!wsPicture.IsEmpty()) {
break;
}
pContainerWidgetData = nullptr;
}
} else if (GetPacketID() == XFA_XDPPACKET_Form) {
pContainerWidgetData = GetContainerWidgetData();
}
if (pContainerWidgetData) {
pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
}
SetScriptContent(wsNewValue, wsFormatValue, true, TRUE);
} else {
CFX_WideString content = GetScriptContent(TRUE);
if (content.IsEmpty() && eType != XFA_Element::Text &&
eType != XFA_Element::SubmitUrl) {
pValue->SetNull();
} else if (eType == XFA_Element::Integer) {
pValue->SetInteger(FXSYS_wtoi(content.c_str()));
} else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) {
CFX_Decimal decimal(content.AsStringC());
pValue->SetFloat((FX_FLOAT)(double)decimal);
} else {
pValue->SetString(
FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
}
}
}
void CXFA_Node::Script_Som_DefaultValue_Read(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
if (bSetting) {
ThrowException(XFA_IDS_INVAlID_PROP_SET);
return;
}
CFX_WideString content = GetScriptContent(TRUE);
if (content.IsEmpty()) {
pValue->SetNull();
} else {
pValue->SetString(
FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
}
}
void CXFA_Node::Script_Boolean_Value(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
if (bSetting) {
CFX_ByteString newValue;
if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
newValue = pValue->ToString();
int32_t iValue = FXSYS_atoi(newValue.c_str());
CFX_WideString wsNewValue(iValue == 0 ? L"0" : L"1");
CFX_WideString wsFormatValue(wsNewValue);
CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
if (pContainerWidgetData) {
pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
}
SetScriptContent(wsNewValue, wsFormatValue, true, TRUE);
} else {
CFX_WideString wsValue = GetScriptContent(TRUE);
pValue->SetBoolean(wsValue == FX_WSTRC(L"1"));
}
}
struct XFA_ExecEventParaInfo {
public:
uint32_t m_uHash;
const FX_WCHAR* m_lpcEventName;
XFA_EVENTTYPE m_eventType;
uint32_t m_validFlags;
};
static const XFA_ExecEventParaInfo gs_eventParaInfos[] = {
{0x02a6c55a, L"postSubmit", XFA_EVENT_PostSubmit, 0},
{0x0ab466bb, L"preSubmit", XFA_EVENT_PreSubmit, 0},
{0x109d7ce7, L"mouseEnter", XFA_EVENT_MouseEnter, 5},
{0x17fad373, L"postPrint", XFA_EVENT_PostPrint, 0},
{0x1bfc72d9, L"preOpen", XFA_EVENT_PreOpen, 7},
{0x2196a452, L"initialize", XFA_EVENT_Initialize, 1},
{0x27410f03, L"mouseExit", XFA_EVENT_MouseExit, 5},
{0x33c43dec, L"docClose", XFA_EVENT_DocClose, 0},
{0x361fa1b6, L"preSave", XFA_EVENT_PreSave, 0},
{0x36f1c6d8, L"preSign", XFA_EVENT_PreSign, 6},
{0x4731d6ba, L"exit", XFA_EVENT_Exit, 2},
{0x56bf456b, L"docReady", XFA_EVENT_DocReady, 0},
{0x7233018a, L"validate", XFA_EVENT_Validate, 1},
{0x8808385e, L"indexChange", XFA_EVENT_IndexChange, 3},
{0x891f4606, L"change", XFA_EVENT_Change, 4},
{0x9528a7b4, L"prePrint", XFA_EVENT_PrePrint, 0},
{0x9f693b21, L"mouseDown", XFA_EVENT_MouseDown, 5},
{0xcdce56b3, L"full", XFA_EVENT_Full, 4},
{0xd576d08e, L"mouseUp", XFA_EVENT_MouseUp, 5},
{0xd95657a6, L"click", XFA_EVENT_Click, 4},
{0xdbfbe02e, L"calculate", XFA_EVENT_Calculate, 1},
{0xe25fa7b8, L"postOpen", XFA_EVENT_PostOpen, 7},
{0xe28dce7e, L"enter", XFA_EVENT_Enter, 2},
{0xfc82d695, L"postSave", XFA_EVENT_PostSave, 0},
{0xfd54fbb7, L"postSign", XFA_EVENT_PostSign, 6},
};
const XFA_ExecEventParaInfo* GetEventParaInfoByName(
const CFX_WideStringC& wsEventName) {
uint32_t uHash = FX_HashCode_GetW(wsEventName, false);
int32_t iStart = 0;
int32_t iEnd = (sizeof(gs_eventParaInfos) / sizeof(gs_eventParaInfos[0])) - 1;
do {
int32_t iMid = (iStart + iEnd) / 2;
const XFA_ExecEventParaInfo* eventParaInfo = &gs_eventParaInfos[iMid];
if (uHash == eventParaInfo->m_uHash) {
return eventParaInfo;
}
if (uHash < eventParaInfo->m_uHash) {
iEnd = iMid - 1;
} else {
iStart = iMid + 1;
}
} while (iStart <= iEnd);
return nullptr;
}
void XFA_STRING_TO_RGB(const CFX_WideString& strRGB,
int32_t& r,
int32_t& g,
int32_t& b) {
r = 0;
g = 0;
b = 0;
FX_WCHAR zero = '0';
int32_t iIndex = 0;
int32_t iLen = strRGB.GetLength();
for (int32_t i = 0; i < iLen; ++i) {
FX_WCHAR ch = strRGB.GetAt(i);
if (ch == L',') {
++iIndex;
}
if (iIndex > 2) {
break;
}
int32_t iValue = ch - zero;
if (iValue >= 0 && iValue <= 9) {
switch (iIndex) {
case 0:
r = r * 10 + iValue;
break;
case 1:
g = g * 10 + iValue;
break;
default:
b = b * 10 + iValue;
break;
}
}
}
}
void CXFA_Node::Script_Som_BorderColor(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
CXFA_WidgetData* pWidgetData = GetWidgetData();
if (!pWidgetData) {
return;
}
CXFA_Border border = pWidgetData->GetBorder(TRUE);
int32_t iSize = border.CountEdges();
if (bSetting) {
int32_t r = 0;
int32_t g = 0;
int32_t b = 0;
XFA_STRING_TO_RGB(pValue->ToWideString(), r, g, b);
FX_ARGB rgb = ArgbEncode(100, r, g, b);
for (int32_t i = 0; i < iSize; ++i) {
CXFA_Edge edge = border.GetEdge(i);
edge.SetColor(rgb);
}
} else {
CXFA_Edge edge = border.GetEdge(0);
FX_ARGB color = edge.GetColor();
int32_t a, r, g, b;
ArgbDecode(color, a, r, g, b);
CFX_WideString strColor;
strColor.Format(L"%d,%d,%d", r, g, b);
pValue->SetString(FX_UTF8Encode(strColor).AsStringC());
}
}
void CXFA_Node::Script_Som_BorderWidth(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
CXFA_WidgetData* pWidgetData = GetWidgetData();
if (!pWidgetData) {
return;
}
CXFA_Border border = pWidgetData->GetBorder(TRUE);
int32_t iSize = border.CountEdges();
CFX_WideString wsThickness;
if (bSetting) {
wsThickness = pValue->ToWideString();
for (int32_t i = 0; i < iSize; ++i) {
CXFA_Edge edge = border.GetEdge(i);
CXFA_Measurement thickness(wsThickness.AsStringC());
edge.SetMSThickness(thickness);
}
} else {
CXFA_Edge edge = border.GetEdge(0);
CXFA_Measurement thickness = edge.GetMSThickness();
thickness.ToString(wsThickness);
pValue->SetString(FX_UTF8Encode(wsThickness).AsStringC());
}
}
void CXFA_Node::Script_Som_FillColor(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
CXFA_WidgetData* pWidgetData = GetWidgetData();
if (!pWidgetData) {
return;
}
CXFA_Border border = pWidgetData->GetBorder(TRUE);
CXFA_Fill borderfill = border.GetFill(TRUE);
CXFA_Node* pNode = borderfill.GetNode();
if (!pNode) {
return;
}
if (bSetting) {
int32_t r;
int32_t g;
int32_t b;
XFA_STRING_TO_RGB(pValue->ToWideString(), r, g, b);
FX_ARGB color = ArgbEncode(0xff, r, g, b);
borderfill.SetColor(color);
} else {
FX_ARGB color = borderfill.GetColor();
int32_t a;
int32_t r;
int32_t g;
int32_t b;
ArgbDecode(color, a, r, g, b);
CFX_WideString wsColor;
wsColor.Format(L"%d,%d,%d", r, g, b);
pValue->SetString(FX_UTF8Encode(wsColor).AsStringC());
}
}
void CXFA_Node::Script_Som_DataNode(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
if (!bSetting) {
CXFA_Node* pDataNode = GetBindData();
if (pDataNode) {
pValue->Assign(
m_pDocument->GetScriptContext()->GetJSValueFromMap(pDataNode));
} else {
pValue->SetNull();
}
} else {
ThrowException(XFA_IDS_INVAlID_PROP_SET);
}
}
void CXFA_Node::Script_Draw_DefaultValue(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
if (bSetting) {
if (pValue && pValue->IsString()) {
CXFA_WidgetData* pWidgetData = GetWidgetData();
ASSERT(pWidgetData);
XFA_Element uiType = pWidgetData->GetUIType();
if (uiType == XFA_Element::Text) {
CFX_WideString wsNewValue = pValue->ToWideString();
CFX_WideString wsFormatValue(wsNewValue);
SetScriptContent(wsNewValue, wsFormatValue, true, TRUE);
}
}
} else {
CFX_WideString content = GetScriptContent(TRUE);
if (content.IsEmpty()) {
pValue->SetNull();
} else {
pValue->SetString(
FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
}
}
}
void CXFA_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
CXFA_WidgetData* pWidgetData = GetWidgetData();
if (!pWidgetData) {
return;
}
if (bSetting) {
if (pValue && pValue->IsNull()) {
pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
pWidgetData->m_bIsNull = TRUE;
} else {
pWidgetData->m_bPreNull = pWidgetData->m_bIsNull;
pWidgetData->m_bIsNull = FALSE;
}
CFX_WideString wsNewText;
if (!(pValue && (pValue->IsNull() || pValue->IsUndefined())))
wsNewText = pValue->ToWideString();
CXFA_Node* pUIChild = pWidgetData->GetUIChild();
if (pUIChild->GetElementType() == XFA_Element::NumericEdit) {
int32_t iLeadDigits = 0;
int32_t iFracDigits = 0;
pWidgetData->GetLeadDigits(iLeadDigits);
pWidgetData->GetFracDigits(iFracDigits);
wsNewText =
pWidgetData->NumericLimit(wsNewText, iLeadDigits, iFracDigits);
}
CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData();
CFX_WideString wsFormatText(wsNewText);
if (pContainerWidgetData) {
pContainerWidgetData->GetFormatDataValue(wsNewText, wsFormatText);
}
SetScriptContent(wsNewText, wsFormatText, true, TRUE);
} else {
CFX_WideString content = GetScriptContent(TRUE);
if (content.IsEmpty()) {
pValue->SetNull();
} else {
CXFA_Node* pUIChild = pWidgetData->GetUIChild();
CXFA_Value defVal = pWidgetData->GetFormValue();
CXFA_Node* pNode = defVal.GetNode()->GetNodeItem(XFA_NODEITEM_FirstChild);
if (pNode && pNode->GetElementType() == XFA_Element::Decimal) {
if (pUIChild->GetElementType() == XFA_Element::NumericEdit &&
(pNode->GetInteger(XFA_ATTRIBUTE_FracDigits) == -1)) {
pValue->SetString(
FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
} else {
CFX_Decimal decimal(content.AsStringC());
pValue->SetFloat((FX_FLOAT)(double)decimal);
}
} else if (pNode && pNode->GetElementType() == XFA_Element::Integer) {
pValue->SetInteger(FXSYS_wtoi(content.c_str()));
} else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) {
pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? FALSE : TRUE);
} else if (pNode && pNode->GetElementType() == XFA_Element::Float) {
CFX_Decimal decimal(content.AsStringC());
pValue->SetFloat((FX_FLOAT)(double)decimal);
} else {
pValue->SetString(
FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC());
}
}
}
}
void CXFA_Node::Script_Field_EditValue(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
CXFA_WidgetData* pWidgetData = GetWidgetData();
if (!pWidgetData) {
return;
}
if (bSetting) {
pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Edit);
} else {
CFX_WideString wsValue;
pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Edit);
pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
}
}
void CXFA_Node::Script_Som_FontColor(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
CXFA_WidgetData* pWidgetData = GetWidgetData();
if (!pWidgetData) {
return;
}
CXFA_Font font = pWidgetData->GetFont(TRUE);
CXFA_Node* pNode = font.GetNode();
if (!pNode) {
return;
}
if (bSetting) {
int32_t r;
int32_t g;
int32_t b;
XFA_STRING_TO_RGB(pValue->ToWideString(), r, g, b);
FX_ARGB color = ArgbEncode(0xff, r, g, b);
font.SetColor(color);
} else {
FX_ARGB color = font.GetColor();
int32_t a;
int32_t r;
int32_t g;
int32_t b;
ArgbDecode(color, a, r, g, b);
CFX_WideString wsColor;
wsColor.Format(L"%d,%d,%d", r, g, b);
pValue->SetString(FX_UTF8Encode(wsColor).AsStringC());
}
}
void CXFA_Node::Script_Field_FormatMessage(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
Script_Som_Message(pValue, bSetting, XFA_SOM_FormatMessage);
}
void CXFA_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
CXFA_WidgetData* pWidgetData = GetWidgetData();
if (!pWidgetData) {
return;
}
if (bSetting) {
pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Display);
} else {
CFX_WideString wsValue;
pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Display);
pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
}
}
void CXFA_Node::Script_Som_Mandatory(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
CXFA_WidgetData* pWidgetData = GetWidgetData();
if (!pWidgetData) {
return;
}
CXFA_Validate validate = pWidgetData->GetValidate(TRUE);
if (bSetting) {
validate.SetNullTest(pValue->ToWideString());
} else {
int32_t iValue = validate.GetNullTest();
const XFA_ATTRIBUTEENUMINFO* pInfo =
XFA_GetAttributeEnumByID((XFA_ATTRIBUTEENUM)iValue);
CFX_WideString wsValue;
if (pInfo)
wsValue = pInfo->pName;
pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
}
}
void CXFA_Node::Script_Som_MandatoryMessage(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
Script_Som_Message(pValue, bSetting, XFA_SOM_MandatoryMessage);
}
void CXFA_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
if (bSetting) {
ThrowException(XFA_IDS_INVAlID_PROP_SET);
} else {
pValue->SetNull();
}
}
void CXFA_Node::Script_Field_SelectedIndex(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
CXFA_WidgetData* pWidgetData = GetWidgetData();
if (!pWidgetData) {
return;
}
if (bSetting) {
int32_t iIndex = pValue->ToInteger();
if (iIndex == -1) {
pWidgetData->ClearAllSelections();
return;
}
pWidgetData->SetItemState(iIndex, TRUE, true, TRUE, TRUE);
} else {
pValue->SetInteger(pWidgetData->GetSelectedItem());
}
}
void CXFA_Node::Script_Field_ClearItems(CFXJSE_Arguments* pArguments) {
CXFA_WidgetData* pWidgetData = GetWidgetData();
if (!pWidgetData) {
return;
}
pWidgetData->DeleteItem(-1, TRUE);
}
void CXFA_Node::Script_Field_ExecEvent(CFXJSE_Arguments* pArguments) {
int32_t argc = pArguments->GetLength();
if (argc == 1) {
CFX_ByteString eventString = pArguments->GetUTF8String(0);
int32_t iRet = execSingleEventByName(
CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
XFA_Element::Field);
if (eventString == "validate") {
pArguments->GetReturnValue()->SetBoolean(
(iRet == XFA_EVENTERROR_Error) ? FALSE : TRUE);
}
} else {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent");
}
}
void CXFA_Node::Script_Field_ExecInitialize(CFXJSE_Arguments* pArguments) {
int32_t argc = pArguments->GetLength();
if (argc == 0) {
CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify();
if (!pNotify) {
return;
}
pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize, FALSE, FALSE);
} else {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");
}
}
void CXFA_Node::Script_Field_DeleteItem(CFXJSE_Arguments* pArguments) {
int32_t iLength = pArguments->GetLength();
if (iLength != 1) {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"deleteItem");
return;
}
CXFA_WidgetData* pWidgetData = GetWidgetData();
if (!pWidgetData) {
return;
}
int32_t iIndex = pArguments->GetInt32(0);
FX_BOOL bValue = pWidgetData->DeleteItem(iIndex, TRUE, TRUE);
CFXJSE_Value* pValue = pArguments->GetReturnValue();
if (pValue)
pValue->SetBoolean(bValue);
}
void CXFA_Node::Script_Field_GetSaveItem(CFXJSE_Arguments* pArguments) {
int32_t iLength = pArguments->GetLength();
if (iLength != 1) {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getSaveItem");
return;
}
int32_t iIndex = pArguments->GetInt32(0);
if (iIndex < 0) {
pArguments->GetReturnValue()->SetNull();
return;
}
CXFA_WidgetData* pWidgetData = GetWidgetData();
if (!pWidgetData) {
pArguments->GetReturnValue()->SetNull();
return;
}
CFX_WideString wsValue;
FX_BOOL bHasItem = pWidgetData->GetChoiceListItem(wsValue, iIndex, TRUE);
if (bHasItem) {
pArguments->GetReturnValue()->SetString(
FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
} else {
pArguments->GetReturnValue()->SetNull();
}
}
void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments) {
int32_t iLength = pArguments->GetLength();
if (iLength != 1) {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"boundItem");
return;
}
CXFA_WidgetData* pWidgetData = GetWidgetData();
if (!pWidgetData) {
return;
}
CFX_ByteString bsValue = pArguments->GetUTF8String(0);
CFX_WideString wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
CFX_WideString wsBoundValue;
pWidgetData->GetItemValue(wsValue.AsStringC(), wsBoundValue);
CFXJSE_Value* pValue = pArguments->GetReturnValue();
if (pValue)
pValue->SetString(FX_UTF8Encode(wsBoundValue).AsStringC());
}
void CXFA_Node::Script_Field_GetItemState(CFXJSE_Arguments* pArguments) {
int32_t iLength = pArguments->GetLength();
if (iLength != 1) {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getItemState");
return;
}
CXFA_WidgetData* pWidgetData = GetWidgetData();
if (!pWidgetData) {
return;
}
int32_t iIndex = pArguments->GetInt32(0);
FX_BOOL bValue = pWidgetData->GetItemState(iIndex);
CFXJSE_Value* pValue = pArguments->GetReturnValue();
if (pValue)
pValue->SetBoolean(bValue);
}
void CXFA_Node::Script_Field_ExecCalculate(CFXJSE_Arguments* pArguments) {
int32_t argc = pArguments->GetLength();
if (argc == 0) {
CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify();
if (!pNotify) {
return;
}
pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate, FALSE, FALSE);
} else {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");
}
}
void CXFA_Node::Script_Field_SetItems(CFXJSE_Arguments* pArguments) {}
void CXFA_Node::Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments) {
int32_t iLength = pArguments->GetLength();
if (iLength != 1) {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getDisplayItem");
return;
}
int32_t iIndex = pArguments->GetInt32(0);
if (iIndex < 0) {
pArguments->GetReturnValue()->SetNull();
return;
}
CXFA_WidgetData* pWidgetData = GetWidgetData();
if (!pWidgetData) {
pArguments->GetReturnValue()->SetNull();
return;
}
CFX_WideString wsValue;
FX_BOOL bHasItem = pWidgetData->GetChoiceListItem(wsValue, iIndex, FALSE);
if (bHasItem) {
pArguments->GetReturnValue()->SetString(
FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC());
} else {
pArguments->GetReturnValue()->SetNull();
}
}
void CXFA_Node::Script_Field_SetItemState(CFXJSE_Arguments* pArguments) {
int32_t iLength = pArguments->GetLength();
if (iLength != 2) {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setItemState");
return;
}
CXFA_WidgetData* pWidgetData = GetWidgetData();
if (!pWidgetData)
return;
int32_t iIndex = pArguments->GetInt32(0);
if (pArguments->GetInt32(1) != 0) {
pWidgetData->SetItemState(iIndex, TRUE, true, TRUE, TRUE);
} else {
if (pWidgetData->GetItemState(iIndex))
pWidgetData->SetItemState(iIndex, FALSE, true, TRUE, TRUE);
}
}
void CXFA_Node::Script_Field_AddItem(CFXJSE_Arguments* pArguments) {
int32_t iLength = pArguments->GetLength();
if (iLength < 1 || iLength > 2) {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"addItem");
return;
}
CXFA_WidgetData* pWidgetData = GetWidgetData();
if (!pWidgetData) {
return;
}
CFX_WideString wsLabel;
CFX_WideString wsValue;
if (iLength >= 1) {
CFX_ByteString bsLabel = pArguments->GetUTF8String(0);
wsLabel = CFX_WideString::FromUTF8(bsLabel.AsStringC());
}
if (iLength >= 2) {
CFX_ByteString bsValue = pArguments->GetUTF8String(1);
wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC());
}
pWidgetData->InsertItem(wsLabel, wsValue, -1, TRUE);
}
void CXFA_Node::Script_Field_ExecValidate(CFXJSE_Arguments* pArguments) {
int32_t argc = pArguments->GetLength();
if (argc == 0) {
CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify();
if (!pNotify) {
pArguments->GetReturnValue()->SetBoolean(FALSE);
} else {
int32_t iRet =
pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate, FALSE, FALSE);
pArguments->GetReturnValue()->SetBoolean(
(iRet == XFA_EVENTERROR_Error) ? FALSE : TRUE);
}
} else {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");
}
}
void CXFA_Node::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
if (!bSetting) {
} else {
ThrowException(XFA_IDS_INVAlID_PROP_SET);
}
}
void CXFA_Node::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
CXFA_WidgetData* pWidgetData = GetWidgetData();
if (!pWidgetData) {
return;
}
if (bSetting) {
pWidgetData->SetSelectedMemberByValue(pValue->ToWideString().AsStringC(),
true, TRUE, TRUE);
} else {
CFX_WideString wsValue = GetScriptContent(TRUE);
XFA_VERSION curVersion = GetDocument()->GetCurVersionMode();
if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) {
pValue->SetNull();
} else {
pValue->SetString(FX_UTF8Encode(wsValue).AsStringC());
}
}
}
void CXFA_Node::Script_ExclGroup_Transient(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {}
void CXFA_Node::Script_ExclGroup_ExecEvent(CFXJSE_Arguments* pArguments) {
int32_t argc = pArguments->GetLength();
if (argc == 1) {
CFX_ByteString eventString = pArguments->GetUTF8String(0);
execSingleEventByName(
CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
XFA_Element::ExclGroup);
} else {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent");
}
}
void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments) {
int32_t argc = pArguments->GetLength();
if (argc < 0 || argc > 1) {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"selectedMember");
return;
}
CXFA_WidgetData* pWidgetData = GetWidgetData();
if (!pWidgetData) {
pArguments->GetReturnValue()->SetNull();
return;
}
CXFA_Node* pReturnNode = nullptr;
if (argc == 0) {
pReturnNode = pWidgetData->GetSelectedMember();
} else {
CFX_ByteString szName;
szName = pArguments->GetUTF8String(0);
pReturnNode = pWidgetData->SetSelectedMember(
CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC(), true);
}
if (!pReturnNode) {
pArguments->GetReturnValue()->SetNull();
return;
}
pArguments->GetReturnValue()->Assign(
m_pDocument->GetScriptContext()->GetJSValueFromMap(pReturnNode));
}
void CXFA_Node::Script_ExclGroup_ExecInitialize(CFXJSE_Arguments* pArguments) {
int32_t argc = pArguments->GetLength();
if (argc == 0) {
CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify();
if (!pNotify) {
return;
}
pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize);
} else {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize");
}
}
void CXFA_Node::Script_ExclGroup_ExecCalculate(CFXJSE_Arguments* pArguments) {
int32_t argc = pArguments->GetLength();
if (argc == 0) {
CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify();
if (!pNotify) {
return;
}
pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate);
} else {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate");
}
}
void CXFA_Node::Script_ExclGroup_ExecValidate(CFXJSE_Arguments* pArguments) {
int32_t argc = pArguments->GetLength();
if (argc == 0) {
CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify();
if (!pNotify) {
pArguments->GetReturnValue()->SetBoolean(FALSE);
} else {
int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate);
pArguments->GetReturnValue()->SetBoolean(
(iRet == XFA_EVENTERROR_Error) ? FALSE : TRUE);
}
} else {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate");
}
}
static CXFA_Node* XFA_ScriptInstanceManager_GetItem(CXFA_Node* pInstMgrNode,
int32_t iIndex) {
ASSERT(pInstMgrNode);
int32_t iCount = 0;
uint32_t dwNameHash = 0;
for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
XFA_Element eCurType = pNode->GetElementType();
if (eCurType == XFA_Element::InstanceManager) {
break;
}
if ((eCurType != XFA_Element::Subform) &&
(eCurType != XFA_Element::SubformSet)) {
continue;
}
if (iCount == 0) {
CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
wsInstName.Mid(1) != wsName) {
return nullptr;
}
dwNameHash = pNode->GetNameHash();
}
if (dwNameHash != pNode->GetNameHash()) {
break;
}
iCount++;
if (iCount > iIndex) {
return pNode;
}
}
return nullptr;
}
void CXFA_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
if (bSetting) {
int32_t iTo = pValue->ToInteger();
int32_t iFrom = Subform_and_SubformSet_InstanceIndex();
CXFA_Node* pManagerNode = nullptr;
for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
if (pNode->GetElementType() == XFA_Element::InstanceManager) {
pManagerNode = pNode;
break;
}
}
if (pManagerNode) {
pManagerNode->InstanceManager_MoveInstance(iTo, iFrom);
CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify();
if (!pNotify) {
return;
}
CXFA_Node* pToInstance =
XFA_ScriptInstanceManager_GetItem(pManagerNode, iTo);
if (pToInstance &&
pToInstance->GetElementType() == XFA_Element::Subform) {
pNotify->RunSubformIndexChange(pToInstance);
}
CXFA_Node* pFromInstance =
XFA_ScriptInstanceManager_GetItem(pManagerNode, iFrom);
if (pFromInstance &&
pFromInstance->GetElementType() == XFA_Element::Subform) {
pNotify->RunSubformIndexChange(pFromInstance);
}
}
} else {
pValue->SetInteger(Subform_and_SubformSet_InstanceIndex());
}
}
void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
if (!bSetting) {
CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
CXFA_Node* pInstanceMgr = nullptr;
for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
if (pNode->GetElementType() == XFA_Element::InstanceManager) {
CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name);
if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' &&
wsInstMgrName.Mid(1) == wsName) {
pInstanceMgr = pNode;
}
break;
}
}
if (pInstanceMgr) {
pValue->Assign(
m_pDocument->GetScriptContext()->GetJSValueFromMap(pInstanceMgr));
} else {
pValue->SetNull();
}
} else {
ThrowException(XFA_IDS_INVAlID_PROP_SET);
}
}
void CXFA_Node::Script_Subform_Locale(CFXJSE_Value* pValue,
FX_BOOL bSetting,
XFA_ATTRIBUTE eAttribute) {
if (bSetting) {
SetCData(XFA_ATTRIBUTE_Locale, pValue->ToWideString(), true, TRUE);
} else {
CFX_WideString wsLocaleName;
GetLocaleName(wsLocaleName);
pValue->SetString(
FX_UTF8Encode(wsLocaleName.c_str(), wsLocaleName.GetLength())
.AsStringC());
}
}
void CXFA_Node::Script_Subform_ExecEvent(CFXJSE_Arguments* pArguments) {
int32_t argc = pArguments->GetLength();
if (argc == 1) {
CFX_ByteString eventString = pArguments->GetUTF8String(0);
execSingleEventByName(
CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(),
XFA_Element::Subform);
} else {
ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent");
}
}