From c1515ef195a2310f1d07838902eb10d66f66dbed Mon Sep 17 00:00:00 2001 From: dsinclair Date: Wed, 20 Jul 2016 06:16:06 -0700 Subject: Rename the CScript_* files to match class names. This Cl updates the various files to have filenames which match the classes inside those files. Review-Url: https://codereview.chromium.org/2161193002 --- BUILD.gn | 24 +- xfa.gyp | 24 +- xfa/fxfa/parser/cscript_datawindow.cpp | 47 ++ xfa/fxfa/parser/cscript_datawindow.h | 36 ++ xfa/fxfa/parser/cscript_eventpseudomodel.cpp | 234 +++++++ xfa/fxfa/parser/cscript_eventpseudomodel.h | 86 +++ xfa/fxfa/parser/cscript_hostpseudomodel.cpp | 717 +++++++++++++++++++++ xfa/fxfa/parser/cscript_hostpseudomodel.h | 74 +++ xfa/fxfa/parser/cscript_layoutpseudomodel.cpp | 514 +++++++++++++++ xfa/fxfa/parser/cscript_layoutpseudomodel.h | 59 ++ xfa/fxfa/parser/cscript_logpseudomodel.cpp | 33 + xfa/fxfa/parser/cscript_logpseudomodel.h | 25 + xfa/fxfa/parser/cscript_signaturepseudomodel.cpp | 122 ++++ xfa/fxfa/parser/cscript_signaturepseudomodel.h | 24 + xfa/fxfa/parser/xfa_basic_data_element_script.cpp | 12 +- xfa/fxfa/parser/xfa_document_imp.cpp | 12 +- xfa/fxfa/parser/xfa_script_datawindow.cpp | 47 -- xfa/fxfa/parser/xfa_script_datawindow.h | 36 -- xfa/fxfa/parser/xfa_script_eventpseudomodel.cpp | 234 ------- xfa/fxfa/parser/xfa_script_eventpseudomodel.h | 86 --- xfa/fxfa/parser/xfa_script_hostpseudomodel.cpp | 717 --------------------- xfa/fxfa/parser/xfa_script_hostpseudomodel.h | 74 --- xfa/fxfa/parser/xfa_script_layoutpseudomodel.cpp | 514 --------------- xfa/fxfa/parser/xfa_script_layoutpseudomodel.h | 59 -- xfa/fxfa/parser/xfa_script_logpseudomodel.cpp | 33 - xfa/fxfa/parser/xfa_script_logpseudomodel.h | 25 - .../parser/xfa_script_signaturepseudomodel.cpp | 122 ---- xfa/fxfa/parser/xfa_script_signaturepseudomodel.h | 24 - 28 files changed, 2007 insertions(+), 2007 deletions(-) create mode 100644 xfa/fxfa/parser/cscript_datawindow.cpp create mode 100644 xfa/fxfa/parser/cscript_datawindow.h create mode 100644 xfa/fxfa/parser/cscript_eventpseudomodel.cpp create mode 100644 xfa/fxfa/parser/cscript_eventpseudomodel.h create mode 100644 xfa/fxfa/parser/cscript_hostpseudomodel.cpp create mode 100644 xfa/fxfa/parser/cscript_hostpseudomodel.h create mode 100644 xfa/fxfa/parser/cscript_layoutpseudomodel.cpp create mode 100644 xfa/fxfa/parser/cscript_layoutpseudomodel.h create mode 100644 xfa/fxfa/parser/cscript_logpseudomodel.cpp create mode 100644 xfa/fxfa/parser/cscript_logpseudomodel.h create mode 100644 xfa/fxfa/parser/cscript_signaturepseudomodel.cpp create mode 100644 xfa/fxfa/parser/cscript_signaturepseudomodel.h delete mode 100644 xfa/fxfa/parser/xfa_script_datawindow.cpp delete mode 100644 xfa/fxfa/parser/xfa_script_datawindow.h delete mode 100644 xfa/fxfa/parser/xfa_script_eventpseudomodel.cpp delete mode 100644 xfa/fxfa/parser/xfa_script_eventpseudomodel.h delete mode 100644 xfa/fxfa/parser/xfa_script_hostpseudomodel.cpp delete mode 100644 xfa/fxfa/parser/xfa_script_hostpseudomodel.h delete mode 100644 xfa/fxfa/parser/xfa_script_layoutpseudomodel.cpp delete mode 100644 xfa/fxfa/parser/xfa_script_layoutpseudomodel.h delete mode 100644 xfa/fxfa/parser/xfa_script_logpseudomodel.cpp delete mode 100644 xfa/fxfa/parser/xfa_script_logpseudomodel.h delete mode 100644 xfa/fxfa/parser/xfa_script_signaturepseudomodel.cpp delete mode 100644 xfa/fxfa/parser/xfa_script_signaturepseudomodel.h diff --git a/BUILD.gn b/BUILD.gn index 562036ad23..f4f4092c4f 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1327,6 +1327,18 @@ if (pdf_enable_xfa) { "xfa/fxfa/include/xfa_ffwidgethandler.h", "xfa/fxfa/include/xfa_fontmgr.h", "xfa/fxfa/include/xfa_rendercontext.h", + "xfa/fxfa/parser/cscript_datawindow.cpp", + "xfa/fxfa/parser/cscript_datawindow.h", + "xfa/fxfa/parser/cscript_eventpseudomodel.cpp", + "xfa/fxfa/parser/cscript_eventpseudomodel.h", + "xfa/fxfa/parser/cscript_hostpseudomodel.cpp", + "xfa/fxfa/parser/cscript_hostpseudomodel.h", + "xfa/fxfa/parser/cscript_layoutpseudomodel.cpp", + "xfa/fxfa/parser/cscript_layoutpseudomodel.h", + "xfa/fxfa/parser/cscript_logpseudomodel.cpp", + "xfa/fxfa/parser/cscript_logpseudomodel.h", + "xfa/fxfa/parser/cscript_signaturepseudomodel.cpp", + "xfa/fxfa/parser/cscript_signaturepseudomodel.h", "xfa/fxfa/parser/cxfa_arc.h", "xfa/fxfa/parser/cxfa_arraynodelist.cpp", "xfa/fxfa/parser/cxfa_assist.cpp", @@ -1427,24 +1439,12 @@ if (pdf_enable_xfa) { "xfa/fxfa/parser/xfa_localevalue.h", "xfa/fxfa/parser/xfa_object.h", "xfa/fxfa/parser/xfa_script.h", - "xfa/fxfa/parser/xfa_script_datawindow.cpp", - "xfa/fxfa/parser/xfa_script_datawindow.h", - "xfa/fxfa/parser/xfa_script_eventpseudomodel.cpp", - "xfa/fxfa/parser/xfa_script_eventpseudomodel.h", - "xfa/fxfa/parser/xfa_script_hostpseudomodel.cpp", - "xfa/fxfa/parser/xfa_script_hostpseudomodel.h", "xfa/fxfa/parser/xfa_script_imp.cpp", "xfa/fxfa/parser/xfa_script_imp.h", - "xfa/fxfa/parser/xfa_script_layoutpseudomodel.cpp", - "xfa/fxfa/parser/xfa_script_layoutpseudomodel.h", - "xfa/fxfa/parser/xfa_script_logpseudomodel.cpp", - "xfa/fxfa/parser/xfa_script_logpseudomodel.h", "xfa/fxfa/parser/xfa_script_nodehelper.cpp", "xfa/fxfa/parser/xfa_script_nodehelper.h", "xfa/fxfa/parser/xfa_script_resolveprocessor.cpp", "xfa/fxfa/parser/xfa_script_resolveprocessor.h", - "xfa/fxfa/parser/xfa_script_signaturepseudomodel.cpp", - "xfa/fxfa/parser/xfa_script_signaturepseudomodel.h", "xfa/fxfa/parser/xfa_utils.h", "xfa/fxfa/parser/xfa_utils_imp.cpp", "xfa/fxgraphics/cagg_graphics.cpp", diff --git a/xfa.gyp b/xfa.gyp index 999be123e9..92ea4542bb 100644 --- a/xfa.gyp +++ b/xfa.gyp @@ -437,6 +437,18 @@ "xfa/fxfa/include/xfa_ffwidgethandler.h", "xfa/fxfa/include/xfa_fontmgr.h", "xfa/fxfa/include/xfa_rendercontext.h", + "xfa/fxfa/parser/cscript_datawindow.cpp", + "xfa/fxfa/parser/cscript_datawindow.h", + "xfa/fxfa/parser/cscript_eventpseudomodel.cpp", + "xfa/fxfa/parser/cscript_eventpseudomodel.h", + "xfa/fxfa/parser/cscript_hostpseudomodel.cpp", + "xfa/fxfa/parser/cscript_hostpseudomodel.h", + "xfa/fxfa/parser/cscript_layoutpseudomodel.cpp", + "xfa/fxfa/parser/cscript_layoutpseudomodel.h", + "xfa/fxfa/parser/cscript_logpseudomodel.cpp", + "xfa/fxfa/parser/cscript_logpseudomodel.h", + "xfa/fxfa/parser/cscript_signaturepseudomodel.cpp", + "xfa/fxfa/parser/cscript_signaturepseudomodel.h", "xfa/fxfa/parser/cxfa_arc.h", "xfa/fxfa/parser/cxfa_arraynodelist.cpp", "xfa/fxfa/parser/cxfa_assist.cpp", @@ -537,24 +549,12 @@ "xfa/fxfa/parser/xfa_localevalue.h", "xfa/fxfa/parser/xfa_object.h", "xfa/fxfa/parser/xfa_script.h", - "xfa/fxfa/parser/xfa_script_datawindow.cpp", - "xfa/fxfa/parser/xfa_script_datawindow.h", - "xfa/fxfa/parser/xfa_script_eventpseudomodel.cpp", - "xfa/fxfa/parser/xfa_script_eventpseudomodel.h", - "xfa/fxfa/parser/xfa_script_hostpseudomodel.cpp", - "xfa/fxfa/parser/xfa_script_hostpseudomodel.h", "xfa/fxfa/parser/xfa_script_imp.cpp", "xfa/fxfa/parser/xfa_script_imp.h", - "xfa/fxfa/parser/xfa_script_layoutpseudomodel.cpp", - "xfa/fxfa/parser/xfa_script_layoutpseudomodel.h", - "xfa/fxfa/parser/xfa_script_logpseudomodel.cpp", - "xfa/fxfa/parser/xfa_script_logpseudomodel.h", "xfa/fxfa/parser/xfa_script_nodehelper.cpp", "xfa/fxfa/parser/xfa_script_nodehelper.h", "xfa/fxfa/parser/xfa_script_resolveprocessor.cpp", "xfa/fxfa/parser/xfa_script_resolveprocessor.h", - "xfa/fxfa/parser/xfa_script_signaturepseudomodel.cpp", - "xfa/fxfa/parser/xfa_script_signaturepseudomodel.h", "xfa/fxfa/parser/xfa_utils.h", "xfa/fxfa/parser/xfa_utils_imp.cpp", "xfa/fxgraphics/cagg_graphics.cpp", diff --git a/xfa/fxfa/parser/cscript_datawindow.cpp b/xfa/fxfa/parser/cscript_datawindow.cpp new file mode 100644 index 0000000000..a5b0587d4d --- /dev/null +++ b/xfa/fxfa/parser/cscript_datawindow.cpp @@ -0,0 +1,47 @@ +// 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/cscript_datawindow.h" + +#include "fxjs/include/cfxjse_arguments.h" +#include "xfa/fxfa/parser/xfa_doclayout.h" +#include "xfa/fxfa/parser/xfa_document.h" +#include "xfa/fxfa/parser/xfa_localemgr.h" +#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/xfa_script.h" +#include "xfa/fxfa/parser/xfa_utils.h" + +CScript_DataWindow::CScript_DataWindow(CXFA_Document* pDocument) + : CXFA_Object(pDocument, + XFA_ObjectType::Object, + XFA_Element::DataWindow, + CFX_WideStringC(L"dataWindow")) {} + +CScript_DataWindow::~CScript_DataWindow() {} + +void CScript_DataWindow::MoveCurrentRecord(CFXJSE_Arguments* pArguments) {} + +void CScript_DataWindow::Record(CFXJSE_Arguments* pArguments) {} + +void CScript_DataWindow::GotoRecord(CFXJSE_Arguments* pArguments) {} + +void CScript_DataWindow::IsRecordGroup(CFXJSE_Arguments* pArguments) {} + +void CScript_DataWindow::RecordsBefore(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) {} + +void CScript_DataWindow::CurrentRecordNumber(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) {} + +void CScript_DataWindow::RecordsAfter(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) {} + +void CScript_DataWindow::IsDefined(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) {} diff --git a/xfa/fxfa/parser/cscript_datawindow.h b/xfa/fxfa/parser/cscript_datawindow.h new file mode 100644 index 0000000000..e1ee13ad44 --- /dev/null +++ b/xfa/fxfa/parser/cscript_datawindow.h @@ -0,0 +1,36 @@ +// 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 + +#ifndef XFA_FXFA_PARSER_CSCRIPT_DATAWINDOW_H_ +#define XFA_FXFA_PARSER_CSCRIPT_DATAWINDOW_H_ + +#include "fxjs/include/cfxjse_arguments.h" +#include "xfa/fxfa/parser/xfa_object.h" + +class CScript_DataWindow : public CXFA_Object { + public: + explicit CScript_DataWindow(CXFA_Document* pDocument); + ~CScript_DataWindow() override; + + void MoveCurrentRecord(CFXJSE_Arguments* pArguments); + void Record(CFXJSE_Arguments* pArguments); + void GotoRecord(CFXJSE_Arguments* pArguments); + void IsRecordGroup(CFXJSE_Arguments* pArguments); + void RecordsBefore(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute); + void CurrentRecordNumber(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute); + void RecordsAfter(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute); + void IsDefined(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute); +}; + +#endif // XFA_FXFA_PARSER_CSCRIPT_DATAWINDOW_H_ diff --git a/xfa/fxfa/parser/cscript_eventpseudomodel.cpp b/xfa/fxfa/parser/cscript_eventpseudomodel.cpp new file mode 100644 index 0000000000..d1d1aeaaa9 --- /dev/null +++ b/xfa/fxfa/parser/cscript_eventpseudomodel.cpp @@ -0,0 +1,234 @@ +// 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/cscript_eventpseudomodel.h" + +#include "fxjs/include/cfxjse_arguments.h" +#include "xfa/fxfa/app/xfa_ffnotify.h" +#include "xfa/fxfa/include/cxfa_eventparam.h" +#include "xfa/fxfa/include/xfa_ffwidgethandler.h" +#include "xfa/fxfa/parser/xfa_doclayout.h" +#include "xfa/fxfa/parser/xfa_document.h" +#include "xfa/fxfa/parser/xfa_localemgr.h" +#include "xfa/fxfa/parser/xfa_object.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 StringProperty(CFXJSE_Value* pValue, + CFX_WideString& wsValue, + FX_BOOL bSetting) { + if (bSetting) { + wsValue = pValue->ToWideString(); + return; + } + pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); +} + +void InterProperty(CFXJSE_Value* pValue, int32_t& iValue, FX_BOOL bSetting) { + if (bSetting) { + iValue = pValue->ToInteger(); + return; + } + pValue->SetInteger(iValue); +} + +void BooleanProperty(CFXJSE_Value* pValue, FX_BOOL& bValue, FX_BOOL bSetting) { + if (bSetting) { + bValue = pValue->ToBoolean(); + return; + } + pValue->SetBoolean(bValue); +} + +} // namespace + +CScript_EventPseudoModel::CScript_EventPseudoModel(CXFA_Document* pDocument) + : CXFA_Object(pDocument, + XFA_ObjectType::Object, + XFA_Element::EventPseudoModel, + CFX_WideStringC(L"eventPseudoModel")) {} + +CScript_EventPseudoModel::~CScript_EventPseudoModel() {} + +void CScript_EventPseudoModel::Property(CFXJSE_Value* pValue, + XFA_Event dwFlag, + FX_BOOL bSetting) { + CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); + if (!pScriptContext) + return; + + CXFA_EventParam* pEventParam = pScriptContext->GetEventParam(); + if (!pEventParam) + return; + + switch (dwFlag) { + case XFA_Event::CancelAction: + BooleanProperty(pValue, pEventParam->m_bCancelAction, bSetting); + break; + case XFA_Event::Change: + StringProperty(pValue, pEventParam->m_wsChange, bSetting); + break; + case XFA_Event::CommitKey: + InterProperty(pValue, pEventParam->m_iCommitKey, bSetting); + break; + case XFA_Event::FullText: + StringProperty(pValue, pEventParam->m_wsFullText, bSetting); + break; + case XFA_Event::Keydown: + BooleanProperty(pValue, pEventParam->m_bKeyDown, bSetting); + break; + case XFA_Event::Modifier: + BooleanProperty(pValue, pEventParam->m_bModifier, bSetting); + break; + case XFA_Event::NewContentType: + StringProperty(pValue, pEventParam->m_wsNewContentType, bSetting); + break; + case XFA_Event::NewText: + StringProperty(pValue, pEventParam->m_wsNewText, bSetting); + break; + case XFA_Event::PreviousContentType: + StringProperty(pValue, pEventParam->m_wsPrevContentType, bSetting); + break; + case XFA_Event::PreviousText: + StringProperty(pValue, pEventParam->m_wsPrevText, bSetting); + break; + case XFA_Event::Reenter: + BooleanProperty(pValue, pEventParam->m_bReenter, bSetting); + break; + case XFA_Event::SelectionEnd: + InterProperty(pValue, pEventParam->m_iSelEnd, bSetting); + break; + case XFA_Event::SelectionStart: + InterProperty(pValue, pEventParam->m_iSelStart, bSetting); + break; + case XFA_Event::Shift: + BooleanProperty(pValue, pEventParam->m_bShift, bSetting); + break; + case XFA_Event::SoapFaultCode: + StringProperty(pValue, pEventParam->m_wsSoapFaultCode, bSetting); + break; + case XFA_Event::SoapFaultString: + StringProperty(pValue, pEventParam->m_wsSoapFaultString, bSetting); + break; + case XFA_Event::Target: + break; + default: + break; + } +} +void CScript_EventPseudoModel::Change(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) { + Property(pValue, XFA_Event::Change, bSetting); +} +void CScript_EventPseudoModel::CommitKey(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) { + Property(pValue, XFA_Event::CommitKey, bSetting); +} +void CScript_EventPseudoModel::FullText(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) { + Property(pValue, XFA_Event::FullText, bSetting); +} +void CScript_EventPseudoModel::KeyDown(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) { + Property(pValue, XFA_Event::Keydown, bSetting); +} +void CScript_EventPseudoModel::Modifier(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) { + Property(pValue, XFA_Event::Modifier, bSetting); +} +void CScript_EventPseudoModel::NewContentType(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) { + Property(pValue, XFA_Event::NewContentType, bSetting); +} +void CScript_EventPseudoModel::NewText(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) { + Property(pValue, XFA_Event::NewText, bSetting); +} +void CScript_EventPseudoModel::PrevContentType(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) { + Property(pValue, XFA_Event::PreviousContentType, bSetting); +} +void CScript_EventPseudoModel::PrevText(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) { + Property(pValue, XFA_Event::PreviousText, bSetting); +} +void CScript_EventPseudoModel::Reenter(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) { + Property(pValue, XFA_Event::Reenter, bSetting); +} +void CScript_EventPseudoModel::SelEnd(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) { + Property(pValue, XFA_Event::SelectionEnd, bSetting); +} +void CScript_EventPseudoModel::SelStart(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) { + Property(pValue, XFA_Event::SelectionStart, bSetting); +} +void CScript_EventPseudoModel::Shift(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) { + Property(pValue, XFA_Event::Shift, bSetting); +} +void CScript_EventPseudoModel::SoapFaultCode(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) { + Property(pValue, XFA_Event::SoapFaultCode, bSetting); +} +void CScript_EventPseudoModel::SoapFaultString(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) { + Property(pValue, XFA_Event::SoapFaultString, bSetting); +} +void CScript_EventPseudoModel::Target(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) { + Property(pValue, XFA_Event::Target, bSetting); +} +void CScript_EventPseudoModel::Emit(CFXJSE_Arguments* pArguments) { + CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); + if (!pScriptContext) { + return; + } + CXFA_EventParam* pEventParam = pScriptContext->GetEventParam(); + if (!pEventParam) { + return; + } + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + CXFA_FFWidgetHandler* pWidgetHandler = pNotify->GetWidgetHandler(); + if (!pWidgetHandler) { + return; + } + pWidgetHandler->ProcessEvent(pEventParam->m_pTarget, pEventParam); +} +void CScript_EventPseudoModel::Reset(CFXJSE_Arguments* pArguments) { + CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); + if (!pScriptContext) { + return; + } + CXFA_EventParam* pEventParam = pScriptContext->GetEventParam(); + if (!pEventParam) { + return; + } + pEventParam->Reset(); +} diff --git a/xfa/fxfa/parser/cscript_eventpseudomodel.h b/xfa/fxfa/parser/cscript_eventpseudomodel.h new file mode 100644 index 0000000000..41307d4d39 --- /dev/null +++ b/xfa/fxfa/parser/cscript_eventpseudomodel.h @@ -0,0 +1,86 @@ +// 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 + +#ifndef XFA_FXFA_PARSER_CSCRIPT_EVENTPSEUDOMODEL_H_ +#define XFA_FXFA_PARSER_CSCRIPT_EVENTPSEUDOMODEL_H_ + +#include "fxjs/include/cfxjse_arguments.h" +#include "xfa/fxfa/parser/xfa_object.h" + +enum class XFA_Event { + Change = 0, + CommitKey, + FullText, + Keydown, + Modifier, + NewContentType, + NewText, + PreviousContentType, + PreviousText, + Reenter, + SelectionEnd, + SelectionStart, + Shift, + SoapFaultCode, + SoapFaultString, + Target, + CancelAction +}; + +class CScript_EventPseudoModel : public CXFA_Object { + public: + explicit CScript_EventPseudoModel(CXFA_Document* pDocument); + ~CScript_EventPseudoModel() override; + + void Change(CFXJSE_Value* pValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute); + void CommitKey(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute); + void FullText(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute); + void KeyDown(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute); + void Modifier(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute); + void NewContentType(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute); + void NewText(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute); + void PrevContentType(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute); + void PrevText(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute); + void Reenter(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute); + void SelEnd(CFXJSE_Value* pValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute); + void SelStart(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute); + void Shift(CFXJSE_Value* pValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute); + void SoapFaultCode(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute); + void SoapFaultString(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute); + void Target(CFXJSE_Value* pValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute); + + void Emit(CFXJSE_Arguments* pArguments); + void Reset(CFXJSE_Arguments* pArguments); + + protected: + void Property(CFXJSE_Value* pValue, XFA_Event dwFlag, FX_BOOL bSetting); +}; + +#endif // XFA_FXFA_PARSER_CSCRIPT_EVENTPSEUDOMODEL_H_ diff --git a/xfa/fxfa/parser/cscript_hostpseudomodel.cpp b/xfa/fxfa/parser/cscript_hostpseudomodel.cpp new file mode 100644 index 0000000000..365d268b0e --- /dev/null +++ b/xfa/fxfa/parser/cscript_hostpseudomodel.cpp @@ -0,0 +1,717 @@ +// 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/cscript_hostpseudomodel.h" + +#include "fxjs/include/cfxjse_arguments.h" +#include "xfa/fxfa/app/xfa_ffnotify.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_object.h" +#include "xfa/fxfa/parser/xfa_script.h" +#include "xfa/fxfa/parser/xfa_script_imp.h" +#include "xfa/fxfa/parser/xfa_utils.h" + +namespace { + +CXFA_Node* ToNode(CFXJSE_Value* pValue, CFXJSE_Class* pClass) { + return static_cast(pValue->ToHostObject(pClass)); +} + +} // namespace + +CScript_HostPseudoModel::CScript_HostPseudoModel(CXFA_Document* pDocument) + : CXFA_Object(pDocument, + XFA_ObjectType::Object, + XFA_Element::HostPseudoModel, + CFX_WideStringC(L"hostPseudoModel")) {} + +CScript_HostPseudoModel::~CScript_HostPseudoModel() {} + +void CScript_HostPseudoModel::LoadString(CFXJSE_Value* pValue, + CXFA_FFNotify* pNotify, + uint32_t dwFlag) { + CFX_WideString wsValue; + pNotify->GetAppProvider()->LoadString(dwFlag, wsValue); + pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); +} + +void CScript_HostPseudoModel::AppType(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) { + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + if (bSetting) { + ThrowException(XFA_IDS_INVAlID_PROP_SET); + return; + } + CFX_WideString wsAppType; + pNotify->GetAppProvider()->GetAppType(wsAppType); + pValue->SetString(FX_UTF8Encode(wsAppType).AsStringC()); +} + +void CScript_HostPseudoModel::CalculationsEnabled(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) { + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + CXFA_FFDoc* hDoc = pNotify->GetHDOC(); + if (bSetting) { + pNotify->GetDocProvider()->SetCalculationsEnabled(hDoc, + pValue->ToBoolean()); + return; + } + pValue->SetBoolean(pNotify->GetDocProvider()->IsCalculationsEnabled(hDoc)); +} + +void CScript_HostPseudoModel::CurrentPage(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) { + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + CXFA_FFDoc* hDoc = pNotify->GetHDOC(); + if (bSetting) { + pNotify->GetDocProvider()->SetCurrentPage(hDoc, pValue->ToInteger()); + return; + } + pValue->SetInteger(pNotify->GetDocProvider()->GetCurrentPage(hDoc)); +} + +void CScript_HostPseudoModel::Language(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) { + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + if (bSetting) { + ThrowException(XFA_IDS_UNABLE_SET_LANGUAGE); + return; + } + CFX_WideString wsLanguage; + pNotify->GetAppProvider()->GetLanguage(wsLanguage); + pValue->SetString(FX_UTF8Encode(wsLanguage).AsStringC()); +} + +void CScript_HostPseudoModel::NumPages(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) { + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + CXFA_FFDoc* hDoc = pNotify->GetHDOC(); + if (bSetting) { + ThrowException(XFA_IDS_UNABLE_SET_NUMPAGES); + return; + } + pValue->SetInteger(pNotify->GetDocProvider()->CountPages(hDoc)); +} + +void CScript_HostPseudoModel::Platform(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) { + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + if (bSetting) { + ThrowException(XFA_IDS_UNABLE_SET_PLATFORM); + return; + } + CFX_WideString wsPlatform; + pNotify->GetAppProvider()->GetPlatform(wsPlatform); + pValue->SetString(FX_UTF8Encode(wsPlatform).AsStringC()); +} +void CScript_HostPseudoModel::Title(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) { + if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { + return; + } + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + CXFA_FFDoc* hDoc = pNotify->GetHDOC(); + if (bSetting) { + pNotify->GetDocProvider()->SetTitle(hDoc, pValue->ToWideString()); + return; + } + CFX_WideString wsTitle; + pNotify->GetDocProvider()->GetTitle(hDoc, wsTitle); + pValue->SetString(FX_UTF8Encode(wsTitle).AsStringC()); +} + +void CScript_HostPseudoModel::ValidationsEnabled(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) { + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + CXFA_FFDoc* hDoc = pNotify->GetHDOC(); + if (bSetting) { + pNotify->GetDocProvider()->SetValidationsEnabled(hDoc, pValue->ToBoolean()); + return; + } + FX_BOOL bEnabled = pNotify->GetDocProvider()->IsValidationsEnabled(hDoc); + pValue->SetBoolean(bEnabled); +} +void CScript_HostPseudoModel::Variation(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) { + if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { + return; + } + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + if (bSetting) { + ThrowException(XFA_IDS_UNABLE_SET_VARIATION); + return; + } + CFX_WideString wsVariation; + pNotify->GetAppProvider()->GetVariation(wsVariation); + pValue->SetString(FX_UTF8Encode(wsVariation).AsStringC()); +} + +void CScript_HostPseudoModel::Version(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) { + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + if (bSetting) { + ThrowException(XFA_IDS_UNABLE_SET_VERSION); + return; + } + CFX_WideString wsVersion; + pNotify->GetAppProvider()->GetVersion(wsVersion); + pValue->SetString(FX_UTF8Encode(wsVersion).AsStringC()); +} + +void CScript_HostPseudoModel::Name(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) { + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + if (bSetting) { + ThrowException(XFA_IDS_INVAlID_PROP_SET); + return; + } + CFX_WideString wsAppName; + pNotify->GetAppProvider()->GetAppName(wsAppName); + pValue->SetString(FX_UTF8Encode(wsAppName).AsStringC()); +} + +void CScript_HostPseudoModel::GotoURL(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"gotoURL"); + return; + } + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + CXFA_FFDoc* hDoc = pNotify->GetHDOC(); + CFX_WideString wsURL; + if (iLength >= 1) { + CFX_ByteString bsURL = pArguments->GetUTF8String(0); + wsURL = CFX_WideString::FromUTF8(bsURL.AsStringC()); + } + pNotify->GetDocProvider()->GotoURL(hDoc, wsURL); +} +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 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->GetDocProvider()->SetFocusWidget(pNotify->GetHDOC(), hWidget); + pNotify->OpenDropDownList(hWidget); +} +void CScript_HostPseudoModel::Response(CFXJSE_Arguments* pArguments) { + int32_t iLength = pArguments->GetLength(); + if (iLength < 1 || iLength > 4) { + ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"response"); + return; + } + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + CFX_WideString wsQuestion; + CFX_WideString wsTitle; + CFX_WideString wsDefaultAnswer; + FX_BOOL bMark = FALSE; + if (iLength >= 1) { + CFX_ByteString bsQuestion = pArguments->GetUTF8String(0); + wsQuestion = CFX_WideString::FromUTF8(bsQuestion.AsStringC()); + } + if (iLength >= 2) { + CFX_ByteString bsTitle = pArguments->GetUTF8String(1); + wsTitle = CFX_WideString::FromUTF8(bsTitle.AsStringC()); + } + if (iLength >= 3) { + CFX_ByteString bsDefaultAnswer = pArguments->GetUTF8String(2); + wsDefaultAnswer = CFX_WideString::FromUTF8(bsDefaultAnswer.AsStringC()); + } + if (iLength >= 4) { + bMark = pArguments->GetInt32(3) == 0 ? FALSE : TRUE; + } + CFX_WideString wsAnswer = pNotify->GetAppProvider()->Response( + wsQuestion, wsTitle, wsDefaultAnswer, bMark); + CFXJSE_Value* pValue = pArguments->GetReturnValue(); + if (pValue) + pValue->SetString(FX_UTF8Encode(wsAnswer).AsStringC()); +} + +void CScript_HostPseudoModel::DocumentInBatch(CFXJSE_Arguments* pArguments) { + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + int32_t iCur = pNotify->GetAppProvider()->GetCurDocumentInBatch(); + CFXJSE_Value* pValue = pArguments->GetReturnValue(); + if (pValue) + pValue->SetInteger(iCur); +} +static int32_t XFA_FilterName(const CFX_WideStringC& wsExpression, + int32_t nStart, + CFX_WideString& wsFilter) { + ASSERT(nStart > -1); + int32_t iLength = wsExpression.GetLength(); + if (nStart >= iLength) { + return iLength; + } + FX_WCHAR* pBuf = wsFilter.GetBuffer(iLength - nStart); + int32_t nCount = 0; + const FX_WCHAR* pSrc = wsExpression.c_str(); + FX_WCHAR wCur; + while (nStart < iLength) { + wCur = pSrc[nStart++]; + if (wCur == ',') { + break; + } + pBuf[nCount++] = wCur; + } + wsFilter.ReleaseBuffer(nCount); + wsFilter.TrimLeft(); + wsFilter.TrimRight(); + return nStart; +} +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 CScript_HostPseudoModel::Beep(CFXJSE_Arguments* pArguments) { + if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { + return; + } + int32_t iLength = pArguments->GetLength(); + if (iLength < 0 || iLength > 1) { + ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"beep"); + return; + } + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + uint32_t dwType = 4; + if (iLength >= 1) { + dwType = pArguments->GetInt32(0); + } + pNotify->GetAppProvider()->Beep(dwType); +} +void CScript_HostPseudoModel::SetFocus(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"setFocus"); + return; + } + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + CXFA_Node* pNode = nullptr; + if (iLength >= 1) { + std::unique_ptr 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(); + } + } + pNotify->SetFocusWidgetNode(pNode); +} + +void CScript_HostPseudoModel::GetFocus(CFXJSE_Arguments* pArguments) { + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + CXFA_Node* pNode = pNotify->GetFocusWidgetNode(); + if (!pNode) { + return; + } + pArguments->GetReturnValue()->Assign( + m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode)); +} +void CScript_HostPseudoModel::MessageBox(CFXJSE_Arguments* pArguments) { + if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { + return; + } + int32_t iLength = pArguments->GetLength(); + if (iLength < 1 || iLength > 4) { + ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"messageBox"); + return; + } + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + CFX_WideString wsMessage; + CFX_WideString bsTitle; + uint32_t dwMessageType = XFA_MBICON_Error; + uint32_t dwButtonType = XFA_MB_OK; + if (iLength >= 1) { + if (!ValidateArgsForMsg(pArguments, 0, wsMessage)) { + return; + } + } + if (iLength >= 2) { + if (!ValidateArgsForMsg(pArguments, 1, bsTitle)) { + return; + } + } + if (iLength >= 3) { + dwMessageType = pArguments->GetInt32(2); + if (dwMessageType > XFA_MBICON_Status) { + dwMessageType = XFA_MBICON_Error; + } + } + if (iLength >= 4) { + dwButtonType = pArguments->GetInt32(3); + if (dwButtonType > XFA_MB_YesNoCancel) { + dwButtonType = XFA_MB_OK; + } + } + int32_t iValue = pNotify->GetAppProvider()->MsgBox( + wsMessage, bsTitle, dwMessageType, dwButtonType); + CFXJSE_Value* pValue = pArguments->GetReturnValue(); + if (pValue) + pValue->SetInteger(iValue); +} +FX_BOOL CScript_HostPseudoModel::ValidateArgsForMsg( + CFXJSE_Arguments* pArguments, + int32_t iArgIndex, + CFX_WideString& wsValue) { + if (!pArguments || iArgIndex < 0) { + return FALSE; + } + FX_BOOL bIsJsType = FALSE; + if (m_pDocument->GetScriptContext()->GetType() == + XFA_SCRIPTLANGTYPE_Javascript) { + bIsJsType = TRUE; + } + std::unique_ptr pValueArg(pArguments->GetValue(iArgIndex)); + if (!pValueArg->IsString() && bIsJsType) { + ThrowException(XFA_IDS_ARGUMENT_MISMATCH); + return FALSE; + } + if (pValueArg->IsNull()) { + wsValue = FX_WSTRC(L""); + } else { + wsValue = pValueArg->ToWideString(); + } + return TRUE; +} +void CScript_HostPseudoModel::DocumentCountInBatch( + CFXJSE_Arguments* pArguments) { + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + int32_t iValue = pNotify->GetAppProvider()->GetDocumentCountInBatch(); + CFXJSE_Value* pValue = pArguments->GetReturnValue(); + if (pValue) + pValue->SetInteger(iValue); +} +void CScript_HostPseudoModel::Print(CFXJSE_Arguments* pArguments) { + if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { + return; + } + int32_t iLength = pArguments->GetLength(); + if (iLength != 8) { + ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"print"); + return; + } + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + CXFA_FFDoc* hDoc = pNotify->GetHDOC(); + uint32_t dwOptions = 0; + FX_BOOL bShowDialog = TRUE; + if (iLength >= 1) { + bShowDialog = pArguments->GetInt32(0) == 0 ? FALSE : TRUE; + } + if (bShowDialog) { + dwOptions |= XFA_PRINTOPT_ShowDialog; + } + int32_t nStartPage = 0; + if (iLength >= 2) { + nStartPage = pArguments->GetInt32(1); + } + int32_t nEndPage = 0; + if (iLength >= 3) { + nEndPage = pArguments->GetInt32(2); + } + FX_BOOL bCanCancel = TRUE; + if (iLength >= 4) { + bCanCancel = pArguments->GetInt32(3) == 0 ? FALSE : TRUE; + } + if (bCanCancel) { + dwOptions |= XFA_PRINTOPT_CanCancel; + } + FX_BOOL bShrinkPage = TRUE; + if (iLength >= 5) { + bShrinkPage = pArguments->GetInt32(4) == 0 ? FALSE : TRUE; + } + if (bShrinkPage) { + dwOptions |= XFA_PRINTOPT_ShrinkPage; + } + FX_BOOL bAsImage = TRUE; + if (iLength >= 6) { + bAsImage = pArguments->GetInt32(5) == 0 ? FALSE : TRUE; + } + if (bAsImage) { + dwOptions |= XFA_PRINTOPT_AsImage; + } + FX_BOOL bReverseOrder = TRUE; + if (iLength >= 7) { + bAsImage = pArguments->GetInt32(5) == 0 ? FALSE : TRUE; + } + bReverseOrder = pArguments->GetInt32(6) == 0 ? FALSE : TRUE; + if (bReverseOrder) { + dwOptions |= XFA_PRINTOPT_ReverseOrder; + } + FX_BOOL bPrintAnnot = TRUE; + if (iLength >= 8) { + bPrintAnnot = pArguments->GetInt32(7) == 0 ? FALSE : TRUE; + } + if (bPrintAnnot) { + dwOptions |= XFA_PRINTOPT_PrintAnnot; + } + pNotify->GetDocProvider()->Print(hDoc, nStartPage, nEndPage, dwOptions); +} +void CScript_HostPseudoModel::ImportData(CFXJSE_Arguments* pArguments) { + int32_t iLength = pArguments->GetLength(); + if (iLength < 0 || iLength > 1) { + ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"importData"); + return; + } + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + CFX_WideString wsFilePath; + if (iLength > 0) { + CFX_ByteString bsFilePath = pArguments->GetUTF8String(0); + wsFilePath = CFX_WideString::FromUTF8(bsFilePath.AsStringC()); + } + CXFA_FFDoc* hDoc = pNotify->GetHDOC(); + pNotify->GetDocProvider()->ImportData(hDoc, wsFilePath); +} +void CScript_HostPseudoModel::ExportData(CFXJSE_Arguments* pArguments) { + int32_t iLength = pArguments->GetLength(); + if (iLength < 0 || iLength > 2) { + ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"exportData"); + return; + } + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + CXFA_FFDoc* hDoc = pNotify->GetHDOC(); + CFX_WideString wsFilePath; + FX_BOOL bXDP = TRUE; + if (iLength >= 1) { + CFX_ByteString bsFilePath = pArguments->GetUTF8String(0); + wsFilePath = CFX_WideString::FromUTF8(bsFilePath.AsStringC()); + } + if (iLength >= 2) { + bXDP = pArguments->GetInt32(1) == 0 ? FALSE : TRUE; + } + pNotify->GetDocProvider()->ExportData(hDoc, wsFilePath, bXDP); +} + +void CScript_HostPseudoModel::PageUp(CFXJSE_Arguments* pArguments) { + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + CXFA_FFDoc* hDoc = pNotify->GetHDOC(); + int32_t nCurPage = pNotify->GetDocProvider()->GetCurrentPage(hDoc); + int32_t nNewPage = 0; + if (nCurPage <= 1) { + return; + } + nNewPage = nCurPage - 1; + pNotify->GetDocProvider()->SetCurrentPage(hDoc, nNewPage); +} + +void CScript_HostPseudoModel::PageDown(CFXJSE_Arguments* pArguments) { + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + CXFA_FFDoc* hDoc = pNotify->GetHDOC(); + int32_t nCurPage = pNotify->GetDocProvider()->GetCurrentPage(hDoc); + int32_t nPageCount = pNotify->GetDocProvider()->CountPages(hDoc); + if (!nPageCount || nCurPage == nPageCount) { + return; + } + int32_t nNewPage = 0; + if (nCurPage >= nPageCount) { + nNewPage = nPageCount - 1; + } else { + nNewPage = nCurPage + 1; + } + pNotify->GetDocProvider()->SetCurrentPage(hDoc, nNewPage); +} + +void CScript_HostPseudoModel::CurrentDateTime(CFXJSE_Arguments* pArguments) { + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + CFX_WideString wsDataTime = pNotify->GetCurrentDateTime(); + CFXJSE_Value* pValue = pArguments->GetReturnValue(); + if (pValue) + pValue->SetString(FX_UTF8Encode(wsDataTime).AsStringC()); +} diff --git a/xfa/fxfa/parser/cscript_hostpseudomodel.h b/xfa/fxfa/parser/cscript_hostpseudomodel.h new file mode 100644 index 0000000000..f07ba956c5 --- /dev/null +++ b/xfa/fxfa/parser/cscript_hostpseudomodel.h @@ -0,0 +1,74 @@ +// 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 + +#ifndef XFA_FXFA_PARSER_CSCRIPT_HOSTPSEUDOMODEL_H_ +#define XFA_FXFA_PARSER_CSCRIPT_HOSTPSEUDOMODEL_H_ + +#include "fxjs/include/cfxjse_arguments.h" +#include "xfa/fxfa/parser/xfa_document.h" +#include "xfa/fxfa/parser/xfa_object.h" + +class CScript_HostPseudoModel : public CXFA_Object { + public: + explicit CScript_HostPseudoModel(CXFA_Document* pDocument); + ~CScript_HostPseudoModel() override; + + void AppType(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute); + void CalculationsEnabled(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute); + void CurrentPage(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute); + void Language(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute); + void NumPages(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute); + void Platform(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute); + void Title(CFXJSE_Value* pValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute); + void ValidationsEnabled(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute); + void Variation(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute); + void Version(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute); + void Name(CFXJSE_Value* pValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute); + void GotoURL(CFXJSE_Arguments* pArguments); + void OpenList(CFXJSE_Arguments* pArguments); + void Response(CFXJSE_Arguments* pArguments); + void DocumentInBatch(CFXJSE_Arguments* pArguments); + void ResetData(CFXJSE_Arguments* pArguments); + void Beep(CFXJSE_Arguments* pArguments); + void SetFocus(CFXJSE_Arguments* pArguments); + void GetFocus(CFXJSE_Arguments* pArguments); + void MessageBox(CFXJSE_Arguments* pArguments); + void DocumentCountInBatch(CFXJSE_Arguments* pArguments); + void Print(CFXJSE_Arguments* pArguments); + void ImportData(CFXJSE_Arguments* pArguments); + void ExportData(CFXJSE_Arguments* pArguments); + void PageUp(CFXJSE_Arguments* pArguments); + void PageDown(CFXJSE_Arguments* pArguments); + void CurrentDateTime(CFXJSE_Arguments* pArguments); + + protected: + void LoadString(CFXJSE_Value* pValue, + CXFA_FFNotify* pNotify, + uint32_t dwFlag); + FX_BOOL ValidateArgsForMsg(CFXJSE_Arguments* pArguments, + int32_t iArgIndex, + CFX_WideString& wsValue); +}; + +#endif // XFA_FXFA_PARSER_CSCRIPT_HOSTPSEUDOMODEL_H_ diff --git a/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp b/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp new file mode 100644 index 0000000000..d50f1b77d6 --- /dev/null +++ b/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp @@ -0,0 +1,514 @@ +// 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/cscript_layoutpseudomodel.h" + +#include + +#include "fxjs/include/cfxjse_arguments.h" +#include "third_party/base/stl_util.h" +#include "xfa/fxfa/app/xfa_ffnotify.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_layout_appadapter.h" +#include "xfa/fxfa/parser/xfa_localemgr.h" +#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/xfa_script.h" +#include "xfa/fxfa/parser/xfa_script_imp.h" +#include "xfa/fxfa/parser/xfa_utils.h" + +CScript_LayoutPseudoModel::CScript_LayoutPseudoModel(CXFA_Document* pDocument) + : CXFA_Object(pDocument, + XFA_ObjectType::Object, + XFA_Element::LayoutPseudoModel, + CFX_WideStringC(L"layoutPseudoModel")) {} + +CScript_LayoutPseudoModel::~CScript_LayoutPseudoModel() {} + +void CScript_LayoutPseudoModel::Ready(CFXJSE_Value* pValue, + FX_BOOL bSetting, + XFA_ATTRIBUTE eAttribute) { + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + if (bSetting) { + ThrowException(XFA_IDS_UNABLE_SET_READY); + return; + } + int32_t iStatus = pNotify->GetLayoutStatus(); + pValue->SetBoolean(iStatus >= 2); +} +void CScript_LayoutPseudoModel::HWXY(CFXJSE_Arguments* pArguments, + XFA_LAYOUTMODEL_HWXY layoutModel) { + int32_t iLength = pArguments->GetLength(); + if (iLength < 1 || iLength > 3) { + const FX_WCHAR* methodName = nullptr; + 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; + } + ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, methodName); + return; + } + CXFA_Node* pNode = nullptr; + CFX_WideString wsUnit(L"pt"); + int32_t iIndex = 0; + if (iLength >= 1) { + pNode = static_cast(pArguments->GetObject(0)); + } + if (iLength >= 2) { + CFX_ByteString bsUnit = pArguments->GetUTF8String(1); + if (!bsUnit.IsEmpty()) { + wsUnit = CFX_WideString::FromUTF8(bsUnit.AsStringC()); + } + } + if (iLength >= 3) { + iIndex = pArguments->GetInt32(2); + } + if (!pNode) { + return; + } + CXFA_LayoutProcessor* 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--; + } + CFXJSE_Value* pValue = pArguments->GetReturnValue(); + if (!pLayoutItem) { + pValue->SetFloat(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.AsStringC()); + FX_FLOAT fValue = measure.ToUnit(unit); + fValue = FXSYS_round(fValue * 1000) / 1000.0f; + if (pValue) + pValue->SetFloat(fValue); +} +void CScript_LayoutPseudoModel::H(CFXJSE_Arguments* pArguments) { + HWXY(pArguments, XFA_LAYOUTMODEL_H); +} +void CScript_LayoutPseudoModel::W(CFXJSE_Arguments* pArguments) { + HWXY(pArguments, XFA_LAYOUTMODEL_W); +} +void CScript_LayoutPseudoModel::X(CFXJSE_Arguments* pArguments) { + HWXY(pArguments, XFA_LAYOUTMODEL_X); +} +void CScript_LayoutPseudoModel::Y(CFXJSE_Arguments* pArguments) { + HWXY(pArguments, XFA_LAYOUTMODEL_Y); +} +void CScript_LayoutPseudoModel::NumberedPageCount(CFXJSE_Arguments* pArguments, + FX_BOOL bNumbered) { + CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout(); + if (!pDocLayout) { + return; + } + int32_t iPageCount = 0; + int32_t iPageNum = pDocLayout->CountPages(); + if (bNumbered) { + for (int32_t i = 0; i < iPageNum; i++) { + CXFA_ContainerLayoutItem* pLayoutPage = pDocLayout->GetPage(i); + if (!pLayoutPage) { + continue; + } + CXFA_Node* pMasterPage = pLayoutPage->GetMasterPage(); + if (pMasterPage->GetInteger(XFA_ATTRIBUTE_Numbered)) { + iPageCount++; + } + } + } else { + iPageCount = iPageNum; + } + CFXJSE_Value* pValue = pArguments->GetReturnValue(); + if (pValue) + pValue->SetInteger(iPageCount); +} +void CScript_LayoutPseudoModel::PageCount(CFXJSE_Arguments* pArguments) { + NumberedPageCount(pArguments, TRUE); +} +void CScript_LayoutPseudoModel::PageSpan(CFXJSE_Arguments* pArguments) { + int32_t iLength = pArguments->GetLength(); + if (iLength != 1) { + ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"pageSpan"); + return; + } + CXFA_Node* pNode = nullptr; + if (iLength >= 1) { + pNode = static_cast(pArguments->GetObject(0)); + } + if (!pNode) { + return; + } + CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout(); + if (!pDocLayout) { + return; + } + CFXJSE_Value* pValue = pArguments->GetReturnValue(); + CXFA_LayoutItem* pLayoutItem = pDocLayout->GetLayoutItem(pNode); + if (!pLayoutItem) { + pValue->SetInteger(-1); + return; + } + int32_t iLast = pLayoutItem->GetLast()->GetPage()->GetPageIndex(); + int32_t iFirst = pLayoutItem->GetFirst()->GetPage()->GetPageIndex(); + int32_t iPageSpan = iLast - iFirst + 1; + if (pValue) + pValue->SetInteger(iPageSpan); +} +void CScript_LayoutPseudoModel::Page(CFXJSE_Arguments* pArguments) { + PageImp(pArguments, FALSE); +} +void CScript_LayoutPseudoModel::GetObjArray(CXFA_LayoutProcessor* pDocLayout, + int32_t iPageNo, + const CFX_WideString& wsType, + FX_BOOL bOnPageArea, + CXFA_NodeArray& retArray) { + CXFA_ContainerLayoutItem* pLayoutPage = pDocLayout->GetPage(iPageNo); + if (!pLayoutPage) { + return; + } + if (wsType == FX_WSTRC(L"pageArea")) { + if (CXFA_Node* pMasterPage = pLayoutPage->m_pFormNode) { + retArray.Add(pMasterPage); + } + return; + } + if (wsType == FX_WSTRC(L"contentArea")) { + for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem; + pItem = pItem->m_pNextSibling) { + if (pItem->m_pFormNode->GetElementType() == XFA_Element::ContentArea) { + retArray.Add(pItem->m_pFormNode); + } + } + return; + } + std::set formItems; + if (wsType.IsEmpty()) { + if (CXFA_Node* pMasterPage = pLayoutPage->m_pFormNode) { + retArray.Add(pMasterPage); + } + for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem; + pItem = pItem->m_pNextSibling) { + if (pItem->m_pFormNode->GetElementType() == XFA_Element::ContentArea) { + retArray.Add(pItem->m_pFormNode); + if (!bOnPageArea) { + CXFA_NodeIteratorTemplate + iterator(static_cast(pItem->m_pFirstChild)); + for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); + pItemChild; pItemChild = iterator.MoveToNext()) { + if (!pItemChild->IsContentLayoutItem()) { + continue; + } + XFA_Element eType = pItemChild->m_pFormNode->GetElementType(); + if (eType != XFA_Element::Field && eType != XFA_Element::Draw && + eType != XFA_Element::Subform && eType != XFA_Element::Area) { + continue; + } + if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode)) + continue; + + formItems.insert(pItemChild->m_pFormNode); + retArray.Add(pItemChild->m_pFormNode); + } + } + } else { + if (bOnPageArea) { + CXFA_NodeIteratorTemplate + iterator(static_cast(pItem)); + for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); + pItemChild; pItemChild = iterator.MoveToNext()) { + if (!pItemChild->IsContentLayoutItem()) { + continue; + } + XFA_Element eType = pItemChild->m_pFormNode->GetElementType(); + if (eType != XFA_Element::Field && eType != XFA_Element::Draw && + eType != XFA_Element::Subform && eType != XFA_Element::Area) { + continue; + } + if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode)) + continue; + formItems.insert(pItemChild->m_pFormNode); + retArray.Add(pItemChild->m_pFormNode); + } + } + } + } + return; + } + XFA_Element eType = XFA_Element::Unknown; + if (wsType == FX_WSTRC(L"field")) { + eType = XFA_Element::Field; + } else if (wsType == FX_WSTRC(L"draw")) { + eType = XFA_Element::Draw; + } else if (wsType == FX_WSTRC(L"subform")) { + eType = XFA_Element::Subform; + } else if (wsType == FX_WSTRC(L"area")) { + eType = XFA_Element::Area; + } + if (eType != XFA_Element::Unknown) { + for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem; + pItem = pItem->m_pNextSibling) { + if (pItem->m_pFormNode->GetElementType() == XFA_Element::ContentArea) { + if (!bOnPageArea) { + CXFA_NodeIteratorTemplate + iterator(static_cast(pItem->m_pFirstChild)); + for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); + pItemChild; pItemChild = iterator.MoveToNext()) { + if (!pItemChild->IsContentLayoutItem()) + continue; + if (pItemChild->m_pFormNode->GetElementType() != eType) + continue; + if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode)) + continue; + formItems.insert(pItemChild->m_pFormNode); + retArray.Add(pItemChild->m_pFormNode); + } + } + } else { + if (bOnPageArea) { + CXFA_NodeIteratorTemplate + iterator(static_cast(pItem)); + for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); + pItemChild; pItemChild = iterator.MoveToNext()) { + if (!pItemChild->IsContentLayoutItem()) + continue; + if (pItemChild->m_pFormNode->GetElementType() != eType) + continue; + if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode)) + continue; + formItems.insert(pItemChild->m_pFormNode); + retArray.Add(pItemChild->m_pFormNode); + } + } + } + } + return; + } +} +void CScript_LayoutPseudoModel::PageContent(CFXJSE_Arguments* pArguments) { + int32_t iLength = pArguments->GetLength(); + if (iLength < 1 || iLength > 3) { + ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"pageContent"); + return; + } + int32_t iIndex = 0; + CFX_WideString wsType; + FX_BOOL bOnPageArea = FALSE; + if (iLength >= 1) { + iIndex = pArguments->GetInt32(0); + } + if (iLength >= 2) { + CFX_ByteString bsType = pArguments->GetUTF8String(1); + wsType = CFX_WideString::FromUTF8(bsType.AsStringC()); + } + if (iLength >= 3) { + bOnPageArea = pArguments->GetInt32(2) == 0 ? FALSE : TRUE; + } + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout(); + if (!pDocLayout) { + return; + } + CXFA_NodeArray retArray; + GetObjArray(pDocLayout, iIndex, wsType, bOnPageArea, retArray); + CXFA_ArrayNodeList* pArrayNodeList = new CXFA_ArrayNodeList(m_pDocument); + pArrayNodeList->SetArrayNodeList(retArray); + pArguments->GetReturnValue()->SetObject( + pArrayNodeList, m_pDocument->GetScriptContext()->GetJseNormalClass()); +} +void CScript_LayoutPseudoModel::AbsPageCount(CFXJSE_Arguments* pArguments) { + NumberedPageCount(pArguments, FALSE); +} +void CScript_LayoutPseudoModel::AbsPageCountInBatch( + CFXJSE_Arguments* pArguments) { + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + CXFA_FFDoc* hDoc = pNotify->GetHDOC(); + int32_t iPageCount = pNotify->GetDocProvider()->AbsPageCountInBatch(hDoc); + CFXJSE_Value* pValue = pArguments->GetReturnValue(); + if (pValue) + pValue->SetInteger(iPageCount); +} +void CScript_LayoutPseudoModel::SheetCountInBatch( + CFXJSE_Arguments* pArguments) { + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + CXFA_FFDoc* hDoc = pNotify->GetHDOC(); + int32_t iPageCount = pNotify->GetDocProvider()->SheetCountInBatch(hDoc); + CFXJSE_Value* pValue = pArguments->GetReturnValue(); + if (pValue) + pValue->SetInteger(iPageCount); +} +void CScript_LayoutPseudoModel::Relayout(CFXJSE_Arguments* pArguments) { + CXFA_Node* pRootNode = m_pDocument->GetRoot(); + CXFA_Node* pFormRoot = pRootNode->GetFirstChildByClass(XFA_Element::Form); + ASSERT(pFormRoot); + CXFA_Node* pContentRootNode = pFormRoot->GetNodeItem(XFA_NODEITEM_FirstChild); + CXFA_LayoutProcessor* pLayoutProcessor = m_pDocument->GetLayoutProcessor(); + if (pContentRootNode) { + pLayoutProcessor->AddChangedContainer(pContentRootNode); + } + pLayoutProcessor->SetForceReLayout(TRUE); +} +void CScript_LayoutPseudoModel::AbsPageSpan(CFXJSE_Arguments* pArguments) { + PageSpan(pArguments); +} +void CScript_LayoutPseudoModel::AbsPageInBatch(CFXJSE_Arguments* pArguments) { + int32_t iLength = pArguments->GetLength(); + if (iLength != 1) { + ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"absPageInBatch"); + return; + } + CXFA_Node* pNode = nullptr; + if (iLength >= 1) { + pNode = static_cast(pArguments->GetObject(0)); + } + if (!pNode) { + return; + } + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout(); + if (!pDocLayout) { + return; + } + CXFA_FFWidget* hWidget = + pNotify->GetHWidget(pDocLayout->GetLayoutItem(pNode)); + if (!hWidget) { + return; + } + CXFA_FFDoc* hDoc = pNotify->GetHDOC(); + int32_t iPageCount = pNotify->GetDocProvider()->AbsPageInBatch(hDoc, hWidget); + CFXJSE_Value* pValue = pArguments->GetReturnValue(); + if (pValue) + pValue->SetInteger(iPageCount); +} +void CScript_LayoutPseudoModel::SheetInBatch(CFXJSE_Arguments* pArguments) { + int32_t iLength = pArguments->GetLength(); + if (iLength != 1) { + ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"sheetInBatch"); + return; + } + CXFA_Node* pNode = nullptr; + if (iLength >= 1) { + pNode = static_cast(pArguments->GetObject(0)); + } + if (!pNode) { + return; + } + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout(); + if (!pDocLayout) { + return; + } + CXFA_FFWidget* hWidget = + pNotify->GetHWidget(pDocLayout->GetLayoutItem(pNode)); + if (!hWidget) { + return; + } + CXFA_FFDoc* hDoc = pNotify->GetHDOC(); + int32_t iPageCount = pNotify->GetDocProvider()->SheetInBatch(hDoc, hWidget); + CFXJSE_Value* pValue = pArguments->GetReturnValue(); + if (pValue) + pValue->SetInteger(iPageCount); +} +void CScript_LayoutPseudoModel::Sheet(CFXJSE_Arguments* pArguments) { + PageImp(pArguments, TRUE); +} +void CScript_LayoutPseudoModel::RelayoutPageArea(CFXJSE_Arguments* pArguments) { +} +void CScript_LayoutPseudoModel::SheetCount(CFXJSE_Arguments* pArguments) { + NumberedPageCount(pArguments, FALSE); +} +void CScript_LayoutPseudoModel::AbsPage(CFXJSE_Arguments* pArguments) { + PageImp(pArguments, TRUE); +} +void CScript_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"; + } + ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, methodName); + return; + } + CXFA_Node* pNode = nullptr; + if (iLength >= 1) { + pNode = static_cast(pArguments->GetObject(0)); + } + int32_t iPage = 0; + CFXJSE_Value* pValue = pArguments->GetReturnValue(); + if (!pNode && pValue) + pValue->SetInteger(iPage); + + CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout(); + if (!pDocLayout) { + return; + } + CXFA_LayoutItem* pLayoutItem = pDocLayout->GetLayoutItem(pNode); + if (!pLayoutItem) { + pValue->SetInteger(-1); + return; + } + iPage = pLayoutItem->GetFirst()->GetPage()->GetPageIndex(); + if (pValue) + pValue->SetInteger(bAbsPage ? iPage : iPage + 1); +} diff --git a/xfa/fxfa/parser/cscript_layoutpseudomodel.h b/xfa/fxfa/parser/cscript_layoutpseudomodel.h new file mode 100644 index 0000000000..f812c3d330 --- /dev/null +++ b/xfa/fxfa/parser/cscript_layoutpseudomodel.h @@ -0,0 +1,59 @@ +// 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 + +#ifndef XFA_FXFA_PARSER_CSCRIPT_LAYOUTPSEUDOMODEL_H_ +#define XFA_FXFA_PARSER_CSCRIPT_LAYOUTPSEUDOMODEL_H_ + +#include "fxjs/include/cfxjse_arguments.h" +#include "xfa/fxfa/parser/xfa_doclayout.h" +#include "xfa/fxfa/parser/xfa_object.h" + +enum XFA_LAYOUTMODEL_HWXY { + XFA_LAYOUTMODEL_H, + XFA_LAYOUTMODEL_W, + XFA_LAYOUTMODEL_X, + XFA_LAYOUTMODEL_Y +}; + +class CScript_LayoutPseudoModel : public CXFA_Object { + public: + explicit CScript_LayoutPseudoModel(CXFA_Document* pDocument); + ~CScript_LayoutPseudoModel() override; + + void Ready(CFXJSE_Value* pValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute); + + void HWXY(CFXJSE_Arguments* pArguments, XFA_LAYOUTMODEL_HWXY layoutModel); + void H(CFXJSE_Arguments* pArguments); + void W(CFXJSE_Arguments* pArguments); + void X(CFXJSE_Arguments* pArguments); + void Y(CFXJSE_Arguments* pArguments); + void NumberedPageCount(CFXJSE_Arguments* pArguments, FX_BOOL bNumbered); + void PageCount(CFXJSE_Arguments* pArguments); + void PageSpan(CFXJSE_Arguments* pArguments); + void Page(CFXJSE_Arguments* pArguments); + void PageContent(CFXJSE_Arguments* pArguments); + void AbsPageCount(CFXJSE_Arguments* pArguments); + void AbsPageCountInBatch(CFXJSE_Arguments* pArguments); + void SheetCountInBatch(CFXJSE_Arguments* pArguments); + void Relayout(CFXJSE_Arguments* pArguments); + void AbsPageSpan(CFXJSE_Arguments* pArguments); + void AbsPageInBatch(CFXJSE_Arguments* pArguments); + void SheetInBatch(CFXJSE_Arguments* pArguments); + void Sheet(CFXJSE_Arguments* pArguments); + void RelayoutPageArea(CFXJSE_Arguments* pArguments); + void SheetCount(CFXJSE_Arguments* pArguments); + void AbsPage(CFXJSE_Arguments* pArguments); + + protected: + void GetObjArray(CXFA_LayoutProcessor* pDocLayout, + int32_t iPageNo, + const CFX_WideString& wsType, + FX_BOOL bOnPageArea, + CXFA_NodeArray& retArray); + void PageImp(CFXJSE_Arguments* pArguments, FX_BOOL bAbsPage); +}; + +#endif // XFA_FXFA_PARSER_CSCRIPT_LAYOUTPSEUDOMODEL_H_ diff --git a/xfa/fxfa/parser/cscript_logpseudomodel.cpp b/xfa/fxfa/parser/cscript_logpseudomodel.cpp new file mode 100644 index 0000000000..ae3629d5a5 --- /dev/null +++ b/xfa/fxfa/parser/cscript_logpseudomodel.cpp @@ -0,0 +1,33 @@ +// 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/cscript_logpseudomodel.h" + +#include "fxjs/include/cfxjse_arguments.h" +#include "xfa/fxfa/parser/xfa_doclayout.h" +#include "xfa/fxfa/parser/xfa_document.h" +#include "xfa/fxfa/parser/xfa_localemgr.h" +#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/xfa_script.h" +#include "xfa/fxfa/parser/xfa_utils.h" + +CScript_LogPseudoModel::CScript_LogPseudoModel(CXFA_Document* pDocument) + : CXFA_Object(pDocument, + XFA_ObjectType::Object, + XFA_Element::LogPseudoModel, + CFX_WideStringC(L"logPseudoModel")) {} + +CScript_LogPseudoModel::~CScript_LogPseudoModel() {} + +void CScript_LogPseudoModel::Message(CFXJSE_Arguments* pArguments) {} + +void CScript_LogPseudoModel::TraceEnabled(CFXJSE_Arguments* pArguments) {} + +void CScript_LogPseudoModel::TraceActivate(CFXJSE_Arguments* pArguments) {} + +void CScript_LogPseudoModel::TraceDeactivate(CFXJSE_Arguments* pArguments) {} + +void CScript_LogPseudoModel::Trace(CFXJSE_Arguments* pArguments) {} diff --git a/xfa/fxfa/parser/cscript_logpseudomodel.h b/xfa/fxfa/parser/cscript_logpseudomodel.h new file mode 100644 index 0000000000..1da076ef3d --- /dev/null +++ b/xfa/fxfa/parser/cscript_logpseudomodel.h @@ -0,0 +1,25 @@ +// 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 + +#ifndef XFA_FXFA_PARSER_CSCRIPT_LOGPSEUDOMODEL_H_ +#define XFA_FXFA_PARSER_CSCRIPT_LOGPSEUDOMODEL_H_ + +#include "fxjs/include/cfxjse_arguments.h" +#include "xfa/fxfa/parser/xfa_object.h" + +class CScript_LogPseudoModel : public CXFA_Object { + public: + explicit CScript_LogPseudoModel(CXFA_Document* pDocument); + ~CScript_LogPseudoModel() override; + + void Message(CFXJSE_Arguments* pArguments); + void TraceEnabled(CFXJSE_Arguments* pArguments); + void TraceActivate(CFXJSE_Arguments* pArguments); + void TraceDeactivate(CFXJSE_Arguments* pArguments); + void Trace(CFXJSE_Arguments* pArguments); +}; + +#endif // XFA_FXFA_PARSER_CSCRIPT_LOGPSEUDOMODEL_H_ diff --git a/xfa/fxfa/parser/cscript_signaturepseudomodel.cpp b/xfa/fxfa/parser/cscript_signaturepseudomodel.cpp new file mode 100644 index 0000000000..ed5891eb3a --- /dev/null +++ b/xfa/fxfa/parser/cscript_signaturepseudomodel.cpp @@ -0,0 +1,122 @@ +// 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/cscript_signaturepseudomodel.h" + +#include "fxjs/include/cfxjse_arguments.h" +#include "xfa/fxfa/app/xfa_ffnotify.h" +#include "xfa/fxfa/parser/xfa_doclayout.h" +#include "xfa/fxfa/parser/xfa_document.h" +#include "xfa/fxfa/parser/xfa_localemgr.h" +#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/xfa_script.h" +#include "xfa/fxfa/parser/xfa_script_imp.h" +#include "xfa/fxfa/parser/xfa_utils.h" + +CScript_SignaturePseudoModel::CScript_SignaturePseudoModel( + CXFA_Document* pDocument) + : CXFA_Object(pDocument, + XFA_ObjectType::Object, + XFA_Element::SignaturePseudoModel, + CFX_WideStringC(L"signaturePseudoModel")) {} + +CScript_SignaturePseudoModel::~CScript_SignaturePseudoModel() {} + +void CScript_SignaturePseudoModel::Verify(CFXJSE_Arguments* pArguments) { + int32_t iLength = pArguments->GetLength(); + if (iLength < 1 || iLength > 4) { + ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"verify"); + return; + } + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + CXFA_FFDoc* hDoc = pNotify->GetHDOC(); + CXFA_Node* pNode = nullptr; + if (iLength >= 1) { + pNode = static_cast(pArguments->GetObject(0)); + } + int32_t bVerify = pNotify->GetDocProvider()->Verify(hDoc, pNode); + CFXJSE_Value* pValue = pArguments->GetReturnValue(); + if (pValue) + pValue->SetInteger(bVerify); +} + +void CScript_SignaturePseudoModel::Sign(CFXJSE_Arguments* pArguments) { + int32_t iLength = pArguments->GetLength(); + if (iLength < 3 || iLength > 7) { + ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"sign"); + return; + } + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + CXFA_FFDoc* hDoc = pNotify->GetHDOC(); + CXFA_NodeList* pNodeList = nullptr; + CFX_WideString wsExpression; + CFX_WideString wsXMLIdent; + if (iLength >= 1) { + pNodeList = (CXFA_NodeList*)pArguments->GetObject(0); + } + if (iLength >= 2) { + CFX_ByteString bsExpression = pArguments->GetUTF8String(1); + wsExpression = CFX_WideString::FromUTF8(bsExpression.AsStringC()); + } + if (iLength >= 3) { + CFX_ByteString bsXMLIdent = pArguments->GetUTF8String(2); + wsXMLIdent = CFX_WideString::FromUTF8(bsXMLIdent.AsStringC()); + } + FX_BOOL bSign = pNotify->GetDocProvider()->Sign( + hDoc, pNodeList, wsExpression.AsStringC(), wsXMLIdent.AsStringC()); + CFXJSE_Value* pValue = pArguments->GetReturnValue(); + if (pValue) + pValue->SetBoolean(bSign); +} + +void CScript_SignaturePseudoModel::Enumerate(CFXJSE_Arguments* pArguments) { + int32_t iLength = pArguments->GetLength(); + if (iLength != 0) { + ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"enumerate"); + return; + } + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + CXFA_FFDoc* hDoc = pNotify->GetHDOC(); + CXFA_NodeList* pList = pNotify->GetDocProvider()->Enumerate(hDoc); + if (!pList) + return; + pArguments->GetReturnValue()->Assign( + m_pDocument->GetScriptContext()->GetJSValueFromMap(pList)); +} + +void CScript_SignaturePseudoModel::Clear(CFXJSE_Arguments* pArguments) { + int32_t iLength = pArguments->GetLength(); + if (iLength < 1 || iLength > 2) { + ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"clear"); + return; + } + CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); + if (!pNotify) { + return; + } + CXFA_FFDoc* hDoc = pNotify->GetHDOC(); + CXFA_Node* pNode = nullptr; + FX_BOOL bClear = TRUE; + if (iLength >= 1) { + pNode = static_cast(pArguments->GetObject(0)); + } + if (iLength >= 2) { + bClear = pArguments->GetInt32(1) == 0 ? FALSE : TRUE; + } + FX_BOOL bFlag = pNotify->GetDocProvider()->Clear(hDoc, pNode, bClear); + CFXJSE_Value* pValue = pArguments->GetReturnValue(); + if (pValue) + pValue->SetBoolean(bFlag); +} diff --git a/xfa/fxfa/parser/cscript_signaturepseudomodel.h b/xfa/fxfa/parser/cscript_signaturepseudomodel.h new file mode 100644 index 0000000000..f8478c2a0f --- /dev/null +++ b/xfa/fxfa/parser/cscript_signaturepseudomodel.h @@ -0,0 +1,24 @@ +// 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 + +#ifndef XFA_FXFA_PARSER_CSCRIPT_SIGNATUREPSEUDOMODEL_H_ +#define XFA_FXFA_PARSER_CSCRIPT_SIGNATUREPSEUDOMODEL_H_ + +#include "fxjs/include/cfxjse_arguments.h" +#include "xfa/fxfa/parser/xfa_object.h" + +class CScript_SignaturePseudoModel : public CXFA_Object { + public: + explicit CScript_SignaturePseudoModel(CXFA_Document* pDocument); + ~CScript_SignaturePseudoModel() override; + + void Verify(CFXJSE_Arguments* pArguments); + void Sign(CFXJSE_Arguments* pArguments); + void Enumerate(CFXJSE_Arguments* pArguments); + void Clear(CFXJSE_Arguments* pArguments); +}; + +#endif // XFA_FXFA_PARSER_CSCRIPT_SIGNATUREPSEUDOMODEL_H_ diff --git a/xfa/fxfa/parser/xfa_basic_data_element_script.cpp b/xfa/fxfa/parser/xfa_basic_data_element_script.cpp index ee4d578b6e..7ea1679dcb 100644 --- a/xfa/fxfa/parser/xfa_basic_data_element_script.cpp +++ b/xfa/fxfa/parser/xfa_basic_data_element_script.cpp @@ -7,13 +7,13 @@ #include "xfa/fxfa/parser/xfa_basic_data.h" #include "xfa/fxfa/include/fxfa_basic.h" +#include "xfa/fxfa/parser/cscript_datawindow.h" +#include "xfa/fxfa/parser/cscript_eventpseudomodel.h" +#include "xfa/fxfa/parser/cscript_hostpseudomodel.h" +#include "xfa/fxfa/parser/cscript_layoutpseudomodel.h" +#include "xfa/fxfa/parser/cscript_logpseudomodel.h" +#include "xfa/fxfa/parser/cscript_signaturepseudomodel.h" #include "xfa/fxfa/parser/xfa_script.h" -#include "xfa/fxfa/parser/xfa_script_datawindow.h" -#include "xfa/fxfa/parser/xfa_script_eventpseudomodel.h" -#include "xfa/fxfa/parser/xfa_script_hostpseudomodel.h" -#include "xfa/fxfa/parser/xfa_script_layoutpseudomodel.h" -#include "xfa/fxfa/parser/xfa_script_logpseudomodel.h" -#include "xfa/fxfa/parser/xfa_script_signaturepseudomodel.h" const XFA_SCRIPTHIERARCHY g_XFAScriptIndex[] = { {0, 0, 0, 2, 316}, {0, 0, 2, 2, 316}, {0, 0, 4, 2, 316}, diff --git a/xfa/fxfa/parser/xfa_document_imp.cpp b/xfa/fxfa/parser/xfa_document_imp.cpp index 382fd7db3b..b862b59ecd 100644 --- a/xfa/fxfa/parser/xfa_document_imp.cpp +++ b/xfa/fxfa/parser/xfa_document_imp.cpp @@ -6,6 +6,12 @@ #include "core/fxcrt/include/fx_ext.h" #include "xfa/fxfa/app/xfa_ffnotify.h" +#include "xfa/fxfa/parser/cscript_datawindow.h" +#include "xfa/fxfa/parser/cscript_eventpseudomodel.h" +#include "xfa/fxfa/parser/cscript_hostpseudomodel.h" +#include "xfa/fxfa/parser/cscript_layoutpseudomodel.h" +#include "xfa/fxfa/parser/cscript_logpseudomodel.h" +#include "xfa/fxfa/parser/cscript_signaturepseudomodel.h" #include "xfa/fxfa/parser/cxfa_document_parser.h" #include "xfa/fxfa/parser/xfa_basic_imp.h" #include "xfa/fxfa/parser/xfa_doclayout.h" @@ -14,13 +20,7 @@ #include "xfa/fxfa/parser/xfa_localemgr.h" #include "xfa/fxfa/parser/xfa_object.h" #include "xfa/fxfa/parser/xfa_script.h" -#include "xfa/fxfa/parser/xfa_script_datawindow.h" -#include "xfa/fxfa/parser/xfa_script_eventpseudomodel.h" -#include "xfa/fxfa/parser/xfa_script_hostpseudomodel.h" #include "xfa/fxfa/parser/xfa_script_imp.h" -#include "xfa/fxfa/parser/xfa_script_layoutpseudomodel.h" -#include "xfa/fxfa/parser/xfa_script_logpseudomodel.h" -#include "xfa/fxfa/parser/xfa_script_signaturepseudomodel.h" #include "xfa/fxfa/parser/xfa_utils.h" CXFA_Document::CXFA_Document(CXFA_DocumentParser* pParser) diff --git a/xfa/fxfa/parser/xfa_script_datawindow.cpp b/xfa/fxfa/parser/xfa_script_datawindow.cpp deleted file mode 100644 index aa399b79de..0000000000 --- a/xfa/fxfa/parser/xfa_script_datawindow.cpp +++ /dev/null @@ -1,47 +0,0 @@ -// 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_script_datawindow.h" - -#include "fxjs/include/cfxjse_arguments.h" -#include "xfa/fxfa/parser/xfa_doclayout.h" -#include "xfa/fxfa/parser/xfa_document.h" -#include "xfa/fxfa/parser/xfa_localemgr.h" -#include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_script.h" -#include "xfa/fxfa/parser/xfa_utils.h" - -CScript_DataWindow::CScript_DataWindow(CXFA_Document* pDocument) - : CXFA_Object(pDocument, - XFA_ObjectType::Object, - XFA_Element::DataWindow, - CFX_WideStringC(L"dataWindow")) {} - -CScript_DataWindow::~CScript_DataWindow() {} - -void CScript_DataWindow::MoveCurrentRecord(CFXJSE_Arguments* pArguments) {} - -void CScript_DataWindow::Record(CFXJSE_Arguments* pArguments) {} - -void CScript_DataWindow::GotoRecord(CFXJSE_Arguments* pArguments) {} - -void CScript_DataWindow::IsRecordGroup(CFXJSE_Arguments* pArguments) {} - -void CScript_DataWindow::RecordsBefore(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) {} - -void CScript_DataWindow::CurrentRecordNumber(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) {} - -void CScript_DataWindow::RecordsAfter(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) {} - -void CScript_DataWindow::IsDefined(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) {} diff --git a/xfa/fxfa/parser/xfa_script_datawindow.h b/xfa/fxfa/parser/xfa_script_datawindow.h deleted file mode 100644 index ea8e6ad242..0000000000 --- a/xfa/fxfa/parser/xfa_script_datawindow.h +++ /dev/null @@ -1,36 +0,0 @@ -// 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 - -#ifndef XFA_FXFA_PARSER_XFA_SCRIPT_DATAWINDOW_H_ -#define XFA_FXFA_PARSER_XFA_SCRIPT_DATAWINDOW_H_ - -#include "fxjs/include/cfxjse_arguments.h" -#include "xfa/fxfa/parser/xfa_object.h" - -class CScript_DataWindow : public CXFA_Object { - public: - explicit CScript_DataWindow(CXFA_Document* pDocument); - ~CScript_DataWindow() override; - - void MoveCurrentRecord(CFXJSE_Arguments* pArguments); - void Record(CFXJSE_Arguments* pArguments); - void GotoRecord(CFXJSE_Arguments* pArguments); - void IsRecordGroup(CFXJSE_Arguments* pArguments); - void RecordsBefore(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute); - void CurrentRecordNumber(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute); - void RecordsAfter(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute); - void IsDefined(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute); -}; - -#endif // XFA_FXFA_PARSER_XFA_SCRIPT_DATAWINDOW_H_ diff --git a/xfa/fxfa/parser/xfa_script_eventpseudomodel.cpp b/xfa/fxfa/parser/xfa_script_eventpseudomodel.cpp deleted file mode 100644 index de4b7ae8da..0000000000 --- a/xfa/fxfa/parser/xfa_script_eventpseudomodel.cpp +++ /dev/null @@ -1,234 +0,0 @@ -// 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_script_eventpseudomodel.h" - -#include "fxjs/include/cfxjse_arguments.h" -#include "xfa/fxfa/app/xfa_ffnotify.h" -#include "xfa/fxfa/include/cxfa_eventparam.h" -#include "xfa/fxfa/include/xfa_ffwidgethandler.h" -#include "xfa/fxfa/parser/xfa_doclayout.h" -#include "xfa/fxfa/parser/xfa_document.h" -#include "xfa/fxfa/parser/xfa_localemgr.h" -#include "xfa/fxfa/parser/xfa_object.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 StringProperty(CFXJSE_Value* pValue, - CFX_WideString& wsValue, - FX_BOOL bSetting) { - if (bSetting) { - wsValue = pValue->ToWideString(); - return; - } - pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); -} - -void InterProperty(CFXJSE_Value* pValue, int32_t& iValue, FX_BOOL bSetting) { - if (bSetting) { - iValue = pValue->ToInteger(); - return; - } - pValue->SetInteger(iValue); -} - -void BooleanProperty(CFXJSE_Value* pValue, FX_BOOL& bValue, FX_BOOL bSetting) { - if (bSetting) { - bValue = pValue->ToBoolean(); - return; - } - pValue->SetBoolean(bValue); -} - -} // namespace - -CScript_EventPseudoModel::CScript_EventPseudoModel(CXFA_Document* pDocument) - : CXFA_Object(pDocument, - XFA_ObjectType::Object, - XFA_Element::EventPseudoModel, - CFX_WideStringC(L"eventPseudoModel")) {} - -CScript_EventPseudoModel::~CScript_EventPseudoModel() {} - -void CScript_EventPseudoModel::Property(CFXJSE_Value* pValue, - XFA_Event dwFlag, - FX_BOOL bSetting) { - CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); - if (!pScriptContext) - return; - - CXFA_EventParam* pEventParam = pScriptContext->GetEventParam(); - if (!pEventParam) - return; - - switch (dwFlag) { - case XFA_Event::CancelAction: - BooleanProperty(pValue, pEventParam->m_bCancelAction, bSetting); - break; - case XFA_Event::Change: - StringProperty(pValue, pEventParam->m_wsChange, bSetting); - break; - case XFA_Event::CommitKey: - InterProperty(pValue, pEventParam->m_iCommitKey, bSetting); - break; - case XFA_Event::FullText: - StringProperty(pValue, pEventParam->m_wsFullText, bSetting); - break; - case XFA_Event::Keydown: - BooleanProperty(pValue, pEventParam->m_bKeyDown, bSetting); - break; - case XFA_Event::Modifier: - BooleanProperty(pValue, pEventParam->m_bModifier, bSetting); - break; - case XFA_Event::NewContentType: - StringProperty(pValue, pEventParam->m_wsNewContentType, bSetting); - break; - case XFA_Event::NewText: - StringProperty(pValue, pEventParam->m_wsNewText, bSetting); - break; - case XFA_Event::PreviousContentType: - StringProperty(pValue, pEventParam->m_wsPrevContentType, bSetting); - break; - case XFA_Event::PreviousText: - StringProperty(pValue, pEventParam->m_wsPrevText, bSetting); - break; - case XFA_Event::Reenter: - BooleanProperty(pValue, pEventParam->m_bReenter, bSetting); - break; - case XFA_Event::SelectionEnd: - InterProperty(pValue, pEventParam->m_iSelEnd, bSetting); - break; - case XFA_Event::SelectionStart: - InterProperty(pValue, pEventParam->m_iSelStart, bSetting); - break; - case XFA_Event::Shift: - BooleanProperty(pValue, pEventParam->m_bShift, bSetting); - break; - case XFA_Event::SoapFaultCode: - StringProperty(pValue, pEventParam->m_wsSoapFaultCode, bSetting); - break; - case XFA_Event::SoapFaultString: - StringProperty(pValue, pEventParam->m_wsSoapFaultString, bSetting); - break; - case XFA_Event::Target: - break; - default: - break; - } -} -void CScript_EventPseudoModel::Change(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) { - Property(pValue, XFA_Event::Change, bSetting); -} -void CScript_EventPseudoModel::CommitKey(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) { - Property(pValue, XFA_Event::CommitKey, bSetting); -} -void CScript_EventPseudoModel::FullText(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) { - Property(pValue, XFA_Event::FullText, bSetting); -} -void CScript_EventPseudoModel::KeyDown(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) { - Property(pValue, XFA_Event::Keydown, bSetting); -} -void CScript_EventPseudoModel::Modifier(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) { - Property(pValue, XFA_Event::Modifier, bSetting); -} -void CScript_EventPseudoModel::NewContentType(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) { - Property(pValue, XFA_Event::NewContentType, bSetting); -} -void CScript_EventPseudoModel::NewText(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) { - Property(pValue, XFA_Event::NewText, bSetting); -} -void CScript_EventPseudoModel::PrevContentType(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) { - Property(pValue, XFA_Event::PreviousContentType, bSetting); -} -void CScript_EventPseudoModel::PrevText(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) { - Property(pValue, XFA_Event::PreviousText, bSetting); -} -void CScript_EventPseudoModel::Reenter(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) { - Property(pValue, XFA_Event::Reenter, bSetting); -} -void CScript_EventPseudoModel::SelEnd(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) { - Property(pValue, XFA_Event::SelectionEnd, bSetting); -} -void CScript_EventPseudoModel::SelStart(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) { - Property(pValue, XFA_Event::SelectionStart, bSetting); -} -void CScript_EventPseudoModel::Shift(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) { - Property(pValue, XFA_Event::Shift, bSetting); -} -void CScript_EventPseudoModel::SoapFaultCode(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) { - Property(pValue, XFA_Event::SoapFaultCode, bSetting); -} -void CScript_EventPseudoModel::SoapFaultString(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) { - Property(pValue, XFA_Event::SoapFaultString, bSetting); -} -void CScript_EventPseudoModel::Target(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) { - Property(pValue, XFA_Event::Target, bSetting); -} -void CScript_EventPseudoModel::Emit(CFXJSE_Arguments* pArguments) { - CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); - if (!pScriptContext) { - return; - } - CXFA_EventParam* pEventParam = pScriptContext->GetEventParam(); - if (!pEventParam) { - return; - } - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - CXFA_FFWidgetHandler* pWidgetHandler = pNotify->GetWidgetHandler(); - if (!pWidgetHandler) { - return; - } - pWidgetHandler->ProcessEvent(pEventParam->m_pTarget, pEventParam); -} -void CScript_EventPseudoModel::Reset(CFXJSE_Arguments* pArguments) { - CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); - if (!pScriptContext) { - return; - } - CXFA_EventParam* pEventParam = pScriptContext->GetEventParam(); - if (!pEventParam) { - return; - } - pEventParam->Reset(); -} diff --git a/xfa/fxfa/parser/xfa_script_eventpseudomodel.h b/xfa/fxfa/parser/xfa_script_eventpseudomodel.h deleted file mode 100644 index c52d3ce5fa..0000000000 --- a/xfa/fxfa/parser/xfa_script_eventpseudomodel.h +++ /dev/null @@ -1,86 +0,0 @@ -// 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 - -#ifndef XFA_FXFA_PARSER_XFA_SCRIPT_EVENTPSEUDOMODEL_H_ -#define XFA_FXFA_PARSER_XFA_SCRIPT_EVENTPSEUDOMODEL_H_ - -#include "fxjs/include/cfxjse_arguments.h" -#include "xfa/fxfa/parser/xfa_object.h" - -enum class XFA_Event { - Change = 0, - CommitKey, - FullText, - Keydown, - Modifier, - NewContentType, - NewText, - PreviousContentType, - PreviousText, - Reenter, - SelectionEnd, - SelectionStart, - Shift, - SoapFaultCode, - SoapFaultString, - Target, - CancelAction -}; - -class CScript_EventPseudoModel : public CXFA_Object { - public: - explicit CScript_EventPseudoModel(CXFA_Document* pDocument); - ~CScript_EventPseudoModel() override; - - void Change(CFXJSE_Value* pValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute); - void CommitKey(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute); - void FullText(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute); - void KeyDown(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute); - void Modifier(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute); - void NewContentType(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute); - void NewText(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute); - void PrevContentType(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute); - void PrevText(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute); - void Reenter(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute); - void SelEnd(CFXJSE_Value* pValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute); - void SelStart(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute); - void Shift(CFXJSE_Value* pValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute); - void SoapFaultCode(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute); - void SoapFaultString(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute); - void Target(CFXJSE_Value* pValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute); - - void Emit(CFXJSE_Arguments* pArguments); - void Reset(CFXJSE_Arguments* pArguments); - - protected: - void Property(CFXJSE_Value* pValue, XFA_Event dwFlag, FX_BOOL bSetting); -}; - -#endif // XFA_FXFA_PARSER_XFA_SCRIPT_EVENTPSEUDOMODEL_H_ diff --git a/xfa/fxfa/parser/xfa_script_hostpseudomodel.cpp b/xfa/fxfa/parser/xfa_script_hostpseudomodel.cpp deleted file mode 100644 index 9153761abf..0000000000 --- a/xfa/fxfa/parser/xfa_script_hostpseudomodel.cpp +++ /dev/null @@ -1,717 +0,0 @@ -// 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_script_hostpseudomodel.h" - -#include "fxjs/include/cfxjse_arguments.h" -#include "xfa/fxfa/app/xfa_ffnotify.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_object.h" -#include "xfa/fxfa/parser/xfa_script.h" -#include "xfa/fxfa/parser/xfa_script_imp.h" -#include "xfa/fxfa/parser/xfa_utils.h" - -namespace { - -CXFA_Node* ToNode(CFXJSE_Value* pValue, CFXJSE_Class* pClass) { - return static_cast(pValue->ToHostObject(pClass)); -} - -} // namespace - -CScript_HostPseudoModel::CScript_HostPseudoModel(CXFA_Document* pDocument) - : CXFA_Object(pDocument, - XFA_ObjectType::Object, - XFA_Element::HostPseudoModel, - CFX_WideStringC(L"hostPseudoModel")) {} - -CScript_HostPseudoModel::~CScript_HostPseudoModel() {} - -void CScript_HostPseudoModel::LoadString(CFXJSE_Value* pValue, - CXFA_FFNotify* pNotify, - uint32_t dwFlag) { - CFX_WideString wsValue; - pNotify->GetAppProvider()->LoadString(dwFlag, wsValue); - pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); -} - -void CScript_HostPseudoModel::AppType(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) { - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - if (bSetting) { - ThrowException(XFA_IDS_INVAlID_PROP_SET); - return; - } - CFX_WideString wsAppType; - pNotify->GetAppProvider()->GetAppType(wsAppType); - pValue->SetString(FX_UTF8Encode(wsAppType).AsStringC()); -} - -void CScript_HostPseudoModel::CalculationsEnabled(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) { - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - CXFA_FFDoc* hDoc = pNotify->GetHDOC(); - if (bSetting) { - pNotify->GetDocProvider()->SetCalculationsEnabled(hDoc, - pValue->ToBoolean()); - return; - } - pValue->SetBoolean(pNotify->GetDocProvider()->IsCalculationsEnabled(hDoc)); -} - -void CScript_HostPseudoModel::CurrentPage(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) { - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - CXFA_FFDoc* hDoc = pNotify->GetHDOC(); - if (bSetting) { - pNotify->GetDocProvider()->SetCurrentPage(hDoc, pValue->ToInteger()); - return; - } - pValue->SetInteger(pNotify->GetDocProvider()->GetCurrentPage(hDoc)); -} - -void CScript_HostPseudoModel::Language(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) { - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - if (bSetting) { - ThrowException(XFA_IDS_UNABLE_SET_LANGUAGE); - return; - } - CFX_WideString wsLanguage; - pNotify->GetAppProvider()->GetLanguage(wsLanguage); - pValue->SetString(FX_UTF8Encode(wsLanguage).AsStringC()); -} - -void CScript_HostPseudoModel::NumPages(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) { - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - CXFA_FFDoc* hDoc = pNotify->GetHDOC(); - if (bSetting) { - ThrowException(XFA_IDS_UNABLE_SET_NUMPAGES); - return; - } - pValue->SetInteger(pNotify->GetDocProvider()->CountPages(hDoc)); -} - -void CScript_HostPseudoModel::Platform(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) { - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - if (bSetting) { - ThrowException(XFA_IDS_UNABLE_SET_PLATFORM); - return; - } - CFX_WideString wsPlatform; - pNotify->GetAppProvider()->GetPlatform(wsPlatform); - pValue->SetString(FX_UTF8Encode(wsPlatform).AsStringC()); -} -void CScript_HostPseudoModel::Title(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) { - if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { - return; - } - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - CXFA_FFDoc* hDoc = pNotify->GetHDOC(); - if (bSetting) { - pNotify->GetDocProvider()->SetTitle(hDoc, pValue->ToWideString()); - return; - } - CFX_WideString wsTitle; - pNotify->GetDocProvider()->GetTitle(hDoc, wsTitle); - pValue->SetString(FX_UTF8Encode(wsTitle).AsStringC()); -} - -void CScript_HostPseudoModel::ValidationsEnabled(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) { - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - CXFA_FFDoc* hDoc = pNotify->GetHDOC(); - if (bSetting) { - pNotify->GetDocProvider()->SetValidationsEnabled(hDoc, pValue->ToBoolean()); - return; - } - FX_BOOL bEnabled = pNotify->GetDocProvider()->IsValidationsEnabled(hDoc); - pValue->SetBoolean(bEnabled); -} -void CScript_HostPseudoModel::Variation(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) { - if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { - return; - } - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - if (bSetting) { - ThrowException(XFA_IDS_UNABLE_SET_VARIATION); - return; - } - CFX_WideString wsVariation; - pNotify->GetAppProvider()->GetVariation(wsVariation); - pValue->SetString(FX_UTF8Encode(wsVariation).AsStringC()); -} - -void CScript_HostPseudoModel::Version(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) { - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - if (bSetting) { - ThrowException(XFA_IDS_UNABLE_SET_VERSION); - return; - } - CFX_WideString wsVersion; - pNotify->GetAppProvider()->GetVersion(wsVersion); - pValue->SetString(FX_UTF8Encode(wsVersion).AsStringC()); -} - -void CScript_HostPseudoModel::Name(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) { - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - if (bSetting) { - ThrowException(XFA_IDS_INVAlID_PROP_SET); - return; - } - CFX_WideString wsAppName; - pNotify->GetAppProvider()->GetAppName(wsAppName); - pValue->SetString(FX_UTF8Encode(wsAppName).AsStringC()); -} - -void CScript_HostPseudoModel::GotoURL(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"gotoURL"); - return; - } - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - CXFA_FFDoc* hDoc = pNotify->GetHDOC(); - CFX_WideString wsURL; - if (iLength >= 1) { - CFX_ByteString bsURL = pArguments->GetUTF8String(0); - wsURL = CFX_WideString::FromUTF8(bsURL.AsStringC()); - } - pNotify->GetDocProvider()->GotoURL(hDoc, wsURL); -} -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 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->GetDocProvider()->SetFocusWidget(pNotify->GetHDOC(), hWidget); - pNotify->OpenDropDownList(hWidget); -} -void CScript_HostPseudoModel::Response(CFXJSE_Arguments* pArguments) { - int32_t iLength = pArguments->GetLength(); - if (iLength < 1 || iLength > 4) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"response"); - return; - } - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - CFX_WideString wsQuestion; - CFX_WideString wsTitle; - CFX_WideString wsDefaultAnswer; - FX_BOOL bMark = FALSE; - if (iLength >= 1) { - CFX_ByteString bsQuestion = pArguments->GetUTF8String(0); - wsQuestion = CFX_WideString::FromUTF8(bsQuestion.AsStringC()); - } - if (iLength >= 2) { - CFX_ByteString bsTitle = pArguments->GetUTF8String(1); - wsTitle = CFX_WideString::FromUTF8(bsTitle.AsStringC()); - } - if (iLength >= 3) { - CFX_ByteString bsDefaultAnswer = pArguments->GetUTF8String(2); - wsDefaultAnswer = CFX_WideString::FromUTF8(bsDefaultAnswer.AsStringC()); - } - if (iLength >= 4) { - bMark = pArguments->GetInt32(3) == 0 ? FALSE : TRUE; - } - CFX_WideString wsAnswer = pNotify->GetAppProvider()->Response( - wsQuestion, wsTitle, wsDefaultAnswer, bMark); - CFXJSE_Value* pValue = pArguments->GetReturnValue(); - if (pValue) - pValue->SetString(FX_UTF8Encode(wsAnswer).AsStringC()); -} - -void CScript_HostPseudoModel::DocumentInBatch(CFXJSE_Arguments* pArguments) { - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - int32_t iCur = pNotify->GetAppProvider()->GetCurDocumentInBatch(); - CFXJSE_Value* pValue = pArguments->GetReturnValue(); - if (pValue) - pValue->SetInteger(iCur); -} -static int32_t XFA_FilterName(const CFX_WideStringC& wsExpression, - int32_t nStart, - CFX_WideString& wsFilter) { - ASSERT(nStart > -1); - int32_t iLength = wsExpression.GetLength(); - if (nStart >= iLength) { - return iLength; - } - FX_WCHAR* pBuf = wsFilter.GetBuffer(iLength - nStart); - int32_t nCount = 0; - const FX_WCHAR* pSrc = wsExpression.c_str(); - FX_WCHAR wCur; - while (nStart < iLength) { - wCur = pSrc[nStart++]; - if (wCur == ',') { - break; - } - pBuf[nCount++] = wCur; - } - wsFilter.ReleaseBuffer(nCount); - wsFilter.TrimLeft(); - wsFilter.TrimRight(); - return nStart; -} -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 CScript_HostPseudoModel::Beep(CFXJSE_Arguments* pArguments) { - if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { - return; - } - int32_t iLength = pArguments->GetLength(); - if (iLength < 0 || iLength > 1) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"beep"); - return; - } - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - uint32_t dwType = 4; - if (iLength >= 1) { - dwType = pArguments->GetInt32(0); - } - pNotify->GetAppProvider()->Beep(dwType); -} -void CScript_HostPseudoModel::SetFocus(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"setFocus"); - return; - } - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - CXFA_Node* pNode = nullptr; - if (iLength >= 1) { - std::unique_ptr 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(); - } - } - pNotify->SetFocusWidgetNode(pNode); -} - -void CScript_HostPseudoModel::GetFocus(CFXJSE_Arguments* pArguments) { - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - CXFA_Node* pNode = pNotify->GetFocusWidgetNode(); - if (!pNode) { - return; - } - pArguments->GetReturnValue()->Assign( - m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode)); -} -void CScript_HostPseudoModel::MessageBox(CFXJSE_Arguments* pArguments) { - if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { - return; - } - int32_t iLength = pArguments->GetLength(); - if (iLength < 1 || iLength > 4) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"messageBox"); - return; - } - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - CFX_WideString wsMessage; - CFX_WideString bsTitle; - uint32_t dwMessageType = XFA_MBICON_Error; - uint32_t dwButtonType = XFA_MB_OK; - if (iLength >= 1) { - if (!ValidateArgsForMsg(pArguments, 0, wsMessage)) { - return; - } - } - if (iLength >= 2) { - if (!ValidateArgsForMsg(pArguments, 1, bsTitle)) { - return; - } - } - if (iLength >= 3) { - dwMessageType = pArguments->GetInt32(2); - if (dwMessageType > XFA_MBICON_Status) { - dwMessageType = XFA_MBICON_Error; - } - } - if (iLength >= 4) { - dwButtonType = pArguments->GetInt32(3); - if (dwButtonType > XFA_MB_YesNoCancel) { - dwButtonType = XFA_MB_OK; - } - } - int32_t iValue = pNotify->GetAppProvider()->MsgBox( - wsMessage, bsTitle, dwMessageType, dwButtonType); - CFXJSE_Value* pValue = pArguments->GetReturnValue(); - if (pValue) - pValue->SetInteger(iValue); -} -FX_BOOL CScript_HostPseudoModel::ValidateArgsForMsg( - CFXJSE_Arguments* pArguments, - int32_t iArgIndex, - CFX_WideString& wsValue) { - if (!pArguments || iArgIndex < 0) { - return FALSE; - } - FX_BOOL bIsJsType = FALSE; - if (m_pDocument->GetScriptContext()->GetType() == - XFA_SCRIPTLANGTYPE_Javascript) { - bIsJsType = TRUE; - } - std::unique_ptr pValueArg(pArguments->GetValue(iArgIndex)); - if (!pValueArg->IsString() && bIsJsType) { - ThrowException(XFA_IDS_ARGUMENT_MISMATCH); - return FALSE; - } - if (pValueArg->IsNull()) { - wsValue = FX_WSTRC(L""); - } else { - wsValue = pValueArg->ToWideString(); - } - return TRUE; -} -void CScript_HostPseudoModel::DocumentCountInBatch( - CFXJSE_Arguments* pArguments) { - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - int32_t iValue = pNotify->GetAppProvider()->GetDocumentCountInBatch(); - CFXJSE_Value* pValue = pArguments->GetReturnValue(); - if (pValue) - pValue->SetInteger(iValue); -} -void CScript_HostPseudoModel::Print(CFXJSE_Arguments* pArguments) { - if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { - return; - } - int32_t iLength = pArguments->GetLength(); - if (iLength != 8) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"print"); - return; - } - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - CXFA_FFDoc* hDoc = pNotify->GetHDOC(); - uint32_t dwOptions = 0; - FX_BOOL bShowDialog = TRUE; - if (iLength >= 1) { - bShowDialog = pArguments->GetInt32(0) == 0 ? FALSE : TRUE; - } - if (bShowDialog) { - dwOptions |= XFA_PRINTOPT_ShowDialog; - } - int32_t nStartPage = 0; - if (iLength >= 2) { - nStartPage = pArguments->GetInt32(1); - } - int32_t nEndPage = 0; - if (iLength >= 3) { - nEndPage = pArguments->GetInt32(2); - } - FX_BOOL bCanCancel = TRUE; - if (iLength >= 4) { - bCanCancel = pArguments->GetInt32(3) == 0 ? FALSE : TRUE; - } - if (bCanCancel) { - dwOptions |= XFA_PRINTOPT_CanCancel; - } - FX_BOOL bShrinkPage = TRUE; - if (iLength >= 5) { - bShrinkPage = pArguments->GetInt32(4) == 0 ? FALSE : TRUE; - } - if (bShrinkPage) { - dwOptions |= XFA_PRINTOPT_ShrinkPage; - } - FX_BOOL bAsImage = TRUE; - if (iLength >= 6) { - bAsImage = pArguments->GetInt32(5) == 0 ? FALSE : TRUE; - } - if (bAsImage) { - dwOptions |= XFA_PRINTOPT_AsImage; - } - FX_BOOL bReverseOrder = TRUE; - if (iLength >= 7) { - bAsImage = pArguments->GetInt32(5) == 0 ? FALSE : TRUE; - } - bReverseOrder = pArguments->GetInt32(6) == 0 ? FALSE : TRUE; - if (bReverseOrder) { - dwOptions |= XFA_PRINTOPT_ReverseOrder; - } - FX_BOOL bPrintAnnot = TRUE; - if (iLength >= 8) { - bPrintAnnot = pArguments->GetInt32(7) == 0 ? FALSE : TRUE; - } - if (bPrintAnnot) { - dwOptions |= XFA_PRINTOPT_PrintAnnot; - } - pNotify->GetDocProvider()->Print(hDoc, nStartPage, nEndPage, dwOptions); -} -void CScript_HostPseudoModel::ImportData(CFXJSE_Arguments* pArguments) { - int32_t iLength = pArguments->GetLength(); - if (iLength < 0 || iLength > 1) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"importData"); - return; - } - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - CFX_WideString wsFilePath; - if (iLength > 0) { - CFX_ByteString bsFilePath = pArguments->GetUTF8String(0); - wsFilePath = CFX_WideString::FromUTF8(bsFilePath.AsStringC()); - } - CXFA_FFDoc* hDoc = pNotify->GetHDOC(); - pNotify->GetDocProvider()->ImportData(hDoc, wsFilePath); -} -void CScript_HostPseudoModel::ExportData(CFXJSE_Arguments* pArguments) { - int32_t iLength = pArguments->GetLength(); - if (iLength < 0 || iLength > 2) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"exportData"); - return; - } - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - CXFA_FFDoc* hDoc = pNotify->GetHDOC(); - CFX_WideString wsFilePath; - FX_BOOL bXDP = TRUE; - if (iLength >= 1) { - CFX_ByteString bsFilePath = pArguments->GetUTF8String(0); - wsFilePath = CFX_WideString::FromUTF8(bsFilePath.AsStringC()); - } - if (iLength >= 2) { - bXDP = pArguments->GetInt32(1) == 0 ? FALSE : TRUE; - } - pNotify->GetDocProvider()->ExportData(hDoc, wsFilePath, bXDP); -} - -void CScript_HostPseudoModel::PageUp(CFXJSE_Arguments* pArguments) { - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - CXFA_FFDoc* hDoc = pNotify->GetHDOC(); - int32_t nCurPage = pNotify->GetDocProvider()->GetCurrentPage(hDoc); - int32_t nNewPage = 0; - if (nCurPage <= 1) { - return; - } - nNewPage = nCurPage - 1; - pNotify->GetDocProvider()->SetCurrentPage(hDoc, nNewPage); -} - -void CScript_HostPseudoModel::PageDown(CFXJSE_Arguments* pArguments) { - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - CXFA_FFDoc* hDoc = pNotify->GetHDOC(); - int32_t nCurPage = pNotify->GetDocProvider()->GetCurrentPage(hDoc); - int32_t nPageCount = pNotify->GetDocProvider()->CountPages(hDoc); - if (!nPageCount || nCurPage == nPageCount) { - return; - } - int32_t nNewPage = 0; - if (nCurPage >= nPageCount) { - nNewPage = nPageCount - 1; - } else { - nNewPage = nCurPage + 1; - } - pNotify->GetDocProvider()->SetCurrentPage(hDoc, nNewPage); -} - -void CScript_HostPseudoModel::CurrentDateTime(CFXJSE_Arguments* pArguments) { - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - CFX_WideString wsDataTime = pNotify->GetCurrentDateTime(); - CFXJSE_Value* pValue = pArguments->GetReturnValue(); - if (pValue) - pValue->SetString(FX_UTF8Encode(wsDataTime).AsStringC()); -} diff --git a/xfa/fxfa/parser/xfa_script_hostpseudomodel.h b/xfa/fxfa/parser/xfa_script_hostpseudomodel.h deleted file mode 100644 index d5c1b197b8..0000000000 --- a/xfa/fxfa/parser/xfa_script_hostpseudomodel.h +++ /dev/null @@ -1,74 +0,0 @@ -// 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 - -#ifndef XFA_FXFA_PARSER_XFA_SCRIPT_HOSTPSEUDOMODEL_H_ -#define XFA_FXFA_PARSER_XFA_SCRIPT_HOSTPSEUDOMODEL_H_ - -#include "fxjs/include/cfxjse_arguments.h" -#include "xfa/fxfa/parser/xfa_document.h" -#include "xfa/fxfa/parser/xfa_object.h" - -class CScript_HostPseudoModel : public CXFA_Object { - public: - explicit CScript_HostPseudoModel(CXFA_Document* pDocument); - ~CScript_HostPseudoModel() override; - - void AppType(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute); - void CalculationsEnabled(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute); - void CurrentPage(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute); - void Language(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute); - void NumPages(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute); - void Platform(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute); - void Title(CFXJSE_Value* pValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute); - void ValidationsEnabled(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute); - void Variation(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute); - void Version(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute); - void Name(CFXJSE_Value* pValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute); - void GotoURL(CFXJSE_Arguments* pArguments); - void OpenList(CFXJSE_Arguments* pArguments); - void Response(CFXJSE_Arguments* pArguments); - void DocumentInBatch(CFXJSE_Arguments* pArguments); - void ResetData(CFXJSE_Arguments* pArguments); - void Beep(CFXJSE_Arguments* pArguments); - void SetFocus(CFXJSE_Arguments* pArguments); - void GetFocus(CFXJSE_Arguments* pArguments); - void MessageBox(CFXJSE_Arguments* pArguments); - void DocumentCountInBatch(CFXJSE_Arguments* pArguments); - void Print(CFXJSE_Arguments* pArguments); - void ImportData(CFXJSE_Arguments* pArguments); - void ExportData(CFXJSE_Arguments* pArguments); - void PageUp(CFXJSE_Arguments* pArguments); - void PageDown(CFXJSE_Arguments* pArguments); - void CurrentDateTime(CFXJSE_Arguments* pArguments); - - protected: - void LoadString(CFXJSE_Value* pValue, - CXFA_FFNotify* pNotify, - uint32_t dwFlag); - FX_BOOL ValidateArgsForMsg(CFXJSE_Arguments* pArguments, - int32_t iArgIndex, - CFX_WideString& wsValue); -}; - -#endif // XFA_FXFA_PARSER_XFA_SCRIPT_HOSTPSEUDOMODEL_H_ diff --git a/xfa/fxfa/parser/xfa_script_layoutpseudomodel.cpp b/xfa/fxfa/parser/xfa_script_layoutpseudomodel.cpp deleted file mode 100644 index 4a64af9869..0000000000 --- a/xfa/fxfa/parser/xfa_script_layoutpseudomodel.cpp +++ /dev/null @@ -1,514 +0,0 @@ -// 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_script_layoutpseudomodel.h" - -#include - -#include "fxjs/include/cfxjse_arguments.h" -#include "third_party/base/stl_util.h" -#include "xfa/fxfa/app/xfa_ffnotify.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_layout_appadapter.h" -#include "xfa/fxfa/parser/xfa_localemgr.h" -#include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_script.h" -#include "xfa/fxfa/parser/xfa_script_imp.h" -#include "xfa/fxfa/parser/xfa_utils.h" - -CScript_LayoutPseudoModel::CScript_LayoutPseudoModel(CXFA_Document* pDocument) - : CXFA_Object(pDocument, - XFA_ObjectType::Object, - XFA_Element::LayoutPseudoModel, - CFX_WideStringC(L"layoutPseudoModel")) {} - -CScript_LayoutPseudoModel::~CScript_LayoutPseudoModel() {} - -void CScript_LayoutPseudoModel::Ready(CFXJSE_Value* pValue, - FX_BOOL bSetting, - XFA_ATTRIBUTE eAttribute) { - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - if (bSetting) { - ThrowException(XFA_IDS_UNABLE_SET_READY); - return; - } - int32_t iStatus = pNotify->GetLayoutStatus(); - pValue->SetBoolean(iStatus >= 2); -} -void CScript_LayoutPseudoModel::HWXY(CFXJSE_Arguments* pArguments, - XFA_LAYOUTMODEL_HWXY layoutModel) { - int32_t iLength = pArguments->GetLength(); - if (iLength < 1 || iLength > 3) { - const FX_WCHAR* methodName = nullptr; - 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; - } - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, methodName); - return; - } - CXFA_Node* pNode = nullptr; - CFX_WideString wsUnit(L"pt"); - int32_t iIndex = 0; - if (iLength >= 1) { - pNode = static_cast(pArguments->GetObject(0)); - } - if (iLength >= 2) { - CFX_ByteString bsUnit = pArguments->GetUTF8String(1); - if (!bsUnit.IsEmpty()) { - wsUnit = CFX_WideString::FromUTF8(bsUnit.AsStringC()); - } - } - if (iLength >= 3) { - iIndex = pArguments->GetInt32(2); - } - if (!pNode) { - return; - } - CXFA_LayoutProcessor* 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--; - } - CFXJSE_Value* pValue = pArguments->GetReturnValue(); - if (!pLayoutItem) { - pValue->SetFloat(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.AsStringC()); - FX_FLOAT fValue = measure.ToUnit(unit); - fValue = FXSYS_round(fValue * 1000) / 1000.0f; - if (pValue) - pValue->SetFloat(fValue); -} -void CScript_LayoutPseudoModel::H(CFXJSE_Arguments* pArguments) { - HWXY(pArguments, XFA_LAYOUTMODEL_H); -} -void CScript_LayoutPseudoModel::W(CFXJSE_Arguments* pArguments) { - HWXY(pArguments, XFA_LAYOUTMODEL_W); -} -void CScript_LayoutPseudoModel::X(CFXJSE_Arguments* pArguments) { - HWXY(pArguments, XFA_LAYOUTMODEL_X); -} -void CScript_LayoutPseudoModel::Y(CFXJSE_Arguments* pArguments) { - HWXY(pArguments, XFA_LAYOUTMODEL_Y); -} -void CScript_LayoutPseudoModel::NumberedPageCount(CFXJSE_Arguments* pArguments, - FX_BOOL bNumbered) { - CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout(); - if (!pDocLayout) { - return; - } - int32_t iPageCount = 0; - int32_t iPageNum = pDocLayout->CountPages(); - if (bNumbered) { - for (int32_t i = 0; i < iPageNum; i++) { - CXFA_ContainerLayoutItem* pLayoutPage = pDocLayout->GetPage(i); - if (!pLayoutPage) { - continue; - } - CXFA_Node* pMasterPage = pLayoutPage->GetMasterPage(); - if (pMasterPage->GetInteger(XFA_ATTRIBUTE_Numbered)) { - iPageCount++; - } - } - } else { - iPageCount = iPageNum; - } - CFXJSE_Value* pValue = pArguments->GetReturnValue(); - if (pValue) - pValue->SetInteger(iPageCount); -} -void CScript_LayoutPseudoModel::PageCount(CFXJSE_Arguments* pArguments) { - NumberedPageCount(pArguments, TRUE); -} -void CScript_LayoutPseudoModel::PageSpan(CFXJSE_Arguments* pArguments) { - int32_t iLength = pArguments->GetLength(); - if (iLength != 1) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"pageSpan"); - return; - } - CXFA_Node* pNode = nullptr; - if (iLength >= 1) { - pNode = static_cast(pArguments->GetObject(0)); - } - if (!pNode) { - return; - } - CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout(); - if (!pDocLayout) { - return; - } - CFXJSE_Value* pValue = pArguments->GetReturnValue(); - CXFA_LayoutItem* pLayoutItem = pDocLayout->GetLayoutItem(pNode); - if (!pLayoutItem) { - pValue->SetInteger(-1); - return; - } - int32_t iLast = pLayoutItem->GetLast()->GetPage()->GetPageIndex(); - int32_t iFirst = pLayoutItem->GetFirst()->GetPage()->GetPageIndex(); - int32_t iPageSpan = iLast - iFirst + 1; - if (pValue) - pValue->SetInteger(iPageSpan); -} -void CScript_LayoutPseudoModel::Page(CFXJSE_Arguments* pArguments) { - PageImp(pArguments, FALSE); -} -void CScript_LayoutPseudoModel::GetObjArray(CXFA_LayoutProcessor* pDocLayout, - int32_t iPageNo, - const CFX_WideString& wsType, - FX_BOOL bOnPageArea, - CXFA_NodeArray& retArray) { - CXFA_ContainerLayoutItem* pLayoutPage = pDocLayout->GetPage(iPageNo); - if (!pLayoutPage) { - return; - } - if (wsType == FX_WSTRC(L"pageArea")) { - if (CXFA_Node* pMasterPage = pLayoutPage->m_pFormNode) { - retArray.Add(pMasterPage); - } - return; - } - if (wsType == FX_WSTRC(L"contentArea")) { - for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem; - pItem = pItem->m_pNextSibling) { - if (pItem->m_pFormNode->GetElementType() == XFA_Element::ContentArea) { - retArray.Add(pItem->m_pFormNode); - } - } - return; - } - std::set formItems; - if (wsType.IsEmpty()) { - if (CXFA_Node* pMasterPage = pLayoutPage->m_pFormNode) { - retArray.Add(pMasterPage); - } - for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem; - pItem = pItem->m_pNextSibling) { - if (pItem->m_pFormNode->GetElementType() == XFA_Element::ContentArea) { - retArray.Add(pItem->m_pFormNode); - if (!bOnPageArea) { - CXFA_NodeIteratorTemplate - iterator(static_cast(pItem->m_pFirstChild)); - for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); - pItemChild; pItemChild = iterator.MoveToNext()) { - if (!pItemChild->IsContentLayoutItem()) { - continue; - } - XFA_Element eType = pItemChild->m_pFormNode->GetElementType(); - if (eType != XFA_Element::Field && eType != XFA_Element::Draw && - eType != XFA_Element::Subform && eType != XFA_Element::Area) { - continue; - } - if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode)) - continue; - - formItems.insert(pItemChild->m_pFormNode); - retArray.Add(pItemChild->m_pFormNode); - } - } - } else { - if (bOnPageArea) { - CXFA_NodeIteratorTemplate - iterator(static_cast(pItem)); - for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); - pItemChild; pItemChild = iterator.MoveToNext()) { - if (!pItemChild->IsContentLayoutItem()) { - continue; - } - XFA_Element eType = pItemChild->m_pFormNode->GetElementType(); - if (eType != XFA_Element::Field && eType != XFA_Element::Draw && - eType != XFA_Element::Subform && eType != XFA_Element::Area) { - continue; - } - if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode)) - continue; - formItems.insert(pItemChild->m_pFormNode); - retArray.Add(pItemChild->m_pFormNode); - } - } - } - } - return; - } - XFA_Element eType = XFA_Element::Unknown; - if (wsType == FX_WSTRC(L"field")) { - eType = XFA_Element::Field; - } else if (wsType == FX_WSTRC(L"draw")) { - eType = XFA_Element::Draw; - } else if (wsType == FX_WSTRC(L"subform")) { - eType = XFA_Element::Subform; - } else if (wsType == FX_WSTRC(L"area")) { - eType = XFA_Element::Area; - } - if (eType != XFA_Element::Unknown) { - for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem; - pItem = pItem->m_pNextSibling) { - if (pItem->m_pFormNode->GetElementType() == XFA_Element::ContentArea) { - if (!bOnPageArea) { - CXFA_NodeIteratorTemplate - iterator(static_cast(pItem->m_pFirstChild)); - for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); - pItemChild; pItemChild = iterator.MoveToNext()) { - if (!pItemChild->IsContentLayoutItem()) - continue; - if (pItemChild->m_pFormNode->GetElementType() != eType) - continue; - if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode)) - continue; - formItems.insert(pItemChild->m_pFormNode); - retArray.Add(pItemChild->m_pFormNode); - } - } - } else { - if (bOnPageArea) { - CXFA_NodeIteratorTemplate - iterator(static_cast(pItem)); - for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); - pItemChild; pItemChild = iterator.MoveToNext()) { - if (!pItemChild->IsContentLayoutItem()) - continue; - if (pItemChild->m_pFormNode->GetElementType() != eType) - continue; - if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode)) - continue; - formItems.insert(pItemChild->m_pFormNode); - retArray.Add(pItemChild->m_pFormNode); - } - } - } - } - return; - } -} -void CScript_LayoutPseudoModel::PageContent(CFXJSE_Arguments* pArguments) { - int32_t iLength = pArguments->GetLength(); - if (iLength < 1 || iLength > 3) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"pageContent"); - return; - } - int32_t iIndex = 0; - CFX_WideString wsType; - FX_BOOL bOnPageArea = FALSE; - if (iLength >= 1) { - iIndex = pArguments->GetInt32(0); - } - if (iLength >= 2) { - CFX_ByteString bsType = pArguments->GetUTF8String(1); - wsType = CFX_WideString::FromUTF8(bsType.AsStringC()); - } - if (iLength >= 3) { - bOnPageArea = pArguments->GetInt32(2) == 0 ? FALSE : TRUE; - } - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout(); - if (!pDocLayout) { - return; - } - CXFA_NodeArray retArray; - GetObjArray(pDocLayout, iIndex, wsType, bOnPageArea, retArray); - CXFA_ArrayNodeList* pArrayNodeList = new CXFA_ArrayNodeList(m_pDocument); - pArrayNodeList->SetArrayNodeList(retArray); - pArguments->GetReturnValue()->SetObject( - pArrayNodeList, m_pDocument->GetScriptContext()->GetJseNormalClass()); -} -void CScript_LayoutPseudoModel::AbsPageCount(CFXJSE_Arguments* pArguments) { - NumberedPageCount(pArguments, FALSE); -} -void CScript_LayoutPseudoModel::AbsPageCountInBatch( - CFXJSE_Arguments* pArguments) { - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - CXFA_FFDoc* hDoc = pNotify->GetHDOC(); - int32_t iPageCount = pNotify->GetDocProvider()->AbsPageCountInBatch(hDoc); - CFXJSE_Value* pValue = pArguments->GetReturnValue(); - if (pValue) - pValue->SetInteger(iPageCount); -} -void CScript_LayoutPseudoModel::SheetCountInBatch( - CFXJSE_Arguments* pArguments) { - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - CXFA_FFDoc* hDoc = pNotify->GetHDOC(); - int32_t iPageCount = pNotify->GetDocProvider()->SheetCountInBatch(hDoc); - CFXJSE_Value* pValue = pArguments->GetReturnValue(); - if (pValue) - pValue->SetInteger(iPageCount); -} -void CScript_LayoutPseudoModel::Relayout(CFXJSE_Arguments* pArguments) { - CXFA_Node* pRootNode = m_pDocument->GetRoot(); - CXFA_Node* pFormRoot = pRootNode->GetFirstChildByClass(XFA_Element::Form); - ASSERT(pFormRoot); - CXFA_Node* pContentRootNode = pFormRoot->GetNodeItem(XFA_NODEITEM_FirstChild); - CXFA_LayoutProcessor* pLayoutProcessor = m_pDocument->GetLayoutProcessor(); - if (pContentRootNode) { - pLayoutProcessor->AddChangedContainer(pContentRootNode); - } - pLayoutProcessor->SetForceReLayout(TRUE); -} -void CScript_LayoutPseudoModel::AbsPageSpan(CFXJSE_Arguments* pArguments) { - PageSpan(pArguments); -} -void CScript_LayoutPseudoModel::AbsPageInBatch(CFXJSE_Arguments* pArguments) { - int32_t iLength = pArguments->GetLength(); - if (iLength != 1) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"absPageInBatch"); - return; - } - CXFA_Node* pNode = nullptr; - if (iLength >= 1) { - pNode = static_cast(pArguments->GetObject(0)); - } - if (!pNode) { - return; - } - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout(); - if (!pDocLayout) { - return; - } - CXFA_FFWidget* hWidget = - pNotify->GetHWidget(pDocLayout->GetLayoutItem(pNode)); - if (!hWidget) { - return; - } - CXFA_FFDoc* hDoc = pNotify->GetHDOC(); - int32_t iPageCount = pNotify->GetDocProvider()->AbsPageInBatch(hDoc, hWidget); - CFXJSE_Value* pValue = pArguments->GetReturnValue(); - if (pValue) - pValue->SetInteger(iPageCount); -} -void CScript_LayoutPseudoModel::SheetInBatch(CFXJSE_Arguments* pArguments) { - int32_t iLength = pArguments->GetLength(); - if (iLength != 1) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"sheetInBatch"); - return; - } - CXFA_Node* pNode = nullptr; - if (iLength >= 1) { - pNode = static_cast(pArguments->GetObject(0)); - } - if (!pNode) { - return; - } - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout(); - if (!pDocLayout) { - return; - } - CXFA_FFWidget* hWidget = - pNotify->GetHWidget(pDocLayout->GetLayoutItem(pNode)); - if (!hWidget) { - return; - } - CXFA_FFDoc* hDoc = pNotify->GetHDOC(); - int32_t iPageCount = pNotify->GetDocProvider()->SheetInBatch(hDoc, hWidget); - CFXJSE_Value* pValue = pArguments->GetReturnValue(); - if (pValue) - pValue->SetInteger(iPageCount); -} -void CScript_LayoutPseudoModel::Sheet(CFXJSE_Arguments* pArguments) { - PageImp(pArguments, TRUE); -} -void CScript_LayoutPseudoModel::RelayoutPageArea(CFXJSE_Arguments* pArguments) { -} -void CScript_LayoutPseudoModel::SheetCount(CFXJSE_Arguments* pArguments) { - NumberedPageCount(pArguments, FALSE); -} -void CScript_LayoutPseudoModel::AbsPage(CFXJSE_Arguments* pArguments) { - PageImp(pArguments, TRUE); -} -void CScript_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"; - } - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, methodName); - return; - } - CXFA_Node* pNode = nullptr; - if (iLength >= 1) { - pNode = static_cast(pArguments->GetObject(0)); - } - int32_t iPage = 0; - CFXJSE_Value* pValue = pArguments->GetReturnValue(); - if (!pNode && pValue) - pValue->SetInteger(iPage); - - CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout(); - if (!pDocLayout) { - return; - } - CXFA_LayoutItem* pLayoutItem = pDocLayout->GetLayoutItem(pNode); - if (!pLayoutItem) { - pValue->SetInteger(-1); - return; - } - iPage = pLayoutItem->GetFirst()->GetPage()->GetPageIndex(); - if (pValue) - pValue->SetInteger(bAbsPage ? iPage : iPage + 1); -} diff --git a/xfa/fxfa/parser/xfa_script_layoutpseudomodel.h b/xfa/fxfa/parser/xfa_script_layoutpseudomodel.h deleted file mode 100644 index 1e61c42064..0000000000 --- a/xfa/fxfa/parser/xfa_script_layoutpseudomodel.h +++ /dev/null @@ -1,59 +0,0 @@ -// 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 - -#ifndef XFA_FXFA_PARSER_XFA_SCRIPT_LAYOUTPSEUDOMODEL_H_ -#define XFA_FXFA_PARSER_XFA_SCRIPT_LAYOUTPSEUDOMODEL_H_ - -#include "fxjs/include/cfxjse_arguments.h" -#include "xfa/fxfa/parser/xfa_doclayout.h" -#include "xfa/fxfa/parser/xfa_object.h" - -enum XFA_LAYOUTMODEL_HWXY { - XFA_LAYOUTMODEL_H, - XFA_LAYOUTMODEL_W, - XFA_LAYOUTMODEL_X, - XFA_LAYOUTMODEL_Y -}; - -class CScript_LayoutPseudoModel : public CXFA_Object { - public: - explicit CScript_LayoutPseudoModel(CXFA_Document* pDocument); - ~CScript_LayoutPseudoModel() override; - - void Ready(CFXJSE_Value* pValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute); - - void HWXY(CFXJSE_Arguments* pArguments, XFA_LAYOUTMODEL_HWXY layoutModel); - void H(CFXJSE_Arguments* pArguments); - void W(CFXJSE_Arguments* pArguments); - void X(CFXJSE_Arguments* pArguments); - void Y(CFXJSE_Arguments* pArguments); - void NumberedPageCount(CFXJSE_Arguments* pArguments, FX_BOOL bNumbered); - void PageCount(CFXJSE_Arguments* pArguments); - void PageSpan(CFXJSE_Arguments* pArguments); - void Page(CFXJSE_Arguments* pArguments); - void PageContent(CFXJSE_Arguments* pArguments); - void AbsPageCount(CFXJSE_Arguments* pArguments); - void AbsPageCountInBatch(CFXJSE_Arguments* pArguments); - void SheetCountInBatch(CFXJSE_Arguments* pArguments); - void Relayout(CFXJSE_Arguments* pArguments); - void AbsPageSpan(CFXJSE_Arguments* pArguments); - void AbsPageInBatch(CFXJSE_Arguments* pArguments); - void SheetInBatch(CFXJSE_Arguments* pArguments); - void Sheet(CFXJSE_Arguments* pArguments); - void RelayoutPageArea(CFXJSE_Arguments* pArguments); - void SheetCount(CFXJSE_Arguments* pArguments); - void AbsPage(CFXJSE_Arguments* pArguments); - - protected: - void GetObjArray(CXFA_LayoutProcessor* pDocLayout, - int32_t iPageNo, - const CFX_WideString& wsType, - FX_BOOL bOnPageArea, - CXFA_NodeArray& retArray); - void PageImp(CFXJSE_Arguments* pArguments, FX_BOOL bAbsPage); -}; - -#endif // XFA_FXFA_PARSER_XFA_SCRIPT_LAYOUTPSEUDOMODEL_H_ diff --git a/xfa/fxfa/parser/xfa_script_logpseudomodel.cpp b/xfa/fxfa/parser/xfa_script_logpseudomodel.cpp deleted file mode 100644 index 4abed33a77..0000000000 --- a/xfa/fxfa/parser/xfa_script_logpseudomodel.cpp +++ /dev/null @@ -1,33 +0,0 @@ -// 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_script_logpseudomodel.h" - -#include "fxjs/include/cfxjse_arguments.h" -#include "xfa/fxfa/parser/xfa_doclayout.h" -#include "xfa/fxfa/parser/xfa_document.h" -#include "xfa/fxfa/parser/xfa_localemgr.h" -#include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_script.h" -#include "xfa/fxfa/parser/xfa_utils.h" - -CScript_LogPseudoModel::CScript_LogPseudoModel(CXFA_Document* pDocument) - : CXFA_Object(pDocument, - XFA_ObjectType::Object, - XFA_Element::LogPseudoModel, - CFX_WideStringC(L"logPseudoModel")) {} - -CScript_LogPseudoModel::~CScript_LogPseudoModel() {} - -void CScript_LogPseudoModel::Message(CFXJSE_Arguments* pArguments) {} - -void CScript_LogPseudoModel::TraceEnabled(CFXJSE_Arguments* pArguments) {} - -void CScript_LogPseudoModel::TraceActivate(CFXJSE_Arguments* pArguments) {} - -void CScript_LogPseudoModel::TraceDeactivate(CFXJSE_Arguments* pArguments) {} - -void CScript_LogPseudoModel::Trace(CFXJSE_Arguments* pArguments) {} diff --git a/xfa/fxfa/parser/xfa_script_logpseudomodel.h b/xfa/fxfa/parser/xfa_script_logpseudomodel.h deleted file mode 100644 index 917bbdcf0d..0000000000 --- a/xfa/fxfa/parser/xfa_script_logpseudomodel.h +++ /dev/null @@ -1,25 +0,0 @@ -// 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 - -#ifndef XFA_FXFA_PARSER_XFA_SCRIPT_LOGPSEUDOMODEL_H_ -#define XFA_FXFA_PARSER_XFA_SCRIPT_LOGPSEUDOMODEL_H_ - -#include "fxjs/include/cfxjse_arguments.h" -#include "xfa/fxfa/parser/xfa_object.h" - -class CScript_LogPseudoModel : public CXFA_Object { - public: - explicit CScript_LogPseudoModel(CXFA_Document* pDocument); - ~CScript_LogPseudoModel() override; - - void Message(CFXJSE_Arguments* pArguments); - void TraceEnabled(CFXJSE_Arguments* pArguments); - void TraceActivate(CFXJSE_Arguments* pArguments); - void TraceDeactivate(CFXJSE_Arguments* pArguments); - void Trace(CFXJSE_Arguments* pArguments); -}; - -#endif // XFA_FXFA_PARSER_XFA_SCRIPT_LOGPSEUDOMODEL_H_ diff --git a/xfa/fxfa/parser/xfa_script_signaturepseudomodel.cpp b/xfa/fxfa/parser/xfa_script_signaturepseudomodel.cpp deleted file mode 100644 index 95b9a3605b..0000000000 --- a/xfa/fxfa/parser/xfa_script_signaturepseudomodel.cpp +++ /dev/null @@ -1,122 +0,0 @@ -// 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_script_signaturepseudomodel.h" - -#include "fxjs/include/cfxjse_arguments.h" -#include "xfa/fxfa/app/xfa_ffnotify.h" -#include "xfa/fxfa/parser/xfa_doclayout.h" -#include "xfa/fxfa/parser/xfa_document.h" -#include "xfa/fxfa/parser/xfa_localemgr.h" -#include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_script.h" -#include "xfa/fxfa/parser/xfa_script_imp.h" -#include "xfa/fxfa/parser/xfa_utils.h" - -CScript_SignaturePseudoModel::CScript_SignaturePseudoModel( - CXFA_Document* pDocument) - : CXFA_Object(pDocument, - XFA_ObjectType::Object, - XFA_Element::SignaturePseudoModel, - CFX_WideStringC(L"signaturePseudoModel")) {} - -CScript_SignaturePseudoModel::~CScript_SignaturePseudoModel() {} - -void CScript_SignaturePseudoModel::Verify(CFXJSE_Arguments* pArguments) { - int32_t iLength = pArguments->GetLength(); - if (iLength < 1 || iLength > 4) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"verify"); - return; - } - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - CXFA_FFDoc* hDoc = pNotify->GetHDOC(); - CXFA_Node* pNode = nullptr; - if (iLength >= 1) { - pNode = static_cast(pArguments->GetObject(0)); - } - int32_t bVerify = pNotify->GetDocProvider()->Verify(hDoc, pNode); - CFXJSE_Value* pValue = pArguments->GetReturnValue(); - if (pValue) - pValue->SetInteger(bVerify); -} - -void CScript_SignaturePseudoModel::Sign(CFXJSE_Arguments* pArguments) { - int32_t iLength = pArguments->GetLength(); - if (iLength < 3 || iLength > 7) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"sign"); - return; - } - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - CXFA_FFDoc* hDoc = pNotify->GetHDOC(); - CXFA_NodeList* pNodeList = nullptr; - CFX_WideString wsExpression; - CFX_WideString wsXMLIdent; - if (iLength >= 1) { - pNodeList = (CXFA_NodeList*)pArguments->GetObject(0); - } - if (iLength >= 2) { - CFX_ByteString bsExpression = pArguments->GetUTF8String(1); - wsExpression = CFX_WideString::FromUTF8(bsExpression.AsStringC()); - } - if (iLength >= 3) { - CFX_ByteString bsXMLIdent = pArguments->GetUTF8String(2); - wsXMLIdent = CFX_WideString::FromUTF8(bsXMLIdent.AsStringC()); - } - FX_BOOL bSign = pNotify->GetDocProvider()->Sign( - hDoc, pNodeList, wsExpression.AsStringC(), wsXMLIdent.AsStringC()); - CFXJSE_Value* pValue = pArguments->GetReturnValue(); - if (pValue) - pValue->SetBoolean(bSign); -} - -void CScript_SignaturePseudoModel::Enumerate(CFXJSE_Arguments* pArguments) { - int32_t iLength = pArguments->GetLength(); - if (iLength != 0) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"enumerate"); - return; - } - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - CXFA_FFDoc* hDoc = pNotify->GetHDOC(); - CXFA_NodeList* pList = pNotify->GetDocProvider()->Enumerate(hDoc); - if (!pList) - return; - pArguments->GetReturnValue()->Assign( - m_pDocument->GetScriptContext()->GetJSValueFromMap(pList)); -} - -void CScript_SignaturePseudoModel::Clear(CFXJSE_Arguments* pArguments) { - int32_t iLength = pArguments->GetLength(); - if (iLength < 1 || iLength > 2) { - ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"clear"); - return; - } - CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); - if (!pNotify) { - return; - } - CXFA_FFDoc* hDoc = pNotify->GetHDOC(); - CXFA_Node* pNode = nullptr; - FX_BOOL bClear = TRUE; - if (iLength >= 1) { - pNode = static_cast(pArguments->GetObject(0)); - } - if (iLength >= 2) { - bClear = pArguments->GetInt32(1) == 0 ? FALSE : TRUE; - } - FX_BOOL bFlag = pNotify->GetDocProvider()->Clear(hDoc, pNode, bClear); - CFXJSE_Value* pValue = pArguments->GetReturnValue(); - if (pValue) - pValue->SetBoolean(bFlag); -} diff --git a/xfa/fxfa/parser/xfa_script_signaturepseudomodel.h b/xfa/fxfa/parser/xfa_script_signaturepseudomodel.h deleted file mode 100644 index 56f5e5de43..0000000000 --- a/xfa/fxfa/parser/xfa_script_signaturepseudomodel.h +++ /dev/null @@ -1,24 +0,0 @@ -// 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 - -#ifndef XFA_FXFA_PARSER_XFA_SCRIPT_SIGNATUREPSEUDOMODEL_H_ -#define XFA_FXFA_PARSER_XFA_SCRIPT_SIGNATUREPSEUDOMODEL_H_ - -#include "fxjs/include/cfxjse_arguments.h" -#include "xfa/fxfa/parser/xfa_object.h" - -class CScript_SignaturePseudoModel : public CXFA_Object { - public: - explicit CScript_SignaturePseudoModel(CXFA_Document* pDocument); - ~CScript_SignaturePseudoModel() override; - - void Verify(CFXJSE_Arguments* pArguments); - void Sign(CFXJSE_Arguments* pArguments); - void Enumerate(CFXJSE_Arguments* pArguments); - void Clear(CFXJSE_Arguments* pArguments); -}; - -#endif // XFA_FXFA_PARSER_XFA_SCRIPT_SIGNATUREPSEUDOMODEL_H_ -- cgit v1.2.3