blob: 0eaad733466a338530711ac6b63d50c6dcd6bdb2 [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
170IMPLEMENT_JS_CLASS(CJS_Field, Field)
171
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,
385 CJS_PropValue* vp,
386 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:
403 vp->Set(L"center");
404 break;
405 case 0:
406 vp->Set(L"left");
407 break;
408 case 2:
409 vp->Set(L"right");
410 break;
411 default:
412 vp->Set(L"");
413 }
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,
419 const CJS_PropValue& vp,
420 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,
426 CJS_PropValue* vp,
427 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:
445 vp->Set(L"solid");
446 break;
447 case BorderStyle::DASH:
448 vp->Set(L"dashed");
449 break;
450 case BorderStyle::BEVELED:
451 vp->Set(L"beveled");
452 break;
453 case BorderStyle::INSET:
454 vp->Set(L"inset");
455 break;
456 case BorderStyle::UNDERLINE:
457 vp->Set(L"underline");
458 break;
459 default:
460 vp->Set(L"");
461 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,
467 const CJS_PropValue& vp,
468 WideString* sError) {
469 ASSERT(m_pFormFillEnv);
470
471 if (!m_bCanSet)
472 return false;
473
474 if (m_bDelay) {
475 AddDelay_String(FP_BORDERSTYLE, vp.ToByteString());
476 } else {
477 Field::SetBorderStyle(m_pFormFillEnv.Get(), m_FieldName,
478 m_nFormControlIndex, vp.ToByteString());
479 }
tsepez4cf55152016-11-02 14:37:54 -0700480 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700481}
482
dsinclair3a7741a2016-10-11 10:39:49 -0700483void Field::SetBorderStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -0400484 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700485 int nControlIndex,
Ryan Harrison275e2602017-09-18 14:23:18 -0400486 const ByteString& string) {
dsinclair3a7741a2016-10-11 10:39:49 -0700487 ASSERT(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700488
dsinclair92cb5e52016-05-16 11:38:28 -0700489 BorderStyle nBorderStyle = BorderStyle::SOLID;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700490 if (string == "solid")
dsinclair92cb5e52016-05-16 11:38:28 -0700491 nBorderStyle = BorderStyle::SOLID;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700492 else if (string == "beveled")
dsinclair92cb5e52016-05-16 11:38:28 -0700493 nBorderStyle = BorderStyle::BEVELED;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700494 else if (string == "dashed")
dsinclair92cb5e52016-05-16 11:38:28 -0700495 nBorderStyle = BorderStyle::DASH;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700496 else if (string == "inset")
dsinclair92cb5e52016-05-16 11:38:28 -0700497 nBorderStyle = BorderStyle::INSET;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700498 else if (string == "underline")
dsinclair92cb5e52016-05-16 11:38:28 -0700499 nBorderStyle = BorderStyle::UNDERLINE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700500 else
501 return;
502
Lei Zhangd88a3642015-11-10 09:38:57 -0800503 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -0700504 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -0800505 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700506 if (nControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -0700507 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -0800508 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700509 if (CPDFSDK_Widget* pWidget =
dsinclairc5267c52016-11-04 15:35:12 -0700510 GetWidget(pFormFillEnv, pFormField->GetControl(i))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700511 if (pWidget->GetBorderStyle() != nBorderStyle) {
512 pWidget->SetBorderStyle(nBorderStyle);
tsepez4cf55152016-11-02 14:37:54 -0700513 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700514 }
515 }
516 }
517 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -0700518 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700519 } else {
520 if (nControlIndex >= pFormField->CountControls())
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700521 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700522 if (CPDF_FormControl* pFormControl =
523 pFormField->GetControl(nControlIndex)) {
dsinclairc5267c52016-11-04 15:35:12 -0700524 if (CPDFSDK_Widget* pWidget = GetWidget(pFormFillEnv, pFormControl)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700525 if (pWidget->GetBorderStyle() != nBorderStyle) {
526 pWidget->SetBorderStyle(nBorderStyle);
tsepez4cf55152016-11-02 14:37:54 -0700527 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700528 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700529 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700530 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700531 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700532 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700533}
534
dan sinclaircbe23db2017-10-19 14:29:33 -0400535bool Field::get_button_align_x(CJS_Runtime* pRuntime,
536 CJS_PropValue* vp,
537 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700538 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700539
dan sinclaircbe23db2017-10-19 14:29:33 -0400540 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
541 if (FieldArray.empty())
542 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700543
dan sinclaircbe23db2017-10-19 14:29:33 -0400544 CPDF_FormField* pFormField = FieldArray[0];
545 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
546 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700547
dan sinclaircbe23db2017-10-19 14:29:33 -0400548 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
549 if (!pFormControl)
550 return false;
551
552 CPDF_IconFit IconFit = pFormControl->GetIconFit();
553
554 float fLeft;
555 float fBottom;
556 IconFit.GetIconPosition(fLeft, fBottom);
557
558 vp->Set(static_cast<int32_t>(fLeft));
559 return true;
560}
561
562bool Field::set_button_align_x(CJS_Runtime* pRuntime,
563 const CJS_PropValue& vp,
564 WideString* sError) {
565 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400566 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700567}
568
dan sinclaircbe23db2017-10-19 14:29:33 -0400569bool Field::get_button_align_y(CJS_Runtime* pRuntime,
570 CJS_PropValue* vp,
571 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700572 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700573
dan sinclaircbe23db2017-10-19 14:29:33 -0400574 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
575 if (FieldArray.empty())
576 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700577
dan sinclaircbe23db2017-10-19 14:29:33 -0400578 CPDF_FormField* pFormField = FieldArray[0];
579 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
580 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700581
dan sinclaircbe23db2017-10-19 14:29:33 -0400582 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
583 if (!pFormControl)
584 return false;
585
586 CPDF_IconFit IconFit = pFormControl->GetIconFit();
587
588 float fLeft;
589 float fBottom;
590 IconFit.GetIconPosition(fLeft, fBottom);
591
592 vp->Set(static_cast<int32_t>(fBottom));
593 return true;
594}
595
596bool Field::set_button_align_y(CJS_Runtime* pRuntime,
597 const CJS_PropValue& vp,
598 WideString* sError) {
599 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400600 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700601}
602
dan sinclaircbe23db2017-10-19 14:29:33 -0400603bool Field::get_button_fit_bounds(CJS_Runtime* pRuntime,
604 CJS_PropValue* vp,
605 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700606 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700607
dan sinclair646634b2017-10-19 14:30:28 -0400608 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
609 if (FieldArray.empty())
610 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700611
dan sinclair646634b2017-10-19 14:30:28 -0400612 CPDF_FormField* pFormField = FieldArray[0];
613 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
614 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700615
dan sinclair646634b2017-10-19 14:30:28 -0400616 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
617 if (!pFormControl)
618 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700619
dan sinclair646634b2017-10-19 14:30:28 -0400620 vp->Set(pFormControl->GetIconFit().GetFittingBounds());
621 return true;
dan sinclaircbe23db2017-10-19 14:29:33 -0400622}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700623
dan sinclaircbe23db2017-10-19 14:29:33 -0400624bool Field::set_button_fit_bounds(CJS_Runtime* pRuntime,
625 const CJS_PropValue& vp,
626 WideString* sError) {
627 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400628 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700629}
630
dan sinclaircbe23db2017-10-19 14:29:33 -0400631bool Field::get_button_position(CJS_Runtime* pRuntime,
632 CJS_PropValue* vp,
633 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700634 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700635
dan sinclair646634b2017-10-19 14:30:28 -0400636 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
637 if (FieldArray.empty())
638 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700639
dan sinclair646634b2017-10-19 14:30:28 -0400640 CPDF_FormField* pFormField = FieldArray[0];
641 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
642 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700643
dan sinclair646634b2017-10-19 14:30:28 -0400644 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
645 if (!pFormControl)
646 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700647
dan sinclair646634b2017-10-19 14:30:28 -0400648 vp->Set(pFormControl->GetTextPosition());
649 return true;
dan sinclaircbe23db2017-10-19 14:29:33 -0400650}
651
652bool Field::set_button_position(CJS_Runtime* pRuntime,
653 const CJS_PropValue& vp,
654 WideString* sError) {
655 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400656 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700657}
658
dan sinclaircbe23db2017-10-19 14:29:33 -0400659bool Field::get_button_scale_how(CJS_Runtime* pRuntime,
660 CJS_PropValue* vp,
661 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700662 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700663
dan sinclair646634b2017-10-19 14:30:28 -0400664 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
665 if (FieldArray.empty())
666 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700667
dan sinclair646634b2017-10-19 14:30:28 -0400668 CPDF_FormField* pFormField = FieldArray[0];
669 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
670 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700671
dan sinclair646634b2017-10-19 14:30:28 -0400672 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
673 if (!pFormControl)
674 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700675
dan sinclair646634b2017-10-19 14:30:28 -0400676 vp->Set(pFormControl->GetIconFit().IsProportionalScale() ? 0 : 1);
677 return true;
dan sinclaircbe23db2017-10-19 14:29:33 -0400678}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700679
dan sinclaircbe23db2017-10-19 14:29:33 -0400680bool Field::set_button_scale_how(CJS_Runtime* pRuntime,
681 const CJS_PropValue& vp,
682 WideString* sError) {
683 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400684 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700685}
686
dan sinclaircbe23db2017-10-19 14:29:33 -0400687bool Field::get_button_scale_when(CJS_Runtime* pRuntime,
688 CJS_PropValue* vp,
689 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700690 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700691
dan sinclair646634b2017-10-19 14:30:28 -0400692 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
693 if (FieldArray.empty())
694 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700695
dan sinclair646634b2017-10-19 14:30:28 -0400696 CPDF_FormField* pFormField = FieldArray[0];
697 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
698 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700699
dan sinclair646634b2017-10-19 14:30:28 -0400700 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
701 if (!pFormControl)
702 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700703
dan sinclair646634b2017-10-19 14:30:28 -0400704 CPDF_IconFit IconFit = pFormControl->GetIconFit();
705 int ScaleM = IconFit.GetScaleMethod();
706 switch (ScaleM) {
707 case CPDF_IconFit::Always:
708 vp->Set(static_cast<int32_t>(CPDF_IconFit::Always));
709 break;
710 case CPDF_IconFit::Bigger:
711 vp->Set(static_cast<int32_t>(CPDF_IconFit::Bigger));
712 break;
713 case CPDF_IconFit::Never:
714 vp->Set(static_cast<int32_t>(CPDF_IconFit::Never));
715 break;
716 case CPDF_IconFit::Smaller:
717 vp->Set(static_cast<int32_t>(CPDF_IconFit::Smaller));
718 break;
719 }
720 return true;
dan sinclaircbe23db2017-10-19 14:29:33 -0400721}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700722
dan sinclaircbe23db2017-10-19 14:29:33 -0400723bool Field::set_button_scale_when(CJS_Runtime* pRuntime,
724 const CJS_PropValue& vp,
725 WideString* sError) {
726 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400727 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700728}
729
dan sinclaircbe23db2017-10-19 14:29:33 -0400730bool Field::get_calc_order_index(CJS_Runtime* pRuntime,
731 CJS_PropValue* vp,
732 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700733 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700734
dan sinclair646634b2017-10-19 14:30:28 -0400735 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
736 if (FieldArray.empty())
737 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700738
dan sinclair646634b2017-10-19 14:30:28 -0400739 CPDF_FormField* pFormField = FieldArray[0];
740 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
741 pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) {
742 return false;
743 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700744
dan sinclair646634b2017-10-19 14:30:28 -0400745 CPDFSDK_InterForm* pRDInterForm = m_pFormFillEnv->GetInterForm();
746 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
747 vp->Set(static_cast<int32_t>(
748 pInterForm->FindFieldInCalculationOrder(pFormField)));
749 return true;
dan sinclaircbe23db2017-10-19 14:29:33 -0400750}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700751
dan sinclaircbe23db2017-10-19 14:29:33 -0400752bool Field::set_calc_order_index(CJS_Runtime* pRuntime,
753 const CJS_PropValue& vp,
754 WideString* sError) {
755 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400756 return m_bCanSet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700757}
758
dan sinclaircbe23db2017-10-19 14:29:33 -0400759bool Field::get_char_limit(CJS_Runtime* pRuntime,
760 CJS_PropValue* vp,
761 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700762 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700763
dan sinclaircbe23db2017-10-19 14:29:33 -0400764 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
765 if (FieldArray.empty())
766 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700767
dan sinclaircbe23db2017-10-19 14:29:33 -0400768 CPDF_FormField* pFormField = FieldArray[0];
769 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
770 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700771
dan sinclaircbe23db2017-10-19 14:29:33 -0400772 vp->Set(static_cast<int32_t>(pFormField->GetMaxLen()));
773 return true;
774}
775
776bool Field::set_char_limit(CJS_Runtime* pRuntime,
777 const CJS_PropValue& vp,
778 WideString* sError) {
779 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400780 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700781}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700782
dan sinclaircbe23db2017-10-19 14:29:33 -0400783bool Field::get_comb(CJS_Runtime* pRuntime,
784 CJS_PropValue* vp,
785 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700786 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700787
dan sinclaircbe23db2017-10-19 14:29:33 -0400788 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
789 if (FieldArray.empty())
790 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700791
dan sinclaircbe23db2017-10-19 14:29:33 -0400792 CPDF_FormField* pFormField = FieldArray[0];
793 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
794 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700795
dan sinclaircbe23db2017-10-19 14:29:33 -0400796 vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_COMB));
797 return true;
798}
799
800bool Field::set_comb(CJS_Runtime* pRuntime,
801 const CJS_PropValue& vp,
802 WideString* sError) {
803 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400804 return m_bCanSet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700805}
806
dan sinclaircbe23db2017-10-19 14:29:33 -0400807bool Field::get_commit_on_sel_change(CJS_Runtime* pRuntime,
808 CJS_PropValue* vp,
809 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700810 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700811
dan sinclair646634b2017-10-19 14:30:28 -0400812 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
813 if (FieldArray.empty())
814 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700815
dan sinclair646634b2017-10-19 14:30:28 -0400816 CPDF_FormField* pFormField = FieldArray[0];
817 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
818 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
819 return false;
820 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700821
dan sinclair646634b2017-10-19 14:30:28 -0400822 vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE));
823 return true;
dan sinclaircbe23db2017-10-19 14:29:33 -0400824}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700825
dan sinclaircbe23db2017-10-19 14:29:33 -0400826bool Field::set_commit_on_sel_change(CJS_Runtime* pRuntime,
827 const CJS_PropValue& vp,
828 WideString* sError) {
829 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400830 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700831}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700832
dan sinclaircbe23db2017-10-19 14:29:33 -0400833bool Field::get_current_value_indices(CJS_Runtime* pRuntime,
834 CJS_PropValue* vp,
835 WideString* sError) {
836 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
837 if (FieldArray.empty())
838 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700839
dan sinclaircbe23db2017-10-19 14:29:33 -0400840 CPDF_FormField* pFormField = FieldArray[0];
841 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
842 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
843 return false;
844 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700845
dan sinclaircbe23db2017-10-19 14:29:33 -0400846 int count = pFormField->CountSelectedItems();
847 if (count <= 0) {
848 vp->Set(-1);
849 return true;
850 }
851 if (count == 1) {
852 vp->Set(pFormField->GetSelectedIndex(0));
853 return true;
854 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700855
dan sinclaircbe23db2017-10-19 14:29:33 -0400856 CJS_Array SelArray;
857 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
858 SelArray.SetElement(pRuntime, i,
859 CJS_Value(pRuntime, pFormField->GetSelectedIndex(i)));
860 }
861 vp->Set(SelArray);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700862
dan sinclaircbe23db2017-10-19 14:29:33 -0400863 return true;
864}
865
866bool Field::set_current_value_indices(CJS_Runtime* pRuntime,
867 const CJS_PropValue& vp,
868 WideString* sError) {
869 if (!m_bCanSet)
870 return false;
871
872 std::vector<uint32_t> array;
873 if (vp.GetJSValue()->GetType() == CJS_Value::VT_number) {
874 array.push_back(vp.ToInt());
875 } else if (vp.GetJSValue()->IsArrayObject()) {
876 CJS_Array SelArray = vp.ToArray();
877 CJS_Value SelValue(pRuntime);
878 for (int i = 0, sz = SelArray.GetLength(pRuntime); i < sz; i++) {
879 SelArray.GetElement(pRuntime, i, SelValue);
880 array.push_back(SelValue.ToInt(pRuntime));
Lei Zhangd88a3642015-11-10 09:38:57 -0800881 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700882 }
883
dan sinclaircbe23db2017-10-19 14:29:33 -0400884 if (m_bDelay) {
885 AddDelay_WordArray(FP_CURRENTVALUEINDICES, array);
886 } else {
887 Field::SetCurrentValueIndices(m_pFormFillEnv.Get(), m_FieldName,
888 m_nFormControlIndex, array);
889 }
tsepez4cf55152016-11-02 14:37:54 -0700890 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700891}
892
dsinclair3a7741a2016-10-11 10:39:49 -0700893void Field::SetCurrentValueIndices(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -0400894 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700895 int nControlIndex,
tsepez41a53ad2016-03-28 16:59:30 -0700896 const std::vector<uint32_t>& array) {
dsinclair3a7741a2016-10-11 10:39:49 -0700897 ASSERT(pFormFillEnv);
Lei Zhangd88a3642015-11-10 09:38:57 -0800898 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -0700899 GetFormFields(pFormFillEnv, swFieldName);
tsepez41a53ad2016-03-28 16:59:30 -0700900
Lei Zhangd88a3642015-11-10 09:38:57 -0800901 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700902 int nFieldType = pFormField->GetFieldType();
903 if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX) {
tsepezc3255f52016-03-25 14:52:27 -0700904 uint32_t dwFieldFlags = pFormField->GetFieldFlags();
tsepez4cf55152016-11-02 14:37:54 -0700905 pFormField->ClearSelection(true);
tsepez41a53ad2016-03-28 16:59:30 -0700906 for (size_t i = 0; i < array.size(); ++i) {
907 if (i != 0 && !(dwFieldFlags & (1 << 21)))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700908 break;
Wei Li05d53f02016-03-29 16:42:53 -0700909 if (array[i] < static_cast<uint32_t>(pFormField->CountOptions()) &&
tsepez41a53ad2016-03-28 16:59:30 -0700910 !pFormField->IsItemSelected(array[i])) {
tsepez4cf55152016-11-02 14:37:54 -0700911 pFormField->SetItemSelection(array[i], true);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700912 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700913 }
tsepez4cf55152016-11-02 14:37:54 -0700914 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700915 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700916 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700917}
918
dan sinclaircbe23db2017-10-19 14:29:33 -0400919bool Field::get_default_style(CJS_Runtime* pRuntime,
920 CJS_PropValue* vp,
921 WideString* sError) {
922 return false;
923}
924
925bool Field::set_default_style(CJS_Runtime* pRuntime,
926 const CJS_PropValue& vp,
927 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -0700928 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700929}
930
dan sinclaircbe23db2017-10-19 14:29:33 -0400931bool Field::get_default_value(CJS_Runtime* pRuntime,
932 CJS_PropValue* vp,
933 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700934 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700935
Lei Zhangd88a3642015-11-10 09:38:57 -0800936 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
937 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700938 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700939
Lei Zhangd88a3642015-11-10 09:38:57 -0800940 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700941 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON ||
Lei Zhangd88a3642015-11-10 09:38:57 -0800942 pFormField->GetFieldType() == FIELDTYPE_SIGNATURE) {
tsepez4cf55152016-11-02 14:37:54 -0700943 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -0800944 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700945
dan sinclaircbe23db2017-10-19 14:29:33 -0400946 vp->Set(pFormField->GetDefaultValue());
947 return true;
948}
949
950bool Field::set_default_value(CJS_Runtime* pRuntime,
951 const CJS_PropValue& vp,
952 WideString* sError) {
953 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400954 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700955}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700956
dan sinclaircbe23db2017-10-19 14:29:33 -0400957bool Field::get_do_not_scroll(CJS_Runtime* pRuntime,
958 CJS_PropValue* vp,
959 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700960 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700961
dan sinclaircbe23db2017-10-19 14:29:33 -0400962 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
963 if (FieldArray.empty())
964 return false;
965
966 CPDF_FormField* pFormField = FieldArray[0];
967 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
968 return false;
969
970 vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL));
971 return true;
972}
973
974bool Field::set_do_not_scroll(CJS_Runtime* pRuntime,
975 const CJS_PropValue& vp,
976 WideString* sError) {
977 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400978 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700979}
980
dan sinclaircbe23db2017-10-19 14:29:33 -0400981bool Field::get_do_not_spell_check(CJS_Runtime* pRuntime,
982 CJS_PropValue* vp,
983 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700984 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700985
dan sinclair646634b2017-10-19 14:30:28 -0400986 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
987 if (FieldArray.empty())
988 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700989
dan sinclair646634b2017-10-19 14:30:28 -0400990 CPDF_FormField* pFormField = FieldArray[0];
991 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD &&
992 pFormField->GetFieldType() != FIELDTYPE_COMBOBOX) {
993 return false;
994 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700995
dan sinclair646634b2017-10-19 14:30:28 -0400996 vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK));
997 return true;
dan sinclaircbe23db2017-10-19 14:29:33 -0400998}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700999
dan sinclaircbe23db2017-10-19 14:29:33 -04001000bool Field::set_do_not_spell_check(CJS_Runtime* pRuntime,
1001 const CJS_PropValue& vp,
1002 WideString* sError) {
1003 ASSERT(m_pFormFillEnv);
1004 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001005}
1006
tsepez4cf55152016-11-02 14:37:54 -07001007void Field::SetDelay(bool bDelay) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001008 m_bDelay = bDelay;
1009
dan sinclaircbe23db2017-10-19 14:29:33 -04001010 if (m_bDelay)
1011 return;
dan sinclaircbe23db2017-10-19 14:29:33 -04001012 if (m_pJSDoc)
1013 m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001014}
1015
dan sinclaircbe23db2017-10-19 14:29:33 -04001016bool Field::get_delay(CJS_Runtime* pRuntime,
1017 CJS_PropValue* vp,
1018 WideString* sError) {
1019 vp->Set(m_bDelay);
tsepez4cf55152016-11-02 14:37:54 -07001020 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001021}
1022
dan sinclaircbe23db2017-10-19 14:29:33 -04001023bool Field::set_delay(CJS_Runtime* pRuntime,
1024 const CJS_PropValue& vp,
1025 WideString* sError) {
1026 if (!m_bCanSet)
1027 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001028
dan sinclaircbe23db2017-10-19 14:29:33 -04001029 SetDelay(vp.ToBool());
1030 return true;
1031}
1032
1033bool Field::get_display(CJS_Runtime* pRuntime,
1034 CJS_PropValue* vp,
1035 WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001036 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1037 if (FieldArray.empty())
1038 return false;
1039
1040 CPDF_FormField* pFormField = FieldArray[0];
1041 ASSERT(pFormField);
dan sinclaircbe23db2017-10-19 14:29:33 -04001042
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001043 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1044 CPDFSDK_Widget* pWidget =
1045 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1046 if (!pWidget)
1047 return false;
1048
1049 uint32_t dwFlag = pWidget->GetFlags();
1050 if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001051 vp->Set(1);
1052 return true;
1053 }
1054 if (ANNOTFLAG_PRINT & dwFlag) {
1055 if (ANNOTFLAG_NOVIEW & dwFlag)
1056 vp->Set(3);
1057 else
1058 vp->Set(0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001059 } else {
dan sinclaircbe23db2017-10-19 14:29:33 -04001060 vp->Set(2);
1061 }
1062 return true;
1063}
1064
1065bool Field::set_display(CJS_Runtime* pRuntime,
1066 const CJS_PropValue& vp,
1067 WideString* sError) {
1068 if (!m_bCanSet)
1069 return false;
1070
1071 if (m_bDelay) {
1072 AddDelay_Int(FP_DISPLAY, vp.ToInt());
1073 } else {
1074 Field::SetDisplay(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
1075 vp.ToInt());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001076 }
tsepez4cf55152016-11-02 14:37:54 -07001077 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001078}
1079
dsinclair3a7741a2016-10-11 10:39:49 -07001080void Field::SetDisplay(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04001081 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001082 int nControlIndex,
1083 int number) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001084 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001085 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07001086 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -08001087 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001088 if (nControlIndex < 0) {
tonikitoo7c05a7a2016-08-17 11:08:46 -07001089 bool bAnySet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001090 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1091 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08001092 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001093
dsinclairc5267c52016-11-04 15:35:12 -07001094 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
tonikitoo7c05a7a2016-08-17 11:08:46 -07001095 if (SetWidgetDisplayStatus(pWidget, number))
1096 bAnySet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001097 }
1098
tonikitoo7c05a7a2016-08-17 11:08:46 -07001099 if (bAnySet)
tsepez4cf55152016-11-02 14:37:54 -07001100 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001101 } else {
1102 if (nControlIndex >= pFormField->CountControls())
1103 return;
tonikitoo7c05a7a2016-08-17 11:08:46 -07001104
1105 CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex);
1106 if (!pFormControl)
1107 return;
1108
dsinclairc5267c52016-11-04 15:35:12 -07001109 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
tonikitoo7c05a7a2016-08-17 11:08:46 -07001110 if (SetWidgetDisplayStatus(pWidget, number))
tsepez4cf55152016-11-02 14:37:54 -07001111 UpdateFormControl(pFormFillEnv, pFormControl, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001112 }
1113 }
1114}
1115
dan sinclaircbe23db2017-10-19 14:29:33 -04001116bool Field::get_doc(CJS_Runtime* pRuntime,
1117 CJS_PropValue* vp,
1118 WideString* sError) {
1119 vp->Set(m_pJSDoc->GetCJSDoc());
tsepez4cf55152016-11-02 14:37:54 -07001120 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001121}
1122
dan sinclaircbe23db2017-10-19 14:29:33 -04001123bool Field::set_doc(CJS_Runtime* pRuntime,
1124 const CJS_PropValue& vp,
1125 WideString* sError) {
1126 return false;
1127}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001128
dan sinclaircbe23db2017-10-19 14:29:33 -04001129bool Field::get_editable(CJS_Runtime* pRuntime,
1130 CJS_PropValue* vp,
1131 WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001132 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1133 if (FieldArray.empty())
1134 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001135
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001136 CPDF_FormField* pFormField = FieldArray[0];
1137 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX)
1138 return false;
1139
dan sinclaircbe23db2017-10-19 14:29:33 -04001140 vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_EDIT));
tsepez4cf55152016-11-02 14:37:54 -07001141 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001142}
1143
dan sinclaircbe23db2017-10-19 14:29:33 -04001144bool Field::set_editable(CJS_Runtime* pRuntime,
1145 const CJS_PropValue& vp,
1146 WideString* sError) {
1147 return m_bCanSet;
1148}
1149
1150bool Field::get_export_values(CJS_Runtime* pRuntime,
1151 CJS_PropValue* vp,
1152 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001153 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1154 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001155 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001156
Lei Zhangd88a3642015-11-10 09:38:57 -08001157 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001158 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001159 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) {
tsepez4cf55152016-11-02 14:37:54 -07001160 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001161 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001162
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001163 CJS_Array ExportValusArray;
1164 if (m_nFormControlIndex < 0) {
1165 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
1166 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001167 ExportValusArray.SetElement(
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001168 pRuntime, i,
tsepeze5aff742016-08-08 09:49:42 -07001169 CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001170 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001171 } else {
1172 if (m_nFormControlIndex >= pFormField->CountControls())
1173 return false;
1174
1175 CPDF_FormControl* pFormControl =
1176 pFormField->GetControl(m_nFormControlIndex);
1177 if (!pFormControl)
1178 return false;
1179
1180 ExportValusArray.SetElement(
1181 pRuntime, 0,
1182 CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001183 }
dan sinclaircbe23db2017-10-19 14:29:33 -04001184
1185 vp->Set(ExportValusArray);
tsepez4cf55152016-11-02 14:37:54 -07001186 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001187}
1188
dan sinclaircbe23db2017-10-19 14:29:33 -04001189bool Field::set_export_values(CJS_Runtime* pRuntime,
1190 const CJS_PropValue& vp,
1191 WideString* sError) {
1192 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1193 if (FieldArray.empty())
1194 return false;
1195
1196 CPDF_FormField* pFormField = FieldArray[0];
1197 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
1198 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) {
1199 return false;
1200 }
1201
1202 return m_bCanSet && vp.GetJSValue()->IsArrayObject();
1203}
1204
1205bool Field::get_file_select(CJS_Runtime* pRuntime,
1206 CJS_PropValue* vp,
1207 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001208 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1209 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001210 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001211
Lei Zhangd88a3642015-11-10 09:38:57 -08001212 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001213 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
tsepez4cf55152016-11-02 14:37:54 -07001214 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001215
dan sinclaircbe23db2017-10-19 14:29:33 -04001216 vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT));
tsepez4cf55152016-11-02 14:37:54 -07001217 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001218}
1219
dan sinclaircbe23db2017-10-19 14:29:33 -04001220bool Field::set_file_select(CJS_Runtime* pRuntime,
1221 const CJS_PropValue& vp,
1222 WideString* sError) {
1223 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1224 if (FieldArray.empty())
1225 return false;
1226
1227 CPDF_FormField* pFormField = FieldArray[0];
1228 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1229 return false;
1230
1231 return m_bCanSet;
1232}
1233
1234bool Field::get_fill_color(CJS_Runtime* pRuntime,
1235 CJS_PropValue* vp,
1236 WideString* sError) {
tsepeze5aff742016-08-08 09:49:42 -07001237 CJS_Array crArray;
Lei Zhangd88a3642015-11-10 09:38:57 -08001238 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1239 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001240 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001241
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001242 CPDF_FormField* pFormField = FieldArray[0];
1243 ASSERT(pFormField);
1244 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1245 if (!pFormControl)
1246 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001247
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001248 int iColorType;
1249 pFormControl->GetBackgroundColor(iColorType);
1250
Dan Sinclair7f55a542017-07-13 14:17:10 -04001251 CFX_Color color;
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001252 if (iColorType == CFX_Color::kTransparent) {
1253 color = CFX_Color(CFX_Color::kTransparent);
1254 } else if (iColorType == CFX_Color::kGray) {
1255 color = CFX_Color(CFX_Color::kGray,
1256 pFormControl->GetOriginalBackgroundColor(0));
1257 } else if (iColorType == CFX_Color::kRGB) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001258 color =
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001259 CFX_Color(CFX_Color::kRGB, pFormControl->GetOriginalBackgroundColor(0),
Dan Sinclair7f55a542017-07-13 14:17:10 -04001260 pFormControl->GetOriginalBackgroundColor(1),
1261 pFormControl->GetOriginalBackgroundColor(2));
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001262 } else if (iColorType == CFX_Color::kCMYK) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001263 color =
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001264 CFX_Color(CFX_Color::kCMYK, pFormControl->GetOriginalBackgroundColor(0),
Dan Sinclair7f55a542017-07-13 14:17:10 -04001265 pFormControl->GetOriginalBackgroundColor(1),
1266 pFormControl->GetOriginalBackgroundColor(2),
1267 pFormControl->GetOriginalBackgroundColor(3));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001268 } else {
1269 return false;
1270 }
dan sinclaircbe23db2017-10-19 14:29:33 -04001271
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001272 color::ConvertPWLColorToArray(pRuntime, color, &crArray);
dan sinclaircbe23db2017-10-19 14:29:33 -04001273 vp->Set(crArray);
1274 return true;
1275}
1276
1277bool Field::set_fill_color(CJS_Runtime* pRuntime,
1278 const CJS_PropValue& vp,
1279 WideString* sError) {
1280 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1281 if (FieldArray.empty())
1282 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -04001283 if (!m_bCanSet)
1284 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -04001285 if (!vp.GetJSValue()->IsArrayObject())
1286 return false;
tsepez4cf55152016-11-02 14:37:54 -07001287 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001288}
1289
dan sinclaircbe23db2017-10-19 14:29:33 -04001290bool Field::get_hidden(CJS_Runtime* pRuntime,
1291 CJS_PropValue* vp,
1292 WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001293 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1294 if (FieldArray.empty())
1295 return false;
1296
1297 CPDF_FormField* pFormField = FieldArray[0];
1298 ASSERT(pFormField);
dan sinclaircbe23db2017-10-19 14:29:33 -04001299
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001300 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1301 CPDFSDK_Widget* pWidget =
1302 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1303 if (!pWidget)
1304 return false;
1305
1306 uint32_t dwFlags = pWidget->GetFlags();
dan sinclaircbe23db2017-10-19 14:29:33 -04001307 vp->Set(ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags);
1308 return true;
1309}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001310
dan sinclaircbe23db2017-10-19 14:29:33 -04001311bool Field::set_hidden(CJS_Runtime* pRuntime,
1312 const CJS_PropValue& vp,
1313 WideString* sError) {
1314 if (!m_bCanSet)
1315 return false;
1316
1317 if (m_bDelay) {
1318 AddDelay_Bool(FP_HIDDEN, vp.ToBool());
1319 } else {
1320 Field::SetHidden(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
1321 vp.ToBool());
1322 }
tsepez4cf55152016-11-02 14:37:54 -07001323 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001324}
1325
dsinclair3a7741a2016-10-11 10:39:49 -07001326void Field::SetHidden(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04001327 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001328 int nControlIndex,
1329 bool b) {
tonikitooa73b8fe2016-08-22 14:06:49 -07001330 int display = b ? 1 /*Hidden*/ : 0 /*Visible*/;
dsinclair3a7741a2016-10-11 10:39:49 -07001331 SetDisplay(pFormFillEnv, swFieldName, nControlIndex, display);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001332}
1333
dan sinclaircbe23db2017-10-19 14:29:33 -04001334bool Field::get_highlight(CJS_Runtime* pRuntime,
1335 CJS_PropValue* vp,
1336 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001337 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001338
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001339 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1340 if (FieldArray.empty())
1341 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001342
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001343 CPDF_FormField* pFormField = FieldArray[0];
1344 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
1345 return false;
1346
1347 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1348 if (!pFormControl)
1349 return false;
1350
1351 int eHM = pFormControl->GetHighlightingMode();
1352 switch (eHM) {
1353 case CPDF_FormControl::None:
dan sinclaircbe23db2017-10-19 14:29:33 -04001354 vp->Set(L"none");
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001355 break;
1356 case CPDF_FormControl::Push:
dan sinclaircbe23db2017-10-19 14:29:33 -04001357 vp->Set(L"push");
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001358 break;
1359 case CPDF_FormControl::Invert:
dan sinclaircbe23db2017-10-19 14:29:33 -04001360 vp->Set(L"invert");
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001361 break;
1362 case CPDF_FormControl::Outline:
dan sinclaircbe23db2017-10-19 14:29:33 -04001363 vp->Set(L"outline");
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001364 break;
1365 case CPDF_FormControl::Toggle:
dan sinclaircbe23db2017-10-19 14:29:33 -04001366 vp->Set(L"toggle");
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001367 break;
1368 }
tsepez4cf55152016-11-02 14:37:54 -07001369 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001370}
1371
dan sinclaircbe23db2017-10-19 14:29:33 -04001372bool Field::set_highlight(CJS_Runtime* pRuntime,
1373 const CJS_PropValue& vp,
1374 WideString* sError) {
1375 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04001376 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001377}
1378
dan sinclaircbe23db2017-10-19 14:29:33 -04001379bool Field::get_line_width(CJS_Runtime* pRuntime,
1380 CJS_PropValue* vp,
1381 WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001382 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1383 if (FieldArray.empty())
1384 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001385
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001386 CPDF_FormField* pFormField = FieldArray[0];
1387 ASSERT(pFormField);
dan sinclaircbe23db2017-10-19 14:29:33 -04001388
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001389 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1390 if (!pFormControl)
1391 return false;
1392
1393 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1394 if (!pFormField->CountControls())
1395 return false;
1396
1397 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
1398 if (!pWidget)
1399 return false;
1400
dan sinclaircbe23db2017-10-19 14:29:33 -04001401 vp->Set(pWidget->GetBorderWidth());
1402 return true;
1403}
1404
1405bool Field::set_line_width(CJS_Runtime* pRuntime,
1406 const CJS_PropValue& vp,
1407 WideString* sError) {
1408 if (!m_bCanSet)
1409 return false;
1410
1411 if (m_bDelay) {
1412 AddDelay_Int(FP_LINEWIDTH, vp.ToInt());
1413 } else {
1414 Field::SetLineWidth(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
1415 vp.ToInt());
1416 }
tsepez4cf55152016-11-02 14:37:54 -07001417 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001418}
1419
dsinclair3a7741a2016-10-11 10:39:49 -07001420void Field::SetLineWidth(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04001421 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001422 int nControlIndex,
1423 int number) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001424 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001425 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07001426 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -08001427 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001428 if (nControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -07001429 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001430 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1431 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08001432 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001433
dsinclairc5267c52016-11-04 15:35:12 -07001434 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001435 if (number != pWidget->GetBorderWidth()) {
1436 pWidget->SetBorderWidth(number);
tsepez4cf55152016-11-02 14:37:54 -07001437 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001438 }
1439 }
1440 }
1441 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -07001442 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001443 } else {
1444 if (nControlIndex >= pFormField->CountControls())
1445 return;
1446 if (CPDF_FormControl* pFormControl =
1447 pFormField->GetControl(nControlIndex)) {
dsinclairc5267c52016-11-04 15:35:12 -07001448 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001449 if (number != pWidget->GetBorderWidth()) {
1450 pWidget->SetBorderWidth(number);
tsepez4cf55152016-11-02 14:37:54 -07001451 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001452 }
1453 }
1454 }
1455 }
1456 }
1457}
1458
dan sinclaircbe23db2017-10-19 14:29:33 -04001459bool Field::get_multiline(CJS_Runtime* pRuntime,
1460 CJS_PropValue* vp,
1461 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001462 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001463
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001464 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1465 if (FieldArray.empty())
1466 return false;
1467
1468 CPDF_FormField* pFormField = FieldArray[0];
1469 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1470 return false;
1471
dan sinclaircbe23db2017-10-19 14:29:33 -04001472 vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE));
tsepez4cf55152016-11-02 14:37:54 -07001473 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001474}
1475
dan sinclaircbe23db2017-10-19 14:29:33 -04001476bool Field::set_multiline(CJS_Runtime* pRuntime,
1477 const CJS_PropValue& vp,
1478 WideString* sError) {
1479 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04001480 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001481}
1482
dan sinclaircbe23db2017-10-19 14:29:33 -04001483bool Field::get_multiple_selection(CJS_Runtime* pRuntime,
1484 CJS_PropValue* vp,
1485 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001486 ASSERT(m_pFormFillEnv);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001487 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1488 if (FieldArray.empty())
1489 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001490
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001491 CPDF_FormField* pFormField = FieldArray[0];
1492 if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
1493 return false;
1494
dan sinclaircbe23db2017-10-19 14:29:33 -04001495 vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT));
1496 return true;
1497}
1498
1499bool Field::set_multiple_selection(CJS_Runtime* pRuntime,
1500 const CJS_PropValue& vp,
1501 WideString* sError) {
1502 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04001503 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001504}
1505
dan sinclaircbe23db2017-10-19 14:29:33 -04001506bool Field::get_name(CJS_Runtime* pRuntime,
1507 CJS_PropValue* vp,
1508 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001509 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1510 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001511 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001512
dan sinclaircbe23db2017-10-19 14:29:33 -04001513 vp->Set(m_FieldName);
tsepez4cf55152016-11-02 14:37:54 -07001514 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001515}
1516
dan sinclaircbe23db2017-10-19 14:29:33 -04001517bool Field::set_name(CJS_Runtime* pRuntime,
1518 const CJS_PropValue& vp,
1519 WideString* sError) {
1520 return false;
1521}
Tom Sepez67fd5df2015-10-08 12:24:19 -07001522
dan sinclaircbe23db2017-10-19 14:29:33 -04001523bool Field::get_num_items(CJS_Runtime* pRuntime,
1524 CJS_PropValue* vp,
1525 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001526 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1527 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001528 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001529
Lei Zhangd88a3642015-11-10 09:38:57 -08001530 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001531 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001532 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
tsepez4cf55152016-11-02 14:37:54 -07001533 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001534 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001535
dan sinclaircbe23db2017-10-19 14:29:33 -04001536 vp->Set(pFormField->CountOptions());
tsepez4cf55152016-11-02 14:37:54 -07001537 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001538}
1539
dan sinclaircbe23db2017-10-19 14:29:33 -04001540bool Field::set_num_items(CJS_Runtime* pRuntime,
1541 const CJS_PropValue& vp,
1542 WideString* sError) {
1543 return false;
1544}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001545
dan sinclaircbe23db2017-10-19 14:29:33 -04001546bool Field::get_page(CJS_Runtime* pRuntime,
1547 CJS_PropValue* vp,
1548 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001549 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1550 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001551 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001552
Lei Zhangd88a3642015-11-10 09:38:57 -08001553 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001554 if (!pFormField)
tsepez4cf55152016-11-02 14:37:54 -07001555 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001556
tsepez8fa82792017-01-11 09:32:33 -08001557 std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
dsinclair7cbe68e2016-10-12 11:56:23 -07001558 m_pFormFillEnv->GetInterForm()->GetWidgets(pFormField, &widgets);
Lei Zhangd88a3642015-11-10 09:38:57 -08001559 if (widgets.empty()) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001560 vp->Set(-1);
tsepez4cf55152016-11-02 14:37:54 -07001561 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001562 }
1563
tsepeze5aff742016-08-08 09:49:42 -07001564 CJS_Array PageArray;
tsepez8fa82792017-01-11 09:32:33 -08001565 int i = 0;
1566 for (const auto& pObserved : widgets) {
1567 if (!pObserved) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001568 *sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
tsepez8fa82792017-01-11 09:32:33 -08001569 return false;
1570 }
1571
Lei Zhang375c2762017-03-10 14:37:14 -08001572 auto* pWidget = static_cast<CPDFSDK_Widget*>(pObserved.Get());
tsepez8fa82792017-01-11 09:32:33 -08001573 CPDFSDK_PageView* pPageView = pWidget->GetPageView();
Lei Zhangd88a3642015-11-10 09:38:57 -08001574 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -07001575 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001576
1577 PageArray.SetElement(
tsepezb4694242016-08-15 16:44:55 -07001578 pRuntime, i, CJS_Value(pRuntime, (int32_t)pPageView->GetPageIndex()));
tsepez8fa82792017-01-11 09:32:33 -08001579 ++i;
Lei Zhangd88a3642015-11-10 09:38:57 -08001580 }
1581
dan sinclaircbe23db2017-10-19 14:29:33 -04001582 vp->Set(PageArray);
tsepez4cf55152016-11-02 14:37:54 -07001583 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001584}
1585
dan sinclaircbe23db2017-10-19 14:29:33 -04001586bool Field::set_page(CJS_Runtime* pRuntime,
1587 const CJS_PropValue& vp,
1588 WideString* sError) {
1589 *sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
1590 return false;
1591}
1592
1593bool Field::get_password(CJS_Runtime* pRuntime,
1594 CJS_PropValue* vp,
1595 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001596 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001597
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001598 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1599 if (FieldArray.empty())
1600 return false;
1601
1602 CPDF_FormField* pFormField = FieldArray[0];
1603 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1604 return false;
1605
dan sinclaircbe23db2017-10-19 14:29:33 -04001606 vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD));
tsepez4cf55152016-11-02 14:37:54 -07001607 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001608}
1609
dan sinclaircbe23db2017-10-19 14:29:33 -04001610bool Field::set_password(CJS_Runtime* pRuntime,
1611 const CJS_PropValue& vp,
1612 WideString* sError) {
1613 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04001614 return m_bCanSet;
1615}
dan sinclaircbe23db2017-10-19 14:29:33 -04001616
dan sinclair646634b2017-10-19 14:30:28 -04001617bool Field::get_print(CJS_Runtime* pRuntime,
1618 CJS_PropValue* vp,
1619 WideString* sError) {
1620 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1621 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1622 if (FieldArray.empty())
1623 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -04001624
dan sinclair646634b2017-10-19 14:30:28 -04001625 CPDF_FormField* pFormField = FieldArray[0];
1626 CPDFSDK_Widget* pWidget =
1627 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1628 if (!pWidget)
1629 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -04001630
dan sinclair646634b2017-10-19 14:30:28 -04001631 vp->Set(!!(pWidget->GetFlags() & ANNOTFLAG_PRINT));
1632 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001633}
1634
dan sinclaircbe23db2017-10-19 14:29:33 -04001635bool Field::set_print(CJS_Runtime* pRuntime,
1636 const CJS_PropValue& vp,
1637 WideString* sError) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001638 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001639 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1640 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001641 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001642
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001643 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001644 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001645
Lei Zhangd88a3642015-11-10 09:38:57 -08001646 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001647 if (m_nFormControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -07001648 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001649 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001650 if (CPDFSDK_Widget* pWidget =
dsinclairc5267c52016-11-04 15:35:12 -07001651 pInterForm->GetWidget(pFormField->GetControl(i))) {
tsepezc3255f52016-03-25 14:52:27 -07001652 uint32_t dwFlags = pWidget->GetFlags();
dan sinclaircbe23db2017-10-19 14:29:33 -04001653 if (vp.ToBool())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001654 dwFlags |= ANNOTFLAG_PRINT;
1655 else
1656 dwFlags &= ~ANNOTFLAG_PRINT;
1657
1658 if (dwFlags != pWidget->GetFlags()) {
1659 pWidget->SetFlags(dwFlags);
tsepez4cf55152016-11-02 14:37:54 -07001660 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001661 }
1662 }
1663 }
1664
1665 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -07001666 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001667
dan sinclaircbe23db2017-10-19 14:29:33 -04001668 continue;
1669 }
1670
1671 if (m_nFormControlIndex >= pFormField->CountControls())
1672 return false;
1673 if (CPDF_FormControl* pFormControl =
1674 pFormField->GetControl(m_nFormControlIndex)) {
1675 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1676 uint32_t dwFlags = pWidget->GetFlags();
1677 if (vp.ToBool())
1678 dwFlags |= ANNOTFLAG_PRINT;
1679 else
1680 dwFlags &= ~ANNOTFLAG_PRINT;
1681
1682 if (dwFlags != pWidget->GetFlags()) {
1683 pWidget->SetFlags(dwFlags);
1684 UpdateFormControl(m_pFormFillEnv.Get(),
1685 pFormField->GetControl(m_nFormControlIndex), true,
1686 false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001687 }
1688 }
1689 }
1690 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001691 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001692}
1693
dan sinclaircbe23db2017-10-19 14:29:33 -04001694bool Field::get_radios_in_unison(CJS_Runtime* pRuntime,
1695 CJS_PropValue* vp,
1696 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001697 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1698 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001699 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001700
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001701 CPDF_FormField* pFormField = FieldArray[0];
1702 if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
1703 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001704
dan sinclaircbe23db2017-10-19 14:29:33 -04001705 vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON));
tsepez4cf55152016-11-02 14:37:54 -07001706 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001707}
1708
dan sinclaircbe23db2017-10-19 14:29:33 -04001709bool Field::set_radios_in_unison(CJS_Runtime* pRuntime,
1710 const CJS_PropValue& vp,
1711 WideString* sError) {
1712 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1713 if (FieldArray.empty())
1714 return false;
1715 return m_bCanSet;
1716}
1717
1718bool Field::get_readonly(CJS_Runtime* pRuntime,
1719 CJS_PropValue* vp,
1720 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001721 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1722 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001723 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001724
dan sinclaircbe23db2017-10-19 14:29:33 -04001725 vp->Set(!!(FieldArray[0]->GetFieldFlags() & FIELDFLAG_READONLY));
tsepez4cf55152016-11-02 14:37:54 -07001726 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001727}
1728
dan sinclaircbe23db2017-10-19 14:29:33 -04001729bool Field::set_readonly(CJS_Runtime* pRuntime,
1730 const CJS_PropValue& vp,
1731 WideString* sError) {
1732 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1733 if (FieldArray.empty())
1734 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -04001735 return m_bCanSet;
1736}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001737
dan sinclaircbe23db2017-10-19 14:29:33 -04001738bool Field::get_rect(CJS_Runtime* pRuntime,
1739 CJS_PropValue* vp,
1740 WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001741 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1742 if (FieldArray.empty())
1743 return false;
1744
1745 CPDF_FormField* pFormField = FieldArray[0];
1746 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1747 CPDFSDK_Widget* pWidget =
1748 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1749 if (!pWidget)
1750 return false;
1751
1752 CFX_FloatRect crRect = pWidget->GetRect();
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001753 CJS_Array rcArray;
dan sinclaircbe23db2017-10-19 14:29:33 -04001754 rcArray.SetElement(pRuntime, 0,
1755 CJS_Value(pRuntime, static_cast<int32_t>(crRect.left)));
1756 rcArray.SetElement(pRuntime, 1,
1757 CJS_Value(pRuntime, static_cast<int32_t>(crRect.top)));
1758 rcArray.SetElement(pRuntime, 2,
1759 CJS_Value(pRuntime, static_cast<int32_t>(crRect.right)));
1760 rcArray.SetElement(pRuntime, 3,
1761 CJS_Value(pRuntime, static_cast<int32_t>(crRect.bottom)));
1762 vp->Set(rcArray);
1763 return true;
1764}
1765
1766bool Field::set_rect(CJS_Runtime* pRuntime,
1767 const CJS_PropValue& vp,
1768 WideString* sError) {
1769 if (!m_bCanSet)
1770 return false;
1771 if (!vp.GetJSValue()->IsArrayObject())
1772 return false;
1773
1774 CJS_Value Upper_Leftx(pRuntime);
1775 CJS_Value Upper_Lefty(pRuntime);
1776 CJS_Value Lower_Rightx(pRuntime);
1777 CJS_Value Lower_Righty(pRuntime);
1778
1779 CJS_Array rcArray = vp.ToArray();
1780 rcArray.GetElement(pRuntime, 0, Upper_Leftx);
1781 rcArray.GetElement(pRuntime, 1, Upper_Lefty);
1782 rcArray.GetElement(pRuntime, 2, Lower_Rightx);
1783 rcArray.GetElement(pRuntime, 3, Lower_Righty);
1784
1785 float pArray[4];
1786 pArray[0] = static_cast<float>(Upper_Leftx.ToInt(pRuntime));
1787 pArray[1] = static_cast<float>(Lower_Righty.ToInt(pRuntime));
1788 pArray[2] = static_cast<float>(Lower_Rightx.ToInt(pRuntime));
1789 pArray[3] = static_cast<float>(Upper_Lefty.ToInt(pRuntime));
1790
1791 CFX_FloatRect crRect(pArray);
1792 if (m_bDelay) {
1793 AddDelay_Rect(FP_RECT, crRect);
1794 } else {
1795 Field::SetRect(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
1796 crRect);
1797 }
tsepez4cf55152016-11-02 14:37:54 -07001798 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001799}
1800
dsinclair3a7741a2016-10-11 10:39:49 -07001801void Field::SetRect(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04001802 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001803 int nControlIndex,
Tom Sepez281a9ea2016-02-26 14:24:28 -08001804 const CFX_FloatRect& rect) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001805 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001806 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07001807 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -08001808 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001809 if (nControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -07001810 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001811 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001812 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08001813 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001814
dsinclairc5267c52016-11-04 15:35:12 -07001815 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08001816 CFX_FloatRect crRect = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001817
1818 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001819 crRect.Intersect(pPDFPage->GetPageBBox());
1820
1821 if (!crRect.IsEmpty()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08001822 CFX_FloatRect rcOld = pWidget->GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001823 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
1824 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
1825 pWidget->SetRect(crRect);
tsepez4cf55152016-11-02 14:37:54 -07001826 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001827 }
1828 }
1829 }
1830 }
1831
1832 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -07001833 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001834
dan sinclaircbe23db2017-10-19 14:29:33 -04001835 continue;
1836 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001837
dan sinclaircbe23db2017-10-19 14:29:33 -04001838 if (nControlIndex >= pFormField->CountControls())
1839 return;
1840 if (CPDF_FormControl* pFormControl =
1841 pFormField->GetControl(nControlIndex)) {
1842 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1843 CFX_FloatRect crRect = rect;
1844
1845 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
1846 crRect.Intersect(pPDFPage->GetPageBBox());
1847
1848 if (!crRect.IsEmpty()) {
1849 CFX_FloatRect rcOld = pWidget->GetRect();
1850 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
1851 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
1852 pWidget->SetRect(crRect);
1853 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001854 }
1855 }
1856 }
1857 }
1858 }
1859}
1860
dan sinclaircbe23db2017-10-19 14:29:33 -04001861bool Field::get_required(CJS_Runtime* pRuntime,
1862 CJS_PropValue* vp,
1863 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001864 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1865 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001866 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001867
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001868 CPDF_FormField* pFormField = FieldArray[0];
1869 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
1870 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001871
dan sinclaircbe23db2017-10-19 14:29:33 -04001872 vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED));
tsepez4cf55152016-11-02 14:37:54 -07001873 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001874}
1875
dan sinclaircbe23db2017-10-19 14:29:33 -04001876bool Field::set_required(CJS_Runtime* pRuntime,
1877 const CJS_PropValue& vp,
1878 WideString* sError) {
1879 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1880 if (FieldArray.empty())
1881 return false;
1882
1883 return m_bCanSet;
1884}
1885
1886bool Field::get_rich_text(CJS_Runtime* pRuntime,
1887 CJS_PropValue* vp,
1888 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001889 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001890
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001891 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1892 if (FieldArray.empty())
1893 return false;
1894
1895 CPDF_FormField* pFormField = FieldArray[0];
1896 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1897 return false;
1898
dan sinclaircbe23db2017-10-19 14:29:33 -04001899 vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT));
tsepez4cf55152016-11-02 14:37:54 -07001900 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001901}
1902
dan sinclaircbe23db2017-10-19 14:29:33 -04001903bool Field::set_rich_text(CJS_Runtime* pRuntime,
1904 const CJS_PropValue& vp,
1905 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001906 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04001907 return m_bCanSet;
dan sinclaircbe23db2017-10-19 14:29:33 -04001908}
1909
1910bool Field::get_rich_value(CJS_Runtime* pRuntime,
1911 CJS_PropValue* vp,
1912 WideString* sError) {
1913 return true;
1914}
1915
1916bool Field::set_rich_value(CJS_Runtime* pRuntime,
1917 const CJS_PropValue& vp,
1918 WideString* sError) {
1919 return true;
1920}
1921
1922bool Field::get_rotation(CJS_Runtime* pRuntime,
1923 CJS_PropValue* vp,
1924 WideString* sError) {
1925 ASSERT(m_pFormFillEnv);
1926
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001927 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1928 if (FieldArray.empty())
1929 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001930
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001931 CPDF_FormField* pFormField = FieldArray[0];
1932 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1933 if (!pFormControl)
1934 return false;
1935
dan sinclaircbe23db2017-10-19 14:29:33 -04001936 vp->Set(pFormControl->GetRotation());
1937 return true;
1938}
1939
1940bool Field::set_rotation(CJS_Runtime* pRuntime,
1941 const CJS_PropValue& vp,
1942 WideString* sError) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001943 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04001944 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001945}
1946
dan sinclaircbe23db2017-10-19 14:29:33 -04001947bool Field::get_stroke_color(CJS_Runtime* pRuntime,
1948 CJS_PropValue* vp,
1949 WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001950 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1951 if (FieldArray.empty())
1952 return false;
1953
1954 CPDF_FormField* pFormField = FieldArray[0];
1955 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1956 if (!pFormControl)
1957 return false;
1958
1959 int iColorType;
1960 pFormControl->GetBorderColor(iColorType);
1961
Dan Sinclair7f55a542017-07-13 14:17:10 -04001962 CFX_Color color;
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001963 if (iColorType == CFX_Color::kTransparent) {
1964 color = CFX_Color(CFX_Color::kTransparent);
1965 } else if (iColorType == CFX_Color::kGray) {
1966 color =
1967 CFX_Color(CFX_Color::kGray, pFormControl->GetOriginalBorderColor(0));
1968 } else if (iColorType == CFX_Color::kRGB) {
1969 color = CFX_Color(CFX_Color::kRGB, pFormControl->GetOriginalBorderColor(0),
Dan Sinclair7f55a542017-07-13 14:17:10 -04001970 pFormControl->GetOriginalBorderColor(1),
1971 pFormControl->GetOriginalBorderColor(2));
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001972 } else if (iColorType == CFX_Color::kCMYK) {
1973 color = CFX_Color(CFX_Color::kCMYK, pFormControl->GetOriginalBorderColor(0),
Dan Sinclair7f55a542017-07-13 14:17:10 -04001974 pFormControl->GetOriginalBorderColor(1),
1975 pFormControl->GetOriginalBorderColor(2),
1976 pFormControl->GetOriginalBorderColor(3));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001977 } else {
1978 return false;
1979 }
1980
dan sinclaircbe23db2017-10-19 14:29:33 -04001981 CJS_Array crArray;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001982 color::ConvertPWLColorToArray(pRuntime, color, &crArray);
dan sinclaircbe23db2017-10-19 14:29:33 -04001983 vp->Set(crArray);
1984 return true;
1985}
1986
1987bool Field::set_stroke_color(CJS_Runtime* pRuntime,
1988 const CJS_PropValue& vp,
1989 WideString* sError) {
1990 if (!m_bCanSet)
1991 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -04001992 if (!vp.GetJSValue()->IsArrayObject())
1993 return false;
tsepez4cf55152016-11-02 14:37:54 -07001994 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001995}
1996
dan sinclaircbe23db2017-10-19 14:29:33 -04001997bool Field::get_style(CJS_Runtime* pRuntime,
1998 CJS_PropValue* vp,
1999 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002000 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002001
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002002 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2003 if (FieldArray.empty())
2004 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002005
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002006 CPDF_FormField* pFormField = FieldArray[0];
2007 if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON &&
2008 pFormField->GetFieldType() != FIELDTYPE_CHECKBOX) {
2009 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002010 }
2011
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002012 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2013 if (!pFormControl)
2014 return false;
2015
Ryan Harrison275e2602017-09-18 14:23:18 -04002016 WideString csWCaption = pFormControl->GetNormalCaption();
2017 ByteString csBCaption;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002018
2019 switch (csWCaption[0]) {
2020 case L'l':
2021 csBCaption = "circle";
2022 break;
2023 case L'8':
2024 csBCaption = "cross";
2025 break;
2026 case L'u':
2027 csBCaption = "diamond";
2028 break;
2029 case L'n':
2030 csBCaption = "square";
2031 break;
2032 case L'H':
2033 csBCaption = "star";
2034 break;
2035 default: // L'4'
2036 csBCaption = "check";
2037 break;
2038 }
dan sinclaircbe23db2017-10-19 14:29:33 -04002039 vp->Set(csBCaption);
2040 return true;
2041}
2042
2043bool Field::set_style(CJS_Runtime* pRuntime,
2044 const CJS_PropValue& vp,
2045 WideString* sError) {
2046 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04002047 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002048}
2049
dan sinclaircbe23db2017-10-19 14:29:33 -04002050bool Field::get_submit_name(CJS_Runtime* pRuntime,
2051 CJS_PropValue* vp,
2052 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -07002053 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002054}
2055
dan sinclaircbe23db2017-10-19 14:29:33 -04002056bool Field::set_submit_name(CJS_Runtime* pRuntime,
2057 const CJS_PropValue& vp,
2058 WideString* sError) {
2059 return true;
2060}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002061
dan sinclaircbe23db2017-10-19 14:29:33 -04002062bool Field::get_text_color(CJS_Runtime* pRuntime,
2063 CJS_PropValue* vp,
2064 WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002065 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2066 if (FieldArray.empty())
2067 return false;
2068
2069 CPDF_FormField* pFormField = FieldArray[0];
2070 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2071 if (!pFormControl)
2072 return false;
2073
2074 int iColorType;
2075 FX_ARGB color;
2076 CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
2077 FieldAppearance.GetColor(color, iColorType);
2078
2079 int32_t a;
2080 int32_t r;
2081 int32_t g;
2082 int32_t b;
Nicolas Penaddfc3dc2017-04-20 15:29:25 -04002083 std::tie(a, r, g, b) = ArgbDecode(color);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002084
Dan Sinclair7f55a542017-07-13 14:17:10 -04002085 CFX_Color crRet =
Dan Sinclair8e7f9322017-10-16 11:35:42 -04002086 CFX_Color(CFX_Color::kRGB, r / 255.0f, g / 255.0f, b / 255.0f);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002087
Dan Sinclair8e7f9322017-10-16 11:35:42 -04002088 if (iColorType == CFX_Color::kTransparent)
2089 crRet = CFX_Color(CFX_Color::kTransparent);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002090
dan sinclaircbe23db2017-10-19 14:29:33 -04002091 CJS_Array crArray;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002092 color::ConvertPWLColorToArray(pRuntime, crRet, &crArray);
dan sinclaircbe23db2017-10-19 14:29:33 -04002093 vp->Set(crArray);
2094 return true;
2095}
2096
2097bool Field::set_text_color(CJS_Runtime* pRuntime,
2098 const CJS_PropValue& vp,
2099 WideString* sError) {
2100 if (!m_bCanSet)
2101 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -04002102 if (!vp.GetJSValue()->IsArrayObject())
2103 return false;
tsepez4cf55152016-11-02 14:37:54 -07002104 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002105}
2106
dan sinclaircbe23db2017-10-19 14:29:33 -04002107bool Field::get_text_font(CJS_Runtime* pRuntime,
2108 CJS_PropValue* vp,
2109 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002110 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002111
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002112 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2113 if (FieldArray.empty())
2114 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002115
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002116 CPDF_FormField* pFormField = FieldArray[0];
2117 ASSERT(pFormField);
2118 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2119 if (!pFormControl)
2120 return false;
2121
2122 int nFieldType = pFormField->GetFieldType();
2123 if (nFieldType != FIELDTYPE_PUSHBUTTON && nFieldType != FIELDTYPE_COMBOBOX &&
2124 nFieldType != FIELDTYPE_LISTBOX && nFieldType != FIELDTYPE_TEXTFIELD) {
2125 return false;
2126 }
2127 CPDF_Font* pFont = pFormControl->GetDefaultControlFont();
2128 if (!pFont)
2129 return false;
2130
dan sinclaircbe23db2017-10-19 14:29:33 -04002131 vp->Set(pFont->GetBaseFont());
tsepez4cf55152016-11-02 14:37:54 -07002132 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002133}
2134
dan sinclaircbe23db2017-10-19 14:29:33 -04002135bool Field::set_text_font(CJS_Runtime* pRuntime,
2136 const CJS_PropValue& vp,
2137 WideString* sError) {
2138 ASSERT(m_pFormFillEnv);
2139
dan sinclair646634b2017-10-19 14:30:28 -04002140 if (!m_bCanSet)
2141 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -04002142
dan sinclair646634b2017-10-19 14:30:28 -04002143 ByteString fontName = vp.ToByteString();
2144 return !fontName.IsEmpty();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002145}
2146
dan sinclaircbe23db2017-10-19 14:29:33 -04002147bool Field::get_text_size(CJS_Runtime* pRuntime,
2148 CJS_PropValue* vp,
2149 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002150 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002151
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002152 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2153 if (FieldArray.empty())
2154 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002155
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002156 CPDF_FormField* pFormField = FieldArray[0];
2157 ASSERT(pFormField);
2158 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2159 if (!pFormControl)
2160 return false;
2161
Dan Sinclair05df0752017-03-14 14:43:42 -04002162 float fFontSize;
Tom Sepezc4a2b752017-04-07 13:56:13 -07002163 CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
2164 FieldAppearance.GetFont(&fFontSize);
dan sinclaircbe23db2017-10-19 14:29:33 -04002165 vp->Set(static_cast<int>(fFontSize));
2166 return true;
2167}
2168
2169bool Field::set_text_size(CJS_Runtime* pRuntime,
2170 const CJS_PropValue& vp,
2171 WideString* sError) {
2172 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04002173 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002174}
2175
dan sinclaircbe23db2017-10-19 14:29:33 -04002176bool Field::get_type(CJS_Runtime* pRuntime,
2177 CJS_PropValue* vp,
2178 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002179 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2180 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002181 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002182
Lei Zhangd88a3642015-11-10 09:38:57 -08002183 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002184 switch (pFormField->GetFieldType()) {
2185 case FIELDTYPE_UNKNOWN:
dan sinclaircbe23db2017-10-19 14:29:33 -04002186 vp->Set(L"unknown");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002187 break;
2188 case FIELDTYPE_PUSHBUTTON:
dan sinclaircbe23db2017-10-19 14:29:33 -04002189 vp->Set(L"button");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002190 break;
2191 case FIELDTYPE_CHECKBOX:
dan sinclaircbe23db2017-10-19 14:29:33 -04002192 vp->Set(L"checkbox");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002193 break;
2194 case FIELDTYPE_RADIOBUTTON:
dan sinclaircbe23db2017-10-19 14:29:33 -04002195 vp->Set(L"radiobutton");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002196 break;
2197 case FIELDTYPE_COMBOBOX:
dan sinclaircbe23db2017-10-19 14:29:33 -04002198 vp->Set(L"combobox");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002199 break;
2200 case FIELDTYPE_LISTBOX:
dan sinclaircbe23db2017-10-19 14:29:33 -04002201 vp->Set(L"listbox");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002202 break;
2203 case FIELDTYPE_TEXTFIELD:
dan sinclaircbe23db2017-10-19 14:29:33 -04002204 vp->Set(L"text");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002205 break;
2206 case FIELDTYPE_SIGNATURE:
dan sinclaircbe23db2017-10-19 14:29:33 -04002207 vp->Set(L"signature");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002208 break;
2209 default:
dan sinclaircbe23db2017-10-19 14:29:33 -04002210 vp->Set(L"unknown");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002211 break;
2212 }
tsepez4cf55152016-11-02 14:37:54 -07002213 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002214}
2215
dan sinclaircbe23db2017-10-19 14:29:33 -04002216bool Field::set_type(CJS_Runtime* pRuntime,
2217 const CJS_PropValue& vp,
2218 WideString* sError) {
2219 return false;
2220}
2221
2222bool Field::get_user_name(CJS_Runtime* pRuntime,
2223 CJS_PropValue* vp,
2224 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002225 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002226
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002227 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2228 if (FieldArray.empty())
2229 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002230
dan sinclaircbe23db2017-10-19 14:29:33 -04002231 vp->Set(FieldArray[0]->GetAlternateName());
tsepez4cf55152016-11-02 14:37:54 -07002232 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002233}
2234
dan sinclaircbe23db2017-10-19 14:29:33 -04002235bool Field::set_user_name(CJS_Runtime* pRuntime,
2236 const CJS_PropValue& vp,
2237 WideString* sError) {
2238 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04002239 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002240}
2241
dan sinclaircbe23db2017-10-19 14:29:33 -04002242bool Field::get_value(CJS_Runtime* pRuntime,
2243 CJS_PropValue* vp,
2244 WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002245 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2246 if (FieldArray.empty())
2247 return false;
2248
2249 CPDF_FormField* pFormField = FieldArray[0];
2250 switch (pFormField->GetFieldType()) {
2251 case FIELDTYPE_PUSHBUTTON:
2252 return false;
2253 case FIELDTYPE_COMBOBOX:
dan sinclaircbe23db2017-10-19 14:29:33 -04002254 case FIELDTYPE_TEXTFIELD:
2255 vp->Set(pFormField->GetValue());
2256 break;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002257 case FIELDTYPE_LISTBOX: {
2258 if (pFormField->CountSelectedItems() > 1) {
2259 CJS_Array ValueArray;
2260 CJS_Value ElementValue(pRuntime);
2261 int iIndex;
2262 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
2263 iIndex = pFormField->GetSelectedIndex(i);
2264 ElementValue =
2265 CJS_Value(pRuntime, pFormField->GetOptionValue(iIndex).c_str());
Ryan Harrison8b1408e2017-09-27 11:07:51 -04002266 if (wcslen(ElementValue.ToCFXWideString(pRuntime).c_str()) == 0) {
tsepezf3dc8c62016-08-10 06:29:29 -07002267 ElementValue =
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002268 CJS_Value(pRuntime, pFormField->GetOptionLabel(iIndex).c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002269 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002270 ValueArray.SetElement(pRuntime, i, ElementValue);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002271 }
dan sinclaircbe23db2017-10-19 14:29:33 -04002272 vp->Set(ValueArray);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002273 } else {
dan sinclaircbe23db2017-10-19 14:29:33 -04002274 vp->Set(pFormField->GetValue());
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002275 }
dan sinclaircbe23db2017-10-19 14:29:33 -04002276 break;
2277 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002278 case FIELDTYPE_CHECKBOX:
2279 case FIELDTYPE_RADIOBUTTON: {
2280 bool bFind = false;
2281 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2282 if (pFormField->GetControl(i)->IsChecked()) {
dan sinclaircbe23db2017-10-19 14:29:33 -04002283 vp->Set(pFormField->GetControl(i)->GetExportValue());
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002284 bFind = true;
2285 break;
2286 }
2287 }
2288 if (!bFind)
dan sinclaircbe23db2017-10-19 14:29:33 -04002289 vp->Set(L"Off");
2290
2291 break;
2292 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002293 default:
dan sinclaircbe23db2017-10-19 14:29:33 -04002294 vp->Set(pFormField->GetValue());
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002295 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002296 }
dan sinclaircbe23db2017-10-19 14:29:33 -04002297 vp->GetJSValue()->MaybeCoerceToNumber(pRuntime);
2298 return true;
2299}
2300
2301bool Field::set_value(CJS_Runtime* pRuntime,
2302 const CJS_PropValue& vp,
2303 WideString* sError) {
2304 if (!m_bCanSet)
2305 return false;
2306
2307 std::vector<WideString> strArray;
2308 if (vp.GetJSValue()->IsArrayObject()) {
2309 CJS_Array ValueArray = vp.ToArray();
2310 for (int i = 0, sz = ValueArray.GetLength(pRuntime); i < sz; i++) {
2311 CJS_Value ElementValue(pRuntime);
2312 ValueArray.GetElement(pRuntime, i, ElementValue);
2313 strArray.push_back(ElementValue.ToCFXWideString(pRuntime));
2314 }
2315 } else {
2316 strArray.push_back(vp.ToWideString());
2317 }
2318
2319 if (m_bDelay) {
2320 AddDelay_WideStringArray(FP_VALUE, strArray);
2321 } else {
2322 Field::SetValue(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
2323 strArray);
2324 }
tsepez4cf55152016-11-02 14:37:54 -07002325 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002326}
2327
dsinclair3a7741a2016-10-11 10:39:49 -07002328void Field::SetValue(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04002329 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002330 int nControlIndex,
Ryan Harrison275e2602017-09-18 14:23:18 -04002331 const std::vector<WideString>& strArray) {
dsinclair3a7741a2016-10-11 10:39:49 -07002332 ASSERT(pFormFillEnv);
tsepez41a53ad2016-03-28 16:59:30 -07002333 if (strArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002334 return;
2335
Lei Zhangd88a3642015-11-10 09:38:57 -08002336 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07002337 GetFormFields(pFormFillEnv, swFieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002338
Lei Zhangd88a3642015-11-10 09:38:57 -08002339 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002340 if (pFormField->GetFullName().Compare(swFieldName) != 0)
2341 continue;
2342
2343 switch (pFormField->GetFieldType()) {
2344 case FIELDTYPE_TEXTFIELD:
2345 case FIELDTYPE_COMBOBOX:
tsepez41a53ad2016-03-28 16:59:30 -07002346 if (pFormField->GetValue() != strArray[0]) {
tsepez4cf55152016-11-02 14:37:54 -07002347 pFormField->SetValue(strArray[0], true);
2348 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002349 }
2350 break;
tsepez41a53ad2016-03-28 16:59:30 -07002351 case FIELDTYPE_CHECKBOX:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002352 case FIELDTYPE_RADIOBUTTON: {
tsepez41a53ad2016-03-28 16:59:30 -07002353 if (pFormField->GetValue() != strArray[0]) {
tsepez4cf55152016-11-02 14:37:54 -07002354 pFormField->SetValue(strArray[0], true);
2355 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002356 }
2357 } break;
2358 case FIELDTYPE_LISTBOX: {
tsepez4cf55152016-11-02 14:37:54 -07002359 bool bModified = false;
tsepez41a53ad2016-03-28 16:59:30 -07002360 for (const auto& str : strArray) {
2361 if (!pFormField->IsItemSelected(pFormField->FindOption(str))) {
tsepez4cf55152016-11-02 14:37:54 -07002362 bModified = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002363 break;
2364 }
2365 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002366 if (bModified) {
tsepez4cf55152016-11-02 14:37:54 -07002367 pFormField->ClearSelection(true);
tsepez41a53ad2016-03-28 16:59:30 -07002368 for (const auto& str : strArray) {
2369 int index = pFormField->FindOption(str);
2370 if (!pFormField->IsItemSelected(index))
tsepez4cf55152016-11-02 14:37:54 -07002371 pFormField->SetItemSelection(index, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002372 }
tsepez4cf55152016-11-02 14:37:54 -07002373 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002374 }
2375 } break;
2376 default:
2377 break;
2378 }
2379 }
2380}
2381
dan sinclaircbe23db2017-10-19 14:29:33 -04002382bool Field::get_value_as_string(CJS_Runtime* pRuntime,
2383 CJS_PropValue* vp,
2384 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002385 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2386 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002387 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002388
Lei Zhangd88a3642015-11-10 09:38:57 -08002389 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002390 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002391 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002392
2393 if (pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) {
2394 if (!pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002395 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002396
dan sinclaircbe23db2017-10-19 14:29:33 -04002397 vp->Set(pFormField->GetControl(0)->IsChecked() ? L"Yes" : L"Off");
2398 return true;
2399 }
2400
2401 if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON &&
2402 !(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002403 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2404 if (pFormField->GetControl(i)->IsChecked()) {
dan sinclaircbe23db2017-10-19 14:29:33 -04002405 vp->Set(pFormField->GetControl(i)->GetExportValue().c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002406 break;
Lei Zhangd88a3642015-11-10 09:38:57 -08002407 } else {
dan sinclaircbe23db2017-10-19 14:29:33 -04002408 vp->Set(L"Off");
Lei Zhangd88a3642015-11-10 09:38:57 -08002409 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002410 }
dan sinclaircbe23db2017-10-19 14:29:33 -04002411 return true;
2412 }
2413
2414 if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX &&
2415 (pFormField->CountSelectedItems() > 1)) {
2416 vp->Set(L"");
Lei Zhangd88a3642015-11-10 09:38:57 -08002417 } else {
dan sinclaircbe23db2017-10-19 14:29:33 -04002418 vp->Set(pFormField->GetValue().c_str());
Lei Zhangd88a3642015-11-10 09:38:57 -08002419 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002420
tsepez4cf55152016-11-02 14:37:54 -07002421 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002422}
2423
dan sinclaircbe23db2017-10-19 14:29:33 -04002424bool Field::set_value_as_string(CJS_Runtime* pRuntime,
2425 const CJS_PropValue& vp,
2426 WideString* sError) {
2427 return false;
2428}
2429
Tom Sepezb1670b52017-02-16 17:01:00 -08002430bool Field::browseForFileToSubmit(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002431 const std::vector<CJS_Value>& params,
2432 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002433 WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002434 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2435 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002436 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002437
Lei Zhangd88a3642015-11-10 09:38:57 -08002438 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002439 if ((pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) &&
2440 (pFormField->GetFieldType() == FIELDTYPE_TEXTFIELD)) {
Ryan Harrison275e2602017-09-18 14:23:18 -04002441 WideString wsFileName = m_pFormFillEnv->JS_fieldBrowse();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002442 if (!wsFileName.IsEmpty()) {
2443 pFormField->SetValue(wsFileName);
tsepez4cf55152016-11-02 14:37:54 -07002444 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002445 }
tsepez4cf55152016-11-02 14:37:54 -07002446 return true;
Lei Zhangd88a3642015-11-10 09:38:57 -08002447 }
tsepez4cf55152016-11-02 14:37:54 -07002448 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002449}
2450
Tom Sepezb1670b52017-02-16 17:01:00 -08002451bool Field::buttonGetCaption(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002452 const std::vector<CJS_Value>& params,
2453 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002454 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002455 int nface = 0;
2456 int iSize = params.size();
2457 if (iSize >= 1)
tsepezb4694242016-08-15 16:44:55 -07002458 nface = params[0].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002459
Lei Zhangd88a3642015-11-10 09:38:57 -08002460 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2461 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002462 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002463
Lei Zhangd88a3642015-11-10 09:38:57 -08002464 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002465 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002466 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002467
2468 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2469 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -07002470 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002471
2472 if (nface == 0)
tsepezf3dc8c62016-08-10 06:29:29 -07002473 vRet = CJS_Value(pRuntime, pFormControl->GetNormalCaption().c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002474 else if (nface == 1)
tsepezf3dc8c62016-08-10 06:29:29 -07002475 vRet = CJS_Value(pRuntime, pFormControl->GetDownCaption().c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002476 else if (nface == 2)
tsepezf3dc8c62016-08-10 06:29:29 -07002477 vRet = CJS_Value(pRuntime, pFormControl->GetRolloverCaption().c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002478 else
tsepez4cf55152016-11-02 14:37:54 -07002479 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002480
tsepez4cf55152016-11-02 14:37:54 -07002481 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002482}
2483
Tom Sepezb1670b52017-02-16 17:01:00 -08002484bool Field::buttonGetIcon(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002485 const std::vector<CJS_Value>& params,
2486 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002487 WideString& sError) {
Tom Sepez40e0a812017-02-23 13:07:36 -08002488 if (params.size() >= 1) {
2489 int nFace = params[0].ToInt(pRuntime);
2490 if (nFace < 0 || nFace > 2)
2491 return false;
2492 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002493
Lei Zhangd88a3642015-11-10 09:38:57 -08002494 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2495 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002496 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002497
Lei Zhangd88a3642015-11-10 09:38:57 -08002498 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002499 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002500 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002501
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002502 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2503 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -07002504 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002505
tsepezb4694242016-08-15 16:44:55 -07002506 v8::Local<v8::Object> pObj =
2507 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID);
Tom Sepezc5a14722017-02-24 15:31:12 -08002508 if (pObj.IsEmpty())
2509 return false;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002510
tsepezb4694242016-08-15 16:44:55 -07002511 CJS_Icon* pJS_Icon = static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj));
tsepezf3dc8c62016-08-10 06:29:29 -07002512 vRet = CJS_Value(pRuntime, pJS_Icon);
tsepez4cf55152016-11-02 14:37:54 -07002513 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002514}
2515
Tom Sepezb1670b52017-02-16 17:01:00 -08002516bool Field::buttonImportIcon(CJS_Runtime* pRuntime,
Lei Zhang945fdb72015-11-11 10:18:16 -08002517 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002518 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002519 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002520 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002521}
2522
Tom Sepezb1670b52017-02-16 17:01:00 -08002523bool Field::buttonSetCaption(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002524 const std::vector<CJS_Value>& params,
2525 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002526 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002527 return false;
2528}
2529
Tom Sepezb1670b52017-02-16 17:01:00 -08002530bool Field::buttonSetIcon(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002531 const std::vector<CJS_Value>& params,
2532 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002533 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002534 return false;
2535}
2536
Tom Sepezb1670b52017-02-16 17:01:00 -08002537bool Field::checkThisBox(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002538 const std::vector<CJS_Value>& params,
2539 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002540 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002541 int iSize = params.size();
2542 if (iSize < 1)
tsepez4cf55152016-11-02 14:37:54 -07002543 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002544
tsepezf3dc8c62016-08-10 06:29:29 -07002545 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002546 return false;
tsepezf3dc8c62016-08-10 06:29:29 -07002547
tsepezb4694242016-08-15 16:44:55 -07002548 int nWidget = params[0].ToInt(pRuntime);
Wei Li97da9762016-03-11 17:00:48 -08002549 bool bCheckit = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002550 if (iSize >= 2)
tsepezb4694242016-08-15 16:44:55 -07002551 bCheckit = params[1].ToBool(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002552
Lei Zhangd88a3642015-11-10 09:38:57 -08002553 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2554 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002555 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002556
Lei Zhangd88a3642015-11-10 09:38:57 -08002557 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002558 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
2559 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002560 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002561 if (nWidget < 0 || nWidget >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002562 return false;
Wei Li97da9762016-03-11 17:00:48 -08002563 // TODO(weili): Check whether anything special needed for radio button,
2564 // otherwise merge these branches.
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002565 if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)
Wei Li97da9762016-03-11 17:00:48 -08002566 pFormField->CheckControl(nWidget, bCheckit, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002567 else
Wei Li97da9762016-03-11 17:00:48 -08002568 pFormField->CheckControl(nWidget, bCheckit, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002569
tsepez4cf55152016-11-02 14:37:54 -07002570 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true);
2571 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002572}
2573
Tom Sepezb1670b52017-02-16 17:01:00 -08002574bool Field::clearItems(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002575 const std::vector<CJS_Value>& params,
2576 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002577 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002578 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002579}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002580
Tom Sepezb1670b52017-02-16 17:01:00 -08002581bool Field::defaultIsChecked(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002582 const std::vector<CJS_Value>& params,
2583 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002584 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002585 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002586 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002587
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002588 int iSize = params.size();
2589 if (iSize < 1)
tsepez4cf55152016-11-02 14:37:54 -07002590 return false;
Tom Sepezf4ef3f92015-04-23 11:31:31 -07002591
tsepezb4694242016-08-15 16:44:55 -07002592 int nWidget = params[0].ToInt(pRuntime);
Lei Zhangd88a3642015-11-10 09:38:57 -08002593 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2594 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002595 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002596
Lei Zhangd88a3642015-11-10 09:38:57 -08002597 CPDF_FormField* pFormField = FieldArray[0];
tsepezf3dc8c62016-08-10 06:29:29 -07002598 if (nWidget < 0 || nWidget >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002599 return false;
tsepezf3dc8c62016-08-10 06:29:29 -07002600
2601 vRet = CJS_Value(pRuntime,
2602 pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
2603 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002604
tsepez4cf55152016-11-02 14:37:54 -07002605 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002606}
2607
Tom Sepezb1670b52017-02-16 17:01:00 -08002608bool Field::deleteItemAt(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002609 const std::vector<CJS_Value>& params,
2610 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002611 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002612 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002613}
2614
Tom Sepezb1670b52017-02-16 17:01:00 -08002615bool Field::getArray(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002616 const std::vector<CJS_Value>& params,
2617 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002618 WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002619 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2620 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002621 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002622
Ryan Harrison275e2602017-09-18 14:23:18 -04002623 std::vector<std::unique_ptr<WideString>> swSort;
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002624 for (CPDF_FormField* pFormField : FieldArray) {
Ryan Harrison275e2602017-09-18 14:23:18 -04002625 swSort.push_back(
2626 std::unique_ptr<WideString>(new WideString(pFormField->GetFullName())));
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002627 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002628
Ryan Harrison275e2602017-09-18 14:23:18 -04002629 std::sort(swSort.begin(), swSort.end(),
2630 [](const std::unique_ptr<WideString>& p1,
2631 const std::unique_ptr<WideString>& p2) { return *p1 < *p2; });
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002632
tsepeze5aff742016-08-08 09:49:42 -07002633 CJS_Array FormFieldArray;
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002634
2635 int j = 0;
2636 for (const auto& pStr : swSort) {
tsepezb4694242016-08-15 16:44:55 -07002637 v8::Local<v8::Object> pObj =
2638 pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID);
Tom Sepezc5a14722017-02-24 15:31:12 -08002639 if (pObj.IsEmpty())
2640 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002641
Tom Sepezd5a0e952015-09-17 15:40:06 -07002642 CJS_Field* pJSField =
tsepezb4694242016-08-15 16:44:55 -07002643 static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pObj));
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002644 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002645 pField->AttachField(m_pJSDoc, *pStr);
tsepezb4694242016-08-15 16:44:55 -07002646 FormFieldArray.SetElement(pRuntime, j++, CJS_Value(pRuntime, pJSField));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002647 }
2648
tsepeze5aff742016-08-08 09:49:42 -07002649 vRet = CJS_Value(pRuntime, FormFieldArray);
tsepez4cf55152016-11-02 14:37:54 -07002650 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002651}
2652
Tom Sepezb1670b52017-02-16 17:01:00 -08002653bool Field::getItemAt(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002654 const std::vector<CJS_Value>& params,
2655 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002656 WideString& sError) {
tsepezf3dc8c62016-08-10 06:29:29 -07002657 int iSize = params.size();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002658 int nIdx = -1;
2659 if (iSize >= 1)
tsepezb4694242016-08-15 16:44:55 -07002660 nIdx = params[0].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002661
tsepez4cf55152016-11-02 14:37:54 -07002662 bool bExport = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002663 if (iSize >= 2)
tsepezb4694242016-08-15 16:44:55 -07002664 bExport = params[1].ToBool(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002665
Lei Zhangd88a3642015-11-10 09:38:57 -08002666 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2667 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002668 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002669
Lei Zhangd88a3642015-11-10 09:38:57 -08002670 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002671 if ((pFormField->GetFieldType() == FIELDTYPE_LISTBOX) ||
2672 (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX)) {
2673 if (nIdx == -1 || nIdx > pFormField->CountOptions())
2674 nIdx = pFormField->CountOptions() - 1;
2675 if (bExport) {
Ryan Harrison275e2602017-09-18 14:23:18 -04002676 WideString strval = pFormField->GetOptionValue(nIdx);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002677 if (strval.IsEmpty())
tsepezf3dc8c62016-08-10 06:29:29 -07002678 vRet = CJS_Value(pRuntime, pFormField->GetOptionLabel(nIdx).c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002679 else
tsepezf3dc8c62016-08-10 06:29:29 -07002680 vRet = CJS_Value(pRuntime, strval.c_str());
Lei Zhangd88a3642015-11-10 09:38:57 -08002681 } else {
tsepezf3dc8c62016-08-10 06:29:29 -07002682 vRet = CJS_Value(pRuntime, pFormField->GetOptionLabel(nIdx).c_str());
Lei Zhangd88a3642015-11-10 09:38:57 -08002683 }
2684 } else {
tsepez4cf55152016-11-02 14:37:54 -07002685 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08002686 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002687
tsepez4cf55152016-11-02 14:37:54 -07002688 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002689}
2690
Tom Sepezb1670b52017-02-16 17:01:00 -08002691bool Field::getLock(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002692 const std::vector<CJS_Value>& params,
2693 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002694 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002695 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002696}
2697
Tom Sepezb1670b52017-02-16 17:01:00 -08002698bool Field::insertItemAt(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002699 const std::vector<CJS_Value>& params,
2700 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002701 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002702 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002703}
2704
Tom Sepezb1670b52017-02-16 17:01:00 -08002705bool Field::isBoxChecked(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002706 const std::vector<CJS_Value>& params,
2707 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002708 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002709 int nIndex = -1;
2710 if (params.size() >= 1)
tsepezb4694242016-08-15 16:44:55 -07002711 nIndex = params[0].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002712
Lei Zhangd88a3642015-11-10 09:38:57 -08002713 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2714 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002715 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002716
Lei Zhangd88a3642015-11-10 09:38:57 -08002717 CPDF_FormField* pFormField = FieldArray[0];
dan sinclair646634b2017-10-19 14:30:28 -04002718 if (nIndex < 0 || nIndex >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002719 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002720
tsepezf3dc8c62016-08-10 06:29:29 -07002721 vRet = CJS_Value(pRuntime,
2722 ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
2723 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) &&
2724 pFormField->GetControl(nIndex)->IsChecked() != 0));
tsepez4cf55152016-11-02 14:37:54 -07002725 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002726}
2727
Tom Sepezb1670b52017-02-16 17:01:00 -08002728bool Field::isDefaultChecked(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002729 const std::vector<CJS_Value>& params,
2730 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002731 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002732 int nIndex = -1;
2733 if (params.size() >= 1)
tsepezb4694242016-08-15 16:44:55 -07002734 nIndex = params[0].ToInt(pRuntime);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002735
Lei Zhangd88a3642015-11-10 09:38:57 -08002736 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2737 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002738 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002739
Lei Zhangd88a3642015-11-10 09:38:57 -08002740 CPDF_FormField* pFormField = FieldArray[0];
tsepezf3dc8c62016-08-10 06:29:29 -07002741 if (nIndex < 0 || nIndex >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002742 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002743
tsepezf3dc8c62016-08-10 06:29:29 -07002744 vRet = CJS_Value(pRuntime,
2745 ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
2746 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) &&
2747 pFormField->GetControl(nIndex)->IsDefaultChecked() != 0));
tsepez4cf55152016-11-02 14:37:54 -07002748 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002749}
2750
Tom Sepezb1670b52017-02-16 17:01:00 -08002751bool Field::setAction(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002752 const std::vector<CJS_Value>& params,
2753 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002754 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002755 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002756}
2757
Tom Sepezb1670b52017-02-16 17:01:00 -08002758bool Field::setFocus(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002759 const std::vector<CJS_Value>& params,
2760 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002761 WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002762 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2763 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002764 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002765
Lei Zhangd88a3642015-11-10 09:38:57 -08002766 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002767 int32_t nCount = pFormField->CountControls();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002768 if (nCount < 1)
tsepez4cf55152016-11-02 14:37:54 -07002769 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002770
dsinclair7cbe68e2016-10-12 11:56:23 -07002771 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
thestig1cd352e2016-06-07 17:53:06 -07002772 CPDFSDK_Widget* pWidget = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002773 if (nCount == 1) {
dsinclairc5267c52016-11-04 15:35:12 -07002774 pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002775 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002776 UnderlyingPageType* pPage =
2777 UnderlyingFromFPDFPage(m_pFormFillEnv->GetCurrentPage(
2778 m_pFormFillEnv->GetUnderlyingDocument()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002779 if (!pPage)
tsepez4cf55152016-11-02 14:37:54 -07002780 return false;
dsinclair461eeaf2016-07-27 07:40:05 -07002781 if (CPDFSDK_PageView* pCurPageView =
dsinclair7cbe68e2016-10-12 11:56:23 -07002782 m_pFormFillEnv->GetPageView(pPage, true)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002783 for (int32_t i = 0; i < nCount; i++) {
2784 if (CPDFSDK_Widget* pTempWidget =
dsinclairc5267c52016-11-04 15:35:12 -07002785 pInterForm->GetWidget(pFormField->GetControl(i))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002786 if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage()) {
2787 pWidget = pTempWidget;
2788 break;
2789 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002790 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002791 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002792 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002793 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002794
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002795 if (pWidget) {
tsepezf8074ce2016-09-27 14:29:57 -07002796 CPDFSDK_Annot::ObservedPtr pObserved(pWidget);
dsinclair7cbe68e2016-10-12 11:56:23 -07002797 m_pFormFillEnv->SetFocusAnnot(&pObserved);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002798 }
2799
tsepez4cf55152016-11-02 14:37:54 -07002800 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002801}
2802
Tom Sepezb1670b52017-02-16 17:01:00 -08002803bool Field::setItems(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002804 const std::vector<CJS_Value>& params,
2805 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002806 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002807 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002808}
2809
Tom Sepezb1670b52017-02-16 17:01:00 -08002810bool Field::setLock(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002811 const std::vector<CJS_Value>& params,
2812 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002813 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002814 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002815}
2816
Tom Sepezb1670b52017-02-16 17:01:00 -08002817bool Field::signatureGetModifications(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002818 const std::vector<CJS_Value>& params,
2819 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002820 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002821 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002822}
2823
Tom Sepezb1670b52017-02-16 17:01:00 -08002824bool Field::signatureGetSeedValue(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002825 const std::vector<CJS_Value>& params,
2826 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002827 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002828 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002829}
2830
Tom Sepezb1670b52017-02-16 17:01:00 -08002831bool Field::signatureInfo(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002832 const std::vector<CJS_Value>& params,
2833 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002834 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002835 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002836}
2837
Tom Sepezb1670b52017-02-16 17:01:00 -08002838bool Field::signatureSetSeedValue(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002839 const std::vector<CJS_Value>& params,
2840 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002841 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002842 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002843}
2844
Tom Sepezb1670b52017-02-16 17:01:00 -08002845bool Field::signatureSign(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002846 const std::vector<CJS_Value>& params,
2847 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002848 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002849 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002850}
2851
Tom Sepezb1670b52017-02-16 17:01:00 -08002852bool Field::signatureValidate(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002853 const std::vector<CJS_Value>& params,
2854 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002855 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002856 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002857}
2858
dan sinclaircbe23db2017-10-19 14:29:33 -04002859bool Field::get_source(CJS_Runtime* pRuntime,
2860 CJS_PropValue* vp,
2861 WideString* sError) {
2862 vp->Set(static_cast<CJS_Object*>(nullptr));
2863 return true;
2864}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002865
dan sinclaircbe23db2017-10-19 14:29:33 -04002866bool Field::set_source(CJS_Runtime* pRuntime,
2867 const CJS_PropValue& vp,
2868 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -07002869 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002870}
2871
tsepez41a53ad2016-03-28 16:59:30 -07002872void Field::AddDelay_Int(FIELD_PROP prop, int32_t n) {
2873 CJS_DelayData* pNewData =
2874 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002875 pNewData->num = n;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002876 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002877}
2878
tsepez41a53ad2016-03-28 16:59:30 -07002879void Field::AddDelay_Bool(FIELD_PROP prop, bool b) {
2880 CJS_DelayData* pNewData =
2881 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002882 pNewData->b = b;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002883 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002884}
2885
Ryan Harrison275e2602017-09-18 14:23:18 -04002886void Field::AddDelay_String(FIELD_PROP prop, const ByteString& string) {
tsepez41a53ad2016-03-28 16:59:30 -07002887 CJS_DelayData* pNewData =
2888 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002889 pNewData->string = string;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002890 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002891}
2892
tsepez41a53ad2016-03-28 16:59:30 -07002893void Field::AddDelay_Rect(FIELD_PROP prop, const CFX_FloatRect& rect) {
2894 CJS_DelayData* pNewData =
2895 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002896 pNewData->rect = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002897 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002898}
2899
tsepez41a53ad2016-03-28 16:59:30 -07002900void Field::AddDelay_WordArray(FIELD_PROP prop,
2901 const std::vector<uint32_t>& array) {
2902 CJS_DelayData* pNewData =
2903 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
2904 pNewData->wordarray = array;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002905 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002906}
2907
tsepez41a53ad2016-03-28 16:59:30 -07002908void Field::AddDelay_WideStringArray(FIELD_PROP prop,
Ryan Harrison275e2602017-09-18 14:23:18 -04002909 const std::vector<WideString>& array) {
tsepez41a53ad2016-03-28 16:59:30 -07002910 CJS_DelayData* pNewData =
2911 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
2912 pNewData->widestringarray = array;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002913 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002914}
2915
dsinclair3a7741a2016-10-11 10:39:49 -07002916void Field::DoDelay(CPDFSDK_FormFillEnvironment* pFormFillEnv,
2917 CJS_DelayData* pData) {
2918 ASSERT(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002919 switch (pData->eProp) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002920 case FP_BORDERSTYLE:
dsinclair3a7741a2016-10-11 10:39:49 -07002921 Field::SetBorderStyle(pFormFillEnv, pData->sFieldName,
2922 pData->nControlIndex, pData->string);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002923 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002924 case FP_CURRENTVALUEINDICES:
dsinclair3a7741a2016-10-11 10:39:49 -07002925 Field::SetCurrentValueIndices(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002926 pData->nControlIndex, pData->wordarray);
2927 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002928 case FP_DISPLAY:
dsinclair3a7741a2016-10-11 10:39:49 -07002929 Field::SetDisplay(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002930 pData->num);
2931 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002932 case FP_HIDDEN:
dsinclair3a7741a2016-10-11 10:39:49 -07002933 Field::SetHidden(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002934 pData->b);
2935 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002936 case FP_LINEWIDTH:
dsinclair3a7741a2016-10-11 10:39:49 -07002937 Field::SetLineWidth(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002938 pData->num);
2939 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002940 case FP_RECT:
dsinclair3a7741a2016-10-11 10:39:49 -07002941 Field::SetRect(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002942 pData->rect);
2943 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002944 case FP_VALUE:
dsinclair3a7741a2016-10-11 10:39:49 -07002945 Field::SetValue(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002946 pData->widestringarray);
2947 break;
dan sinclair646634b2017-10-19 14:30:28 -04002948 default:
2949 NOTREACHED();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002950 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002951}