Exemplo n.º 1
0
void CScript_HostPseudoModel::Script_HostPseudoModel_OpenList(
    CFXJSE_Arguments* pArguments) {
    if (!m_pDocument->GetScriptContext()->IsRunAtClient()) {
        return;
    }
    int32_t iLength = pArguments->GetLength();
    if (iLength != 1) {
        ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"openList");
        return;
    }
    IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    if (!pNotify) {
        return;
    }
    CXFA_Node* pNode = NULL;
    if (iLength >= 1) {
        FXJSE_HVALUE hValue = pArguments->GetValue(0);
        if (FXJSE_Value_IsObject(hValue)) {
            pNode = static_cast<CXFA_Node*>(FXJSE_Value_ToObject(hValue, nullptr));
        } else if (FXJSE_Value_IsUTF8String(hValue)) {
            CFX_ByteString bsString;
            FXJSE_Value_ToUTF8String(hValue, bsString);
            CFX_WideString wsExpression =
                CFX_WideString::FromUTF8(bsString, bsString.GetLength());
            IXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
            if (!pScriptContext) {
                FXJSE_Value_Release(hValue);
                return;
            }
            CXFA_Object* pObject = pScriptContext->GetThisObject();
            if (!pObject) {
                FXJSE_Value_Release(hValue);
                return;
            }
            FX_DWORD dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Parent |
                              XFA_RESOLVENODE_Siblings;
            XFA_RESOLVENODE_RS resoveNodeRS;
            int32_t iRet = pScriptContext->ResolveObjects(pObject, wsExpression,
                           resoveNodeRS, dwFlag);
            if (iRet < 1 || !resoveNodeRS.nodes[0]->IsNode()) {
                FXJSE_Value_Release(hValue);
                return;
            }
            pNode = resoveNodeRS.nodes[0]->AsNode();
        }
        FXJSE_Value_Release(hValue);
    }
    IXFA_DocLayout* pDocLayout = m_pDocument->GetDocLayout();
    if (!pDocLayout) {
        return;
    }
    IXFA_Widget* hWidget = pNotify->GetHWidget(pDocLayout->GetLayoutItem(pNode));
    if (!hWidget) {
        return;
    }
    pNotify->GetDocProvider()->SetFocusWidget(pNotify->GetHDOC(), hWidget);
    pNotify->OpenDropDownList(hWidget);
}
Exemplo n.º 2
0
void CScript_HostPseudoModel::Script_HostPseudoModel_ResetData(
    CFXJSE_Arguments* pArguments) {
    int32_t iLength = pArguments->GetLength();
    if (iLength < 0 || iLength > 1) {
        ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resetData");
        return;
    }
    IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    if (!pNotify) {
        return;
    }
    CFX_WideString wsExpression;
    if (iLength >= 1) {
        CFX_ByteString bsExpression = pArguments->GetUTF8String(0);
        wsExpression =
            CFX_WideString::FromUTF8(bsExpression, bsExpression.GetLength());
    }
    if (wsExpression.IsEmpty()) {
        pNotify->ResetData();
        return;
    }
    int32_t iStart = 0;
    CFX_WideString wsName;
    CXFA_Node* pNode = NULL;
    int32_t iExpLength = wsExpression.GetLength();
    while (iStart < iExpLength) {
        iStart = XFA_FilterName(wsExpression, iStart, wsName);
        IXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
        if (!pScriptContext) {
            return;
        }
        CXFA_Object* pObject = pScriptContext->GetThisObject();
        if (!pObject) {
            return;
        }
        FX_DWORD dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Parent |
                          XFA_RESOLVENODE_Siblings;
        XFA_RESOLVENODE_RS resoveNodeRS;
        int32_t iRet =
            pScriptContext->ResolveObjects(pObject, wsName, resoveNodeRS, dwFlag);
        if (iRet < 1 || !resoveNodeRS.nodes[0]->IsNode()) {
            continue;
        }
        pNode = resoveNodeRS.nodes[0]->AsNode();
        pNotify->ResetData(pNode->GetWidgetData());
    }
    if (!pNode) {
        pNotify->ResetData();
    }
}