John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Lei Zhang | 95e854f | 2015-06-13 00:58:06 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 7 | #include "core/fpdfdoc/cpdf_formfield.h" |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 8 | |
thestig | 695aac5 | 2016-08-25 09:13:52 -0700 | [diff] [blame] | 9 | #include <set> |
| 10 | |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame^] | 11 | #include "core/fpdfapi/parser/cfdf_document.h" |
| 12 | #include "core/fpdfapi/parser/cpdf_array.h" |
| 13 | #include "core/fpdfapi/parser/cpdf_document.h" |
| 14 | #include "core/fpdfapi/parser/cpdf_number.h" |
| 15 | #include "core/fpdfapi/parser/cpdf_simple_parser.h" |
| 16 | #include "core/fpdfapi/parser/cpdf_string.h" |
| 17 | #include "core/fpdfapi/parser/fpdf_parser_decode.h" |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 18 | #include "core/fpdfdoc/cpdf_formcontrol.h" |
| 19 | #include "core/fpdfdoc/cpdf_interform.h" |
dsinclair | 777b333 | 2016-03-31 20:03:08 -0700 | [diff] [blame] | 20 | #include "core/fpdfdoc/cpvt_generateap.h" |
thestig | 695aac5 | 2016-08-25 09:13:52 -0700 | [diff] [blame] | 21 | #include "third_party/base/stl_util.h" |
Tom Sepez | eff208f | 2015-05-08 13:45:01 -0700 | [diff] [blame] | 22 | |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 23 | namespace { |
| 24 | |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 25 | const int kMaxRecursion = 32; |
| 26 | |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 27 | const int kFormListMultiSelect = 0x100; |
| 28 | |
| 29 | const int kFormComboEdit = 0x100; |
| 30 | |
| 31 | const int kFormFieldReadOnly = 0x01; |
| 32 | const int kFormFieldRequired = 0x02; |
| 33 | const int kFormFieldNoExport = 0x04; |
| 34 | |
| 35 | const int kFormRadioNoToggleOff = 0x100; |
| 36 | const int kFormRadioUnison = 0x200; |
| 37 | |
| 38 | const int kFormTextMultiLine = 0x100; |
| 39 | const int kFormTextPassword = 0x200; |
| 40 | const int kFormTextNoScroll = 0x400; |
| 41 | const int kFormTextComb = 0x800; |
| 42 | |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 43 | bool IsUnison(CPDF_FormField* pField) { |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 44 | if (pField->GetType() == CPDF_FormField::CheckBox) |
| 45 | return true; |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 46 | return (pField->GetFieldFlags() & 0x2000000) != 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 47 | } |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 48 | |
| 49 | } // namespace |
| 50 | |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 51 | CPDF_Object* FPDF_GetFieldAttr(CPDF_Dictionary* pFieldDict, |
| 52 | const FX_CHAR* name, |
| 53 | int nLevel) { |
| 54 | if (nLevel > kMaxRecursion) |
| 55 | return nullptr; |
| 56 | if (!pFieldDict) |
| 57 | return nullptr; |
| 58 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 59 | CPDF_Object* pAttr = pFieldDict->GetDirectObjectFor(name); |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 60 | if (pAttr) |
| 61 | return pAttr; |
| 62 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 63 | CPDF_Dictionary* pParent = pFieldDict->GetDictFor("Parent"); |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 64 | if (!pParent) |
| 65 | return nullptr; |
| 66 | return FPDF_GetFieldAttr(pParent, name, nLevel + 1); |
| 67 | } |
| 68 | |
| 69 | CFX_WideString FPDF_GetFullName(CPDF_Dictionary* pFieldDict) { |
| 70 | CFX_WideString full_name; |
thestig | 695aac5 | 2016-08-25 09:13:52 -0700 | [diff] [blame] | 71 | std::set<CPDF_Dictionary*> visited; |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 72 | CPDF_Dictionary* pLevel = pFieldDict; |
| 73 | while (pLevel) { |
thestig | 695aac5 | 2016-08-25 09:13:52 -0700 | [diff] [blame] | 74 | visited.insert(pLevel); |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 75 | CFX_WideString short_name = pLevel->GetUnicodeTextFor("T"); |
thestig | 695aac5 | 2016-08-25 09:13:52 -0700 | [diff] [blame] | 76 | if (!short_name.IsEmpty()) { |
| 77 | if (full_name.IsEmpty()) |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 78 | full_name = short_name; |
| 79 | else |
| 80 | full_name = short_name + L"." + full_name; |
| 81 | } |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 82 | pLevel = pLevel->GetDictFor("Parent"); |
thestig | 695aac5 | 2016-08-25 09:13:52 -0700 | [diff] [blame] | 83 | if (pdfium::ContainsKey(visited, pLevel)) |
| 84 | break; |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 85 | } |
| 86 | return full_name; |
| 87 | } |
| 88 | |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 89 | CPDF_FormField::CPDF_FormField(CPDF_InterForm* pForm, CPDF_Dictionary* pDict) |
| 90 | : m_Type(Unknown), |
| 91 | m_pForm(pForm), |
| 92 | m_pDict(pDict), |
| 93 | m_FontSize(0), |
| 94 | m_pFont(nullptr) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 95 | SyncFieldFlags(); |
| 96 | } |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 97 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 98 | CPDF_FormField::~CPDF_FormField() {} |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 99 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 100 | void CPDF_FormField::SyncFieldFlags() { |
| 101 | CFX_ByteString type_name = FPDF_GetFieldAttr(m_pDict, "FT") |
| 102 | ? FPDF_GetFieldAttr(m_pDict, "FT")->GetString() |
| 103 | : CFX_ByteString(); |
tsepez | b5e8f14 | 2016-03-25 15:18:35 -0700 | [diff] [blame] | 104 | uint32_t flags = FPDF_GetFieldAttr(m_pDict, "Ff") |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 105 | ? FPDF_GetFieldAttr(m_pDict, "Ff")->GetInteger() |
| 106 | : 0; |
| 107 | m_Flags = 0; |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 108 | if (flags & 1) |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 109 | m_Flags |= kFormFieldReadOnly; |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 110 | if (flags & 2) |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 111 | m_Flags |= kFormFieldRequired; |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 112 | if (flags & 4) |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 113 | m_Flags |= kFormFieldNoExport; |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 114 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 115 | if (type_name == "Btn") { |
| 116 | if (flags & 0x8000) { |
| 117 | m_Type = RadioButton; |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 118 | if (flags & 0x4000) |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 119 | m_Flags |= kFormRadioNoToggleOff; |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 120 | if (flags & 0x2000000) |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 121 | m_Flags |= kFormRadioUnison; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 122 | } else if (flags & 0x10000) { |
| 123 | m_Type = PushButton; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 124 | } else { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 125 | m_Type = CheckBox; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 126 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 127 | } else if (type_name == "Tx") { |
| 128 | if (flags & 0x100000) { |
| 129 | m_Type = File; |
| 130 | } else if (flags & 0x2000000) { |
| 131 | m_Type = RichText; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 132 | } else { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 133 | m_Type = Text; |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 134 | if (flags & 0x1000) |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 135 | m_Flags |= kFormTextMultiLine; |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 136 | if (flags & 0x2000) |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 137 | m_Flags |= kFormTextPassword; |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 138 | if (flags & 0x800000) |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 139 | m_Flags |= kFormTextNoScroll; |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 140 | if (flags & 0x100000) |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 141 | m_Flags |= kFormTextComb; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 142 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 143 | LoadDA(); |
| 144 | } else if (type_name == "Ch") { |
| 145 | if (flags & 0x20000) { |
| 146 | m_Type = ComboBox; |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 147 | if (flags & 0x40000) |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 148 | m_Flags |= kFormComboEdit; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 149 | } else { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 150 | m_Type = ListBox; |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 151 | if (flags & 0x200000) |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 152 | m_Flags |= kFormListMultiSelect; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 153 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 154 | LoadDA(); |
| 155 | } else if (type_name == "Sig") { |
| 156 | m_Type = Sign; |
| 157 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 158 | } |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 159 | |
tsepez | c183561 | 2016-06-08 13:30:06 -0700 | [diff] [blame] | 160 | CFX_WideString CPDF_FormField::GetFullName() const { |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 161 | return FPDF_GetFullName(m_pDict); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 162 | } |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 163 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 164 | FX_BOOL CPDF_FormField::ResetField(FX_BOOL bNotify) { |
| 165 | switch (m_Type) { |
| 166 | case CPDF_FormField::CheckBox: |
| 167 | case CPDF_FormField::RadioButton: { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 168 | int iCount = CountControls(); |
| 169 | if (iCount) { |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 170 | // TODO(weili): Check whether anything special needs to be done for |
| 171 | // unison field. Otherwise, merge these branches. |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 172 | if (IsUnison(this)) { |
| 173 | for (int i = 0; i < iCount; i++) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 174 | CheckControl(i, GetControl(i)->IsDefaultChecked(), FALSE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 175 | } else { |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 176 | for (int i = 0; i < iCount; i++) |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 177 | CheckControl(i, GetControl(i)->IsDefaultChecked(), FALSE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 178 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 179 | } |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 180 | if (bNotify && m_pForm->m_pFormNotify) |
Tom Sepez | ed5d7aa | 2016-02-02 16:02:03 -0800 | [diff] [blame] | 181 | m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 182 | break; |
| 183 | } |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 184 | case CPDF_FormField::ComboBox: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 185 | case CPDF_FormField::ListBox: { |
| 186 | CFX_WideString csValue; |
| 187 | ClearSelection(); |
| 188 | int iIndex = GetDefaultSelectedItem(); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 189 | if (iIndex >= 0) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 190 | csValue = GetOptionLabel(iIndex); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 191 | |
| 192 | if (bNotify && !NotifyListOrComboBoxBeforeChange(csValue)) |
| 193 | return FALSE; |
| 194 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 195 | SetItemSelection(iIndex, TRUE); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 196 | if (bNotify) |
| 197 | NotifyListOrComboBoxAfterChange(); |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 198 | break; |
| 199 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 200 | case CPDF_FormField::Text: |
| 201 | case CPDF_FormField::RichText: |
| 202 | case CPDF_FormField::File: |
| 203 | default: { |
| 204 | CPDF_Object* pDV = FPDF_GetFieldAttr(m_pDict, "DV"); |
| 205 | CFX_WideString csDValue; |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 206 | if (pDV) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 207 | csDValue = pDV->GetUnicodeText(); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 208 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 209 | CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V"); |
| 210 | CFX_WideString csValue; |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 211 | if (pV) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 212 | csValue = pV->GetUnicodeText(); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 213 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 214 | CPDF_Object* pRV = FPDF_GetFieldAttr(m_pDict, "RV"); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 215 | if (!pRV && (csDValue == csValue)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 216 | return FALSE; |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 217 | |
| 218 | if (bNotify && !NotifyBeforeValueChange(csDValue)) |
| 219 | return FALSE; |
| 220 | |
Lei Zhang | 412e908 | 2015-12-14 18:34:00 -0800 | [diff] [blame] | 221 | if (pDV) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 222 | CPDF_Object* pClone = pDV->Clone(); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 223 | if (!pClone) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 224 | return FALSE; |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 225 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 226 | m_pDict->SetFor("V", pClone); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 227 | if (pRV) { |
| 228 | CPDF_Object* pCloneR = pDV->Clone(); |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 229 | m_pDict->SetFor("RV", pCloneR); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 230 | } |
Lei Zhang | 412e908 | 2015-12-14 18:34:00 -0800 | [diff] [blame] | 231 | } else { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 232 | m_pDict->RemoveFor("V"); |
| 233 | m_pDict->RemoveFor("RV"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 234 | } |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 235 | if (bNotify) |
| 236 | NotifyAfterValueChange(); |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 237 | break; |
| 238 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 239 | } |
| 240 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 241 | } |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 242 | |
tsepez | c183561 | 2016-06-08 13:30:06 -0700 | [diff] [blame] | 243 | int CPDF_FormField::GetControlIndex(const CPDF_FormControl* pControl) const { |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 244 | if (!pControl) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 245 | return -1; |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 246 | |
Tom Sepez | bd573f1 | 2015-12-09 16:39:40 -0800 | [diff] [blame] | 247 | for (int i = 0; i < m_ControlList.GetSize(); i++) { |
| 248 | if (m_ControlList.GetAt(i) == pControl) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 249 | return i; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 250 | } |
| 251 | return -1; |
| 252 | } |
tsepez | c183561 | 2016-06-08 13:30:06 -0700 | [diff] [blame] | 253 | |
| 254 | int CPDF_FormField::GetFieldType() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 255 | switch (m_Type) { |
| 256 | case PushButton: |
| 257 | return FIELDTYPE_PUSHBUTTON; |
| 258 | case CheckBox: |
| 259 | return FIELDTYPE_CHECKBOX; |
| 260 | case RadioButton: |
| 261 | return FIELDTYPE_RADIOBUTTON; |
| 262 | case ComboBox: |
| 263 | return FIELDTYPE_COMBOBOX; |
| 264 | case ListBox: |
| 265 | return FIELDTYPE_LISTBOX; |
| 266 | case Text: |
| 267 | case RichText: |
| 268 | case File: |
| 269 | return FIELDTYPE_TEXTFIELD; |
| 270 | case Sign: |
| 271 | return FIELDTYPE_SIGNATURE; |
| 272 | default: |
| 273 | break; |
| 274 | } |
| 275 | return FIELDTYPE_UNKNOWN; |
| 276 | } |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 277 | |
tsepez | c183561 | 2016-06-08 13:30:06 -0700 | [diff] [blame] | 278 | CPDF_AAction CPDF_FormField::GetAdditionalAction() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 279 | CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "AA"); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 280 | return CPDF_AAction(pObj ? pObj->GetDict() : nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 281 | } |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 282 | |
tsepez | c183561 | 2016-06-08 13:30:06 -0700 | [diff] [blame] | 283 | CFX_WideString CPDF_FormField::GetAlternateName() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 284 | CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TU"); |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 285 | return pObj ? pObj->GetUnicodeText() : L""; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 286 | } |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 287 | |
tsepez | c183561 | 2016-06-08 13:30:06 -0700 | [diff] [blame] | 288 | CFX_WideString CPDF_FormField::GetMappingName() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 289 | CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TM"); |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 290 | return pObj ? pObj->GetUnicodeText() : L""; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 291 | } |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 292 | |
tsepez | c183561 | 2016-06-08 13:30:06 -0700 | [diff] [blame] | 293 | uint32_t CPDF_FormField::GetFieldFlags() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 294 | CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "Ff"); |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 295 | return pObj ? pObj->GetInteger() : 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 296 | } |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 297 | |
tsepez | c183561 | 2016-06-08 13:30:06 -0700 | [diff] [blame] | 298 | CFX_ByteString CPDF_FormField::GetDefaultStyle() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 299 | CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "DS"); |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 300 | return pObj ? pObj->GetString() : ""; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 301 | } |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 302 | |
tsepez | c183561 | 2016-06-08 13:30:06 -0700 | [diff] [blame] | 303 | CFX_WideString CPDF_FormField::GetRichTextString() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 304 | CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "RV"); |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 305 | return pObj ? pObj->GetUnicodeText() : L""; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 306 | } |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 307 | |
tsepez | c183561 | 2016-06-08 13:30:06 -0700 | [diff] [blame] | 308 | CFX_WideString CPDF_FormField::GetValue(FX_BOOL bDefault) const { |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 309 | if (GetType() == CheckBox || GetType() == RadioButton) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 310 | return GetCheckValue(bDefault); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 311 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 312 | CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, bDefault ? "DV" : "V"); |
Lei Zhang | 412e908 | 2015-12-14 18:34:00 -0800 | [diff] [blame] | 313 | if (!pValue) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 314 | if (!bDefault) { |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 315 | if (m_Type == RichText) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 316 | pValue = FPDF_GetFieldAttr(m_pDict, "V"); |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 317 | if (!pValue && m_Type != Text) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 318 | pValue = FPDF_GetFieldAttr(m_pDict, "DV"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 319 | } |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 320 | if (!pValue) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 321 | return CFX_WideString(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 322 | } |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 323 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 324 | switch (pValue->GetType()) { |
Tom Sepez | 8e5cd19 | 2016-01-26 13:20:26 -0800 | [diff] [blame] | 325 | case CPDF_Object::STRING: |
| 326 | case CPDF_Object::STREAM: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 327 | return pValue->GetUnicodeText(); |
Tom Sepez | 8e5cd19 | 2016-01-26 13:20:26 -0800 | [diff] [blame] | 328 | case CPDF_Object::ARRAY: |
tsepez | bd56755 | 2016-03-29 14:51:50 -0700 | [diff] [blame] | 329 | pValue = pValue->AsArray()->GetDirectObjectAt(0); |
Dan Sinclair | 2b11dc1 | 2015-10-22 15:02:06 -0400 | [diff] [blame] | 330 | if (pValue) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 331 | return pValue->GetUnicodeText(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 332 | break; |
Tom Sepez | 8e5cd19 | 2016-01-26 13:20:26 -0800 | [diff] [blame] | 333 | default: |
| 334 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 335 | } |
| 336 | return CFX_WideString(); |
| 337 | } |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 338 | |
tsepez | c183561 | 2016-06-08 13:30:06 -0700 | [diff] [blame] | 339 | CFX_WideString CPDF_FormField::GetValue() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 340 | return GetValue(FALSE); |
| 341 | } |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 342 | |
tsepez | c183561 | 2016-06-08 13:30:06 -0700 | [diff] [blame] | 343 | CFX_WideString CPDF_FormField::GetDefaultValue() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 344 | return GetValue(TRUE); |
| 345 | } |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 346 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 347 | FX_BOOL CPDF_FormField::SetValue(const CFX_WideString& value, |
| 348 | FX_BOOL bDefault, |
| 349 | FX_BOOL bNotify) { |
| 350 | switch (m_Type) { |
| 351 | case CheckBox: |
| 352 | case RadioButton: { |
| 353 | SetCheckValue(value, bDefault, bNotify); |
| 354 | return TRUE; |
| 355 | } |
| 356 | case File: |
| 357 | case RichText: |
| 358 | case Text: |
| 359 | case ComboBox: { |
| 360 | CFX_WideString csValue = value; |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 361 | if (bNotify && !NotifyBeforeValueChange(csValue)) |
| 362 | return FALSE; |
| 363 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 364 | int iIndex = FindOptionValue(csValue); |
| 365 | if (iIndex < 0) { |
| 366 | CFX_ByteString bsEncodeText = PDF_EncodeText(csValue); |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 367 | m_pDict->SetStringFor(bDefault ? "DV" : "V", bsEncodeText); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 368 | if (m_Type == RichText && !bDefault) |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 369 | m_pDict->SetStringFor("RV", bsEncodeText); |
| 370 | m_pDict->RemoveFor("I"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 371 | } else { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 372 | m_pDict->SetStringFor(bDefault ? "DV" : "V", PDF_EncodeText(csValue)); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 373 | if (!bDefault) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 374 | ClearSelection(); |
| 375 | SetItemSelection(iIndex, TRUE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 376 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 377 | } |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 378 | if (bNotify) |
| 379 | NotifyAfterValueChange(); |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 380 | break; |
| 381 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 382 | case ListBox: { |
| 383 | int iIndex = FindOptionValue(value); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 384 | if (iIndex < 0) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 385 | return FALSE; |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 386 | |
| 387 | if (bDefault && iIndex == GetDefaultSelectedItem()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 388 | return FALSE; |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 389 | |
| 390 | if (bNotify && !NotifyBeforeSelectionChange(value)) |
| 391 | return FALSE; |
| 392 | |
| 393 | if (!bDefault) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 394 | ClearSelection(); |
| 395 | SetItemSelection(iIndex, TRUE); |
| 396 | } |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 397 | if (bNotify) |
| 398 | NotifyAfterSelectionChange(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 399 | break; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 400 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 401 | default: |
| 402 | break; |
| 403 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 404 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 405 | } |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 406 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 407 | FX_BOOL CPDF_FormField::SetValue(const CFX_WideString& value, FX_BOOL bNotify) { |
| 408 | return SetValue(value, FALSE, bNotify); |
| 409 | } |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 410 | |
tsepez | c183561 | 2016-06-08 13:30:06 -0700 | [diff] [blame] | 411 | int CPDF_FormField::GetMaxLen() const { |
Tom Sepez | bd573f1 | 2015-12-09 16:39:40 -0800 | [diff] [blame] | 412 | if (CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "MaxLen")) |
| 413 | return pObj->GetInteger(); |
| 414 | |
| 415 | for (int i = 0; i < m_ControlList.GetSize(); i++) { |
| 416 | CPDF_FormControl* pControl = m_ControlList.GetAt(i); |
| 417 | if (!pControl) |
| 418 | continue; |
| 419 | |
| 420 | CPDF_Dictionary* pWidgetDict = pControl->m_pWidgetDict; |
| 421 | if (pWidgetDict->KeyExist("MaxLen")) |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 422 | return pWidgetDict->GetIntegerFor("MaxLen"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 423 | } |
Tom Sepez | bd573f1 | 2015-12-09 16:39:40 -0800 | [diff] [blame] | 424 | return 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 425 | } |
Wei Li | e1aebd4 | 2016-04-11 10:02:09 -0700 | [diff] [blame] | 426 | |
tsepez | c183561 | 2016-06-08 13:30:06 -0700 | [diff] [blame] | 427 | int CPDF_FormField::CountSelectedItems() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 428 | CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); |
Dan Sinclair | 2b11dc1 | 2015-10-22 15:02:06 -0400 | [diff] [blame] | 429 | if (!pValue) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 430 | pValue = FPDF_GetFieldAttr(m_pDict, "I"); |
Dan Sinclair | 2b11dc1 | 2015-10-22 15:02:06 -0400 | [diff] [blame] | 431 | if (!pValue) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 432 | return 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 433 | } |
Dan Sinclair | 316eb86 | 2015-10-21 13:29:23 -0400 | [diff] [blame] | 434 | |
| 435 | if (pValue->IsString() || pValue->IsNumber()) |
| 436 | return pValue->GetString().IsEmpty() ? 0 : 1; |
Dan Sinclair | 2b11dc1 | 2015-10-22 15:02:06 -0400 | [diff] [blame] | 437 | if (CPDF_Array* pArray = pValue->AsArray()) |
| 438 | return pArray->GetCount(); |
| 439 | return 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 440 | } |
Wei Li | e1aebd4 | 2016-04-11 10:02:09 -0700 | [diff] [blame] | 441 | |
tsepez | c183561 | 2016-06-08 13:30:06 -0700 | [diff] [blame] | 442 | int CPDF_FormField::GetSelectedIndex(int index) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 443 | CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); |
Dan Sinclair | 2b11dc1 | 2015-10-22 15:02:06 -0400 | [diff] [blame] | 444 | if (!pValue) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 445 | pValue = FPDF_GetFieldAttr(m_pDict, "I"); |
Dan Sinclair | 2b11dc1 | 2015-10-22 15:02:06 -0400 | [diff] [blame] | 446 | if (!pValue) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 447 | return -1; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 448 | } |
Dan Sinclair | 43ce903 | 2015-10-21 11:07:42 -0400 | [diff] [blame] | 449 | if (pValue->IsNumber()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 450 | return pValue->GetInteger(); |
Dan Sinclair | 43ce903 | 2015-10-21 11:07:42 -0400 | [diff] [blame] | 451 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 452 | CFX_WideString sel_value; |
Dan Sinclair | 316eb86 | 2015-10-21 13:29:23 -0400 | [diff] [blame] | 453 | if (pValue->IsString()) { |
| 454 | if (index != 0) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 455 | return -1; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 456 | sel_value = pValue->GetUnicodeText(); |
| 457 | } else { |
Dan Sinclair | 2b11dc1 | 2015-10-22 15:02:06 -0400 | [diff] [blame] | 458 | CPDF_Array* pArray = pValue->AsArray(); |
| 459 | if (!pArray || index < 0) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 460 | return -1; |
Dan Sinclair | 2b11dc1 | 2015-10-22 15:02:06 -0400 | [diff] [blame] | 461 | |
tsepez | bd56755 | 2016-03-29 14:51:50 -0700 | [diff] [blame] | 462 | CPDF_Object* elementValue = pArray->GetDirectObjectAt(index); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 463 | sel_value = |
| 464 | elementValue ? elementValue->GetUnicodeText() : CFX_WideString(); |
| 465 | } |
| 466 | if (index < CountSelectedOptions()) { |
| 467 | int iOptIndex = GetSelectedOptionIndex(index); |
| 468 | CFX_WideString csOpt = GetOptionValue(iOptIndex); |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 469 | if (csOpt == sel_value) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 470 | return iOptIndex; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 471 | } |
Wei Li | 05d53f0 | 2016-03-29 16:42:53 -0700 | [diff] [blame] | 472 | for (int i = 0; i < CountOptions(); i++) { |
| 473 | if (sel_value == GetOptionValue(i)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 474 | return i; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 475 | } |
| 476 | return -1; |
| 477 | } |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 478 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 479 | FX_BOOL CPDF_FormField::ClearSelection(FX_BOOL bNotify) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 480 | if (bNotify && m_pForm->m_pFormNotify) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 481 | CFX_WideString csValue; |
| 482 | int iIndex = GetSelectedIndex(0); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 483 | if (iIndex >= 0) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 484 | csValue = GetOptionLabel(iIndex); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 485 | |
| 486 | if (!NotifyListOrComboBoxBeforeChange(csValue)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 487 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 488 | } |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 489 | m_pDict->RemoveFor("V"); |
| 490 | m_pDict->RemoveFor("I"); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 491 | if (bNotify) |
| 492 | NotifyListOrComboBoxAfterChange(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 493 | return TRUE; |
| 494 | } |
Wei Li | 05d53f0 | 2016-03-29 16:42:53 -0700 | [diff] [blame] | 495 | |
tsepez | c183561 | 2016-06-08 13:30:06 -0700 | [diff] [blame] | 496 | FX_BOOL CPDF_FormField::IsItemSelected(int index) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 497 | ASSERT(GetType() == ComboBox || GetType() == ListBox); |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 498 | if (index < 0 || index >= CountOptions()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 499 | return FALSE; |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 500 | if (IsOptionSelected(index)) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 501 | return TRUE; |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 502 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 503 | CFX_WideString opt_value = GetOptionValue(index); |
| 504 | CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); |
Lei Zhang | 412e908 | 2015-12-14 18:34:00 -0800 | [diff] [blame] | 505 | if (!pValue) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 506 | pValue = FPDF_GetFieldAttr(m_pDict, "I"); |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 507 | if (!pValue) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 508 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 509 | } |
Dan Sinclair | 316eb86 | 2015-10-21 13:29:23 -0400 | [diff] [blame] | 510 | |
| 511 | if (pValue->IsString()) |
Dan Sinclair | 710c909 | 2015-10-21 15:46:10 -0400 | [diff] [blame] | 512 | return pValue->GetUnicodeText() == opt_value; |
Dan Sinclair | 316eb86 | 2015-10-21 13:29:23 -0400 | [diff] [blame] | 513 | |
Dan Sinclair | 43ce903 | 2015-10-21 11:07:42 -0400 | [diff] [blame] | 514 | if (pValue->IsNumber()) { |
Dan Sinclair | 316eb86 | 2015-10-21 13:29:23 -0400 | [diff] [blame] | 515 | if (pValue->GetString().IsEmpty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 516 | return FALSE; |
Dan Sinclair | 316eb86 | 2015-10-21 13:29:23 -0400 | [diff] [blame] | 517 | return (pValue->GetInteger() == index); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 518 | } |
Dan Sinclair | 316eb86 | 2015-10-21 13:29:23 -0400 | [diff] [blame] | 519 | |
Dan Sinclair | 2b11dc1 | 2015-10-22 15:02:06 -0400 | [diff] [blame] | 520 | CPDF_Array* pArray = pValue->AsArray(); |
| 521 | if (!pArray) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 522 | return FALSE; |
Dan Sinclair | 2b11dc1 | 2015-10-22 15:02:06 -0400 | [diff] [blame] | 523 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 524 | int iPos = -1; |
| 525 | for (int j = 0; j < CountSelectedOptions(); j++) { |
| 526 | if (GetSelectedOptionIndex(j) == index) { |
| 527 | iPos = j; |
| 528 | break; |
| 529 | } |
| 530 | } |
Wei Li | e1aebd4 | 2016-04-11 10:02:09 -0700 | [diff] [blame] | 531 | for (int i = 0; i < static_cast<int>(pArray->GetCount()); i++) |
tsepez | bd56755 | 2016-03-29 14:51:50 -0700 | [diff] [blame] | 532 | if (pArray->GetDirectObjectAt(i)->GetUnicodeText() == opt_value && |
Wei Li | e1aebd4 | 2016-04-11 10:02:09 -0700 | [diff] [blame] | 533 | i == iPos) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 534 | return TRUE; |
| 535 | } |
| 536 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 537 | } |
Wei Li | 05d53f0 | 2016-03-29 16:42:53 -0700 | [diff] [blame] | 538 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 539 | FX_BOOL CPDF_FormField::SetItemSelection(int index, |
| 540 | FX_BOOL bSelected, |
| 541 | FX_BOOL bNotify) { |
| 542 | ASSERT(GetType() == ComboBox || GetType() == ListBox); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 543 | if (index < 0 || index >= CountOptions()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 544 | return FALSE; |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 545 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 546 | CFX_WideString opt_value = GetOptionValue(index); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 547 | if (bNotify && !NotifyListOrComboBoxBeforeChange(opt_value)) |
| 548 | return FALSE; |
| 549 | |
| 550 | if (bSelected) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 551 | if (GetType() == ListBox) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 552 | SelectOption(index, TRUE); |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 553 | if (!(m_Flags & kFormListMultiSelect)) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 554 | m_pDict->SetStringFor("V", PDF_EncodeText(opt_value)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 555 | } else { |
Lei Zhang | 4880d1a | 2015-12-18 17:05:11 -0800 | [diff] [blame] | 556 | CPDF_Array* pArray = new CPDF_Array; |
Wei Li | 05d53f0 | 2016-03-29 16:42:53 -0700 | [diff] [blame] | 557 | for (int i = 0; i < CountOptions(); i++) { |
| 558 | if (i == index || IsItemSelected(i)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 559 | opt_value = GetOptionValue(i); |
| 560 | pArray->AddString(PDF_EncodeText(opt_value)); |
| 561 | } |
| 562 | } |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 563 | m_pDict->SetFor("V", pArray); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 564 | } |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 565 | } else { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 566 | m_pDict->SetStringFor("V", PDF_EncodeText(opt_value)); |
Lei Zhang | 4880d1a | 2015-12-18 17:05:11 -0800 | [diff] [blame] | 567 | CPDF_Array* pI = new CPDF_Array; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 568 | pI->AddInteger(index); |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 569 | m_pDict->SetFor("I", pI); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 570 | } |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 571 | } else { |
| 572 | CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); |
| 573 | if (pValue) { |
| 574 | if (GetType() == ListBox) { |
| 575 | SelectOption(index, FALSE); |
| 576 | if (pValue->IsString()) { |
| 577 | if (pValue->GetUnicodeText() == opt_value) |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 578 | m_pDict->RemoveFor("V"); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 579 | } else if (pValue->IsArray()) { |
tsepez | 298880f | 2016-09-21 14:04:25 -0700 | [diff] [blame] | 580 | std::unique_ptr<CPDF_Array, ReleaseDeleter<CPDF_Array>> pArray( |
| 581 | new CPDF_Array); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 582 | for (int i = 0; i < CountOptions(); i++) { |
| 583 | if (i != index && IsItemSelected(i)) { |
| 584 | opt_value = GetOptionValue(i); |
| 585 | pArray->AddString(PDF_EncodeText(opt_value)); |
| 586 | } |
| 587 | } |
tsepez | 298880f | 2016-09-21 14:04:25 -0700 | [diff] [blame] | 588 | if (pArray->GetCount() > 0) |
| 589 | m_pDict->SetFor("V", pArray.release()); // std::move someday |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 590 | } |
| 591 | } else { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 592 | m_pDict->RemoveFor("V"); |
| 593 | m_pDict->RemoveFor("I"); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 594 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 595 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 596 | } |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 597 | if (bNotify) |
| 598 | NotifyListOrComboBoxAfterChange(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 599 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 600 | } |
Wei Li | 05d53f0 | 2016-03-29 16:42:53 -0700 | [diff] [blame] | 601 | |
tsepez | c183561 | 2016-06-08 13:30:06 -0700 | [diff] [blame] | 602 | FX_BOOL CPDF_FormField::IsItemDefaultSelected(int index) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 603 | ASSERT(GetType() == ComboBox || GetType() == ListBox); |
Wei Li | 05d53f0 | 2016-03-29 16:42:53 -0700 | [diff] [blame] | 604 | if (index < 0 || index >= CountOptions()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 605 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 606 | int iDVIndex = GetDefaultSelectedItem(); |
Wei Li | 05d53f0 | 2016-03-29 16:42:53 -0700 | [diff] [blame] | 607 | return iDVIndex >= 0 && iDVIndex == index; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 608 | } |
Wei Li | 05d53f0 | 2016-03-29 16:42:53 -0700 | [diff] [blame] | 609 | |
tsepez | c183561 | 2016-06-08 13:30:06 -0700 | [diff] [blame] | 610 | int CPDF_FormField::GetDefaultSelectedItem() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 611 | ASSERT(GetType() == ComboBox || GetType() == ListBox); |
| 612 | CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "DV"); |
Wei Li | 05d53f0 | 2016-03-29 16:42:53 -0700 | [diff] [blame] | 613 | if (!pValue) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 614 | return -1; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 615 | CFX_WideString csDV = pValue->GetUnicodeText(); |
Wei Li | 05d53f0 | 2016-03-29 16:42:53 -0700 | [diff] [blame] | 616 | if (csDV.IsEmpty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 617 | return -1; |
Wei Li | 05d53f0 | 2016-03-29 16:42:53 -0700 | [diff] [blame] | 618 | for (int i = 0; i < CountOptions(); i++) { |
| 619 | if (csDV == GetOptionValue(i)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 620 | return i; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 621 | } |
| 622 | return -1; |
| 623 | } |
Wei Li | 05d53f0 | 2016-03-29 16:42:53 -0700 | [diff] [blame] | 624 | |
tsepez | c183561 | 2016-06-08 13:30:06 -0700 | [diff] [blame] | 625 | int CPDF_FormField::CountOptions() const { |
Dan Sinclair | 2b11dc1 | 2015-10-22 15:02:06 -0400 | [diff] [blame] | 626 | CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "Opt")); |
| 627 | return pArray ? pArray->GetCount() : 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 628 | } |
Wei Li | 05d53f0 | 2016-03-29 16:42:53 -0700 | [diff] [blame] | 629 | |
tsepez | c183561 | 2016-06-08 13:30:06 -0700 | [diff] [blame] | 630 | CFX_WideString CPDF_FormField::GetOptionText(int index, int sub_index) const { |
Dan Sinclair | 2b11dc1 | 2015-10-22 15:02:06 -0400 | [diff] [blame] | 631 | CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "Opt")); |
| 632 | if (!pArray) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 633 | return CFX_WideString(); |
Dan Sinclair | 2b11dc1 | 2015-10-22 15:02:06 -0400 | [diff] [blame] | 634 | |
tsepez | bd56755 | 2016-03-29 14:51:50 -0700 | [diff] [blame] | 635 | CPDF_Object* pOption = pArray->GetDirectObjectAt(index); |
Dan Sinclair | 2b11dc1 | 2015-10-22 15:02:06 -0400 | [diff] [blame] | 636 | if (!pOption) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 637 | return CFX_WideString(); |
Dan Sinclair | 2b11dc1 | 2015-10-22 15:02:06 -0400 | [diff] [blame] | 638 | if (CPDF_Array* pOptionArray = pOption->AsArray()) |
tsepez | bd56755 | 2016-03-29 14:51:50 -0700 | [diff] [blame] | 639 | pOption = pOptionArray->GetDirectObjectAt(sub_index); |
Dan Sinclair | 316eb86 | 2015-10-21 13:29:23 -0400 | [diff] [blame] | 640 | |
| 641 | CPDF_String* pString = ToString(pOption); |
| 642 | return pString ? pString->GetUnicodeText() : CFX_WideString(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 643 | } |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 644 | |
tsepez | c183561 | 2016-06-08 13:30:06 -0700 | [diff] [blame] | 645 | CFX_WideString CPDF_FormField::GetOptionLabel(int index) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 646 | return GetOptionText(index, 1); |
| 647 | } |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 648 | |
tsepez | c183561 | 2016-06-08 13:30:06 -0700 | [diff] [blame] | 649 | CFX_WideString CPDF_FormField::GetOptionValue(int index) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 650 | return GetOptionText(index, 0); |
| 651 | } |
Wei Li | 05d53f0 | 2016-03-29 16:42:53 -0700 | [diff] [blame] | 652 | |
tsepez | c183561 | 2016-06-08 13:30:06 -0700 | [diff] [blame] | 653 | int CPDF_FormField::FindOption(CFX_WideString csOptLabel) const { |
Wei Li | 05d53f0 | 2016-03-29 16:42:53 -0700 | [diff] [blame] | 654 | for (int i = 0; i < CountOptions(); i++) { |
| 655 | if (GetOptionValue(i) == csOptLabel) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 656 | return i; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 657 | } |
| 658 | return -1; |
| 659 | } |
Wei Li | 05d53f0 | 2016-03-29 16:42:53 -0700 | [diff] [blame] | 660 | |
tsepez | c183561 | 2016-06-08 13:30:06 -0700 | [diff] [blame] | 661 | int CPDF_FormField::FindOptionValue(const CFX_WideString& csOptValue) const { |
Wei Li | 05d53f0 | 2016-03-29 16:42:53 -0700 | [diff] [blame] | 662 | for (int i = 0; i < CountOptions(); i++) { |
| 663 | if (GetOptionValue(i) == csOptValue) |
| 664 | return i; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 665 | } |
| 666 | return -1; |
| 667 | } |
Wei Li | 05d53f0 | 2016-03-29 16:42:53 -0700 | [diff] [blame] | 668 | |
Tom Sepez | 5c4c193 | 2015-11-25 12:15:38 -0800 | [diff] [blame] | 669 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 670 | int CPDF_FormField::InsertOption(CFX_WideString csOptLabel, |
| 671 | int index, |
| 672 | FX_BOOL bNotify) { |
| 673 | if (csOptLabel.IsEmpty()) |
| 674 | return -1; |
| 675 | |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 676 | if (bNotify && !NotifyListOrComboBoxBeforeChange(csOptLabel)) |
| 677 | return -1; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 678 | |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 679 | CFX_ByteString csStr = |
| 680 | PDF_EncodeText(csOptLabel.c_str(), csOptLabel.GetLength()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 681 | CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "Opt"); |
Lei Zhang | 4880d1a | 2015-12-18 17:05:11 -0800 | [diff] [blame] | 682 | CPDF_Array* pOpt = ToArray(pValue); |
| 683 | if (!pOpt) { |
| 684 | pOpt = new CPDF_Array; |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 685 | m_pDict->SetFor("Opt", pOpt); |
Lei Zhang | 4880d1a | 2015-12-18 17:05:11 -0800 | [diff] [blame] | 686 | } |
| 687 | |
thestig | 695aac5 | 2016-08-25 09:13:52 -0700 | [diff] [blame] | 688 | int iCount = pdfium::base::checked_cast<int, size_t>(pOpt->GetCount()); |
| 689 | if (index >= iCount) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 690 | pOpt->AddString(csStr); |
| 691 | index = iCount; |
| 692 | } else { |
Lei Zhang | 4880d1a | 2015-12-18 17:05:11 -0800 | [diff] [blame] | 693 | CPDF_String* pString = new CPDF_String(csStr, FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 694 | pOpt->InsertAt(index, pString); |
| 695 | } |
| 696 | |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 697 | if (bNotify) |
| 698 | NotifyListOrComboBoxAfterChange(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 699 | return index; |
| 700 | } |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 701 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 702 | FX_BOOL CPDF_FormField::ClearOptions(FX_BOOL bNotify) { |
Lei Zhang | 4880d1a | 2015-12-18 17:05:11 -0800 | [diff] [blame] | 703 | if (bNotify && m_pForm->m_pFormNotify) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 704 | CFX_WideString csValue; |
| 705 | int iIndex = GetSelectedIndex(0); |
| 706 | if (iIndex >= 0) |
| 707 | csValue = GetOptionLabel(iIndex); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 708 | if (!NotifyListOrComboBoxBeforeChange(csValue)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 709 | return FALSE; |
| 710 | } |
| 711 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 712 | m_pDict->RemoveFor("Opt"); |
| 713 | m_pDict->RemoveFor("V"); |
| 714 | m_pDict->RemoveFor("DV"); |
| 715 | m_pDict->RemoveFor("I"); |
| 716 | m_pDict->RemoveFor("TI"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 717 | |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 718 | if (bNotify) |
| 719 | NotifyListOrComboBoxAfterChange(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 720 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 721 | return TRUE; |
| 722 | } |
Tom Sepez | a2c42ce | 2015-11-25 15:52:28 -0800 | [diff] [blame] | 723 | #endif // PDF_ENABLE_XFA |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 724 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 725 | FX_BOOL CPDF_FormField::CheckControl(int iControlIndex, |
Tom Sepez | ed5d7aa | 2016-02-02 16:02:03 -0800 | [diff] [blame] | 726 | bool bChecked, |
| 727 | bool bNotify) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 728 | ASSERT(GetType() == CheckBox || GetType() == RadioButton); |
| 729 | CPDF_FormControl* pControl = GetControl(iControlIndex); |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 730 | if (!pControl) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 731 | return FALSE; |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 732 | if (!bChecked && pControl->IsChecked() == bChecked) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 733 | return FALSE; |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 734 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 735 | CFX_WideString csWExport = pControl->GetExportValue(); |
| 736 | CFX_ByteString csBExport = PDF_EncodeText(csWExport); |
| 737 | int iCount = CountControls(); |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 738 | bool bUnison = IsUnison(this); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 739 | for (int i = 0; i < iCount; i++) { |
| 740 | CPDF_FormControl* pCtrl = GetControl(i); |
| 741 | if (bUnison) { |
| 742 | CFX_WideString csEValue = pCtrl->GetExportValue(); |
| 743 | if (csEValue == csWExport) { |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 744 | if (pCtrl->GetOnStateName() == pControl->GetOnStateName()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 745 | pCtrl->CheckControl(bChecked); |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 746 | else if (bChecked) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 747 | pCtrl->CheckControl(FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 748 | } else if (bChecked) { |
| 749 | pCtrl->CheckControl(FALSE); |
| 750 | } |
| 751 | } else { |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 752 | if (i == iControlIndex) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 753 | pCtrl->CheckControl(bChecked); |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 754 | else if (bChecked) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 755 | pCtrl->CheckControl(FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 756 | } |
| 757 | } |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 758 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 759 | CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pDict, "Opt"); |
Dan Sinclair | 2b11dc1 | 2015-10-22 15:02:06 -0400 | [diff] [blame] | 760 | if (!ToArray(pOpt)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 761 | if (bChecked) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 762 | m_pDict->SetNameFor("V", csBExport); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 763 | } else { |
| 764 | CFX_ByteString csV; |
| 765 | CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V"); |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 766 | if (pV) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 767 | csV = pV->GetString(); |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 768 | if (csV == csBExport) |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 769 | m_pDict->SetNameFor("V", "Off"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 770 | } |
| 771 | } else if (bChecked) { |
| 772 | CFX_ByteString csIndex; |
| 773 | csIndex.Format("%d", iControlIndex); |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 774 | m_pDict->SetNameFor("V", csIndex); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 775 | } |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 776 | if (bNotify && m_pForm->m_pFormNotify) |
Tom Sepez | ed5d7aa | 2016-02-02 16:02:03 -0800 | [diff] [blame] | 777 | m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 778 | return TRUE; |
| 779 | } |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 780 | |
tsepez | c183561 | 2016-06-08 13:30:06 -0700 | [diff] [blame] | 781 | CFX_WideString CPDF_FormField::GetCheckValue(FX_BOOL bDefault) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 782 | ASSERT(GetType() == CheckBox || GetType() == RadioButton); |
| 783 | CFX_WideString csExport = L"Off"; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 784 | int iCount = CountControls(); |
| 785 | for (int i = 0; i < iCount; i++) { |
| 786 | CPDF_FormControl* pControl = GetControl(i); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 787 | FX_BOOL bChecked = |
| 788 | bDefault ? pControl->IsDefaultChecked() : pControl->IsChecked(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 789 | if (bChecked) { |
| 790 | csExport = pControl->GetExportValue(); |
| 791 | break; |
| 792 | } |
| 793 | } |
| 794 | return csExport; |
| 795 | } |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 796 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 797 | FX_BOOL CPDF_FormField::SetCheckValue(const CFX_WideString& value, |
| 798 | FX_BOOL bDefault, |
| 799 | FX_BOOL bNotify) { |
| 800 | ASSERT(GetType() == CheckBox || GetType() == RadioButton); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 801 | int iCount = CountControls(); |
| 802 | for (int i = 0; i < iCount; i++) { |
| 803 | CPDF_FormControl* pControl = GetControl(i); |
| 804 | CFX_WideString csExport = pControl->GetExportValue(); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 805 | bool val = csExport == value; |
| 806 | if (!bDefault) |
| 807 | CheckControl(GetControlIndex(pControl), val); |
| 808 | if (val) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 809 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 810 | } |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 811 | if (bNotify && m_pForm->m_pFormNotify) |
Tom Sepez | ed5d7aa | 2016-02-02 16:02:03 -0800 | [diff] [blame] | 812 | m_pForm->m_pFormNotify->AfterCheckedStatusChange(this); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 813 | return TRUE; |
| 814 | } |
Wei Li | e1aebd4 | 2016-04-11 10:02:09 -0700 | [diff] [blame] | 815 | |
tsepez | c183561 | 2016-06-08 13:30:06 -0700 | [diff] [blame] | 816 | int CPDF_FormField::GetTopVisibleIndex() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 817 | CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TI"); |
thestig | b8bf55f | 2016-05-21 21:08:05 -0700 | [diff] [blame] | 818 | return pObj ? pObj->GetInteger() : 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 819 | } |
Wei Li | e1aebd4 | 2016-04-11 10:02:09 -0700 | [diff] [blame] | 820 | |
tsepez | c183561 | 2016-06-08 13:30:06 -0700 | [diff] [blame] | 821 | int CPDF_FormField::CountSelectedOptions() const { |
thestig | b8bf55f | 2016-05-21 21:08:05 -0700 | [diff] [blame] | 822 | CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "I")); |
| 823 | return pArray ? pArray->GetCount() : 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 824 | } |
Wei Li | e1aebd4 | 2016-04-11 10:02:09 -0700 | [diff] [blame] | 825 | |
tsepez | c183561 | 2016-06-08 13:30:06 -0700 | [diff] [blame] | 826 | int CPDF_FormField::GetSelectedOptionIndex(int index) const { |
thestig | b8bf55f | 2016-05-21 21:08:05 -0700 | [diff] [blame] | 827 | CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "I")); |
| 828 | if (!pArray) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 829 | return -1; |
thestig | b8bf55f | 2016-05-21 21:08:05 -0700 | [diff] [blame] | 830 | |
| 831 | int iCount = pArray->GetCount(); |
| 832 | if (iCount < 0 || index >= iCount) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 833 | return -1; |
thestig | b8bf55f | 2016-05-21 21:08:05 -0700 | [diff] [blame] | 834 | return pArray->GetIntegerAt(index); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 835 | } |
thestig | b8bf55f | 2016-05-21 21:08:05 -0700 | [diff] [blame] | 836 | |
tsepez | c183561 | 2016-06-08 13:30:06 -0700 | [diff] [blame] | 837 | FX_BOOL CPDF_FormField::IsOptionSelected(int iOptIndex) const { |
thestig | b8bf55f | 2016-05-21 21:08:05 -0700 | [diff] [blame] | 838 | CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "I")); |
| 839 | if (!pArray) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 840 | return FALSE; |
thestig | b8bf55f | 2016-05-21 21:08:05 -0700 | [diff] [blame] | 841 | |
| 842 | for (CPDF_Object* pObj : *pArray) { |
| 843 | if (pObj->GetInteger() == iOptIndex) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 844 | return TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 845 | } |
| 846 | return FALSE; |
| 847 | } |
thestig | b8bf55f | 2016-05-21 21:08:05 -0700 | [diff] [blame] | 848 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 849 | FX_BOOL CPDF_FormField::SelectOption(int iOptIndex, |
| 850 | FX_BOOL bSelected, |
| 851 | FX_BOOL bNotify) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 852 | CPDF_Array* pArray = m_pDict->GetArrayFor("I"); |
Lei Zhang | 412e908 | 2015-12-14 18:34:00 -0800 | [diff] [blame] | 853 | if (!pArray) { |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 854 | if (!bSelected) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 855 | return TRUE; |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 856 | |
Lei Zhang | 4880d1a | 2015-12-18 17:05:11 -0800 | [diff] [blame] | 857 | pArray = new CPDF_Array; |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 858 | m_pDict->SetFor("I", pArray); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 859 | } |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 860 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 861 | FX_BOOL bReturn = FALSE; |
Wei Li | e1aebd4 | 2016-04-11 10:02:09 -0700 | [diff] [blame] | 862 | for (size_t i = 0; i < pArray->GetCount(); i++) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 863 | int iFind = pArray->GetIntegerAt(i); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 864 | if (iFind == iOptIndex) { |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 865 | if (bSelected) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 866 | return TRUE; |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 867 | |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 868 | if (bNotify && m_pForm->m_pFormNotify) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 869 | CFX_WideString csValue = GetOptionLabel(iOptIndex); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 870 | if (!NotifyListOrComboBoxBeforeChange(csValue)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 871 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 872 | } |
| 873 | pArray->RemoveAt(i); |
| 874 | bReturn = TRUE; |
| 875 | break; |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | if (iFind > iOptIndex) { |
| 879 | if (!bSelected) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 880 | continue; |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 881 | |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 882 | if (bNotify && m_pForm->m_pFormNotify) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 883 | CFX_WideString csValue = GetOptionLabel(iOptIndex); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 884 | if (!NotifyListOrComboBoxBeforeChange(csValue)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 885 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 886 | } |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 887 | pArray->InsertAt(i, new CPDF_Number(iOptIndex)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 888 | bReturn = TRUE; |
| 889 | break; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 890 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 891 | } |
| 892 | if (!bReturn) { |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 893 | if (bSelected) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 894 | pArray->AddInteger(iOptIndex); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 895 | |
jaepark | 727da4f | 2016-08-08 15:45:58 -0700 | [diff] [blame] | 896 | if (pArray->IsEmpty()) |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 897 | m_pDict->RemoveFor("I"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 898 | } |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 899 | if (bNotify) |
| 900 | NotifyListOrComboBoxAfterChange(); |
| 901 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 902 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 903 | } |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 904 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 905 | FX_BOOL CPDF_FormField::ClearSelectedOptions(FX_BOOL bNotify) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 906 | if (bNotify && m_pForm->m_pFormNotify) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 907 | CFX_WideString csValue; |
| 908 | int iIndex = GetSelectedIndex(0); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 909 | if (iIndex >= 0) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 910 | csValue = GetOptionLabel(iIndex); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 911 | |
| 912 | if (!NotifyListOrComboBoxBeforeChange(csValue)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 913 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 914 | } |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 915 | m_pDict->RemoveFor("I"); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 916 | if (bNotify) |
| 917 | NotifyListOrComboBoxAfterChange(); |
| 918 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 919 | return TRUE; |
| 920 | } |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 921 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 922 | void CPDF_FormField::LoadDA() { |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 923 | CPDF_Dictionary* pFormDict = m_pForm->m_pFormDict; |
| 924 | if (!pFormDict) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 925 | return; |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 926 | |
| 927 | CFX_ByteString DA; |
| 928 | if (CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "DA")) |
| 929 | DA = pObj->GetString(); |
| 930 | |
| 931 | if (DA.IsEmpty()) |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 932 | DA = pFormDict->GetStringFor("DA"); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 933 | |
| 934 | if (DA.IsEmpty()) |
| 935 | return; |
| 936 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 937 | CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 938 | if (!pDR) |
| 939 | return; |
| 940 | |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 941 | CPDF_Dictionary* pFont = pDR->GetDictFor("Font"); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 942 | if (!pFont) |
| 943 | return; |
| 944 | |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 945 | CPDF_SimpleParser syntax(DA.AsStringC()); |
Wei Li | 970c11e | 2016-02-16 14:26:22 -0800 | [diff] [blame] | 946 | syntax.FindTagParamFromStart("Tf", 2); |
tsepez | 71a452f | 2016-05-13 17:51:27 -0700 | [diff] [blame] | 947 | CFX_ByteString font_name(syntax.GetWord()); |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 948 | CPDF_Dictionary* pFontDict = pFont->GetDictFor(font_name); |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 949 | if (!pFontDict) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 950 | return; |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 951 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 952 | m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict); |
| 953 | m_FontSize = FX_atof(syntax.GetWord()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 954 | } |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 955 | |
| 956 | bool CPDF_FormField::NotifyBeforeSelectionChange(const CFX_WideString& value) { |
| 957 | if (!m_pForm->m_pFormNotify) |
| 958 | return true; |
| 959 | return m_pForm->m_pFormNotify->BeforeSelectionChange(this, value) >= 0; |
| 960 | } |
| 961 | |
| 962 | void CPDF_FormField::NotifyAfterSelectionChange() { |
| 963 | if (!m_pForm->m_pFormNotify) |
| 964 | return; |
| 965 | m_pForm->m_pFormNotify->AfterSelectionChange(this); |
| 966 | } |
| 967 | |
| 968 | bool CPDF_FormField::NotifyBeforeValueChange(const CFX_WideString& value) { |
| 969 | if (!m_pForm->m_pFormNotify) |
| 970 | return true; |
| 971 | return m_pForm->m_pFormNotify->BeforeValueChange(this, value) >= 0; |
| 972 | } |
| 973 | |
| 974 | void CPDF_FormField::NotifyAfterValueChange() { |
| 975 | if (!m_pForm->m_pFormNotify) |
| 976 | return; |
| 977 | m_pForm->m_pFormNotify->AfterValueChange(this); |
| 978 | } |
| 979 | |
| 980 | bool CPDF_FormField::NotifyListOrComboBoxBeforeChange( |
| 981 | const CFX_WideString& value) { |
| 982 | switch (GetType()) { |
| 983 | case ListBox: |
| 984 | return NotifyBeforeSelectionChange(value); |
| 985 | case ComboBox: |
| 986 | return NotifyBeforeValueChange(value); |
| 987 | default: |
| 988 | return true; |
| 989 | } |
| 990 | } |
| 991 | |
| 992 | void CPDF_FormField::NotifyListOrComboBoxAfterChange() { |
| 993 | switch (GetType()) { |
| 994 | case ListBox: |
| 995 | NotifyAfterSelectionChange(); |
| 996 | break; |
| 997 | case ComboBox: |
| 998 | NotifyAfterValueChange(); |
| 999 | break; |
| 1000 | default: |
| 1001 | break; |
| 1002 | } |
| 1003 | } |