From 6aec70bc09cb65b169fe6ca1af65e8929aeea43a Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Thu, 23 Nov 2017 17:02:23 +0000 Subject: Cleanup CXFA_WidgetData This CL cleans up return values, out-params and changes simple methods to boolean checks where possible in CXFA_WidgetData. Change-Id: I29daa67993730f3e9d61cb6fdf918a886cc9120e Reviewed-on: https://pdfium-review.googlesource.com/19230 Reviewed-by: Henrique Nakashima Commit-Queue: dsinclair --- xfa/fxfa/parser/cxfa_captiondata.cpp | 14 +- xfa/fxfa/parser/cxfa_captiondata.h | 5 +- xfa/fxfa/parser/cxfa_eventdata.cpp | 2 +- xfa/fxfa/parser/cxfa_eventdata.h | 2 +- xfa/fxfa/parser/cxfa_node.cpp | 44 +- xfa/fxfa/parser/cxfa_widgetdata.cpp | 532 +++++++++++------------- xfa/fxfa/parser/cxfa_widgetdata.h | 87 ++-- xfa/fxfa/parser/xfa_document_datamerger_imp.cpp | 52 +-- 8 files changed, 337 insertions(+), 401 deletions(-) (limited to 'xfa/fxfa/parser') diff --git a/xfa/fxfa/parser/cxfa_captiondata.cpp b/xfa/fxfa/parser/cxfa_captiondata.cpp index 1553a50e00..61bcbcefa1 100644 --- a/xfa/fxfa/parser/cxfa_captiondata.cpp +++ b/xfa/fxfa/parser/cxfa_captiondata.cpp @@ -11,13 +11,19 @@ CXFA_CaptionData::CXFA_CaptionData(CXFA_Node* pNode) : CXFA_DataData(pNode) {} -int32_t CXFA_CaptionData::GetPresence() const { +bool CXFA_CaptionData::IsVisible() const { return m_pNode->JSNode() - ->TryEnum(XFA_Attribute::Presence, true) - .value_or(XFA_ATTRIBUTEENUM_Visible); + ->TryEnum(XFA_Attribute::Presence, true) + .value_or(XFA_ATTRIBUTEENUM_Visible) == XFA_ATTRIBUTEENUM_Visible; } -int32_t CXFA_CaptionData::GetPlacementType() const { +bool CXFA_CaptionData::IsHidden() const { + return m_pNode->JSNode() + ->TryEnum(XFA_Attribute::Presence, true) + .value_or(XFA_ATTRIBUTEENUM_Visible) == XFA_ATTRIBUTEENUM_Hidden; +} + +XFA_ATTRIBUTEENUM CXFA_CaptionData::GetPlacementType() const { return m_pNode->JSNode() ->TryEnum(XFA_Attribute::Placement, true) .value_or(XFA_ATTRIBUTEENUM_Left); diff --git a/xfa/fxfa/parser/cxfa_captiondata.h b/xfa/fxfa/parser/cxfa_captiondata.h index ade938bebb..1a0d61fb8e 100644 --- a/xfa/fxfa/parser/cxfa_captiondata.h +++ b/xfa/fxfa/parser/cxfa_captiondata.h @@ -18,8 +18,9 @@ class CXFA_CaptionData : public CXFA_DataData { public: explicit CXFA_CaptionData(CXFA_Node* pNode); - int32_t GetPresence() const; - int32_t GetPlacementType() const; + bool IsVisible() const; + bool IsHidden() const; + XFA_ATTRIBUTEENUM GetPlacementType() const; float GetReserve() const; CXFA_MarginData GetMarginData() const; CXFA_FontData GetFontData() const; diff --git a/xfa/fxfa/parser/cxfa_eventdata.cpp b/xfa/fxfa/parser/cxfa_eventdata.cpp index 1485d8e0f5..3c9720d1fd 100644 --- a/xfa/fxfa/parser/cxfa_eventdata.cpp +++ b/xfa/fxfa/parser/cxfa_eventdata.cpp @@ -10,7 +10,7 @@ CXFA_EventData::CXFA_EventData(CXFA_Node* pNode) : CXFA_DataData(pNode) {} -int32_t CXFA_EventData::GetActivity() { +XFA_ATTRIBUTEENUM CXFA_EventData::GetActivity() { return m_pNode->JSNode()->GetEnum(XFA_Attribute::Activity); } diff --git a/xfa/fxfa/parser/cxfa_eventdata.h b/xfa/fxfa/parser/cxfa_eventdata.h index a93d04352c..89ed63e269 100644 --- a/xfa/fxfa/parser/cxfa_eventdata.h +++ b/xfa/fxfa/parser/cxfa_eventdata.h @@ -20,7 +20,7 @@ class CXFA_EventData : public CXFA_DataData { public: explicit CXFA_EventData(CXFA_Node* pNode); - int32_t GetActivity(); + XFA_ATTRIBUTEENUM GetActivity(); XFA_Element GetEventType() const; CXFA_ScriptData GetScriptData() const; CXFA_SubmitData GetSubmitData() const; diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 185b2a935a..a947374814 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -465,38 +465,36 @@ CXFA_WidgetData* CXFA_Node::GetContainerWidgetData() { if (eType == XFA_Element::Field) { CXFA_WidgetData* pFieldWidgetData = GetWidgetData(); - if (pFieldWidgetData && - pFieldWidgetData->GetChoiceListOpen() == - XFA_ATTRIBUTEENUM_MultiSelect) { + if (pFieldWidgetData && pFieldWidgetData->IsChoiceListMultiSelect()) return nullptr; - } else { - WideString wsPicture; + + WideString wsPicture; + if (pFieldWidgetData) { + wsPicture = + pFieldWidgetData->GetPictureContent(XFA_VALUEPICTURE_DataBind); + } + if (!wsPicture.IsEmpty()) + return pFieldWidgetData; + + CXFA_Node* pDataNode = GetBindData(); + if (!pDataNode) + return nullptr; + pFieldWidgetData = nullptr; + for (const auto& pFormNode : *(pDataNode->GetBindItems())) { + if (!pFormNode || pFormNode->HasRemovedChildren()) + continue; + pFieldWidgetData = pFormNode->GetWidgetData(); if (pFieldWidgetData) { wsPicture = pFieldWidgetData->GetPictureContent(XFA_VALUEPICTURE_DataBind); } if (!wsPicture.IsEmpty()) - return pFieldWidgetData; - - CXFA_Node* pDataNode = GetBindData(); - if (!pDataNode) - return nullptr; + break; pFieldWidgetData = nullptr; - for (const auto& pFormNode : *(pDataNode->GetBindItems())) { - if (!pFormNode || pFormNode->HasRemovedChildren()) - continue; - pFieldWidgetData = pFormNode->GetWidgetData(); - if (pFieldWidgetData) { - wsPicture = - pFieldWidgetData->GetPictureContent(XFA_VALUEPICTURE_DataBind); - } - if (!wsPicture.IsEmpty()) - break; - pFieldWidgetData = nullptr; - } - return pFieldWidgetData; } + return pFieldWidgetData; } + CXFA_Node* pGrandNode = pParentNode ? pParentNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr; CXFA_Node* pValueNode = diff --git a/xfa/fxfa/parser/cxfa_widgetdata.cpp b/xfa/fxfa/parser/cxfa_widgetdata.cpp index 9b0bbccde8..19a82542ea 100644 --- a/xfa/fxfa/parser/cxfa_widgetdata.cpp +++ b/xfa/fxfa/parser/cxfa_widgetdata.cpp @@ -8,7 +8,6 @@ #include "core/fxcrt/cfx_decimal.h" #include "core/fxcrt/fx_extension.h" -#include "fxbarcode/BC_Library.h" #include "third_party/base/stl_util.h" #include "xfa/fxfa/cxfa_ffnotify.h" #include "xfa/fxfa/parser/cxfa_document.h" @@ -234,7 +233,7 @@ bool CXFA_WidgetData::IsOpenAccess() const { return true; } -int32_t CXFA_WidgetData::GetRotate() { +int32_t CXFA_WidgetData::GetRotate() const { pdfium::Optional measure = m_pNode->JSNode()->TryMeasure(XFA_Attribute::Rotate, false); if (!measure) @@ -274,8 +273,9 @@ std::vector CXFA_WidgetData::GetEventList() { return m_pNode->GetNodeList(0, XFA_Element::Event); } -std::vector CXFA_WidgetData::GetEventByActivity(int32_t iActivity, - bool bIsFormReady) { +std::vector CXFA_WidgetData::GetEventByActivity( + XFA_ATTRIBUTEENUM iActivity, + bool bIsFormReady) { std::vector events; for (CXFA_Node* pNode : GetEventList()) { CXFA_EventData eventData(pNode); @@ -401,42 +401,38 @@ XFA_ATTRIBUTEENUM CXFA_WidgetData::GetButtonHighlight() { return XFA_ATTRIBUTEENUM_Inverted; } -bool CXFA_WidgetData::GetButtonRollover(WideString& wsRollover, - bool& bRichText) { - if (CXFA_Node* pItems = m_pNode->GetChild(0, XFA_Element::Items, false)) { - CXFA_Node* pText = pItems->GetNodeItem(XFA_NODEITEM_FirstChild); - while (pText) { - if (pText->JSNode()->GetCData(XFA_Attribute::Name) == L"rollover") { - wsRollover = pText->JSNode()->GetContent(false); - bRichText = pText->GetElementType() == XFA_Element::ExData; - return !wsRollover.IsEmpty(); - } - pText = pText->GetNodeItem(XFA_NODEITEM_NextSibling); - } +bool CXFA_WidgetData::HasButtonRollover() const { + CXFA_Node* 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->JSNode()->GetCData(XFA_Attribute::Name) == L"rollover") + return !pText->JSNode()->GetContent(false).IsEmpty(); } return false; } -bool CXFA_WidgetData::GetButtonDown(WideString& wsDown, bool& bRichText) { - if (CXFA_Node* pItems = m_pNode->GetChild(0, XFA_Element::Items, false)) { - CXFA_Node* pText = pItems->GetNodeItem(XFA_NODEITEM_FirstChild); - while (pText) { - if (pText->JSNode()->GetCData(XFA_Attribute::Name) == L"down") { - wsDown = pText->JSNode()->GetContent(false); - bRichText = pText->GetElementType() == XFA_Element::ExData; - return !wsDown.IsEmpty(); - } - pText = pText->GetNodeItem(XFA_NODEITEM_NextSibling); - } +bool CXFA_WidgetData::HasButtonDown() const { + CXFA_Node* 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->JSNode()->GetCData(XFA_Attribute::Name) == L"down") + return !pText->JSNode()->GetContent(false).IsEmpty(); } return false; } -XFA_ATTRIBUTEENUM CXFA_WidgetData::GetCheckButtonShape() { +bool CXFA_WidgetData::IsCheckButtonRound() { CXFA_Node* pUIChild = GetUIChild(); if (pUIChild) - return pUIChild->JSNode()->GetEnum(XFA_Attribute::Shape); - return XFA_ATTRIBUTEENUM_Square; + return pUIChild->JSNode()->GetEnum(XFA_Attribute::Shape) == + XFA_ATTRIBUTEENUM_Round; + return false; } XFA_ATTRIBUTEENUM CXFA_WidgetData::GetCheckButtonMark() { @@ -649,11 +645,13 @@ CXFA_Node* CXFA_WidgetData::GetExclGroupNextMember(CXFA_Node* pNode) { return nullptr; } -XFA_ATTRIBUTEENUM CXFA_WidgetData::GetChoiceListCommitOn() { +bool CXFA_WidgetData::IsChoiceListCommitOnSelect() { CXFA_Node* pUIChild = GetUIChild(); - if (pUIChild) - return pUIChild->JSNode()->GetEnum(XFA_Attribute::CommitOn); - return XFA_ATTRIBUTEENUM_Select; + if (pUIChild) { + return pUIChild->JSNode()->GetEnum(XFA_Attribute::CommitOn) == + XFA_ATTRIBUTEENUM_Select; + } + return true; } bool CXFA_WidgetData::IsChoiceListAllowTextEntry() { @@ -661,17 +659,23 @@ bool CXFA_WidgetData::IsChoiceListAllowTextEntry() { return pUIChild && pUIChild->JSNode()->GetBoolean(XFA_Attribute::TextEntry); } -XFA_ATTRIBUTEENUM CXFA_WidgetData::GetChoiceListOpen() { +bool CXFA_WidgetData::IsChoiceListMultiSelect() { CXFA_Node* pUIChild = GetUIChild(); - if (pUIChild) - return pUIChild->JSNode()->GetEnum(XFA_Attribute::Open); - return XFA_ATTRIBUTEENUM_UserControl; + if (pUIChild) { + return pUIChild->JSNode()->GetEnum(XFA_Attribute::Open) == + XFA_ATTRIBUTEENUM_MultiSelect; + } + return false; } bool CXFA_WidgetData::IsListBox() { - int32_t iOpenMode = GetChoiceListOpen(); - return iOpenMode == XFA_ATTRIBUTEENUM_Always || - iOpenMode == XFA_ATTRIBUTEENUM_MultiSelect; + CXFA_Node* pUIChild = GetUIChild(); + if (!pUIChild) + return false; + + XFA_ATTRIBUTEENUM attr = pUIChild->JSNode()->GetEnum(XFA_Attribute::Open); + return attr == XFA_ATTRIBUTEENUM_Always || + attr == XFA_ATTRIBUTEENUM_MultiSelect; } int32_t CXFA_WidgetData::CountChoiceListItems(bool bSaveValue) { @@ -699,26 +703,25 @@ int32_t CXFA_WidgetData::CountChoiceListItems(bool bSaveValue) { return pItem->CountChildren(XFA_Element::Unknown, false); } -bool CXFA_WidgetData::GetChoiceListItem(WideString& wsText, - int32_t nIndex, - bool bSaveValue) { - wsText.clear(); +pdfium::Optional CXFA_WidgetData::GetChoiceListItem( + int32_t nIndex, + bool bSaveValue) { std::vector pItemsArray; - CXFA_Node* pItems = nullptr; int32_t iCount = 0; - CXFA_Node* pNode = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); - for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { + 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++; + + ++iCount; pItemsArray.push_back(pNode); if (iCount == 2) break; } if (iCount == 0) - return false; + return {}; - pItems = pItemsArray[0]; + CXFA_Node* pItems = pItemsArray[0]; if (iCount > 1) { bool bItemOneHasSave = pItemsArray[0]->JSNode()->GetBoolean(XFA_Attribute::Save); @@ -727,14 +730,13 @@ bool CXFA_WidgetData::GetChoiceListItem(WideString& wsText, if (bItemOneHasSave != bItemTwoHasSave && bSaveValue == bItemTwoHasSave) pItems = pItemsArray[1]; } - if (pItems) { - CXFA_Node* pItem = pItems->GetChild(nIndex, XFA_Element::Unknown, false); - if (pItem) { - wsText = pItem->JSNode()->GetContent(false); - return true; - } - } - return false; + if (!pItems) + return {}; + + CXFA_Node* pItem = pItems->GetChild(nIndex, XFA_Element::Unknown, false); + if (pItem) + return {pItem->JSNode()->GetContent(false)}; + return {}; } std::vector CXFA_WidgetData::GetChoiceListItems(bool bSaveValue) { @@ -804,7 +806,7 @@ std::vector CXFA_WidgetData::GetSelectedItems() { std::vector CXFA_WidgetData::GetSelectedItemsValue() { std::vector wsSelTextArray; WideString wsValue = GetRawValue(); - if (GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) { + if (IsChoiceListMultiSelect()) { if (!wsValue.IsEmpty()) { size_t iStart = 0; size_t iLength = wsValue.GetLength(); @@ -849,7 +851,7 @@ void CXFA_WidgetData::SetItemState(int32_t nIndex, if (it != wsValueArray.end()) iSel = it - wsValueArray.begin(); - if (GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) { + if (IsChoiceListMultiSelect()) { if (bSelected) { if (iSel < 0) { WideString wsValue = GetRawValue(); @@ -871,9 +873,8 @@ void CXFA_WidgetData::SetItemState(int32_t nIndex, if (bSelected) { if (iSel < 0) { WideString wsSaveText = wsSaveTextArray[nIndex]; - WideString wsFormatText(wsSaveText); - GetFormatDataValue(wsSaveText, wsFormatText); - m_pNode->JSNode()->SetContent(wsSaveText, wsFormatText, bNotify, + m_pNode->JSNode()->SetContent(wsSaveText, + GetFormatDataValue(wsSaveText), bNotify, bScriptModify, bSyncData); } } else if (iSel >= 0) { @@ -899,8 +900,8 @@ void CXFA_WidgetData::SetSelectedItems(const std::vector& iSelArray, } } WideString wsFormat(wsValue); - if (GetChoiceListOpen() != XFA_ATTRIBUTEENUM_MultiSelect) - GetFormatDataValue(wsValue, wsFormat); + if (!IsChoiceListMultiSelect()) + wsFormat = GetFormatDataValue(wsValue); m_pNode->JSNode()->SetContent(wsValue, wsFormat, bNotify, bScriptModify, bSyncData); @@ -908,7 +909,7 @@ void CXFA_WidgetData::SetSelectedItems(const std::vector& iSelArray, void CXFA_WidgetData::ClearAllSelections() { CXFA_Node* pBind = m_pNode->GetBindData(); - if (!pBind || GetChoiceListOpen() != XFA_ATTRIBUTEENUM_MultiSelect) { + if (!pBind || !IsChoiceListMultiSelect()) { SyncValue(WideString(), false); return; } @@ -1023,8 +1024,7 @@ void CXFA_WidgetData::GetItemLabel(const WideStringView& wsValue, wsLabel = pText->JSNode()->GetContent(false); } -void CXFA_WidgetData::GetItemValue(const WideStringView& wsLabel, - WideString& wsValue) { +WideString CXFA_WidgetData::GetItemValue(const WideStringView& wsLabel) { int32_t iCount = 0; std::vector listitems; for (CXFA_Node* pItems = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); @@ -1034,10 +1034,8 @@ void CXFA_WidgetData::GetItemValue(const WideStringView& wsLabel, iCount++; listitems.push_back(pItems); } - if (iCount <= 1) { - wsValue = wsLabel; - return; - } + if (iCount <= 1) + return WideString(wsLabel); CXFA_Node* pLabelItems = listitems[0]; bool bSave = pLabelItems->JSNode()->GetBoolean(XFA_Attribute::Save); @@ -1062,11 +1060,10 @@ void CXFA_WidgetData::GetItemValue(const WideStringView& wsLabel, iCount++; } if (iSearch < 0) - return; + return L""; CXFA_Node* pText = pSaveItems->GetChild(iSearch, XFA_Element::Unknown, false); - if (pText) - wsValue = pText->JSNode()->GetContent(false); + return pText ? pText->JSNode()->GetContent(false) : L""; } bool CXFA_WidgetData::DeleteItem(int32_t nIndex, @@ -1104,20 +1101,31 @@ bool CXFA_WidgetData::DeleteItem(int32_t nIndex, return true; } -int32_t CXFA_WidgetData::GetHorizontalScrollPolicy() { +bool CXFA_WidgetData::IsHorizontalScrollPolicyOff() { CXFA_Node* pUIChild = GetUIChild(); - if (pUIChild) - return pUIChild->JSNode()->GetEnum(XFA_Attribute::HScrollPolicy); - return XFA_ATTRIBUTEENUM_Auto; + if (pUIChild) { + return pUIChild->JSNode()->GetEnum(XFA_Attribute::HScrollPolicy) == + XFA_ATTRIBUTEENUM_Off; + } + return false; } -int32_t CXFA_WidgetData::GetNumberOfCells() { +bool CXFA_WidgetData::IsVerticalScrollPolicyOff() { + CXFA_Node* pUIChild = GetUIChild(); + if (pUIChild) { + return pUIChild->JSNode()->GetEnum(XFA_Attribute::VScrollPolicy) == + XFA_ATTRIBUTEENUM_Off; + } + return false; +} + +pdfium::Optional CXFA_WidgetData::GetNumberOfCells() { CXFA_Node* pUIChild = GetUIChild(); if (!pUIChild) - return -1; + return {}; if (CXFA_Node* pNode = pUIChild->GetChild(0, XFA_Element::Comb, false)) - return pNode->JSNode()->GetInteger(XFA_Attribute::NumberOfCells); - return -1; + return {pNode->JSNode()->GetInteger(XFA_Attribute::NumberOfCells)}; + return {}; } WideString CXFA_WidgetData::GetBarcodeType() { @@ -1127,183 +1135,151 @@ WideString CXFA_WidgetData::GetBarcodeType() { : WideString(); } -bool CXFA_WidgetData::GetBarcodeAttribute_CharEncoding(int32_t* val) { +pdfium::Optional +CXFA_WidgetData::GetBarcodeAttribute_CharEncoding() { pdfium::Optional wsCharEncoding = GetUIChild()->JSNode()->TryCData(XFA_Attribute::CharEncoding, true); if (!wsCharEncoding) - return false; - if (wsCharEncoding->CompareNoCase(L"UTF-16")) { - *val = CHAR_ENCODING_UNICODE; - return true; - } - if (wsCharEncoding->CompareNoCase(L"UTF-8")) { - *val = CHAR_ENCODING_UTF8; - return true; - } - return false; + return {}; + if (wsCharEncoding->CompareNoCase(L"UTF-16")) + return {CHAR_ENCODING_UNICODE}; + if (wsCharEncoding->CompareNoCase(L"UTF-8")) + return {CHAR_ENCODING_UTF8}; + return {}; } -bool CXFA_WidgetData::GetBarcodeAttribute_Checksum(bool* val) { +pdfium::Optional CXFA_WidgetData::GetBarcodeAttribute_Checksum() { pdfium::Optional checksum = GetUIChild()->JSNode()->TryEnum(XFA_Attribute::Checksum, true); if (!checksum) - return false; + return {}; switch (*checksum) { case XFA_ATTRIBUTEENUM_None: - *val = false; - return true; + return {false}; case XFA_ATTRIBUTEENUM_Auto: - *val = true; - return true; + return {true}; case XFA_ATTRIBUTEENUM_1mod10: case XFA_ATTRIBUTEENUM_1mod10_1mod11: case XFA_ATTRIBUTEENUM_2mod10: default: break; } - return false; + return {}; } -bool CXFA_WidgetData::GetBarcodeAttribute_DataLength(int32_t* val) { +pdfium::Optional CXFA_WidgetData::GetBarcodeAttribute_DataLength() { pdfium::Optional wsDataLength = GetUIChild()->JSNode()->TryCData(XFA_Attribute::DataLength, true); if (!wsDataLength) - return false; + return {}; - *val = FXSYS_wtoi(wsDataLength->c_str()); - return true; + return {FXSYS_wtoi(wsDataLength->c_str())}; } -bool CXFA_WidgetData::GetBarcodeAttribute_StartChar(char* val) { +pdfium::Optional CXFA_WidgetData::GetBarcodeAttribute_StartChar() { pdfium::Optional wsStartEndChar = GetUIChild()->JSNode()->TryCData(XFA_Attribute::StartChar, true); if (!wsStartEndChar || wsStartEndChar->IsEmpty()) - return false; + return {}; - *val = static_cast((*wsStartEndChar)[0]); - return true; + return {static_cast((*wsStartEndChar)[0])}; } -bool CXFA_WidgetData::GetBarcodeAttribute_EndChar(char* val) { +pdfium::Optional CXFA_WidgetData::GetBarcodeAttribute_EndChar() { pdfium::Optional wsStartEndChar = GetUIChild()->JSNode()->TryCData(XFA_Attribute::EndChar, true); if (!wsStartEndChar || wsStartEndChar->IsEmpty()) - return false; + return {}; - *val = static_cast((*wsStartEndChar)[0]); - return true; + return {static_cast((*wsStartEndChar)[0])}; } -bool CXFA_WidgetData::GetBarcodeAttribute_ECLevel(int32_t* val) { +pdfium::Optional CXFA_WidgetData::GetBarcodeAttribute_ECLevel() { pdfium::Optional wsECLevel = GetUIChild()->JSNode()->TryCData( XFA_Attribute::ErrorCorrectionLevel, true); if (!wsECLevel) - return false; - - *val = FXSYS_wtoi(wsECLevel->c_str()); - return true; + return {}; + return {FXSYS_wtoi(wsECLevel->c_str())}; } -bool CXFA_WidgetData::GetBarcodeAttribute_ModuleWidth(int32_t* val) { +pdfium::Optional CXFA_WidgetData::GetBarcodeAttribute_ModuleWidth() { pdfium::Optional moduleWidthHeight = GetUIChild()->JSNode()->TryMeasure(XFA_Attribute::ModuleWidth, true); if (!moduleWidthHeight) - return false; + return {}; - *val = static_cast(moduleWidthHeight->ToUnit(XFA_Unit::Pt)); - return true; + return {static_cast(moduleWidthHeight->ToUnit(XFA_Unit::Pt))}; } -bool CXFA_WidgetData::GetBarcodeAttribute_ModuleHeight(int32_t* val) { +pdfium::Optional CXFA_WidgetData::GetBarcodeAttribute_ModuleHeight() { pdfium::Optional moduleWidthHeight = GetUIChild()->JSNode()->TryMeasure(XFA_Attribute::ModuleHeight, true); if (!moduleWidthHeight) - return false; + return {}; - *val = static_cast(moduleWidthHeight->ToUnit(XFA_Unit::Pt)); - return true; + return {static_cast(moduleWidthHeight->ToUnit(XFA_Unit::Pt))}; } -bool CXFA_WidgetData::GetBarcodeAttribute_PrintChecksum(bool* val) { - pdfium::Optional printCheckDigit = - GetUIChild()->JSNode()->TryBoolean(XFA_Attribute::PrintCheckDigit, true); - if (printCheckDigit) { - *val = *printCheckDigit; - return true; - } - return false; +pdfium::Optional CXFA_WidgetData::GetBarcodeAttribute_PrintChecksum() { + return GetUIChild()->JSNode()->TryBoolean(XFA_Attribute::PrintCheckDigit, + true); } -bool CXFA_WidgetData::GetBarcodeAttribute_TextLocation(int32_t* val) { +pdfium::Optional +CXFA_WidgetData::GetBarcodeAttribute_TextLocation() { pdfium::Optional textLocation = GetUIChild()->JSNode()->TryEnum(XFA_Attribute::TextLocation, true); if (!textLocation) - return false; + return {}; switch (*textLocation) { case XFA_ATTRIBUTEENUM_None: - *val = BC_TEXT_LOC_NONE; - return true; + return {BC_TEXT_LOC_NONE}; case XFA_ATTRIBUTEENUM_Above: - *val = BC_TEXT_LOC_ABOVE; - return true; + return {BC_TEXT_LOC_ABOVE}; case XFA_ATTRIBUTEENUM_Below: - *val = BC_TEXT_LOC_BELOW; - return true; + return {BC_TEXT_LOC_BELOW}; case XFA_ATTRIBUTEENUM_AboveEmbedded: - *val = BC_TEXT_LOC_ABOVEEMBED; - return true; + return {BC_TEXT_LOC_ABOVEEMBED}; case XFA_ATTRIBUTEENUM_BelowEmbedded: - *val = BC_TEXT_LOC_BELOWEMBED; - return true; + return {BC_TEXT_LOC_BELOWEMBED}; default: break; } - return false; + return {}; } -bool CXFA_WidgetData::GetBarcodeAttribute_Truncate(bool* val) { - pdfium::Optional truncate = - GetUIChild()->JSNode()->TryBoolean(XFA_Attribute::Truncate, true); - if (!truncate) - return false; - - *val = *truncate; - return true; +pdfium::Optional CXFA_WidgetData::GetBarcodeAttribute_Truncate() { + return GetUIChild()->JSNode()->TryBoolean(XFA_Attribute::Truncate, true); } -bool CXFA_WidgetData::GetBarcodeAttribute_WideNarrowRatio(float* val) { +pdfium::Optional +CXFA_WidgetData::GetBarcodeAttribute_WideNarrowRatio() { pdfium::Optional wsWideNarrowRatio = GetUIChild()->JSNode()->TryCData(XFA_Attribute::WideNarrowRatio, true); if (!wsWideNarrowRatio) - return false; + return {}; pdfium::Optional ptPos = wsWideNarrowRatio->Find(':'); - if (!ptPos) { - *val = static_cast(FXSYS_wtoi(wsWideNarrowRatio->c_str())); - return true; - } + if (!ptPos) + return {static_cast(FXSYS_wtoi(wsWideNarrowRatio->c_str()))}; - *val = 0.0f; int32_t fB = FXSYS_wtoi( wsWideNarrowRatio->Right(wsWideNarrowRatio->GetLength() - (*ptPos + 1)) .c_str()); if (!fB) - return true; + return {0}; int32_t fA = FXSYS_wtoi(wsWideNarrowRatio->Left(*ptPos).c_str()); - *val = static_cast(fA) / static_cast(fB); - return true; + float result = static_cast(fA) / static_cast(fB); + return {static_cast(result)}; } -void CXFA_WidgetData::GetPasswordChar(WideString& wsPassWord) { +WideString CXFA_WidgetData::GetPasswordChar() { CXFA_Node* pUIChild = GetUIChild(); - if (!pUIChild) { - wsPassWord = L"*"; - return; - } - wsPassWord = pUIChild->JSNode()->GetCData(XFA_Attribute::PasswordChar); + return pUIChild ? pUIChild->JSNode()->GetCData(XFA_Attribute::PasswordChar) + : L"*"; } bool CXFA_WidgetData::IsMultiLine() { @@ -1311,79 +1287,60 @@ bool CXFA_WidgetData::IsMultiLine() { return pUIChild && pUIChild->JSNode()->GetBoolean(XFA_Attribute::MultiLine); } -XFA_ATTRIBUTEENUM CXFA_WidgetData::GetVerticalScrollPolicy() { - CXFA_Node* pUIChild = GetUIChild(); - if (pUIChild) - return pUIChild->JSNode()->GetEnum(XFA_Attribute::VScrollPolicy); - return XFA_ATTRIBUTEENUM_Auto; -} - -int32_t CXFA_WidgetData::GetMaxChars(XFA_Element& eType) { +std::pair CXFA_WidgetData::GetMaxChars() { if (CXFA_Node* 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: - eType = XFA_Element::Text; - return pChild->JSNode()->GetInteger(XFA_Attribute::MaxChars); + return {XFA_Element::Text, + pChild->JSNode()->GetInteger(XFA_Attribute::MaxChars)}; case XFA_Element::ExData: { - eType = XFA_Element::ExData; int32_t iMax = pChild->JSNode()->GetInteger(XFA_Attribute::MaxLength); - return iMax < 0 ? 0 : iMax; + return {XFA_Element::ExData, iMax < 0 ? 0 : iMax}; } default: break; } } } - return 0; + return {XFA_Element::Unknown, 0}; } -bool CXFA_WidgetData::GetFracDigits(int32_t& iFracDigits) { - iFracDigits = -1; - +int32_t CXFA_WidgetData::GetFracDigits() { CXFA_Node* pNode = m_pNode->GetChild(0, XFA_Element::Value, false); if (!pNode) - return false; + return -1; CXFA_Node* pChild = pNode->GetChild(0, XFA_Element::Decimal, false); if (!pChild) - return false; - - pdfium::Optional ret = - pChild->JSNode()->TryInteger(XFA_Attribute::FracDigits, true); - if (!ret) - return false; + return -1; - iFracDigits = *ret; - return true; + return pChild->JSNode() + ->TryInteger(XFA_Attribute::FracDigits, true) + .value_or(-1); } -bool CXFA_WidgetData::GetLeadDigits(int32_t& iLeadDigits) { - iLeadDigits = -1; - +int32_t CXFA_WidgetData::GetLeadDigits() { CXFA_Node* pNode = m_pNode->GetChild(0, XFA_Element::Value, false); if (!pNode) - return false; + return -1; CXFA_Node* pChild = pNode->GetChild(0, XFA_Element::Decimal, false); if (!pChild) - return false; - - pdfium::Optional ret = - pChild->JSNode()->TryInteger(XFA_Attribute::LeadDigits, true); - if (!ret) - return false; + return -1; - iLeadDigits = *ret; - return true; + return pChild->JSNode() + ->TryInteger(XFA_Attribute::LeadDigits, true) + .value_or(-1); } -bool CXFA_WidgetData::SetValue(const WideString& wsValue, - XFA_VALUEPICTURE eValueType) { +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); @@ -1397,7 +1354,7 @@ bool CXFA_WidgetData::SetValue(const WideString& wsValue, XFA_Element eType = pNode->GetElementType(); if (!wsPicture.IsEmpty()) { CXFA_LocaleMgr* pLocalMgr = m_pNode->GetDocument()->GetLocalMgr(); - IFX_Locale* pLocale = GetLocal(); + IFX_Locale* pLocale = GetLocale(); CXFA_LocaleValue widgetValue = XFA_GetLocaleValue(this); bValidate = widgetValue.ValidateValue(wsValue, wsPicture, pLocale, &wsPicture); @@ -1405,24 +1362,16 @@ bool CXFA_WidgetData::SetValue(const WideString& wsValue, widgetValue = CXFA_LocaleValue(widgetValue.GetType(), wsNewText, wsPicture, pLocale, pLocalMgr); wsNewText = widgetValue.GetValue(); - if (eType == XFA_Element::NumericEdit) { - int32_t iLeadDigits = 0; - int32_t iFracDigits = 0; - GetLeadDigits(iLeadDigits); - GetFracDigits(iFracDigits); - wsNewText = NumericLimit(wsNewText, iLeadDigits, iFracDigits); - } + if (eType == XFA_Element::NumericEdit) + wsNewText = NumericLimit(wsNewText, GetLeadDigits(), GetFracDigits()); + bSyncData = true; } } else { if (eType == XFA_Element::NumericEdit) { - if (wsNewText != L"0") { - int32_t iLeadDigits = 0; - int32_t iFracDigits = 0; - GetLeadDigits(iLeadDigits); - GetFracDigits(iFracDigits); - wsNewText = NumericLimit(wsNewText, iLeadDigits, iFracDigits); - } + if (wsNewText != L"0") + wsNewText = NumericLimit(wsNewText, GetLeadDigits(), GetFracDigits()); + bSyncData = true; } } @@ -1450,7 +1399,7 @@ WideString CXFA_WidgetData::GetPictureContent(XFA_VALUEPICTURE ePicture) { } } - IFX_Locale* pLocale = GetLocal(); + IFX_Locale* pLocale = GetLocale(); if (!pLocale) return L""; @@ -1482,7 +1431,7 @@ WideString CXFA_WidgetData::GetPictureContent(XFA_VALUEPICTURE ePicture) { } } - IFX_Locale* pLocale = GetLocal(); + IFX_Locale* pLocale = GetLocale(); if (!pLocale) return L""; @@ -1512,7 +1461,7 @@ WideString CXFA_WidgetData::GetPictureContent(XFA_VALUEPICTURE ePicture) { return L""; } -IFX_Locale* CXFA_WidgetData::GetLocal() { +IFX_Locale* CXFA_WidgetData::GetLocale() { if (!m_pNode) return nullptr; @@ -1524,9 +1473,8 @@ IFX_Locale* CXFA_WidgetData::GetLocal() { return m_pNode->GetDocument()->GetLocalMgr()->GetLocaleByName(wsLocaleName); } -bool CXFA_WidgetData::GetValue(WideString& wsValue, - XFA_VALUEPICTURE eValueType) { - wsValue = m_pNode->JSNode()->GetContent(false); +WideString CXFA_WidgetData::GetValue(XFA_VALUEPICTURE eValueType) { + WideString wsValue = m_pNode->JSNode()->GetContent(false); if (eValueType == XFA_VALUEPICTURE_Display) GetItemLabel(wsValue.AsStringView(), wsValue); @@ -1534,36 +1482,32 @@ bool CXFA_WidgetData::GetValue(WideString& wsValue, WideString wsPicture = GetPictureContent(eValueType); CXFA_Node* pNode = GetUIChild(); if (!pNode) - return true; + return wsValue; switch (GetUIChild()->GetElementType()) { case XFA_Element::ChoiceList: { if (eValueType == XFA_VALUEPICTURE_Display) { int32_t iSelItemIndex = GetSelectedItem(0); if (iSelItemIndex >= 0) { - GetChoiceListItem(wsValue, iSelItemIndex, false); + wsValue = GetChoiceListItem(iSelItemIndex, false).value_or(L""); wsPicture.clear(); } } } break; case XFA_Element::NumericEdit: if (eValueType != XFA_VALUEPICTURE_Raw && wsPicture.IsEmpty()) { - IFX_Locale* pLocale = GetLocal(); - if (eValueType == XFA_VALUEPICTURE_Display && pLocale) { - WideString wsOutput; - NormalizeNumStr(wsValue, wsOutput); - FormatNumStr(wsOutput, pLocale, wsOutput); - wsValue = wsOutput; - } + IFX_Locale* pLocale = GetLocale(); + if (eValueType == XFA_VALUEPICTURE_Display && pLocale) + wsValue = FormatNumStr(NormalizeNumStr(wsValue), pLocale); } break; default: break; } if (wsPicture.IsEmpty()) - return true; + return wsValue; - if (IFX_Locale* pLocale = GetLocal()) { + if (IFX_Locale* pLocale = GetLocale()) { CXFA_LocaleValue widgetValue = XFA_GetLocaleValue(this); CXFA_LocaleMgr* pLocalMgr = m_pNode->GetDocument()->GetLocalMgr(); switch (widgetValue.GetType()) { @@ -1572,7 +1516,7 @@ bool CXFA_WidgetData::GetValue(WideString& wsValue, if (SplitDateTime(wsValue, wsDate, wsTime)) { CXFA_LocaleValue date(XFA_VT_DATE, wsDate, pLocalMgr); if (date.FormatPatterns(wsValue, wsPicture, pLocale, eValueType)) - return true; + return wsValue; } break; } @@ -1581,7 +1525,7 @@ bool CXFA_WidgetData::GetValue(WideString& wsValue, if (SplitDateTime(wsValue, wsDate, wsTime)) { CXFA_LocaleValue time(XFA_VT_TIME, wsTime, pLocalMgr); if (time.FormatPatterns(wsValue, wsPicture, pLocale, eValueType)) - return true; + return wsValue; } break; } @@ -1590,51 +1534,47 @@ bool CXFA_WidgetData::GetValue(WideString& wsValue, } widgetValue.FormatPatterns(wsValue, wsPicture, pLocale, eValueType); } - return true; + return wsValue; } -bool CXFA_WidgetData::GetNormalizeDataValue(const WideString& wsValue, - WideString& wsNormalizeValue) { - wsNormalizeValue = wsValue; +WideString CXFA_WidgetData::GetNormalizeDataValue(const WideString& wsValue) { if (wsValue.IsEmpty()) - return true; + return L""; WideString wsPicture = GetPictureContent(XFA_VALUEPICTURE_DataBind); if (wsPicture.IsEmpty()) - return true; + return wsValue; ASSERT(GetNode()); CXFA_LocaleMgr* pLocalMgr = GetNode()->GetDocument()->GetLocalMgr(); - IFX_Locale* pLocale = GetLocal(); + IFX_Locale* pLocale = GetLocale(); CXFA_LocaleValue widgetValue = XFA_GetLocaleValue(this); if (widgetValue.ValidateValue(wsValue, wsPicture, pLocale, &wsPicture)) { - widgetValue = CXFA_LocaleValue(widgetValue.GetType(), wsNormalizeValue, - wsPicture, pLocale, pLocalMgr); - wsNormalizeValue = widgetValue.GetValue(); - return true; + widgetValue = CXFA_LocaleValue(widgetValue.GetType(), wsValue, wsPicture, + pLocale, pLocalMgr); + return widgetValue.GetValue(); } - return false; + return wsValue; } -bool CXFA_WidgetData::GetFormatDataValue(const WideString& wsValue, - WideString& wsFormattedValue) { - wsFormattedValue = wsValue; +WideString CXFA_WidgetData::GetFormatDataValue(const WideString& wsValue) { if (wsValue.IsEmpty()) - return true; + return L""; WideString wsPicture = GetPictureContent(XFA_VALUEPICTURE_DataBind); if (wsPicture.IsEmpty()) - return true; + return wsValue; - if (IFX_Locale* pLocale = GetLocal()) { + WideString wsFormattedValue = wsValue; + if (IFX_Locale* pLocale = GetLocale()) { ASSERT(GetNode()); CXFA_Node* pNodeValue = GetNode()->GetChild(0, XFA_Element::Value, false); if (!pNodeValue) - return false; + return wsValue; CXFA_Node* pValueChild = pNodeValue->GetNodeItem(XFA_NODEITEM_FirstChild); if (!pValueChild) - return false; + return wsValue; int32_t iVTType = XFA_VT_NULL; switch (pValueChild->GetElementType()) { @@ -1675,7 +1615,7 @@ bool CXFA_WidgetData::GetFormatDataValue(const WideString& wsValue, CXFA_LocaleValue date(XFA_VT_DATE, wsDate, pLocalMgr); if (date.FormatPatterns(wsFormattedValue, wsPicture, pLocale, XFA_VALUEPICTURE_DataBind)) { - return true; + return wsFormattedValue; } } break; @@ -1686,7 +1626,7 @@ bool CXFA_WidgetData::GetFormatDataValue(const WideString& wsValue, CXFA_LocaleValue time(XFA_VT_TIME, wsTime, pLocalMgr); if (time.FormatPatterns(wsFormattedValue, wsPicture, pLocale, XFA_VALUEPICTURE_DataBind)) { - return true; + return wsFormattedValue; } } break; @@ -1697,31 +1637,30 @@ bool CXFA_WidgetData::GetFormatDataValue(const WideString& wsValue, widgetValue.FormatPatterns(wsFormattedValue, wsPicture, pLocale, XFA_VALUEPICTURE_DataBind); } - return false; + return wsFormattedValue; } -void CXFA_WidgetData::NormalizeNumStr(const WideString& wsValue, - WideString& wsOutput) { +WideString CXFA_WidgetData::NormalizeNumStr(const WideString& wsValue) { if (wsValue.IsEmpty()) - return; + return L""; - wsOutput = wsValue; + WideString wsOutput = wsValue; wsOutput.TrimLeft('0'); - int32_t iFracDigits = 0; - if (!wsOutput.IsEmpty() && wsOutput.Contains('.') && - (!GetFracDigits(iFracDigits) || iFracDigits != -1)) { + + if (!wsOutput.IsEmpty() && wsOutput.Contains('.') && GetFracDigits() != -1) { wsOutput.TrimRight(L"0"); wsOutput.TrimRight(L"."); } if (wsOutput.IsEmpty() || wsOutput[0] == '.') wsOutput.InsertAtFront('0'); + + return wsOutput; } -void CXFA_WidgetData::FormatNumStr(const WideString& wsValue, - IFX_Locale* pLocale, - WideString& wsOutput) { +WideString CXFA_WidgetData::FormatNumStr(const WideString& wsValue, + IFX_Locale* pLocale) { if (wsValue.IsEmpty()) - return; + return L""; WideString wsSrcNum = wsValue; WideString wsGroupSymbol = @@ -1735,24 +1674,25 @@ void CXFA_WidgetData::FormatNumStr(const WideString& wsValue, auto dot_index = wsSrcNum.Find('.'); dot_index = !dot_index.has_value() ? wsSrcNum.GetLength() : dot_index; - if (dot_index.value() >= 1) { - size_t nPos = dot_index.value() % 3; - wsOutput.clear(); - for (size_t i = 0; i < dot_index.value(); i++) { - if (i % 3 == nPos && i != 0) - wsOutput += wsGroupSymbol; + if (dot_index.value() < 1) + return L""; - 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) { - wsOutput = - pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus) + wsOutput; - } + 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) { @@ -1762,7 +1702,7 @@ void CXFA_WidgetData::SyncValue(const WideString& wsValue, bool bNotify) { WideString wsFormatValue(wsValue); CXFA_WidgetData* pContainerWidgetData = m_pNode->GetContainerWidgetData(); if (pContainerWidgetData) - pContainerWidgetData->GetFormatDataValue(wsValue, wsFormatValue); + wsFormatValue = pContainerWidgetData->GetFormatDataValue(wsValue); m_pNode->JSNode()->SetContent(wsValue, wsFormatValue, bNotify, false, true); } diff --git a/xfa/fxfa/parser/cxfa_widgetdata.h b/xfa/fxfa/parser/cxfa_widgetdata.h index c6f07e2f2a..7e17323ec8 100644 --- a/xfa/fxfa/parser/cxfa_widgetdata.h +++ b/xfa/fxfa/parser/cxfa_widgetdata.h @@ -7,11 +7,13 @@ #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/parser/cxfa_binddata.h" #include "xfa/fxfa/parser/cxfa_borderdata.h" #include "xfa/fxfa/parser/cxfa_calculatedata.h" @@ -47,7 +49,7 @@ class CXFA_WidgetData : public CXFA_DataData { CFX_RectF GetUIMargin(); WideString GetRawValue() const; - int32_t GetRotate(); + int32_t GetRotate() const; bool IsOpenAccess() const; bool IsListBox(); @@ -67,7 +69,7 @@ class CXFA_WidgetData : public CXFA_DataData { CXFA_ValidateData GetValidateData(bool bModified); CXFA_BorderData GetUIBorderData(); - std::vector GetEventByActivity(int32_t iActivity, + std::vector GetEventByActivity(XFA_ATTRIBUTEENUM iActivity, bool bIsFormReady); pdfium::Optional TryWidth(); @@ -78,10 +80,10 @@ class CXFA_WidgetData : public CXFA_DataData { pdfium::Optional TryMaxHeight(); XFA_ATTRIBUTEENUM GetButtonHighlight(); - bool GetButtonRollover(WideString& wsRollover, bool& bRichText); - bool GetButtonDown(WideString& wsDown, bool& bRichText); + bool HasButtonRollover() const; + bool HasButtonDown() const; - XFA_ATTRIBUTEENUM GetCheckButtonShape(); + bool IsCheckButtonRound(); XFA_ATTRIBUTEENUM GetCheckButtonMark(); float GetCheckButtonSize(); @@ -99,9 +101,10 @@ class CXFA_WidgetData : public CXFA_DataData { CXFA_Node* GetExclGroupNextMember(CXFA_Node* pNode); int32_t CountChoiceListItems(bool bSaveValue); - bool GetChoiceListItem(WideString& wsText, int32_t nIndex, bool bSaveValue); - XFA_ATTRIBUTEENUM GetChoiceListOpen(); - XFA_ATTRIBUTEENUM GetChoiceListCommitOn(); + pdfium::Optional GetChoiceListItem(int32_t nIndex, + bool bSaveValue); + bool IsChoiceListMultiSelect(); + bool IsChoiceListCommitOnSelect(); std::vector GetChoiceListItems(bool bSaveValue); int32_t CountSelectedItems(); @@ -125,49 +128,49 @@ class CXFA_WidgetData : public CXFA_DataData { bool bScriptModify, bool bSyncData); - void GetItemValue(const WideStringView& wsLabel, WideString& wsValue); + WideString GetItemValue(const WideStringView& wsLabel); - int32_t GetHorizontalScrollPolicy(); - XFA_ATTRIBUTEENUM GetVerticalScrollPolicy(); - int32_t GetNumberOfCells(); + bool IsHorizontalScrollPolicyOff(); + bool IsVerticalScrollPolicyOff(); + pdfium::Optional GetNumberOfCells(); - bool SetValue(const WideString& wsValue, XFA_VALUEPICTURE eValueType); - bool GetValue(WideString& wsValue, XFA_VALUEPICTURE eValueType); + bool SetValue(XFA_VALUEPICTURE eValueType, const WideString& wsValue); + WideString GetValue(XFA_VALUEPICTURE eValueType); WideString GetPictureContent(XFA_VALUEPICTURE ePicture); - IFX_Locale* GetLocal(); + IFX_Locale* GetLocale(); - bool GetNormalizeDataValue(const WideString& wsValue, - WideString& wsNormalizeValue); - bool GetFormatDataValue(const WideString& wsValue, - WideString& wsFormattedValue); - void NormalizeNumStr(const WideString& wsValue, WideString& wsOutput); + WideString GetNormalizeDataValue(const WideString& wsValue); + WideString GetFormatDataValue(const WideString& wsValue); + WideString NormalizeNumStr(const WideString& wsValue); WideString GetBarcodeType(); - bool GetBarcodeAttribute_CharEncoding(int32_t* val); - bool GetBarcodeAttribute_Checksum(bool* val); - bool GetBarcodeAttribute_DataLength(int32_t* val); - bool GetBarcodeAttribute_StartChar(char* val); - bool GetBarcodeAttribute_EndChar(char* val); - bool GetBarcodeAttribute_ECLevel(int32_t* val); - bool GetBarcodeAttribute_ModuleWidth(int32_t* val); - bool GetBarcodeAttribute_ModuleHeight(int32_t* val); - bool GetBarcodeAttribute_PrintChecksum(bool* val); - bool GetBarcodeAttribute_TextLocation(int32_t* val); - bool GetBarcodeAttribute_Truncate(bool* val); - bool GetBarcodeAttribute_WideNarrowRatio(float* val); - void GetPasswordChar(WideString& wsPassWord); - - int32_t GetMaxChars(XFA_Element& eType); - bool GetFracDigits(int32_t& iFracDigits); - bool GetLeadDigits(int32_t& iLeadDigits); + 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 m_bIsNull; - bool m_bPreNull; + 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: CXFA_BindData GetBindData(); @@ -175,13 +178,13 @@ class CXFA_WidgetData : public CXFA_DataData { void InsertListTextItem(CXFA_Node* pItems, const WideString& wsText, int32_t nIndex); - void FormatNumStr(const WideString& wsValue, - IFX_Locale* pLocale, - WideString& wsOutput); + WideString FormatNumStr(const WideString& wsValue, IFX_Locale* pLocale); CXFA_Node* GetExclGroupNode(); void GetItemLabel(const WideStringView& wsValue, WideString& wsLabel); std::vector GetEventList(); + bool m_bIsNull; + bool m_bPreNull; CXFA_Node* m_pUiChildNode; XFA_Element m_eUIType; }; diff --git a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp index 2a3494f276..b2df645ebc 100644 --- a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp +++ b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp @@ -127,7 +127,6 @@ void CreateDataBinding(CXFA_Node* pFormNode, pFormNode->JSNode()->GetProperty(0, XFA_Element::Value, true)); if (!bDataToForm) { WideString wsValue; - WideString wsFormattedValue; switch (eUIType) { case XFA_Element::ImageEdit: { CXFA_ImageData imageData = defValueData.GetImageData(); @@ -141,9 +140,9 @@ void CreateDataBinding(CXFA_Node* pFormNode, CFX_XMLElement* pXMLDataElement = static_cast(pDataNode->GetXMLMappingNode()); ASSERT(pXMLDataElement); - pWidgetData->GetFormatDataValue(wsValue, wsFormattedValue); - pDataNode->JSNode()->SetAttributeValue(wsValue, wsFormattedValue, false, - false); + + pDataNode->JSNode()->SetAttributeValue( + wsValue, pWidgetData->GetFormatDataValue(wsValue), false, false); pDataNode->JSNode()->SetCData(XFA_Attribute::ContentType, wsContentType, false, false); if (!wsHref.IsEmpty()) @@ -153,7 +152,7 @@ void CreateDataBinding(CXFA_Node* pFormNode, } case XFA_Element::ChoiceList: wsValue = defValueData.GetChildValueContent(); - if (pWidgetData->GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) { + if (pWidgetData->IsChoiceListMultiSelect()) { std::vector wsSelTextArray = pWidgetData->GetSelectedItemsValue(); if (!wsSelTextArray.empty()) { @@ -174,9 +173,8 @@ void CreateDataBinding(CXFA_Node* pFormNode, L"dataGroup"); } } else if (!wsValue.IsEmpty()) { - pWidgetData->GetFormatDataValue(wsValue, wsFormattedValue); - pDataNode->JSNode()->SetAttributeValue(wsValue, wsFormattedValue, - false, false); + pDataNode->JSNode()->SetAttributeValue( + wsValue, pWidgetData->GetFormatDataValue(wsValue), false, false); } break; case XFA_Element::CheckButton: @@ -184,9 +182,8 @@ void CreateDataBinding(CXFA_Node* pFormNode, if (wsValue.IsEmpty()) break; - pWidgetData->GetFormatDataValue(wsValue, wsFormattedValue); - pDataNode->JSNode()->SetAttributeValue(wsValue, wsFormattedValue, false, - false); + pDataNode->JSNode()->SetAttributeValue( + wsValue, pWidgetData->GetFormatDataValue(wsValue), false, false); break; case XFA_Element::ExclGroup: { CXFA_Node* pChecked = nullptr; @@ -214,9 +211,8 @@ void CreateDataBinding(CXFA_Node* pFormNode, WideString wsContent = pText->JSNode()->GetContent(false); if (wsContent == wsValue) { pChecked = pChild; - wsFormattedValue = wsValue; - pDataNode->JSNode()->SetAttributeValue(wsValue, wsFormattedValue, - false, false); + pDataNode->JSNode()->SetAttributeValue(wsValue, wsValue, false, + false); pFormNode->JSNode()->SetCData(XFA_Attribute::Value, wsContent, false, false); break; @@ -253,12 +249,9 @@ void CreateDataBinding(CXFA_Node* pFormNode, if (wsValue.IsEmpty()) break; - WideString wsOutput; - pWidgetData->NormalizeNumStr(wsValue, wsOutput); - wsValue = wsOutput; - pWidgetData->GetFormatDataValue(wsValue, wsFormattedValue); - pDataNode->JSNode()->SetAttributeValue(wsValue, wsFormattedValue, false, - false); + wsValue = pWidgetData->NormalizeNumStr(wsValue); + pDataNode->JSNode()->SetAttributeValue( + wsValue, pWidgetData->GetFormatDataValue(wsValue), false, false); CXFA_Node* pValue = pFormNode->JSNode()->GetProperty(0, XFA_Element::Value, true); FormValueNode_SetChildContent(pValue, wsValue, XFA_Element::Float); @@ -269,18 +262,15 @@ void CreateDataBinding(CXFA_Node* pFormNode, if (wsValue.IsEmpty()) break; - pWidgetData->GetFormatDataValue(wsValue, wsFormattedValue); - pDataNode->JSNode()->SetAttributeValue(wsValue, wsFormattedValue, false, - false); + pDataNode->JSNode()->SetAttributeValue( + wsValue, pWidgetData->GetFormatDataValue(wsValue), false, false); break; } return; } WideString wsXMLValue = pDataNode->JSNode()->GetContent(false); - - WideString wsNormalizeValue; - pWidgetData->GetNormalizeDataValue(wsXMLValue, wsNormalizeValue); + WideString wsNormalizeValue = pWidgetData->GetNormalizeDataValue(wsXMLValue); pDataNode->JSNode()->SetAttributeValue(wsNormalizeValue, wsXMLValue, false, false); @@ -309,7 +299,7 @@ void CreateDataBinding(CXFA_Node* pFormNode, break; } case XFA_Element::ChoiceList: - if (pWidgetData->GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) { + if (pWidgetData->IsChoiceListMultiSelect()) { std::vector items = pDataNode->GetNodeList( XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties, XFA_Element::Unknown); @@ -352,11 +342,9 @@ void CreateDataBinding(CXFA_Node* pFormNode, case XFA_Element::NumericEdit: { WideString wsPicture = pWidgetData->GetPictureContent(XFA_VALUEPICTURE_DataBind); - if (wsPicture.IsEmpty()) { - WideString wsOutput; - pWidgetData->NormalizeNumStr(wsNormalizeValue, wsOutput); - wsNormalizeValue = wsOutput; - } + if (wsPicture.IsEmpty()) + wsNormalizeValue = pWidgetData->NormalizeNumStr(wsNormalizeValue); + FormValueNode_SetChildContent(defValueData.GetNode(), wsNormalizeValue, XFA_Element::Float); break; -- cgit v1.2.3