Chromium Code Reviews| 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/fpdfapi/fpdf_parser/include/cfdf_document.h" | 7 #include "core/fpdfapi/fpdf_parser/include/cfdf_document.h" |
| 8 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 8 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
| 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
| 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" |
| 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" | 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" |
| 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" | 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" |
| 13 #include "core/fpdfdoc/cpvt_generateap.h" | 13 #include "core/fpdfdoc/cpvt_generateap.h" |
| 14 #include "core/fpdfdoc/doc_utils.h" | 14 #include "core/fpdfdoc/doc_utils.h" |
| 15 #include "core/fpdfdoc/include/fpdf_doc.h" | 15 #include "core/fpdfdoc/include/fpdf_doc.h" |
| 16 | 16 |
| 17 FX_BOOL PDF_FormField_IsUnison(CPDF_FormField* pField) { | 17 namespace { |
| 18 FX_BOOL bUnison = FALSE; | 18 |
| 19 if (pField->GetType() == CPDF_FormField::CheckBox) { | 19 bool PDF_FormField_IsUnison(CPDF_FormField* pField) { |
| 20 bUnison = TRUE; | 20 if (pField->GetType() == CPDF_FormField::CheckBox) |
| 21 } else { | 21 return true; |
| 22 uint32_t dwFlags = pField->GetFieldFlags(); | 22 |
| 23 bUnison = ((dwFlags & 0x2000000) != 0); | 23 return (pField->GetFieldFlags() & 0x2000000) != 0; |
| 24 } | |
| 25 return bUnison; | |
| 26 } | 24 } |
| 27 CPDF_FormField::CPDF_FormField(CPDF_InterForm* pForm, CPDF_Dictionary* pDict) { | 25 |
| 28 m_pDict = pDict; | 26 } // namespace |
| 29 m_Type = Unknown; | 27 |
| 30 m_pForm = pForm; | 28 CPDF_FormField::CPDF_FormField(CPDF_InterForm* pForm, CPDF_Dictionary* pDict) |
| 31 m_pFont = NULL; | 29 : m_Type(Unknown), |
| 32 m_FontSize = 0; | 30 m_pForm(pForm), |
| 31 m_pDict(pDict), | |
| 32 m_FontSize(0), | |
| 33 m_pFont(nullptr) { | |
| 33 SyncFieldFlags(); | 34 SyncFieldFlags(); |
| 34 } | 35 } |
| 36 | |
| 35 CPDF_FormField::~CPDF_FormField() {} | 37 CPDF_FormField::~CPDF_FormField() {} |
| 38 | |
| 36 void CPDF_FormField::SyncFieldFlags() { | 39 void CPDF_FormField::SyncFieldFlags() { |
| 37 CFX_ByteString type_name = FPDF_GetFieldAttr(m_pDict, "FT") | 40 CFX_ByteString type_name = FPDF_GetFieldAttr(m_pDict, "FT") |
| 38 ? FPDF_GetFieldAttr(m_pDict, "FT")->GetString() | 41 ? FPDF_GetFieldAttr(m_pDict, "FT")->GetString() |
| 39 : CFX_ByteString(); | 42 : CFX_ByteString(); |
| 40 uint32_t flags = FPDF_GetFieldAttr(m_pDict, "Ff") | 43 uint32_t flags = FPDF_GetFieldAttr(m_pDict, "Ff") |
| 41 ? FPDF_GetFieldAttr(m_pDict, "Ff")->GetInteger() | 44 ? FPDF_GetFieldAttr(m_pDict, "Ff")->GetInteger() |
| 42 : 0; | 45 : 0; |
| 43 m_Flags = 0; | 46 m_Flags = 0; |
| 44 if (flags & 1) { | 47 if (flags & 1) { |
| 45 m_Flags |= FORMFIELD_READONLY; | 48 m_Flags |= FORMFIELD_READONLY; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 } | 101 } |
| 99 } | 102 } |
| 100 LoadDA(); | 103 LoadDA(); |
| 101 } else if (type_name == "Sig") { | 104 } else if (type_name == "Sig") { |
| 102 m_Type = Sign; | 105 m_Type = Sign; |
| 103 } | 106 } |
| 104 } | 107 } |
| 105 CFX_WideString CPDF_FormField::GetFullName() { | 108 CFX_WideString CPDF_FormField::GetFullName() { |
| 106 return ::GetFullName(m_pDict); | 109 return ::GetFullName(m_pDict); |
| 107 } | 110 } |
| 111 | |
| 108 FX_BOOL CPDF_FormField::ResetField(FX_BOOL bNotify) { | 112 FX_BOOL CPDF_FormField::ResetField(FX_BOOL bNotify) { |
| 109 switch (m_Type) { | 113 switch (m_Type) { |
| 110 case CPDF_FormField::CheckBox: | 114 case CPDF_FormField::CheckBox: |
| 111 case CPDF_FormField::RadioButton: { | 115 case CPDF_FormField::RadioButton: { |
| 112 int iCount = CountControls(); | 116 int iCount = CountControls(); |
| 113 if (iCount) { | 117 if (iCount) { |
| 114 // TODO(weili): Check whether anything special needs to be done for | 118 // TODO(weili): Check whether anything special needs to be done for |
| 115 // unison field. Otherwise, merge these branches. | 119 // unison field. Otherwise, merge these branches. |
| 116 if (PDF_FormField_IsUnison(this)) { | 120 if (PDF_FormField_IsUnison(this)) { |
| 117 for (int i = 0; i < iCount; i++) { | 121 for (int i = 0; i < iCount; i++) { |
| 118 CheckControl(i, GetControl(i)->IsDefaultChecked(), FALSE); | 122 CheckControl(i, GetControl(i)->IsDefaultChecked(), FALSE); |
| 119 } | 123 } |
| 120 } else { | 124 } else { |
| 121 for (int i = 0; i < iCount; i++) { | 125 for (int i = 0; i < iCount; i++) { |
| 122 CheckControl(i, GetControl(i)->IsDefaultChecked(), FALSE); | 126 CheckControl(i, GetControl(i)->IsDefaultChecked(), FALSE); |
| 123 } | 127 } |
| 124 } | 128 } |
| 125 } | 129 } |
| 126 if (bNotify && m_pForm->m_pFormNotify) { | 130 if (bNotify && m_pForm->m_pFormNotify) { |
| 127 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); | 131 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); |
| 128 } | 132 } |
| 129 } break; | 133 } break; |
| 130 case CPDF_FormField::ComboBox: { | 134 case CPDF_FormField::ComboBox: |
| 131 CFX_WideString csValue; | |
| 132 ClearSelection(); | |
| 133 int iIndex = GetDefaultSelectedItem(); | |
| 134 if (iIndex >= 0) { | |
| 135 csValue = GetOptionLabel(iIndex); | |
| 136 } | |
| 137 if (bNotify && m_pForm->m_pFormNotify) { | |
| 138 int iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); | |
| 139 if (iRet < 0) { | |
| 140 return FALSE; | |
| 141 } | |
| 142 } | |
| 143 SetItemSelection(iIndex, TRUE); | |
| 144 if (bNotify && m_pForm->m_pFormNotify) { | |
| 145 m_pForm->m_pFormNotify->AfterValueChange(this); | |
| 146 } | |
| 147 } break; | |
| 148 case CPDF_FormField::ListBox: { | 135 case CPDF_FormField::ListBox: { |
| 149 CFX_WideString csValue; | 136 CFX_WideString csValue; |
| 150 ClearSelection(); | 137 ClearSelection(); |
| 151 int iIndex = GetDefaultSelectedItem(); | 138 int iIndex = GetDefaultSelectedItem(); |
| 152 if (iIndex >= 0) { | 139 if (iIndex >= 0) |
| 153 csValue = GetOptionLabel(iIndex); | 140 csValue = GetOptionLabel(iIndex); |
| 154 } | 141 |
| 155 if (bNotify && m_pForm->m_pFormNotify) { | 142 if (bNotify && !NotifyListOrComboBoxBeforeChange(csValue)) |
| 156 int iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); | 143 return FALSE; |
| 157 if (iRet < 0) { | 144 |
| 158 return FALSE; | |
| 159 } | |
| 160 } | |
| 161 SetItemSelection(iIndex, TRUE); | 145 SetItemSelection(iIndex, TRUE); |
| 162 if (bNotify && m_pForm->m_pFormNotify) { | 146 if (bNotify) |
| 163 m_pForm->m_pFormNotify->AfterSelectionChange(this); | 147 NotifyListOrComboBoxAfterChange(); |
| 164 } | |
| 165 } break; | 148 } break; |
| 166 case CPDF_FormField::Text: | 149 case CPDF_FormField::Text: |
| 167 case CPDF_FormField::RichText: | 150 case CPDF_FormField::RichText: |
| 168 case CPDF_FormField::File: | 151 case CPDF_FormField::File: |
| 169 default: { | 152 default: { |
| 170 CPDF_Object* pDV = FPDF_GetFieldAttr(m_pDict, "DV"); | 153 CPDF_Object* pDV = FPDF_GetFieldAttr(m_pDict, "DV"); |
| 171 CFX_WideString csDValue; | 154 CFX_WideString csDValue; |
| 172 if (pDV) { | 155 if (pDV) |
| 173 csDValue = pDV->GetUnicodeText(); | 156 csDValue = pDV->GetUnicodeText(); |
| 174 } | 157 |
| 175 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V"); | 158 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V"); |
| 176 CFX_WideString csValue; | 159 CFX_WideString csValue; |
| 177 if (pV) { | 160 if (pV) |
| 178 csValue = pV->GetUnicodeText(); | 161 csValue = pV->GetUnicodeText(); |
| 179 } | 162 |
| 180 CPDF_Object* pRV = FPDF_GetFieldAttr(m_pDict, "RV"); | 163 CPDF_Object* pRV = FPDF_GetFieldAttr(m_pDict, "RV"); |
| 181 if (!pRV && (csDValue == csValue)) { | 164 if (!pRV && (csDValue == csValue)) |
| 182 return FALSE; | 165 return FALSE; |
| 183 } | 166 |
| 184 if (bNotify && m_pForm->m_pFormNotify) { | 167 if (bNotify && !NotifyBeforeValueChange(csDValue)) |
| 185 int iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csDValue); | 168 return FALSE; |
| 186 if (iRet < 0) { | 169 |
| 187 return FALSE; | |
| 188 } | |
| 189 } | |
| 190 if (pDV) { | 170 if (pDV) { |
| 191 CPDF_Object* pClone = pDV->Clone(); | 171 CPDF_Object* pClone = pDV->Clone(); |
| 192 if (!pClone) { | 172 if (!pClone) |
| 193 return FALSE; | 173 return FALSE; |
| 194 } | 174 |
| 195 m_pDict->SetAt("V", pClone); | 175 m_pDict->SetAt("V", pClone); |
| 196 if (pRV) { | 176 if (pRV) { |
| 197 CPDF_Object* pCloneR = pDV->Clone(); | 177 CPDF_Object* pCloneR = pDV->Clone(); |
| 198 m_pDict->SetAt("RV", pCloneR); | 178 m_pDict->SetAt("RV", pCloneR); |
| 199 } | 179 } |
| 200 } else { | 180 } else { |
| 201 m_pDict->RemoveAt("V"); | 181 m_pDict->RemoveAt("V"); |
| 202 m_pDict->RemoveAt("RV"); | 182 m_pDict->RemoveAt("RV"); |
| 203 } | 183 } |
| 204 if (bNotify && m_pForm->m_pFormNotify) { | 184 if (bNotify) |
| 205 m_pForm->m_pFormNotify->AfterValueChange(this); | 185 NotifyAfterValueChange(); |
| 206 } | |
| 207 m_pForm->m_bUpdated = TRUE; | |
| 208 } break; | 186 } break; |
| 209 } | 187 } |
| 210 return TRUE; | 188 return TRUE; |
| 211 } | 189 } |
| 190 | |
| 212 int CPDF_FormField::GetControlIndex(const CPDF_FormControl* pControl) { | 191 int CPDF_FormField::GetControlIndex(const CPDF_FormControl* pControl) { |
| 213 if (!pControl) { | 192 if (!pControl) |
| 214 return -1; | 193 return -1; |
| 215 } | 194 |
| 216 for (int i = 0; i < m_ControlList.GetSize(); i++) { | 195 for (int i = 0; i < m_ControlList.GetSize(); i++) { |
| 217 if (m_ControlList.GetAt(i) == pControl) | 196 if (m_ControlList.GetAt(i) == pControl) |
| 218 return i; | 197 return i; |
| 219 } | 198 } |
| 220 return -1; | 199 return -1; |
| 221 } | 200 } |
| 222 int CPDF_FormField::GetFieldType() { | 201 int CPDF_FormField::GetFieldType() { |
| 223 switch (m_Type) { | 202 switch (m_Type) { |
| 224 case PushButton: | 203 case PushButton: |
| 225 return FIELDTYPE_PUSHBUTTON; | 204 return FIELDTYPE_PUSHBUTTON; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 return pObj->GetString(); | 256 return pObj->GetString(); |
| 278 } | 257 } |
| 279 CFX_WideString CPDF_FormField::GetRichTextString() { | 258 CFX_WideString CPDF_FormField::GetRichTextString() { |
| 280 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "RV"); | 259 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "RV"); |
| 281 if (!pObj) { | 260 if (!pObj) { |
| 282 return L""; | 261 return L""; |
| 283 } | 262 } |
| 284 return pObj->GetUnicodeText(); | 263 return pObj->GetUnicodeText(); |
| 285 } | 264 } |
| 286 CFX_WideString CPDF_FormField::GetValue(FX_BOOL bDefault) { | 265 CFX_WideString CPDF_FormField::GetValue(FX_BOOL bDefault) { |
| 287 if (GetType() == CheckBox || GetType() == RadioButton) { | 266 if (GetType() == CheckBox || GetType() == RadioButton) |
| 288 return GetCheckValue(bDefault); | 267 return GetCheckValue(bDefault); |
| 289 } | 268 |
| 290 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, bDefault ? "DV" : "V"); | 269 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, bDefault ? "DV" : "V"); |
| 291 if (!pValue) { | 270 if (!pValue) { |
| 292 if (!bDefault) { | 271 if (!bDefault) { |
| 293 if (m_Type == RichText) { | 272 if (m_Type == RichText) { |
| 294 pValue = FPDF_GetFieldAttr(m_pDict, "V"); | 273 pValue = FPDF_GetFieldAttr(m_pDict, "V"); |
| 295 } | 274 } |
| 296 if (!pValue && m_Type != Text) { | 275 if (!pValue && m_Type != Text) { |
| 297 pValue = FPDF_GetFieldAttr(m_pDict, "DV"); | 276 pValue = FPDF_GetFieldAttr(m_pDict, "DV"); |
| 298 } | 277 } |
| 299 } | 278 } |
| 300 if (!pValue) { | 279 if (!pValue) |
| 301 return CFX_WideString(); | 280 return CFX_WideString(); |
| 302 } | |
| 303 } | 281 } |
| 304 switch (pValue->GetType()) { | 282 switch (pValue->GetType()) { |
| 305 case CPDF_Object::STRING: | 283 case CPDF_Object::STRING: |
| 306 case CPDF_Object::STREAM: | 284 case CPDF_Object::STREAM: |
| 307 return pValue->GetUnicodeText(); | 285 return pValue->GetUnicodeText(); |
| 308 case CPDF_Object::ARRAY: | 286 case CPDF_Object::ARRAY: |
| 309 pValue = pValue->AsArray()->GetDirectObjectAt(0); | 287 pValue = pValue->AsArray()->GetDirectObjectAt(0); |
| 310 if (pValue) | 288 if (pValue) |
| 311 return pValue->GetUnicodeText(); | 289 return pValue->GetUnicodeText(); |
| 312 break; | 290 break; |
| 313 default: | 291 default: |
| 314 break; | 292 break; |
| 315 } | 293 } |
| 316 return CFX_WideString(); | 294 return CFX_WideString(); |
| 317 } | 295 } |
| 296 | |
| 318 CFX_WideString CPDF_FormField::GetValue() { | 297 CFX_WideString CPDF_FormField::GetValue() { |
| 319 return GetValue(FALSE); | 298 return GetValue(FALSE); |
| 320 } | 299 } |
| 300 | |
| 321 CFX_WideString CPDF_FormField::GetDefaultValue() { | 301 CFX_WideString CPDF_FormField::GetDefaultValue() { |
| 322 return GetValue(TRUE); | 302 return GetValue(TRUE); |
| 323 } | 303 } |
| 304 | |
| 324 FX_BOOL CPDF_FormField::SetValue(const CFX_WideString& value, | 305 FX_BOOL CPDF_FormField::SetValue(const CFX_WideString& value, |
| 325 FX_BOOL bDefault, | 306 FX_BOOL bDefault, |
| 326 FX_BOOL bNotify) { | 307 FX_BOOL bNotify) { |
| 327 switch (m_Type) { | 308 switch (m_Type) { |
| 328 case CheckBox: | 309 case CheckBox: |
| 329 case RadioButton: { | 310 case RadioButton: { |
| 330 SetCheckValue(value, bDefault, bNotify); | 311 SetCheckValue(value, bDefault, bNotify); |
| 331 return TRUE; | 312 return TRUE; |
| 332 } | 313 } |
| 333 case File: | 314 case File: |
| 334 case RichText: | 315 case RichText: |
| 335 case Text: | 316 case Text: |
| 336 case ComboBox: { | 317 case ComboBox: { |
| 337 CFX_WideString csValue = value; | 318 CFX_WideString csValue = value; |
| 338 if (bNotify && m_pForm->m_pFormNotify) { | 319 if (bNotify && !NotifyBeforeValueChange(csValue)) |
| 339 int iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); | 320 return FALSE; |
| 340 if (iRet < 0) { | 321 |
| 341 return FALSE; | |
| 342 } | |
| 343 } | |
| 344 int iIndex = FindOptionValue(csValue); | 322 int iIndex = FindOptionValue(csValue); |
| 345 if (iIndex < 0) { | 323 if (iIndex < 0) { |
| 346 CFX_ByteString bsEncodeText = PDF_EncodeText(csValue); | 324 CFX_ByteString bsEncodeText = PDF_EncodeText(csValue); |
| 347 m_pDict->SetAtString(bDefault ? "DV" : "V", bsEncodeText); | 325 m_pDict->SetAtString(bDefault ? "DV" : "V", bsEncodeText); |
| 348 if (m_Type == RichText && !bDefault) { | 326 if (m_Type == RichText && !bDefault) |
| 349 m_pDict->SetAtString("RV", bsEncodeText); | 327 m_pDict->SetAtString("RV", bsEncodeText); |
| 350 } | |
| 351 m_pDict->RemoveAt("I"); | 328 m_pDict->RemoveAt("I"); |
| 352 } else { | 329 } else { |
| 353 m_pDict->SetAtString(bDefault ? "DV" : "V", PDF_EncodeText(csValue)); | 330 m_pDict->SetAtString(bDefault ? "DV" : "V", PDF_EncodeText(csValue)); |
| 354 if (bDefault) { | 331 if (!bDefault) { |
| 355 } else { | |
| 356 ClearSelection(); | 332 ClearSelection(); |
| 357 SetItemSelection(iIndex, TRUE); | 333 SetItemSelection(iIndex, TRUE); |
| 358 } | 334 } |
| 359 } | 335 } |
| 360 if (bNotify && m_pForm->m_pFormNotify) { | 336 if (bNotify) |
| 361 m_pForm->m_pFormNotify->AfterValueChange(this); | 337 NotifyAfterValueChange(); |
| 362 } | |
| 363 m_pForm->m_bUpdated = TRUE; | |
| 364 } break; | 338 } break; |
| 365 case ListBox: { | 339 case ListBox: { |
| 366 int iIndex = FindOptionValue(value); | 340 int iIndex = FindOptionValue(value); |
| 367 if (iIndex < 0) { | 341 if (iIndex < 0) |
| 368 return FALSE; | 342 return FALSE; |
| 369 } | 343 |
| 370 if (bDefault && iIndex == GetDefaultSelectedItem()) { | 344 if (bDefault && iIndex == GetDefaultSelectedItem()) |
| 371 return FALSE; | 345 return FALSE; |
| 372 } | 346 |
| 373 if (bNotify && m_pForm->m_pFormNotify) { | 347 if (bNotify && !NotifyBeforeSelectionChange(value)) |
| 374 CFX_WideString csValue = value; | 348 return FALSE; |
| 375 int iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); | 349 |
| 376 if (iRet < 0) { | 350 if (!bDefault) { |
| 377 return FALSE; | |
| 378 } | |
| 379 } | |
| 380 if (bDefault) { | |
| 381 } else { | |
| 382 ClearSelection(); | 351 ClearSelection(); |
| 383 SetItemSelection(iIndex, TRUE); | 352 SetItemSelection(iIndex, TRUE); |
| 384 } | 353 } |
| 385 if (bNotify && m_pForm->m_pFormNotify) { | 354 if (bNotify) |
| 386 m_pForm->m_pFormNotify->AfterSelectionChange(this); | 355 NotifyAfterSelectionChange(); |
| 387 } | |
| 388 m_pForm->m_bUpdated = TRUE; | |
| 389 break; | 356 break; |
| 390 } | 357 } |
| 391 default: | 358 default: |
| 392 break; | 359 break; |
| 393 } | 360 } |
| 394 if (CPDF_InterForm::m_bUpdateAP) { | |
| 395 UpdateAP(NULL); | |
| 396 } | |
| 397 return TRUE; | 361 return TRUE; |
| 398 } | 362 } |
| 363 | |
| 399 FX_BOOL CPDF_FormField::SetValue(const CFX_WideString& value, FX_BOOL bNotify) { | 364 FX_BOOL CPDF_FormField::SetValue(const CFX_WideString& value, FX_BOOL bNotify) { |
| 400 return SetValue(value, FALSE, bNotify); | 365 return SetValue(value, FALSE, bNotify); |
| 401 } | 366 } |
| 367 | |
| 402 int CPDF_FormField::GetMaxLen() { | 368 int CPDF_FormField::GetMaxLen() { |
| 403 if (CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "MaxLen")) | 369 if (CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "MaxLen")) |
| 404 return pObj->GetInteger(); | 370 return pObj->GetInteger(); |
| 405 | 371 |
| 406 for (int i = 0; i < m_ControlList.GetSize(); i++) { | 372 for (int i = 0; i < m_ControlList.GetSize(); i++) { |
| 407 CPDF_FormControl* pControl = m_ControlList.GetAt(i); | 373 CPDF_FormControl* pControl = m_ControlList.GetAt(i); |
| 408 if (!pControl) | 374 if (!pControl) |
| 409 continue; | 375 continue; |
| 410 | 376 |
| 411 CPDF_Dictionary* pWidgetDict = pControl->m_pWidgetDict; | 377 CPDF_Dictionary* pWidgetDict = pControl->m_pWidgetDict; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 460 if (csOpt == sel_value) { | 426 if (csOpt == sel_value) { |
| 461 return iOptIndex; | 427 return iOptIndex; |
| 462 } | 428 } |
| 463 } | 429 } |
| 464 for (int i = 0; i < CountOptions(); i++) { | 430 for (int i = 0; i < CountOptions(); i++) { |
| 465 if (sel_value == GetOptionValue(i)) | 431 if (sel_value == GetOptionValue(i)) |
| 466 return i; | 432 return i; |
| 467 } | 433 } |
| 468 return -1; | 434 return -1; |
| 469 } | 435 } |
| 436 | |
| 470 FX_BOOL CPDF_FormField::ClearSelection(FX_BOOL bNotify) { | 437 FX_BOOL CPDF_FormField::ClearSelection(FX_BOOL bNotify) { |
| 471 if (bNotify && m_pForm->m_pFormNotify) { | 438 if (bNotify && m_pForm->m_pFormNotify) { |
| 472 int iRet = 0; | |
| 473 CFX_WideString csValue; | 439 CFX_WideString csValue; |
| 474 int iIndex = GetSelectedIndex(0); | 440 int iIndex = GetSelectedIndex(0); |
| 475 if (iIndex >= 0) { | 441 if (iIndex >= 0) |
| 476 csValue = GetOptionLabel(iIndex); | 442 csValue = GetOptionLabel(iIndex); |
| 477 } | 443 |
| 478 if (GetType() == ListBox) { | 444 if (!NotifyListOrComboBoxBeforeChange(csValue)) |
| 479 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); | |
| 480 } | |
| 481 if (GetType() == ComboBox) { | |
| 482 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); | |
| 483 } | |
| 484 if (iRet < 0) { | |
| 485 return FALSE; | 445 return FALSE; |
| 486 } | |
| 487 } | 446 } |
| 488 m_pDict->RemoveAt("V"); | 447 m_pDict->RemoveAt("V"); |
| 489 m_pDict->RemoveAt("I"); | 448 m_pDict->RemoveAt("I"); |
| 490 if (bNotify && m_pForm->m_pFormNotify) { | 449 if (bNotify) |
| 491 if (GetType() == ListBox) { | 450 NotifyListOrComboBoxAfterChange(); |
| 492 m_pForm->m_pFormNotify->AfterSelectionChange(this); | |
| 493 } | |
| 494 if (GetType() == ComboBox) { | |
| 495 m_pForm->m_pFormNotify->AfterValueChange(this); | |
| 496 } | |
| 497 } | |
| 498 if (CPDF_InterForm::m_bUpdateAP) { | |
| 499 UpdateAP(NULL); | |
| 500 } | |
| 501 m_pForm->m_bUpdated = TRUE; | |
| 502 return TRUE; | 451 return TRUE; |
| 503 } | 452 } |
| 504 | 453 |
| 505 FX_BOOL CPDF_FormField::IsItemSelected(int index) { | 454 FX_BOOL CPDF_FormField::IsItemSelected(int index) { |
| 506 ASSERT(GetType() == ComboBox || GetType() == ListBox); | 455 ASSERT(GetType() == ComboBox || GetType() == ListBox); |
| 507 if (index < 0 || index >= CountOptions()) { | 456 if (index < 0 || index >= CountOptions()) { |
| 508 return FALSE; | 457 return FALSE; |
| 509 } | 458 } |
| 510 if (IsOptionSelected(index)) { | 459 if (IsOptionSelected(index)) { |
| 511 return TRUE; | 460 return TRUE; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 544 i == iPos) { | 493 i == iPos) { |
| 545 return TRUE; | 494 return TRUE; |
| 546 } | 495 } |
| 547 return FALSE; | 496 return FALSE; |
| 548 } | 497 } |
| 549 | 498 |
| 550 FX_BOOL CPDF_FormField::SetItemSelection(int index, | 499 FX_BOOL CPDF_FormField::SetItemSelection(int index, |
| 551 FX_BOOL bSelected, | 500 FX_BOOL bSelected, |
| 552 FX_BOOL bNotify) { | 501 FX_BOOL bNotify) { |
| 553 ASSERT(GetType() == ComboBox || GetType() == ListBox); | 502 ASSERT(GetType() == ComboBox || GetType() == ListBox); |
| 554 if (index < 0 || index >= CountOptions()) { | 503 if (index < 0 || index >= CountOptions()) |
| 555 return FALSE; | 504 return FALSE; |
| 505 | |
| 506 CFX_WideString opt_value = GetOptionValue(index); | |
| 507 if (bNotify) { | |
| 508 if (!NotifyListOrComboBoxBeforeChange(opt_value)) | |
|
Wei Li
2016/05/23 22:26:14
Nit: Merge two if stmts
Lei Zhang
2016/05/23 22:52:46
Done.
| |
| 509 return FALSE; | |
| 556 } | 510 } |
| 557 CFX_WideString opt_value = GetOptionValue(index); | 511 if (bSelected) { |
| 558 if (bNotify && m_pForm->m_pFormNotify) { | |
| 559 int iRet = 0; | |
| 560 if (GetType() == ListBox) { | 512 if (GetType() == ListBox) { |
| 561 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, opt_value); | 513 SelectOption(index, TRUE); |
| 514 if (!(m_Flags & FORMLIST_MULTISELECT)) { | |
| 515 m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); | |
| 516 } else { | |
| 517 CPDF_Array* pArray = new CPDF_Array; | |
| 518 for (int i = 0; i < CountOptions(); i++) { | |
| 519 if (i == index || IsItemSelected(i)) { | |
| 520 opt_value = GetOptionValue(i); | |
| 521 pArray->AddString(PDF_EncodeText(opt_value)); | |
| 522 } | |
| 523 } | |
| 524 m_pDict->SetAt("V", pArray); | |
| 525 } | |
| 526 } else { | |
| 527 m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); | |
| 528 CPDF_Array* pI = new CPDF_Array; | |
| 529 pI->AddInteger(index); | |
| 530 m_pDict->SetAt("I", pI); | |
| 562 } | 531 } |
| 563 if (GetType() == ComboBox) { | 532 } else { |
| 564 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, opt_value); | |
| 565 } | |
| 566 if (iRet < 0) { | |
| 567 return FALSE; | |
| 568 } | |
| 569 } | |
| 570 if (!bSelected) { | |
| 571 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); | 533 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); |
| 572 if (pValue) { | 534 if (pValue) { |
| 573 if (m_Type == ListBox) { | 535 if (GetType() == ListBox) { |
| 574 SelectOption(index, FALSE); | 536 SelectOption(index, FALSE); |
| 575 if (pValue->IsString()) { | 537 if (pValue->IsString()) { |
| 576 if (pValue->GetUnicodeText() == opt_value) { | 538 if (pValue->GetUnicodeText() == opt_value) |
| 577 m_pDict->RemoveAt("V"); | 539 m_pDict->RemoveAt("V"); |
| 578 } | |
| 579 } else if (pValue->IsArray()) { | 540 } else if (pValue->IsArray()) { |
| 580 CPDF_Array* pArray = new CPDF_Array; | 541 CPDF_Array* pArray = new CPDF_Array; |
| 581 for (int i = 0; i < CountOptions(); i++) { | 542 for (int i = 0; i < CountOptions(); i++) { |
| 582 if (i != index && IsItemSelected(i)) { | 543 if (i != index && IsItemSelected(i)) { |
| 583 opt_value = GetOptionValue(i); | 544 opt_value = GetOptionValue(i); |
| 584 pArray->AddString(PDF_EncodeText(opt_value)); | 545 pArray->AddString(PDF_EncodeText(opt_value)); |
| 585 } | 546 } |
| 586 } | 547 } |
| 587 if (pArray->GetCount() < 1) | 548 if (pArray->GetCount() < 1) |
| 588 pArray->Release(); | 549 pArray->Release(); |
| 589 else | 550 else |
| 590 m_pDict->SetAt("V", pArray); | 551 m_pDict->SetAt("V", pArray); |
| 591 } | 552 } |
| 592 } else if (m_Type == ComboBox) { | 553 } else { |
| 593 m_pDict->RemoveAt("V"); | 554 m_pDict->RemoveAt("V"); |
| 594 m_pDict->RemoveAt("I"); | 555 m_pDict->RemoveAt("I"); |
| 595 } | 556 } |
| 596 } | 557 } |
| 597 } else { | |
| 598 if (m_Type == ListBox) { | |
| 599 SelectOption(index, TRUE); | |
| 600 if (!(m_Flags & FORMLIST_MULTISELECT)) { | |
| 601 m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); | |
| 602 } else { | |
| 603 CPDF_Array* pArray = new CPDF_Array; | |
| 604 for (int i = 0; i < CountOptions(); i++) { | |
| 605 if (i == index || IsItemSelected(i)) { | |
| 606 opt_value = GetOptionValue(i); | |
| 607 pArray->AddString(PDF_EncodeText(opt_value)); | |
| 608 } | |
| 609 } | |
| 610 m_pDict->SetAt("V", pArray); | |
| 611 } | |
| 612 } else if (m_Type == ComboBox) { | |
| 613 m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); | |
| 614 CPDF_Array* pI = new CPDF_Array; | |
| 615 pI->AddInteger(index); | |
| 616 m_pDict->SetAt("I", pI); | |
| 617 } | |
| 618 } | 558 } |
| 619 if (bNotify && m_pForm->m_pFormNotify) { | 559 if (bNotify) |
| 620 if (GetType() == ListBox) { | 560 NotifyListOrComboBoxAfterChange(); |
| 621 m_pForm->m_pFormNotify->AfterSelectionChange(this); | |
| 622 } | |
| 623 if (GetType() == ComboBox) { | |
| 624 m_pForm->m_pFormNotify->AfterValueChange(this); | |
| 625 } | |
| 626 } | |
| 627 if (CPDF_InterForm::m_bUpdateAP) { | |
| 628 UpdateAP(NULL); | |
| 629 } | |
| 630 m_pForm->m_bUpdated = TRUE; | |
| 631 return TRUE; | 561 return TRUE; |
| 632 } | 562 } |
| 633 | 563 |
| 634 FX_BOOL CPDF_FormField::IsItemDefaultSelected(int index) { | 564 FX_BOOL CPDF_FormField::IsItemDefaultSelected(int index) { |
| 635 ASSERT(GetType() == ComboBox || GetType() == ListBox); | 565 ASSERT(GetType() == ComboBox || GetType() == ListBox); |
| 636 if (index < 0 || index >= CountOptions()) | 566 if (index < 0 || index >= CountOptions()) |
| 637 return FALSE; | 567 return FALSE; |
| 638 int iDVIndex = GetDefaultSelectedItem(); | 568 int iDVIndex = GetDefaultSelectedItem(); |
| 639 return iDVIndex >= 0 && iDVIndex == index; | 569 return iDVIndex >= 0 && iDVIndex == index; |
| 640 } | 570 } |
| 641 | 571 |
| 642 int CPDF_FormField::GetDefaultSelectedItem() { | 572 int CPDF_FormField::GetDefaultSelectedItem() { |
| 643 ASSERT(GetType() == ComboBox || GetType() == ListBox); | 573 ASSERT(GetType() == ComboBox || GetType() == ListBox); |
| 644 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "DV"); | 574 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "DV"); |
| 645 if (!pValue) | 575 if (!pValue) |
| 646 return -1; | 576 return -1; |
| 647 CFX_WideString csDV = pValue->GetUnicodeText(); | 577 CFX_WideString csDV = pValue->GetUnicodeText(); |
| 648 if (csDV.IsEmpty()) | 578 if (csDV.IsEmpty()) |
| 649 return -1; | 579 return -1; |
| 650 for (int i = 0; i < CountOptions(); i++) { | 580 for (int i = 0; i < CountOptions(); i++) { |
| 651 if (csDV == GetOptionValue(i)) | 581 if (csDV == GetOptionValue(i)) |
| 652 return i; | 582 return i; |
| 653 } | 583 } |
| 654 return -1; | 584 return -1; |
| 655 } | 585 } |
| 656 | 586 |
| 657 void CPDF_FormField::UpdateAP(CPDF_FormControl* pControl) { | |
| 658 if (m_Type == PushButton || m_Type == RadioButton || m_Type == CheckBox) | |
| 659 return; | |
| 660 if (!m_pForm->m_bGenerateAP) | |
| 661 return; | |
| 662 for (int i = 0; i < CountControls(); i++) { | |
| 663 CPDF_FormControl* pControl = GetControl(i); | |
| 664 FPDF_GenerateAP(m_pForm->m_pDocument, pControl->m_pWidgetDict); | |
| 665 } | |
| 666 } | |
| 667 | |
| 668 int CPDF_FormField::CountOptions() { | 587 int CPDF_FormField::CountOptions() { |
| 669 CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "Opt")); | 588 CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "Opt")); |
| 670 return pArray ? pArray->GetCount() : 0; | 589 return pArray ? pArray->GetCount() : 0; |
| 671 } | 590 } |
| 672 | 591 |
| 673 CFX_WideString CPDF_FormField::GetOptionText(int index, int sub_index) { | 592 CFX_WideString CPDF_FormField::GetOptionText(int index, int sub_index) { |
| 674 CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "Opt")); | 593 CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "Opt")); |
| 675 if (!pArray) | 594 if (!pArray) |
| 676 return CFX_WideString(); | 595 return CFX_WideString(); |
| 677 | 596 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 707 return -1; | 626 return -1; |
| 708 } | 627 } |
| 709 | 628 |
| 710 #ifdef PDF_ENABLE_XFA | 629 #ifdef PDF_ENABLE_XFA |
| 711 int CPDF_FormField::InsertOption(CFX_WideString csOptLabel, | 630 int CPDF_FormField::InsertOption(CFX_WideString csOptLabel, |
| 712 int index, | 631 int index, |
| 713 FX_BOOL bNotify) { | 632 FX_BOOL bNotify) { |
| 714 if (csOptLabel.IsEmpty()) | 633 if (csOptLabel.IsEmpty()) |
| 715 return -1; | 634 return -1; |
| 716 | 635 |
| 717 if (bNotify && m_pForm->m_pFormNotify) { | 636 if (bNotify && !NotifyListOrComboBoxBeforeChange(csOptLabel)) |
| 718 int iRet = 0; | 637 return -1; |
| 719 if (GetType() == ListBox) | |
| 720 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csOptLabel); | |
| 721 if (GetType() == ComboBox) | |
| 722 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csOptLabel); | |
| 723 if (iRet < 0) | |
| 724 return -1; | |
| 725 } | |
| 726 | 638 |
| 727 CFX_ByteString csStr = | 639 CFX_ByteString csStr = |
| 728 PDF_EncodeText(csOptLabel.c_str(), csOptLabel.GetLength()); | 640 PDF_EncodeText(csOptLabel.c_str(), csOptLabel.GetLength()); |
| 729 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "Opt"); | 641 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "Opt"); |
| 730 CPDF_Array* pOpt = ToArray(pValue); | 642 CPDF_Array* pOpt = ToArray(pValue); |
| 731 if (!pOpt) { | 643 if (!pOpt) { |
| 732 pOpt = new CPDF_Array; | 644 pOpt = new CPDF_Array; |
| 733 m_pDict->SetAt("Opt", pOpt); | 645 m_pDict->SetAt("Opt", pOpt); |
| 734 } | 646 } |
| 735 | 647 |
| 736 int iCount = (int)pOpt->GetCount(); | 648 int iCount = (int)pOpt->GetCount(); |
| 737 if (index < 0 || index >= iCount) { | 649 if (index < 0 || index >= iCount) { |
| 738 pOpt->AddString(csStr); | 650 pOpt->AddString(csStr); |
| 739 index = iCount; | 651 index = iCount; |
| 740 } else { | 652 } else { |
| 741 CPDF_String* pString = new CPDF_String(csStr, FALSE); | 653 CPDF_String* pString = new CPDF_String(csStr, FALSE); |
| 742 pOpt->InsertAt(index, pString); | 654 pOpt->InsertAt(index, pString); |
| 743 } | 655 } |
| 744 | 656 |
| 745 if (bNotify && m_pForm->m_pFormNotify) { | 657 if (bNotify) |
| 746 if (GetType() == ListBox) | 658 NotifyListOrComboBoxAfterChange(); |
| 747 m_pForm->m_pFormNotify->AfterSelectionChange(this); | |
| 748 if (GetType() == ComboBox) | |
| 749 m_pForm->m_pFormNotify->AfterValueChange(this); | |
| 750 } | |
| 751 m_pForm->m_bUpdated = TRUE; | |
| 752 return index; | 659 return index; |
| 753 } | 660 } |
| 661 | |
| 754 FX_BOOL CPDF_FormField::ClearOptions(FX_BOOL bNotify) { | 662 FX_BOOL CPDF_FormField::ClearOptions(FX_BOOL bNotify) { |
| 755 if (bNotify && m_pForm->m_pFormNotify) { | 663 if (bNotify && m_pForm->m_pFormNotify) { |
| 756 int iRet = 0; | |
| 757 CFX_WideString csValue; | 664 CFX_WideString csValue; |
| 758 int iIndex = GetSelectedIndex(0); | 665 int iIndex = GetSelectedIndex(0); |
| 759 if (iIndex >= 0) | 666 if (iIndex >= 0) |
| 760 csValue = GetOptionLabel(iIndex); | 667 csValue = GetOptionLabel(iIndex); |
| 761 if (GetType() == ListBox) | 668 if (!NotifyListOrComboBoxBeforeChange(csValue)) |
| 762 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); | |
| 763 if (GetType() == ComboBox) | |
| 764 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); | |
| 765 if (iRet < 0) | |
| 766 return FALSE; | 669 return FALSE; |
| 767 } | 670 } |
| 768 | 671 |
| 769 m_pDict->RemoveAt("Opt"); | 672 m_pDict->RemoveAt("Opt"); |
| 770 m_pDict->RemoveAt("V"); | 673 m_pDict->RemoveAt("V"); |
| 771 m_pDict->RemoveAt("DV"); | 674 m_pDict->RemoveAt("DV"); |
| 772 m_pDict->RemoveAt("I"); | 675 m_pDict->RemoveAt("I"); |
| 773 m_pDict->RemoveAt("TI"); | 676 m_pDict->RemoveAt("TI"); |
| 774 | 677 |
| 775 if (bNotify && m_pForm->m_pFormNotify) { | 678 if (bNotify) |
| 776 if (GetType() == ListBox) | 679 NotifyListOrComboBoxAfterChange(); |
| 777 m_pForm->m_pFormNotify->AfterSelectionChange(this); | |
| 778 if (GetType() == ComboBox) | |
| 779 m_pForm->m_pFormNotify->AfterValueChange(this); | |
| 780 } | |
| 781 | 680 |
| 782 m_pForm->m_bUpdated = TRUE; | |
| 783 return TRUE; | 681 return TRUE; |
| 784 } | 682 } |
| 785 #endif // PDF_ENABLE_XFA | 683 #endif // PDF_ENABLE_XFA |
| 684 | |
| 786 FX_BOOL CPDF_FormField::CheckControl(int iControlIndex, | 685 FX_BOOL CPDF_FormField::CheckControl(int iControlIndex, |
| 787 bool bChecked, | 686 bool bChecked, |
| 788 bool bNotify) { | 687 bool bNotify) { |
| 789 ASSERT(GetType() == CheckBox || GetType() == RadioButton); | 688 ASSERT(GetType() == CheckBox || GetType() == RadioButton); |
| 790 CPDF_FormControl* pControl = GetControl(iControlIndex); | 689 CPDF_FormControl* pControl = GetControl(iControlIndex); |
| 791 if (!pControl) { | 690 if (!pControl) { |
| 792 return FALSE; | 691 return FALSE; |
| 793 } | 692 } |
| 794 if (!bChecked && pControl->IsChecked() == bChecked) { | 693 if (!bChecked && pControl->IsChecked() == bChecked) { |
| 795 return FALSE; | 694 return FALSE; |
| 796 } | 695 } |
| 797 CFX_WideString csWExport = pControl->GetExportValue(); | 696 CFX_WideString csWExport = pControl->GetExportValue(); |
| 798 CFX_ByteString csBExport = PDF_EncodeText(csWExport); | 697 CFX_ByteString csBExport = PDF_EncodeText(csWExport); |
| 799 int iCount = CountControls(); | 698 int iCount = CountControls(); |
| 800 FX_BOOL bUnison = PDF_FormField_IsUnison(this); | 699 bool bUnison = PDF_FormField_IsUnison(this); |
| 801 for (int i = 0; i < iCount; i++) { | 700 for (int i = 0; i < iCount; i++) { |
| 802 CPDF_FormControl* pCtrl = GetControl(i); | 701 CPDF_FormControl* pCtrl = GetControl(i); |
| 803 if (bUnison) { | 702 if (bUnison) { |
| 804 CFX_WideString csEValue = pCtrl->GetExportValue(); | 703 CFX_WideString csEValue = pCtrl->GetExportValue(); |
| 805 if (csEValue == csWExport) { | 704 if (csEValue == csWExport) { |
| 806 if (pCtrl->GetOnStateName() == pControl->GetOnStateName()) { | 705 if (pCtrl->GetOnStateName() == pControl->GetOnStateName()) { |
| 807 pCtrl->CheckControl(bChecked); | 706 pCtrl->CheckControl(bChecked); |
| 808 } else if (bChecked) { | 707 } else if (bChecked) { |
| 809 pCtrl->CheckControl(FALSE); | 708 pCtrl->CheckControl(FALSE); |
| 810 } | 709 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 831 } | 730 } |
| 832 if (csV == csBExport) { | 731 if (csV == csBExport) { |
| 833 m_pDict->SetAtName("V", "Off"); | 732 m_pDict->SetAtName("V", "Off"); |
| 834 } | 733 } |
| 835 } | 734 } |
| 836 } else if (bChecked) { | 735 } else if (bChecked) { |
| 837 CFX_ByteString csIndex; | 736 CFX_ByteString csIndex; |
| 838 csIndex.Format("%d", iControlIndex); | 737 csIndex.Format("%d", iControlIndex); |
| 839 m_pDict->SetAtName("V", csIndex); | 738 m_pDict->SetAtName("V", csIndex); |
| 840 } | 739 } |
| 841 if (bNotify && m_pForm->m_pFormNotify) { | 740 if (bNotify && m_pForm->m_pFormNotify) |
| 842 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); | 741 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); |
| 843 } | |
| 844 m_pForm->m_bUpdated = TRUE; | |
| 845 return TRUE; | 742 return TRUE; |
| 846 } | 743 } |
| 744 | |
| 847 CFX_WideString CPDF_FormField::GetCheckValue(FX_BOOL bDefault) { | 745 CFX_WideString CPDF_FormField::GetCheckValue(FX_BOOL bDefault) { |
| 848 ASSERT(GetType() == CheckBox || GetType() == RadioButton); | 746 ASSERT(GetType() == CheckBox || GetType() == RadioButton); |
| 849 CFX_WideString csExport = L"Off"; | 747 CFX_WideString csExport = L"Off"; |
| 850 FX_BOOL bChecked; | |
| 851 int iCount = CountControls(); | 748 int iCount = CountControls(); |
| 852 for (int i = 0; i < iCount; i++) { | 749 for (int i = 0; i < iCount; i++) { |
| 853 CPDF_FormControl* pControl = GetControl(i); | 750 CPDF_FormControl* pControl = GetControl(i); |
| 854 if (bDefault) { | 751 FX_BOOL bChecked = |
| 855 bChecked = pControl->IsDefaultChecked(); | 752 bDefault ? pControl->IsDefaultChecked() : pControl->IsChecked(); |
| 856 } else { | |
| 857 bChecked = pControl->IsChecked(); | |
| 858 } | |
| 859 if (bChecked) { | 753 if (bChecked) { |
| 860 csExport = pControl->GetExportValue(); | 754 csExport = pControl->GetExportValue(); |
| 861 break; | 755 break; |
| 862 } | 756 } |
| 863 } | 757 } |
| 864 return csExport; | 758 return csExport; |
| 865 } | 759 } |
| 760 | |
| 866 FX_BOOL CPDF_FormField::SetCheckValue(const CFX_WideString& value, | 761 FX_BOOL CPDF_FormField::SetCheckValue(const CFX_WideString& value, |
| 867 FX_BOOL bDefault, | 762 FX_BOOL bDefault, |
| 868 FX_BOOL bNotify) { | 763 FX_BOOL bNotify) { |
| 869 ASSERT(GetType() == CheckBox || GetType() == RadioButton); | 764 ASSERT(GetType() == CheckBox || GetType() == RadioButton); |
| 870 int iCount = CountControls(); | 765 int iCount = CountControls(); |
| 871 for (int i = 0; i < iCount; i++) { | 766 for (int i = 0; i < iCount; i++) { |
| 872 CPDF_FormControl* pControl = GetControl(i); | 767 CPDF_FormControl* pControl = GetControl(i); |
| 873 CFX_WideString csExport = pControl->GetExportValue(); | 768 CFX_WideString csExport = pControl->GetExportValue(); |
| 874 if (csExport == value) { | 769 bool val = csExport == value; |
| 875 if (bDefault) { | 770 if (!bDefault) |
| 876 } else { | 771 CheckControl(GetControlIndex(pControl), val); |
| 877 CheckControl(GetControlIndex(pControl), TRUE); | 772 if (val) |
| 878 } | |
| 879 break; | 773 break; |
| 880 } else { | |
| 881 if (bDefault) { | |
| 882 } else { | |
| 883 CheckControl(GetControlIndex(pControl), FALSE); | |
| 884 } | |
| 885 } | |
| 886 } | 774 } |
| 887 if (bNotify && m_pForm->m_pFormNotify) { | 775 if (bNotify && m_pForm->m_pFormNotify) |
| 888 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); | 776 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); |
| 889 } | |
| 890 m_pForm->m_bUpdated = TRUE; | |
| 891 return TRUE; | 777 return TRUE; |
| 892 } | 778 } |
| 893 | 779 |
| 894 int CPDF_FormField::GetTopVisibleIndex() { | 780 int CPDF_FormField::GetTopVisibleIndex() { |
| 895 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TI"); | 781 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TI"); |
| 896 if (!pObj) { | 782 if (!pObj) { |
| 897 return 0; | 783 return 0; |
| 898 } | 784 } |
| 899 return pObj->GetInteger(); | 785 return pObj->GetInteger(); |
| 900 } | 786 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 936 return FALSE; | 822 return FALSE; |
| 937 } | 823 } |
| 938 size_t iCount = pArray->GetCount(); | 824 size_t iCount = pArray->GetCount(); |
| 939 for (size_t i = 0; i < iCount; i++) { | 825 for (size_t i = 0; i < iCount; i++) { |
| 940 if (pArray->GetIntegerAt(i) == iOptIndex) { | 826 if (pArray->GetIntegerAt(i) == iOptIndex) { |
| 941 return TRUE; | 827 return TRUE; |
| 942 } | 828 } |
| 943 } | 829 } |
| 944 return FALSE; | 830 return FALSE; |
| 945 } | 831 } |
| 832 | |
| 946 FX_BOOL CPDF_FormField::SelectOption(int iOptIndex, | 833 FX_BOOL CPDF_FormField::SelectOption(int iOptIndex, |
| 947 FX_BOOL bSelected, | 834 FX_BOOL bSelected, |
| 948 FX_BOOL bNotify) { | 835 FX_BOOL bNotify) { |
| 949 CPDF_Array* pArray = m_pDict->GetArrayBy("I"); | 836 CPDF_Array* pArray = m_pDict->GetArrayBy("I"); |
| 950 if (!pArray) { | 837 if (!pArray) { |
| 951 if (!bSelected) { | 838 if (!bSelected) |
| 952 return TRUE; | 839 return TRUE; |
| 953 } | 840 |
| 954 pArray = new CPDF_Array; | 841 pArray = new CPDF_Array; |
| 955 m_pDict->SetAt("I", pArray); | 842 m_pDict->SetAt("I", pArray); |
| 956 } | 843 } |
| 844 | |
| 957 FX_BOOL bReturn = FALSE; | 845 FX_BOOL bReturn = FALSE; |
| 958 for (size_t i = 0; i < pArray->GetCount(); i++) { | 846 for (size_t i = 0; i < pArray->GetCount(); i++) { |
| 959 int iFind = pArray->GetIntegerAt(i); | 847 int iFind = pArray->GetIntegerAt(i); |
| 960 if (iFind == iOptIndex) { | 848 if (iFind == iOptIndex) { |
| 961 if (bSelected) { | 849 if (bSelected) |
| 962 return TRUE; | 850 return TRUE; |
| 963 } | 851 |
| 964 if (bNotify && m_pForm->m_pFormNotify) { | 852 if (bNotify && m_pForm->m_pFormNotify) { |
| 965 int iRet = 0; | |
| 966 CFX_WideString csValue = GetOptionLabel(iOptIndex); | 853 CFX_WideString csValue = GetOptionLabel(iOptIndex); |
| 967 if (GetType() == ListBox) { | 854 if (!NotifyListOrComboBoxBeforeChange(csValue)) |
| 968 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); | |
| 969 } | |
| 970 if (GetType() == ComboBox) { | |
| 971 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); | |
| 972 } | |
| 973 if (iRet < 0) { | |
| 974 return FALSE; | 855 return FALSE; |
| 975 } | |
| 976 } | 856 } |
| 977 pArray->RemoveAt(i); | 857 pArray->RemoveAt(i); |
| 978 bReturn = TRUE; | 858 bReturn = TRUE; |
| 979 break; | 859 break; |
| 980 } else if (iFind > iOptIndex) { | 860 } |
| 981 if (!bSelected) { | 861 |
| 862 if (iFind > iOptIndex) { | |
| 863 if (!bSelected) | |
| 982 continue; | 864 continue; |
| 865 | |
| 866 if (bNotify && m_pForm->m_pFormNotify) { | |
| 867 CFX_WideString csValue = GetOptionLabel(iOptIndex); | |
| 868 if (!NotifyListOrComboBoxBeforeChange(csValue)) | |
| 869 return FALSE; | |
| 983 } | 870 } |
| 984 if (bNotify && m_pForm->m_pFormNotify) { | 871 pArray->InsertAt(i, new CPDF_Number(iOptIndex)); |
| 985 int iRet = 0; | |
| 986 CFX_WideString csValue = GetOptionLabel(iOptIndex); | |
| 987 if (GetType() == ListBox) { | |
| 988 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); | |
| 989 } | |
| 990 if (GetType() == ComboBox) { | |
| 991 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); | |
| 992 } | |
| 993 if (iRet < 0) { | |
| 994 return FALSE; | |
| 995 } | |
| 996 } | |
| 997 CPDF_Number* pNum = new CPDF_Number(iOptIndex); | |
| 998 pArray->InsertAt(i, pNum); | |
| 999 bReturn = TRUE; | 872 bReturn = TRUE; |
| 1000 break; | 873 break; |
| 1001 } | 874 } |
| 1002 } | 875 } |
| 1003 if (!bReturn) { | 876 if (!bReturn) { |
| 1004 if (bSelected) { | 877 if (bSelected) |
| 1005 pArray->AddInteger(iOptIndex); | 878 pArray->AddInteger(iOptIndex); |
| 1006 } | 879 |
| 1007 if (pArray->GetCount() == 0) { | 880 if (pArray->GetCount() == 0) |
| 1008 m_pDict->RemoveAt("I"); | 881 m_pDict->RemoveAt("I"); |
| 1009 } | |
| 1010 } | 882 } |
| 1011 if (bNotify && m_pForm->m_pFormNotify) { | 883 if (bNotify) |
| 1012 if (GetType() == ListBox) { | 884 NotifyListOrComboBoxAfterChange(); |
| 1013 m_pForm->m_pFormNotify->AfterSelectionChange(this); | 885 |
| 1014 } | |
| 1015 if (GetType() == ComboBox) { | |
| 1016 m_pForm->m_pFormNotify->AfterValueChange(this); | |
| 1017 } | |
| 1018 } | |
| 1019 m_pForm->m_bUpdated = TRUE; | |
| 1020 return TRUE; | 886 return TRUE; |
| 1021 } | 887 } |
| 888 | |
| 1022 FX_BOOL CPDF_FormField::ClearSelectedOptions(FX_BOOL bNotify) { | 889 FX_BOOL CPDF_FormField::ClearSelectedOptions(FX_BOOL bNotify) { |
| 1023 if (bNotify && m_pForm->m_pFormNotify) { | 890 if (bNotify && m_pForm->m_pFormNotify) { |
| 1024 int iRet = 0; | |
| 1025 CFX_WideString csValue; | 891 CFX_WideString csValue; |
| 1026 int iIndex = GetSelectedIndex(0); | 892 int iIndex = GetSelectedIndex(0); |
| 1027 if (iIndex >= 0) { | 893 if (iIndex >= 0) |
| 1028 csValue = GetOptionLabel(iIndex); | 894 csValue = GetOptionLabel(iIndex); |
| 1029 } | 895 |
| 1030 if (GetType() == ListBox) { | 896 if (!NotifyListOrComboBoxBeforeChange(csValue)) |
| 1031 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); | |
| 1032 } | |
| 1033 if (GetType() == ComboBox) { | |
| 1034 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); | |
| 1035 } | |
| 1036 if (iRet < 0) { | |
| 1037 return FALSE; | 897 return FALSE; |
| 1038 } | |
| 1039 } | 898 } |
| 1040 m_pDict->RemoveAt("I"); | 899 m_pDict->RemoveAt("I"); |
| 1041 if (bNotify && m_pForm->m_pFormNotify) { | 900 if (bNotify) |
| 1042 if (GetType() == ListBox) { | 901 NotifyListOrComboBoxAfterChange(); |
| 1043 m_pForm->m_pFormNotify->AfterSelectionChange(this); | 902 |
| 1044 } | |
| 1045 if (GetType() == ComboBox) { | |
| 1046 m_pForm->m_pFormNotify->AfterValueChange(this); | |
| 1047 } | |
| 1048 } | |
| 1049 m_pForm->m_bUpdated = TRUE; | |
| 1050 return TRUE; | 903 return TRUE; |
| 1051 } | 904 } |
| 905 | |
| 1052 void CPDF_FormField::LoadDA() { | 906 void CPDF_FormField::LoadDA() { |
| 1053 CFX_ByteString DA; | 907 CFX_ByteString DA; |
| 1054 if (CPDF_Object* pObj_t = FPDF_GetFieldAttr(m_pDict, "DA")) { | 908 if (CPDF_Object* pObj_t = FPDF_GetFieldAttr(m_pDict, "DA")) |
| 1055 DA = pObj_t->GetString(); | 909 DA = pObj_t->GetString(); |
| 1056 } | 910 |
| 1057 if (DA.IsEmpty() && m_pForm->m_pFormDict) { | 911 if (DA.IsEmpty() && m_pForm->m_pFormDict) |
| 1058 DA = m_pForm->m_pFormDict->GetStringBy("DA"); | 912 DA = m_pForm->m_pFormDict->GetStringBy("DA"); |
| 1059 } | 913 |
| 1060 if (DA.IsEmpty()) { | 914 if (DA.IsEmpty()) |
| 1061 return; | 915 return; |
| 1062 } | 916 |
| 917 if (!m_pForm->m_pFormDict) | |
|
Wei Li
2016/05/23 22:26:14
move this before line 911 so the condition there i
Lei Zhang
2016/05/23 22:52:46
I actually moved it to the top.
| |
| 918 return; | |
| 919 | |
| 920 CPDF_Dictionary* pDR = m_pForm->m_pFormDict->GetDictBy("DR"); | |
| 921 if (!pDR) | |
| 922 return; | |
| 923 | |
| 924 CPDF_Dictionary* pFont = pDR->GetDictBy("Font"); | |
| 925 if (!pFont) | |
| 926 return; | |
| 927 | |
| 1063 CPDF_SimpleParser syntax(DA.AsStringC()); | 928 CPDF_SimpleParser syntax(DA.AsStringC()); |
| 1064 syntax.FindTagParamFromStart("Tf", 2); | 929 syntax.FindTagParamFromStart("Tf", 2); |
| 1065 CFX_ByteString font_name(syntax.GetWord()); | 930 CFX_ByteString font_name(syntax.GetWord()); |
| 1066 CPDF_Dictionary* pFontDict = NULL; | 931 CPDF_Dictionary* pFontDict = pFont->GetDictBy(font_name); |
| 1067 if (m_pForm->m_pFormDict && m_pForm->m_pFormDict->GetDictBy("DR") && | 932 if (!pFontDict) |
| 1068 m_pForm->m_pFormDict->GetDictBy("DR")->GetDictBy("Font")) { | |
| 1069 pFontDict = m_pForm->m_pFormDict->GetDictBy("DR") | |
| 1070 ->GetDictBy("Font") | |
| 1071 ->GetDictBy(font_name); | |
| 1072 } | |
| 1073 if (!pFontDict) { | |
| 1074 return; | 933 return; |
| 1075 } | 934 |
| 1076 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict); | 935 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict); |
| 1077 m_FontSize = FX_atof(syntax.GetWord()); | 936 m_FontSize = FX_atof(syntax.GetWord()); |
| 1078 } | 937 } |
| 938 | |
| 939 bool CPDF_FormField::NotifyBeforeSelectionChange(const CFX_WideString& value) { | |
| 940 if (!m_pForm->m_pFormNotify) | |
| 941 return true; | |
| 942 return m_pForm->m_pFormNotify->BeforeSelectionChange(this, value) >= 0; | |
| 943 } | |
| 944 | |
| 945 void CPDF_FormField::NotifyAfterSelectionChange() { | |
| 946 if (!m_pForm->m_pFormNotify) | |
| 947 return; | |
| 948 m_pForm->m_pFormNotify->AfterSelectionChange(this); | |
| 949 } | |
| 950 | |
| 951 bool CPDF_FormField::NotifyBeforeValueChange(const CFX_WideString& value) { | |
| 952 if (!m_pForm->m_pFormNotify) | |
| 953 return true; | |
| 954 return m_pForm->m_pFormNotify->BeforeValueChange(this, value) >= 0; | |
| 955 } | |
| 956 | |
| 957 void CPDF_FormField::NotifyAfterValueChange() { | |
| 958 if (!m_pForm->m_pFormNotify) | |
| 959 return; | |
| 960 m_pForm->m_pFormNotify->AfterValueChange(this); | |
| 961 } | |
| 962 | |
| 963 bool CPDF_FormField::NotifyListOrComboBoxBeforeChange( | |
| 964 const CFX_WideString& value) { | |
| 965 switch (GetType()) { | |
| 966 case ListBox: | |
| 967 return NotifyBeforeSelectionChange(value); | |
| 968 case ComboBox: | |
| 969 return NotifyBeforeValueChange(value); | |
| 970 default: | |
| 971 return true; | |
| 972 } | |
| 973 } | |
| 974 | |
| 975 void CPDF_FormField::NotifyListOrComboBoxAfterChange() { | |
| 976 switch (GetType()) { | |
| 977 case ListBox: | |
| 978 NotifyAfterSelectionChange(); | |
| 979 break; | |
| 980 case ComboBox: | |
| 981 NotifyAfterValueChange(); | |
| 982 break; | |
| 983 default: | |
| 984 break; | |
| 985 } | |
| 986 } | |
| OLD | NEW |