blob: 8979e7f8eccc6f4c7b9b297d8ef0a55c4226603c [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// Copyright 2014 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Dan Sinclairf766ad22016-03-14 13:51:24 -04007#include "fpdfsdk/javascript/Field.h"
Tom Sepez37458412015-10-06 11:33:46 -07008
Tom Sepezb9cc7a02016-02-01 13:42:30 -08009#include <algorithm>
10#include <memory>
Dan Sinclair3ebd1212016-03-09 09:59:23 -050011#include <string>
Tom Sepezb9cc7a02016-02-01 13:42:30 -080012#include <vector>
13
dsinclairbc5e6d22016-10-04 11:08:49 -070014#include "core/fpdfapi/font/cpdf_font.h"
dsinclair41872fa2016-10-04 11:29:35 -070015#include "core/fpdfapi/page/cpdf_page.h"
dsinclair488b7ad2016-10-04 11:55:50 -070016#include "core/fpdfapi/parser/cpdf_document.h"
dsinclair1727aee2016-09-29 13:12:56 -070017#include "core/fpdfdoc/cpdf_interform.h"
dsinclair735606d2016-10-05 15:47:02 -070018#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
dsinclair114e46a2016-09-29 17:18:21 -070019#include "fpdfsdk/cpdfsdk_interform.h"
20#include "fpdfsdk/cpdfsdk_pageview.h"
21#include "fpdfsdk/cpdfsdk_widget.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040022#include "fpdfsdk/javascript/Document.h"
23#include "fpdfsdk/javascript/Icon.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040024#include "fpdfsdk/javascript/JS_Define.h"
25#include "fpdfsdk/javascript/JS_EventHandler.h"
26#include "fpdfsdk/javascript/JS_Object.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040027#include "fpdfsdk/javascript/JS_Value.h"
28#include "fpdfsdk/javascript/PublicMethods.h"
Tom Sepezd6ae2af2017-02-16 11:49:55 -080029#include "fpdfsdk/javascript/cjs_event_context.h"
dsinclair64376be2016-03-31 20:03:24 -070030#include "fpdfsdk/javascript/cjs_runtime.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040031#include "fpdfsdk/javascript/color.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070032
tonikitoo7c05a7a2016-08-17 11:08:46 -070033namespace {
34
35bool SetWidgetDisplayStatus(CPDFSDK_Widget* pWidget, int value) {
36 if (!pWidget)
37 return false;
38
39 uint32_t dwFlag = pWidget->GetFlags();
40 switch (value) {
41 case 0:
42 dwFlag &= ~ANNOTFLAG_INVISIBLE;
43 dwFlag &= ~ANNOTFLAG_HIDDEN;
44 dwFlag &= ~ANNOTFLAG_NOVIEW;
45 dwFlag |= ANNOTFLAG_PRINT;
46 break;
47 case 1:
48 dwFlag &= ~ANNOTFLAG_INVISIBLE;
49 dwFlag &= ~ANNOTFLAG_NOVIEW;
50 dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
51 break;
52 case 2:
53 dwFlag &= ~ANNOTFLAG_INVISIBLE;
54 dwFlag &= ~ANNOTFLAG_PRINT;
55 dwFlag &= ~ANNOTFLAG_HIDDEN;
56 dwFlag &= ~ANNOTFLAG_NOVIEW;
57 break;
58 case 3:
59 dwFlag |= ANNOTFLAG_NOVIEW;
60 dwFlag |= ANNOTFLAG_PRINT;
61 dwFlag &= ~ANNOTFLAG_HIDDEN;
62 break;
63 }
64
65 if (dwFlag != pWidget->GetFlags()) {
66 pWidget->SetFlags(dwFlag);
67 return true;
68 }
69
70 return false;
71}
72
73} // namespace
74
Tom Sepez04557b82017-02-16 09:43:10 -080075JSConstSpec CJS_Field::ConstSpecs[] = {{0, JSConstSpec::Number, 0, 0}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070076
Tom Sepez04557b82017-02-16 09:43:10 -080077JSPropertySpec CJS_Field::PropertySpecs[] = {
Tom Sepez4d5b8c52017-02-21 15:17:07 -080078 {"alignment", get_alignment_static, set_alignment_static},
dan sinclaircbe23db2017-10-19 14:29:33 -040079 {"borderStyle", get_border_style_static, set_border_style_static},
80 {"buttonAlignX", get_button_align_x_static, set_button_align_x_static},
81 {"buttonAlignY", get_button_align_y_static, set_button_align_y_static},
82 {"buttonFitBounds", get_button_fit_bounds_static,
83 set_button_fit_bounds_static},
84 {"buttonPosition", get_button_position_static, set_button_position_static},
85 {"buttonScaleHow", get_button_scale_how_static,
86 set_button_scale_how_static},
87 {"buttonScaleWhen", get_button_scale_when_static,
88 set_button_scale_when_static},
89 {"calcOrderIndex", get_calc_order_index_static,
90 set_calc_order_index_static},
91 {"charLimit", get_char_limit_static, set_char_limit_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -080092 {"comb", get_comb_static, set_comb_static},
dan sinclaircbe23db2017-10-19 14:29:33 -040093 {"commitOnSelChange", get_commit_on_sel_change_static,
94 set_commit_on_sel_change_static},
95 {"currentValueIndices", get_current_value_indices_static,
96 set_current_value_indices_static},
97 {"defaultStyle", get_default_style_static, set_default_style_static},
98 {"defaultValue", get_default_value_static, set_default_value_static},
99 {"doNotScroll", get_do_not_scroll_static, set_do_not_scroll_static},
100 {"doNotSpellCheck", get_do_not_spell_check_static,
101 set_do_not_spell_check_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800102 {"delay", get_delay_static, set_delay_static},
103 {"display", get_display_static, set_display_static},
104 {"doc", get_doc_static, set_doc_static},
105 {"editable", get_editable_static, set_editable_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400106 {"exportValues", get_export_values_static, set_export_values_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800107 {"hidden", get_hidden_static, set_hidden_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400108 {"fileSelect", get_file_select_static, set_file_select_static},
109 {"fillColor", get_fill_color_static, set_fill_color_static},
110 {"lineWidth", get_line_width_static, set_line_width_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800111 {"highlight", get_highlight_static, set_highlight_static},
112 {"multiline", get_multiline_static, set_multiline_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400113 {"multipleSelection", get_multiple_selection_static,
114 set_multiple_selection_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800115 {"name", get_name_static, set_name_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400116 {"numItems", get_num_items_static, set_num_items_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800117 {"page", get_page_static, set_page_static},
118 {"password", get_password_static, set_password_static},
119 {"print", get_print_static, set_print_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400120 {"radiosInUnison", get_radios_in_unison_static,
121 set_radios_in_unison_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800122 {"readonly", get_readonly_static, set_readonly_static},
123 {"rect", get_rect_static, set_rect_static},
124 {"required", get_required_static, set_required_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400125 {"richText", get_rich_text_static, set_rich_text_static},
126 {"richValue", get_rich_value_static, set_rich_value_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800127 {"rotation", get_rotation_static, set_rotation_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400128 {"strokeColor", get_stroke_color_static, set_stroke_color_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800129 {"style", get_style_static, set_style_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400130 {"submitName", get_submit_name_static, set_submit_name_static},
131 {"textColor", get_text_color_static, set_text_color_static},
132 {"textFont", get_text_font_static, set_text_font_static},
133 {"textSize", get_text_size_static, set_text_size_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800134 {"type", get_type_static, set_type_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400135 {"userName", get_user_name_static, set_user_name_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800136 {"value", get_value_static, set_value_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400137 {"valueAsString", get_value_as_string_static, set_value_as_string_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800138 {"source", get_source_static, set_source_static},
Tom Sepez04557b82017-02-16 09:43:10 -0800139 {0, 0, 0}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700140
Tom Sepez04557b82017-02-16 09:43:10 -0800141JSMethodSpec CJS_Field::MethodSpecs[] = {
Tom Sepez9b99b632017-02-21 15:05:57 -0800142 {"browseForFileToSubmit", browseForFileToSubmit_static},
143 {"buttonGetCaption", buttonGetCaption_static},
144 {"buttonGetIcon", buttonGetIcon_static},
145 {"buttonImportIcon", buttonImportIcon_static},
146 {"buttonSetCaption", buttonSetCaption_static},
147 {"buttonSetIcon", buttonSetIcon_static},
148 {"checkThisBox", checkThisBox_static},
149 {"clearItems", clearItems_static},
150 {"defaultIsChecked", defaultIsChecked_static},
151 {"deleteItemAt", deleteItemAt_static},
152 {"getArray", getArray_static},
153 {"getItemAt", getItemAt_static},
154 {"getLock", getLock_static},
155 {"insertItemAt", insertItemAt_static},
156 {"isBoxChecked", isBoxChecked_static},
157 {"isDefaultChecked", isDefaultChecked_static},
158 {"setAction", setAction_static},
159 {"setFocus", setFocus_static},
160 {"setItems", setItems_static},
161 {"setLock", setLock_static},
162 {"signatureGetModifications", signatureGetModifications_static},
163 {"signatureGetSeedValue", signatureGetSeedValue_static},
164 {"signatureInfo", signatureInfo_static},
165 {"signatureSetSeedValue", signatureSetSeedValue_static},
166 {"signatureSign", signatureSign_static},
167 {"signatureValidate", signatureValidate_static},
Tom Sepez04557b82017-02-16 09:43:10 -0800168 {0, 0}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700169
Dan Sinclair4b172c42017-10-23 11:22:31 -0400170IMPLEMENT_JS_CLASS(CJS_Field, Field, Field)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700171
Ryan Harrison275e2602017-09-18 14:23:18 -0400172CJS_DelayData::CJS_DelayData(FIELD_PROP prop, int idx, const WideString& name)
weili625ad662016-06-15 11:21:33 -0700173 : eProp(prop), nControlIndex(idx), sFieldName(name) {}
174
175CJS_DelayData::~CJS_DelayData() {}
176
dan sinclaircbe23db2017-10-19 14:29:33 -0400177void CJS_Field::InitInstance(IJS_Runtime* pIRuntime) {}
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
Ryan Harrison275e2602017-09-18 14:23:18 -0400216bool Field::AttachField(Document* pDocument, const WideString& csFieldName) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700217 m_pJSDoc = pDocument;
dsinclair82e17672016-10-11 12:38:01 -0700218 m_pFormFillEnv.Reset(pDocument->GetFormFillEnv());
dsinclair7cbe68e2016-10-12 11:56:23 -0700219 m_bCanSet = m_pFormFillEnv->GetPermissions(FPDFPERM_FILL_FORM) ||
220 m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM) ||
221 m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700222
dsinclair7cbe68e2016-10-12 11:56:23 -0700223 CPDFSDK_InterForm* pRDInterForm = m_pFormFillEnv->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700224 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
Ryan Harrison275e2602017-09-18 14:23:18 -0400225 WideString swFieldNameTemp = csFieldName;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700226 swFieldNameTemp.Replace(L"..", L".");
227
228 if (pInterForm->CountFields(swFieldNameTemp) <= 0) {
229 std::wstring strFieldName;
230 int iControlNo = -1;
231 ParseFieldName(swFieldNameTemp.c_str(), strFieldName, iControlNo);
232 if (iControlNo == -1)
tsepez4cf55152016-11-02 14:37:54 -0700233 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700234
235 m_FieldName = strFieldName.c_str();
236 m_nFormControlIndex = iControlNo;
tsepez4cf55152016-11-02 14:37:54 -0700237 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700238 }
239
240 m_FieldName = swFieldNameTemp;
241 m_nFormControlIndex = -1;
242
tsepez4cf55152016-11-02 14:37:54 -0700243 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700244}
245
Lei Zhangd88a3642015-11-10 09:38:57 -0800246std::vector<CPDF_FormField*> Field::GetFormFields(
dsinclair3a7741a2016-10-11 10:39:49 -0700247 CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -0400248 const WideString& csFieldName) {
Lei Zhangd88a3642015-11-10 09:38:57 -0800249 std::vector<CPDF_FormField*> fields;
dsinclair7cbe68e2016-10-12 11:56:23 -0700250 CPDFSDK_InterForm* pReaderInterForm = pFormFillEnv->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700251 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -0800252 for (int i = 0, sz = pInterForm->CountFields(csFieldName); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700253 if (CPDF_FormField* pFormField = pInterForm->GetField(i, csFieldName))
Lei Zhangd88a3642015-11-10 09:38:57 -0800254 fields.push_back(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700255 }
Lei Zhangd88a3642015-11-10 09:38:57 -0800256 return fields;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700257}
258
Lei Zhangd88a3642015-11-10 09:38:57 -0800259std::vector<CPDF_FormField*> Field::GetFormFields(
Ryan Harrison275e2602017-09-18 14:23:18 -0400260 const WideString& csFieldName) const {
dsinclair3a7741a2016-10-11 10:39:49 -0700261 return Field::GetFormFields(m_pFormFillEnv.Get(), csFieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700262}
263
dsinclair3a7741a2016-10-11 10:39:49 -0700264void Field::UpdateFormField(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700265 CPDF_FormField* pFormField,
tsepez4cf55152016-11-02 14:37:54 -0700266 bool bChangeMark,
267 bool bResetAP,
268 bool bRefresh) {
dsinclair7cbe68e2016-10-12 11:56:23 -0700269 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700270
271 if (bResetAP) {
tsepez8fa82792017-01-11 09:32:33 -0800272 std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
dsinclair1df1efa2016-09-07 09:55:37 -0700273 pInterForm->GetWidgets(pFormField, &widgets);
274
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700275 int nFieldType = pFormField->GetFieldType();
276 if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_TEXTFIELD) {
tsepez8fa82792017-01-11 09:32:33 -0800277 for (auto& pObserved : widgets) {
tsepez1c620542016-09-12 09:47:52 -0700278 if (pObserved) {
tsepez8fa82792017-01-11 09:32:33 -0800279 bool bFormatted = false;
Ryan Harrison275e2602017-09-18 14:23:18 -0400280 WideString sValue = static_cast<CPDFSDK_Widget*>(pObserved.Get())
281 ->OnFormat(bFormatted);
tsepez8fa82792017-01-11 09:32:33 -0800282 if (pObserved) { // Not redundant, may be clobbered by OnFormat.
283 static_cast<CPDFSDK_Widget*>(pObserved.Get())
284 ->ResetAppearance(bFormatted ? &sValue : nullptr, false);
285 }
tsepezca97a8e2016-08-01 10:10:36 -0700286 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700287 }
288 } else {
tsepez8fa82792017-01-11 09:32:33 -0800289 for (auto& pObserved : widgets) {
290 if (pObserved) {
291 static_cast<CPDFSDK_Widget*>(pObserved.Get())
292 ->ResetAppearance(nullptr, false);
293 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700294 }
295 }
296 }
297
298 if (bRefresh) {
dsinclair1df1efa2016-09-07 09:55:37 -0700299 // Refresh the widget list. The calls in |bResetAP| may have caused widgets
300 // to be removed from the list. We need to call |GetWidgets| again to be
301 // sure none of the widgets have been deleted.
tsepez8fa82792017-01-11 09:32:33 -0800302 std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
dsinclair1df1efa2016-09-07 09:55:37 -0700303 pInterForm->GetWidgets(pFormField, &widgets);
304
dsinclair690c0332016-10-11 09:13:01 -0700305 // TODO(dsinclair): Determine if all widgets share the same
306 // CPDFSDK_InterForm. If that's the case, we can move the code to
dsinclair7cbe68e2016-10-12 11:56:23 -0700307 // |GetFormFillEnv| out of the loop.
tsepez8fa82792017-01-11 09:32:33 -0800308 for (auto& pObserved : widgets) {
309 if (pObserved) {
310 CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pObserved.Get());
311 pWidget->GetInterForm()->GetFormFillEnv()->UpdateAllViews(nullptr,
312 pWidget);
313 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700314 }
315 }
316
317 if (bChangeMark)
dsinclair7cbe68e2016-10-12 11:56:23 -0700318 pFormFillEnv->SetChangeMark();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700319}
320
dsinclair3a7741a2016-10-11 10:39:49 -0700321void Field::UpdateFormControl(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700322 CPDF_FormControl* pFormControl,
tsepez4cf55152016-11-02 14:37:54 -0700323 bool bChangeMark,
324 bool bResetAP,
325 bool bRefresh) {
Lei Zhang96660d62015-12-14 18:27:25 -0800326 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700327
dsinclair7cbe68e2016-10-12 11:56:23 -0700328 CPDFSDK_InterForm* pForm = pFormFillEnv->GetInterForm();
dsinclairc5267c52016-11-04 15:35:12 -0700329 CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700330
331 if (pWidget) {
Ryan Harrison569817c2017-10-05 14:14:03 -0400332 CPDFSDK_Widget::ObservedPtr observed_widget(pWidget);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700333 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;
Ryan Harrison275e2602017-09-18 14:23:18 -0400338 WideString sValue = pWidget->OnFormat(bFormatted);
Ryan Harrison569817c2017-10-05 14:14:03 -0400339 if (!observed_widget)
340 return;
tsepez4cf55152016-11-02 14:37:54 -0700341 pWidget->ResetAppearance(bFormatted ? &sValue : nullptr, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700342 } else {
tsepez4cf55152016-11-02 14:37:54 -0700343 pWidget->ResetAppearance(nullptr, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700344 }
Ryan Harrison569817c2017-10-05 14:14:03 -0400345 if (!observed_widget)
346 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700347 }
348
349 if (bRefresh) {
350 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
dsinclair7cbe68e2016-10-12 11:56:23 -0700351 pInterForm->GetFormFillEnv()->UpdateAllViews(nullptr, pWidget);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700352 }
353 }
354
355 if (bChangeMark)
dsinclair7cbe68e2016-10-12 11:56:23 -0700356 pFormFillEnv->SetChangeMark();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700357}
358
dsinclair3a7741a2016-10-11 10:39:49 -0700359CPDFSDK_Widget* Field::GetWidget(CPDFSDK_FormFillEnvironment* pFormFillEnv,
dsinclairc5267c52016-11-04 15:35:12 -0700360 CPDF_FormControl* pFormControl) {
dsinclair7cbe68e2016-10-12 11:56:23 -0700361 CPDFSDK_InterForm* pInterForm =
362 static_cast<CPDFSDK_InterForm*>(pFormFillEnv->GetInterForm());
dsinclairc5267c52016-11-04 15:35:12 -0700363 return pInterForm ? pInterForm->GetWidget(pFormControl) : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700364}
365
Ryan Harrison275e2602017-09-18 14:23:18 -0400366bool Field::ValueIsOccur(CPDF_FormField* pFormField, WideString csOptLabel) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700367 for (int i = 0, sz = pFormField->CountOptions(); i < sz; i++) {
368 if (csOptLabel.Compare(pFormField->GetOptionLabel(i)) == 0)
tsepez4cf55152016-11-02 14:37:54 -0700369 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700370 }
371
tsepez4cf55152016-11-02 14:37:54 -0700372 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700373}
374
375CPDF_FormControl* Field::GetSmartFieldControl(CPDF_FormField* pFormField) {
376 if (!pFormField->CountControls() ||
377 m_nFormControlIndex >= pFormField->CountControls())
thestig1cd352e2016-06-07 17:53:06 -0700378 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700379 if (m_nFormControlIndex < 0)
380 return pFormField->GetControl(0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700381 return pFormField->GetControl(m_nFormControlIndex);
382}
383
dan sinclaircbe23db2017-10-19 14:29:33 -0400384bool Field::get_alignment(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400385 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400386 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700387 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700388
dan sinclair646634b2017-10-19 14:30:28 -0400389 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
390 if (FieldArray.empty())
391 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700392
dan sinclair646634b2017-10-19 14:30:28 -0400393 CPDF_FormField* pFormField = FieldArray[0];
394 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
395 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700396
dan sinclair646634b2017-10-19 14:30:28 -0400397 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
398 if (!pFormControl)
399 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700400
dan sinclair646634b2017-10-19 14:30:28 -0400401 switch (pFormControl->GetControlAlignment()) {
402 case 1:
Dan Sinclaire4974922017-10-24 09:36:16 -0400403 vp->Set(pRuntime->NewString(L"center"));
dan sinclair646634b2017-10-19 14:30:28 -0400404 break;
405 case 0:
Dan Sinclaire4974922017-10-24 09:36:16 -0400406 vp->Set(pRuntime->NewString(L"left"));
dan sinclair646634b2017-10-19 14:30:28 -0400407 break;
408 case 2:
Dan Sinclaire4974922017-10-24 09:36:16 -0400409 vp->Set(pRuntime->NewString(L"right"));
dan sinclair646634b2017-10-19 14:30:28 -0400410 break;
411 default:
Dan Sinclaire4974922017-10-24 09:36:16 -0400412 vp->Set(pRuntime->NewString(L""));
dan sinclair646634b2017-10-19 14:30:28 -0400413 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700414
tsepez4cf55152016-11-02 14:37:54 -0700415 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700416}
417
dan sinclaircbe23db2017-10-19 14:29:33 -0400418bool Field::set_alignment(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400419 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400420 WideString* sError) {
421 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400422 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700423}
424
dan sinclaircbe23db2017-10-19 14:29:33 -0400425bool Field::get_border_style(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400426 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400427 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700428 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700429
dan sinclaircbe23db2017-10-19 14:29:33 -0400430 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
431 if (FieldArray.empty())
432 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700433
dan sinclaircbe23db2017-10-19 14:29:33 -0400434 CPDF_FormField* pFormField = FieldArray[0];
435 if (!pFormField)
436 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700437
dan sinclaircbe23db2017-10-19 14:29:33 -0400438 CPDFSDK_Widget* pWidget =
439 GetWidget(m_pFormFillEnv.Get(), GetSmartFieldControl(pFormField));
440 if (!pWidget)
441 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700442
dan sinclaircbe23db2017-10-19 14:29:33 -0400443 switch (pWidget->GetBorderStyle()) {
444 case BorderStyle::SOLID:
Dan Sinclaire4974922017-10-24 09:36:16 -0400445 vp->Set(pRuntime->NewString(L"solid"));
dan sinclaircbe23db2017-10-19 14:29:33 -0400446 break;
447 case BorderStyle::DASH:
Dan Sinclaire4974922017-10-24 09:36:16 -0400448 vp->Set(pRuntime->NewString(L"dashed"));
dan sinclaircbe23db2017-10-19 14:29:33 -0400449 break;
450 case BorderStyle::BEVELED:
Dan Sinclaire4974922017-10-24 09:36:16 -0400451 vp->Set(pRuntime->NewString(L"beveled"));
dan sinclaircbe23db2017-10-19 14:29:33 -0400452 break;
453 case BorderStyle::INSET:
Dan Sinclaire4974922017-10-24 09:36:16 -0400454 vp->Set(pRuntime->NewString(L"inset"));
dan sinclaircbe23db2017-10-19 14:29:33 -0400455 break;
456 case BorderStyle::UNDERLINE:
Dan Sinclaire4974922017-10-24 09:36:16 -0400457 vp->Set(pRuntime->NewString(L"underline"));
dan sinclaircbe23db2017-10-19 14:29:33 -0400458 break;
459 default:
Dan Sinclaire4974922017-10-24 09:36:16 -0400460 vp->Set(pRuntime->NewString(L""));
dan sinclaircbe23db2017-10-19 14:29:33 -0400461 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700462 }
dan sinclaircbe23db2017-10-19 14:29:33 -0400463 return true;
464}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700465
dan sinclaircbe23db2017-10-19 14:29:33 -0400466bool Field::set_border_style(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400467 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400468 WideString* sError) {
469 ASSERT(m_pFormFillEnv);
470
471 if (!m_bCanSet)
472 return false;
473
474 if (m_bDelay) {
Dan Sinclair33d13f22017-10-23 09:44:30 -0400475 AddDelay_String(FP_BORDERSTYLE, vp.ToByteString(pRuntime));
dan sinclaircbe23db2017-10-19 14:29:33 -0400476 } else {
477 Field::SetBorderStyle(m_pFormFillEnv.Get(), m_FieldName,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400478 m_nFormControlIndex, vp.ToByteString(pRuntime));
dan sinclaircbe23db2017-10-19 14:29:33 -0400479 }
tsepez4cf55152016-11-02 14:37:54 -0700480 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700481}
482
dsinclair3a7741a2016-10-11 10:39:49 -0700483void Field::SetBorderStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -0400484 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700485 int nControlIndex,
Ryan Harrison275e2602017-09-18 14:23:18 -0400486 const ByteString& string) {
dsinclair3a7741a2016-10-11 10:39:49 -0700487 ASSERT(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700488
dsinclair92cb5e52016-05-16 11:38:28 -0700489 BorderStyle nBorderStyle = BorderStyle::SOLID;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700490 if (string == "solid")
dsinclair92cb5e52016-05-16 11:38:28 -0700491 nBorderStyle = BorderStyle::SOLID;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700492 else if (string == "beveled")
dsinclair92cb5e52016-05-16 11:38:28 -0700493 nBorderStyle = BorderStyle::BEVELED;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700494 else if (string == "dashed")
dsinclair92cb5e52016-05-16 11:38:28 -0700495 nBorderStyle = BorderStyle::DASH;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700496 else if (string == "inset")
dsinclair92cb5e52016-05-16 11:38:28 -0700497 nBorderStyle = BorderStyle::INSET;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700498 else if (string == "underline")
dsinclair92cb5e52016-05-16 11:38:28 -0700499 nBorderStyle = BorderStyle::UNDERLINE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700500 else
501 return;
502
Lei Zhangd88a3642015-11-10 09:38:57 -0800503 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -0700504 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -0800505 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700506 if (nControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -0700507 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -0800508 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700509 if (CPDFSDK_Widget* pWidget =
dsinclairc5267c52016-11-04 15:35:12 -0700510 GetWidget(pFormFillEnv, pFormField->GetControl(i))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700511 if (pWidget->GetBorderStyle() != nBorderStyle) {
512 pWidget->SetBorderStyle(nBorderStyle);
tsepez4cf55152016-11-02 14:37:54 -0700513 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700514 }
515 }
516 }
517 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -0700518 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700519 } else {
520 if (nControlIndex >= pFormField->CountControls())
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700521 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700522 if (CPDF_FormControl* pFormControl =
523 pFormField->GetControl(nControlIndex)) {
dsinclairc5267c52016-11-04 15:35:12 -0700524 if (CPDFSDK_Widget* pWidget = GetWidget(pFormFillEnv, pFormControl)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700525 if (pWidget->GetBorderStyle() != nBorderStyle) {
526 pWidget->SetBorderStyle(nBorderStyle);
tsepez4cf55152016-11-02 14:37:54 -0700527 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700528 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700529 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700530 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700531 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700532 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700533}
534
dan sinclaircbe23db2017-10-19 14:29:33 -0400535bool Field::get_button_align_x(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400536 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400537 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700538 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700539
dan sinclaircbe23db2017-10-19 14:29:33 -0400540 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
541 if (FieldArray.empty())
542 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700543
dan sinclaircbe23db2017-10-19 14:29:33 -0400544 CPDF_FormField* pFormField = FieldArray[0];
545 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
546 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700547
dan sinclaircbe23db2017-10-19 14:29:33 -0400548 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
549 if (!pFormControl)
550 return false;
551
552 CPDF_IconFit IconFit = pFormControl->GetIconFit();
553
554 float fLeft;
555 float fBottom;
556 IconFit.GetIconPosition(fLeft, fBottom);
557
Dan Sinclaire4974922017-10-24 09:36:16 -0400558 vp->Set(pRuntime->NewNumber(static_cast<int32_t>(fLeft)));
dan sinclaircbe23db2017-10-19 14:29:33 -0400559 return true;
560}
561
562bool Field::set_button_align_x(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400563 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400564 WideString* sError) {
565 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400566 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700567}
568
dan sinclaircbe23db2017-10-19 14:29:33 -0400569bool Field::get_button_align_y(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400570 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400571 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700572 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700573
dan sinclaircbe23db2017-10-19 14:29:33 -0400574 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
575 if (FieldArray.empty())
576 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700577
dan sinclaircbe23db2017-10-19 14:29:33 -0400578 CPDF_FormField* pFormField = FieldArray[0];
579 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
580 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700581
dan sinclaircbe23db2017-10-19 14:29:33 -0400582 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
583 if (!pFormControl)
584 return false;
585
586 CPDF_IconFit IconFit = pFormControl->GetIconFit();
587
588 float fLeft;
589 float fBottom;
590 IconFit.GetIconPosition(fLeft, fBottom);
591
Dan Sinclaire4974922017-10-24 09:36:16 -0400592 vp->Set(pRuntime->NewNumber(static_cast<int32_t>(fBottom)));
dan sinclaircbe23db2017-10-19 14:29:33 -0400593 return true;
594}
595
596bool Field::set_button_align_y(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400597 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400598 WideString* sError) {
599 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400600 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700601}
602
dan sinclaircbe23db2017-10-19 14:29:33 -0400603bool Field::get_button_fit_bounds(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400604 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400605 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700606 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700607
dan sinclair646634b2017-10-19 14:30:28 -0400608 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
609 if (FieldArray.empty())
610 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700611
dan sinclair646634b2017-10-19 14:30:28 -0400612 CPDF_FormField* pFormField = FieldArray[0];
613 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
614 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700615
dan sinclair646634b2017-10-19 14:30:28 -0400616 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
617 if (!pFormControl)
618 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700619
Dan Sinclaire4974922017-10-24 09:36:16 -0400620 vp->Set(pRuntime->NewBoolean(pFormControl->GetIconFit().GetFittingBounds()));
dan sinclair646634b2017-10-19 14:30:28 -0400621 return true;
dan sinclaircbe23db2017-10-19 14:29:33 -0400622}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700623
dan sinclaircbe23db2017-10-19 14:29:33 -0400624bool Field::set_button_fit_bounds(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400625 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400626 WideString* sError) {
627 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400628 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700629}
630
dan sinclaircbe23db2017-10-19 14:29:33 -0400631bool Field::get_button_position(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400632 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400633 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700634 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700635
dan sinclair646634b2017-10-19 14:30:28 -0400636 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
637 if (FieldArray.empty())
638 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700639
dan sinclair646634b2017-10-19 14:30:28 -0400640 CPDF_FormField* pFormField = FieldArray[0];
641 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
642 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700643
dan sinclair646634b2017-10-19 14:30:28 -0400644 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
645 if (!pFormControl)
646 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700647
Dan Sinclaire4974922017-10-24 09:36:16 -0400648 vp->Set(pRuntime->NewNumber(pFormControl->GetTextPosition()));
dan sinclair646634b2017-10-19 14:30:28 -0400649 return true;
dan sinclaircbe23db2017-10-19 14:29:33 -0400650}
651
652bool Field::set_button_position(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400653 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400654 WideString* sError) {
655 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400656 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700657}
658
dan sinclaircbe23db2017-10-19 14:29:33 -0400659bool Field::get_button_scale_how(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400660 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400661 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700662 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700663
dan sinclair646634b2017-10-19 14:30:28 -0400664 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
665 if (FieldArray.empty())
666 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700667
dan sinclair646634b2017-10-19 14:30:28 -0400668 CPDF_FormField* pFormField = FieldArray[0];
669 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
670 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700671
dan sinclair646634b2017-10-19 14:30:28 -0400672 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
673 if (!pFormControl)
674 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700675
Dan Sinclaire4974922017-10-24 09:36:16 -0400676 vp->Set(pRuntime->NewBoolean(
677 pFormControl->GetIconFit().IsProportionalScale() ? 0 : 1));
dan sinclair646634b2017-10-19 14:30:28 -0400678 return true;
dan sinclaircbe23db2017-10-19 14:29:33 -0400679}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700680
dan sinclaircbe23db2017-10-19 14:29:33 -0400681bool Field::set_button_scale_how(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400682 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400683 WideString* sError) {
684 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400685 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700686}
687
dan sinclaircbe23db2017-10-19 14:29:33 -0400688bool Field::get_button_scale_when(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400689 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400690 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700691 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700692
dan sinclair646634b2017-10-19 14:30:28 -0400693 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
694 if (FieldArray.empty())
695 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700696
dan sinclair646634b2017-10-19 14:30:28 -0400697 CPDF_FormField* pFormField = FieldArray[0];
698 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
699 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700700
dan sinclair646634b2017-10-19 14:30:28 -0400701 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
702 if (!pFormControl)
703 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700704
dan sinclair646634b2017-10-19 14:30:28 -0400705 CPDF_IconFit IconFit = pFormControl->GetIconFit();
706 int ScaleM = IconFit.GetScaleMethod();
707 switch (ScaleM) {
708 case CPDF_IconFit::Always:
Dan Sinclaire4974922017-10-24 09:36:16 -0400709 vp->Set(pRuntime->NewNumber(static_cast<int32_t>(CPDF_IconFit::Always)));
dan sinclair646634b2017-10-19 14:30:28 -0400710 break;
711 case CPDF_IconFit::Bigger:
Dan Sinclaire4974922017-10-24 09:36:16 -0400712 vp->Set(pRuntime->NewNumber(static_cast<int32_t>(CPDF_IconFit::Bigger)));
dan sinclair646634b2017-10-19 14:30:28 -0400713 break;
714 case CPDF_IconFit::Never:
Dan Sinclaire4974922017-10-24 09:36:16 -0400715 vp->Set(pRuntime->NewNumber(static_cast<int32_t>(CPDF_IconFit::Never)));
dan sinclair646634b2017-10-19 14:30:28 -0400716 break;
717 case CPDF_IconFit::Smaller:
Dan Sinclaire4974922017-10-24 09:36:16 -0400718 vp->Set(pRuntime->NewNumber(static_cast<int32_t>(CPDF_IconFit::Smaller)));
dan sinclair646634b2017-10-19 14:30:28 -0400719 break;
720 }
721 return true;
dan sinclaircbe23db2017-10-19 14:29:33 -0400722}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700723
dan sinclaircbe23db2017-10-19 14:29:33 -0400724bool Field::set_button_scale_when(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400725 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400726 WideString* sError) {
727 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400728 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700729}
730
dan sinclaircbe23db2017-10-19 14:29:33 -0400731bool Field::get_calc_order_index(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400732 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400733 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700734 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700735
dan sinclair646634b2017-10-19 14:30:28 -0400736 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
737 if (FieldArray.empty())
738 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700739
dan sinclair646634b2017-10-19 14:30:28 -0400740 CPDF_FormField* pFormField = FieldArray[0];
741 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
742 pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) {
743 return false;
744 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700745
dan sinclair646634b2017-10-19 14:30:28 -0400746 CPDFSDK_InterForm* pRDInterForm = m_pFormFillEnv->GetInterForm();
747 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
Dan Sinclaire4974922017-10-24 09:36:16 -0400748 vp->Set(pRuntime->NewNumber(static_cast<int32_t>(
749 pInterForm->FindFieldInCalculationOrder(pFormField))));
dan sinclair646634b2017-10-19 14:30:28 -0400750 return true;
dan sinclaircbe23db2017-10-19 14:29:33 -0400751}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700752
dan sinclaircbe23db2017-10-19 14:29:33 -0400753bool Field::set_calc_order_index(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400754 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400755 WideString* sError) {
756 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400757 return m_bCanSet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700758}
759
dan sinclaircbe23db2017-10-19 14:29:33 -0400760bool Field::get_char_limit(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400761 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400762 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700763 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700764
dan sinclaircbe23db2017-10-19 14:29:33 -0400765 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
766 if (FieldArray.empty())
767 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700768
dan sinclaircbe23db2017-10-19 14:29:33 -0400769 CPDF_FormField* pFormField = FieldArray[0];
770 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
771 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700772
Dan Sinclaire4974922017-10-24 09:36:16 -0400773 vp->Set(pRuntime->NewNumber(static_cast<int32_t>(pFormField->GetMaxLen())));
dan sinclaircbe23db2017-10-19 14:29:33 -0400774 return true;
775}
776
777bool Field::set_char_limit(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400778 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400779 WideString* sError) {
780 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400781 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700782}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700783
Dan Sinclair33d13f22017-10-23 09:44:30 -0400784bool Field::get_comb(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700785 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700786
dan sinclaircbe23db2017-10-19 14:29:33 -0400787 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
788 if (FieldArray.empty())
789 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700790
dan sinclaircbe23db2017-10-19 14:29:33 -0400791 CPDF_FormField* pFormField = FieldArray[0];
792 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
793 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700794
Dan Sinclaire4974922017-10-24 09:36:16 -0400795 vp->Set(
796 pRuntime->NewBoolean(!!(pFormField->GetFieldFlags() & FIELDFLAG_COMB)));
dan sinclaircbe23db2017-10-19 14:29:33 -0400797 return true;
798}
799
800bool Field::set_comb(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400801 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400802 WideString* sError) {
803 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400804 return m_bCanSet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700805}
806
dan sinclaircbe23db2017-10-19 14:29:33 -0400807bool Field::get_commit_on_sel_change(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400808 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400809 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700810 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700811
dan sinclair646634b2017-10-19 14:30:28 -0400812 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
813 if (FieldArray.empty())
814 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700815
dan sinclair646634b2017-10-19 14:30:28 -0400816 CPDF_FormField* pFormField = FieldArray[0];
817 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
818 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
819 return false;
820 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700821
Dan Sinclaire4974922017-10-24 09:36:16 -0400822 vp->Set(pRuntime->NewBoolean(
823 !!(pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE)));
dan sinclair646634b2017-10-19 14:30:28 -0400824 return true;
dan sinclaircbe23db2017-10-19 14:29:33 -0400825}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700826
dan sinclaircbe23db2017-10-19 14:29:33 -0400827bool Field::set_commit_on_sel_change(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400828 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400829 WideString* sError) {
830 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400831 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700832}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700833
dan sinclaircbe23db2017-10-19 14:29:33 -0400834bool Field::get_current_value_indices(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400835 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400836 WideString* sError) {
837 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
838 if (FieldArray.empty())
839 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700840
dan sinclaircbe23db2017-10-19 14:29:33 -0400841 CPDF_FormField* pFormField = FieldArray[0];
842 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
843 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
844 return false;
845 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700846
dan sinclaircbe23db2017-10-19 14:29:33 -0400847 int count = pFormField->CountSelectedItems();
848 if (count <= 0) {
Dan Sinclaire4974922017-10-24 09:36:16 -0400849 vp->Set(pRuntime->NewNumber(-1));
dan sinclaircbe23db2017-10-19 14:29:33 -0400850 return true;
851 }
852 if (count == 1) {
Dan Sinclaire4974922017-10-24 09:36:16 -0400853 vp->Set(pRuntime->NewNumber(pFormField->GetSelectedIndex(0)));
dan sinclaircbe23db2017-10-19 14:29:33 -0400854 return true;
855 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700856
dan sinclaircbe23db2017-10-19 14:29:33 -0400857 CJS_Array SelArray;
858 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -0400859 SelArray.SetElement(
860 pRuntime, i,
861 CJS_Value(pRuntime->NewNumber(pFormField->GetSelectedIndex(i))));
dan sinclaircbe23db2017-10-19 14:29:33 -0400862 }
Dan Sinclaire4974922017-10-24 09:36:16 -0400863 vp->Set(SelArray.ToV8Array(pRuntime));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700864
dan sinclaircbe23db2017-10-19 14:29:33 -0400865 return true;
866}
867
868bool Field::set_current_value_indices(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400869 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400870 WideString* sError) {
871 if (!m_bCanSet)
872 return false;
873
874 std::vector<uint32_t> array;
Dan Sinclair33d13f22017-10-23 09:44:30 -0400875 if (vp.GetType() == CJS_Value::VT_number) {
876 array.push_back(vp.ToInt(pRuntime));
877 } else if (vp.IsArrayObject()) {
878 CJS_Array SelArray = vp.ToArray(pRuntime);
Dan Sinclairc9708952017-10-23 09:40:59 -0400879 for (int i = 0, sz = SelArray.GetLength(pRuntime); i < sz; i++)
880 array.push_back(SelArray.GetElement(pRuntime, i).ToInt(pRuntime));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700881 }
882
dan sinclaircbe23db2017-10-19 14:29:33 -0400883 if (m_bDelay) {
884 AddDelay_WordArray(FP_CURRENTVALUEINDICES, array);
885 } else {
886 Field::SetCurrentValueIndices(m_pFormFillEnv.Get(), m_FieldName,
887 m_nFormControlIndex, array);
888 }
tsepez4cf55152016-11-02 14:37:54 -0700889 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700890}
891
dsinclair3a7741a2016-10-11 10:39:49 -0700892void Field::SetCurrentValueIndices(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -0400893 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700894 int nControlIndex,
tsepez41a53ad2016-03-28 16:59:30 -0700895 const std::vector<uint32_t>& array) {
dsinclair3a7741a2016-10-11 10:39:49 -0700896 ASSERT(pFormFillEnv);
Lei Zhangd88a3642015-11-10 09:38:57 -0800897 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -0700898 GetFormFields(pFormFillEnv, swFieldName);
tsepez41a53ad2016-03-28 16:59:30 -0700899
Lei Zhangd88a3642015-11-10 09:38:57 -0800900 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700901 int nFieldType = pFormField->GetFieldType();
902 if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX) {
tsepezc3255f52016-03-25 14:52:27 -0700903 uint32_t dwFieldFlags = pFormField->GetFieldFlags();
tsepez4cf55152016-11-02 14:37:54 -0700904 pFormField->ClearSelection(true);
tsepez41a53ad2016-03-28 16:59:30 -0700905 for (size_t i = 0; i < array.size(); ++i) {
906 if (i != 0 && !(dwFieldFlags & (1 << 21)))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700907 break;
Wei Li05d53f02016-03-29 16:42:53 -0700908 if (array[i] < static_cast<uint32_t>(pFormField->CountOptions()) &&
tsepez41a53ad2016-03-28 16:59:30 -0700909 !pFormField->IsItemSelected(array[i])) {
tsepez4cf55152016-11-02 14:37:54 -0700910 pFormField->SetItemSelection(array[i], true);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700911 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700912 }
tsepez4cf55152016-11-02 14:37:54 -0700913 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700914 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700915 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700916}
917
dan sinclaircbe23db2017-10-19 14:29:33 -0400918bool Field::get_default_style(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400919 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400920 WideString* sError) {
921 return false;
922}
923
924bool Field::set_default_style(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400925 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400926 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -0700927 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700928}
929
dan sinclaircbe23db2017-10-19 14:29:33 -0400930bool Field::get_default_value(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400931 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400932 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700933 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700934
Lei Zhangd88a3642015-11-10 09:38:57 -0800935 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
936 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700937 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700938
Lei Zhangd88a3642015-11-10 09:38:57 -0800939 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700940 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON ||
Lei Zhangd88a3642015-11-10 09:38:57 -0800941 pFormField->GetFieldType() == FIELDTYPE_SIGNATURE) {
tsepez4cf55152016-11-02 14:37:54 -0700942 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -0800943 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700944
Dan Sinclaire4974922017-10-24 09:36:16 -0400945 vp->Set(pRuntime->NewString(pFormField->GetDefaultValue().c_str()));
dan sinclaircbe23db2017-10-19 14:29:33 -0400946 return true;
947}
948
949bool Field::set_default_value(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400950 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400951 WideString* sError) {
952 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400953 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700954}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700955
dan sinclaircbe23db2017-10-19 14:29:33 -0400956bool Field::get_do_not_scroll(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400957 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400958 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700959 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700960
dan sinclaircbe23db2017-10-19 14:29:33 -0400961 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
962 if (FieldArray.empty())
963 return false;
964
965 CPDF_FormField* pFormField = FieldArray[0];
966 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
967 return false;
968
Dan Sinclaire4974922017-10-24 09:36:16 -0400969 vp->Set(pRuntime->NewBoolean(
970 !!(pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL)));
dan sinclaircbe23db2017-10-19 14:29:33 -0400971 return true;
972}
973
974bool Field::set_do_not_scroll(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400975 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400976 WideString* sError) {
977 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400978 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700979}
980
dan sinclaircbe23db2017-10-19 14:29:33 -0400981bool Field::get_do_not_spell_check(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400982 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400983 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700984 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700985
dan sinclair646634b2017-10-19 14:30:28 -0400986 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
987 if (FieldArray.empty())
988 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700989
dan sinclair646634b2017-10-19 14:30:28 -0400990 CPDF_FormField* pFormField = FieldArray[0];
991 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD &&
992 pFormField->GetFieldType() != FIELDTYPE_COMBOBOX) {
993 return false;
994 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700995
Dan Sinclaire4974922017-10-24 09:36:16 -0400996 vp->Set(pRuntime->NewBoolean(
997 !!(pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK)));
dan sinclair646634b2017-10-19 14:30:28 -0400998 return true;
dan sinclaircbe23db2017-10-19 14:29:33 -0400999}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001000
dan sinclaircbe23db2017-10-19 14:29:33 -04001001bool Field::set_do_not_spell_check(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001002 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001003 WideString* sError) {
1004 ASSERT(m_pFormFillEnv);
1005 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001006}
1007
tsepez4cf55152016-11-02 14:37:54 -07001008void Field::SetDelay(bool bDelay) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001009 m_bDelay = bDelay;
1010
dan sinclaircbe23db2017-10-19 14:29:33 -04001011 if (m_bDelay)
1012 return;
dan sinclaircbe23db2017-10-19 14:29:33 -04001013 if (m_pJSDoc)
1014 m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001015}
1016
dan sinclaircbe23db2017-10-19 14:29:33 -04001017bool Field::get_delay(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001018 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001019 WideString* sError) {
Dan Sinclaire4974922017-10-24 09:36:16 -04001020 vp->Set(pRuntime->NewBoolean(m_bDelay));
tsepez4cf55152016-11-02 14:37:54 -07001021 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001022}
1023
dan sinclaircbe23db2017-10-19 14:29:33 -04001024bool Field::set_delay(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001025 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001026 WideString* sError) {
1027 if (!m_bCanSet)
1028 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001029
Dan Sinclair33d13f22017-10-23 09:44:30 -04001030 SetDelay(vp.ToBool(pRuntime));
dan sinclaircbe23db2017-10-19 14:29:33 -04001031 return true;
1032}
1033
1034bool Field::get_display(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001035 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001036 WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001037 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1038 if (FieldArray.empty())
1039 return false;
1040
1041 CPDF_FormField* pFormField = FieldArray[0];
1042 ASSERT(pFormField);
dan sinclaircbe23db2017-10-19 14:29:33 -04001043
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001044 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1045 CPDFSDK_Widget* pWidget =
1046 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1047 if (!pWidget)
1048 return false;
1049
1050 uint32_t dwFlag = pWidget->GetFlags();
1051 if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag) {
Dan Sinclaire4974922017-10-24 09:36:16 -04001052 vp->Set(pRuntime->NewNumber(1));
dan sinclaircbe23db2017-10-19 14:29:33 -04001053 return true;
1054 }
1055 if (ANNOTFLAG_PRINT & dwFlag) {
1056 if (ANNOTFLAG_NOVIEW & dwFlag)
Dan Sinclaire4974922017-10-24 09:36:16 -04001057 vp->Set(pRuntime->NewNumber(3));
dan sinclaircbe23db2017-10-19 14:29:33 -04001058 else
Dan Sinclaire4974922017-10-24 09:36:16 -04001059 vp->Set(pRuntime->NewNumber(0));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001060 } else {
Dan Sinclaire4974922017-10-24 09:36:16 -04001061 vp->Set(pRuntime->NewNumber(2));
dan sinclaircbe23db2017-10-19 14:29:33 -04001062 }
1063 return true;
1064}
1065
1066bool Field::set_display(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001067 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001068 WideString* sError) {
1069 if (!m_bCanSet)
1070 return false;
1071
1072 if (m_bDelay) {
Dan Sinclair33d13f22017-10-23 09:44:30 -04001073 AddDelay_Int(FP_DISPLAY, vp.ToInt(pRuntime));
dan sinclaircbe23db2017-10-19 14:29:33 -04001074 } else {
1075 Field::SetDisplay(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001076 vp.ToInt(pRuntime));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001077 }
tsepez4cf55152016-11-02 14:37:54 -07001078 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001079}
1080
dsinclair3a7741a2016-10-11 10:39:49 -07001081void Field::SetDisplay(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04001082 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001083 int nControlIndex,
1084 int number) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001085 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001086 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07001087 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -08001088 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001089 if (nControlIndex < 0) {
tonikitoo7c05a7a2016-08-17 11:08:46 -07001090 bool bAnySet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001091 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1092 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08001093 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001094
dsinclairc5267c52016-11-04 15:35:12 -07001095 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
tonikitoo7c05a7a2016-08-17 11:08:46 -07001096 if (SetWidgetDisplayStatus(pWidget, number))
1097 bAnySet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001098 }
1099
tonikitoo7c05a7a2016-08-17 11:08:46 -07001100 if (bAnySet)
tsepez4cf55152016-11-02 14:37:54 -07001101 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001102 } else {
1103 if (nControlIndex >= pFormField->CountControls())
1104 return;
tonikitoo7c05a7a2016-08-17 11:08:46 -07001105
1106 CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex);
1107 if (!pFormControl)
1108 return;
1109
dsinclairc5267c52016-11-04 15:35:12 -07001110 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
tonikitoo7c05a7a2016-08-17 11:08:46 -07001111 if (SetWidgetDisplayStatus(pWidget, number))
tsepez4cf55152016-11-02 14:37:54 -07001112 UpdateFormControl(pFormFillEnv, pFormControl, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001113 }
1114 }
1115}
1116
Dan Sinclair33d13f22017-10-23 09:44:30 -04001117bool Field::get_doc(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError) {
Dan Sinclaire4974922017-10-24 09:36:16 -04001118 vp->Set(m_pJSDoc->GetCJSDoc()->ToV8Object());
tsepez4cf55152016-11-02 14:37:54 -07001119 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001120}
1121
dan sinclaircbe23db2017-10-19 14:29:33 -04001122bool Field::set_doc(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001123 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001124 WideString* sError) {
1125 return false;
1126}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001127
dan sinclaircbe23db2017-10-19 14:29:33 -04001128bool Field::get_editable(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001129 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001130 WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001131 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1132 if (FieldArray.empty())
1133 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001134
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001135 CPDF_FormField* pFormField = FieldArray[0];
1136 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX)
1137 return false;
1138
Dan Sinclaire4974922017-10-24 09:36:16 -04001139 vp->Set(
1140 pRuntime->NewBoolean(!!(pFormField->GetFieldFlags() & FIELDFLAG_EDIT)));
tsepez4cf55152016-11-02 14:37:54 -07001141 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001142}
1143
dan sinclaircbe23db2017-10-19 14:29:33 -04001144bool Field::set_editable(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001145 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001146 WideString* sError) {
1147 return m_bCanSet;
1148}
1149
1150bool Field::get_export_values(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001151 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001152 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001153 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1154 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001155 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001156
Lei Zhangd88a3642015-11-10 09:38:57 -08001157 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001158 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001159 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) {
tsepez4cf55152016-11-02 14:37:54 -07001160 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001161 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001162
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001163 CJS_Array ExportValusArray;
1164 if (m_nFormControlIndex < 0) {
1165 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
1166 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04001167 ExportValusArray.SetElement(pRuntime, i,
1168 CJS_Value(pRuntime->NewString(
1169 pFormControl->GetExportValue().c_str())));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001170 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001171 } else {
1172 if (m_nFormControlIndex >= pFormField->CountControls())
1173 return false;
1174
1175 CPDF_FormControl* pFormControl =
1176 pFormField->GetControl(m_nFormControlIndex);
1177 if (!pFormControl)
1178 return false;
1179
1180 ExportValusArray.SetElement(
1181 pRuntime, 0,
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04001182 CJS_Value(pRuntime->NewString(pFormControl->GetExportValue().c_str())));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001183 }
dan sinclaircbe23db2017-10-19 14:29:33 -04001184
Dan Sinclaire4974922017-10-24 09:36:16 -04001185 vp->Set(ExportValusArray.ToV8Array(pRuntime));
tsepez4cf55152016-11-02 14:37:54 -07001186 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001187}
1188
dan sinclaircbe23db2017-10-19 14:29:33 -04001189bool Field::set_export_values(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001190 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001191 WideString* sError) {
1192 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1193 if (FieldArray.empty())
1194 return false;
1195
1196 CPDF_FormField* pFormField = FieldArray[0];
1197 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
1198 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) {
1199 return false;
1200 }
1201
Dan Sinclair33d13f22017-10-23 09:44:30 -04001202 return m_bCanSet && vp.IsArrayObject();
dan sinclaircbe23db2017-10-19 14:29:33 -04001203}
1204
1205bool Field::get_file_select(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001206 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001207 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001208 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1209 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001210 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001211
Lei Zhangd88a3642015-11-10 09:38:57 -08001212 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001213 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
tsepez4cf55152016-11-02 14:37:54 -07001214 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001215
Dan Sinclaire4974922017-10-24 09:36:16 -04001216 vp->Set(pRuntime->NewBoolean(
1217 !!(pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT)));
tsepez4cf55152016-11-02 14:37:54 -07001218 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001219}
1220
dan sinclaircbe23db2017-10-19 14:29:33 -04001221bool Field::set_file_select(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001222 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001223 WideString* sError) {
1224 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1225 if (FieldArray.empty())
1226 return false;
1227
1228 CPDF_FormField* pFormField = FieldArray[0];
1229 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1230 return false;
1231
1232 return m_bCanSet;
1233}
1234
1235bool Field::get_fill_color(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001236 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001237 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001238 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1239 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001240 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001241
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001242 CPDF_FormField* pFormField = FieldArray[0];
1243 ASSERT(pFormField);
1244 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1245 if (!pFormControl)
1246 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001247
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001248 int iColorType;
1249 pFormControl->GetBackgroundColor(iColorType);
1250
Dan Sinclair7f55a542017-07-13 14:17:10 -04001251 CFX_Color color;
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001252 if (iColorType == CFX_Color::kTransparent) {
1253 color = CFX_Color(CFX_Color::kTransparent);
1254 } else if (iColorType == CFX_Color::kGray) {
1255 color = CFX_Color(CFX_Color::kGray,
1256 pFormControl->GetOriginalBackgroundColor(0));
1257 } else if (iColorType == CFX_Color::kRGB) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001258 color =
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001259 CFX_Color(CFX_Color::kRGB, pFormControl->GetOriginalBackgroundColor(0),
Dan Sinclair7f55a542017-07-13 14:17:10 -04001260 pFormControl->GetOriginalBackgroundColor(1),
1261 pFormControl->GetOriginalBackgroundColor(2));
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001262 } else if (iColorType == CFX_Color::kCMYK) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001263 color =
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001264 CFX_Color(CFX_Color::kCMYK, pFormControl->GetOriginalBackgroundColor(0),
Dan Sinclair7f55a542017-07-13 14:17:10 -04001265 pFormControl->GetOriginalBackgroundColor(1),
1266 pFormControl->GetOriginalBackgroundColor(2),
1267 pFormControl->GetOriginalBackgroundColor(3));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001268 } else {
1269 return false;
1270 }
dan sinclaircbe23db2017-10-19 14:29:33 -04001271
Dan Sinclaire4974922017-10-24 09:36:16 -04001272 vp->Set(color::ConvertPWLColorToArray(pRuntime, color).ToV8Array(pRuntime));
dan sinclaircbe23db2017-10-19 14:29:33 -04001273 return true;
1274}
1275
1276bool Field::set_fill_color(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001277 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001278 WideString* sError) {
1279 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1280 if (FieldArray.empty())
1281 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -04001282 if (!m_bCanSet)
1283 return false;
Dan Sinclair33d13f22017-10-23 09:44:30 -04001284 if (!vp.IsArrayObject())
dan sinclaircbe23db2017-10-19 14:29:33 -04001285 return false;
tsepez4cf55152016-11-02 14:37:54 -07001286 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001287}
1288
dan sinclaircbe23db2017-10-19 14:29:33 -04001289bool Field::get_hidden(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001290 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001291 WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001292 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1293 if (FieldArray.empty())
1294 return false;
1295
1296 CPDF_FormField* pFormField = FieldArray[0];
1297 ASSERT(pFormField);
dan sinclaircbe23db2017-10-19 14:29:33 -04001298
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001299 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1300 CPDFSDK_Widget* pWidget =
1301 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1302 if (!pWidget)
1303 return false;
1304
1305 uint32_t dwFlags = pWidget->GetFlags();
Dan Sinclaire4974922017-10-24 09:36:16 -04001306 vp->Set(pRuntime->NewBoolean(ANNOTFLAG_INVISIBLE & dwFlags ||
1307 ANNOTFLAG_HIDDEN & dwFlags));
dan sinclaircbe23db2017-10-19 14:29:33 -04001308 return true;
1309}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001310
dan sinclaircbe23db2017-10-19 14:29:33 -04001311bool Field::set_hidden(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001312 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001313 WideString* sError) {
1314 if (!m_bCanSet)
1315 return false;
1316
1317 if (m_bDelay) {
Dan Sinclair33d13f22017-10-23 09:44:30 -04001318 AddDelay_Bool(FP_HIDDEN, vp.ToBool(pRuntime));
dan sinclaircbe23db2017-10-19 14:29:33 -04001319 } else {
1320 Field::SetHidden(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001321 vp.ToBool(pRuntime));
dan sinclaircbe23db2017-10-19 14:29:33 -04001322 }
tsepez4cf55152016-11-02 14:37:54 -07001323 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001324}
1325
dsinclair3a7741a2016-10-11 10:39:49 -07001326void Field::SetHidden(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04001327 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001328 int nControlIndex,
1329 bool b) {
tonikitooa73b8fe2016-08-22 14:06:49 -07001330 int display = b ? 1 /*Hidden*/ : 0 /*Visible*/;
dsinclair3a7741a2016-10-11 10:39:49 -07001331 SetDisplay(pFormFillEnv, swFieldName, nControlIndex, display);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001332}
1333
dan sinclaircbe23db2017-10-19 14:29:33 -04001334bool Field::get_highlight(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001335 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001336 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001337 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001338
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001339 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1340 if (FieldArray.empty())
1341 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001342
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001343 CPDF_FormField* pFormField = FieldArray[0];
1344 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
1345 return false;
1346
1347 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1348 if (!pFormControl)
1349 return false;
1350
1351 int eHM = pFormControl->GetHighlightingMode();
1352 switch (eHM) {
1353 case CPDF_FormControl::None:
Dan Sinclaire4974922017-10-24 09:36:16 -04001354 vp->Set(pRuntime->NewString(L"none"));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001355 break;
1356 case CPDF_FormControl::Push:
Dan Sinclaire4974922017-10-24 09:36:16 -04001357 vp->Set(pRuntime->NewString(L"push"));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001358 break;
1359 case CPDF_FormControl::Invert:
Dan Sinclaire4974922017-10-24 09:36:16 -04001360 vp->Set(pRuntime->NewString(L"invert"));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001361 break;
1362 case CPDF_FormControl::Outline:
Dan Sinclaire4974922017-10-24 09:36:16 -04001363 vp->Set(pRuntime->NewString(L"outline"));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001364 break;
1365 case CPDF_FormControl::Toggle:
Dan Sinclaire4974922017-10-24 09:36:16 -04001366 vp->Set(pRuntime->NewString(L"toggle"));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001367 break;
1368 }
tsepez4cf55152016-11-02 14:37:54 -07001369 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001370}
1371
dan sinclaircbe23db2017-10-19 14:29:33 -04001372bool Field::set_highlight(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001373 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001374 WideString* sError) {
1375 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04001376 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001377}
1378
dan sinclaircbe23db2017-10-19 14:29:33 -04001379bool Field::get_line_width(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001380 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001381 WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001382 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1383 if (FieldArray.empty())
1384 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001385
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001386 CPDF_FormField* pFormField = FieldArray[0];
1387 ASSERT(pFormField);
dan sinclaircbe23db2017-10-19 14:29:33 -04001388
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001389 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1390 if (!pFormControl)
1391 return false;
1392
1393 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1394 if (!pFormField->CountControls())
1395 return false;
1396
1397 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
1398 if (!pWidget)
1399 return false;
1400
Dan Sinclaire4974922017-10-24 09:36:16 -04001401 vp->Set(pRuntime->NewNumber(pWidget->GetBorderWidth()));
dan sinclaircbe23db2017-10-19 14:29:33 -04001402 return true;
1403}
1404
1405bool Field::set_line_width(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001406 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001407 WideString* sError) {
1408 if (!m_bCanSet)
1409 return false;
1410
1411 if (m_bDelay) {
Dan Sinclair33d13f22017-10-23 09:44:30 -04001412 AddDelay_Int(FP_LINEWIDTH, vp.ToInt(pRuntime));
dan sinclaircbe23db2017-10-19 14:29:33 -04001413 } else {
1414 Field::SetLineWidth(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001415 vp.ToInt(pRuntime));
dan sinclaircbe23db2017-10-19 14:29:33 -04001416 }
tsepez4cf55152016-11-02 14:37:54 -07001417 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001418}
1419
dsinclair3a7741a2016-10-11 10:39:49 -07001420void Field::SetLineWidth(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04001421 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001422 int nControlIndex,
1423 int number) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001424 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001425 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07001426 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -08001427 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001428 if (nControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -07001429 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001430 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1431 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08001432 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001433
dsinclairc5267c52016-11-04 15:35:12 -07001434 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001435 if (number != pWidget->GetBorderWidth()) {
1436 pWidget->SetBorderWidth(number);
tsepez4cf55152016-11-02 14:37:54 -07001437 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001438 }
1439 }
1440 }
1441 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -07001442 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001443 } else {
1444 if (nControlIndex >= pFormField->CountControls())
1445 return;
1446 if (CPDF_FormControl* pFormControl =
1447 pFormField->GetControl(nControlIndex)) {
dsinclairc5267c52016-11-04 15:35:12 -07001448 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001449 if (number != pWidget->GetBorderWidth()) {
1450 pWidget->SetBorderWidth(number);
tsepez4cf55152016-11-02 14:37:54 -07001451 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001452 }
1453 }
1454 }
1455 }
1456 }
1457}
1458
dan sinclaircbe23db2017-10-19 14:29:33 -04001459bool Field::get_multiline(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001460 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001461 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001462 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001463
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001464 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1465 if (FieldArray.empty())
1466 return false;
1467
1468 CPDF_FormField* pFormField = FieldArray[0];
1469 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1470 return false;
1471
Dan Sinclaire4974922017-10-24 09:36:16 -04001472 vp->Set(pRuntime->NewBoolean(
1473 !!(pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE)));
tsepez4cf55152016-11-02 14:37:54 -07001474 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001475}
1476
dan sinclaircbe23db2017-10-19 14:29:33 -04001477bool Field::set_multiline(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001478 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001479 WideString* sError) {
1480 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04001481 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001482}
1483
dan sinclaircbe23db2017-10-19 14:29:33 -04001484bool Field::get_multiple_selection(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001485 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001486 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001487 ASSERT(m_pFormFillEnv);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001488 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1489 if (FieldArray.empty())
1490 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001491
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001492 CPDF_FormField* pFormField = FieldArray[0];
1493 if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
1494 return false;
1495
Dan Sinclaire4974922017-10-24 09:36:16 -04001496 vp->Set(pRuntime->NewBoolean(
1497 !!(pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT)));
dan sinclaircbe23db2017-10-19 14:29:33 -04001498 return true;
1499}
1500
1501bool Field::set_multiple_selection(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001502 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001503 WideString* sError) {
1504 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04001505 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001506}
1507
Dan Sinclair33d13f22017-10-23 09:44:30 -04001508bool Field::get_name(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001509 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1510 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001511 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001512
Dan Sinclaire4974922017-10-24 09:36:16 -04001513 vp->Set(pRuntime->NewString(m_FieldName.c_str()));
tsepez4cf55152016-11-02 14:37:54 -07001514 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001515}
1516
dan sinclaircbe23db2017-10-19 14:29:33 -04001517bool Field::set_name(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001518 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001519 WideString* sError) {
1520 return false;
1521}
Tom Sepez67fd5df2015-10-08 12:24:19 -07001522
dan sinclaircbe23db2017-10-19 14:29:33 -04001523bool Field::get_num_items(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001524 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001525 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001526 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1527 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001528 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001529
Lei Zhangd88a3642015-11-10 09:38:57 -08001530 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001531 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001532 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
tsepez4cf55152016-11-02 14:37:54 -07001533 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001534 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001535
Dan Sinclaire4974922017-10-24 09:36:16 -04001536 vp->Set(pRuntime->NewNumber(pFormField->CountOptions()));
tsepez4cf55152016-11-02 14:37:54 -07001537 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001538}
1539
dan sinclaircbe23db2017-10-19 14:29:33 -04001540bool Field::set_num_items(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001541 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001542 WideString* sError) {
1543 return false;
1544}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001545
Dan Sinclair33d13f22017-10-23 09:44:30 -04001546bool Field::get_page(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001547 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1548 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001549 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001550
Lei Zhangd88a3642015-11-10 09:38:57 -08001551 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001552 if (!pFormField)
tsepez4cf55152016-11-02 14:37:54 -07001553 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001554
tsepez8fa82792017-01-11 09:32:33 -08001555 std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
dsinclair7cbe68e2016-10-12 11:56:23 -07001556 m_pFormFillEnv->GetInterForm()->GetWidgets(pFormField, &widgets);
Lei Zhangd88a3642015-11-10 09:38:57 -08001557 if (widgets.empty()) {
Dan Sinclaire4974922017-10-24 09:36:16 -04001558 vp->Set(pRuntime->NewNumber(-1));
tsepez4cf55152016-11-02 14:37:54 -07001559 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001560 }
1561
tsepeze5aff742016-08-08 09:49:42 -07001562 CJS_Array PageArray;
tsepez8fa82792017-01-11 09:32:33 -08001563 int i = 0;
1564 for (const auto& pObserved : widgets) {
1565 if (!pObserved) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001566 *sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
tsepez8fa82792017-01-11 09:32:33 -08001567 return false;
1568 }
1569
Lei Zhang375c2762017-03-10 14:37:14 -08001570 auto* pWidget = static_cast<CPDFSDK_Widget*>(pObserved.Get());
tsepez8fa82792017-01-11 09:32:33 -08001571 CPDFSDK_PageView* pPageView = pWidget->GetPageView();
Lei Zhangd88a3642015-11-10 09:38:57 -08001572 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -07001573 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001574
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04001575 PageArray.SetElement(pRuntime, i,
1576 CJS_Value(pRuntime->NewNumber(
1577 static_cast<int32_t>(pPageView->GetPageIndex()))));
tsepez8fa82792017-01-11 09:32:33 -08001578 ++i;
Lei Zhangd88a3642015-11-10 09:38:57 -08001579 }
1580
Dan Sinclaire4974922017-10-24 09:36:16 -04001581 vp->Set(PageArray.ToV8Array(pRuntime));
tsepez4cf55152016-11-02 14:37:54 -07001582 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001583}
1584
dan sinclaircbe23db2017-10-19 14:29:33 -04001585bool Field::set_page(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001586 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001587 WideString* sError) {
1588 *sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
1589 return false;
1590}
1591
1592bool Field::get_password(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001593 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001594 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001595 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001596
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001597 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1598 if (FieldArray.empty())
1599 return false;
1600
1601 CPDF_FormField* pFormField = FieldArray[0];
1602 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1603 return false;
1604
Dan Sinclaire4974922017-10-24 09:36:16 -04001605 vp->Set(pRuntime->NewBoolean(
1606 !!(pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD)));
tsepez4cf55152016-11-02 14:37:54 -07001607 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001608}
1609
dan sinclaircbe23db2017-10-19 14:29:33 -04001610bool Field::set_password(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001611 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001612 WideString* sError) {
1613 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04001614 return m_bCanSet;
1615}
dan sinclaircbe23db2017-10-19 14:29:33 -04001616
dan sinclair646634b2017-10-19 14:30:28 -04001617bool Field::get_print(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001618 CJS_Value* vp,
dan sinclair646634b2017-10-19 14:30:28 -04001619 WideString* sError) {
1620 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1621 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1622 if (FieldArray.empty())
1623 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -04001624
dan sinclair646634b2017-10-19 14:30:28 -04001625 CPDF_FormField* pFormField = FieldArray[0];
1626 CPDFSDK_Widget* pWidget =
1627 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1628 if (!pWidget)
1629 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -04001630
Dan Sinclaire4974922017-10-24 09:36:16 -04001631 vp->Set(pRuntime->NewBoolean(!!(pWidget->GetFlags() & ANNOTFLAG_PRINT)));
dan sinclair646634b2017-10-19 14:30:28 -04001632 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001633}
1634
dan sinclaircbe23db2017-10-19 14:29:33 -04001635bool Field::set_print(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001636 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001637 WideString* sError) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001638 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001639 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1640 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001641 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001642
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001643 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001644 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001645
Lei Zhangd88a3642015-11-10 09:38:57 -08001646 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001647 if (m_nFormControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -07001648 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001649 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001650 if (CPDFSDK_Widget* pWidget =
dsinclairc5267c52016-11-04 15:35:12 -07001651 pInterForm->GetWidget(pFormField->GetControl(i))) {
tsepezc3255f52016-03-25 14:52:27 -07001652 uint32_t dwFlags = pWidget->GetFlags();
Dan Sinclair33d13f22017-10-23 09:44:30 -04001653 if (vp.ToBool(pRuntime))
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001654 dwFlags |= ANNOTFLAG_PRINT;
1655 else
1656 dwFlags &= ~ANNOTFLAG_PRINT;
1657
1658 if (dwFlags != pWidget->GetFlags()) {
1659 pWidget->SetFlags(dwFlags);
tsepez4cf55152016-11-02 14:37:54 -07001660 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001661 }
1662 }
1663 }
1664
1665 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -07001666 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001667
dan sinclaircbe23db2017-10-19 14:29:33 -04001668 continue;
1669 }
1670
1671 if (m_nFormControlIndex >= pFormField->CountControls())
1672 return false;
1673 if (CPDF_FormControl* pFormControl =
1674 pFormField->GetControl(m_nFormControlIndex)) {
1675 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1676 uint32_t dwFlags = pWidget->GetFlags();
Dan Sinclair33d13f22017-10-23 09:44:30 -04001677 if (vp.ToBool(pRuntime))
dan sinclaircbe23db2017-10-19 14:29:33 -04001678 dwFlags |= ANNOTFLAG_PRINT;
1679 else
1680 dwFlags &= ~ANNOTFLAG_PRINT;
1681
1682 if (dwFlags != pWidget->GetFlags()) {
1683 pWidget->SetFlags(dwFlags);
1684 UpdateFormControl(m_pFormFillEnv.Get(),
1685 pFormField->GetControl(m_nFormControlIndex), true,
1686 false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001687 }
1688 }
1689 }
1690 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001691 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001692}
1693
dan sinclaircbe23db2017-10-19 14:29:33 -04001694bool Field::get_radios_in_unison(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001695 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001696 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001697 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1698 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001699 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001700
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001701 CPDF_FormField* pFormField = FieldArray[0];
1702 if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
1703 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001704
Dan Sinclaire4974922017-10-24 09:36:16 -04001705 vp->Set(pRuntime->NewBoolean(
1706 !!(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)));
tsepez4cf55152016-11-02 14:37:54 -07001707 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001708}
1709
dan sinclaircbe23db2017-10-19 14:29:33 -04001710bool Field::set_radios_in_unison(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001711 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001712 WideString* sError) {
1713 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1714 if (FieldArray.empty())
1715 return false;
1716 return m_bCanSet;
1717}
1718
1719bool Field::get_readonly(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001720 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001721 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001722 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1723 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001724 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001725
Dan Sinclaire4974922017-10-24 09:36:16 -04001726 vp->Set(pRuntime->NewBoolean(
1727 !!(FieldArray[0]->GetFieldFlags() & FIELDFLAG_READONLY)));
tsepez4cf55152016-11-02 14:37:54 -07001728 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001729}
1730
dan sinclaircbe23db2017-10-19 14:29:33 -04001731bool Field::set_readonly(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001732 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001733 WideString* sError) {
1734 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1735 if (FieldArray.empty())
1736 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -04001737 return m_bCanSet;
1738}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001739
Dan Sinclair33d13f22017-10-23 09:44:30 -04001740bool Field::get_rect(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001741 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1742 if (FieldArray.empty())
1743 return false;
1744
1745 CPDF_FormField* pFormField = FieldArray[0];
1746 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1747 CPDFSDK_Widget* pWidget =
1748 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1749 if (!pWidget)
1750 return false;
1751
1752 CFX_FloatRect crRect = pWidget->GetRect();
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001753 CJS_Array rcArray;
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04001754 rcArray.SetElement(
1755 pRuntime, 0,
1756 CJS_Value(pRuntime->NewNumber(static_cast<int32_t>(crRect.left))));
1757 rcArray.SetElement(
1758 pRuntime, 1,
1759 CJS_Value(pRuntime->NewNumber(static_cast<int32_t>(crRect.top))));
1760 rcArray.SetElement(
1761 pRuntime, 2,
1762 CJS_Value(pRuntime->NewNumber(static_cast<int32_t>(crRect.right))));
1763 rcArray.SetElement(
1764 pRuntime, 3,
1765 CJS_Value(pRuntime->NewNumber(static_cast<int32_t>(crRect.bottom))));
Dan Sinclaire4974922017-10-24 09:36:16 -04001766 vp->Set(rcArray.ToV8Array(pRuntime));
dan sinclaircbe23db2017-10-19 14:29:33 -04001767 return true;
1768}
1769
1770bool Field::set_rect(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001771 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001772 WideString* sError) {
1773 if (!m_bCanSet)
1774 return false;
Dan Sinclair33d13f22017-10-23 09:44:30 -04001775 if (!vp.IsArrayObject())
dan sinclaircbe23db2017-10-19 14:29:33 -04001776 return false;
1777
Dan Sinclair33d13f22017-10-23 09:44:30 -04001778 CJS_Array rcArray = vp.ToArray(pRuntime);
dan sinclaircbe23db2017-10-19 14:29:33 -04001779 float pArray[4];
Dan Sinclaire4974922017-10-24 09:36:16 -04001780 pArray[0] =
1781 static_cast<float>(rcArray.GetElement(pRuntime, 0).ToInt(pRuntime));
1782 pArray[1] =
1783 static_cast<float>(rcArray.GetElement(pRuntime, 1).ToInt(pRuntime));
1784 pArray[2] =
1785 static_cast<float>(rcArray.GetElement(pRuntime, 2).ToInt(pRuntime));
1786 pArray[3] =
1787 static_cast<float>(rcArray.GetElement(pRuntime, 3).ToInt(pRuntime));
dan sinclaircbe23db2017-10-19 14:29:33 -04001788
1789 CFX_FloatRect crRect(pArray);
1790 if (m_bDelay) {
1791 AddDelay_Rect(FP_RECT, crRect);
1792 } else {
1793 Field::SetRect(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
1794 crRect);
1795 }
tsepez4cf55152016-11-02 14:37:54 -07001796 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001797}
1798
dsinclair3a7741a2016-10-11 10:39:49 -07001799void Field::SetRect(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04001800 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001801 int nControlIndex,
Tom Sepez281a9ea2016-02-26 14:24:28 -08001802 const CFX_FloatRect& rect) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001803 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001804 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07001805 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -08001806 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001807 if (nControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -07001808 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001809 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001810 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08001811 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001812
dsinclairc5267c52016-11-04 15:35:12 -07001813 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08001814 CFX_FloatRect crRect = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001815
1816 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001817 crRect.Intersect(pPDFPage->GetPageBBox());
1818
1819 if (!crRect.IsEmpty()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08001820 CFX_FloatRect rcOld = pWidget->GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001821 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
1822 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
1823 pWidget->SetRect(crRect);
tsepez4cf55152016-11-02 14:37:54 -07001824 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001825 }
1826 }
1827 }
1828 }
1829
1830 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -07001831 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001832
dan sinclaircbe23db2017-10-19 14:29:33 -04001833 continue;
1834 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001835
dan sinclaircbe23db2017-10-19 14:29:33 -04001836 if (nControlIndex >= pFormField->CountControls())
1837 return;
1838 if (CPDF_FormControl* pFormControl =
1839 pFormField->GetControl(nControlIndex)) {
1840 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1841 CFX_FloatRect crRect = rect;
1842
1843 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
1844 crRect.Intersect(pPDFPage->GetPageBBox());
1845
1846 if (!crRect.IsEmpty()) {
1847 CFX_FloatRect rcOld = pWidget->GetRect();
1848 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
1849 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
1850 pWidget->SetRect(crRect);
1851 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001852 }
1853 }
1854 }
1855 }
1856 }
1857}
1858
dan sinclaircbe23db2017-10-19 14:29:33 -04001859bool Field::get_required(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001860 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001861 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001862 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1863 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001864 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001865
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001866 CPDF_FormField* pFormField = FieldArray[0];
1867 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
1868 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001869
Dan Sinclaire4974922017-10-24 09:36:16 -04001870 vp->Set(pRuntime->NewBoolean(
1871 !!(pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED)));
tsepez4cf55152016-11-02 14:37:54 -07001872 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001873}
1874
dan sinclaircbe23db2017-10-19 14:29:33 -04001875bool Field::set_required(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001876 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001877 WideString* sError) {
1878 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1879 if (FieldArray.empty())
1880 return false;
1881
1882 return m_bCanSet;
1883}
1884
1885bool Field::get_rich_text(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001886 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001887 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001888 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001889
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001890 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1891 if (FieldArray.empty())
1892 return false;
1893
1894 CPDF_FormField* pFormField = FieldArray[0];
1895 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1896 return false;
1897
Dan Sinclaire4974922017-10-24 09:36:16 -04001898 vp->Set(pRuntime->NewBoolean(
1899 !!(pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT)));
tsepez4cf55152016-11-02 14:37:54 -07001900 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001901}
1902
dan sinclaircbe23db2017-10-19 14:29:33 -04001903bool Field::set_rich_text(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001904 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001905 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001906 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04001907 return m_bCanSet;
dan sinclaircbe23db2017-10-19 14:29:33 -04001908}
1909
1910bool Field::get_rich_value(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001911 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001912 WideString* sError) {
1913 return true;
1914}
1915
1916bool Field::set_rich_value(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001917 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001918 WideString* sError) {
1919 return true;
1920}
1921
1922bool Field::get_rotation(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001923 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001924 WideString* sError) {
1925 ASSERT(m_pFormFillEnv);
1926
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001927 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1928 if (FieldArray.empty())
1929 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001930
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001931 CPDF_FormField* pFormField = FieldArray[0];
1932 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1933 if (!pFormControl)
1934 return false;
1935
Dan Sinclaire4974922017-10-24 09:36:16 -04001936 vp->Set(pRuntime->NewNumber(pFormControl->GetRotation()));
dan sinclaircbe23db2017-10-19 14:29:33 -04001937 return true;
1938}
1939
1940bool Field::set_rotation(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001941 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001942 WideString* sError) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001943 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04001944 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001945}
1946
dan sinclaircbe23db2017-10-19 14:29:33 -04001947bool Field::get_stroke_color(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001948 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001949 WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001950 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1951 if (FieldArray.empty())
1952 return false;
1953
1954 CPDF_FormField* pFormField = FieldArray[0];
1955 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1956 if (!pFormControl)
1957 return false;
1958
1959 int iColorType;
1960 pFormControl->GetBorderColor(iColorType);
1961
Dan Sinclair7f55a542017-07-13 14:17:10 -04001962 CFX_Color color;
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001963 if (iColorType == CFX_Color::kTransparent) {
1964 color = CFX_Color(CFX_Color::kTransparent);
1965 } else if (iColorType == CFX_Color::kGray) {
1966 color =
1967 CFX_Color(CFX_Color::kGray, pFormControl->GetOriginalBorderColor(0));
1968 } else if (iColorType == CFX_Color::kRGB) {
1969 color = CFX_Color(CFX_Color::kRGB, pFormControl->GetOriginalBorderColor(0),
Dan Sinclair7f55a542017-07-13 14:17:10 -04001970 pFormControl->GetOriginalBorderColor(1),
1971 pFormControl->GetOriginalBorderColor(2));
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001972 } else if (iColorType == CFX_Color::kCMYK) {
1973 color = CFX_Color(CFX_Color::kCMYK, pFormControl->GetOriginalBorderColor(0),
Dan Sinclair7f55a542017-07-13 14:17:10 -04001974 pFormControl->GetOriginalBorderColor(1),
1975 pFormControl->GetOriginalBorderColor(2),
1976 pFormControl->GetOriginalBorderColor(3));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001977 } else {
1978 return false;
1979 }
1980
Dan Sinclaire4974922017-10-24 09:36:16 -04001981 vp->Set(color::ConvertPWLColorToArray(pRuntime, color).ToV8Array(pRuntime));
dan sinclaircbe23db2017-10-19 14:29:33 -04001982 return true;
1983}
1984
1985bool Field::set_stroke_color(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001986 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001987 WideString* sError) {
1988 if (!m_bCanSet)
1989 return false;
Dan Sinclair33d13f22017-10-23 09:44:30 -04001990 if (!vp.IsArrayObject())
dan sinclaircbe23db2017-10-19 14:29:33 -04001991 return false;
tsepez4cf55152016-11-02 14:37:54 -07001992 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001993}
1994
dan sinclaircbe23db2017-10-19 14:29:33 -04001995bool Field::get_style(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001996 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001997 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001998 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001999
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002000 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2001 if (FieldArray.empty())
2002 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002003
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002004 CPDF_FormField* pFormField = FieldArray[0];
2005 if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON &&
2006 pFormField->GetFieldType() != FIELDTYPE_CHECKBOX) {
2007 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002008 }
2009
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002010 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2011 if (!pFormControl)
2012 return false;
2013
Ryan Harrison275e2602017-09-18 14:23:18 -04002014 WideString csWCaption = pFormControl->GetNormalCaption();
2015 ByteString csBCaption;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002016
2017 switch (csWCaption[0]) {
2018 case L'l':
2019 csBCaption = "circle";
2020 break;
2021 case L'8':
2022 csBCaption = "cross";
2023 break;
2024 case L'u':
2025 csBCaption = "diamond";
2026 break;
2027 case L'n':
2028 csBCaption = "square";
2029 break;
2030 case L'H':
2031 csBCaption = "star";
2032 break;
2033 default: // L'4'
2034 csBCaption = "check";
2035 break;
2036 }
Dan Sinclaire4974922017-10-24 09:36:16 -04002037 vp->Set(
2038 pRuntime->NewString(WideString::FromLocal(csBCaption.c_str()).c_str()));
dan sinclaircbe23db2017-10-19 14:29:33 -04002039 return true;
2040}
2041
2042bool Field::set_style(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002043 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002044 WideString* sError) {
2045 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04002046 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002047}
2048
dan sinclaircbe23db2017-10-19 14:29:33 -04002049bool Field::get_submit_name(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002050 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002051 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -07002052 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002053}
2054
dan sinclaircbe23db2017-10-19 14:29:33 -04002055bool Field::set_submit_name(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002056 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002057 WideString* sError) {
2058 return true;
2059}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002060
dan sinclaircbe23db2017-10-19 14:29:33 -04002061bool Field::get_text_color(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002062 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002063 WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002064 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2065 if (FieldArray.empty())
2066 return false;
2067
2068 CPDF_FormField* pFormField = FieldArray[0];
2069 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2070 if (!pFormControl)
2071 return false;
2072
2073 int iColorType;
2074 FX_ARGB color;
2075 CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
2076 FieldAppearance.GetColor(color, iColorType);
2077
2078 int32_t a;
2079 int32_t r;
2080 int32_t g;
2081 int32_t b;
Nicolas Penaddfc3dc2017-04-20 15:29:25 -04002082 std::tie(a, r, g, b) = ArgbDecode(color);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002083
Dan Sinclair7f55a542017-07-13 14:17:10 -04002084 CFX_Color crRet =
Dan Sinclair8e7f9322017-10-16 11:35:42 -04002085 CFX_Color(CFX_Color::kRGB, r / 255.0f, g / 255.0f, b / 255.0f);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002086
Dan Sinclair8e7f9322017-10-16 11:35:42 -04002087 if (iColorType == CFX_Color::kTransparent)
2088 crRet = CFX_Color(CFX_Color::kTransparent);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002089
Dan Sinclaire4974922017-10-24 09:36:16 -04002090 vp->Set(color::ConvertPWLColorToArray(pRuntime, crRet).ToV8Array(pRuntime));
dan sinclaircbe23db2017-10-19 14:29:33 -04002091 return true;
2092}
2093
2094bool Field::set_text_color(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002095 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002096 WideString* sError) {
2097 if (!m_bCanSet)
2098 return false;
Dan Sinclair33d13f22017-10-23 09:44:30 -04002099 if (!vp.IsArrayObject())
dan sinclaircbe23db2017-10-19 14:29:33 -04002100 return false;
tsepez4cf55152016-11-02 14:37:54 -07002101 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002102}
2103
dan sinclaircbe23db2017-10-19 14:29:33 -04002104bool Field::get_text_font(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002105 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002106 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002107 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002108
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002109 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2110 if (FieldArray.empty())
2111 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002112
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002113 CPDF_FormField* pFormField = FieldArray[0];
2114 ASSERT(pFormField);
2115 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2116 if (!pFormControl)
2117 return false;
2118
2119 int nFieldType = pFormField->GetFieldType();
2120 if (nFieldType != FIELDTYPE_PUSHBUTTON && nFieldType != FIELDTYPE_COMBOBOX &&
2121 nFieldType != FIELDTYPE_LISTBOX && nFieldType != FIELDTYPE_TEXTFIELD) {
2122 return false;
2123 }
2124 CPDF_Font* pFont = pFormControl->GetDefaultControlFont();
2125 if (!pFont)
2126 return false;
2127
Dan Sinclaire4974922017-10-24 09:36:16 -04002128 vp->Set(pRuntime->NewString(
2129 WideString::FromLocal(pFont->GetBaseFont().c_str()).c_str()));
tsepez4cf55152016-11-02 14:37:54 -07002130 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002131}
2132
dan sinclaircbe23db2017-10-19 14:29:33 -04002133bool Field::set_text_font(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002134 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002135 WideString* sError) {
2136 ASSERT(m_pFormFillEnv);
2137
dan sinclair646634b2017-10-19 14:30:28 -04002138 if (!m_bCanSet)
2139 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -04002140
Dan Sinclair33d13f22017-10-23 09:44:30 -04002141 ByteString fontName = vp.ToByteString(pRuntime);
dan sinclair646634b2017-10-19 14:30:28 -04002142 return !fontName.IsEmpty();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002143}
2144
dan sinclaircbe23db2017-10-19 14:29:33 -04002145bool Field::get_text_size(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002146 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002147 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002148 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002149
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002150 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2151 if (FieldArray.empty())
2152 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002153
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002154 CPDF_FormField* pFormField = FieldArray[0];
2155 ASSERT(pFormField);
2156 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2157 if (!pFormControl)
2158 return false;
2159
Dan Sinclair05df0752017-03-14 14:43:42 -04002160 float fFontSize;
Tom Sepezc4a2b752017-04-07 13:56:13 -07002161 CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
2162 FieldAppearance.GetFont(&fFontSize);
Dan Sinclaire4974922017-10-24 09:36:16 -04002163 vp->Set(pRuntime->NewNumber(static_cast<int>(fFontSize)));
dan sinclaircbe23db2017-10-19 14:29:33 -04002164 return true;
2165}
2166
2167bool Field::set_text_size(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002168 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002169 WideString* sError) {
2170 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04002171 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002172}
2173
Dan Sinclair33d13f22017-10-23 09:44:30 -04002174bool Field::get_type(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002175 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2176 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002177 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002178
Lei Zhangd88a3642015-11-10 09:38:57 -08002179 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002180 switch (pFormField->GetFieldType()) {
2181 case FIELDTYPE_UNKNOWN:
Dan Sinclaire4974922017-10-24 09:36:16 -04002182 vp->Set(pRuntime->NewString(L"unknown"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002183 break;
2184 case FIELDTYPE_PUSHBUTTON:
Dan Sinclaire4974922017-10-24 09:36:16 -04002185 vp->Set(pRuntime->NewString(L"button"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002186 break;
2187 case FIELDTYPE_CHECKBOX:
Dan Sinclaire4974922017-10-24 09:36:16 -04002188 vp->Set(pRuntime->NewString(L"checkbox"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002189 break;
2190 case FIELDTYPE_RADIOBUTTON:
Dan Sinclaire4974922017-10-24 09:36:16 -04002191 vp->Set(pRuntime->NewString(L"radiobutton"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002192 break;
2193 case FIELDTYPE_COMBOBOX:
Dan Sinclaire4974922017-10-24 09:36:16 -04002194 vp->Set(pRuntime->NewString(L"combobox"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002195 break;
2196 case FIELDTYPE_LISTBOX:
Dan Sinclaire4974922017-10-24 09:36:16 -04002197 vp->Set(pRuntime->NewString(L"listbox"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002198 break;
2199 case FIELDTYPE_TEXTFIELD:
Dan Sinclaire4974922017-10-24 09:36:16 -04002200 vp->Set(pRuntime->NewString(L"text"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002201 break;
2202 case FIELDTYPE_SIGNATURE:
Dan Sinclaire4974922017-10-24 09:36:16 -04002203 vp->Set(pRuntime->NewString(L"signature"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002204 break;
2205 default:
Dan Sinclaire4974922017-10-24 09:36:16 -04002206 vp->Set(pRuntime->NewString(L"unknown"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002207 break;
2208 }
tsepez4cf55152016-11-02 14:37:54 -07002209 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002210}
2211
dan sinclaircbe23db2017-10-19 14:29:33 -04002212bool Field::set_type(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002213 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002214 WideString* sError) {
2215 return false;
2216}
2217
2218bool Field::get_user_name(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002219 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002220 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002221 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002222
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002223 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2224 if (FieldArray.empty())
2225 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002226
Dan Sinclaire4974922017-10-24 09:36:16 -04002227 vp->Set(pRuntime->NewString(FieldArray[0]->GetAlternateName().c_str()));
tsepez4cf55152016-11-02 14:37:54 -07002228 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002229}
2230
dan sinclaircbe23db2017-10-19 14:29:33 -04002231bool Field::set_user_name(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002232 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002233 WideString* sError) {
2234 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04002235 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002236}
2237
dan sinclaircbe23db2017-10-19 14:29:33 -04002238bool Field::get_value(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002239 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002240 WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002241 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2242 if (FieldArray.empty())
2243 return false;
2244
2245 CPDF_FormField* pFormField = FieldArray[0];
2246 switch (pFormField->GetFieldType()) {
2247 case FIELDTYPE_PUSHBUTTON:
2248 return false;
2249 case FIELDTYPE_COMBOBOX:
dan sinclaircbe23db2017-10-19 14:29:33 -04002250 case FIELDTYPE_TEXTFIELD:
Dan Sinclaire4974922017-10-24 09:36:16 -04002251 vp->Set(pRuntime->NewString(pFormField->GetValue().c_str()));
dan sinclaircbe23db2017-10-19 14:29:33 -04002252 break;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002253 case FIELDTYPE_LISTBOX: {
2254 if (pFormField->CountSelectedItems() > 1) {
2255 CJS_Array ValueArray;
Dan Sinclaire4974922017-10-24 09:36:16 -04002256 CJS_Value ElementValue;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002257 int iIndex;
2258 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
2259 iIndex = pFormField->GetSelectedIndex(i);
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04002260 ElementValue = CJS_Value(
2261 pRuntime->NewString(pFormField->GetOptionValue(iIndex).c_str()));
Dan Sinclairc9708952017-10-23 09:40:59 -04002262 if (wcslen(ElementValue.ToWideString(pRuntime).c_str()) == 0) {
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04002263 ElementValue = CJS_Value(pRuntime->NewString(
2264 pFormField->GetOptionLabel(iIndex).c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002265 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002266 ValueArray.SetElement(pRuntime, i, ElementValue);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002267 }
Dan Sinclaire4974922017-10-24 09:36:16 -04002268 vp->Set(ValueArray.ToV8Array(pRuntime));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002269 } else {
Dan Sinclaire4974922017-10-24 09:36:16 -04002270 vp->Set(pRuntime->NewString(pFormField->GetValue().c_str()));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002271 }
dan sinclaircbe23db2017-10-19 14:29:33 -04002272 break;
2273 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002274 case FIELDTYPE_CHECKBOX:
2275 case FIELDTYPE_RADIOBUTTON: {
2276 bool bFind = false;
2277 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2278 if (pFormField->GetControl(i)->IsChecked()) {
Dan Sinclaire4974922017-10-24 09:36:16 -04002279 vp->Set(pRuntime->NewString(
2280 pFormField->GetControl(i)->GetExportValue().c_str()));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002281 bFind = true;
2282 break;
2283 }
2284 }
2285 if (!bFind)
Dan Sinclaire4974922017-10-24 09:36:16 -04002286 vp->Set(pRuntime->NewString(L"Off"));
dan sinclaircbe23db2017-10-19 14:29:33 -04002287
2288 break;
2289 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002290 default:
Dan Sinclaire4974922017-10-24 09:36:16 -04002291 vp->Set(pRuntime->NewString(pFormField->GetValue().c_str()));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002292 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002293 }
Dan Sinclair33d13f22017-10-23 09:44:30 -04002294 vp->MaybeCoerceToNumber(pRuntime);
dan sinclaircbe23db2017-10-19 14:29:33 -04002295 return true;
2296}
2297
2298bool Field::set_value(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002299 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002300 WideString* sError) {
2301 if (!m_bCanSet)
2302 return false;
2303
2304 std::vector<WideString> strArray;
Dan Sinclair33d13f22017-10-23 09:44:30 -04002305 if (vp.IsArrayObject()) {
Dan Sinclaire4974922017-10-24 09:36:16 -04002306 CJS_Array ValueArray(vp.ToArray(pRuntime));
dan sinclaircbe23db2017-10-19 14:29:33 -04002307 for (int i = 0, sz = ValueArray.GetLength(pRuntime); i < sz; i++) {
Dan Sinclaire4974922017-10-24 09:36:16 -04002308 CJS_Value ElementValue(ValueArray.GetElement(pRuntime, i));
Dan Sinclairc9708952017-10-23 09:40:59 -04002309 strArray.push_back(ElementValue.ToWideString(pRuntime));
dan sinclaircbe23db2017-10-19 14:29:33 -04002310 }
2311 } else {
Dan Sinclair33d13f22017-10-23 09:44:30 -04002312 strArray.push_back(vp.ToWideString(pRuntime));
dan sinclaircbe23db2017-10-19 14:29:33 -04002313 }
2314
2315 if (m_bDelay) {
2316 AddDelay_WideStringArray(FP_VALUE, strArray);
2317 } else {
2318 Field::SetValue(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
2319 strArray);
2320 }
tsepez4cf55152016-11-02 14:37:54 -07002321 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002322}
2323
dsinclair3a7741a2016-10-11 10:39:49 -07002324void Field::SetValue(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04002325 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002326 int nControlIndex,
Ryan Harrison275e2602017-09-18 14:23:18 -04002327 const std::vector<WideString>& strArray) {
dsinclair3a7741a2016-10-11 10:39:49 -07002328 ASSERT(pFormFillEnv);
tsepez41a53ad2016-03-28 16:59:30 -07002329 if (strArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002330 return;
2331
Lei Zhangd88a3642015-11-10 09:38:57 -08002332 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07002333 GetFormFields(pFormFillEnv, swFieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002334
Lei Zhangd88a3642015-11-10 09:38:57 -08002335 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002336 if (pFormField->GetFullName().Compare(swFieldName) != 0)
2337 continue;
2338
2339 switch (pFormField->GetFieldType()) {
2340 case FIELDTYPE_TEXTFIELD:
2341 case FIELDTYPE_COMBOBOX:
tsepez41a53ad2016-03-28 16:59:30 -07002342 if (pFormField->GetValue() != strArray[0]) {
tsepez4cf55152016-11-02 14:37:54 -07002343 pFormField->SetValue(strArray[0], true);
2344 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002345 }
2346 break;
tsepez41a53ad2016-03-28 16:59:30 -07002347 case FIELDTYPE_CHECKBOX:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002348 case FIELDTYPE_RADIOBUTTON: {
tsepez41a53ad2016-03-28 16:59:30 -07002349 if (pFormField->GetValue() != strArray[0]) {
tsepez4cf55152016-11-02 14:37:54 -07002350 pFormField->SetValue(strArray[0], true);
2351 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002352 }
2353 } break;
2354 case FIELDTYPE_LISTBOX: {
tsepez4cf55152016-11-02 14:37:54 -07002355 bool bModified = false;
tsepez41a53ad2016-03-28 16:59:30 -07002356 for (const auto& str : strArray) {
2357 if (!pFormField->IsItemSelected(pFormField->FindOption(str))) {
tsepez4cf55152016-11-02 14:37:54 -07002358 bModified = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002359 break;
2360 }
2361 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002362 if (bModified) {
tsepez4cf55152016-11-02 14:37:54 -07002363 pFormField->ClearSelection(true);
tsepez41a53ad2016-03-28 16:59:30 -07002364 for (const auto& str : strArray) {
2365 int index = pFormField->FindOption(str);
2366 if (!pFormField->IsItemSelected(index))
tsepez4cf55152016-11-02 14:37:54 -07002367 pFormField->SetItemSelection(index, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002368 }
tsepez4cf55152016-11-02 14:37:54 -07002369 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002370 }
2371 } break;
2372 default:
2373 break;
2374 }
2375 }
2376}
2377
dan sinclaircbe23db2017-10-19 14:29:33 -04002378bool Field::get_value_as_string(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002379 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002380 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002381 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2382 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002383 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002384
Lei Zhangd88a3642015-11-10 09:38:57 -08002385 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002386 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002387 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002388
2389 if (pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) {
2390 if (!pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002391 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002392
Dan Sinclaire4974922017-10-24 09:36:16 -04002393 vp->Set(pRuntime->NewString(
2394 pFormField->GetControl(0)->IsChecked() ? L"Yes" : L"Off"));
dan sinclaircbe23db2017-10-19 14:29:33 -04002395 return true;
2396 }
2397
2398 if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON &&
2399 !(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002400 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2401 if (pFormField->GetControl(i)->IsChecked()) {
Dan Sinclaire4974922017-10-24 09:36:16 -04002402 vp->Set(pRuntime->NewString(
2403 pFormField->GetControl(i)->GetExportValue().c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002404 break;
Lei Zhangd88a3642015-11-10 09:38:57 -08002405 } else {
Dan Sinclaire4974922017-10-24 09:36:16 -04002406 vp->Set(pRuntime->NewString(L"Off"));
Lei Zhangd88a3642015-11-10 09:38:57 -08002407 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002408 }
dan sinclaircbe23db2017-10-19 14:29:33 -04002409 return true;
2410 }
2411
2412 if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX &&
2413 (pFormField->CountSelectedItems() > 1)) {
Dan Sinclaire4974922017-10-24 09:36:16 -04002414 vp->Set(pRuntime->NewString(L""));
Lei Zhangd88a3642015-11-10 09:38:57 -08002415 } else {
Dan Sinclaire4974922017-10-24 09:36:16 -04002416 vp->Set(pRuntime->NewString(pFormField->GetValue().c_str()));
Lei Zhangd88a3642015-11-10 09:38:57 -08002417 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002418
tsepez4cf55152016-11-02 14:37:54 -07002419 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002420}
2421
dan sinclaircbe23db2017-10-19 14:29:33 -04002422bool Field::set_value_as_string(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002423 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002424 WideString* sError) {
2425 return false;
2426}
2427
Tom Sepezb1670b52017-02-16 17:01:00 -08002428bool Field::browseForFileToSubmit(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002429 const std::vector<CJS_Value>& params,
2430 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002431 WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002432 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2433 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002434 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002435
Lei Zhangd88a3642015-11-10 09:38:57 -08002436 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002437 if ((pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) &&
2438 (pFormField->GetFieldType() == FIELDTYPE_TEXTFIELD)) {
Ryan Harrison275e2602017-09-18 14:23:18 -04002439 WideString wsFileName = m_pFormFillEnv->JS_fieldBrowse();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002440 if (!wsFileName.IsEmpty()) {
2441 pFormField->SetValue(wsFileName);
tsepez4cf55152016-11-02 14:37:54 -07002442 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002443 }
tsepez4cf55152016-11-02 14:37:54 -07002444 return true;
Lei Zhangd88a3642015-11-10 09:38:57 -08002445 }
tsepez4cf55152016-11-02 14:37:54 -07002446 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002447}
2448
Tom Sepezb1670b52017-02-16 17:01:00 -08002449bool Field::buttonGetCaption(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002450 const std::vector<CJS_Value>& params,
2451 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002452 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002453 int nface = 0;
2454 int iSize = params.size();
2455 if (iSize >= 1)
tsepezb4694242016-08-15 16:44:55 -07002456 nface = params[0].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002457
Lei Zhangd88a3642015-11-10 09:38:57 -08002458 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2459 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002460 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002461
Lei Zhangd88a3642015-11-10 09:38:57 -08002462 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002463 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002464 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002465
2466 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2467 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -07002468 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002469
2470 if (nface == 0)
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04002471 vRet = CJS_Value(
2472 pRuntime->NewString(pFormControl->GetNormalCaption().c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002473 else if (nface == 1)
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04002474 vRet =
2475 CJS_Value(pRuntime->NewString(pFormControl->GetDownCaption().c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002476 else if (nface == 2)
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04002477 vRet = CJS_Value(
2478 pRuntime->NewString(pFormControl->GetRolloverCaption().c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002479 else
tsepez4cf55152016-11-02 14:37:54 -07002480 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002481
tsepez4cf55152016-11-02 14:37:54 -07002482 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002483}
2484
Tom Sepezb1670b52017-02-16 17:01:00 -08002485bool Field::buttonGetIcon(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002486 const std::vector<CJS_Value>& params,
2487 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002488 WideString& sError) {
Tom Sepez40e0a812017-02-23 13:07:36 -08002489 if (params.size() >= 1) {
2490 int nFace = params[0].ToInt(pRuntime);
2491 if (nFace < 0 || nFace > 2)
2492 return false;
2493 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002494
Lei Zhangd88a3642015-11-10 09:38:57 -08002495 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2496 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002497 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002498
Lei Zhangd88a3642015-11-10 09:38:57 -08002499 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002500 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002501 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002502
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002503 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2504 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -07002505 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002506
tsepezb4694242016-08-15 16:44:55 -07002507 v8::Local<v8::Object> pObj =
2508 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID);
Tom Sepezc5a14722017-02-24 15:31:12 -08002509 if (pObj.IsEmpty())
2510 return false;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002511
tsepezb4694242016-08-15 16:44:55 -07002512 CJS_Icon* pJS_Icon = static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj));
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04002513 if (pJS_Icon)
2514 vRet = CJS_Value(pJS_Icon->ToV8Object());
2515
tsepez4cf55152016-11-02 14:37:54 -07002516 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002517}
2518
Tom Sepezb1670b52017-02-16 17:01:00 -08002519bool Field::buttonImportIcon(CJS_Runtime* pRuntime,
Lei Zhang945fdb72015-11-11 10:18:16 -08002520 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002521 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002522 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002523 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002524}
2525
Tom Sepezb1670b52017-02-16 17:01:00 -08002526bool Field::buttonSetCaption(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002527 const std::vector<CJS_Value>& params,
2528 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002529 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002530 return false;
2531}
2532
Tom Sepezb1670b52017-02-16 17:01:00 -08002533bool Field::buttonSetIcon(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002534 const std::vector<CJS_Value>& params,
2535 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002536 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002537 return false;
2538}
2539
Tom Sepezb1670b52017-02-16 17:01:00 -08002540bool Field::checkThisBox(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002541 const std::vector<CJS_Value>& params,
2542 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002543 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002544 int iSize = params.size();
2545 if (iSize < 1)
tsepez4cf55152016-11-02 14:37:54 -07002546 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002547
tsepezf3dc8c62016-08-10 06:29:29 -07002548 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002549 return false;
tsepezf3dc8c62016-08-10 06:29:29 -07002550
tsepezb4694242016-08-15 16:44:55 -07002551 int nWidget = params[0].ToInt(pRuntime);
Wei Li97da9762016-03-11 17:00:48 -08002552 bool bCheckit = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002553 if (iSize >= 2)
tsepezb4694242016-08-15 16:44:55 -07002554 bCheckit = params[1].ToBool(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002555
Lei Zhangd88a3642015-11-10 09:38:57 -08002556 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2557 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002558 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002559
Lei Zhangd88a3642015-11-10 09:38:57 -08002560 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002561 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
2562 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002563 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002564 if (nWidget < 0 || nWidget >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002565 return false;
Wei Li97da9762016-03-11 17:00:48 -08002566 // TODO(weili): Check whether anything special needed for radio button,
2567 // otherwise merge these branches.
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002568 if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)
Wei Li97da9762016-03-11 17:00:48 -08002569 pFormField->CheckControl(nWidget, bCheckit, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002570 else
Wei Li97da9762016-03-11 17:00:48 -08002571 pFormField->CheckControl(nWidget, bCheckit, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002572
tsepez4cf55152016-11-02 14:37:54 -07002573 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true);
2574 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002575}
2576
Tom Sepezb1670b52017-02-16 17:01:00 -08002577bool Field::clearItems(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002578 const std::vector<CJS_Value>& params,
2579 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002580 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002581 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002582}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002583
Tom Sepezb1670b52017-02-16 17:01:00 -08002584bool Field::defaultIsChecked(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002585 const std::vector<CJS_Value>& params,
2586 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002587 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002588 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002589 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002590
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002591 int iSize = params.size();
2592 if (iSize < 1)
tsepez4cf55152016-11-02 14:37:54 -07002593 return false;
Tom Sepezf4ef3f92015-04-23 11:31:31 -07002594
tsepezb4694242016-08-15 16:44:55 -07002595 int nWidget = params[0].ToInt(pRuntime);
Lei Zhangd88a3642015-11-10 09:38:57 -08002596 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2597 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002598 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002599
Lei Zhangd88a3642015-11-10 09:38:57 -08002600 CPDF_FormField* pFormField = FieldArray[0];
tsepezf3dc8c62016-08-10 06:29:29 -07002601 if (nWidget < 0 || nWidget >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002602 return false;
tsepezf3dc8c62016-08-10 06:29:29 -07002603
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04002604 vRet = CJS_Value(pRuntime->NewBoolean(
2605 pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
2606 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002607
tsepez4cf55152016-11-02 14:37:54 -07002608 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002609}
2610
Tom Sepezb1670b52017-02-16 17:01:00 -08002611bool Field::deleteItemAt(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002612 const std::vector<CJS_Value>& params,
2613 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002614 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002615 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002616}
2617
Tom Sepezb1670b52017-02-16 17:01:00 -08002618bool Field::getArray(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002619 const std::vector<CJS_Value>& params,
2620 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002621 WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002622 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2623 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002624 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002625
Ryan Harrison275e2602017-09-18 14:23:18 -04002626 std::vector<std::unique_ptr<WideString>> swSort;
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002627 for (CPDF_FormField* pFormField : FieldArray) {
Ryan Harrison275e2602017-09-18 14:23:18 -04002628 swSort.push_back(
2629 std::unique_ptr<WideString>(new WideString(pFormField->GetFullName())));
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002630 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002631
Ryan Harrison275e2602017-09-18 14:23:18 -04002632 std::sort(swSort.begin(), swSort.end(),
2633 [](const std::unique_ptr<WideString>& p1,
2634 const std::unique_ptr<WideString>& p2) { return *p1 < *p2; });
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002635
tsepeze5aff742016-08-08 09:49:42 -07002636 CJS_Array FormFieldArray;
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002637
2638 int j = 0;
2639 for (const auto& pStr : swSort) {
tsepezb4694242016-08-15 16:44:55 -07002640 v8::Local<v8::Object> pObj =
2641 pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID);
Tom Sepezc5a14722017-02-24 15:31:12 -08002642 if (pObj.IsEmpty())
2643 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002644
Tom Sepezd5a0e952015-09-17 15:40:06 -07002645 CJS_Field* pJSField =
tsepezb4694242016-08-15 16:44:55 -07002646 static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pObj));
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002647 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002648 pField->AttachField(m_pJSDoc, *pStr);
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04002649 FormFieldArray.SetElement(
2650 pRuntime, j++,
2651 pJSField ? CJS_Value(pJSField->ToV8Object()) : CJS_Value());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002652 }
2653
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04002654 vRet = CJS_Value(FormFieldArray.ToV8Array(pRuntime));
tsepez4cf55152016-11-02 14:37:54 -07002655 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002656}
2657
Tom Sepezb1670b52017-02-16 17:01:00 -08002658bool Field::getItemAt(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002659 const std::vector<CJS_Value>& params,
2660 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002661 WideString& sError) {
tsepezf3dc8c62016-08-10 06:29:29 -07002662 int iSize = params.size();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002663 int nIdx = -1;
2664 if (iSize >= 1)
tsepezb4694242016-08-15 16:44:55 -07002665 nIdx = params[0].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002666
tsepez4cf55152016-11-02 14:37:54 -07002667 bool bExport = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002668 if (iSize >= 2)
tsepezb4694242016-08-15 16:44:55 -07002669 bExport = params[1].ToBool(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002670
Lei Zhangd88a3642015-11-10 09:38:57 -08002671 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2672 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002673 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002674
Lei Zhangd88a3642015-11-10 09:38:57 -08002675 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002676 if ((pFormField->GetFieldType() == FIELDTYPE_LISTBOX) ||
2677 (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX)) {
2678 if (nIdx == -1 || nIdx > pFormField->CountOptions())
2679 nIdx = pFormField->CountOptions() - 1;
2680 if (bExport) {
Ryan Harrison275e2602017-09-18 14:23:18 -04002681 WideString strval = pFormField->GetOptionValue(nIdx);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002682 if (strval.IsEmpty())
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04002683 vRet = CJS_Value(
2684 pRuntime->NewString(pFormField->GetOptionLabel(nIdx).c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002685 else
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04002686 vRet = CJS_Value(pRuntime->NewString(strval.c_str()));
Lei Zhangd88a3642015-11-10 09:38:57 -08002687 } else {
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04002688 vRet = CJS_Value(
2689 pRuntime->NewString(pFormField->GetOptionLabel(nIdx).c_str()));
Lei Zhangd88a3642015-11-10 09:38:57 -08002690 }
2691 } else {
tsepez4cf55152016-11-02 14:37:54 -07002692 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08002693 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002694
tsepez4cf55152016-11-02 14:37:54 -07002695 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002696}
2697
Tom Sepezb1670b52017-02-16 17:01:00 -08002698bool Field::getLock(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002699 const std::vector<CJS_Value>& params,
2700 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002701 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002702 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002703}
2704
Tom Sepezb1670b52017-02-16 17:01:00 -08002705bool Field::insertItemAt(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002706 const std::vector<CJS_Value>& params,
2707 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002708 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002709 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002710}
2711
Tom Sepezb1670b52017-02-16 17:01:00 -08002712bool Field::isBoxChecked(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002713 const std::vector<CJS_Value>& params,
2714 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002715 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002716 int nIndex = -1;
2717 if (params.size() >= 1)
tsepezb4694242016-08-15 16:44:55 -07002718 nIndex = params[0].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002719
Lei Zhangd88a3642015-11-10 09:38:57 -08002720 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2721 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002722 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002723
Lei Zhangd88a3642015-11-10 09:38:57 -08002724 CPDF_FormField* pFormField = FieldArray[0];
dan sinclair646634b2017-10-19 14:30:28 -04002725 if (nIndex < 0 || nIndex >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002726 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002727
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04002728 vRet = CJS_Value(pRuntime->NewBoolean(
2729 ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
2730 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) &&
2731 pFormField->GetControl(nIndex)->IsChecked() != 0)));
tsepez4cf55152016-11-02 14:37:54 -07002732 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002733}
2734
Tom Sepezb1670b52017-02-16 17:01:00 -08002735bool Field::isDefaultChecked(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002736 const std::vector<CJS_Value>& params,
2737 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002738 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002739 int nIndex = -1;
2740 if (params.size() >= 1)
tsepezb4694242016-08-15 16:44:55 -07002741 nIndex = params[0].ToInt(pRuntime);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002742
Lei Zhangd88a3642015-11-10 09:38:57 -08002743 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2744 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002745 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002746
Lei Zhangd88a3642015-11-10 09:38:57 -08002747 CPDF_FormField* pFormField = FieldArray[0];
tsepezf3dc8c62016-08-10 06:29:29 -07002748 if (nIndex < 0 || nIndex >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002749 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002750
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04002751 vRet = CJS_Value(pRuntime->NewBoolean(
2752 ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
2753 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) &&
2754 pFormField->GetControl(nIndex)->IsDefaultChecked() != 0)));
tsepez4cf55152016-11-02 14:37:54 -07002755 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002756}
2757
Tom Sepezb1670b52017-02-16 17:01:00 -08002758bool Field::setAction(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002759 const std::vector<CJS_Value>& params,
2760 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002761 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002762 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002763}
2764
Tom Sepezb1670b52017-02-16 17:01:00 -08002765bool Field::setFocus(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002766 const std::vector<CJS_Value>& params,
2767 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002768 WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002769 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2770 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002771 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002772
Lei Zhangd88a3642015-11-10 09:38:57 -08002773 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002774 int32_t nCount = pFormField->CountControls();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002775 if (nCount < 1)
tsepez4cf55152016-11-02 14:37:54 -07002776 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002777
dsinclair7cbe68e2016-10-12 11:56:23 -07002778 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
thestig1cd352e2016-06-07 17:53:06 -07002779 CPDFSDK_Widget* pWidget = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002780 if (nCount == 1) {
dsinclairc5267c52016-11-04 15:35:12 -07002781 pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002782 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002783 UnderlyingPageType* pPage =
2784 UnderlyingFromFPDFPage(m_pFormFillEnv->GetCurrentPage(
2785 m_pFormFillEnv->GetUnderlyingDocument()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002786 if (!pPage)
tsepez4cf55152016-11-02 14:37:54 -07002787 return false;
dsinclair461eeaf2016-07-27 07:40:05 -07002788 if (CPDFSDK_PageView* pCurPageView =
dsinclair7cbe68e2016-10-12 11:56:23 -07002789 m_pFormFillEnv->GetPageView(pPage, true)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002790 for (int32_t i = 0; i < nCount; i++) {
2791 if (CPDFSDK_Widget* pTempWidget =
dsinclairc5267c52016-11-04 15:35:12 -07002792 pInterForm->GetWidget(pFormField->GetControl(i))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002793 if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage()) {
2794 pWidget = pTempWidget;
2795 break;
2796 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002797 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002798 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002799 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002800 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002801
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002802 if (pWidget) {
tsepezf8074ce2016-09-27 14:29:57 -07002803 CPDFSDK_Annot::ObservedPtr pObserved(pWidget);
dsinclair7cbe68e2016-10-12 11:56:23 -07002804 m_pFormFillEnv->SetFocusAnnot(&pObserved);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002805 }
2806
tsepez4cf55152016-11-02 14:37:54 -07002807 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002808}
2809
Tom Sepezb1670b52017-02-16 17:01:00 -08002810bool Field::setItems(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002811 const std::vector<CJS_Value>& params,
2812 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002813 WideString& sError) {
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::setLock(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002818 const std::vector<CJS_Value>& params,
2819 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002820 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002821 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002822}
2823
Tom Sepezb1670b52017-02-16 17:01:00 -08002824bool Field::signatureGetModifications(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002825 const std::vector<CJS_Value>& params,
2826 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002827 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002828 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002829}
2830
Tom Sepezb1670b52017-02-16 17:01:00 -08002831bool Field::signatureGetSeedValue(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002832 const std::vector<CJS_Value>& params,
2833 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002834 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002835 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002836}
2837
Tom Sepezb1670b52017-02-16 17:01:00 -08002838bool Field::signatureInfo(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002839 const std::vector<CJS_Value>& params,
2840 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002841 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002842 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002843}
2844
Tom Sepezb1670b52017-02-16 17:01:00 -08002845bool Field::signatureSetSeedValue(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002846 const std::vector<CJS_Value>& params,
2847 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002848 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002849 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002850}
2851
Tom Sepezb1670b52017-02-16 17:01:00 -08002852bool Field::signatureSign(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002853 const std::vector<CJS_Value>& params,
2854 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002855 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002856 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002857}
2858
Tom Sepezb1670b52017-02-16 17:01:00 -08002859bool Field::signatureValidate(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002860 const std::vector<CJS_Value>& params,
2861 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002862 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002863 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002864}
2865
dan sinclaircbe23db2017-10-19 14:29:33 -04002866bool Field::get_source(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002867 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002868 WideString* sError) {
Dan Sinclaire4974922017-10-24 09:36:16 -04002869 vp->Set(v8::Local<v8::Value>());
dan sinclaircbe23db2017-10-19 14:29:33 -04002870 return true;
2871}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002872
dan sinclaircbe23db2017-10-19 14:29:33 -04002873bool Field::set_source(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002874 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002875 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -07002876 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002877}
2878
tsepez41a53ad2016-03-28 16:59:30 -07002879void Field::AddDelay_Int(FIELD_PROP prop, int32_t n) {
2880 CJS_DelayData* pNewData =
2881 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002882 pNewData->num = n;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002883 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002884}
2885
tsepez41a53ad2016-03-28 16:59:30 -07002886void Field::AddDelay_Bool(FIELD_PROP prop, bool b) {
2887 CJS_DelayData* pNewData =
2888 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002889 pNewData->b = b;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002890 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002891}
2892
Ryan Harrison275e2602017-09-18 14:23:18 -04002893void Field::AddDelay_String(FIELD_PROP prop, const ByteString& string) {
tsepez41a53ad2016-03-28 16:59:30 -07002894 CJS_DelayData* pNewData =
2895 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002896 pNewData->string = string;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002897 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002898}
2899
tsepez41a53ad2016-03-28 16:59:30 -07002900void Field::AddDelay_Rect(FIELD_PROP prop, const CFX_FloatRect& rect) {
2901 CJS_DelayData* pNewData =
2902 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002903 pNewData->rect = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002904 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002905}
2906
tsepez41a53ad2016-03-28 16:59:30 -07002907void Field::AddDelay_WordArray(FIELD_PROP prop,
2908 const std::vector<uint32_t>& array) {
2909 CJS_DelayData* pNewData =
2910 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
2911 pNewData->wordarray = array;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002912 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002913}
2914
tsepez41a53ad2016-03-28 16:59:30 -07002915void Field::AddDelay_WideStringArray(FIELD_PROP prop,
Ryan Harrison275e2602017-09-18 14:23:18 -04002916 const std::vector<WideString>& array) {
tsepez41a53ad2016-03-28 16:59:30 -07002917 CJS_DelayData* pNewData =
2918 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
2919 pNewData->widestringarray = array;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002920 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002921}
2922
dsinclair3a7741a2016-10-11 10:39:49 -07002923void Field::DoDelay(CPDFSDK_FormFillEnvironment* pFormFillEnv,
2924 CJS_DelayData* pData) {
2925 ASSERT(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002926 switch (pData->eProp) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002927 case FP_BORDERSTYLE:
dsinclair3a7741a2016-10-11 10:39:49 -07002928 Field::SetBorderStyle(pFormFillEnv, pData->sFieldName,
2929 pData->nControlIndex, pData->string);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002930 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002931 case FP_CURRENTVALUEINDICES:
dsinclair3a7741a2016-10-11 10:39:49 -07002932 Field::SetCurrentValueIndices(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002933 pData->nControlIndex, pData->wordarray);
2934 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002935 case FP_DISPLAY:
dsinclair3a7741a2016-10-11 10:39:49 -07002936 Field::SetDisplay(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002937 pData->num);
2938 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002939 case FP_HIDDEN:
dsinclair3a7741a2016-10-11 10:39:49 -07002940 Field::SetHidden(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002941 pData->b);
2942 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002943 case FP_LINEWIDTH:
dsinclair3a7741a2016-10-11 10:39:49 -07002944 Field::SetLineWidth(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002945 pData->num);
2946 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002947 case FP_RECT:
dsinclair3a7741a2016-10-11 10:39:49 -07002948 Field::SetRect(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002949 pData->rect);
2950 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002951 case FP_VALUE:
dsinclair3a7741a2016-10-11 10:39:49 -07002952 Field::SetValue(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002953 pData->widestringarray);
2954 break;
dan sinclair646634b2017-10-19 14:30:28 -04002955 default:
2956 NOTREACHED();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002957 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002958}