diff options
author | thestig <thestig@chromium.org> | 2016-05-23 16:55:09 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-05-23 16:55:09 -0700 |
commit | db1a24e86d40977fb6d8aa8fa57dadee4c2f1be1 (patch) | |
tree | e55123ef697226a15ccbb87f36bb52f5833a285d | |
parent | 27ddf161579f79510b361d0016ccc7f0cdffdc6d (diff) | |
download | pdfium-db1a24e86d40977fb6d8aa8fa57dadee4c2f1be1.tar.xz |
Remove dead code from CPDF_InterForm.
Clean up related code.
Review-Url: https://codereview.chromium.org/2003853003
-rw-r--r-- | core/fpdfdoc/doc_form.cpp | 96 | ||||
-rw-r--r-- | core/fpdfdoc/doc_formcontrol.cpp | 80 | ||||
-rw-r--r-- | core/fpdfdoc/doc_formfield.cpp | 539 | ||||
-rw-r--r-- | core/fpdfdoc/include/fpdf_doc.h | 65 | ||||
-rw-r--r-- | fpdfsdk/fpdf_ext.cpp | 16 | ||||
-rw-r--r-- | fpdfsdk/fpdfformfill.cpp | 4 | ||||
-rw-r--r-- | fpdfsdk/fsdk_baseform.cpp | 6 | ||||
-rw-r--r-- | fpdfsdk/include/fsdk_baseform.h | 10 |
8 files changed, 354 insertions, 462 deletions
diff --git a/core/fpdfdoc/doc_form.cpp b/core/fpdfdoc/doc_form.cpp index 7c81f0ee6f..7357f0a2eb 100644 --- a/core/fpdfdoc/doc_form.cpp +++ b/core/fpdfdoc/doc_form.cpp @@ -260,14 +260,13 @@ CFieldTree::_Node* CFieldTree::FindNode(const CFX_WideString& full_name) { } return pNode; } -CPDF_InterForm::CPDF_InterForm(CPDF_Document* pDocument, FX_BOOL bGenerateAP) + +CPDF_InterForm::CPDF_InterForm(CPDF_Document* pDocument) : CFX_PrivateData(), m_pDocument(pDocument), - m_bGenerateAP(bGenerateAP), m_pFormDict(nullptr), m_pFieldTree(new CFieldTree), - m_pFormNotify(nullptr), - m_bUpdated(FALSE) { + m_pFormNotify(nullptr) { CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); if (!pRoot) return; @@ -732,47 +731,38 @@ CPDF_FormControl* CPDF_InterForm::GetControlByDict( return it != m_ControlMap.end() ? it->second : nullptr; } -FX_BOOL CPDF_InterForm::NeedConstructAP() { +FX_BOOL CPDF_InterForm::NeedConstructAP() const { return m_pFormDict && m_pFormDict->GetBooleanBy("NeedAppearances"); } -void CPDF_InterForm::NeedConstructAP(FX_BOOL bNeedAP) { - if (!m_pFormDict) { - InitInterFormDict(m_pFormDict, m_pDocument); - } - m_pFormDict->SetAtBoolean("NeedAppearances", bNeedAP); - m_bGenerateAP = bNeedAP; -} int CPDF_InterForm::CountFieldsInCalculationOrder() { - if (!m_pFormDict) { + if (!m_pFormDict) return 0; - } + CPDF_Array* pArray = m_pFormDict->GetArrayBy("CO"); return pArray ? pArray->GetCount() : 0; } CPDF_FormField* CPDF_InterForm::GetFieldInCalculationOrder(int index) { - if (!m_pFormDict || index < 0) { - return NULL; - } + if (!m_pFormDict || index < 0) + return nullptr; + CPDF_Array* pArray = m_pFormDict->GetArrayBy("CO"); - if (!pArray) { - return NULL; - } - if (CPDF_Dictionary* pElement = - ToDictionary(pArray->GetDirectObjectAt(index))) { - return GetFieldByDict(pElement); - } - return NULL; + if (!pArray) + return nullptr; + + CPDF_Dictionary* pElement = ToDictionary(pArray->GetDirectObjectAt(index)); + return pElement ? GetFieldByDict(pElement) : nullptr; } + int CPDF_InterForm::FindFieldInCalculationOrder(const CPDF_FormField* pField) { - if (!m_pFormDict || !pField) { + if (!m_pFormDict || !pField) return -1; - } + CPDF_Array* pArray = m_pFormDict->GetArrayBy("CO"); - if (!pArray) { + if (!pArray) return -1; - } + for (size_t i = 0; i < pArray->GetCount(); i++) { CPDF_Object* pElement = pArray->GetDirectObjectAt(i); if (pElement == pField->m_pDict) { @@ -781,9 +771,11 @@ int CPDF_InterForm::FindFieldInCalculationOrder(const CPDF_FormField* pField) { } return -1; } + uint32_t CPDF_InterForm::CountFormFonts() { return CountInterFormFonts(m_pFormDict); } + CPDF_Font* CPDF_InterForm::GetFormFont(uint32_t index, CFX_ByteString& csNameTag) { return GetInterFormFont(m_pFormDict, m_pDocument, index, csNameTag); @@ -815,23 +807,22 @@ FX_BOOL CPDF_InterForm::FindFormFont(CFX_ByteString csFontName, void CPDF_InterForm::AddFormFont(const CPDF_Font* pFont, CFX_ByteString& csNameTag) { AddInterFormFont(m_pFormDict, m_pDocument, pFont, csNameTag); - m_bUpdated = TRUE; } + CPDF_Font* CPDF_InterForm::AddNativeFormFont(uint8_t charSet, CFX_ByteString& csNameTag) { - m_bUpdated = TRUE; return AddNativeInterFormFont(m_pFormDict, m_pDocument, charSet, csNameTag); } + CPDF_Font* CPDF_InterForm::AddNativeFormFont(CFX_ByteString& csNameTag) { - m_bUpdated = TRUE; return AddNativeInterFormFont(m_pFormDict, m_pDocument, csNameTag); } + void CPDF_InterForm::RemoveFormFont(const CPDF_Font* pFont) { - m_bUpdated = TRUE; RemoveInterFormFont(m_pFormDict, pFont); } + void CPDF_InterForm::RemoveFormFont(CFX_ByteString csNameTag) { - m_bUpdated = TRUE; RemoveInterFormFont(m_pFormDict, csNameTag); } @@ -1171,42 +1162,37 @@ void CPDF_InterForm::FDF_ImportField(CPDF_Dictionary* pFieldDict, m_pFormNotify->AfterValueChange(pField); } } - if (CPDF_InterForm::m_bUpdateAP) { - pField->UpdateAP(NULL); - } } + FX_BOOL CPDF_InterForm::ImportFromFDF(const CFDF_Document* pFDF, FX_BOOL bNotify) { - if (!pFDF) { + if (!pFDF) return FALSE; - } + CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDictBy("FDF"); - if (!pMainDict) { + if (!pMainDict) return FALSE; - } + CPDF_Array* pFields = pMainDict->GetArrayBy("Fields"); - if (!pFields) { + if (!pFields) return FALSE; - } + m_bsEncoding = pMainDict->GetStringBy("Encoding"); - if (bNotify && m_pFormNotify) { - int iRet = m_pFormNotify->BeforeFormImportData(this); - if (iRet < 0) { - return FALSE; - } - } + if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormImportData(this) < 0) + return FALSE; + for (size_t i = 0; i < pFields->GetCount(); i++) { CPDF_Dictionary* pField = pFields->GetDictAt(i); - if (!pField) { + if (!pField) continue; - } + FDF_ImportField(pField, L"", bNotify); } - if (bNotify && m_pFormNotify) { + if (bNotify && m_pFormNotify) m_pFormNotify->AfterFormImportData(this); - } return TRUE; } -void CPDF_InterForm::SetFormNotify(const CPDF_FormNotify* pNotify) { - m_pFormNotify = (CPDF_FormNotify*)pNotify; + +void CPDF_InterForm::SetFormNotify(IPDF_FormNotify* pNotify) { + m_pFormNotify = pNotify; } diff --git a/core/fpdfdoc/doc_formcontrol.cpp b/core/fpdfdoc/doc_formcontrol.cpp index aa6cf986f1..9b3cf1e5de 100644 --- a/core/fpdfdoc/doc_formcontrol.cpp +++ b/core/fpdfdoc/doc_formcontrol.cpp @@ -13,34 +13,43 @@ #include "core/fpdfapi/fpdf_render/include/cpdf_rendercontext.h" #include "core/fpdfdoc/include/fpdf_doc.h" +namespace { + +const FX_CHAR* const g_sHighlightingMode[] = { + // Must match order of HighlightingMode enum. + "N", "I", "O", "P", "T"}; + +} // namespace + CPDF_FormControl::CPDF_FormControl(CPDF_FormField* pField, - CPDF_Dictionary* pWidgetDict) { - m_pField = pField; - m_pWidgetDict = pWidgetDict; - m_pForm = m_pField->m_pForm; -} + CPDF_Dictionary* pWidgetDict) + : m_pField(pField), + m_pWidgetDict(pWidgetDict), + m_pForm(m_pField->m_pForm) {} + CFX_FloatRect CPDF_FormControl::GetRect() const { return m_pWidgetDict->GetRectBy("Rect"); } + CFX_ByteString CPDF_FormControl::GetOnStateName() const { ASSERT(GetType() == CPDF_FormField::CheckBox || GetType() == CPDF_FormField::RadioButton); CFX_ByteString csOn; CPDF_Dictionary* pAP = m_pWidgetDict->GetDictBy("AP"); - if (!pAP) { + if (!pAP) return csOn; - } + CPDF_Dictionary* pN = pAP->GetDictBy("N"); - if (!pN) { + if (!pN) return csOn; - } + for (const auto& it : *pN) { - if (it.first != "Off") { + if (it.first != "Off") return it.first; - } } return CFX_ByteString(); } + void CPDF_FormControl::SetOnStateName(const CFX_ByteString& csOn) { ASSERT(GetType() == CPDF_FormField::CheckBox || GetType() == CPDF_FormField::RadioButton); @@ -99,7 +108,8 @@ CFX_ByteString CPDF_FormControl::GetCheckedAPState() { csOn = "Yes"; return csOn; } -CFX_WideString CPDF_FormControl::GetExportValue() { + +CFX_WideString CPDF_FormControl::GetExportValue() const { ASSERT(GetType() == CPDF_FormField::CheckBox || GetType() == CPDF_FormField::RadioButton); CFX_ByteString csOn = GetOnStateName(); @@ -111,11 +121,9 @@ CFX_WideString CPDF_FormControl::GetExportValue() { csOn = pArray->GetStringAt(iIndex); } } - if (csOn.IsEmpty()) { + if (csOn.IsEmpty()) csOn = "Yes"; - } - CFX_WideString csWOn = PDF_DecodeText(csOn); - return csWOn; + return PDF_DecodeText(csOn); } bool CPDF_FormControl::IsChecked() const { @@ -144,29 +152,25 @@ void CPDF_FormControl::CheckControl(FX_BOOL bChecked) { CFX_ByteString csOn = GetOnStateName(); CFX_ByteString csOldAS = m_pWidgetDict->GetStringBy("AS", "Off"); CFX_ByteString csAS = "Off"; - if (bChecked) { + if (bChecked) csAS = csOn; - } - if (csOldAS == csAS) { + if (csOldAS == csAS) return; - } m_pWidgetDict->SetAtName("AS", csAS); - m_pForm->m_bUpdated = TRUE; } -CPDF_Stream* FPDFDOC_GetAnnotAP(CPDF_Dictionary* pAnnotDict, - CPDF_Annot::AppearanceMode mode); + void CPDF_FormControl::DrawControl(CFX_RenderDevice* pDevice, CFX_Matrix* pMatrix, CPDF_Page* pPage, CPDF_Annot::AppearanceMode mode, const CPDF_RenderOptions* pOptions) { - if (m_pWidgetDict->GetIntegerBy("F") & ANNOTFLAG_HIDDEN) { + if (m_pWidgetDict->GetIntegerBy("F") & ANNOTFLAG_HIDDEN) return; - } + CPDF_Stream* pStream = FPDFDOC_GetAnnotAP(m_pWidgetDict, mode); - if (!pStream) { + if (!pStream) return; - } + CFX_FloatRect form_bbox = pStream->GetDict()->GetRectBy("BBox"); CFX_Matrix form_matrix = pStream->GetDict()->GetMatrixBy("Matrix"); form_matrix.TransformRect(form_bbox); @@ -181,15 +185,13 @@ void CPDF_FormControl::DrawControl(CFX_RenderDevice* pDevice, context.AppendLayer(&form, &matrix); context.Render(pDevice, pOptions, nullptr); } -static const FX_CHAR* const g_sHighlightingMode[] = { - // Must match order of HiglightingMode enum. - "N", "I", "O", "P", "T", nullptr}; + CPDF_FormControl::HighlightingMode CPDF_FormControl::GetHighlightingMode() { - if (!m_pWidgetDict) { + if (!m_pWidgetDict) return Invert; - } + CFX_ByteString csH = m_pWidgetDict->GetStringBy("H", "I"); - for (int i = 0; g_sHighlightingMode[i]; ++i) { + for (size_t i = 0; i < FX_ArraySize(g_sHighlightingMode); ++i) { if (csH == g_sHighlightingMode[i]) return static_cast<HighlightingMode>(i); } @@ -241,16 +243,16 @@ int CPDF_FormControl::GetTextPosition() { } CPDF_Action CPDF_FormControl::GetAction() { - if (!m_pWidgetDict) { + if (!m_pWidgetDict) return CPDF_Action(); - } - if (m_pWidgetDict->KeyExist("A")) { + + if (m_pWidgetDict->KeyExist("A")) return CPDF_Action(m_pWidgetDict->GetDictBy("A")); - } + CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "A"); - if (!pObj) { + if (!pObj) return CPDF_Action(); - } + return CPDF_Action(pObj->GetDict()); } diff --git a/core/fpdfdoc/doc_formfield.cpp b/core/fpdfdoc/doc_formfield.cpp index 9849fa1e35..310f0754bf 100644 --- a/core/fpdfdoc/doc_formfield.cpp +++ b/core/fpdfdoc/doc_formfield.cpp @@ -14,25 +14,28 @@ #include "core/fpdfdoc/doc_utils.h" #include "core/fpdfdoc/include/fpdf_doc.h" -FX_BOOL PDF_FormField_IsUnison(CPDF_FormField* pField) { - FX_BOOL bUnison = FALSE; - if (pField->GetType() == CPDF_FormField::CheckBox) { - bUnison = TRUE; - } else { - uint32_t dwFlags = pField->GetFieldFlags(); - bUnison = ((dwFlags & 0x2000000) != 0); - } - return bUnison; +namespace { + +bool PDF_FormField_IsUnison(CPDF_FormField* pField) { + if (pField->GetType() == CPDF_FormField::CheckBox) + return true; + + return (pField->GetFieldFlags() & 0x2000000) != 0; } -CPDF_FormField::CPDF_FormField(CPDF_InterForm* pForm, CPDF_Dictionary* pDict) { - m_pDict = pDict; - m_Type = Unknown; - m_pForm = pForm; - m_pFont = NULL; - m_FontSize = 0; + +} // namespace + +CPDF_FormField::CPDF_FormField(CPDF_InterForm* pForm, CPDF_Dictionary* pDict) + : m_Type(Unknown), + m_pForm(pForm), + m_pDict(pDict), + m_FontSize(0), + m_pFont(nullptr) { SyncFieldFlags(); } + CPDF_FormField::~CPDF_FormField() {} + void CPDF_FormField::SyncFieldFlags() { CFX_ByteString type_name = FPDF_GetFieldAttr(m_pDict, "FT") ? FPDF_GetFieldAttr(m_pDict, "FT")->GetString() @@ -105,6 +108,7 @@ void CPDF_FormField::SyncFieldFlags() { CFX_WideString CPDF_FormField::GetFullName() { return ::GetFullName(m_pDict); } + FX_BOOL CPDF_FormField::ResetField(FX_BOOL bNotify) { switch (m_Type) { case CPDF_FormField::CheckBox: @@ -127,41 +131,20 @@ FX_BOOL CPDF_FormField::ResetField(FX_BOOL bNotify) { m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); } } break; - case CPDF_FormField::ComboBox: { - CFX_WideString csValue; - ClearSelection(); - int iIndex = GetDefaultSelectedItem(); - if (iIndex >= 0) { - csValue = GetOptionLabel(iIndex); - } - if (bNotify && m_pForm->m_pFormNotify) { - int iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); - if (iRet < 0) { - return FALSE; - } - } - SetItemSelection(iIndex, TRUE); - if (bNotify && m_pForm->m_pFormNotify) { - m_pForm->m_pFormNotify->AfterValueChange(this); - } - } break; + case CPDF_FormField::ComboBox: case CPDF_FormField::ListBox: { CFX_WideString csValue; ClearSelection(); int iIndex = GetDefaultSelectedItem(); - if (iIndex >= 0) { + if (iIndex >= 0) csValue = GetOptionLabel(iIndex); - } - if (bNotify && m_pForm->m_pFormNotify) { - int iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); - if (iRet < 0) { - return FALSE; - } - } + + if (bNotify && !NotifyListOrComboBoxBeforeChange(csValue)) + return FALSE; + SetItemSelection(iIndex, TRUE); - if (bNotify && m_pForm->m_pFormNotify) { - m_pForm->m_pFormNotify->AfterSelectionChange(this); - } + if (bNotify) + NotifyListOrComboBoxAfterChange(); } break; case CPDF_FormField::Text: case CPDF_FormField::RichText: @@ -169,29 +152,26 @@ FX_BOOL CPDF_FormField::ResetField(FX_BOOL bNotify) { default: { CPDF_Object* pDV = FPDF_GetFieldAttr(m_pDict, "DV"); CFX_WideString csDValue; - if (pDV) { + if (pDV) csDValue = pDV->GetUnicodeText(); - } + CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V"); CFX_WideString csValue; - if (pV) { + if (pV) csValue = pV->GetUnicodeText(); - } + CPDF_Object* pRV = FPDF_GetFieldAttr(m_pDict, "RV"); - if (!pRV && (csDValue == csValue)) { + if (!pRV && (csDValue == csValue)) return FALSE; - } - if (bNotify && m_pForm->m_pFormNotify) { - int iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csDValue); - if (iRet < 0) { - return FALSE; - } - } + + if (bNotify && !NotifyBeforeValueChange(csDValue)) + return FALSE; + if (pDV) { CPDF_Object* pClone = pDV->Clone(); - if (!pClone) { + if (!pClone) return FALSE; - } + m_pDict->SetAt("V", pClone); if (pRV) { CPDF_Object* pCloneR = pDV->Clone(); @@ -201,18 +181,17 @@ FX_BOOL CPDF_FormField::ResetField(FX_BOOL bNotify) { m_pDict->RemoveAt("V"); m_pDict->RemoveAt("RV"); } - if (bNotify && m_pForm->m_pFormNotify) { - m_pForm->m_pFormNotify->AfterValueChange(this); - } - m_pForm->m_bUpdated = TRUE; + if (bNotify) + NotifyAfterValueChange(); } break; } return TRUE; } + int CPDF_FormField::GetControlIndex(const CPDF_FormControl* pControl) { - if (!pControl) { + if (!pControl) return -1; - } + for (int i = 0; i < m_ControlList.GetSize(); i++) { if (m_ControlList.GetAt(i) == pControl) return i; @@ -284,9 +263,9 @@ CFX_WideString CPDF_FormField::GetRichTextString() { return pObj->GetUnicodeText(); } CFX_WideString CPDF_FormField::GetValue(FX_BOOL bDefault) { - if (GetType() == CheckBox || GetType() == RadioButton) { + if (GetType() == CheckBox || GetType() == RadioButton) return GetCheckValue(bDefault); - } + CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, bDefault ? "DV" : "V"); if (!pValue) { if (!bDefault) { @@ -297,9 +276,8 @@ CFX_WideString CPDF_FormField::GetValue(FX_BOOL bDefault) { pValue = FPDF_GetFieldAttr(m_pDict, "DV"); } } - if (!pValue) { + if (!pValue) return CFX_WideString(); - } } switch (pValue->GetType()) { case CPDF_Object::STRING: @@ -315,12 +293,15 @@ CFX_WideString CPDF_FormField::GetValue(FX_BOOL bDefault) { } return CFX_WideString(); } + CFX_WideString CPDF_FormField::GetValue() { return GetValue(FALSE); } + CFX_WideString CPDF_FormField::GetDefaultValue() { return GetValue(TRUE); } + FX_BOOL CPDF_FormField::SetValue(const CFX_WideString& value, FX_BOOL bDefault, FX_BOOL bNotify) { @@ -335,70 +316,55 @@ FX_BOOL CPDF_FormField::SetValue(const CFX_WideString& value, case Text: case ComboBox: { CFX_WideString csValue = value; - if (bNotify && m_pForm->m_pFormNotify) { - int iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); - if (iRet < 0) { - return FALSE; - } - } + if (bNotify && !NotifyBeforeValueChange(csValue)) + return FALSE; + int iIndex = FindOptionValue(csValue); if (iIndex < 0) { CFX_ByteString bsEncodeText = PDF_EncodeText(csValue); m_pDict->SetAtString(bDefault ? "DV" : "V", bsEncodeText); - if (m_Type == RichText && !bDefault) { + if (m_Type == RichText && !bDefault) m_pDict->SetAtString("RV", bsEncodeText); - } m_pDict->RemoveAt("I"); } else { m_pDict->SetAtString(bDefault ? "DV" : "V", PDF_EncodeText(csValue)); - if (bDefault) { - } else { + if (!bDefault) { ClearSelection(); SetItemSelection(iIndex, TRUE); } } - if (bNotify && m_pForm->m_pFormNotify) { - m_pForm->m_pFormNotify->AfterValueChange(this); - } - m_pForm->m_bUpdated = TRUE; + if (bNotify) + NotifyAfterValueChange(); } break; case ListBox: { int iIndex = FindOptionValue(value); - if (iIndex < 0) { + if (iIndex < 0) return FALSE; - } - if (bDefault && iIndex == GetDefaultSelectedItem()) { + + if (bDefault && iIndex == GetDefaultSelectedItem()) return FALSE; - } - if (bNotify && m_pForm->m_pFormNotify) { - CFX_WideString csValue = value; - int iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); - if (iRet < 0) { - return FALSE; - } - } - if (bDefault) { - } else { + + if (bNotify && !NotifyBeforeSelectionChange(value)) + return FALSE; + + if (!bDefault) { ClearSelection(); SetItemSelection(iIndex, TRUE); } - if (bNotify && m_pForm->m_pFormNotify) { - m_pForm->m_pFormNotify->AfterSelectionChange(this); - } - m_pForm->m_bUpdated = TRUE; + if (bNotify) + NotifyAfterSelectionChange(); break; } default: break; } - if (CPDF_InterForm::m_bUpdateAP) { - UpdateAP(NULL); - } return TRUE; } + FX_BOOL CPDF_FormField::SetValue(const CFX_WideString& value, FX_BOOL bNotify) { return SetValue(value, FALSE, bNotify); } + int CPDF_FormField::GetMaxLen() { if (CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "MaxLen")) return pObj->GetInteger(); @@ -467,38 +433,21 @@ int CPDF_FormField::GetSelectedIndex(int index) { } return -1; } + FX_BOOL CPDF_FormField::ClearSelection(FX_BOOL bNotify) { if (bNotify && m_pForm->m_pFormNotify) { - int iRet = 0; CFX_WideString csValue; int iIndex = GetSelectedIndex(0); - if (iIndex >= 0) { + if (iIndex >= 0) csValue = GetOptionLabel(iIndex); - } - if (GetType() == ListBox) { - iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); - } - if (GetType() == ComboBox) { - iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); - } - if (iRet < 0) { + + if (!NotifyListOrComboBoxBeforeChange(csValue)) return FALSE; - } } m_pDict->RemoveAt("V"); m_pDict->RemoveAt("I"); - if (bNotify && m_pForm->m_pFormNotify) { - if (GetType() == ListBox) { - m_pForm->m_pFormNotify->AfterSelectionChange(this); - } - if (GetType() == ComboBox) { - m_pForm->m_pFormNotify->AfterValueChange(this); - } - } - if (CPDF_InterForm::m_bUpdateAP) { - UpdateAP(NULL); - } - m_pForm->m_bUpdated = TRUE; + if (bNotify) + NotifyListOrComboBoxAfterChange(); return TRUE; } @@ -551,31 +500,42 @@ FX_BOOL CPDF_FormField::SetItemSelection(int index, FX_BOOL bSelected, FX_BOOL bNotify) { ASSERT(GetType() == ComboBox || GetType() == ListBox); - if (index < 0 || index >= CountOptions()) { + if (index < 0 || index >= CountOptions()) return FALSE; - } + CFX_WideString opt_value = GetOptionValue(index); - if (bNotify && m_pForm->m_pFormNotify) { - int iRet = 0; + if (bNotify && !NotifyListOrComboBoxBeforeChange(opt_value)) + return FALSE; + + if (bSelected) { if (GetType() == ListBox) { - iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, opt_value); - } - if (GetType() == ComboBox) { - iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, opt_value); - } - if (iRet < 0) { - return FALSE; + SelectOption(index, TRUE); + if (!(m_Flags & FORMLIST_MULTISELECT)) { + m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); + } else { + CPDF_Array* pArray = new CPDF_Array; + for (int i = 0; i < CountOptions(); i++) { + if (i == index || IsItemSelected(i)) { + opt_value = GetOptionValue(i); + pArray->AddString(PDF_EncodeText(opt_value)); + } + } + m_pDict->SetAt("V", pArray); + } + } else { + m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); + CPDF_Array* pI = new CPDF_Array; + pI->AddInteger(index); + m_pDict->SetAt("I", pI); } - } - if (!bSelected) { + } else { CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); if (pValue) { - if (m_Type == ListBox) { + if (GetType() == ListBox) { SelectOption(index, FALSE); if (pValue->IsString()) { - if (pValue->GetUnicodeText() == opt_value) { + if (pValue->GetUnicodeText() == opt_value) m_pDict->RemoveAt("V"); - } } else if (pValue->IsArray()) { CPDF_Array* pArray = new CPDF_Array; for (int i = 0; i < CountOptions(); i++) { @@ -589,45 +549,14 @@ FX_BOOL CPDF_FormField::SetItemSelection(int index, else m_pDict->SetAt("V", pArray); } - } else if (m_Type == ComboBox) { + } else { m_pDict->RemoveAt("V"); m_pDict->RemoveAt("I"); } } - } else { - if (m_Type == ListBox) { - SelectOption(index, TRUE); - if (!(m_Flags & FORMLIST_MULTISELECT)) { - m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); - } else { - CPDF_Array* pArray = new CPDF_Array; - for (int i = 0; i < CountOptions(); i++) { - if (i == index || IsItemSelected(i)) { - opt_value = GetOptionValue(i); - pArray->AddString(PDF_EncodeText(opt_value)); - } - } - m_pDict->SetAt("V", pArray); - } - } else if (m_Type == ComboBox) { - m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); - CPDF_Array* pI = new CPDF_Array; - pI->AddInteger(index); - m_pDict->SetAt("I", pI); - } } - if (bNotify && m_pForm->m_pFormNotify) { - if (GetType() == ListBox) { - m_pForm->m_pFormNotify->AfterSelectionChange(this); - } - if (GetType() == ComboBox) { - m_pForm->m_pFormNotify->AfterValueChange(this); - } - } - if (CPDF_InterForm::m_bUpdateAP) { - UpdateAP(NULL); - } - m_pForm->m_bUpdated = TRUE; + if (bNotify) + NotifyListOrComboBoxAfterChange(); return TRUE; } @@ -654,17 +583,6 @@ int CPDF_FormField::GetDefaultSelectedItem() { return -1; } -void CPDF_FormField::UpdateAP(CPDF_FormControl* pControl) { - if (m_Type == PushButton || m_Type == RadioButton || m_Type == CheckBox) - return; - if (!m_pForm->m_bGenerateAP) - return; - for (int i = 0; i < CountControls(); i++) { - CPDF_FormControl* pControl = GetControl(i); - FPDF_GenerateAP(m_pForm->m_pDocument, pControl->m_pWidgetDict); - } -} - int CPDF_FormField::CountOptions() { CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "Opt")); return pArray ? pArray->GetCount() : 0; @@ -714,15 +632,8 @@ int CPDF_FormField::InsertOption(CFX_WideString csOptLabel, if (csOptLabel.IsEmpty()) return -1; - if (bNotify && m_pForm->m_pFormNotify) { - int iRet = 0; - if (GetType() == ListBox) - iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csOptLabel); - if (GetType() == ComboBox) - iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csOptLabel); - if (iRet < 0) - return -1; - } + if (bNotify && !NotifyListOrComboBoxBeforeChange(csOptLabel)) + return -1; CFX_ByteString csStr = PDF_EncodeText(csOptLabel.c_str(), csOptLabel.GetLength()); @@ -742,27 +653,18 @@ int CPDF_FormField::InsertOption(CFX_WideString csOptLabel, pOpt->InsertAt(index, pString); } - if (bNotify && m_pForm->m_pFormNotify) { - if (GetType() == ListBox) - m_pForm->m_pFormNotify->AfterSelectionChange(this); - if (GetType() == ComboBox) - m_pForm->m_pFormNotify->AfterValueChange(this); - } - m_pForm->m_bUpdated = TRUE; + if (bNotify) + NotifyListOrComboBoxAfterChange(); return index; } + FX_BOOL CPDF_FormField::ClearOptions(FX_BOOL bNotify) { if (bNotify && m_pForm->m_pFormNotify) { - int iRet = 0; CFX_WideString csValue; int iIndex = GetSelectedIndex(0); if (iIndex >= 0) csValue = GetOptionLabel(iIndex); - if (GetType() == ListBox) - iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); - if (GetType() == ComboBox) - iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); - if (iRet < 0) + if (!NotifyListOrComboBoxBeforeChange(csValue)) return FALSE; } @@ -772,17 +674,13 @@ FX_BOOL CPDF_FormField::ClearOptions(FX_BOOL bNotify) { m_pDict->RemoveAt("I"); m_pDict->RemoveAt("TI"); - if (bNotify && m_pForm->m_pFormNotify) { - if (GetType() == ListBox) - m_pForm->m_pFormNotify->AfterSelectionChange(this); - if (GetType() == ComboBox) - m_pForm->m_pFormNotify->AfterValueChange(this); - } + if (bNotify) + NotifyListOrComboBoxAfterChange(); - m_pForm->m_bUpdated = TRUE; return TRUE; } #endif // PDF_ENABLE_XFA + FX_BOOL CPDF_FormField::CheckControl(int iControlIndex, bool bChecked, bool bNotify) { @@ -797,7 +695,7 @@ FX_BOOL CPDF_FormField::CheckControl(int iControlIndex, CFX_WideString csWExport = pControl->GetExportValue(); CFX_ByteString csBExport = PDF_EncodeText(csWExport); int iCount = CountControls(); - FX_BOOL bUnison = PDF_FormField_IsUnison(this); + bool bUnison = PDF_FormField_IsUnison(this); for (int i = 0; i < iCount; i++) { CPDF_FormControl* pCtrl = GetControl(i); if (bUnison) { @@ -838,24 +736,19 @@ FX_BOOL CPDF_FormField::CheckControl(int iControlIndex, csIndex.Format("%d", iControlIndex); m_pDict->SetAtName("V", csIndex); } - if (bNotify && m_pForm->m_pFormNotify) { + if (bNotify && m_pForm->m_pFormNotify) m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); - } - m_pForm->m_bUpdated = TRUE; return TRUE; } + CFX_WideString CPDF_FormField::GetCheckValue(FX_BOOL bDefault) { ASSERT(GetType() == CheckBox || GetType() == RadioButton); CFX_WideString csExport = L"Off"; - FX_BOOL bChecked; int iCount = CountControls(); for (int i = 0; i < iCount; i++) { CPDF_FormControl* pControl = GetControl(i); - if (bDefault) { - bChecked = pControl->IsDefaultChecked(); - } else { - bChecked = pControl->IsChecked(); - } + FX_BOOL bChecked = + bDefault ? pControl->IsDefaultChecked() : pControl->IsChecked(); if (bChecked) { csExport = pControl->GetExportValue(); break; @@ -863,6 +756,7 @@ CFX_WideString CPDF_FormField::GetCheckValue(FX_BOOL bDefault) { } return csExport; } + FX_BOOL CPDF_FormField::SetCheckValue(const CFX_WideString& value, FX_BOOL bDefault, FX_BOOL bNotify) { @@ -871,23 +765,14 @@ FX_BOOL CPDF_FormField::SetCheckValue(const CFX_WideString& value, for (int i = 0; i < iCount; i++) { CPDF_FormControl* pControl = GetControl(i); CFX_WideString csExport = pControl->GetExportValue(); - if (csExport == value) { - if (bDefault) { - } else { - CheckControl(GetControlIndex(pControl), TRUE); - } + bool val = csExport == value; + if (!bDefault) + CheckControl(GetControlIndex(pControl), val); + if (val) break; - } else { - if (bDefault) { - } else { - CheckControl(GetControlIndex(pControl), FALSE); - } - } } - if (bNotify && m_pForm->m_pFormNotify) { + if (bNotify && m_pForm->m_pFormNotify) m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); - } - m_pForm->m_bUpdated = TRUE; return TRUE; } @@ -929,131 +814,153 @@ FX_BOOL CPDF_FormField::SelectOption(int iOptIndex, FX_BOOL bNotify) { CPDF_Array* pArray = m_pDict->GetArrayBy("I"); if (!pArray) { - if (!bSelected) { + if (!bSelected) return TRUE; - } + pArray = new CPDF_Array; m_pDict->SetAt("I", pArray); } + FX_BOOL bReturn = FALSE; for (size_t i = 0; i < pArray->GetCount(); i++) { int iFind = pArray->GetIntegerAt(i); if (iFind == iOptIndex) { - if (bSelected) { + if (bSelected) return TRUE; - } + if (bNotify && m_pForm->m_pFormNotify) { - int iRet = 0; CFX_WideString csValue = GetOptionLabel(iOptIndex); - if (GetType() == ListBox) { - iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); - } - if (GetType() == ComboBox) { - iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); - } - if (iRet < 0) { + if (!NotifyListOrComboBoxBeforeChange(csValue)) return FALSE; - } } pArray->RemoveAt(i); bReturn = TRUE; break; - } else if (iFind > iOptIndex) { - if (!bSelected) { + } + + if (iFind > iOptIndex) { + if (!bSelected) continue; - } + if (bNotify && m_pForm->m_pFormNotify) { - int iRet = 0; CFX_WideString csValue = GetOptionLabel(iOptIndex); - if (GetType() == ListBox) { - iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); - } - if (GetType() == ComboBox) { - iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); - } - if (iRet < 0) { + if (!NotifyListOrComboBoxBeforeChange(csValue)) return FALSE; - } } - CPDF_Number* pNum = new CPDF_Number(iOptIndex); - pArray->InsertAt(i, pNum); + pArray->InsertAt(i, new CPDF_Number(iOptIndex)); bReturn = TRUE; break; } } if (!bReturn) { - if (bSelected) { + if (bSelected) pArray->AddInteger(iOptIndex); - } - if (pArray->GetCount() == 0) { + + if (pArray->GetCount() == 0) m_pDict->RemoveAt("I"); - } } - if (bNotify && m_pForm->m_pFormNotify) { - if (GetType() == ListBox) { - m_pForm->m_pFormNotify->AfterSelectionChange(this); - } - if (GetType() == ComboBox) { - m_pForm->m_pFormNotify->AfterValueChange(this); - } - } - m_pForm->m_bUpdated = TRUE; + if (bNotify) + NotifyListOrComboBoxAfterChange(); + return TRUE; } + FX_BOOL CPDF_FormField::ClearSelectedOptions(FX_BOOL bNotify) { if (bNotify && m_pForm->m_pFormNotify) { - int iRet = 0; CFX_WideString csValue; int iIndex = GetSelectedIndex(0); - if (iIndex >= 0) { + if (iIndex >= 0) csValue = GetOptionLabel(iIndex); - } - if (GetType() == ListBox) { - iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); - } - if (GetType() == ComboBox) { - iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); - } - if (iRet < 0) { + + if (!NotifyListOrComboBoxBeforeChange(csValue)) return FALSE; - } } m_pDict->RemoveAt("I"); - if (bNotify && m_pForm->m_pFormNotify) { - if (GetType() == ListBox) { - m_pForm->m_pFormNotify->AfterSelectionChange(this); - } - if (GetType() == ComboBox) { - m_pForm->m_pFormNotify->AfterValueChange(this); - } - } - m_pForm->m_bUpdated = TRUE; + if (bNotify) + NotifyListOrComboBoxAfterChange(); + return TRUE; } + void CPDF_FormField::LoadDA() { + CPDF_Dictionary* pFormDict = m_pForm->m_pFormDict; + if (!pFormDict) + return; + CFX_ByteString DA; - if (CPDF_Object* pObj_t = FPDF_GetFieldAttr(m_pDict, "DA")) { - DA = pObj_t->GetString(); - } - if (DA.IsEmpty() && m_pForm->m_pFormDict) { - DA = m_pForm->m_pFormDict->GetStringBy("DA"); - } - if (DA.IsEmpty()) { + if (CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "DA")) + DA = pObj->GetString(); + + if (DA.IsEmpty()) + DA = pFormDict->GetStringBy("DA"); + + if (DA.IsEmpty()) return; - } + + CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); + if (!pDR) + return; + + CPDF_Dictionary* pFont = pDR->GetDictBy("Font"); + if (!pFont) + return; + CPDF_SimpleParser syntax(DA.AsStringC()); syntax.FindTagParamFromStart("Tf", 2); CFX_ByteString font_name(syntax.GetWord()); - CPDF_Dictionary* pFontDict = NULL; - if (m_pForm->m_pFormDict && m_pForm->m_pFormDict->GetDictBy("DR") && - m_pForm->m_pFormDict->GetDictBy("DR")->GetDictBy("Font")) { - pFontDict = m_pForm->m_pFormDict->GetDictBy("DR") - ->GetDictBy("Font") - ->GetDictBy(font_name); - } - if (!pFontDict) { + CPDF_Dictionary* pFontDict = pFont->GetDictBy(font_name); + if (!pFontDict) return; - } + m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict); m_FontSize = FX_atof(syntax.GetWord()); } + +bool CPDF_FormField::NotifyBeforeSelectionChange(const CFX_WideString& value) { + if (!m_pForm->m_pFormNotify) + return true; + return m_pForm->m_pFormNotify->BeforeSelectionChange(this, value) >= 0; +} + +void CPDF_FormField::NotifyAfterSelectionChange() { + if (!m_pForm->m_pFormNotify) + return; + m_pForm->m_pFormNotify->AfterSelectionChange(this); +} + +bool CPDF_FormField::NotifyBeforeValueChange(const CFX_WideString& value) { + if (!m_pForm->m_pFormNotify) + return true; + return m_pForm->m_pFormNotify->BeforeValueChange(this, value) >= 0; +} + +void CPDF_FormField::NotifyAfterValueChange() { + if (!m_pForm->m_pFormNotify) + return; + m_pForm->m_pFormNotify->AfterValueChange(this); +} + +bool CPDF_FormField::NotifyListOrComboBoxBeforeChange( + const CFX_WideString& value) { + switch (GetType()) { + case ListBox: + return NotifyBeforeSelectionChange(value); + case ComboBox: + return NotifyBeforeValueChange(value); + default: + return true; + } +} + +void CPDF_FormField::NotifyListOrComboBoxAfterChange() { + switch (GetType()) { + case ListBox: + NotifyAfterSelectionChange(); + break; + case ComboBox: + NotifyAfterValueChange(); + break; + default: + break; + } +} diff --git a/core/fpdfdoc/include/fpdf_doc.h b/core/fpdfdoc/include/fpdf_doc.h index cb751915d4..4fc5b5232b 100644 --- a/core/fpdfdoc/include/fpdf_doc.h +++ b/core/fpdfdoc/include/fpdf_doc.h @@ -18,6 +18,7 @@ class CFDF_Document; class CFieldTree; +class CFX_RenderDevice; class CPDF_AAction; class CPDF_Action; class CPDF_ActionFields; @@ -28,26 +29,24 @@ class CPDF_Bookmark; class CPDF_BookmarkTree; class CPDF_DefaultAppearance; class CPDF_Dest; -class CPDF_Document; class CPDF_DocJSActions; +class CPDF_Document; class CPDF_FileSpec; +class CPDF_Font; +class CPDF_Form; class CPDF_FormControl; class CPDF_FormField; -class CPDF_FormNotify; class CPDF_IconFit; -class CPDF_InterForm; class CPDF_Link; class CPDF_Metadata; class CPDF_OCContext; class CPDF_Page; class CPDF_PageObject; -class CPDF_Font; -class CPDF_Form; -class CPDF_RenderOptions; class CPDF_RenderContext; +class CPDF_RenderOptions; class CPDF_ViewerPreferences; class CXML_Element; -class CFX_RenderDevice; +class IPDF_FormNotify; enum class BorderStyle { SOLID, DASH, BEVELED, INSET, UNDERLINE }; @@ -445,9 +444,10 @@ class CPDF_DefaultAppearance { #define FIELDTYPE_LISTBOX 5 #define FIELDTYPE_TEXTFIELD 6 #define FIELDTYPE_SIGNATURE 7 + class CPDF_InterForm : public CFX_PrivateData { public: - CPDF_InterForm(CPDF_Document* pDocument, FX_BOOL bUpdateAP); + explicit CPDF_InterForm(CPDF_Document* pDocument); ~CPDF_InterForm(); static void EnableUpdateAP(FX_BOOL bUpdateAP); @@ -499,9 +499,7 @@ class CPDF_InterForm : public CFX_PrivateData { CPDF_Dictionary* GetFormDict() const { return m_pFormDict; } - FX_BOOL NeedConstructAP(); - - void NeedConstructAP(FX_BOOL bNeedAP); + FX_BOOL NeedConstructAP() const; int CountFieldsInCalculationOrder(); @@ -569,13 +567,7 @@ class CPDF_InterForm : public CFX_PrivateData { bool ResetForm(bool bNotify = false); - CPDF_FormNotify* GetFormNotify() const { return m_pFormNotify; } - - void SetFormNotify(const CPDF_FormNotify* pNotify); - - FX_BOOL IsUpdated() { return m_bUpdated; } - - void ClearUpdatedFlag() { m_bUpdated = FALSE; } + void SetFormNotify(IPDF_FormNotify* pNotify); FX_BOOL HasXFAForm() const; @@ -611,8 +603,6 @@ class CPDF_InterForm : public CFX_PrivateData { CPDF_Document* const m_pDocument; - FX_BOOL m_bGenerateAP; - CPDF_Dictionary* m_pFormDict; std::map<const CPDF_Dictionary*, CPDF_FormControl*> m_ControlMap; @@ -621,9 +611,8 @@ class CPDF_InterForm : public CFX_PrivateData { CFX_ByteString m_bsEncoding; - CPDF_FormNotify* m_pFormNotify; + IPDF_FormNotify* m_pFormNotify; - FX_BOOL m_bUpdated; friend class CPDF_FormControl; friend class CPDF_FormField; }; @@ -664,9 +653,11 @@ class CPDF_FormField { FX_BOOL ResetField(FX_BOOL bNotify = FALSE); - int CountControls() { return m_ControlList.GetSize(); } + int CountControls() const { return m_ControlList.GetSize(); } - CPDF_FormControl* GetControl(int index) { return m_ControlList.GetAt(index); } + CPDF_FormControl* GetControl(int index) const { + return m_ControlList.GetAt(index); + } int GetControlIndex(const CPDF_FormControl* pControl); @@ -764,14 +755,21 @@ class CPDF_FormField { void LoadDA(); - void UpdateAP(CPDF_FormControl* pControl); - CFX_WideString GetCheckValue(FX_BOOL bDefault); FX_BOOL SetCheckValue(const CFX_WideString& value, FX_BOOL bDefault, FX_BOOL bNotify); + bool NotifyBeforeSelectionChange(const CFX_WideString& value); + void NotifyAfterSelectionChange(); + + bool NotifyBeforeValueChange(const CFX_WideString& value); + void NotifyAfterValueChange(); + + bool NotifyListOrComboBoxBeforeChange(const CFX_WideString& value); + void NotifyListOrComboBoxAfterChange(); + CPDF_FormField::Type m_Type; uint32_t m_Flags; CPDF_InterForm* m_pForm; @@ -828,7 +826,7 @@ class CPDF_FormControl { const CPDF_RenderOptions* pOptions = nullptr); CFX_ByteString GetCheckedAPState(); - CFX_WideString GetExportValue(); + CFX_WideString GetExportValue() const; bool IsChecked() const; bool IsDefaultChecked() const; @@ -894,17 +892,17 @@ class CPDF_FormControl { CPDF_Stream* GetIcon(const CFX_ByteString& csEntry); CPDF_ApSettings GetMK() const; - CPDF_InterForm* m_pForm; - CPDF_FormField* m_pField; - CPDF_Dictionary* m_pWidgetDict; + CPDF_FormField* const m_pField; + CPDF_Dictionary* const m_pWidgetDict; + CPDF_InterForm* const m_pForm; friend class CPDF_InterForm; friend class CPDF_FormField; }; -class CPDF_FormNotify { +class IPDF_FormNotify { public: - virtual ~CPDF_FormNotify() {} + virtual ~IPDF_FormNotify() {} virtual int BeforeValueChange(CPDF_FormField* pField, const CFX_WideString& csValue) { @@ -1016,4 +1014,7 @@ class CPDF_ApSettings { CPDF_Dictionary* const m_pDict; }; +CPDF_Stream* FPDFDOC_GetAnnotAP(CPDF_Dictionary* pAnnotDict, + CPDF_Annot::AppearanceMode mode); + #endif // CORE_FPDFDOC_INCLUDE_FPDF_DOC_H_ diff --git a/fpdfsdk/fpdf_ext.cpp b/fpdfsdk/fpdf_ext.cpp index 9bb54da594..350945e328 100644 --- a/fpdfsdk/fpdf_ext.cpp +++ b/fpdfsdk/fpdf_ext.cpp @@ -6,6 +6,8 @@ #include "public/fpdf_ext.h" +#include <memory> + #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" #include "core/fpdfapi/include/cpdf_modulemgr.h" @@ -20,13 +22,13 @@ class CFSDK_UnsupportInfo_Adapter { public: - CFSDK_UnsupportInfo_Adapter(UNSUPPORT_INFO* unsp_info) { - m_unsp_info = unsp_info; - } + explicit CFSDK_UnsupportInfo_Adapter(UNSUPPORT_INFO* unsp_info) + : m_unsp_info(unsp_info) {} + void ReportError(int nErrorType); private: - UNSUPPORT_INFO* m_unsp_info; + UNSUPPORT_INFO* const m_unsp_info; }; void CFSDK_UnsupportInfo_Adapter::ReportError(int nErrorType) { @@ -183,11 +185,9 @@ void CheckUnSupportError(CPDF_Document* pDoc, uint32_t err_code) { #ifndef PDF_ENABLE_XFA // XFA Forms - CPDF_InterForm* pInterForm = new CPDF_InterForm(pDoc, FALSE); - if (pInterForm->HasXFAForm()) { + CPDF_InterForm interform(pDoc); + if (interform.HasXFAForm()) FPDF_UnSupportError(FPDF_UNSP_DOC_XFAFORM); - } - delete pInterForm; #endif // PDF_ENABLE_XFA } diff --git a/fpdfsdk/fpdfformfill.cpp b/fpdfsdk/fpdfformfill.cpp index 438150974d..81c5dd7a12 100644 --- a/fpdfsdk/fpdfformfill.cpp +++ b/fpdfsdk/fpdfformfill.cpp @@ -64,7 +64,7 @@ DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, return -1; CPDF_Page* pPage = CPDFPageFromFPDFPage(page); if (pPage) { - CPDF_InterForm interform(pPage->m_pDocument, FALSE); + CPDF_InterForm interform(pPage->m_pDocument); CPDF_FormControl* pFormCtrl = interform.GetControlAtPoint(pPage, static_cast<FX_FLOAT>(page_x), static_cast<FX_FLOAT>(page_y), nullptr); @@ -134,7 +134,7 @@ DLLEXPORT int STDCALL FPDFPage_FormFieldZOrderAtPoint(FPDF_FORMHANDLE hHandle, CPDF_Page* pPage = CPDFPageFromFPDFPage(page); if (!pPage) return -1; - CPDF_InterForm interform(pPage->m_pDocument, FALSE); + CPDF_InterForm interform(pPage->m_pDocument); int z_order = -1; (void)interform.GetControlAtPoint(pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y, &z_order); diff --git a/fpdfsdk/fsdk_baseform.cpp b/fpdfsdk/fsdk_baseform.cpp index 4e5c9f0065..dbef4a9b67 100644 --- a/fpdfsdk/fsdk_baseform.cpp +++ b/fpdfsdk/fsdk_baseform.cpp @@ -1967,24 +1967,20 @@ CFX_FloatRect CPDFSDK_XFAWidget::GetRect() const { CPDFSDK_InterForm::CPDFSDK_InterForm(CPDFSDK_Document* pDocument) : m_pDocument(pDocument), - m_pInterForm(NULL), + m_pInterForm(new CPDF_InterForm(m_pDocument->GetPDFDocument())), #ifdef PDF_ENABLE_XFA m_bXfaCalculate(TRUE), m_bXfaValidationsEnabled(TRUE), #endif // PDF_ENABLE_XFA m_bCalculate(TRUE), m_bBusy(FALSE) { - m_pInterForm = new CPDF_InterForm(m_pDocument->GetPDFDocument(), FALSE); m_pInterForm->SetFormNotify(this); - for (int i = 0; i < kNumFieldTypes; ++i) m_bNeedHightlight[i] = FALSE; m_iHighlightAlpha = 0; } CPDFSDK_InterForm::~CPDFSDK_InterForm() { - delete m_pInterForm; - m_pInterForm = nullptr; m_Map.clear(); #ifdef PDF_ENABLE_XFA m_XFAMap.clear(); diff --git a/fpdfsdk/include/fsdk_baseform.h b/fpdfsdk/include/fsdk_baseform.h index fa19c75a6b..5e00e16402 100644 --- a/fpdfsdk/include/fsdk_baseform.h +++ b/fpdfsdk/include/fsdk_baseform.h @@ -212,7 +212,7 @@ class CPDFSDK_Widget : public CPDFSDK_BAAnnot { FX_BOOL HitTest(FX_FLOAT pageX, FX_FLOAT pageY); private: - CPDFSDK_InterForm* m_pInterForm; + CPDFSDK_InterForm* const m_pInterForm; FX_BOOL m_bAppModified; int32_t m_nAppAge; int32_t m_nValueAge; @@ -245,12 +245,12 @@ class CPDFSDK_XFAWidget : public CPDFSDK_Annot { }; #endif // PDF_ENABLE_XFA -class CPDFSDK_InterForm : public CPDF_FormNotify { +class CPDFSDK_InterForm : public IPDF_FormNotify { public: explicit CPDFSDK_InterForm(CPDFSDK_Document* pDocument); ~CPDFSDK_InterForm() override; - CPDF_InterForm* GetInterForm() const { return m_pInterForm; } + CPDF_InterForm* GetInterForm() const { return m_pInterForm.get(); } CPDFSDK_Document* GetDocument() const { return m_pDocument; } FX_BOOL HighlightWidgets(); @@ -313,7 +313,7 @@ class CPDFSDK_InterForm : public CPDF_FormNotify { #endif // PDF_ENABLE_XFA private: - // CPDF_FormNotify: + // IPDF_FormNotify: int BeforeValueChange(CPDF_FormField* pField, const CFX_WideString& csValue) override; void AfterValueChange(CPDF_FormField* pField) override; @@ -335,7 +335,7 @@ class CPDFSDK_InterForm : public CPDF_FormNotify { using CPDFSDK_WidgetMap = std::map<CPDF_FormControl*, CPDFSDK_Widget*>; CPDFSDK_Document* m_pDocument; - CPDF_InterForm* m_pInterForm; + std::unique_ptr<CPDF_InterForm> m_pInterForm; CPDFSDK_WidgetMap m_Map; #ifdef PDF_ENABLE_XFA std::map<CXFA_FFWidget*, CPDFSDK_XFAWidget*> m_XFAMap; |