void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_SheetInBatch(
    CFXJSE_Arguments* pArguments) {
  int32_t iLength = pArguments->GetLength();
  if (iLength != 1) {
    ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
                            L"sheetInBatch");
    return;
  }
  CXFA_Node* pNode = NULL;
  if (iLength >= 1) {
    pNode = (CXFA_Node*)pArguments->GetObject(0);
  }
  if (!pNode) {
    return;
  }
  IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();
  if (!pNotify) {
    return;
  }
  IXFA_DocLayout* pDocLayout = m_pDocument->GetDocLayout();
  if (!pDocLayout) {
    return;
  }
  IXFA_Widget* hWidget = pNotify->GetHWidget(pDocLayout->GetLayoutItem(pNode));
  if (!hWidget) {
    return;
  }
  IXFA_Doc* hDoc = pNotify->GetHDOC();
  int32_t iPageCount = pNotify->GetDocProvider()->SheetInBatch(hDoc, hWidget);
  FXJSE_HVALUE hValue = pArguments->GetReturnValue();
  if (hValue) {
    FXJSE_Value_SetInteger(hValue, iPageCount);
  }
}
void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_PageSpan(
    CFXJSE_Arguments* pArguments) {
  int32_t iLength = pArguments->GetLength();
  if (iLength != 1) {
    ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"pageSpan");
    return;
  }
  CXFA_Node* pNode = NULL;
  if (iLength >= 1) {
    pNode = (CXFA_Node*)pArguments->GetObject(0);
  }
  if (!pNode) {
    return;
  }
  IXFA_DocLayout* pDocLayout = m_pDocument->GetDocLayout();
  if (!pDocLayout) {
    return;
  }
  FXJSE_HVALUE hValue = pArguments->GetReturnValue();
  CXFA_LayoutItem* pLayoutItem = pDocLayout->GetLayoutItem(pNode);
  if (!pLayoutItem) {
    FXJSE_Value_SetInteger(hValue, -1);
    return;
  }
  int32_t iLast = pLayoutItem->GetLast()->GetPage()->GetPageIndex();
  int32_t iFirst = pLayoutItem->GetFirst()->GetPage()->GetPageIndex();
  int32_t iPageSpan = iLast - iFirst + 1;
  if (hValue) {
    FXJSE_Value_SetInteger(hValue, iPageSpan);
  }
}
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);
}
void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_PageImp(
    CFXJSE_Arguments* pArguments,
    FX_BOOL bAbsPage) {
  int32_t iLength = pArguments->GetLength();
  if (iLength != 1) {
    const FX_WCHAR* methodName;
    if (bAbsPage) {
      methodName = L"absPage";
    } else {
      methodName = L"page";
    }
    ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, methodName);
    return;
  }
  CXFA_Node* pNode = NULL;
  if (iLength >= 1) {
    pNode = (CXFA_Node*)pArguments->GetObject(0);
  }
  int32_t iPage = 0;
  FXJSE_HVALUE hValue = pArguments->GetReturnValue();
  if (!pNode && hValue) {
    FXJSE_Value_SetInteger(hValue, iPage);
  }
  IXFA_DocLayout* pDocLayout = m_pDocument->GetDocLayout();
  if (!pDocLayout) {
    return;
  }
  CXFA_LayoutItem* pLayoutItem = pDocLayout->GetLayoutItem(pNode);
  if (!pLayoutItem) {
    FXJSE_Value_SetInteger(hValue, -1);
    return;
  }
  iPage = pLayoutItem->GetFirst()->GetPage()->GetPageIndex();
  if (hValue) {
    FXJSE_Value_SetInteger(hValue, bAbsPage ? iPage : iPage + 1);
  }
}
void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_HWXY(
    CFXJSE_Arguments* pArguments,
    XFA_LAYOUTMODEL_HWXY layoutModel) {
  int32_t iLength = pArguments->GetLength();
  if (iLength < 1 || iLength > 3) {
    const FX_WCHAR* methodName = NULL;
    switch (layoutModel) {
      case XFA_LAYOUTMODEL_H:
        methodName = L"h";
        break;
      case XFA_LAYOUTMODEL_W:
        methodName = L"w";
        break;
      case XFA_LAYOUTMODEL_X:
        methodName = L"x";
        break;
      case XFA_LAYOUTMODEL_Y:
        methodName = L"y";
        break;
    }
    ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, methodName);
    return;
  }
  CXFA_Node* pNode = NULL;
  CFX_WideString wsUnit = FX_WSTRC(L"pt");
  int32_t iIndex = 0;
  if (iLength >= 1) {
    pNode = (CXFA_Node*)pArguments->GetObject(0);
  }
  if (iLength >= 2) {
    CFX_ByteString bsUnit = pArguments->GetUTF8String(1);
    if (!bsUnit.IsEmpty()) {
      wsUnit = CFX_WideString::FromUTF8(bsUnit, bsUnit.GetLength());
    }
  }
  if (iLength >= 3) {
    iIndex = pArguments->GetInt32(2);
  }
  if (!pNode) {
    return;
  }
  IXFA_DocLayout* pDocLayout = m_pDocument->GetDocLayout();
  if (!pDocLayout) {
    return;
  }
  CFX_RectF rtRect;
  CXFA_Measurement measure;
  CXFA_LayoutItem* pLayoutItem = pDocLayout->GetLayoutItem(pNode);
  if (!pLayoutItem) {
    return;
  }
  while (iIndex > 0 && pLayoutItem) {
    pLayoutItem = pLayoutItem->GetNext();
    iIndex--;
  }
  FXJSE_HVALUE hValue = pArguments->GetReturnValue();
  if (!pLayoutItem) {
    FXJSE_Value_SetFloat(hValue, 0);
    return;
  }
  pLayoutItem->GetRect(rtRect, TRUE);
  switch (layoutModel) {
    case XFA_LAYOUTMODEL_H:
      measure.Set(rtRect.height, XFA_UNIT_Pt);
      break;
    case XFA_LAYOUTMODEL_W:
      measure.Set(rtRect.width, XFA_UNIT_Pt);
      break;
    case XFA_LAYOUTMODEL_X:
      measure.Set(rtRect.left, XFA_UNIT_Pt);
      break;
    case XFA_LAYOUTMODEL_Y:
      measure.Set(rtRect.top, XFA_UNIT_Pt);
      break;
  }
  XFA_UNIT unit = measure.GetUnit(wsUnit);
  FX_FLOAT fValue = measure.ToUnit(unit);
  fValue = FXSYS_round(fValue * 1000) / 1000.0f;
  if (hValue) {
    FXJSE_Value_SetFloat(hValue, fValue);
  }
}