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/fpdfxfa/fpdfxfa_doc.h" | 8 #include "../include/fpdfxfa/fpdfxfa_doc.h" |
9 #include "../include/fpdfxfa/fpdfxfa_util.h" | 9 #include "../include/fpdfxfa/fpdfxfa_util.h" |
10 #include "../include/fsdk_mgr.h" | 10 #include "../include/fsdk_mgr.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 new CPDFSDK_XFAAnnotHandler(m_pApp); | 22 new CPDFSDK_XFAAnnotHandler(m_pApp); |
23 RegisterAnnotHandler(pXFAAnnotHandler); | 23 RegisterAnnotHandler(pXFAAnnotHandler); |
24 } | 24 } |
25 | 25 |
26 CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() { | 26 CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() { |
27 for (int i = 0; i < m_Handlers.GetSize(); i++) { | 27 for (int i = 0; i < m_Handlers.GetSize(); i++) { |
28 IPDFSDK_AnnotHandler* pHandler = m_Handlers.GetAt(i); | 28 IPDFSDK_AnnotHandler* pHandler = m_Handlers.GetAt(i); |
29 delete pHandler; | 29 delete pHandler; |
30 } | 30 } |
31 m_Handlers.RemoveAll(); | 31 m_Handlers.RemoveAll(); |
32 m_mapType2Handler.RemoveAll(); | 32 m_mapType2Handler.clear(); |
33 } | 33 } |
34 | 34 |
35 void CPDFSDK_AnnotHandlerMgr::RegisterAnnotHandler( | 35 void CPDFSDK_AnnotHandlerMgr::RegisterAnnotHandler( |
36 IPDFSDK_AnnotHandler* pAnnotHandler) { | 36 IPDFSDK_AnnotHandler* pAnnotHandler) { |
37 ASSERT(pAnnotHandler != NULL); | 37 ASSERT(!GetAnnotHandler(pAnnotHandler->GetType())); |
38 | |
39 ASSERT(GetAnnotHandler(pAnnotHandler->GetType()) == NULL); | |
40 | 38 |
41 m_Handlers.Add(pAnnotHandler); | 39 m_Handlers.Add(pAnnotHandler); |
42 m_mapType2Handler.SetAt(pAnnotHandler->GetType(), (void*)pAnnotHandler); | 40 m_mapType2Handler[pAnnotHandler->GetType()] = pAnnotHandler; |
43 } | 41 } |
44 | 42 |
45 void CPDFSDK_AnnotHandlerMgr::UnRegisterAnnotHandler( | 43 void CPDFSDK_AnnotHandlerMgr::UnRegisterAnnotHandler( |
46 IPDFSDK_AnnotHandler* pAnnotHandler) { | 44 IPDFSDK_AnnotHandler* pAnnotHandler) { |
47 ASSERT(pAnnotHandler != NULL); | 45 m_mapType2Handler.erase(pAnnotHandler->GetType()); |
48 | |
49 m_mapType2Handler.RemoveKey(pAnnotHandler->GetType()); | |
50 | |
51 for (int i = 0, sz = m_Handlers.GetSize(); i < sz; i++) { | 46 for (int i = 0, sz = m_Handlers.GetSize(); i < sz; i++) { |
52 if (m_Handlers.GetAt(i) == pAnnotHandler) { | 47 if (m_Handlers.GetAt(i) == pAnnotHandler) { |
53 m_Handlers.RemoveAt(i); | 48 m_Handlers.RemoveAt(i); |
54 break; | 49 break; |
55 } | 50 } |
56 } | 51 } |
57 } | 52 } |
58 | 53 |
59 CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot* pAnnot, | 54 CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot* pAnnot, |
60 CPDFSDK_PageView* pPageView) { | 55 CPDFSDK_PageView* pPageView) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot(); | 119 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot(); |
125 if (pPDFAnnot) | 120 if (pPDFAnnot) |
126 return GetAnnotHandler(pPDFAnnot->GetSubType()); | 121 return GetAnnotHandler(pPDFAnnot->GetSubType()); |
127 else if (pAnnot->GetXFAWidget()) | 122 else if (pAnnot->GetXFAWidget()) |
128 return GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME); | 123 return GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME); |
129 return NULL; | 124 return NULL; |
130 } | 125 } |
131 | 126 |
132 IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler( | 127 IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler( |
133 const CFX_ByteString& sType) const { | 128 const CFX_ByteString& sType) const { |
134 void* pRet = NULL; | 129 auto it = m_mapType2Handler.find(sType); |
135 m_mapType2Handler.Lookup(sType, pRet); | 130 return it != m_mapType2Handler.end() ? it->second : nullptr; |
136 return (IPDFSDK_AnnotHandler*)pRet; | |
137 } | 131 } |
138 | 132 |
139 void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView, | 133 void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView, |
140 CPDFSDK_Annot* pAnnot, | 134 CPDFSDK_Annot* pAnnot, |
141 CFX_RenderDevice* pDevice, | 135 CFX_RenderDevice* pDevice, |
142 CPDF_Matrix* pUser2Device, | 136 CPDF_Matrix* pUser2Device, |
143 FX_DWORD dwFlags) { | 137 FX_DWORD dwFlags) { |
144 ASSERT(pAnnot != NULL); | 138 ASSERT(pAnnot != NULL); |
145 | 139 |
146 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { | 140 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { |
(...skipping 1164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1311 if (pReaderAnnot == pTopMostAnnot) { | 1305 if (pReaderAnnot == pTopMostAnnot) { |
1312 m_pIteratorAnnotList.RemoveAt(i); | 1306 m_pIteratorAnnotList.RemoveAt(i); |
1313 m_pIteratorAnnotList.InsertAt(0, pReaderAnnot); | 1307 m_pIteratorAnnotList.InsertAt(0, pReaderAnnot); |
1314 break; | 1308 break; |
1315 } | 1309 } |
1316 } | 1310 } |
1317 } | 1311 } |
1318 | 1312 |
1319 return TRUE; | 1313 return TRUE; |
1320 } | 1314 } |
OLD | NEW |