void CXFA_ScriptContext::GlobalPropertySetter(CFXJSE_Value* pObject, const CFX_ByteStringC& szPropName, CFXJSE_Value* pValue) { CXFA_Object* lpOrginalNode = ToObject(pObject, nullptr); CXFA_Document* pDoc = lpOrginalNode->GetDocument(); CXFA_ScriptContext* lpScriptContext = pDoc->GetScriptContext(); CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(lpOrginalNode); CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); uint32_t dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Attributes; CXFA_Node* pRefNode = ToNode(lpScriptContext->GetThisObject()); if (lpOrginalNode->IsVariablesThis()) pRefNode = ToNode(lpCurNode); if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsStringC(), pValue, dwFlag, TRUE)) { return; } if (lpOrginalNode->IsVariablesThis()) { if (pValue && pValue->IsUndefined()) { pObject->SetObjectOwnProperty(szPropName, pValue); return; } } CXFA_FFNotify* pNotify = pDoc->GetNotify(); if (!pNotify) { return; } pNotify->GetDocProvider()->SetGlobalProperty(pNotify->GetHDOC(), szPropName, pValue); }
CXFA_WidgetAcc* CXFA_FFDocView::GetWidgetAccByName( const CFX_WideString& wsName, CXFA_WidgetAcc* pRefWidgetAcc) { CFX_WideString wsExpression; uint32_t dwStyle = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_Parent; CXFA_ScriptContext* pScriptContext = m_pDoc->GetXFADoc()->GetScriptContext(); if (!pScriptContext) { return nullptr; } CXFA_Node* refNode = nullptr; if (pRefWidgetAcc) { refNode = pRefWidgetAcc->GetNode(); wsExpression = wsName; } else { wsExpression = L"$form." + wsName; } XFA_RESOLVENODE_RS resoveNodeRS; int32_t iRet = pScriptContext->ResolveObjects( refNode, wsExpression.AsStringC(), resoveNodeRS, dwStyle); if (iRet < 1) { return nullptr; } if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { CXFA_Node* pNode = resoveNodeRS.nodes[0]->AsNode(); if (pNode) { return (CXFA_WidgetAcc*)pNode->GetWidgetData(); } } return nullptr; }
void CXFA_ScriptContext::GlobalPropertyGetter(CFXJSE_Value* pObject, const CFX_ByteStringC& szPropName, CFXJSE_Value* pValue) { CXFA_Object* pOriginalObject = ToObject(pObject, nullptr); CXFA_Document* pDoc = pOriginalObject->GetDocument(); CXFA_ScriptContext* lpScriptContext = pDoc->GetScriptContext(); CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(pOriginalObject); CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); if (lpScriptContext->GetType() == XFA_SCRIPTLANGTYPE_Formcalc) { if (szPropName == kFormCalcRuntime) { lpScriptContext->m_FM2JSContext->GlobalPropertyGetter(pValue); return; } XFA_HashCode uHashCode = static_cast<XFA_HashCode>( FX_HashCode_GetW(wsPropName.AsStringC(), false)); if (uHashCode != XFA_HASHCODE_Layout) { CXFA_Object* pObj = lpScriptContext->GetDocument()->GetXFAObject(uHashCode); if (pObj) { pValue->Assign(lpScriptContext->GetJSValueFromMap(pObj)); return; } } } uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Attributes; CXFA_Node* pRefNode = ToNode(lpScriptContext->GetThisObject()); if (pOriginalObject->IsVariablesThis()) { pRefNode = ToNode(lpCurNode); } if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsStringC(), pValue, dwFlag, FALSE)) { return; } dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsStringC(), pValue, dwFlag, FALSE)) { return; } CXFA_Object* pScriptObject = lpScriptContext->GetVariablesThis(pOriginalObject, TRUE); if (pScriptObject && lpScriptContext->QueryVariableValue(pScriptObject->AsNode(), szPropName, pValue, TRUE)) { return; } CXFA_FFNotify* pNotify = pDoc->GetNotify(); if (!pNotify) { return; } pNotify->GetDocProvider()->GetGlobalProperty(pNotify->GetHDOC(), szPropName, pValue); }
void CScript_HostPseudoModel::OpenList(CFXJSE_Arguments* pArguments) { if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { return; } int32_t iLength = pArguments->GetLength(); if (iLength != 1) { ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"openList"); return; } CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); if (!pNotify) { return; } CXFA_Node* pNode = nullptr; if (iLength >= 1) { std::unique_ptr<CFXJSE_Value> pValue(pArguments->GetValue(0)); if (pValue->IsObject()) { pNode = ToNode(pValue.get(), nullptr); } else if (pValue->IsString()) { CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); if (!pScriptContext) return; CXFA_Object* pObject = pScriptContext->GetThisObject(); if (!pObject) return; uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; XFA_RESOLVENODE_RS resoveNodeRS; int32_t iRet = pScriptContext->ResolveObjects( pObject, pValue->ToWideString().AsStringC(), resoveNodeRS, dwFlag); if (iRet < 1 || !resoveNodeRS.nodes[0]->IsNode()) return; pNode = resoveNodeRS.nodes[0]->AsNode(); } } CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout(); if (!pDocLayout) { return; } CXFA_FFWidget* hWidget = pNotify->GetHWidget(pDocLayout->GetLayoutItem(pNode)); if (!hWidget) { return; } pNotify->GetDocEnvironment()->SetFocusWidget(pNotify->GetHDOC(), hWidget); pNotify->OpenDropDownList(hWidget); }
void CXFA_ScriptContext::NormalPropertySetter(CFXJSE_Value* pOriginalValue, const CFX_ByteStringC& szPropName, CFXJSE_Value* pReturnValue) { CXFA_Object* pOriginalObject = ToObject(pOriginalValue, nullptr); if (!pOriginalObject) return; CXFA_ScriptContext* lpScriptContext = pOriginalObject->GetDocument()->GetScriptContext(); CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOriginalObject); CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = XFA_GetScriptAttributeByName( pObject->GetElementType(), wsPropName.AsStringC()); if (lpAttributeInfo) { (pObject->*(lpAttributeInfo->lpfnCallback))( pReturnValue, TRUE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); } else { if (pObject->IsNode()) { if (wsPropName.GetAt(0) == '#') { wsPropName = wsPropName.Right(wsPropName.GetLength() - 1); } CXFA_Node* pNode = ToNode(pObject); CXFA_Node* pPropOrChild = nullptr; XFA_Element eType = XFA_GetElementTypeForName(wsPropName.AsStringC()); if (eType != XFA_Element::Unknown) pPropOrChild = pNode->GetProperty(0, eType); else pPropOrChild = pNode->GetFirstChildByName(wsPropName.AsStringC()); if (pPropOrChild) { CFX_WideString wsDefaultName(L"{default}"); const XFA_SCRIPTATTRIBUTEINFO* lpAttrInfo = XFA_GetScriptAttributeByName(pPropOrChild->GetElementType(), wsDefaultName.AsStringC()); if (lpAttrInfo) { (pPropOrChild->*(lpAttrInfo->lpfnCallback))( pReturnValue, TRUE, (XFA_ATTRIBUTE)lpAttrInfo->eAttribute); return; } } } CXFA_Object* pScriptObject = lpScriptContext->GetVariablesThis(pOriginalObject, TRUE); if (pScriptObject) { lpScriptContext->QueryVariableValue(ToNode(pScriptObject), szPropName, pReturnValue, FALSE); } } }
void CScript_HostPseudoModel::ResetData(CFXJSE_Arguments* pArguments) { int32_t iLength = pArguments->GetLength(); if (iLength < 0 || iLength > 1) { ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resetData"); return; } CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); if (!pNotify) { return; } CFX_WideString wsExpression; if (iLength >= 1) { CFX_ByteString bsExpression = pArguments->GetUTF8String(0); wsExpression = CFX_WideString::FromUTF8(bsExpression.AsStringC()); } if (wsExpression.IsEmpty()) { pNotify->ResetData(); return; } int32_t iStart = 0; CFX_WideString wsName; CXFA_Node* pNode = nullptr; int32_t iExpLength = wsExpression.GetLength(); while (iStart < iExpLength) { iStart = XFA_FilterName(wsExpression.AsStringC(), iStart, wsName); CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); if (!pScriptContext) { return; } CXFA_Object* pObject = pScriptContext->GetThisObject(); if (!pObject) { return; } uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; XFA_RESOLVENODE_RS resoveNodeRS; int32_t iRet = pScriptContext->ResolveObjects(pObject, wsName.AsStringC(), resoveNodeRS, dwFlag); if (iRet < 1 || !resoveNodeRS.nodes[0]->IsNode()) { continue; } pNode = resoveNodeRS.nodes[0]->AsNode(); pNotify->ResetData(pNode->GetWidgetData()); } if (!pNode) { pNotify->ResetData(); } }
void CXFA_ScriptContext::NormalMethodCall(CFXJSE_Value* pThis, const CFX_ByteStringC& szFuncName, CFXJSE_Arguments& args) { CXFA_Object* pObject = ToObject(pThis, nullptr); if (!pObject) return; CXFA_ScriptContext* lpScriptContext = pObject->GetDocument()->GetScriptContext(); pObject = lpScriptContext->GetVariablesThis(pObject); CFX_WideString wsFunName = CFX_WideString::FromUTF8(szFuncName); const XFA_METHODINFO* lpMethodInfo = GetMethodByName(pObject->GetElementType(), wsFunName.AsStringC()); if (!lpMethodInfo) return; (pObject->*(lpMethodInfo->lpfnCallback))(&args); }
int32_t CXFA_ScriptContext::GlobalPropTypeGetter( CFXJSE_Value* pOriginalValue, const CFX_ByteStringC& szPropName, FX_BOOL bQueryIn) { CXFA_Object* pObject = ToObject(pOriginalValue, nullptr); if (!pObject) return FXJSE_ClassPropType_None; CXFA_ScriptContext* lpScriptContext = pObject->GetDocument()->GetScriptContext(); pObject = lpScriptContext->GetVariablesThis(pObject); XFA_Element eType = pObject->GetElementType(); CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); if (GetMethodByName(eType, wsPropName.AsStringC())) { return FXJSE_ClassPropType_Method; } return FXJSE_ClassPropType_Property; }
void CXFA_FFDocView::RunBindItems() { for (int32_t i = 0; i < m_BindItems.GetSize(); i++) { if (m_BindItems[i]->HasRemovedChildren()) continue; CXFA_Node* pWidgetNode = m_BindItems[i]->GetNodeItem(XFA_NODEITEM_Parent); CXFA_WidgetAcc* pAcc = static_cast<CXFA_WidgetAcc*>(pWidgetNode->GetWidgetData()); if (!pAcc) continue; CXFA_BindItems binditems(m_BindItems[i]); CXFA_ScriptContext* pScriptContext = pWidgetNode->GetDocument()->GetScriptContext(); CFX_WideStringC wsRef; binditems.GetRef(wsRef); uint32_t dwStyle = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_ALL; XFA_RESOLVENODE_RS rs; pScriptContext->ResolveObjects(pWidgetNode, wsRef, rs, dwStyle); int32_t iCount = rs.nodes.GetSize(); pAcc->DeleteItem(-1); if (rs.dwFlags != XFA_RESOVENODE_RSTYPE_Nodes || iCount < 1) continue; CFX_WideStringC wsValueRef, wsLabelRef; binditems.GetValueRef(wsValueRef); binditems.GetLabelRef(wsLabelRef); const bool bUseValue = wsLabelRef.IsEmpty() || wsLabelRef == wsValueRef; const bool bLabelUseContent = wsLabelRef.IsEmpty() || wsLabelRef == FX_WSTRC(L"$"); const bool bValueUseContent = wsValueRef.IsEmpty() || wsValueRef == FX_WSTRC(L"$"); CFX_WideString wsValue; CFX_WideString wsLabel; uint32_t uValueHash = FX_HashCode_GetW(wsValueRef, false); for (int32_t j = 0; j < iCount; j++) { CXFA_Object* refObj = rs.nodes[j]; if (!refObj->IsNode()) { continue; } CXFA_Node* refNode = refObj->AsNode(); if (bValueUseContent) { wsValue = refNode->GetContent(); } else { CXFA_Node* nodeValue = refNode->GetFirstChildByName(uValueHash); wsValue = nodeValue ? nodeValue->GetContent() : refNode->GetContent(); } if (!bUseValue) { if (bLabelUseContent) { wsLabel = refNode->GetContent(); } else { CXFA_Node* nodeLabel = refNode->GetFirstChildByName(wsLabelRef); if (nodeLabel) wsLabel = nodeLabel->GetContent(); } } else { wsLabel = wsValue; } pAcc->InsertItem(wsLabel, wsValue); } } m_BindItems.RemoveAll(); }
void CXFA_ScriptContext::NormalPropertyGetter(CFXJSE_Value* pOriginalValue, const CFX_ByteStringC& szPropName, CFXJSE_Value* pReturnValue) { CXFA_Object* pOriginalObject = ToObject(pOriginalValue, nullptr); if (!pOriginalObject) { pReturnValue->SetUndefined(); return; } CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); CXFA_ScriptContext* lpScriptContext = pOriginalObject->GetDocument()->GetScriptContext(); CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOriginalObject); if (wsPropName == FX_WSTRC(L"xfa")) { CFXJSE_Value* pValue = lpScriptContext->GetJSValueFromMap( lpScriptContext->GetDocument()->GetRoot()); pReturnValue->Assign(pValue); return; } uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Attributes; FX_BOOL bRet = lpScriptContext->QueryNodeByFlag( ToNode(pObject), wsPropName.AsStringC(), pReturnValue, dwFlag, FALSE); if (bRet) { return; } if (pObject == lpScriptContext->GetThisObject() || (lpScriptContext->GetType() == XFA_SCRIPTLANGTYPE_Javascript && !lpScriptContext->IsStrictScopeInJavaScript())) { dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; bRet = lpScriptContext->QueryNodeByFlag( ToNode(pObject), wsPropName.AsStringC(), pReturnValue, dwFlag, FALSE); } if (bRet) { return; } CXFA_Object* pScriptObject = lpScriptContext->GetVariablesThis(pOriginalObject, TRUE); if (pScriptObject) { bRet = lpScriptContext->QueryVariableValue(ToNode(pScriptObject), szPropName, pReturnValue, TRUE); } if (!bRet) { pReturnValue->SetUndefined(); } }