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" |
| 8 |
7 #include "core/fpdfapi/fpdf_parser/include/cfdf_document.h" | 9 #include "core/fpdfapi/fpdf_parser/include/cfdf_document.h" |
8 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" | 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" |
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" | 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_simple_parser.h" |
12 #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" |
13 #include "core/fpdfdoc/cpvt_generateap.h" | 16 #include "core/fpdfdoc/cpvt_generateap.h" |
14 #include "core/fpdfdoc/doc_utils.h" | 17 #include "core/fpdfdoc/doc_utils.h" |
15 #include "core/fpdfdoc/include/fpdf_doc.h" | 18 #include "core/fpdfdoc/include/cpdf_formcontrol.h" |
| 19 #include "core/fpdfdoc/include/cpdf_interform.h" |
16 | 20 |
17 namespace { | 21 namespace { |
18 | 22 |
| 23 const int kFormListMultiSelect = 0x100; |
| 24 |
| 25 const int kFormComboEdit = 0x100; |
| 26 |
| 27 const int kFormFieldReadOnly = 0x01; |
| 28 const int kFormFieldRequired = 0x02; |
| 29 const int kFormFieldNoExport = 0x04; |
| 30 |
| 31 const int kFormRadioNoToggleOff = 0x100; |
| 32 const int kFormRadioUnison = 0x200; |
| 33 |
| 34 const int kFormTextMultiLine = 0x100; |
| 35 const int kFormTextPassword = 0x200; |
| 36 const int kFormTextNoScroll = 0x400; |
| 37 const int kFormTextComb = 0x800; |
| 38 |
19 bool PDF_FormField_IsUnison(CPDF_FormField* pField) { | 39 bool PDF_FormField_IsUnison(CPDF_FormField* pField) { |
20 if (pField->GetType() == CPDF_FormField::CheckBox) | 40 if (pField->GetType() == CPDF_FormField::CheckBox) |
21 return true; | 41 return true; |
22 | 42 |
23 return (pField->GetFieldFlags() & 0x2000000) != 0; | 43 return (pField->GetFieldFlags() & 0x2000000) != 0; |
24 } | 44 } |
25 | 45 |
26 } // namespace | 46 } // namespace |
27 | 47 |
28 CPDF_FormField::CPDF_FormField(CPDF_InterForm* pForm, CPDF_Dictionary* pDict) | 48 CPDF_FormField::CPDF_FormField(CPDF_InterForm* pForm, CPDF_Dictionary* pDict) |
29 : m_Type(Unknown), | 49 : m_Type(Unknown), |
30 m_pForm(pForm), | 50 m_pForm(pForm), |
31 m_pDict(pDict), | 51 m_pDict(pDict), |
32 m_FontSize(0), | 52 m_FontSize(0), |
33 m_pFont(nullptr) { | 53 m_pFont(nullptr) { |
34 SyncFieldFlags(); | 54 SyncFieldFlags(); |
35 } | 55 } |
36 | 56 |
37 CPDF_FormField::~CPDF_FormField() {} | 57 CPDF_FormField::~CPDF_FormField() {} |
38 | 58 |
39 void CPDF_FormField::SyncFieldFlags() { | 59 void CPDF_FormField::SyncFieldFlags() { |
40 CFX_ByteString type_name = FPDF_GetFieldAttr(m_pDict, "FT") | 60 CFX_ByteString type_name = FPDF_GetFieldAttr(m_pDict, "FT") |
41 ? FPDF_GetFieldAttr(m_pDict, "FT")->GetString() | 61 ? FPDF_GetFieldAttr(m_pDict, "FT")->GetString() |
42 : CFX_ByteString(); | 62 : CFX_ByteString(); |
43 uint32_t flags = FPDF_GetFieldAttr(m_pDict, "Ff") | 63 uint32_t flags = FPDF_GetFieldAttr(m_pDict, "Ff") |
44 ? FPDF_GetFieldAttr(m_pDict, "Ff")->GetInteger() | 64 ? FPDF_GetFieldAttr(m_pDict, "Ff")->GetInteger() |
45 : 0; | 65 : 0; |
46 m_Flags = 0; | 66 m_Flags = 0; |
47 if (flags & 1) { | 67 if (flags & 1) { |
48 m_Flags |= FORMFIELD_READONLY; | 68 m_Flags |= kFormFieldReadOnly; |
49 } | 69 } |
50 if (flags & 2) { | 70 if (flags & 2) { |
51 m_Flags |= FORMFIELD_REQUIRED; | 71 m_Flags |= kFormFieldRequired; |
52 } | 72 } |
53 if (flags & 4) { | 73 if (flags & 4) { |
54 m_Flags |= FORMFIELD_NOEXPORT; | 74 m_Flags |= kFormFieldNoExport; |
55 } | 75 } |
56 if (type_name == "Btn") { | 76 if (type_name == "Btn") { |
57 if (flags & 0x8000) { | 77 if (flags & 0x8000) { |
58 m_Type = RadioButton; | 78 m_Type = RadioButton; |
59 if (flags & 0x4000) { | 79 if (flags & 0x4000) { |
60 m_Flags |= FORMRADIO_NOTOGGLEOFF; | 80 m_Flags |= kFormRadioNoToggleOff; |
61 } | 81 } |
62 if (flags & 0x2000000) { | 82 if (flags & 0x2000000) { |
63 m_Flags |= FORMRADIO_UNISON; | 83 m_Flags |= kFormRadioUnison; |
64 } | 84 } |
65 } else if (flags & 0x10000) { | 85 } else if (flags & 0x10000) { |
66 m_Type = PushButton; | 86 m_Type = PushButton; |
67 } else { | 87 } else { |
68 m_Type = CheckBox; | 88 m_Type = CheckBox; |
69 } | 89 } |
70 } else if (type_name == "Tx") { | 90 } else if (type_name == "Tx") { |
71 if (flags & 0x100000) { | 91 if (flags & 0x100000) { |
72 m_Type = File; | 92 m_Type = File; |
73 } else if (flags & 0x2000000) { | 93 } else if (flags & 0x2000000) { |
74 m_Type = RichText; | 94 m_Type = RichText; |
75 } else { | 95 } else { |
76 m_Type = Text; | 96 m_Type = Text; |
77 if (flags & 0x1000) { | 97 if (flags & 0x1000) { |
78 m_Flags |= FORMTEXT_MULTILINE; | 98 m_Flags |= kFormTextMultiLine; |
79 } | 99 } |
80 if (flags & 0x2000) { | 100 if (flags & 0x2000) { |
81 m_Flags |= FORMTEXT_PASSWORD; | 101 m_Flags |= kFormTextPassword; |
82 } | 102 } |
83 if (flags & 0x800000) { | 103 if (flags & 0x800000) { |
84 m_Flags |= FORMTEXT_NOSCROLL; | 104 m_Flags |= kFormTextNoScroll; |
85 } | 105 } |
86 if (flags & 0x100000) { | 106 if (flags & 0x100000) { |
87 m_Flags |= FORMTEXT_COMB; | 107 m_Flags |= kFormTextComb; |
88 } | 108 } |
89 } | 109 } |
90 LoadDA(); | 110 LoadDA(); |
91 } else if (type_name == "Ch") { | 111 } else if (type_name == "Ch") { |
92 if (flags & 0x20000) { | 112 if (flags & 0x20000) { |
93 m_Type = ComboBox; | 113 m_Type = ComboBox; |
94 if (flags & 0x40000) { | 114 if (flags & 0x40000) { |
95 m_Flags |= FORMCOMBO_EDIT; | 115 m_Flags |= kFormComboEdit; |
96 } | 116 } |
97 } else { | 117 } else { |
98 m_Type = ListBox; | 118 m_Type = ListBox; |
99 if (flags & 0x200000) { | 119 if (flags & 0x200000) { |
100 m_Flags |= FORMLIST_MULTISELECT; | 120 m_Flags |= kFormListMultiSelect; |
101 } | 121 } |
102 } | 122 } |
103 LoadDA(); | 123 LoadDA(); |
104 } else if (type_name == "Sig") { | 124 } else if (type_name == "Sig") { |
105 m_Type = Sign; | 125 m_Type = Sign; |
106 } | 126 } |
107 } | 127 } |
108 CFX_WideString CPDF_FormField::GetFullName() const { | 128 CFX_WideString CPDF_FormField::GetFullName() const { |
109 return ::GetFullName(m_pDict); | 129 return ::GetFullName(m_pDict); |
110 } | 130 } |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 if (index < 0 || index >= CountOptions()) | 524 if (index < 0 || index >= CountOptions()) |
505 return FALSE; | 525 return FALSE; |
506 | 526 |
507 CFX_WideString opt_value = GetOptionValue(index); | 527 CFX_WideString opt_value = GetOptionValue(index); |
508 if (bNotify && !NotifyListOrComboBoxBeforeChange(opt_value)) | 528 if (bNotify && !NotifyListOrComboBoxBeforeChange(opt_value)) |
509 return FALSE; | 529 return FALSE; |
510 | 530 |
511 if (bSelected) { | 531 if (bSelected) { |
512 if (GetType() == ListBox) { | 532 if (GetType() == ListBox) { |
513 SelectOption(index, TRUE); | 533 SelectOption(index, TRUE); |
514 if (!(m_Flags & FORMLIST_MULTISELECT)) { | 534 if (!(m_Flags & kFormListMultiSelect)) { |
515 m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); | 535 m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); |
516 } else { | 536 } else { |
517 CPDF_Array* pArray = new CPDF_Array; | 537 CPDF_Array* pArray = new CPDF_Array; |
518 for (int i = 0; i < CountOptions(); i++) { | 538 for (int i = 0; i < CountOptions(); i++) { |
519 if (i == index || IsItemSelected(i)) { | 539 if (i == index || IsItemSelected(i)) { |
520 opt_value = GetOptionValue(i); | 540 opt_value = GetOptionValue(i); |
521 pArray->AddString(PDF_EncodeText(opt_value)); | 541 pArray->AddString(PDF_EncodeText(opt_value)); |
522 } | 542 } |
523 } | 543 } |
524 m_pDict->SetAt("V", pArray); | 544 m_pDict->SetAt("V", pArray); |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
958 case ListBox: | 978 case ListBox: |
959 NotifyAfterSelectionChange(); | 979 NotifyAfterSelectionChange(); |
960 break; | 980 break; |
961 case ComboBox: | 981 case ComboBox: |
962 NotifyAfterValueChange(); | 982 NotifyAfterValueChange(); |
963 break; | 983 break; |
964 default: | 984 default: |
965 break; | 985 break; |
966 } | 986 } |
967 } | 987 } |
OLD | NEW |