| 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" |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 CPDF_FormControl* pControl = m_ControlList.GetAt(i); | 407 CPDF_FormControl* pControl = m_ControlList.GetAt(i); |
| 408 if (!pControl) | 408 if (!pControl) |
| 409 continue; | 409 continue; |
| 410 | 410 |
| 411 CPDF_Dictionary* pWidgetDict = pControl->m_pWidgetDict; | 411 CPDF_Dictionary* pWidgetDict = pControl->m_pWidgetDict; |
| 412 if (pWidgetDict->KeyExist("MaxLen")) | 412 if (pWidgetDict->KeyExist("MaxLen")) |
| 413 return pWidgetDict->GetIntegerBy("MaxLen"); | 413 return pWidgetDict->GetIntegerBy("MaxLen"); |
| 414 } | 414 } |
| 415 return 0; | 415 return 0; |
| 416 } | 416 } |
| 417 |
| 417 int CPDF_FormField::CountSelectedItems() { | 418 int CPDF_FormField::CountSelectedItems() { |
| 418 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); | 419 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); |
| 419 if (!pValue) { | 420 if (!pValue) { |
| 420 pValue = FPDF_GetFieldAttr(m_pDict, "I"); | 421 pValue = FPDF_GetFieldAttr(m_pDict, "I"); |
| 421 if (!pValue) | 422 if (!pValue) |
| 422 return 0; | 423 return 0; |
| 423 } | 424 } |
| 424 | 425 |
| 425 if (pValue->IsString() || pValue->IsNumber()) | 426 if (pValue->IsString() || pValue->IsNumber()) |
| 426 return pValue->GetString().IsEmpty() ? 0 : 1; | 427 return pValue->GetString().IsEmpty() ? 0 : 1; |
| 427 if (CPDF_Array* pArray = pValue->AsArray()) | 428 if (CPDF_Array* pArray = pValue->AsArray()) |
| 428 return pArray->GetCount(); | 429 return pArray->GetCount(); |
| 429 return 0; | 430 return 0; |
| 430 } | 431 } |
| 432 |
| 431 int CPDF_FormField::GetSelectedIndex(int index) { | 433 int CPDF_FormField::GetSelectedIndex(int index) { |
| 432 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); | 434 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); |
| 433 if (!pValue) { | 435 if (!pValue) { |
| 434 pValue = FPDF_GetFieldAttr(m_pDict, "I"); | 436 pValue = FPDF_GetFieldAttr(m_pDict, "I"); |
| 435 if (!pValue) | 437 if (!pValue) |
| 436 return -1; | 438 return -1; |
| 437 } | 439 } |
| 438 if (pValue->IsNumber()) | 440 if (pValue->IsNumber()) |
| 439 return pValue->GetInteger(); | 441 return pValue->GetInteger(); |
| 440 | 442 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 if (!pArray) | 532 if (!pArray) |
| 531 return FALSE; | 533 return FALSE; |
| 532 | 534 |
| 533 int iPos = -1; | 535 int iPos = -1; |
| 534 for (int j = 0; j < CountSelectedOptions(); j++) { | 536 for (int j = 0; j < CountSelectedOptions(); j++) { |
| 535 if (GetSelectedOptionIndex(j) == index) { | 537 if (GetSelectedOptionIndex(j) == index) { |
| 536 iPos = j; | 538 iPos = j; |
| 537 break; | 539 break; |
| 538 } | 540 } |
| 539 } | 541 } |
| 540 for (uint32_t i = 0; i < pArray->GetCount(); i++) | 542 for (int i = 0; i < static_cast<int>(pArray->GetCount()); i++) |
| 541 if (pArray->GetDirectObjectAt(i)->GetUnicodeText() == opt_value && | 543 if (pArray->GetDirectObjectAt(i)->GetUnicodeText() == opt_value && |
| 542 (int)i == iPos) { | 544 i == iPos) { |
| 543 return TRUE; | 545 return TRUE; |
| 544 } | 546 } |
| 545 return FALSE; | 547 return FALSE; |
| 546 } | 548 } |
| 547 | 549 |
| 548 FX_BOOL CPDF_FormField::SetItemSelection(int index, | 550 FX_BOOL CPDF_FormField::SetItemSelection(int index, |
| 549 FX_BOOL bSelected, | 551 FX_BOOL bSelected, |
| 550 FX_BOOL bNotify) { | 552 FX_BOOL bNotify) { |
| 551 ASSERT(GetType() == ComboBox || GetType() == ListBox); | 553 ASSERT(GetType() == ComboBox || GetType() == ListBox); |
| 552 if (index < 0 || index >= CountOptions()) { | 554 if (index < 0 || index >= CountOptions()) { |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 CheckControl(GetControlIndex(pControl), FALSE); | 882 CheckControl(GetControlIndex(pControl), FALSE); |
| 881 } | 883 } |
| 882 } | 884 } |
| 883 } | 885 } |
| 884 if (bNotify && m_pForm->m_pFormNotify) { | 886 if (bNotify && m_pForm->m_pFormNotify) { |
| 885 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); | 887 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); |
| 886 } | 888 } |
| 887 m_pForm->m_bUpdated = TRUE; | 889 m_pForm->m_bUpdated = TRUE; |
| 888 return TRUE; | 890 return TRUE; |
| 889 } | 891 } |
| 892 |
| 890 int CPDF_FormField::GetTopVisibleIndex() { | 893 int CPDF_FormField::GetTopVisibleIndex() { |
| 891 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TI"); | 894 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TI"); |
| 892 if (!pObj) { | 895 if (!pObj) { |
| 893 return 0; | 896 return 0; |
| 894 } | 897 } |
| 895 return pObj->GetInteger(); | 898 return pObj->GetInteger(); |
| 896 } | 899 } |
| 900 |
| 897 int CPDF_FormField::CountSelectedOptions() { | 901 int CPDF_FormField::CountSelectedOptions() { |
| 898 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "I"); | 902 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "I"); |
| 899 if (!pObj) { | 903 if (!pObj) { |
| 900 return 0; | 904 return 0; |
| 901 } | 905 } |
| 902 CPDF_Array* pArray = pObj->GetArray(); | 906 CPDF_Array* pArray = pObj->GetArray(); |
| 903 if (!pArray) { | 907 if (!pArray) { |
| 904 return 0; | 908 return 0; |
| 905 } | 909 } |
| 906 return (int)pArray->GetCount(); | 910 return static_cast<int>(pArray->GetCount()); |
| 907 } | 911 } |
| 912 |
| 908 int CPDF_FormField::GetSelectedOptionIndex(int index) { | 913 int CPDF_FormField::GetSelectedOptionIndex(int index) { |
| 909 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "I"); | 914 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "I"); |
| 910 if (!pObj) { | 915 if (!pObj) { |
| 911 return -1; | 916 return -1; |
| 912 } | 917 } |
| 913 CPDF_Array* pArray = pObj->GetArray(); | 918 CPDF_Array* pArray = pObj->GetArray(); |
| 914 if (!pArray) { | 919 if (!pArray) { |
| 915 return -1; | 920 return -1; |
| 916 } | 921 } |
| 917 int iCount = (int)pArray->GetCount(); | 922 int iCount = static_cast<int>(pArray->GetCount()); |
| 918 if (iCount > 0 && index < iCount) { | 923 if (iCount > 0 && index < iCount) { |
| 919 return pArray->GetIntegerAt(index); | 924 return pArray->GetIntegerAt(index); |
| 920 } | 925 } |
| 921 return -1; | 926 return -1; |
| 922 } | 927 } |
| 923 FX_BOOL CPDF_FormField::IsOptionSelected(int iOptIndex) { | 928 FX_BOOL CPDF_FormField::IsOptionSelected(int iOptIndex) { |
| 924 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "I"); | 929 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "I"); |
| 925 if (!pObj) { | 930 if (!pObj) { |
| 926 return FALSE; | 931 return FALSE; |
| 927 } | 932 } |
| 928 CPDF_Array* pArray = pObj->GetArray(); | 933 CPDF_Array* pArray = pObj->GetArray(); |
| 929 if (!pArray) { | 934 if (!pArray) { |
| 930 return FALSE; | 935 return FALSE; |
| 931 } | 936 } |
| 932 int iCount = (int)pArray->GetCount(); | 937 size_t iCount = pArray->GetCount(); |
| 933 for (int i = 0; i < iCount; i++) { | 938 for (size_t i = 0; i < iCount; i++) { |
| 934 if (pArray->GetIntegerAt(i) == iOptIndex) { | 939 if (pArray->GetIntegerAt(i) == iOptIndex) { |
| 935 return TRUE; | 940 return TRUE; |
| 936 } | 941 } |
| 937 } | 942 } |
| 938 return FALSE; | 943 return FALSE; |
| 939 } | 944 } |
| 940 FX_BOOL CPDF_FormField::SelectOption(int iOptIndex, | 945 FX_BOOL CPDF_FormField::SelectOption(int iOptIndex, |
| 941 FX_BOOL bSelected, | 946 FX_BOOL bSelected, |
| 942 FX_BOOL bNotify) { | 947 FX_BOOL bNotify) { |
| 943 CPDF_Array* pArray = m_pDict->GetArrayBy("I"); | 948 CPDF_Array* pArray = m_pDict->GetArrayBy("I"); |
| 944 if (!pArray) { | 949 if (!pArray) { |
| 945 if (!bSelected) { | 950 if (!bSelected) { |
| 946 return TRUE; | 951 return TRUE; |
| 947 } | 952 } |
| 948 pArray = new CPDF_Array; | 953 pArray = new CPDF_Array; |
| 949 m_pDict->SetAt("I", pArray); | 954 m_pDict->SetAt("I", pArray); |
| 950 } | 955 } |
| 951 FX_BOOL bReturn = FALSE; | 956 FX_BOOL bReturn = FALSE; |
| 952 for (int i = 0; i < (int)pArray->GetCount(); i++) { | 957 for (size_t i = 0; i < pArray->GetCount(); i++) { |
| 953 int iFind = pArray->GetIntegerAt(i); | 958 int iFind = pArray->GetIntegerAt(i); |
| 954 if (iFind == iOptIndex) { | 959 if (iFind == iOptIndex) { |
| 955 if (bSelected) { | 960 if (bSelected) { |
| 956 return TRUE; | 961 return TRUE; |
| 957 } | 962 } |
| 958 if (bNotify && m_pForm->m_pFormNotify) { | 963 if (bNotify && m_pForm->m_pFormNotify) { |
| 959 int iRet = 0; | 964 int iRet = 0; |
| 960 CFX_WideString csValue = GetOptionLabel(iOptIndex); | 965 CFX_WideString csValue = GetOptionLabel(iOptIndex); |
| 961 if (GetType() == ListBox) { | 966 if (GetType() == ListBox) { |
| 962 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); | 967 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1063 pFontDict = m_pForm->m_pFormDict->GetDictBy("DR") | 1068 pFontDict = m_pForm->m_pFormDict->GetDictBy("DR") |
| 1064 ->GetDictBy("Font") | 1069 ->GetDictBy("Font") |
| 1065 ->GetDictBy(font_name.AsByteStringC()); | 1070 ->GetDictBy(font_name.AsByteStringC()); |
| 1066 | 1071 |
| 1067 if (!pFontDict) { | 1072 if (!pFontDict) { |
| 1068 return; | 1073 return; |
| 1069 } | 1074 } |
| 1070 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict); | 1075 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict); |
| 1071 m_FontSize = FX_atof(syntax.GetWord()); | 1076 m_FontSize = FX_atof(syntax.GetWord()); |
| 1072 } | 1077 } |
| OLD | NEW |