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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "core/include/fpdfdoc/fpdf_doc.h" | 9 #include "core/include/fpdfdoc/fpdf_doc.h" |
10 | 10 |
11 CPDF_FormControl::CPDF_FormControl(CPDF_FormField* pField, | 11 CPDF_FormControl::CPDF_FormControl(CPDF_FormField* pField, |
12 CPDF_Dictionary* pWidgetDict) { | 12 CPDF_Dictionary* pWidgetDict) { |
13 m_pField = pField; | 13 m_pField = pField; |
14 m_pWidgetDict = pWidgetDict; | 14 m_pWidgetDict = pWidgetDict; |
15 m_pForm = m_pField->m_pForm; | 15 m_pForm = m_pField->m_pForm; |
16 } | 16 } |
17 CFX_FloatRect CPDF_FormControl::GetRect() const { | 17 CFX_FloatRect CPDF_FormControl::GetRect() const { |
18 return m_pWidgetDict->GetRectBy("Rect"); | 18 return m_pWidgetDict->GetRectBy("Rect"); |
19 } | 19 } |
20 CFX_ByteString CPDF_FormControl::GetOnStateName() { | 20 CFX_ByteString CPDF_FormControl::GetOnStateName() const { |
21 ASSERT(GetType() == CPDF_FormField::CheckBox || | 21 ASSERT(GetType() == CPDF_FormField::CheckBox || |
22 GetType() == CPDF_FormField::RadioButton); | 22 GetType() == CPDF_FormField::RadioButton); |
23 CFX_ByteString csOn; | 23 CFX_ByteString csOn; |
24 CPDF_Dictionary* pAP = m_pWidgetDict->GetDictBy("AP"); | 24 CPDF_Dictionary* pAP = m_pWidgetDict->GetDictBy("AP"); |
25 if (!pAP) { | 25 if (!pAP) { |
26 return csOn; | 26 return csOn; |
27 } | 27 } |
28 CPDF_Dictionary* pN = pAP->GetDictBy("N"); | 28 CPDF_Dictionary* pN = pAP->GetDictBy("N"); |
29 if (!pN) { | 29 if (!pN) { |
30 return csOn; | 30 return csOn; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 int iIndex = m_pField->GetControlIndex(this); | 105 int iIndex = m_pField->GetControlIndex(this); |
106 csOn = pArray->GetStringAt(iIndex); | 106 csOn = pArray->GetStringAt(iIndex); |
107 } | 107 } |
108 } | 108 } |
109 if (csOn.IsEmpty()) { | 109 if (csOn.IsEmpty()) { |
110 csOn = "Yes"; | 110 csOn = "Yes"; |
111 } | 111 } |
112 CFX_WideString csWOn = PDF_DecodeText(csOn); | 112 CFX_WideString csWOn = PDF_DecodeText(csOn); |
113 return csWOn; | 113 return csWOn; |
114 } | 114 } |
115 FX_BOOL CPDF_FormControl::IsChecked() { | 115 |
| 116 bool CPDF_FormControl::IsChecked() const { |
116 ASSERT(GetType() == CPDF_FormField::CheckBox || | 117 ASSERT(GetType() == CPDF_FormField::CheckBox || |
117 GetType() == CPDF_FormField::RadioButton); | 118 GetType() == CPDF_FormField::RadioButton); |
118 CFX_ByteString csOn = GetOnStateName(); | 119 CFX_ByteString csOn = GetOnStateName(); |
119 CFX_ByteString csAS = m_pWidgetDict->GetStringBy("AS"); | 120 CFX_ByteString csAS = m_pWidgetDict->GetStringBy("AS"); |
120 return csAS == csOn; | 121 return csAS == csOn; |
121 } | 122 } |
122 FX_BOOL CPDF_FormControl::IsDefaultChecked() { | 123 |
| 124 bool CPDF_FormControl::IsDefaultChecked() const { |
123 ASSERT(GetType() == CPDF_FormField::CheckBox || | 125 ASSERT(GetType() == CPDF_FormField::CheckBox || |
124 GetType() == CPDF_FormField::RadioButton); | 126 GetType() == CPDF_FormField::RadioButton); |
125 CPDF_Object* pDV = FPDF_GetFieldAttr(m_pField->m_pDict, "DV"); | 127 CPDF_Object* pDV = FPDF_GetFieldAttr(m_pField->m_pDict, "DV"); |
126 if (!pDV) { | 128 if (!pDV) { |
127 return FALSE; | 129 return FALSE; |
128 } | 130 } |
129 CFX_ByteString csDV = pDV->GetString(); | 131 CFX_ByteString csDV = pDV->GetString(); |
130 CFX_ByteString csOn = GetOnStateName(); | 132 CFX_ByteString csOn = GetOnStateName(); |
131 return (csDV == csOn); | 133 return (csDV == csOn); |
132 } | 134 } |
| 135 |
133 void CPDF_FormControl::CheckControl(FX_BOOL bChecked) { | 136 void CPDF_FormControl::CheckControl(FX_BOOL bChecked) { |
134 ASSERT(GetType() == CPDF_FormField::CheckBox || | 137 ASSERT(GetType() == CPDF_FormField::CheckBox || |
135 GetType() == CPDF_FormField::RadioButton); | 138 GetType() == CPDF_FormField::RadioButton); |
136 CFX_ByteString csOn = GetOnStateName(); | 139 CFX_ByteString csOn = GetOnStateName(); |
137 CFX_ByteString csOldAS = m_pWidgetDict->GetStringBy("AS", "Off"); | 140 CFX_ByteString csOldAS = m_pWidgetDict->GetStringBy("AS", "Off"); |
138 CFX_ByteString csAS = "Off"; | 141 CFX_ByteString csAS = "Off"; |
139 if (bChecked) { | 142 if (bChecked) { |
140 csAS = csOn; | 143 csAS = csOn; |
141 } | 144 } |
142 if (csOldAS == csAS) { | 145 if (csOldAS == csAS) { |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 } | 421 } |
419 | 422 |
420 CPDF_IconFit CPDF_ApSettings::GetIconFit() const { | 423 CPDF_IconFit CPDF_ApSettings::GetIconFit() const { |
421 return m_pDict ? m_pDict->GetDictBy("IF") : nullptr; | 424 return m_pDict ? m_pDict->GetDictBy("IF") : nullptr; |
422 } | 425 } |
423 | 426 |
424 int CPDF_ApSettings::GetTextPosition() const { | 427 int CPDF_ApSettings::GetTextPosition() const { |
425 return m_pDict ? m_pDict->GetIntegerBy("TP", TEXTPOS_CAPTION) | 428 return m_pDict ? m_pDict->GetIntegerBy("TP", TEXTPOS_CAPTION) |
426 : TEXTPOS_CAPTION; | 429 : TEXTPOS_CAPTION; |
427 } | 430 } |
OLD | NEW |