OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/fpdfdoc/cpdf_formcontrol.h" | 7 #include "core/fpdfdoc/cpdf_formcontrol.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "core/fpdfapi/page/cpdf_form.h" | 11 #include "core/fpdfapi/page/cpdf_form.h" |
12 #include "core/fpdfapi/parser/cpdf_array.h" | 12 #include "core/fpdfapi/parser/cpdf_array.h" |
13 #include "core/fpdfapi/parser/cpdf_document.h" | 13 #include "core/fpdfapi/parser/cpdf_document.h" |
| 14 #include "core/fpdfapi/parser/cpdf_name.h" |
14 #include "core/fpdfapi/parser/cpdf_stream.h" | 15 #include "core/fpdfapi/parser/cpdf_stream.h" |
15 #include "core/fpdfapi/parser/fpdf_parser_decode.h" | 16 #include "core/fpdfapi/parser/fpdf_parser_decode.h" |
16 #include "core/fpdfapi/render/cpdf_rendercontext.h" | 17 #include "core/fpdfapi/render/cpdf_rendercontext.h" |
17 #include "core/fpdfdoc/cpdf_interform.h" | 18 #include "core/fpdfdoc/cpdf_interform.h" |
18 #include "core/fxge/cfx_renderdevice.h" | 19 #include "core/fxge/cfx_renderdevice.h" |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 const FX_CHAR* const g_sHighlightingMode[] = { | 23 const FX_CHAR* const g_sHighlightingMode[] = { |
23 // Must match order of HighlightingMode enum. | 24 // Must match order of HighlightingMode enum. |
(...skipping 30 matching lines...) Expand all Loading... |
54 ASSERT(GetType() == CPDF_FormField::CheckBox || | 55 ASSERT(GetType() == CPDF_FormField::CheckBox || |
55 GetType() == CPDF_FormField::RadioButton); | 56 GetType() == CPDF_FormField::RadioButton); |
56 CFX_ByteString csValue = csOn; | 57 CFX_ByteString csValue = csOn; |
57 if (csValue.IsEmpty()) | 58 if (csValue.IsEmpty()) |
58 csValue = "Yes"; | 59 csValue = "Yes"; |
59 else if (csValue == "Off") | 60 else if (csValue == "Off") |
60 csValue = "Yes"; | 61 csValue = "Yes"; |
61 | 62 |
62 CFX_ByteString csAS = m_pWidgetDict->GetStringFor("AS", "Off"); | 63 CFX_ByteString csAS = m_pWidgetDict->GetStringFor("AS", "Off"); |
63 if (csAS != "Off") | 64 if (csAS != "Off") |
64 m_pWidgetDict->SetNameFor("AS", csValue); | 65 m_pWidgetDict->SetNewFor<CPDF_Name>("AS", csValue); |
65 | 66 |
66 CPDF_Dictionary* pAP = m_pWidgetDict->GetDictFor("AP"); | 67 CPDF_Dictionary* pAP = m_pWidgetDict->GetDictFor("AP"); |
67 if (!pAP) | 68 if (!pAP) |
68 return; | 69 return; |
69 | 70 |
70 for (const auto& it : *pAP) { | 71 for (const auto& it : *pAP) { |
71 CPDF_Object* pObj1 = it.second; | 72 CPDF_Object* pObj1 = it.second.get(); |
72 if (!pObj1) | 73 if (!pObj1) |
73 continue; | 74 continue; |
74 | 75 |
75 CPDF_Object* pObjDirect1 = pObj1->GetDirect(); | 76 CPDF_Object* pObjDirect1 = pObj1->GetDirect(); |
76 CPDF_Dictionary* pSubDict = pObjDirect1->AsDictionary(); | 77 CPDF_Dictionary* pSubDict = pObjDirect1->AsDictionary(); |
77 if (!pSubDict) | 78 if (!pSubDict) |
78 continue; | 79 continue; |
79 | 80 |
80 auto subdict_it = pSubDict->begin(); | 81 auto subdict_it = pSubDict->begin(); |
81 while (subdict_it != pSubDict->end()) { | 82 while (subdict_it != pSubDict->end()) { |
82 const CFX_ByteString& csKey2 = subdict_it->first; | 83 const CFX_ByteString& csKey2 = subdict_it->first; |
83 CPDF_Object* pObj2 = subdict_it->second; | 84 CPDF_Object* pObj2 = subdict_it->second.get(); |
84 ++subdict_it; | 85 ++subdict_it; |
85 if (!pObj2) | 86 if (!pObj2) |
86 continue; | 87 continue; |
87 if (csKey2 != "Off") { | 88 if (csKey2 != "Off") { |
88 pSubDict->ReplaceKey(csKey2, csValue); | 89 pSubDict->ReplaceKey(csKey2, csValue); |
89 break; | 90 break; |
90 } | 91 } |
91 } | 92 } |
92 } | 93 } |
93 } | 94 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 void CPDF_FormControl::CheckControl(bool bChecked) { | 149 void CPDF_FormControl::CheckControl(bool bChecked) { |
149 ASSERT(GetType() == CPDF_FormField::CheckBox || | 150 ASSERT(GetType() == CPDF_FormField::CheckBox || |
150 GetType() == CPDF_FormField::RadioButton); | 151 GetType() == CPDF_FormField::RadioButton); |
151 CFX_ByteString csOn = GetOnStateName(); | 152 CFX_ByteString csOn = GetOnStateName(); |
152 CFX_ByteString csOldAS = m_pWidgetDict->GetStringFor("AS", "Off"); | 153 CFX_ByteString csOldAS = m_pWidgetDict->GetStringFor("AS", "Off"); |
153 CFX_ByteString csAS = "Off"; | 154 CFX_ByteString csAS = "Off"; |
154 if (bChecked) | 155 if (bChecked) |
155 csAS = csOn; | 156 csAS = csOn; |
156 if (csOldAS == csAS) | 157 if (csOldAS == csAS) |
157 return; | 158 return; |
158 m_pWidgetDict->SetNameFor("AS", csAS); | 159 m_pWidgetDict->SetNewFor<CPDF_Name>("AS", csAS); |
159 } | 160 } |
160 | 161 |
161 void CPDF_FormControl::DrawControl(CFX_RenderDevice* pDevice, | 162 void CPDF_FormControl::DrawControl(CFX_RenderDevice* pDevice, |
162 CFX_Matrix* pMatrix, | 163 CFX_Matrix* pMatrix, |
163 CPDF_Page* pPage, | 164 CPDF_Page* pPage, |
164 CPDF_Annot::AppearanceMode mode, | 165 CPDF_Annot::AppearanceMode mode, |
165 const CPDF_RenderOptions* pOptions) { | 166 const CPDF_RenderOptions* pOptions) { |
166 if (m_pWidgetDict->GetIntegerFor("F") & ANNOTFLAG_HIDDEN) | 167 if (m_pWidgetDict->GetIntegerFor("F") & ANNOTFLAG_HIDDEN) |
167 return; | 168 return; |
168 | 169 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 if (!m_pWidgetDict) | 322 if (!m_pWidgetDict) |
322 return 0; | 323 return 0; |
323 if (m_pWidgetDict->KeyExist("Q")) | 324 if (m_pWidgetDict->KeyExist("Q")) |
324 return m_pWidgetDict->GetIntegerFor("Q", 0); | 325 return m_pWidgetDict->GetIntegerFor("Q", 0); |
325 | 326 |
326 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "Q"); | 327 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "Q"); |
327 if (pObj) | 328 if (pObj) |
328 return pObj->GetInteger(); | 329 return pObj->GetInteger(); |
329 return m_pField->m_pForm->GetFormAlignment(); | 330 return m_pField->m_pForm->GetFormAlignment(); |
330 } | 331 } |
OLD | NEW |