void CXFA_ResolveProcessor::XFA_ResolveNode_DoPredicateFilter(
    int32_t iCurIndex,
    CFX_WideString wsCondition,
    int32_t iFoundCount,
    CXFA_ResolveNodesData& rnd) {
  CXFA_NodeArray& findNodes = (CXFA_NodeArray&)rnd.m_Nodes;
  FXSYS_assert(iFoundCount == findNodes.GetSize());
  CFX_WideString wsExpression;
  IXFA_ScriptContext* pContext = NULL;
  XFA_SCRIPTLANGTYPE eLangType = XFA_SCRIPTLANGTYPE_Unkown;
  if (wsCondition.Left(2) == FX_WSTRC(L".[") &&
      wsCondition.Right(1) == FX_WSTRC(L"]")) {
    eLangType = XFA_SCRIPTLANGTYPE_Formcalc;
  } else if (wsCondition.Left(2) == FX_WSTRC(L".(") &&
             wsCondition.Right(1) == FX_WSTRC(L")")) {
    eLangType = XFA_SCRIPTLANGTYPE_Javascript;
  } else {
    return;
  }
  pContext = rnd.m_pSC;
  wsExpression = wsCondition.Mid(2, wsCondition.GetLength() - 3);
  for (int32_t i = iFoundCount - 1; i >= 0; i--) {
    CXFA_Object* node = findNodes[i];
    FX_BOOL bRet = FALSE;
    FXJSE_HVALUE pRetValue = FXJSE_Value_Create(rnd.m_pSC->GetRuntime());
    bRet = pContext->RunScript(eLangType, wsExpression, pRetValue, node);
    if (!bRet || !FXJSE_Value_ToBoolean(pRetValue)) {
      findNodes.RemoveAt(i);
    }
    FXJSE_Value_Release(pRetValue);
  }
}
Esempio n. 2
0
CXFA_WidgetAcc* CXFA_FFDocView::GetWidgetAccByName(
    const CFX_WideStringC& wsName,
    CXFA_WidgetAcc* pRefWidgetAcc) {
  CFX_WideString wsExpression;
  FX_DWORD dwStyle = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties |
                     XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_Parent;
  IXFA_ScriptContext* pScriptContext = m_pDoc->GetXFADoc()->GetScriptContext();
  if (!pScriptContext) {
    return NULL;
  }
  CXFA_Node* refNode = NULL;
  if (pRefWidgetAcc != NULL) {
    refNode = pRefWidgetAcc->GetNode();
    wsExpression = wsName;
  } else {
    wsExpression = L"$form." + wsName;
  }
  XFA_RESOLVENODE_RS resoveNodeRS;
  int32_t iRet = pScriptContext->ResolveObjects(refNode, wsExpression,
                                                resoveNodeRS, dwStyle);
  if (iRet < 1) {
    return NULL;
  }
  if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
    CXFA_Node* pNode = resoveNodeRS.nodes[0]->AsNode();
    if (pNode) {
      return (CXFA_WidgetAcc*)pNode->GetWidgetData();
    }
  }
  return NULL;
}
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);
}
Esempio n. 4
0
FXJSE_HVALUE CXFA_FFDocHandler::GetXFAScriptObject(IXFA_Doc* hDoc) {
  CXFA_Document* pXFADoc = static_cast<CXFA_FFDoc*>(hDoc)->GetXFADoc();
  if (!pXFADoc) {
    return NULL;
  }
  IXFA_ScriptContext* pScriptContext = pXFADoc->GetScriptContext();
  if (!pScriptContext) {
    return NULL;
  }
  return pScriptContext->GetJSValueFromMap(pXFADoc->GetRoot());
}
void CScript_EventPseudoModel::Script_EventPseudoModel_Reset(
    CFXJSE_Arguments* pArguments) {
    IXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
    if (!pScriptContext) {
        return;
    }
    CXFA_EventParam* pEventParam = pScriptContext->GetEventParam();
    if (!pEventParam) {
        return;
    }
    pEventParam->Reset();
}
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();
    }
}
Esempio n. 7
0
FX_BOOL CXFA_FFDocHandler::RunDocScript(IXFA_Doc* hDoc,
                                        XFA_SCRIPTTYPE eScriptType,
                                        const CFX_WideStringC& wsScript,
                                        FXJSE_HVALUE hRetValue,
                                        FXJSE_HVALUE hThisObject) {
  CXFA_Document* pXFADoc = static_cast<CXFA_FFDoc*>(hDoc)->GetXFADoc();
  if (!pXFADoc) {
    return FALSE;
  }
  IXFA_ScriptContext* pScriptContext = pXFADoc->GetScriptContext();
  if (!pScriptContext) {
    return FALSE;
  }
  return pScriptContext->RunScript(
      (XFA_SCRIPTLANGTYPE)eScriptType, wsScript, hRetValue,
      hThisObject ? (CXFA_Object*)FXJSE_Value_ToObject(hThisObject, NULL)
                  : NULL);
}
void CScript_EventPseudoModel::Script_EventPseudoModel_Emit(
    CFXJSE_Arguments* pArguments) {
    IXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
    if (!pScriptContext) {
        return;
    }
    CXFA_EventParam* pEventParam = pScriptContext->GetEventParam();
    if (!pEventParam) {
        return;
    }
    IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
    if (!pNotify) {
        return;
    }
    IXFA_WidgetHandler* pWidgetHandler = pNotify->GetWidgetHandler();
    if (!pWidgetHandler) {
        return;
    }
    pWidgetHandler->ProcessEvent(pEventParam->m_pTarget, pEventParam);
}
void CScript_EventPseudoModel::Script_EventPseudoModel_Property(
    FXJSE_HVALUE hValue,
    FX_DWORD dwFlag,
    FX_BOOL bSetting) {
    IXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
    if (!pScriptContext) {
        return;
    }
    CXFA_EventParam* pEventParam = pScriptContext->GetEventParam();
    if (!pEventParam) {
        return;
    }
    switch (dwFlag) {
    case XFA_EVENT_CANCELACTION:
        Script_EventPseudoModel_BooleanProperty(
            hValue, pEventParam->m_bCancelAction, bSetting);
        break;
    case XFA_EVENT_CHANGE:
        Script_EventPseudoModel_StringProperty(hValue, pEventParam->m_wsChange,
                                               bSetting);
        break;
    case XFA_EVENT_COMMITKEY:
        Script_EventPseudoModel_InterProperty(hValue, pEventParam->m_iCommitKey,
                                              bSetting);
        break;
    case XFA_EVENT_FULLTEXT:
        Script_EventPseudoModel_StringProperty(hValue, pEventParam->m_wsFullText,
                                               bSetting);
        break;
    case XFA_EVENT_KEYDOWN:
        Script_EventPseudoModel_BooleanProperty(hValue, pEventParam->m_bKeyDown,
                                                bSetting);
        break;
    case XFA_EVENT_MODIFIER:
        Script_EventPseudoModel_BooleanProperty(hValue, pEventParam->m_bModifier,
                                                bSetting);
        break;
    case XFA_EVENT_NEWCONTENTTYPE:
        Script_EventPseudoModel_StringProperty(
            hValue, pEventParam->m_wsNewContentType, bSetting);
        break;
    case XFA_EVENT_NEWTEXT:
        Script_EventPseudoModel_StringProperty(hValue, pEventParam->m_wsNewText,
                                               bSetting);
        break;
    case XFA_EVENT_PREVCONTENTTYPE:
        Script_EventPseudoModel_StringProperty(
            hValue, pEventParam->m_wsPrevContentType, bSetting);
        break;
    case XFA_EVENT_PREVTEXT:
        Script_EventPseudoModel_StringProperty(hValue, pEventParam->m_wsPrevText,
                                               bSetting);
        break;
    case XFA_EVENT_REENTER:
        Script_EventPseudoModel_BooleanProperty(hValue, pEventParam->m_bReenter,
                                                bSetting);
        break;
    case XFA_EVENT_SELEND:
        Script_EventPseudoModel_InterProperty(hValue, pEventParam->m_iSelEnd,
                                              bSetting);
        break;
    case XFA_EVENT_SELSTART:
        Script_EventPseudoModel_InterProperty(hValue, pEventParam->m_iSelStart,
                                              bSetting);
        break;
    case XFA_EVENT_SHIFT:
        Script_EventPseudoModel_BooleanProperty(hValue, pEventParam->m_bShift,
                                                bSetting);
        break;
    case XFA_EVENT_SOAPFAULTCODE:
        Script_EventPseudoModel_StringProperty(
            hValue, pEventParam->m_wsSoapFaultCode, bSetting);
        break;
    case XFA_EVENT_SOAPFAULTSTRING:
        Script_EventPseudoModel_StringProperty(
            hValue, pEventParam->m_wsSoapFaultString, bSetting);
        break;
    case XFA_EVENT_TARGET:
        break;
    default:
        break;
    }
}
Esempio n. 10
0
void CXFA_FFDocView::RunBindItems() {
  int32_t iCount = m_bindItems.GetSize();
  for (int32_t i = 0; i < iCount; i++) {
    if (reinterpret_cast<CXFA_Node*>(m_bindItems[i])
            ->HasFlag(XFA_NODEFLAG_HasRemoved)) {
      continue;
    }
    CXFA_Node* pWidgetNode = reinterpret_cast<CXFA_Node*>(m_bindItems[i])
                                 ->GetNodeItem(XFA_NODEITEM_Parent);
    CXFA_WidgetAcc* pAcc = (CXFA_WidgetAcc*)pWidgetNode->GetWidgetData();
    if (!pAcc) {
      continue;
    }
    CXFA_BindItems binditems(reinterpret_cast<CXFA_Node*>(m_bindItems[i]));
    IXFA_ScriptContext* pScriptContext =
        pWidgetNode->GetDocument()->GetScriptContext();
    CFX_WideStringC wsRef;
    binditems.GetRef(wsRef);
    FX_DWORD 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);
    FX_BOOL bUseValue = wsLabelRef.IsEmpty() || wsLabelRef == wsValueRef;
    FX_BOOL bLabelUseContent =
        wsLabelRef.IsEmpty() || wsLabelRef == FX_WSTRC(L"$");
    FX_BOOL bValueUseContent =
        wsValueRef.IsEmpty() || wsValueRef == FX_WSTRC(L"$");
    CFX_WideString wsValue, wsLabel;
    FX_DWORD uValueHash = FX_HashCode_String_GetW(CFX_WideString(wsValueRef),
                                                  wsValueRef.GetLength());
    for (int32_t i = 0; i < iCount; i++) {
      CXFA_Object* refObj = rs.nodes[i];
      if (!refObj->IsNode()) {
        continue;
      }
      CXFA_Node* refNode = refObj->AsNode();
      if (bValueUseContent) {
        wsValue = refNode->GetContent();
      } else {
        CXFA_Node* nodeValue = refNode->GetFirstChildByName(uValueHash);
        if (nodeValue == NULL) {
          wsValue = refNode->GetContent();
        } else {
          wsValue = nodeValue->GetContent();
        }
      }
      if (!bUseValue) {
        if (bLabelUseContent) {
          wsLabel = refNode->GetContent();
        } else {
          CXFA_Node* nodeLabel = refNode->GetFirstChildByName(wsLabelRef);
          if (nodeLabel != NULL) {
            wsLabel = nodeLabel->GetContent();
          }
        }
      } else {
        wsLabel = wsValue;
      }
      pAcc->InsertItem(wsLabel, wsValue);
    }
  }
  m_bindItems.RemoveAll();
}