blob: d3923141da53b82d7888277e38a01067537dc517 [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();
Dan Sinclairc9708952017-10-23 09:40:59 -0400877 for (int i = 0, sz = SelArray.GetLength(pRuntime); i < sz; i++)
878 array.push_back(SelArray.GetElement(pRuntime, i).ToInt(pRuntime));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700879 }
880
dan sinclaircbe23db2017-10-19 14:29:33 -0400881 if (m_bDelay) {
882 AddDelay_WordArray(FP_CURRENTVALUEINDICES, array);
883 } else {
884 Field::SetCurrentValueIndices(m_pFormFillEnv.Get(), m_FieldName,
885 m_nFormControlIndex, array);
886 }
tsepez4cf55152016-11-02 14:37:54 -0700887 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700888}
889
dsinclair3a7741a2016-10-11 10:39:49 -0700890void Field::SetCurrentValueIndices(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -0400891 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700892 int nControlIndex,
tsepez41a53ad2016-03-28 16:59:30 -0700893 const std::vector<uint32_t>& array) {
dsinclair3a7741a2016-10-11 10:39:49 -0700894 ASSERT(pFormFillEnv);
Lei Zhangd88a3642015-11-10 09:38:57 -0800895 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -0700896 GetFormFields(pFormFillEnv, swFieldName);
tsepez41a53ad2016-03-28 16:59:30 -0700897
Lei Zhangd88a3642015-11-10 09:38:57 -0800898 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700899 int nFieldType = pFormField->GetFieldType();
900 if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX) {
tsepezc3255f52016-03-25 14:52:27 -0700901 uint32_t dwFieldFlags = pFormField->GetFieldFlags();
tsepez4cf55152016-11-02 14:37:54 -0700902 pFormField->ClearSelection(true);
tsepez41a53ad2016-03-28 16:59:30 -0700903 for (size_t i = 0; i < array.size(); ++i) {
904 if (i != 0 && !(dwFieldFlags & (1 << 21)))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700905 break;
Wei Li05d53f02016-03-29 16:42:53 -0700906 if (array[i] < static_cast<uint32_t>(pFormField->CountOptions()) &&
tsepez41a53ad2016-03-28 16:59:30 -0700907 !pFormField->IsItemSelected(array[i])) {
tsepez4cf55152016-11-02 14:37:54 -0700908 pFormField->SetItemSelection(array[i], true);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700909 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700910 }
tsepez4cf55152016-11-02 14:37:54 -0700911 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700912 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700913 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700914}
915
dan sinclaircbe23db2017-10-19 14:29:33 -0400916bool Field::get_default_style(CJS_Runtime* pRuntime,
917 CJS_PropValue* vp,
918 WideString* sError) {
919 return false;
920}
921
922bool Field::set_default_style(CJS_Runtime* pRuntime,
923 const CJS_PropValue& vp,
924 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -0700925 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700926}
927
dan sinclaircbe23db2017-10-19 14:29:33 -0400928bool Field::get_default_value(CJS_Runtime* pRuntime,
929 CJS_PropValue* vp,
930 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700931 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700932
Lei Zhangd88a3642015-11-10 09:38:57 -0800933 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
934 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700935 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700936
Lei Zhangd88a3642015-11-10 09:38:57 -0800937 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700938 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON ||
Lei Zhangd88a3642015-11-10 09:38:57 -0800939 pFormField->GetFieldType() == FIELDTYPE_SIGNATURE) {
tsepez4cf55152016-11-02 14:37:54 -0700940 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -0800941 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700942
dan sinclaircbe23db2017-10-19 14:29:33 -0400943 vp->Set(pFormField->GetDefaultValue());
944 return true;
945}
946
947bool Field::set_default_value(CJS_Runtime* pRuntime,
948 const CJS_PropValue& vp,
949 WideString* sError) {
950 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400951 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700952}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700953
dan sinclaircbe23db2017-10-19 14:29:33 -0400954bool Field::get_do_not_scroll(CJS_Runtime* pRuntime,
955 CJS_PropValue* vp,
956 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700957 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700958
dan sinclaircbe23db2017-10-19 14:29:33 -0400959 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
960 if (FieldArray.empty())
961 return false;
962
963 CPDF_FormField* pFormField = FieldArray[0];
964 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
965 return false;
966
967 vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL));
968 return true;
969}
970
971bool Field::set_do_not_scroll(CJS_Runtime* pRuntime,
972 const CJS_PropValue& vp,
973 WideString* sError) {
974 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -0400975 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700976}
977
dan sinclaircbe23db2017-10-19 14:29:33 -0400978bool Field::get_do_not_spell_check(CJS_Runtime* pRuntime,
979 CJS_PropValue* vp,
980 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700981 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700982
dan sinclair646634b2017-10-19 14:30:28 -0400983 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
984 if (FieldArray.empty())
985 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700986
dan sinclair646634b2017-10-19 14:30:28 -0400987 CPDF_FormField* pFormField = FieldArray[0];
988 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD &&
989 pFormField->GetFieldType() != FIELDTYPE_COMBOBOX) {
990 return false;
991 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700992
dan sinclair646634b2017-10-19 14:30:28 -0400993 vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK));
994 return true;
dan sinclaircbe23db2017-10-19 14:29:33 -0400995}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700996
dan sinclaircbe23db2017-10-19 14:29:33 -0400997bool Field::set_do_not_spell_check(CJS_Runtime* pRuntime,
998 const CJS_PropValue& vp,
999 WideString* sError) {
1000 ASSERT(m_pFormFillEnv);
1001 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001002}
1003
tsepez4cf55152016-11-02 14:37:54 -07001004void Field::SetDelay(bool bDelay) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001005 m_bDelay = bDelay;
1006
dan sinclaircbe23db2017-10-19 14:29:33 -04001007 if (m_bDelay)
1008 return;
dan sinclaircbe23db2017-10-19 14:29:33 -04001009 if (m_pJSDoc)
1010 m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001011}
1012
dan sinclaircbe23db2017-10-19 14:29:33 -04001013bool Field::get_delay(CJS_Runtime* pRuntime,
1014 CJS_PropValue* vp,
1015 WideString* sError) {
1016 vp->Set(m_bDelay);
tsepez4cf55152016-11-02 14:37:54 -07001017 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001018}
1019
dan sinclaircbe23db2017-10-19 14:29:33 -04001020bool Field::set_delay(CJS_Runtime* pRuntime,
1021 const CJS_PropValue& vp,
1022 WideString* sError) {
1023 if (!m_bCanSet)
1024 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001025
dan sinclaircbe23db2017-10-19 14:29:33 -04001026 SetDelay(vp.ToBool());
1027 return true;
1028}
1029
1030bool Field::get_display(CJS_Runtime* pRuntime,
1031 CJS_PropValue* vp,
1032 WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001033 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1034 if (FieldArray.empty())
1035 return false;
1036
1037 CPDF_FormField* pFormField = FieldArray[0];
1038 ASSERT(pFormField);
dan sinclaircbe23db2017-10-19 14:29:33 -04001039
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001040 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1041 CPDFSDK_Widget* pWidget =
1042 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1043 if (!pWidget)
1044 return false;
1045
1046 uint32_t dwFlag = pWidget->GetFlags();
1047 if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001048 vp->Set(1);
1049 return true;
1050 }
1051 if (ANNOTFLAG_PRINT & dwFlag) {
1052 if (ANNOTFLAG_NOVIEW & dwFlag)
1053 vp->Set(3);
1054 else
1055 vp->Set(0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001056 } else {
dan sinclaircbe23db2017-10-19 14:29:33 -04001057 vp->Set(2);
1058 }
1059 return true;
1060}
1061
1062bool Field::set_display(CJS_Runtime* pRuntime,
1063 const CJS_PropValue& vp,
1064 WideString* sError) {
1065 if (!m_bCanSet)
1066 return false;
1067
1068 if (m_bDelay) {
1069 AddDelay_Int(FP_DISPLAY, vp.ToInt());
1070 } else {
1071 Field::SetDisplay(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
1072 vp.ToInt());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001073 }
tsepez4cf55152016-11-02 14:37:54 -07001074 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001075}
1076
dsinclair3a7741a2016-10-11 10:39:49 -07001077void Field::SetDisplay(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04001078 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001079 int nControlIndex,
1080 int number) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001081 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001082 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07001083 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -08001084 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001085 if (nControlIndex < 0) {
tonikitoo7c05a7a2016-08-17 11:08:46 -07001086 bool bAnySet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001087 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1088 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08001089 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001090
dsinclairc5267c52016-11-04 15:35:12 -07001091 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
tonikitoo7c05a7a2016-08-17 11:08:46 -07001092 if (SetWidgetDisplayStatus(pWidget, number))
1093 bAnySet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001094 }
1095
tonikitoo7c05a7a2016-08-17 11:08:46 -07001096 if (bAnySet)
tsepez4cf55152016-11-02 14:37:54 -07001097 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001098 } else {
1099 if (nControlIndex >= pFormField->CountControls())
1100 return;
tonikitoo7c05a7a2016-08-17 11:08:46 -07001101
1102 CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex);
1103 if (!pFormControl)
1104 return;
1105
dsinclairc5267c52016-11-04 15:35:12 -07001106 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
tonikitoo7c05a7a2016-08-17 11:08:46 -07001107 if (SetWidgetDisplayStatus(pWidget, number))
tsepez4cf55152016-11-02 14:37:54 -07001108 UpdateFormControl(pFormFillEnv, pFormControl, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001109 }
1110 }
1111}
1112
dan sinclaircbe23db2017-10-19 14:29:33 -04001113bool Field::get_doc(CJS_Runtime* pRuntime,
1114 CJS_PropValue* vp,
1115 WideString* sError) {
1116 vp->Set(m_pJSDoc->GetCJSDoc());
tsepez4cf55152016-11-02 14:37:54 -07001117 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001118}
1119
dan sinclaircbe23db2017-10-19 14:29:33 -04001120bool Field::set_doc(CJS_Runtime* pRuntime,
1121 const CJS_PropValue& vp,
1122 WideString* sError) {
1123 return false;
1124}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001125
dan sinclaircbe23db2017-10-19 14:29:33 -04001126bool Field::get_editable(CJS_Runtime* pRuntime,
1127 CJS_PropValue* vp,
1128 WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001129 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1130 if (FieldArray.empty())
1131 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001132
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001133 CPDF_FormField* pFormField = FieldArray[0];
1134 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX)
1135 return false;
1136
dan sinclaircbe23db2017-10-19 14:29:33 -04001137 vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_EDIT));
tsepez4cf55152016-11-02 14:37:54 -07001138 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001139}
1140
dan sinclaircbe23db2017-10-19 14:29:33 -04001141bool Field::set_editable(CJS_Runtime* pRuntime,
1142 const CJS_PropValue& vp,
1143 WideString* sError) {
1144 return m_bCanSet;
1145}
1146
1147bool Field::get_export_values(CJS_Runtime* pRuntime,
1148 CJS_PropValue* vp,
1149 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001150 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1151 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001152 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001153
Lei Zhangd88a3642015-11-10 09:38:57 -08001154 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001155 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001156 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) {
tsepez4cf55152016-11-02 14:37:54 -07001157 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001158 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001159
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001160 CJS_Array ExportValusArray;
1161 if (m_nFormControlIndex < 0) {
1162 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
1163 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001164 ExportValusArray.SetElement(
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001165 pRuntime, i,
tsepeze5aff742016-08-08 09:49:42 -07001166 CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001167 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001168 } else {
1169 if (m_nFormControlIndex >= pFormField->CountControls())
1170 return false;
1171
1172 CPDF_FormControl* pFormControl =
1173 pFormField->GetControl(m_nFormControlIndex);
1174 if (!pFormControl)
1175 return false;
1176
1177 ExportValusArray.SetElement(
1178 pRuntime, 0,
1179 CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001180 }
dan sinclaircbe23db2017-10-19 14:29:33 -04001181
1182 vp->Set(ExportValusArray);
tsepez4cf55152016-11-02 14:37:54 -07001183 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001184}
1185
dan sinclaircbe23db2017-10-19 14:29:33 -04001186bool Field::set_export_values(CJS_Runtime* pRuntime,
1187 const CJS_PropValue& vp,
1188 WideString* sError) {
1189 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1190 if (FieldArray.empty())
1191 return false;
1192
1193 CPDF_FormField* pFormField = FieldArray[0];
1194 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
1195 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) {
1196 return false;
1197 }
1198
1199 return m_bCanSet && vp.GetJSValue()->IsArrayObject();
1200}
1201
1202bool Field::get_file_select(CJS_Runtime* pRuntime,
1203 CJS_PropValue* vp,
1204 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001205 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1206 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001207 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001208
Lei Zhangd88a3642015-11-10 09:38:57 -08001209 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001210 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
tsepez4cf55152016-11-02 14:37:54 -07001211 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001212
dan sinclaircbe23db2017-10-19 14:29:33 -04001213 vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT));
tsepez4cf55152016-11-02 14:37:54 -07001214 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001215}
1216
dan sinclaircbe23db2017-10-19 14:29:33 -04001217bool Field::set_file_select(CJS_Runtime* pRuntime,
1218 const CJS_PropValue& vp,
1219 WideString* sError) {
1220 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1221 if (FieldArray.empty())
1222 return false;
1223
1224 CPDF_FormField* pFormField = FieldArray[0];
1225 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1226 return false;
1227
1228 return m_bCanSet;
1229}
1230
1231bool Field::get_fill_color(CJS_Runtime* pRuntime,
1232 CJS_PropValue* vp,
1233 WideString* sError) {
tsepeze5aff742016-08-08 09:49:42 -07001234 CJS_Array crArray;
Lei Zhangd88a3642015-11-10 09:38:57 -08001235 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1236 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001237 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001238
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001239 CPDF_FormField* pFormField = FieldArray[0];
1240 ASSERT(pFormField);
1241 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1242 if (!pFormControl)
1243 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001244
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001245 int iColorType;
1246 pFormControl->GetBackgroundColor(iColorType);
1247
Dan Sinclair7f55a542017-07-13 14:17:10 -04001248 CFX_Color color;
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001249 if (iColorType == CFX_Color::kTransparent) {
1250 color = CFX_Color(CFX_Color::kTransparent);
1251 } else if (iColorType == CFX_Color::kGray) {
1252 color = CFX_Color(CFX_Color::kGray,
1253 pFormControl->GetOriginalBackgroundColor(0));
1254 } else if (iColorType == CFX_Color::kRGB) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001255 color =
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001256 CFX_Color(CFX_Color::kRGB, pFormControl->GetOriginalBackgroundColor(0),
Dan Sinclair7f55a542017-07-13 14:17:10 -04001257 pFormControl->GetOriginalBackgroundColor(1),
1258 pFormControl->GetOriginalBackgroundColor(2));
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001259 } else if (iColorType == CFX_Color::kCMYK) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001260 color =
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001261 CFX_Color(CFX_Color::kCMYK, pFormControl->GetOriginalBackgroundColor(0),
Dan Sinclair7f55a542017-07-13 14:17:10 -04001262 pFormControl->GetOriginalBackgroundColor(1),
1263 pFormControl->GetOriginalBackgroundColor(2),
1264 pFormControl->GetOriginalBackgroundColor(3));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001265 } else {
1266 return false;
1267 }
dan sinclaircbe23db2017-10-19 14:29:33 -04001268
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001269 color::ConvertPWLColorToArray(pRuntime, color, &crArray);
dan sinclaircbe23db2017-10-19 14:29:33 -04001270 vp->Set(crArray);
1271 return true;
1272}
1273
1274bool Field::set_fill_color(CJS_Runtime* pRuntime,
1275 const CJS_PropValue& vp,
1276 WideString* sError) {
1277 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1278 if (FieldArray.empty())
1279 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -04001280 if (!m_bCanSet)
1281 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -04001282 if (!vp.GetJSValue()->IsArrayObject())
1283 return false;
tsepez4cf55152016-11-02 14:37:54 -07001284 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001285}
1286
dan sinclaircbe23db2017-10-19 14:29:33 -04001287bool Field::get_hidden(CJS_Runtime* pRuntime,
1288 CJS_PropValue* vp,
1289 WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001290 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1291 if (FieldArray.empty())
1292 return false;
1293
1294 CPDF_FormField* pFormField = FieldArray[0];
1295 ASSERT(pFormField);
dan sinclaircbe23db2017-10-19 14:29:33 -04001296
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001297 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1298 CPDFSDK_Widget* pWidget =
1299 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1300 if (!pWidget)
1301 return false;
1302
1303 uint32_t dwFlags = pWidget->GetFlags();
dan sinclaircbe23db2017-10-19 14:29:33 -04001304 vp->Set(ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags);
1305 return true;
1306}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001307
dan sinclaircbe23db2017-10-19 14:29:33 -04001308bool Field::set_hidden(CJS_Runtime* pRuntime,
1309 const CJS_PropValue& vp,
1310 WideString* sError) {
1311 if (!m_bCanSet)
1312 return false;
1313
1314 if (m_bDelay) {
1315 AddDelay_Bool(FP_HIDDEN, vp.ToBool());
1316 } else {
1317 Field::SetHidden(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
1318 vp.ToBool());
1319 }
tsepez4cf55152016-11-02 14:37:54 -07001320 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001321}
1322
dsinclair3a7741a2016-10-11 10:39:49 -07001323void Field::SetHidden(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04001324 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001325 int nControlIndex,
1326 bool b) {
tonikitooa73b8fe2016-08-22 14:06:49 -07001327 int display = b ? 1 /*Hidden*/ : 0 /*Visible*/;
dsinclair3a7741a2016-10-11 10:39:49 -07001328 SetDisplay(pFormFillEnv, swFieldName, nControlIndex, display);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001329}
1330
dan sinclaircbe23db2017-10-19 14:29:33 -04001331bool Field::get_highlight(CJS_Runtime* pRuntime,
1332 CJS_PropValue* vp,
1333 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001334 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001335
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001336 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1337 if (FieldArray.empty())
1338 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001339
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001340 CPDF_FormField* pFormField = FieldArray[0];
1341 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
1342 return false;
1343
1344 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1345 if (!pFormControl)
1346 return false;
1347
1348 int eHM = pFormControl->GetHighlightingMode();
1349 switch (eHM) {
1350 case CPDF_FormControl::None:
dan sinclaircbe23db2017-10-19 14:29:33 -04001351 vp->Set(L"none");
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001352 break;
1353 case CPDF_FormControl::Push:
dan sinclaircbe23db2017-10-19 14:29:33 -04001354 vp->Set(L"push");
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001355 break;
1356 case CPDF_FormControl::Invert:
dan sinclaircbe23db2017-10-19 14:29:33 -04001357 vp->Set(L"invert");
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001358 break;
1359 case CPDF_FormControl::Outline:
dan sinclaircbe23db2017-10-19 14:29:33 -04001360 vp->Set(L"outline");
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001361 break;
1362 case CPDF_FormControl::Toggle:
dan sinclaircbe23db2017-10-19 14:29:33 -04001363 vp->Set(L"toggle");
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001364 break;
1365 }
tsepez4cf55152016-11-02 14:37:54 -07001366 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001367}
1368
dan sinclaircbe23db2017-10-19 14:29:33 -04001369bool Field::set_highlight(CJS_Runtime* pRuntime,
1370 const CJS_PropValue& vp,
1371 WideString* sError) {
1372 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04001373 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001374}
1375
dan sinclaircbe23db2017-10-19 14:29:33 -04001376bool Field::get_line_width(CJS_Runtime* pRuntime,
1377 CJS_PropValue* vp,
1378 WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001379 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1380 if (FieldArray.empty())
1381 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001382
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001383 CPDF_FormField* pFormField = FieldArray[0];
1384 ASSERT(pFormField);
dan sinclaircbe23db2017-10-19 14:29:33 -04001385
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001386 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1387 if (!pFormControl)
1388 return false;
1389
1390 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1391 if (!pFormField->CountControls())
1392 return false;
1393
1394 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
1395 if (!pWidget)
1396 return false;
1397
dan sinclaircbe23db2017-10-19 14:29:33 -04001398 vp->Set(pWidget->GetBorderWidth());
1399 return true;
1400}
1401
1402bool Field::set_line_width(CJS_Runtime* pRuntime,
1403 const CJS_PropValue& vp,
1404 WideString* sError) {
1405 if (!m_bCanSet)
1406 return false;
1407
1408 if (m_bDelay) {
1409 AddDelay_Int(FP_LINEWIDTH, vp.ToInt());
1410 } else {
1411 Field::SetLineWidth(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
1412 vp.ToInt());
1413 }
tsepez4cf55152016-11-02 14:37:54 -07001414 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001415}
1416
dsinclair3a7741a2016-10-11 10:39:49 -07001417void Field::SetLineWidth(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04001418 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001419 int nControlIndex,
1420 int number) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001421 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001422 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07001423 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -08001424 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001425 if (nControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -07001426 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001427 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1428 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08001429 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001430
dsinclairc5267c52016-11-04 15:35:12 -07001431 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001432 if (number != pWidget->GetBorderWidth()) {
1433 pWidget->SetBorderWidth(number);
tsepez4cf55152016-11-02 14:37:54 -07001434 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001435 }
1436 }
1437 }
1438 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -07001439 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001440 } else {
1441 if (nControlIndex >= pFormField->CountControls())
1442 return;
1443 if (CPDF_FormControl* pFormControl =
1444 pFormField->GetControl(nControlIndex)) {
dsinclairc5267c52016-11-04 15:35:12 -07001445 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001446 if (number != pWidget->GetBorderWidth()) {
1447 pWidget->SetBorderWidth(number);
tsepez4cf55152016-11-02 14:37:54 -07001448 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001449 }
1450 }
1451 }
1452 }
1453 }
1454}
1455
dan sinclaircbe23db2017-10-19 14:29:33 -04001456bool Field::get_multiline(CJS_Runtime* pRuntime,
1457 CJS_PropValue* vp,
1458 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001459 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001460
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001461 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1462 if (FieldArray.empty())
1463 return false;
1464
1465 CPDF_FormField* pFormField = FieldArray[0];
1466 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1467 return false;
1468
dan sinclaircbe23db2017-10-19 14:29:33 -04001469 vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE));
tsepez4cf55152016-11-02 14:37:54 -07001470 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001471}
1472
dan sinclaircbe23db2017-10-19 14:29:33 -04001473bool Field::set_multiline(CJS_Runtime* pRuntime,
1474 const CJS_PropValue& vp,
1475 WideString* sError) {
1476 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04001477 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001478}
1479
dan sinclaircbe23db2017-10-19 14:29:33 -04001480bool Field::get_multiple_selection(CJS_Runtime* pRuntime,
1481 CJS_PropValue* vp,
1482 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001483 ASSERT(m_pFormFillEnv);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001484 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1485 if (FieldArray.empty())
1486 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001487
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001488 CPDF_FormField* pFormField = FieldArray[0];
1489 if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
1490 return false;
1491
dan sinclaircbe23db2017-10-19 14:29:33 -04001492 vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT));
1493 return true;
1494}
1495
1496bool Field::set_multiple_selection(CJS_Runtime* pRuntime,
1497 const CJS_PropValue& vp,
1498 WideString* sError) {
1499 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04001500 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001501}
1502
dan sinclaircbe23db2017-10-19 14:29:33 -04001503bool Field::get_name(CJS_Runtime* pRuntime,
1504 CJS_PropValue* vp,
1505 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001506 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1507 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001508 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001509
dan sinclaircbe23db2017-10-19 14:29:33 -04001510 vp->Set(m_FieldName);
tsepez4cf55152016-11-02 14:37:54 -07001511 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001512}
1513
dan sinclaircbe23db2017-10-19 14:29:33 -04001514bool Field::set_name(CJS_Runtime* pRuntime,
1515 const CJS_PropValue& vp,
1516 WideString* sError) {
1517 return false;
1518}
Tom Sepez67fd5df2015-10-08 12:24:19 -07001519
dan sinclaircbe23db2017-10-19 14:29:33 -04001520bool Field::get_num_items(CJS_Runtime* pRuntime,
1521 CJS_PropValue* vp,
1522 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001523 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1524 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001525 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001526
Lei Zhangd88a3642015-11-10 09:38:57 -08001527 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001528 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001529 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
tsepez4cf55152016-11-02 14:37:54 -07001530 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001531 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001532
dan sinclaircbe23db2017-10-19 14:29:33 -04001533 vp->Set(pFormField->CountOptions());
tsepez4cf55152016-11-02 14:37:54 -07001534 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001535}
1536
dan sinclaircbe23db2017-10-19 14:29:33 -04001537bool Field::set_num_items(CJS_Runtime* pRuntime,
1538 const CJS_PropValue& vp,
1539 WideString* sError) {
1540 return false;
1541}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001542
dan sinclaircbe23db2017-10-19 14:29:33 -04001543bool Field::get_page(CJS_Runtime* pRuntime,
1544 CJS_PropValue* vp,
1545 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001546 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1547 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001548 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001549
Lei Zhangd88a3642015-11-10 09:38:57 -08001550 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001551 if (!pFormField)
tsepez4cf55152016-11-02 14:37:54 -07001552 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001553
tsepez8fa82792017-01-11 09:32:33 -08001554 std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
dsinclair7cbe68e2016-10-12 11:56:23 -07001555 m_pFormFillEnv->GetInterForm()->GetWidgets(pFormField, &widgets);
Lei Zhangd88a3642015-11-10 09:38:57 -08001556 if (widgets.empty()) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001557 vp->Set(-1);
tsepez4cf55152016-11-02 14:37:54 -07001558 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001559 }
1560
tsepeze5aff742016-08-08 09:49:42 -07001561 CJS_Array PageArray;
tsepez8fa82792017-01-11 09:32:33 -08001562 int i = 0;
1563 for (const auto& pObserved : widgets) {
1564 if (!pObserved) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001565 *sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
tsepez8fa82792017-01-11 09:32:33 -08001566 return false;
1567 }
1568
Lei Zhang375c2762017-03-10 14:37:14 -08001569 auto* pWidget = static_cast<CPDFSDK_Widget*>(pObserved.Get());
tsepez8fa82792017-01-11 09:32:33 -08001570 CPDFSDK_PageView* pPageView = pWidget->GetPageView();
Lei Zhangd88a3642015-11-10 09:38:57 -08001571 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -07001572 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001573
1574 PageArray.SetElement(
tsepezb4694242016-08-15 16:44:55 -07001575 pRuntime, i, CJS_Value(pRuntime, (int32_t)pPageView->GetPageIndex()));
tsepez8fa82792017-01-11 09:32:33 -08001576 ++i;
Lei Zhangd88a3642015-11-10 09:38:57 -08001577 }
1578
dan sinclaircbe23db2017-10-19 14:29:33 -04001579 vp->Set(PageArray);
tsepez4cf55152016-11-02 14:37:54 -07001580 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001581}
1582
dan sinclaircbe23db2017-10-19 14:29:33 -04001583bool Field::set_page(CJS_Runtime* pRuntime,
1584 const CJS_PropValue& vp,
1585 WideString* sError) {
1586 *sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
1587 return false;
1588}
1589
1590bool Field::get_password(CJS_Runtime* pRuntime,
1591 CJS_PropValue* vp,
1592 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001593 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001594
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001595 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1596 if (FieldArray.empty())
1597 return false;
1598
1599 CPDF_FormField* pFormField = FieldArray[0];
1600 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1601 return false;
1602
dan sinclaircbe23db2017-10-19 14:29:33 -04001603 vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD));
tsepez4cf55152016-11-02 14:37:54 -07001604 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001605}
1606
dan sinclaircbe23db2017-10-19 14:29:33 -04001607bool Field::set_password(CJS_Runtime* pRuntime,
1608 const CJS_PropValue& vp,
1609 WideString* sError) {
1610 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04001611 return m_bCanSet;
1612}
dan sinclaircbe23db2017-10-19 14:29:33 -04001613
dan sinclair646634b2017-10-19 14:30:28 -04001614bool Field::get_print(CJS_Runtime* pRuntime,
1615 CJS_PropValue* vp,
1616 WideString* sError) {
1617 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1618 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1619 if (FieldArray.empty())
1620 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -04001621
dan sinclair646634b2017-10-19 14:30:28 -04001622 CPDF_FormField* pFormField = FieldArray[0];
1623 CPDFSDK_Widget* pWidget =
1624 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1625 if (!pWidget)
1626 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -04001627
dan sinclair646634b2017-10-19 14:30:28 -04001628 vp->Set(!!(pWidget->GetFlags() & ANNOTFLAG_PRINT));
1629 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001630}
1631
dan sinclaircbe23db2017-10-19 14:29:33 -04001632bool Field::set_print(CJS_Runtime* pRuntime,
1633 const CJS_PropValue& vp,
1634 WideString* sError) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001635 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001636 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1637 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001638 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001639
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001640 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001641 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001642
Lei Zhangd88a3642015-11-10 09:38:57 -08001643 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001644 if (m_nFormControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -07001645 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001646 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001647 if (CPDFSDK_Widget* pWidget =
dsinclairc5267c52016-11-04 15:35:12 -07001648 pInterForm->GetWidget(pFormField->GetControl(i))) {
tsepezc3255f52016-03-25 14:52:27 -07001649 uint32_t dwFlags = pWidget->GetFlags();
dan sinclaircbe23db2017-10-19 14:29:33 -04001650 if (vp.ToBool())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001651 dwFlags |= ANNOTFLAG_PRINT;
1652 else
1653 dwFlags &= ~ANNOTFLAG_PRINT;
1654
1655 if (dwFlags != pWidget->GetFlags()) {
1656 pWidget->SetFlags(dwFlags);
tsepez4cf55152016-11-02 14:37:54 -07001657 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001658 }
1659 }
1660 }
1661
1662 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -07001663 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001664
dan sinclaircbe23db2017-10-19 14:29:33 -04001665 continue;
1666 }
1667
1668 if (m_nFormControlIndex >= pFormField->CountControls())
1669 return false;
1670 if (CPDF_FormControl* pFormControl =
1671 pFormField->GetControl(m_nFormControlIndex)) {
1672 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1673 uint32_t dwFlags = pWidget->GetFlags();
1674 if (vp.ToBool())
1675 dwFlags |= ANNOTFLAG_PRINT;
1676 else
1677 dwFlags &= ~ANNOTFLAG_PRINT;
1678
1679 if (dwFlags != pWidget->GetFlags()) {
1680 pWidget->SetFlags(dwFlags);
1681 UpdateFormControl(m_pFormFillEnv.Get(),
1682 pFormField->GetControl(m_nFormControlIndex), true,
1683 false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001684 }
1685 }
1686 }
1687 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001688 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001689}
1690
dan sinclaircbe23db2017-10-19 14:29:33 -04001691bool Field::get_radios_in_unison(CJS_Runtime* pRuntime,
1692 CJS_PropValue* vp,
1693 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001694 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1695 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001696 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001697
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001698 CPDF_FormField* pFormField = FieldArray[0];
1699 if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
1700 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001701
dan sinclaircbe23db2017-10-19 14:29:33 -04001702 vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON));
tsepez4cf55152016-11-02 14:37:54 -07001703 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001704}
1705
dan sinclaircbe23db2017-10-19 14:29:33 -04001706bool Field::set_radios_in_unison(CJS_Runtime* pRuntime,
1707 const CJS_PropValue& vp,
1708 WideString* sError) {
1709 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1710 if (FieldArray.empty())
1711 return false;
1712 return m_bCanSet;
1713}
1714
1715bool Field::get_readonly(CJS_Runtime* pRuntime,
1716 CJS_PropValue* vp,
1717 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001718 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1719 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001720 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001721
dan sinclaircbe23db2017-10-19 14:29:33 -04001722 vp->Set(!!(FieldArray[0]->GetFieldFlags() & FIELDFLAG_READONLY));
tsepez4cf55152016-11-02 14:37:54 -07001723 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001724}
1725
dan sinclaircbe23db2017-10-19 14:29:33 -04001726bool Field::set_readonly(CJS_Runtime* pRuntime,
1727 const CJS_PropValue& vp,
1728 WideString* sError) {
1729 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1730 if (FieldArray.empty())
1731 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -04001732 return m_bCanSet;
1733}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001734
dan sinclaircbe23db2017-10-19 14:29:33 -04001735bool Field::get_rect(CJS_Runtime* pRuntime,
1736 CJS_PropValue* vp,
1737 WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001738 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1739 if (FieldArray.empty())
1740 return false;
1741
1742 CPDF_FormField* pFormField = FieldArray[0];
1743 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1744 CPDFSDK_Widget* pWidget =
1745 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1746 if (!pWidget)
1747 return false;
1748
1749 CFX_FloatRect crRect = pWidget->GetRect();
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001750 CJS_Array rcArray;
dan sinclaircbe23db2017-10-19 14:29:33 -04001751 rcArray.SetElement(pRuntime, 0,
1752 CJS_Value(pRuntime, static_cast<int32_t>(crRect.left)));
1753 rcArray.SetElement(pRuntime, 1,
1754 CJS_Value(pRuntime, static_cast<int32_t>(crRect.top)));
1755 rcArray.SetElement(pRuntime, 2,
1756 CJS_Value(pRuntime, static_cast<int32_t>(crRect.right)));
1757 rcArray.SetElement(pRuntime, 3,
1758 CJS_Value(pRuntime, static_cast<int32_t>(crRect.bottom)));
1759 vp->Set(rcArray);
1760 return true;
1761}
1762
1763bool Field::set_rect(CJS_Runtime* pRuntime,
1764 const CJS_PropValue& vp,
1765 WideString* sError) {
1766 if (!m_bCanSet)
1767 return false;
1768 if (!vp.GetJSValue()->IsArrayObject())
1769 return false;
1770
dan sinclaircbe23db2017-10-19 14:29:33 -04001771 CJS_Array rcArray = vp.ToArray();
Dan Sinclairc9708952017-10-23 09:40:59 -04001772 CJS_Value Upper_Leftx = rcArray.GetElement(pRuntime, 0);
1773 CJS_Value Upper_Lefty = rcArray.GetElement(pRuntime, 1);
1774 CJS_Value Lower_Rightx = rcArray.GetElement(pRuntime, 2);
1775 CJS_Value Lower_Righty = rcArray.GetElement(pRuntime, 3);
dan sinclaircbe23db2017-10-19 14:29:33 -04001776
1777 float pArray[4];
1778 pArray[0] = static_cast<float>(Upper_Leftx.ToInt(pRuntime));
1779 pArray[1] = static_cast<float>(Lower_Righty.ToInt(pRuntime));
1780 pArray[2] = static_cast<float>(Lower_Rightx.ToInt(pRuntime));
1781 pArray[3] = static_cast<float>(Upper_Lefty.ToInt(pRuntime));
1782
1783 CFX_FloatRect crRect(pArray);
1784 if (m_bDelay) {
1785 AddDelay_Rect(FP_RECT, crRect);
1786 } else {
1787 Field::SetRect(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
1788 crRect);
1789 }
tsepez4cf55152016-11-02 14:37:54 -07001790 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001791}
1792
dsinclair3a7741a2016-10-11 10:39:49 -07001793void Field::SetRect(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04001794 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001795 int nControlIndex,
Tom Sepez281a9ea2016-02-26 14:24:28 -08001796 const CFX_FloatRect& rect) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001797 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001798 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07001799 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -08001800 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001801 if (nControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -07001802 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001803 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001804 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08001805 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001806
dsinclairc5267c52016-11-04 15:35:12 -07001807 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08001808 CFX_FloatRect crRect = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001809
1810 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001811 crRect.Intersect(pPDFPage->GetPageBBox());
1812
1813 if (!crRect.IsEmpty()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08001814 CFX_FloatRect rcOld = pWidget->GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001815 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
1816 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
1817 pWidget->SetRect(crRect);
tsepez4cf55152016-11-02 14:37:54 -07001818 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001819 }
1820 }
1821 }
1822 }
1823
1824 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -07001825 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001826
dan sinclaircbe23db2017-10-19 14:29:33 -04001827 continue;
1828 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001829
dan sinclaircbe23db2017-10-19 14:29:33 -04001830 if (nControlIndex >= pFormField->CountControls())
1831 return;
1832 if (CPDF_FormControl* pFormControl =
1833 pFormField->GetControl(nControlIndex)) {
1834 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1835 CFX_FloatRect crRect = rect;
1836
1837 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
1838 crRect.Intersect(pPDFPage->GetPageBBox());
1839
1840 if (!crRect.IsEmpty()) {
1841 CFX_FloatRect rcOld = pWidget->GetRect();
1842 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
1843 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
1844 pWidget->SetRect(crRect);
1845 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001846 }
1847 }
1848 }
1849 }
1850 }
1851}
1852
dan sinclaircbe23db2017-10-19 14:29:33 -04001853bool Field::get_required(CJS_Runtime* pRuntime,
1854 CJS_PropValue* vp,
1855 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001856 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1857 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001858 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001859
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001860 CPDF_FormField* pFormField = FieldArray[0];
1861 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
1862 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001863
dan sinclaircbe23db2017-10-19 14:29:33 -04001864 vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED));
tsepez4cf55152016-11-02 14:37:54 -07001865 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001866}
1867
dan sinclaircbe23db2017-10-19 14:29:33 -04001868bool Field::set_required(CJS_Runtime* pRuntime,
1869 const CJS_PropValue& vp,
1870 WideString* sError) {
1871 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1872 if (FieldArray.empty())
1873 return false;
1874
1875 return m_bCanSet;
1876}
1877
1878bool Field::get_rich_text(CJS_Runtime* pRuntime,
1879 CJS_PropValue* vp,
1880 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001881 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001882
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001883 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1884 if (FieldArray.empty())
1885 return false;
1886
1887 CPDF_FormField* pFormField = FieldArray[0];
1888 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1889 return false;
1890
dan sinclaircbe23db2017-10-19 14:29:33 -04001891 vp->Set(!!(pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT));
tsepez4cf55152016-11-02 14:37:54 -07001892 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001893}
1894
dan sinclaircbe23db2017-10-19 14:29:33 -04001895bool Field::set_rich_text(CJS_Runtime* pRuntime,
1896 const CJS_PropValue& vp,
1897 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001898 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04001899 return m_bCanSet;
dan sinclaircbe23db2017-10-19 14:29:33 -04001900}
1901
1902bool Field::get_rich_value(CJS_Runtime* pRuntime,
1903 CJS_PropValue* vp,
1904 WideString* sError) {
1905 return true;
1906}
1907
1908bool Field::set_rich_value(CJS_Runtime* pRuntime,
1909 const CJS_PropValue& vp,
1910 WideString* sError) {
1911 return true;
1912}
1913
1914bool Field::get_rotation(CJS_Runtime* pRuntime,
1915 CJS_PropValue* vp,
1916 WideString* sError) {
1917 ASSERT(m_pFormFillEnv);
1918
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001919 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1920 if (FieldArray.empty())
1921 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001922
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001923 CPDF_FormField* pFormField = FieldArray[0];
1924 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1925 if (!pFormControl)
1926 return false;
1927
dan sinclaircbe23db2017-10-19 14:29:33 -04001928 vp->Set(pFormControl->GetRotation());
1929 return true;
1930}
1931
1932bool Field::set_rotation(CJS_Runtime* pRuntime,
1933 const CJS_PropValue& vp,
1934 WideString* sError) {
dan sinclaircbe23db2017-10-19 14:29:33 -04001935 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04001936 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001937}
1938
dan sinclaircbe23db2017-10-19 14:29:33 -04001939bool Field::get_stroke_color(CJS_Runtime* pRuntime,
1940 CJS_PropValue* vp,
1941 WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001942 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1943 if (FieldArray.empty())
1944 return false;
1945
1946 CPDF_FormField* pFormField = FieldArray[0];
1947 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1948 if (!pFormControl)
1949 return false;
1950
1951 int iColorType;
1952 pFormControl->GetBorderColor(iColorType);
1953
Dan Sinclair7f55a542017-07-13 14:17:10 -04001954 CFX_Color color;
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001955 if (iColorType == CFX_Color::kTransparent) {
1956 color = CFX_Color(CFX_Color::kTransparent);
1957 } else if (iColorType == CFX_Color::kGray) {
1958 color =
1959 CFX_Color(CFX_Color::kGray, pFormControl->GetOriginalBorderColor(0));
1960 } else if (iColorType == CFX_Color::kRGB) {
1961 color = CFX_Color(CFX_Color::kRGB, pFormControl->GetOriginalBorderColor(0),
Dan Sinclair7f55a542017-07-13 14:17:10 -04001962 pFormControl->GetOriginalBorderColor(1),
1963 pFormControl->GetOriginalBorderColor(2));
Dan Sinclair8e7f9322017-10-16 11:35:42 -04001964 } else if (iColorType == CFX_Color::kCMYK) {
1965 color = CFX_Color(CFX_Color::kCMYK, pFormControl->GetOriginalBorderColor(0),
Dan Sinclair7f55a542017-07-13 14:17:10 -04001966 pFormControl->GetOriginalBorderColor(1),
1967 pFormControl->GetOriginalBorderColor(2),
1968 pFormControl->GetOriginalBorderColor(3));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001969 } else {
1970 return false;
1971 }
1972
dan sinclaircbe23db2017-10-19 14:29:33 -04001973 CJS_Array crArray;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001974 color::ConvertPWLColorToArray(pRuntime, color, &crArray);
dan sinclaircbe23db2017-10-19 14:29:33 -04001975 vp->Set(crArray);
1976 return true;
1977}
1978
1979bool Field::set_stroke_color(CJS_Runtime* pRuntime,
1980 const CJS_PropValue& vp,
1981 WideString* sError) {
1982 if (!m_bCanSet)
1983 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -04001984 if (!vp.GetJSValue()->IsArrayObject())
1985 return false;
tsepez4cf55152016-11-02 14:37:54 -07001986 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001987}
1988
dan sinclaircbe23db2017-10-19 14:29:33 -04001989bool Field::get_style(CJS_Runtime* pRuntime,
1990 CJS_PropValue* vp,
1991 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001992 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001993
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001994 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1995 if (FieldArray.empty())
1996 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001997
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001998 CPDF_FormField* pFormField = FieldArray[0];
1999 if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON &&
2000 pFormField->GetFieldType() != FIELDTYPE_CHECKBOX) {
2001 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002002 }
2003
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002004 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2005 if (!pFormControl)
2006 return false;
2007
Ryan Harrison275e2602017-09-18 14:23:18 -04002008 WideString csWCaption = pFormControl->GetNormalCaption();
2009 ByteString csBCaption;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002010
2011 switch (csWCaption[0]) {
2012 case L'l':
2013 csBCaption = "circle";
2014 break;
2015 case L'8':
2016 csBCaption = "cross";
2017 break;
2018 case L'u':
2019 csBCaption = "diamond";
2020 break;
2021 case L'n':
2022 csBCaption = "square";
2023 break;
2024 case L'H':
2025 csBCaption = "star";
2026 break;
2027 default: // L'4'
2028 csBCaption = "check";
2029 break;
2030 }
dan sinclaircbe23db2017-10-19 14:29:33 -04002031 vp->Set(csBCaption);
2032 return true;
2033}
2034
2035bool Field::set_style(CJS_Runtime* pRuntime,
2036 const CJS_PropValue& vp,
2037 WideString* sError) {
2038 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04002039 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002040}
2041
dan sinclaircbe23db2017-10-19 14:29:33 -04002042bool Field::get_submit_name(CJS_Runtime* pRuntime,
2043 CJS_PropValue* vp,
2044 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -07002045 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002046}
2047
dan sinclaircbe23db2017-10-19 14:29:33 -04002048bool Field::set_submit_name(CJS_Runtime* pRuntime,
2049 const CJS_PropValue& vp,
2050 WideString* sError) {
2051 return true;
2052}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002053
dan sinclaircbe23db2017-10-19 14:29:33 -04002054bool Field::get_text_color(CJS_Runtime* pRuntime,
2055 CJS_PropValue* vp,
2056 WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002057 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2058 if (FieldArray.empty())
2059 return false;
2060
2061 CPDF_FormField* pFormField = FieldArray[0];
2062 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2063 if (!pFormControl)
2064 return false;
2065
2066 int iColorType;
2067 FX_ARGB color;
2068 CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
2069 FieldAppearance.GetColor(color, iColorType);
2070
2071 int32_t a;
2072 int32_t r;
2073 int32_t g;
2074 int32_t b;
Nicolas Penaddfc3dc2017-04-20 15:29:25 -04002075 std::tie(a, r, g, b) = ArgbDecode(color);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002076
Dan Sinclair7f55a542017-07-13 14:17:10 -04002077 CFX_Color crRet =
Dan Sinclair8e7f9322017-10-16 11:35:42 -04002078 CFX_Color(CFX_Color::kRGB, r / 255.0f, g / 255.0f, b / 255.0f);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002079
Dan Sinclair8e7f9322017-10-16 11:35:42 -04002080 if (iColorType == CFX_Color::kTransparent)
2081 crRet = CFX_Color(CFX_Color::kTransparent);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002082
dan sinclaircbe23db2017-10-19 14:29:33 -04002083 CJS_Array crArray;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002084 color::ConvertPWLColorToArray(pRuntime, crRet, &crArray);
dan sinclaircbe23db2017-10-19 14:29:33 -04002085 vp->Set(crArray);
2086 return true;
2087}
2088
2089bool Field::set_text_color(CJS_Runtime* pRuntime,
2090 const CJS_PropValue& vp,
2091 WideString* sError) {
2092 if (!m_bCanSet)
2093 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -04002094 if (!vp.GetJSValue()->IsArrayObject())
2095 return false;
tsepez4cf55152016-11-02 14:37:54 -07002096 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002097}
2098
dan sinclaircbe23db2017-10-19 14:29:33 -04002099bool Field::get_text_font(CJS_Runtime* pRuntime,
2100 CJS_PropValue* vp,
2101 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002102 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002103
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002104 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2105 if (FieldArray.empty())
2106 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002107
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002108 CPDF_FormField* pFormField = FieldArray[0];
2109 ASSERT(pFormField);
2110 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2111 if (!pFormControl)
2112 return false;
2113
2114 int nFieldType = pFormField->GetFieldType();
2115 if (nFieldType != FIELDTYPE_PUSHBUTTON && nFieldType != FIELDTYPE_COMBOBOX &&
2116 nFieldType != FIELDTYPE_LISTBOX && nFieldType != FIELDTYPE_TEXTFIELD) {
2117 return false;
2118 }
2119 CPDF_Font* pFont = pFormControl->GetDefaultControlFont();
2120 if (!pFont)
2121 return false;
2122
dan sinclaircbe23db2017-10-19 14:29:33 -04002123 vp->Set(pFont->GetBaseFont());
tsepez4cf55152016-11-02 14:37:54 -07002124 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002125}
2126
dan sinclaircbe23db2017-10-19 14:29:33 -04002127bool Field::set_text_font(CJS_Runtime* pRuntime,
2128 const CJS_PropValue& vp,
2129 WideString* sError) {
2130 ASSERT(m_pFormFillEnv);
2131
dan sinclair646634b2017-10-19 14:30:28 -04002132 if (!m_bCanSet)
2133 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -04002134
dan sinclair646634b2017-10-19 14:30:28 -04002135 ByteString fontName = vp.ToByteString();
2136 return !fontName.IsEmpty();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002137}
2138
dan sinclaircbe23db2017-10-19 14:29:33 -04002139bool Field::get_text_size(CJS_Runtime* pRuntime,
2140 CJS_PropValue* vp,
2141 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002142 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002143
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002144 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2145 if (FieldArray.empty())
2146 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002147
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002148 CPDF_FormField* pFormField = FieldArray[0];
2149 ASSERT(pFormField);
2150 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2151 if (!pFormControl)
2152 return false;
2153
Dan Sinclair05df0752017-03-14 14:43:42 -04002154 float fFontSize;
Tom Sepezc4a2b752017-04-07 13:56:13 -07002155 CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
2156 FieldAppearance.GetFont(&fFontSize);
dan sinclaircbe23db2017-10-19 14:29:33 -04002157 vp->Set(static_cast<int>(fFontSize));
2158 return true;
2159}
2160
2161bool Field::set_text_size(CJS_Runtime* pRuntime,
2162 const CJS_PropValue& vp,
2163 WideString* sError) {
2164 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04002165 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002166}
2167
dan sinclaircbe23db2017-10-19 14:29:33 -04002168bool Field::get_type(CJS_Runtime* pRuntime,
2169 CJS_PropValue* vp,
2170 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002171 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2172 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002173 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002174
Lei Zhangd88a3642015-11-10 09:38:57 -08002175 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002176 switch (pFormField->GetFieldType()) {
2177 case FIELDTYPE_UNKNOWN:
dan sinclaircbe23db2017-10-19 14:29:33 -04002178 vp->Set(L"unknown");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002179 break;
2180 case FIELDTYPE_PUSHBUTTON:
dan sinclaircbe23db2017-10-19 14:29:33 -04002181 vp->Set(L"button");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002182 break;
2183 case FIELDTYPE_CHECKBOX:
dan sinclaircbe23db2017-10-19 14:29:33 -04002184 vp->Set(L"checkbox");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002185 break;
2186 case FIELDTYPE_RADIOBUTTON:
dan sinclaircbe23db2017-10-19 14:29:33 -04002187 vp->Set(L"radiobutton");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002188 break;
2189 case FIELDTYPE_COMBOBOX:
dan sinclaircbe23db2017-10-19 14:29:33 -04002190 vp->Set(L"combobox");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002191 break;
2192 case FIELDTYPE_LISTBOX:
dan sinclaircbe23db2017-10-19 14:29:33 -04002193 vp->Set(L"listbox");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002194 break;
2195 case FIELDTYPE_TEXTFIELD:
dan sinclaircbe23db2017-10-19 14:29:33 -04002196 vp->Set(L"text");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002197 break;
2198 case FIELDTYPE_SIGNATURE:
dan sinclaircbe23db2017-10-19 14:29:33 -04002199 vp->Set(L"signature");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002200 break;
2201 default:
dan sinclaircbe23db2017-10-19 14:29:33 -04002202 vp->Set(L"unknown");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002203 break;
2204 }
tsepez4cf55152016-11-02 14:37:54 -07002205 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002206}
2207
dan sinclaircbe23db2017-10-19 14:29:33 -04002208bool Field::set_type(CJS_Runtime* pRuntime,
2209 const CJS_PropValue& vp,
2210 WideString* sError) {
2211 return false;
2212}
2213
2214bool Field::get_user_name(CJS_Runtime* pRuntime,
2215 CJS_PropValue* vp,
2216 WideString* sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002217 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002218
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002219 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2220 if (FieldArray.empty())
2221 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002222
dan sinclaircbe23db2017-10-19 14:29:33 -04002223 vp->Set(FieldArray[0]->GetAlternateName());
tsepez4cf55152016-11-02 14:37:54 -07002224 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002225}
2226
dan sinclaircbe23db2017-10-19 14:29:33 -04002227bool Field::set_user_name(CJS_Runtime* pRuntime,
2228 const CJS_PropValue& vp,
2229 WideString* sError) {
2230 ASSERT(m_pFormFillEnv);
dan sinclair646634b2017-10-19 14:30:28 -04002231 return m_bCanSet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002232}
2233
dan sinclaircbe23db2017-10-19 14:29:33 -04002234bool Field::get_value(CJS_Runtime* pRuntime,
2235 CJS_PropValue* vp,
2236 WideString* sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002237 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2238 if (FieldArray.empty())
2239 return false;
2240
2241 CPDF_FormField* pFormField = FieldArray[0];
2242 switch (pFormField->GetFieldType()) {
2243 case FIELDTYPE_PUSHBUTTON:
2244 return false;
2245 case FIELDTYPE_COMBOBOX:
dan sinclaircbe23db2017-10-19 14:29:33 -04002246 case FIELDTYPE_TEXTFIELD:
2247 vp->Set(pFormField->GetValue());
2248 break;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002249 case FIELDTYPE_LISTBOX: {
2250 if (pFormField->CountSelectedItems() > 1) {
2251 CJS_Array ValueArray;
2252 CJS_Value ElementValue(pRuntime);
2253 int iIndex;
2254 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
2255 iIndex = pFormField->GetSelectedIndex(i);
2256 ElementValue =
2257 CJS_Value(pRuntime, pFormField->GetOptionValue(iIndex).c_str());
Dan Sinclairc9708952017-10-23 09:40:59 -04002258 if (wcslen(ElementValue.ToWideString(pRuntime).c_str()) == 0) {
tsepezf3dc8c62016-08-10 06:29:29 -07002259 ElementValue =
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002260 CJS_Value(pRuntime, pFormField->GetOptionLabel(iIndex).c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002261 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002262 ValueArray.SetElement(pRuntime, i, ElementValue);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002263 }
dan sinclaircbe23db2017-10-19 14:29:33 -04002264 vp->Set(ValueArray);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002265 } else {
dan sinclaircbe23db2017-10-19 14:29:33 -04002266 vp->Set(pFormField->GetValue());
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002267 }
dan sinclaircbe23db2017-10-19 14:29:33 -04002268 break;
2269 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002270 case FIELDTYPE_CHECKBOX:
2271 case FIELDTYPE_RADIOBUTTON: {
2272 bool bFind = false;
2273 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2274 if (pFormField->GetControl(i)->IsChecked()) {
dan sinclaircbe23db2017-10-19 14:29:33 -04002275 vp->Set(pFormField->GetControl(i)->GetExportValue());
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002276 bFind = true;
2277 break;
2278 }
2279 }
2280 if (!bFind)
dan sinclaircbe23db2017-10-19 14:29:33 -04002281 vp->Set(L"Off");
2282
2283 break;
2284 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002285 default:
dan sinclaircbe23db2017-10-19 14:29:33 -04002286 vp->Set(pFormField->GetValue());
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002287 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002288 }
dan sinclaircbe23db2017-10-19 14:29:33 -04002289 vp->GetJSValue()->MaybeCoerceToNumber(pRuntime);
2290 return true;
2291}
2292
2293bool Field::set_value(CJS_Runtime* pRuntime,
2294 const CJS_PropValue& vp,
2295 WideString* sError) {
2296 if (!m_bCanSet)
2297 return false;
2298
2299 std::vector<WideString> strArray;
2300 if (vp.GetJSValue()->IsArrayObject()) {
2301 CJS_Array ValueArray = vp.ToArray();
2302 for (int i = 0, sz = ValueArray.GetLength(pRuntime); i < sz; i++) {
Dan Sinclairc9708952017-10-23 09:40:59 -04002303 CJS_Value ElementValue = ValueArray.GetElement(pRuntime, i);
2304 strArray.push_back(ElementValue.ToWideString(pRuntime));
dan sinclaircbe23db2017-10-19 14:29:33 -04002305 }
2306 } else {
2307 strArray.push_back(vp.ToWideString());
2308 }
2309
2310 if (m_bDelay) {
2311 AddDelay_WideStringArray(FP_VALUE, strArray);
2312 } else {
2313 Field::SetValue(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
2314 strArray);
2315 }
tsepez4cf55152016-11-02 14:37:54 -07002316 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002317}
2318
dsinclair3a7741a2016-10-11 10:39:49 -07002319void Field::SetValue(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04002320 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002321 int nControlIndex,
Ryan Harrison275e2602017-09-18 14:23:18 -04002322 const std::vector<WideString>& strArray) {
dsinclair3a7741a2016-10-11 10:39:49 -07002323 ASSERT(pFormFillEnv);
tsepez41a53ad2016-03-28 16:59:30 -07002324 if (strArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002325 return;
2326
Lei Zhangd88a3642015-11-10 09:38:57 -08002327 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07002328 GetFormFields(pFormFillEnv, swFieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002329
Lei Zhangd88a3642015-11-10 09:38:57 -08002330 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002331 if (pFormField->GetFullName().Compare(swFieldName) != 0)
2332 continue;
2333
2334 switch (pFormField->GetFieldType()) {
2335 case FIELDTYPE_TEXTFIELD:
2336 case FIELDTYPE_COMBOBOX:
tsepez41a53ad2016-03-28 16:59:30 -07002337 if (pFormField->GetValue() != strArray[0]) {
tsepez4cf55152016-11-02 14:37:54 -07002338 pFormField->SetValue(strArray[0], true);
2339 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002340 }
2341 break;
tsepez41a53ad2016-03-28 16:59:30 -07002342 case FIELDTYPE_CHECKBOX:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002343 case FIELDTYPE_RADIOBUTTON: {
tsepez41a53ad2016-03-28 16:59:30 -07002344 if (pFormField->GetValue() != strArray[0]) {
tsepez4cf55152016-11-02 14:37:54 -07002345 pFormField->SetValue(strArray[0], true);
2346 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002347 }
2348 } break;
2349 case FIELDTYPE_LISTBOX: {
tsepez4cf55152016-11-02 14:37:54 -07002350 bool bModified = false;
tsepez41a53ad2016-03-28 16:59:30 -07002351 for (const auto& str : strArray) {
2352 if (!pFormField->IsItemSelected(pFormField->FindOption(str))) {
tsepez4cf55152016-11-02 14:37:54 -07002353 bModified = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002354 break;
2355 }
2356 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002357 if (bModified) {
tsepez4cf55152016-11-02 14:37:54 -07002358 pFormField->ClearSelection(true);
tsepez41a53ad2016-03-28 16:59:30 -07002359 for (const auto& str : strArray) {
2360 int index = pFormField->FindOption(str);
2361 if (!pFormField->IsItemSelected(index))
tsepez4cf55152016-11-02 14:37:54 -07002362 pFormField->SetItemSelection(index, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002363 }
tsepez4cf55152016-11-02 14:37:54 -07002364 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002365 }
2366 } break;
2367 default:
2368 break;
2369 }
2370 }
2371}
2372
dan sinclaircbe23db2017-10-19 14:29:33 -04002373bool Field::get_value_as_string(CJS_Runtime* pRuntime,
2374 CJS_PropValue* vp,
2375 WideString* sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002376 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2377 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002378 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002379
Lei Zhangd88a3642015-11-10 09:38:57 -08002380 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002381 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002382 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002383
2384 if (pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) {
2385 if (!pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002386 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002387
dan sinclaircbe23db2017-10-19 14:29:33 -04002388 vp->Set(pFormField->GetControl(0)->IsChecked() ? L"Yes" : L"Off");
2389 return true;
2390 }
2391
2392 if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON &&
2393 !(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002394 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2395 if (pFormField->GetControl(i)->IsChecked()) {
dan sinclaircbe23db2017-10-19 14:29:33 -04002396 vp->Set(pFormField->GetControl(i)->GetExportValue().c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002397 break;
Lei Zhangd88a3642015-11-10 09:38:57 -08002398 } else {
dan sinclaircbe23db2017-10-19 14:29:33 -04002399 vp->Set(L"Off");
Lei Zhangd88a3642015-11-10 09:38:57 -08002400 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002401 }
dan sinclaircbe23db2017-10-19 14:29:33 -04002402 return true;
2403 }
2404
2405 if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX &&
2406 (pFormField->CountSelectedItems() > 1)) {
2407 vp->Set(L"");
Lei Zhangd88a3642015-11-10 09:38:57 -08002408 } else {
dan sinclaircbe23db2017-10-19 14:29:33 -04002409 vp->Set(pFormField->GetValue().c_str());
Lei Zhangd88a3642015-11-10 09:38:57 -08002410 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002411
tsepez4cf55152016-11-02 14:37:54 -07002412 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002413}
2414
dan sinclaircbe23db2017-10-19 14:29:33 -04002415bool Field::set_value_as_string(CJS_Runtime* pRuntime,
2416 const CJS_PropValue& vp,
2417 WideString* sError) {
2418 return false;
2419}
2420
Tom Sepezb1670b52017-02-16 17:01:00 -08002421bool Field::browseForFileToSubmit(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002422 const std::vector<CJS_Value>& params,
2423 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002424 WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002425 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2426 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002427 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002428
Lei Zhangd88a3642015-11-10 09:38:57 -08002429 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002430 if ((pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) &&
2431 (pFormField->GetFieldType() == FIELDTYPE_TEXTFIELD)) {
Ryan Harrison275e2602017-09-18 14:23:18 -04002432 WideString wsFileName = m_pFormFillEnv->JS_fieldBrowse();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002433 if (!wsFileName.IsEmpty()) {
2434 pFormField->SetValue(wsFileName);
tsepez4cf55152016-11-02 14:37:54 -07002435 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002436 }
tsepez4cf55152016-11-02 14:37:54 -07002437 return true;
Lei Zhangd88a3642015-11-10 09:38:57 -08002438 }
tsepez4cf55152016-11-02 14:37:54 -07002439 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002440}
2441
Tom Sepezb1670b52017-02-16 17:01:00 -08002442bool Field::buttonGetCaption(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002443 const std::vector<CJS_Value>& params,
2444 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002445 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002446 int nface = 0;
2447 int iSize = params.size();
2448 if (iSize >= 1)
tsepezb4694242016-08-15 16:44:55 -07002449 nface = params[0].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002450
Lei Zhangd88a3642015-11-10 09:38:57 -08002451 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2452 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002453 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002454
Lei Zhangd88a3642015-11-10 09:38:57 -08002455 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002456 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002457 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002458
2459 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2460 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -07002461 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002462
2463 if (nface == 0)
tsepezf3dc8c62016-08-10 06:29:29 -07002464 vRet = CJS_Value(pRuntime, pFormControl->GetNormalCaption().c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002465 else if (nface == 1)
tsepezf3dc8c62016-08-10 06:29:29 -07002466 vRet = CJS_Value(pRuntime, pFormControl->GetDownCaption().c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002467 else if (nface == 2)
tsepezf3dc8c62016-08-10 06:29:29 -07002468 vRet = CJS_Value(pRuntime, pFormControl->GetRolloverCaption().c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002469 else
tsepez4cf55152016-11-02 14:37:54 -07002470 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002471
tsepez4cf55152016-11-02 14:37:54 -07002472 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002473}
2474
Tom Sepezb1670b52017-02-16 17:01:00 -08002475bool Field::buttonGetIcon(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002476 const std::vector<CJS_Value>& params,
2477 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002478 WideString& sError) {
Tom Sepez40e0a812017-02-23 13:07:36 -08002479 if (params.size() >= 1) {
2480 int nFace = params[0].ToInt(pRuntime);
2481 if (nFace < 0 || nFace > 2)
2482 return false;
2483 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002484
Lei Zhangd88a3642015-11-10 09:38:57 -08002485 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2486 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002487 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002488
Lei Zhangd88a3642015-11-10 09:38:57 -08002489 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002490 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002491 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002492
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002493 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2494 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -07002495 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002496
tsepezb4694242016-08-15 16:44:55 -07002497 v8::Local<v8::Object> pObj =
2498 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID);
Tom Sepezc5a14722017-02-24 15:31:12 -08002499 if (pObj.IsEmpty())
2500 return false;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002501
tsepezb4694242016-08-15 16:44:55 -07002502 CJS_Icon* pJS_Icon = static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj));
tsepezf3dc8c62016-08-10 06:29:29 -07002503 vRet = CJS_Value(pRuntime, pJS_Icon);
tsepez4cf55152016-11-02 14:37:54 -07002504 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002505}
2506
Tom Sepezb1670b52017-02-16 17:01:00 -08002507bool Field::buttonImportIcon(CJS_Runtime* pRuntime,
Lei Zhang945fdb72015-11-11 10:18:16 -08002508 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002509 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002510 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002511 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002512}
2513
Tom Sepezb1670b52017-02-16 17:01:00 -08002514bool Field::buttonSetCaption(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002515 const std::vector<CJS_Value>& params,
2516 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002517 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002518 return false;
2519}
2520
Tom Sepezb1670b52017-02-16 17:01:00 -08002521bool Field::buttonSetIcon(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002522 const std::vector<CJS_Value>& params,
2523 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002524 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002525 return false;
2526}
2527
Tom Sepezb1670b52017-02-16 17:01:00 -08002528bool Field::checkThisBox(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002529 const std::vector<CJS_Value>& params,
2530 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002531 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002532 int iSize = params.size();
2533 if (iSize < 1)
tsepez4cf55152016-11-02 14:37:54 -07002534 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002535
tsepezf3dc8c62016-08-10 06:29:29 -07002536 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002537 return false;
tsepezf3dc8c62016-08-10 06:29:29 -07002538
tsepezb4694242016-08-15 16:44:55 -07002539 int nWidget = params[0].ToInt(pRuntime);
Wei Li97da9762016-03-11 17:00:48 -08002540 bool bCheckit = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002541 if (iSize >= 2)
tsepezb4694242016-08-15 16:44:55 -07002542 bCheckit = params[1].ToBool(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002543
Lei Zhangd88a3642015-11-10 09:38:57 -08002544 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2545 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002546 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002547
Lei Zhangd88a3642015-11-10 09:38:57 -08002548 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002549 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
2550 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002551 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002552 if (nWidget < 0 || nWidget >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002553 return false;
Wei Li97da9762016-03-11 17:00:48 -08002554 // TODO(weili): Check whether anything special needed for radio button,
2555 // otherwise merge these branches.
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002556 if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)
Wei Li97da9762016-03-11 17:00:48 -08002557 pFormField->CheckControl(nWidget, bCheckit, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002558 else
Wei Li97da9762016-03-11 17:00:48 -08002559 pFormField->CheckControl(nWidget, bCheckit, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002560
tsepez4cf55152016-11-02 14:37:54 -07002561 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true);
2562 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002563}
2564
Tom Sepezb1670b52017-02-16 17:01:00 -08002565bool Field::clearItems(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002566 const std::vector<CJS_Value>& params,
2567 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002568 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002569 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002570}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002571
Tom Sepezb1670b52017-02-16 17:01:00 -08002572bool Field::defaultIsChecked(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002573 const std::vector<CJS_Value>& params,
2574 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002575 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002576 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002577 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002578
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002579 int iSize = params.size();
2580 if (iSize < 1)
tsepez4cf55152016-11-02 14:37:54 -07002581 return false;
Tom Sepezf4ef3f92015-04-23 11:31:31 -07002582
tsepezb4694242016-08-15 16:44:55 -07002583 int nWidget = params[0].ToInt(pRuntime);
Lei Zhangd88a3642015-11-10 09:38:57 -08002584 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2585 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002586 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002587
Lei Zhangd88a3642015-11-10 09:38:57 -08002588 CPDF_FormField* pFormField = FieldArray[0];
tsepezf3dc8c62016-08-10 06:29:29 -07002589 if (nWidget < 0 || nWidget >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002590 return false;
tsepezf3dc8c62016-08-10 06:29:29 -07002591
2592 vRet = CJS_Value(pRuntime,
2593 pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
2594 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002595
tsepez4cf55152016-11-02 14:37:54 -07002596 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002597}
2598
Tom Sepezb1670b52017-02-16 17:01:00 -08002599bool Field::deleteItemAt(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002600 const std::vector<CJS_Value>& params,
2601 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002602 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002603 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002604}
2605
Tom Sepezb1670b52017-02-16 17:01:00 -08002606bool Field::getArray(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002607 const std::vector<CJS_Value>& params,
2608 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002609 WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002610 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2611 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002612 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002613
Ryan Harrison275e2602017-09-18 14:23:18 -04002614 std::vector<std::unique_ptr<WideString>> swSort;
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002615 for (CPDF_FormField* pFormField : FieldArray) {
Ryan Harrison275e2602017-09-18 14:23:18 -04002616 swSort.push_back(
2617 std::unique_ptr<WideString>(new WideString(pFormField->GetFullName())));
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002618 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002619
Ryan Harrison275e2602017-09-18 14:23:18 -04002620 std::sort(swSort.begin(), swSort.end(),
2621 [](const std::unique_ptr<WideString>& p1,
2622 const std::unique_ptr<WideString>& p2) { return *p1 < *p2; });
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002623
tsepeze5aff742016-08-08 09:49:42 -07002624 CJS_Array FormFieldArray;
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002625
2626 int j = 0;
2627 for (const auto& pStr : swSort) {
tsepezb4694242016-08-15 16:44:55 -07002628 v8::Local<v8::Object> pObj =
2629 pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID);
Tom Sepezc5a14722017-02-24 15:31:12 -08002630 if (pObj.IsEmpty())
2631 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002632
Tom Sepezd5a0e952015-09-17 15:40:06 -07002633 CJS_Field* pJSField =
tsepezb4694242016-08-15 16:44:55 -07002634 static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pObj));
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002635 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002636 pField->AttachField(m_pJSDoc, *pStr);
tsepezb4694242016-08-15 16:44:55 -07002637 FormFieldArray.SetElement(pRuntime, j++, CJS_Value(pRuntime, pJSField));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002638 }
2639
tsepeze5aff742016-08-08 09:49:42 -07002640 vRet = CJS_Value(pRuntime, FormFieldArray);
tsepez4cf55152016-11-02 14:37:54 -07002641 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002642}
2643
Tom Sepezb1670b52017-02-16 17:01:00 -08002644bool Field::getItemAt(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002645 const std::vector<CJS_Value>& params,
2646 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002647 WideString& sError) {
tsepezf3dc8c62016-08-10 06:29:29 -07002648 int iSize = params.size();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002649 int nIdx = -1;
2650 if (iSize >= 1)
tsepezb4694242016-08-15 16:44:55 -07002651 nIdx = params[0].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002652
tsepez4cf55152016-11-02 14:37:54 -07002653 bool bExport = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002654 if (iSize >= 2)
tsepezb4694242016-08-15 16:44:55 -07002655 bExport = params[1].ToBool(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002656
Lei Zhangd88a3642015-11-10 09:38:57 -08002657 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2658 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002659 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002660
Lei Zhangd88a3642015-11-10 09:38:57 -08002661 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002662 if ((pFormField->GetFieldType() == FIELDTYPE_LISTBOX) ||
2663 (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX)) {
2664 if (nIdx == -1 || nIdx > pFormField->CountOptions())
2665 nIdx = pFormField->CountOptions() - 1;
2666 if (bExport) {
Ryan Harrison275e2602017-09-18 14:23:18 -04002667 WideString strval = pFormField->GetOptionValue(nIdx);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002668 if (strval.IsEmpty())
tsepezf3dc8c62016-08-10 06:29:29 -07002669 vRet = CJS_Value(pRuntime, pFormField->GetOptionLabel(nIdx).c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002670 else
tsepezf3dc8c62016-08-10 06:29:29 -07002671 vRet = CJS_Value(pRuntime, strval.c_str());
Lei Zhangd88a3642015-11-10 09:38:57 -08002672 } else {
tsepezf3dc8c62016-08-10 06:29:29 -07002673 vRet = CJS_Value(pRuntime, pFormField->GetOptionLabel(nIdx).c_str());
Lei Zhangd88a3642015-11-10 09:38:57 -08002674 }
2675 } else {
tsepez4cf55152016-11-02 14:37:54 -07002676 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08002677 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002678
tsepez4cf55152016-11-02 14:37:54 -07002679 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002680}
2681
Tom Sepezb1670b52017-02-16 17:01:00 -08002682bool Field::getLock(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002683 const std::vector<CJS_Value>& params,
2684 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002685 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002686 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002687}
2688
Tom Sepezb1670b52017-02-16 17:01:00 -08002689bool Field::insertItemAt(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002690 const std::vector<CJS_Value>& params,
2691 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002692 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002693 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002694}
2695
Tom Sepezb1670b52017-02-16 17:01:00 -08002696bool Field::isBoxChecked(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002697 const std::vector<CJS_Value>& params,
2698 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002699 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002700 int nIndex = -1;
2701 if (params.size() >= 1)
tsepezb4694242016-08-15 16:44:55 -07002702 nIndex = params[0].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002703
Lei Zhangd88a3642015-11-10 09:38:57 -08002704 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2705 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002706 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002707
Lei Zhangd88a3642015-11-10 09:38:57 -08002708 CPDF_FormField* pFormField = FieldArray[0];
dan sinclair646634b2017-10-19 14:30:28 -04002709 if (nIndex < 0 || nIndex >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002710 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002711
tsepezf3dc8c62016-08-10 06:29:29 -07002712 vRet = CJS_Value(pRuntime,
2713 ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
2714 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) &&
2715 pFormField->GetControl(nIndex)->IsChecked() != 0));
tsepez4cf55152016-11-02 14:37:54 -07002716 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002717}
2718
Tom Sepezb1670b52017-02-16 17:01:00 -08002719bool Field::isDefaultChecked(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002720 const std::vector<CJS_Value>& params,
2721 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002722 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002723 int nIndex = -1;
2724 if (params.size() >= 1)
tsepezb4694242016-08-15 16:44:55 -07002725 nIndex = params[0].ToInt(pRuntime);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002726
Lei Zhangd88a3642015-11-10 09:38:57 -08002727 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2728 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002729 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002730
Lei Zhangd88a3642015-11-10 09:38:57 -08002731 CPDF_FormField* pFormField = FieldArray[0];
tsepezf3dc8c62016-08-10 06:29:29 -07002732 if (nIndex < 0 || nIndex >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002733 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002734
tsepezf3dc8c62016-08-10 06:29:29 -07002735 vRet = CJS_Value(pRuntime,
2736 ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
2737 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) &&
2738 pFormField->GetControl(nIndex)->IsDefaultChecked() != 0));
tsepez4cf55152016-11-02 14:37:54 -07002739 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002740}
2741
Tom Sepezb1670b52017-02-16 17:01:00 -08002742bool Field::setAction(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002743 const std::vector<CJS_Value>& params,
2744 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002745 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002746 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002747}
2748
Tom Sepezb1670b52017-02-16 17:01:00 -08002749bool Field::setFocus(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002750 const std::vector<CJS_Value>& params,
2751 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002752 WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002753 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2754 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002755 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002756
Lei Zhangd88a3642015-11-10 09:38:57 -08002757 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002758 int32_t nCount = pFormField->CountControls();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002759 if (nCount < 1)
tsepez4cf55152016-11-02 14:37:54 -07002760 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002761
dsinclair7cbe68e2016-10-12 11:56:23 -07002762 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
thestig1cd352e2016-06-07 17:53:06 -07002763 CPDFSDK_Widget* pWidget = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002764 if (nCount == 1) {
dsinclairc5267c52016-11-04 15:35:12 -07002765 pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002766 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002767 UnderlyingPageType* pPage =
2768 UnderlyingFromFPDFPage(m_pFormFillEnv->GetCurrentPage(
2769 m_pFormFillEnv->GetUnderlyingDocument()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002770 if (!pPage)
tsepez4cf55152016-11-02 14:37:54 -07002771 return false;
dsinclair461eeaf2016-07-27 07:40:05 -07002772 if (CPDFSDK_PageView* pCurPageView =
dsinclair7cbe68e2016-10-12 11:56:23 -07002773 m_pFormFillEnv->GetPageView(pPage, true)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002774 for (int32_t i = 0; i < nCount; i++) {
2775 if (CPDFSDK_Widget* pTempWidget =
dsinclairc5267c52016-11-04 15:35:12 -07002776 pInterForm->GetWidget(pFormField->GetControl(i))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002777 if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage()) {
2778 pWidget = pTempWidget;
2779 break;
2780 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002781 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002782 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002783 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002784 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002785
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002786 if (pWidget) {
tsepezf8074ce2016-09-27 14:29:57 -07002787 CPDFSDK_Annot::ObservedPtr pObserved(pWidget);
dsinclair7cbe68e2016-10-12 11:56:23 -07002788 m_pFormFillEnv->SetFocusAnnot(&pObserved);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002789 }
2790
tsepez4cf55152016-11-02 14:37:54 -07002791 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002792}
2793
Tom Sepezb1670b52017-02-16 17:01:00 -08002794bool Field::setItems(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002795 const std::vector<CJS_Value>& params,
2796 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002797 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002798 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002799}
2800
Tom Sepezb1670b52017-02-16 17:01:00 -08002801bool Field::setLock(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002802 const std::vector<CJS_Value>& params,
2803 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002804 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002805 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002806}
2807
Tom Sepezb1670b52017-02-16 17:01:00 -08002808bool Field::signatureGetModifications(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002809 const std::vector<CJS_Value>& params,
2810 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002811 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002812 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002813}
2814
Tom Sepezb1670b52017-02-16 17:01:00 -08002815bool Field::signatureGetSeedValue(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002816 const std::vector<CJS_Value>& params,
2817 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002818 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002819 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002820}
2821
Tom Sepezb1670b52017-02-16 17:01:00 -08002822bool Field::signatureInfo(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002823 const std::vector<CJS_Value>& params,
2824 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002825 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002826 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002827}
2828
Tom Sepezb1670b52017-02-16 17:01:00 -08002829bool Field::signatureSetSeedValue(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002830 const std::vector<CJS_Value>& params,
2831 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002832 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002833 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002834}
2835
Tom Sepezb1670b52017-02-16 17:01:00 -08002836bool Field::signatureSign(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002837 const std::vector<CJS_Value>& params,
2838 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002839 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002840 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002841}
2842
Tom Sepezb1670b52017-02-16 17:01:00 -08002843bool Field::signatureValidate(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002844 const std::vector<CJS_Value>& params,
2845 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002846 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002847 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002848}
2849
dan sinclaircbe23db2017-10-19 14:29:33 -04002850bool Field::get_source(CJS_Runtime* pRuntime,
2851 CJS_PropValue* vp,
2852 WideString* sError) {
2853 vp->Set(static_cast<CJS_Object*>(nullptr));
2854 return true;
2855}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002856
dan sinclaircbe23db2017-10-19 14:29:33 -04002857bool Field::set_source(CJS_Runtime* pRuntime,
2858 const CJS_PropValue& vp,
2859 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -07002860 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002861}
2862
tsepez41a53ad2016-03-28 16:59:30 -07002863void Field::AddDelay_Int(FIELD_PROP prop, int32_t n) {
2864 CJS_DelayData* pNewData =
2865 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002866 pNewData->num = n;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002867 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002868}
2869
tsepez41a53ad2016-03-28 16:59:30 -07002870void Field::AddDelay_Bool(FIELD_PROP prop, bool b) {
2871 CJS_DelayData* pNewData =
2872 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002873 pNewData->b = b;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002874 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002875}
2876
Ryan Harrison275e2602017-09-18 14:23:18 -04002877void Field::AddDelay_String(FIELD_PROP prop, const ByteString& string) {
tsepez41a53ad2016-03-28 16:59:30 -07002878 CJS_DelayData* pNewData =
2879 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002880 pNewData->string = string;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002881 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002882}
2883
tsepez41a53ad2016-03-28 16:59:30 -07002884void Field::AddDelay_Rect(FIELD_PROP prop, const CFX_FloatRect& rect) {
2885 CJS_DelayData* pNewData =
2886 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002887 pNewData->rect = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002888 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002889}
2890
tsepez41a53ad2016-03-28 16:59:30 -07002891void Field::AddDelay_WordArray(FIELD_PROP prop,
2892 const std::vector<uint32_t>& array) {
2893 CJS_DelayData* pNewData =
2894 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
2895 pNewData->wordarray = array;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002896 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002897}
2898
tsepez41a53ad2016-03-28 16:59:30 -07002899void Field::AddDelay_WideStringArray(FIELD_PROP prop,
Ryan Harrison275e2602017-09-18 14:23:18 -04002900 const std::vector<WideString>& array) {
tsepez41a53ad2016-03-28 16:59:30 -07002901 CJS_DelayData* pNewData =
2902 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
2903 pNewData->widestringarray = array;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002904 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002905}
2906
dsinclair3a7741a2016-10-11 10:39:49 -07002907void Field::DoDelay(CPDFSDK_FormFillEnvironment* pFormFillEnv,
2908 CJS_DelayData* pData) {
2909 ASSERT(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002910 switch (pData->eProp) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002911 case FP_BORDERSTYLE:
dsinclair3a7741a2016-10-11 10:39:49 -07002912 Field::SetBorderStyle(pFormFillEnv, pData->sFieldName,
2913 pData->nControlIndex, pData->string);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002914 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002915 case FP_CURRENTVALUEINDICES:
dsinclair3a7741a2016-10-11 10:39:49 -07002916 Field::SetCurrentValueIndices(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002917 pData->nControlIndex, pData->wordarray);
2918 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002919 case FP_DISPLAY:
dsinclair3a7741a2016-10-11 10:39:49 -07002920 Field::SetDisplay(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002921 pData->num);
2922 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002923 case FP_HIDDEN:
dsinclair3a7741a2016-10-11 10:39:49 -07002924 Field::SetHidden(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002925 pData->b);
2926 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002927 case FP_LINEWIDTH:
dsinclair3a7741a2016-10-11 10:39:49 -07002928 Field::SetLineWidth(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002929 pData->num);
2930 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002931 case FP_RECT:
dsinclair3a7741a2016-10-11 10:39:49 -07002932 Field::SetRect(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002933 pData->rect);
2934 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002935 case FP_VALUE:
dsinclair3a7741a2016-10-11 10:39:49 -07002936 Field::SetValue(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002937 pData->widestringarray);
2938 break;
dan sinclair646634b2017-10-19 14:30:28 -04002939 default:
2940 NOTREACHED();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002941 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002942}