| 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 "core/fpdfdoc/include/cpdf_formfield.h" | 7 #include "core/fpdfdoc/include/cpdf_formfield.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/fpdf_parser/include/cfdf_document.h" | 9 #include "core/fpdfapi/fpdf_parser/include/cfdf_document.h" |
| 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
| 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
| 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" | 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" |
| 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" | 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" |
| 14 #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" | 14 #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" |
| 15 #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" | 15 #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" |
| 16 #include "core/fpdfdoc/cpvt_generateap.h" | 16 #include "core/fpdfdoc/cpvt_generateap.h" |
| 17 #include "core/fpdfdoc/doc_utils.h" | |
| 18 #include "core/fpdfdoc/include/cpdf_formcontrol.h" | 17 #include "core/fpdfdoc/include/cpdf_formcontrol.h" |
| 19 #include "core/fpdfdoc/include/cpdf_interform.h" | 18 #include "core/fpdfdoc/include/cpdf_interform.h" |
| 20 | 19 |
| 21 namespace { | 20 namespace { |
| 22 | 21 |
| 22 const int kMaxRecursion = 32; |
| 23 |
| 23 const int kFormListMultiSelect = 0x100; | 24 const int kFormListMultiSelect = 0x100; |
| 24 | 25 |
| 25 const int kFormComboEdit = 0x100; | 26 const int kFormComboEdit = 0x100; |
| 26 | 27 |
| 27 const int kFormFieldReadOnly = 0x01; | 28 const int kFormFieldReadOnly = 0x01; |
| 28 const int kFormFieldRequired = 0x02; | 29 const int kFormFieldRequired = 0x02; |
| 29 const int kFormFieldNoExport = 0x04; | 30 const int kFormFieldNoExport = 0x04; |
| 30 | 31 |
| 31 const int kFormRadioNoToggleOff = 0x100; | 32 const int kFormRadioNoToggleOff = 0x100; |
| 32 const int kFormRadioUnison = 0x200; | 33 const int kFormRadioUnison = 0x200; |
| 33 | 34 |
| 34 const int kFormTextMultiLine = 0x100; | 35 const int kFormTextMultiLine = 0x100; |
| 35 const int kFormTextPassword = 0x200; | 36 const int kFormTextPassword = 0x200; |
| 36 const int kFormTextNoScroll = 0x400; | 37 const int kFormTextNoScroll = 0x400; |
| 37 const int kFormTextComb = 0x800; | 38 const int kFormTextComb = 0x800; |
| 38 | 39 |
| 39 bool PDF_FormField_IsUnison(CPDF_FormField* pField) { | 40 bool IsUnison(CPDF_FormField* pField) { |
| 40 if (pField->GetType() == CPDF_FormField::CheckBox) | 41 if (pField->GetType() == CPDF_FormField::CheckBox) |
| 41 return true; | 42 return true; |
| 42 | |
| 43 return (pField->GetFieldFlags() & 0x2000000) != 0; | 43 return (pField->GetFieldFlags() & 0x2000000) != 0; |
| 44 } | 44 } |
| 45 | 45 |
| 46 } // namespace | 46 } // namespace |
| 47 | 47 |
| 48 CPDF_Object* FPDF_GetFieldAttr(CPDF_Dictionary* pFieldDict, |
| 49 const FX_CHAR* name, |
| 50 int nLevel) { |
| 51 if (nLevel > kMaxRecursion) |
| 52 return nullptr; |
| 53 if (!pFieldDict) |
| 54 return nullptr; |
| 55 |
| 56 CPDF_Object* pAttr = pFieldDict->GetDirectObjectBy(name); |
| 57 if (pAttr) |
| 58 return pAttr; |
| 59 |
| 60 CPDF_Dictionary* pParent = pFieldDict->GetDictBy("Parent"); |
| 61 if (!pParent) |
| 62 return nullptr; |
| 63 return FPDF_GetFieldAttr(pParent, name, nLevel + 1); |
| 64 } |
| 65 |
| 66 CFX_WideString FPDF_GetFullName(CPDF_Dictionary* pFieldDict) { |
| 67 CFX_WideString full_name; |
| 68 CPDF_Dictionary* pLevel = pFieldDict; |
| 69 while (pLevel) { |
| 70 CFX_WideString short_name = pLevel->GetUnicodeTextBy("T"); |
| 71 if (short_name != L"") { |
| 72 if (full_name == L"") |
| 73 full_name = short_name; |
| 74 else |
| 75 full_name = short_name + L"." + full_name; |
| 76 } |
| 77 pLevel = pLevel->GetDictBy("Parent"); |
| 78 } |
| 79 return full_name; |
| 80 } |
| 81 |
| 48 CPDF_FormField::CPDF_FormField(CPDF_InterForm* pForm, CPDF_Dictionary* pDict) | 82 CPDF_FormField::CPDF_FormField(CPDF_InterForm* pForm, CPDF_Dictionary* pDict) |
| 49 : m_Type(Unknown), | 83 : m_Type(Unknown), |
| 50 m_pForm(pForm), | 84 m_pForm(pForm), |
| 51 m_pDict(pDict), | 85 m_pDict(pDict), |
| 52 m_FontSize(0), | 86 m_FontSize(0), |
| 53 m_pFont(nullptr) { | 87 m_pFont(nullptr) { |
| 54 SyncFieldFlags(); | 88 SyncFieldFlags(); |
| 55 } | 89 } |
| 56 | 90 |
| 57 CPDF_FormField::~CPDF_FormField() {} | 91 CPDF_FormField::~CPDF_FormField() {} |
| 58 | 92 |
| 59 void CPDF_FormField::SyncFieldFlags() { | 93 void CPDF_FormField::SyncFieldFlags() { |
| 60 CFX_ByteString type_name = FPDF_GetFieldAttr(m_pDict, "FT") | 94 CFX_ByteString type_name = FPDF_GetFieldAttr(m_pDict, "FT") |
| 61 ? FPDF_GetFieldAttr(m_pDict, "FT")->GetString() | 95 ? FPDF_GetFieldAttr(m_pDict, "FT")->GetString() |
| 62 : CFX_ByteString(); | 96 : CFX_ByteString(); |
| 63 uint32_t flags = FPDF_GetFieldAttr(m_pDict, "Ff") | 97 uint32_t flags = FPDF_GetFieldAttr(m_pDict, "Ff") |
| 64 ? FPDF_GetFieldAttr(m_pDict, "Ff")->GetInteger() | 98 ? FPDF_GetFieldAttr(m_pDict, "Ff")->GetInteger() |
| 65 : 0; | 99 : 0; |
| 66 m_Flags = 0; | 100 m_Flags = 0; |
| 67 if (flags & 1) { | 101 if (flags & 1) |
| 68 m_Flags |= kFormFieldReadOnly; | 102 m_Flags |= kFormFieldReadOnly; |
| 69 } | 103 if (flags & 2) |
| 70 if (flags & 2) { | |
| 71 m_Flags |= kFormFieldRequired; | 104 m_Flags |= kFormFieldRequired; |
| 72 } | 105 if (flags & 4) |
| 73 if (flags & 4) { | |
| 74 m_Flags |= kFormFieldNoExport; | 106 m_Flags |= kFormFieldNoExport; |
| 75 } | 107 |
| 76 if (type_name == "Btn") { | 108 if (type_name == "Btn") { |
| 77 if (flags & 0x8000) { | 109 if (flags & 0x8000) { |
| 78 m_Type = RadioButton; | 110 m_Type = RadioButton; |
| 79 if (flags & 0x4000) { | 111 if (flags & 0x4000) |
| 80 m_Flags |= kFormRadioNoToggleOff; | 112 m_Flags |= kFormRadioNoToggleOff; |
| 81 } | 113 if (flags & 0x2000000) |
| 82 if (flags & 0x2000000) { | |
| 83 m_Flags |= kFormRadioUnison; | 114 m_Flags |= kFormRadioUnison; |
| 84 } | |
| 85 } else if (flags & 0x10000) { | 115 } else if (flags & 0x10000) { |
| 86 m_Type = PushButton; | 116 m_Type = PushButton; |
| 87 } else { | 117 } else { |
| 88 m_Type = CheckBox; | 118 m_Type = CheckBox; |
| 89 } | 119 } |
| 90 } else if (type_name == "Tx") { | 120 } else if (type_name == "Tx") { |
| 91 if (flags & 0x100000) { | 121 if (flags & 0x100000) { |
| 92 m_Type = File; | 122 m_Type = File; |
| 93 } else if (flags & 0x2000000) { | 123 } else if (flags & 0x2000000) { |
| 94 m_Type = RichText; | 124 m_Type = RichText; |
| 95 } else { | 125 } else { |
| 96 m_Type = Text; | 126 m_Type = Text; |
| 97 if (flags & 0x1000) { | 127 if (flags & 0x1000) |
| 98 m_Flags |= kFormTextMultiLine; | 128 m_Flags |= kFormTextMultiLine; |
| 99 } | 129 if (flags & 0x2000) |
| 100 if (flags & 0x2000) { | |
| 101 m_Flags |= kFormTextPassword; | 130 m_Flags |= kFormTextPassword; |
| 102 } | 131 if (flags & 0x800000) |
| 103 if (flags & 0x800000) { | |
| 104 m_Flags |= kFormTextNoScroll; | 132 m_Flags |= kFormTextNoScroll; |
| 105 } | 133 if (flags & 0x100000) |
| 106 if (flags & 0x100000) { | |
| 107 m_Flags |= kFormTextComb; | 134 m_Flags |= kFormTextComb; |
| 108 } | |
| 109 } | 135 } |
| 110 LoadDA(); | 136 LoadDA(); |
| 111 } else if (type_name == "Ch") { | 137 } else if (type_name == "Ch") { |
| 112 if (flags & 0x20000) { | 138 if (flags & 0x20000) { |
| 113 m_Type = ComboBox; | 139 m_Type = ComboBox; |
| 114 if (flags & 0x40000) { | 140 if (flags & 0x40000) |
| 115 m_Flags |= kFormComboEdit; | 141 m_Flags |= kFormComboEdit; |
| 116 } | |
| 117 } else { | 142 } else { |
| 118 m_Type = ListBox; | 143 m_Type = ListBox; |
| 119 if (flags & 0x200000) { | 144 if (flags & 0x200000) |
| 120 m_Flags |= kFormListMultiSelect; | 145 m_Flags |= kFormListMultiSelect; |
| 121 } | |
| 122 } | 146 } |
| 123 LoadDA(); | 147 LoadDA(); |
| 124 } else if (type_name == "Sig") { | 148 } else if (type_name == "Sig") { |
| 125 m_Type = Sign; | 149 m_Type = Sign; |
| 126 } | 150 } |
| 127 } | 151 } |
| 152 |
| 128 CFX_WideString CPDF_FormField::GetFullName() const { | 153 CFX_WideString CPDF_FormField::GetFullName() const { |
| 129 return ::GetFullName(m_pDict); | 154 return FPDF_GetFullName(m_pDict); |
| 130 } | 155 } |
| 131 | 156 |
| 132 FX_BOOL CPDF_FormField::ResetField(FX_BOOL bNotify) { | 157 FX_BOOL CPDF_FormField::ResetField(FX_BOOL bNotify) { |
| 133 switch (m_Type) { | 158 switch (m_Type) { |
| 134 case CPDF_FormField::CheckBox: | 159 case CPDF_FormField::CheckBox: |
| 135 case CPDF_FormField::RadioButton: { | 160 case CPDF_FormField::RadioButton: { |
| 136 int iCount = CountControls(); | 161 int iCount = CountControls(); |
| 137 if (iCount) { | 162 if (iCount) { |
| 138 // TODO(weili): Check whether anything special needs to be done for | 163 // TODO(weili): Check whether anything special needs to be done for |
| 139 // unison field. Otherwise, merge these branches. | 164 // unison field. Otherwise, merge these branches. |
| 140 if (PDF_FormField_IsUnison(this)) { | 165 if (IsUnison(this)) { |
| 141 for (int i = 0; i < iCount; i++) { | 166 for (int i = 0; i < iCount; i++) |
| 142 CheckControl(i, GetControl(i)->IsDefaultChecked(), FALSE); | 167 CheckControl(i, GetControl(i)->IsDefaultChecked(), FALSE); |
| 143 } | |
| 144 } else { | 168 } else { |
| 145 for (int i = 0; i < iCount; i++) { | 169 for (int i = 0; i < iCount; i++) |
| 146 CheckControl(i, GetControl(i)->IsDefaultChecked(), FALSE); | 170 CheckControl(i, GetControl(i)->IsDefaultChecked(), FALSE); |
| 147 } | |
| 148 } | 171 } |
| 149 } | 172 } |
| 150 if (bNotify && m_pForm->m_pFormNotify) { | 173 if (bNotify && m_pForm->m_pFormNotify) |
| 151 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); | 174 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); |
| 152 } | 175 break; |
| 153 } break; | 176 } |
| 154 case CPDF_FormField::ComboBox: | 177 case CPDF_FormField::ComboBox: |
| 155 case CPDF_FormField::ListBox: { | 178 case CPDF_FormField::ListBox: { |
| 156 CFX_WideString csValue; | 179 CFX_WideString csValue; |
| 157 ClearSelection(); | 180 ClearSelection(); |
| 158 int iIndex = GetDefaultSelectedItem(); | 181 int iIndex = GetDefaultSelectedItem(); |
| 159 if (iIndex >= 0) | 182 if (iIndex >= 0) |
| 160 csValue = GetOptionLabel(iIndex); | 183 csValue = GetOptionLabel(iIndex); |
| 161 | 184 |
| 162 if (bNotify && !NotifyListOrComboBoxBeforeChange(csValue)) | 185 if (bNotify && !NotifyListOrComboBoxBeforeChange(csValue)) |
| 163 return FALSE; | 186 return FALSE; |
| 164 | 187 |
| 165 SetItemSelection(iIndex, TRUE); | 188 SetItemSelection(iIndex, TRUE); |
| 166 if (bNotify) | 189 if (bNotify) |
| 167 NotifyListOrComboBoxAfterChange(); | 190 NotifyListOrComboBoxAfterChange(); |
| 168 } break; | 191 break; |
| 192 } |
| 169 case CPDF_FormField::Text: | 193 case CPDF_FormField::Text: |
| 170 case CPDF_FormField::RichText: | 194 case CPDF_FormField::RichText: |
| 171 case CPDF_FormField::File: | 195 case CPDF_FormField::File: |
| 172 default: { | 196 default: { |
| 173 CPDF_Object* pDV = FPDF_GetFieldAttr(m_pDict, "DV"); | 197 CPDF_Object* pDV = FPDF_GetFieldAttr(m_pDict, "DV"); |
| 174 CFX_WideString csDValue; | 198 CFX_WideString csDValue; |
| 175 if (pDV) | 199 if (pDV) |
| 176 csDValue = pDV->GetUnicodeText(); | 200 csDValue = pDV->GetUnicodeText(); |
| 177 | 201 |
| 178 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V"); | 202 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V"); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 196 if (pRV) { | 220 if (pRV) { |
| 197 CPDF_Object* pCloneR = pDV->Clone(); | 221 CPDF_Object* pCloneR = pDV->Clone(); |
| 198 m_pDict->SetAt("RV", pCloneR); | 222 m_pDict->SetAt("RV", pCloneR); |
| 199 } | 223 } |
| 200 } else { | 224 } else { |
| 201 m_pDict->RemoveAt("V"); | 225 m_pDict->RemoveAt("V"); |
| 202 m_pDict->RemoveAt("RV"); | 226 m_pDict->RemoveAt("RV"); |
| 203 } | 227 } |
| 204 if (bNotify) | 228 if (bNotify) |
| 205 NotifyAfterValueChange(); | 229 NotifyAfterValueChange(); |
| 206 } break; | 230 break; |
| 231 } |
| 207 } | 232 } |
| 208 return TRUE; | 233 return TRUE; |
| 209 } | 234 } |
| 210 | 235 |
| 211 int CPDF_FormField::GetControlIndex(const CPDF_FormControl* pControl) const { | 236 int CPDF_FormField::GetControlIndex(const CPDF_FormControl* pControl) const { |
| 212 if (!pControl) | 237 if (!pControl) |
| 213 return -1; | 238 return -1; |
| 214 | 239 |
| 215 for (int i = 0; i < m_ControlList.GetSize(); i++) { | 240 for (int i = 0; i < m_ControlList.GetSize(); i++) { |
| 216 if (m_ControlList.GetAt(i) == pControl) | 241 if (m_ControlList.GetAt(i) == pControl) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 243 return FIELDTYPE_UNKNOWN; | 268 return FIELDTYPE_UNKNOWN; |
| 244 } | 269 } |
| 245 | 270 |
| 246 CPDF_AAction CPDF_FormField::GetAdditionalAction() const { | 271 CPDF_AAction CPDF_FormField::GetAdditionalAction() const { |
| 247 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "AA"); | 272 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "AA"); |
| 248 return CPDF_AAction(pObj ? pObj->GetDict() : nullptr); | 273 return CPDF_AAction(pObj ? pObj->GetDict() : nullptr); |
| 249 } | 274 } |
| 250 | 275 |
| 251 CFX_WideString CPDF_FormField::GetAlternateName() const { | 276 CFX_WideString CPDF_FormField::GetAlternateName() const { |
| 252 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TU"); | 277 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TU"); |
| 253 if (!pObj) { | 278 return pObj ? pObj->GetUnicodeText() : L""; |
| 254 return L""; | |
| 255 } | |
| 256 return pObj->GetUnicodeText(); | |
| 257 } | 279 } |
| 280 |
| 258 CFX_WideString CPDF_FormField::GetMappingName() const { | 281 CFX_WideString CPDF_FormField::GetMappingName() const { |
| 259 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TM"); | 282 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TM"); |
| 260 if (!pObj) { | 283 return pObj ? pObj->GetUnicodeText() : L""; |
| 261 return L""; | |
| 262 } | |
| 263 return pObj->GetUnicodeText(); | |
| 264 } | 284 } |
| 285 |
| 265 uint32_t CPDF_FormField::GetFieldFlags() const { | 286 uint32_t CPDF_FormField::GetFieldFlags() const { |
| 266 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "Ff"); | 287 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "Ff"); |
| 267 if (!pObj) { | 288 return pObj ? pObj->GetInteger() : 0; |
| 268 return 0; | |
| 269 } | |
| 270 return pObj->GetInteger(); | |
| 271 } | 289 } |
| 290 |
| 272 CFX_ByteString CPDF_FormField::GetDefaultStyle() const { | 291 CFX_ByteString CPDF_FormField::GetDefaultStyle() const { |
| 273 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "DS"); | 292 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "DS"); |
| 274 if (!pObj) { | 293 return pObj ? pObj->GetString() : ""; |
| 275 return ""; | |
| 276 } | |
| 277 return pObj->GetString(); | |
| 278 } | 294 } |
| 295 |
| 279 CFX_WideString CPDF_FormField::GetRichTextString() const { | 296 CFX_WideString CPDF_FormField::GetRichTextString() const { |
| 280 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "RV"); | 297 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "RV"); |
| 281 if (!pObj) { | 298 return pObj ? pObj->GetUnicodeText() : L""; |
| 282 return L""; | |
| 283 } | |
| 284 return pObj->GetUnicodeText(); | |
| 285 } | 299 } |
| 300 |
| 286 CFX_WideString CPDF_FormField::GetValue(FX_BOOL bDefault) const { | 301 CFX_WideString CPDF_FormField::GetValue(FX_BOOL bDefault) const { |
| 287 if (GetType() == CheckBox || GetType() == RadioButton) | 302 if (GetType() == CheckBox || GetType() == RadioButton) |
| 288 return GetCheckValue(bDefault); | 303 return GetCheckValue(bDefault); |
| 289 | 304 |
| 290 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, bDefault ? "DV" : "V"); | 305 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, bDefault ? "DV" : "V"); |
| 291 if (!pValue) { | 306 if (!pValue) { |
| 292 if (!bDefault) { | 307 if (!bDefault) { |
| 293 if (m_Type == RichText) { | 308 if (m_Type == RichText) |
| 294 pValue = FPDF_GetFieldAttr(m_pDict, "V"); | 309 pValue = FPDF_GetFieldAttr(m_pDict, "V"); |
| 295 } | 310 if (!pValue && m_Type != Text) |
| 296 if (!pValue && m_Type != Text) { | |
| 297 pValue = FPDF_GetFieldAttr(m_pDict, "DV"); | 311 pValue = FPDF_GetFieldAttr(m_pDict, "DV"); |
| 298 } | |
| 299 } | 312 } |
| 300 if (!pValue) | 313 if (!pValue) |
| 301 return CFX_WideString(); | 314 return CFX_WideString(); |
| 302 } | 315 } |
| 316 |
| 303 switch (pValue->GetType()) { | 317 switch (pValue->GetType()) { |
| 304 case CPDF_Object::STRING: | 318 case CPDF_Object::STRING: |
| 305 case CPDF_Object::STREAM: | 319 case CPDF_Object::STREAM: |
| 306 return pValue->GetUnicodeText(); | 320 return pValue->GetUnicodeText(); |
| 307 case CPDF_Object::ARRAY: | 321 case CPDF_Object::ARRAY: |
| 308 pValue = pValue->AsArray()->GetDirectObjectAt(0); | 322 pValue = pValue->AsArray()->GetDirectObjectAt(0); |
| 309 if (pValue) | 323 if (pValue) |
| 310 return pValue->GetUnicodeText(); | 324 return pValue->GetUnicodeText(); |
| 311 break; | 325 break; |
| 312 default: | 326 default: |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 m_pDict->RemoveAt("I"); | 363 m_pDict->RemoveAt("I"); |
| 350 } else { | 364 } else { |
| 351 m_pDict->SetAtString(bDefault ? "DV" : "V", PDF_EncodeText(csValue)); | 365 m_pDict->SetAtString(bDefault ? "DV" : "V", PDF_EncodeText(csValue)); |
| 352 if (!bDefault) { | 366 if (!bDefault) { |
| 353 ClearSelection(); | 367 ClearSelection(); |
| 354 SetItemSelection(iIndex, TRUE); | 368 SetItemSelection(iIndex, TRUE); |
| 355 } | 369 } |
| 356 } | 370 } |
| 357 if (bNotify) | 371 if (bNotify) |
| 358 NotifyAfterValueChange(); | 372 NotifyAfterValueChange(); |
| 359 } break; | 373 break; |
| 374 } |
| 360 case ListBox: { | 375 case ListBox: { |
| 361 int iIndex = FindOptionValue(value); | 376 int iIndex = FindOptionValue(value); |
| 362 if (iIndex < 0) | 377 if (iIndex < 0) |
| 363 return FALSE; | 378 return FALSE; |
| 364 | 379 |
| 365 if (bDefault && iIndex == GetDefaultSelectedItem()) | 380 if (bDefault && iIndex == GetDefaultSelectedItem()) |
| 366 return FALSE; | 381 return FALSE; |
| 367 | 382 |
| 368 if (bNotify && !NotifyBeforeSelectionChange(value)) | 383 if (bNotify && !NotifyBeforeSelectionChange(value)) |
| 369 return FALSE; | 384 return FALSE; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 if (!pArray || index < 0) | 452 if (!pArray || index < 0) |
| 438 return -1; | 453 return -1; |
| 439 | 454 |
| 440 CPDF_Object* elementValue = pArray->GetDirectObjectAt(index); | 455 CPDF_Object* elementValue = pArray->GetDirectObjectAt(index); |
| 441 sel_value = | 456 sel_value = |
| 442 elementValue ? elementValue->GetUnicodeText() : CFX_WideString(); | 457 elementValue ? elementValue->GetUnicodeText() : CFX_WideString(); |
| 443 } | 458 } |
| 444 if (index < CountSelectedOptions()) { | 459 if (index < CountSelectedOptions()) { |
| 445 int iOptIndex = GetSelectedOptionIndex(index); | 460 int iOptIndex = GetSelectedOptionIndex(index); |
| 446 CFX_WideString csOpt = GetOptionValue(iOptIndex); | 461 CFX_WideString csOpt = GetOptionValue(iOptIndex); |
| 447 if (csOpt == sel_value) { | 462 if (csOpt == sel_value) |
| 448 return iOptIndex; | 463 return iOptIndex; |
| 449 } | |
| 450 } | 464 } |
| 451 for (int i = 0; i < CountOptions(); i++) { | 465 for (int i = 0; i < CountOptions(); i++) { |
| 452 if (sel_value == GetOptionValue(i)) | 466 if (sel_value == GetOptionValue(i)) |
| 453 return i; | 467 return i; |
| 454 } | 468 } |
| 455 return -1; | 469 return -1; |
| 456 } | 470 } |
| 457 | 471 |
| 458 FX_BOOL CPDF_FormField::ClearSelection(FX_BOOL bNotify) { | 472 FX_BOOL CPDF_FormField::ClearSelection(FX_BOOL bNotify) { |
| 459 if (bNotify && m_pForm->m_pFormNotify) { | 473 if (bNotify && m_pForm->m_pFormNotify) { |
| 460 CFX_WideString csValue; | 474 CFX_WideString csValue; |
| 461 int iIndex = GetSelectedIndex(0); | 475 int iIndex = GetSelectedIndex(0); |
| 462 if (iIndex >= 0) | 476 if (iIndex >= 0) |
| 463 csValue = GetOptionLabel(iIndex); | 477 csValue = GetOptionLabel(iIndex); |
| 464 | 478 |
| 465 if (!NotifyListOrComboBoxBeforeChange(csValue)) | 479 if (!NotifyListOrComboBoxBeforeChange(csValue)) |
| 466 return FALSE; | 480 return FALSE; |
| 467 } | 481 } |
| 468 m_pDict->RemoveAt("V"); | 482 m_pDict->RemoveAt("V"); |
| 469 m_pDict->RemoveAt("I"); | 483 m_pDict->RemoveAt("I"); |
| 470 if (bNotify) | 484 if (bNotify) |
| 471 NotifyListOrComboBoxAfterChange(); | 485 NotifyListOrComboBoxAfterChange(); |
| 472 return TRUE; | 486 return TRUE; |
| 473 } | 487 } |
| 474 | 488 |
| 475 FX_BOOL CPDF_FormField::IsItemSelected(int index) const { | 489 FX_BOOL CPDF_FormField::IsItemSelected(int index) const { |
| 476 ASSERT(GetType() == ComboBox || GetType() == ListBox); | 490 ASSERT(GetType() == ComboBox || GetType() == ListBox); |
| 477 if (index < 0 || index >= CountOptions()) { | 491 if (index < 0 || index >= CountOptions()) |
| 478 return FALSE; | 492 return FALSE; |
| 479 } | 493 if (IsOptionSelected(index)) |
| 480 if (IsOptionSelected(index)) { | |
| 481 return TRUE; | 494 return TRUE; |
| 482 } | 495 |
| 483 CFX_WideString opt_value = GetOptionValue(index); | 496 CFX_WideString opt_value = GetOptionValue(index); |
| 484 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); | 497 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); |
| 485 if (!pValue) { | 498 if (!pValue) { |
| 486 pValue = FPDF_GetFieldAttr(m_pDict, "I"); | 499 pValue = FPDF_GetFieldAttr(m_pDict, "I"); |
| 487 if (!pValue) { | 500 if (!pValue) |
| 488 return FALSE; | 501 return FALSE; |
| 489 } | |
| 490 } | 502 } |
| 491 | 503 |
| 492 if (pValue->IsString()) | 504 if (pValue->IsString()) |
| 493 return pValue->GetUnicodeText() == opt_value; | 505 return pValue->GetUnicodeText() == opt_value; |
| 494 | 506 |
| 495 if (pValue->IsNumber()) { | 507 if (pValue->IsNumber()) { |
| 496 if (pValue->GetString().IsEmpty()) | 508 if (pValue->GetString().IsEmpty()) |
| 497 return FALSE; | 509 return FALSE; |
| 498 return (pValue->GetInteger() == index); | 510 return (pValue->GetInteger() == index); |
| 499 } | 511 } |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 | 628 |
| 617 CPDF_Object* pOption = pArray->GetDirectObjectAt(index); | 629 CPDF_Object* pOption = pArray->GetDirectObjectAt(index); |
| 618 if (!pOption) | 630 if (!pOption) |
| 619 return CFX_WideString(); | 631 return CFX_WideString(); |
| 620 if (CPDF_Array* pOptionArray = pOption->AsArray()) | 632 if (CPDF_Array* pOptionArray = pOption->AsArray()) |
| 621 pOption = pOptionArray->GetDirectObjectAt(sub_index); | 633 pOption = pOptionArray->GetDirectObjectAt(sub_index); |
| 622 | 634 |
| 623 CPDF_String* pString = ToString(pOption); | 635 CPDF_String* pString = ToString(pOption); |
| 624 return pString ? pString->GetUnicodeText() : CFX_WideString(); | 636 return pString ? pString->GetUnicodeText() : CFX_WideString(); |
| 625 } | 637 } |
| 638 |
| 626 CFX_WideString CPDF_FormField::GetOptionLabel(int index) const { | 639 CFX_WideString CPDF_FormField::GetOptionLabel(int index) const { |
| 627 return GetOptionText(index, 1); | 640 return GetOptionText(index, 1); |
| 628 } | 641 } |
| 642 |
| 629 CFX_WideString CPDF_FormField::GetOptionValue(int index) const { | 643 CFX_WideString CPDF_FormField::GetOptionValue(int index) const { |
| 630 return GetOptionText(index, 0); | 644 return GetOptionText(index, 0); |
| 631 } | 645 } |
| 632 | 646 |
| 633 int CPDF_FormField::FindOption(CFX_WideString csOptLabel) const { | 647 int CPDF_FormField::FindOption(CFX_WideString csOptLabel) const { |
| 634 for (int i = 0; i < CountOptions(); i++) { | 648 for (int i = 0; i < CountOptions(); i++) { |
| 635 if (GetOptionValue(i) == csOptLabel) | 649 if (GetOptionValue(i) == csOptLabel) |
| 636 return i; | 650 return i; |
| 637 } | 651 } |
| 638 return -1; | 652 return -1; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 | 714 |
| 701 return TRUE; | 715 return TRUE; |
| 702 } | 716 } |
| 703 #endif // PDF_ENABLE_XFA | 717 #endif // PDF_ENABLE_XFA |
| 704 | 718 |
| 705 FX_BOOL CPDF_FormField::CheckControl(int iControlIndex, | 719 FX_BOOL CPDF_FormField::CheckControl(int iControlIndex, |
| 706 bool bChecked, | 720 bool bChecked, |
| 707 bool bNotify) { | 721 bool bNotify) { |
| 708 ASSERT(GetType() == CheckBox || GetType() == RadioButton); | 722 ASSERT(GetType() == CheckBox || GetType() == RadioButton); |
| 709 CPDF_FormControl* pControl = GetControl(iControlIndex); | 723 CPDF_FormControl* pControl = GetControl(iControlIndex); |
| 710 if (!pControl) { | 724 if (!pControl) |
| 711 return FALSE; | 725 return FALSE; |
| 712 } | 726 if (!bChecked && pControl->IsChecked() == bChecked) |
| 713 if (!bChecked && pControl->IsChecked() == bChecked) { | |
| 714 return FALSE; | 727 return FALSE; |
| 715 } | 728 |
| 716 CFX_WideString csWExport = pControl->GetExportValue(); | 729 CFX_WideString csWExport = pControl->GetExportValue(); |
| 717 CFX_ByteString csBExport = PDF_EncodeText(csWExport); | 730 CFX_ByteString csBExport = PDF_EncodeText(csWExport); |
| 718 int iCount = CountControls(); | 731 int iCount = CountControls(); |
| 719 bool bUnison = PDF_FormField_IsUnison(this); | 732 bool bUnison = IsUnison(this); |
| 720 for (int i = 0; i < iCount; i++) { | 733 for (int i = 0; i < iCount; i++) { |
| 721 CPDF_FormControl* pCtrl = GetControl(i); | 734 CPDF_FormControl* pCtrl = GetControl(i); |
| 722 if (bUnison) { | 735 if (bUnison) { |
| 723 CFX_WideString csEValue = pCtrl->GetExportValue(); | 736 CFX_WideString csEValue = pCtrl->GetExportValue(); |
| 724 if (csEValue == csWExport) { | 737 if (csEValue == csWExport) { |
| 725 if (pCtrl->GetOnStateName() == pControl->GetOnStateName()) { | 738 if (pCtrl->GetOnStateName() == pControl->GetOnStateName()) |
| 726 pCtrl->CheckControl(bChecked); | 739 pCtrl->CheckControl(bChecked); |
| 727 } else if (bChecked) { | 740 else if (bChecked) |
| 728 pCtrl->CheckControl(FALSE); | 741 pCtrl->CheckControl(FALSE); |
| 729 } | |
| 730 } else if (bChecked) { | 742 } else if (bChecked) { |
| 731 pCtrl->CheckControl(FALSE); | 743 pCtrl->CheckControl(FALSE); |
| 732 } | 744 } |
| 733 } else { | 745 } else { |
| 734 if (i == iControlIndex) { | 746 if (i == iControlIndex) |
| 735 pCtrl->CheckControl(bChecked); | 747 pCtrl->CheckControl(bChecked); |
| 736 } else if (bChecked) { | 748 else if (bChecked) |
| 737 pCtrl->CheckControl(FALSE); | 749 pCtrl->CheckControl(FALSE); |
| 738 } | |
| 739 } | 750 } |
| 740 } | 751 } |
| 752 |
| 741 CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pDict, "Opt"); | 753 CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pDict, "Opt"); |
| 742 if (!ToArray(pOpt)) { | 754 if (!ToArray(pOpt)) { |
| 743 if (bChecked) { | 755 if (bChecked) { |
| 744 m_pDict->SetAtName("V", csBExport); | 756 m_pDict->SetAtName("V", csBExport); |
| 745 } else { | 757 } else { |
| 746 CFX_ByteString csV; | 758 CFX_ByteString csV; |
| 747 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V"); | 759 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V"); |
| 748 if (pV) { | 760 if (pV) |
| 749 csV = pV->GetString(); | 761 csV = pV->GetString(); |
| 750 } | 762 if (csV == csBExport) |
| 751 if (csV == csBExport) { | |
| 752 m_pDict->SetAtName("V", "Off"); | 763 m_pDict->SetAtName("V", "Off"); |
| 753 } | |
| 754 } | 764 } |
| 755 } else if (bChecked) { | 765 } else if (bChecked) { |
| 756 CFX_ByteString csIndex; | 766 CFX_ByteString csIndex; |
| 757 csIndex.Format("%d", iControlIndex); | 767 csIndex.Format("%d", iControlIndex); |
| 758 m_pDict->SetAtName("V", csIndex); | 768 m_pDict->SetAtName("V", csIndex); |
| 759 } | 769 } |
| 760 if (bNotify && m_pForm->m_pFormNotify) | 770 if (bNotify && m_pForm->m_pFormNotify) |
| 761 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); | 771 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); |
| 762 return TRUE; | 772 return TRUE; |
| 763 } | 773 } |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 case ListBox: | 988 case ListBox: |
| 979 NotifyAfterSelectionChange(); | 989 NotifyAfterSelectionChange(); |
| 980 break; | 990 break; |
| 981 case ComboBox: | 991 case ComboBox: |
| 982 NotifyAfterValueChange(); | 992 NotifyAfterValueChange(); |
| 983 break; | 993 break; |
| 984 default: | 994 default: |
| 985 break; | 995 break; |
| 986 } | 996 } |
| 987 } | 997 } |
| OLD | NEW |