blob: 0ed0594b3b3b0d24440a43d6a3a554888ba4e0ae [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
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400474 ByteString byte_str =
475 ByteString::FromUnicode(pRuntime->ToWideString(vp.ToV8Value()));
dan sinclaircbe23db2017-10-19 14:29:33 -0400476 if (m_bDelay) {
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400477 AddDelay_String(FP_BORDERSTYLE, byte_str);
dan sinclaircbe23db2017-10-19 14:29:33 -0400478 } else {
479 Field::SetBorderStyle(m_pFormFillEnv.Get(), m_FieldName,
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400480 m_nFormControlIndex, byte_str);
dan sinclaircbe23db2017-10-19 14:29:33 -0400481 }
tsepez4cf55152016-11-02 14:37:54 -0700482 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700483}
484
dsinclair3a7741a2016-10-11 10:39:49 -0700485void Field::SetBorderStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -0400486 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700487 int nControlIndex,
Ryan Harrison275e2602017-09-18 14:23:18 -0400488 const ByteString& string) {
dsinclair3a7741a2016-10-11 10:39:49 -0700489 ASSERT(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700490
dsinclair92cb5e52016-05-16 11:38:28 -0700491 BorderStyle nBorderStyle = BorderStyle::SOLID;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700492 if (string == "solid")
dsinclair92cb5e52016-05-16 11:38:28 -0700493 nBorderStyle = BorderStyle::SOLID;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700494 else if (string == "beveled")
dsinclair92cb5e52016-05-16 11:38:28 -0700495 nBorderStyle = BorderStyle::BEVELED;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700496 else if (string == "dashed")
dsinclair92cb5e52016-05-16 11:38:28 -0700497 nBorderStyle = BorderStyle::DASH;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700498 else if (string == "inset")
dsinclair92cb5e52016-05-16 11:38:28 -0700499 nBorderStyle = BorderStyle::INSET;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700500 else if (string == "underline")
dsinclair92cb5e52016-05-16 11:38:28 -0700501 nBorderStyle = BorderStyle::UNDERLINE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700502 else
503 return;
504
Lei Zhangd88a3642015-11-10 09:38:57 -0800505 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -0700506 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -0800507 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700508 if (nControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -0700509 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -0800510 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700511 if (CPDFSDK_Widget* pWidget =
dsinclairc5267c52016-11-04 15:35:12 -0700512 GetWidget(pFormFillEnv, pFormField->GetControl(i))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700513 if (pWidget->GetBorderStyle() != nBorderStyle) {
514 pWidget->SetBorderStyle(nBorderStyle);
tsepez4cf55152016-11-02 14:37:54 -0700515 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700516 }
517 }
518 }
519 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -0700520 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700521 } else {
522 if (nControlIndex >= pFormField->CountControls())
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700523 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700524 if (CPDF_FormControl* pFormControl =
525 pFormField->GetControl(nControlIndex)) {
dsinclairc5267c52016-11-04 15:35:12 -0700526 if (CPDFSDK_Widget* pWidget = GetWidget(pFormFillEnv, pFormControl)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700527 if (pWidget->GetBorderStyle() != nBorderStyle) {
528 pWidget->SetBorderStyle(nBorderStyle);
tsepez4cf55152016-11-02 14:37:54 -0700529 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700530 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700531 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700532 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700533 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700534 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700535}
536
dan sinclaircbe23db2017-10-19 14:29:33 -0400537bool Field::get_button_align_x(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400538 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400539 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700540 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700541
dan sinclaircbe23db2017-10-19 14:29:33 -0400542 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
543 if (FieldArray.empty())
544 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700545
dan sinclaircbe23db2017-10-19 14:29:33 -0400546 CPDF_FormField* pFormField = FieldArray[0];
547 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
548 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700549
dan sinclaircbe23db2017-10-19 14:29:33 -0400550 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
551 if (!pFormControl)
552 return false;
553
554 CPDF_IconFit IconFit = pFormControl->GetIconFit();
555
556 float fLeft;
557 float fBottom;
558 IconFit.GetIconPosition(fLeft, fBottom);
559
Dan Sinclaire4974922017-10-24 09:36:16 -0400560 vp->Set(pRuntime->NewNumber(static_cast<int32_t>(fLeft)));
dan sinclaircbe23db2017-10-19 14:29:33 -0400561 return true;
562}
563
564bool Field::set_button_align_x(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400565 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400566 WideString* sError) {
567 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400568 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700569}
570
dan sinclaircbe23db2017-10-19 14:29:33 -0400571bool Field::get_button_align_y(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400572 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400573 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700574 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700575
dan sinclaircbe23db2017-10-19 14:29:33 -0400576 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
577 if (FieldArray.empty())
578 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700579
dan sinclaircbe23db2017-10-19 14:29:33 -0400580 CPDF_FormField* pFormField = FieldArray[0];
581 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
582 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700583
dan sinclaircbe23db2017-10-19 14:29:33 -0400584 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
585 if (!pFormControl)
586 return false;
587
588 CPDF_IconFit IconFit = pFormControl->GetIconFit();
589
590 float fLeft;
591 float fBottom;
592 IconFit.GetIconPosition(fLeft, fBottom);
593
Dan Sinclaire4974922017-10-24 09:36:16 -0400594 vp->Set(pRuntime->NewNumber(static_cast<int32_t>(fBottom)));
dan sinclaircbe23db2017-10-19 14:29:33 -0400595 return true;
596}
597
598bool Field::set_button_align_y(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400599 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400600 WideString* sError) {
601 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400602 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700603}
604
dan sinclaircbe23db2017-10-19 14:29:33 -0400605bool Field::get_button_fit_bounds(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400606 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400607 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700608 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700609
dan sinclair646634b2017-10-19 14:30:28 -0400610 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
611 if (FieldArray.empty())
612 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700613
dan sinclair646634b2017-10-19 14:30:28 -0400614 CPDF_FormField* pFormField = FieldArray[0];
615 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
616 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700617
dan sinclair646634b2017-10-19 14:30:28 -0400618 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
619 if (!pFormControl)
620 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700621
Dan Sinclaire4974922017-10-24 09:36:16 -0400622 vp->Set(pRuntime->NewBoolean(pFormControl->GetIconFit().GetFittingBounds()));
dan sinclair646634b2017-10-19 14:30:28 -0400623 return true;
dan sinclaircbe23db2017-10-19 14:29:33 -0400624}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700625
dan sinclaircbe23db2017-10-19 14:29:33 -0400626bool Field::set_button_fit_bounds(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400627 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400628 WideString* sError) {
629 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400630 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700631}
632
dan sinclaircbe23db2017-10-19 14:29:33 -0400633bool Field::get_button_position(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400634 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400635 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700636 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700637
dan sinclair646634b2017-10-19 14:30:28 -0400638 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
639 if (FieldArray.empty())
640 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700641
dan sinclair646634b2017-10-19 14:30:28 -0400642 CPDF_FormField* pFormField = FieldArray[0];
643 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
644 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700645
dan sinclair646634b2017-10-19 14:30:28 -0400646 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
647 if (!pFormControl)
648 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700649
Dan Sinclaire4974922017-10-24 09:36:16 -0400650 vp->Set(pRuntime->NewNumber(pFormControl->GetTextPosition()));
dan sinclair646634b2017-10-19 14:30:28 -0400651 return true;
dan sinclaircbe23db2017-10-19 14:29:33 -0400652}
653
654bool Field::set_button_position(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400655 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400656 WideString* sError) {
657 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400658 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700659}
660
dan sinclaircbe23db2017-10-19 14:29:33 -0400661bool Field::get_button_scale_how(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400662 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400663 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700664 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700665
dan sinclair646634b2017-10-19 14:30:28 -0400666 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
667 if (FieldArray.empty())
668 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700669
dan sinclair646634b2017-10-19 14:30:28 -0400670 CPDF_FormField* pFormField = FieldArray[0];
671 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
672 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700673
dan sinclair646634b2017-10-19 14:30:28 -0400674 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
675 if (!pFormControl)
676 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700677
Dan Sinclaire4974922017-10-24 09:36:16 -0400678 vp->Set(pRuntime->NewBoolean(
679 pFormControl->GetIconFit().IsProportionalScale() ? 0 : 1));
dan sinclair646634b2017-10-19 14:30:28 -0400680 return true;
dan sinclaircbe23db2017-10-19 14:29:33 -0400681}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700682
dan sinclaircbe23db2017-10-19 14:29:33 -0400683bool Field::set_button_scale_how(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400684 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400685 WideString* sError) {
686 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400687 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700688}
689
dan sinclaircbe23db2017-10-19 14:29:33 -0400690bool Field::get_button_scale_when(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400691 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400692 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700693 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700694
dan sinclair646634b2017-10-19 14:30:28 -0400695 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
696 if (FieldArray.empty())
697 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700698
dan sinclair646634b2017-10-19 14:30:28 -0400699 CPDF_FormField* pFormField = FieldArray[0];
700 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
701 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700702
dan sinclair646634b2017-10-19 14:30:28 -0400703 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
704 if (!pFormControl)
705 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700706
dan sinclair646634b2017-10-19 14:30:28 -0400707 CPDF_IconFit IconFit = pFormControl->GetIconFit();
708 int ScaleM = IconFit.GetScaleMethod();
709 switch (ScaleM) {
710 case CPDF_IconFit::Always:
Dan Sinclaire4974922017-10-24 09:36:16 -0400711 vp->Set(pRuntime->NewNumber(static_cast<int32_t>(CPDF_IconFit::Always)));
dan sinclair646634b2017-10-19 14:30:28 -0400712 break;
713 case CPDF_IconFit::Bigger:
Dan Sinclaire4974922017-10-24 09:36:16 -0400714 vp->Set(pRuntime->NewNumber(static_cast<int32_t>(CPDF_IconFit::Bigger)));
dan sinclair646634b2017-10-19 14:30:28 -0400715 break;
716 case CPDF_IconFit::Never:
Dan Sinclaire4974922017-10-24 09:36:16 -0400717 vp->Set(pRuntime->NewNumber(static_cast<int32_t>(CPDF_IconFit::Never)));
dan sinclair646634b2017-10-19 14:30:28 -0400718 break;
719 case CPDF_IconFit::Smaller:
Dan Sinclaire4974922017-10-24 09:36:16 -0400720 vp->Set(pRuntime->NewNumber(static_cast<int32_t>(CPDF_IconFit::Smaller)));
dan sinclair646634b2017-10-19 14:30:28 -0400721 break;
722 }
723 return true;
dan sinclaircbe23db2017-10-19 14:29:33 -0400724}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700725
dan sinclaircbe23db2017-10-19 14:29:33 -0400726bool Field::set_button_scale_when(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400727 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400728 WideString* sError) {
729 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400730 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700731}
732
dan sinclaircbe23db2017-10-19 14:29:33 -0400733bool Field::get_calc_order_index(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400734 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400735 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700736 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700737
dan sinclair646634b2017-10-19 14:30:28 -0400738 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
739 if (FieldArray.empty())
740 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700741
dan sinclair646634b2017-10-19 14:30:28 -0400742 CPDF_FormField* pFormField = FieldArray[0];
743 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
744 pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) {
745 return false;
746 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700747
dan sinclair646634b2017-10-19 14:30:28 -0400748 CPDFSDK_InterForm* pRDInterForm = m_pFormFillEnv->GetInterForm();
749 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
Dan Sinclaire4974922017-10-24 09:36:16 -0400750 vp->Set(pRuntime->NewNumber(static_cast<int32_t>(
751 pInterForm->FindFieldInCalculationOrder(pFormField))));
dan sinclair646634b2017-10-19 14:30:28 -0400752 return true;
dan sinclaircbe23db2017-10-19 14:29:33 -0400753}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700754
dan sinclaircbe23db2017-10-19 14:29:33 -0400755bool Field::set_calc_order_index(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400756 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400757 WideString* sError) {
758 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400759 return m_bCanSet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700760}
761
dan sinclaircbe23db2017-10-19 14:29:33 -0400762bool Field::get_char_limit(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400763 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400764 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700765 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700766
dan sinclaircbe23db2017-10-19 14:29:33 -0400767 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
768 if (FieldArray.empty())
769 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700770
dan sinclaircbe23db2017-10-19 14:29:33 -0400771 CPDF_FormField* pFormField = FieldArray[0];
772 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
773 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700774
Dan Sinclaire4974922017-10-24 09:36:16 -0400775 vp->Set(pRuntime->NewNumber(static_cast<int32_t>(pFormField->GetMaxLen())));
dan sinclaircbe23db2017-10-19 14:29:33 -0400776 return true;
777}
778
779bool Field::set_char_limit(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400780 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400781 WideString* sError) {
782 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400783 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700784}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700785
Dan Sinclair33d13f22017-10-23 09:44:30 -0400786bool Field::get_comb(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700787 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700788
dan sinclaircbe23db2017-10-19 14:29:33 -0400789 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
790 if (FieldArray.empty())
791 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700792
dan sinclaircbe23db2017-10-19 14:29:33 -0400793 CPDF_FormField* pFormField = FieldArray[0];
794 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
795 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700796
Dan Sinclaire4974922017-10-24 09:36:16 -0400797 vp->Set(
798 pRuntime->NewBoolean(!!(pFormField->GetFieldFlags() & FIELDFLAG_COMB)));
dan sinclaircbe23db2017-10-19 14:29:33 -0400799 return true;
800}
801
802bool Field::set_comb(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400803 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400804 WideString* sError) {
805 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400806 return m_bCanSet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700807}
808
dan sinclaircbe23db2017-10-19 14:29:33 -0400809bool Field::get_commit_on_sel_change(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400810 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400811 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700812 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700813
dan sinclair646634b2017-10-19 14:30:28 -0400814 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
815 if (FieldArray.empty())
816 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700817
dan sinclair646634b2017-10-19 14:30:28 -0400818 CPDF_FormField* pFormField = FieldArray[0];
819 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
820 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
821 return false;
822 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700823
Dan Sinclaire4974922017-10-24 09:36:16 -0400824 vp->Set(pRuntime->NewBoolean(
825 !!(pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE)));
dan sinclair646634b2017-10-19 14:30:28 -0400826 return true;
dan sinclaircbe23db2017-10-19 14:29:33 -0400827}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700828
dan sinclaircbe23db2017-10-19 14:29:33 -0400829bool Field::set_commit_on_sel_change(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400830 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400831 WideString* sError) {
832 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400833 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700834}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700835
dan sinclaircbe23db2017-10-19 14:29:33 -0400836bool Field::get_current_value_indices(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400837 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400838 WideString* sError) {
839 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
840 if (FieldArray.empty())
841 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700842
dan sinclaircbe23db2017-10-19 14:29:33 -0400843 CPDF_FormField* pFormField = FieldArray[0];
844 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
845 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
846 return false;
847 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700848
dan sinclaircbe23db2017-10-19 14:29:33 -0400849 int count = pFormField->CountSelectedItems();
850 if (count <= 0) {
Dan Sinclaire4974922017-10-24 09:36:16 -0400851 vp->Set(pRuntime->NewNumber(-1));
dan sinclaircbe23db2017-10-19 14:29:33 -0400852 return true;
853 }
854 if (count == 1) {
Dan Sinclaire4974922017-10-24 09:36:16 -0400855 vp->Set(pRuntime->NewNumber(pFormField->GetSelectedIndex(0)));
dan sinclaircbe23db2017-10-19 14:29:33 -0400856 return true;
857 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700858
dan sinclaircbe23db2017-10-19 14:29:33 -0400859 CJS_Array SelArray;
860 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -0400861 SelArray.SetElement(
862 pRuntime, i,
863 CJS_Value(pRuntime->NewNumber(pFormField->GetSelectedIndex(i))));
dan sinclaircbe23db2017-10-19 14:29:33 -0400864 }
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400865 if (SelArray.ToV8Value().IsEmpty())
866 vp->Set(pRuntime->NewArray());
867 else
868 vp->Set(SelArray.ToV8Value());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700869
dan sinclaircbe23db2017-10-19 14:29:33 -0400870 return true;
871}
872
873bool Field::set_current_value_indices(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400874 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400875 WideString* sError) {
876 if (!m_bCanSet)
877 return false;
878
879 std::vector<uint32_t> array;
Dan Sinclair3cac3602017-10-24 15:15:27 -0400880 if (vp.ToV8Value()->IsNumber()) {
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400881 array.push_back(pRuntime->ToInt32(vp.ToV8Value()));
Dan Sinclair33d13f22017-10-23 09:44:30 -0400882 } else if (vp.IsArrayObject()) {
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400883 CJS_Array SelArray(pRuntime->ToArray(vp.ToV8Value()));
Dan Sinclairc9708952017-10-23 09:40:59 -0400884 for (int i = 0, sz = SelArray.GetLength(pRuntime); i < sz; i++)
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400885 array.push_back(
886 pRuntime->ToInt32(SelArray.GetElement(pRuntime, i).ToV8Value()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700887 }
888
dan sinclaircbe23db2017-10-19 14:29:33 -0400889 if (m_bDelay) {
890 AddDelay_WordArray(FP_CURRENTVALUEINDICES, array);
891 } else {
892 Field::SetCurrentValueIndices(m_pFormFillEnv.Get(), m_FieldName,
893 m_nFormControlIndex, array);
894 }
tsepez4cf55152016-11-02 14:37:54 -0700895 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700896}
897
dsinclair3a7741a2016-10-11 10:39:49 -0700898void Field::SetCurrentValueIndices(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -0400899 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700900 int nControlIndex,
tsepez41a53ad2016-03-28 16:59:30 -0700901 const std::vector<uint32_t>& array) {
dsinclair3a7741a2016-10-11 10:39:49 -0700902 ASSERT(pFormFillEnv);
Lei Zhangd88a3642015-11-10 09:38:57 -0800903 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -0700904 GetFormFields(pFormFillEnv, swFieldName);
tsepez41a53ad2016-03-28 16:59:30 -0700905
Lei Zhangd88a3642015-11-10 09:38:57 -0800906 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700907 int nFieldType = pFormField->GetFieldType();
908 if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX) {
tsepezc3255f52016-03-25 14:52:27 -0700909 uint32_t dwFieldFlags = pFormField->GetFieldFlags();
tsepez4cf55152016-11-02 14:37:54 -0700910 pFormField->ClearSelection(true);
tsepez41a53ad2016-03-28 16:59:30 -0700911 for (size_t i = 0; i < array.size(); ++i) {
912 if (i != 0 && !(dwFieldFlags & (1 << 21)))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700913 break;
Wei Li05d53f02016-03-29 16:42:53 -0700914 if (array[i] < static_cast<uint32_t>(pFormField->CountOptions()) &&
tsepez41a53ad2016-03-28 16:59:30 -0700915 !pFormField->IsItemSelected(array[i])) {
tsepez4cf55152016-11-02 14:37:54 -0700916 pFormField->SetItemSelection(array[i], true);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700917 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700918 }
tsepez4cf55152016-11-02 14:37:54 -0700919 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700920 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700921 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700922}
923
dan sinclaircbe23db2017-10-19 14:29:33 -0400924bool Field::get_default_style(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400925 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400926 WideString* sError) {
927 return false;
928}
929
930bool Field::set_default_style(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400931 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400932 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -0700933 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700934}
935
dan sinclaircbe23db2017-10-19 14:29:33 -0400936bool Field::get_default_value(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400937 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400938 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700939 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700940
Lei Zhangd88a3642015-11-10 09:38:57 -0800941 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
942 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700943 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700944
Lei Zhangd88a3642015-11-10 09:38:57 -0800945 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700946 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON ||
Lei Zhangd88a3642015-11-10 09:38:57 -0800947 pFormField->GetFieldType() == FIELDTYPE_SIGNATURE) {
tsepez4cf55152016-11-02 14:37:54 -0700948 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -0800949 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700950
Dan Sinclaire4974922017-10-24 09:36:16 -0400951 vp->Set(pRuntime->NewString(pFormField->GetDefaultValue().c_str()));
dan sinclaircbe23db2017-10-19 14:29:33 -0400952 return true;
953}
954
955bool Field::set_default_value(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400956 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400957 WideString* sError) {
958 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400959 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700960}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700961
dan sinclaircbe23db2017-10-19 14:29:33 -0400962bool Field::get_do_not_scroll(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400963 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400964 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700965 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700966
dan sinclaircbe23db2017-10-19 14:29:33 -0400967 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
968 if (FieldArray.empty())
969 return false;
970
971 CPDF_FormField* pFormField = FieldArray[0];
972 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
973 return false;
974
Dan Sinclaire4974922017-10-24 09:36:16 -0400975 vp->Set(pRuntime->NewBoolean(
976 !!(pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL)));
dan sinclaircbe23db2017-10-19 14:29:33 -0400977 return true;
978}
979
980bool Field::set_do_not_scroll(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400981 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400982 WideString* sError) {
983 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400984 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700985}
986
dan sinclaircbe23db2017-10-19 14:29:33 -0400987bool Field::get_do_not_spell_check(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400988 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400989 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700990 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700991
dan sinclair646634b2017-10-19 14:30:28 -0400992 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
993 if (FieldArray.empty())
994 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700995
dan sinclair646634b2017-10-19 14:30:28 -0400996 CPDF_FormField* pFormField = FieldArray[0];
997 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD &&
998 pFormField->GetFieldType() != FIELDTYPE_COMBOBOX) {
999 return false;
1000 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001001
Dan Sinclaire4974922017-10-24 09:36:16 -04001002 vp->Set(pRuntime->NewBoolean(
1003 !!(pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK)));
dan sinclair646634b2017-10-19 14:30:28 -04001004 return true;
dan sinclaircbe23db2017-10-19 14:29:33 -04001005}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001006
dan sinclaircbe23db2017-10-19 14:29:33 -04001007bool Field::set_do_not_spell_check(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001008 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001009 WideString* sError) {
1010 ASSERT(m_pFormFillEnv);
1011 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001012}
1013
tsepez4cf55152016-11-02 14:37:54 -07001014void Field::SetDelay(bool bDelay) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001015 m_bDelay = bDelay;
1016
dan sinclaircbe23db2017-10-19 14:29:33 -04001017 if (m_bDelay)
1018 return;
dan sinclaircbe23db2017-10-19 14:29:33 -04001019 if (m_pJSDoc)
1020 m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001021}
1022
dan sinclaircbe23db2017-10-19 14:29:33 -04001023bool Field::get_delay(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001024 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001025 WideString* sError) {
Dan Sinclaire4974922017-10-24 09:36:16 -04001026 vp->Set(pRuntime->NewBoolean(m_bDelay));
tsepez4cf55152016-11-02 14:37:54 -07001027 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001028}
1029
dan sinclaircbe23db2017-10-19 14:29:33 -04001030bool Field::set_delay(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001031 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001032 WideString* sError) {
1033 if (!m_bCanSet)
1034 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001035
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04001036 SetDelay(pRuntime->ToBoolean(vp.ToV8Value()));
dan sinclaircbe23db2017-10-19 14:29:33 -04001037 return true;
1038}
1039
1040bool Field::get_display(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001041 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001042 WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001043 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1044 if (FieldArray.empty())
1045 return false;
1046
1047 CPDF_FormField* pFormField = FieldArray[0];
1048 ASSERT(pFormField);
dan sinclaircbe23db2017-10-19 14:29:33 -04001049
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001050 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1051 CPDFSDK_Widget* pWidget =
1052 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1053 if (!pWidget)
1054 return false;
1055
1056 uint32_t dwFlag = pWidget->GetFlags();
1057 if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag) {
Dan Sinclaire4974922017-10-24 09:36:16 -04001058 vp->Set(pRuntime->NewNumber(1));
dan sinclaircbe23db2017-10-19 14:29:33 -04001059 return true;
1060 }
1061 if (ANNOTFLAG_PRINT & dwFlag) {
1062 if (ANNOTFLAG_NOVIEW & dwFlag)
Dan Sinclaire4974922017-10-24 09:36:16 -04001063 vp->Set(pRuntime->NewNumber(3));
dan sinclaircbe23db2017-10-19 14:29:33 -04001064 else
Dan Sinclaire4974922017-10-24 09:36:16 -04001065 vp->Set(pRuntime->NewNumber(0));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001066 } else {
Dan Sinclaire4974922017-10-24 09:36:16 -04001067 vp->Set(pRuntime->NewNumber(2));
dan sinclaircbe23db2017-10-19 14:29:33 -04001068 }
1069 return true;
1070}
1071
1072bool Field::set_display(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001073 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001074 WideString* sError) {
1075 if (!m_bCanSet)
1076 return false;
1077
1078 if (m_bDelay) {
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04001079 AddDelay_Int(FP_DISPLAY, pRuntime->ToInt32(vp.ToV8Value()));
dan sinclaircbe23db2017-10-19 14:29:33 -04001080 } else {
1081 Field::SetDisplay(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04001082 pRuntime->ToInt32(vp.ToV8Value()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001083 }
tsepez4cf55152016-11-02 14:37:54 -07001084 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001085}
1086
dsinclair3a7741a2016-10-11 10:39:49 -07001087void Field::SetDisplay(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04001088 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001089 int nControlIndex,
1090 int number) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001091 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001092 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07001093 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -08001094 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001095 if (nControlIndex < 0) {
tonikitoo7c05a7a2016-08-17 11:08:46 -07001096 bool bAnySet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001097 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1098 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08001099 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001100
dsinclairc5267c52016-11-04 15:35:12 -07001101 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
tonikitoo7c05a7a2016-08-17 11:08:46 -07001102 if (SetWidgetDisplayStatus(pWidget, number))
1103 bAnySet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001104 }
1105
tonikitoo7c05a7a2016-08-17 11:08:46 -07001106 if (bAnySet)
tsepez4cf55152016-11-02 14:37:54 -07001107 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001108 } else {
1109 if (nControlIndex >= pFormField->CountControls())
1110 return;
tonikitoo7c05a7a2016-08-17 11:08:46 -07001111
1112 CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex);
1113 if (!pFormControl)
1114 return;
1115
dsinclairc5267c52016-11-04 15:35:12 -07001116 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
tonikitoo7c05a7a2016-08-17 11:08:46 -07001117 if (SetWidgetDisplayStatus(pWidget, number))
tsepez4cf55152016-11-02 14:37:54 -07001118 UpdateFormControl(pFormFillEnv, pFormControl, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001119 }
1120 }
1121}
1122
Dan Sinclair33d13f22017-10-23 09:44:30 -04001123bool Field::get_doc(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError) {
Dan Sinclaire4974922017-10-24 09:36:16 -04001124 vp->Set(m_pJSDoc->GetCJSDoc()->ToV8Object());
tsepez4cf55152016-11-02 14:37:54 -07001125 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001126}
1127
dan sinclaircbe23db2017-10-19 14:29:33 -04001128bool Field::set_doc(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001129 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001130 WideString* sError) {
1131 return false;
1132}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001133
dan sinclaircbe23db2017-10-19 14:29:33 -04001134bool Field::get_editable(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001135 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001136 WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001137 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1138 if (FieldArray.empty())
1139 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001140
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001141 CPDF_FormField* pFormField = FieldArray[0];
1142 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX)
1143 return false;
1144
Dan Sinclaire4974922017-10-24 09:36:16 -04001145 vp->Set(
1146 pRuntime->NewBoolean(!!(pFormField->GetFieldFlags() & FIELDFLAG_EDIT)));
tsepez4cf55152016-11-02 14:37:54 -07001147 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001148}
1149
dan sinclaircbe23db2017-10-19 14:29:33 -04001150bool Field::set_editable(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001151 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001152 WideString* sError) {
1153 return m_bCanSet;
1154}
1155
1156bool Field::get_export_values(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001157 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001158 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001159 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1160 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001161 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001162
Lei Zhangd88a3642015-11-10 09:38:57 -08001163 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001164 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001165 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) {
tsepez4cf55152016-11-02 14:37:54 -07001166 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001167 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001168
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04001169 CJS_Array ExportValuesArray;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001170 if (m_nFormControlIndex < 0) {
1171 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
1172 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04001173 ExportValuesArray.SetElement(
1174 pRuntime, i,
1175 CJS_Value(
1176 pRuntime->NewString(pFormControl->GetExportValue().c_str())));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001177 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001178 } else {
1179 if (m_nFormControlIndex >= pFormField->CountControls())
1180 return false;
1181
1182 CPDF_FormControl* pFormControl =
1183 pFormField->GetControl(m_nFormControlIndex);
1184 if (!pFormControl)
1185 return false;
1186
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04001187 ExportValuesArray.SetElement(
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001188 pRuntime, 0,
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04001189 CJS_Value(pRuntime->NewString(pFormControl->GetExportValue().c_str())));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001190 }
dan sinclaircbe23db2017-10-19 14:29:33 -04001191
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04001192 if (ExportValuesArray.ToV8Value().IsEmpty())
1193 vp->Set(pRuntime->NewArray());
1194 else
1195 vp->Set(ExportValuesArray.ToV8Value());
1196
tsepez4cf55152016-11-02 14:37:54 -07001197 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001198}
1199
dan sinclaircbe23db2017-10-19 14:29:33 -04001200bool Field::set_export_values(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001201 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001202 WideString* sError) {
1203 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1204 if (FieldArray.empty())
1205 return false;
1206
1207 CPDF_FormField* pFormField = FieldArray[0];
1208 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
1209 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) {
1210 return false;
1211 }
1212
Dan Sinclair33d13f22017-10-23 09:44:30 -04001213 return m_bCanSet && vp.IsArrayObject();
dan sinclaircbe23db2017-10-19 14:29:33 -04001214}
1215
1216bool Field::get_file_select(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001217 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001218 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001219 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1220 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001221 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001222
Lei Zhangd88a3642015-11-10 09:38:57 -08001223 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001224 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
tsepez4cf55152016-11-02 14:37:54 -07001225 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001226
Dan Sinclaire4974922017-10-24 09:36:16 -04001227 vp->Set(pRuntime->NewBoolean(
1228 !!(pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT)));
tsepez4cf55152016-11-02 14:37:54 -07001229 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001230}
1231
dan sinclaircbe23db2017-10-19 14:29:33 -04001232bool Field::set_file_select(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001233 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001234 WideString* sError) {
1235 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1236 if (FieldArray.empty())
1237 return false;
1238
1239 CPDF_FormField* pFormField = FieldArray[0];
1240 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1241 return false;
1242
1243 return m_bCanSet;
1244}
1245
1246bool Field::get_fill_color(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001247 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001248 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001249 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1250 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001251 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001252
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001253 CPDF_FormField* pFormField = FieldArray[0];
1254 ASSERT(pFormField);
1255 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1256 if (!pFormControl)
1257 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001258
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001259 int iColorType;
1260 pFormControl->GetBackgroundColor(iColorType);
1261
Dan Sinclair7f55a542017-07-13 14:17:10 -04001262 CFX_Color color;
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001263 if (iColorType == CFX_Color::kTransparent) {
1264 color = CFX_Color(CFX_Color::kTransparent);
1265 } else if (iColorType == CFX_Color::kGray) {
1266 color = CFX_Color(CFX_Color::kGray,
1267 pFormControl->GetOriginalBackgroundColor(0));
1268 } else if (iColorType == CFX_Color::kRGB) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001269 color =
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001270 CFX_Color(CFX_Color::kRGB, pFormControl->GetOriginalBackgroundColor(0),
Dan Sinclair7f55a542017-07-13 14:17:10 -04001271 pFormControl->GetOriginalBackgroundColor(1),
1272 pFormControl->GetOriginalBackgroundColor(2));
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001273 } else if (iColorType == CFX_Color::kCMYK) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001274 color =
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001275 CFX_Color(CFX_Color::kCMYK, pFormControl->GetOriginalBackgroundColor(0),
Dan Sinclair7f55a542017-07-13 14:17:10 -04001276 pFormControl->GetOriginalBackgroundColor(1),
1277 pFormControl->GetOriginalBackgroundColor(2),
1278 pFormControl->GetOriginalBackgroundColor(3));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001279 } else {
1280 return false;
1281 }
dan sinclaircbe23db2017-10-19 14:29:33 -04001282
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04001283 CJS_Array array = color::ConvertPWLColorToArray(pRuntime, color);
1284 if (array.ToV8Value().IsEmpty())
1285 vp->Set(pRuntime->NewArray());
1286 else
1287 vp->Set(array.ToV8Value());
1288
dan sinclaircbe23db2017-10-19 14:29:33 -04001289 return true;
1290}
1291
1292bool Field::set_fill_color(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001293 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001294 WideString* sError) {
1295 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1296 if (FieldArray.empty())
1297 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -04001298 if (!m_bCanSet)
1299 return false;
Dan Sinclair33d13f22017-10-23 09:44:30 -04001300 if (!vp.IsArrayObject())
dan sinclaircbe23db2017-10-19 14:29:33 -04001301 return false;
tsepez4cf55152016-11-02 14:37:54 -07001302 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001303}
1304
dan sinclaircbe23db2017-10-19 14:29:33 -04001305bool Field::get_hidden(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001306 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001307 WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001308 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1309 if (FieldArray.empty())
1310 return false;
1311
1312 CPDF_FormField* pFormField = FieldArray[0];
1313 ASSERT(pFormField);
dan sinclaircbe23db2017-10-19 14:29:33 -04001314
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001315 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1316 CPDFSDK_Widget* pWidget =
1317 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1318 if (!pWidget)
1319 return false;
1320
1321 uint32_t dwFlags = pWidget->GetFlags();
Dan Sinclaire4974922017-10-24 09:36:16 -04001322 vp->Set(pRuntime->NewBoolean(ANNOTFLAG_INVISIBLE & dwFlags ||
1323 ANNOTFLAG_HIDDEN & dwFlags));
dan sinclaircbe23db2017-10-19 14:29:33 -04001324 return true;
1325}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001326
dan sinclaircbe23db2017-10-19 14:29:33 -04001327bool Field::set_hidden(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001328 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001329 WideString* sError) {
1330 if (!m_bCanSet)
1331 return false;
1332
1333 if (m_bDelay) {
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04001334 AddDelay_Bool(FP_HIDDEN, pRuntime->ToBoolean(vp.ToV8Value()));
dan sinclaircbe23db2017-10-19 14:29:33 -04001335 } else {
1336 Field::SetHidden(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04001337 pRuntime->ToBoolean(vp.ToV8Value()));
dan sinclaircbe23db2017-10-19 14:29:33 -04001338 }
tsepez4cf55152016-11-02 14:37:54 -07001339 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001340}
1341
dsinclair3a7741a2016-10-11 10:39:49 -07001342void Field::SetHidden(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04001343 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001344 int nControlIndex,
1345 bool b) {
tonikitooa73b8fe2016-08-22 14:06:49 -07001346 int display = b ? 1 /*Hidden*/ : 0 /*Visible*/;
dsinclair3a7741a2016-10-11 10:39:49 -07001347 SetDisplay(pFormFillEnv, swFieldName, nControlIndex, display);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001348}
1349
dan sinclaircbe23db2017-10-19 14:29:33 -04001350bool Field::get_highlight(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001351 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001352 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001353 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001354
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001355 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1356 if (FieldArray.empty())
1357 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001358
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001359 CPDF_FormField* pFormField = FieldArray[0];
1360 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
1361 return false;
1362
1363 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1364 if (!pFormControl)
1365 return false;
1366
1367 int eHM = pFormControl->GetHighlightingMode();
1368 switch (eHM) {
1369 case CPDF_FormControl::None:
Dan Sinclaire4974922017-10-24 09:36:16 -04001370 vp->Set(pRuntime->NewString(L"none"));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001371 break;
1372 case CPDF_FormControl::Push:
Dan Sinclaire4974922017-10-24 09:36:16 -04001373 vp->Set(pRuntime->NewString(L"push"));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001374 break;
1375 case CPDF_FormControl::Invert:
Dan Sinclaire4974922017-10-24 09:36:16 -04001376 vp->Set(pRuntime->NewString(L"invert"));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001377 break;
1378 case CPDF_FormControl::Outline:
Dan Sinclaire4974922017-10-24 09:36:16 -04001379 vp->Set(pRuntime->NewString(L"outline"));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001380 break;
1381 case CPDF_FormControl::Toggle:
Dan Sinclaire4974922017-10-24 09:36:16 -04001382 vp->Set(pRuntime->NewString(L"toggle"));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001383 break;
1384 }
tsepez4cf55152016-11-02 14:37:54 -07001385 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001386}
1387
dan sinclaircbe23db2017-10-19 14:29:33 -04001388bool Field::set_highlight(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001389 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001390 WideString* sError) {
1391 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04001392 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001393}
1394
dan sinclaircbe23db2017-10-19 14:29:33 -04001395bool Field::get_line_width(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001396 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001397 WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001398 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1399 if (FieldArray.empty())
1400 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001401
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001402 CPDF_FormField* pFormField = FieldArray[0];
1403 ASSERT(pFormField);
dan sinclaircbe23db2017-10-19 14:29:33 -04001404
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001405 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1406 if (!pFormControl)
1407 return false;
1408
1409 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1410 if (!pFormField->CountControls())
1411 return false;
1412
1413 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
1414 if (!pWidget)
1415 return false;
1416
Dan Sinclaire4974922017-10-24 09:36:16 -04001417 vp->Set(pRuntime->NewNumber(pWidget->GetBorderWidth()));
dan sinclaircbe23db2017-10-19 14:29:33 -04001418 return true;
1419}
1420
1421bool Field::set_line_width(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001422 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001423 WideString* sError) {
1424 if (!m_bCanSet)
1425 return false;
1426
1427 if (m_bDelay) {
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04001428 AddDelay_Int(FP_LINEWIDTH, pRuntime->ToInt32(vp.ToV8Value()));
dan sinclaircbe23db2017-10-19 14:29:33 -04001429 } else {
1430 Field::SetLineWidth(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04001431 pRuntime->ToInt32(vp.ToV8Value()));
dan sinclaircbe23db2017-10-19 14:29:33 -04001432 }
tsepez4cf55152016-11-02 14:37:54 -07001433 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001434}
1435
dsinclair3a7741a2016-10-11 10:39:49 -07001436void Field::SetLineWidth(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04001437 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001438 int nControlIndex,
1439 int number) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001440 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001441 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07001442 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -08001443 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001444 if (nControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -07001445 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001446 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1447 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08001448 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001449
dsinclairc5267c52016-11-04 15:35:12 -07001450 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001451 if (number != pWidget->GetBorderWidth()) {
1452 pWidget->SetBorderWidth(number);
tsepez4cf55152016-11-02 14:37:54 -07001453 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001454 }
1455 }
1456 }
1457 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -07001458 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001459 } else {
1460 if (nControlIndex >= pFormField->CountControls())
1461 return;
1462 if (CPDF_FormControl* pFormControl =
1463 pFormField->GetControl(nControlIndex)) {
dsinclairc5267c52016-11-04 15:35:12 -07001464 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001465 if (number != pWidget->GetBorderWidth()) {
1466 pWidget->SetBorderWidth(number);
tsepez4cf55152016-11-02 14:37:54 -07001467 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001468 }
1469 }
1470 }
1471 }
1472 }
1473}
1474
dan sinclaircbe23db2017-10-19 14:29:33 -04001475bool Field::get_multiline(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001476 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001477 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001478 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001479
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001480 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1481 if (FieldArray.empty())
1482 return false;
1483
1484 CPDF_FormField* pFormField = FieldArray[0];
1485 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1486 return false;
1487
Dan Sinclaire4974922017-10-24 09:36:16 -04001488 vp->Set(pRuntime->NewBoolean(
1489 !!(pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE)));
tsepez4cf55152016-11-02 14:37:54 -07001490 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001491}
1492
dan sinclaircbe23db2017-10-19 14:29:33 -04001493bool Field::set_multiline(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001494 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001495 WideString* sError) {
1496 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04001497 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001498}
1499
dan sinclaircbe23db2017-10-19 14:29:33 -04001500bool Field::get_multiple_selection(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001501 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001502 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001503 ASSERT(m_pFormFillEnv);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001504 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1505 if (FieldArray.empty())
1506 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001507
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001508 CPDF_FormField* pFormField = FieldArray[0];
1509 if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
1510 return false;
1511
Dan Sinclaire4974922017-10-24 09:36:16 -04001512 vp->Set(pRuntime->NewBoolean(
1513 !!(pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT)));
dan sinclaircbe23db2017-10-19 14:29:33 -04001514 return true;
1515}
1516
1517bool Field::set_multiple_selection(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 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04001521 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001522}
1523
Dan Sinclair33d13f22017-10-23 09:44:30 -04001524bool Field::get_name(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001525 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1526 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001527 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001528
Dan Sinclaire4974922017-10-24 09:36:16 -04001529 vp->Set(pRuntime->NewString(m_FieldName.c_str()));
tsepez4cf55152016-11-02 14:37:54 -07001530 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001531}
1532
dan sinclaircbe23db2017-10-19 14:29:33 -04001533bool Field::set_name(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001534 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001535 WideString* sError) {
1536 return false;
1537}
Tom Sepez67fd5df2015-10-08 12:24:19 -07001538
dan sinclaircbe23db2017-10-19 14:29:33 -04001539bool Field::get_num_items(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001540 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001541 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001542 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1543 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001544 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001545
Lei Zhangd88a3642015-11-10 09:38:57 -08001546 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001547 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001548 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
tsepez4cf55152016-11-02 14:37:54 -07001549 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001550 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001551
Dan Sinclaire4974922017-10-24 09:36:16 -04001552 vp->Set(pRuntime->NewNumber(pFormField->CountOptions()));
tsepez4cf55152016-11-02 14:37:54 -07001553 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001554}
1555
dan sinclaircbe23db2017-10-19 14:29:33 -04001556bool Field::set_num_items(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001557 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001558 WideString* sError) {
1559 return false;
1560}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001561
Dan Sinclair33d13f22017-10-23 09:44:30 -04001562bool Field::get_page(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001563 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1564 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001565 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001566
Lei Zhangd88a3642015-11-10 09:38:57 -08001567 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001568 if (!pFormField)
tsepez4cf55152016-11-02 14:37:54 -07001569 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001570
tsepez8fa82792017-01-11 09:32:33 -08001571 std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
dsinclair7cbe68e2016-10-12 11:56:23 -07001572 m_pFormFillEnv->GetInterForm()->GetWidgets(pFormField, &widgets);
Lei Zhangd88a3642015-11-10 09:38:57 -08001573 if (widgets.empty()) {
Dan Sinclaire4974922017-10-24 09:36:16 -04001574 vp->Set(pRuntime->NewNumber(-1));
tsepez4cf55152016-11-02 14:37:54 -07001575 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001576 }
1577
tsepeze5aff742016-08-08 09:49:42 -07001578 CJS_Array PageArray;
tsepez8fa82792017-01-11 09:32:33 -08001579 int i = 0;
1580 for (const auto& pObserved : widgets) {
1581 if (!pObserved) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001582 *sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
tsepez8fa82792017-01-11 09:32:33 -08001583 return false;
1584 }
1585
Lei Zhang375c2762017-03-10 14:37:14 -08001586 auto* pWidget = static_cast<CPDFSDK_Widget*>(pObserved.Get());
tsepez8fa82792017-01-11 09:32:33 -08001587 CPDFSDK_PageView* pPageView = pWidget->GetPageView();
Lei Zhangd88a3642015-11-10 09:38:57 -08001588 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -07001589 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001590
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04001591 PageArray.SetElement(pRuntime, i,
1592 CJS_Value(pRuntime->NewNumber(
1593 static_cast<int32_t>(pPageView->GetPageIndex()))));
tsepez8fa82792017-01-11 09:32:33 -08001594 ++i;
Lei Zhangd88a3642015-11-10 09:38:57 -08001595 }
1596
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04001597 if (PageArray.ToV8Value().IsEmpty())
1598 vp->Set(pRuntime->NewArray());
1599 else
1600 vp->Set(PageArray.ToV8Value());
1601
tsepez4cf55152016-11-02 14:37:54 -07001602 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001603}
1604
dan sinclaircbe23db2017-10-19 14:29:33 -04001605bool Field::set_page(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001606 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001607 WideString* sError) {
1608 *sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
1609 return false;
1610}
1611
1612bool Field::get_password(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001613 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001614 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001615 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001616
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001617 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1618 if (FieldArray.empty())
1619 return false;
1620
1621 CPDF_FormField* pFormField = FieldArray[0];
1622 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1623 return false;
1624
Dan Sinclaire4974922017-10-24 09:36:16 -04001625 vp->Set(pRuntime->NewBoolean(
1626 !!(pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD)));
tsepez4cf55152016-11-02 14:37:54 -07001627 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001628}
1629
dan sinclaircbe23db2017-10-19 14:29:33 -04001630bool Field::set_password(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001631 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001632 WideString* sError) {
1633 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04001634 return m_bCanSet;
1635}
dan sinclaircbe23db2017-10-19 14:29:33 -04001636
dan sinclair646634b2017-10-19 14:30:28 -04001637bool Field::get_print(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001638 CJS_Value* vp,
dan sinclair646634b2017-10-19 14:30:28 -04001639 WideString* sError) {
1640 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1641 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1642 if (FieldArray.empty())
1643 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -04001644
dan sinclair646634b2017-10-19 14:30:28 -04001645 CPDF_FormField* pFormField = FieldArray[0];
1646 CPDFSDK_Widget* pWidget =
1647 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1648 if (!pWidget)
1649 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -04001650
Dan Sinclaire4974922017-10-24 09:36:16 -04001651 vp->Set(pRuntime->NewBoolean(!!(pWidget->GetFlags() & ANNOTFLAG_PRINT)));
dan sinclair646634b2017-10-19 14:30:28 -04001652 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001653}
1654
dan sinclaircbe23db2017-10-19 14:29:33 -04001655bool Field::set_print(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001656 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001657 WideString* sError) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001658 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001659 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1660 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001661 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001662
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001663 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001664 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001665
Lei Zhangd88a3642015-11-10 09:38:57 -08001666 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001667 if (m_nFormControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -07001668 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001669 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001670 if (CPDFSDK_Widget* pWidget =
dsinclairc5267c52016-11-04 15:35:12 -07001671 pInterForm->GetWidget(pFormField->GetControl(i))) {
tsepezc3255f52016-03-25 14:52:27 -07001672 uint32_t dwFlags = pWidget->GetFlags();
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04001673 if (pRuntime->ToBoolean(vp.ToV8Value()))
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001674 dwFlags |= ANNOTFLAG_PRINT;
1675 else
1676 dwFlags &= ~ANNOTFLAG_PRINT;
1677
1678 if (dwFlags != pWidget->GetFlags()) {
1679 pWidget->SetFlags(dwFlags);
tsepez4cf55152016-11-02 14:37:54 -07001680 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001681 }
1682 }
1683 }
1684
1685 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -07001686 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001687
dan sinclaircbe23db2017-10-19 14:29:33 -04001688 continue;
1689 }
1690
1691 if (m_nFormControlIndex >= pFormField->CountControls())
1692 return false;
1693 if (CPDF_FormControl* pFormControl =
1694 pFormField->GetControl(m_nFormControlIndex)) {
1695 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1696 uint32_t dwFlags = pWidget->GetFlags();
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04001697 if (pRuntime->ToBoolean(vp.ToV8Value()))
dan sinclaircbe23db2017-10-19 14:29:33 -04001698 dwFlags |= ANNOTFLAG_PRINT;
1699 else
1700 dwFlags &= ~ANNOTFLAG_PRINT;
1701
1702 if (dwFlags != pWidget->GetFlags()) {
1703 pWidget->SetFlags(dwFlags);
1704 UpdateFormControl(m_pFormFillEnv.Get(),
1705 pFormField->GetControl(m_nFormControlIndex), true,
1706 false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001707 }
1708 }
1709 }
1710 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001711 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001712}
1713
dan sinclaircbe23db2017-10-19 14:29:33 -04001714bool Field::get_radios_in_unison(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001715 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001716 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001717 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1718 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001719 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001720
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001721 CPDF_FormField* pFormField = FieldArray[0];
1722 if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
1723 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001724
Dan Sinclaire4974922017-10-24 09:36:16 -04001725 vp->Set(pRuntime->NewBoolean(
1726 !!(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)));
tsepez4cf55152016-11-02 14:37:54 -07001727 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001728}
1729
dan sinclaircbe23db2017-10-19 14:29:33 -04001730bool Field::set_radios_in_unison(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001731 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001732 WideString* sError) {
1733 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1734 if (FieldArray.empty())
1735 return false;
1736 return m_bCanSet;
1737}
1738
1739bool Field::get_readonly(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001740 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001741 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001742 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1743 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001744 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001745
Dan Sinclaire4974922017-10-24 09:36:16 -04001746 vp->Set(pRuntime->NewBoolean(
1747 !!(FieldArray[0]->GetFieldFlags() & FIELDFLAG_READONLY)));
tsepez4cf55152016-11-02 14:37:54 -07001748 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001749}
1750
dan sinclaircbe23db2017-10-19 14:29:33 -04001751bool Field::set_readonly(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001752 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001753 WideString* sError) {
1754 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1755 if (FieldArray.empty())
1756 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -04001757 return m_bCanSet;
1758}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001759
Dan Sinclair33d13f22017-10-23 09:44:30 -04001760bool Field::get_rect(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001761 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1762 if (FieldArray.empty())
1763 return false;
1764
1765 CPDF_FormField* pFormField = FieldArray[0];
1766 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1767 CPDFSDK_Widget* pWidget =
1768 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1769 if (!pWidget)
1770 return false;
1771
1772 CFX_FloatRect crRect = pWidget->GetRect();
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001773 CJS_Array rcArray;
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04001774 rcArray.SetElement(
1775 pRuntime, 0,
1776 CJS_Value(pRuntime->NewNumber(static_cast<int32_t>(crRect.left))));
1777 rcArray.SetElement(
1778 pRuntime, 1,
1779 CJS_Value(pRuntime->NewNumber(static_cast<int32_t>(crRect.top))));
1780 rcArray.SetElement(
1781 pRuntime, 2,
1782 CJS_Value(pRuntime->NewNumber(static_cast<int32_t>(crRect.right))));
1783 rcArray.SetElement(
1784 pRuntime, 3,
1785 CJS_Value(pRuntime->NewNumber(static_cast<int32_t>(crRect.bottom))));
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04001786
1787 if (rcArray.ToV8Value().IsEmpty())
1788 vp->Set(pRuntime->NewArray());
1789 else
1790 vp->Set(rcArray.ToV8Value());
1791
dan sinclaircbe23db2017-10-19 14:29:33 -04001792 return true;
1793}
1794
1795bool Field::set_rect(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001796 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001797 WideString* sError) {
1798 if (!m_bCanSet)
1799 return false;
Dan Sinclair33d13f22017-10-23 09:44:30 -04001800 if (!vp.IsArrayObject())
dan sinclaircbe23db2017-10-19 14:29:33 -04001801 return false;
1802
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04001803 CJS_Array rcArray(pRuntime->ToArray(vp.ToV8Value()));
dan sinclaircbe23db2017-10-19 14:29:33 -04001804 float pArray[4];
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04001805 pArray[0] = static_cast<float>(
1806 pRuntime->ToInt32(rcArray.GetElement(pRuntime, 0).ToV8Value()));
1807 pArray[1] = static_cast<float>(
1808 pRuntime->ToInt32(rcArray.GetElement(pRuntime, 1).ToV8Value()));
1809 pArray[2] = static_cast<float>(
1810 pRuntime->ToInt32(rcArray.GetElement(pRuntime, 2).ToV8Value()));
1811 pArray[3] = static_cast<float>(
1812 pRuntime->ToInt32(rcArray.GetElement(pRuntime, 3).ToV8Value()));
dan sinclaircbe23db2017-10-19 14:29:33 -04001813
1814 CFX_FloatRect crRect(pArray);
1815 if (m_bDelay) {
1816 AddDelay_Rect(FP_RECT, crRect);
1817 } else {
1818 Field::SetRect(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
1819 crRect);
1820 }
tsepez4cf55152016-11-02 14:37:54 -07001821 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001822}
1823
dsinclair3a7741a2016-10-11 10:39:49 -07001824void Field::SetRect(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04001825 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001826 int nControlIndex,
Tom Sepez281a9ea2016-02-26 14:24:28 -08001827 const CFX_FloatRect& rect) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001828 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001829 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07001830 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -08001831 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001832 if (nControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -07001833 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001834 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001835 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08001836 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001837
dsinclairc5267c52016-11-04 15:35:12 -07001838 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08001839 CFX_FloatRect crRect = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001840
1841 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001842 crRect.Intersect(pPDFPage->GetPageBBox());
1843
1844 if (!crRect.IsEmpty()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08001845 CFX_FloatRect rcOld = pWidget->GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001846 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
1847 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
1848 pWidget->SetRect(crRect);
tsepez4cf55152016-11-02 14:37:54 -07001849 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001850 }
1851 }
1852 }
1853 }
1854
1855 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -07001856 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001857
dan sinclaircbe23db2017-10-19 14:29:33 -04001858 continue;
1859 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001860
dan sinclaircbe23db2017-10-19 14:29:33 -04001861 if (nControlIndex >= pFormField->CountControls())
1862 return;
1863 if (CPDF_FormControl* pFormControl =
1864 pFormField->GetControl(nControlIndex)) {
1865 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1866 CFX_FloatRect crRect = rect;
1867
1868 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
1869 crRect.Intersect(pPDFPage->GetPageBBox());
1870
1871 if (!crRect.IsEmpty()) {
1872 CFX_FloatRect rcOld = pWidget->GetRect();
1873 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
1874 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
1875 pWidget->SetRect(crRect);
1876 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001877 }
1878 }
1879 }
1880 }
1881 }
1882}
1883
dan sinclaircbe23db2017-10-19 14:29:33 -04001884bool Field::get_required(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001885 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001886 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001887 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1888 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001889 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001890
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001891 CPDF_FormField* pFormField = FieldArray[0];
1892 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
1893 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001894
Dan Sinclaire4974922017-10-24 09:36:16 -04001895 vp->Set(pRuntime->NewBoolean(
1896 !!(pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED)));
tsepez4cf55152016-11-02 14:37:54 -07001897 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001898}
1899
dan sinclaircbe23db2017-10-19 14:29:33 -04001900bool Field::set_required(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001901 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001902 WideString* sError) {
1903 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1904 if (FieldArray.empty())
1905 return false;
1906
1907 return m_bCanSet;
1908}
1909
1910bool Field::get_rich_text(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001911 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001912 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001913 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001914
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001915 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1916 if (FieldArray.empty())
1917 return false;
1918
1919 CPDF_FormField* pFormField = FieldArray[0];
1920 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1921 return false;
1922
Dan Sinclaire4974922017-10-24 09:36:16 -04001923 vp->Set(pRuntime->NewBoolean(
1924 !!(pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT)));
tsepez4cf55152016-11-02 14:37:54 -07001925 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001926}
1927
dan sinclaircbe23db2017-10-19 14:29:33 -04001928bool Field::set_rich_text(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001929 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001930 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001931 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04001932 return m_bCanSet;
dan sinclaircbe23db2017-10-19 14:29:33 -04001933}
1934
1935bool Field::get_rich_value(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001936 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001937 WideString* sError) {
1938 return true;
1939}
1940
1941bool Field::set_rich_value(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001942 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001943 WideString* sError) {
1944 return true;
1945}
1946
1947bool Field::get_rotation(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001948 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001949 WideString* sError) {
1950 ASSERT(m_pFormFillEnv);
1951
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001952 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1953 if (FieldArray.empty())
1954 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001955
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001956 CPDF_FormField* pFormField = FieldArray[0];
1957 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1958 if (!pFormControl)
1959 return false;
1960
Dan Sinclaire4974922017-10-24 09:36:16 -04001961 vp->Set(pRuntime->NewNumber(pFormControl->GetRotation()));
dan sinclaircbe23db2017-10-19 14:29:33 -04001962 return true;
1963}
1964
1965bool Field::set_rotation(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001966 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001967 WideString* sError) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001968 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04001969 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001970}
1971
dan sinclaircbe23db2017-10-19 14:29:33 -04001972bool Field::get_stroke_color(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04001973 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04001974 WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001975 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1976 if (FieldArray.empty())
1977 return false;
1978
1979 CPDF_FormField* pFormField = FieldArray[0];
1980 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1981 if (!pFormControl)
1982 return false;
1983
1984 int iColorType;
1985 pFormControl->GetBorderColor(iColorType);
1986
Dan Sinclair7f55a542017-07-13 14:17:10 -04001987 CFX_Color color;
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001988 if (iColorType == CFX_Color::kTransparent) {
1989 color = CFX_Color(CFX_Color::kTransparent);
1990 } else if (iColorType == CFX_Color::kGray) {
1991 color =
1992 CFX_Color(CFX_Color::kGray, pFormControl->GetOriginalBorderColor(0));
1993 } else if (iColorType == CFX_Color::kRGB) {
1994 color = CFX_Color(CFX_Color::kRGB, pFormControl->GetOriginalBorderColor(0),
Dan Sinclair7f55a542017-07-13 14:17:10 -04001995 pFormControl->GetOriginalBorderColor(1),
1996 pFormControl->GetOriginalBorderColor(2));
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001997 } else if (iColorType == CFX_Color::kCMYK) {
1998 color = CFX_Color(CFX_Color::kCMYK, pFormControl->GetOriginalBorderColor(0),
Dan Sinclair7f55a542017-07-13 14:17:10 -04001999 pFormControl->GetOriginalBorderColor(1),
2000 pFormControl->GetOriginalBorderColor(2),
2001 pFormControl->GetOriginalBorderColor(3));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002002 } else {
2003 return false;
2004 }
2005
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04002006 CJS_Array array = color::ConvertPWLColorToArray(pRuntime, color);
2007 if (array.ToV8Value().IsEmpty())
2008 vp->Set(pRuntime->NewArray());
2009 else
2010 vp->Set(array.ToV8Value());
2011
dan sinclaircbe23db2017-10-19 14:29:33 -04002012 return true;
2013}
2014
2015bool Field::set_stroke_color(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002016 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002017 WideString* sError) {
2018 if (!m_bCanSet)
2019 return false;
Dan Sinclair33d13f22017-10-23 09:44:30 -04002020 if (!vp.IsArrayObject())
dan sinclaircbe23db2017-10-19 14:29:33 -04002021 return false;
tsepez4cf55152016-11-02 14:37:54 -07002022 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002023}
2024
dan sinclaircbe23db2017-10-19 14:29:33 -04002025bool Field::get_style(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002026 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002027 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002028 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002029
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002030 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2031 if (FieldArray.empty())
2032 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002033
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002034 CPDF_FormField* pFormField = FieldArray[0];
2035 if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON &&
2036 pFormField->GetFieldType() != FIELDTYPE_CHECKBOX) {
2037 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002038 }
2039
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002040 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2041 if (!pFormControl)
2042 return false;
2043
Ryan Harrison275e2602017-09-18 14:23:18 -04002044 WideString csWCaption = pFormControl->GetNormalCaption();
2045 ByteString csBCaption;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002046
2047 switch (csWCaption[0]) {
2048 case L'l':
2049 csBCaption = "circle";
2050 break;
2051 case L'8':
2052 csBCaption = "cross";
2053 break;
2054 case L'u':
2055 csBCaption = "diamond";
2056 break;
2057 case L'n':
2058 csBCaption = "square";
2059 break;
2060 case L'H':
2061 csBCaption = "star";
2062 break;
2063 default: // L'4'
2064 csBCaption = "check";
2065 break;
2066 }
Dan Sinclaire4974922017-10-24 09:36:16 -04002067 vp->Set(
2068 pRuntime->NewString(WideString::FromLocal(csBCaption.c_str()).c_str()));
dan sinclaircbe23db2017-10-19 14:29:33 -04002069 return true;
2070}
2071
2072bool Field::set_style(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002073 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002074 WideString* sError) {
2075 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04002076 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002077}
2078
dan sinclaircbe23db2017-10-19 14:29:33 -04002079bool Field::get_submit_name(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002080 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002081 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -07002082 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002083}
2084
dan sinclaircbe23db2017-10-19 14:29:33 -04002085bool Field::set_submit_name(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002086 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002087 WideString* sError) {
2088 return true;
2089}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002090
dan sinclaircbe23db2017-10-19 14:29:33 -04002091bool Field::get_text_color(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002092 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002093 WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002094 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2095 if (FieldArray.empty())
2096 return false;
2097
2098 CPDF_FormField* pFormField = FieldArray[0];
2099 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2100 if (!pFormControl)
2101 return false;
2102
2103 int iColorType;
2104 FX_ARGB color;
2105 CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
2106 FieldAppearance.GetColor(color, iColorType);
2107
2108 int32_t a;
2109 int32_t r;
2110 int32_t g;
2111 int32_t b;
Nicolas Penaddfc3dc2017-04-20 15:29:25 -04002112 std::tie(a, r, g, b) = ArgbDecode(color);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002113
Dan Sinclair7f55a542017-07-13 14:17:10 -04002114 CFX_Color crRet =
Dan Sinclair8e7f9322017-10-16 11:35:42 -04002115 CFX_Color(CFX_Color::kRGB, r / 255.0f, g / 255.0f, b / 255.0f);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002116
Dan Sinclair8e7f9322017-10-16 11:35:42 -04002117 if (iColorType == CFX_Color::kTransparent)
2118 crRet = CFX_Color(CFX_Color::kTransparent);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002119
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04002120 CJS_Array array = color::ConvertPWLColorToArray(pRuntime, crRet);
2121 if (array.ToV8Value().IsEmpty())
2122 vp->Set(pRuntime->NewArray());
2123 else
2124 vp->Set(array.ToV8Value());
2125
dan sinclaircbe23db2017-10-19 14:29:33 -04002126 return true;
2127}
2128
2129bool Field::set_text_color(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002130 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002131 WideString* sError) {
2132 if (!m_bCanSet)
2133 return false;
Dan Sinclair33d13f22017-10-23 09:44:30 -04002134 if (!vp.IsArrayObject())
dan sinclaircbe23db2017-10-19 14:29:33 -04002135 return false;
tsepez4cf55152016-11-02 14:37:54 -07002136 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002137}
2138
dan sinclaircbe23db2017-10-19 14:29:33 -04002139bool Field::get_text_font(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002140 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002141 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002142 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002143
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002144 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2145 if (FieldArray.empty())
2146 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002147
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002148 CPDF_FormField* pFormField = FieldArray[0];
2149 ASSERT(pFormField);
2150 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2151 if (!pFormControl)
2152 return false;
2153
2154 int nFieldType = pFormField->GetFieldType();
2155 if (nFieldType != FIELDTYPE_PUSHBUTTON && nFieldType != FIELDTYPE_COMBOBOX &&
2156 nFieldType != FIELDTYPE_LISTBOX && nFieldType != FIELDTYPE_TEXTFIELD) {
2157 return false;
2158 }
2159 CPDF_Font* pFont = pFormControl->GetDefaultControlFont();
2160 if (!pFont)
2161 return false;
2162
Dan Sinclaire4974922017-10-24 09:36:16 -04002163 vp->Set(pRuntime->NewString(
2164 WideString::FromLocal(pFont->GetBaseFont().c_str()).c_str()));
tsepez4cf55152016-11-02 14:37:54 -07002165 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002166}
2167
dan sinclaircbe23db2017-10-19 14:29:33 -04002168bool Field::set_text_font(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002169 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002170 WideString* sError) {
2171 ASSERT(m_pFormFillEnv);
2172
dan sinclair646634b2017-10-19 14:30:28 -04002173 if (!m_bCanSet)
2174 return false;
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04002175 return !ByteString::FromUnicode(pRuntime->ToWideString(vp.ToV8Value()))
2176 .IsEmpty();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002177}
2178
dan sinclaircbe23db2017-10-19 14:29:33 -04002179bool Field::get_text_size(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002180 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002181 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002182 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002183
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002184 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2185 if (FieldArray.empty())
2186 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002187
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002188 CPDF_FormField* pFormField = FieldArray[0];
2189 ASSERT(pFormField);
2190 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2191 if (!pFormControl)
2192 return false;
2193
Dan Sinclair05df0752017-03-14 14:43:42 -04002194 float fFontSize;
Tom Sepezc4a2b752017-04-07 13:56:13 -07002195 CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
2196 FieldAppearance.GetFont(&fFontSize);
Dan Sinclaire4974922017-10-24 09:36:16 -04002197 vp->Set(pRuntime->NewNumber(static_cast<int>(fFontSize)));
dan sinclaircbe23db2017-10-19 14:29:33 -04002198 return true;
2199}
2200
2201bool Field::set_text_size(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002202 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002203 WideString* sError) {
2204 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04002205 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002206}
2207
Dan Sinclair33d13f22017-10-23 09:44:30 -04002208bool Field::get_type(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002209 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2210 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002211 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002212
Lei Zhangd88a3642015-11-10 09:38:57 -08002213 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002214 switch (pFormField->GetFieldType()) {
2215 case FIELDTYPE_UNKNOWN:
Dan Sinclaire4974922017-10-24 09:36:16 -04002216 vp->Set(pRuntime->NewString(L"unknown"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002217 break;
2218 case FIELDTYPE_PUSHBUTTON:
Dan Sinclaire4974922017-10-24 09:36:16 -04002219 vp->Set(pRuntime->NewString(L"button"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002220 break;
2221 case FIELDTYPE_CHECKBOX:
Dan Sinclaire4974922017-10-24 09:36:16 -04002222 vp->Set(pRuntime->NewString(L"checkbox"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002223 break;
2224 case FIELDTYPE_RADIOBUTTON:
Dan Sinclaire4974922017-10-24 09:36:16 -04002225 vp->Set(pRuntime->NewString(L"radiobutton"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002226 break;
2227 case FIELDTYPE_COMBOBOX:
Dan Sinclaire4974922017-10-24 09:36:16 -04002228 vp->Set(pRuntime->NewString(L"combobox"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002229 break;
2230 case FIELDTYPE_LISTBOX:
Dan Sinclaire4974922017-10-24 09:36:16 -04002231 vp->Set(pRuntime->NewString(L"listbox"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002232 break;
2233 case FIELDTYPE_TEXTFIELD:
Dan Sinclaire4974922017-10-24 09:36:16 -04002234 vp->Set(pRuntime->NewString(L"text"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002235 break;
2236 case FIELDTYPE_SIGNATURE:
Dan Sinclaire4974922017-10-24 09:36:16 -04002237 vp->Set(pRuntime->NewString(L"signature"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002238 break;
2239 default:
Dan Sinclaire4974922017-10-24 09:36:16 -04002240 vp->Set(pRuntime->NewString(L"unknown"));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002241 break;
2242 }
tsepez4cf55152016-11-02 14:37:54 -07002243 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002244}
2245
dan sinclaircbe23db2017-10-19 14:29:33 -04002246bool Field::set_type(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002247 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002248 WideString* sError) {
2249 return false;
2250}
2251
2252bool Field::get_user_name(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002253 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002254 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002255 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002256
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002257 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2258 if (FieldArray.empty())
2259 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002260
Dan Sinclaire4974922017-10-24 09:36:16 -04002261 vp->Set(pRuntime->NewString(FieldArray[0]->GetAlternateName().c_str()));
tsepez4cf55152016-11-02 14:37:54 -07002262 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002263}
2264
dan sinclaircbe23db2017-10-19 14:29:33 -04002265bool Field::set_user_name(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002266 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002267 WideString* sError) {
2268 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04002269 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002270}
2271
dan sinclaircbe23db2017-10-19 14:29:33 -04002272bool Field::get_value(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002273 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002274 WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002275 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2276 if (FieldArray.empty())
2277 return false;
2278
2279 CPDF_FormField* pFormField = FieldArray[0];
2280 switch (pFormField->GetFieldType()) {
2281 case FIELDTYPE_PUSHBUTTON:
2282 return false;
2283 case FIELDTYPE_COMBOBOX:
dan sinclaircbe23db2017-10-19 14:29:33 -04002284 case FIELDTYPE_TEXTFIELD:
Dan Sinclaire4974922017-10-24 09:36:16 -04002285 vp->Set(pRuntime->NewString(pFormField->GetValue().c_str()));
dan sinclaircbe23db2017-10-19 14:29:33 -04002286 break;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002287 case FIELDTYPE_LISTBOX: {
2288 if (pFormField->CountSelectedItems() > 1) {
2289 CJS_Array ValueArray;
Dan Sinclaire4974922017-10-24 09:36:16 -04002290 CJS_Value ElementValue;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002291 int iIndex;
2292 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
2293 iIndex = pFormField->GetSelectedIndex(i);
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04002294 ElementValue = CJS_Value(
2295 pRuntime->NewString(pFormField->GetOptionValue(iIndex).c_str()));
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04002296 if (wcslen(
2297 pRuntime->ToWideString(ElementValue.ToV8Value()).c_str()) ==
2298 0) {
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04002299 ElementValue = CJS_Value(pRuntime->NewString(
2300 pFormField->GetOptionLabel(iIndex).c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002301 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002302 ValueArray.SetElement(pRuntime, i, ElementValue);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002303 }
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04002304
2305 if (ValueArray.ToV8Value().IsEmpty())
2306 vp->Set(pRuntime->NewArray());
2307 else
2308 vp->Set(ValueArray.ToV8Value());
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002309 } else {
Dan Sinclaire4974922017-10-24 09:36:16 -04002310 vp->Set(pRuntime->NewString(pFormField->GetValue().c_str()));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002311 }
dan sinclaircbe23db2017-10-19 14:29:33 -04002312 break;
2313 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002314 case FIELDTYPE_CHECKBOX:
2315 case FIELDTYPE_RADIOBUTTON: {
2316 bool bFind = false;
2317 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2318 if (pFormField->GetControl(i)->IsChecked()) {
Dan Sinclaire4974922017-10-24 09:36:16 -04002319 vp->Set(pRuntime->NewString(
2320 pFormField->GetControl(i)->GetExportValue().c_str()));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002321 bFind = true;
2322 break;
2323 }
2324 }
2325 if (!bFind)
Dan Sinclaire4974922017-10-24 09:36:16 -04002326 vp->Set(pRuntime->NewString(L"Off"));
dan sinclaircbe23db2017-10-19 14:29:33 -04002327
2328 break;
2329 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002330 default:
Dan Sinclaire4974922017-10-24 09:36:16 -04002331 vp->Set(pRuntime->NewString(pFormField->GetValue().c_str()));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002332 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002333 }
Dan Sinclair33d13f22017-10-23 09:44:30 -04002334 vp->MaybeCoerceToNumber(pRuntime);
dan sinclaircbe23db2017-10-19 14:29:33 -04002335 return true;
2336}
2337
2338bool Field::set_value(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002339 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002340 WideString* sError) {
2341 if (!m_bCanSet)
2342 return false;
2343
2344 std::vector<WideString> strArray;
Dan Sinclair33d13f22017-10-23 09:44:30 -04002345 if (vp.IsArrayObject()) {
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04002346 CJS_Array ValueArray(pRuntime->ToArray(vp.ToV8Value()));
dan sinclaircbe23db2017-10-19 14:29:33 -04002347 for (int i = 0, sz = ValueArray.GetLength(pRuntime); i < sz; i++) {
Dan Sinclaire4974922017-10-24 09:36:16 -04002348 CJS_Value ElementValue(ValueArray.GetElement(pRuntime, i));
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04002349 strArray.push_back(pRuntime->ToWideString(ElementValue.ToV8Value()));
dan sinclaircbe23db2017-10-19 14:29:33 -04002350 }
2351 } else {
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04002352 strArray.push_back(pRuntime->ToWideString(vp.ToV8Value()));
dan sinclaircbe23db2017-10-19 14:29:33 -04002353 }
2354
2355 if (m_bDelay) {
2356 AddDelay_WideStringArray(FP_VALUE, strArray);
2357 } else {
2358 Field::SetValue(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
2359 strArray);
2360 }
tsepez4cf55152016-11-02 14:37:54 -07002361 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002362}
2363
dsinclair3a7741a2016-10-11 10:39:49 -07002364void Field::SetValue(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04002365 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002366 int nControlIndex,
Ryan Harrison275e2602017-09-18 14:23:18 -04002367 const std::vector<WideString>& strArray) {
dsinclair3a7741a2016-10-11 10:39:49 -07002368 ASSERT(pFormFillEnv);
tsepez41a53ad2016-03-28 16:59:30 -07002369 if (strArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002370 return;
2371
Lei Zhangd88a3642015-11-10 09:38:57 -08002372 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07002373 GetFormFields(pFormFillEnv, swFieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002374
Lei Zhangd88a3642015-11-10 09:38:57 -08002375 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002376 if (pFormField->GetFullName().Compare(swFieldName) != 0)
2377 continue;
2378
2379 switch (pFormField->GetFieldType()) {
2380 case FIELDTYPE_TEXTFIELD:
2381 case FIELDTYPE_COMBOBOX:
tsepez41a53ad2016-03-28 16:59:30 -07002382 if (pFormField->GetValue() != strArray[0]) {
tsepez4cf55152016-11-02 14:37:54 -07002383 pFormField->SetValue(strArray[0], true);
2384 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002385 }
2386 break;
tsepez41a53ad2016-03-28 16:59:30 -07002387 case FIELDTYPE_CHECKBOX:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002388 case FIELDTYPE_RADIOBUTTON: {
tsepez41a53ad2016-03-28 16:59:30 -07002389 if (pFormField->GetValue() != strArray[0]) {
tsepez4cf55152016-11-02 14:37:54 -07002390 pFormField->SetValue(strArray[0], true);
2391 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002392 }
2393 } break;
2394 case FIELDTYPE_LISTBOX: {
tsepez4cf55152016-11-02 14:37:54 -07002395 bool bModified = false;
tsepez41a53ad2016-03-28 16:59:30 -07002396 for (const auto& str : strArray) {
2397 if (!pFormField->IsItemSelected(pFormField->FindOption(str))) {
tsepez4cf55152016-11-02 14:37:54 -07002398 bModified = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002399 break;
2400 }
2401 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002402 if (bModified) {
tsepez4cf55152016-11-02 14:37:54 -07002403 pFormField->ClearSelection(true);
tsepez41a53ad2016-03-28 16:59:30 -07002404 for (const auto& str : strArray) {
2405 int index = pFormField->FindOption(str);
2406 if (!pFormField->IsItemSelected(index))
tsepez4cf55152016-11-02 14:37:54 -07002407 pFormField->SetItemSelection(index, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002408 }
tsepez4cf55152016-11-02 14:37:54 -07002409 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002410 }
2411 } break;
2412 default:
2413 break;
2414 }
2415 }
2416}
2417
dan sinclaircbe23db2017-10-19 14:29:33 -04002418bool Field::get_value_as_string(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002419 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002420 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002421 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2422 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002423 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002424
Lei Zhangd88a3642015-11-10 09:38:57 -08002425 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002426 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002427 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002428
2429 if (pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) {
2430 if (!pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002431 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002432
Dan Sinclaire4974922017-10-24 09:36:16 -04002433 vp->Set(pRuntime->NewString(
2434 pFormField->GetControl(0)->IsChecked() ? L"Yes" : L"Off"));
dan sinclaircbe23db2017-10-19 14:29:33 -04002435 return true;
2436 }
2437
2438 if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON &&
2439 !(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002440 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2441 if (pFormField->GetControl(i)->IsChecked()) {
Dan Sinclaire4974922017-10-24 09:36:16 -04002442 vp->Set(pRuntime->NewString(
2443 pFormField->GetControl(i)->GetExportValue().c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002444 break;
Lei Zhangd88a3642015-11-10 09:38:57 -08002445 } else {
Dan Sinclaire4974922017-10-24 09:36:16 -04002446 vp->Set(pRuntime->NewString(L"Off"));
Lei Zhangd88a3642015-11-10 09:38:57 -08002447 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002448 }
dan sinclaircbe23db2017-10-19 14:29:33 -04002449 return true;
2450 }
2451
2452 if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX &&
2453 (pFormField->CountSelectedItems() > 1)) {
Dan Sinclaire4974922017-10-24 09:36:16 -04002454 vp->Set(pRuntime->NewString(L""));
Lei Zhangd88a3642015-11-10 09:38:57 -08002455 } else {
Dan Sinclaire4974922017-10-24 09:36:16 -04002456 vp->Set(pRuntime->NewString(pFormField->GetValue().c_str()));
Lei Zhangd88a3642015-11-10 09:38:57 -08002457 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002458
tsepez4cf55152016-11-02 14:37:54 -07002459 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002460}
2461
dan sinclaircbe23db2017-10-19 14:29:33 -04002462bool Field::set_value_as_string(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002463 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002464 WideString* sError) {
2465 return false;
2466}
2467
Tom Sepezb1670b52017-02-16 17:01:00 -08002468bool Field::browseForFileToSubmit(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002469 const std::vector<CJS_Value>& params,
2470 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002471 WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002472 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2473 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002474 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002475
Lei Zhangd88a3642015-11-10 09:38:57 -08002476 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002477 if ((pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) &&
2478 (pFormField->GetFieldType() == FIELDTYPE_TEXTFIELD)) {
Ryan Harrison275e2602017-09-18 14:23:18 -04002479 WideString wsFileName = m_pFormFillEnv->JS_fieldBrowse();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002480 if (!wsFileName.IsEmpty()) {
2481 pFormField->SetValue(wsFileName);
tsepez4cf55152016-11-02 14:37:54 -07002482 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002483 }
tsepez4cf55152016-11-02 14:37:54 -07002484 return true;
Lei Zhangd88a3642015-11-10 09:38:57 -08002485 }
tsepez4cf55152016-11-02 14:37:54 -07002486 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002487}
2488
Tom Sepezb1670b52017-02-16 17:01:00 -08002489bool Field::buttonGetCaption(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002490 const std::vector<CJS_Value>& params,
2491 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002492 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002493 int nface = 0;
2494 int iSize = params.size();
2495 if (iSize >= 1)
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04002496 nface = pRuntime->ToInt32(params[0].ToV8Value());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002497
Lei Zhangd88a3642015-11-10 09:38:57 -08002498 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2499 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002500 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002501
Lei Zhangd88a3642015-11-10 09:38:57 -08002502 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002503 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002504 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002505
2506 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2507 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -07002508 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002509
2510 if (nface == 0)
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04002511 vRet = CJS_Value(
2512 pRuntime->NewString(pFormControl->GetNormalCaption().c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002513 else if (nface == 1)
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04002514 vRet =
2515 CJS_Value(pRuntime->NewString(pFormControl->GetDownCaption().c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002516 else if (nface == 2)
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04002517 vRet = CJS_Value(
2518 pRuntime->NewString(pFormControl->GetRolloverCaption().c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002519 else
tsepez4cf55152016-11-02 14:37:54 -07002520 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002521
tsepez4cf55152016-11-02 14:37:54 -07002522 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002523}
2524
Tom Sepezb1670b52017-02-16 17:01:00 -08002525bool Field::buttonGetIcon(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002526 const std::vector<CJS_Value>& params,
2527 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002528 WideString& sError) {
Tom Sepez40e0a812017-02-23 13:07:36 -08002529 if (params.size() >= 1) {
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04002530 int nFace = pRuntime->ToInt32(params[0].ToV8Value());
Tom Sepez40e0a812017-02-23 13:07:36 -08002531 if (nFace < 0 || nFace > 2)
2532 return false;
2533 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002534
Lei Zhangd88a3642015-11-10 09:38:57 -08002535 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2536 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002537 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002538
Lei Zhangd88a3642015-11-10 09:38:57 -08002539 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002540 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002541 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002542
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002543 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2544 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -07002545 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002546
tsepezb4694242016-08-15 16:44:55 -07002547 v8::Local<v8::Object> pObj =
2548 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID);
Tom Sepezc5a14722017-02-24 15:31:12 -08002549 if (pObj.IsEmpty())
2550 return false;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002551
tsepezb4694242016-08-15 16:44:55 -07002552 CJS_Icon* pJS_Icon = static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj));
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04002553 if (pJS_Icon)
2554 vRet = CJS_Value(pJS_Icon->ToV8Object());
2555
tsepez4cf55152016-11-02 14:37:54 -07002556 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002557}
2558
Tom Sepezb1670b52017-02-16 17:01:00 -08002559bool Field::buttonImportIcon(CJS_Runtime* pRuntime,
Lei Zhang945fdb72015-11-11 10:18:16 -08002560 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002561 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002562 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002563 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002564}
2565
Tom Sepezb1670b52017-02-16 17:01:00 -08002566bool Field::buttonSetCaption(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002567 const std::vector<CJS_Value>& params,
2568 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002569 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002570 return false;
2571}
2572
Tom Sepezb1670b52017-02-16 17:01:00 -08002573bool Field::buttonSetIcon(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002574 const std::vector<CJS_Value>& params,
2575 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002576 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002577 return false;
2578}
2579
Tom Sepezb1670b52017-02-16 17:01:00 -08002580bool Field::checkThisBox(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002581 const std::vector<CJS_Value>& params,
2582 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002583 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002584 int iSize = params.size();
2585 if (iSize < 1)
tsepez4cf55152016-11-02 14:37:54 -07002586 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002587
tsepezf3dc8c62016-08-10 06:29:29 -07002588 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002589 return false;
tsepezf3dc8c62016-08-10 06:29:29 -07002590
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04002591 int nWidget = pRuntime->ToInt32(params[0].ToV8Value());
Wei Li97da9762016-03-11 17:00:48 -08002592 bool bCheckit = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002593 if (iSize >= 2)
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04002594 bCheckit = pRuntime->ToBoolean(params[1].ToV8Value());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002595
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;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002599
Lei Zhangd88a3642015-11-10 09:38:57 -08002600 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002601 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
2602 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002603 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002604 if (nWidget < 0 || nWidget >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002605 return false;
Wei Li97da9762016-03-11 17:00:48 -08002606 // TODO(weili): Check whether anything special needed for radio button,
2607 // otherwise merge these branches.
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002608 if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)
Wei Li97da9762016-03-11 17:00:48 -08002609 pFormField->CheckControl(nWidget, bCheckit, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002610 else
Wei Li97da9762016-03-11 17:00:48 -08002611 pFormField->CheckControl(nWidget, bCheckit, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002612
tsepez4cf55152016-11-02 14:37:54 -07002613 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true);
2614 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002615}
2616
Tom Sepezb1670b52017-02-16 17:01:00 -08002617bool Field::clearItems(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002618 const std::vector<CJS_Value>& params,
2619 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002620 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002621 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002622}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002623
Tom Sepezb1670b52017-02-16 17:01:00 -08002624bool Field::defaultIsChecked(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002625 const std::vector<CJS_Value>& params,
2626 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002627 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002628 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002629 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002630
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002631 int iSize = params.size();
2632 if (iSize < 1)
tsepez4cf55152016-11-02 14:37:54 -07002633 return false;
Tom Sepezf4ef3f92015-04-23 11:31:31 -07002634
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04002635 int nWidget = pRuntime->ToInt32(params[0].ToV8Value());
Lei Zhangd88a3642015-11-10 09:38:57 -08002636 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2637 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002638 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002639
Lei Zhangd88a3642015-11-10 09:38:57 -08002640 CPDF_FormField* pFormField = FieldArray[0];
tsepezf3dc8c62016-08-10 06:29:29 -07002641 if (nWidget < 0 || nWidget >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002642 return false;
tsepezf3dc8c62016-08-10 06:29:29 -07002643
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04002644 vRet = CJS_Value(pRuntime->NewBoolean(
2645 pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
2646 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002647
tsepez4cf55152016-11-02 14:37:54 -07002648 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002649}
2650
Tom Sepezb1670b52017-02-16 17:01:00 -08002651bool Field::deleteItemAt(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002652 const std::vector<CJS_Value>& params,
2653 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002654 WideString& sError) {
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::getArray(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) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002662 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2663 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002664 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002665
Ryan Harrison275e2602017-09-18 14:23:18 -04002666 std::vector<std::unique_ptr<WideString>> swSort;
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002667 for (CPDF_FormField* pFormField : FieldArray) {
Ryan Harrison275e2602017-09-18 14:23:18 -04002668 swSort.push_back(
2669 std::unique_ptr<WideString>(new WideString(pFormField->GetFullName())));
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002670 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002671
Ryan Harrison275e2602017-09-18 14:23:18 -04002672 std::sort(swSort.begin(), swSort.end(),
2673 [](const std::unique_ptr<WideString>& p1,
2674 const std::unique_ptr<WideString>& p2) { return *p1 < *p2; });
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002675
tsepeze5aff742016-08-08 09:49:42 -07002676 CJS_Array FormFieldArray;
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002677
2678 int j = 0;
2679 for (const auto& pStr : swSort) {
tsepezb4694242016-08-15 16:44:55 -07002680 v8::Local<v8::Object> pObj =
2681 pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID);
Tom Sepezc5a14722017-02-24 15:31:12 -08002682 if (pObj.IsEmpty())
2683 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002684
Tom Sepezd5a0e952015-09-17 15:40:06 -07002685 CJS_Field* pJSField =
tsepezb4694242016-08-15 16:44:55 -07002686 static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pObj));
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002687 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002688 pField->AttachField(m_pJSDoc, *pStr);
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04002689 FormFieldArray.SetElement(
2690 pRuntime, j++,
2691 pJSField ? CJS_Value(pJSField->ToV8Object()) : CJS_Value());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002692 }
2693
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04002694 if (FormFieldArray.ToV8Value().IsEmpty())
2695 vRet = CJS_Value(pRuntime->NewArray());
2696 else
2697 vRet = CJS_Value(FormFieldArray.ToV8Value());
2698
tsepez4cf55152016-11-02 14:37:54 -07002699 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002700}
2701
Tom Sepezb1670b52017-02-16 17:01:00 -08002702bool Field::getItemAt(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002703 const std::vector<CJS_Value>& params,
2704 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002705 WideString& sError) {
tsepezf3dc8c62016-08-10 06:29:29 -07002706 int iSize = params.size();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002707 int nIdx = -1;
2708 if (iSize >= 1)
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04002709 nIdx = pRuntime->ToInt32(params[0].ToV8Value());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002710
tsepez4cf55152016-11-02 14:37:54 -07002711 bool bExport = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002712 if (iSize >= 2)
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04002713 bExport = pRuntime->ToBoolean(params[1].ToV8Value());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002714
Lei Zhangd88a3642015-11-10 09:38:57 -08002715 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2716 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002717 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002718
Lei Zhangd88a3642015-11-10 09:38:57 -08002719 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002720 if ((pFormField->GetFieldType() == FIELDTYPE_LISTBOX) ||
2721 (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX)) {
2722 if (nIdx == -1 || nIdx > pFormField->CountOptions())
2723 nIdx = pFormField->CountOptions() - 1;
2724 if (bExport) {
Ryan Harrison275e2602017-09-18 14:23:18 -04002725 WideString strval = pFormField->GetOptionValue(nIdx);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002726 if (strval.IsEmpty())
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04002727 vRet = CJS_Value(
2728 pRuntime->NewString(pFormField->GetOptionLabel(nIdx).c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002729 else
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04002730 vRet = CJS_Value(pRuntime->NewString(strval.c_str()));
Lei Zhangd88a3642015-11-10 09:38:57 -08002731 } else {
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04002732 vRet = CJS_Value(
2733 pRuntime->NewString(pFormField->GetOptionLabel(nIdx).c_str()));
Lei Zhangd88a3642015-11-10 09:38:57 -08002734 }
2735 } else {
tsepez4cf55152016-11-02 14:37:54 -07002736 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08002737 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002738
tsepez4cf55152016-11-02 14:37:54 -07002739 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002740}
2741
Tom Sepezb1670b52017-02-16 17:01:00 -08002742bool Field::getLock(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002743 const std::vector<CJS_Value>& params,
2744 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002745 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002746 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002747}
2748
Tom Sepezb1670b52017-02-16 17:01:00 -08002749bool Field::insertItemAt(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002750 const std::vector<CJS_Value>& params,
2751 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002752 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002753 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002754}
2755
Tom Sepezb1670b52017-02-16 17:01:00 -08002756bool Field::isBoxChecked(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002757 const std::vector<CJS_Value>& params,
2758 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002759 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002760 int nIndex = -1;
2761 if (params.size() >= 1)
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04002762 nIndex = pRuntime->ToInt32(params[0].ToV8Value());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002763
Lei Zhangd88a3642015-11-10 09:38:57 -08002764 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2765 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002766 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002767
Lei Zhangd88a3642015-11-10 09:38:57 -08002768 CPDF_FormField* pFormField = FieldArray[0];
dan sinclair646634b2017-10-19 14:30:28 -04002769 if (nIndex < 0 || nIndex >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002770 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002771
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04002772 vRet = CJS_Value(pRuntime->NewBoolean(
2773 ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
2774 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) &&
2775 pFormField->GetControl(nIndex)->IsChecked() != 0)));
tsepez4cf55152016-11-02 14:37:54 -07002776 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002777}
2778
Tom Sepezb1670b52017-02-16 17:01:00 -08002779bool Field::isDefaultChecked(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002780 const std::vector<CJS_Value>& params,
2781 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002782 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002783 int nIndex = -1;
2784 if (params.size() >= 1)
Dan Sinclair1b2a18e2017-10-24 13:56:29 -04002785 nIndex = pRuntime->ToInt32(params[0].ToV8Value());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002786
Lei Zhangd88a3642015-11-10 09:38:57 -08002787 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2788 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002789 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002790
Lei Zhangd88a3642015-11-10 09:38:57 -08002791 CPDF_FormField* pFormField = FieldArray[0];
tsepezf3dc8c62016-08-10 06:29:29 -07002792 if (nIndex < 0 || nIndex >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002793 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002794
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -04002795 vRet = CJS_Value(pRuntime->NewBoolean(
2796 ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
2797 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) &&
2798 pFormField->GetControl(nIndex)->IsDefaultChecked() != 0)));
tsepez4cf55152016-11-02 14:37:54 -07002799 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002800}
2801
Tom Sepezb1670b52017-02-16 17:01:00 -08002802bool Field::setAction(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002803 const std::vector<CJS_Value>& params,
2804 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002805 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002806 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002807}
2808
Tom Sepezb1670b52017-02-16 17:01:00 -08002809bool Field::setFocus(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002810 const std::vector<CJS_Value>& params,
2811 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002812 WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002813 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2814 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002815 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002816
Lei Zhangd88a3642015-11-10 09:38:57 -08002817 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002818 int32_t nCount = pFormField->CountControls();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002819 if (nCount < 1)
tsepez4cf55152016-11-02 14:37:54 -07002820 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002821
dsinclair7cbe68e2016-10-12 11:56:23 -07002822 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
thestig1cd352e2016-06-07 17:53:06 -07002823 CPDFSDK_Widget* pWidget = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002824 if (nCount == 1) {
dsinclairc5267c52016-11-04 15:35:12 -07002825 pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002826 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002827 UnderlyingPageType* pPage =
2828 UnderlyingFromFPDFPage(m_pFormFillEnv->GetCurrentPage(
2829 m_pFormFillEnv->GetUnderlyingDocument()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002830 if (!pPage)
tsepez4cf55152016-11-02 14:37:54 -07002831 return false;
dsinclair461eeaf2016-07-27 07:40:05 -07002832 if (CPDFSDK_PageView* pCurPageView =
dsinclair7cbe68e2016-10-12 11:56:23 -07002833 m_pFormFillEnv->GetPageView(pPage, true)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002834 for (int32_t i = 0; i < nCount; i++) {
2835 if (CPDFSDK_Widget* pTempWidget =
dsinclairc5267c52016-11-04 15:35:12 -07002836 pInterForm->GetWidget(pFormField->GetControl(i))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002837 if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage()) {
2838 pWidget = pTempWidget;
2839 break;
2840 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002841 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002842 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002843 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002844 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002845
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002846 if (pWidget) {
tsepezf8074ce2016-09-27 14:29:57 -07002847 CPDFSDK_Annot::ObservedPtr pObserved(pWidget);
dsinclair7cbe68e2016-10-12 11:56:23 -07002848 m_pFormFillEnv->SetFocusAnnot(&pObserved);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002849 }
2850
tsepez4cf55152016-11-02 14:37:54 -07002851 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002852}
2853
Tom Sepezb1670b52017-02-16 17:01:00 -08002854bool Field::setItems(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002855 const std::vector<CJS_Value>& params,
2856 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002857 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002858 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002859}
2860
Tom Sepezb1670b52017-02-16 17:01:00 -08002861bool Field::setLock(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002862 const std::vector<CJS_Value>& params,
2863 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002864 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002865 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002866}
2867
Tom Sepezb1670b52017-02-16 17:01:00 -08002868bool Field::signatureGetModifications(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002869 const std::vector<CJS_Value>& params,
2870 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002871 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002872 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002873}
2874
Tom Sepezb1670b52017-02-16 17:01:00 -08002875bool Field::signatureGetSeedValue(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002876 const std::vector<CJS_Value>& params,
2877 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002878 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002879 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002880}
2881
Tom Sepezb1670b52017-02-16 17:01:00 -08002882bool Field::signatureInfo(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002883 const std::vector<CJS_Value>& params,
2884 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002885 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002886 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002887}
2888
Tom Sepezb1670b52017-02-16 17:01:00 -08002889bool Field::signatureSetSeedValue(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002890 const std::vector<CJS_Value>& params,
2891 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002892 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002893 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002894}
2895
Tom Sepezb1670b52017-02-16 17:01:00 -08002896bool Field::signatureSign(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002897 const std::vector<CJS_Value>& params,
2898 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002899 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002900 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002901}
2902
Tom Sepezb1670b52017-02-16 17:01:00 -08002903bool Field::signatureValidate(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002904 const std::vector<CJS_Value>& params,
2905 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002906 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002907 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002908}
2909
dan sinclaircbe23db2017-10-19 14:29:33 -04002910bool Field::get_source(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002911 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002912 WideString* sError) {
Dan Sinclaire4974922017-10-24 09:36:16 -04002913 vp->Set(v8::Local<v8::Value>());
dan sinclaircbe23db2017-10-19 14:29:33 -04002914 return true;
2915}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002916
dan sinclaircbe23db2017-10-19 14:29:33 -04002917bool Field::set_source(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -04002918 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -04002919 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -07002920 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002921}
2922
tsepez41a53ad2016-03-28 16:59:30 -07002923void Field::AddDelay_Int(FIELD_PROP prop, int32_t n) {
2924 CJS_DelayData* pNewData =
2925 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002926 pNewData->num = n;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002927 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002928}
2929
tsepez41a53ad2016-03-28 16:59:30 -07002930void Field::AddDelay_Bool(FIELD_PROP prop, bool b) {
2931 CJS_DelayData* pNewData =
2932 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002933 pNewData->b = b;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002934 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002935}
2936
Ryan Harrison275e2602017-09-18 14:23:18 -04002937void Field::AddDelay_String(FIELD_PROP prop, const ByteString& string) {
tsepez41a53ad2016-03-28 16:59:30 -07002938 CJS_DelayData* pNewData =
2939 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002940 pNewData->string = string;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002941 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002942}
2943
tsepez41a53ad2016-03-28 16:59:30 -07002944void Field::AddDelay_Rect(FIELD_PROP prop, const CFX_FloatRect& rect) {
2945 CJS_DelayData* pNewData =
2946 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002947 pNewData->rect = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002948 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002949}
2950
tsepez41a53ad2016-03-28 16:59:30 -07002951void Field::AddDelay_WordArray(FIELD_PROP prop,
2952 const std::vector<uint32_t>& array) {
2953 CJS_DelayData* pNewData =
2954 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
2955 pNewData->wordarray = array;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002956 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002957}
2958
tsepez41a53ad2016-03-28 16:59:30 -07002959void Field::AddDelay_WideStringArray(FIELD_PROP prop,
Ryan Harrison275e2602017-09-18 14:23:18 -04002960 const std::vector<WideString>& array) {
tsepez41a53ad2016-03-28 16:59:30 -07002961 CJS_DelayData* pNewData =
2962 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
2963 pNewData->widestringarray = array;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002964 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002965}
2966
dsinclair3a7741a2016-10-11 10:39:49 -07002967void Field::DoDelay(CPDFSDK_FormFillEnvironment* pFormFillEnv,
2968 CJS_DelayData* pData) {
2969 ASSERT(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002970 switch (pData->eProp) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002971 case FP_BORDERSTYLE:
dsinclair3a7741a2016-10-11 10:39:49 -07002972 Field::SetBorderStyle(pFormFillEnv, pData->sFieldName,
2973 pData->nControlIndex, pData->string);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002974 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002975 case FP_CURRENTVALUEINDICES:
dsinclair3a7741a2016-10-11 10:39:49 -07002976 Field::SetCurrentValueIndices(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002977 pData->nControlIndex, pData->wordarray);
2978 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002979 case FP_DISPLAY:
dsinclair3a7741a2016-10-11 10:39:49 -07002980 Field::SetDisplay(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002981 pData->num);
2982 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002983 case FP_HIDDEN:
dsinclair3a7741a2016-10-11 10:39:49 -07002984 Field::SetHidden(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002985 pData->b);
2986 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002987 case FP_LINEWIDTH:
dsinclair3a7741a2016-10-11 10:39:49 -07002988 Field::SetLineWidth(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002989 pData->num);
2990 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002991 case FP_RECT:
dsinclair3a7741a2016-10-11 10:39:49 -07002992 Field::SetRect(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002993 pData->rect);
2994 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002995 case FP_VALUE:
dsinclair3a7741a2016-10-11 10:39:49 -07002996 Field::SetValue(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002997 pData->widestringarray);
2998 break;
dan sinclair646634b2017-10-19 14:30:28 -04002999 default:
3000 NOTREACHED();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003001 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003002}