diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-11-23 17:02:23 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-11-23 17:02:23 +0000 |
commit | 6aec70bc09cb65b169fe6ca1af65e8929aeea43a (patch) | |
tree | 34d55cf15cba0fe71e87a896184ecdc891d4752f /xfa/fxfa | |
parent | d49254bc9323883deba14d27026ec2bb9af096fa (diff) | |
download | pdfium-chromium/3277.tar.xz |
Cleanup CXFA_WidgetDatachromium/3277
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 <hnakashima@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa')
-rw-r--r-- | xfa/fxfa/cxfa_ffbarcode.cpp | 85 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffcheckbutton.cpp | 22 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffcheckbutton.h | 2 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffcombobox.cpp | 32 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffdatetimeedit.cpp | 27 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_fffield.cpp | 9 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_fflistbox.cpp | 4 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffnumericedit.cpp | 23 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffpasswordedit.cpp | 13 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffpushbutton.cpp | 16 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_fftextedit.cpp | 42 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_textprovider.cpp | 2 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_widgetacc.cpp | 55 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_widgetacc.h | 3 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_captiondata.cpp | 14 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_captiondata.h | 5 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_eventdata.cpp | 2 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_eventdata.h | 2 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_node.cpp | 44 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_widgetdata.cpp | 532 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_widgetdata.h | 87 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_document_datamerger_imp.cpp | 52 |
22 files changed, 488 insertions, 585 deletions
diff --git a/xfa/fxfa/cxfa_ffbarcode.cpp b/xfa/fxfa/cxfa_ffbarcode.cpp index 726f89176f..29c6d85e89 100644 --- a/xfa/fxfa/cxfa_ffbarcode.cpp +++ b/xfa/fxfa/cxfa_ffbarcode.cpp @@ -129,9 +129,7 @@ bool CXFA_FFBarcode::LoadWidget() { m_pNormalWidget->SetDelegate(this); m_pNormalWidget->LockUpdate(); - WideString wsText; - m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); - pFWLBarcode->SetText(wsText); + pFWLBarcode->SetText(m_pDataAcc->GetValue(XFA_VALUEPICTURE_Display)); UpdateWidgetProperty(); m_pNormalWidget->UnlockUpdate(); return CXFA_FFField::LoadWidget(); @@ -168,37 +166,56 @@ void CXFA_FFBarcode::UpdateWidgetProperty() { pBarCodeWidget->SetType(pBarcodeInfo->eBCType); CXFA_WidgetAcc* pAcc = GetDataAcc(); - int32_t intVal; - if (pAcc->GetBarcodeAttribute_CharEncoding(&intVal)) - pBarCodeWidget->SetCharEncoding((BC_CHAR_ENCODING)intVal); - - bool boolVal; - if (pAcc->GetBarcodeAttribute_Checksum(&boolVal)) - pBarCodeWidget->SetCalChecksum(boolVal); - if (pAcc->GetBarcodeAttribute_DataLength(&intVal)) - pBarCodeWidget->SetDataLength(intVal); - - char charVal; - if (pAcc->GetBarcodeAttribute_StartChar(&charVal)) - pBarCodeWidget->SetStartChar(charVal); - if (pAcc->GetBarcodeAttribute_EndChar(&charVal)) - pBarCodeWidget->SetEndChar(charVal); - if (pAcc->GetBarcodeAttribute_ECLevel(&intVal)) - pBarCodeWidget->SetErrorCorrectionLevel(intVal); - if (pAcc->GetBarcodeAttribute_ModuleWidth(&intVal)) - pBarCodeWidget->SetModuleWidth(intVal); - if (pAcc->GetBarcodeAttribute_ModuleHeight(&intVal)) - pBarCodeWidget->SetModuleHeight(intVal); - if (pAcc->GetBarcodeAttribute_PrintChecksum(&boolVal)) - pBarCodeWidget->SetPrintChecksum(boolVal); - if (pAcc->GetBarcodeAttribute_TextLocation(&intVal)) - pBarCodeWidget->SetTextLocation((BC_TEXT_LOC)intVal); - if (pAcc->GetBarcodeAttribute_Truncate(&boolVal)) - pBarCodeWidget->SetTruncated(boolVal); - - float floatVal; - if (pAcc->GetBarcodeAttribute_WideNarrowRatio(&floatVal)) - pBarCodeWidget->SetWideNarrowRatio(static_cast<int8_t>(floatVal)); + pdfium::Optional<BC_CHAR_ENCODING> encoding = + pAcc->GetBarcodeAttribute_CharEncoding(); + if (encoding) + pBarCodeWidget->SetCharEncoding(*encoding); + + pdfium::Optional<bool> calcChecksum = pAcc->GetBarcodeAttribute_Checksum(); + if (calcChecksum) + pBarCodeWidget->SetCalChecksum(*calcChecksum); + + pdfium::Optional<int32_t> dataLen = pAcc->GetBarcodeAttribute_DataLength(); + if (dataLen) + pBarCodeWidget->SetDataLength(*dataLen); + + pdfium::Optional<char> startChar = pAcc->GetBarcodeAttribute_StartChar(); + if (startChar) + pBarCodeWidget->SetStartChar(*startChar); + + pdfium::Optional<char> endChar = pAcc->GetBarcodeAttribute_EndChar(); + if (endChar) + pBarCodeWidget->SetEndChar(*endChar); + + pdfium::Optional<int32_t> ecLevel = pAcc->GetBarcodeAttribute_ECLevel(); + if (ecLevel) + pBarCodeWidget->SetErrorCorrectionLevel(*ecLevel); + + pdfium::Optional<int32_t> width = pAcc->GetBarcodeAttribute_ModuleWidth(); + if (width) + pBarCodeWidget->SetModuleWidth(*width); + + pdfium::Optional<int32_t> height = pAcc->GetBarcodeAttribute_ModuleHeight(); + if (height) + pBarCodeWidget->SetModuleHeight(*height); + + pdfium::Optional<bool> printCheck = pAcc->GetBarcodeAttribute_PrintChecksum(); + if (printCheck) + pBarCodeWidget->SetPrintChecksum(*printCheck); + + pdfium::Optional<BC_TEXT_LOC> textLoc = + pAcc->GetBarcodeAttribute_TextLocation(); + if (textLoc) + pBarCodeWidget->SetTextLocation(*textLoc); + + pdfium::Optional<bool> truncate = pAcc->GetBarcodeAttribute_Truncate(); + if (truncate) + pBarCodeWidget->SetTruncated(*truncate); + + pdfium::Optional<int8_t> ratio = pAcc->GetBarcodeAttribute_WideNarrowRatio(); + if (ratio) + pBarCodeWidget->SetWideNarrowRatio(*ratio); + if (pBarcodeInfo->eName == BarcodeType::code3Of9 || pBarcodeInfo->eName == BarcodeType::ean8 || pBarcodeInfo->eName == BarcodeType::ean13 || diff --git a/xfa/fxfa/cxfa_ffcheckbutton.cpp b/xfa/fxfa/cxfa_ffcheckbutton.cpp index 48a4857980..7d44c08107 100644 --- a/xfa/fxfa/cxfa_ffcheckbutton.cpp +++ b/xfa/fxfa/cxfa_ffcheckbutton.cpp @@ -54,8 +54,7 @@ void CXFA_FFCheckButton::UpdateWidgetProperty() { pCheckBox->SetBoxSize(m_pDataAcc->GetCheckButtonSize()); uint32_t dwStyleEx = FWL_STYLEEXT_CKB_SignShapeCross; - int32_t iCheckMark = m_pDataAcc->GetCheckButtonMark(); - switch (iCheckMark) { + switch (m_pDataAcc->GetCheckButtonMark()) { case XFA_ATTRIBUTEENUM_Check: dwStyleEx = FWL_STYLEEXT_CKB_SignShapeCheck; break; @@ -74,10 +73,8 @@ void CXFA_FFCheckButton::UpdateWidgetProperty() { dwStyleEx = FWL_STYLEEXT_CKB_SignShapeStar; break; default: { - int32_t iShape = m_pDataAcc->GetCheckButtonShape(); - if (iShape == XFA_ATTRIBUTEENUM_Round) { + if (m_pDataAcc->IsCheckButtonRound()) dwStyleEx = FWL_STYLEEXT_CKB_SignShapeCircle; - } } break; } if (m_pDataAcc->IsAllowNeutral()) @@ -96,10 +93,10 @@ bool CXFA_FFCheckButton::PerformLayout() { if (marginData.HasValidNode()) XFA_RectWidthoutMargin(rtWidget, marginData); - int32_t iCapPlacement = -1; + XFA_ATTRIBUTEENUM iCapPlacement = XFA_ATTRIBUTEENUM_Unknown; float fCapReserve = 0; CXFA_CaptionData captionData = m_pDataAcc->GetCaptionData(); - if (captionData.HasValidNode() && captionData.GetPresence()) { + if (captionData.HasValidNode() && captionData.IsVisible()) { m_rtCaption = rtWidget; iCapPlacement = captionData.GetPlacementType(); fCapReserve = captionData.GetReserve(); @@ -200,7 +197,7 @@ void CXFA_FFCheckButton::CapLeftRightPlacement( } } -void CXFA_FFCheckButton::AddUIMargin(int32_t iCapPlacement) { +void CXFA_FFCheckButton::AddUIMargin(XFA_ATTRIBUTEENUM iCapPlacement) { CFX_RectF rtUIMargin = m_pDataAcc->GetUIMargin(); m_rtUI.top -= rtUIMargin.top / 2 - rtUIMargin.height / 2; @@ -236,12 +233,9 @@ void CXFA_FFCheckButton::RenderWidget(CXFA_Graphics* pGS, CXFA_FFWidget::RenderWidget(pGS, mtRotate, dwStatus); DrawBorderWithFlags( pGS, m_pDataAcc->GetUIBorderData(), m_rtUI, mtRotate, - m_pDataAcc->GetCheckButtonShape() == XFA_ATTRIBUTEENUM_Round - ? XFA_DRAWBOX_ForceRound - : 0); + m_pDataAcc->IsCheckButtonRound() ? XFA_DRAWBOX_ForceRound : 0); RenderCaption(pGS, &mtRotate); - DrawHighlight(pGS, &mtRotate, dwStatus, - m_pDataAcc->GetCheckButtonShape() == XFA_ATTRIBUTEENUM_Round); + DrawHighlight(pGS, &mtRotate, dwStatus, m_pDataAcc->IsCheckButtonRound()); CFX_Matrix mt(1, 0, 0, 1, m_rtCheckBox.left, m_rtCheckBox.top); mt.Concat(mtRotate); GetApp()->GetFWLWidgetMgr()->OnDrawWidget(m_pNormalWidget.get(), pGS, mt); @@ -310,7 +304,7 @@ void CXFA_FFCheckButton::OnProcessEvent(CFWL_Event* pEvent) { case CFWL_Event::Type::CheckStateChanged: { CXFA_EventParam eParam; eParam.m_eType = XFA_EVENT_Change; - m_pDataAcc->GetValue(eParam.m_wsNewText, XFA_VALUEPICTURE_Raw); + eParam.m_wsNewText = m_pDataAcc->GetValue(XFA_VALUEPICTURE_Raw); CXFA_WidgetAcc* pFFExclGroup = m_pDataAcc->GetExclGroup(); if (ProcessCommittedData()) { diff --git a/xfa/fxfa/cxfa_ffcheckbutton.h b/xfa/fxfa/cxfa_ffcheckbutton.h index 566e803ad3..da772d3e6b 100644 --- a/xfa/fxfa/cxfa_ffcheckbutton.h +++ b/xfa/fxfa/cxfa_ffcheckbutton.h @@ -36,7 +36,7 @@ class CXFA_FFCheckButton : public CXFA_FFField { bool CommitData() override; bool IsDataChanged() override; void CapLeftRightPlacement(const CXFA_MarginData& captionMarginData); - void AddUIMargin(int32_t iCapPlacement); + void AddUIMargin(XFA_ATTRIBUTEENUM iCapPlacement); XFA_CHECKSTATE FWLState2XFAState(); IFWL_WidgetDelegate* m_pOldDelegate; diff --git a/xfa/fxfa/cxfa_ffcombobox.cpp b/xfa/fxfa/cxfa_ffcombobox.cpp index 87e14d205f..f96ccb8b32 100644 --- a/xfa/fxfa/cxfa_ffcombobox.cpp +++ b/xfa/fxfa/cxfa_ffcombobox.cpp @@ -55,13 +55,10 @@ bool CXFA_FFComboBox::LoadWidget() { pComboBox->AddString(label.AsStringView()); std::vector<int32_t> iSelArray = m_pDataAcc->GetSelectedItems(); - if (!iSelArray.empty()) { + if (iSelArray.empty()) + pComboBox->SetEditText(m_pDataAcc->GetValue(XFA_VALUEPICTURE_Raw)); + else pComboBox->SetCurSel(iSelArray.front()); - } else { - WideString wsText; - m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Raw); - pComboBox->SetEditText(wsText); - } UpdateWidgetProperty(); m_pNormalWidget->UnlockUpdate(); @@ -88,7 +85,7 @@ void CXFA_FFComboBox::UpdateWidgetProperty() { dwExtendedStyle |= GetAlignment(); m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); - if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) + if (!m_pDataAcc->IsHorizontalScrollPolicyOff()) dwEditStyles |= FWL_STYLEEXT_EDT_AutoHScroll; pComboBox->EditModifyStylesEx(dwEditStyles, 0xFFFFFFFF); @@ -115,7 +112,7 @@ void CXFA_FFComboBox::OpenDropDownList() { } bool CXFA_FFComboBox::CommitData() { - return m_pDataAcc->SetValue(m_wsNewValue, XFA_VALUEPICTURE_Raw); + return m_pDataAcc->SetValue(XFA_VALUEPICTURE_Raw, m_wsNewValue); } bool CXFA_FFComboBox::IsDataChanged() { @@ -125,12 +122,9 @@ bool CXFA_FFComboBox::IsDataChanged() { if (iCursel >= 0) { WideString wsSel = pFWLcombobox->GetTextByIndex(iCursel); if (wsSel == wsText) - m_pDataAcc->GetChoiceListItem(wsText, iCursel, true); + wsText = m_pDataAcc->GetChoiceListItem(iCursel, true).value_or(L""); } - - WideString wsOldValue; - m_pDataAcc->GetValue(wsOldValue, XFA_VALUEPICTURE_Raw); - if (wsOldValue == wsText) + if (m_pDataAcc->GetValue(XFA_VALUEPICTURE_Raw) == wsText) return false; m_wsNewValue = wsText; @@ -193,10 +187,8 @@ bool CXFA_FFComboBox::UpdateFWLData() { if (!iSelArray.empty()) { pComboBox->SetCurSel(iSelArray.front()); } else { - WideString wsText; pComboBox->SetCurSel(-1); - m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Raw); - pComboBox->SetEditText(wsText); + pComboBox->SetEditText(m_pDataAcc->GetValue(XFA_VALUEPICTURE_Raw)); } pComboBox->Update(); return true; @@ -292,19 +284,17 @@ void CXFA_FFComboBox::DeleteItem(int32_t nIndex) { void CXFA_FFComboBox::OnTextChanged(CFWL_Widget* pWidget, const WideString& wsChanged) { CXFA_EventParam eParam; - m_pDataAcc->GetValue(eParam.m_wsPrevText, XFA_VALUEPICTURE_Raw); + eParam.m_wsPrevText = m_pDataAcc->GetValue(XFA_VALUEPICTURE_Raw); eParam.m_wsChange = wsChanged; FWLEventSelChange(&eParam); } void CXFA_FFComboBox::OnSelectChanged(CFWL_Widget* pWidget, bool bLButtonUp) { CXFA_EventParam eParam; - m_pDataAcc->GetValue(eParam.m_wsPrevText, XFA_VALUEPICTURE_Raw); + eParam.m_wsPrevText = m_pDataAcc->GetValue(XFA_VALUEPICTURE_Raw); FWLEventSelChange(&eParam); - if (m_pDataAcc->GetChoiceListCommitOn() == XFA_ATTRIBUTEENUM_Select && - bLButtonUp) { + if (m_pDataAcc->IsChoiceListCommitOnSelect() && bLButtonUp) m_pDocView->SetFocusWidgetAcc(nullptr); - } } void CXFA_FFComboBox::OnPreOpen(CFWL_Widget* pWidget) { diff --git a/xfa/fxfa/cxfa_ffdatetimeedit.cpp b/xfa/fxfa/cxfa_ffdatetimeedit.cpp index 4b8f39704d..109b7e8228 100644 --- a/xfa/fxfa/cxfa_ffdatetimeedit.cpp +++ b/xfa/fxfa/cxfa_ffdatetimeedit.cpp @@ -47,9 +47,9 @@ bool CXFA_FFDateTimeEdit::LoadWidget() { m_pNormalWidget->SetDelegate(this); m_pNormalWidget->LockUpdate(); - WideString wsText; - m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); + WideString wsText = m_pDataAcc->GetValue(XFA_VALUEPICTURE_Display); pWidget->SetEditText(wsText); + CXFA_ValueData valueData = m_pDataAcc->GetFormValueData(); if (valueData.HasValidNode()) { switch (valueData.GetChildValueClassID()) { @@ -80,17 +80,18 @@ void CXFA_FFDateTimeEdit::UpdateWidgetProperty() { dwExtendedStyle |= UpdateUIProperty(); dwExtendedStyle |= GetAlignment(); m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); + uint32_t dwEditStyles = 0; - int32_t iNumCells = m_pDataAcc->GetNumberOfCells(); - if (iNumCells > 0) { + pdfium::Optional<int32_t> numCells = m_pDataAcc->GetNumberOfCells(); + if (numCells && *numCells > 0) { dwEditStyles |= FWL_STYLEEXT_EDT_CombText; - pWidget->SetEditLimit(iNumCells); + pWidget->SetEditLimit(*numCells); } if (!m_pDataAcc->IsOpenAccess() || !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { dwEditStyles |= FWL_STYLEEXT_EDT_ReadOnly; } - if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) + if (!m_pDataAcc->IsHorizontalScrollPolicyOff()) dwEditStyles |= FWL_STYLEEXT_EDT_AutoHScroll; pWidget->ModifyEditStylesEx(dwEditStyles, 0xFFFFFFFF); @@ -136,7 +137,7 @@ uint32_t CXFA_FFDateTimeEdit::GetAlignment() { bool CXFA_FFDateTimeEdit::CommitData() { auto* pPicker = static_cast<CFWL_DateTimePicker*>(m_pNormalWidget.get()); - if (!m_pDataAcc->SetValue(pPicker->GetEditText(), XFA_VALUEPICTURE_Edit)) + if (!m_pDataAcc->SetValue(XFA_VALUEPICTURE_Edit, pPicker->GetEditText())) return false; m_pDataAcc->UpdateUIDisplay(this); @@ -151,9 +152,7 @@ bool CXFA_FFDateTimeEdit::UpdateFWLData() { if (IsFocused()) eType = XFA_VALUEPICTURE_Edit; - WideString wsText; - m_pDataAcc->GetValue(wsText, eType); - + WideString wsText = m_pDataAcc->GetValue(eType); auto* normalWidget = static_cast<CFWL_DateTimePicker*>(m_pNormalWidget.get()); normalWidget->SetEditText(wsText); if (IsFocused() && !wsText.IsEmpty()) { @@ -174,9 +173,7 @@ bool CXFA_FFDateTimeEdit::IsDataChanged() { WideString wsText = static_cast<CFWL_DateTimePicker*>(m_pNormalWidget.get())->GetEditText(); - WideString wsOldValue; - m_pDataAcc->GetValue(wsOldValue, XFA_VALUEPICTURE_Edit); - return wsOldValue != wsText; + return m_pDataAcc->GetValue(XFA_VALUEPICTURE_Edit) != wsText; } void CXFA_FFDateTimeEdit::OnSelectChanged(CFWL_Widget* pWidget, @@ -189,7 +186,7 @@ void CXFA_FFDateTimeEdit::OnSelectChanged(CFWL_Widget* pWidget, date.SetDate(CFX_DateTime(iYear, iMonth, iDay, 0, 0, 0, 0)); WideString wsDate; - date.FormatPatterns(wsDate, wsPicture, m_pDataAcc->GetLocal(), + date.FormatPatterns(wsDate, wsPicture, m_pDataAcc->GetLocale(), XFA_VALUEPICTURE_Edit); auto* pDateTime = static_cast<CFWL_DateTimePicker*>(m_pNormalWidget.get()); @@ -200,7 +197,7 @@ void CXFA_FFDateTimeEdit::OnSelectChanged(CFWL_Widget* pWidget, CXFA_EventParam eParam; eParam.m_eType = XFA_EVENT_Change; eParam.m_pTarget = m_pDataAcc.Get(); - m_pDataAcc->GetValue(eParam.m_wsNewText, XFA_VALUEPICTURE_Raw); + eParam.m_wsNewText = m_pDataAcc->GetValue(XFA_VALUEPICTURE_Raw); m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam); } diff --git a/xfa/fxfa/cxfa_fffield.cpp b/xfa/fxfa/cxfa_fffield.cpp index 70b11640ec..1f4cf56c1d 100644 --- a/xfa/fxfa/cxfa_fffield.cpp +++ b/xfa/fxfa/cxfa_fffield.cpp @@ -188,9 +188,8 @@ void CXFA_FFField::CapPlacement() { XFA_ATTRIBUTEENUM iCapPlacement = XFA_ATTRIBUTEENUM_Unknown; float fCapReserve = 0; CXFA_CaptionData captionData = m_pDataAcc->GetCaptionData(); - if (captionData.HasValidNode() && - captionData.GetPresence() != XFA_ATTRIBUTEENUM_Hidden) { - iCapPlacement = (XFA_ATTRIBUTEENUM)captionData.GetPlacementType(); + if (captionData.HasValidNode() && !captionData.IsHidden()) { + iCapPlacement = captionData.GetPlacementType(); if (iCapPlacement == XFA_ATTRIBUTEENUM_Top && GetPrev()) { m_rtCaption.Reset(); } else if (iCapPlacement == XFA_ATTRIBUTEENUM_Bottom && GetNext()) { @@ -604,10 +603,8 @@ void CXFA_FFField::RenderCaption(CXFA_Graphics* pGS, CFX_Matrix* pMatrix) { return; CXFA_CaptionData captionData = m_pDataAcc->GetCaptionData(); - if (!captionData.HasValidNode() || - captionData.GetPresence() != XFA_ATTRIBUTEENUM_Visible) { + if (!captionData.HasValidNode() || !captionData.IsVisible()) return; - } if (!pCapTextLayout->IsLoaded()) pCapTextLayout->Layout(CFX_SizeF(m_rtCaption.width, m_rtCaption.height)); diff --git a/xfa/fxfa/cxfa_fflistbox.cpp b/xfa/fxfa/cxfa_fflistbox.cpp index 79496b310e..0609cd270a 100644 --- a/xfa/fxfa/cxfa_fflistbox.cpp +++ b/xfa/fxfa/cxfa_fflistbox.cpp @@ -56,7 +56,7 @@ bool CXFA_FFListBox::LoadWidget() { pListBox->AddString(label.AsStringView()); uint32_t dwExtendedStyle = FWL_STYLEEXT_LTB_ShowScrollBarFocus; - if (m_pDataAcc->GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) + if (m_pDataAcc->IsChoiceListMultiSelect()) dwExtendedStyle |= FWL_STYLEEXT_LTB_MultiSelection; dwExtendedStyle |= GetAlignment(); @@ -151,7 +151,7 @@ void CXFA_FFListBox::OnSelectChanged(CFWL_Widget* pWidget) { CXFA_EventParam eParam; eParam.m_eType = XFA_EVENT_Change; eParam.m_pTarget = m_pDataAcc.Get(); - m_pDataAcc->GetValue(eParam.m_wsPrevText, XFA_VALUEPICTURE_Raw); + eParam.m_wsPrevText = m_pDataAcc->GetValue(XFA_VALUEPICTURE_Raw); auto* pListBox = ToListBox(m_pNormalWidget.get()); int32_t iSels = pListBox->CountSelItems(); diff --git a/xfa/fxfa/cxfa_ffnumericedit.cpp b/xfa/fxfa/cxfa_ffnumericedit.cpp index 8f020351c2..197905c56b 100644 --- a/xfa/fxfa/cxfa_ffnumericedit.cpp +++ b/xfa/fxfa/cxfa_ffnumericedit.cpp @@ -35,9 +35,7 @@ bool CXFA_FFNumericEdit::LoadWidget() { m_pNormalWidget->SetDelegate(this); m_pNormalWidget->LockUpdate(); - WideString wsText; - m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); - pWidget->SetText(wsText); + pWidget->SetText(m_pDataAcc->GetValue(XFA_VALUEPICTURE_Display)); UpdateWidgetProperty(); m_pNormalWidget->UnlockUpdate(); return CXFA_FFField::LoadWidget(); @@ -52,13 +50,13 @@ void CXFA_FFNumericEdit::UpdateWidgetProperty() { FWL_STYLEEXT_EDT_ShowScrollbarFocus | FWL_STYLEEXT_EDT_OuterScrollbar | FWL_STYLEEXT_EDT_Validate | FWL_STYLEEXT_EDT_Number; dwExtendedStyle |= UpdateUIProperty(); - if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) + if (!m_pDataAcc->IsHorizontalScrollPolicyOff()) dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll; - int32_t iNumCells = m_pDataAcc->GetNumberOfCells(); - if (iNumCells > 0) { + pdfium::Optional<int32_t> numCells = m_pDataAcc->GetNumberOfCells(); + if (numCells && *numCells > 0) { dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText; - pWidget->SetLimit(iNumCells); + pWidget->SetLimit(*numCells); } dwExtendedStyle |= GetAlignment(); if (!m_pDataAcc->IsOpenAccess() || @@ -82,15 +80,10 @@ bool CXFA_FFNumericEdit::OnValidate(CFWL_Widget* pWidget, WideString& wsText) { if (!wsPattern.IsEmpty()) return true; - int32_t iLeads = 0; - m_pDataAcc->GetLeadDigits(iLeads); - - int32_t iFracs = 0; - m_pDataAcc->GetFracDigits(iFracs); - WideString wsFormat; CXFA_LocaleValue widgetValue = XFA_GetLocaleValue(m_pDataAcc.Get()); - widgetValue.GetNumericFormat(wsFormat, iLeads, iFracs); + widgetValue.GetNumericFormat(wsFormat, m_pDataAcc->GetLeadDigits(), + m_pDataAcc->GetFracDigits()); return widgetValue.ValidateNumericTemp(wsText, wsFormat, - m_pDataAcc->GetLocal()); + m_pDataAcc->GetLocale()); } diff --git a/xfa/fxfa/cxfa_ffpasswordedit.cpp b/xfa/fxfa/cxfa_ffpasswordedit.cpp index 8cbe265b7a..3bb2eb5b90 100644 --- a/xfa/fxfa/cxfa_ffpasswordedit.cpp +++ b/xfa/fxfa/cxfa_ffpasswordedit.cpp @@ -32,9 +32,7 @@ bool CXFA_FFPasswordEdit::LoadWidget() { m_pNormalWidget->SetDelegate(this); m_pNormalWidget->LockUpdate(); - WideString wsText; - m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); - pWidget->SetText(wsText); + pWidget->SetText(m_pDataAcc->GetValue(XFA_VALUEPICTURE_Display)); UpdateWidgetProperty(); m_pNormalWidget->UnlockUpdate(); return CXFA_FFField::LoadWidget(); @@ -50,11 +48,10 @@ void CXFA_FFPasswordEdit::UpdateWidgetProperty() { FWL_STYLEEXT_EDT_Password; dwExtendedStyle |= UpdateUIProperty(); - WideString wsPassWord; - m_pDataAcc->GetPasswordChar(wsPassWord); - if (!wsPassWord.IsEmpty()) - pWidget->SetAliasChar(wsPassWord[0]); - if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) + WideString password = m_pDataAcc->GetPasswordChar(); + if (!password.IsEmpty()) + pWidget->SetAliasChar(password[0]); + if (!m_pDataAcc->IsHorizontalScrollPolicyOff()) dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll; if (!m_pDataAcc->IsOpenAccess() || !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { diff --git a/xfa/fxfa/cxfa_ffpushbutton.cpp b/xfa/fxfa/cxfa_ffpushbutton.cpp index 9a799cd2ce..8745c7a1c1 100644 --- a/xfa/fxfa/cxfa_ffpushbutton.cpp +++ b/xfa/fxfa/cxfa_ffpushbutton.cpp @@ -134,14 +134,10 @@ FX_ARGB CXFA_FFPushButton::GetFillColor() { void CXFA_FFPushButton::LoadHighlightCaption() { CXFA_CaptionData captionData = m_pDataAcc->GetCaptionData(); - if (!captionData.HasValidNode() || - captionData.GetPresence() == XFA_ATTRIBUTEENUM_Hidden) { + if (!captionData.HasValidNode() || captionData.IsHidden()) return; - } - bool bRichText; - WideString wsRollover; - if (m_pDataAcc->GetButtonRollover(wsRollover, bRichText)) { + if (m_pDataAcc->HasButtonRollover()) { if (!m_pRollProvider) { m_pRollProvider = pdfium::MakeUnique<CXFA_TextProvider>( m_pDataAcc.Get(), XFA_TEXTPROVIDERTYPE_Rollover); @@ -149,8 +145,8 @@ void CXFA_FFPushButton::LoadHighlightCaption() { m_pRolloverTextLayout = pdfium::MakeUnique<CXFA_TextLayout>(m_pRollProvider.get()); } - WideString wsDown; - if (m_pDataAcc->GetButtonDown(wsDown, bRichText)) { + + if (m_pDataAcc->HasButtonDown()) { if (!m_pDownProvider) { m_pDownProvider = pdfium::MakeUnique<CXFA_TextProvider>( m_pDataAcc.Get(), XFA_TEXTPROVIDERTYPE_Down); @@ -173,10 +169,8 @@ void CXFA_FFPushButton::RenderHighlightCaption(CXFA_Graphics* pGS, CFX_Matrix* pMatrix) { CXFA_TextLayout* pCapTextLayout = m_pDataAcc->GetCaptionTextLayout(); CXFA_CaptionData captionData = m_pDataAcc->GetCaptionData(); - if (!captionData.HasValidNode() || - captionData.GetPresence() != XFA_ATTRIBUTEENUM_Visible) { + if (!captionData.HasValidNode() || !captionData.IsVisible()) return; - } CFX_RenderDevice* pRenderDevice = pGS->GetRenderDevice(); CFX_RectF rtClip = m_rtCaption; diff --git a/xfa/fxfa/cxfa_fftextedit.cpp b/xfa/fxfa/cxfa_fftextedit.cpp index abc8e9997c..5b9c3c2f8f 100644 --- a/xfa/fxfa/cxfa_fftextedit.cpp +++ b/xfa/fxfa/cxfa_fftextedit.cpp @@ -56,9 +56,7 @@ bool CXFA_FFTextEdit::LoadWidget() { m_pNormalWidget->LockUpdate(); UpdateWidgetProperty(); - WideString wsText; - m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); - pFWLEdit->SetText(wsText); + pFWLEdit->SetText(m_pDataAcc->GetValue(XFA_VALUEPICTURE_Display)); m_pNormalWidget->UnlockUpdate(); return CXFA_FFField::LoadWidget(); } @@ -74,11 +72,11 @@ void CXFA_FFTextEdit::UpdateWidgetProperty() { dwExtendedStyle |= UpdateUIProperty(); if (m_pDataAcc->IsMultiLine()) { dwExtendedStyle |= FWL_STYLEEXT_EDT_MultiLine | FWL_STYLEEXT_EDT_WantReturn; - if (m_pDataAcc->GetVerticalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) { + if (!m_pDataAcc->IsVerticalScrollPolicyOff()) { dwStyle |= FWL_WGTSTYLE_VScroll; dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoVScroll; } - } else if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) { + } else if (!m_pDataAcc->IsHorizontalScrollPolicyOff()) { dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll; } if (!m_pDataAcc->IsOpenAccess() || @@ -87,21 +85,23 @@ void CXFA_FFTextEdit::UpdateWidgetProperty() { dwExtendedStyle |= FWL_STYLEEXT_EDT_MultiLine; } - XFA_Element eType = XFA_Element::Unknown; - int32_t iMaxChars = m_pDataAcc->GetMaxChars(eType); + XFA_Element eType; + int32_t iMaxChars; + std::tie(eType, iMaxChars) = m_pDataAcc->GetMaxChars(); if (eType == XFA_Element::ExData) iMaxChars = 0; - int32_t iNumCells = m_pDataAcc->GetNumberOfCells(); - if (iNumCells == 0) { + pdfium::Optional<int32_t> numCells = m_pDataAcc->GetNumberOfCells(); + if (!numCells) { + pWidget->SetLimit(iMaxChars); + } else if (*numCells == 0) { dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText; pWidget->SetLimit(iMaxChars > 0 ? iMaxChars : 1); - } else if (iNumCells > 0) { - dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText; - pWidget->SetLimit(iNumCells); } else { - pWidget->SetLimit(iMaxChars); + dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText; + pWidget->SetLimit(*numCells); } + dwExtendedStyle |= GetAlignment(); m_pNormalWidget->ModifyStyles(dwStyle, 0xFFFFFFFF); m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); @@ -183,7 +183,7 @@ bool CXFA_FFTextEdit::OnKillFocus(CXFA_FFWidget* pNewWidget) { bool CXFA_FFTextEdit::CommitData() { WideString wsText = static_cast<CFWL_Edit*>(m_pNormalWidget.get())->GetText(); - if (m_pDataAcc->SetValue(wsText, XFA_VALUEPICTURE_Edit)) { + if (m_pDataAcc->SetValue(XFA_VALUEPICTURE_Edit, wsText)) { m_pDataAcc->UpdateUIDisplay(this); return true; } @@ -262,9 +262,10 @@ bool CXFA_FFTextEdit::UpdateFWLData() { bool bUpdate = false; if (m_pDataAcc->GetUIType() == XFA_Element::TextEdit && - m_pDataAcc->GetNumberOfCells() < 0) { - XFA_Element elementType = XFA_Element::Unknown; - int32_t iMaxChars = m_pDataAcc->GetMaxChars(elementType); + !m_pDataAcc->GetNumberOfCells()) { + XFA_Element elementType; + int32_t iMaxChars; + std::tie(elementType, iMaxChars) = m_pDataAcc->GetMaxChars(); if (elementType == XFA_Element::ExData) iMaxChars = eType == XFA_VALUEPICTURE_Edit ? iMaxChars : 0; if (pEdit->GetLimit() != iMaxChars) { @@ -274,14 +275,13 @@ bool CXFA_FFTextEdit::UpdateFWLData() { } else if (m_pDataAcc->GetUIType() == XFA_Element::Barcode) { int32_t nDataLen = 0; if (eType == XFA_VALUEPICTURE_Edit) - m_pDataAcc->GetBarcodeAttribute_DataLength(&nDataLen); + nDataLen = m_pDataAcc->GetBarcodeAttribute_DataLength().value_or(0); + pEdit->SetLimit(nDataLen); bUpdate = true; } - WideString wsText; - m_pDataAcc->GetValue(wsText, eType); - + WideString wsText = m_pDataAcc->GetValue(eType); WideString wsOldText = pEdit->GetText(); if (wsText != wsOldText || (eType == XFA_VALUEPICTURE_Edit && bUpdate)) { pEdit->SetText(wsText); diff --git a/xfa/fxfa/cxfa_textprovider.cpp b/xfa/fxfa/cxfa_textprovider.cpp index 876e0b1708..996ed00be0 100644 --- a/xfa/fxfa/cxfa_textprovider.cpp +++ b/xfa/fxfa/cxfa_textprovider.cpp @@ -164,6 +164,6 @@ bool CXFA_TextProvider::GetEmbbedObj(bool bURI, if (!pEmbAcc) return false; - pEmbAcc->GetValue(wsValue, XFA_VALUEPICTURE_Display); + wsValue = pEmbAcc->GetValue(XFA_VALUEPICTURE_Display); return true; } diff --git a/xfa/fxfa/cxfa_widgetacc.cpp b/xfa/fxfa/cxfa_widgetacc.cpp index 683c8a2619..f70b6b952c 100644 --- a/xfa/fxfa/cxfa_widgetacc.cpp +++ b/xfa/fxfa/cxfa_widgetacc.cpp @@ -98,10 +98,8 @@ class CXFA_FieldLayoutData : public CXFA_WidgetLayoutData { if (m_pCapTextLayout) return true; CXFA_CaptionData captionData = pAcc->GetCaptionData(); - if (!captionData.HasValidNode() || - captionData.GetPresence() == XFA_ATTRIBUTEENUM_Hidden) { + if (!captionData.HasValidNode() || captionData.IsHidden()) return false; - } m_pCapTextProvider = pdfium::MakeUnique<CXFA_TextProvider>( pAcc, XFA_TEXTPROVIDERTYPE_Caption); @@ -198,8 +196,8 @@ void CXFA_WidgetAcc::ResetData() { CXFA_ValueData defValueData = pAcc->GetDefaultValueData(); if (defValueData.HasValidNode()) { wsValue = defValueData.GetChildValueContent(); - SetValue(wsValue, XFA_VALUEPICTURE_Raw); - pAcc->SetValue(wsValue, XFA_VALUEPICTURE_Raw); + SetValue(XFA_VALUEPICTURE_Raw, wsValue); + pAcc->SetValue(XFA_VALUEPICTURE_Raw, wsValue); done = true; } } @@ -214,8 +212,7 @@ void CXFA_WidgetAcc::ResetData() { ->JSNode() ->GetContent(false); } - - pAcc->SetValue(itemText, XFA_VALUEPICTURE_Raw); + pAcc->SetValue(XFA_VALUEPICTURE_Raw, itemText); } pNextChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling, XFA_ObjectType::ContainerNode); @@ -229,7 +226,7 @@ void CXFA_WidgetAcc::ResetData() { if (defValueData.HasValidNode()) wsValue = defValueData.GetChildValueContent(); - SetValue(wsValue, XFA_VALUEPICTURE_Raw); + SetValue(XFA_VALUEPICTURE_Raw, wsValue); break; } } @@ -244,9 +241,8 @@ void CXFA_WidgetAcc::SetImageEdit(const WideString& wsContentType, imageData.SetHref(wsHref); } - WideString wsFormatValue(wsData); - GetFormatDataValue(wsData, wsFormatValue); - m_pNode->JSNode()->SetContent(wsData, wsFormatValue, true, false, true); + m_pNode->JSNode()->SetContent(wsData, GetFormatDataValue(wsData), true, false, + true); CXFA_Node* pBind = GetDatasets(); if (!pBind) { @@ -280,7 +276,7 @@ IXFA_AppProvider* CXFA_WidgetAcc::GetAppProvider() { return GetDoc()->GetApp()->GetAppProvider(); } -int32_t CXFA_WidgetAcc::ProcessEvent(int32_t iActivity, +int32_t CXFA_WidgetAcc::ProcessEvent(XFA_ATTRIBUTEENUM iActivity, CXFA_EventParam* pEventParam) { if (GetElementType() == XFA_Element::Draw) return XFA_EVENTERROR_NotExist; @@ -336,7 +332,7 @@ int32_t CXFA_WidgetAcc::ProcessCalculate() { return iRet; if (GetRawValue() != EventParam.m_wsResult) { - SetValue(EventParam.m_wsResult, XFA_VALUEPICTURE_Raw); + SetValue(XFA_VALUEPICTURE_Raw, EventParam.m_wsResult); UpdateUIDisplay(); } return XFA_EVENTERROR_Success; @@ -388,7 +384,7 @@ int32_t CXFA_WidgetAcc::ProcessFormatTestValidate( if (wsPicture.IsEmpty()) return XFA_EVENTERROR_NotExist; - IFX_Locale* pLocale = GetLocal(); + IFX_Locale* pLocale = GetLocale(); if (!pLocale) return XFA_EVENTERROR_NotExist; @@ -430,11 +426,9 @@ int32_t CXFA_WidgetAcc::ProcessFormatTestValidate( int32_t CXFA_WidgetAcc::ProcessNullTestValidate(CXFA_ValidateData validateData, int32_t iFlags, bool bVersionFlag) { - WideString wsValue; - GetValue(wsValue, XFA_VALUEPICTURE_Raw); - if (!wsValue.IsEmpty()) + if (!GetValue(XFA_VALUEPICTURE_Raw).IsEmpty()) return XFA_EVENTERROR_Success; - if (m_bIsNull && (m_bPreNull == m_bIsNull)) + if (IsNull() && IsPreNull()) return XFA_EVENTERROR_Success; XFA_ATTRIBUTEENUM eNullTest = validateData.GetNullTest(); @@ -633,7 +627,7 @@ std::pair<int32_t, bool> CXFA_WidgetAcc::ExecuteBoolScript( if (pEventParam->m_eType == XFA_EVENT_InitCalculate) { if ((iRet == XFA_EVENTERROR_Success) && (GetRawValue() != pEventParam->m_wsResult)) { - SetValue(pEventParam->m_wsResult, XFA_VALUEPICTURE_Raw); + SetValue(XFA_VALUEPICTURE_Raw, pEventParam->m_wsResult); m_pDocView->AddValidateWidget(this); } } @@ -680,14 +674,12 @@ void CXFA_WidgetAcc::UpdateUIDisplay(CXFA_FFWidget* pExcept) { void CXFA_WidgetAcc::CalcCaptionSize(CFX_SizeF& szCap) { CXFA_CaptionData captionData = GetCaptionData(); - if (!captionData.HasValidNode() || - captionData.GetPresence() != XFA_ATTRIBUTEENUM_Visible) { + if (!captionData.HasValidNode() || !captionData.IsVisible()) return; - } LoadCaption(); XFA_Element eUIType = GetUIType(); - int32_t iCapPlacement = captionData.GetPlacementType(); + XFA_ATTRIBUTEENUM iCapPlacement = captionData.GetPlacementType(); float fCapReserve = captionData.GetReserve(); const bool bVert = iCapPlacement == XFA_ATTRIBUTEENUM_Top || iCapPlacement == XFA_ATTRIBUTEENUM_Bottom; @@ -745,8 +737,7 @@ bool CXFA_WidgetAcc::CalculateFieldAutoSize(CFX_SizeF& size) { size.width += rtUIMargin.left + rtUIMargin.width; size.height += rtUIMargin.top + rtUIMargin.height; if (szCap.width > 0 && szCap.height > 0) { - int32_t iCapPlacement = GetCaptionData().GetPlacementType(); - switch (iCapPlacement) { + switch (GetCaptionData().GetPlacementType()) { case XFA_ATTRIBUTEENUM_Left: case XFA_ATTRIBUTEENUM_Right: case XFA_ATTRIBUTEENUM_Inline: { @@ -806,8 +797,7 @@ bool CXFA_WidgetAcc::CalculateWidgetAutoSize(CFX_SizeF& size) { void CXFA_WidgetAcc::CalculateTextContentSize(CFX_SizeF& size) { float fFontSize = GetFontSize(); - WideString wsText; - GetValue(wsText, XFA_VALUEPICTURE_Display); + WideString wsText = GetValue(XFA_VALUEPICTURE_Display); if (wsText.IsEmpty()) { size.height += fFontSize; return; @@ -844,7 +834,7 @@ bool CXFA_WidgetAcc::CalculateTextEditAutoSize(CFX_SizeF& size) { CFX_SizeF szCap; CalcCaptionSize(szCap); bool bCapExit = szCap.width > 0.01 && szCap.height > 0.01; - int32_t iCapPlacement = XFA_ATTRIBUTEENUM_Unknown; + XFA_ATTRIBUTEENUM iCapPlacement = XFA_ATTRIBUTEENUM_Unknown; if (bCapExit) { iCapPlacement = GetCaptionData().GetPlacementType(); switch (iCapPlacement) { @@ -1183,9 +1173,8 @@ bool CXFA_WidgetAcc::FindSplitPos(int32_t iBlockIndex, float& fCalcHeight) { float fCapReserve = 0; if (iBlockIndex == 0) { CXFA_CaptionData captionData = GetCaptionData(); - if (captionData.HasValidNode() && - captionData.GetPresence() != XFA_ATTRIBUTEENUM_Hidden) { - iCapPlacement = (XFA_ATTRIBUTEENUM)captionData.GetPlacementType(); + if (captionData.HasValidNode() && !captionData.IsHidden()) { + iCapPlacement = captionData.GetPlacementType(); fCapReserve = captionData.GetReserve(); } if (iCapPlacement == XFA_ATTRIBUTEENUM_Top && @@ -1205,9 +1194,7 @@ bool CXFA_WidgetAcc::FindSplitPos(int32_t iBlockIndex, float& fCalcHeight) { static_cast<CXFA_FieldLayoutData*>(m_pLayoutData.get()); int32_t iLinesCount = 0; float fHeight = m_pLayoutData->m_fWidgetHeight; - WideString wsText; - GetValue(wsText, XFA_VALUEPICTURE_Display); - if (wsText.IsEmpty()) { + if (GetValue(XFA_VALUEPICTURE_Display).IsEmpty()) { iLinesCount = 1; } else { if (!pFieldData->m_pTextOut) { diff --git a/xfa/fxfa/cxfa_widgetacc.h b/xfa/fxfa/cxfa_widgetacc.h index e12954c19e..8bef65a4bf 100644 --- a/xfa/fxfa/cxfa_widgetacc.h +++ b/xfa/fxfa/cxfa_widgetacc.h @@ -44,7 +44,8 @@ class CXFA_WidgetAcc : public CXFA_WidgetData { CXFA_FFDoc* GetDoc(); bool ProcessValueChanged(); - int32_t ProcessEvent(int32_t iActivity, CXFA_EventParam* pEventParam); + int32_t ProcessEvent(XFA_ATTRIBUTEENUM iActivity, + CXFA_EventParam* pEventParam); int32_t ProcessEvent(const CXFA_EventData& eventData, CXFA_EventParam* pEventParam); int32_t ProcessCalculate(); 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<CXFA_Measurement> measure = m_pNode->JSNode()->TryMeasure(XFA_Attribute::Rotate, false); if (!measure) @@ -274,8 +273,9 @@ std::vector<CXFA_Node*> CXFA_WidgetData::GetEventList() { return m_pNode->GetNodeList(0, XFA_Element::Event); } -std::vector<CXFA_Node*> CXFA_WidgetData::GetEventByActivity(int32_t iActivity, - bool bIsFormReady) { +std::vector<CXFA_Node*> CXFA_WidgetData::GetEventByActivity( + XFA_ATTRIBUTEENUM iActivity, + bool bIsFormReady) { std::vector<CXFA_Node*> 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<WideString> CXFA_WidgetData::GetChoiceListItem( + int32_t nIndex, + bool bSaveValue) { std::vector<CXFA_Node*> 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<WideString> CXFA_WidgetData::GetChoiceListItems(bool bSaveValue) { @@ -804,7 +806,7 @@ std::vector<int32_t> CXFA_WidgetData::GetSelectedItems() { std::vector<WideString> CXFA_WidgetData::GetSelectedItemsValue() { std::vector<WideString> 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<int32_t>& 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<int32_t>& 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<CXFA_Node*> 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<int32_t> 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<BC_CHAR_ENCODING> +CXFA_WidgetData::GetBarcodeAttribute_CharEncoding() { pdfium::Optional<WideString> 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<bool> CXFA_WidgetData::GetBarcodeAttribute_Checksum() { pdfium::Optional<XFA_ATTRIBUTEENUM> 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<int32_t> CXFA_WidgetData::GetBarcodeAttribute_DataLength() { pdfium::Optional<WideString> 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<char> CXFA_WidgetData::GetBarcodeAttribute_StartChar() { pdfium::Optional<WideString> wsStartEndChar = GetUIChild()->JSNode()->TryCData(XFA_Attribute::StartChar, true); if (!wsStartEndChar || wsStartEndChar->IsEmpty()) - return false; + return {}; - *val = static_cast<char>((*wsStartEndChar)[0]); - return true; + return {static_cast<char>((*wsStartEndChar)[0])}; } -bool CXFA_WidgetData::GetBarcodeAttribute_EndChar(char* val) { +pdfium::Optional<char> CXFA_WidgetData::GetBarcodeAttribute_EndChar() { pdfium::Optional<WideString> wsStartEndChar = GetUIChild()->JSNode()->TryCData(XFA_Attribute::EndChar, true); if (!wsStartEndChar || wsStartEndChar->IsEmpty()) - return false; + return {}; - *val = static_cast<char>((*wsStartEndChar)[0]); - return true; + return {static_cast<char>((*wsStartEndChar)[0])}; } -bool CXFA_WidgetData::GetBarcodeAttribute_ECLevel(int32_t* val) { +pdfium::Optional<int32_t> CXFA_WidgetData::GetBarcodeAttribute_ECLevel() { pdfium::Optional<WideString> 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<int32_t> CXFA_WidgetData::GetBarcodeAttribute_ModuleWidth() { pdfium::Optional<CXFA_Measurement> moduleWidthHeight = GetUIChild()->JSNode()->TryMeasure(XFA_Attribute::ModuleWidth, true); if (!moduleWidthHeight) - return false; + return {}; - *val = static_cast<int32_t>(moduleWidthHeight->ToUnit(XFA_Unit::Pt)); - return true; + return {static_cast<int32_t>(moduleWidthHeight->ToUnit(XFA_Unit::Pt))}; } -bool CXFA_WidgetData::GetBarcodeAttribute_ModuleHeight(int32_t* val) { +pdfium::Optional<int32_t> CXFA_WidgetData::GetBarcodeAttribute_ModuleHeight() { pdfium::Optional<CXFA_Measurement> moduleWidthHeight = GetUIChild()->JSNode()->TryMeasure(XFA_Attribute::ModuleHeight, true); if (!moduleWidthHeight) - return false; + return {}; - *val = static_cast<int32_t>(moduleWidthHeight->ToUnit(XFA_Unit::Pt)); - return true; + return {static_cast<int32_t>(moduleWidthHeight->ToUnit(XFA_Unit::Pt))}; } -bool CXFA_WidgetData::GetBarcodeAttribute_PrintChecksum(bool* val) { - pdfium::Optional<bool> printCheckDigit = - GetUIChild()->JSNode()->TryBoolean(XFA_Attribute::PrintCheckDigit, true); - if (printCheckDigit) { - *val = *printCheckDigit; - return true; - } - return false; +pdfium::Optional<bool> CXFA_WidgetData::GetBarcodeAttribute_PrintChecksum() { + return GetUIChild()->JSNode()->TryBoolean(XFA_Attribute::PrintCheckDigit, + true); } -bool CXFA_WidgetData::GetBarcodeAttribute_TextLocation(int32_t* val) { +pdfium::Optional<BC_TEXT_LOC> +CXFA_WidgetData::GetBarcodeAttribute_TextLocation() { pdfium::Optional<XFA_ATTRIBUTEENUM> 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<bool> truncate = - GetUIChild()->JSNode()->TryBoolean(XFA_Attribute::Truncate, true); - if (!truncate) - return false; - - *val = *truncate; - return true; +pdfium::Optional<bool> CXFA_WidgetData::GetBarcodeAttribute_Truncate() { + return GetUIChild()->JSNode()->TryBoolean(XFA_Attribute::Truncate, true); } -bool CXFA_WidgetData::GetBarcodeAttribute_WideNarrowRatio(float* val) { +pdfium::Optional<int8_t> +CXFA_WidgetData::GetBarcodeAttribute_WideNarrowRatio() { pdfium::Optional<WideString> wsWideNarrowRatio = GetUIChild()->JSNode()->TryCData(XFA_Attribute::WideNarrowRatio, true); if (!wsWideNarrowRatio) - return false; + return {}; pdfium::Optional<size_t> ptPos = wsWideNarrowRatio->Find(':'); - if (!ptPos) { - *val = static_cast<float>(FXSYS_wtoi(wsWideNarrowRatio->c_str())); - return true; - } + if (!ptPos) + return {static_cast<int8_t>(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<float>(fA) / static_cast<float>(fB); - return true; + float result = static_cast<float>(fA) / static_cast<float>(fB); + return {static_cast<int8_t>(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<XFA_Element, int32_t> 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<int32_t> 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<int32_t> 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 <utility> #include <vector> #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<CXFA_Node*> GetEventByActivity(int32_t iActivity, + std::vector<CXFA_Node*> GetEventByActivity(XFA_ATTRIBUTEENUM iActivity, bool bIsFormReady); pdfium::Optional<float> TryWidth(); @@ -78,10 +80,10 @@ class CXFA_WidgetData : public CXFA_DataData { pdfium::Optional<float> 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<WideString> GetChoiceListItem(int32_t nIndex, + bool bSaveValue); + bool IsChoiceListMultiSelect(); + bool IsChoiceListCommitOnSelect(); std::vector<WideString> 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<int32_t> 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<BC_CHAR_ENCODING> GetBarcodeAttribute_CharEncoding(); + pdfium::Optional<bool> GetBarcodeAttribute_Checksum(); + pdfium::Optional<int32_t> GetBarcodeAttribute_DataLength(); + pdfium::Optional<char> GetBarcodeAttribute_StartChar(); + pdfium::Optional<char> GetBarcodeAttribute_EndChar(); + pdfium::Optional<int32_t> GetBarcodeAttribute_ECLevel(); + pdfium::Optional<int32_t> GetBarcodeAttribute_ModuleWidth(); + pdfium::Optional<int32_t> GetBarcodeAttribute_ModuleHeight(); + pdfium::Optional<bool> GetBarcodeAttribute_PrintChecksum(); + pdfium::Optional<BC_TEXT_LOC> GetBarcodeAttribute_TextLocation(); + pdfium::Optional<bool> GetBarcodeAttribute_Truncate(); + pdfium::Optional<int8_t> GetBarcodeAttribute_WideNarrowRatio(); + + WideString GetPasswordChar(); + std::pair<XFA_Element, int32_t> 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<CXFA_Node*> 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<CFX_XMLElement*>(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<WideString> 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<CXFA_Node*> 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; |