From d9dfb6cc16f689753e9b3f896fbda1aec791051a Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Thu, 4 Jan 2018 11:03:26 -0500 Subject: Merge CXFA_WidgetData into CXFA_WidgetAcc This CL merges the CXFA_WidgetData class into the only subclass, CXFA_WidgetAcc. Code has been updated as needed. Change-Id: I3f5bc83b1422bcbe065276b16bfb91e656f5c174 Reviewed-on: https://pdfium-review.googlesource.com/22252 Reviewed-by: Ryan Harrison Commit-Queue: dsinclair --- BUILD.gn | 2 - fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp | 4 +- fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h | 4 +- fxjs/xfa/cjx_boolean.cpp | 8 +- fxjs/xfa/cjx_draw.cpp | 4 +- fxjs/xfa/cjx_exclgroup.cpp | 17 +- fxjs/xfa/cjx_field.cpp | 106 +- fxjs/xfa/cjx_hostpseudomodel.cpp | 2 +- fxjs/xfa/cjx_manifest.cpp | 4 +- fxjs/xfa/cjx_node.cpp | 14 +- fxjs/xfa/cjx_object.cpp | 25 +- fxjs/xfa/cjx_object.h | 9 +- fxjs/xfa/cjx_template.cpp | 6 +- xfa/fxfa/cxfa_ffdocview.cpp | 14 +- xfa/fxfa/cxfa_ffdocview.h | 2 +- xfa/fxfa/cxfa_fffield.cpp | 2 +- xfa/fxfa/cxfa_ffnotify.cpp | 44 +- xfa/fxfa/cxfa_ffnotify.h | 6 +- xfa/fxfa/cxfa_ffwidget.cpp | 2 +- xfa/fxfa/cxfa_textprovider.cpp | 2 +- xfa/fxfa/cxfa_widgetacc.cpp | 1764 +++++++++++++++++++++- xfa/fxfa/cxfa_widgetacc.h | 176 ++- xfa/fxfa/cxfa_widgetacciterator.cpp | 2 +- xfa/fxfa/fxfa.h | 4 +- xfa/fxfa/parser/cxfa_dataexporter.cpp | 1 - xfa/fxfa/parser/cxfa_localevalue.h | 2 +- xfa/fxfa/parser/cxfa_node.cpp | 40 +- xfa/fxfa/parser/cxfa_node.h | 9 +- xfa/fxfa/parser/cxfa_widgetdata.cpp | 1791 ----------------------- xfa/fxfa/parser/cxfa_widgetdata.h | 200 --- xfa/fxfa/parser/xfa_document_datamerger_imp.cpp | 40 +- xfa/fxfa/parser/xfa_utils.cpp | 14 +- xfa/fxfa/parser/xfa_utils.h | 4 +- 33 files changed, 2126 insertions(+), 2198 deletions(-) delete mode 100644 xfa/fxfa/parser/cxfa_widgetdata.cpp delete mode 100644 xfa/fxfa/parser/cxfa_widgetdata.h diff --git a/BUILD.gn b/BUILD.gn index fc445e37e9..0bc8134720 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -2713,8 +2713,6 @@ if (pdf_enable_xfa) { "xfa/fxfa/parser/cxfa_webclient.h", "xfa/fxfa/parser/cxfa_whitespace.cpp", "xfa/fxfa/parser/cxfa_whitespace.h", - "xfa/fxfa/parser/cxfa_widgetdata.cpp", - "xfa/fxfa/parser/cxfa_widgetdata.h", "xfa/fxfa/parser/cxfa_window.cpp", "xfa/fxfa/parser/cxfa_window.h", "xfa/fxfa/parser/cxfa_wsdladdress.cpp", diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp index 071fe34bdd..fd385aa4ae 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp @@ -289,7 +289,7 @@ void CPDFXFA_DocEnvironment::PageViewEvent(CXFA_FFPageView* pPageView, } void CPDFXFA_DocEnvironment::WidgetPostAdd(CXFA_FFWidget* hWidget, - CXFA_WidgetAcc* pWidgetData) { + CXFA_WidgetAcc* pWidgetAcc) { if (m_pContext->GetFormType() != FormType::kXFAFull || !hWidget) return; @@ -307,7 +307,7 @@ void CPDFXFA_DocEnvironment::WidgetPostAdd(CXFA_FFWidget* hWidget, } void CPDFXFA_DocEnvironment::WidgetPreRemove(CXFA_FFWidget* hWidget, - CXFA_WidgetAcc* pWidgetData) { + CXFA_WidgetAcc* pWidgetAcc) { if (m_pContext->GetFormType() != FormType::kXFAFull || !hWidget) return; diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h index 7933da33e4..9eabf8d655 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h +++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h @@ -39,9 +39,9 @@ class CPDFXFA_DocEnvironment : public IXFA_DocEnvironment { // dwFlags XFA_PAGEVIEWEVENT_Added, XFA_PAGEVIEWEVENT_Removing void PageViewEvent(CXFA_FFPageView* pPageView, uint32_t dwFlags) override; void WidgetPostAdd(CXFA_FFWidget* hWidget, - CXFA_WidgetAcc* pWidgetData) override; + CXFA_WidgetAcc* pWidgetAcc) override; void WidgetPreRemove(CXFA_FFWidget* hWidget, - CXFA_WidgetAcc* pWidgetData) override; + CXFA_WidgetAcc* pWidgetAcc) override; // Host method int32_t CountPages(CXFA_FFDoc* hDoc) override; diff --git a/fxjs/xfa/cjx_boolean.cpp b/fxjs/xfa/cjx_boolean.cpp index f5af9547a7..1e66a14e77 100644 --- a/fxjs/xfa/cjx_boolean.cpp +++ b/fxjs/xfa/cjx_boolean.cpp @@ -35,10 +35,10 @@ void CJX_Boolean::defaultValue(CFXJSE_Value* pValue, int32_t iValue = FXSYS_atoi(newValue.c_str()); WideString wsNewValue(iValue == 0 ? L"0" : L"1"); WideString wsFormatValue(wsNewValue); - CXFA_WidgetData* pContainerWidgetData = - ToNode(GetXFAObject())->GetContainerWidgetData(); - if (pContainerWidgetData) - wsFormatValue = pContainerWidgetData->GetFormatDataValue(wsNewValue); + CXFA_WidgetAcc* pContainerWidgetAcc = + ToNode(GetXFAObject())->GetContainerWidgetAcc(); + if (pContainerWidgetAcc) + wsFormatValue = pContainerWidgetAcc->GetFormatDataValue(wsNewValue); SetContent(wsNewValue, wsFormatValue, true, true, true); } diff --git a/fxjs/xfa/cjx_draw.cpp b/fxjs/xfa/cjx_draw.cpp index 0752bf7457..036cfc76bc 100644 --- a/fxjs/xfa/cjx_draw.cpp +++ b/fxjs/xfa/cjx_draw.cpp @@ -119,8 +119,8 @@ void CJX_Draw::defaultValue(CFXJSE_Value* pValue, if (!pValue || !pValue->IsString()) return; - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); - XFA_Element uiType = pWidgetData->GetUIType(); + CXFA_WidgetAcc* pWidgetAcc = GetXFANode()->GetWidgetAcc(); + XFA_Element uiType = pWidgetAcc->GetUIType(); if (uiType != XFA_Element::Text) return; diff --git a/fxjs/xfa/cjx_exclgroup.cpp b/fxjs/xfa/cjx_exclgroup.cpp index fac58ff054..b7223ec200 100644 --- a/fxjs/xfa/cjx_exclgroup.cpp +++ b/fxjs/xfa/cjx_exclgroup.cpp @@ -16,7 +16,6 @@ #include "xfa/fxfa/fxfa.h" #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_exclgroup.h" -#include "xfa/fxfa/parser/cxfa_widgetdata.h" const CJX_MethodSpec CJX_ExclGroup::MethodSpecs[] = { {"execCalculate", execCalculate_static}, @@ -86,15 +85,15 @@ CJS_Return CJX_ExclGroup::selectedMember( if (!params.empty()) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - CXFA_WidgetData* pWidgetData = GetWidgetData(); - if (!pWidgetData) + CXFA_WidgetAcc* pWidgetAcc = GetWidgetAcc(); + if (!pWidgetAcc) return CJS_Return(runtime->NewNull()); CXFA_Node* pReturnNode = nullptr; if (params.empty()) { - pReturnNode = pWidgetData->GetSelectedMember(); + pReturnNode = pWidgetAcc->GetSelectedMember(); } else { - pReturnNode = pWidgetData->SetSelectedMember( + pReturnNode = pWidgetAcc->SetSelectedMember( runtime->ToWideString(params[0]).AsStringView(), true); } if (!pReturnNode) @@ -111,13 +110,13 @@ CJS_Return CJX_ExclGroup::selectedMember( void CJX_ExclGroup::defaultValue(CFXJSE_Value* pValue, bool bSetting, XFA_Attribute eAttribute) { - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); - if (!pWidgetData) + CXFA_WidgetAcc* pWidgetAcc = GetXFANode()->GetWidgetAcc(); + if (!pWidgetAcc) return; if (bSetting) { - pWidgetData->SetSelectedMemberByValue(pValue->ToWideString().AsStringView(), - true, true, true); + pWidgetAcc->SetSelectedMemberByValue(pValue->ToWideString().AsStringView(), + true, true, true); return; } diff --git a/fxjs/xfa/cjx_field.cpp b/fxjs/xfa/cjx_field.cpp index a3e4405a17..cb0722eeee 100644 --- a/fxjs/xfa/cjx_field.cpp +++ b/fxjs/xfa/cjx_field.cpp @@ -17,7 +17,6 @@ #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_field.h" #include "xfa/fxfa/parser/cxfa_value.h" -#include "xfa/fxfa/parser/cxfa_widgetdata.h" const CJX_MethodSpec CJX_Field::MethodSpecs[] = { {"addItem", addItem_static}, @@ -42,9 +41,9 @@ CJX_Field::~CJX_Field() {} CJS_Return CJX_Field::clearItems( CJS_V8* runtime, const std::vector>& params) { - CXFA_WidgetData* pWidgetData = GetWidgetData(); - if (pWidgetData) - pWidgetData->DeleteItem(-1, true, false); + CXFA_WidgetAcc* pWidgetAcc = GetWidgetAcc(); + if (pWidgetAcc) + pWidgetAcc->DeleteItem(-1, true, false); return CJS_Return(true); } @@ -83,12 +82,11 @@ CJS_Return CJX_Field::deleteItem( if (params.size() != 1) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - CXFA_WidgetData* pWidgetData = GetWidgetData(); - if (!pWidgetData) + CXFA_WidgetAcc* pWidgetAcc = GetWidgetAcc(); + if (!pWidgetAcc) return CJS_Return(true); - bool bValue = - pWidgetData->DeleteItem(runtime->ToInt32(params[0]), true, true); + bool bValue = pWidgetAcc->DeleteItem(runtime->ToInt32(params[0]), true, true); return CJS_Return(runtime->NewBoolean(bValue)); } @@ -102,12 +100,12 @@ CJS_Return CJX_Field::getSaveItem( if (iIndex < 0) return CJS_Return(runtime->NewNull()); - CXFA_WidgetData* pWidgetData = GetWidgetData(); - if (!pWidgetData) + CXFA_WidgetAcc* pWidgetAcc = GetWidgetAcc(); + if (!pWidgetAcc) return CJS_Return(runtime->NewNull()); pdfium::Optional value = - pWidgetData->GetChoiceListItem(iIndex, true); + pWidgetAcc->GetChoiceListItem(iIndex, true); if (!value) return CJS_Return(runtime->NewNull()); @@ -120,12 +118,12 @@ CJS_Return CJX_Field::boundItem( if (params.size() != 1) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - CXFA_WidgetData* pWidgetData = GetWidgetData(); - if (!pWidgetData) + CXFA_WidgetAcc* pWidgetAcc = GetWidgetAcc(); + if (!pWidgetAcc) return CJS_Return(true); WideString value = runtime->ToWideString(params[0]); - WideString boundValue = pWidgetData->GetItemValue(value.AsStringView()); + WideString boundValue = pWidgetAcc->GetItemValue(value.AsStringView()); return CJS_Return(runtime->NewString(boundValue.UTF8Encode().AsStringView())); } @@ -135,11 +133,11 @@ CJS_Return CJX_Field::getItemState( if (params.size() != 1) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - CXFA_WidgetData* pWidgetData = GetWidgetData(); - if (!pWidgetData) + CXFA_WidgetAcc* pWidgetAcc = GetWidgetAcc(); + if (!pWidgetAcc) return CJS_Return(true); - int32_t state = pWidgetData->GetItemState(runtime->ToInt32(params[0])); + int32_t state = pWidgetAcc->GetItemState(runtime->ToInt32(params[0])); return CJS_Return(runtime->NewBoolean(state != 0)); } @@ -167,12 +165,12 @@ CJS_Return CJX_Field::getDisplayItem( if (iIndex < 0) return CJS_Return(runtime->NewNull()); - CXFA_WidgetData* pWidgetData = GetWidgetData(); - if (!pWidgetData) + CXFA_WidgetAcc* pWidgetAcc = GetWidgetAcc(); + if (!pWidgetAcc) return CJS_Return(runtime->NewNull()); pdfium::Optional value = - pWidgetData->GetChoiceListItem(iIndex, false); + pWidgetAcc->GetChoiceListItem(iIndex, false); if (!value) return CJS_Return(runtime->NewNull()); @@ -185,17 +183,17 @@ CJS_Return CJX_Field::setItemState( if (params.size() != 2) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - CXFA_WidgetData* pWidgetData = GetWidgetData(); - if (!pWidgetData) + CXFA_WidgetAcc* pWidgetAcc = GetWidgetAcc(); + if (!pWidgetAcc) return CJS_Return(true); int32_t iIndex = runtime->ToInt32(params[0]); if (runtime->ToInt32(params[1]) != 0) { - pWidgetData->SetItemState(iIndex, true, true, true, true); + pWidgetAcc->SetItemState(iIndex, true, true, true, true); return CJS_Return(true); } - if (pWidgetData->GetItemState(iIndex)) - pWidgetData->SetItemState(iIndex, false, true, true, true); + if (pWidgetAcc->GetItemState(iIndex)) + pWidgetAcc->SetItemState(iIndex, false, true, true, true); return CJS_Return(true); } @@ -205,8 +203,8 @@ CJS_Return CJX_Field::addItem(CJS_V8* runtime, if (params.size() != 1 && params.size() != 2) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - CXFA_WidgetData* pWidgetData = GetWidgetData(); - if (!pWidgetData) + CXFA_WidgetAcc* pWidgetAcc = GetWidgetAcc(); + if (!pWidgetAcc) return CJS_Return(true); WideString label; @@ -217,7 +215,7 @@ CJS_Return CJX_Field::addItem(CJS_V8* runtime, if (params.size() >= 2) value = runtime->ToWideString(params[1]); - pWidgetData->InsertItem(label, value, true); + pWidgetAcc->InsertItem(label, value, true); return CJS_Return(true); } @@ -239,32 +237,30 @@ CJS_Return CJX_Field::execValidate( void CJX_Field::defaultValue(CFXJSE_Value* pValue, bool bSetting, XFA_Attribute eAttribute) { - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); - if (!pWidgetData) + CXFA_WidgetAcc* pWidgetAcc = GetXFANode()->GetWidgetAcc(); + if (!pWidgetAcc) return; if (bSetting) { if (pValue) { - pWidgetData->SetPreNull(pWidgetData->IsNull()); - pWidgetData->SetIsNull(pValue->IsNull()); + pWidgetAcc->SetPreNull(pWidgetAcc->IsNull()); + pWidgetAcc->SetIsNull(pValue->IsNull()); } WideString wsNewText; if (pValue && !(pValue->IsNull() || pValue->IsUndefined())) wsNewText = pValue->ToWideString(); - CXFA_Node* pUIChild = pWidgetData->GetUIChild(); + CXFA_Node* pUIChild = pWidgetAcc->GetUIChild(); if (pUIChild->GetElementType() == XFA_Element::NumericEdit) { - wsNewText = - pWidgetData->NumericLimit(wsNewText, pWidgetData->GetLeadDigits(), - pWidgetData->GetFracDigits()); + wsNewText = pWidgetAcc->NumericLimit( + wsNewText, pWidgetAcc->GetLeadDigits(), pWidgetAcc->GetFracDigits()); } - CXFA_WidgetData* pContainerWidgetData = - GetXFANode()->GetContainerWidgetData(); + CXFA_WidgetAcc* pContainerWidgetAcc = GetXFANode()->GetContainerWidgetAcc(); WideString wsFormatText(wsNewText); - if (pContainerWidgetData) - wsFormatText = pContainerWidgetData->GetFormatDataValue(wsNewText); + if (pContainerWidgetAcc) + wsFormatText = pContainerWidgetAcc->GetFormatDataValue(wsNewText); SetContent(wsNewText, wsFormatText, true, true, true); return; @@ -276,9 +272,9 @@ void CJX_Field::defaultValue(CFXJSE_Value* pValue, return; } - CXFA_Node* pUIChild = pWidgetData->GetUIChild(); + CXFA_Node* pUIChild = pWidgetAcc->GetUIChild(); CXFA_Node* pNode = - pWidgetData->GetFormValue()->GetNodeItem(XFA_NODEITEM_FirstChild); + pWidgetAcc->GetFormValue()->GetNodeItem(XFA_NODEITEM_FirstChild); if (pNode && pNode->GetElementType() == XFA_Element::Decimal) { if (pUIChild->GetElementType() == XFA_Element::NumericEdit && (pNode->JSObject()->GetInteger(XFA_Attribute::FracDigits) == -1)) { @@ -302,16 +298,16 @@ void CJX_Field::defaultValue(CFXJSE_Value* pValue, void CJX_Field::editValue(CFXJSE_Value* pValue, bool bSetting, XFA_Attribute eAttribute) { - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); - if (!pWidgetData) + CXFA_WidgetAcc* pWidgetAcc = GetXFANode()->GetWidgetAcc(); + if (!pWidgetAcc) return; if (bSetting) { - pWidgetData->SetValue(XFA_VALUEPICTURE_Edit, pValue->ToWideString()); + pWidgetAcc->SetValue(XFA_VALUEPICTURE_Edit, pValue->ToWideString()); return; } pValue->SetString( - pWidgetData->GetValue(XFA_VALUEPICTURE_Edit).UTF8Encode().AsStringView()); + pWidgetAcc->GetValue(XFA_VALUEPICTURE_Edit).UTF8Encode().AsStringView()); } void CJX_Field::formatMessage(CFXJSE_Value* pValue, @@ -323,15 +319,15 @@ void CJX_Field::formatMessage(CFXJSE_Value* pValue, void CJX_Field::formattedValue(CFXJSE_Value* pValue, bool bSetting, XFA_Attribute eAttribute) { - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); - if (!pWidgetData) + CXFA_WidgetAcc* pWidgetAcc = GetXFANode()->GetWidgetAcc(); + if (!pWidgetAcc) return; if (bSetting) { - pWidgetData->SetValue(XFA_VALUEPICTURE_Display, pValue->ToWideString()); + pWidgetAcc->SetValue(XFA_VALUEPICTURE_Display, pValue->ToWideString()); return; } - pValue->SetString(pWidgetData->GetValue(XFA_VALUEPICTURE_Display) + pValue->SetString(pWidgetAcc->GetValue(XFA_VALUEPICTURE_Display) .UTF8Encode() .AsStringView()); } @@ -349,22 +345,22 @@ void CJX_Field::parentSubform(CFXJSE_Value* pValue, void CJX_Field::selectedIndex(CFXJSE_Value* pValue, bool bSetting, XFA_Attribute eAttribute) { - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); - if (!pWidgetData) + CXFA_WidgetAcc* pWidgetAcc = GetXFANode()->GetWidgetAcc(); + if (!pWidgetAcc) return; if (!bSetting) { - pValue->SetInteger(pWidgetData->GetSelectedItem(0)); + pValue->SetInteger(pWidgetAcc->GetSelectedItem(0)); return; } int32_t iIndex = pValue->ToInteger(); if (iIndex == -1) { - pWidgetData->ClearAllSelections(); + pWidgetAcc->ClearAllSelections(); return; } - pWidgetData->SetItemState(iIndex, true, true, true, true); + pWidgetAcc->SetItemState(iIndex, true, true, true, true); } void CJX_Field::access(CFXJSE_Value* pValue, diff --git a/fxjs/xfa/cjx_hostpseudomodel.cpp b/fxjs/xfa/cjx_hostpseudomodel.cpp index f862accbe0..12aa2bdb2b 100644 --- a/fxjs/xfa/cjx_hostpseudomodel.cpp +++ b/fxjs/xfa/cjx_hostpseudomodel.cpp @@ -394,7 +394,7 @@ CJS_Return CJX_HostPseudoModel::resetData( continue; pNode = resolveNodeRS.objects.front()->AsNode(); - pNotify->ResetData(pNode->GetWidgetData()); + pNotify->ResetData(pNode->GetWidgetAcc()); } if (!pNode) pNotify->ResetData(); diff --git a/fxjs/xfa/cjx_manifest.cpp b/fxjs/xfa/cjx_manifest.cpp index bd482d0f4b..69c3e944df 100644 --- a/fxjs/xfa/cjx_manifest.cpp +++ b/fxjs/xfa/cjx_manifest.cpp @@ -27,8 +27,8 @@ CJS_Return CJX_Manifest::evaluate( if (!params.empty()) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - CXFA_WidgetData* pWidgetData = GetWidgetData(); - return CJS_Return(runtime->NewBoolean(!!pWidgetData)); + CXFA_WidgetAcc* pWidgetAcc = GetWidgetAcc(); + return CJS_Return(runtime->NewBoolean(!!pWidgetAcc)); } void CJX_Manifest::defaultValue(CFXJSE_Value* pValue, diff --git a/fxjs/xfa/cjx_node.cpp b/fxjs/xfa/cjx_node.cpp index e64f1fd5e7..c0634767cf 100644 --- a/fxjs/xfa/cjx_node.cpp +++ b/fxjs/xfa/cjx_node.cpp @@ -500,11 +500,11 @@ int32_t CJX_Node::execSingleEventByName(const WideStringView& wsEventName, return pNotify->ExecEventByDeepFirst( GetXFANode(), eventParaInfo->m_eventType, false, false); case EventAppliesToo::kSignature: { - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); - if (!pWidgetData) + CXFA_WidgetAcc* pWidgetAcc = GetXFANode()->GetWidgetAcc(); + if (!pWidgetAcc) return XFA_EVENTERROR_NotExist; - CXFA_Node* pUINode = pWidgetData->GetUIChild(); + CXFA_Node* pUINode = pWidgetAcc->GetUIChild(); if (pUINode->GetElementType() != XFA_Element::Signature) return XFA_EVENTERROR_NotExist; @@ -512,13 +512,13 @@ int32_t CJX_Node::execSingleEventByName(const WideStringView& wsEventName, GetXFANode(), eventParaInfo->m_eventType, false, false); } case EventAppliesToo::kChoiceList: { - CXFA_WidgetData* pWidgetData = GetXFANode()->GetWidgetData(); - if (!pWidgetData) + CXFA_WidgetAcc* pWidgetAcc = GetXFANode()->GetWidgetAcc(); + if (!pWidgetAcc) return XFA_EVENTERROR_NotExist; - CXFA_Node* pUINode = pWidgetData->GetUIChild(); + CXFA_Node* pUINode = pWidgetAcc->GetUIChild(); if (pUINode->GetElementType() != XFA_Element::ChoiceList || - pWidgetData->IsListBox()) { + pWidgetAcc->IsListBox()) { return XFA_EVENTERROR_NotExist; } return pNotify->ExecEventByDeepFirst( diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp index ce3f92a9bf..e574454673 100644 --- a/fxjs/xfa/cjx_object.cpp +++ b/fxjs/xfa/cjx_object.cpp @@ -21,6 +21,7 @@ #include "third_party/base/ptr_util.h" #include "xfa/fxfa/cxfa_ffnotify.h" #include "xfa/fxfa/cxfa_ffwidget.h" +#include "xfa/fxfa/cxfa_widgetacc.h" #include "xfa/fxfa/parser/cxfa_border.h" #include "xfa/fxfa/parser/cxfa_datavalue.h" #include "xfa/fxfa/parser/cxfa_document.h" @@ -1166,9 +1167,9 @@ void CJX_Object::MoveBufferMapData(CXFA_Object* pDstModule) { WideString wsValue = ToNode(pDstModule)->JSObject()->GetContent(false); WideString wsFormatValue(wsValue); - CXFA_WidgetData* pWidgetData = ToNode(pDstModule)->GetContainerWidgetData(); - if (pWidgetData) - wsFormatValue = pWidgetData->GetFormatDataValue(wsValue); + CXFA_WidgetAcc* pWidgetAcc = ToNode(pDstModule)->GetContainerWidgetAcc(); + if (pWidgetAcc) + wsFormatValue = pWidgetAcc->GetFormatDataValue(wsValue); ToNode(pDstModule) ->JSObject() @@ -1524,30 +1525,30 @@ void CJX_Object::Script_Som_DefaultValue(CFXJSE_Value* pValue, wsNewValue = pValue->ToWideString(); WideString wsFormatValue(wsNewValue); - CXFA_WidgetData* pContainerWidgetData = nullptr; + CXFA_WidgetAcc* pContainerWidgetAcc = nullptr; if (ToNode(GetXFAObject())->GetPacketType() == XFA_PacketType::Datasets) { WideString wsPicture; for (const auto& pFormNode : *(ToNode(GetXFAObject())->GetBindItems())) { if (!pFormNode || pFormNode->HasRemovedChildren()) continue; - pContainerWidgetData = pFormNode->GetContainerWidgetData(); - if (pContainerWidgetData) { - wsPicture = pContainerWidgetData->GetPictureContent( - XFA_VALUEPICTURE_DataBind); + pContainerWidgetAcc = pFormNode->GetContainerWidgetAcc(); + if (pContainerWidgetAcc) { + wsPicture = + pContainerWidgetAcc->GetPictureContent(XFA_VALUEPICTURE_DataBind); } if (!wsPicture.IsEmpty()) break; - pContainerWidgetData = nullptr; + pContainerWidgetAcc = nullptr; } } else if (ToNode(GetXFAObject())->GetPacketType() == XFA_PacketType::Form) { - pContainerWidgetData = ToNode(GetXFAObject())->GetContainerWidgetData(); + pContainerWidgetAcc = ToNode(GetXFAObject())->GetContainerWidgetAcc(); } - if (pContainerWidgetData) - wsFormatValue = pContainerWidgetData->GetFormatDataValue(wsNewValue); + if (pContainerWidgetAcc) + wsFormatValue = pContainerWidgetAcc->GetFormatDataValue(wsNewValue); SetContent(wsNewValue, wsFormatValue, true, true, true); return; diff --git a/fxjs/xfa/cjx_object.h b/fxjs/xfa/cjx_object.h index 32bb01f3f6..d7979a381f 100644 --- a/fxjs/xfa/cjx_object.h +++ b/fxjs/xfa/cjx_object.h @@ -17,14 +17,15 @@ #include "core/fxcrt/xml/cfx_xmlelement.h" #include "fxjs/CJX_Define.h" #include "third_party/base/optional.h" +#include "xfa/fxfa/cxfa_widgetacc.h" #include "xfa/fxfa/fxfa_basic.h" -#include "xfa/fxfa/parser/cxfa_widgetdata.h" class CFXJSE_Value; class CJS_V8; class CXFA_CalcData; class CXFA_Document; class CXFA_LayoutItem; +class CXFA_Node; class CXFA_Object; struct XFA_MAPMODULEDATA; @@ -63,10 +64,10 @@ class CJX_Object { CXFA_Document* GetDocument() const; - void SetWidgetData(std::unique_ptr data) { + void SetWidgetAcc(std::unique_ptr data) { widget_data_ = std::move(data); } - CXFA_WidgetData* GetWidgetData() const { return widget_data_.get(); } + CXFA_WidgetAcc* GetWidgetAcc() const { return widget_data_.get(); } void SetCalcRecursionCount(size_t count) { calc_recursion_count_ = count; } size_t GetCalcRecursionCount() const { return calc_recursion_count_; } @@ -272,7 +273,7 @@ class CJX_Object { UnownedPtr object_; UnownedPtr layout_item_; - std::unique_ptr widget_data_; + std::unique_ptr widget_data_; std::unique_ptr map_module_data_; std::unique_ptr calc_data_; std::map method_specs_; diff --git a/fxjs/xfa/cjx_template.cpp b/fxjs/xfa/cjx_template.cpp index d55fd66452..9e72257cf3 100644 --- a/fxjs/xfa/cjx_template.cpp +++ b/fxjs/xfa/cjx_template.cpp @@ -50,7 +50,7 @@ CJS_Return CJX_Template::execInitialize( const std::vector>& params) { if (!params.empty()) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - return CJS_Return(runtime->NewBoolean(!!GetWidgetData())); + return CJS_Return(runtime->NewBoolean(!!GetWidgetAcc())); } CJS_Return CJX_Template::recalculate( @@ -66,7 +66,7 @@ CJS_Return CJX_Template::execCalculate( const std::vector>& params) { if (!params.empty()) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - return CJS_Return(runtime->NewBoolean(!!GetWidgetData())); + return CJS_Return(runtime->NewBoolean(!!GetWidgetAcc())); } CJS_Return CJX_Template::execValidate( @@ -74,5 +74,5 @@ CJS_Return CJX_Template::execValidate( const std::vector>& params) { if (!params.empty()) return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - return CJS_Return(runtime->NewBoolean(!!GetWidgetData())); + return CJS_Return(runtime->NewBoolean(!!GetWidgetAcc())); } diff --git a/xfa/fxfa/cxfa_ffdocview.cpp b/xfa/fxfa/cxfa_ffdocview.cpp index 1160d55999..e5d2fe12dc 100644 --- a/xfa/fxfa/cxfa_ffdocview.cpp +++ b/xfa/fxfa/cxfa_ffdocview.cpp @@ -237,7 +237,7 @@ bool CXFA_FFDocView::ResetSingleWidgetAccData(CXFA_WidgetAcc* pWidgetAcc) { return true; } -void CXFA_FFDocView::ResetWidgetData(CXFA_WidgetAcc* pWidgetAcc) { +void CXFA_FFDocView::ResetWidgetAcc(CXFA_WidgetAcc* pWidgetAcc) { m_bLayoutEvent = true; bool bChanged = false; CXFA_Node* pFormNode = nullptr; @@ -445,7 +445,7 @@ int32_t CXFA_FFDocView::ExecEventActivityByDeepFirst(CXFA_Node* pFormNode, if (eEventType == XFA_EVENT_IndexChange) return XFA_EVENTERROR_NotExist; - CXFA_WidgetAcc* pWidgetAcc = (CXFA_WidgetAcc*)pFormNode->GetWidgetData(); + CXFA_WidgetAcc* pWidgetAcc = pFormNode->GetWidgetAcc(); if (!pWidgetAcc) return XFA_EVENTERROR_NotExist; @@ -470,7 +470,7 @@ int32_t CXFA_FFDocView::ExecEventActivityByDeepFirst(CXFA_Node* pFormNode, } } } - CXFA_WidgetAcc* pWidgetAcc = (CXFA_WidgetAcc*)pFormNode->GetWidgetData(); + CXFA_WidgetAcc* pWidgetAcc = pFormNode->GetWidgetAcc(); if (!pWidgetAcc) return iRet; @@ -517,7 +517,7 @@ CXFA_WidgetAcc* CXFA_FFDocView::GetWidgetAccByName( if (resolveNodeRS.dwFlags == XFA_ResolveNode_RSType_Nodes) { CXFA_Node* pNode = resolveNodeRS.objects.front()->AsNode(); if (pNode) - return static_cast(pNode->GetWidgetData()); + return pNode->GetWidgetAcc(); } return nullptr; } @@ -573,8 +573,7 @@ bool CXFA_FFDocView::RunLayout() { void CXFA_FFDocView::RunSubformIndexChange() { for (CXFA_Node* pSubformNode : m_IndexChangedSubforms) { - CXFA_WidgetAcc* pWidgetAcc = - static_cast(pSubformNode->GetWidgetData()); + CXFA_WidgetAcc* pWidgetAcc = pSubformNode->GetWidgetAcc(); if (!pWidgetAcc) continue; @@ -712,8 +711,7 @@ void CXFA_FFDocView::RunBindItems() { continue; CXFA_Node* pWidgetNode = item->GetNodeItem(XFA_NODEITEM_Parent); - CXFA_WidgetAcc* pAcc = - static_cast(pWidgetNode->GetWidgetData()); + CXFA_WidgetAcc* pAcc = pWidgetNode->GetWidgetAcc(); if (!pAcc) continue; diff --git a/xfa/fxfa/cxfa_ffdocview.h b/xfa/fxfa/cxfa_ffdocview.h index be03c10043..f980ad2feb 100644 --- a/xfa/fxfa/cxfa_ffdocview.h +++ b/xfa/fxfa/cxfa_ffdocview.h @@ -54,7 +54,7 @@ class CXFA_FFDocView { int32_t CountPageViews() const; CXFA_FFPageView* GetPageView(int32_t nIndex) const; - void ResetWidgetData(CXFA_WidgetAcc* pWidgetAcc); + void ResetWidgetAcc(CXFA_WidgetAcc* pWidgetAcc); int32_t ProcessWidgetEvent(CXFA_EventParam* pParam, CXFA_WidgetAcc* pWidgetAcc); CXFA_FFWidgetHandler* GetWidgetHandler(); diff --git a/xfa/fxfa/cxfa_fffield.cpp b/xfa/fxfa/cxfa_fffield.cpp index ff5cc76138..fbe0d958cb 100644 --- a/xfa/fxfa/cxfa_fffield.cpp +++ b/xfa/fxfa/cxfa_fffield.cpp @@ -649,7 +649,7 @@ int32_t CXFA_FFField::CalculateOverride() { CXFA_WidgetAcc* pWidgetAcc = nullptr; while (pNode) { - pWidgetAcc = static_cast(pNode->GetWidgetData()); + pWidgetAcc = pNode->GetWidgetAcc(); if (!pWidgetAcc) return 1; if (CalculateWidgetAcc(pWidgetAcc) == 0) diff --git a/xfa/fxfa/cxfa_ffnotify.cpp b/xfa/fxfa/cxfa_ffnotify.cpp index 5b47d99387..616edf7507 100644 --- a/xfa/fxfa/cxfa_ffnotify.cpp +++ b/xfa/fxfa/cxfa_ffnotify.cpp @@ -42,10 +42,6 @@ namespace { -CXFA_WidgetAcc* ToWidgetAcc(void* data) { - return static_cast(data); -} - CXFA_FFListBox* ToListBox(CXFA_FFWidget* widget) { return static_cast(widget); } @@ -67,18 +63,17 @@ void CXFA_FFNotify::OnPageEvent(CXFA_ContainerLayoutItem* pSender, pDocView->OnPageEvent(pSender, dwEvent); } -void CXFA_FFNotify::OnWidgetListItemAdded(CXFA_WidgetData* pSender, +void CXFA_FFNotify::OnWidgetListItemAdded(CXFA_WidgetAcc* pSender, const wchar_t* pLabel, const wchar_t* pValue, int32_t iIndex) { - CXFA_WidgetAcc* pWidgetAcc = ToWidgetAcc(pSender); - if (pWidgetAcc->GetUIType() != XFA_Element::ChoiceList) + if (pSender->GetUIType() != XFA_Element::ChoiceList) return; CXFA_FFWidget* pWidget = nullptr; - while ((pWidget = pWidgetAcc->GetNextWidget(pWidget)) != nullptr) { + while ((pWidget = pSender->GetNextWidget(pWidget)) != nullptr) { if (pWidget->IsLoaded()) { - if (pWidgetAcc->IsListBox()) + if (pSender->IsListBox()) ToListBox(pWidget)->InsertItem(pLabel, iIndex); else ToComboBox(pWidget)->InsertItem(pLabel, iIndex); @@ -86,16 +81,15 @@ void CXFA_FFNotify::OnWidgetListItemAdded(CXFA_WidgetData* pSender, } } -void CXFA_FFNotify::OnWidgetListItemRemoved(CXFA_WidgetData* pSender, +void CXFA_FFNotify::OnWidgetListItemRemoved(CXFA_WidgetAcc* pSender, int32_t iIndex) { - CXFA_WidgetAcc* pWidgetAcc = ToWidgetAcc(pSender); - if (pWidgetAcc->GetUIType() != XFA_Element::ChoiceList) + if (pSender->GetUIType() != XFA_Element::ChoiceList) return; CXFA_FFWidget* pWidget = nullptr; - while ((pWidget = pWidgetAcc->GetNextWidget(pWidget)) != nullptr) { + while ((pWidget = pSender->GetNextWidget(pWidget)) != nullptr) { if (pWidget->IsLoaded()) { - if (pWidgetAcc->IsListBox()) + if (pSender->IsListBox()) ToListBox(pWidget)->DeleteItem(iIndex); else ToComboBox(pWidget)->DeleteItem(iIndex); @@ -112,7 +106,7 @@ CXFA_LayoutItem* CXFA_FFNotify::OnCreateLayoutItem(CXFA_Node* pNode) { if (eType == XFA_Element::ContentArea) return new CXFA_ContainerLayoutItem(pNode); - CXFA_WidgetAcc* pAcc = ToWidgetAcc(pNode->GetWidgetData()); + CXFA_WidgetAcc* pAcc = pNode->GetWidgetAcc(); if (!pAcc) return new CXFA_ContentLayoutItem(pNode); @@ -189,7 +183,7 @@ CXFA_LayoutItem* CXFA_FFNotify::OnCreateLayoutItem(CXFA_Node* pNode) { void CXFA_FFNotify::StartFieldDrawLayout(CXFA_Node* pItem, float& fCalcWidth, float& fCalcHeight) { - CXFA_WidgetAcc* pAcc = ToWidgetAcc(pItem->GetWidgetData()); + CXFA_WidgetAcc* pAcc = pItem->GetWidgetAcc(); if (!pAcc) return; @@ -199,7 +193,7 @@ void CXFA_FFNotify::StartFieldDrawLayout(CXFA_Node* pItem, bool CXFA_FFNotify::FindSplitPos(CXFA_Node* pItem, int32_t iBlockIndex, float& fCalcHeightPos) { - CXFA_WidgetAcc* pAcc = ToWidgetAcc(pItem->GetWidgetData()); + CXFA_WidgetAcc* pAcc = pItem->GetWidgetAcc(); return pAcc && pAcc->FindSplitPos(iBlockIndex, fCalcHeightPos); } @@ -208,7 +202,7 @@ bool CXFA_FFNotify::RunScript(CXFA_Script* pScript, CXFA_Node* pFormItem) { if (!pDocView) return false; - CXFA_WidgetAcc* pWidgetAcc = ToWidgetAcc(pFormItem->GetWidgetData()); + CXFA_WidgetAcc* pWidgetAcc = pFormItem->GetWidgetAcc(); if (!pWidgetAcc) return false; @@ -239,7 +233,7 @@ void CXFA_FFNotify::AddCalcValidate(CXFA_Node* pNode) { if (!pDocView) return; - CXFA_WidgetAcc* pWidgetAcc = ToWidgetAcc(pNode->GetWidgetData()); + CXFA_WidgetAcc* pWidgetAcc = pNode->GetWidgetAcc(); if (!pWidgetAcc) return; @@ -287,12 +281,12 @@ WideString CXFA_FFNotify::GetCurrentDateTime() { dataTime.GetSecond()); } -void CXFA_FFNotify::ResetData(CXFA_WidgetData* pWidgetData) { +void CXFA_FFNotify::ResetData(CXFA_WidgetAcc* pWidgetAcc) { CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); if (!pDocView) return; - pDocView->ResetWidgetData(ToWidgetAcc(pWidgetData)); + pDocView->ResetWidgetAcc(pWidgetAcc); } int32_t CXFA_FFNotify::GetLayoutStatus() { @@ -330,7 +324,7 @@ void CXFA_FFNotify::SetFocusWidgetNode(CXFA_Node* pNode) { if (!pDocView) return; - CXFA_WidgetAcc* pAcc = pNode ? ToWidgetAcc(pNode->GetWidgetData()) : nullptr; + CXFA_WidgetAcc* pAcc = pNode ? pNode->GetWidgetAcc() : nullptr; pDocView->SetFocusWidgetAcc(pAcc); } @@ -341,7 +335,7 @@ void CXFA_FFNotify::OnNodeReady(CXFA_Node* pNode) { XFA_Element eType = pNode->GetElementType(); if (XFA_IsCreateWidget(eType)) { - pNode->JSObject()->SetWidgetData( + pNode->JSObject()->SetWidgetAcc( pdfium::MakeUnique(pDocView, pNode)); return; } @@ -371,7 +365,7 @@ void CXFA_FFNotify::OnValueChanging(CXFA_Node* pSender, XFA_Attribute eAttr) { if (pDocView->GetLayoutStatus() < XFA_DOCVIEW_LAYOUTSTATUS_End) return; - CXFA_WidgetAcc* pWidgetAcc = ToWidgetAcc(pSender->GetWidgetData()); + CXFA_WidgetAcc* pWidgetAcc = pSender->GetWidgetAcc(); if (!pWidgetAcc) return; @@ -398,7 +392,7 @@ void CXFA_FFNotify::OnValueChanged(CXFA_Node* pSender, XFA_Element eType = pParentNode->GetElementType(); bool bIsContainerNode = pParentNode->IsContainerNode(); - CXFA_WidgetAcc* pWidgetAcc = ToWidgetAcc(pWidgetNode->GetWidgetData()); + CXFA_WidgetAcc* pWidgetAcc = pWidgetNode->GetWidgetAcc(); if (!pWidgetAcc) return; diff --git a/xfa/fxfa/cxfa_ffnotify.h b/xfa/fxfa/cxfa_ffnotify.h index 651e91f21b..35b38fd91a 100644 --- a/xfa/fxfa/cxfa_ffnotify.h +++ b/xfa/fxfa/cxfa_ffnotify.h @@ -19,11 +19,11 @@ class CXFA_FFNotify { void OnPageEvent(CXFA_ContainerLayoutItem* pSender, uint32_t dwEvent); - void OnWidgetListItemAdded(CXFA_WidgetData* pSender, + void OnWidgetListItemAdded(CXFA_WidgetAcc* pSender, const wchar_t* pLabel, const wchar_t* pValue, int32_t iIndex); - void OnWidgetListItemRemoved(CXFA_WidgetData* pSender, int32_t iIndex); + void OnWidgetListItemRemoved(CXFA_WidgetAcc* pSender, int32_t iIndex); // Node events void OnNodeReady(CXFA_Node* pNode); @@ -63,7 +63,7 @@ class CXFA_FFNotify { CXFA_FFWidget* GetHWidget(CXFA_LayoutItem* pLayoutItem); void OpenDropDownList(CXFA_FFWidget* hWidget); WideString GetCurrentDateTime(); - void ResetData(CXFA_WidgetData* pWidgetData = nullptr); + void ResetData(CXFA_WidgetAcc* pWidgetAcc = nullptr); int32_t GetLayoutStatus(); void RunNodeInitialize(CXFA_Node* pNode); void RunSubformIndexChange(CXFA_Node* pSubformNode); diff --git a/xfa/fxfa/cxfa_ffwidget.cpp b/xfa/fxfa/cxfa_ffwidget.cpp index ad0c64258b..82ed1aeffe 100644 --- a/xfa/fxfa/cxfa_ffwidget.cpp +++ b/xfa/fxfa/cxfa_ffwidget.cpp @@ -1280,7 +1280,7 @@ CXFA_FFWidget* CXFA_FFWidget::GetParent() { m_pDataAcc->GetNode()->GetNodeItem(XFA_NODEITEM_Parent); if (pParentNode) { CXFA_WidgetAcc* pParentWidgetAcc = - static_cast(pParentNode->GetWidgetData()); + static_cast(pParentNode->GetWidgetAcc()); if (pParentWidgetAcc) { return pParentWidgetAcc->GetNextWidget(nullptr); } diff --git a/xfa/fxfa/cxfa_textprovider.cpp b/xfa/fxfa/cxfa_textprovider.cpp index b32241ea35..b0c1433135 100644 --- a/xfa/fxfa/cxfa_textprovider.cpp +++ b/xfa/fxfa/cxfa_textprovider.cpp @@ -167,7 +167,7 @@ bool CXFA_TextProvider::GetEmbbedObj(bool bURI, wsAttr.AsStringView()); } if (pIDNode) - pEmbAcc = static_cast(pIDNode->GetWidgetData()); + pEmbAcc = pIDNode->GetWidgetAcc(); if (!pEmbAcc) return false; diff --git a/xfa/fxfa/cxfa_widgetacc.cpp b/xfa/fxfa/cxfa_widgetacc.cpp index 2e2807b1f0..47a9c942b0 100644 --- a/xfa/fxfa/cxfa_widgetacc.cpp +++ b/xfa/fxfa/cxfa_widgetacc.cpp @@ -9,6 +9,8 @@ #include #include +#include "core/fxcrt/cfx_decimal.h" +#include "core/fxcrt/fx_extension.h" #include "core/fxcrt/xml/cfx_xmlelement.h" #include "core/fxcrt/xml/cfx_xmlnode.h" #include "fxjs/cfxjse_engine.h" @@ -17,22 +19,33 @@ #include "xfa/fxfa/cxfa_ffapp.h" #include "xfa/fxfa/cxfa_ffdoc.h" #include "xfa/fxfa/cxfa_ffdocview.h" +#include "xfa/fxfa/cxfa_ffnotify.h" #include "xfa/fxfa/cxfa_ffwidget.h" #include "xfa/fxfa/cxfa_fontmgr.h" #include "xfa/fxfa/cxfa_textlayout.h" #include "xfa/fxfa/cxfa_textprovider.h" +#include "xfa/fxfa/parser/cxfa_bind.h" +#include "xfa/fxfa/parser/cxfa_border.h" #include "xfa/fxfa/parser/cxfa_calculate.h" #include "xfa/fxfa/parser/cxfa_caption.h" +#include "xfa/fxfa/parser/cxfa_comb.h" +#include "xfa/fxfa/parser/cxfa_decimal.h" +#include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_event.h" #include "xfa/fxfa/parser/cxfa_font.h" +#include "xfa/fxfa/parser/cxfa_format.h" #include "xfa/fxfa/parser/cxfa_image.h" #include "xfa/fxfa/parser/cxfa_items.h" #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" #include "xfa/fxfa/parser/cxfa_localevalue.h" #include "xfa/fxfa/parser/cxfa_margin.h" +#include "xfa/fxfa/parser/cxfa_measurement.h" #include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/cxfa_para.h" +#include "xfa/fxfa/parser/cxfa_picture.h" #include "xfa/fxfa/parser/cxfa_script.h" +#include "xfa/fxfa/parser/cxfa_stroke.h" +#include "xfa/fxfa/parser/cxfa_ui.h" #include "xfa/fxfa/parser/cxfa_validate.h" #include "xfa/fxfa/parser/cxfa_value.h" #include "xfa/fxfa/parser/xfa_utils.h" @@ -157,12 +170,203 @@ class CXFA_ImageEditData : public CXFA_FieldLayoutData { int32_t m_iImageYDpi; }; +float GetEdgeThickness(const std::vector& strokes, + bool b3DStyle, + int32_t nIndex) { + float fThickness = 0; + + CXFA_Stroke* stroke = strokes[nIndex * 2 + 1]; + if (stroke->IsVisible()) { + if (nIndex == 0) + fThickness += 2.5f; + + fThickness += stroke->GetThickness() * (b3DStyle ? 4 : 2); + } + return fThickness; +} + +bool SplitDateTime(const WideString& wsDateTime, + WideString& wsDate, + WideString& wsTime) { + wsDate = L""; + wsTime = L""; + if (wsDateTime.IsEmpty()) + return false; + + auto nSplitIndex = wsDateTime.Find('T'); + if (!nSplitIndex.has_value()) + nSplitIndex = wsDateTime.Find(' '); + if (!nSplitIndex.has_value()) + return false; + + wsDate = wsDateTime.Left(nSplitIndex.value()); + if (!wsDate.IsEmpty()) { + if (!std::any_of(wsDate.begin(), wsDate.end(), std::iswdigit)) + return false; + } + wsTime = wsDateTime.Right(wsDateTime.GetLength() - nSplitIndex.value() - 1); + if (!wsTime.IsEmpty()) { + if (!std::any_of(wsTime.begin(), wsTime.end(), std::iswdigit)) + return false; + } + return true; +} + +CXFA_Node* CreateUIChild(CXFA_Node* pNode, XFA_Element& eWidgetType) { + XFA_Element eType = pNode->GetElementType(); + eWidgetType = eType; + if (eType != XFA_Element::Field && eType != XFA_Element::Draw) + return nullptr; + + eWidgetType = XFA_Element::Unknown; + XFA_Element eUIType = XFA_Element::Unknown; + auto* defValue = + pNode->JSObject()->GetProperty(0, XFA_Element::Value, true); + XFA_Element eValueType = + defValue ? defValue->GetChildValueClassID() : XFA_Element::Unknown; + switch (eValueType) { + case XFA_Element::Boolean: + eUIType = XFA_Element::CheckButton; + break; + case XFA_Element::Integer: + case XFA_Element::Decimal: + case XFA_Element::Float: + eUIType = XFA_Element::NumericEdit; + break; + case XFA_Element::ExData: + case XFA_Element::Text: + eUIType = XFA_Element::TextEdit; + eWidgetType = XFA_Element::Text; + break; + case XFA_Element::Date: + case XFA_Element::Time: + case XFA_Element::DateTime: + eUIType = XFA_Element::DateTimeEdit; + break; + case XFA_Element::Image: + eUIType = XFA_Element::ImageEdit; + eWidgetType = XFA_Element::Image; + break; + case XFA_Element::Arc: + case XFA_Element::Line: + case XFA_Element::Rectangle: + eUIType = XFA_Element::DefaultUi; + eWidgetType = eValueType; + break; + default: + break; + } + + CXFA_Node* pUIChild = nullptr; + CXFA_Ui* pUI = + pNode->JSObject()->GetProperty(0, XFA_Element::Ui, true); + CXFA_Node* pChild = pUI->GetNodeItem(XFA_NODEITEM_FirstChild); + for (; pChild; pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { + XFA_Element eChildType = pChild->GetElementType(); + if (eChildType == XFA_Element::Extras || + eChildType == XFA_Element::Picture) { + continue; + } + + auto node = CXFA_Node::Create(pChild->GetDocument(), XFA_Element::Ui, + XFA_PacketType::Form); + if (node && node->HasPropertyFlags(eChildType, XFA_PROPERTYFLAG_OneOf)) { + pUIChild = pChild; + break; + } + } + + if (eType == XFA_Element::Draw) { + XFA_Element eDraw = + pUIChild ? pUIChild->GetElementType() : XFA_Element::Unknown; + switch (eDraw) { + case XFA_Element::TextEdit: + eWidgetType = XFA_Element::Text; + break; + case XFA_Element::ImageEdit: + eWidgetType = XFA_Element::Image; + break; + default: + eWidgetType = eWidgetType == XFA_Element::Unknown ? XFA_Element::Text + : eWidgetType; + break; + } + } else { + if (pUIChild && pUIChild->GetElementType() == XFA_Element::DefaultUi) { + eWidgetType = XFA_Element::TextEdit; + } else { + eWidgetType = + pUIChild ? pUIChild->GetElementType() + : (eUIType == XFA_Element::Unknown ? XFA_Element::TextEdit + : eUIType); + } + } + + if (!pUIChild) { + if (eUIType == XFA_Element::Unknown) { + eUIType = XFA_Element::TextEdit; + defValue->JSObject()->GetProperty(0, XFA_Element::Text, true); + } + return pUI->JSObject()->GetProperty(0, eUIType, true); + } + + if (eUIType != XFA_Element::Unknown) + return pUIChild; + + switch (pUIChild->GetElementType()) { + case XFA_Element::CheckButton: { + eValueType = XFA_Element::Text; + if (CXFA_Items* pItems = + pNode->GetChild(0, XFA_Element::Items, false)) { + if (CXFA_Node* pItem = + pItems->GetChild(0, XFA_Element::Unknown, false)) { + eValueType = pItem->GetElementType(); + } + } + break; + } + case XFA_Element::DateTimeEdit: + eValueType = XFA_Element::DateTime; + break; + case XFA_Element::ImageEdit: + eValueType = XFA_Element::Image; + break; + case XFA_Element::NumericEdit: + eValueType = XFA_Element::Float; + break; + case XFA_Element::ChoiceList: { + eValueType = (pUIChild->JSObject()->GetEnum(XFA_Attribute::Open) == + XFA_AttributeEnum::MultiSelect) + ? XFA_Element::ExData + : XFA_Element::Text; + break; + } + case XFA_Element::Barcode: + case XFA_Element::Button: + case XFA_Element::PasswordEdit: + case XFA_Element::Signature: + case XFA_Element::TextEdit: + default: + eValueType = XFA_Element::Text; + break; + } + defValue->JSObject()->GetProperty(0, eValueType, true); + + return pUIChild; +} + } // namespace CXFA_WidgetAcc::CXFA_WidgetAcc(CXFA_FFDocView* pDocView, CXFA_Node* pNode) - : CXFA_WidgetData(pNode), m_pDocView(pDocView), m_nRecursionDepth(0) {} + : m_pDocView(pDocView), + m_nRecursionDepth(0), + m_bIsNull(true), + m_bPreNull(true), + m_pUiChildNode(nullptr), + m_eUIType(XFA_Element::Unknown), + m_pNode(pNode) {} -CXFA_WidgetAcc::~CXFA_WidgetAcc() {} +CXFA_WidgetAcc::~CXFA_WidgetAcc() = default; XFA_Element CXFA_WidgetAcc::GetElementType() const { return m_pNode ? m_pNode->GetElementType() : XFA_Element::Unknown; @@ -201,8 +405,7 @@ void CXFA_WidgetAcc::ResetData() { XFA_NODEITEM_FirstChild, XFA_ObjectType::ContainerNode); while (pNextChild) { CXFA_Node* pChild = pNextChild; - CXFA_WidgetAcc* pAcc = - static_cast(pChild->GetWidgetData()); + CXFA_WidgetAcc* pAcc = pChild->GetWidgetAcc(); if (!pAcc) continue; @@ -282,7 +485,7 @@ CXFA_WidgetAcc* CXFA_WidgetAcc::GetExclGroup() { CXFA_Node* pExcl = m_pNode->GetNodeItem(XFA_NODEITEM_Parent); if (!pExcl || pExcl->GetElementType() != XFA_Element::ExclGroup) return nullptr; - return static_cast(pExcl->GetWidgetData()); + return pExcl->GetWidgetAcc(); } CXFA_FFDoc* CXFA_WidgetAcc::GetDoc() { @@ -649,7 +852,7 @@ std::pair CXFA_WidgetAcc::ExecuteBoolScript( } } for (CXFA_Node* pRefNode : refNodes) { - if (static_cast(pRefNode->GetWidgetData()) == this) + if (pRefNode->GetWidgetAcc() == this) continue; CXFA_CalcData* pGlobalData = pRefNode->JSObject()->GetCalcData(); @@ -1524,3 +1727,1552 @@ FX_ARGB CXFA_WidgetAcc::GetTextColor() { CXFA_Font* font = GetFont(false); return font ? font->GetColor() : 0xFF000000; } + +CXFA_Node* CXFA_WidgetAcc::GetUIChild() { + if (m_eUIType == XFA_Element::Unknown) + m_pUiChildNode = CreateUIChild(m_pNode, m_eUIType); + + return m_pUiChildNode; +} + +XFA_Element CXFA_WidgetAcc::GetUIType() { + GetUIChild(); + return m_eUIType; +} + +WideString CXFA_WidgetAcc::GetRawValue() const { + return m_pNode->JSObject()->GetContent(false); +} + +bool CXFA_WidgetAcc::IsOpenAccess() const { + for (CXFA_Node* pNode = m_pNode; pNode; + pNode = pNode->GetNodeItem(XFA_NODEITEM_Parent, + XFA_ObjectType::ContainerNode)) { + XFA_AttributeEnum iAcc = pNode->JSObject()->GetEnum(XFA_Attribute::Access); + if (iAcc != XFA_AttributeEnum::Open) + return false; + } + return true; +} + +int32_t CXFA_WidgetAcc::GetRotate() const { + pdfium::Optional degrees = + m_pNode->JSObject()->TryInteger(XFA_Attribute::Rotate, false); + return degrees ? XFA_MapRotation(*degrees) / 90 * 90 : 0; +} + +CXFA_Border* CXFA_WidgetAcc::GetBorder(bool bModified) { + return m_pNode->JSObject()->GetProperty(0, XFA_Element::Border, + bModified); +} + +CXFA_Caption* CXFA_WidgetAcc::GetCaption() { + return m_pNode->JSObject()->GetProperty(0, XFA_Element::Caption, + false); +} + +CXFA_Font* CXFA_WidgetAcc::GetFont(bool bModified) { + return m_pNode->JSObject()->GetProperty(0, XFA_Element::Font, + bModified); +} + +CXFA_Margin* CXFA_WidgetAcc::GetMargin() { + return m_pNode->JSObject()->GetProperty(0, XFA_Element::Margin, + false); +} + +CXFA_Para* CXFA_WidgetAcc::GetPara() { + return m_pNode->JSObject()->GetProperty(0, XFA_Element::Para, + false); +} + +std::vector CXFA_WidgetAcc::GetEventByActivity( + XFA_AttributeEnum iActivity, + bool bIsFormReady) { + std::vector events; + for (CXFA_Node* node : m_pNode->GetNodeList(0, XFA_Element::Event)) { + auto* event = static_cast(node); + if (event->GetActivity() == iActivity) { + if (iActivity == XFA_AttributeEnum::Ready) { + WideString wsRef = event->GetRef(); + if (bIsFormReady) { + if (wsRef == WideStringView(L"$form")) + events.push_back(event); + } else { + if (wsRef == WideStringView(L"$layout")) + events.push_back(event); + } + } else { + events.push_back(event); + } + } + } + return events; +} + +CXFA_Value* CXFA_WidgetAcc::GetDefaultValue() { + CXFA_Node* pTemNode = m_pNode->GetTemplateNode(); + return pTemNode->JSObject()->GetProperty(0, XFA_Element::Value, + false); +} + +CXFA_Value* CXFA_WidgetAcc::GetFormValue() { + return m_pNode->JSObject()->GetProperty(0, XFA_Element::Value, + false); +} + +CXFA_Calculate* CXFA_WidgetAcc::GetCalculate() { + return m_pNode->JSObject()->GetProperty( + 0, XFA_Element::Calculate, false); +} + +CXFA_Validate* CXFA_WidgetAcc::GetValidate(bool bModified) { + return m_pNode->JSObject()->GetProperty( + 0, XFA_Element::Validate, bModified); +} + +CXFA_Bind* CXFA_WidgetAcc::GetBind() { + return m_pNode->JSObject()->GetProperty(0, XFA_Element::Bind, + false); +} + +pdfium::Optional CXFA_WidgetAcc::TryWidth() { + return m_pNode->JSObject()->TryMeasureAsFloat(XFA_Attribute::W); +} + +pdfium::Optional CXFA_WidgetAcc::TryHeight() { + return m_pNode->JSObject()->TryMeasureAsFloat(XFA_Attribute::H); +} + +pdfium::Optional CXFA_WidgetAcc::TryMinWidth() { + return m_pNode->JSObject()->TryMeasureAsFloat(XFA_Attribute::MinW); +} + +pdfium::Optional CXFA_WidgetAcc::TryMinHeight() { + return m_pNode->JSObject()->TryMeasureAsFloat(XFA_Attribute::MinH); +} + +pdfium::Optional CXFA_WidgetAcc::TryMaxWidth() { + return m_pNode->JSObject()->TryMeasureAsFloat(XFA_Attribute::MaxW); +} + +pdfium::Optional CXFA_WidgetAcc::TryMaxHeight() { + return m_pNode->JSObject()->TryMeasureAsFloat(XFA_Attribute::MaxH); +} + +CXFA_Border* CXFA_WidgetAcc::GetUIBorder() { + CXFA_Node* pUIChild = GetUIChild(); + return pUIChild ? pUIChild->JSObject()->GetProperty( + 0, XFA_Element::Border, false) + : nullptr; +} + +CFX_RectF CXFA_WidgetAcc::GetUIMargin() { + CXFA_Node* pUIChild = GetUIChild(); + CXFA_Margin* mgUI = nullptr; + if (pUIChild) { + mgUI = pUIChild->JSObject()->GetProperty( + 0, XFA_Element::Margin, false); + } + + if (!mgUI) + return CFX_RectF(); + + CXFA_Border* border = GetUIBorder(); + if (border && border->GetPresence() != XFA_AttributeEnum::Visible) + return CFX_RectF(); + + pdfium::Optional left = mgUI->TryLeftInset(); + pdfium::Optional top = mgUI->TryTopInset(); + pdfium::Optional right = mgUI->TryRightInset(); + pdfium::Optional bottom = mgUI->TryBottomInset(); + if (border) { + bool bVisible = false; + float fThickness = 0; + XFA_AttributeEnum iType = XFA_AttributeEnum::Unknown; + std::tie(iType, bVisible, fThickness) = border->Get3DStyle(); + if (!left || !top || !right || !bottom) { + std::vector strokes = border->GetStrokes(); + if (!top) + top = GetEdgeThickness(strokes, bVisible, 0); + if (!right) + right = GetEdgeThickness(strokes, bVisible, 1); + if (!bottom) + bottom = GetEdgeThickness(strokes, bVisible, 2); + if (!left) + left = GetEdgeThickness(strokes, bVisible, 3); + } + } + return CFX_RectF(left.value_or(0.0), top.value_or(0.0), right.value_or(0.0), + bottom.value_or(0.0)); +} + +XFA_AttributeEnum CXFA_WidgetAcc::GetButtonHighlight() { + CXFA_Node* pUIChild = GetUIChild(); + if (pUIChild) + return pUIChild->JSObject()->GetEnum(XFA_Attribute::Highlight); + return XFA_AttributeEnum::Inverted; +} + +bool CXFA_WidgetAcc::HasButtonRollover() const { + CXFA_Items* pItems = + m_pNode->GetChild(0, XFA_Element::Items, false); + if (!pItems) + return false; + + for (CXFA_Node* pText = pItems->GetNodeItem(XFA_NODEITEM_FirstChild); pText; + pText = pText->GetNodeItem(XFA_NODEITEM_NextSibling)) { + if (pText->JSObject()->GetCData(XFA_Attribute::Name) == L"rollover") + return !pText->JSObject()->GetContent(false).IsEmpty(); + } + return false; +} + +bool CXFA_WidgetAcc::HasButtonDown() const { + CXFA_Items* pItems = + m_pNode->GetChild(0, XFA_Element::Items, false); + if (!pItems) + return false; + + for (CXFA_Node* pText = pItems->GetNodeItem(XFA_NODEITEM_FirstChild); pText; + pText = pText->GetNodeItem(XFA_NODEITEM_NextSibling)) { + if (pText->JSObject()->GetCData(XFA_Attribute::Name) == L"down") + return !pText->JSObject()->GetContent(false).IsEmpty(); + } + return false; +} + +bool CXFA_WidgetAcc::IsCheckButtonRound() { + CXFA_Node* pUIChild = GetUIChild(); + if (pUIChild) + return pUIChild->JSObject()->GetEnum(XFA_Attribute::Shape) == + XFA_AttributeEnum::Round; + return false; +} + +XFA_AttributeEnum CXFA_WidgetAcc::GetCheckButtonMark() { + CXFA_Node* pUIChild = GetUIChild(); + if (pUIChild) + return pUIChild->JSObject()->GetEnum(XFA_Attribute::Mark); + return XFA_AttributeEnum::Default; +} + +bool CXFA_WidgetAcc::IsRadioButton() { + CXFA_Node* pParent = m_pNode->GetNodeItem(XFA_NODEITEM_Parent); + return pParent && pParent->GetElementType() == XFA_Element::ExclGroup; +} + +float CXFA_WidgetAcc::GetCheckButtonSize() { + CXFA_Node* pUIChild = GetUIChild(); + if (pUIChild) { + return pUIChild->JSObject() + ->GetMeasure(XFA_Attribute::Size) + .ToUnit(XFA_Unit::Pt); + } + return CXFA_Measurement(10, XFA_Unit::Pt).ToUnit(XFA_Unit::Pt); +} + +bool CXFA_WidgetAcc::IsAllowNeutral() { + CXFA_Node* pUIChild = GetUIChild(); + return pUIChild && + pUIChild->JSObject()->GetBoolean(XFA_Attribute::AllowNeutral); +} + +XFA_CHECKSTATE CXFA_WidgetAcc::GetCheckState() { + WideString wsValue = GetRawValue(); + if (wsValue.IsEmpty()) + return XFA_CHECKSTATE_Off; + + auto* pItems = m_pNode->GetChild(0, XFA_Element::Items, false); + if (!pItems) + return XFA_CHECKSTATE_Off; + + CXFA_Node* pText = pItems->GetNodeItem(XFA_NODEITEM_FirstChild); + int32_t i = 0; + while (pText) { + pdfium::Optional wsContent = + pText->JSObject()->TryContent(false, true); + if (wsContent && *wsContent == wsValue) + return static_cast(i); + + i++; + pText = pText->GetNodeItem(XFA_NODEITEM_NextSibling); + } + return XFA_CHECKSTATE_Off; +} + +void CXFA_WidgetAcc::SetCheckState(XFA_CHECKSTATE eCheckState, bool bNotify) { + CXFA_Node* node = GetExclGroupNode(); + if (!node) { + CXFA_Items* pItems = + m_pNode->GetChild(0, XFA_Element::Items, false); + if (!pItems) + return; + + int32_t i = -1; + CXFA_Node* pText = pItems->GetNodeItem(XFA_NODEITEM_FirstChild); + WideString wsContent; + while (pText) { + i++; + if (i == eCheckState) { + wsContent = pText->JSObject()->GetContent(false); + break; + } + pText = pText->GetNodeItem(XFA_NODEITEM_NextSibling); + } + if (m_pNode) + m_pNode->SyncValue(wsContent, bNotify); + return; + } + + WideString wsValue; + if (eCheckState != XFA_CHECKSTATE_Off) { + if (CXFA_Items* pItems = + m_pNode->GetChild(0, XFA_Element::Items, false)) { + CXFA_Node* pText = pItems->GetNodeItem(XFA_NODEITEM_FirstChild); + if (pText) + wsValue = pText->JSObject()->GetContent(false); + } + } + CXFA_Node* pChild = node->GetNodeItem(XFA_NODEITEM_FirstChild); + for (; pChild; pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { + if (pChild->GetElementType() != XFA_Element::Field) + continue; + + CXFA_Items* pItem = + pChild->GetChild(0, XFA_Element::Items, false); + if (!pItem) + continue; + + CXFA_Node* pItemchild = pItem->GetNodeItem(XFA_NODEITEM_FirstChild); + if (!pItemchild) + continue; + + WideString text = pItemchild->JSObject()->GetContent(false); + WideString wsChildValue = text; + if (wsValue != text) { + pItemchild = pItemchild->GetNodeItem(XFA_NODEITEM_NextSibling); + if (pItemchild) + wsChildValue = pItemchild->JSObject()->GetContent(false); + else + wsChildValue.clear(); + } + pChild->SyncValue(wsChildValue, bNotify); + } + node->SyncValue(wsValue, bNotify); +} + +CXFA_Node* CXFA_WidgetAcc::GetExclGroupNode() { + CXFA_Node* pExcl = ToNode(m_pNode->GetNodeItem(XFA_NODEITEM_Parent)); + if (!pExcl || pExcl->GetElementType() != XFA_Element::ExclGroup) + return nullptr; + return pExcl; +} + +CXFA_Node* CXFA_WidgetAcc::GetSelectedMember() { + CXFA_Node* pSelectedMember = nullptr; + WideString wsState = GetRawValue(); + if (wsState.IsEmpty()) + return pSelectedMember; + + for (CXFA_Node* pNode = ToNode(m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild)); + pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { + CXFA_WidgetAcc widgetData(nullptr, pNode); + if (widgetData.GetCheckState() == XFA_CHECKSTATE_On) { + pSelectedMember = pNode; + break; + } + } + return pSelectedMember; +} + +CXFA_Node* CXFA_WidgetAcc::SetSelectedMember(const WideStringView& wsName, + bool bNotify) { + uint32_t nameHash = FX_HashCode_GetW(wsName, false); + for (CXFA_Node* pNode = ToNode(m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild)); + pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { + if (pNode->GetNameHash() == nameHash) { + CXFA_WidgetAcc widgetData(nullptr, pNode); + widgetData.SetCheckState(XFA_CHECKSTATE_On, bNotify); + return pNode; + } + } + return nullptr; +} + +void CXFA_WidgetAcc::SetSelectedMemberByValue(const WideStringView& wsValue, + bool bNotify, + bool bScriptModify, + bool bSyncData) { + WideString wsExclGroup; + for (CXFA_Node* pNode = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); pNode; + pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { + if (pNode->GetElementType() != XFA_Element::Field) + continue; + + CXFA_Items* pItem = + pNode->GetChild(0, XFA_Element::Items, false); + if (!pItem) + continue; + + CXFA_Node* pItemchild = pItem->GetNodeItem(XFA_NODEITEM_FirstChild); + if (!pItemchild) + continue; + + WideString wsChildValue = pItemchild->JSObject()->GetContent(false); + if (wsValue != wsChildValue) { + pItemchild = pItemchild->GetNodeItem(XFA_NODEITEM_NextSibling); + if (pItemchild) + wsChildValue = pItemchild->JSObject()->GetContent(false); + else + wsChildValue.clear(); + } else { + wsExclGroup = wsValue; + } + pNode->JSObject()->SetContent(wsChildValue, wsChildValue, bNotify, + bScriptModify, false); + } + if (m_pNode) { + m_pNode->JSObject()->SetContent(wsExclGroup, wsExclGroup, bNotify, + bScriptModify, bSyncData); + } +} + +CXFA_Node* CXFA_WidgetAcc::GetExclGroupFirstMember() { + CXFA_Node* pExcl = GetNode(); + if (!pExcl) + return nullptr; + + CXFA_Node* pNode = pExcl->GetNodeItem(XFA_NODEITEM_FirstChild); + while (pNode) { + if (pNode->GetElementType() == XFA_Element::Field) + return pNode; + + pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling); + } + return nullptr; +} +CXFA_Node* CXFA_WidgetAcc::GetExclGroupNextMember(CXFA_Node* pNode) { + if (!pNode) + return nullptr; + + CXFA_Node* pNodeField = pNode->GetNodeItem(XFA_NODEITEM_NextSibling); + while (pNodeField) { + if (pNodeField->GetElementType() == XFA_Element::Field) + return pNodeField; + + pNodeField = pNodeField->GetNodeItem(XFA_NODEITEM_NextSibling); + } + return nullptr; +} + +bool CXFA_WidgetAcc::IsChoiceListCommitOnSelect() { + CXFA_Node* pUIChild = GetUIChild(); + if (pUIChild) { + return pUIChild->JSObject()->GetEnum(XFA_Attribute::CommitOn) == + XFA_AttributeEnum::Select; + } + return true; +} + +bool CXFA_WidgetAcc::IsChoiceListAllowTextEntry() { + CXFA_Node* pUIChild = GetUIChild(); + return pUIChild && pUIChild->JSObject()->GetBoolean(XFA_Attribute::TextEntry); +} + +bool CXFA_WidgetAcc::IsChoiceListMultiSelect() { + CXFA_Node* pUIChild = GetUIChild(); + if (pUIChild) { + return pUIChild->JSObject()->GetEnum(XFA_Attribute::Open) == + XFA_AttributeEnum::MultiSelect; + } + return false; +} + +bool CXFA_WidgetAcc::IsListBox() { + CXFA_Node* pUIChild = GetUIChild(); + if (!pUIChild) + return false; + + XFA_AttributeEnum attr = pUIChild->JSObject()->GetEnum(XFA_Attribute::Open); + return attr == XFA_AttributeEnum::Always || + attr == XFA_AttributeEnum::MultiSelect; +} + +int32_t CXFA_WidgetAcc::CountChoiceListItems(bool bSaveValue) { + std::vector pItems; + int32_t iCount = 0; + for (CXFA_Node* pNode = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); pNode; + pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { + if (pNode->GetElementType() != XFA_Element::Items) + continue; + iCount++; + pItems.push_back(pNode); + if (iCount == 2) + break; + } + if (iCount == 0) + return 0; + + CXFA_Node* pItem = pItems[0]; + if (iCount > 1) { + bool bItemOneHasSave = + pItems[0]->JSObject()->GetBoolean(XFA_Attribute::Save); + bool bItemTwoHasSave = + pItems[1]->JSObject()->GetBoolean(XFA_Attribute::Save); + if (bItemOneHasSave != bItemTwoHasSave && bSaveValue == bItemTwoHasSave) + pItem = pItems[1]; + } + return pItem->CountChildren(XFA_Element::Unknown, false); +} + +pdfium::Optional CXFA_WidgetAcc::GetChoiceListItem( + int32_t nIndex, + bool bSaveValue) { + std::vector pItemsArray; + int32_t iCount = 0; + for (CXFA_Node* pNode = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); pNode; + pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { + if (pNode->GetElementType() != XFA_Element::Items) + continue; + + ++iCount; + pItemsArray.push_back(pNode); + if (iCount == 2) + break; + } + if (iCount == 0) + return {}; + + CXFA_Node* pItems = pItemsArray[0]; + if (iCount > 1) { + bool bItemOneHasSave = + pItemsArray[0]->JSObject()->GetBoolean(XFA_Attribute::Save); + bool bItemTwoHasSave = + pItemsArray[1]->JSObject()->GetBoolean(XFA_Attribute::Save); + if (bItemOneHasSave != bItemTwoHasSave && bSaveValue == bItemTwoHasSave) + pItems = pItemsArray[1]; + } + if (!pItems) + return {}; + + CXFA_Node* pItem = + pItems->GetChild(nIndex, XFA_Element::Unknown, false); + if (pItem) + return {pItem->JSObject()->GetContent(false)}; + return {}; +} + +std::vector CXFA_WidgetAcc::GetChoiceListItems(bool bSaveValue) { + std::vector items; + for (CXFA_Node* pNode = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); + pNode && items.size() < 2; + pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { + if (pNode->GetElementType() == XFA_Element::Items) + items.push_back(pNode); + } + if (items.empty()) + return std::vector(); + + CXFA_Node* pItem = items.front(); + if (items.size() > 1) { + bool bItemOneHasSave = + items[0]->JSObject()->GetBoolean(XFA_Attribute::Save); + bool bItemTwoHasSave = + items[1]->JSObject()->GetBoolean(XFA_Attribute::Save); + if (bItemOneHasSave != bItemTwoHasSave && bSaveValue == bItemTwoHasSave) + pItem = items[1]; + } + + std::vector wsTextArray; + for (CXFA_Node* pNode = pItem->GetNodeItem(XFA_NODEITEM_FirstChild); pNode; + pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { + wsTextArray.emplace_back(pNode->JSObject()->GetContent(false)); + } + return wsTextArray; +} + +int32_t CXFA_WidgetAcc::CountSelectedItems() { + std::vector wsValueArray = GetSelectedItemsValue(); + if (IsListBox() || !IsChoiceListAllowTextEntry()) + return pdfium::CollectionSize(wsValueArray); + + int32_t iSelected = 0; + std::vector wsSaveTextArray = GetChoiceListItems(true); + for (const auto& value : wsValueArray) { + if (pdfium::ContainsValue(wsSaveTextArray, value)) + iSelected++; + } + return iSelected; +} + +int32_t CXFA_WidgetAcc::GetSelectedItem(int32_t nIndex) { + std::vector wsValueArray = GetSelectedItemsValue(); + if (!pdfium::IndexInBounds(wsValueArray, nIndex)) + return -1; + + std::vector wsSaveTextArray = GetChoiceListItems(true); + auto it = std::find(wsSaveTextArray.begin(), wsSaveTextArray.end(), + wsValueArray[nIndex]); + return it != wsSaveTextArray.end() ? it - wsSaveTextArray.begin() : -1; +} + +std::vector CXFA_WidgetAcc::GetSelectedItems() { + std::vector iSelArray; + std::vector wsValueArray = GetSelectedItemsValue(); + std::vector wsSaveTextArray = GetChoiceListItems(true); + for (const auto& value : wsValueArray) { + auto it = std::find(wsSaveTextArray.begin(), wsSaveTextArray.end(), value); + if (it != wsSaveTextArray.end()) + iSelArray.push_back(it - wsSaveTextArray.begin()); + } + return iSelArray; +} + +std::vector CXFA_WidgetAcc::GetSelectedItemsValue() { + std::vector wsSelTextArray; + WideString wsValue = GetRawValue(); + if (IsChoiceListMultiSelect()) { + if (!wsValue.IsEmpty()) { + size_t iStart = 0; + size_t iLength = wsValue.GetLength(); + auto iEnd = wsValue.Find(L'\n', iStart); + iEnd = (!iEnd.has_value()) ? iLength : iEnd; + while (iEnd >= iStart) { + wsSelTextArray.push_back(wsValue.Mid(iStart, iEnd.value() - iStart)); + iStart = iEnd.value() + 1; + if (iStart >= iLength) + break; + iEnd = wsValue.Find(L'\n', iStart); + if (!iEnd.has_value()) + wsSelTextArray.push_back(wsValue.Mid(iStart, iLength - iStart)); + } + } + } else { + wsSelTextArray.push_back(wsValue); + } + return wsSelTextArray; +} + +bool CXFA_WidgetAcc::GetItemState(int32_t nIndex) { + std::vector wsSaveTextArray = GetChoiceListItems(true); + return pdfium::IndexInBounds(wsSaveTextArray, nIndex) && + pdfium::ContainsValue(GetSelectedItemsValue(), + wsSaveTextArray[nIndex]); +} + +void CXFA_WidgetAcc::SetItemState(int32_t nIndex, + bool bSelected, + bool bNotify, + bool bScriptModify, + bool bSyncData) { + std::vector wsSaveTextArray = GetChoiceListItems(true); + if (!pdfium::IndexInBounds(wsSaveTextArray, nIndex)) + return; + + int32_t iSel = -1; + std::vector wsValueArray = GetSelectedItemsValue(); + auto it = std::find(wsValueArray.begin(), wsValueArray.end(), + wsSaveTextArray[nIndex]); + if (it != wsValueArray.end()) + iSel = it - wsValueArray.begin(); + + if (IsChoiceListMultiSelect()) { + if (bSelected) { + if (iSel < 0) { + WideString wsValue = GetRawValue(); + if (!wsValue.IsEmpty()) { + wsValue += L"\n"; + } + wsValue += wsSaveTextArray[nIndex]; + m_pNode->JSObject()->SetContent(wsValue, wsValue, bNotify, + bScriptModify, bSyncData); + } + } else if (iSel >= 0) { + std::vector iSelArray = GetSelectedItems(); + auto it = std::find(iSelArray.begin(), iSelArray.end(), nIndex); + if (it != iSelArray.end()) + iSelArray.erase(it); + SetSelectedItems(iSelArray, bNotify, bScriptModify, bSyncData); + } + } else { + if (bSelected) { + if (iSel < 0) { + WideString wsSaveText = wsSaveTextArray[nIndex]; + m_pNode->JSObject()->SetContent(wsSaveText, + GetFormatDataValue(wsSaveText), bNotify, + bScriptModify, bSyncData); + } + } else if (iSel >= 0) { + m_pNode->JSObject()->SetContent(WideString(), WideString(), bNotify, + bScriptModify, bSyncData); + } + } +} + +void CXFA_WidgetAcc::SetSelectedItems(const std::vector& iSelArray, + bool bNotify, + bool bScriptModify, + bool bSyncData) { + WideString wsValue; + int32_t iSize = pdfium::CollectionSize(iSelArray); + if (iSize >= 1) { + std::vector wsSaveTextArray = GetChoiceListItems(true); + WideString wsItemValue; + for (int32_t i = 0; i < iSize; i++) { + wsItemValue = (iSize == 1) ? wsSaveTextArray[iSelArray[i]] + : wsSaveTextArray[iSelArray[i]] + L"\n"; + wsValue += wsItemValue; + } + } + WideString wsFormat(wsValue); + if (!IsChoiceListMultiSelect()) + wsFormat = GetFormatDataValue(wsValue); + + m_pNode->JSObject()->SetContent(wsValue, wsFormat, bNotify, bScriptModify, + bSyncData); +} + +void CXFA_WidgetAcc::ClearAllSelections() { + CXFA_Node* pBind = m_pNode->GetBindData(); + if (!pBind || !IsChoiceListMultiSelect()) { + m_pNode->SyncValue(WideString(), false); + return; + } + + while (CXFA_Node* pChildNode = pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) + pBind->RemoveChild(pChildNode, true); +} + +void CXFA_WidgetAcc::InsertItem(const WideString& wsLabel, + const WideString& wsValue, + bool bNotify) { + int32_t nIndex = -1; + WideString wsNewValue(wsValue); + if (wsNewValue.IsEmpty()) + wsNewValue = wsLabel; + + std::vector listitems; + for (CXFA_Node* pItem = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); pItem; + pItem = pItem->GetNodeItem(XFA_NODEITEM_NextSibling)) { + if (pItem->GetElementType() == XFA_Element::Items) + listitems.push_back(pItem); + } + if (listitems.empty()) { + CXFA_Node* pItems = m_pNode->CreateSamePacketNode(XFA_Element::Items); + m_pNode->InsertChild(-1, pItems); + InsertListTextItem(pItems, wsLabel, nIndex); + CXFA_Node* pSaveItems = m_pNode->CreateSamePacketNode(XFA_Element::Items); + m_pNode->InsertChild(-1, pSaveItems); + pSaveItems->JSObject()->SetBoolean(XFA_Attribute::Save, true, false); + InsertListTextItem(pSaveItems, wsNewValue, nIndex); + } else if (listitems.size() > 1) { + for (int32_t i = 0; i < 2; i++) { + CXFA_Node* pNode = listitems[i]; + bool bHasSave = pNode->JSObject()->GetBoolean(XFA_Attribute::Save); + if (bHasSave) + InsertListTextItem(pNode, wsNewValue, nIndex); + else + InsertListTextItem(pNode, wsLabel, nIndex); + } + } else { + CXFA_Node* pNode = listitems[0]; + pNode->JSObject()->SetBoolean(XFA_Attribute::Save, false, false); + pNode->JSObject()->SetEnum(XFA_Attribute::Presence, + XFA_AttributeEnum::Visible, false); + CXFA_Node* pSaveItems = m_pNode->CreateSamePacketNode(XFA_Element::Items); + m_pNode->InsertChild(-1, pSaveItems); + pSaveItems->JSObject()->SetBoolean(XFA_Attribute::Save, true, false); + pSaveItems->JSObject()->SetEnum(XFA_Attribute::Presence, + XFA_AttributeEnum::Hidden, false); + CXFA_Node* pListNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); + int32_t i = 0; + while (pListNode) { + InsertListTextItem(pSaveItems, pListNode->JSObject()->GetContent(false), + i); + ++i; + + pListNode = pListNode->GetNodeItem(XFA_NODEITEM_NextSibling); + } + InsertListTextItem(pNode, wsLabel, nIndex); + InsertListTextItem(pSaveItems, wsNewValue, nIndex); + } + if (!bNotify) + return; + + m_pNode->GetDocument()->GetNotify()->OnWidgetListItemAdded( + this, wsLabel.c_str(), wsValue.c_str(), nIndex); +} + +void CXFA_WidgetAcc::GetItemLabel(const WideStringView& wsValue, + WideString& wsLabel) { + int32_t iCount = 0; + std::vector listitems; + CXFA_Node* pItems = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); + for (; pItems; pItems = pItems->GetNodeItem(XFA_NODEITEM_NextSibling)) { + if (pItems->GetElementType() != XFA_Element::Items) + continue; + iCount++; + listitems.push_back(pItems); + } + + if (iCount <= 1) { + wsLabel = wsValue; + return; + } + + CXFA_Node* pLabelItems = listitems[0]; + bool bSave = pLabelItems->JSObject()->GetBoolean(XFA_Attribute::Save); + CXFA_Node* pSaveItems = nullptr; + if (bSave) { + pSaveItems = pLabelItems; + pLabelItems = listitems[1]; + } else { + pSaveItems = listitems[1]; + } + iCount = 0; + + int32_t iSearch = -1; + for (CXFA_Node* pChildItem = pSaveItems->GetNodeItem(XFA_NODEITEM_FirstChild); + pChildItem; + pChildItem = pChildItem->GetNodeItem(XFA_NODEITEM_NextSibling)) { + if (pChildItem->JSObject()->GetContent(false) == wsValue) { + iSearch = iCount; + break; + } + iCount++; + } + if (iSearch < 0) + return; + + CXFA_Node* pText = + pLabelItems->GetChild(iSearch, XFA_Element::Unknown, false); + if (pText) + wsLabel = pText->JSObject()->GetContent(false); +} + +WideString CXFA_WidgetAcc::GetItemValue(const WideStringView& wsLabel) { + int32_t iCount = 0; + std::vector listitems; + for (CXFA_Node* pItems = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); + pItems; pItems = pItems->GetNodeItem(XFA_NODEITEM_NextSibling)) { + if (pItems->GetElementType() != XFA_Element::Items) + continue; + iCount++; + listitems.push_back(pItems); + } + if (iCount <= 1) + return WideString(wsLabel); + + CXFA_Node* pLabelItems = listitems[0]; + bool bSave = pLabelItems->JSObject()->GetBoolean(XFA_Attribute::Save); + CXFA_Node* pSaveItems = nullptr; + if (bSave) { + pSaveItems = pLabelItems; + pLabelItems = listitems[1]; + } else { + pSaveItems = listitems[1]; + } + iCount = 0; + + int32_t iSearch = -1; + WideString wsContent; + CXFA_Node* pChildItem = pLabelItems->GetNodeItem(XFA_NODEITEM_FirstChild); + for (; pChildItem; + pChildItem = pChildItem->GetNodeItem(XFA_NODEITEM_NextSibling)) { + if (pChildItem->JSObject()->GetContent(false) == wsLabel) { + iSearch = iCount; + break; + } + iCount++; + } + if (iSearch < 0) + return L""; + + CXFA_Node* pText = + pSaveItems->GetChild(iSearch, XFA_Element::Unknown, false); + return pText ? pText->JSObject()->GetContent(false) : L""; +} + +bool CXFA_WidgetAcc::DeleteItem(int32_t nIndex, + bool bNotify, + bool bScriptModify) { + bool bSetValue = false; + CXFA_Node* pItems = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); + for (; pItems; pItems = pItems->GetNodeItem(XFA_NODEITEM_NextSibling)) { + if (pItems->GetElementType() != XFA_Element::Items) + continue; + + if (nIndex < 0) { + while (CXFA_Node* pNode = pItems->GetNodeItem(XFA_NODEITEM_FirstChild)) { + pItems->RemoveChild(pNode, true); + } + } else { + if (!bSetValue && pItems->JSObject()->GetBoolean(XFA_Attribute::Save)) { + SetItemState(nIndex, false, true, bScriptModify, true); + bSetValue = true; + } + int32_t i = 0; + CXFA_Node* pNode = pItems->GetNodeItem(XFA_NODEITEM_FirstChild); + while (pNode) { + if (i == nIndex) { + pItems->RemoveChild(pNode, true); + break; + } + i++; + pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling); + } + } + } + if (bNotify) + m_pNode->GetDocument()->GetNotify()->OnWidgetListItemRemoved(this, nIndex); + return true; +} + +bool CXFA_WidgetAcc::IsHorizontalScrollPolicyOff() { + CXFA_Node* pUIChild = GetUIChild(); + if (pUIChild) { + return pUIChild->JSObject()->GetEnum(XFA_Attribute::HScrollPolicy) == + XFA_AttributeEnum::Off; + } + return false; +} + +bool CXFA_WidgetAcc::IsVerticalScrollPolicyOff() { + CXFA_Node* pUIChild = GetUIChild(); + if (pUIChild) { + return pUIChild->JSObject()->GetEnum(XFA_Attribute::VScrollPolicy) == + XFA_AttributeEnum::Off; + } + return false; +} + +pdfium::Optional CXFA_WidgetAcc::GetNumberOfCells() { + CXFA_Node* pUIChild = GetUIChild(); + if (!pUIChild) + return {}; + if (CXFA_Comb* pNode = + pUIChild->GetChild(0, XFA_Element::Comb, false)) + return {pNode->JSObject()->GetInteger(XFA_Attribute::NumberOfCells)}; + return {}; +} + +WideString CXFA_WidgetAcc::GetBarcodeType() { + CXFA_Node* pUIChild = GetUIChild(); + return pUIChild + ? WideString(pUIChild->JSObject()->GetCData(XFA_Attribute::Type)) + : WideString(); +} + +pdfium::Optional +CXFA_WidgetAcc::GetBarcodeAttribute_CharEncoding() { + pdfium::Optional wsCharEncoding = + GetUIChild()->JSObject()->TryCData(XFA_Attribute::CharEncoding, true); + if (!wsCharEncoding) + return {}; + if (wsCharEncoding->CompareNoCase(L"UTF-16")) + return {CHAR_ENCODING_UNICODE}; + if (wsCharEncoding->CompareNoCase(L"UTF-8")) + return {CHAR_ENCODING_UTF8}; + return {}; +} + +pdfium::Optional CXFA_WidgetAcc::GetBarcodeAttribute_Checksum() { + pdfium::Optional checksum = + GetUIChild()->JSObject()->TryEnum(XFA_Attribute::Checksum, true); + if (!checksum) + return {}; + + switch (*checksum) { + case XFA_AttributeEnum::None: + return {false}; + case XFA_AttributeEnum::Auto: + return {true}; + case XFA_AttributeEnum::Checksum_1mod10: + case XFA_AttributeEnum::Checksum_1mod10_1mod11: + case XFA_AttributeEnum::Checksum_2mod10: + default: + break; + } + return {}; +} + +pdfium::Optional CXFA_WidgetAcc::GetBarcodeAttribute_DataLength() { + pdfium::Optional wsDataLength = + GetUIChild()->JSObject()->TryCData(XFA_Attribute::DataLength, true); + if (!wsDataLength) + return {}; + + return {FXSYS_wtoi(wsDataLength->c_str())}; +} + +pdfium::Optional CXFA_WidgetAcc::GetBarcodeAttribute_StartChar() { + pdfium::Optional wsStartEndChar = + GetUIChild()->JSObject()->TryCData(XFA_Attribute::StartChar, true); + if (!wsStartEndChar || wsStartEndChar->IsEmpty()) + return {}; + + return {static_cast((*wsStartEndChar)[0])}; +} + +pdfium::Optional CXFA_WidgetAcc::GetBarcodeAttribute_EndChar() { + pdfium::Optional wsStartEndChar = + GetUIChild()->JSObject()->TryCData(XFA_Attribute::EndChar, true); + if (!wsStartEndChar || wsStartEndChar->IsEmpty()) + return {}; + + return {static_cast((*wsStartEndChar)[0])}; +} + +pdfium::Optional CXFA_WidgetAcc::GetBarcodeAttribute_ECLevel() { + pdfium::Optional wsECLevel = GetUIChild()->JSObject()->TryCData( + XFA_Attribute::ErrorCorrectionLevel, true); + if (!wsECLevel) + return {}; + return {FXSYS_wtoi(wsECLevel->c_str())}; +} + +pdfium::Optional CXFA_WidgetAcc::GetBarcodeAttribute_ModuleWidth() { + pdfium::Optional moduleWidthHeight = + GetUIChild()->JSObject()->TryMeasure(XFA_Attribute::ModuleWidth, true); + if (!moduleWidthHeight) + return {}; + + return {static_cast(moduleWidthHeight->ToUnit(XFA_Unit::Pt))}; +} + +pdfium::Optional CXFA_WidgetAcc::GetBarcodeAttribute_ModuleHeight() { + pdfium::Optional moduleWidthHeight = + GetUIChild()->JSObject()->TryMeasure(XFA_Attribute::ModuleHeight, true); + if (!moduleWidthHeight) + return {}; + + return {static_cast(moduleWidthHeight->ToUnit(XFA_Unit::Pt))}; +} + +pdfium::Optional CXFA_WidgetAcc::GetBarcodeAttribute_PrintChecksum() { + return GetUIChild()->JSObject()->TryBoolean(XFA_Attribute::PrintCheckDigit, + true); +} + +pdfium::Optional +CXFA_WidgetAcc::GetBarcodeAttribute_TextLocation() { + pdfium::Optional textLocation = + GetUIChild()->JSObject()->TryEnum(XFA_Attribute::TextLocation, true); + if (!textLocation) + return {}; + + switch (*textLocation) { + case XFA_AttributeEnum::None: + return {BC_TEXT_LOC_NONE}; + case XFA_AttributeEnum::Above: + return {BC_TEXT_LOC_ABOVE}; + case XFA_AttributeEnum::Below: + return {BC_TEXT_LOC_BELOW}; + case XFA_AttributeEnum::AboveEmbedded: + return {BC_TEXT_LOC_ABOVEEMBED}; + case XFA_AttributeEnum::BelowEmbedded: + return {BC_TEXT_LOC_BELOWEMBED}; + default: + break; + } + return {}; +} + +pdfium::Optional CXFA_WidgetAcc::GetBarcodeAttribute_Truncate() { + return GetUIChild()->JSObject()->TryBoolean(XFA_Attribute::Truncate, true); +} + +pdfium::Optional CXFA_WidgetAcc::GetBarcodeAttribute_WideNarrowRatio() { + pdfium::Optional wsWideNarrowRatio = + GetUIChild()->JSObject()->TryCData(XFA_Attribute::WideNarrowRatio, true); + if (!wsWideNarrowRatio) + return {}; + + pdfium::Optional ptPos = wsWideNarrowRatio->Find(':'); + if (!ptPos) + return {static_cast(FXSYS_wtoi(wsWideNarrowRatio->c_str()))}; + + int32_t fB = FXSYS_wtoi( + wsWideNarrowRatio->Right(wsWideNarrowRatio->GetLength() - (*ptPos + 1)) + .c_str()); + if (!fB) + return {0}; + + int32_t fA = FXSYS_wtoi(wsWideNarrowRatio->Left(*ptPos).c_str()); + float result = static_cast(fA) / static_cast(fB); + return {static_cast(result)}; +} + +WideString CXFA_WidgetAcc::GetPasswordChar() { + CXFA_Node* pUIChild = GetUIChild(); + return pUIChild ? pUIChild->JSObject()->GetCData(XFA_Attribute::PasswordChar) + : L"*"; +} + +bool CXFA_WidgetAcc::IsMultiLine() { + CXFA_Node* pUIChild = GetUIChild(); + return pUIChild && pUIChild->JSObject()->GetBoolean(XFA_Attribute::MultiLine); +} + +std::pair CXFA_WidgetAcc::GetMaxChars() { + if (CXFA_Value* pNode = + m_pNode->GetChild(0, XFA_Element::Value, false)) { + if (CXFA_Node* pChild = pNode->GetNodeItem(XFA_NODEITEM_FirstChild)) { + switch (pChild->GetElementType()) { + case XFA_Element::Text: + return {XFA_Element::Text, + pChild->JSObject()->GetInteger(XFA_Attribute::MaxChars)}; + case XFA_Element::ExData: { + int32_t iMax = + pChild->JSObject()->GetInteger(XFA_Attribute::MaxLength); + return {XFA_Element::ExData, iMax < 0 ? 0 : iMax}; + } + default: + break; + } + } + } + return {XFA_Element::Unknown, 0}; +} + +int32_t CXFA_WidgetAcc::GetFracDigits() { + CXFA_Value* pNode = + m_pNode->GetChild(0, XFA_Element::Value, false); + if (!pNode) + return -1; + + CXFA_Decimal* pChild = + pNode->GetChild(0, XFA_Element::Decimal, false); + if (!pChild) + return -1; + + return pChild->JSObject() + ->TryInteger(XFA_Attribute::FracDigits, true) + .value_or(-1); +} + +int32_t CXFA_WidgetAcc::GetLeadDigits() { + CXFA_Value* pNode = + m_pNode->GetChild(0, XFA_Element::Value, false); + if (!pNode) + return -1; + + CXFA_Decimal* pChild = + pNode->GetChild(0, XFA_Element::Decimal, false); + if (!pChild) + return -1; + + return pChild->JSObject() + ->TryInteger(XFA_Attribute::LeadDigits, true) + .value_or(-1); +} + +bool CXFA_WidgetAcc::SetValue(XFA_VALUEPICTURE eValueType, + const WideString& wsValue) { + if (wsValue.IsEmpty()) { + if (m_pNode) + m_pNode->SyncValue(wsValue, true); + return true; + } + + m_bPreNull = m_bIsNull; + m_bIsNull = false; + WideString wsNewText(wsValue); + WideString wsPicture = GetPictureContent(eValueType); + bool bValidate = true; + bool bSyncData = false; + CXFA_Node* pNode = GetUIChild(); + if (!pNode) + return true; + + XFA_Element eType = pNode->GetElementType(); + if (!wsPicture.IsEmpty()) { + CXFA_LocaleMgr* pLocalMgr = m_pNode->GetDocument()->GetLocalMgr(); + IFX_Locale* pLocale = GetLocale(); + CXFA_LocaleValue widgetValue = XFA_GetLocaleValue(this); + bValidate = + widgetValue.ValidateValue(wsValue, wsPicture, pLocale, &wsPicture); + if (bValidate) { + widgetValue = CXFA_LocaleValue(widgetValue.GetType(), wsNewText, + wsPicture, pLocale, pLocalMgr); + wsNewText = widgetValue.GetValue(); + if (eType == XFA_Element::NumericEdit) + wsNewText = NumericLimit(wsNewText, GetLeadDigits(), GetFracDigits()); + + bSyncData = true; + } + } else { + if (eType == XFA_Element::NumericEdit) { + if (wsNewText != L"0") + wsNewText = NumericLimit(wsNewText, GetLeadDigits(), GetFracDigits()); + + bSyncData = true; + } + } + if (eType != XFA_Element::NumericEdit || bSyncData) { + if (m_pNode) + m_pNode->SyncValue(wsNewText, true); + } + + return bValidate; +} + +WideString CXFA_WidgetAcc::GetPictureContent(XFA_VALUEPICTURE ePicture) { + if (ePicture == XFA_VALUEPICTURE_Raw) + return L""; + + CXFA_LocaleValue widgetValue = XFA_GetLocaleValue(this); + switch (ePicture) { + case XFA_VALUEPICTURE_Display: { + if (CXFA_Format* pFormat = + m_pNode->GetChild(0, XFA_Element::Format, false)) { + if (CXFA_Picture* pPicture = pFormat->GetChild( + 0, XFA_Element::Picture, false)) { + pdfium::Optional picture = + pPicture->JSObject()->TryContent(false, true); + if (picture) + return *picture; + } + } + + IFX_Locale* pLocale = GetLocale(); + if (!pLocale) + return L""; + + uint32_t dwType = widgetValue.GetType(); + switch (dwType) { + case XFA_VT_DATE: + return pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Medium); + case XFA_VT_TIME: + return pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Medium); + case XFA_VT_DATETIME: + return pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Medium) + + L"T" + + pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Medium); + case XFA_VT_DECIMAL: + case XFA_VT_FLOAT: + default: + return L""; + } + } + case XFA_VALUEPICTURE_Edit: { + CXFA_Ui* pUI = m_pNode->GetChild(0, XFA_Element::Ui, false); + if (pUI) { + if (CXFA_Picture* pPicture = + pUI->GetChild(0, XFA_Element::Picture, false)) { + pdfium::Optional picture = + pPicture->JSObject()->TryContent(false, true); + if (picture) + return *picture; + } + } + + IFX_Locale* pLocale = GetLocale(); + if (!pLocale) + return L""; + + uint32_t dwType = widgetValue.GetType(); + switch (dwType) { + case XFA_VT_DATE: + return pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Short); + case XFA_VT_TIME: + return pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Short); + case XFA_VT_DATETIME: + return pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Short) + + L"T" + + pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Short); + default: + return L""; + } + } + case XFA_VALUEPICTURE_DataBind: { + CXFA_Bind* bind = GetBind(); + if (bind) + return bind->GetPicture(); + break; + } + default: + break; + } + return L""; +} + +IFX_Locale* CXFA_WidgetAcc::GetLocale() { + return m_pNode ? m_pNode->GetLocale() : nullptr; +} + +WideString CXFA_WidgetAcc::GetValue(XFA_VALUEPICTURE eValueType) { + WideString wsValue = m_pNode->JSObject()->GetContent(false); + + if (eValueType == XFA_VALUEPICTURE_Display) + GetItemLabel(wsValue.AsStringView(), wsValue); + + WideString wsPicture = GetPictureContent(eValueType); + CXFA_Node* pNode = GetUIChild(); + if (!pNode) + return wsValue; + + switch (GetUIChild()->GetElementType()) { + case XFA_Element::ChoiceList: { + if (eValueType == XFA_VALUEPICTURE_Display) { + int32_t iSelItemIndex = GetSelectedItem(0); + if (iSelItemIndex >= 0) { + wsValue = GetChoiceListItem(iSelItemIndex, false).value_or(L""); + wsPicture.clear(); + } + } + } break; + case XFA_Element::NumericEdit: + if (eValueType != XFA_VALUEPICTURE_Raw && wsPicture.IsEmpty()) { + IFX_Locale* pLocale = GetLocale(); + if (eValueType == XFA_VALUEPICTURE_Display && pLocale) + wsValue = FormatNumStr(NormalizeNumStr(wsValue), pLocale); + } + break; + default: + break; + } + if (wsPicture.IsEmpty()) + return wsValue; + + if (IFX_Locale* pLocale = GetLocale()) { + CXFA_LocaleValue widgetValue = XFA_GetLocaleValue(this); + CXFA_LocaleMgr* pLocalMgr = m_pNode->GetDocument()->GetLocalMgr(); + switch (widgetValue.GetType()) { + case XFA_VT_DATE: { + WideString wsDate, wsTime; + if (SplitDateTime(wsValue, wsDate, wsTime)) { + CXFA_LocaleValue date(XFA_VT_DATE, wsDate, pLocalMgr); + if (date.FormatPatterns(wsValue, wsPicture, pLocale, eValueType)) + return wsValue; + } + break; + } + case XFA_VT_TIME: { + WideString wsDate, wsTime; + if (SplitDateTime(wsValue, wsDate, wsTime)) { + CXFA_LocaleValue time(XFA_VT_TIME, wsTime, pLocalMgr); + if (time.FormatPatterns(wsValue, wsPicture, pLocale, eValueType)) + return wsValue; + } + break; + } + default: + break; + } + widgetValue.FormatPatterns(wsValue, wsPicture, pLocale, eValueType); + } + return wsValue; +} + +WideString CXFA_WidgetAcc::GetNormalizeDataValue(const WideString& wsValue) { + if (wsValue.IsEmpty()) + return L""; + + WideString wsPicture = GetPictureContent(XFA_VALUEPICTURE_DataBind); + if (wsPicture.IsEmpty()) + return wsValue; + + ASSERT(GetNode()); + CXFA_LocaleMgr* pLocalMgr = GetNode()->GetDocument()->GetLocalMgr(); + IFX_Locale* pLocale = GetLocale(); + CXFA_LocaleValue widgetValue = XFA_GetLocaleValue(this); + if (widgetValue.ValidateValue(wsValue, wsPicture, pLocale, &wsPicture)) { + widgetValue = CXFA_LocaleValue(widgetValue.GetType(), wsValue, wsPicture, + pLocale, pLocalMgr); + return widgetValue.GetValue(); + } + return wsValue; +} + +WideString CXFA_WidgetAcc::GetFormatDataValue(const WideString& wsValue) { + if (wsValue.IsEmpty()) + return L""; + + WideString wsPicture = GetPictureContent(XFA_VALUEPICTURE_DataBind); + if (wsPicture.IsEmpty()) + return wsValue; + + WideString wsFormattedValue = wsValue; + if (IFX_Locale* pLocale = GetLocale()) { + ASSERT(GetNode()); + CXFA_Value* pNodeValue = + GetNode()->GetChild(0, XFA_Element::Value, false); + if (!pNodeValue) + return wsValue; + + CXFA_Node* pValueChild = pNodeValue->GetNodeItem(XFA_NODEITEM_FirstChild); + if (!pValueChild) + return wsValue; + + int32_t iVTType = XFA_VT_NULL; + switch (pValueChild->GetElementType()) { + case XFA_Element::Decimal: + iVTType = XFA_VT_DECIMAL; + break; + case XFA_Element::Float: + iVTType = XFA_VT_FLOAT; + break; + case XFA_Element::Date: + iVTType = XFA_VT_DATE; + break; + case XFA_Element::Time: + iVTType = XFA_VT_TIME; + break; + case XFA_Element::DateTime: + iVTType = XFA_VT_DATETIME; + break; + case XFA_Element::Boolean: + iVTType = XFA_VT_BOOLEAN; + break; + case XFA_Element::Integer: + iVTType = XFA_VT_INTEGER; + break; + case XFA_Element::Text: + iVTType = XFA_VT_TEXT; + break; + default: + iVTType = XFA_VT_NULL; + break; + } + CXFA_LocaleMgr* pLocalMgr = GetNode()->GetDocument()->GetLocalMgr(); + CXFA_LocaleValue widgetValue(iVTType, wsValue, pLocalMgr); + switch (widgetValue.GetType()) { + case XFA_VT_DATE: { + WideString wsDate, wsTime; + if (SplitDateTime(wsValue, wsDate, wsTime)) { + CXFA_LocaleValue date(XFA_VT_DATE, wsDate, pLocalMgr); + if (date.FormatPatterns(wsFormattedValue, wsPicture, pLocale, + XFA_VALUEPICTURE_DataBind)) { + return wsFormattedValue; + } + } + break; + } + case XFA_VT_TIME: { + WideString wsDate, wsTime; + if (SplitDateTime(wsValue, wsDate, wsTime)) { + CXFA_LocaleValue time(XFA_VT_TIME, wsTime, pLocalMgr); + if (time.FormatPatterns(wsFormattedValue, wsPicture, pLocale, + XFA_VALUEPICTURE_DataBind)) { + return wsFormattedValue; + } + } + break; + } + default: + break; + } + widgetValue.FormatPatterns(wsFormattedValue, wsPicture, pLocale, + XFA_VALUEPICTURE_DataBind); + } + return wsFormattedValue; +} + +WideString CXFA_WidgetAcc::NormalizeNumStr(const WideString& wsValue) { + if (wsValue.IsEmpty()) + return L""; + + WideString wsOutput = wsValue; + wsOutput.TrimLeft('0'); + + if (!wsOutput.IsEmpty() && wsOutput.Contains('.') && GetFracDigits() != -1) { + wsOutput.TrimRight(L"0"); + wsOutput.TrimRight(L"."); + } + if (wsOutput.IsEmpty() || wsOutput[0] == '.') + wsOutput.InsertAtFront('0'); + + return wsOutput; +} + +WideString CXFA_WidgetAcc::FormatNumStr(const WideString& wsValue, + IFX_Locale* pLocale) { + if (wsValue.IsEmpty()) + return L""; + + WideString wsSrcNum = wsValue; + WideString wsGroupSymbol = + pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Grouping); + bool bNeg = false; + if (wsSrcNum[0] == '-') { + bNeg = true; + wsSrcNum.Delete(0, 1); + } + + auto dot_index = wsSrcNum.Find('.'); + dot_index = !dot_index.has_value() ? wsSrcNum.GetLength() : dot_index; + + if (dot_index.value() < 1) + return L""; + + size_t nPos = dot_index.value() % 3; + WideString wsOutput; + for (size_t i = 0; i < dot_index.value(); i++) { + if (i % 3 == nPos && i != 0) + wsOutput += wsGroupSymbol; + + wsOutput += wsSrcNum[i]; + } + if (dot_index.value() < wsSrcNum.GetLength()) { + wsOutput += pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Decimal); + wsOutput += wsSrcNum.Right(wsSrcNum.GetLength() - dot_index.value() - 1); + } + if (bNeg) + return pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus) + wsOutput; + + return wsOutput; +} + +void CXFA_WidgetAcc::InsertListTextItem(CXFA_Node* pItems, + const WideString& wsText, + int32_t nIndex) { + CXFA_Node* pText = pItems->CreateSamePacketNode(XFA_Element::Text); + pItems->InsertChild(nIndex, pText); + pText->JSObject()->SetContent(wsText, wsText, false, false, false); +} + +WideString CXFA_WidgetAcc::NumericLimit(const WideString& wsValue, + int32_t iLead, + int32_t iTread) const { + if ((iLead == -1) && (iTread == -1)) + return wsValue; + + WideString wsRet; + int32_t iLead_ = 0, iTread_ = -1; + int32_t iCount = wsValue.GetLength(); + if (iCount == 0) + return wsValue; + + int32_t i = 0; + if (wsValue[i] == L'-') { + wsRet += L'-'; + i++; + } + for (; i < iCount; i++) { + wchar_t wc = wsValue[i]; + if (FXSYS_isDecimalDigit(wc)) { + if (iLead >= 0) { + iLead_++; + if (iLead_ > iLead) + return L"0"; + } else if (iTread_ >= 0) { + iTread_++; + if (iTread_ > iTread) { + if (iTread != -1) { + CFX_Decimal wsDeci = CFX_Decimal(wsValue.AsStringView()); + wsDeci.SetScale(iTread); + wsRet = wsDeci; + } + return wsRet; + } + } + } else if (wc == L'.') { + iTread_ = 0; + iLead = -1; + } + wsRet += wc; + } + return wsRet; +} diff --git a/xfa/fxfa/cxfa_widgetacc.h b/xfa/fxfa/cxfa_widgetacc.h index aa4303aef6..29c78d9576 100644 --- a/xfa/fxfa/cxfa_widgetacc.h +++ b/xfa/fxfa/cxfa_widgetacc.h @@ -9,30 +9,57 @@ #include #include +#include #include "core/fxcrt/fx_coordinates.h" +#include "core/fxcrt/fx_string.h" +#include "core/fxcrt/fx_system.h" #include "core/fxcrt/retain_ptr.h" #include "core/fxge/dib/cfx_dibitmap.h" #include "core/fxge/fx_dib.h" -#include "xfa/fxfa/parser/cxfa_widgetdata.h" +#include "fxbarcode/BC_Library.h" +#include "xfa/fxfa/fxfa_basic.h" + +enum XFA_CHECKSTATE { + XFA_CHECKSTATE_On = 0, + XFA_CHECKSTATE_Off = 1, + XFA_CHECKSTATE_Neutral = 2, +}; + +enum XFA_VALUEPICTURE { + XFA_VALUEPICTURE_Raw = 0, + XFA_VALUEPICTURE_Display, + XFA_VALUEPICTURE_Edit, + XFA_VALUEPICTURE_DataBind, +}; class CFGAS_GEFont; +class CXFA_Bind; +class CXFA_Border; +class CXFA_Calculate; +class CXFA_Caption; class CXFA_Event; class CXFA_EventParam; class CXFA_FFApp; class CXFA_FFDoc; class CXFA_FFDocView; class CXFA_FFWidget; +class CXFA_Font; +class CXFA_Margin; class CXFA_Node; class CXFA_Script; +class CXFA_Para; class CXFA_TextLayout; +class CXFA_Value; +class CXFA_Validate; class CXFA_WidgetLayoutData; class IXFA_AppProvider; +class IFX_Locale; -class CXFA_WidgetAcc : public CXFA_WidgetData { +class CXFA_WidgetAcc { public: CXFA_WidgetAcc(CXFA_FFDocView* pDocView, CXFA_Node* pNode); - ~CXFA_WidgetAcc() override; + ~CXFA_WidgetAcc(); void ResetData(); @@ -81,6 +108,136 @@ class CXFA_WidgetAcc : public CXFA_WidgetData { FX_ARGB GetTextColor(); float GetLineHeight(); + CXFA_Node* GetNode() const { return m_pNode; } + + CXFA_Node* GetUIChild(); + XFA_Element GetUIType(); + CFX_RectF GetUIMargin(); + + WideString GetRawValue() const; + int32_t GetRotate() const; + + bool IsOpenAccess() const; + bool IsListBox(); + bool IsAllowNeutral(); + bool IsRadioButton(); + bool IsChoiceListAllowTextEntry(); + bool IsMultiLine(); + + CXFA_Border* GetBorder(bool bModified); + CXFA_Caption* GetCaption(); + CXFA_Font* GetFont(bool bModified); + CXFA_Margin* GetMargin(); + CXFA_Para* GetPara(); + CXFA_Value* GetDefaultValue(); + CXFA_Value* GetFormValue(); + CXFA_Calculate* GetCalculate(); + CXFA_Validate* GetValidate(bool bModified); + CXFA_Border* GetUIBorder(); + + std::vector GetEventByActivity(XFA_AttributeEnum iActivity, + bool bIsFormReady); + + pdfium::Optional TryWidth(); + pdfium::Optional TryHeight(); + pdfium::Optional TryMinWidth(); + pdfium::Optional TryMinHeight(); + pdfium::Optional TryMaxWidth(); + pdfium::Optional TryMaxHeight(); + + XFA_AttributeEnum GetButtonHighlight(); + bool HasButtonRollover() const; + bool HasButtonDown() const; + + bool IsCheckButtonRound(); + XFA_AttributeEnum GetCheckButtonMark(); + float GetCheckButtonSize(); + + XFA_CHECKSTATE GetCheckState(); + void SetCheckState(XFA_CHECKSTATE eCheckState, bool bNotify); + + CXFA_Node* GetSelectedMember(); + CXFA_Node* SetSelectedMember(const WideStringView& wsName, bool bNotify); + void SetSelectedMemberByValue(const WideStringView& wsValue, + bool bNotify, + bool bScriptModify, + bool bSyncData); + + CXFA_Node* GetExclGroupFirstMember(); + CXFA_Node* GetExclGroupNextMember(CXFA_Node* pNode); + + int32_t CountChoiceListItems(bool bSaveValue); + pdfium::Optional GetChoiceListItem(int32_t nIndex, + bool bSaveValue); + bool IsChoiceListMultiSelect(); + bool IsChoiceListCommitOnSelect(); + std::vector GetChoiceListItems(bool bSaveValue); + + int32_t CountSelectedItems(); + int32_t GetSelectedItem(int32_t nIndex); + std::vector GetSelectedItems(); + std::vector GetSelectedItemsValue(); + void SetSelectedItems(const std::vector& iSelArray, + bool bNotify, + bool bScriptModify, + bool bSyncData); + void InsertItem(const WideString& wsLabel, + const WideString& wsValue, + bool bNotify); + bool DeleteItem(int32_t nIndex, bool bNotify, bool bScriptModify); + void ClearAllSelections(); + + bool GetItemState(int32_t nIndex); + void SetItemState(int32_t nIndex, + bool bSelected, + bool bNotify, + bool bScriptModify, + bool bSyncData); + + WideString GetItemValue(const WideStringView& wsLabel); + + bool IsHorizontalScrollPolicyOff(); + bool IsVerticalScrollPolicyOff(); + pdfium::Optional GetNumberOfCells(); + + bool SetValue(XFA_VALUEPICTURE eValueType, const WideString& wsValue); + WideString GetValue(XFA_VALUEPICTURE eValueType); + + WideString GetPictureContent(XFA_VALUEPICTURE ePicture); + IFX_Locale* GetLocale(); + + WideString GetNormalizeDataValue(const WideString& wsValue); + WideString GetFormatDataValue(const WideString& wsValue); + WideString NormalizeNumStr(const WideString& wsValue); + + WideString GetBarcodeType(); + pdfium::Optional GetBarcodeAttribute_CharEncoding(); + pdfium::Optional GetBarcodeAttribute_Checksum(); + pdfium::Optional GetBarcodeAttribute_DataLength(); + pdfium::Optional GetBarcodeAttribute_StartChar(); + pdfium::Optional GetBarcodeAttribute_EndChar(); + pdfium::Optional GetBarcodeAttribute_ECLevel(); + pdfium::Optional GetBarcodeAttribute_ModuleWidth(); + pdfium::Optional GetBarcodeAttribute_ModuleHeight(); + pdfium::Optional GetBarcodeAttribute_PrintChecksum(); + pdfium::Optional GetBarcodeAttribute_TextLocation(); + pdfium::Optional GetBarcodeAttribute_Truncate(); + pdfium::Optional GetBarcodeAttribute_WideNarrowRatio(); + + WideString GetPasswordChar(); + std::pair GetMaxChars(); + int32_t GetFracDigits(); + int32_t GetLeadDigits(); + + WideString NumericLimit(const WideString& wsValue, + int32_t iLead, + int32_t iTread) const; + + bool IsPreNull() const { return m_bPreNull; } + void SetPreNull(bool val) { m_bPreNull = val; } + bool IsNull() const { return m_bIsNull; } + void SetIsNull(bool val) { m_bIsNull = val; } + private: IXFA_AppProvider* GetAppProvider(); void ProcessScriptTestValidate(CXFA_Validate* validate, @@ -117,9 +274,22 @@ class CXFA_WidgetAcc : public CXFA_WidgetData { void InitLayoutData(); void StartTextLayout(float& fCalcWidth, float& fCalcHeight); + CXFA_Bind* GetBind(); + void InsertListTextItem(CXFA_Node* pItems, + const WideString& wsText, + int32_t nIndex); + WideString FormatNumStr(const WideString& wsValue, IFX_Locale* pLocale); + CXFA_Node* GetExclGroupNode(); + void GetItemLabel(const WideStringView& wsValue, WideString& wsLabel); + CXFA_FFDocView* m_pDocView; std::unique_ptr m_pLayoutData; uint32_t m_nRecursionDepth; + bool m_bIsNull; + bool m_bPreNull; + CXFA_Node* m_pUiChildNode; + XFA_Element m_eUIType; + CXFA_Node* m_pNode; }; #endif // XFA_FXFA_CXFA_WIDGETACC_H_ diff --git a/xfa/fxfa/cxfa_widgetacciterator.cpp b/xfa/fxfa/cxfa_widgetacciterator.cpp index ed780853df..ece5604f7d 100644 --- a/xfa/fxfa/cxfa_widgetacciterator.cpp +++ b/xfa/fxfa/cxfa_widgetacciterator.cpp @@ -17,7 +17,7 @@ CXFA_WidgetAcc* CXFA_WidgetAccIterator::MoveToNext() { CXFA_Node* pItem = m_pCurWidgetAcc ? m_ContentIterator.MoveToNext() : m_ContentIterator.GetCurrent(); while (pItem) { - m_pCurWidgetAcc = static_cast(pItem->GetWidgetData()); + m_pCurWidgetAcc = pItem->GetWidgetAcc(); if (m_pCurWidgetAcc) return m_pCurWidgetAcc.Get(); pItem = m_ContentIterator.MoveToNext(); diff --git a/xfa/fxfa/fxfa.h b/xfa/fxfa/fxfa.h index d7c8c651ca..d42cd1b158 100644 --- a/xfa/fxfa/fxfa.h +++ b/xfa/fxfa/fxfa.h @@ -225,9 +225,9 @@ class IXFA_DocEnvironment { virtual bool PopupMenu(CXFA_FFWidget* hWidget, CFX_PointF ptPopup) = 0; virtual void PageViewEvent(CXFA_FFPageView* pPageView, uint32_t dwFlags) = 0; virtual void WidgetPostAdd(CXFA_FFWidget* hWidget, - CXFA_WidgetAcc* pWidgetData) = 0; + CXFA_WidgetAcc* pWidgetAcc) = 0; virtual void WidgetPreRemove(CXFA_FFWidget* hWidget, - CXFA_WidgetAcc* pWidgetData) = 0; + CXFA_WidgetAcc* pWidgetAcc) = 0; virtual int32_t CountPages(CXFA_FFDoc* hDoc) = 0; virtual int32_t GetCurrentPage(CXFA_FFDoc* hDoc) = 0; diff --git a/xfa/fxfa/parser/cxfa_dataexporter.cpp b/xfa/fxfa/parser/cxfa_dataexporter.cpp index 2b5f3e6755..fdd09c80a8 100644 --- a/xfa/fxfa/parser/cxfa_dataexporter.cpp +++ b/xfa/fxfa/parser/cxfa_dataexporter.cpp @@ -13,7 +13,6 @@ #include "third_party/base/stl_util.h" #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_node.h" -#include "xfa/fxfa/parser/cxfa_widgetdata.h" #include "xfa/fxfa/parser/xfa_utils.h" CXFA_DataExporter::CXFA_DataExporter(CXFA_Document* pDocument) diff --git a/xfa/fxfa/parser/cxfa_localevalue.h b/xfa/fxfa/parser/cxfa_localevalue.h index d49376332d..60de601c02 100644 --- a/xfa/fxfa/parser/cxfa_localevalue.h +++ b/xfa/fxfa/parser/cxfa_localevalue.h @@ -9,7 +9,7 @@ #include "core/fxcrt/fx_string.h" #include "core/fxcrt/fx_system.h" -#include "xfa/fxfa/parser/cxfa_widgetdata.h" +#include "xfa/fxfa/cxfa_widgetacc.h" class IFX_Locale; class CFX_DateTime; diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 9a1dec6716..d7d187d168 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -557,11 +557,11 @@ bool CXFA_Node::HasBindItem() { return GetPacketType() == XFA_PacketType::Datasets && GetBindingNode(); } -CXFA_WidgetData* CXFA_Node::GetWidgetData() { - return JSObject()->GetWidgetData(); +CXFA_WidgetAcc* CXFA_Node::GetWidgetAcc() { + return JSObject()->GetWidgetAcc(); } -CXFA_WidgetData* CXFA_Node::GetContainerWidgetData() { +CXFA_WidgetAcc* CXFA_Node::GetContainerWidgetAcc() { if (GetPacketType() != XFA_PacketType::Form) return nullptr; XFA_Element eType = GetElementType(); @@ -572,35 +572,34 @@ CXFA_WidgetData* CXFA_Node::GetContainerWidgetData() { return nullptr; if (eType == XFA_Element::Field) { - CXFA_WidgetData* pFieldWidgetData = GetWidgetData(); - if (pFieldWidgetData && pFieldWidgetData->IsChoiceListMultiSelect()) + CXFA_WidgetAcc* pFieldWidgetAcc = GetWidgetAcc(); + if (pFieldWidgetAcc && pFieldWidgetAcc->IsChoiceListMultiSelect()) return nullptr; WideString wsPicture; - if (pFieldWidgetData) { - wsPicture = - pFieldWidgetData->GetPictureContent(XFA_VALUEPICTURE_DataBind); + if (pFieldWidgetAcc) { + wsPicture = pFieldWidgetAcc->GetPictureContent(XFA_VALUEPICTURE_DataBind); } if (!wsPicture.IsEmpty()) - return pFieldWidgetData; + return pFieldWidgetAcc; CXFA_Node* pDataNode = GetBindData(); if (!pDataNode) return nullptr; - pFieldWidgetData = nullptr; + pFieldWidgetAcc = nullptr; for (const auto& pFormNode : *(pDataNode->GetBindItems())) { if (!pFormNode || pFormNode->HasRemovedChildren()) continue; - pFieldWidgetData = pFormNode->GetWidgetData(); - if (pFieldWidgetData) { + pFieldWidgetAcc = pFormNode->GetWidgetAcc(); + if (pFieldWidgetAcc) { wsPicture = - pFieldWidgetData->GetPictureContent(XFA_VALUEPICTURE_DataBind); + pFieldWidgetAcc->GetPictureContent(XFA_VALUEPICTURE_DataBind); } if (!wsPicture.IsEmpty()) break; - pFieldWidgetData = nullptr; + pFieldWidgetAcc = nullptr; } - return pFieldWidgetData; + return pFieldWidgetAcc; } CXFA_Node* pGrandNode = @@ -617,7 +616,7 @@ CXFA_WidgetData* CXFA_Node::GetContainerWidgetData() { } CXFA_Node* pParentOfValueNode = pValueNode ? pValueNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr; - return pParentOfValueNode ? pParentOfValueNode->GetContainerWidgetData() + return pParentOfValueNode ? pParentOfValueNode->GetContainerWidgetAcc() : nullptr; } @@ -1539,3 +1538,12 @@ void CXFA_Node::SendAttributeChangeMessage(XFA_Attribute eAttribute, if (pParent) pLayoutPro->AddChangedContainer(pParent); } + +void CXFA_Node::SyncValue(const WideString& wsValue, bool bNotify) { + WideString wsFormatValue = wsValue; + CXFA_WidgetAcc* pContainerWidgetAcc = GetContainerWidgetAcc(); + if (pContainerWidgetAcc) + wsFormatValue = pContainerWidgetAcc->GetFormatDataValue(wsValue); + + JSObject()->SetContent(wsValue, wsFormatValue, bNotify, false, true); +} diff --git a/xfa/fxfa/parser/cxfa_node.h b/xfa/fxfa/parser/cxfa_node.h index 194f870d76..794e5fc032 100644 --- a/xfa/fxfa/parser/cxfa_node.h +++ b/xfa/fxfa/parser/cxfa_node.h @@ -19,7 +19,8 @@ class CFX_XMLNode; class CXFA_Occur; -class CXFA_WidgetData; +class CXFA_WidgetAcc; +class IXFA_Locale; #define XFA_NODEFILTER_Children 0x01 #define XFA_NODEFILTER_Properties 0x02 @@ -181,8 +182,8 @@ class CXFA_Node : public CXFA_Object { int32_t AddBindItem(CXFA_Node* pFormNode); int32_t RemoveBindItem(CXFA_Node* pFormNode); bool HasBindItem(); - CXFA_WidgetData* GetWidgetData(); - CXFA_WidgetData* GetContainerWidgetData(); + CXFA_WidgetAcc* GetWidgetAcc(); + CXFA_WidgetAcc* GetContainerWidgetAcc(); IFX_Locale* GetLocale(); bool GetLocaleName(WideString& wsLocaleName); XFA_AttributeEnum GetIntact(); @@ -216,6 +217,8 @@ class CXFA_Node : public CXFA_Object { pdfium::Optional GetDefaultCData(XFA_Attribute attr) const; pdfium::Optional GetDefaultEnum(XFA_Attribute attr) const; + void SyncValue(const WideString& wsValue, bool bNotify); + protected: CXFA_Node(CXFA_Document* pDoc, XFA_PacketType ePacket, diff --git a/xfa/fxfa/parser/cxfa_widgetdata.cpp b/xfa/fxfa/parser/cxfa_widgetdata.cpp deleted file mode 100644 index 68063e2a07..0000000000 --- a/xfa/fxfa/parser/cxfa_widgetdata.cpp +++ /dev/null @@ -1,1791 +0,0 @@ -// Copyright 2016 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/cxfa_widgetdata.h" - -#include "core/fxcrt/cfx_decimal.h" -#include "core/fxcrt/fx_extension.h" -#include "third_party/base/stl_util.h" -#include "xfa/fxfa/cxfa_ffnotify.h" -#include "xfa/fxfa/parser/cxfa_bind.h" -#include "xfa/fxfa/parser/cxfa_border.h" -#include "xfa/fxfa/parser/cxfa_calculate.h" -#include "xfa/fxfa/parser/cxfa_caption.h" -#include "xfa/fxfa/parser/cxfa_comb.h" -#include "xfa/fxfa/parser/cxfa_decimal.h" -#include "xfa/fxfa/parser/cxfa_document.h" -#include "xfa/fxfa/parser/cxfa_event.h" -#include "xfa/fxfa/parser/cxfa_font.h" -#include "xfa/fxfa/parser/cxfa_format.h" -#include "xfa/fxfa/parser/cxfa_items.h" -#include "xfa/fxfa/parser/cxfa_localevalue.h" -#include "xfa/fxfa/parser/cxfa_margin.h" -#include "xfa/fxfa/parser/cxfa_measurement.h" -#include "xfa/fxfa/parser/cxfa_node.h" -#include "xfa/fxfa/parser/cxfa_para.h" -#include "xfa/fxfa/parser/cxfa_picture.h" -#include "xfa/fxfa/parser/cxfa_stroke.h" -#include "xfa/fxfa/parser/cxfa_ui.h" -#include "xfa/fxfa/parser/cxfa_validate.h" -#include "xfa/fxfa/parser/cxfa_value.h" -#include "xfa/fxfa/parser/xfa_utils.h" - -namespace { - -float GetEdgeThickness(const std::vector& strokes, - bool b3DStyle, - int32_t nIndex) { - float fThickness = 0; - - CXFA_Stroke* stroke = strokes[nIndex * 2 + 1]; - if (stroke->IsVisible()) { - if (nIndex == 0) - fThickness += 2.5f; - - fThickness += stroke->GetThickness() * (b3DStyle ? 4 : 2); - } - return fThickness; -} - -bool SplitDateTime(const WideString& wsDateTime, - WideString& wsDate, - WideString& wsTime) { - wsDate = L""; - wsTime = L""; - if (wsDateTime.IsEmpty()) - return false; - - auto nSplitIndex = wsDateTime.Find('T'); - if (!nSplitIndex.has_value()) - nSplitIndex = wsDateTime.Find(' '); - if (!nSplitIndex.has_value()) - return false; - - wsDate = wsDateTime.Left(nSplitIndex.value()); - if (!wsDate.IsEmpty()) { - if (!std::any_of(wsDate.begin(), wsDate.end(), std::iswdigit)) - return false; - } - wsTime = wsDateTime.Right(wsDateTime.GetLength() - nSplitIndex.value() - 1); - if (!wsTime.IsEmpty()) { - if (!std::any_of(wsTime.begin(), wsTime.end(), std::iswdigit)) - return false; - } - return true; -} - -CXFA_Node* CreateUIChild(CXFA_Node* pNode, XFA_Element& eWidgetType) { - XFA_Element eType = pNode->GetElementType(); - eWidgetType = eType; - if (eType != XFA_Element::Field && eType != XFA_Element::Draw) - return nullptr; - - eWidgetType = XFA_Element::Unknown; - XFA_Element eUIType = XFA_Element::Unknown; - auto* defValue = - pNode->JSObject()->GetProperty(0, XFA_Element::Value, true); - XFA_Element eValueType = - defValue ? defValue->GetChildValueClassID() : XFA_Element::Unknown; - switch (eValueType) { - case XFA_Element::Boolean: - eUIType = XFA_Element::CheckButton; - break; - case XFA_Element::Integer: - case XFA_Element::Decimal: - case XFA_Element::Float: - eUIType = XFA_Element::NumericEdit; - break; - case XFA_Element::ExData: - case XFA_Element::Text: - eUIType = XFA_Element::TextEdit; - eWidgetType = XFA_Element::Text; - break; - case XFA_Element::Date: - case XFA_Element::Time: - case XFA_Element::DateTime: - eUIType = XFA_Element::DateTimeEdit; - break; - case XFA_Element::Image: - eUIType = XFA_Element::ImageEdit; - eWidgetType = XFA_Element::Image; - break; - case XFA_Element::Arc: - case XFA_Element::Line: - case XFA_Element::Rectangle: - eUIType = XFA_Element::DefaultUi; - eWidgetType = eValueType; - break; - default: - break; - } - - CXFA_Node* pUIChild = nullptr; - CXFA_Ui* pUI = - pNode->JSObject()->GetProperty(0, XFA_Element::Ui, true); - CXFA_Node* pChild = pUI->GetNodeItem(XFA_NODEITEM_FirstChild); - for (; pChild; pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { - XFA_Element eChildType = pChild->GetElementType(); - if (eChildType == XFA_Element::Extras || - eChildType == XFA_Element::Picture) { - continue; - } - - auto node = CXFA_Node::Create(pChild->GetDocument(), XFA_Element::Ui, - XFA_PacketType::Form); - if (node && node->HasPropertyFlags(eChildType, XFA_PROPERTYFLAG_OneOf)) { - pUIChild = pChild; - break; - } - } - - if (eType == XFA_Element::Draw) { - XFA_Element eDraw = - pUIChild ? pUIChild->GetElementType() : XFA_Element::Unknown; - switch (eDraw) { - case XFA_Element::TextEdit: - eWidgetType = XFA_Element::Text; - break; - case XFA_Element::ImageEdit: - eWidgetType = XFA_Element::Image; - break; - default: - eWidgetType = eWidgetType == XFA_Element::Unknown ? XFA_Element::Text - : eWidgetType; - break; - } - } else { - if (pUIChild && pUIChild->GetElementType() == XFA_Element::DefaultUi) { - eWidgetType = XFA_Element::TextEdit; - } else { - eWidgetType = - pUIChild ? pUIChild->GetElementType() - : (eUIType == XFA_Element::Unknown ? XFA_Element::TextEdit - : eUIType); - } - } - - if (!pUIChild) { - if (eUIType == XFA_Element::Unknown) { - eUIType = XFA_Element::TextEdit; - defValue->JSObject()->GetProperty(0, XFA_Element::Text, true); - } - return pUI->JSObject()->GetProperty(0, eUIType, true); - } - - if (eUIType != XFA_Element::Unknown) - return pUIChild; - - switch (pUIChild->GetElementType()) { - case XFA_Element::CheckButton: { - eValueType = XFA_Element::Text; - if (CXFA_Items* pItems = - pNode->GetChild(0, XFA_Element::Items, false)) { - if (CXFA_Node* pItem = - pItems->GetChild(0, XFA_Element::Unknown, false)) { - eValueType = pItem->GetElementType(); - } - } - break; - } - case XFA_Element::DateTimeEdit: - eValueType = XFA_Element::DateTime; - break; - case XFA_Element::ImageEdit: - eValueType = XFA_Element::Image; - break; - case XFA_Element::NumericEdit: - eValueType = XFA_Element::Float; - break; - case XFA_Element::ChoiceList: { - eValueType = (pUIChild->JSObject()->GetEnum(XFA_Attribute::Open) == - XFA_AttributeEnum::MultiSelect) - ? XFA_Element::ExData - : XFA_Element::Text; - break; - } - case XFA_Element::Barcode: - case XFA_Element::Button: - case XFA_Element::PasswordEdit: - case XFA_Element::Signature: - case XFA_Element::TextEdit: - default: - eValueType = XFA_Element::Text; - break; - } - defValue->JSObject()->GetProperty(0, eValueType, true); - - return pUIChild; -} - -} // namespace - -CXFA_WidgetData::CXFA_WidgetData(CXFA_Node* pNode) - : m_pNode(pNode), - m_bIsNull(true), - m_bPreNull(true), - m_pUiChildNode(nullptr), - m_eUIType(XFA_Element::Unknown) {} - -CXFA_WidgetData::~CXFA_WidgetData() = default; - -CXFA_Node* CXFA_WidgetData::GetUIChild() { - if (m_eUIType == XFA_Element::Unknown) - m_pUiChildNode = CreateUIChild(m_pNode, m_eUIType); - - return m_pUiChildNode; -} - -XFA_Element CXFA_WidgetData::GetUIType() { - GetUIChild(); - return m_eUIType; -} - -WideString CXFA_WidgetData::GetRawValue() const { - return m_pNode->JSObject()->GetContent(false); -} - -bool CXFA_WidgetData::IsOpenAccess() const { - for (CXFA_Node* pNode = m_pNode; pNode; - pNode = pNode->GetNodeItem(XFA_NODEITEM_Parent, - XFA_ObjectType::ContainerNode)) { - XFA_AttributeEnum iAcc = pNode->JSObject()->GetEnum(XFA_Attribute::Access); - if (iAcc != XFA_AttributeEnum::Open) - return false; - } - return true; -} - -int32_t CXFA_WidgetData::GetRotate() const { - pdfium::Optional degrees = - m_pNode->JSObject()->TryInteger(XFA_Attribute::Rotate, false); - return degrees ? XFA_MapRotation(*degrees) / 90 * 90 : 0; -} - -CXFA_Border* CXFA_WidgetData::GetBorder(bool bModified) { - return m_pNode->JSObject()->GetProperty(0, XFA_Element::Border, - bModified); -} - -CXFA_Caption* CXFA_WidgetData::GetCaption() { - return m_pNode->JSObject()->GetProperty(0, XFA_Element::Caption, - false); -} - -CXFA_Font* CXFA_WidgetData::GetFont(bool bModified) { - return m_pNode->JSObject()->GetProperty(0, XFA_Element::Font, - bModified); -} - -CXFA_Margin* CXFA_WidgetData::GetMargin() { - return m_pNode->JSObject()->GetProperty(0, XFA_Element::Margin, - false); -} - -CXFA_Para* CXFA_WidgetData::GetPara() { - return m_pNode->JSObject()->GetProperty(0, XFA_Element::Para, - false); -} - -std::vector CXFA_WidgetData::GetEventByActivity( - XFA_AttributeEnum iActivity, - bool bIsFormReady) { - std::vector events; - for (CXFA_Node* node : m_pNode->GetNodeList(0, XFA_Element::Event)) { - auto* event = static_cast(node); - if (event->GetActivity() == iActivity) { - if (iActivity == XFA_AttributeEnum::Ready) { - WideString wsRef = event->GetRef(); - if (bIsFormReady) { - if (wsRef == WideStringView(L"$form")) - events.push_back(event); - } else { - if (wsRef == WideStringView(L"$layout")) - events.push_back(event); - } - } else { - events.push_back(event); - } - } - } - return events; -} - -CXFA_Value* CXFA_WidgetData::GetDefaultValue() { - CXFA_Node* pTemNode = m_pNode->GetTemplateNode(); - return pTemNode->JSObject()->GetProperty(0, XFA_Element::Value, - false); -} - -CXFA_Value* CXFA_WidgetData::GetFormValue() { - return m_pNode->JSObject()->GetProperty(0, XFA_Element::Value, - false); -} - -CXFA_Calculate* CXFA_WidgetData::GetCalculate() { - return m_pNode->JSObject()->GetProperty( - 0, XFA_Element::Calculate, false); -} - -CXFA_Validate* CXFA_WidgetData::GetValidate(bool bModified) { - return m_pNode->JSObject()->GetProperty( - 0, XFA_Element::Validate, bModified); -} - -CXFA_Bind* CXFA_WidgetData::GetBind() { - return m_pNode->JSObject()->GetProperty(0, XFA_Element::Bind, - false); -} - -pdfium::Optional CXFA_WidgetData::TryWidth() { - return m_pNode->JSObject()->TryMeasureAsFloat(XFA_Attribute::W); -} - -pdfium::Optional CXFA_WidgetData::TryHeight() { - return m_pNode->JSObject()->TryMeasureAsFloat(XFA_Attribute::H); -} - -pdfium::Optional CXFA_WidgetData::TryMinWidth() { - return m_pNode->JSObject()->TryMeasureAsFloat(XFA_Attribute::MinW); -} - -pdfium::Optional CXFA_WidgetData::TryMinHeight() { - return m_pNode->JSObject()->TryMeasureAsFloat(XFA_Attribute::MinH); -} - -pdfium::Optional CXFA_WidgetData::TryMaxWidth() { - return m_pNode->JSObject()->TryMeasureAsFloat(XFA_Attribute::MaxW); -} - -pdfium::Optional CXFA_WidgetData::TryMaxHeight() { - return m_pNode->JSObject()->TryMeasureAsFloat(XFA_Attribute::MaxH); -} - -CXFA_Border* CXFA_WidgetData::GetUIBorder() { - CXFA_Node* pUIChild = GetUIChild(); - return pUIChild ? pUIChild->JSObject()->GetProperty( - 0, XFA_Element::Border, false) - : nullptr; -} - -CFX_RectF CXFA_WidgetData::GetUIMargin() { - CXFA_Node* pUIChild = GetUIChild(); - CXFA_Margin* mgUI = nullptr; - if (pUIChild) { - mgUI = pUIChild->JSObject()->GetProperty( - 0, XFA_Element::Margin, false); - } - - if (!mgUI) - return CFX_RectF(); - - CXFA_Border* border = GetUIBorder(); - if (border && border->GetPresence() != XFA_AttributeEnum::Visible) - return CFX_RectF(); - - pdfium::Optional left = mgUI->TryLeftInset(); - pdfium::Optional top = mgUI->TryTopInset(); - pdfium::Optional right = mgUI->TryRightInset(); - pdfium::Optional bottom = mgUI->TryBottomInset(); - if (border) { - bool bVisible = false; - float fThickness = 0; - XFA_AttributeEnum iType = XFA_AttributeEnum::Unknown; - std::tie(iType, bVisible, fThickness) = border->Get3DStyle(); - if (!left || !top || !right || !bottom) { - std::vector strokes = border->GetStrokes(); - if (!top) - top = GetEdgeThickness(strokes, bVisible, 0); - if (!right) - right = GetEdgeThickness(strokes, bVisible, 1); - if (!bottom) - bottom = GetEdgeThickness(strokes, bVisible, 2); - if (!left) - left = GetEdgeThickness(strokes, bVisible, 3); - } - } - return CFX_RectF(left.value_or(0.0), top.value_or(0.0), right.value_or(0.0), - bottom.value_or(0.0)); -} - -XFA_AttributeEnum CXFA_WidgetData::GetButtonHighlight() { - CXFA_Node* pUIChild = GetUIChild(); - if (pUIChild) - return pUIChild->JSObject()->GetEnum(XFA_Attribute::Highlight); - return XFA_AttributeEnum::Inverted; -} - -bool CXFA_WidgetData::HasButtonRollover() const { - CXFA_Items* pItems = - m_pNode->GetChild(0, XFA_Element::Items, false); - if (!pItems) - return false; - - for (CXFA_Node* pText = pItems->GetNodeItem(XFA_NODEITEM_FirstChild); pText; - pText = pText->GetNodeItem(XFA_NODEITEM_NextSibling)) { - if (pText->JSObject()->GetCData(XFA_Attribute::Name) == L"rollover") - return !pText->JSObject()->GetContent(false).IsEmpty(); - } - return false; -} - -bool CXFA_WidgetData::HasButtonDown() const { - CXFA_Items* pItems = - m_pNode->GetChild(0, XFA_Element::Items, false); - if (!pItems) - return false; - - for (CXFA_Node* pText = pItems->GetNodeItem(XFA_NODEITEM_FirstChild); pText; - pText = pText->GetNodeItem(XFA_NODEITEM_NextSibling)) { - if (pText->JSObject()->GetCData(XFA_Attribute::Name) == L"down") - return !pText->JSObject()->GetContent(false).IsEmpty(); - } - return false; -} - -bool CXFA_WidgetData::IsCheckButtonRound() { - CXFA_Node* pUIChild = GetUIChild(); - if (pUIChild) - return pUIChild->JSObject()->GetEnum(XFA_Attribute::Shape) == - XFA_AttributeEnum::Round; - return false; -} - -XFA_AttributeEnum CXFA_WidgetData::GetCheckButtonMark() { - CXFA_Node* pUIChild = GetUIChild(); - if (pUIChild) - return pUIChild->JSObject()->GetEnum(XFA_Attribute::Mark); - return XFA_AttributeEnum::Default; -} - -bool CXFA_WidgetData::IsRadioButton() { - CXFA_Node* pParent = m_pNode->GetNodeItem(XFA_NODEITEM_Parent); - return pParent && pParent->GetElementType() == XFA_Element::ExclGroup; -} - -float CXFA_WidgetData::GetCheckButtonSize() { - CXFA_Node* pUIChild = GetUIChild(); - if (pUIChild) { - return pUIChild->JSObject() - ->GetMeasure(XFA_Attribute::Size) - .ToUnit(XFA_Unit::Pt); - } - return CXFA_Measurement(10, XFA_Unit::Pt).ToUnit(XFA_Unit::Pt); -} - -bool CXFA_WidgetData::IsAllowNeutral() { - CXFA_Node* pUIChild = GetUIChild(); - return pUIChild && - pUIChild->JSObject()->GetBoolean(XFA_Attribute::AllowNeutral); -} - -XFA_CHECKSTATE CXFA_WidgetData::GetCheckState() { - WideString wsValue = GetRawValue(); - if (wsValue.IsEmpty()) - return XFA_CHECKSTATE_Off; - - if (CXFA_Items* pItems = - m_pNode->GetChild(0, XFA_Element::Items, false)) { - CXFA_Node* pText = pItems->GetNodeItem(XFA_NODEITEM_FirstChild); - int32_t i = 0; - while (pText) { - pdfium::Optional wsContent = - pText->JSObject()->TryContent(false, true); - if (wsContent && *wsContent == wsValue) - return static_cast(i); - - i++; - pText = pText->GetNodeItem(XFA_NODEITEM_NextSibling); - } - } - return XFA_CHECKSTATE_Off; -} - -void CXFA_WidgetData::SetCheckState(XFA_CHECKSTATE eCheckState, bool bNotify) { - CXFA_Node* node = GetExclGroupNode(); - if (!node) { - CXFA_Items* pItems = - m_pNode->GetChild(0, XFA_Element::Items, false); - if (!pItems) - return; - - int32_t i = -1; - CXFA_Node* pText = pItems->GetNodeItem(XFA_NODEITEM_FirstChild); - WideString wsContent; - while (pText) { - i++; - if (i == eCheckState) { - wsContent = pText->JSObject()->GetContent(false); - break; - } - pText = pText->GetNodeItem(XFA_NODEITEM_NextSibling); - } - SyncValue(wsContent, bNotify); - return; - } - - CXFA_WidgetData exclGroup(node); - WideString wsValue; - if (eCheckState != XFA_CHECKSTATE_Off) { - if (CXFA_Items* pItems = - m_pNode->GetChild(0, XFA_Element::Items, false)) { - CXFA_Node* pText = pItems->GetNodeItem(XFA_NODEITEM_FirstChild); - if (pText) - wsValue = pText->JSObject()->GetContent(false); - } - } - CXFA_Node* pChild = exclGroup.GetNode()->GetNodeItem(XFA_NODEITEM_FirstChild); - for (; pChild; pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { - if (pChild->GetElementType() != XFA_Element::Field) - continue; - - CXFA_Items* pItem = - pChild->GetChild(0, XFA_Element::Items, false); - if (!pItem) - continue; - - CXFA_Node* pItemchild = pItem->GetNodeItem(XFA_NODEITEM_FirstChild); - if (!pItemchild) - continue; - - WideString text = pItemchild->JSObject()->GetContent(false); - WideString wsChildValue = text; - if (wsValue != text) { - pItemchild = pItemchild->GetNodeItem(XFA_NODEITEM_NextSibling); - if (pItemchild) - wsChildValue = pItemchild->JSObject()->GetContent(false); - else - wsChildValue.clear(); - } - CXFA_WidgetData ch(pChild); - ch.SyncValue(wsChildValue, bNotify); - } - exclGroup.SyncValue(wsValue, bNotify); -} - -CXFA_Node* CXFA_WidgetData::GetExclGroupNode() { - CXFA_Node* pExcl = ToNode(m_pNode->GetNodeItem(XFA_NODEITEM_Parent)); - if (!pExcl || pExcl->GetElementType() != XFA_Element::ExclGroup) - return nullptr; - return pExcl; -} - -CXFA_Node* CXFA_WidgetData::GetSelectedMember() { - CXFA_Node* pSelectedMember = nullptr; - WideString wsState = GetRawValue(); - if (wsState.IsEmpty()) - return pSelectedMember; - - for (CXFA_Node* pNode = ToNode(m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild)); - pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { - CXFA_WidgetData widgetData(pNode); - if (widgetData.GetCheckState() == XFA_CHECKSTATE_On) { - pSelectedMember = pNode; - break; - } - } - return pSelectedMember; -} - -CXFA_Node* CXFA_WidgetData::SetSelectedMember(const WideStringView& wsName, - bool bNotify) { - uint32_t nameHash = FX_HashCode_GetW(wsName, false); - for (CXFA_Node* pNode = ToNode(m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild)); - pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { - if (pNode->GetNameHash() == nameHash) { - CXFA_WidgetData widgetData(pNode); - widgetData.SetCheckState(XFA_CHECKSTATE_On, bNotify); - return pNode; - } - } - return nullptr; -} - -void CXFA_WidgetData::SetSelectedMemberByValue(const WideStringView& wsValue, - bool bNotify, - bool bScriptModify, - bool bSyncData) { - WideString wsExclGroup; - for (CXFA_Node* pNode = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); pNode; - pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { - if (pNode->GetElementType() != XFA_Element::Field) - continue; - - CXFA_Items* pItem = - pNode->GetChild(0, XFA_Element::Items, false); - if (!pItem) - continue; - - CXFA_Node* pItemchild = pItem->GetNodeItem(XFA_NODEITEM_FirstChild); - if (!pItemchild) - continue; - - WideString wsChildValue = pItemchild->JSObject()->GetContent(false); - if (wsValue != wsChildValue) { - pItemchild = pItemchild->GetNodeItem(XFA_NODEITEM_NextSibling); - if (pItemchild) - wsChildValue = pItemchild->JSObject()->GetContent(false); - else - wsChildValue.clear(); - } else { - wsExclGroup = wsValue; - } - pNode->JSObject()->SetContent(wsChildValue, wsChildValue, bNotify, - bScriptModify, false); - } - if (m_pNode) { - m_pNode->JSObject()->SetContent(wsExclGroup, wsExclGroup, bNotify, - bScriptModify, bSyncData); - } -} - -CXFA_Node* CXFA_WidgetData::GetExclGroupFirstMember() { - CXFA_Node* pExcl = GetNode(); - if (!pExcl) - return nullptr; - - CXFA_Node* pNode = pExcl->GetNodeItem(XFA_NODEITEM_FirstChild); - while (pNode) { - if (pNode->GetElementType() == XFA_Element::Field) - return pNode; - - pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling); - } - return nullptr; -} -CXFA_Node* CXFA_WidgetData::GetExclGroupNextMember(CXFA_Node* pNode) { - if (!pNode) - return nullptr; - - CXFA_Node* pNodeField = pNode->GetNodeItem(XFA_NODEITEM_NextSibling); - while (pNodeField) { - if (pNodeField->GetElementType() == XFA_Element::Field) - return pNodeField; - - pNodeField = pNodeField->GetNodeItem(XFA_NODEITEM_NextSibling); - } - return nullptr; -} - -bool CXFA_WidgetData::IsChoiceListCommitOnSelect() { - CXFA_Node* pUIChild = GetUIChild(); - if (pUIChild) { - return pUIChild->JSObject()->GetEnum(XFA_Attribute::CommitOn) == - XFA_AttributeEnum::Select; - } - return true; -} - -bool CXFA_WidgetData::IsChoiceListAllowTextEntry() { - CXFA_Node* pUIChild = GetUIChild(); - return pUIChild && pUIChild->JSObject()->GetBoolean(XFA_Attribute::TextEntry); -} - -bool CXFA_WidgetData::IsChoiceListMultiSelect() { - CXFA_Node* pUIChild = GetUIChild(); - if (pUIChild) { - return pUIChild->JSObject()->GetEnum(XFA_Attribute::Open) == - XFA_AttributeEnum::MultiSelect; - } - return false; -} - -bool CXFA_WidgetData::IsListBox() { - CXFA_Node* pUIChild = GetUIChild(); - if (!pUIChild) - return false; - - XFA_AttributeEnum attr = pUIChild->JSObject()->GetEnum(XFA_Attribute::Open); - return attr == XFA_AttributeEnum::Always || - attr == XFA_AttributeEnum::MultiSelect; -} - -int32_t CXFA_WidgetData::CountChoiceListItems(bool bSaveValue) { - std::vector pItems; - int32_t iCount = 0; - for (CXFA_Node* pNode = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); pNode; - pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { - if (pNode->GetElementType() != XFA_Element::Items) - continue; - iCount++; - pItems.push_back(pNode); - if (iCount == 2) - break; - } - if (iCount == 0) - return 0; - - CXFA_Node* pItem = pItems[0]; - if (iCount > 1) { - bool bItemOneHasSave = - pItems[0]->JSObject()->GetBoolean(XFA_Attribute::Save); - bool bItemTwoHasSave = - pItems[1]->JSObject()->GetBoolean(XFA_Attribute::Save); - if (bItemOneHasSave != bItemTwoHasSave && bSaveValue == bItemTwoHasSave) - pItem = pItems[1]; - } - return pItem->CountChildren(XFA_Element::Unknown, false); -} - -pdfium::Optional CXFA_WidgetData::GetChoiceListItem( - int32_t nIndex, - bool bSaveValue) { - std::vector pItemsArray; - int32_t iCount = 0; - for (CXFA_Node* pNode = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); pNode; - pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { - if (pNode->GetElementType() != XFA_Element::Items) - continue; - - ++iCount; - pItemsArray.push_back(pNode); - if (iCount == 2) - break; - } - if (iCount == 0) - return {}; - - CXFA_Node* pItems = pItemsArray[0]; - if (iCount > 1) { - bool bItemOneHasSave = - pItemsArray[0]->JSObject()->GetBoolean(XFA_Attribute::Save); - bool bItemTwoHasSave = - pItemsArray[1]->JSObject()->GetBoolean(XFA_Attribute::Save); - if (bItemOneHasSave != bItemTwoHasSave && bSaveValue == bItemTwoHasSave) - pItems = pItemsArray[1]; - } - if (!pItems) - return {}; - - CXFA_Node* pItem = - pItems->GetChild(nIndex, XFA_Element::Unknown, false); - if (pItem) - return {pItem->JSObject()->GetContent(false)}; - return {}; -} - -std::vector CXFA_WidgetData::GetChoiceListItems(bool bSaveValue) { - std::vector items; - for (CXFA_Node* pNode = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); - pNode && items.size() < 2; - pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { - if (pNode->GetElementType() == XFA_Element::Items) - items.push_back(pNode); - } - if (items.empty()) - return std::vector(); - - CXFA_Node* pItem = items.front(); - if (items.size() > 1) { - bool bItemOneHasSave = - items[0]->JSObject()->GetBoolean(XFA_Attribute::Save); - bool bItemTwoHasSave = - items[1]->JSObject()->GetBoolean(XFA_Attribute::Save); - if (bItemOneHasSave != bItemTwoHasSave && bSaveValue == bItemTwoHasSave) - pItem = items[1]; - } - - std::vector wsTextArray; - for (CXFA_Node* pNode = pItem->GetNodeItem(XFA_NODEITEM_FirstChild); pNode; - pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { - wsTextArray.emplace_back(pNode->JSObject()->GetContent(false)); - } - return wsTextArray; -} - -int32_t CXFA_WidgetData::CountSelectedItems() { - std::vector wsValueArray = GetSelectedItemsValue(); - if (IsListBox() || !IsChoiceListAllowTextEntry()) - return pdfium::CollectionSize(wsValueArray); - - int32_t iSelected = 0; - std::vector wsSaveTextArray = GetChoiceListItems(true); - for (const auto& value : wsValueArray) { - if (pdfium::ContainsValue(wsSaveTextArray, value)) - iSelected++; - } - return iSelected; -} - -int32_t CXFA_WidgetData::GetSelectedItem(int32_t nIndex) { - std::vector wsValueArray = GetSelectedItemsValue(); - if (!pdfium::IndexInBounds(wsValueArray, nIndex)) - return -1; - - std::vector wsSaveTextArray = GetChoiceListItems(true); - auto it = std::find(wsSaveTextArray.begin(), wsSaveTextArray.end(), - wsValueArray[nIndex]); - return it != wsSaveTextArray.end() ? it - wsSaveTextArray.begin() : -1; -} - -std::vector CXFA_WidgetData::GetSelectedItems() { - std::vector iSelArray; - std::vector wsValueArray = GetSelectedItemsValue(); - std::vector wsSaveTextArray = GetChoiceListItems(true); - for (const auto& value : wsValueArray) { - auto it = std::find(wsSaveTextArray.begin(), wsSaveTextArray.end(), value); - if (it != wsSaveTextArray.end()) - iSelArray.push_back(it - wsSaveTextArray.begin()); - } - return iSelArray; -} - -std::vector CXFA_WidgetData::GetSelectedItemsValue() { - std::vector wsSelTextArray; - WideString wsValue = GetRawValue(); - if (IsChoiceListMultiSelect()) { - if (!wsValue.IsEmpty()) { - size_t iStart = 0; - size_t iLength = wsValue.GetLength(); - auto iEnd = wsValue.Find(L'\n', iStart); - iEnd = (!iEnd.has_value()) ? iLength : iEnd; - while (iEnd >= iStart) { - wsSelTextArray.push_back(wsValue.Mid(iStart, iEnd.value() - iStart)); - iStart = iEnd.value() + 1; - if (iStart >= iLength) - break; - iEnd = wsValue.Find(L'\n', iStart); - if (!iEnd.has_value()) - wsSelTextArray.push_back(wsValue.Mid(iStart, iLength - iStart)); - } - } - } else { - wsSelTextArray.push_back(wsValue); - } - return wsSelTextArray; -} - -bool CXFA_WidgetData::GetItemState(int32_t nIndex) { - std::vector wsSaveTextArray = GetChoiceListItems(true); - return pdfium::IndexInBounds(wsSaveTextArray, nIndex) && - pdfium::ContainsValue(GetSelectedItemsValue(), - wsSaveTextArray[nIndex]); -} - -void CXFA_WidgetData::SetItemState(int32_t nIndex, - bool bSelected, - bool bNotify, - bool bScriptModify, - bool bSyncData) { - std::vector wsSaveTextArray = GetChoiceListItems(true); - if (!pdfium::IndexInBounds(wsSaveTextArray, nIndex)) - return; - - int32_t iSel = -1; - std::vector wsValueArray = GetSelectedItemsValue(); - auto it = std::find(wsValueArray.begin(), wsValueArray.end(), - wsSaveTextArray[nIndex]); - if (it != wsValueArray.end()) - iSel = it - wsValueArray.begin(); - - if (IsChoiceListMultiSelect()) { - if (bSelected) { - if (iSel < 0) { - WideString wsValue = GetRawValue(); - if (!wsValue.IsEmpty()) { - wsValue += L"\n"; - } - wsValue += wsSaveTextArray[nIndex]; - m_pNode->JSObject()->SetContent(wsValue, wsValue, bNotify, - bScriptModify, bSyncData); - } - } else if (iSel >= 0) { - std::vector iSelArray = GetSelectedItems(); - auto it = std::find(iSelArray.begin(), iSelArray.end(), nIndex); - if (it != iSelArray.end()) - iSelArray.erase(it); - SetSelectedItems(iSelArray, bNotify, bScriptModify, bSyncData); - } - } else { - if (bSelected) { - if (iSel < 0) { - WideString wsSaveText = wsSaveTextArray[nIndex]; - m_pNode->JSObject()->SetContent(wsSaveText, - GetFormatDataValue(wsSaveText), bNotify, - bScriptModify, bSyncData); - } - } else if (iSel >= 0) { - m_pNode->JSObject()->SetContent(WideString(), WideString(), bNotify, - bScriptModify, bSyncData); - } - } -} - -void CXFA_WidgetData::SetSelectedItems(const std::vector& iSelArray, - bool bNotify, - bool bScriptModify, - bool bSyncData) { - WideString wsValue; - int32_t iSize = pdfium::CollectionSize(iSelArray); - if (iSize >= 1) { - std::vector wsSaveTextArray = GetChoiceListItems(true); - WideString wsItemValue; - for (int32_t i = 0; i < iSize; i++) { - wsItemValue = (iSize == 1) ? wsSaveTextArray[iSelArray[i]] - : wsSaveTextArray[iSelArray[i]] + L"\n"; - wsValue += wsItemValue; - } - } - WideString wsFormat(wsValue); - if (!IsChoiceListMultiSelect()) - wsFormat = GetFormatDataValue(wsValue); - - m_pNode->JSObject()->SetContent(wsValue, wsFormat, bNotify, bScriptModify, - bSyncData); -} - -void CXFA_WidgetData::ClearAllSelections() { - CXFA_Node* pBind = m_pNode->GetBindData(); - if (!pBind || !IsChoiceListMultiSelect()) { - SyncValue(WideString(), false); - return; - } - - while (CXFA_Node* pChildNode = pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) - pBind->RemoveChild(pChildNode, true); -} - -void CXFA_WidgetData::InsertItem(const WideString& wsLabel, - const WideString& wsValue, - bool bNotify) { - int32_t nIndex = -1; - WideString wsNewValue(wsValue); - if (wsNewValue.IsEmpty()) - wsNewValue = wsLabel; - - std::vector listitems; - for (CXFA_Node* pItem = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); pItem; - pItem = pItem->GetNodeItem(XFA_NODEITEM_NextSibling)) { - if (pItem->GetElementType() == XFA_Element::Items) - listitems.push_back(pItem); - } - if (listitems.empty()) { - CXFA_Node* pItems = m_pNode->CreateSamePacketNode(XFA_Element::Items); - m_pNode->InsertChild(-1, pItems); - InsertListTextItem(pItems, wsLabel, nIndex); - CXFA_Node* pSaveItems = m_pNode->CreateSamePacketNode(XFA_Element::Items); - m_pNode->InsertChild(-1, pSaveItems); - pSaveItems->JSObject()->SetBoolean(XFA_Attribute::Save, true, false); - InsertListTextItem(pSaveItems, wsNewValue, nIndex); - } else if (listitems.size() > 1) { - for (int32_t i = 0; i < 2; i++) { - CXFA_Node* pNode = listitems[i]; - bool bHasSave = pNode->JSObject()->GetBoolean(XFA_Attribute::Save); - if (bHasSave) - InsertListTextItem(pNode, wsNewValue, nIndex); - else - InsertListTextItem(pNode, wsLabel, nIndex); - } - } else { - CXFA_Node* pNode = listitems[0]; - pNode->JSObject()->SetBoolean(XFA_Attribute::Save, false, false); - pNode->JSObject()->SetEnum(XFA_Attribute::Presence, - XFA_AttributeEnum::Visible, false); - CXFA_Node* pSaveItems = m_pNode->CreateSamePacketNode(XFA_Element::Items); - m_pNode->InsertChild(-1, pSaveItems); - pSaveItems->JSObject()->SetBoolean(XFA_Attribute::Save, true, false); - pSaveItems->JSObject()->SetEnum(XFA_Attribute::Presence, - XFA_AttributeEnum::Hidden, false); - CXFA_Node* pListNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); - int32_t i = 0; - while (pListNode) { - InsertListTextItem(pSaveItems, pListNode->JSObject()->GetContent(false), - i); - ++i; - - pListNode = pListNode->GetNodeItem(XFA_NODEITEM_NextSibling); - } - InsertListTextItem(pNode, wsLabel, nIndex); - InsertListTextItem(pSaveItems, wsNewValue, nIndex); - } - if (!bNotify) - return; - - m_pNode->GetDocument()->GetNotify()->OnWidgetListItemAdded( - this, wsLabel.c_str(), wsValue.c_str(), nIndex); -} - -void CXFA_WidgetData::GetItemLabel(const WideStringView& wsValue, - WideString& wsLabel) { - int32_t iCount = 0; - std::vector listitems; - CXFA_Node* pItems = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); - for (; pItems; pItems = pItems->GetNodeItem(XFA_NODEITEM_NextSibling)) { - if (pItems->GetElementType() != XFA_Element::Items) - continue; - iCount++; - listitems.push_back(pItems); - } - - if (iCount <= 1) { - wsLabel = wsValue; - return; - } - - CXFA_Node* pLabelItems = listitems[0]; - bool bSave = pLabelItems->JSObject()->GetBoolean(XFA_Attribute::Save); - CXFA_Node* pSaveItems = nullptr; - if (bSave) { - pSaveItems = pLabelItems; - pLabelItems = listitems[1]; - } else { - pSaveItems = listitems[1]; - } - iCount = 0; - - int32_t iSearch = -1; - for (CXFA_Node* pChildItem = pSaveItems->GetNodeItem(XFA_NODEITEM_FirstChild); - pChildItem; - pChildItem = pChildItem->GetNodeItem(XFA_NODEITEM_NextSibling)) { - if (pChildItem->JSObject()->GetContent(false) == wsValue) { - iSearch = iCount; - break; - } - iCount++; - } - if (iSearch < 0) - return; - - CXFA_Node* pText = - pLabelItems->GetChild(iSearch, XFA_Element::Unknown, false); - if (pText) - wsLabel = pText->JSObject()->GetContent(false); -} - -WideString CXFA_WidgetData::GetItemValue(const WideStringView& wsLabel) { - int32_t iCount = 0; - std::vector listitems; - for (CXFA_Node* pItems = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); - pItems; pItems = pItems->GetNodeItem(XFA_NODEITEM_NextSibling)) { - if (pItems->GetElementType() != XFA_Element::Items) - continue; - iCount++; - listitems.push_back(pItems); - } - if (iCount <= 1) - return WideString(wsLabel); - - CXFA_Node* pLabelItems = listitems[0]; - bool bSave = pLabelItems->JSObject()->GetBoolean(XFA_Attribute::Save); - CXFA_Node* pSaveItems = nullptr; - if (bSave) { - pSaveItems = pLabelItems; - pLabelItems = listitems[1]; - } else { - pSaveItems = listitems[1]; - } - iCount = 0; - - int32_t iSearch = -1; - WideString wsContent; - CXFA_Node* pChildItem = pLabelItems->GetNodeItem(XFA_NODEITEM_FirstChild); - for (; pChildItem; - pChildItem = pChildItem->GetNodeItem(XFA_NODEITEM_NextSibling)) { - if (pChildItem->JSObject()->GetContent(false) == wsLabel) { - iSearch = iCount; - break; - } - iCount++; - } - if (iSearch < 0) - return L""; - - CXFA_Node* pText = - pSaveItems->GetChild(iSearch, XFA_Element::Unknown, false); - return pText ? pText->JSObject()->GetContent(false) : L""; -} - -bool CXFA_WidgetData::DeleteItem(int32_t nIndex, - bool bNotify, - bool bScriptModify) { - bool bSetValue = false; - CXFA_Node* pItems = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); - for (; pItems; pItems = pItems->GetNodeItem(XFA_NODEITEM_NextSibling)) { - if (pItems->GetElementType() != XFA_Element::Items) - continue; - - if (nIndex < 0) { - while (CXFA_Node* pNode = pItems->GetNodeItem(XFA_NODEITEM_FirstChild)) { - pItems->RemoveChild(pNode, true); - } - } else { - if (!bSetValue && pItems->JSObject()->GetBoolean(XFA_Attribute::Save)) { - SetItemState(nIndex, false, true, bScriptModify, true); - bSetValue = true; - } - int32_t i = 0; - CXFA_Node* pNode = pItems->GetNodeItem(XFA_NODEITEM_FirstChild); - while (pNode) { - if (i == nIndex) { - pItems->RemoveChild(pNode, true); - break; - } - i++; - pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling); - } - } - } - if (bNotify) - m_pNode->GetDocument()->GetNotify()->OnWidgetListItemRemoved(this, nIndex); - return true; -} - -bool CXFA_WidgetData::IsHorizontalScrollPolicyOff() { - CXFA_Node* pUIChild = GetUIChild(); - if (pUIChild) { - return pUIChild->JSObject()->GetEnum(XFA_Attribute::HScrollPolicy) == - XFA_AttributeEnum::Off; - } - return false; -} - -bool CXFA_WidgetData::IsVerticalScrollPolicyOff() { - CXFA_Node* pUIChild = GetUIChild(); - if (pUIChild) { - return pUIChild->JSObject()->GetEnum(XFA_Attribute::VScrollPolicy) == - XFA_AttributeEnum::Off; - } - return false; -} - -pdfium::Optional CXFA_WidgetData::GetNumberOfCells() { - CXFA_Node* pUIChild = GetUIChild(); - if (!pUIChild) - return {}; - if (CXFA_Comb* pNode = - pUIChild->GetChild(0, XFA_Element::Comb, false)) - return {pNode->JSObject()->GetInteger(XFA_Attribute::NumberOfCells)}; - return {}; -} - -WideString CXFA_WidgetData::GetBarcodeType() { - CXFA_Node* pUIChild = GetUIChild(); - return pUIChild - ? WideString(pUIChild->JSObject()->GetCData(XFA_Attribute::Type)) - : WideString(); -} - -pdfium::Optional -CXFA_WidgetData::GetBarcodeAttribute_CharEncoding() { - pdfium::Optional wsCharEncoding = - GetUIChild()->JSObject()->TryCData(XFA_Attribute::CharEncoding, true); - if (!wsCharEncoding) - return {}; - if (wsCharEncoding->CompareNoCase(L"UTF-16")) - return {CHAR_ENCODING_UNICODE}; - if (wsCharEncoding->CompareNoCase(L"UTF-8")) - return {CHAR_ENCODING_UTF8}; - return {}; -} - -pdfium::Optional CXFA_WidgetData::GetBarcodeAttribute_Checksum() { - pdfium::Optional checksum = - GetUIChild()->JSObject()->TryEnum(XFA_Attribute::Checksum, true); - if (!checksum) - return {}; - - switch (*checksum) { - case XFA_AttributeEnum::None: - return {false}; - case XFA_AttributeEnum::Auto: - return {true}; - case XFA_AttributeEnum::Checksum_1mod10: - case XFA_AttributeEnum::Checksum_1mod10_1mod11: - case XFA_AttributeEnum::Checksum_2mod10: - default: - break; - } - return {}; -} - -pdfium::Optional CXFA_WidgetData::GetBarcodeAttribute_DataLength() { - pdfium::Optional wsDataLength = - GetUIChild()->JSObject()->TryCData(XFA_Attribute::DataLength, true); - if (!wsDataLength) - return {}; - - return {FXSYS_wtoi(wsDataLength->c_str())}; -} - -pdfium::Optional CXFA_WidgetData::GetBarcodeAttribute_StartChar() { - pdfium::Optional wsStartEndChar = - GetUIChild()->JSObject()->TryCData(XFA_Attribute::StartChar, true); - if (!wsStartEndChar || wsStartEndChar->IsEmpty()) - return {}; - - return {static_cast((*wsStartEndChar)[0])}; -} - -pdfium::Optional CXFA_WidgetData::GetBarcodeAttribute_EndChar() { - pdfium::Optional wsStartEndChar = - GetUIChild()->JSObject()->TryCData(XFA_Attribute::EndChar, true); - if (!wsStartEndChar || wsStartEndChar->IsEmpty()) - return {}; - - return {static_cast((*wsStartEndChar)[0])}; -} - -pdfium::Optional CXFA_WidgetData::GetBarcodeAttribute_ECLevel() { - pdfium::Optional wsECLevel = GetUIChild()->JSObject()->TryCData( - XFA_Attribute::ErrorCorrectionLevel, true); - if (!wsECLevel) - return {}; - return {FXSYS_wtoi(wsECLevel->c_str())}; -} - -pdfium::Optional CXFA_WidgetData::GetBarcodeAttribute_ModuleWidth() { - pdfium::Optional moduleWidthHeight = - GetUIChild()->JSObject()->TryMeasure(XFA_Attribute::ModuleWidth, true); - if (!moduleWidthHeight) - return {}; - - return {static_cast(moduleWidthHeight->ToUnit(XFA_Unit::Pt))}; -} - -pdfium::Optional CXFA_WidgetData::GetBarcodeAttribute_ModuleHeight() { - pdfium::Optional moduleWidthHeight = - GetUIChild()->JSObject()->TryMeasure(XFA_Attribute::ModuleHeight, true); - if (!moduleWidthHeight) - return {}; - - return {static_cast(moduleWidthHeight->ToUnit(XFA_Unit::Pt))}; -} - -pdfium::Optional CXFA_WidgetData::GetBarcodeAttribute_PrintChecksum() { - return GetUIChild()->JSObject()->TryBoolean(XFA_Attribute::PrintCheckDigit, - true); -} - -pdfium::Optional -CXFA_WidgetData::GetBarcodeAttribute_TextLocation() { - pdfium::Optional textLocation = - GetUIChild()->JSObject()->TryEnum(XFA_Attribute::TextLocation, true); - if (!textLocation) - return {}; - - switch (*textLocation) { - case XFA_AttributeEnum::None: - return {BC_TEXT_LOC_NONE}; - case XFA_AttributeEnum::Above: - return {BC_TEXT_LOC_ABOVE}; - case XFA_AttributeEnum::Below: - return {BC_TEXT_LOC_BELOW}; - case XFA_AttributeEnum::AboveEmbedded: - return {BC_TEXT_LOC_ABOVEEMBED}; - case XFA_AttributeEnum::BelowEmbedded: - return {BC_TEXT_LOC_BELOWEMBED}; - default: - break; - } - return {}; -} - -pdfium::Optional CXFA_WidgetData::GetBarcodeAttribute_Truncate() { - return GetUIChild()->JSObject()->TryBoolean(XFA_Attribute::Truncate, true); -} - -pdfium::Optional -CXFA_WidgetData::GetBarcodeAttribute_WideNarrowRatio() { - pdfium::Optional wsWideNarrowRatio = - GetUIChild()->JSObject()->TryCData(XFA_Attribute::WideNarrowRatio, true); - if (!wsWideNarrowRatio) - return {}; - - pdfium::Optional ptPos = wsWideNarrowRatio->Find(':'); - if (!ptPos) - return {static_cast(FXSYS_wtoi(wsWideNarrowRatio->c_str()))}; - - int32_t fB = FXSYS_wtoi( - wsWideNarrowRatio->Right(wsWideNarrowRatio->GetLength() - (*ptPos + 1)) - .c_str()); - if (!fB) - return {0}; - - int32_t fA = FXSYS_wtoi(wsWideNarrowRatio->Left(*ptPos).c_str()); - float result = static_cast(fA) / static_cast(fB); - return {static_cast(result)}; -} - -WideString CXFA_WidgetData::GetPasswordChar() { - CXFA_Node* pUIChild = GetUIChild(); - return pUIChild ? pUIChild->JSObject()->GetCData(XFA_Attribute::PasswordChar) - : L"*"; -} - -bool CXFA_WidgetData::IsMultiLine() { - CXFA_Node* pUIChild = GetUIChild(); - return pUIChild && pUIChild->JSObject()->GetBoolean(XFA_Attribute::MultiLine); -} - -std::pair CXFA_WidgetData::GetMaxChars() { - if (CXFA_Value* pNode = - m_pNode->GetChild(0, XFA_Element::Value, false)) { - if (CXFA_Node* pChild = pNode->GetNodeItem(XFA_NODEITEM_FirstChild)) { - switch (pChild->GetElementType()) { - case XFA_Element::Text: - return {XFA_Element::Text, - pChild->JSObject()->GetInteger(XFA_Attribute::MaxChars)}; - case XFA_Element::ExData: { - int32_t iMax = - pChild->JSObject()->GetInteger(XFA_Attribute::MaxLength); - return {XFA_Element::ExData, iMax < 0 ? 0 : iMax}; - } - default: - break; - } - } - } - return {XFA_Element::Unknown, 0}; -} - -int32_t CXFA_WidgetData::GetFracDigits() { - CXFA_Value* pNode = - m_pNode->GetChild(0, XFA_Element::Value, false); - if (!pNode) - return -1; - - CXFA_Decimal* pChild = - pNode->GetChild(0, XFA_Element::Decimal, false); - if (!pChild) - return -1; - - return pChild->JSObject() - ->TryInteger(XFA_Attribute::FracDigits, true) - .value_or(-1); -} - -int32_t CXFA_WidgetData::GetLeadDigits() { - CXFA_Value* pNode = - m_pNode->GetChild(0, XFA_Element::Value, false); - if (!pNode) - return -1; - - CXFA_Decimal* pChild = - pNode->GetChild(0, XFA_Element::Decimal, false); - if (!pChild) - return -1; - - return pChild->JSObject() - ->TryInteger(XFA_Attribute::LeadDigits, true) - .value_or(-1); -} - -bool CXFA_WidgetData::SetValue(XFA_VALUEPICTURE eValueType, - const WideString& wsValue) { - if (wsValue.IsEmpty()) { - SyncValue(wsValue, true); - return true; - } - - m_bPreNull = m_bIsNull; - m_bIsNull = false; - WideString wsNewText(wsValue); - WideString wsPicture = GetPictureContent(eValueType); - bool bValidate = true; - bool bSyncData = false; - CXFA_Node* pNode = GetUIChild(); - if (!pNode) - return true; - - XFA_Element eType = pNode->GetElementType(); - if (!wsPicture.IsEmpty()) { - CXFA_LocaleMgr* pLocalMgr = m_pNode->GetDocument()->GetLocalMgr(); - IFX_Locale* pLocale = GetLocale(); - CXFA_LocaleValue widgetValue = XFA_GetLocaleValue(this); - bValidate = - widgetValue.ValidateValue(wsValue, wsPicture, pLocale, &wsPicture); - if (bValidate) { - widgetValue = CXFA_LocaleValue(widgetValue.GetType(), wsNewText, - wsPicture, pLocale, pLocalMgr); - wsNewText = widgetValue.GetValue(); - if (eType == XFA_Element::NumericEdit) - wsNewText = NumericLimit(wsNewText, GetLeadDigits(), GetFracDigits()); - - bSyncData = true; - } - } else { - if (eType == XFA_Element::NumericEdit) { - if (wsNewText != L"0") - wsNewText = NumericLimit(wsNewText, GetLeadDigits(), GetFracDigits()); - - bSyncData = true; - } - } - if (eType != XFA_Element::NumericEdit || bSyncData) - SyncValue(wsNewText, true); - - return bValidate; -} - -WideString CXFA_WidgetData::GetPictureContent(XFA_VALUEPICTURE ePicture) { - if (ePicture == XFA_VALUEPICTURE_Raw) - return L""; - - CXFA_LocaleValue widgetValue = XFA_GetLocaleValue(this); - switch (ePicture) { - case XFA_VALUEPICTURE_Display: { - if (CXFA_Format* pFormat = - m_pNode->GetChild(0, XFA_Element::Format, false)) { - if (CXFA_Picture* pPicture = pFormat->GetChild( - 0, XFA_Element::Picture, false)) { - pdfium::Optional picture = - pPicture->JSObject()->TryContent(false, true); - if (picture) - return *picture; - } - } - - IFX_Locale* pLocale = GetLocale(); - if (!pLocale) - return L""; - - uint32_t dwType = widgetValue.GetType(); - switch (dwType) { - case XFA_VT_DATE: - return pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Medium); - case XFA_VT_TIME: - return pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Medium); - case XFA_VT_DATETIME: - return pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Medium) + - L"T" + - pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Medium); - case XFA_VT_DECIMAL: - case XFA_VT_FLOAT: - default: - return L""; - } - } - case XFA_VALUEPICTURE_Edit: { - CXFA_Ui* pUI = m_pNode->GetChild(0, XFA_Element::Ui, false); - if (pUI) { - if (CXFA_Picture* pPicture = - pUI->GetChild(0, XFA_Element::Picture, false)) { - pdfium::Optional picture = - pPicture->JSObject()->TryContent(false, true); - if (picture) - return *picture; - } - } - - IFX_Locale* pLocale = GetLocale(); - if (!pLocale) - return L""; - - uint32_t dwType = widgetValue.GetType(); - switch (dwType) { - case XFA_VT_DATE: - return pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Short); - case XFA_VT_TIME: - return pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Short); - case XFA_VT_DATETIME: - return pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Short) + - L"T" + - pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Short); - default: - return L""; - } - } - case XFA_VALUEPICTURE_DataBind: { - CXFA_Bind* bind = GetBind(); - if (bind) - return bind->GetPicture(); - break; - } - default: - break; - } - return L""; -} - -IFX_Locale* CXFA_WidgetData::GetLocale() { - return m_pNode ? m_pNode->GetLocale() : nullptr; -} - -WideString CXFA_WidgetData::GetValue(XFA_VALUEPICTURE eValueType) { - WideString wsValue = m_pNode->JSObject()->GetContent(false); - - if (eValueType == XFA_VALUEPICTURE_Display) - GetItemLabel(wsValue.AsStringView(), wsValue); - - WideString wsPicture = GetPictureContent(eValueType); - CXFA_Node* pNode = GetUIChild(); - if (!pNode) - return wsValue; - - switch (GetUIChild()->GetElementType()) { - case XFA_Element::ChoiceList: { - if (eValueType == XFA_VALUEPICTURE_Display) { - int32_t iSelItemIndex = GetSelectedItem(0); - if (iSelItemIndex >= 0) { - wsValue = GetChoiceListItem(iSelItemIndex, false).value_or(L""); - wsPicture.clear(); - } - } - } break; - case XFA_Element::NumericEdit: - if (eValueType != XFA_VALUEPICTURE_Raw && wsPicture.IsEmpty()) { - IFX_Locale* pLocale = GetLocale(); - if (eValueType == XFA_VALUEPICTURE_Display && pLocale) - wsValue = FormatNumStr(NormalizeNumStr(wsValue), pLocale); - } - break; - default: - break; - } - if (wsPicture.IsEmpty()) - return wsValue; - - if (IFX_Locale* pLocale = GetLocale()) { - CXFA_LocaleValue widgetValue = XFA_GetLocaleValue(this); - CXFA_LocaleMgr* pLocalMgr = m_pNode->GetDocument()->GetLocalMgr(); - switch (widgetValue.GetType()) { - case XFA_VT_DATE: { - WideString wsDate, wsTime; - if (SplitDateTime(wsValue, wsDate, wsTime)) { - CXFA_LocaleValue date(XFA_VT_DATE, wsDate, pLocalMgr); - if (date.FormatPatterns(wsValue, wsPicture, pLocale, eValueType)) - return wsValue; - } - break; - } - case XFA_VT_TIME: { - WideString wsDate, wsTime; - if (SplitDateTime(wsValue, wsDate, wsTime)) { - CXFA_LocaleValue time(XFA_VT_TIME, wsTime, pLocalMgr); - if (time.FormatPatterns(wsValue, wsPicture, pLocale, eValueType)) - return wsValue; - } - break; - } - default: - break; - } - widgetValue.FormatPatterns(wsValue, wsPicture, pLocale, eValueType); - } - return wsValue; -} - -WideString CXFA_WidgetData::GetNormalizeDataValue(const WideString& wsValue) { - if (wsValue.IsEmpty()) - return L""; - - WideString wsPicture = GetPictureContent(XFA_VALUEPICTURE_DataBind); - if (wsPicture.IsEmpty()) - return wsValue; - - ASSERT(GetNode()); - CXFA_LocaleMgr* pLocalMgr = GetNode()->GetDocument()->GetLocalMgr(); - IFX_Locale* pLocale = GetLocale(); - CXFA_LocaleValue widgetValue = XFA_GetLocaleValue(this); - if (widgetValue.ValidateValue(wsValue, wsPicture, pLocale, &wsPicture)) { - widgetValue = CXFA_LocaleValue(widgetValue.GetType(), wsValue, wsPicture, - pLocale, pLocalMgr); - return widgetValue.GetValue(); - } - return wsValue; -} - -WideString CXFA_WidgetData::GetFormatDataValue(const WideString& wsValue) { - if (wsValue.IsEmpty()) - return L""; - - WideString wsPicture = GetPictureContent(XFA_VALUEPICTURE_DataBind); - if (wsPicture.IsEmpty()) - return wsValue; - - WideString wsFormattedValue = wsValue; - if (IFX_Locale* pLocale = GetLocale()) { - ASSERT(GetNode()); - CXFA_Value* pNodeValue = - GetNode()->GetChild(0, XFA_Element::Value, false); - if (!pNodeValue) - return wsValue; - - CXFA_Node* pValueChild = pNodeValue->GetNodeItem(XFA_NODEITEM_FirstChild); - if (!pValueChild) - return wsValue; - - int32_t iVTType = XFA_VT_NULL; - switch (pValueChild->GetElementType()) { - case XFA_Element::Decimal: - iVTType = XFA_VT_DECIMAL; - break; - case XFA_Element::Float: - iVTType = XFA_VT_FLOAT; - break; - case XFA_Element::Date: - iVTType = XFA_VT_DATE; - break; - case XFA_Element::Time: - iVTType = XFA_VT_TIME; - break; - case XFA_Element::DateTime: - iVTType = XFA_VT_DATETIME; - break; - case XFA_Element::Boolean: - iVTType = XFA_VT_BOOLEAN; - break; - case XFA_Element::Integer: - iVTType = XFA_VT_INTEGER; - break; - case XFA_Element::Text: - iVTType = XFA_VT_TEXT; - break; - default: - iVTType = XFA_VT_NULL; - break; - } - CXFA_LocaleMgr* pLocalMgr = GetNode()->GetDocument()->GetLocalMgr(); - CXFA_LocaleValue widgetValue(iVTType, wsValue, pLocalMgr); - switch (widgetValue.GetType()) { - case XFA_VT_DATE: { - WideString wsDate, wsTime; - if (SplitDateTime(wsValue, wsDate, wsTime)) { - CXFA_LocaleValue date(XFA_VT_DATE, wsDate, pLocalMgr); - if (date.FormatPatterns(wsFormattedValue, wsPicture, pLocale, - XFA_VALUEPICTURE_DataBind)) { - return wsFormattedValue; - } - } - break; - } - case XFA_VT_TIME: { - WideString wsDate, wsTime; - if (SplitDateTime(wsValue, wsDate, wsTime)) { - CXFA_LocaleValue time(XFA_VT_TIME, wsTime, pLocalMgr); - if (time.FormatPatterns(wsFormattedValue, wsPicture, pLocale, - XFA_VALUEPICTURE_DataBind)) { - return wsFormattedValue; - } - } - break; - } - default: - break; - } - widgetValue.FormatPatterns(wsFormattedValue, wsPicture, pLocale, - XFA_VALUEPICTURE_DataBind); - } - return wsFormattedValue; -} - -WideString CXFA_WidgetData::NormalizeNumStr(const WideString& wsValue) { - if (wsValue.IsEmpty()) - return L""; - - WideString wsOutput = wsValue; - wsOutput.TrimLeft('0'); - - if (!wsOutput.IsEmpty() && wsOutput.Contains('.') && GetFracDigits() != -1) { - wsOutput.TrimRight(L"0"); - wsOutput.TrimRight(L"."); - } - if (wsOutput.IsEmpty() || wsOutput[0] == '.') - wsOutput.InsertAtFront('0'); - - return wsOutput; -} - -WideString CXFA_WidgetData::FormatNumStr(const WideString& wsValue, - IFX_Locale* pLocale) { - if (wsValue.IsEmpty()) - return L""; - - WideString wsSrcNum = wsValue; - WideString wsGroupSymbol = - pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Grouping); - bool bNeg = false; - if (wsSrcNum[0] == '-') { - bNeg = true; - wsSrcNum.Delete(0, 1); - } - - auto dot_index = wsSrcNum.Find('.'); - dot_index = !dot_index.has_value() ? wsSrcNum.GetLength() : dot_index; - - if (dot_index.value() < 1) - return L""; - - size_t nPos = dot_index.value() % 3; - WideString wsOutput; - for (size_t i = 0; i < dot_index.value(); i++) { - if (i % 3 == nPos && i != 0) - wsOutput += wsGroupSymbol; - - wsOutput += wsSrcNum[i]; - } - if (dot_index.value() < wsSrcNum.GetLength()) { - wsOutput += pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Decimal); - wsOutput += wsSrcNum.Right(wsSrcNum.GetLength() - dot_index.value() - 1); - } - if (bNeg) - return pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus) + wsOutput; - - return wsOutput; -} - -void CXFA_WidgetData::SyncValue(const WideString& wsValue, bool bNotify) { - if (!m_pNode) - return; - - WideString wsFormatValue(wsValue); - CXFA_WidgetData* pContainerWidgetData = m_pNode->GetContainerWidgetData(); - if (pContainerWidgetData) - wsFormatValue = pContainerWidgetData->GetFormatDataValue(wsValue); - - m_pNode->JSObject()->SetContent(wsValue, wsFormatValue, bNotify, false, true); -} - -void CXFA_WidgetData::InsertListTextItem(CXFA_Node* pItems, - const WideString& wsText, - int32_t nIndex) { - CXFA_Node* pText = pItems->CreateSamePacketNode(XFA_Element::Text); - pItems->InsertChild(nIndex, pText); - pText->JSObject()->SetContent(wsText, wsText, false, false, false); -} - -WideString CXFA_WidgetData::NumericLimit(const WideString& wsValue, - int32_t iLead, - int32_t iTread) const { - if ((iLead == -1) && (iTread == -1)) - return wsValue; - - WideString wsRet; - int32_t iLead_ = 0, iTread_ = -1; - int32_t iCount = wsValue.GetLength(); - if (iCount == 0) - return wsValue; - - int32_t i = 0; - if (wsValue[i] == L'-') { - wsRet += L'-'; - i++; - } - for (; i < iCount; i++) { - wchar_t wc = wsValue[i]; - if (FXSYS_isDecimalDigit(wc)) { - if (iLead >= 0) { - iLead_++; - if (iLead_ > iLead) - return L"0"; - } else if (iTread_ >= 0) { - iTread_++; - if (iTread_ > iTread) { - if (iTread != -1) { - CFX_Decimal wsDeci = CFX_Decimal(wsValue.AsStringView()); - wsDeci.SetScale(iTread); - wsRet = wsDeci; - } - return wsRet; - } - } - } else if (wc == L'.') { - iTread_ = 0; - iLead = -1; - } - wsRet += wc; - } - return wsRet; -} diff --git a/xfa/fxfa/parser/cxfa_widgetdata.h b/xfa/fxfa/parser/cxfa_widgetdata.h deleted file mode 100644 index 4b11521b6f..0000000000 --- a/xfa/fxfa/parser/cxfa_widgetdata.h +++ /dev/null @@ -1,200 +0,0 @@ -// Copyright 2016 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_CXFA_WIDGETDATA_H_ -#define XFA_FXFA_PARSER_CXFA_WIDGETDATA_H_ - -#include -#include - -#include "core/fxcrt/fx_coordinates.h" -#include "core/fxcrt/fx_string.h" -#include "core/fxcrt/fx_system.h" -#include "fxbarcode/BC_Library.h" -#include "xfa/fxfa/fxfa_basic.h" - -enum XFA_CHECKSTATE { - XFA_CHECKSTATE_On = 0, - XFA_CHECKSTATE_Off = 1, - XFA_CHECKSTATE_Neutral = 2, -}; - -enum XFA_VALUEPICTURE { - XFA_VALUEPICTURE_Raw = 0, - XFA_VALUEPICTURE_Display, - XFA_VALUEPICTURE_Edit, - XFA_VALUEPICTURE_DataBind, -}; - -class CXFA_Bind; -class CXFA_Border; -class CXFA_Calculate; -class CXFA_Caption; -class CXFA_Event; -class CXFA_Font; -class CXFA_Margin; -class CXFA_Node; -class CXFA_Para; -class CXFA_Value; -class CXFA_Validate; -class IFX_Locale; - -class CXFA_WidgetData { - public: - virtual ~CXFA_WidgetData(); - - CXFA_Node* GetNode() const { return m_pNode; } - - CXFA_Node* GetUIChild(); - XFA_Element GetUIType(); - CFX_RectF GetUIMargin(); - - WideString GetRawValue() const; - int32_t GetRotate() const; - - bool IsOpenAccess() const; - bool IsListBox(); - bool IsAllowNeutral(); - bool IsRadioButton(); - bool IsChoiceListAllowTextEntry(); - bool IsMultiLine(); - - CXFA_Border* GetBorder(bool bModified); - CXFA_Caption* GetCaption(); - CXFA_Font* GetFont(bool bModified); - CXFA_Margin* GetMargin(); - CXFA_Para* GetPara(); - CXFA_Value* GetDefaultValue(); - CXFA_Value* GetFormValue(); - CXFA_Calculate* GetCalculate(); - CXFA_Validate* GetValidate(bool bModified); - CXFA_Border* GetUIBorder(); - - std::vector GetEventByActivity(XFA_AttributeEnum iActivity, - bool bIsFormReady); - - pdfium::Optional TryWidth(); - pdfium::Optional TryHeight(); - pdfium::Optional TryMinWidth(); - pdfium::Optional TryMinHeight(); - pdfium::Optional TryMaxWidth(); - pdfium::Optional TryMaxHeight(); - - XFA_AttributeEnum GetButtonHighlight(); - bool HasButtonRollover() const; - bool HasButtonDown() const; - - bool IsCheckButtonRound(); - XFA_AttributeEnum GetCheckButtonMark(); - float GetCheckButtonSize(); - - XFA_CHECKSTATE GetCheckState(); - void SetCheckState(XFA_CHECKSTATE eCheckState, bool bNotify); - - CXFA_Node* GetSelectedMember(); - CXFA_Node* SetSelectedMember(const WideStringView& wsName, bool bNotify); - void SetSelectedMemberByValue(const WideStringView& wsValue, - bool bNotify, - bool bScriptModify, - bool bSyncData); - - CXFA_Node* GetExclGroupFirstMember(); - CXFA_Node* GetExclGroupNextMember(CXFA_Node* pNode); - - int32_t CountChoiceListItems(bool bSaveValue); - pdfium::Optional GetChoiceListItem(int32_t nIndex, - bool bSaveValue); - bool IsChoiceListMultiSelect(); - bool IsChoiceListCommitOnSelect(); - std::vector GetChoiceListItems(bool bSaveValue); - - int32_t CountSelectedItems(); - int32_t GetSelectedItem(int32_t nIndex); - std::vector GetSelectedItems(); - std::vector GetSelectedItemsValue(); - void SetSelectedItems(const std::vector& iSelArray, - bool bNotify, - bool bScriptModify, - bool bSyncData); - void InsertItem(const WideString& wsLabel, - const WideString& wsValue, - bool bNotify); - bool DeleteItem(int32_t nIndex, bool bNotify, bool bScriptModify); - void ClearAllSelections(); - - bool GetItemState(int32_t nIndex); - void SetItemState(int32_t nIndex, - bool bSelected, - bool bNotify, - bool bScriptModify, - bool bSyncData); - - WideString GetItemValue(const WideStringView& wsLabel); - - bool IsHorizontalScrollPolicyOff(); - bool IsVerticalScrollPolicyOff(); - pdfium::Optional GetNumberOfCells(); - - bool SetValue(XFA_VALUEPICTURE eValueType, const WideString& wsValue); - WideString GetValue(XFA_VALUEPICTURE eValueType); - - WideString GetPictureContent(XFA_VALUEPICTURE ePicture); - IFX_Locale* GetLocale(); - - WideString GetNormalizeDataValue(const WideString& wsValue); - WideString GetFormatDataValue(const WideString& wsValue); - WideString NormalizeNumStr(const WideString& wsValue); - - WideString GetBarcodeType(); - pdfium::Optional GetBarcodeAttribute_CharEncoding(); - pdfium::Optional GetBarcodeAttribute_Checksum(); - pdfium::Optional GetBarcodeAttribute_DataLength(); - pdfium::Optional GetBarcodeAttribute_StartChar(); - pdfium::Optional GetBarcodeAttribute_EndChar(); - pdfium::Optional GetBarcodeAttribute_ECLevel(); - pdfium::Optional GetBarcodeAttribute_ModuleWidth(); - pdfium::Optional GetBarcodeAttribute_ModuleHeight(); - pdfium::Optional GetBarcodeAttribute_PrintChecksum(); - pdfium::Optional GetBarcodeAttribute_TextLocation(); - pdfium::Optional GetBarcodeAttribute_Truncate(); - pdfium::Optional GetBarcodeAttribute_WideNarrowRatio(); - - WideString GetPasswordChar(); - std::pair GetMaxChars(); - int32_t GetFracDigits(); - int32_t GetLeadDigits(); - - WideString NumericLimit(const WideString& wsValue, - int32_t iLead, - int32_t iTread) const; - - bool IsPreNull() const { return m_bPreNull; } - void SetPreNull(bool val) { m_bPreNull = val; } - bool IsNull() const { return m_bIsNull; } - void SetIsNull(bool val) { m_bIsNull = val; } - - protected: - explicit CXFA_WidgetData(CXFA_Node* pNode); - - CXFA_Node* m_pNode; - - private: - CXFA_Bind* GetBind(); - void SyncValue(const WideString& wsValue, bool bNotify); - void InsertListTextItem(CXFA_Node* pItems, - const WideString& wsText, - int32_t nIndex); - WideString FormatNumStr(const WideString& wsValue, IFX_Locale* pLocale); - CXFA_Node* GetExclGroupNode(); - void GetItemLabel(const WideStringView& wsValue, WideString& wsLabel); - - bool m_bIsNull; - bool m_bPreNull; - CXFA_Node* m_pUiChildNode; - XFA_Element m_eUIType; -}; - -#endif // XFA_FXFA_PARSER_CXFA_WIDGETDATA_H_ diff --git a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp index 8de905278e..5a42f21159 100644 --- a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp +++ b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp @@ -67,9 +67,9 @@ CXFA_Node* FormValueNode_CreateChild(CXFA_Node* pValueNode, XFA_Element iType) { } void FormValueNode_MatchNoneCreateChild(CXFA_Node* pFormNode) { - CXFA_WidgetData* pWidgetData = pFormNode->GetWidgetData(); - ASSERT(pWidgetData); - pWidgetData->GetUIType(); + CXFA_WidgetAcc* pWidgetAcc = pFormNode->GetWidgetAcc(); + ASSERT(pWidgetAcc); + pWidgetAcc->GetUIType(); } bool FormValueNode_SetChildContent(CXFA_Node* pValueNode, @@ -130,9 +130,9 @@ void CreateDataBinding(CXFA_Node* pFormNode, if (eType != XFA_Element::Field && eType != XFA_Element::ExclGroup) return; - CXFA_WidgetData* pWidgetData = pFormNode->GetWidgetData(); - ASSERT(pWidgetData); - XFA_Element eUIType = pWidgetData->GetUIType(); + CXFA_WidgetAcc* pWidgetAcc = pFormNode->GetWidgetAcc(); + ASSERT(pWidgetAcc); + XFA_Element eUIType = pWidgetAcc->GetUIType(); auto* defValue = pFormNode->JSObject()->GetProperty( 0, XFA_Element::Value, true); if (!bDataToForm) { @@ -152,7 +152,7 @@ void CreateDataBinding(CXFA_Node* pFormNode, ASSERT(pXMLDataElement); pDataNode->JSObject()->SetAttributeValue( - wsValue, pWidgetData->GetFormatDataValue(wsValue), false, false); + wsValue, pWidgetAcc->GetFormatDataValue(wsValue), false, false); pDataNode->JSObject()->SetCData(XFA_Attribute::ContentType, wsContentType, false, false); if (!wsHref.IsEmpty()) @@ -162,9 +162,9 @@ void CreateDataBinding(CXFA_Node* pFormNode, } case XFA_Element::ChoiceList: wsValue = defValue ? defValue->GetChildValueContent() : L""; - if (pWidgetData->IsChoiceListMultiSelect()) { + if (pWidgetAcc->IsChoiceListMultiSelect()) { std::vector wsSelTextArray = - pWidgetData->GetSelectedItemsValue(); + pWidgetAcc->GetSelectedItemsValue(); if (!wsSelTextArray.empty()) { for (const auto& text : wsSelTextArray) { CXFA_Node* pValue = @@ -184,7 +184,7 @@ void CreateDataBinding(CXFA_Node* pFormNode, } } else if (!wsValue.IsEmpty()) { pDataNode->JSObject()->SetAttributeValue( - wsValue, pWidgetData->GetFormatDataValue(wsValue), false, false); + wsValue, pWidgetAcc->GetFormatDataValue(wsValue), false, false); } break; case XFA_Element::CheckButton: @@ -193,7 +193,7 @@ void CreateDataBinding(CXFA_Node* pFormNode, break; pDataNode->JSObject()->SetAttributeValue( - wsValue, pWidgetData->GetFormatDataValue(wsValue), false, false); + wsValue, pWidgetAcc->GetFormatDataValue(wsValue), false, false); break; case XFA_Element::ExclGroup: { CXFA_Node* pChecked = nullptr; @@ -262,9 +262,9 @@ void CreateDataBinding(CXFA_Node* pFormNode, if (wsValue.IsEmpty()) break; - wsValue = pWidgetData->NormalizeNumStr(wsValue); + wsValue = pWidgetAcc->NormalizeNumStr(wsValue); pDataNode->JSObject()->SetAttributeValue( - wsValue, pWidgetData->GetFormatDataValue(wsValue), false, false); + wsValue, pWidgetAcc->GetFormatDataValue(wsValue), false, false); CXFA_Value* pValue = pFormNode->JSObject()->GetProperty( 0, XFA_Element::Value, true); FormValueNode_SetChildContent(pValue, wsValue, XFA_Element::Float); @@ -276,14 +276,14 @@ void CreateDataBinding(CXFA_Node* pFormNode, break; pDataNode->JSObject()->SetAttributeValue( - wsValue, pWidgetData->GetFormatDataValue(wsValue), false, false); + wsValue, pWidgetAcc->GetFormatDataValue(wsValue), false, false); break; } return; } WideString wsXMLValue = pDataNode->JSObject()->GetContent(false); - WideString wsNormalizeValue = pWidgetData->GetNormalizeDataValue(wsXMLValue); + WideString wsNormalizeValue = pWidgetAcc->GetNormalizeDataValue(wsXMLValue); pDataNode->JSObject()->SetAttributeValue(wsNormalizeValue, wsXMLValue, false, false); @@ -312,7 +312,7 @@ void CreateDataBinding(CXFA_Node* pFormNode, break; } case XFA_Element::ChoiceList: - if (pWidgetData->IsChoiceListMultiSelect()) { + if (pWidgetAcc->IsChoiceListMultiSelect()) { std::vector items = pDataNode->GetNodeList( XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties, XFA_Element::Unknown); @@ -344,8 +344,8 @@ void CreateDataBinding(CXFA_Node* pFormNode, XFA_Element::Text); break; case XFA_Element::ExclGroup: { - pWidgetData->SetSelectedMemberByValue(wsNormalizeValue.AsStringView(), - false, false, false); + pWidgetAcc->SetSelectedMemberByValue(wsNormalizeValue.AsStringView(), + false, false, false); break; } case XFA_Element::DateTimeEdit: @@ -354,9 +354,9 @@ void CreateDataBinding(CXFA_Node* pFormNode, break; case XFA_Element::NumericEdit: { WideString wsPicture = - pWidgetData->GetPictureContent(XFA_VALUEPICTURE_DataBind); + pWidgetAcc->GetPictureContent(XFA_VALUEPICTURE_DataBind); if (wsPicture.IsEmpty()) - wsNormalizeValue = pWidgetData->NormalizeNumStr(wsNormalizeValue); + wsNormalizeValue = pWidgetAcc->NormalizeNumStr(wsNormalizeValue); FormValueNode_SetChildContent(defValue, wsNormalizeValue, XFA_Element::Float); diff --git a/xfa/fxfa/parser/xfa_utils.cpp b/xfa/fxfa/parser/xfa_utils.cpp index 5f00f3e926..f891d47f23 100644 --- a/xfa/fxfa/parser/xfa_utils.cpp +++ b/xfa/fxfa/parser/xfa_utils.cpp @@ -144,8 +144,8 @@ bool ContentNodeNeedtoExport(CXFA_Node* pContentNode) { if (pGrandParentNode->GetBindData()) return false; - CXFA_WidgetData* pWidgetData = pGrandParentNode->GetWidgetData(); - XFA_Element eUIType = pWidgetData->GetUIType(); + CXFA_WidgetAcc* pWidgetAcc = pGrandParentNode->GetWidgetAcc(); + XFA_Element eUIType = pWidgetAcc->GetUIType(); if (eUIType == XFA_Element::PasswordEdit) return false; return true; @@ -423,9 +423,9 @@ int XFA_GetMaxFractionalScale() { return FX_ArraySize(fraction_scales); } -CXFA_LocaleValue XFA_GetLocaleValue(CXFA_WidgetData* pWidgetData) { - CXFA_Value* pNodeValue = pWidgetData->GetNode()->GetChild( - 0, XFA_Element::Value, false); +CXFA_LocaleValue XFA_GetLocaleValue(CXFA_WidgetAcc* pWidgetAcc) { + CXFA_Value* pNodeValue = + pWidgetAcc->GetNode()->GetChild(0, XFA_Element::Value, false); if (!pNodeValue) return CXFA_LocaleValue(); @@ -463,8 +463,8 @@ CXFA_LocaleValue XFA_GetLocaleValue(CXFA_WidgetData* pWidgetData) { iVTType = XFA_VT_NULL; break; } - return CXFA_LocaleValue(iVTType, pWidgetData->GetRawValue(), - pWidgetData->GetNode()->GetDocument()->GetLocalMgr()); + return CXFA_LocaleValue(iVTType, pWidgetAcc->GetRawValue(), + pWidgetAcc->GetNode()->GetDocument()->GetLocalMgr()); } bool XFA_FDEExtension_ResolveNamespaceQualifier(CFX_XMLElement* pNode, diff --git a/xfa/fxfa/parser/xfa_utils.h b/xfa/fxfa/parser/xfa_utils.h index 27e6534aab..9317a783c4 100644 --- a/xfa/fxfa/parser/xfa_utils.h +++ b/xfa/fxfa/parser/xfa_utils.h @@ -14,7 +14,7 @@ class CFX_XMLElement; class CFX_XMLNode; class CXFA_LocaleValue; class CXFA_Node; -class CXFA_WidgetData; +class CXFA_WidgetAcc; double XFA_GetFractionalScale(uint32_t idx); int XFA_GetMaxFractionalScale(); @@ -23,7 +23,7 @@ bool XFA_FDEExtension_ResolveNamespaceQualifier(CFX_XMLElement* pNode, const WideString& wsQualifier, WideString* wsNamespaceURI); -CXFA_LocaleValue XFA_GetLocaleValue(CXFA_WidgetData* pWidgetData); +CXFA_LocaleValue XFA_GetLocaleValue(CXFA_WidgetAcc* pWidgetAcc); int32_t XFA_MapRotation(int32_t nRotation); bool XFA_RecognizeRichText(CFX_XMLElement* pRichTextXMLNode); -- cgit v1.2.3