blob: 8e4b465d5e04a7b46d8545ec9d4be351a4922dab [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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 Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Dan Sinclairf766ad22016-03-14 13:51:24 -04007#include "fpdfsdk/javascript/Field.h"
Tom Sepez37458412015-10-06 11:33:46 -07008
Tom Sepezb9cc7a02016-02-01 13:42:30 -08009#include <algorithm>
10#include <memory>
Dan Sinclair3ebd1212016-03-09 09:59:23 -050011#include <string>
Tom Sepezb9cc7a02016-02-01 13:42:30 -080012#include <vector>
13
dsinclairbc5e6d22016-10-04 11:08:49 -070014#include "core/fpdfapi/font/cpdf_font.h"
dsinclair41872fa2016-10-04 11:29:35 -070015#include "core/fpdfapi/page/cpdf_page.h"
dsinclair488b7ad2016-10-04 11:55:50 -070016#include "core/fpdfapi/parser/cpdf_document.h"
dsinclair1727aee2016-09-29 13:12:56 -070017#include "core/fpdfdoc/cpdf_interform.h"
dsinclair735606d2016-10-05 15:47:02 -070018#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
dsinclair114e46a2016-09-29 17:18:21 -070019#include "fpdfsdk/cpdfsdk_interform.h"
20#include "fpdfsdk/cpdfsdk_pageview.h"
21#include "fpdfsdk/cpdfsdk_widget.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040022#include "fpdfsdk/javascript/Document.h"
23#include "fpdfsdk/javascript/Icon.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040024#include "fpdfsdk/javascript/JS_Define.h"
25#include "fpdfsdk/javascript/JS_EventHandler.h"
26#include "fpdfsdk/javascript/JS_Object.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040027#include "fpdfsdk/javascript/JS_Value.h"
28#include "fpdfsdk/javascript/PublicMethods.h"
Tom Sepezd6ae2af2017-02-16 11:49:55 -080029#include "fpdfsdk/javascript/cjs_event_context.h"
dsinclair64376be2016-03-31 20:03:24 -070030#include "fpdfsdk/javascript/cjs_runtime.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040031#include "fpdfsdk/javascript/color.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070032
tonikitoo7c05a7a2016-08-17 11:08:46 -070033namespace {
34
35bool SetWidgetDisplayStatus(CPDFSDK_Widget* pWidget, int value) {
36 if (!pWidget)
37 return false;
38
39 uint32_t dwFlag = pWidget->GetFlags();
40 switch (value) {
41 case 0:
42 dwFlag &= ~ANNOTFLAG_INVISIBLE;
43 dwFlag &= ~ANNOTFLAG_HIDDEN;
44 dwFlag &= ~ANNOTFLAG_NOVIEW;
45 dwFlag |= ANNOTFLAG_PRINT;
46 break;
47 case 1:
48 dwFlag &= ~ANNOTFLAG_INVISIBLE;
49 dwFlag &= ~ANNOTFLAG_NOVIEW;
50 dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
51 break;
52 case 2:
53 dwFlag &= ~ANNOTFLAG_INVISIBLE;
54 dwFlag &= ~ANNOTFLAG_PRINT;
55 dwFlag &= ~ANNOTFLAG_HIDDEN;
56 dwFlag &= ~ANNOTFLAG_NOVIEW;
57 break;
58 case 3:
59 dwFlag |= ANNOTFLAG_NOVIEW;
60 dwFlag |= ANNOTFLAG_PRINT;
61 dwFlag &= ~ANNOTFLAG_HIDDEN;
62 break;
63 }
64
65 if (dwFlag != pWidget->GetFlags()) {
66 pWidget->SetFlags(dwFlag);
67 return true;
68 }
69
70 return false;
71}
72
73} // namespace
74
Tom Sepez04557b82017-02-16 09:43:10 -080075JSConstSpec CJS_Field::ConstSpecs[] = {{0, JSConstSpec::Number, 0, 0}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070076
Tom Sepez04557b82017-02-16 09:43:10 -080077JSPropertySpec CJS_Field::PropertySpecs[] = {
Tom Sepez4d5b8c52017-02-21 15:17:07 -080078 {"alignment", get_alignment_static, set_alignment_static},
79 {"borderStyle", get_borderStyle_static, set_borderStyle_static},
80 {"buttonAlignX", get_buttonAlignX_static, set_buttonAlignX_static},
81 {"buttonAlignY", get_buttonAlignY_static, set_buttonAlignY_static},
82 {"buttonFitBounds", get_buttonFitBounds_static, set_buttonFitBounds_static},
83 {"buttonPosition", get_buttonPosition_static, set_buttonPosition_static},
84 {"buttonScaleHow", get_buttonScaleHow_static, set_buttonScaleHow_static},
85 {"buttonScaleWhen", get_buttonScaleWhen_static, set_buttonScaleWhen_static},
86 {"calcOrderIndex", get_calcOrderIndex_static, set_calcOrderIndex_static},
87 {"charLimit", get_charLimit_static, set_charLimit_static},
88 {"comb", get_comb_static, set_comb_static},
89 {"commitOnSelChange", get_commitOnSelChange_static,
Tom Sepez04557b82017-02-16 09:43:10 -080090 set_commitOnSelChange_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -080091 {"currentValueIndices", get_currentValueIndices_static,
Tom Sepez04557b82017-02-16 09:43:10 -080092 set_currentValueIndices_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -080093 {"defaultStyle", get_defaultStyle_static, set_defaultStyle_static},
94 {"defaultValue", get_defaultValue_static, set_defaultValue_static},
95 {"doNotScroll", get_doNotScroll_static, set_doNotScroll_static},
96 {"doNotSpellCheck", get_doNotSpellCheck_static, set_doNotSpellCheck_static},
97 {"delay", get_delay_static, set_delay_static},
98 {"display", get_display_static, set_display_static},
99 {"doc", get_doc_static, set_doc_static},
100 {"editable", get_editable_static, set_editable_static},
101 {"exportValues", get_exportValues_static, set_exportValues_static},
102 {"hidden", get_hidden_static, set_hidden_static},
103 {"fileSelect", get_fileSelect_static, set_fileSelect_static},
104 {"fillColor", get_fillColor_static, set_fillColor_static},
105 {"lineWidth", get_lineWidth_static, set_lineWidth_static},
106 {"highlight", get_highlight_static, set_highlight_static},
107 {"multiline", get_multiline_static, set_multiline_static},
108 {"multipleSelection", get_multipleSelection_static,
Tom Sepez04557b82017-02-16 09:43:10 -0800109 set_multipleSelection_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800110 {"name", get_name_static, set_name_static},
111 {"numItems", get_numItems_static, set_numItems_static},
112 {"page", get_page_static, set_page_static},
113 {"password", get_password_static, set_password_static},
114 {"print", get_print_static, set_print_static},
115 {"radiosInUnison", get_radiosInUnison_static, set_radiosInUnison_static},
116 {"readonly", get_readonly_static, set_readonly_static},
117 {"rect", get_rect_static, set_rect_static},
118 {"required", get_required_static, set_required_static},
119 {"richText", get_richText_static, set_richText_static},
120 {"richValue", get_richValue_static, set_richValue_static},
121 {"rotation", get_rotation_static, set_rotation_static},
122 {"strokeColor", get_strokeColor_static, set_strokeColor_static},
123 {"style", get_style_static, set_style_static},
124 {"submitName", get_submitName_static, set_submitName_static},
125 {"textColor", get_textColor_static, set_textColor_static},
126 {"textFont", get_textFont_static, set_textFont_static},
127 {"textSize", get_textSize_static, set_textSize_static},
128 {"type", get_type_static, set_type_static},
129 {"userName", get_userName_static, set_userName_static},
130 {"value", get_value_static, set_value_static},
131 {"valueAsString", get_valueAsString_static, set_valueAsString_static},
132 {"source", get_source_static, set_source_static},
Tom Sepez04557b82017-02-16 09:43:10 -0800133 {0, 0, 0}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700134
Tom Sepez04557b82017-02-16 09:43:10 -0800135JSMethodSpec CJS_Field::MethodSpecs[] = {
Tom Sepez9b99b632017-02-21 15:05:57 -0800136 {"browseForFileToSubmit", browseForFileToSubmit_static},
137 {"buttonGetCaption", buttonGetCaption_static},
138 {"buttonGetIcon", buttonGetIcon_static},
139 {"buttonImportIcon", buttonImportIcon_static},
140 {"buttonSetCaption", buttonSetCaption_static},
141 {"buttonSetIcon", buttonSetIcon_static},
142 {"checkThisBox", checkThisBox_static},
143 {"clearItems", clearItems_static},
144 {"defaultIsChecked", defaultIsChecked_static},
145 {"deleteItemAt", deleteItemAt_static},
146 {"getArray", getArray_static},
147 {"getItemAt", getItemAt_static},
148 {"getLock", getLock_static},
149 {"insertItemAt", insertItemAt_static},
150 {"isBoxChecked", isBoxChecked_static},
151 {"isDefaultChecked", isDefaultChecked_static},
152 {"setAction", setAction_static},
153 {"setFocus", setFocus_static},
154 {"setItems", setItems_static},
155 {"setLock", setLock_static},
156 {"signatureGetModifications", signatureGetModifications_static},
157 {"signatureGetSeedValue", signatureGetSeedValue_static},
158 {"signatureInfo", signatureInfo_static},
159 {"signatureSetSeedValue", signatureSetSeedValue_static},
160 {"signatureSign", signatureSign_static},
161 {"signatureValidate", signatureValidate_static},
Tom Sepez04557b82017-02-16 09:43:10 -0800162 {0, 0}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700163
164IMPLEMENT_JS_CLASS(CJS_Field, Field)
165
weili625ad662016-06-15 11:21:33 -0700166CJS_DelayData::CJS_DelayData(FIELD_PROP prop,
167 int idx,
168 const CFX_WideString& name)
169 : eProp(prop), nControlIndex(idx), sFieldName(name) {}
170
171CJS_DelayData::~CJS_DelayData() {}
172
Tom Sepez33420902015-10-13 15:00:10 -0700173void CJS_Field::InitInstance(IJS_Runtime* pIRuntime) {
Lei Zhangd88a3642015-11-10 09:38:57 -0800174}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700175
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700176Field::Field(CJS_Object* pJSObject)
177 : CJS_EmbedObj(pJSObject),
thestig1cd352e2016-06-07 17:53:06 -0700178 m_pJSDoc(nullptr),
dsinclair3a7741a2016-10-11 10:39:49 -0700179 m_pFormFillEnv(nullptr),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700180 m_nFormControlIndex(-1),
tsepez4cf55152016-11-02 14:37:54 -0700181 m_bCanSet(false),
182 m_bDelay(false) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700183
184Field::~Field() {}
185
186// note: iControlNo = -1, means not a widget.
187void Field::ParseFieldName(const std::wstring& strFieldNameParsed,
188 std::wstring& strFieldName,
189 int& iControlNo) {
190 int iStart = strFieldNameParsed.find_last_of(L'.');
191 if (iStart == -1) {
192 strFieldName = strFieldNameParsed;
193 iControlNo = -1;
194 return;
195 }
196 std::wstring suffixal = strFieldNameParsed.substr(iStart + 1);
197 iControlNo = FXSYS_wtoi(suffixal.c_str());
198 if (iControlNo == 0) {
weilidb444d22016-06-02 15:48:15 -0700199 int iSpaceStart;
200 while ((iSpaceStart = suffixal.find_last_of(L" ")) != -1) {
201 suffixal.erase(iSpaceStart, 1);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700202 }
203
204 if (suffixal.compare(L"0") != 0) {
205 strFieldName = strFieldNameParsed;
206 iControlNo = -1;
207 return;
208 }
209 }
210 strFieldName = strFieldNameParsed.substr(0, iStart);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700211}
212
tsepez4cf55152016-11-02 14:37:54 -0700213bool Field::AttachField(Document* pDocument,
214 const CFX_WideString& csFieldName) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700215 m_pJSDoc = pDocument;
dsinclair82e17672016-10-11 12:38:01 -0700216 m_pFormFillEnv.Reset(pDocument->GetFormFillEnv());
dsinclair7cbe68e2016-10-12 11:56:23 -0700217 m_bCanSet = m_pFormFillEnv->GetPermissions(FPDFPERM_FILL_FORM) ||
218 m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM) ||
219 m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700220
dsinclair7cbe68e2016-10-12 11:56:23 -0700221 CPDFSDK_InterForm* pRDInterForm = m_pFormFillEnv->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700222 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700223 CFX_WideString swFieldNameTemp = csFieldName;
224 swFieldNameTemp.Replace(L"..", L".");
225
226 if (pInterForm->CountFields(swFieldNameTemp) <= 0) {
227 std::wstring strFieldName;
228 int iControlNo = -1;
229 ParseFieldName(swFieldNameTemp.c_str(), strFieldName, iControlNo);
230 if (iControlNo == -1)
tsepez4cf55152016-11-02 14:37:54 -0700231 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700232
233 m_FieldName = strFieldName.c_str();
234 m_nFormControlIndex = iControlNo;
tsepez4cf55152016-11-02 14:37:54 -0700235 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700236 }
237
238 m_FieldName = swFieldNameTemp;
239 m_nFormControlIndex = -1;
240
tsepez4cf55152016-11-02 14:37:54 -0700241 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700242}
243
Lei Zhangd88a3642015-11-10 09:38:57 -0800244std::vector<CPDF_FormField*> Field::GetFormFields(
dsinclair3a7741a2016-10-11 10:39:49 -0700245 CPDFSDK_FormFillEnvironment* pFormFillEnv,
Lei Zhangd88a3642015-11-10 09:38:57 -0800246 const CFX_WideString& csFieldName) {
247 std::vector<CPDF_FormField*> fields;
dsinclair7cbe68e2016-10-12 11:56:23 -0700248 CPDFSDK_InterForm* pReaderInterForm = pFormFillEnv->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700249 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -0800250 for (int i = 0, sz = pInterForm->CountFields(csFieldName); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700251 if (CPDF_FormField* pFormField = pInterForm->GetField(i, csFieldName))
Lei Zhangd88a3642015-11-10 09:38:57 -0800252 fields.push_back(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700253 }
Lei Zhangd88a3642015-11-10 09:38:57 -0800254 return fields;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700255}
256
Lei Zhangd88a3642015-11-10 09:38:57 -0800257std::vector<CPDF_FormField*> Field::GetFormFields(
258 const CFX_WideString& csFieldName) const {
dsinclair3a7741a2016-10-11 10:39:49 -0700259 return Field::GetFormFields(m_pFormFillEnv.Get(), csFieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700260}
261
dsinclair3a7741a2016-10-11 10:39:49 -0700262void Field::UpdateFormField(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700263 CPDF_FormField* pFormField,
tsepez4cf55152016-11-02 14:37:54 -0700264 bool bChangeMark,
265 bool bResetAP,
266 bool bRefresh) {
dsinclair7cbe68e2016-10-12 11:56:23 -0700267 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700268
269 if (bResetAP) {
tsepez8fa82792017-01-11 09:32:33 -0800270 std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
dsinclair1df1efa2016-09-07 09:55:37 -0700271 pInterForm->GetWidgets(pFormField, &widgets);
272
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700273 int nFieldType = pFormField->GetFieldType();
274 if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_TEXTFIELD) {
tsepez8fa82792017-01-11 09:32:33 -0800275 for (auto& pObserved : widgets) {
tsepez1c620542016-09-12 09:47:52 -0700276 if (pObserved) {
tsepez8fa82792017-01-11 09:32:33 -0800277 bool bFormatted = false;
278 CFX_WideString sValue = static_cast<CPDFSDK_Widget*>(pObserved.Get())
279 ->OnFormat(bFormatted);
280 if (pObserved) { // Not redundant, may be clobbered by OnFormat.
281 static_cast<CPDFSDK_Widget*>(pObserved.Get())
282 ->ResetAppearance(bFormatted ? &sValue : nullptr, false);
283 }
tsepezca97a8e2016-08-01 10:10:36 -0700284 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700285 }
286 } else {
tsepez8fa82792017-01-11 09:32:33 -0800287 for (auto& pObserved : widgets) {
288 if (pObserved) {
289 static_cast<CPDFSDK_Widget*>(pObserved.Get())
290 ->ResetAppearance(nullptr, false);
291 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700292 }
293 }
294 }
295
296 if (bRefresh) {
dsinclair1df1efa2016-09-07 09:55:37 -0700297 // Refresh the widget list. The calls in |bResetAP| may have caused widgets
298 // to be removed from the list. We need to call |GetWidgets| again to be
299 // sure none of the widgets have been deleted.
tsepez8fa82792017-01-11 09:32:33 -0800300 std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
dsinclair1df1efa2016-09-07 09:55:37 -0700301 pInterForm->GetWidgets(pFormField, &widgets);
302
dsinclair690c0332016-10-11 09:13:01 -0700303 // TODO(dsinclair): Determine if all widgets share the same
304 // CPDFSDK_InterForm. If that's the case, we can move the code to
dsinclair7cbe68e2016-10-12 11:56:23 -0700305 // |GetFormFillEnv| out of the loop.
tsepez8fa82792017-01-11 09:32:33 -0800306 for (auto& pObserved : widgets) {
307 if (pObserved) {
308 CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pObserved.Get());
309 pWidget->GetInterForm()->GetFormFillEnv()->UpdateAllViews(nullptr,
310 pWidget);
311 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700312 }
313 }
314
315 if (bChangeMark)
dsinclair7cbe68e2016-10-12 11:56:23 -0700316 pFormFillEnv->SetChangeMark();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700317}
318
dsinclair3a7741a2016-10-11 10:39:49 -0700319void Field::UpdateFormControl(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700320 CPDF_FormControl* pFormControl,
tsepez4cf55152016-11-02 14:37:54 -0700321 bool bChangeMark,
322 bool bResetAP,
323 bool bRefresh) {
Lei Zhang96660d62015-12-14 18:27:25 -0800324 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700325
dsinclair7cbe68e2016-10-12 11:56:23 -0700326 CPDFSDK_InterForm* pForm = pFormFillEnv->GetInterForm();
dsinclairc5267c52016-11-04 15:35:12 -0700327 CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700328
329 if (pWidget) {
330 if (bResetAP) {
331 int nFieldType = pWidget->GetFieldType();
332 if (nFieldType == FIELDTYPE_COMBOBOX ||
333 nFieldType == FIELDTYPE_TEXTFIELD) {
tsepez4cf55152016-11-02 14:37:54 -0700334 bool bFormatted = false;
tsepez8c2a8cd2016-09-07 15:29:11 -0700335 CFX_WideString sValue = pWidget->OnFormat(bFormatted);
tsepez4cf55152016-11-02 14:37:54 -0700336 pWidget->ResetAppearance(bFormatted ? &sValue : nullptr, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700337 } else {
tsepez4cf55152016-11-02 14:37:54 -0700338 pWidget->ResetAppearance(nullptr, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700339 }
340 }
341
342 if (bRefresh) {
343 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
dsinclair7cbe68e2016-10-12 11:56:23 -0700344 pInterForm->GetFormFillEnv()->UpdateAllViews(nullptr, pWidget);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700345 }
346 }
347
348 if (bChangeMark)
dsinclair7cbe68e2016-10-12 11:56:23 -0700349 pFormFillEnv->SetChangeMark();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700350}
351
dsinclair3a7741a2016-10-11 10:39:49 -0700352CPDFSDK_Widget* Field::GetWidget(CPDFSDK_FormFillEnvironment* pFormFillEnv,
dsinclairc5267c52016-11-04 15:35:12 -0700353 CPDF_FormControl* pFormControl) {
dsinclair7cbe68e2016-10-12 11:56:23 -0700354 CPDFSDK_InterForm* pInterForm =
355 static_cast<CPDFSDK_InterForm*>(pFormFillEnv->GetInterForm());
dsinclairc5267c52016-11-04 15:35:12 -0700356 return pInterForm ? pInterForm->GetWidget(pFormControl) : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700357}
358
tsepez4cf55152016-11-02 14:37:54 -0700359bool Field::ValueIsOccur(CPDF_FormField* pFormField,
360 CFX_WideString csOptLabel) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700361 for (int i = 0, sz = pFormField->CountOptions(); i < sz; i++) {
362 if (csOptLabel.Compare(pFormField->GetOptionLabel(i)) == 0)
tsepez4cf55152016-11-02 14:37:54 -0700363 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700364 }
365
tsepez4cf55152016-11-02 14:37:54 -0700366 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700367}
368
369CPDF_FormControl* Field::GetSmartFieldControl(CPDF_FormField* pFormField) {
370 if (!pFormField->CountControls() ||
371 m_nFormControlIndex >= pFormField->CountControls())
thestig1cd352e2016-06-07 17:53:06 -0700372 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700373
374 if (m_nFormControlIndex < 0)
375 return pFormField->GetControl(0);
376
377 return pFormField->GetControl(m_nFormControlIndex);
378}
379
Tom Sepezb1670b52017-02-16 17:01:00 -0800380bool Field::alignment(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700381 CJS_PropValue& vp,
382 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700383 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700384
385 if (vp.IsSetting()) {
386 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700387 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700388
389 CFX_ByteString alignStr;
390 vp >> alignStr;
391
392 if (m_bDelay) {
393 AddDelay_String(FP_ALIGNMENT, alignStr);
394 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700395 Field::SetAlignment(m_pFormFillEnv.Get(), m_FieldName,
396 m_nFormControlIndex, alignStr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700397 }
398 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800399 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
400 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700401 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700402
Lei Zhangd88a3642015-11-10 09:38:57 -0800403 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700404 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
tsepez4cf55152016-11-02 14:37:54 -0700405 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700406
407 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
408 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -0700409 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700410
411 switch (pFormControl->GetControlAlignment()) {
412 case 1:
413 vp << L"center";
414 break;
415 case 0:
416 vp << L"left";
417 break;
418 case 2:
419 vp << L"right";
420 break;
421 default:
422 vp << L"";
423 }
424 }
425
tsepez4cf55152016-11-02 14:37:54 -0700426 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700427}
428
dsinclair3a7741a2016-10-11 10:39:49 -0700429void Field::SetAlignment(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700430 const CFX_WideString& swFieldName,
431 int nControlIndex,
432 const CFX_ByteString& string) {
433 // Not supported.
434}
435
Tom Sepezb1670b52017-02-16 17:01:00 -0800436bool Field::borderStyle(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700437 CJS_PropValue& vp,
438 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700439 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700440
441 if (vp.IsSetting()) {
442 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700443 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700444
445 CFX_ByteString strType = "";
446 vp >> strType;
447
448 if (m_bDelay) {
449 AddDelay_String(FP_BORDERSTYLE, strType);
450 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700451 Field::SetBorderStyle(m_pFormFillEnv.Get(), m_FieldName,
452 m_nFormControlIndex, strType);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700453 }
454 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800455 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
456 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700457 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700458
Lei Zhangd88a3642015-11-10 09:38:57 -0800459 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700460 if (!pFormField)
tsepez4cf55152016-11-02 14:37:54 -0700461 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700462
dsinclairc5267c52016-11-04 15:35:12 -0700463 CPDFSDK_Widget* pWidget =
464 GetWidget(m_pFormFillEnv.Get(), GetSmartFieldControl(pFormField));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700465 if (!pWidget)
tsepez4cf55152016-11-02 14:37:54 -0700466 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700467
dsinclair92cb5e52016-05-16 11:38:28 -0700468 switch (pWidget->GetBorderStyle()) {
469 case BorderStyle::SOLID:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700470 vp << L"solid";
471 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700472 case BorderStyle::DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700473 vp << L"dashed";
474 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700475 case BorderStyle::BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700476 vp << L"beveled";
477 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700478 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700479 vp << L"inset";
480 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700481 case BorderStyle::UNDERLINE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700482 vp << L"underline";
483 break;
484 default:
485 vp << L"";
486 break;
487 }
488 }
489
tsepez4cf55152016-11-02 14:37:54 -0700490 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700491}
492
dsinclair3a7741a2016-10-11 10:39:49 -0700493void Field::SetBorderStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700494 const CFX_WideString& swFieldName,
495 int nControlIndex,
496 const CFX_ByteString& string) {
dsinclair3a7741a2016-10-11 10:39:49 -0700497 ASSERT(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700498
dsinclair92cb5e52016-05-16 11:38:28 -0700499 BorderStyle nBorderStyle = BorderStyle::SOLID;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700500 if (string == "solid")
dsinclair92cb5e52016-05-16 11:38:28 -0700501 nBorderStyle = BorderStyle::SOLID;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700502 else if (string == "beveled")
dsinclair92cb5e52016-05-16 11:38:28 -0700503 nBorderStyle = BorderStyle::BEVELED;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700504 else if (string == "dashed")
dsinclair92cb5e52016-05-16 11:38:28 -0700505 nBorderStyle = BorderStyle::DASH;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700506 else if (string == "inset")
dsinclair92cb5e52016-05-16 11:38:28 -0700507 nBorderStyle = BorderStyle::INSET;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700508 else if (string == "underline")
dsinclair92cb5e52016-05-16 11:38:28 -0700509 nBorderStyle = BorderStyle::UNDERLINE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700510 else
511 return;
512
Lei Zhangd88a3642015-11-10 09:38:57 -0800513 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -0700514 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -0800515 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700516 if (nControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -0700517 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -0800518 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700519 if (CPDFSDK_Widget* pWidget =
dsinclairc5267c52016-11-04 15:35:12 -0700520 GetWidget(pFormFillEnv, pFormField->GetControl(i))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700521 if (pWidget->GetBorderStyle() != nBorderStyle) {
522 pWidget->SetBorderStyle(nBorderStyle);
tsepez4cf55152016-11-02 14:37:54 -0700523 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700524 }
525 }
526 }
527 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -0700528 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700529 } else {
530 if (nControlIndex >= pFormField->CountControls())
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700531 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700532 if (CPDF_FormControl* pFormControl =
533 pFormField->GetControl(nControlIndex)) {
dsinclairc5267c52016-11-04 15:35:12 -0700534 if (CPDFSDK_Widget* pWidget = GetWidget(pFormFillEnv, pFormControl)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700535 if (pWidget->GetBorderStyle() != nBorderStyle) {
536 pWidget->SetBorderStyle(nBorderStyle);
tsepez4cf55152016-11-02 14:37:54 -0700537 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700538 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700539 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700540 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700541 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700542 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700543}
544
Tom Sepezb1670b52017-02-16 17:01:00 -0800545bool Field::buttonAlignX(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700546 CJS_PropValue& vp,
547 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700548 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700549
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700550 if (vp.IsSetting()) {
551 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700552 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700553
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700554 int nVP;
555 vp >> nVP;
556
557 if (m_bDelay) {
558 AddDelay_Int(FP_BUTTONALIGNX, nVP);
559 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700560 Field::SetButtonAlignX(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700561 m_nFormControlIndex, nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700562 }
563 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800564 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
565 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700566 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700567
Lei Zhangd88a3642015-11-10 09:38:57 -0800568 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700569 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -0700570 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700571
572 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
573 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -0700574 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700575
576 CPDF_IconFit IconFit = pFormControl->GetIconFit();
577
Dan Sinclair05df0752017-03-14 14:43:42 -0400578 float fLeft, fBottom;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700579 IconFit.GetIconPosition(fLeft, fBottom);
580
581 vp << (int32_t)fLeft;
582 }
583
tsepez4cf55152016-11-02 14:37:54 -0700584 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700585}
586
dsinclair3a7741a2016-10-11 10:39:49 -0700587void Field::SetButtonAlignX(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700588 const CFX_WideString& swFieldName,
589 int nControlIndex,
590 int number) {
591 // Not supported.
592}
593
Tom Sepezb1670b52017-02-16 17:01:00 -0800594bool Field::buttonAlignY(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700595 CJS_PropValue& vp,
596 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700597 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700598
599 if (vp.IsSetting()) {
600 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700601 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700602
603 int nVP;
604 vp >> nVP;
605
606 if (m_bDelay) {
607 AddDelay_Int(FP_BUTTONALIGNY, nVP);
608 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700609 Field::SetButtonAlignY(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700610 m_nFormControlIndex, nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700611 }
612 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800613 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
614 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700615 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700616
Lei Zhangd88a3642015-11-10 09:38:57 -0800617 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700618 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -0700619 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700620
621 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
622 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -0700623 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700624
625 CPDF_IconFit IconFit = pFormControl->GetIconFit();
626
Dan Sinclair05df0752017-03-14 14:43:42 -0400627 float fLeft, fBottom;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700628 IconFit.GetIconPosition(fLeft, fBottom);
629
630 vp << (int32_t)fBottom;
631 }
632
tsepez4cf55152016-11-02 14:37:54 -0700633 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700634}
635
dsinclair3a7741a2016-10-11 10:39:49 -0700636void Field::SetButtonAlignY(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700637 const CFX_WideString& swFieldName,
638 int nControlIndex,
639 int number) {
640 // Not supported.
641}
642
Tom Sepezb1670b52017-02-16 17:01:00 -0800643bool Field::buttonFitBounds(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700644 CJS_PropValue& vp,
645 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700646 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700647
648 if (vp.IsSetting()) {
649 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700650 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700651
652 bool bVP;
653 vp >> bVP;
654
655 if (m_bDelay) {
656 AddDelay_Bool(FP_BUTTONFITBOUNDS, bVP);
657 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700658 Field::SetButtonFitBounds(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700659 m_nFormControlIndex, bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700660 }
661 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800662 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
663 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700664 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700665
Lei Zhangd88a3642015-11-10 09:38:57 -0800666 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700667 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -0700668 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700669
670 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
671 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -0700672 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700673
thestigded36342016-05-23 17:54:02 -0700674 vp << pFormControl->GetIconFit().GetFittingBounds();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700675 }
676
tsepez4cf55152016-11-02 14:37:54 -0700677 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700678}
679
dsinclair3a7741a2016-10-11 10:39:49 -0700680void Field::SetButtonFitBounds(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700681 const CFX_WideString& swFieldName,
682 int nControlIndex,
683 bool b) {
684 // Not supported.
685}
686
Tom Sepezb1670b52017-02-16 17:01:00 -0800687bool Field::buttonPosition(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700688 CJS_PropValue& vp,
689 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700690 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700691
692 if (vp.IsSetting()) {
693 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700694 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700695
696 int nVP;
697 vp >> nVP;
698
699 if (m_bDelay) {
700 AddDelay_Int(FP_BUTTONPOSITION, nVP);
701 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700702 Field::SetButtonPosition(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700703 m_nFormControlIndex, nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700704 }
705 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800706 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
707 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700708 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700709
Lei Zhangd88a3642015-11-10 09:38:57 -0800710 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700711 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -0700712 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700713
714 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
715 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -0700716 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700717
718 vp << pFormControl->GetTextPosition();
719 }
tsepez4cf55152016-11-02 14:37:54 -0700720 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700721}
722
dsinclair3a7741a2016-10-11 10:39:49 -0700723void Field::SetButtonPosition(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700724 const CFX_WideString& swFieldName,
725 int nControlIndex,
726 int number) {
727 // Not supported.
728}
729
Tom Sepezb1670b52017-02-16 17:01:00 -0800730bool Field::buttonScaleHow(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700731 CJS_PropValue& vp,
732 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700733 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700734
735 if (vp.IsSetting()) {
736 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700737 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700738
739 int nVP;
740 vp >> nVP;
741
742 if (m_bDelay) {
743 AddDelay_Int(FP_BUTTONSCALEHOW, nVP);
744 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700745 Field::SetButtonScaleHow(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700746 m_nFormControlIndex, nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700747 }
748 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800749 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
750 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700751 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700752
Lei Zhangd88a3642015-11-10 09:38:57 -0800753 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700754 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -0700755 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700756
757 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
758 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -0700759 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700760
761 CPDF_IconFit IconFit = pFormControl->GetIconFit();
762 if (IconFit.IsProportionalScale())
763 vp << (int32_t)0;
764 else
765 vp << (int32_t)1;
766 }
767
tsepez4cf55152016-11-02 14:37:54 -0700768 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700769}
770
dsinclair3a7741a2016-10-11 10:39:49 -0700771void Field::SetButtonScaleHow(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700772 const CFX_WideString& swFieldName,
773 int nControlIndex,
774 int number) {
775 // Not supported.
776}
777
Tom Sepezb1670b52017-02-16 17:01:00 -0800778bool Field::buttonScaleWhen(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700779 CJS_PropValue& vp,
780 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700781 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700782
783 if (vp.IsSetting()) {
784 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700785 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700786
787 int nVP;
788 vp >> nVP;
789
790 if (m_bDelay) {
791 AddDelay_Int(FP_BUTTONSCALEWHEN, nVP);
792 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700793 Field::SetButtonScaleWhen(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700794 m_nFormControlIndex, nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700795 }
796 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800797 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
798 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700799 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700800
Lei Zhangd88a3642015-11-10 09:38:57 -0800801 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700802 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -0700803 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700804
805 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
806 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -0700807 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700808
809 CPDF_IconFit IconFit = pFormControl->GetIconFit();
810 int ScaleM = IconFit.GetScaleMethod();
811 switch (ScaleM) {
812 case CPDF_IconFit::Always:
813 vp << (int32_t)CPDF_IconFit::Always;
814 break;
815 case CPDF_IconFit::Bigger:
816 vp << (int32_t)CPDF_IconFit::Bigger;
817 break;
818 case CPDF_IconFit::Never:
819 vp << (int32_t)CPDF_IconFit::Never;
820 break;
821 case CPDF_IconFit::Smaller:
822 vp << (int32_t)CPDF_IconFit::Smaller;
823 break;
824 }
825 }
826
tsepez4cf55152016-11-02 14:37:54 -0700827 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700828}
829
dsinclair3a7741a2016-10-11 10:39:49 -0700830void Field::SetButtonScaleWhen(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700831 const CFX_WideString& swFieldName,
832 int nControlIndex,
833 int number) {
834 // Not supported.
835}
836
Tom Sepezb1670b52017-02-16 17:01:00 -0800837bool Field::calcOrderIndex(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700838 CJS_PropValue& vp,
839 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700840 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700841
842 if (vp.IsSetting()) {
843 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700844 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700845
846 int nVP;
847 vp >> nVP;
848
849 if (m_bDelay) {
850 AddDelay_Int(FP_CALCORDERINDEX, nVP);
851 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700852 Field::SetCalcOrderIndex(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700853 m_nFormControlIndex, nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700854 }
855 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800856 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
857 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700858 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700859
Lei Zhangd88a3642015-11-10 09:38:57 -0800860 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700861 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -0800862 pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) {
tsepez4cf55152016-11-02 14:37:54 -0700863 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -0800864 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700865
dsinclair7cbe68e2016-10-12 11:56:23 -0700866 CPDFSDK_InterForm* pRDInterForm = m_pFormFillEnv->GetInterForm();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700867 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700868 vp << (int32_t)pInterForm->FindFieldInCalculationOrder(pFormField);
869 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700870
tsepez4cf55152016-11-02 14:37:54 -0700871 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700872}
873
dsinclair3a7741a2016-10-11 10:39:49 -0700874void Field::SetCalcOrderIndex(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700875 const CFX_WideString& swFieldName,
876 int nControlIndex,
877 int number) {
878 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700879}
880
Tom Sepezb1670b52017-02-16 17:01:00 -0800881bool Field::charLimit(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700882 CJS_PropValue& vp,
883 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700884 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700885
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700886 if (vp.IsSetting()) {
887 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700888 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700889
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700890 int nVP;
891 vp >> nVP;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700892
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700893 if (m_bDelay) {
894 AddDelay_Int(FP_CHARLIMIT, nVP);
895 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700896 Field::SetCharLimit(m_pFormFillEnv.Get(), m_FieldName,
897 m_nFormControlIndex, nVP);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700898 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700899 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800900 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
901 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700902 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700903
Lei Zhangd88a3642015-11-10 09:38:57 -0800904 CPDF_FormField* pFormField = FieldArray[0];
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700905 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
tsepez4cf55152016-11-02 14:37:54 -0700906 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700907
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700908 vp << (int32_t)pFormField->GetMaxLen();
909 }
tsepez4cf55152016-11-02 14:37:54 -0700910 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700911}
912
dsinclair3a7741a2016-10-11 10:39:49 -0700913void Field::SetCharLimit(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700914 const CFX_WideString& swFieldName,
915 int nControlIndex,
916 int number) {
917 // Not supported.
918}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700919
Tom Sepezb1670b52017-02-16 17:01:00 -0800920bool Field::comb(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800921 CJS_PropValue& vp,
922 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700923 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700924
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700925 if (vp.IsSetting()) {
926 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700927 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700928
929 bool bVP;
930 vp >> bVP;
931
932 if (m_bDelay) {
933 AddDelay_Bool(FP_COMB, bVP);
934 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700935 Field::SetComb(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
936 bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700937 }
938 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800939 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
940 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700941 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700942
Lei Zhangd88a3642015-11-10 09:38:57 -0800943 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700944 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
tsepez4cf55152016-11-02 14:37:54 -0700945 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700946
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700947 if (pFormField->GetFieldFlags() & FIELDFLAG_COMB)
948 vp << true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700949 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700950 vp << false;
951 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700952
tsepez4cf55152016-11-02 14:37:54 -0700953 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700954}
955
dsinclair3a7741a2016-10-11 10:39:49 -0700956void Field::SetComb(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700957 const CFX_WideString& swFieldName,
958 int nControlIndex,
959 bool b) {
960 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700961}
962
Tom Sepezb1670b52017-02-16 17:01:00 -0800963bool Field::commitOnSelChange(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700964 CJS_PropValue& vp,
965 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700966 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700967
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700968 if (vp.IsSetting()) {
969 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700970 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700971
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700972 bool bVP;
973 vp >> bVP;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700974
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700975 if (m_bDelay) {
976 AddDelay_Bool(FP_COMMITONSELCHANGE, bVP);
977 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700978 Field::SetCommitOnSelChange(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700979 m_nFormControlIndex, bVP);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700980 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700981 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800982 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
983 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700984 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700985
Lei Zhangd88a3642015-11-10 09:38:57 -0800986 CPDF_FormField* pFormField = FieldArray[0];
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700987 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -0800988 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
tsepez4cf55152016-11-02 14:37:54 -0700989 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -0800990 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700991
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700992 if (pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE)
993 vp << true;
994 else
995 vp << false;
996 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700997
tsepez4cf55152016-11-02 14:37:54 -0700998 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700999}
1000
dsinclair3a7741a2016-10-11 10:39:49 -07001001void Field::SetCommitOnSelChange(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001002 const CFX_WideString& swFieldName,
1003 int nControlIndex,
1004 bool b) {
1005 // Not supported.
1006}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001007
Tom Sepezb1670b52017-02-16 17:01:00 -08001008bool Field::currentValueIndices(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001009 CJS_PropValue& vp,
1010 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001011 if (vp.IsSetting()) {
1012 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001013 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001014
tsepez41a53ad2016-03-28 16:59:30 -07001015 std::vector<uint32_t> array;
tsepezf3dc8c62016-08-10 06:29:29 -07001016 if (vp.GetJSValue()->GetType() == CJS_Value::VT_number) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001017 int iSelecting = 0;
1018 vp >> iSelecting;
tsepez41a53ad2016-03-28 16:59:30 -07001019 array.push_back(iSelecting);
tsepezf3dc8c62016-08-10 06:29:29 -07001020 } else if (vp.GetJSValue()->IsArrayObject()) {
tsepeze5aff742016-08-08 09:49:42 -07001021 CJS_Array SelArray;
Tom Sepez67fd5df2015-10-08 12:24:19 -07001022 CJS_Value SelValue(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001023 int iSelecting;
1024 vp >> SelArray;
tsepezb4694242016-08-15 16:44:55 -07001025 for (int i = 0, sz = SelArray.GetLength(pRuntime); i < sz; i++) {
1026 SelArray.GetElement(pRuntime, i, SelValue);
1027 iSelecting = SelValue.ToInt(pRuntime);
tsepez41a53ad2016-03-28 16:59:30 -07001028 array.push_back(iSelecting);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001029 }
1030 }
1031
1032 if (m_bDelay) {
1033 AddDelay_WordArray(FP_CURRENTVALUEINDICES, array);
1034 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001035 Field::SetCurrentValueIndices(m_pFormFillEnv.Get(), m_FieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001036 m_nFormControlIndex, array);
1037 }
1038 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001039 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1040 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001041 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001042
Lei Zhangd88a3642015-11-10 09:38:57 -08001043 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001044 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001045 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
tsepez4cf55152016-11-02 14:37:54 -07001046 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001047 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001048
Lei Zhangd88a3642015-11-10 09:38:57 -08001049 if (pFormField->CountSelectedItems() == 1) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001050 vp << pFormField->GetSelectedIndex(0);
Lei Zhangd88a3642015-11-10 09:38:57 -08001051 } else if (pFormField->CountSelectedItems() > 1) {
tsepeze5aff742016-08-08 09:49:42 -07001052 CJS_Array SelArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001053 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
1054 SelArray.SetElement(
tsepezb4694242016-08-15 16:44:55 -07001055 pRuntime, i, CJS_Value(pRuntime, pFormField->GetSelectedIndex(i)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001056 }
1057 vp << SelArray;
Lei Zhangd88a3642015-11-10 09:38:57 -08001058 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001059 vp << -1;
Lei Zhangd88a3642015-11-10 09:38:57 -08001060 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001061 }
1062
tsepez4cf55152016-11-02 14:37:54 -07001063 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001064}
1065
dsinclair3a7741a2016-10-11 10:39:49 -07001066void Field::SetCurrentValueIndices(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001067 const CFX_WideString& swFieldName,
1068 int nControlIndex,
tsepez41a53ad2016-03-28 16:59:30 -07001069 const std::vector<uint32_t>& array) {
dsinclair3a7741a2016-10-11 10:39:49 -07001070 ASSERT(pFormFillEnv);
Lei Zhangd88a3642015-11-10 09:38:57 -08001071 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07001072 GetFormFields(pFormFillEnv, swFieldName);
tsepez41a53ad2016-03-28 16:59:30 -07001073
Lei Zhangd88a3642015-11-10 09:38:57 -08001074 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001075 int nFieldType = pFormField->GetFieldType();
1076 if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX) {
tsepezc3255f52016-03-25 14:52:27 -07001077 uint32_t dwFieldFlags = pFormField->GetFieldFlags();
tsepez4cf55152016-11-02 14:37:54 -07001078 pFormField->ClearSelection(true);
tsepez41a53ad2016-03-28 16:59:30 -07001079 for (size_t i = 0; i < array.size(); ++i) {
1080 if (i != 0 && !(dwFieldFlags & (1 << 21)))
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001081 break;
Wei Li05d53f02016-03-29 16:42:53 -07001082 if (array[i] < static_cast<uint32_t>(pFormField->CountOptions()) &&
tsepez41a53ad2016-03-28 16:59:30 -07001083 !pFormField->IsItemSelected(array[i])) {
tsepez4cf55152016-11-02 14:37:54 -07001084 pFormField->SetItemSelection(array[i], true);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001085 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001086 }
tsepez4cf55152016-11-02 14:37:54 -07001087 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001088 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001089 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001090}
1091
Tom Sepezb1670b52017-02-16 17:01:00 -08001092bool Field::defaultStyle(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001093 CJS_PropValue& vp,
1094 CFX_WideString& sError) {
1095 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001096}
1097
dsinclair3a7741a2016-10-11 10:39:49 -07001098void Field::SetDefaultStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001099 const CFX_WideString& swFieldName,
1100 int nControlIndex) {
1101 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001102}
1103
Tom Sepezb1670b52017-02-16 17:01:00 -08001104bool Field::defaultValue(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001105 CJS_PropValue& vp,
1106 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001107 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001108
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001109 if (vp.IsSetting()) {
1110 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001111 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001112
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001113 CFX_WideString WideStr;
1114 vp >> WideStr;
1115
1116 if (m_bDelay) {
1117 AddDelay_WideString(FP_DEFAULTVALUE, WideStr);
1118 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001119 Field::SetDefaultValue(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -07001120 m_nFormControlIndex, WideStr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001121 }
1122 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001123 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1124 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001125 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001126
Lei Zhangd88a3642015-11-10 09:38:57 -08001127 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001128 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON ||
Lei Zhangd88a3642015-11-10 09:38:57 -08001129 pFormField->GetFieldType() == FIELDTYPE_SIGNATURE) {
tsepez4cf55152016-11-02 14:37:54 -07001130 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001131 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001132
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001133 vp << pFormField->GetDefaultValue();
1134 }
tsepez4cf55152016-11-02 14:37:54 -07001135 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001136}
1137
dsinclair3a7741a2016-10-11 10:39:49 -07001138void Field::SetDefaultValue(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001139 const CFX_WideString& swFieldName,
1140 int nControlIndex,
1141 const CFX_WideString& string) {
1142 // Not supported.
1143}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001144
Tom Sepezb1670b52017-02-16 17:01:00 -08001145bool Field::doNotScroll(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001146 CJS_PropValue& vp,
1147 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001148 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001149
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001150 if (vp.IsSetting()) {
1151 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001152 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001153
1154 bool bVP;
1155 vp >> bVP;
1156
1157 if (m_bDelay) {
1158 AddDelay_Bool(FP_DONOTSCROLL, bVP);
1159 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001160 Field::SetDoNotScroll(m_pFormFillEnv.Get(), m_FieldName,
1161 m_nFormControlIndex, bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001162 }
1163 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001164 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1165 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001166 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001167
Lei Zhangd88a3642015-11-10 09:38:57 -08001168 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001169 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
tsepez4cf55152016-11-02 14:37:54 -07001170 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001171
1172 if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL)
1173 vp << true;
1174 else
1175 vp << false;
1176 }
1177
tsepez4cf55152016-11-02 14:37:54 -07001178 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001179}
1180
dsinclair3a7741a2016-10-11 10:39:49 -07001181void Field::SetDoNotScroll(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001182 const CFX_WideString& swFieldName,
1183 int nControlIndex,
1184 bool b) {
1185 // Not supported.
1186}
1187
Tom Sepezb1670b52017-02-16 17:01:00 -08001188bool Field::doNotSpellCheck(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001189 CJS_PropValue& vp,
1190 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001191 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001192
1193 if (vp.IsSetting()) {
1194 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001195 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001196
1197 bool bVP;
1198 vp >> bVP;
1199 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001200 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1201 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001202 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001203
Lei Zhangd88a3642015-11-10 09:38:57 -08001204 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001205 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001206 pFormField->GetFieldType() != FIELDTYPE_COMBOBOX) {
tsepez4cf55152016-11-02 14:37:54 -07001207 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001208 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001209
1210 if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK)
1211 vp << true;
1212 else
1213 vp << false;
1214 }
1215
tsepez4cf55152016-11-02 14:37:54 -07001216 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001217}
1218
tsepez4cf55152016-11-02 14:37:54 -07001219void Field::SetDelay(bool bDelay) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001220 m_bDelay = bDelay;
1221
1222 if (!m_bDelay) {
1223 if (m_pJSDoc)
1224 m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex);
1225 }
1226}
1227
Tom Sepezb1670b52017-02-16 17:01:00 -08001228bool Field::delay(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001229 CJS_PropValue& vp,
1230 CFX_WideString& sError) {
1231 if (!vp.IsSetting()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001232 vp << m_bDelay;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001233 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001234 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001235 if (!m_bCanSet)
1236 return false;
1237
1238 bool bVP;
1239 vp >> bVP;
1240 SetDelay(bVP);
tsepez4cf55152016-11-02 14:37:54 -07001241 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001242}
1243
Tom Sepezb1670b52017-02-16 17:01:00 -08001244bool Field::display(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001245 CJS_PropValue& vp,
1246 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001247 if (vp.IsSetting()) {
1248 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001249 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001250
1251 int nVP;
1252 vp >> nVP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001253 if (m_bDelay) {
1254 AddDelay_Int(FP_DISPLAY, nVP);
1255 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001256 Field::SetDisplay(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07001257 nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001258 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001259 return true;
1260 }
1261 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1262 if (FieldArray.empty())
1263 return false;
1264
1265 CPDF_FormField* pFormField = FieldArray[0];
1266 ASSERT(pFormField);
1267 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1268 CPDFSDK_Widget* pWidget =
1269 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1270 if (!pWidget)
1271 return false;
1272
1273 uint32_t dwFlag = pWidget->GetFlags();
1274 if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag) {
1275 vp << (int32_t)1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001276 } else {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001277 if (ANNOTFLAG_PRINT & dwFlag) {
1278 if (ANNOTFLAG_NOVIEW & dwFlag) {
1279 vp << (int32_t)3;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001280 } else {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001281 vp << (int32_t)0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001282 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001283 } else {
1284 vp << (int32_t)2;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001285 }
1286 }
tsepez4cf55152016-11-02 14:37:54 -07001287 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001288}
1289
dsinclair3a7741a2016-10-11 10:39:49 -07001290void Field::SetDisplay(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001291 const CFX_WideString& swFieldName,
1292 int nControlIndex,
1293 int number) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001294 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001295 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07001296 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -08001297 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001298 if (nControlIndex < 0) {
tonikitoo7c05a7a2016-08-17 11:08:46 -07001299 bool bAnySet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001300 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1301 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08001302 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001303
dsinclairc5267c52016-11-04 15:35:12 -07001304 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
tonikitoo7c05a7a2016-08-17 11:08:46 -07001305 if (SetWidgetDisplayStatus(pWidget, number))
1306 bAnySet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001307 }
1308
tonikitoo7c05a7a2016-08-17 11:08:46 -07001309 if (bAnySet)
tsepez4cf55152016-11-02 14:37:54 -07001310 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001311 } else {
1312 if (nControlIndex >= pFormField->CountControls())
1313 return;
tonikitoo7c05a7a2016-08-17 11:08:46 -07001314
1315 CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex);
1316 if (!pFormControl)
1317 return;
1318
dsinclairc5267c52016-11-04 15:35:12 -07001319 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
tonikitoo7c05a7a2016-08-17 11:08:46 -07001320 if (SetWidgetDisplayStatus(pWidget, number))
tsepez4cf55152016-11-02 14:37:54 -07001321 UpdateFormControl(pFormFillEnv, pFormControl, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001322 }
1323 }
1324}
1325
Tom Sepezb1670b52017-02-16 17:01:00 -08001326bool Field::doc(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001327 CJS_PropValue& vp,
1328 CFX_WideString& sError) {
1329 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -07001330 return false;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001331
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001332 vp << m_pJSDoc->GetCJSDoc();
tsepez4cf55152016-11-02 14:37:54 -07001333 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001334}
1335
Tom Sepezb1670b52017-02-16 17:01:00 -08001336bool Field::editable(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001337 CJS_PropValue& vp,
1338 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001339 if (vp.IsSetting()) {
1340 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001341 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001342
1343 bool bVP;
1344 vp >> bVP;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001345 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001346 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001347 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1348 if (FieldArray.empty())
1349 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001350
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001351 CPDF_FormField* pFormField = FieldArray[0];
1352 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX)
1353 return false;
1354
1355 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_EDIT);
tsepez4cf55152016-11-02 14:37:54 -07001356 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001357}
1358
Tom Sepezb1670b52017-02-16 17:01:00 -08001359bool Field::exportValues(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001360 CJS_PropValue& vp,
1361 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001362 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1363 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001364 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001365
Lei Zhangd88a3642015-11-10 09:38:57 -08001366 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001367 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001368 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) {
tsepez4cf55152016-11-02 14:37:54 -07001369 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001370 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001371 if (vp.IsSetting())
1372 return m_bCanSet && vp.GetJSValue()->IsArrayObject();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001373
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001374 CJS_Array ExportValusArray;
1375 if (m_nFormControlIndex < 0) {
1376 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
1377 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001378 ExportValusArray.SetElement(
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001379 pRuntime, i,
tsepeze5aff742016-08-08 09:49:42 -07001380 CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001381 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001382 } else {
1383 if (m_nFormControlIndex >= pFormField->CountControls())
1384 return false;
1385
1386 CPDF_FormControl* pFormControl =
1387 pFormField->GetControl(m_nFormControlIndex);
1388 if (!pFormControl)
1389 return false;
1390
1391 ExportValusArray.SetElement(
1392 pRuntime, 0,
1393 CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001394 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001395 vp << ExportValusArray;
tsepez4cf55152016-11-02 14:37:54 -07001396 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001397}
1398
Tom Sepezb1670b52017-02-16 17:01:00 -08001399bool Field::fileSelect(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001400 CJS_PropValue& vp,
1401 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001402 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1403 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001404 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001405
Lei Zhangd88a3642015-11-10 09:38:57 -08001406 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001407 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
tsepez4cf55152016-11-02 14:37:54 -07001408 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001409
1410 if (vp.IsSetting()) {
1411 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001412 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001413
1414 bool bVP;
1415 vp >> bVP;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001416 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001417 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001418 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT);
tsepez4cf55152016-11-02 14:37:54 -07001419 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001420}
1421
Tom Sepezb1670b52017-02-16 17:01:00 -08001422bool Field::fillColor(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001423 CJS_PropValue& vp,
1424 CFX_WideString& sError) {
tsepeze5aff742016-08-08 09:49:42 -07001425 CJS_Array crArray;
Lei Zhangd88a3642015-11-10 09:38:57 -08001426 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1427 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001428 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001429
1430 if (vp.IsSetting()) {
1431 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001432 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001433
tsepezf3dc8c62016-08-10 06:29:29 -07001434 if (!vp.GetJSValue()->IsArrayObject())
tsepez4cf55152016-11-02 14:37:54 -07001435 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001436
1437 vp >> crArray;
1438
1439 CPWL_Color color;
tsepeze5aff742016-08-08 09:49:42 -07001440 color::ConvertArrayToPWLColor(pRuntime, crArray, &color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001441 if (m_bDelay) {
1442 AddDelay_Color(FP_FILLCOLOR, color);
1443 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001444 Field::SetFillColor(m_pFormFillEnv.Get(), m_FieldName,
1445 m_nFormControlIndex, color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001446 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001447 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001448 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001449 CPDF_FormField* pFormField = FieldArray[0];
1450 ASSERT(pFormField);
1451 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1452 if (!pFormControl)
1453 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001454
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001455 int iColorType;
1456 pFormControl->GetBackgroundColor(iColorType);
1457
1458 CPWL_Color color;
1459 if (iColorType == COLORTYPE_TRANSPARENT) {
1460 color = CPWL_Color(COLORTYPE_TRANSPARENT);
1461 } else if (iColorType == COLORTYPE_GRAY) {
1462 color =
1463 CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBackgroundColor(0));
1464 } else if (iColorType == COLORTYPE_RGB) {
1465 color =
1466 CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBackgroundColor(0),
1467 pFormControl->GetOriginalBackgroundColor(1),
1468 pFormControl->GetOriginalBackgroundColor(2));
1469 } else if (iColorType == COLORTYPE_CMYK) {
1470 color =
1471 CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBackgroundColor(0),
1472 pFormControl->GetOriginalBackgroundColor(1),
1473 pFormControl->GetOriginalBackgroundColor(2),
1474 pFormControl->GetOriginalBackgroundColor(3));
1475 } else {
1476 return false;
1477 }
1478 color::ConvertPWLColorToArray(pRuntime, color, &crArray);
1479 vp << crArray;
tsepez4cf55152016-11-02 14:37:54 -07001480 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001481}
1482
dsinclair3a7741a2016-10-11 10:39:49 -07001483void Field::SetFillColor(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001484 const CFX_WideString& swFieldName,
1485 int nControlIndex,
1486 const CPWL_Color& color) {
1487 // Not supported.
1488}
1489
Tom Sepezb1670b52017-02-16 17:01:00 -08001490bool Field::hidden(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001491 CJS_PropValue& vp,
1492 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001493 if (vp.IsSetting()) {
1494 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001495 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001496
1497 bool bVP;
1498 vp >> bVP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001499 if (m_bDelay) {
1500 AddDelay_Bool(FP_HIDDEN, bVP);
1501 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001502 Field::SetHidden(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07001503 bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001504 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001505 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001506 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001507 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1508 if (FieldArray.empty())
1509 return false;
1510
1511 CPDF_FormField* pFormField = FieldArray[0];
1512 ASSERT(pFormField);
1513 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1514 CPDFSDK_Widget* pWidget =
1515 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1516 if (!pWidget)
1517 return false;
1518
1519 uint32_t dwFlags = pWidget->GetFlags();
1520 if (ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags)
1521 vp << true;
1522 else
1523 vp << false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001524
tsepez4cf55152016-11-02 14:37:54 -07001525 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001526}
1527
dsinclair3a7741a2016-10-11 10:39:49 -07001528void Field::SetHidden(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001529 const CFX_WideString& swFieldName,
1530 int nControlIndex,
1531 bool b) {
tonikitooa73b8fe2016-08-22 14:06:49 -07001532 int display = b ? 1 /*Hidden*/ : 0 /*Visible*/;
dsinclair3a7741a2016-10-11 10:39:49 -07001533 SetDisplay(pFormFillEnv, swFieldName, nControlIndex, display);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001534}
1535
Tom Sepezb1670b52017-02-16 17:01:00 -08001536bool Field::highlight(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001537 CJS_PropValue& vp,
1538 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001539 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001540 if (vp.IsSetting()) {
1541 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001542 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001543
1544 CFX_ByteString strMode;
1545 vp >> strMode;
1546
1547 if (m_bDelay) {
1548 AddDelay_String(FP_HIGHLIGHT, strMode);
1549 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001550 Field::SetHighlight(m_pFormFillEnv.Get(), m_FieldName,
1551 m_nFormControlIndex, strMode);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001552 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001553 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001554 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001555 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1556 if (FieldArray.empty())
1557 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001558
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001559 CPDF_FormField* pFormField = FieldArray[0];
1560 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
1561 return false;
1562
1563 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1564 if (!pFormControl)
1565 return false;
1566
1567 int eHM = pFormControl->GetHighlightingMode();
1568 switch (eHM) {
1569 case CPDF_FormControl::None:
1570 vp << L"none";
1571 break;
1572 case CPDF_FormControl::Push:
1573 vp << L"push";
1574 break;
1575 case CPDF_FormControl::Invert:
1576 vp << L"invert";
1577 break;
1578 case CPDF_FormControl::Outline:
1579 vp << L"outline";
1580 break;
1581 case CPDF_FormControl::Toggle:
1582 vp << L"toggle";
1583 break;
1584 }
tsepez4cf55152016-11-02 14:37:54 -07001585 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001586}
1587
dsinclair3a7741a2016-10-11 10:39:49 -07001588void Field::SetHighlight(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001589 const CFX_WideString& swFieldName,
1590 int nControlIndex,
1591 const CFX_ByteString& string) {
1592 // Not supported.
1593}
1594
Tom Sepezb1670b52017-02-16 17:01:00 -08001595bool Field::lineWidth(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001596 CJS_PropValue& vp,
1597 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001598 if (vp.IsSetting()) {
1599 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001600 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001601
1602 int iWidth;
1603 vp >> iWidth;
1604
1605 if (m_bDelay) {
1606 AddDelay_Int(FP_LINEWIDTH, iWidth);
1607 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001608 Field::SetLineWidth(m_pFormFillEnv.Get(), m_FieldName,
1609 m_nFormControlIndex, iWidth);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001610 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001611 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001612 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001613 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1614 if (FieldArray.empty())
1615 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001616
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001617 CPDF_FormField* pFormField = FieldArray[0];
1618 ASSERT(pFormField);
1619 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1620 if (!pFormControl)
1621 return false;
1622
1623 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1624 if (!pFormField->CountControls())
1625 return false;
1626
1627 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
1628 if (!pWidget)
1629 return false;
1630
1631 vp << (int32_t)pWidget->GetBorderWidth();
tsepez4cf55152016-11-02 14:37:54 -07001632 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001633}
1634
dsinclair3a7741a2016-10-11 10:39:49 -07001635void Field::SetLineWidth(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001636 const CFX_WideString& swFieldName,
1637 int nControlIndex,
1638 int number) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001639 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001640 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07001641 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -08001642 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001643 if (nControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -07001644 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001645 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1646 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08001647 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001648
dsinclairc5267c52016-11-04 15:35:12 -07001649 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001650 if (number != pWidget->GetBorderWidth()) {
1651 pWidget->SetBorderWidth(number);
tsepez4cf55152016-11-02 14:37:54 -07001652 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001653 }
1654 }
1655 }
1656 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -07001657 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001658 } else {
1659 if (nControlIndex >= pFormField->CountControls())
1660 return;
1661 if (CPDF_FormControl* pFormControl =
1662 pFormField->GetControl(nControlIndex)) {
dsinclairc5267c52016-11-04 15:35:12 -07001663 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001664 if (number != pWidget->GetBorderWidth()) {
1665 pWidget->SetBorderWidth(number);
tsepez4cf55152016-11-02 14:37:54 -07001666 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001667 }
1668 }
1669 }
1670 }
1671 }
1672}
1673
Tom Sepezb1670b52017-02-16 17:01:00 -08001674bool Field::multiline(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001675 CJS_PropValue& vp,
1676 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001677 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001678
1679 if (vp.IsSetting()) {
1680 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001681 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001682
1683 bool bVP;
1684 vp >> bVP;
1685
1686 if (m_bDelay) {
1687 AddDelay_Bool(FP_MULTILINE, bVP);
1688 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001689 Field::SetMultiline(m_pFormFillEnv.Get(), m_FieldName,
1690 m_nFormControlIndex, bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001691 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001692 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001693 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001694 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1695 if (FieldArray.empty())
1696 return false;
1697
1698 CPDF_FormField* pFormField = FieldArray[0];
1699 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1700 return false;
1701
1702 if (pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE)
1703 vp << true;
1704 else
1705 vp << false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001706
tsepez4cf55152016-11-02 14:37:54 -07001707 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001708}
1709
dsinclair3a7741a2016-10-11 10:39:49 -07001710void Field::SetMultiline(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001711 const CFX_WideString& swFieldName,
1712 int nControlIndex,
1713 bool b) {
1714 // Not supported.
1715}
1716
Tom Sepezb1670b52017-02-16 17:01:00 -08001717bool Field::multipleSelection(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001718 CJS_PropValue& vp,
1719 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001720 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001721 if (vp.IsSetting()) {
1722 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001723 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001724
1725 bool bVP;
1726 vp >> bVP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001727 if (m_bDelay) {
1728 AddDelay_Bool(FP_MULTIPLESELECTION, bVP);
1729 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001730 Field::SetMultipleSelection(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -07001731 m_nFormControlIndex, bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001732 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001733 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001734 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001735 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1736 if (FieldArray.empty())
1737 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001738
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001739 CPDF_FormField* pFormField = FieldArray[0];
1740 if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
1741 return false;
1742
1743 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT);
tsepez4cf55152016-11-02 14:37:54 -07001744 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001745}
1746
dsinclair3a7741a2016-10-11 10:39:49 -07001747void Field::SetMultipleSelection(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001748 const CFX_WideString& swFieldName,
1749 int nControlIndex,
1750 bool b) {
1751 // Not supported.
1752}
1753
Tom Sepezb1670b52017-02-16 17:01:00 -08001754bool Field::name(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001755 CJS_PropValue& vp,
1756 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001757 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -07001758 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001759
Lei Zhangd88a3642015-11-10 09:38:57 -08001760 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1761 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001762 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001763
1764 vp << m_FieldName;
tsepez4cf55152016-11-02 14:37:54 -07001765 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001766}
1767
Tom Sepezb1670b52017-02-16 17:01:00 -08001768bool Field::numItems(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001769 CJS_PropValue& vp,
1770 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07001771 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -07001772 return false;
Tom Sepez67fd5df2015-10-08 12:24:19 -07001773
Lei Zhangd88a3642015-11-10 09:38:57 -08001774 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1775 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001776 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001777
Lei Zhangd88a3642015-11-10 09:38:57 -08001778 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001779 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001780 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
tsepez4cf55152016-11-02 14:37:54 -07001781 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001782 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001783
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001784 vp << (int32_t)pFormField->CountOptions();
tsepez4cf55152016-11-02 14:37:54 -07001785 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001786}
1787
Tom Sepezb1670b52017-02-16 17:01:00 -08001788bool Field::page(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001789 CJS_PropValue& vp,
1790 CFX_WideString& sError) {
tsepez8fa82792017-01-11 09:32:33 -08001791 if (!vp.IsGetting()) {
1792 sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
tsepez4cf55152016-11-02 14:37:54 -07001793 return false;
tsepez8fa82792017-01-11 09:32:33 -08001794 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001795
Lei Zhangd88a3642015-11-10 09:38:57 -08001796 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1797 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001798 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001799
Lei Zhangd88a3642015-11-10 09:38:57 -08001800 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001801 if (!pFormField)
tsepez4cf55152016-11-02 14:37:54 -07001802 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001803
tsepez8fa82792017-01-11 09:32:33 -08001804 std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
dsinclair7cbe68e2016-10-12 11:56:23 -07001805 m_pFormFillEnv->GetInterForm()->GetWidgets(pFormField, &widgets);
Lei Zhangd88a3642015-11-10 09:38:57 -08001806 if (widgets.empty()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001807 vp << (int32_t)-1;
tsepez4cf55152016-11-02 14:37:54 -07001808 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001809 }
1810
tsepeze5aff742016-08-08 09:49:42 -07001811 CJS_Array PageArray;
tsepez8fa82792017-01-11 09:32:33 -08001812 int i = 0;
1813 for (const auto& pObserved : widgets) {
1814 if (!pObserved) {
1815 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
1816 return false;
1817 }
1818
Lei Zhang375c2762017-03-10 14:37:14 -08001819 auto* pWidget = static_cast<CPDFSDK_Widget*>(pObserved.Get());
tsepez8fa82792017-01-11 09:32:33 -08001820 CPDFSDK_PageView* pPageView = pWidget->GetPageView();
Lei Zhangd88a3642015-11-10 09:38:57 -08001821 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -07001822 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001823
1824 PageArray.SetElement(
tsepezb4694242016-08-15 16:44:55 -07001825 pRuntime, i, CJS_Value(pRuntime, (int32_t)pPageView->GetPageIndex()));
tsepez8fa82792017-01-11 09:32:33 -08001826 ++i;
Lei Zhangd88a3642015-11-10 09:38:57 -08001827 }
1828
1829 vp << PageArray;
tsepez4cf55152016-11-02 14:37:54 -07001830 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001831}
1832
Tom Sepezb1670b52017-02-16 17:01:00 -08001833bool Field::password(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001834 CJS_PropValue& vp,
1835 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001836 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001837
1838 if (vp.IsSetting()) {
1839 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001840 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001841
1842 bool bVP;
1843 vp >> bVP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001844 if (m_bDelay) {
1845 AddDelay_Bool(FP_PASSWORD, bVP);
1846 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001847 Field::SetPassword(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07001848 bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001849 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001850 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001851 }
1852
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001853 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1854 if (FieldArray.empty())
1855 return false;
1856
1857 CPDF_FormField* pFormField = FieldArray[0];
1858 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1859 return false;
1860
1861 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD);
tsepez4cf55152016-11-02 14:37:54 -07001862 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001863}
1864
dsinclair3a7741a2016-10-11 10:39:49 -07001865void Field::SetPassword(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001866 const CFX_WideString& swFieldName,
1867 int nControlIndex,
1868 bool b) {
1869 // Not supported.
1870}
1871
Tom Sepezb1670b52017-02-16 17:01:00 -08001872bool Field::print(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001873 CJS_PropValue& vp,
1874 CFX_WideString& sError) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001875 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001876 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1877 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001878 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001879
1880 if (vp.IsSetting()) {
1881 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001882 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001883
1884 bool bVP;
1885 vp >> bVP;
1886
Lei Zhangd88a3642015-11-10 09:38:57 -08001887 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001888 if (m_nFormControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -07001889 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001890 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001891 if (CPDFSDK_Widget* pWidget =
dsinclairc5267c52016-11-04 15:35:12 -07001892 pInterForm->GetWidget(pFormField->GetControl(i))) {
tsepezc3255f52016-03-25 14:52:27 -07001893 uint32_t dwFlags = pWidget->GetFlags();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001894 if (bVP)
1895 dwFlags |= ANNOTFLAG_PRINT;
1896 else
1897 dwFlags &= ~ANNOTFLAG_PRINT;
1898
1899 if (dwFlags != pWidget->GetFlags()) {
1900 pWidget->SetFlags(dwFlags);
tsepez4cf55152016-11-02 14:37:54 -07001901 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001902 }
1903 }
1904 }
1905
1906 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -07001907 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001908 } else {
1909 if (m_nFormControlIndex >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07001910 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001911 if (CPDF_FormControl* pFormControl =
1912 pFormField->GetControl(m_nFormControlIndex)) {
dsinclairc5267c52016-11-04 15:35:12 -07001913 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
tsepezc3255f52016-03-25 14:52:27 -07001914 uint32_t dwFlags = pWidget->GetFlags();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001915 if (bVP)
1916 dwFlags |= ANNOTFLAG_PRINT;
1917 else
1918 dwFlags &= ~ANNOTFLAG_PRINT;
1919
1920 if (dwFlags != pWidget->GetFlags()) {
1921 pWidget->SetFlags(dwFlags);
dsinclair3a7741a2016-10-11 10:39:49 -07001922 UpdateFormControl(m_pFormFillEnv.Get(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001923 pFormField->GetControl(m_nFormControlIndex),
tsepez4cf55152016-11-02 14:37:54 -07001924 true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001925 }
1926 }
1927 }
1928 }
1929 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001930 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001931 }
1932
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001933 CPDF_FormField* pFormField = FieldArray[0];
1934 CPDFSDK_Widget* pWidget =
1935 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1936 if (!pWidget)
1937 return false;
1938
1939 vp << !!(pWidget->GetFlags() & ANNOTFLAG_PRINT);
tsepez4cf55152016-11-02 14:37:54 -07001940 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001941}
1942
Tom Sepezb1670b52017-02-16 17:01:00 -08001943bool Field::radiosInUnison(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001944 CJS_PropValue& vp,
1945 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001946 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1947 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001948 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001949
1950 if (vp.IsSetting()) {
1951 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001952 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001953
1954 bool bVP;
1955 vp >> bVP;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001956 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001957 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001958 CPDF_FormField* pFormField = FieldArray[0];
1959 if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
1960 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001961
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001962 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON);
tsepez4cf55152016-11-02 14:37:54 -07001963 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001964}
1965
Tom Sepezb1670b52017-02-16 17:01:00 -08001966bool Field::readonly(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001967 CJS_PropValue& vp,
1968 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001969 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1970 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001971 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001972
1973 if (vp.IsSetting()) {
1974 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001975 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001976
1977 bool bVP;
1978 vp >> bVP;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001979 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001980 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001981 vp << !!(FieldArray[0]->GetFieldFlags() & FIELDFLAG_READONLY);
tsepez4cf55152016-11-02 14:37:54 -07001982 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001983}
1984
Tom Sepezb1670b52017-02-16 17:01:00 -08001985bool Field::rect(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001986 CJS_PropValue& vp,
1987 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07001988 CJS_Value Upper_Leftx(pRuntime);
1989 CJS_Value Upper_Lefty(pRuntime);
1990 CJS_Value Lower_Rightx(pRuntime);
1991 CJS_Value Lower_Righty(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001992
1993 if (vp.IsSetting()) {
1994 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001995 return false;
tsepezf3dc8c62016-08-10 06:29:29 -07001996 if (!vp.GetJSValue()->IsArrayObject())
tsepez4cf55152016-11-02 14:37:54 -07001997 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001998
tsepeze5aff742016-08-08 09:49:42 -07001999 CJS_Array rcArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002000 vp >> rcArray;
tsepezb4694242016-08-15 16:44:55 -07002001 rcArray.GetElement(pRuntime, 0, Upper_Leftx);
2002 rcArray.GetElement(pRuntime, 1, Upper_Lefty);
2003 rcArray.GetElement(pRuntime, 2, Lower_Rightx);
2004 rcArray.GetElement(pRuntime, 3, Lower_Righty);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002005
Dan Sinclair05df0752017-03-14 14:43:42 -04002006 float pArray[4] = {0.0f, 0.0f, 0.0f, 0.0f};
2007 pArray[0] = static_cast<float>(Upper_Leftx.ToInt(pRuntime));
2008 pArray[1] = static_cast<float>(Lower_Righty.ToInt(pRuntime));
2009 pArray[2] = static_cast<float>(Lower_Rightx.ToInt(pRuntime));
2010 pArray[3] = static_cast<float>(Upper_Lefty.ToInt(pRuntime));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002011
Tom Sepez281a9ea2016-02-26 14:24:28 -08002012 CFX_FloatRect crRect(pArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002013 if (m_bDelay) {
2014 AddDelay_Rect(FP_RECT, crRect);
2015 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002016 Field::SetRect(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07002017 crRect);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002018 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002019 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002020 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002021 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2022 if (FieldArray.empty())
2023 return false;
2024
2025 CPDF_FormField* pFormField = FieldArray[0];
2026 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
2027 CPDFSDK_Widget* pWidget =
2028 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
2029 if (!pWidget)
2030 return false;
2031
2032 CFX_FloatRect crRect = pWidget->GetRect();
2033 Upper_Leftx = CJS_Value(pRuntime, static_cast<int32_t>(crRect.left));
2034 Upper_Lefty = CJS_Value(pRuntime, static_cast<int32_t>(crRect.top));
2035 Lower_Rightx = CJS_Value(pRuntime, static_cast<int32_t>(crRect.right));
2036 Lower_Righty = CJS_Value(pRuntime, static_cast<int32_t>(crRect.bottom));
2037
2038 CJS_Array rcArray;
2039 rcArray.SetElement(pRuntime, 0, Upper_Leftx);
2040 rcArray.SetElement(pRuntime, 1, Upper_Lefty);
2041 rcArray.SetElement(pRuntime, 2, Lower_Rightx);
2042 rcArray.SetElement(pRuntime, 3, Lower_Righty);
2043 vp << rcArray;
tsepez4cf55152016-11-02 14:37:54 -07002044 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002045}
2046
dsinclair3a7741a2016-10-11 10:39:49 -07002047void Field::SetRect(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002048 const CFX_WideString& swFieldName,
2049 int nControlIndex,
Tom Sepez281a9ea2016-02-26 14:24:28 -08002050 const CFX_FloatRect& rect) {
dsinclair7cbe68e2016-10-12 11:56:23 -07002051 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08002052 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07002053 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -08002054 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002055 if (nControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -07002056 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08002057 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002058 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08002059 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002060
dsinclairc5267c52016-11-04 15:35:12 -07002061 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002062 CFX_FloatRect crRect = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002063
2064 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002065 crRect.Intersect(pPDFPage->GetPageBBox());
2066
2067 if (!crRect.IsEmpty()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002068 CFX_FloatRect rcOld = pWidget->GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002069 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
2070 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
2071 pWidget->SetRect(crRect);
tsepez4cf55152016-11-02 14:37:54 -07002072 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002073 }
2074 }
2075 }
2076 }
2077
2078 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -07002079 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002080 } else {
2081 if (nControlIndex >= pFormField->CountControls())
2082 return;
2083 if (CPDF_FormControl* pFormControl =
2084 pFormField->GetControl(nControlIndex)) {
dsinclairc5267c52016-11-04 15:35:12 -07002085 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002086 CFX_FloatRect crRect = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002087
2088 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002089 crRect.Intersect(pPDFPage->GetPageBBox());
2090
2091 if (!crRect.IsEmpty()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002092 CFX_FloatRect rcOld = pWidget->GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002093 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
2094 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
2095 pWidget->SetRect(crRect);
tsepez4cf55152016-11-02 14:37:54 -07002096 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002097 }
2098 }
2099 }
2100 }
2101 }
2102 }
2103}
2104
Tom Sepezb1670b52017-02-16 17:01:00 -08002105bool Field::required(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002106 CJS_PropValue& vp,
2107 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002108 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2109 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002110 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002111
2112 if (vp.IsSetting()) {
2113 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002114 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002115
2116 bool bVP;
2117 vp >> bVP;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002118 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002119 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002120 CPDF_FormField* pFormField = FieldArray[0];
2121 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
2122 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002123
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002124 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED);
tsepez4cf55152016-11-02 14:37:54 -07002125 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002126}
2127
Tom Sepezb1670b52017-02-16 17:01:00 -08002128bool Field::richText(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002129 CJS_PropValue& vp,
2130 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002131 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002132
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002133 if (vp.IsSetting()) {
2134 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002135 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002136
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002137 bool bVP;
2138 vp >> bVP;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002139 if (m_bDelay)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002140 AddDelay_Bool(FP_RICHTEXT, bVP);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002141
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002142 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002143 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002144
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002145 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2146 if (FieldArray.empty())
2147 return false;
2148
2149 CPDF_FormField* pFormField = FieldArray[0];
2150 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
2151 return false;
2152
2153 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT);
tsepez4cf55152016-11-02 14:37:54 -07002154 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002155}
2156
Tom Sepezb1670b52017-02-16 17:01:00 -08002157bool Field::richValue(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002158 CJS_PropValue& vp,
2159 CFX_WideString& sError) {
2160 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002161}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002162
Tom Sepezb1670b52017-02-16 17:01:00 -08002163bool Field::rotation(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002164 CJS_PropValue& vp,
2165 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002166 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002167
2168 if (vp.IsSetting()) {
2169 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002170 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002171
2172 int nVP;
2173 vp >> nVP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002174 if (m_bDelay) {
2175 AddDelay_Int(FP_ROTATION, nVP);
2176 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002177 Field::SetRotation(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07002178 nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002179 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002180 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002181 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002182 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2183 if (FieldArray.empty())
2184 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002185
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002186 CPDF_FormField* pFormField = FieldArray[0];
2187 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2188 if (!pFormControl)
2189 return false;
2190
2191 vp << (int32_t)pFormControl->GetRotation();
tsepez4cf55152016-11-02 14:37:54 -07002192 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002193}
2194
dsinclair3a7741a2016-10-11 10:39:49 -07002195void Field::SetRotation(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002196 const CFX_WideString& swFieldName,
2197 int nControlIndex,
2198 int number) {
2199 // Not supported.
2200}
2201
Tom Sepezb1670b52017-02-16 17:01:00 -08002202bool Field::strokeColor(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002203 CJS_PropValue& vp,
2204 CFX_WideString& sError) {
tsepeze5aff742016-08-08 09:49:42 -07002205 CJS_Array crArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002206
2207 if (vp.IsSetting()) {
2208 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002209 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002210
tsepezf3dc8c62016-08-10 06:29:29 -07002211 if (!vp.GetJSValue()->IsArrayObject())
tsepez4cf55152016-11-02 14:37:54 -07002212 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002213
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002214 vp >> crArray;
2215
2216 CPWL_Color color;
tsepeze5aff742016-08-08 09:49:42 -07002217 color::ConvertArrayToPWLColor(pRuntime, crArray, &color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002218 if (m_bDelay) {
2219 AddDelay_Color(FP_STROKECOLOR, color);
2220 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002221 Field::SetStrokeColor(m_pFormFillEnv.Get(), m_FieldName,
2222 m_nFormControlIndex, color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002223 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002224 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002225 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002226 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2227 if (FieldArray.empty())
2228 return false;
2229
2230 CPDF_FormField* pFormField = FieldArray[0];
2231 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2232 if (!pFormControl)
2233 return false;
2234
2235 int iColorType;
2236 pFormControl->GetBorderColor(iColorType);
2237
2238 CPWL_Color color;
2239 if (iColorType == COLORTYPE_TRANSPARENT) {
2240 color = CPWL_Color(COLORTYPE_TRANSPARENT);
2241 } else if (iColorType == COLORTYPE_GRAY) {
2242 color = CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBorderColor(0));
2243 } else if (iColorType == COLORTYPE_RGB) {
2244 color = CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBorderColor(0),
2245 pFormControl->GetOriginalBorderColor(1),
2246 pFormControl->GetOriginalBorderColor(2));
2247 } else if (iColorType == COLORTYPE_CMYK) {
2248 color = CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBorderColor(0),
2249 pFormControl->GetOriginalBorderColor(1),
2250 pFormControl->GetOriginalBorderColor(2),
2251 pFormControl->GetOriginalBorderColor(3));
2252 } else {
2253 return false;
2254 }
2255
2256 color::ConvertPWLColorToArray(pRuntime, color, &crArray);
2257 vp << crArray;
tsepez4cf55152016-11-02 14:37:54 -07002258 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002259}
2260
dsinclair3a7741a2016-10-11 10:39:49 -07002261void Field::SetStrokeColor(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002262 const CFX_WideString& swFieldName,
2263 int nControlIndex,
2264 const CPWL_Color& color) {
2265 // Not supported.
2266}
2267
Tom Sepezb1670b52017-02-16 17:01:00 -08002268bool Field::style(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002269 CJS_PropValue& vp,
2270 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002271 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002272
2273 if (vp.IsSetting()) {
2274 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002275 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002276
2277 CFX_ByteString csBCaption;
2278 vp >> csBCaption;
2279
2280 if (m_bDelay) {
2281 AddDelay_String(FP_STYLE, csBCaption);
2282 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002283 Field::SetStyle(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002284 csBCaption);
2285 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002286 return true;
2287 }
2288 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2289 if (FieldArray.empty())
2290 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002291
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002292 CPDF_FormField* pFormField = FieldArray[0];
2293 if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON &&
2294 pFormField->GetFieldType() != FIELDTYPE_CHECKBOX) {
2295 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002296 }
2297
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002298 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2299 if (!pFormControl)
2300 return false;
2301
2302 CFX_WideString csWCaption = pFormControl->GetNormalCaption();
2303 CFX_ByteString csBCaption;
2304
2305 switch (csWCaption[0]) {
2306 case L'l':
2307 csBCaption = "circle";
2308 break;
2309 case L'8':
2310 csBCaption = "cross";
2311 break;
2312 case L'u':
2313 csBCaption = "diamond";
2314 break;
2315 case L'n':
2316 csBCaption = "square";
2317 break;
2318 case L'H':
2319 csBCaption = "star";
2320 break;
2321 default: // L'4'
2322 csBCaption = "check";
2323 break;
2324 }
2325 vp << csBCaption;
tsepez4cf55152016-11-02 14:37:54 -07002326 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002327}
2328
dsinclair3a7741a2016-10-11 10:39:49 -07002329void Field::SetStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002330 const CFX_WideString& swFieldName,
2331 int nControlIndex,
2332 const CFX_ByteString& string) {
2333 // Not supported.
2334}
2335
Tom Sepezb1670b52017-02-16 17:01:00 -08002336bool Field::submitName(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002337 CJS_PropValue& vp,
2338 CFX_WideString& sError) {
2339 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002340}
2341
Tom Sepezb1670b52017-02-16 17:01:00 -08002342bool Field::textColor(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002343 CJS_PropValue& vp,
2344 CFX_WideString& sError) {
tsepeze5aff742016-08-08 09:49:42 -07002345 CJS_Array crArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002346
2347 if (vp.IsSetting()) {
2348 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002349 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002350
tsepezf3dc8c62016-08-10 06:29:29 -07002351 if (!vp.GetJSValue()->IsArrayObject())
tsepez4cf55152016-11-02 14:37:54 -07002352 return false;
Tom Sepez67fd5df2015-10-08 12:24:19 -07002353
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002354 vp >> crArray;
2355
2356 CPWL_Color color;
tsepeze5aff742016-08-08 09:49:42 -07002357 color::ConvertArrayToPWLColor(pRuntime, crArray, &color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002358 if (m_bDelay) {
2359 AddDelay_Color(FP_TEXTCOLOR, color);
2360 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002361 Field::SetTextColor(m_pFormFillEnv.Get(), m_FieldName,
2362 m_nFormControlIndex, color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002363 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002364 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002365 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002366 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2367 if (FieldArray.empty())
2368 return false;
2369
2370 CPDF_FormField* pFormField = FieldArray[0];
2371 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2372 if (!pFormControl)
2373 return false;
2374
2375 int iColorType;
2376 FX_ARGB color;
2377 CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
2378 FieldAppearance.GetColor(color, iColorType);
2379
2380 int32_t a;
2381 int32_t r;
2382 int32_t g;
2383 int32_t b;
Nicolas Penaddfc3dc2017-04-20 15:29:25 -04002384 std::tie(a, r, g, b) = ArgbDecode(color);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002385
2386 CPWL_Color crRet =
2387 CPWL_Color(COLORTYPE_RGB, r / 255.0f, g / 255.0f, b / 255.0f);
2388
2389 if (iColorType == COLORTYPE_TRANSPARENT)
2390 crRet = CPWL_Color(COLORTYPE_TRANSPARENT);
2391
2392 color::ConvertPWLColorToArray(pRuntime, crRet, &crArray);
2393 vp << crArray;
tsepez4cf55152016-11-02 14:37:54 -07002394 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002395}
2396
dsinclair3a7741a2016-10-11 10:39:49 -07002397void Field::SetTextColor(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002398 const CFX_WideString& swFieldName,
2399 int nControlIndex,
2400 const CPWL_Color& color) {
2401 // Not supported.
2402}
2403
Tom Sepezb1670b52017-02-16 17:01:00 -08002404bool Field::textFont(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002405 CJS_PropValue& vp,
2406 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002407 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002408
2409 if (vp.IsSetting()) {
2410 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002411 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002412
2413 CFX_ByteString csFontName;
2414 vp >> csFontName;
2415 if (csFontName.IsEmpty())
tsepez4cf55152016-11-02 14:37:54 -07002416 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002417
2418 if (m_bDelay) {
2419 AddDelay_String(FP_TEXTFONT, csFontName);
2420 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002421 Field::SetTextFont(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002422 csFontName);
2423 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002424 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002425 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002426 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2427 if (FieldArray.empty())
2428 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002429
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002430 CPDF_FormField* pFormField = FieldArray[0];
2431 ASSERT(pFormField);
2432 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2433 if (!pFormControl)
2434 return false;
2435
2436 int nFieldType = pFormField->GetFieldType();
2437 if (nFieldType != FIELDTYPE_PUSHBUTTON && nFieldType != FIELDTYPE_COMBOBOX &&
2438 nFieldType != FIELDTYPE_LISTBOX && nFieldType != FIELDTYPE_TEXTFIELD) {
2439 return false;
2440 }
2441 CPDF_Font* pFont = pFormControl->GetDefaultControlFont();
2442 if (!pFont)
2443 return false;
2444
2445 vp << pFont->GetBaseFont();
tsepez4cf55152016-11-02 14:37:54 -07002446 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002447}
2448
dsinclair3a7741a2016-10-11 10:39:49 -07002449void Field::SetTextFont(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002450 const CFX_WideString& swFieldName,
2451 int nControlIndex,
2452 const CFX_ByteString& string) {
2453 // Not supported.
2454}
2455
Tom Sepezb1670b52017-02-16 17:01:00 -08002456bool Field::textSize(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002457 CJS_PropValue& vp,
2458 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002459 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002460
2461 if (vp.IsSetting()) {
2462 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002463 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002464
2465 int nVP;
2466 vp >> nVP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002467 if (m_bDelay) {
2468 AddDelay_Int(FP_TEXTSIZE, nVP);
2469 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002470 Field::SetTextSize(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07002471 nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002472 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002473 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002474 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002475 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2476 if (FieldArray.empty())
2477 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002478
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002479 CPDF_FormField* pFormField = FieldArray[0];
2480 ASSERT(pFormField);
2481 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2482 if (!pFormControl)
2483 return false;
2484
Dan Sinclair05df0752017-03-14 14:43:42 -04002485 float fFontSize;
Tom Sepezc4a2b752017-04-07 13:56:13 -07002486 CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
2487 FieldAppearance.GetFont(&fFontSize);
2488 vp << static_cast<int>(fFontSize);
tsepez4cf55152016-11-02 14:37:54 -07002489 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002490}
2491
dsinclair3a7741a2016-10-11 10:39:49 -07002492void Field::SetTextSize(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002493 const CFX_WideString& swFieldName,
2494 int nControlIndex,
2495 int number) {
2496 // Not supported.
2497}
2498
Tom Sepezb1670b52017-02-16 17:01:00 -08002499bool Field::type(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002500 CJS_PropValue& vp,
2501 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002502 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -07002503 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002504
Lei Zhangd88a3642015-11-10 09:38:57 -08002505 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2506 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002507 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002508
Lei Zhangd88a3642015-11-10 09:38:57 -08002509 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002510 switch (pFormField->GetFieldType()) {
2511 case FIELDTYPE_UNKNOWN:
2512 vp << L"unknown";
2513 break;
2514 case FIELDTYPE_PUSHBUTTON:
2515 vp << L"button";
2516 break;
2517 case FIELDTYPE_CHECKBOX:
2518 vp << L"checkbox";
2519 break;
2520 case FIELDTYPE_RADIOBUTTON:
2521 vp << L"radiobutton";
2522 break;
2523 case FIELDTYPE_COMBOBOX:
2524 vp << L"combobox";
2525 break;
2526 case FIELDTYPE_LISTBOX:
2527 vp << L"listbox";
2528 break;
2529 case FIELDTYPE_TEXTFIELD:
2530 vp << L"text";
2531 break;
2532 case FIELDTYPE_SIGNATURE:
2533 vp << L"signature";
2534 break;
2535 default:
2536 vp << L"unknown";
2537 break;
2538 }
tsepez4cf55152016-11-02 14:37:54 -07002539 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002540}
2541
Tom Sepezb1670b52017-02-16 17:01:00 -08002542bool Field::userName(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002543 CJS_PropValue& vp,
2544 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002545 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002546
2547 if (vp.IsSetting()) {
2548 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002549 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002550
2551 CFX_WideString swName;
2552 vp >> swName;
2553
2554 if (m_bDelay) {
2555 AddDelay_WideString(FP_USERNAME, swName);
2556 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002557 Field::SetUserName(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07002558 swName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002559 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002560 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002561 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002562 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2563 if (FieldArray.empty())
2564 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002565
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002566 vp << FieldArray[0]->GetAlternateName();
tsepez4cf55152016-11-02 14:37:54 -07002567 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002568}
2569
dsinclair3a7741a2016-10-11 10:39:49 -07002570void Field::SetUserName(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002571 const CFX_WideString& swFieldName,
2572 int nControlIndex,
2573 const CFX_WideString& string) {
2574 // Not supported.
2575}
2576
Tom Sepezb1670b52017-02-16 17:01:00 -08002577bool Field::value(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002578 CJS_PropValue& vp,
2579 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002580 if (vp.IsSetting()) {
2581 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002582 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002583
tsepez41a53ad2016-03-28 16:59:30 -07002584 std::vector<CFX_WideString> strArray;
tsepezf3dc8c62016-08-10 06:29:29 -07002585 if (vp.GetJSValue()->IsArrayObject()) {
tsepeze5aff742016-08-08 09:49:42 -07002586 CJS_Array ValueArray;
tsepezb4694242016-08-15 16:44:55 -07002587 vp.GetJSValue()->ConvertToArray(pRuntime, ValueArray);
2588 for (int i = 0, sz = ValueArray.GetLength(pRuntime); i < sz; i++) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002589 CJS_Value ElementValue(pRuntime);
tsepezb4694242016-08-15 16:44:55 -07002590 ValueArray.GetElement(pRuntime, i, ElementValue);
2591 strArray.push_back(ElementValue.ToCFXWideString(pRuntime));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002592 }
2593 } else {
2594 CFX_WideString swValue;
2595 vp >> swValue;
tsepez41a53ad2016-03-28 16:59:30 -07002596 strArray.push_back(swValue);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002597 }
2598
2599 if (m_bDelay) {
2600 AddDelay_WideStringArray(FP_VALUE, strArray);
2601 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002602 Field::SetValue(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07002603 strArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002604 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002605 return true;
2606 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002607
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002608 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2609 if (FieldArray.empty())
2610 return false;
2611
2612 CPDF_FormField* pFormField = FieldArray[0];
2613 switch (pFormField->GetFieldType()) {
2614 case FIELDTYPE_PUSHBUTTON:
2615 return false;
2616 case FIELDTYPE_COMBOBOX:
2617 case FIELDTYPE_TEXTFIELD: {
2618 vp << pFormField->GetValue();
2619 } break;
2620 case FIELDTYPE_LISTBOX: {
2621 if (pFormField->CountSelectedItems() > 1) {
2622 CJS_Array ValueArray;
2623 CJS_Value ElementValue(pRuntime);
2624 int iIndex;
2625 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
2626 iIndex = pFormField->GetSelectedIndex(i);
2627 ElementValue =
2628 CJS_Value(pRuntime, pFormField->GetOptionValue(iIndex).c_str());
2629 if (FXSYS_wcslen(ElementValue.ToCFXWideString(pRuntime).c_str()) ==
2630 0) {
tsepezf3dc8c62016-08-10 06:29:29 -07002631 ElementValue =
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002632 CJS_Value(pRuntime, pFormField->GetOptionLabel(iIndex).c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002633 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002634 ValueArray.SetElement(pRuntime, i, ElementValue);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002635 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002636 vp << ValueArray;
2637 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002638 vp << pFormField->GetValue();
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002639 }
2640 } break;
2641 case FIELDTYPE_CHECKBOX:
2642 case FIELDTYPE_RADIOBUTTON: {
2643 bool bFind = false;
2644 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2645 if (pFormField->GetControl(i)->IsChecked()) {
2646 vp << pFormField->GetControl(i)->GetExportValue();
2647 bFind = true;
2648 break;
2649 }
2650 }
2651 if (!bFind)
2652 vp << L"Off";
2653 } break;
2654 default:
2655 vp << pFormField->GetValue();
2656 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002657 }
tsepezb4694242016-08-15 16:44:55 -07002658 vp.GetJSValue()->MaybeCoerceToNumber(pRuntime);
tsepez4cf55152016-11-02 14:37:54 -07002659 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002660}
2661
dsinclair3a7741a2016-10-11 10:39:49 -07002662void Field::SetValue(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002663 const CFX_WideString& swFieldName,
2664 int nControlIndex,
tsepez41a53ad2016-03-28 16:59:30 -07002665 const std::vector<CFX_WideString>& strArray) {
dsinclair3a7741a2016-10-11 10:39:49 -07002666 ASSERT(pFormFillEnv);
tsepez41a53ad2016-03-28 16:59:30 -07002667 if (strArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002668 return;
2669
Lei Zhangd88a3642015-11-10 09:38:57 -08002670 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07002671 GetFormFields(pFormFillEnv, swFieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002672
Lei Zhangd88a3642015-11-10 09:38:57 -08002673 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002674 if (pFormField->GetFullName().Compare(swFieldName) != 0)
2675 continue;
2676
2677 switch (pFormField->GetFieldType()) {
2678 case FIELDTYPE_TEXTFIELD:
2679 case FIELDTYPE_COMBOBOX:
tsepez41a53ad2016-03-28 16:59:30 -07002680 if (pFormField->GetValue() != strArray[0]) {
tsepez4cf55152016-11-02 14:37:54 -07002681 pFormField->SetValue(strArray[0], true);
2682 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002683 }
2684 break;
tsepez41a53ad2016-03-28 16:59:30 -07002685 case FIELDTYPE_CHECKBOX:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002686 case FIELDTYPE_RADIOBUTTON: {
tsepez41a53ad2016-03-28 16:59:30 -07002687 if (pFormField->GetValue() != strArray[0]) {
tsepez4cf55152016-11-02 14:37:54 -07002688 pFormField->SetValue(strArray[0], true);
2689 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002690 }
2691 } break;
2692 case FIELDTYPE_LISTBOX: {
tsepez4cf55152016-11-02 14:37:54 -07002693 bool bModified = false;
tsepez41a53ad2016-03-28 16:59:30 -07002694 for (const auto& str : strArray) {
2695 if (!pFormField->IsItemSelected(pFormField->FindOption(str))) {
tsepez4cf55152016-11-02 14:37:54 -07002696 bModified = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002697 break;
2698 }
2699 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002700 if (bModified) {
tsepez4cf55152016-11-02 14:37:54 -07002701 pFormField->ClearSelection(true);
tsepez41a53ad2016-03-28 16:59:30 -07002702 for (const auto& str : strArray) {
2703 int index = pFormField->FindOption(str);
2704 if (!pFormField->IsItemSelected(index))
tsepez4cf55152016-11-02 14:37:54 -07002705 pFormField->SetItemSelection(index, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002706 }
tsepez4cf55152016-11-02 14:37:54 -07002707 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002708 }
2709 } break;
2710 default:
2711 break;
2712 }
2713 }
2714}
2715
Tom Sepezb1670b52017-02-16 17:01:00 -08002716bool Field::valueAsString(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002717 CJS_PropValue& vp,
2718 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002719 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -07002720 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002721
Lei Zhangd88a3642015-11-10 09:38:57 -08002722 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2723 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002724 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002725
Lei Zhangd88a3642015-11-10 09:38:57 -08002726 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002727 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002728 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002729
2730 if (pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) {
2731 if (!pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002732 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002733
2734 if (pFormField->GetControl(0)->IsChecked())
2735 vp << L"Yes";
2736 else
2737 vp << L"Off";
2738 } else if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON &&
2739 !(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)) {
2740 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2741 if (pFormField->GetControl(i)->IsChecked()) {
2742 vp << pFormField->GetControl(i)->GetExportValue().c_str();
2743 break;
Lei Zhangd88a3642015-11-10 09:38:57 -08002744 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002745 vp << L"Off";
Lei Zhangd88a3642015-11-10 09:38:57 -08002746 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002747 }
2748 } else if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX &&
2749 (pFormField->CountSelectedItems() > 1)) {
2750 vp << L"";
Lei Zhangd88a3642015-11-10 09:38:57 -08002751 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002752 vp << pFormField->GetValue().c_str();
Lei Zhangd88a3642015-11-10 09:38:57 -08002753 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002754
tsepez4cf55152016-11-02 14:37:54 -07002755 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002756}
2757
Tom Sepezb1670b52017-02-16 17:01:00 -08002758bool Field::browseForFileToSubmit(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002759 const std::vector<CJS_Value>& params,
2760 CJS_Value& vRet,
2761 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002762 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2763 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002764 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002765
Lei Zhangd88a3642015-11-10 09:38:57 -08002766 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002767 if ((pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) &&
2768 (pFormField->GetFieldType() == FIELDTYPE_TEXTFIELD)) {
dsinclair3a7741a2016-10-11 10:39:49 -07002769 CFX_WideString wsFileName = m_pFormFillEnv->JS_fieldBrowse();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002770 if (!wsFileName.IsEmpty()) {
2771 pFormField->SetValue(wsFileName);
tsepez4cf55152016-11-02 14:37:54 -07002772 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002773 }
tsepez4cf55152016-11-02 14:37:54 -07002774 return true;
Lei Zhangd88a3642015-11-10 09:38:57 -08002775 }
tsepez4cf55152016-11-02 14:37:54 -07002776 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002777}
2778
Tom Sepezb1670b52017-02-16 17:01:00 -08002779bool Field::buttonGetCaption(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002780 const std::vector<CJS_Value>& params,
2781 CJS_Value& vRet,
2782 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002783 int nface = 0;
2784 int iSize = params.size();
2785 if (iSize >= 1)
tsepezb4694242016-08-15 16:44:55 -07002786 nface = params[0].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002787
Lei Zhangd88a3642015-11-10 09:38:57 -08002788 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2789 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002790 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002791
Lei Zhangd88a3642015-11-10 09:38:57 -08002792 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002793 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002794 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002795
2796 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2797 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -07002798 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002799
2800 if (nface == 0)
tsepezf3dc8c62016-08-10 06:29:29 -07002801 vRet = CJS_Value(pRuntime, pFormControl->GetNormalCaption().c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002802 else if (nface == 1)
tsepezf3dc8c62016-08-10 06:29:29 -07002803 vRet = CJS_Value(pRuntime, pFormControl->GetDownCaption().c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002804 else if (nface == 2)
tsepezf3dc8c62016-08-10 06:29:29 -07002805 vRet = CJS_Value(pRuntime, pFormControl->GetRolloverCaption().c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002806 else
tsepez4cf55152016-11-02 14:37:54 -07002807 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002808
tsepez4cf55152016-11-02 14:37:54 -07002809 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002810}
2811
Tom Sepezb1670b52017-02-16 17:01:00 -08002812bool Field::buttonGetIcon(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002813 const std::vector<CJS_Value>& params,
2814 CJS_Value& vRet,
2815 CFX_WideString& sError) {
Tom Sepez40e0a812017-02-23 13:07:36 -08002816 if (params.size() >= 1) {
2817 int nFace = params[0].ToInt(pRuntime);
2818 if (nFace < 0 || nFace > 2)
2819 return false;
2820 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002821
Lei Zhangd88a3642015-11-10 09:38:57 -08002822 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2823 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002824 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002825
Lei Zhangd88a3642015-11-10 09:38:57 -08002826 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002827 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002828 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002829
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002830 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2831 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -07002832 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002833
tsepezb4694242016-08-15 16:44:55 -07002834 v8::Local<v8::Object> pObj =
2835 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID);
Tom Sepezc5a14722017-02-24 15:31:12 -08002836 if (pObj.IsEmpty())
2837 return false;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002838
tsepezb4694242016-08-15 16:44:55 -07002839 CJS_Icon* pJS_Icon = static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj));
tsepezf3dc8c62016-08-10 06:29:29 -07002840 vRet = CJS_Value(pRuntime, pJS_Icon);
tsepez4cf55152016-11-02 14:37:54 -07002841 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002842}
2843
Tom Sepezb1670b52017-02-16 17:01:00 -08002844bool Field::buttonImportIcon(CJS_Runtime* pRuntime,
Lei Zhang945fdb72015-11-11 10:18:16 -08002845 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002846 CJS_Value& vRet,
2847 CFX_WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002848 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002849}
2850
Tom Sepezb1670b52017-02-16 17:01:00 -08002851bool Field::buttonSetCaption(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002852 const std::vector<CJS_Value>& params,
2853 CJS_Value& vRet,
2854 CFX_WideString& sError) {
2855 return false;
2856}
2857
Tom Sepezb1670b52017-02-16 17:01:00 -08002858bool Field::buttonSetIcon(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002859 const std::vector<CJS_Value>& params,
2860 CJS_Value& vRet,
2861 CFX_WideString& sError) {
2862 return false;
2863}
2864
Tom Sepezb1670b52017-02-16 17:01:00 -08002865bool Field::checkThisBox(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002866 const std::vector<CJS_Value>& params,
2867 CJS_Value& vRet,
2868 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002869 int iSize = params.size();
2870 if (iSize < 1)
tsepez4cf55152016-11-02 14:37:54 -07002871 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002872
tsepezf3dc8c62016-08-10 06:29:29 -07002873 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002874 return false;
tsepezf3dc8c62016-08-10 06:29:29 -07002875
tsepezb4694242016-08-15 16:44:55 -07002876 int nWidget = params[0].ToInt(pRuntime);
Wei Li97da9762016-03-11 17:00:48 -08002877 bool bCheckit = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002878 if (iSize >= 2)
tsepezb4694242016-08-15 16:44:55 -07002879 bCheckit = params[1].ToBool(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002880
Lei Zhangd88a3642015-11-10 09:38:57 -08002881 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2882 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002883 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002884
Lei Zhangd88a3642015-11-10 09:38:57 -08002885 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002886 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
2887 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002888 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002889 if (nWidget < 0 || nWidget >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002890 return false;
Wei Li97da9762016-03-11 17:00:48 -08002891 // TODO(weili): Check whether anything special needed for radio button,
2892 // otherwise merge these branches.
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002893 if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)
Wei Li97da9762016-03-11 17:00:48 -08002894 pFormField->CheckControl(nWidget, bCheckit, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002895 else
Wei Li97da9762016-03-11 17:00:48 -08002896 pFormField->CheckControl(nWidget, bCheckit, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002897
tsepez4cf55152016-11-02 14:37:54 -07002898 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true);
2899 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002900}
2901
Tom Sepezb1670b52017-02-16 17:01:00 -08002902bool Field::clearItems(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002903 const std::vector<CJS_Value>& params,
2904 CJS_Value& vRet,
2905 CFX_WideString& sError) {
2906 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002907}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002908
Tom Sepezb1670b52017-02-16 17:01:00 -08002909bool Field::defaultIsChecked(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002910 const std::vector<CJS_Value>& params,
2911 CJS_Value& vRet,
2912 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002913 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002914 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002915
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002916 int iSize = params.size();
2917 if (iSize < 1)
tsepez4cf55152016-11-02 14:37:54 -07002918 return false;
Tom Sepezf4ef3f92015-04-23 11:31:31 -07002919
tsepezb4694242016-08-15 16:44:55 -07002920 int nWidget = params[0].ToInt(pRuntime);
Lei Zhangd88a3642015-11-10 09:38:57 -08002921 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2922 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002923 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002924
Lei Zhangd88a3642015-11-10 09:38:57 -08002925 CPDF_FormField* pFormField = FieldArray[0];
tsepezf3dc8c62016-08-10 06:29:29 -07002926 if (nWidget < 0 || nWidget >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002927 return false;
tsepezf3dc8c62016-08-10 06:29:29 -07002928
2929 vRet = CJS_Value(pRuntime,
2930 pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
2931 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002932
tsepez4cf55152016-11-02 14:37:54 -07002933 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002934}
2935
Tom Sepezb1670b52017-02-16 17:01:00 -08002936bool Field::deleteItemAt(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002937 const std::vector<CJS_Value>& params,
2938 CJS_Value& vRet,
2939 CFX_WideString& sError) {
2940 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002941}
2942
Tom Sepezb1670b52017-02-16 17:01:00 -08002943bool Field::getArray(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002944 const std::vector<CJS_Value>& params,
2945 CJS_Value& vRet,
2946 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002947 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2948 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002949 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002950
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002951 std::vector<std::unique_ptr<CFX_WideString>> swSort;
2952 for (CPDF_FormField* pFormField : FieldArray) {
2953 swSort.push_back(std::unique_ptr<CFX_WideString>(
2954 new CFX_WideString(pFormField->GetFullName())));
2955 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002956
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002957 std::sort(
2958 swSort.begin(), swSort.end(),
2959 [](const std::unique_ptr<CFX_WideString>& p1,
2960 const std::unique_ptr<CFX_WideString>& p2) { return *p1 < *p2; });
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002961
tsepeze5aff742016-08-08 09:49:42 -07002962 CJS_Array FormFieldArray;
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002963
2964 int j = 0;
2965 for (const auto& pStr : swSort) {
tsepezb4694242016-08-15 16:44:55 -07002966 v8::Local<v8::Object> pObj =
2967 pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID);
Tom Sepezc5a14722017-02-24 15:31:12 -08002968 if (pObj.IsEmpty())
2969 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002970
Tom Sepezd5a0e952015-09-17 15:40:06 -07002971 CJS_Field* pJSField =
tsepezb4694242016-08-15 16:44:55 -07002972 static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pObj));
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002973 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002974 pField->AttachField(m_pJSDoc, *pStr);
tsepezb4694242016-08-15 16:44:55 -07002975 FormFieldArray.SetElement(pRuntime, j++, CJS_Value(pRuntime, pJSField));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002976 }
2977
tsepeze5aff742016-08-08 09:49:42 -07002978 vRet = CJS_Value(pRuntime, FormFieldArray);
tsepez4cf55152016-11-02 14:37:54 -07002979 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002980}
2981
Tom Sepezb1670b52017-02-16 17:01:00 -08002982bool Field::getItemAt(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002983 const std::vector<CJS_Value>& params,
2984 CJS_Value& vRet,
2985 CFX_WideString& sError) {
tsepezf3dc8c62016-08-10 06:29:29 -07002986 int iSize = params.size();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002987 int nIdx = -1;
2988 if (iSize >= 1)
tsepezb4694242016-08-15 16:44:55 -07002989 nIdx = params[0].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002990
tsepez4cf55152016-11-02 14:37:54 -07002991 bool bExport = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002992 if (iSize >= 2)
tsepezb4694242016-08-15 16:44:55 -07002993 bExport = params[1].ToBool(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002994
Lei Zhangd88a3642015-11-10 09:38:57 -08002995 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2996 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002997 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002998
Lei Zhangd88a3642015-11-10 09:38:57 -08002999 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003000 if ((pFormField->GetFieldType() == FIELDTYPE_LISTBOX) ||
3001 (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX)) {
3002 if (nIdx == -1 || nIdx > pFormField->CountOptions())
3003 nIdx = pFormField->CountOptions() - 1;
3004 if (bExport) {
3005 CFX_WideString strval = pFormField->GetOptionValue(nIdx);
3006 if (strval.IsEmpty())
tsepezf3dc8c62016-08-10 06:29:29 -07003007 vRet = CJS_Value(pRuntime, pFormField->GetOptionLabel(nIdx).c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003008 else
tsepezf3dc8c62016-08-10 06:29:29 -07003009 vRet = CJS_Value(pRuntime, strval.c_str());
Lei Zhangd88a3642015-11-10 09:38:57 -08003010 } else {
tsepezf3dc8c62016-08-10 06:29:29 -07003011 vRet = CJS_Value(pRuntime, pFormField->GetOptionLabel(nIdx).c_str());
Lei Zhangd88a3642015-11-10 09:38:57 -08003012 }
3013 } else {
tsepez4cf55152016-11-02 14:37:54 -07003014 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08003015 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003016
tsepez4cf55152016-11-02 14:37:54 -07003017 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003018}
3019
Tom Sepezb1670b52017-02-16 17:01:00 -08003020bool Field::getLock(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003021 const std::vector<CJS_Value>& params,
3022 CJS_Value& vRet,
3023 CFX_WideString& sError) {
3024 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003025}
3026
Tom Sepezb1670b52017-02-16 17:01:00 -08003027bool Field::insertItemAt(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003028 const std::vector<CJS_Value>& params,
3029 CJS_Value& vRet,
3030 CFX_WideString& sError) {
3031 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003032}
3033
Tom Sepezb1670b52017-02-16 17:01:00 -08003034bool Field::isBoxChecked(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003035 const std::vector<CJS_Value>& params,
3036 CJS_Value& vRet,
3037 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003038 int nIndex = -1;
3039 if (params.size() >= 1)
tsepezb4694242016-08-15 16:44:55 -07003040 nIndex = params[0].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003041
Lei Zhangd88a3642015-11-10 09:38:57 -08003042 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3043 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07003044 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003045
Lei Zhangd88a3642015-11-10 09:38:57 -08003046 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003047 if (nIndex < 0 || nIndex >= pFormField->CountControls()) {
tsepez4cf55152016-11-02 14:37:54 -07003048 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003049 }
3050
tsepezf3dc8c62016-08-10 06:29:29 -07003051 vRet = CJS_Value(pRuntime,
3052 ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
3053 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) &&
3054 pFormField->GetControl(nIndex)->IsChecked() != 0));
tsepez4cf55152016-11-02 14:37:54 -07003055 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003056}
3057
Tom Sepezb1670b52017-02-16 17:01:00 -08003058bool Field::isDefaultChecked(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003059 const std::vector<CJS_Value>& params,
3060 CJS_Value& vRet,
3061 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003062 int nIndex = -1;
3063 if (params.size() >= 1)
tsepezb4694242016-08-15 16:44:55 -07003064 nIndex = params[0].ToInt(pRuntime);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003065
Lei Zhangd88a3642015-11-10 09:38:57 -08003066 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3067 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07003068 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003069
Lei Zhangd88a3642015-11-10 09:38:57 -08003070 CPDF_FormField* pFormField = FieldArray[0];
tsepezf3dc8c62016-08-10 06:29:29 -07003071 if (nIndex < 0 || nIndex >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07003072 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003073
tsepezf3dc8c62016-08-10 06:29:29 -07003074 vRet = CJS_Value(pRuntime,
3075 ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
3076 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) &&
3077 pFormField->GetControl(nIndex)->IsDefaultChecked() != 0));
tsepez4cf55152016-11-02 14:37:54 -07003078 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003079}
3080
Tom Sepezb1670b52017-02-16 17:01:00 -08003081bool Field::setAction(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003082 const std::vector<CJS_Value>& params,
3083 CJS_Value& vRet,
3084 CFX_WideString& sError) {
3085 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003086}
3087
Tom Sepezb1670b52017-02-16 17:01:00 -08003088bool Field::setFocus(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003089 const std::vector<CJS_Value>& params,
3090 CJS_Value& vRet,
3091 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08003092 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3093 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07003094 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003095
Lei Zhangd88a3642015-11-10 09:38:57 -08003096 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003097 int32_t nCount = pFormField->CountControls();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003098 if (nCount < 1)
tsepez4cf55152016-11-02 14:37:54 -07003099 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003100
dsinclair7cbe68e2016-10-12 11:56:23 -07003101 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
thestig1cd352e2016-06-07 17:53:06 -07003102 CPDFSDK_Widget* pWidget = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003103 if (nCount == 1) {
dsinclairc5267c52016-11-04 15:35:12 -07003104 pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003105 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07003106 UnderlyingPageType* pPage =
3107 UnderlyingFromFPDFPage(m_pFormFillEnv->GetCurrentPage(
3108 m_pFormFillEnv->GetUnderlyingDocument()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003109 if (!pPage)
tsepez4cf55152016-11-02 14:37:54 -07003110 return false;
dsinclair461eeaf2016-07-27 07:40:05 -07003111 if (CPDFSDK_PageView* pCurPageView =
dsinclair7cbe68e2016-10-12 11:56:23 -07003112 m_pFormFillEnv->GetPageView(pPage, true)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003113 for (int32_t i = 0; i < nCount; i++) {
3114 if (CPDFSDK_Widget* pTempWidget =
dsinclairc5267c52016-11-04 15:35:12 -07003115 pInterForm->GetWidget(pFormField->GetControl(i))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003116 if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage()) {
3117 pWidget = pTempWidget;
3118 break;
3119 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003120 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003121 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003122 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003123 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003124
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003125 if (pWidget) {
tsepezf8074ce2016-09-27 14:29:57 -07003126 CPDFSDK_Annot::ObservedPtr pObserved(pWidget);
dsinclair7cbe68e2016-10-12 11:56:23 -07003127 m_pFormFillEnv->SetFocusAnnot(&pObserved);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003128 }
3129
tsepez4cf55152016-11-02 14:37:54 -07003130 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003131}
3132
Tom Sepezb1670b52017-02-16 17:01:00 -08003133bool Field::setItems(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003134 const std::vector<CJS_Value>& params,
3135 CJS_Value& vRet,
3136 CFX_WideString& sError) {
3137 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003138}
3139
Tom Sepezb1670b52017-02-16 17:01:00 -08003140bool Field::setLock(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003141 const std::vector<CJS_Value>& params,
3142 CJS_Value& vRet,
3143 CFX_WideString& sError) {
3144 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003145}
3146
Tom Sepezb1670b52017-02-16 17:01:00 -08003147bool Field::signatureGetModifications(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003148 const std::vector<CJS_Value>& params,
3149 CJS_Value& vRet,
3150 CFX_WideString& sError) {
3151 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003152}
3153
Tom Sepezb1670b52017-02-16 17:01:00 -08003154bool Field::signatureGetSeedValue(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003155 const std::vector<CJS_Value>& params,
3156 CJS_Value& vRet,
3157 CFX_WideString& sError) {
3158 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003159}
3160
Tom Sepezb1670b52017-02-16 17:01:00 -08003161bool Field::signatureInfo(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003162 const std::vector<CJS_Value>& params,
3163 CJS_Value& vRet,
3164 CFX_WideString& sError) {
3165 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003166}
3167
Tom Sepezb1670b52017-02-16 17:01:00 -08003168bool Field::signatureSetSeedValue(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003169 const std::vector<CJS_Value>& params,
3170 CJS_Value& vRet,
3171 CFX_WideString& sError) {
3172 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003173}
3174
Tom Sepezb1670b52017-02-16 17:01:00 -08003175bool Field::signatureSign(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003176 const std::vector<CJS_Value>& params,
3177 CJS_Value& vRet,
3178 CFX_WideString& sError) {
3179 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003180}
3181
Tom Sepezb1670b52017-02-16 17:01:00 -08003182bool Field::signatureValidate(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003183 const std::vector<CJS_Value>& params,
3184 CJS_Value& vRet,
3185 CFX_WideString& sError) {
3186 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003187}
3188
Tom Sepezb1670b52017-02-16 17:01:00 -08003189bool Field::source(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08003190 CJS_PropValue& vp,
3191 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003192 if (vp.IsGetting()) {
thestig1cd352e2016-06-07 17:53:06 -07003193 vp << (CJS_Object*)nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003194 }
3195
tsepez4cf55152016-11-02 14:37:54 -07003196 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003197}
3198
tsepez41a53ad2016-03-28 16:59:30 -07003199void Field::AddDelay_Int(FIELD_PROP prop, int32_t n) {
3200 CJS_DelayData* pNewData =
3201 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003202 pNewData->num = n;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003203 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003204}
3205
tsepez41a53ad2016-03-28 16:59:30 -07003206void Field::AddDelay_Bool(FIELD_PROP prop, bool b) {
3207 CJS_DelayData* pNewData =
3208 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003209 pNewData->b = b;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003210 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003211}
3212
tsepez41a53ad2016-03-28 16:59:30 -07003213void Field::AddDelay_String(FIELD_PROP prop, const CFX_ByteString& string) {
3214 CJS_DelayData* pNewData =
3215 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003216 pNewData->string = string;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003217 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003218}
3219
tsepez41a53ad2016-03-28 16:59:30 -07003220void Field::AddDelay_WideString(FIELD_PROP prop, const CFX_WideString& string) {
3221 CJS_DelayData* pNewData =
3222 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003223 pNewData->widestring = string;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003224 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003225}
3226
tsepez41a53ad2016-03-28 16:59:30 -07003227void Field::AddDelay_Rect(FIELD_PROP prop, const CFX_FloatRect& rect) {
3228 CJS_DelayData* pNewData =
3229 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003230 pNewData->rect = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003231 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003232}
3233
tsepez41a53ad2016-03-28 16:59:30 -07003234void Field::AddDelay_Color(FIELD_PROP prop, const CPWL_Color& color) {
3235 CJS_DelayData* pNewData =
3236 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003237 pNewData->color = color;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003238 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003239}
3240
tsepez41a53ad2016-03-28 16:59:30 -07003241void Field::AddDelay_WordArray(FIELD_PROP prop,
3242 const std::vector<uint32_t>& array) {
3243 CJS_DelayData* pNewData =
3244 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
3245 pNewData->wordarray = array;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003246 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003247}
3248
tsepez41a53ad2016-03-28 16:59:30 -07003249void Field::AddDelay_WideStringArray(FIELD_PROP prop,
3250 const std::vector<CFX_WideString>& array) {
3251 CJS_DelayData* pNewData =
3252 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
3253 pNewData->widestringarray = array;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003254 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003255}
3256
dsinclair3a7741a2016-10-11 10:39:49 -07003257void Field::DoDelay(CPDFSDK_FormFillEnvironment* pFormFillEnv,
3258 CJS_DelayData* pData) {
3259 ASSERT(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003260 switch (pData->eProp) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003261 case FP_ALIGNMENT:
dsinclair3a7741a2016-10-11 10:39:49 -07003262 Field::SetAlignment(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003263 pData->string);
3264 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003265 case FP_BORDERSTYLE:
dsinclair3a7741a2016-10-11 10:39:49 -07003266 Field::SetBorderStyle(pFormFillEnv, pData->sFieldName,
3267 pData->nControlIndex, pData->string);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003268 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003269 case FP_BUTTONALIGNX:
dsinclair3a7741a2016-10-11 10:39:49 -07003270 Field::SetButtonAlignX(pFormFillEnv, pData->sFieldName,
3271 pData->nControlIndex, pData->num);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003272 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003273 case FP_BUTTONALIGNY:
dsinclair3a7741a2016-10-11 10:39:49 -07003274 Field::SetButtonAlignY(pFormFillEnv, pData->sFieldName,
3275 pData->nControlIndex, pData->num);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003276 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003277 case FP_BUTTONFITBOUNDS:
dsinclair3a7741a2016-10-11 10:39:49 -07003278 Field::SetButtonFitBounds(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003279 pData->nControlIndex, pData->b);
3280 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003281 case FP_BUTTONPOSITION:
dsinclair3a7741a2016-10-11 10:39:49 -07003282 Field::SetButtonPosition(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003283 pData->nControlIndex, pData->num);
3284 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003285 case FP_BUTTONSCALEHOW:
dsinclair3a7741a2016-10-11 10:39:49 -07003286 Field::SetButtonScaleHow(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003287 pData->nControlIndex, pData->num);
3288 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003289 case FP_BUTTONSCALEWHEN:
dsinclair3a7741a2016-10-11 10:39:49 -07003290 Field::SetButtonScaleWhen(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003291 pData->nControlIndex, pData->num);
3292 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003293 case FP_CALCORDERINDEX:
dsinclair3a7741a2016-10-11 10:39:49 -07003294 Field::SetCalcOrderIndex(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003295 pData->nControlIndex, pData->num);
3296 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003297 case FP_CHARLIMIT:
dsinclair3a7741a2016-10-11 10:39:49 -07003298 Field::SetCharLimit(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003299 pData->num);
3300 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003301 case FP_COMB:
dsinclair3a7741a2016-10-11 10:39:49 -07003302 Field::SetComb(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003303 pData->b);
3304 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003305 case FP_COMMITONSELCHANGE:
dsinclair3a7741a2016-10-11 10:39:49 -07003306 Field::SetCommitOnSelChange(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003307 pData->nControlIndex, pData->b);
3308 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003309 case FP_CURRENTVALUEINDICES:
dsinclair3a7741a2016-10-11 10:39:49 -07003310 Field::SetCurrentValueIndices(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003311 pData->nControlIndex, pData->wordarray);
3312 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003313 case FP_DEFAULTVALUE:
dsinclair3a7741a2016-10-11 10:39:49 -07003314 Field::SetDefaultValue(pFormFillEnv, pData->sFieldName,
3315 pData->nControlIndex, pData->widestring);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003316 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003317 case FP_DONOTSCROLL:
dsinclair3a7741a2016-10-11 10:39:49 -07003318 Field::SetDoNotScroll(pFormFillEnv, pData->sFieldName,
3319 pData->nControlIndex, pData->b);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003320 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003321 case FP_DISPLAY:
dsinclair3a7741a2016-10-11 10:39:49 -07003322 Field::SetDisplay(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003323 pData->num);
3324 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003325 case FP_FILLCOLOR:
dsinclair3a7741a2016-10-11 10:39:49 -07003326 Field::SetFillColor(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003327 pData->color);
3328 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003329 case FP_HIDDEN:
dsinclair3a7741a2016-10-11 10:39:49 -07003330 Field::SetHidden(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003331 pData->b);
3332 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003333 case FP_HIGHLIGHT:
dsinclair3a7741a2016-10-11 10:39:49 -07003334 Field::SetHighlight(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003335 pData->string);
3336 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003337 case FP_LINEWIDTH:
dsinclair3a7741a2016-10-11 10:39:49 -07003338 Field::SetLineWidth(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003339 pData->num);
3340 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003341 case FP_MULTILINE:
dsinclair3a7741a2016-10-11 10:39:49 -07003342 Field::SetMultiline(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003343 pData->b);
3344 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003345 case FP_MULTIPLESELECTION:
dsinclair3a7741a2016-10-11 10:39:49 -07003346 Field::SetMultipleSelection(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003347 pData->nControlIndex, pData->b);
3348 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003349 case FP_PASSWORD:
dsinclair3a7741a2016-10-11 10:39:49 -07003350 Field::SetPassword(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003351 pData->b);
3352 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003353 case FP_RECT:
dsinclair3a7741a2016-10-11 10:39:49 -07003354 Field::SetRect(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003355 pData->rect);
3356 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003357 case FP_RICHTEXT:
dsinclaira2919b32016-07-13 10:55:48 -07003358 // Not supported.
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003359 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003360 case FP_RICHVALUE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003361 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003362 case FP_ROTATION:
dsinclair3a7741a2016-10-11 10:39:49 -07003363 Field::SetRotation(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003364 pData->num);
3365 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003366 case FP_STROKECOLOR:
dsinclair3a7741a2016-10-11 10:39:49 -07003367 Field::SetStrokeColor(pFormFillEnv, pData->sFieldName,
3368 pData->nControlIndex, pData->color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003369 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003370 case FP_STYLE:
dsinclair3a7741a2016-10-11 10:39:49 -07003371 Field::SetStyle(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003372 pData->string);
3373 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003374 case FP_TEXTCOLOR:
dsinclair3a7741a2016-10-11 10:39:49 -07003375 Field::SetTextColor(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003376 pData->color);
3377 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003378 case FP_TEXTFONT:
dsinclair3a7741a2016-10-11 10:39:49 -07003379 Field::SetTextFont(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003380 pData->string);
3381 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003382 case FP_TEXTSIZE:
dsinclair3a7741a2016-10-11 10:39:49 -07003383 Field::SetTextSize(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003384 pData->num);
3385 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003386 case FP_USERNAME:
dsinclair3a7741a2016-10-11 10:39:49 -07003387 Field::SetUserName(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003388 pData->widestring);
3389 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003390 case FP_VALUE:
dsinclair3a7741a2016-10-11 10:39:49 -07003391 Field::SetValue(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003392 pData->widestringarray);
3393 break;
3394 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003395}
3396
dsinclair3a7741a2016-10-11 10:39:49 -07003397void Field::AddField(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003398 int nPageIndex,
3399 int nFieldType,
3400 const CFX_WideString& sName,
Tom Sepez281a9ea2016-02-26 14:24:28 -08003401 const CFX_FloatRect& rcCoords) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003402 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003403}