From 606346f584700bdae0741066f2e6d2481744032c Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Fri, 19 Jun 2015 18:11:07 -0700 Subject: Merge to XFA: Replace some CFX_MapPtrTemplates with std::map. There are more CFX_MapPtrTemplate usage on the XFA branch, so it is not removed. R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1181593003. (cherry picked from commit e8d3691c82d1be805ffdce3329d00313af7ce0ab) Review URL: https://codereview.chromium.org/1198663004. --- fpdfsdk/src/formfiller/FFL_FormFiller.cpp | 106 ++++++++++++----------------- fpdfsdk/src/formfiller/FFL_IFormFiller.cpp | 106 +++++++++++++---------------- fpdfsdk/src/formfiller/FFL_ListBox.cpp | 52 ++++++-------- 3 files changed, 111 insertions(+), 153 deletions(-) (limited to 'fpdfsdk/src/formfiller') diff --git a/fpdfsdk/src/formfiller/FFL_FormFiller.cpp b/fpdfsdk/src/formfiller/FFL_FormFiller.cpp index 540619692b..7a70493d4c 100644 --- a/fpdfsdk/src/formfiller/FFL_FormFiller.cpp +++ b/fpdfsdk/src/formfiller/FFL_FormFiller.cpp @@ -28,23 +28,14 @@ CFFL_FormFiller::CFFL_FormFiller(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnno CFFL_FormFiller::~CFFL_FormFiller() { - FX_POSITION pos = m_Maps.GetStartPosition(); - while (pos) - { - CPDFSDK_PageView * pPageView = NULL; - CPWL_Wnd* pWnd = NULL; - m_Maps.GetNextAssoc(pos, pPageView, pWnd); - - if (pWnd) - { - CFFL_PrivateData* pData = (CFFL_PrivateData*)pWnd->GetAttachedData(); - pWnd->Destroy(); - delete pWnd; - delete pData; - } - } - m_Maps.RemoveAll(); - + for (auto& it : m_Maps) { + CPWL_Wnd* pWnd = it.second; + CFFL_PrivateData* pData = (CFFL_PrivateData*)pWnd->GetAttachedData(); + pWnd->Destroy(); + delete pWnd; + delete pData; + } + m_Maps.clear(); } void CFFL_FormFiller::SetWindowRect(CPDFSDK_PageView* pPageView, const CPDF_Rect& rcWindow) @@ -430,64 +421,53 @@ PWL_CREATEPARAM CFFL_FormFiller::GetCreateParam() CPWL_Wnd* CFFL_FormFiller::GetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bNew) { - ASSERT(pPageView != NULL); - ASSERT(m_pWidget != NULL); + ASSERT(pPageView); - CPWL_Wnd* pWnd = NULL; - m_Maps.Lookup(pPageView, pWnd); + auto it = m_Maps.find(pPageView); + const bool found = it != m_Maps.end(); + CPWL_Wnd* pWnd = found ? it->second : nullptr; + if (!bNew) + return pWnd; - if (bNew) - { - if (pWnd) - { - CFFL_PrivateData* pPrivateData = (CFFL_PrivateData*)pWnd->GetAttachedData(); - ASSERT(pPrivateData != NULL); + if (found) { + CFFL_PrivateData* pPrivateData = + (CFFL_PrivateData*)pWnd->GetAttachedData(); + if (pPrivateData->nWidgetAge != m_pWidget->GetAppearanceAge()) { + return ResetPDFWindow( + pPageView, m_pWidget->GetValueAge() == pPrivateData->nValueAge); + } + } else { + PWL_CREATEPARAM cp = GetCreateParam(); + cp.hAttachedWnd = (FX_HWND)m_pWidget; - if (pPrivateData->nWidgetAge != m_pWidget->GetAppearanceAge()) - { - return ResetPDFWindow(pPageView, m_pWidget->GetValueAge() == pPrivateData->nValueAge); - } - } - else - { - PWL_CREATEPARAM cp = GetCreateParam(); - cp.hAttachedWnd = (FX_HWND)m_pWidget; + CFFL_PrivateData* pPrivateData = new CFFL_PrivateData; + pPrivateData->pWidget = m_pWidget; + pPrivateData->pPageView = pPageView; + pPrivateData->nWidgetAge = m_pWidget->GetAppearanceAge(); + pPrivateData->nValueAge = 0; - CFFL_PrivateData* pPrivateData = new CFFL_PrivateData; - pPrivateData->pWidget = m_pWidget; - pPrivateData->pPageView = pPageView; - pPrivateData->nWidgetAge = m_pWidget->GetAppearanceAge(); - pPrivateData->nValueAge = 0; + cp.pAttachedData = pPrivateData; - cp.pAttachedData = pPrivateData; + pWnd = NewPDFWindow(cp, pPageView); + m_Maps[pPageView] = pWnd; + } - pWnd = NewPDFWindow(cp, pPageView); - - if (pWnd) - { - m_Maps.SetAt(pPageView, pWnd); - } - } - } - - return pWnd; + return pWnd; } void CFFL_FormFiller::DestroyPDFWindow(CPDFSDK_PageView* pPageView) { - CPWL_Wnd* pWnd = NULL; - m_Maps.Lookup(pPageView, pWnd); + auto it = m_Maps.find(pPageView); + if (it == m_Maps.end()) + return; - if (pWnd) - { - CFFL_PrivateData* pData = (CFFL_PrivateData*)pWnd->GetAttachedData(); - pData->pPageView = NULL; - pWnd->Destroy(); - delete pWnd; - delete pData; - } + CPWL_Wnd* pWnd = it->second; + CFFL_PrivateData* pData = (CFFL_PrivateData*)pWnd->GetAttachedData(); + pWnd->Destroy(); + delete pWnd; + delete pData; - m_Maps.RemoveKey(pPageView); + m_Maps.erase(it); } CPDF_Matrix CFFL_FormFiller::GetWindowMatrix(void* pAttachedData) diff --git a/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp b/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp index d4ca0235b3..66ae237a31 100644 --- a/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp +++ b/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp @@ -28,15 +28,9 @@ CFFL_IFormFiller::CFFL_IFormFiller(CPDFDoc_Environment* pApp) : CFFL_IFormFiller::~CFFL_IFormFiller() { - FX_POSITION pos = m_Maps.GetStartPosition(); - while (pos) - { - CPDFSDK_Annot * pAnnot = NULL; - CFFL_FormFiller * pFormFiller = NULL; - m_Maps.GetNextAssoc(pos,pAnnot,pFormFiller); - delete pFormFiller; - } - m_Maps.RemoveAll(); + for (auto& it : m_Maps) + delete it.second; + m_Maps.clear(); } FX_BOOL CFFL_IFormFiller::Annot_HitTest(CPDFSDK_PageView* pPageView,CPDFSDK_Annot* pAnnot, CPDF_Point point) @@ -648,53 +642,46 @@ FX_BOOL CFFL_IFormFiller::IsFillingAllowed(CPDFSDK_Widget* pWidget) CFFL_FormFiller* CFFL_IFormFiller::GetFormFiller(CPDFSDK_Annot* pAnnot, FX_BOOL bRegister) { -// ASSERT(pAnnot != NULL); -// ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget"); - - CFFL_FormFiller * pFormFiller = NULL; - m_Maps.Lookup(pAnnot, pFormFiller); - - if (pFormFiller) - return pFormFiller; - - if (bRegister) - { - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - - int nFieldType = pWidget->GetFieldType(); - switch(nFieldType) - { - case FIELDTYPE_PUSHBUTTON: - pFormFiller = new CFFL_PushButton(m_pApp, pWidget); - break; - case FIELDTYPE_CHECKBOX: - pFormFiller = new CFFL_CheckBox(m_pApp, pWidget); - break; - case FIELDTYPE_RADIOBUTTON: - pFormFiller = new CFFL_RadioButton(m_pApp, pWidget); - break; - case FIELDTYPE_TEXTFIELD: - pFormFiller = new CFFL_TextField(m_pApp, pWidget); - break; - case FIELDTYPE_LISTBOX: - pFormFiller = new CFFL_ListBox(m_pApp, pWidget); - break; - case FIELDTYPE_COMBOBOX: - pFormFiller = new CFFL_ComboBox(m_pApp, pWidget); - break; - case FIELDTYPE_UNKNOWN: - default: - pFormFiller = NULL; - break; - } + auto it = m_Maps.find(pAnnot); + if (it != m_Maps.end()) + return it->second; + + if (!bRegister) + return nullptr; + + CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; + int nFieldType = pWidget->GetFieldType(); + CFFL_FormFiller* pFormFiller; + switch (nFieldType) { + case FIELDTYPE_PUSHBUTTON: + pFormFiller = new CFFL_PushButton(m_pApp, pWidget); + break; + case FIELDTYPE_CHECKBOX: + pFormFiller = new CFFL_CheckBox(m_pApp, pWidget); + break; + case FIELDTYPE_RADIOBUTTON: + pFormFiller = new CFFL_RadioButton(m_pApp, pWidget); + break; + case FIELDTYPE_TEXTFIELD: + pFormFiller = new CFFL_TextField(m_pApp, pWidget); + break; + case FIELDTYPE_LISTBOX: + pFormFiller = new CFFL_ListBox(m_pApp, pWidget); + break; + case FIELDTYPE_COMBOBOX: + pFormFiller = new CFFL_ComboBox(m_pApp, pWidget); + break; + case FIELDTYPE_UNKNOWN: + default: + pFormFiller = nullptr; + break; + } - if (pFormFiller) - { - m_Maps.SetAt(pAnnot, pFormFiller); - } - } + if (!pFormFiller) + return nullptr; - return pFormFiller; + m_Maps[pAnnot] = pFormFiller; + return pFormFiller; } void CFFL_IFormFiller::RemoveFormFiller(CPDFSDK_Annot* pAnnot) @@ -707,11 +694,12 @@ void CFFL_IFormFiller::RemoveFormFiller(CPDFSDK_Annot* pAnnot) void CFFL_IFormFiller::UnRegisterFormFiller(CPDFSDK_Annot* pAnnot) { - CFFL_FormFiller* pFormFiller = nullptr; - if (m_Maps.Lookup(pAnnot,pFormFiller)) { - delete pFormFiller; - m_Maps.RemoveKey(pAnnot); - } + auto it = m_Maps.find(pAnnot); + if (it == m_Maps.end()) + return; + + delete it->second; + m_Maps.erase(it); } void CFFL_IFormFiller::SetFocusAnnotTab(CPDFSDK_Annot* pWidget, FX_BOOL bSameField, FX_BOOL bNext) diff --git a/fpdfsdk/src/formfiller/FFL_ListBox.cpp b/fpdfsdk/src/formfiller/FFL_ListBox.cpp index 4622d4fcef..28dcf340ad 100644 --- a/fpdfsdk/src/formfiller/FFL_ListBox.cpp +++ b/fpdfsdk/src/formfiller/FFL_ListBox.cpp @@ -75,7 +75,7 @@ CPWL_Wnd* CFFL_ListBox::NewPDFWindow(const PWL_CREATEPARAM& cp, CPDFSDK_PageView if (pWnd->HasFlag(PLBS_MULTIPLESEL)) { - m_OriginSelections.RemoveAll(); + m_OriginSelections.clear(); FX_BOOL bSetCaret = FALSE; for (int32_t i=0,sz=m_pWidget->CountOptions(); iSelect(i); - m_OriginSelections.SetAt(i, NULL); + m_OriginSelections.insert(i); } } } @@ -115,36 +115,26 @@ FX_BOOL CFFL_ListBox::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlag return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); } -FX_BOOL CFFL_ListBox::IsDataChanged(CPDFSDK_PageView* pPageView) +FX_BOOL CFFL_ListBox::IsDataChanged(CPDFSDK_PageView* pPageView) { - ASSERT(m_pWidget != NULL); - - if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE)) - { - if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) - { - int nSelCount = 0; - for (int32_t i=0,sz=pListBox->GetCount(); iIsItemSelected(i)) - { - void* p = NULL; - if (!m_OriginSelections.Lookup(i, p)) - return TRUE; - - nSelCount++; - } - } - - return nSelCount != m_OriginSelections.GetCount(); - } - else - { - return pListBox->GetCurSel() != m_pWidget->GetSelectedIndex(0); - } - } - - return FALSE; + CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE); + if (!pListBox) + return FALSE; + + if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) { + int nSelCount = 0; + for (int32_t i = 0, sz = pListBox->GetCount(); i < sz; ++i) { + if (pListBox->IsItemSelected(i)) { + if (m_OriginSelections.count(i) == 0) + return TRUE; + + nSelCount++; + } + } + + return nSelCount != m_OriginSelections.size(); + } + return pListBox->GetCurSel() != m_pWidget->GetSelectedIndex(0); } void CFFL_ListBox::SaveData(CPDFSDK_PageView* pPageView) -- cgit v1.2.3