| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "../include/fsdk_define.h" | 7 #include "../include/fsdk_define.h" |
| 8 #include "../include/fsdk_mgr.h" | 8 #include "../include/fsdk_mgr.h" |
| 9 #include "../include/formfiller/FFL_FormFiller.h" | 9 #include "../include/formfiller/FFL_FormFiller.h" |
| 10 #include "../include/fsdk_annothandler.h" | 10 #include "../include/fsdk_annothandler.h" |
| 11 | 11 |
| 12 CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp) { | 12 CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp) { |
| 13 m_pApp = pApp; | 13 m_pApp = pApp; |
| 14 | 14 |
| 15 CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp); | 15 CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp); |
| 16 pHandler->SetFormFiller(m_pApp->GetIFormFiller()); | 16 pHandler->SetFormFiller(m_pApp->GetIFormFiller()); |
| 17 RegisterAnnotHandler(pHandler); | 17 RegisterAnnotHandler(pHandler); |
| 18 } | 18 } |
| 19 | 19 |
| 20 CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() { | 20 CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() { |
| 21 for (int i = 0; i < m_Handlers.GetSize(); i++) { | 21 for (int i = 0; i < m_Handlers.GetSize(); i++) { |
| 22 IPDFSDK_AnnotHandler* pHandler = m_Handlers.GetAt(i); | 22 IPDFSDK_AnnotHandler* pHandler = m_Handlers.GetAt(i); |
| 23 delete pHandler; | 23 delete pHandler; |
| 24 } | 24 } |
| 25 m_Handlers.RemoveAll(); | 25 m_Handlers.RemoveAll(); |
| 26 m_mapType2Handler.RemoveAll(); | 26 m_mapType2Handler.clear(); |
| 27 } | 27 } |
| 28 | 28 |
| 29 void CPDFSDK_AnnotHandlerMgr::RegisterAnnotHandler( | 29 void CPDFSDK_AnnotHandlerMgr::RegisterAnnotHandler( |
| 30 IPDFSDK_AnnotHandler* pAnnotHandler) { | 30 IPDFSDK_AnnotHandler* pAnnotHandler) { |
| 31 ASSERT(pAnnotHandler != NULL); | 31 ASSERT(!GetAnnotHandler(pAnnotHandler->GetType())); |
| 32 | |
| 33 ASSERT(GetAnnotHandler(pAnnotHandler->GetType()) == NULL); | |
| 34 | 32 |
| 35 m_Handlers.Add(pAnnotHandler); | 33 m_Handlers.Add(pAnnotHandler); |
| 36 m_mapType2Handler.SetAt(pAnnotHandler->GetType(), (void*)pAnnotHandler); | 34 m_mapType2Handler[pAnnotHandler->GetType()] = pAnnotHandler; |
| 37 } | 35 } |
| 38 | 36 |
| 39 void CPDFSDK_AnnotHandlerMgr::UnRegisterAnnotHandler( | 37 void CPDFSDK_AnnotHandlerMgr::UnRegisterAnnotHandler( |
| 40 IPDFSDK_AnnotHandler* pAnnotHandler) { | 38 IPDFSDK_AnnotHandler* pAnnotHandler) { |
| 41 ASSERT(pAnnotHandler != NULL); | 39 m_mapType2Handler.erase(pAnnotHandler->GetType()); |
| 42 | |
| 43 m_mapType2Handler.RemoveKey(pAnnotHandler->GetType()); | |
| 44 | |
| 45 for (int i = 0, sz = m_Handlers.GetSize(); i < sz; i++) { | 40 for (int i = 0, sz = m_Handlers.GetSize(); i < sz; i++) { |
| 46 if (m_Handlers.GetAt(i) == pAnnotHandler) { | 41 if (m_Handlers.GetAt(i) == pAnnotHandler) { |
| 47 m_Handlers.RemoveAt(i); | 42 m_Handlers.RemoveAt(i); |
| 48 break; | 43 break; |
| 49 } | 44 } |
| 50 } | 45 } |
| 51 } | 46 } |
| 52 | 47 |
| 53 CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot* pAnnot, | 48 CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot* pAnnot, |
| 54 CPDFSDK_PageView* pPageView) { | 49 CPDFSDK_PageView* pPageView) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 ASSERT(pAnnot != NULL); | 98 ASSERT(pAnnot != NULL); |
| 104 | 99 |
| 105 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot(); | 100 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot(); |
| 106 ASSERT(pPDFAnnot != NULL); | 101 ASSERT(pPDFAnnot != NULL); |
| 107 | 102 |
| 108 return GetAnnotHandler(pPDFAnnot->GetSubType()); | 103 return GetAnnotHandler(pPDFAnnot->GetSubType()); |
| 109 } | 104 } |
| 110 | 105 |
| 111 IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler( | 106 IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler( |
| 112 const CFX_ByteString& sType) const { | 107 const CFX_ByteString& sType) const { |
| 113 void* pRet = NULL; | 108 auto it = m_mapType2Handler.find(sType); |
| 114 m_mapType2Handler.Lookup(sType, pRet); | 109 return it != m_mapType2Handler.end() ? it->second : nullptr; |
| 115 return (IPDFSDK_AnnotHandler*)pRet; | |
| 116 } | 110 } |
| 117 | 111 |
| 118 void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView, | 112 void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView, |
| 119 CPDFSDK_Annot* pAnnot, | 113 CPDFSDK_Annot* pAnnot, |
| 120 CFX_RenderDevice* pDevice, | 114 CFX_RenderDevice* pDevice, |
| 121 CPDF_Matrix* pUser2Device, | 115 CPDF_Matrix* pUser2Device, |
| 122 FX_DWORD dwFlags) { | 116 FX_DWORD dwFlags) { |
| 123 ASSERT(pAnnot != NULL); | 117 ASSERT(pAnnot != NULL); |
| 124 | 118 |
| 125 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { | 119 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { |
| (...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 if (pReaderAnnot == pTopMostAnnot) { | 803 if (pReaderAnnot == pTopMostAnnot) { |
| 810 m_pIteratorAnnotList.RemoveAt(i); | 804 m_pIteratorAnnotList.RemoveAt(i); |
| 811 m_pIteratorAnnotList.InsertAt(0, pReaderAnnot); | 805 m_pIteratorAnnotList.InsertAt(0, pReaderAnnot); |
| 812 break; | 806 break; |
| 813 } | 807 } |
| 814 } | 808 } |
| 815 } | 809 } |
| 816 | 810 |
| 817 return TRUE; | 811 return TRUE; |
| 818 } | 812 } |
| OLD | NEW |