blob: c580a215c5c8de5387d0f72cf771a0ac59bcc275 [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[] = {
78 {L"alignment", get_alignment_static, set_alignment_static},
79 {L"borderStyle", get_borderStyle_static, set_borderStyle_static},
80 {L"buttonAlignX", get_buttonAlignX_static, set_buttonAlignX_static},
81 {L"buttonAlignY", get_buttonAlignY_static, set_buttonAlignY_static},
82 {L"buttonFitBounds", get_buttonFitBounds_static,
83 set_buttonFitBounds_static},
84 {L"buttonPosition", get_buttonPosition_static, set_buttonPosition_static},
85 {L"buttonScaleHow", get_buttonScaleHow_static, set_buttonScaleHow_static},
86 {L"buttonScaleWhen", get_buttonScaleWhen_static,
87 set_buttonScaleWhen_static},
88 {L"calcOrderIndex", get_calcOrderIndex_static, set_calcOrderIndex_static},
89 {L"charLimit", get_charLimit_static, set_charLimit_static},
90 {L"comb", get_comb_static, set_comb_static},
91 {L"commitOnSelChange", get_commitOnSelChange_static,
92 set_commitOnSelChange_static},
93 {L"currentValueIndices", get_currentValueIndices_static,
94 set_currentValueIndices_static},
95 {L"defaultStyle", get_defaultStyle_static, set_defaultStyle_static},
96 {L"defaultValue", get_defaultValue_static, set_defaultValue_static},
97 {L"doNotScroll", get_doNotScroll_static, set_doNotScroll_static},
98 {L"doNotSpellCheck", get_doNotSpellCheck_static,
99 set_doNotSpellCheck_static},
100 {L"delay", get_delay_static, set_delay_static},
101 {L"display", get_display_static, set_display_static},
102 {L"doc", get_doc_static, set_doc_static},
103 {L"editable", get_editable_static, set_editable_static},
104 {L"exportValues", get_exportValues_static, set_exportValues_static},
105 {L"hidden", get_hidden_static, set_hidden_static},
106 {L"fileSelect", get_fileSelect_static, set_fileSelect_static},
107 {L"fillColor", get_fillColor_static, set_fillColor_static},
108 {L"lineWidth", get_lineWidth_static, set_lineWidth_static},
109 {L"highlight", get_highlight_static, set_highlight_static},
110 {L"multiline", get_multiline_static, set_multiline_static},
111 {L"multipleSelection", get_multipleSelection_static,
112 set_multipleSelection_static},
113 {L"name", get_name_static, set_name_static},
114 {L"numItems", get_numItems_static, set_numItems_static},
115 {L"page", get_page_static, set_page_static},
116 {L"password", get_password_static, set_password_static},
117 {L"print", get_print_static, set_print_static},
118 {L"radiosInUnison", get_radiosInUnison_static, set_radiosInUnison_static},
119 {L"readonly", get_readonly_static, set_readonly_static},
120 {L"rect", get_rect_static, set_rect_static},
121 {L"required", get_required_static, set_required_static},
122 {L"richText", get_richText_static, set_richText_static},
123 {L"richValue", get_richValue_static, set_richValue_static},
124 {L"rotation", get_rotation_static, set_rotation_static},
125 {L"strokeColor", get_strokeColor_static, set_strokeColor_static},
126 {L"style", get_style_static, set_style_static},
127 {L"submitName", get_submitName_static, set_submitName_static},
128 {L"textColor", get_textColor_static, set_textColor_static},
129 {L"textFont", get_textFont_static, set_textFont_static},
130 {L"textSize", get_textSize_static, set_textSize_static},
131 {L"type", get_type_static, set_type_static},
132 {L"userName", get_userName_static, set_userName_static},
133 {L"value", get_value_static, set_value_static},
134 {L"valueAsString", get_valueAsString_static, set_valueAsString_static},
135 {L"source", get_source_static, set_source_static},
136 {0, 0, 0}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700137
Tom Sepez04557b82017-02-16 09:43:10 -0800138JSMethodSpec CJS_Field::MethodSpecs[] = {
139 {L"browseForFileToSubmit", browseForFileToSubmit_static},
140 {L"buttonGetCaption", buttonGetCaption_static},
141 {L"buttonGetIcon", buttonGetIcon_static},
142 {L"buttonImportIcon", buttonImportIcon_static},
143 {L"buttonSetCaption", buttonSetCaption_static},
144 {L"buttonSetIcon", buttonSetIcon_static},
145 {L"checkThisBox", checkThisBox_static},
146 {L"clearItems", clearItems_static},
147 {L"defaultIsChecked", defaultIsChecked_static},
148 {L"deleteItemAt", deleteItemAt_static},
149 {L"getArray", getArray_static},
150 {L"getItemAt", getItemAt_static},
151 {L"getLock", getLock_static},
152 {L"insertItemAt", insertItemAt_static},
153 {L"isBoxChecked", isBoxChecked_static},
154 {L"isDefaultChecked", isDefaultChecked_static},
155 {L"setAction", setAction_static},
156 {L"setFocus", setFocus_static},
157 {L"setItems", setItems_static},
158 {L"setLock", setLock_static},
159 {L"signatureGetModifications", signatureGetModifications_static},
160 {L"signatureGetSeedValue", signatureGetSeedValue_static},
161 {L"signatureInfo", signatureInfo_static},
162 {L"signatureSetSeedValue", signatureSetSeedValue_static},
163 {L"signatureSign", signatureSign_static},
164 {L"signatureValidate", signatureValidate_static},
165 {0, 0}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700166
167IMPLEMENT_JS_CLASS(CJS_Field, Field)
168
weili625ad662016-06-15 11:21:33 -0700169CJS_DelayData::CJS_DelayData(FIELD_PROP prop,
170 int idx,
171 const CFX_WideString& name)
172 : eProp(prop), nControlIndex(idx), sFieldName(name) {}
173
174CJS_DelayData::~CJS_DelayData() {}
175
Tom Sepez33420902015-10-13 15:00:10 -0700176void CJS_Field::InitInstance(IJS_Runtime* pIRuntime) {
Lei Zhangd88a3642015-11-10 09:38:57 -0800177}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700178
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700179Field::Field(CJS_Object* pJSObject)
180 : CJS_EmbedObj(pJSObject),
thestig1cd352e2016-06-07 17:53:06 -0700181 m_pJSDoc(nullptr),
dsinclair3a7741a2016-10-11 10:39:49 -0700182 m_pFormFillEnv(nullptr),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700183 m_nFormControlIndex(-1),
tsepez4cf55152016-11-02 14:37:54 -0700184 m_bCanSet(false),
185 m_bDelay(false) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700186
187Field::~Field() {}
188
189// note: iControlNo = -1, means not a widget.
190void Field::ParseFieldName(const std::wstring& strFieldNameParsed,
191 std::wstring& strFieldName,
192 int& iControlNo) {
193 int iStart = strFieldNameParsed.find_last_of(L'.');
194 if (iStart == -1) {
195 strFieldName = strFieldNameParsed;
196 iControlNo = -1;
197 return;
198 }
199 std::wstring suffixal = strFieldNameParsed.substr(iStart + 1);
200 iControlNo = FXSYS_wtoi(suffixal.c_str());
201 if (iControlNo == 0) {
weilidb444d22016-06-02 15:48:15 -0700202 int iSpaceStart;
203 while ((iSpaceStart = suffixal.find_last_of(L" ")) != -1) {
204 suffixal.erase(iSpaceStart, 1);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700205 }
206
207 if (suffixal.compare(L"0") != 0) {
208 strFieldName = strFieldNameParsed;
209 iControlNo = -1;
210 return;
211 }
212 }
213 strFieldName = strFieldNameParsed.substr(0, iStart);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700214}
215
tsepez4cf55152016-11-02 14:37:54 -0700216bool Field::AttachField(Document* pDocument,
217 const CFX_WideString& csFieldName) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700218 m_pJSDoc = pDocument;
dsinclair82e17672016-10-11 12:38:01 -0700219 m_pFormFillEnv.Reset(pDocument->GetFormFillEnv());
dsinclair7cbe68e2016-10-12 11:56:23 -0700220 m_bCanSet = m_pFormFillEnv->GetPermissions(FPDFPERM_FILL_FORM) ||
221 m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM) ||
222 m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700223
dsinclair7cbe68e2016-10-12 11:56:23 -0700224 CPDFSDK_InterForm* pRDInterForm = m_pFormFillEnv->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700225 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700226 CFX_WideString swFieldNameTemp = csFieldName;
227 swFieldNameTemp.Replace(L"..", L".");
228
229 if (pInterForm->CountFields(swFieldNameTemp) <= 0) {
230 std::wstring strFieldName;
231 int iControlNo = -1;
232 ParseFieldName(swFieldNameTemp.c_str(), strFieldName, iControlNo);
233 if (iControlNo == -1)
tsepez4cf55152016-11-02 14:37:54 -0700234 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700235
236 m_FieldName = strFieldName.c_str();
237 m_nFormControlIndex = iControlNo;
tsepez4cf55152016-11-02 14:37:54 -0700238 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700239 }
240
241 m_FieldName = swFieldNameTemp;
242 m_nFormControlIndex = -1;
243
tsepez4cf55152016-11-02 14:37:54 -0700244 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700245}
246
Lei Zhangd88a3642015-11-10 09:38:57 -0800247std::vector<CPDF_FormField*> Field::GetFormFields(
dsinclair3a7741a2016-10-11 10:39:49 -0700248 CPDFSDK_FormFillEnvironment* pFormFillEnv,
Lei Zhangd88a3642015-11-10 09:38:57 -0800249 const CFX_WideString& csFieldName) {
250 std::vector<CPDF_FormField*> fields;
dsinclair7cbe68e2016-10-12 11:56:23 -0700251 CPDFSDK_InterForm* pReaderInterForm = pFormFillEnv->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700252 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -0800253 for (int i = 0, sz = pInterForm->CountFields(csFieldName); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700254 if (CPDF_FormField* pFormField = pInterForm->GetField(i, csFieldName))
Lei Zhangd88a3642015-11-10 09:38:57 -0800255 fields.push_back(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700256 }
Lei Zhangd88a3642015-11-10 09:38:57 -0800257 return fields;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700258}
259
Lei Zhangd88a3642015-11-10 09:38:57 -0800260std::vector<CPDF_FormField*> Field::GetFormFields(
261 const CFX_WideString& csFieldName) const {
dsinclair3a7741a2016-10-11 10:39:49 -0700262 return Field::GetFormFields(m_pFormFillEnv.Get(), csFieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700263}
264
dsinclair3a7741a2016-10-11 10:39:49 -0700265void Field::UpdateFormField(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700266 CPDF_FormField* pFormField,
tsepez4cf55152016-11-02 14:37:54 -0700267 bool bChangeMark,
268 bool bResetAP,
269 bool bRefresh) {
dsinclair7cbe68e2016-10-12 11:56:23 -0700270 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700271
272 if (bResetAP) {
tsepez8fa82792017-01-11 09:32:33 -0800273 std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
dsinclair1df1efa2016-09-07 09:55:37 -0700274 pInterForm->GetWidgets(pFormField, &widgets);
275
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700276 int nFieldType = pFormField->GetFieldType();
277 if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_TEXTFIELD) {
tsepez8fa82792017-01-11 09:32:33 -0800278 for (auto& pObserved : widgets) {
tsepez1c620542016-09-12 09:47:52 -0700279 if (pObserved) {
tsepez8fa82792017-01-11 09:32:33 -0800280 bool bFormatted = false;
281 CFX_WideString sValue = static_cast<CPDFSDK_Widget*>(pObserved.Get())
282 ->OnFormat(bFormatted);
283 if (pObserved) { // Not redundant, may be clobbered by OnFormat.
284 static_cast<CPDFSDK_Widget*>(pObserved.Get())
285 ->ResetAppearance(bFormatted ? &sValue : nullptr, false);
286 }
tsepezca97a8e2016-08-01 10:10:36 -0700287 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700288 }
289 } else {
tsepez8fa82792017-01-11 09:32:33 -0800290 for (auto& pObserved : widgets) {
291 if (pObserved) {
292 static_cast<CPDFSDK_Widget*>(pObserved.Get())
293 ->ResetAppearance(nullptr, false);
294 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700295 }
296 }
297 }
298
299 if (bRefresh) {
dsinclair1df1efa2016-09-07 09:55:37 -0700300 // Refresh the widget list. The calls in |bResetAP| may have caused widgets
301 // to be removed from the list. We need to call |GetWidgets| again to be
302 // sure none of the widgets have been deleted.
tsepez8fa82792017-01-11 09:32:33 -0800303 std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
dsinclair1df1efa2016-09-07 09:55:37 -0700304 pInterForm->GetWidgets(pFormField, &widgets);
305
dsinclair690c0332016-10-11 09:13:01 -0700306 // TODO(dsinclair): Determine if all widgets share the same
307 // CPDFSDK_InterForm. If that's the case, we can move the code to
dsinclair7cbe68e2016-10-12 11:56:23 -0700308 // |GetFormFillEnv| out of the loop.
tsepez8fa82792017-01-11 09:32:33 -0800309 for (auto& pObserved : widgets) {
310 if (pObserved) {
311 CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pObserved.Get());
312 pWidget->GetInterForm()->GetFormFillEnv()->UpdateAllViews(nullptr,
313 pWidget);
314 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700315 }
316 }
317
318 if (bChangeMark)
dsinclair7cbe68e2016-10-12 11:56:23 -0700319 pFormFillEnv->SetChangeMark();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700320}
321
dsinclair3a7741a2016-10-11 10:39:49 -0700322void Field::UpdateFormControl(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700323 CPDF_FormControl* pFormControl,
tsepez4cf55152016-11-02 14:37:54 -0700324 bool bChangeMark,
325 bool bResetAP,
326 bool bRefresh) {
Lei Zhang96660d62015-12-14 18:27:25 -0800327 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700328
dsinclair7cbe68e2016-10-12 11:56:23 -0700329 CPDFSDK_InterForm* pForm = pFormFillEnv->GetInterForm();
dsinclairc5267c52016-11-04 15:35:12 -0700330 CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700331
332 if (pWidget) {
333 if (bResetAP) {
334 int nFieldType = pWidget->GetFieldType();
335 if (nFieldType == FIELDTYPE_COMBOBOX ||
336 nFieldType == FIELDTYPE_TEXTFIELD) {
tsepez4cf55152016-11-02 14:37:54 -0700337 bool bFormatted = false;
tsepez8c2a8cd2016-09-07 15:29:11 -0700338 CFX_WideString sValue = pWidget->OnFormat(bFormatted);
tsepez4cf55152016-11-02 14:37:54 -0700339 pWidget->ResetAppearance(bFormatted ? &sValue : nullptr, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700340 } else {
tsepez4cf55152016-11-02 14:37:54 -0700341 pWidget->ResetAppearance(nullptr, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700342 }
343 }
344
345 if (bRefresh) {
346 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
dsinclair7cbe68e2016-10-12 11:56:23 -0700347 pInterForm->GetFormFillEnv()->UpdateAllViews(nullptr, pWidget);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700348 }
349 }
350
351 if (bChangeMark)
dsinclair7cbe68e2016-10-12 11:56:23 -0700352 pFormFillEnv->SetChangeMark();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700353}
354
dsinclair3a7741a2016-10-11 10:39:49 -0700355CPDFSDK_Widget* Field::GetWidget(CPDFSDK_FormFillEnvironment* pFormFillEnv,
dsinclairc5267c52016-11-04 15:35:12 -0700356 CPDF_FormControl* pFormControl) {
dsinclair7cbe68e2016-10-12 11:56:23 -0700357 CPDFSDK_InterForm* pInterForm =
358 static_cast<CPDFSDK_InterForm*>(pFormFillEnv->GetInterForm());
dsinclairc5267c52016-11-04 15:35:12 -0700359 return pInterForm ? pInterForm->GetWidget(pFormControl) : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700360}
361
tsepez4cf55152016-11-02 14:37:54 -0700362bool Field::ValueIsOccur(CPDF_FormField* pFormField,
363 CFX_WideString csOptLabel) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700364 for (int i = 0, sz = pFormField->CountOptions(); i < sz; i++) {
365 if (csOptLabel.Compare(pFormField->GetOptionLabel(i)) == 0)
tsepez4cf55152016-11-02 14:37:54 -0700366 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700367 }
368
tsepez4cf55152016-11-02 14:37:54 -0700369 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700370}
371
372CPDF_FormControl* Field::GetSmartFieldControl(CPDF_FormField* pFormField) {
373 if (!pFormField->CountControls() ||
374 m_nFormControlIndex >= pFormField->CountControls())
thestig1cd352e2016-06-07 17:53:06 -0700375 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700376
377 if (m_nFormControlIndex < 0)
378 return pFormField->GetControl(0);
379
380 return pFormField->GetControl(m_nFormControlIndex);
381}
382
Tom Sepezb1670b52017-02-16 17:01:00 -0800383bool Field::alignment(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700384 CJS_PropValue& vp,
385 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700386 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700387
388 if (vp.IsSetting()) {
389 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700390 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700391
392 CFX_ByteString alignStr;
393 vp >> alignStr;
394
395 if (m_bDelay) {
396 AddDelay_String(FP_ALIGNMENT, alignStr);
397 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700398 Field::SetAlignment(m_pFormFillEnv.Get(), m_FieldName,
399 m_nFormControlIndex, alignStr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700400 }
401 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800402 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
403 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700404 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700405
Lei Zhangd88a3642015-11-10 09:38:57 -0800406 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700407 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
tsepez4cf55152016-11-02 14:37:54 -0700408 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700409
410 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
411 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -0700412 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700413
414 switch (pFormControl->GetControlAlignment()) {
415 case 1:
416 vp << L"center";
417 break;
418 case 0:
419 vp << L"left";
420 break;
421 case 2:
422 vp << L"right";
423 break;
424 default:
425 vp << L"";
426 }
427 }
428
tsepez4cf55152016-11-02 14:37:54 -0700429 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700430}
431
dsinclair3a7741a2016-10-11 10:39:49 -0700432void Field::SetAlignment(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700433 const CFX_WideString& swFieldName,
434 int nControlIndex,
435 const CFX_ByteString& string) {
436 // Not supported.
437}
438
Tom Sepezb1670b52017-02-16 17:01:00 -0800439bool Field::borderStyle(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700440 CJS_PropValue& vp,
441 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700442 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700443
444 if (vp.IsSetting()) {
445 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700446 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700447
448 CFX_ByteString strType = "";
449 vp >> strType;
450
451 if (m_bDelay) {
452 AddDelay_String(FP_BORDERSTYLE, strType);
453 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700454 Field::SetBorderStyle(m_pFormFillEnv.Get(), m_FieldName,
455 m_nFormControlIndex, strType);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700456 }
457 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800458 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
459 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700460 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700461
Lei Zhangd88a3642015-11-10 09:38:57 -0800462 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700463 if (!pFormField)
tsepez4cf55152016-11-02 14:37:54 -0700464 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700465
dsinclairc5267c52016-11-04 15:35:12 -0700466 CPDFSDK_Widget* pWidget =
467 GetWidget(m_pFormFillEnv.Get(), GetSmartFieldControl(pFormField));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700468 if (!pWidget)
tsepez4cf55152016-11-02 14:37:54 -0700469 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700470
dsinclair92cb5e52016-05-16 11:38:28 -0700471 switch (pWidget->GetBorderStyle()) {
472 case BorderStyle::SOLID:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700473 vp << L"solid";
474 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700475 case BorderStyle::DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700476 vp << L"dashed";
477 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700478 case BorderStyle::BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700479 vp << L"beveled";
480 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700481 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700482 vp << L"inset";
483 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700484 case BorderStyle::UNDERLINE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700485 vp << L"underline";
486 break;
487 default:
488 vp << L"";
489 break;
490 }
491 }
492
tsepez4cf55152016-11-02 14:37:54 -0700493 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700494}
495
dsinclair3a7741a2016-10-11 10:39:49 -0700496void Field::SetBorderStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700497 const CFX_WideString& swFieldName,
498 int nControlIndex,
499 const CFX_ByteString& string) {
dsinclair3a7741a2016-10-11 10:39:49 -0700500 ASSERT(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700501
dsinclair92cb5e52016-05-16 11:38:28 -0700502 BorderStyle nBorderStyle = BorderStyle::SOLID;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700503 if (string == "solid")
dsinclair92cb5e52016-05-16 11:38:28 -0700504 nBorderStyle = BorderStyle::SOLID;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700505 else if (string == "beveled")
dsinclair92cb5e52016-05-16 11:38:28 -0700506 nBorderStyle = BorderStyle::BEVELED;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700507 else if (string == "dashed")
dsinclair92cb5e52016-05-16 11:38:28 -0700508 nBorderStyle = BorderStyle::DASH;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700509 else if (string == "inset")
dsinclair92cb5e52016-05-16 11:38:28 -0700510 nBorderStyle = BorderStyle::INSET;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700511 else if (string == "underline")
dsinclair92cb5e52016-05-16 11:38:28 -0700512 nBorderStyle = BorderStyle::UNDERLINE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700513 else
514 return;
515
Lei Zhangd88a3642015-11-10 09:38:57 -0800516 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -0700517 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -0800518 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700519 if (nControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -0700520 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -0800521 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700522 if (CPDFSDK_Widget* pWidget =
dsinclairc5267c52016-11-04 15:35:12 -0700523 GetWidget(pFormFillEnv, pFormField->GetControl(i))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700524 if (pWidget->GetBorderStyle() != nBorderStyle) {
525 pWidget->SetBorderStyle(nBorderStyle);
tsepez4cf55152016-11-02 14:37:54 -0700526 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700527 }
528 }
529 }
530 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -0700531 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700532 } else {
533 if (nControlIndex >= pFormField->CountControls())
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700534 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700535 if (CPDF_FormControl* pFormControl =
536 pFormField->GetControl(nControlIndex)) {
dsinclairc5267c52016-11-04 15:35:12 -0700537 if (CPDFSDK_Widget* pWidget = GetWidget(pFormFillEnv, pFormControl)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700538 if (pWidget->GetBorderStyle() != nBorderStyle) {
539 pWidget->SetBorderStyle(nBorderStyle);
tsepez4cf55152016-11-02 14:37:54 -0700540 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700541 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700542 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700543 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700544 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700545 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700546}
547
Tom Sepezb1670b52017-02-16 17:01:00 -0800548bool Field::buttonAlignX(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700549 CJS_PropValue& vp,
550 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700551 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700552
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700553 if (vp.IsSetting()) {
554 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700555 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700556
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700557 int nVP;
558 vp >> nVP;
559
560 if (m_bDelay) {
561 AddDelay_Int(FP_BUTTONALIGNX, nVP);
562 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700563 Field::SetButtonAlignX(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700564 m_nFormControlIndex, nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700565 }
566 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800567 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
568 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700569 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700570
Lei Zhangd88a3642015-11-10 09:38:57 -0800571 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700572 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -0700573 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700574
575 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
576 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -0700577 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700578
579 CPDF_IconFit IconFit = pFormControl->GetIconFit();
580
581 FX_FLOAT fLeft, fBottom;
582 IconFit.GetIconPosition(fLeft, fBottom);
583
584 vp << (int32_t)fLeft;
585 }
586
tsepez4cf55152016-11-02 14:37:54 -0700587 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700588}
589
dsinclair3a7741a2016-10-11 10:39:49 -0700590void Field::SetButtonAlignX(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700591 const CFX_WideString& swFieldName,
592 int nControlIndex,
593 int number) {
594 // Not supported.
595}
596
Tom Sepezb1670b52017-02-16 17:01:00 -0800597bool Field::buttonAlignY(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700598 CJS_PropValue& vp,
599 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700600 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700601
602 if (vp.IsSetting()) {
603 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700604 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700605
606 int nVP;
607 vp >> nVP;
608
609 if (m_bDelay) {
610 AddDelay_Int(FP_BUTTONALIGNY, nVP);
611 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700612 Field::SetButtonAlignY(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700613 m_nFormControlIndex, nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700614 }
615 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800616 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
617 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700618 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700619
Lei Zhangd88a3642015-11-10 09:38:57 -0800620 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700621 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -0700622 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700623
624 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
625 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -0700626 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700627
628 CPDF_IconFit IconFit = pFormControl->GetIconFit();
629
630 FX_FLOAT fLeft, fBottom;
631 IconFit.GetIconPosition(fLeft, fBottom);
632
633 vp << (int32_t)fBottom;
634 }
635
tsepez4cf55152016-11-02 14:37:54 -0700636 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700637}
638
dsinclair3a7741a2016-10-11 10:39:49 -0700639void Field::SetButtonAlignY(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700640 const CFX_WideString& swFieldName,
641 int nControlIndex,
642 int number) {
643 // Not supported.
644}
645
Tom Sepezb1670b52017-02-16 17:01:00 -0800646bool Field::buttonFitBounds(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700647 CJS_PropValue& vp,
648 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700649 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700650
651 if (vp.IsSetting()) {
652 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700653 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700654
655 bool bVP;
656 vp >> bVP;
657
658 if (m_bDelay) {
659 AddDelay_Bool(FP_BUTTONFITBOUNDS, bVP);
660 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700661 Field::SetButtonFitBounds(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700662 m_nFormControlIndex, bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700663 }
664 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800665 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
666 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700667 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700668
Lei Zhangd88a3642015-11-10 09:38:57 -0800669 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700670 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -0700671 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700672
673 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
674 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -0700675 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700676
thestigded36342016-05-23 17:54:02 -0700677 vp << pFormControl->GetIconFit().GetFittingBounds();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700678 }
679
tsepez4cf55152016-11-02 14:37:54 -0700680 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700681}
682
dsinclair3a7741a2016-10-11 10:39:49 -0700683void Field::SetButtonFitBounds(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700684 const CFX_WideString& swFieldName,
685 int nControlIndex,
686 bool b) {
687 // Not supported.
688}
689
Tom Sepezb1670b52017-02-16 17:01:00 -0800690bool Field::buttonPosition(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700691 CJS_PropValue& vp,
692 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700693 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700694
695 if (vp.IsSetting()) {
696 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700697 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700698
699 int nVP;
700 vp >> nVP;
701
702 if (m_bDelay) {
703 AddDelay_Int(FP_BUTTONPOSITION, nVP);
704 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700705 Field::SetButtonPosition(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700706 m_nFormControlIndex, nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700707 }
708 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800709 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
710 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700711 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700712
Lei Zhangd88a3642015-11-10 09:38:57 -0800713 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700714 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -0700715 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700716
717 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
718 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -0700719 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700720
721 vp << pFormControl->GetTextPosition();
722 }
tsepez4cf55152016-11-02 14:37:54 -0700723 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700724}
725
dsinclair3a7741a2016-10-11 10:39:49 -0700726void Field::SetButtonPosition(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700727 const CFX_WideString& swFieldName,
728 int nControlIndex,
729 int number) {
730 // Not supported.
731}
732
Tom Sepezb1670b52017-02-16 17:01:00 -0800733bool Field::buttonScaleHow(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700734 CJS_PropValue& vp,
735 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700736 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700737
738 if (vp.IsSetting()) {
739 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700740 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700741
742 int nVP;
743 vp >> nVP;
744
745 if (m_bDelay) {
746 AddDelay_Int(FP_BUTTONSCALEHOW, nVP);
747 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700748 Field::SetButtonScaleHow(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700749 m_nFormControlIndex, nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700750 }
751 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800752 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
753 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700754 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700755
Lei Zhangd88a3642015-11-10 09:38:57 -0800756 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700757 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -0700758 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700759
760 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
761 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -0700762 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700763
764 CPDF_IconFit IconFit = pFormControl->GetIconFit();
765 if (IconFit.IsProportionalScale())
766 vp << (int32_t)0;
767 else
768 vp << (int32_t)1;
769 }
770
tsepez4cf55152016-11-02 14:37:54 -0700771 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700772}
773
dsinclair3a7741a2016-10-11 10:39:49 -0700774void Field::SetButtonScaleHow(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700775 const CFX_WideString& swFieldName,
776 int nControlIndex,
777 int number) {
778 // Not supported.
779}
780
Tom Sepezb1670b52017-02-16 17:01:00 -0800781bool Field::buttonScaleWhen(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700782 CJS_PropValue& vp,
783 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700784 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700785
786 if (vp.IsSetting()) {
787 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700788 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700789
790 int nVP;
791 vp >> nVP;
792
793 if (m_bDelay) {
794 AddDelay_Int(FP_BUTTONSCALEWHEN, nVP);
795 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700796 Field::SetButtonScaleWhen(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700797 m_nFormControlIndex, nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700798 }
799 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800800 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
801 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700802 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700803
Lei Zhangd88a3642015-11-10 09:38:57 -0800804 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700805 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -0700806 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700807
808 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
809 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -0700810 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700811
812 CPDF_IconFit IconFit = pFormControl->GetIconFit();
813 int ScaleM = IconFit.GetScaleMethod();
814 switch (ScaleM) {
815 case CPDF_IconFit::Always:
816 vp << (int32_t)CPDF_IconFit::Always;
817 break;
818 case CPDF_IconFit::Bigger:
819 vp << (int32_t)CPDF_IconFit::Bigger;
820 break;
821 case CPDF_IconFit::Never:
822 vp << (int32_t)CPDF_IconFit::Never;
823 break;
824 case CPDF_IconFit::Smaller:
825 vp << (int32_t)CPDF_IconFit::Smaller;
826 break;
827 }
828 }
829
tsepez4cf55152016-11-02 14:37:54 -0700830 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700831}
832
dsinclair3a7741a2016-10-11 10:39:49 -0700833void Field::SetButtonScaleWhen(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700834 const CFX_WideString& swFieldName,
835 int nControlIndex,
836 int number) {
837 // Not supported.
838}
839
Tom Sepezb1670b52017-02-16 17:01:00 -0800840bool Field::calcOrderIndex(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700841 CJS_PropValue& vp,
842 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700843 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700844
845 if (vp.IsSetting()) {
846 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700847 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700848
849 int nVP;
850 vp >> nVP;
851
852 if (m_bDelay) {
853 AddDelay_Int(FP_CALCORDERINDEX, nVP);
854 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700855 Field::SetCalcOrderIndex(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700856 m_nFormControlIndex, nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700857 }
858 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800859 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
860 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700861 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700862
Lei Zhangd88a3642015-11-10 09:38:57 -0800863 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700864 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -0800865 pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) {
tsepez4cf55152016-11-02 14:37:54 -0700866 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -0800867 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700868
dsinclair7cbe68e2016-10-12 11:56:23 -0700869 CPDFSDK_InterForm* pRDInterForm = m_pFormFillEnv->GetInterForm();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700870 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700871 vp << (int32_t)pInterForm->FindFieldInCalculationOrder(pFormField);
872 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700873
tsepez4cf55152016-11-02 14:37:54 -0700874 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700875}
876
dsinclair3a7741a2016-10-11 10:39:49 -0700877void Field::SetCalcOrderIndex(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700878 const CFX_WideString& swFieldName,
879 int nControlIndex,
880 int number) {
881 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700882}
883
Tom Sepezb1670b52017-02-16 17:01:00 -0800884bool Field::charLimit(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700885 CJS_PropValue& vp,
886 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700887 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700888
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700889 if (vp.IsSetting()) {
890 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700891 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700892
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700893 int nVP;
894 vp >> nVP;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700895
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700896 if (m_bDelay) {
897 AddDelay_Int(FP_CHARLIMIT, nVP);
898 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700899 Field::SetCharLimit(m_pFormFillEnv.Get(), m_FieldName,
900 m_nFormControlIndex, nVP);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700901 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700902 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800903 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
904 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700905 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700906
Lei Zhangd88a3642015-11-10 09:38:57 -0800907 CPDF_FormField* pFormField = FieldArray[0];
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700908 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
tsepez4cf55152016-11-02 14:37:54 -0700909 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700910
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700911 vp << (int32_t)pFormField->GetMaxLen();
912 }
tsepez4cf55152016-11-02 14:37:54 -0700913 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700914}
915
dsinclair3a7741a2016-10-11 10:39:49 -0700916void Field::SetCharLimit(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700917 const CFX_WideString& swFieldName,
918 int nControlIndex,
919 int number) {
920 // Not supported.
921}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700922
Tom Sepezb1670b52017-02-16 17:01:00 -0800923bool Field::comb(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800924 CJS_PropValue& vp,
925 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700926 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700927
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700928 if (vp.IsSetting()) {
929 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700930 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700931
932 bool bVP;
933 vp >> bVP;
934
935 if (m_bDelay) {
936 AddDelay_Bool(FP_COMB, bVP);
937 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700938 Field::SetComb(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
939 bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700940 }
941 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800942 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
943 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700944 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700945
Lei Zhangd88a3642015-11-10 09:38:57 -0800946 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700947 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
tsepez4cf55152016-11-02 14:37:54 -0700948 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700949
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700950 if (pFormField->GetFieldFlags() & FIELDFLAG_COMB)
951 vp << true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700952 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700953 vp << false;
954 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700955
tsepez4cf55152016-11-02 14:37:54 -0700956 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700957}
958
dsinclair3a7741a2016-10-11 10:39:49 -0700959void Field::SetComb(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700960 const CFX_WideString& swFieldName,
961 int nControlIndex,
962 bool b) {
963 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700964}
965
Tom Sepezb1670b52017-02-16 17:01:00 -0800966bool Field::commitOnSelChange(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700967 CJS_PropValue& vp,
968 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700969 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700970
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700971 if (vp.IsSetting()) {
972 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700973 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700974
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700975 bool bVP;
976 vp >> bVP;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700977
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700978 if (m_bDelay) {
979 AddDelay_Bool(FP_COMMITONSELCHANGE, bVP);
980 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700981 Field::SetCommitOnSelChange(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700982 m_nFormControlIndex, bVP);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700983 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700984 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800985 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
986 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700987 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700988
Lei Zhangd88a3642015-11-10 09:38:57 -0800989 CPDF_FormField* pFormField = FieldArray[0];
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700990 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -0800991 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
tsepez4cf55152016-11-02 14:37:54 -0700992 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -0800993 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700994
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700995 if (pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE)
996 vp << true;
997 else
998 vp << false;
999 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001000
tsepez4cf55152016-11-02 14:37:54 -07001001 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001002}
1003
dsinclair3a7741a2016-10-11 10:39:49 -07001004void Field::SetCommitOnSelChange(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001005 const CFX_WideString& swFieldName,
1006 int nControlIndex,
1007 bool b) {
1008 // Not supported.
1009}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001010
Tom Sepezb1670b52017-02-16 17:01:00 -08001011bool Field::currentValueIndices(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001012 CJS_PropValue& vp,
1013 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001014 if (vp.IsSetting()) {
1015 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001016 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001017
tsepez41a53ad2016-03-28 16:59:30 -07001018 std::vector<uint32_t> array;
tsepezf3dc8c62016-08-10 06:29:29 -07001019 if (vp.GetJSValue()->GetType() == CJS_Value::VT_number) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001020 int iSelecting = 0;
1021 vp >> iSelecting;
tsepez41a53ad2016-03-28 16:59:30 -07001022 array.push_back(iSelecting);
tsepezf3dc8c62016-08-10 06:29:29 -07001023 } else if (vp.GetJSValue()->IsArrayObject()) {
tsepeze5aff742016-08-08 09:49:42 -07001024 CJS_Array SelArray;
Tom Sepez67fd5df2015-10-08 12:24:19 -07001025 CJS_Value SelValue(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001026 int iSelecting;
1027 vp >> SelArray;
tsepezb4694242016-08-15 16:44:55 -07001028 for (int i = 0, sz = SelArray.GetLength(pRuntime); i < sz; i++) {
1029 SelArray.GetElement(pRuntime, i, SelValue);
1030 iSelecting = SelValue.ToInt(pRuntime);
tsepez41a53ad2016-03-28 16:59:30 -07001031 array.push_back(iSelecting);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001032 }
1033 }
1034
1035 if (m_bDelay) {
1036 AddDelay_WordArray(FP_CURRENTVALUEINDICES, array);
1037 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001038 Field::SetCurrentValueIndices(m_pFormFillEnv.Get(), m_FieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001039 m_nFormControlIndex, array);
1040 }
1041 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001042 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1043 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001044 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001045
Lei Zhangd88a3642015-11-10 09:38:57 -08001046 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001047 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001048 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
tsepez4cf55152016-11-02 14:37:54 -07001049 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001050 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001051
Lei Zhangd88a3642015-11-10 09:38:57 -08001052 if (pFormField->CountSelectedItems() == 1) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001053 vp << pFormField->GetSelectedIndex(0);
Lei Zhangd88a3642015-11-10 09:38:57 -08001054 } else if (pFormField->CountSelectedItems() > 1) {
tsepeze5aff742016-08-08 09:49:42 -07001055 CJS_Array SelArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001056 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
1057 SelArray.SetElement(
tsepezb4694242016-08-15 16:44:55 -07001058 pRuntime, i, CJS_Value(pRuntime, pFormField->GetSelectedIndex(i)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001059 }
1060 vp << SelArray;
Lei Zhangd88a3642015-11-10 09:38:57 -08001061 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001062 vp << -1;
Lei Zhangd88a3642015-11-10 09:38:57 -08001063 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001064 }
1065
tsepez4cf55152016-11-02 14:37:54 -07001066 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001067}
1068
dsinclair3a7741a2016-10-11 10:39:49 -07001069void Field::SetCurrentValueIndices(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001070 const CFX_WideString& swFieldName,
1071 int nControlIndex,
tsepez41a53ad2016-03-28 16:59:30 -07001072 const std::vector<uint32_t>& array) {
dsinclair3a7741a2016-10-11 10:39:49 -07001073 ASSERT(pFormFillEnv);
Lei Zhangd88a3642015-11-10 09:38:57 -08001074 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07001075 GetFormFields(pFormFillEnv, swFieldName);
tsepez41a53ad2016-03-28 16:59:30 -07001076
Lei Zhangd88a3642015-11-10 09:38:57 -08001077 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001078 int nFieldType = pFormField->GetFieldType();
1079 if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX) {
tsepezc3255f52016-03-25 14:52:27 -07001080 uint32_t dwFieldFlags = pFormField->GetFieldFlags();
tsepez4cf55152016-11-02 14:37:54 -07001081 pFormField->ClearSelection(true);
tsepez41a53ad2016-03-28 16:59:30 -07001082 for (size_t i = 0; i < array.size(); ++i) {
1083 if (i != 0 && !(dwFieldFlags & (1 << 21)))
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001084 break;
Wei Li05d53f02016-03-29 16:42:53 -07001085 if (array[i] < static_cast<uint32_t>(pFormField->CountOptions()) &&
tsepez41a53ad2016-03-28 16:59:30 -07001086 !pFormField->IsItemSelected(array[i])) {
tsepez4cf55152016-11-02 14:37:54 -07001087 pFormField->SetItemSelection(array[i], true);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001088 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001089 }
tsepez4cf55152016-11-02 14:37:54 -07001090 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001091 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001092 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001093}
1094
Tom Sepezb1670b52017-02-16 17:01:00 -08001095bool Field::defaultStyle(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001096 CJS_PropValue& vp,
1097 CFX_WideString& sError) {
1098 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001099}
1100
dsinclair3a7741a2016-10-11 10:39:49 -07001101void Field::SetDefaultStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001102 const CFX_WideString& swFieldName,
1103 int nControlIndex) {
1104 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001105}
1106
Tom Sepezb1670b52017-02-16 17:01:00 -08001107bool Field::defaultValue(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001108 CJS_PropValue& vp,
1109 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001110 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001111
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001112 if (vp.IsSetting()) {
1113 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001114 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001115
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001116 CFX_WideString WideStr;
1117 vp >> WideStr;
1118
1119 if (m_bDelay) {
1120 AddDelay_WideString(FP_DEFAULTVALUE, WideStr);
1121 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001122 Field::SetDefaultValue(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -07001123 m_nFormControlIndex, WideStr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001124 }
1125 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001126 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1127 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001128 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001129
Lei Zhangd88a3642015-11-10 09:38:57 -08001130 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001131 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON ||
Lei Zhangd88a3642015-11-10 09:38:57 -08001132 pFormField->GetFieldType() == FIELDTYPE_SIGNATURE) {
tsepez4cf55152016-11-02 14:37:54 -07001133 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001134 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001135
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001136 vp << pFormField->GetDefaultValue();
1137 }
tsepez4cf55152016-11-02 14:37:54 -07001138 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001139}
1140
dsinclair3a7741a2016-10-11 10:39:49 -07001141void Field::SetDefaultValue(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001142 const CFX_WideString& swFieldName,
1143 int nControlIndex,
1144 const CFX_WideString& string) {
1145 // Not supported.
1146}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001147
Tom Sepezb1670b52017-02-16 17:01:00 -08001148bool Field::doNotScroll(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001149 CJS_PropValue& vp,
1150 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001151 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001152
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001153 if (vp.IsSetting()) {
1154 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001155 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001156
1157 bool bVP;
1158 vp >> bVP;
1159
1160 if (m_bDelay) {
1161 AddDelay_Bool(FP_DONOTSCROLL, bVP);
1162 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001163 Field::SetDoNotScroll(m_pFormFillEnv.Get(), m_FieldName,
1164 m_nFormControlIndex, bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001165 }
1166 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001167 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1168 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001169 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001170
Lei Zhangd88a3642015-11-10 09:38:57 -08001171 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001172 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
tsepez4cf55152016-11-02 14:37:54 -07001173 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001174
1175 if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL)
1176 vp << true;
1177 else
1178 vp << false;
1179 }
1180
tsepez4cf55152016-11-02 14:37:54 -07001181 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001182}
1183
dsinclair3a7741a2016-10-11 10:39:49 -07001184void Field::SetDoNotScroll(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001185 const CFX_WideString& swFieldName,
1186 int nControlIndex,
1187 bool b) {
1188 // Not supported.
1189}
1190
Tom Sepezb1670b52017-02-16 17:01:00 -08001191bool Field::doNotSpellCheck(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001192 CJS_PropValue& vp,
1193 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001194 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001195
1196 if (vp.IsSetting()) {
1197 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001198 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001199
1200 bool bVP;
1201 vp >> bVP;
1202 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001203 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1204 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001205 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001206
Lei Zhangd88a3642015-11-10 09:38:57 -08001207 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001208 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001209 pFormField->GetFieldType() != FIELDTYPE_COMBOBOX) {
tsepez4cf55152016-11-02 14:37:54 -07001210 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001211 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001212
1213 if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK)
1214 vp << true;
1215 else
1216 vp << false;
1217 }
1218
tsepez4cf55152016-11-02 14:37:54 -07001219 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001220}
1221
tsepez4cf55152016-11-02 14:37:54 -07001222void Field::SetDelay(bool bDelay) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001223 m_bDelay = bDelay;
1224
1225 if (!m_bDelay) {
1226 if (m_pJSDoc)
1227 m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex);
1228 }
1229}
1230
Tom Sepezb1670b52017-02-16 17:01:00 -08001231bool Field::delay(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001232 CJS_PropValue& vp,
1233 CFX_WideString& sError) {
1234 if (!vp.IsSetting()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001235 vp << m_bDelay;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001236 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001237 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001238 if (!m_bCanSet)
1239 return false;
1240
1241 bool bVP;
1242 vp >> bVP;
1243 SetDelay(bVP);
tsepez4cf55152016-11-02 14:37:54 -07001244 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001245}
1246
Tom Sepezb1670b52017-02-16 17:01:00 -08001247bool Field::display(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001248 CJS_PropValue& vp,
1249 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001250 if (vp.IsSetting()) {
1251 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001252 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001253
1254 int nVP;
1255 vp >> nVP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001256 if (m_bDelay) {
1257 AddDelay_Int(FP_DISPLAY, nVP);
1258 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001259 Field::SetDisplay(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07001260 nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001261 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001262 return true;
1263 }
1264 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1265 if (FieldArray.empty())
1266 return false;
1267
1268 CPDF_FormField* pFormField = FieldArray[0];
1269 ASSERT(pFormField);
1270 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1271 CPDFSDK_Widget* pWidget =
1272 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1273 if (!pWidget)
1274 return false;
1275
1276 uint32_t dwFlag = pWidget->GetFlags();
1277 if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag) {
1278 vp << (int32_t)1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001279 } else {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001280 if (ANNOTFLAG_PRINT & dwFlag) {
1281 if (ANNOTFLAG_NOVIEW & dwFlag) {
1282 vp << (int32_t)3;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001283 } else {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001284 vp << (int32_t)0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001285 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001286 } else {
1287 vp << (int32_t)2;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001288 }
1289 }
tsepez4cf55152016-11-02 14:37:54 -07001290 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001291}
1292
dsinclair3a7741a2016-10-11 10:39:49 -07001293void Field::SetDisplay(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001294 const CFX_WideString& swFieldName,
1295 int nControlIndex,
1296 int number) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001297 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001298 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07001299 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -08001300 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001301 if (nControlIndex < 0) {
tonikitoo7c05a7a2016-08-17 11:08:46 -07001302 bool bAnySet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001303 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1304 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08001305 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001306
dsinclairc5267c52016-11-04 15:35:12 -07001307 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
tonikitoo7c05a7a2016-08-17 11:08:46 -07001308 if (SetWidgetDisplayStatus(pWidget, number))
1309 bAnySet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001310 }
1311
tonikitoo7c05a7a2016-08-17 11:08:46 -07001312 if (bAnySet)
tsepez4cf55152016-11-02 14:37:54 -07001313 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001314 } else {
1315 if (nControlIndex >= pFormField->CountControls())
1316 return;
tonikitoo7c05a7a2016-08-17 11:08:46 -07001317
1318 CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex);
1319 if (!pFormControl)
1320 return;
1321
dsinclairc5267c52016-11-04 15:35:12 -07001322 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
tonikitoo7c05a7a2016-08-17 11:08:46 -07001323 if (SetWidgetDisplayStatus(pWidget, number))
tsepez4cf55152016-11-02 14:37:54 -07001324 UpdateFormControl(pFormFillEnv, pFormControl, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001325 }
1326 }
1327}
1328
Tom Sepezb1670b52017-02-16 17:01:00 -08001329bool Field::doc(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001330 CJS_PropValue& vp,
1331 CFX_WideString& sError) {
1332 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -07001333 return false;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001334
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001335 vp << m_pJSDoc->GetCJSDoc();
tsepez4cf55152016-11-02 14:37:54 -07001336 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001337}
1338
Tom Sepezb1670b52017-02-16 17:01:00 -08001339bool Field::editable(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001340 CJS_PropValue& vp,
1341 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001342 if (vp.IsSetting()) {
1343 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001344 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001345
1346 bool bVP;
1347 vp >> bVP;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001348 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001349 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001350 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1351 if (FieldArray.empty())
1352 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001353
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001354 CPDF_FormField* pFormField = FieldArray[0];
1355 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX)
1356 return false;
1357
1358 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_EDIT);
tsepez4cf55152016-11-02 14:37:54 -07001359 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001360}
1361
Tom Sepezb1670b52017-02-16 17:01:00 -08001362bool Field::exportValues(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001363 CJS_PropValue& vp,
1364 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001365 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1366 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001367 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001368
Lei Zhangd88a3642015-11-10 09:38:57 -08001369 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001370 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001371 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) {
tsepez4cf55152016-11-02 14:37:54 -07001372 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001373 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001374 if (vp.IsSetting())
1375 return m_bCanSet && vp.GetJSValue()->IsArrayObject();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001376
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001377 CJS_Array ExportValusArray;
1378 if (m_nFormControlIndex < 0) {
1379 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
1380 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001381 ExportValusArray.SetElement(
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001382 pRuntime, i,
tsepeze5aff742016-08-08 09:49:42 -07001383 CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001384 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001385 } else {
1386 if (m_nFormControlIndex >= pFormField->CountControls())
1387 return false;
1388
1389 CPDF_FormControl* pFormControl =
1390 pFormField->GetControl(m_nFormControlIndex);
1391 if (!pFormControl)
1392 return false;
1393
1394 ExportValusArray.SetElement(
1395 pRuntime, 0,
1396 CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001397 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001398 vp << ExportValusArray;
tsepez4cf55152016-11-02 14:37:54 -07001399 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001400}
1401
Tom Sepezb1670b52017-02-16 17:01:00 -08001402bool Field::fileSelect(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001403 CJS_PropValue& vp,
1404 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001405 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1406 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001407 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001408
Lei Zhangd88a3642015-11-10 09:38:57 -08001409 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001410 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
tsepez4cf55152016-11-02 14:37:54 -07001411 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001412
1413 if (vp.IsSetting()) {
1414 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001415 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001416
1417 bool bVP;
1418 vp >> bVP;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001419 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001420 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001421 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT);
tsepez4cf55152016-11-02 14:37:54 -07001422 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001423}
1424
Tom Sepezb1670b52017-02-16 17:01:00 -08001425bool Field::fillColor(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001426 CJS_PropValue& vp,
1427 CFX_WideString& sError) {
tsepeze5aff742016-08-08 09:49:42 -07001428 CJS_Array crArray;
Lei Zhangd88a3642015-11-10 09:38:57 -08001429 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1430 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001431 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001432
1433 if (vp.IsSetting()) {
1434 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001435 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001436
tsepezf3dc8c62016-08-10 06:29:29 -07001437 if (!vp.GetJSValue()->IsArrayObject())
tsepez4cf55152016-11-02 14:37:54 -07001438 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001439
1440 vp >> crArray;
1441
1442 CPWL_Color color;
tsepeze5aff742016-08-08 09:49:42 -07001443 color::ConvertArrayToPWLColor(pRuntime, crArray, &color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001444 if (m_bDelay) {
1445 AddDelay_Color(FP_FILLCOLOR, color);
1446 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001447 Field::SetFillColor(m_pFormFillEnv.Get(), m_FieldName,
1448 m_nFormControlIndex, color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001449 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001450 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001451 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001452 CPDF_FormField* pFormField = FieldArray[0];
1453 ASSERT(pFormField);
1454 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1455 if (!pFormControl)
1456 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001457
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001458 int iColorType;
1459 pFormControl->GetBackgroundColor(iColorType);
1460
1461 CPWL_Color color;
1462 if (iColorType == COLORTYPE_TRANSPARENT) {
1463 color = CPWL_Color(COLORTYPE_TRANSPARENT);
1464 } else if (iColorType == COLORTYPE_GRAY) {
1465 color =
1466 CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBackgroundColor(0));
1467 } else if (iColorType == COLORTYPE_RGB) {
1468 color =
1469 CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBackgroundColor(0),
1470 pFormControl->GetOriginalBackgroundColor(1),
1471 pFormControl->GetOriginalBackgroundColor(2));
1472 } else if (iColorType == COLORTYPE_CMYK) {
1473 color =
1474 CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBackgroundColor(0),
1475 pFormControl->GetOriginalBackgroundColor(1),
1476 pFormControl->GetOriginalBackgroundColor(2),
1477 pFormControl->GetOriginalBackgroundColor(3));
1478 } else {
1479 return false;
1480 }
1481 color::ConvertPWLColorToArray(pRuntime, color, &crArray);
1482 vp << crArray;
tsepez4cf55152016-11-02 14:37:54 -07001483 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001484}
1485
dsinclair3a7741a2016-10-11 10:39:49 -07001486void Field::SetFillColor(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001487 const CFX_WideString& swFieldName,
1488 int nControlIndex,
1489 const CPWL_Color& color) {
1490 // Not supported.
1491}
1492
Tom Sepezb1670b52017-02-16 17:01:00 -08001493bool Field::hidden(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001494 CJS_PropValue& vp,
1495 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001496 if (vp.IsSetting()) {
1497 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001498 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001499
1500 bool bVP;
1501 vp >> bVP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001502 if (m_bDelay) {
1503 AddDelay_Bool(FP_HIDDEN, bVP);
1504 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001505 Field::SetHidden(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07001506 bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001507 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001508 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001509 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001510 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1511 if (FieldArray.empty())
1512 return false;
1513
1514 CPDF_FormField* pFormField = FieldArray[0];
1515 ASSERT(pFormField);
1516 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1517 CPDFSDK_Widget* pWidget =
1518 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1519 if (!pWidget)
1520 return false;
1521
1522 uint32_t dwFlags = pWidget->GetFlags();
1523 if (ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags)
1524 vp << true;
1525 else
1526 vp << false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001527
tsepez4cf55152016-11-02 14:37:54 -07001528 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001529}
1530
dsinclair3a7741a2016-10-11 10:39:49 -07001531void Field::SetHidden(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001532 const CFX_WideString& swFieldName,
1533 int nControlIndex,
1534 bool b) {
tonikitooa73b8fe2016-08-22 14:06:49 -07001535 int display = b ? 1 /*Hidden*/ : 0 /*Visible*/;
dsinclair3a7741a2016-10-11 10:39:49 -07001536 SetDisplay(pFormFillEnv, swFieldName, nControlIndex, display);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001537}
1538
Tom Sepezb1670b52017-02-16 17:01:00 -08001539bool Field::highlight(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001540 CJS_PropValue& vp,
1541 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001542 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001543 if (vp.IsSetting()) {
1544 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001545 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001546
1547 CFX_ByteString strMode;
1548 vp >> strMode;
1549
1550 if (m_bDelay) {
1551 AddDelay_String(FP_HIGHLIGHT, strMode);
1552 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001553 Field::SetHighlight(m_pFormFillEnv.Get(), m_FieldName,
1554 m_nFormControlIndex, strMode);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001555 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001556 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001557 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001558 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1559 if (FieldArray.empty())
1560 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001561
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001562 CPDF_FormField* pFormField = FieldArray[0];
1563 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
1564 return false;
1565
1566 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1567 if (!pFormControl)
1568 return false;
1569
1570 int eHM = pFormControl->GetHighlightingMode();
1571 switch (eHM) {
1572 case CPDF_FormControl::None:
1573 vp << L"none";
1574 break;
1575 case CPDF_FormControl::Push:
1576 vp << L"push";
1577 break;
1578 case CPDF_FormControl::Invert:
1579 vp << L"invert";
1580 break;
1581 case CPDF_FormControl::Outline:
1582 vp << L"outline";
1583 break;
1584 case CPDF_FormControl::Toggle:
1585 vp << L"toggle";
1586 break;
1587 }
tsepez4cf55152016-11-02 14:37:54 -07001588 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001589}
1590
dsinclair3a7741a2016-10-11 10:39:49 -07001591void Field::SetHighlight(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001592 const CFX_WideString& swFieldName,
1593 int nControlIndex,
1594 const CFX_ByteString& string) {
1595 // Not supported.
1596}
1597
Tom Sepezb1670b52017-02-16 17:01:00 -08001598bool Field::lineWidth(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001599 CJS_PropValue& vp,
1600 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001601 if (vp.IsSetting()) {
1602 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001603 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001604
1605 int iWidth;
1606 vp >> iWidth;
1607
1608 if (m_bDelay) {
1609 AddDelay_Int(FP_LINEWIDTH, iWidth);
1610 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001611 Field::SetLineWidth(m_pFormFillEnv.Get(), m_FieldName,
1612 m_nFormControlIndex, iWidth);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001613 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001614 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001615 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001616 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1617 if (FieldArray.empty())
1618 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001619
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001620 CPDF_FormField* pFormField = FieldArray[0];
1621 ASSERT(pFormField);
1622 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1623 if (!pFormControl)
1624 return false;
1625
1626 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1627 if (!pFormField->CountControls())
1628 return false;
1629
1630 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
1631 if (!pWidget)
1632 return false;
1633
1634 vp << (int32_t)pWidget->GetBorderWidth();
tsepez4cf55152016-11-02 14:37:54 -07001635 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001636}
1637
dsinclair3a7741a2016-10-11 10:39:49 -07001638void Field::SetLineWidth(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001639 const CFX_WideString& swFieldName,
1640 int nControlIndex,
1641 int number) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001642 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001643 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07001644 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -08001645 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001646 if (nControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -07001647 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001648 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1649 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08001650 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001651
dsinclairc5267c52016-11-04 15:35:12 -07001652 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001653 if (number != pWidget->GetBorderWidth()) {
1654 pWidget->SetBorderWidth(number);
tsepez4cf55152016-11-02 14:37:54 -07001655 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001656 }
1657 }
1658 }
1659 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -07001660 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001661 } else {
1662 if (nControlIndex >= pFormField->CountControls())
1663 return;
1664 if (CPDF_FormControl* pFormControl =
1665 pFormField->GetControl(nControlIndex)) {
dsinclairc5267c52016-11-04 15:35:12 -07001666 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001667 if (number != pWidget->GetBorderWidth()) {
1668 pWidget->SetBorderWidth(number);
tsepez4cf55152016-11-02 14:37:54 -07001669 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001670 }
1671 }
1672 }
1673 }
1674 }
1675}
1676
Tom Sepezb1670b52017-02-16 17:01:00 -08001677bool Field::multiline(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001678 CJS_PropValue& vp,
1679 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001680 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001681
1682 if (vp.IsSetting()) {
1683 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001684 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001685
1686 bool bVP;
1687 vp >> bVP;
1688
1689 if (m_bDelay) {
1690 AddDelay_Bool(FP_MULTILINE, bVP);
1691 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001692 Field::SetMultiline(m_pFormFillEnv.Get(), m_FieldName,
1693 m_nFormControlIndex, bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001694 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001695 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001696 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001697 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1698 if (FieldArray.empty())
1699 return false;
1700
1701 CPDF_FormField* pFormField = FieldArray[0];
1702 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1703 return false;
1704
1705 if (pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE)
1706 vp << true;
1707 else
1708 vp << false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001709
tsepez4cf55152016-11-02 14:37:54 -07001710 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001711}
1712
dsinclair3a7741a2016-10-11 10:39:49 -07001713void Field::SetMultiline(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001714 const CFX_WideString& swFieldName,
1715 int nControlIndex,
1716 bool b) {
1717 // Not supported.
1718}
1719
Tom Sepezb1670b52017-02-16 17:01:00 -08001720bool Field::multipleSelection(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001721 CJS_PropValue& vp,
1722 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001723 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001724 if (vp.IsSetting()) {
1725 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001726 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001727
1728 bool bVP;
1729 vp >> bVP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001730 if (m_bDelay) {
1731 AddDelay_Bool(FP_MULTIPLESELECTION, bVP);
1732 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001733 Field::SetMultipleSelection(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -07001734 m_nFormControlIndex, bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001735 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001736 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001737 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001738 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1739 if (FieldArray.empty())
1740 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001741
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001742 CPDF_FormField* pFormField = FieldArray[0];
1743 if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
1744 return false;
1745
1746 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT);
tsepez4cf55152016-11-02 14:37:54 -07001747 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001748}
1749
dsinclair3a7741a2016-10-11 10:39:49 -07001750void Field::SetMultipleSelection(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001751 const CFX_WideString& swFieldName,
1752 int nControlIndex,
1753 bool b) {
1754 // Not supported.
1755}
1756
Tom Sepezb1670b52017-02-16 17:01:00 -08001757bool Field::name(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001758 CJS_PropValue& vp,
1759 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001760 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -07001761 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001762
Lei Zhangd88a3642015-11-10 09:38:57 -08001763 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1764 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001765 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001766
1767 vp << m_FieldName;
tsepez4cf55152016-11-02 14:37:54 -07001768 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001769}
1770
Tom Sepezb1670b52017-02-16 17:01:00 -08001771bool Field::numItems(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001772 CJS_PropValue& vp,
1773 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07001774 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -07001775 return false;
Tom Sepez67fd5df2015-10-08 12:24:19 -07001776
Lei Zhangd88a3642015-11-10 09:38:57 -08001777 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1778 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001779 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001780
Lei Zhangd88a3642015-11-10 09:38:57 -08001781 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001782 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001783 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
tsepez4cf55152016-11-02 14:37:54 -07001784 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001785 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001786
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001787 vp << (int32_t)pFormField->CountOptions();
tsepez4cf55152016-11-02 14:37:54 -07001788 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001789}
1790
Tom Sepezb1670b52017-02-16 17:01:00 -08001791bool Field::page(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001792 CJS_PropValue& vp,
1793 CFX_WideString& sError) {
tsepez8fa82792017-01-11 09:32:33 -08001794 if (!vp.IsGetting()) {
1795 sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
tsepez4cf55152016-11-02 14:37:54 -07001796 return false;
tsepez8fa82792017-01-11 09:32:33 -08001797 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001798
Lei Zhangd88a3642015-11-10 09:38:57 -08001799 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1800 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001801 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001802
Lei Zhangd88a3642015-11-10 09:38:57 -08001803 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001804 if (!pFormField)
tsepez4cf55152016-11-02 14:37:54 -07001805 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001806
tsepez8fa82792017-01-11 09:32:33 -08001807 std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
dsinclair7cbe68e2016-10-12 11:56:23 -07001808 m_pFormFillEnv->GetInterForm()->GetWidgets(pFormField, &widgets);
Lei Zhangd88a3642015-11-10 09:38:57 -08001809 if (widgets.empty()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001810 vp << (int32_t)-1;
tsepez4cf55152016-11-02 14:37:54 -07001811 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001812 }
1813
tsepeze5aff742016-08-08 09:49:42 -07001814 CJS_Array PageArray;
tsepez8fa82792017-01-11 09:32:33 -08001815 int i = 0;
1816 for (const auto& pObserved : widgets) {
1817 if (!pObserved) {
1818 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
1819 return false;
1820 }
1821
1822 auto pWidget = static_cast<CPDFSDK_Widget*>(pObserved.Get());
1823 CPDFSDK_PageView* pPageView = pWidget->GetPageView();
Lei Zhangd88a3642015-11-10 09:38:57 -08001824 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -07001825 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001826
1827 PageArray.SetElement(
tsepezb4694242016-08-15 16:44:55 -07001828 pRuntime, i, CJS_Value(pRuntime, (int32_t)pPageView->GetPageIndex()));
tsepez8fa82792017-01-11 09:32:33 -08001829 ++i;
Lei Zhangd88a3642015-11-10 09:38:57 -08001830 }
1831
1832 vp << PageArray;
tsepez4cf55152016-11-02 14:37:54 -07001833 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001834}
1835
Tom Sepezb1670b52017-02-16 17:01:00 -08001836bool Field::password(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001837 CJS_PropValue& vp,
1838 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001839 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001840
1841 if (vp.IsSetting()) {
1842 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001843 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001844
1845 bool bVP;
1846 vp >> bVP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001847 if (m_bDelay) {
1848 AddDelay_Bool(FP_PASSWORD, bVP);
1849 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001850 Field::SetPassword(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07001851 bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001852 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001853 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001854 }
1855
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001856 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1857 if (FieldArray.empty())
1858 return false;
1859
1860 CPDF_FormField* pFormField = FieldArray[0];
1861 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1862 return false;
1863
1864 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD);
tsepez4cf55152016-11-02 14:37:54 -07001865 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001866}
1867
dsinclair3a7741a2016-10-11 10:39:49 -07001868void Field::SetPassword(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001869 const CFX_WideString& swFieldName,
1870 int nControlIndex,
1871 bool b) {
1872 // Not supported.
1873}
1874
Tom Sepezb1670b52017-02-16 17:01:00 -08001875bool Field::print(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001876 CJS_PropValue& vp,
1877 CFX_WideString& sError) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001878 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001879 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1880 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001881 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001882
1883 if (vp.IsSetting()) {
1884 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001885 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001886
1887 bool bVP;
1888 vp >> bVP;
1889
Lei Zhangd88a3642015-11-10 09:38:57 -08001890 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001891 if (m_nFormControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -07001892 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001893 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001894 if (CPDFSDK_Widget* pWidget =
dsinclairc5267c52016-11-04 15:35:12 -07001895 pInterForm->GetWidget(pFormField->GetControl(i))) {
tsepezc3255f52016-03-25 14:52:27 -07001896 uint32_t dwFlags = pWidget->GetFlags();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001897 if (bVP)
1898 dwFlags |= ANNOTFLAG_PRINT;
1899 else
1900 dwFlags &= ~ANNOTFLAG_PRINT;
1901
1902 if (dwFlags != pWidget->GetFlags()) {
1903 pWidget->SetFlags(dwFlags);
tsepez4cf55152016-11-02 14:37:54 -07001904 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001905 }
1906 }
1907 }
1908
1909 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -07001910 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001911 } else {
1912 if (m_nFormControlIndex >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07001913 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001914 if (CPDF_FormControl* pFormControl =
1915 pFormField->GetControl(m_nFormControlIndex)) {
dsinclairc5267c52016-11-04 15:35:12 -07001916 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
tsepezc3255f52016-03-25 14:52:27 -07001917 uint32_t dwFlags = pWidget->GetFlags();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001918 if (bVP)
1919 dwFlags |= ANNOTFLAG_PRINT;
1920 else
1921 dwFlags &= ~ANNOTFLAG_PRINT;
1922
1923 if (dwFlags != pWidget->GetFlags()) {
1924 pWidget->SetFlags(dwFlags);
dsinclair3a7741a2016-10-11 10:39:49 -07001925 UpdateFormControl(m_pFormFillEnv.Get(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001926 pFormField->GetControl(m_nFormControlIndex),
tsepez4cf55152016-11-02 14:37:54 -07001927 true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001928 }
1929 }
1930 }
1931 }
1932 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001933 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001934 }
1935
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001936 CPDF_FormField* pFormField = FieldArray[0];
1937 CPDFSDK_Widget* pWidget =
1938 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1939 if (!pWidget)
1940 return false;
1941
1942 vp << !!(pWidget->GetFlags() & ANNOTFLAG_PRINT);
tsepez4cf55152016-11-02 14:37:54 -07001943 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001944}
1945
Tom Sepezb1670b52017-02-16 17:01:00 -08001946bool Field::radiosInUnison(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001947 CJS_PropValue& vp,
1948 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001949 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1950 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001951 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001952
1953 if (vp.IsSetting()) {
1954 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001955 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001956
1957 bool bVP;
1958 vp >> bVP;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001959 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001960 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001961 CPDF_FormField* pFormField = FieldArray[0];
1962 if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
1963 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001964
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001965 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON);
tsepez4cf55152016-11-02 14:37:54 -07001966 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001967}
1968
Tom Sepezb1670b52017-02-16 17:01:00 -08001969bool Field::readonly(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001970 CJS_PropValue& vp,
1971 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001972 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1973 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001974 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001975
1976 if (vp.IsSetting()) {
1977 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001978 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001979
1980 bool bVP;
1981 vp >> bVP;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001982 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001983 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001984 vp << !!(FieldArray[0]->GetFieldFlags() & FIELDFLAG_READONLY);
tsepez4cf55152016-11-02 14:37:54 -07001985 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001986}
1987
Tom Sepezb1670b52017-02-16 17:01:00 -08001988bool Field::rect(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001989 CJS_PropValue& vp,
1990 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07001991 CJS_Value Upper_Leftx(pRuntime);
1992 CJS_Value Upper_Lefty(pRuntime);
1993 CJS_Value Lower_Rightx(pRuntime);
1994 CJS_Value Lower_Righty(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001995
1996 if (vp.IsSetting()) {
1997 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001998 return false;
tsepezf3dc8c62016-08-10 06:29:29 -07001999 if (!vp.GetJSValue()->IsArrayObject())
tsepez4cf55152016-11-02 14:37:54 -07002000 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002001
tsepeze5aff742016-08-08 09:49:42 -07002002 CJS_Array rcArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002003 vp >> rcArray;
tsepezb4694242016-08-15 16:44:55 -07002004 rcArray.GetElement(pRuntime, 0, Upper_Leftx);
2005 rcArray.GetElement(pRuntime, 1, Upper_Lefty);
2006 rcArray.GetElement(pRuntime, 2, Lower_Rightx);
2007 rcArray.GetElement(pRuntime, 3, Lower_Righty);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002008
2009 FX_FLOAT pArray[4] = {0.0f, 0.0f, 0.0f, 0.0f};
tsepezb4694242016-08-15 16:44:55 -07002010 pArray[0] = static_cast<FX_FLOAT>(Upper_Leftx.ToInt(pRuntime));
2011 pArray[1] = static_cast<FX_FLOAT>(Lower_Righty.ToInt(pRuntime));
2012 pArray[2] = static_cast<FX_FLOAT>(Lower_Rightx.ToInt(pRuntime));
2013 pArray[3] = static_cast<FX_FLOAT>(Upper_Lefty.ToInt(pRuntime));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002014
Tom Sepez281a9ea2016-02-26 14:24:28 -08002015 CFX_FloatRect crRect(pArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002016 if (m_bDelay) {
2017 AddDelay_Rect(FP_RECT, crRect);
2018 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002019 Field::SetRect(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07002020 crRect);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002021 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002022 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002023 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002024 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2025 if (FieldArray.empty())
2026 return false;
2027
2028 CPDF_FormField* pFormField = FieldArray[0];
2029 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
2030 CPDFSDK_Widget* pWidget =
2031 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
2032 if (!pWidget)
2033 return false;
2034
2035 CFX_FloatRect crRect = pWidget->GetRect();
2036 Upper_Leftx = CJS_Value(pRuntime, static_cast<int32_t>(crRect.left));
2037 Upper_Lefty = CJS_Value(pRuntime, static_cast<int32_t>(crRect.top));
2038 Lower_Rightx = CJS_Value(pRuntime, static_cast<int32_t>(crRect.right));
2039 Lower_Righty = CJS_Value(pRuntime, static_cast<int32_t>(crRect.bottom));
2040
2041 CJS_Array rcArray;
2042 rcArray.SetElement(pRuntime, 0, Upper_Leftx);
2043 rcArray.SetElement(pRuntime, 1, Upper_Lefty);
2044 rcArray.SetElement(pRuntime, 2, Lower_Rightx);
2045 rcArray.SetElement(pRuntime, 3, Lower_Righty);
2046 vp << rcArray;
tsepez4cf55152016-11-02 14:37:54 -07002047 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002048}
2049
dsinclair3a7741a2016-10-11 10:39:49 -07002050void Field::SetRect(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002051 const CFX_WideString& swFieldName,
2052 int nControlIndex,
Tom Sepez281a9ea2016-02-26 14:24:28 -08002053 const CFX_FloatRect& rect) {
dsinclair7cbe68e2016-10-12 11:56:23 -07002054 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08002055 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07002056 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -08002057 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002058 if (nControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -07002059 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08002060 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002061 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08002062 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002063
dsinclairc5267c52016-11-04 15:35:12 -07002064 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002065 CFX_FloatRect crRect = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002066
2067 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002068 crRect.Intersect(pPDFPage->GetPageBBox());
2069
2070 if (!crRect.IsEmpty()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002071 CFX_FloatRect rcOld = pWidget->GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002072 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
2073 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
2074 pWidget->SetRect(crRect);
tsepez4cf55152016-11-02 14:37:54 -07002075 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002076 }
2077 }
2078 }
2079 }
2080
2081 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -07002082 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002083 } else {
2084 if (nControlIndex >= pFormField->CountControls())
2085 return;
2086 if (CPDF_FormControl* pFormControl =
2087 pFormField->GetControl(nControlIndex)) {
dsinclairc5267c52016-11-04 15:35:12 -07002088 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002089 CFX_FloatRect crRect = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002090
2091 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002092 crRect.Intersect(pPDFPage->GetPageBBox());
2093
2094 if (!crRect.IsEmpty()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002095 CFX_FloatRect rcOld = pWidget->GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002096 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
2097 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
2098 pWidget->SetRect(crRect);
tsepez4cf55152016-11-02 14:37:54 -07002099 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002100 }
2101 }
2102 }
2103 }
2104 }
2105 }
2106}
2107
Tom Sepezb1670b52017-02-16 17:01:00 -08002108bool Field::required(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002109 CJS_PropValue& vp,
2110 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002111 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2112 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002113 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002114
2115 if (vp.IsSetting()) {
2116 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002117 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002118
2119 bool bVP;
2120 vp >> bVP;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002121 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002122 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002123 CPDF_FormField* pFormField = FieldArray[0];
2124 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
2125 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002126
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002127 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED);
tsepez4cf55152016-11-02 14:37:54 -07002128 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002129}
2130
Tom Sepezb1670b52017-02-16 17:01:00 -08002131bool Field::richText(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002132 CJS_PropValue& vp,
2133 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002134 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002135
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002136 if (vp.IsSetting()) {
2137 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002138 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002139
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002140 bool bVP;
2141 vp >> bVP;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002142 if (m_bDelay)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002143 AddDelay_Bool(FP_RICHTEXT, bVP);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002144
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002145 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002146 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002147
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002148 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2149 if (FieldArray.empty())
2150 return false;
2151
2152 CPDF_FormField* pFormField = FieldArray[0];
2153 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
2154 return false;
2155
2156 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT);
tsepez4cf55152016-11-02 14:37:54 -07002157 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002158}
2159
Tom Sepezb1670b52017-02-16 17:01:00 -08002160bool Field::richValue(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002161 CJS_PropValue& vp,
2162 CFX_WideString& sError) {
2163 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002164}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002165
Tom Sepezb1670b52017-02-16 17:01:00 -08002166bool Field::rotation(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002167 CJS_PropValue& vp,
2168 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002169 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002170
2171 if (vp.IsSetting()) {
2172 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002173 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002174
2175 int nVP;
2176 vp >> nVP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002177 if (m_bDelay) {
2178 AddDelay_Int(FP_ROTATION, nVP);
2179 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002180 Field::SetRotation(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07002181 nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002182 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002183 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002184 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002185 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2186 if (FieldArray.empty())
2187 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002188
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002189 CPDF_FormField* pFormField = FieldArray[0];
2190 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2191 if (!pFormControl)
2192 return false;
2193
2194 vp << (int32_t)pFormControl->GetRotation();
tsepez4cf55152016-11-02 14:37:54 -07002195 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002196}
2197
dsinclair3a7741a2016-10-11 10:39:49 -07002198void Field::SetRotation(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002199 const CFX_WideString& swFieldName,
2200 int nControlIndex,
2201 int number) {
2202 // Not supported.
2203}
2204
Tom Sepezb1670b52017-02-16 17:01:00 -08002205bool Field::strokeColor(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002206 CJS_PropValue& vp,
2207 CFX_WideString& sError) {
tsepeze5aff742016-08-08 09:49:42 -07002208 CJS_Array crArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002209
2210 if (vp.IsSetting()) {
2211 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002212 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002213
tsepezf3dc8c62016-08-10 06:29:29 -07002214 if (!vp.GetJSValue()->IsArrayObject())
tsepez4cf55152016-11-02 14:37:54 -07002215 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002216
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002217 vp >> crArray;
2218
2219 CPWL_Color color;
tsepeze5aff742016-08-08 09:49:42 -07002220 color::ConvertArrayToPWLColor(pRuntime, crArray, &color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002221 if (m_bDelay) {
2222 AddDelay_Color(FP_STROKECOLOR, color);
2223 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002224 Field::SetStrokeColor(m_pFormFillEnv.Get(), m_FieldName,
2225 m_nFormControlIndex, color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002226 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002227 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002228 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002229 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2230 if (FieldArray.empty())
2231 return false;
2232
2233 CPDF_FormField* pFormField = FieldArray[0];
2234 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2235 if (!pFormControl)
2236 return false;
2237
2238 int iColorType;
2239 pFormControl->GetBorderColor(iColorType);
2240
2241 CPWL_Color color;
2242 if (iColorType == COLORTYPE_TRANSPARENT) {
2243 color = CPWL_Color(COLORTYPE_TRANSPARENT);
2244 } else if (iColorType == COLORTYPE_GRAY) {
2245 color = CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBorderColor(0));
2246 } else if (iColorType == COLORTYPE_RGB) {
2247 color = CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBorderColor(0),
2248 pFormControl->GetOriginalBorderColor(1),
2249 pFormControl->GetOriginalBorderColor(2));
2250 } else if (iColorType == COLORTYPE_CMYK) {
2251 color = CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBorderColor(0),
2252 pFormControl->GetOriginalBorderColor(1),
2253 pFormControl->GetOriginalBorderColor(2),
2254 pFormControl->GetOriginalBorderColor(3));
2255 } else {
2256 return false;
2257 }
2258
2259 color::ConvertPWLColorToArray(pRuntime, color, &crArray);
2260 vp << crArray;
tsepez4cf55152016-11-02 14:37:54 -07002261 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002262}
2263
dsinclair3a7741a2016-10-11 10:39:49 -07002264void Field::SetStrokeColor(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002265 const CFX_WideString& swFieldName,
2266 int nControlIndex,
2267 const CPWL_Color& color) {
2268 // Not supported.
2269}
2270
Tom Sepezb1670b52017-02-16 17:01:00 -08002271bool Field::style(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002272 CJS_PropValue& vp,
2273 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002274 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002275
2276 if (vp.IsSetting()) {
2277 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002278 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002279
2280 CFX_ByteString csBCaption;
2281 vp >> csBCaption;
2282
2283 if (m_bDelay) {
2284 AddDelay_String(FP_STYLE, csBCaption);
2285 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002286 Field::SetStyle(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002287 csBCaption);
2288 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002289 return true;
2290 }
2291 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2292 if (FieldArray.empty())
2293 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002294
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002295 CPDF_FormField* pFormField = FieldArray[0];
2296 if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON &&
2297 pFormField->GetFieldType() != FIELDTYPE_CHECKBOX) {
2298 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002299 }
2300
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002301 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2302 if (!pFormControl)
2303 return false;
2304
2305 CFX_WideString csWCaption = pFormControl->GetNormalCaption();
2306 CFX_ByteString csBCaption;
2307
2308 switch (csWCaption[0]) {
2309 case L'l':
2310 csBCaption = "circle";
2311 break;
2312 case L'8':
2313 csBCaption = "cross";
2314 break;
2315 case L'u':
2316 csBCaption = "diamond";
2317 break;
2318 case L'n':
2319 csBCaption = "square";
2320 break;
2321 case L'H':
2322 csBCaption = "star";
2323 break;
2324 default: // L'4'
2325 csBCaption = "check";
2326 break;
2327 }
2328 vp << csBCaption;
tsepez4cf55152016-11-02 14:37:54 -07002329 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002330}
2331
dsinclair3a7741a2016-10-11 10:39:49 -07002332void Field::SetStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002333 const CFX_WideString& swFieldName,
2334 int nControlIndex,
2335 const CFX_ByteString& string) {
2336 // Not supported.
2337}
2338
Tom Sepezb1670b52017-02-16 17:01:00 -08002339bool Field::submitName(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002340 CJS_PropValue& vp,
2341 CFX_WideString& sError) {
2342 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002343}
2344
Tom Sepezb1670b52017-02-16 17:01:00 -08002345bool Field::textColor(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002346 CJS_PropValue& vp,
2347 CFX_WideString& sError) {
tsepeze5aff742016-08-08 09:49:42 -07002348 CJS_Array crArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002349
2350 if (vp.IsSetting()) {
2351 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002352 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002353
tsepezf3dc8c62016-08-10 06:29:29 -07002354 if (!vp.GetJSValue()->IsArrayObject())
tsepez4cf55152016-11-02 14:37:54 -07002355 return false;
Tom Sepez67fd5df2015-10-08 12:24:19 -07002356
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002357 vp >> crArray;
2358
2359 CPWL_Color color;
tsepeze5aff742016-08-08 09:49:42 -07002360 color::ConvertArrayToPWLColor(pRuntime, crArray, &color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002361 if (m_bDelay) {
2362 AddDelay_Color(FP_TEXTCOLOR, color);
2363 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002364 Field::SetTextColor(m_pFormFillEnv.Get(), m_FieldName,
2365 m_nFormControlIndex, color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002366 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002367 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002368 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002369 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2370 if (FieldArray.empty())
2371 return false;
2372
2373 CPDF_FormField* pFormField = FieldArray[0];
2374 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2375 if (!pFormControl)
2376 return false;
2377
2378 int iColorType;
2379 FX_ARGB color;
2380 CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
2381 FieldAppearance.GetColor(color, iColorType);
2382
2383 int32_t a;
2384 int32_t r;
2385 int32_t g;
2386 int32_t b;
2387 ArgbDecode(color, a, r, g, b);
2388
2389 CPWL_Color crRet =
2390 CPWL_Color(COLORTYPE_RGB, r / 255.0f, g / 255.0f, b / 255.0f);
2391
2392 if (iColorType == COLORTYPE_TRANSPARENT)
2393 crRet = CPWL_Color(COLORTYPE_TRANSPARENT);
2394
2395 color::ConvertPWLColorToArray(pRuntime, crRet, &crArray);
2396 vp << crArray;
tsepez4cf55152016-11-02 14:37:54 -07002397 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002398}
2399
dsinclair3a7741a2016-10-11 10:39:49 -07002400void Field::SetTextColor(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002401 const CFX_WideString& swFieldName,
2402 int nControlIndex,
2403 const CPWL_Color& color) {
2404 // Not supported.
2405}
2406
Tom Sepezb1670b52017-02-16 17:01:00 -08002407bool Field::textFont(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002408 CJS_PropValue& vp,
2409 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002410 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002411
2412 if (vp.IsSetting()) {
2413 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002414 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002415
2416 CFX_ByteString csFontName;
2417 vp >> csFontName;
2418 if (csFontName.IsEmpty())
tsepez4cf55152016-11-02 14:37:54 -07002419 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002420
2421 if (m_bDelay) {
2422 AddDelay_String(FP_TEXTFONT, csFontName);
2423 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002424 Field::SetTextFont(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002425 csFontName);
2426 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002427 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002428 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002429 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2430 if (FieldArray.empty())
2431 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002432
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002433 CPDF_FormField* pFormField = FieldArray[0];
2434 ASSERT(pFormField);
2435 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2436 if (!pFormControl)
2437 return false;
2438
2439 int nFieldType = pFormField->GetFieldType();
2440 if (nFieldType != FIELDTYPE_PUSHBUTTON && nFieldType != FIELDTYPE_COMBOBOX &&
2441 nFieldType != FIELDTYPE_LISTBOX && nFieldType != FIELDTYPE_TEXTFIELD) {
2442 return false;
2443 }
2444 CPDF_Font* pFont = pFormControl->GetDefaultControlFont();
2445 if (!pFont)
2446 return false;
2447
2448 vp << pFont->GetBaseFont();
tsepez4cf55152016-11-02 14:37:54 -07002449 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002450}
2451
dsinclair3a7741a2016-10-11 10:39:49 -07002452void Field::SetTextFont(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002453 const CFX_WideString& swFieldName,
2454 int nControlIndex,
2455 const CFX_ByteString& string) {
2456 // Not supported.
2457}
2458
Tom Sepezb1670b52017-02-16 17:01:00 -08002459bool Field::textSize(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002460 CJS_PropValue& vp,
2461 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002462 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002463
2464 if (vp.IsSetting()) {
2465 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002466 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002467
2468 int nVP;
2469 vp >> nVP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002470 if (m_bDelay) {
2471 AddDelay_Int(FP_TEXTSIZE, nVP);
2472 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002473 Field::SetTextSize(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07002474 nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002475 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002476 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002477 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002478 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2479 if (FieldArray.empty())
2480 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002481
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002482 CPDF_FormField* pFormField = FieldArray[0];
2483 ASSERT(pFormField);
2484 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2485 if (!pFormControl)
2486 return false;
2487
2488 CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
2489
2490 CFX_ByteString csFontNameTag;
2491 FX_FLOAT fFontSize;
2492 FieldAppearance.GetFont(csFontNameTag, fFontSize);
2493 vp << (int)fFontSize;
tsepez4cf55152016-11-02 14:37:54 -07002494 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002495}
2496
dsinclair3a7741a2016-10-11 10:39:49 -07002497void Field::SetTextSize(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002498 const CFX_WideString& swFieldName,
2499 int nControlIndex,
2500 int number) {
2501 // Not supported.
2502}
2503
Tom Sepezb1670b52017-02-16 17:01:00 -08002504bool Field::type(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002505 CJS_PropValue& vp,
2506 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002507 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -07002508 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002509
Lei Zhangd88a3642015-11-10 09:38:57 -08002510 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2511 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002512 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002513
Lei Zhangd88a3642015-11-10 09:38:57 -08002514 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002515 switch (pFormField->GetFieldType()) {
2516 case FIELDTYPE_UNKNOWN:
2517 vp << L"unknown";
2518 break;
2519 case FIELDTYPE_PUSHBUTTON:
2520 vp << L"button";
2521 break;
2522 case FIELDTYPE_CHECKBOX:
2523 vp << L"checkbox";
2524 break;
2525 case FIELDTYPE_RADIOBUTTON:
2526 vp << L"radiobutton";
2527 break;
2528 case FIELDTYPE_COMBOBOX:
2529 vp << L"combobox";
2530 break;
2531 case FIELDTYPE_LISTBOX:
2532 vp << L"listbox";
2533 break;
2534 case FIELDTYPE_TEXTFIELD:
2535 vp << L"text";
2536 break;
2537 case FIELDTYPE_SIGNATURE:
2538 vp << L"signature";
2539 break;
2540 default:
2541 vp << L"unknown";
2542 break;
2543 }
tsepez4cf55152016-11-02 14:37:54 -07002544 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002545}
2546
Tom Sepezb1670b52017-02-16 17:01:00 -08002547bool Field::userName(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002548 CJS_PropValue& vp,
2549 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002550 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002551
2552 if (vp.IsSetting()) {
2553 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002554 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002555
2556 CFX_WideString swName;
2557 vp >> swName;
2558
2559 if (m_bDelay) {
2560 AddDelay_WideString(FP_USERNAME, swName);
2561 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002562 Field::SetUserName(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07002563 swName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002564 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002565 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002566 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002567 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2568 if (FieldArray.empty())
2569 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002570
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002571 vp << FieldArray[0]->GetAlternateName();
tsepez4cf55152016-11-02 14:37:54 -07002572 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002573}
2574
dsinclair3a7741a2016-10-11 10:39:49 -07002575void Field::SetUserName(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002576 const CFX_WideString& swFieldName,
2577 int nControlIndex,
2578 const CFX_WideString& string) {
2579 // Not supported.
2580}
2581
Tom Sepezb1670b52017-02-16 17:01:00 -08002582bool Field::value(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002583 CJS_PropValue& vp,
2584 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002585 if (vp.IsSetting()) {
2586 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002587 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002588
tsepez41a53ad2016-03-28 16:59:30 -07002589 std::vector<CFX_WideString> strArray;
tsepezf3dc8c62016-08-10 06:29:29 -07002590 if (vp.GetJSValue()->IsArrayObject()) {
tsepeze5aff742016-08-08 09:49:42 -07002591 CJS_Array ValueArray;
tsepezb4694242016-08-15 16:44:55 -07002592 vp.GetJSValue()->ConvertToArray(pRuntime, ValueArray);
2593 for (int i = 0, sz = ValueArray.GetLength(pRuntime); i < sz; i++) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002594 CJS_Value ElementValue(pRuntime);
tsepezb4694242016-08-15 16:44:55 -07002595 ValueArray.GetElement(pRuntime, i, ElementValue);
2596 strArray.push_back(ElementValue.ToCFXWideString(pRuntime));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002597 }
2598 } else {
2599 CFX_WideString swValue;
2600 vp >> swValue;
tsepez41a53ad2016-03-28 16:59:30 -07002601 strArray.push_back(swValue);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002602 }
2603
2604 if (m_bDelay) {
2605 AddDelay_WideStringArray(FP_VALUE, strArray);
2606 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002607 Field::SetValue(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07002608 strArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002609 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002610 return true;
2611 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002612
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002613 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2614 if (FieldArray.empty())
2615 return false;
2616
2617 CPDF_FormField* pFormField = FieldArray[0];
2618 switch (pFormField->GetFieldType()) {
2619 case FIELDTYPE_PUSHBUTTON:
2620 return false;
2621 case FIELDTYPE_COMBOBOX:
2622 case FIELDTYPE_TEXTFIELD: {
2623 vp << pFormField->GetValue();
2624 } break;
2625 case FIELDTYPE_LISTBOX: {
2626 if (pFormField->CountSelectedItems() > 1) {
2627 CJS_Array ValueArray;
2628 CJS_Value ElementValue(pRuntime);
2629 int iIndex;
2630 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
2631 iIndex = pFormField->GetSelectedIndex(i);
2632 ElementValue =
2633 CJS_Value(pRuntime, pFormField->GetOptionValue(iIndex).c_str());
2634 if (FXSYS_wcslen(ElementValue.ToCFXWideString(pRuntime).c_str()) ==
2635 0) {
tsepezf3dc8c62016-08-10 06:29:29 -07002636 ElementValue =
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002637 CJS_Value(pRuntime, pFormField->GetOptionLabel(iIndex).c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002638 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002639 ValueArray.SetElement(pRuntime, i, ElementValue);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002640 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002641 vp << ValueArray;
2642 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002643 vp << pFormField->GetValue();
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002644 }
2645 } break;
2646 case FIELDTYPE_CHECKBOX:
2647 case FIELDTYPE_RADIOBUTTON: {
2648 bool bFind = false;
2649 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2650 if (pFormField->GetControl(i)->IsChecked()) {
2651 vp << pFormField->GetControl(i)->GetExportValue();
2652 bFind = true;
2653 break;
2654 }
2655 }
2656 if (!bFind)
2657 vp << L"Off";
2658 } break;
2659 default:
2660 vp << pFormField->GetValue();
2661 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002662 }
tsepezb4694242016-08-15 16:44:55 -07002663 vp.GetJSValue()->MaybeCoerceToNumber(pRuntime);
tsepez4cf55152016-11-02 14:37:54 -07002664 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002665}
2666
dsinclair3a7741a2016-10-11 10:39:49 -07002667void Field::SetValue(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002668 const CFX_WideString& swFieldName,
2669 int nControlIndex,
tsepez41a53ad2016-03-28 16:59:30 -07002670 const std::vector<CFX_WideString>& strArray) {
dsinclair3a7741a2016-10-11 10:39:49 -07002671 ASSERT(pFormFillEnv);
tsepez41a53ad2016-03-28 16:59:30 -07002672 if (strArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002673 return;
2674
Lei Zhangd88a3642015-11-10 09:38:57 -08002675 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07002676 GetFormFields(pFormFillEnv, swFieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002677
Lei Zhangd88a3642015-11-10 09:38:57 -08002678 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002679 if (pFormField->GetFullName().Compare(swFieldName) != 0)
2680 continue;
2681
2682 switch (pFormField->GetFieldType()) {
2683 case FIELDTYPE_TEXTFIELD:
2684 case FIELDTYPE_COMBOBOX:
tsepez41a53ad2016-03-28 16:59:30 -07002685 if (pFormField->GetValue() != strArray[0]) {
tsepez4cf55152016-11-02 14:37:54 -07002686 pFormField->SetValue(strArray[0], true);
2687 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002688 }
2689 break;
tsepez41a53ad2016-03-28 16:59:30 -07002690 case FIELDTYPE_CHECKBOX:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002691 case FIELDTYPE_RADIOBUTTON: {
tsepez41a53ad2016-03-28 16:59:30 -07002692 if (pFormField->GetValue() != strArray[0]) {
tsepez4cf55152016-11-02 14:37:54 -07002693 pFormField->SetValue(strArray[0], true);
2694 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002695 }
2696 } break;
2697 case FIELDTYPE_LISTBOX: {
tsepez4cf55152016-11-02 14:37:54 -07002698 bool bModified = false;
tsepez41a53ad2016-03-28 16:59:30 -07002699 for (const auto& str : strArray) {
2700 if (!pFormField->IsItemSelected(pFormField->FindOption(str))) {
tsepez4cf55152016-11-02 14:37:54 -07002701 bModified = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002702 break;
2703 }
2704 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002705 if (bModified) {
tsepez4cf55152016-11-02 14:37:54 -07002706 pFormField->ClearSelection(true);
tsepez41a53ad2016-03-28 16:59:30 -07002707 for (const auto& str : strArray) {
2708 int index = pFormField->FindOption(str);
2709 if (!pFormField->IsItemSelected(index))
tsepez4cf55152016-11-02 14:37:54 -07002710 pFormField->SetItemSelection(index, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002711 }
tsepez4cf55152016-11-02 14:37:54 -07002712 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002713 }
2714 } break;
2715 default:
2716 break;
2717 }
2718 }
2719}
2720
Tom Sepezb1670b52017-02-16 17:01:00 -08002721bool Field::valueAsString(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002722 CJS_PropValue& vp,
2723 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002724 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -07002725 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002726
Lei Zhangd88a3642015-11-10 09:38:57 -08002727 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2728 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002729 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002730
Lei Zhangd88a3642015-11-10 09:38:57 -08002731 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002732 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002733 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002734
2735 if (pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) {
2736 if (!pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002737 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002738
2739 if (pFormField->GetControl(0)->IsChecked())
2740 vp << L"Yes";
2741 else
2742 vp << L"Off";
2743 } else if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON &&
2744 !(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)) {
2745 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2746 if (pFormField->GetControl(i)->IsChecked()) {
2747 vp << pFormField->GetControl(i)->GetExportValue().c_str();
2748 break;
Lei Zhangd88a3642015-11-10 09:38:57 -08002749 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002750 vp << L"Off";
Lei Zhangd88a3642015-11-10 09:38:57 -08002751 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002752 }
2753 } else if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX &&
2754 (pFormField->CountSelectedItems() > 1)) {
2755 vp << L"";
Lei Zhangd88a3642015-11-10 09:38:57 -08002756 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002757 vp << pFormField->GetValue().c_str();
Lei Zhangd88a3642015-11-10 09:38:57 -08002758 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002759
tsepez4cf55152016-11-02 14:37:54 -07002760 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002761}
2762
Tom Sepezb1670b52017-02-16 17:01:00 -08002763bool Field::browseForFileToSubmit(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002764 const std::vector<CJS_Value>& params,
2765 CJS_Value& vRet,
2766 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002767 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2768 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002769 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002770
Lei Zhangd88a3642015-11-10 09:38:57 -08002771 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002772 if ((pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) &&
2773 (pFormField->GetFieldType() == FIELDTYPE_TEXTFIELD)) {
dsinclair3a7741a2016-10-11 10:39:49 -07002774 CFX_WideString wsFileName = m_pFormFillEnv->JS_fieldBrowse();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002775 if (!wsFileName.IsEmpty()) {
2776 pFormField->SetValue(wsFileName);
tsepez4cf55152016-11-02 14:37:54 -07002777 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002778 }
tsepez4cf55152016-11-02 14:37:54 -07002779 return true;
Lei Zhangd88a3642015-11-10 09:38:57 -08002780 }
tsepez4cf55152016-11-02 14:37:54 -07002781 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002782}
2783
Tom Sepezb1670b52017-02-16 17:01:00 -08002784bool Field::buttonGetCaption(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002785 const std::vector<CJS_Value>& params,
2786 CJS_Value& vRet,
2787 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002788 int nface = 0;
2789 int iSize = params.size();
2790 if (iSize >= 1)
tsepezb4694242016-08-15 16:44:55 -07002791 nface = params[0].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002792
Lei Zhangd88a3642015-11-10 09:38:57 -08002793 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2794 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002795 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002796
Lei Zhangd88a3642015-11-10 09:38:57 -08002797 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002798 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002799 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002800
2801 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2802 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -07002803 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002804
2805 if (nface == 0)
tsepezf3dc8c62016-08-10 06:29:29 -07002806 vRet = CJS_Value(pRuntime, pFormControl->GetNormalCaption().c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002807 else if (nface == 1)
tsepezf3dc8c62016-08-10 06:29:29 -07002808 vRet = CJS_Value(pRuntime, pFormControl->GetDownCaption().c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002809 else if (nface == 2)
tsepezf3dc8c62016-08-10 06:29:29 -07002810 vRet = CJS_Value(pRuntime, pFormControl->GetRolloverCaption().c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002811 else
tsepez4cf55152016-11-02 14:37:54 -07002812 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002813
tsepez4cf55152016-11-02 14:37:54 -07002814 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002815}
2816
Tom Sepezb1670b52017-02-16 17:01:00 -08002817bool Field::buttonGetIcon(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002818 const std::vector<CJS_Value>& params,
2819 CJS_Value& vRet,
2820 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002821 int nface = 0;
2822 int iSize = params.size();
2823 if (iSize >= 1)
tsepezb4694242016-08-15 16:44:55 -07002824 nface = params[0].ToInt(pRuntime);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002825
Lei Zhangd88a3642015-11-10 09:38:57 -08002826 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2827 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002828 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002829
Lei Zhangd88a3642015-11-10 09:38:57 -08002830 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002831 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002832 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002833
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002834 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2835 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -07002836 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002837
tsepezb4694242016-08-15 16:44:55 -07002838 v8::Local<v8::Object> pObj =
2839 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID);
tsepez4cf55152016-11-02 14:37:54 -07002840 ASSERT(pObj.IsEmpty() == false);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002841
tsepezb4694242016-08-15 16:44:55 -07002842 CJS_Icon* pJS_Icon = static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002843 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002844
thestig1cd352e2016-06-07 17:53:06 -07002845 CPDF_Stream* pIconStream = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002846 if (nface == 0)
2847 pIconStream = pFormControl->GetNormalIcon();
2848 else if (nface == 1)
2849 pIconStream = pFormControl->GetDownIcon();
2850 else if (nface == 2)
2851 pIconStream = pFormControl->GetRolloverIcon();
2852 else
tsepez4cf55152016-11-02 14:37:54 -07002853 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002854
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002855 pIcon->SetStream(pIconStream);
tsepezf3dc8c62016-08-10 06:29:29 -07002856 vRet = CJS_Value(pRuntime, pJS_Icon);
tsepez4cf55152016-11-02 14:37:54 -07002857 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002858}
2859
Tom Sepezb1670b52017-02-16 17:01:00 -08002860bool Field::buttonImportIcon(CJS_Runtime* pRuntime,
Lei Zhang945fdb72015-11-11 10:18:16 -08002861 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002862 CJS_Value& vRet,
2863 CFX_WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002864 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002865}
2866
Tom Sepezb1670b52017-02-16 17:01:00 -08002867bool Field::buttonSetCaption(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002868 const std::vector<CJS_Value>& params,
2869 CJS_Value& vRet,
2870 CFX_WideString& sError) {
2871 return false;
2872}
2873
Tom Sepezb1670b52017-02-16 17:01:00 -08002874bool Field::buttonSetIcon(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002875 const std::vector<CJS_Value>& params,
2876 CJS_Value& vRet,
2877 CFX_WideString& sError) {
2878 return false;
2879}
2880
Tom Sepezb1670b52017-02-16 17:01:00 -08002881bool Field::checkThisBox(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002882 const std::vector<CJS_Value>& params,
2883 CJS_Value& vRet,
2884 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002885 int iSize = params.size();
2886 if (iSize < 1)
tsepez4cf55152016-11-02 14:37:54 -07002887 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002888
tsepezf3dc8c62016-08-10 06:29:29 -07002889 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002890 return false;
tsepezf3dc8c62016-08-10 06:29:29 -07002891
tsepezb4694242016-08-15 16:44:55 -07002892 int nWidget = params[0].ToInt(pRuntime);
Wei Li97da9762016-03-11 17:00:48 -08002893 bool bCheckit = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002894 if (iSize >= 2)
tsepezb4694242016-08-15 16:44:55 -07002895 bCheckit = params[1].ToBool(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002896
Lei Zhangd88a3642015-11-10 09:38:57 -08002897 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2898 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002899 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002900
Lei Zhangd88a3642015-11-10 09:38:57 -08002901 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002902 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
2903 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002904 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002905 if (nWidget < 0 || nWidget >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002906 return false;
Wei Li97da9762016-03-11 17:00:48 -08002907 // TODO(weili): Check whether anything special needed for radio button,
2908 // otherwise merge these branches.
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002909 if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)
Wei Li97da9762016-03-11 17:00:48 -08002910 pFormField->CheckControl(nWidget, bCheckit, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002911 else
Wei Li97da9762016-03-11 17:00:48 -08002912 pFormField->CheckControl(nWidget, bCheckit, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002913
tsepez4cf55152016-11-02 14:37:54 -07002914 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true);
2915 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002916}
2917
Tom Sepezb1670b52017-02-16 17:01:00 -08002918bool Field::clearItems(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002919 const std::vector<CJS_Value>& params,
2920 CJS_Value& vRet,
2921 CFX_WideString& sError) {
2922 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002923}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002924
Tom Sepezb1670b52017-02-16 17:01:00 -08002925bool Field::defaultIsChecked(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002926 const std::vector<CJS_Value>& params,
2927 CJS_Value& vRet,
2928 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002929 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002930 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002931
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002932 int iSize = params.size();
2933 if (iSize < 1)
tsepez4cf55152016-11-02 14:37:54 -07002934 return false;
Tom Sepezf4ef3f92015-04-23 11:31:31 -07002935
tsepezb4694242016-08-15 16:44:55 -07002936 int nWidget = params[0].ToInt(pRuntime);
Lei Zhangd88a3642015-11-10 09:38:57 -08002937 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2938 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002939 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002940
Lei Zhangd88a3642015-11-10 09:38:57 -08002941 CPDF_FormField* pFormField = FieldArray[0];
tsepezf3dc8c62016-08-10 06:29:29 -07002942 if (nWidget < 0 || nWidget >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002943 return false;
tsepezf3dc8c62016-08-10 06:29:29 -07002944
2945 vRet = CJS_Value(pRuntime,
2946 pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
2947 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002948
tsepez4cf55152016-11-02 14:37:54 -07002949 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002950}
2951
Tom Sepezb1670b52017-02-16 17:01:00 -08002952bool Field::deleteItemAt(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002953 const std::vector<CJS_Value>& params,
2954 CJS_Value& vRet,
2955 CFX_WideString& sError) {
2956 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002957}
2958
Tom Sepezb1670b52017-02-16 17:01:00 -08002959bool Field::getArray(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002960 const std::vector<CJS_Value>& params,
2961 CJS_Value& vRet,
2962 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002963 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2964 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002965 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002966
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002967 std::vector<std::unique_ptr<CFX_WideString>> swSort;
2968 for (CPDF_FormField* pFormField : FieldArray) {
2969 swSort.push_back(std::unique_ptr<CFX_WideString>(
2970 new CFX_WideString(pFormField->GetFullName())));
2971 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002972
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002973 std::sort(
2974 swSort.begin(), swSort.end(),
2975 [](const std::unique_ptr<CFX_WideString>& p1,
2976 const std::unique_ptr<CFX_WideString>& p2) { return *p1 < *p2; });
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002977
tsepeze5aff742016-08-08 09:49:42 -07002978 CJS_Array FormFieldArray;
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002979
2980 int j = 0;
2981 for (const auto& pStr : swSort) {
tsepezb4694242016-08-15 16:44:55 -07002982 v8::Local<v8::Object> pObj =
2983 pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID);
Tom Sepezcd56a7d2015-10-06 11:45:28 -07002984 ASSERT(!pObj.IsEmpty());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002985
Tom Sepezd5a0e952015-09-17 15:40:06 -07002986 CJS_Field* pJSField =
tsepezb4694242016-08-15 16:44:55 -07002987 static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pObj));
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002988 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002989 pField->AttachField(m_pJSDoc, *pStr);
tsepezb4694242016-08-15 16:44:55 -07002990 FormFieldArray.SetElement(pRuntime, j++, CJS_Value(pRuntime, pJSField));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002991 }
2992
tsepeze5aff742016-08-08 09:49:42 -07002993 vRet = CJS_Value(pRuntime, FormFieldArray);
tsepez4cf55152016-11-02 14:37:54 -07002994 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002995}
2996
Tom Sepezb1670b52017-02-16 17:01:00 -08002997bool Field::getItemAt(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002998 const std::vector<CJS_Value>& params,
2999 CJS_Value& vRet,
3000 CFX_WideString& sError) {
tsepezf3dc8c62016-08-10 06:29:29 -07003001 int iSize = params.size();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003002 int nIdx = -1;
3003 if (iSize >= 1)
tsepezb4694242016-08-15 16:44:55 -07003004 nIdx = params[0].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003005
tsepez4cf55152016-11-02 14:37:54 -07003006 bool bExport = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003007 if (iSize >= 2)
tsepezb4694242016-08-15 16:44:55 -07003008 bExport = params[1].ToBool(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003009
Lei Zhangd88a3642015-11-10 09:38:57 -08003010 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3011 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07003012 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003013
Lei Zhangd88a3642015-11-10 09:38:57 -08003014 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003015 if ((pFormField->GetFieldType() == FIELDTYPE_LISTBOX) ||
3016 (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX)) {
3017 if (nIdx == -1 || nIdx > pFormField->CountOptions())
3018 nIdx = pFormField->CountOptions() - 1;
3019 if (bExport) {
3020 CFX_WideString strval = pFormField->GetOptionValue(nIdx);
3021 if (strval.IsEmpty())
tsepezf3dc8c62016-08-10 06:29:29 -07003022 vRet = CJS_Value(pRuntime, pFormField->GetOptionLabel(nIdx).c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003023 else
tsepezf3dc8c62016-08-10 06:29:29 -07003024 vRet = CJS_Value(pRuntime, strval.c_str());
Lei Zhangd88a3642015-11-10 09:38:57 -08003025 } else {
tsepezf3dc8c62016-08-10 06:29:29 -07003026 vRet = CJS_Value(pRuntime, pFormField->GetOptionLabel(nIdx).c_str());
Lei Zhangd88a3642015-11-10 09:38:57 -08003027 }
3028 } else {
tsepez4cf55152016-11-02 14:37:54 -07003029 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08003030 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003031
tsepez4cf55152016-11-02 14:37:54 -07003032 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003033}
3034
Tom Sepezb1670b52017-02-16 17:01:00 -08003035bool Field::getLock(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003036 const std::vector<CJS_Value>& params,
3037 CJS_Value& vRet,
3038 CFX_WideString& sError) {
3039 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003040}
3041
Tom Sepezb1670b52017-02-16 17:01:00 -08003042bool Field::insertItemAt(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003043 const std::vector<CJS_Value>& params,
3044 CJS_Value& vRet,
3045 CFX_WideString& sError) {
3046 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003047}
3048
Tom Sepezb1670b52017-02-16 17:01:00 -08003049bool Field::isBoxChecked(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003050 const std::vector<CJS_Value>& params,
3051 CJS_Value& vRet,
3052 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003053 int nIndex = -1;
3054 if (params.size() >= 1)
tsepezb4694242016-08-15 16:44:55 -07003055 nIndex = params[0].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003056
Lei Zhangd88a3642015-11-10 09:38:57 -08003057 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3058 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07003059 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003060
Lei Zhangd88a3642015-11-10 09:38:57 -08003061 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003062 if (nIndex < 0 || nIndex >= pFormField->CountControls()) {
tsepez4cf55152016-11-02 14:37:54 -07003063 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003064 }
3065
tsepezf3dc8c62016-08-10 06:29:29 -07003066 vRet = CJS_Value(pRuntime,
3067 ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
3068 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) &&
3069 pFormField->GetControl(nIndex)->IsChecked() != 0));
tsepez4cf55152016-11-02 14:37:54 -07003070 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003071}
3072
Tom Sepezb1670b52017-02-16 17:01:00 -08003073bool Field::isDefaultChecked(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003074 const std::vector<CJS_Value>& params,
3075 CJS_Value& vRet,
3076 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003077 int nIndex = -1;
3078 if (params.size() >= 1)
tsepezb4694242016-08-15 16:44:55 -07003079 nIndex = params[0].ToInt(pRuntime);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003080
Lei Zhangd88a3642015-11-10 09:38:57 -08003081 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3082 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07003083 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003084
Lei Zhangd88a3642015-11-10 09:38:57 -08003085 CPDF_FormField* pFormField = FieldArray[0];
tsepezf3dc8c62016-08-10 06:29:29 -07003086 if (nIndex < 0 || nIndex >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07003087 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003088
tsepezf3dc8c62016-08-10 06:29:29 -07003089 vRet = CJS_Value(pRuntime,
3090 ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
3091 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) &&
3092 pFormField->GetControl(nIndex)->IsDefaultChecked() != 0));
tsepez4cf55152016-11-02 14:37:54 -07003093 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003094}
3095
Tom Sepezb1670b52017-02-16 17:01:00 -08003096bool Field::setAction(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003097 const std::vector<CJS_Value>& params,
3098 CJS_Value& vRet,
3099 CFX_WideString& sError) {
3100 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003101}
3102
Tom Sepezb1670b52017-02-16 17:01:00 -08003103bool Field::setFocus(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003104 const std::vector<CJS_Value>& params,
3105 CJS_Value& vRet,
3106 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08003107 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3108 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07003109 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003110
Lei Zhangd88a3642015-11-10 09:38:57 -08003111 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003112 int32_t nCount = pFormField->CountControls();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003113 if (nCount < 1)
tsepez4cf55152016-11-02 14:37:54 -07003114 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003115
dsinclair7cbe68e2016-10-12 11:56:23 -07003116 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
thestig1cd352e2016-06-07 17:53:06 -07003117 CPDFSDK_Widget* pWidget = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003118 if (nCount == 1) {
dsinclairc5267c52016-11-04 15:35:12 -07003119 pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003120 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07003121 UnderlyingPageType* pPage =
3122 UnderlyingFromFPDFPage(m_pFormFillEnv->GetCurrentPage(
3123 m_pFormFillEnv->GetUnderlyingDocument()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003124 if (!pPage)
tsepez4cf55152016-11-02 14:37:54 -07003125 return false;
dsinclair461eeaf2016-07-27 07:40:05 -07003126 if (CPDFSDK_PageView* pCurPageView =
dsinclair7cbe68e2016-10-12 11:56:23 -07003127 m_pFormFillEnv->GetPageView(pPage, true)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003128 for (int32_t i = 0; i < nCount; i++) {
3129 if (CPDFSDK_Widget* pTempWidget =
dsinclairc5267c52016-11-04 15:35:12 -07003130 pInterForm->GetWidget(pFormField->GetControl(i))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003131 if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage()) {
3132 pWidget = pTempWidget;
3133 break;
3134 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003135 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003136 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003137 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003138 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003139
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003140 if (pWidget) {
tsepezf8074ce2016-09-27 14:29:57 -07003141 CPDFSDK_Annot::ObservedPtr pObserved(pWidget);
dsinclair7cbe68e2016-10-12 11:56:23 -07003142 m_pFormFillEnv->SetFocusAnnot(&pObserved);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003143 }
3144
tsepez4cf55152016-11-02 14:37:54 -07003145 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003146}
3147
Tom Sepezb1670b52017-02-16 17:01:00 -08003148bool Field::setItems(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003149 const std::vector<CJS_Value>& params,
3150 CJS_Value& vRet,
3151 CFX_WideString& sError) {
3152 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003153}
3154
Tom Sepezb1670b52017-02-16 17:01:00 -08003155bool Field::setLock(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003156 const std::vector<CJS_Value>& params,
3157 CJS_Value& vRet,
3158 CFX_WideString& sError) {
3159 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003160}
3161
Tom Sepezb1670b52017-02-16 17:01:00 -08003162bool Field::signatureGetModifications(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003163 const std::vector<CJS_Value>& params,
3164 CJS_Value& vRet,
3165 CFX_WideString& sError) {
3166 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003167}
3168
Tom Sepezb1670b52017-02-16 17:01:00 -08003169bool Field::signatureGetSeedValue(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003170 const std::vector<CJS_Value>& params,
3171 CJS_Value& vRet,
3172 CFX_WideString& sError) {
3173 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003174}
3175
Tom Sepezb1670b52017-02-16 17:01:00 -08003176bool Field::signatureInfo(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003177 const std::vector<CJS_Value>& params,
3178 CJS_Value& vRet,
3179 CFX_WideString& sError) {
3180 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003181}
3182
Tom Sepezb1670b52017-02-16 17:01:00 -08003183bool Field::signatureSetSeedValue(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003184 const std::vector<CJS_Value>& params,
3185 CJS_Value& vRet,
3186 CFX_WideString& sError) {
3187 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003188}
3189
Tom Sepezb1670b52017-02-16 17:01:00 -08003190bool Field::signatureSign(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003191 const std::vector<CJS_Value>& params,
3192 CJS_Value& vRet,
3193 CFX_WideString& sError) {
3194 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003195}
3196
Tom Sepezb1670b52017-02-16 17:01:00 -08003197bool Field::signatureValidate(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003198 const std::vector<CJS_Value>& params,
3199 CJS_Value& vRet,
3200 CFX_WideString& sError) {
3201 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003202}
3203
Tom Sepezb1670b52017-02-16 17:01:00 -08003204bool Field::source(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08003205 CJS_PropValue& vp,
3206 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003207 if (vp.IsGetting()) {
thestig1cd352e2016-06-07 17:53:06 -07003208 vp << (CJS_Object*)nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003209 }
3210
tsepez4cf55152016-11-02 14:37:54 -07003211 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003212}
3213
tsepez41a53ad2016-03-28 16:59:30 -07003214void Field::AddDelay_Int(FIELD_PROP prop, int32_t n) {
3215 CJS_DelayData* pNewData =
3216 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003217 pNewData->num = n;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003218 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003219}
3220
tsepez41a53ad2016-03-28 16:59:30 -07003221void Field::AddDelay_Bool(FIELD_PROP prop, bool b) {
3222 CJS_DelayData* pNewData =
3223 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003224 pNewData->b = b;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003225 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003226}
3227
tsepez41a53ad2016-03-28 16:59:30 -07003228void Field::AddDelay_String(FIELD_PROP prop, const CFX_ByteString& string) {
3229 CJS_DelayData* pNewData =
3230 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003231 pNewData->string = string;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003232 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003233}
3234
tsepez41a53ad2016-03-28 16:59:30 -07003235void Field::AddDelay_WideString(FIELD_PROP prop, const CFX_WideString& string) {
3236 CJS_DelayData* pNewData =
3237 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003238 pNewData->widestring = string;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003239 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003240}
3241
tsepez41a53ad2016-03-28 16:59:30 -07003242void Field::AddDelay_Rect(FIELD_PROP prop, const CFX_FloatRect& rect) {
3243 CJS_DelayData* pNewData =
3244 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003245 pNewData->rect = rect;
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_Color(FIELD_PROP prop, const CPWL_Color& color) {
3250 CJS_DelayData* pNewData =
3251 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003252 pNewData->color = color;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003253 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003254}
3255
tsepez41a53ad2016-03-28 16:59:30 -07003256void Field::AddDelay_WordArray(FIELD_PROP prop,
3257 const std::vector<uint32_t>& array) {
3258 CJS_DelayData* pNewData =
3259 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
3260 pNewData->wordarray = array;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003261 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003262}
3263
tsepez41a53ad2016-03-28 16:59:30 -07003264void Field::AddDelay_WideStringArray(FIELD_PROP prop,
3265 const std::vector<CFX_WideString>& array) {
3266 CJS_DelayData* pNewData =
3267 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
3268 pNewData->widestringarray = array;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003269 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003270}
3271
dsinclair3a7741a2016-10-11 10:39:49 -07003272void Field::DoDelay(CPDFSDK_FormFillEnvironment* pFormFillEnv,
3273 CJS_DelayData* pData) {
3274 ASSERT(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003275 switch (pData->eProp) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003276 case FP_ALIGNMENT:
dsinclair3a7741a2016-10-11 10:39:49 -07003277 Field::SetAlignment(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003278 pData->string);
3279 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003280 case FP_BORDERSTYLE:
dsinclair3a7741a2016-10-11 10:39:49 -07003281 Field::SetBorderStyle(pFormFillEnv, pData->sFieldName,
3282 pData->nControlIndex, pData->string);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003283 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003284 case FP_BUTTONALIGNX:
dsinclair3a7741a2016-10-11 10:39:49 -07003285 Field::SetButtonAlignX(pFormFillEnv, pData->sFieldName,
3286 pData->nControlIndex, pData->num);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003287 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003288 case FP_BUTTONALIGNY:
dsinclair3a7741a2016-10-11 10:39:49 -07003289 Field::SetButtonAlignY(pFormFillEnv, pData->sFieldName,
3290 pData->nControlIndex, pData->num);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003291 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003292 case FP_BUTTONFITBOUNDS:
dsinclair3a7741a2016-10-11 10:39:49 -07003293 Field::SetButtonFitBounds(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003294 pData->nControlIndex, pData->b);
3295 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003296 case FP_BUTTONPOSITION:
dsinclair3a7741a2016-10-11 10:39:49 -07003297 Field::SetButtonPosition(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003298 pData->nControlIndex, pData->num);
3299 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003300 case FP_BUTTONSCALEHOW:
dsinclair3a7741a2016-10-11 10:39:49 -07003301 Field::SetButtonScaleHow(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003302 pData->nControlIndex, pData->num);
3303 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003304 case FP_BUTTONSCALEWHEN:
dsinclair3a7741a2016-10-11 10:39:49 -07003305 Field::SetButtonScaleWhen(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003306 pData->nControlIndex, pData->num);
3307 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003308 case FP_CALCORDERINDEX:
dsinclair3a7741a2016-10-11 10:39:49 -07003309 Field::SetCalcOrderIndex(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003310 pData->nControlIndex, pData->num);
3311 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003312 case FP_CHARLIMIT:
dsinclair3a7741a2016-10-11 10:39:49 -07003313 Field::SetCharLimit(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003314 pData->num);
3315 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003316 case FP_COMB:
dsinclair3a7741a2016-10-11 10:39:49 -07003317 Field::SetComb(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003318 pData->b);
3319 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003320 case FP_COMMITONSELCHANGE:
dsinclair3a7741a2016-10-11 10:39:49 -07003321 Field::SetCommitOnSelChange(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003322 pData->nControlIndex, pData->b);
3323 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003324 case FP_CURRENTVALUEINDICES:
dsinclair3a7741a2016-10-11 10:39:49 -07003325 Field::SetCurrentValueIndices(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003326 pData->nControlIndex, pData->wordarray);
3327 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003328 case FP_DEFAULTVALUE:
dsinclair3a7741a2016-10-11 10:39:49 -07003329 Field::SetDefaultValue(pFormFillEnv, pData->sFieldName,
3330 pData->nControlIndex, pData->widestring);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003331 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003332 case FP_DONOTSCROLL:
dsinclair3a7741a2016-10-11 10:39:49 -07003333 Field::SetDoNotScroll(pFormFillEnv, pData->sFieldName,
3334 pData->nControlIndex, pData->b);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003335 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003336 case FP_DISPLAY:
dsinclair3a7741a2016-10-11 10:39:49 -07003337 Field::SetDisplay(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003338 pData->num);
3339 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003340 case FP_FILLCOLOR:
dsinclair3a7741a2016-10-11 10:39:49 -07003341 Field::SetFillColor(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003342 pData->color);
3343 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003344 case FP_HIDDEN:
dsinclair3a7741a2016-10-11 10:39:49 -07003345 Field::SetHidden(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003346 pData->b);
3347 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003348 case FP_HIGHLIGHT:
dsinclair3a7741a2016-10-11 10:39:49 -07003349 Field::SetHighlight(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003350 pData->string);
3351 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003352 case FP_LINEWIDTH:
dsinclair3a7741a2016-10-11 10:39:49 -07003353 Field::SetLineWidth(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003354 pData->num);
3355 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003356 case FP_MULTILINE:
dsinclair3a7741a2016-10-11 10:39:49 -07003357 Field::SetMultiline(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003358 pData->b);
3359 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003360 case FP_MULTIPLESELECTION:
dsinclair3a7741a2016-10-11 10:39:49 -07003361 Field::SetMultipleSelection(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003362 pData->nControlIndex, pData->b);
3363 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003364 case FP_PASSWORD:
dsinclair3a7741a2016-10-11 10:39:49 -07003365 Field::SetPassword(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003366 pData->b);
3367 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003368 case FP_RECT:
dsinclair3a7741a2016-10-11 10:39:49 -07003369 Field::SetRect(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003370 pData->rect);
3371 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003372 case FP_RICHTEXT:
dsinclaira2919b32016-07-13 10:55:48 -07003373 // Not supported.
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003374 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003375 case FP_RICHVALUE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003376 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003377 case FP_ROTATION:
dsinclair3a7741a2016-10-11 10:39:49 -07003378 Field::SetRotation(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003379 pData->num);
3380 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003381 case FP_STROKECOLOR:
dsinclair3a7741a2016-10-11 10:39:49 -07003382 Field::SetStrokeColor(pFormFillEnv, pData->sFieldName,
3383 pData->nControlIndex, pData->color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003384 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003385 case FP_STYLE:
dsinclair3a7741a2016-10-11 10:39:49 -07003386 Field::SetStyle(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003387 pData->string);
3388 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003389 case FP_TEXTCOLOR:
dsinclair3a7741a2016-10-11 10:39:49 -07003390 Field::SetTextColor(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003391 pData->color);
3392 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003393 case FP_TEXTFONT:
dsinclair3a7741a2016-10-11 10:39:49 -07003394 Field::SetTextFont(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003395 pData->string);
3396 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003397 case FP_TEXTSIZE:
dsinclair3a7741a2016-10-11 10:39:49 -07003398 Field::SetTextSize(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003399 pData->num);
3400 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003401 case FP_USERNAME:
dsinclair3a7741a2016-10-11 10:39:49 -07003402 Field::SetUserName(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003403 pData->widestring);
3404 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003405 case FP_VALUE:
dsinclair3a7741a2016-10-11 10:39:49 -07003406 Field::SetValue(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003407 pData->widestringarray);
3408 break;
3409 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003410}
3411
dsinclair3a7741a2016-10-11 10:39:49 -07003412void Field::AddField(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003413 int nPageIndex,
3414 int nFieldType,
3415 const CFX_WideString& sName,
Tom Sepez281a9ea2016-02-26 14:24:28 -08003416 const CFX_FloatRect& rcCoords) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003417 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003418}