blob: a89df16158263956d132211bdeca84c4dcf837c6 [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},
79 {"borderStyle", get_borderStyle_static, set_borderStyle_static},
80 {"buttonAlignX", get_buttonAlignX_static, set_buttonAlignX_static},
81 {"buttonAlignY", get_buttonAlignY_static, set_buttonAlignY_static},
82 {"buttonFitBounds", get_buttonFitBounds_static, set_buttonFitBounds_static},
83 {"buttonPosition", get_buttonPosition_static, set_buttonPosition_static},
84 {"buttonScaleHow", get_buttonScaleHow_static, set_buttonScaleHow_static},
85 {"buttonScaleWhen", get_buttonScaleWhen_static, set_buttonScaleWhen_static},
86 {"calcOrderIndex", get_calcOrderIndex_static, set_calcOrderIndex_static},
87 {"charLimit", get_charLimit_static, set_charLimit_static},
88 {"comb", get_comb_static, set_comb_static},
89 {"commitOnSelChange", get_commitOnSelChange_static,
Tom Sepez04557b82017-02-16 09:43:10 -080090 set_commitOnSelChange_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -080091 {"currentValueIndices", get_currentValueIndices_static,
Tom Sepez04557b82017-02-16 09:43:10 -080092 set_currentValueIndices_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -080093 {"defaultStyle", get_defaultStyle_static, set_defaultStyle_static},
94 {"defaultValue", get_defaultValue_static, set_defaultValue_static},
95 {"doNotScroll", get_doNotScroll_static, set_doNotScroll_static},
96 {"doNotSpellCheck", get_doNotSpellCheck_static, set_doNotSpellCheck_static},
97 {"delay", get_delay_static, set_delay_static},
98 {"display", get_display_static, set_display_static},
99 {"doc", get_doc_static, set_doc_static},
100 {"editable", get_editable_static, set_editable_static},
101 {"exportValues", get_exportValues_static, set_exportValues_static},
102 {"hidden", get_hidden_static, set_hidden_static},
103 {"fileSelect", get_fileSelect_static, set_fileSelect_static},
104 {"fillColor", get_fillColor_static, set_fillColor_static},
105 {"lineWidth", get_lineWidth_static, set_lineWidth_static},
106 {"highlight", get_highlight_static, set_highlight_static},
107 {"multiline", get_multiline_static, set_multiline_static},
108 {"multipleSelection", get_multipleSelection_static,
Tom Sepez04557b82017-02-16 09:43:10 -0800109 set_multipleSelection_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800110 {"name", get_name_static, set_name_static},
111 {"numItems", get_numItems_static, set_numItems_static},
112 {"page", get_page_static, set_page_static},
113 {"password", get_password_static, set_password_static},
114 {"print", get_print_static, set_print_static},
115 {"radiosInUnison", get_radiosInUnison_static, set_radiosInUnison_static},
116 {"readonly", get_readonly_static, set_readonly_static},
117 {"rect", get_rect_static, set_rect_static},
118 {"required", get_required_static, set_required_static},
119 {"richText", get_richText_static, set_richText_static},
120 {"richValue", get_richValue_static, set_richValue_static},
121 {"rotation", get_rotation_static, set_rotation_static},
122 {"strokeColor", get_strokeColor_static, set_strokeColor_static},
123 {"style", get_style_static, set_style_static},
124 {"submitName", get_submitName_static, set_submitName_static},
125 {"textColor", get_textColor_static, set_textColor_static},
126 {"textFont", get_textFont_static, set_textFont_static},
127 {"textSize", get_textSize_static, set_textSize_static},
128 {"type", get_type_static, set_type_static},
129 {"userName", get_userName_static, set_userName_static},
130 {"value", get_value_static, set_value_static},
131 {"valueAsString", get_valueAsString_static, set_valueAsString_static},
132 {"source", get_source_static, set_source_static},
Tom Sepez04557b82017-02-16 09:43:10 -0800133 {0, 0, 0}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700134
Tom Sepez04557b82017-02-16 09:43:10 -0800135JSMethodSpec CJS_Field::MethodSpecs[] = {
Tom Sepez9b99b632017-02-21 15:05:57 -0800136 {"browseForFileToSubmit", browseForFileToSubmit_static},
137 {"buttonGetCaption", buttonGetCaption_static},
138 {"buttonGetIcon", buttonGetIcon_static},
139 {"buttonImportIcon", buttonImportIcon_static},
140 {"buttonSetCaption", buttonSetCaption_static},
141 {"buttonSetIcon", buttonSetIcon_static},
142 {"checkThisBox", checkThisBox_static},
143 {"clearItems", clearItems_static},
144 {"defaultIsChecked", defaultIsChecked_static},
145 {"deleteItemAt", deleteItemAt_static},
146 {"getArray", getArray_static},
147 {"getItemAt", getItemAt_static},
148 {"getLock", getLock_static},
149 {"insertItemAt", insertItemAt_static},
150 {"isBoxChecked", isBoxChecked_static},
151 {"isDefaultChecked", isDefaultChecked_static},
152 {"setAction", setAction_static},
153 {"setFocus", setFocus_static},
154 {"setItems", setItems_static},
155 {"setLock", setLock_static},
156 {"signatureGetModifications", signatureGetModifications_static},
157 {"signatureGetSeedValue", signatureGetSeedValue_static},
158 {"signatureInfo", signatureInfo_static},
159 {"signatureSetSeedValue", signatureSetSeedValue_static},
160 {"signatureSign", signatureSign_static},
161 {"signatureValidate", signatureValidate_static},
Tom Sepez04557b82017-02-16 09:43:10 -0800162 {0, 0}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700163
164IMPLEMENT_JS_CLASS(CJS_Field, Field)
165
Ryan Harrison275e2602017-09-18 14:23:18 -0400166CJS_DelayData::CJS_DelayData(FIELD_PROP prop, int idx, const WideString& name)
weili625ad662016-06-15 11:21:33 -0700167 : eProp(prop), nControlIndex(idx), sFieldName(name) {}
168
169CJS_DelayData::~CJS_DelayData() {}
170
Tom Sepez33420902015-10-13 15:00:10 -0700171void CJS_Field::InitInstance(IJS_Runtime* pIRuntime) {
Lei Zhangd88a3642015-11-10 09:38:57 -0800172}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700173
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700174Field::Field(CJS_Object* pJSObject)
175 : CJS_EmbedObj(pJSObject),
thestig1cd352e2016-06-07 17:53:06 -0700176 m_pJSDoc(nullptr),
dsinclair3a7741a2016-10-11 10:39:49 -0700177 m_pFormFillEnv(nullptr),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700178 m_nFormControlIndex(-1),
tsepez4cf55152016-11-02 14:37:54 -0700179 m_bCanSet(false),
180 m_bDelay(false) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700181
182Field::~Field() {}
183
184// note: iControlNo = -1, means not a widget.
185void Field::ParseFieldName(const std::wstring& strFieldNameParsed,
186 std::wstring& strFieldName,
187 int& iControlNo) {
188 int iStart = strFieldNameParsed.find_last_of(L'.');
189 if (iStart == -1) {
190 strFieldName = strFieldNameParsed;
191 iControlNo = -1;
192 return;
193 }
194 std::wstring suffixal = strFieldNameParsed.substr(iStart + 1);
195 iControlNo = FXSYS_wtoi(suffixal.c_str());
196 if (iControlNo == 0) {
weilidb444d22016-06-02 15:48:15 -0700197 int iSpaceStart;
198 while ((iSpaceStart = suffixal.find_last_of(L" ")) != -1) {
199 suffixal.erase(iSpaceStart, 1);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700200 }
201
202 if (suffixal.compare(L"0") != 0) {
203 strFieldName = strFieldNameParsed;
204 iControlNo = -1;
205 return;
206 }
207 }
208 strFieldName = strFieldNameParsed.substr(0, iStart);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700209}
210
Ryan Harrison275e2602017-09-18 14:23:18 -0400211bool Field::AttachField(Document* pDocument, const WideString& csFieldName) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700212 m_pJSDoc = pDocument;
dsinclair82e17672016-10-11 12:38:01 -0700213 m_pFormFillEnv.Reset(pDocument->GetFormFillEnv());
dsinclair7cbe68e2016-10-12 11:56:23 -0700214 m_bCanSet = m_pFormFillEnv->GetPermissions(FPDFPERM_FILL_FORM) ||
215 m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM) ||
216 m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700217
dsinclair7cbe68e2016-10-12 11:56:23 -0700218 CPDFSDK_InterForm* pRDInterForm = m_pFormFillEnv->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700219 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
Ryan Harrison275e2602017-09-18 14:23:18 -0400220 WideString swFieldNameTemp = csFieldName;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700221 swFieldNameTemp.Replace(L"..", L".");
222
223 if (pInterForm->CountFields(swFieldNameTemp) <= 0) {
224 std::wstring strFieldName;
225 int iControlNo = -1;
226 ParseFieldName(swFieldNameTemp.c_str(), strFieldName, iControlNo);
227 if (iControlNo == -1)
tsepez4cf55152016-11-02 14:37:54 -0700228 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700229
230 m_FieldName = strFieldName.c_str();
231 m_nFormControlIndex = iControlNo;
tsepez4cf55152016-11-02 14:37:54 -0700232 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700233 }
234
235 m_FieldName = swFieldNameTemp;
236 m_nFormControlIndex = -1;
237
tsepez4cf55152016-11-02 14:37:54 -0700238 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700239}
240
Lei Zhangd88a3642015-11-10 09:38:57 -0800241std::vector<CPDF_FormField*> Field::GetFormFields(
dsinclair3a7741a2016-10-11 10:39:49 -0700242 CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -0400243 const WideString& csFieldName) {
Lei Zhangd88a3642015-11-10 09:38:57 -0800244 std::vector<CPDF_FormField*> fields;
dsinclair7cbe68e2016-10-12 11:56:23 -0700245 CPDFSDK_InterForm* pReaderInterForm = pFormFillEnv->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700246 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -0800247 for (int i = 0, sz = pInterForm->CountFields(csFieldName); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700248 if (CPDF_FormField* pFormField = pInterForm->GetField(i, csFieldName))
Lei Zhangd88a3642015-11-10 09:38:57 -0800249 fields.push_back(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700250 }
Lei Zhangd88a3642015-11-10 09:38:57 -0800251 return fields;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700252}
253
Lei Zhangd88a3642015-11-10 09:38:57 -0800254std::vector<CPDF_FormField*> Field::GetFormFields(
Ryan Harrison275e2602017-09-18 14:23:18 -0400255 const WideString& csFieldName) const {
dsinclair3a7741a2016-10-11 10:39:49 -0700256 return Field::GetFormFields(m_pFormFillEnv.Get(), csFieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700257}
258
dsinclair3a7741a2016-10-11 10:39:49 -0700259void Field::UpdateFormField(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700260 CPDF_FormField* pFormField,
tsepez4cf55152016-11-02 14:37:54 -0700261 bool bChangeMark,
262 bool bResetAP,
263 bool bRefresh) {
dsinclair7cbe68e2016-10-12 11:56:23 -0700264 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700265
266 if (bResetAP) {
tsepez8fa82792017-01-11 09:32:33 -0800267 std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
dsinclair1df1efa2016-09-07 09:55:37 -0700268 pInterForm->GetWidgets(pFormField, &widgets);
269
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700270 int nFieldType = pFormField->GetFieldType();
271 if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_TEXTFIELD) {
tsepez8fa82792017-01-11 09:32:33 -0800272 for (auto& pObserved : widgets) {
tsepez1c620542016-09-12 09:47:52 -0700273 if (pObserved) {
tsepez8fa82792017-01-11 09:32:33 -0800274 bool bFormatted = false;
Ryan Harrison275e2602017-09-18 14:23:18 -0400275 WideString sValue = static_cast<CPDFSDK_Widget*>(pObserved.Get())
276 ->OnFormat(bFormatted);
tsepez8fa82792017-01-11 09:32:33 -0800277 if (pObserved) { // Not redundant, may be clobbered by OnFormat.
278 static_cast<CPDFSDK_Widget*>(pObserved.Get())
279 ->ResetAppearance(bFormatted ? &sValue : nullptr, false);
280 }
tsepezca97a8e2016-08-01 10:10:36 -0700281 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700282 }
283 } else {
tsepez8fa82792017-01-11 09:32:33 -0800284 for (auto& pObserved : widgets) {
285 if (pObserved) {
286 static_cast<CPDFSDK_Widget*>(pObserved.Get())
287 ->ResetAppearance(nullptr, false);
288 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700289 }
290 }
291 }
292
293 if (bRefresh) {
dsinclair1df1efa2016-09-07 09:55:37 -0700294 // Refresh the widget list. The calls in |bResetAP| may have caused widgets
295 // to be removed from the list. We need to call |GetWidgets| again to be
296 // sure none of the widgets have been deleted.
tsepez8fa82792017-01-11 09:32:33 -0800297 std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
dsinclair1df1efa2016-09-07 09:55:37 -0700298 pInterForm->GetWidgets(pFormField, &widgets);
299
dsinclair690c0332016-10-11 09:13:01 -0700300 // TODO(dsinclair): Determine if all widgets share the same
301 // CPDFSDK_InterForm. If that's the case, we can move the code to
dsinclair7cbe68e2016-10-12 11:56:23 -0700302 // |GetFormFillEnv| out of the loop.
tsepez8fa82792017-01-11 09:32:33 -0800303 for (auto& pObserved : widgets) {
304 if (pObserved) {
305 CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pObserved.Get());
306 pWidget->GetInterForm()->GetFormFillEnv()->UpdateAllViews(nullptr,
307 pWidget);
308 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700309 }
310 }
311
312 if (bChangeMark)
dsinclair7cbe68e2016-10-12 11:56:23 -0700313 pFormFillEnv->SetChangeMark();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700314}
315
dsinclair3a7741a2016-10-11 10:39:49 -0700316void Field::UpdateFormControl(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700317 CPDF_FormControl* pFormControl,
tsepez4cf55152016-11-02 14:37:54 -0700318 bool bChangeMark,
319 bool bResetAP,
320 bool bRefresh) {
Lei Zhang96660d62015-12-14 18:27:25 -0800321 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700322
dsinclair7cbe68e2016-10-12 11:56:23 -0700323 CPDFSDK_InterForm* pForm = pFormFillEnv->GetInterForm();
dsinclairc5267c52016-11-04 15:35:12 -0700324 CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700325
326 if (pWidget) {
327 if (bResetAP) {
328 int nFieldType = pWidget->GetFieldType();
329 if (nFieldType == FIELDTYPE_COMBOBOX ||
330 nFieldType == FIELDTYPE_TEXTFIELD) {
tsepez4cf55152016-11-02 14:37:54 -0700331 bool bFormatted = false;
Ryan Harrison275e2602017-09-18 14:23:18 -0400332 WideString sValue = pWidget->OnFormat(bFormatted);
tsepez4cf55152016-11-02 14:37:54 -0700333 pWidget->ResetAppearance(bFormatted ? &sValue : nullptr, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700334 } else {
tsepez4cf55152016-11-02 14:37:54 -0700335 pWidget->ResetAppearance(nullptr, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700336 }
337 }
338
339 if (bRefresh) {
340 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
dsinclair7cbe68e2016-10-12 11:56:23 -0700341 pInterForm->GetFormFillEnv()->UpdateAllViews(nullptr, pWidget);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700342 }
343 }
344
345 if (bChangeMark)
dsinclair7cbe68e2016-10-12 11:56:23 -0700346 pFormFillEnv->SetChangeMark();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700347}
348
dsinclair3a7741a2016-10-11 10:39:49 -0700349CPDFSDK_Widget* Field::GetWidget(CPDFSDK_FormFillEnvironment* pFormFillEnv,
dsinclairc5267c52016-11-04 15:35:12 -0700350 CPDF_FormControl* pFormControl) {
dsinclair7cbe68e2016-10-12 11:56:23 -0700351 CPDFSDK_InterForm* pInterForm =
352 static_cast<CPDFSDK_InterForm*>(pFormFillEnv->GetInterForm());
dsinclairc5267c52016-11-04 15:35:12 -0700353 return pInterForm ? pInterForm->GetWidget(pFormControl) : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700354}
355
Ryan Harrison275e2602017-09-18 14:23:18 -0400356bool Field::ValueIsOccur(CPDF_FormField* pFormField, WideString csOptLabel) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700357 for (int i = 0, sz = pFormField->CountOptions(); i < sz; i++) {
358 if (csOptLabel.Compare(pFormField->GetOptionLabel(i)) == 0)
tsepez4cf55152016-11-02 14:37:54 -0700359 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700360 }
361
tsepez4cf55152016-11-02 14:37:54 -0700362 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700363}
364
365CPDF_FormControl* Field::GetSmartFieldControl(CPDF_FormField* pFormField) {
366 if (!pFormField->CountControls() ||
367 m_nFormControlIndex >= pFormField->CountControls())
thestig1cd352e2016-06-07 17:53:06 -0700368 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700369
370 if (m_nFormControlIndex < 0)
371 return pFormField->GetControl(0);
372
373 return pFormField->GetControl(m_nFormControlIndex);
374}
375
Tom Sepezb1670b52017-02-16 17:01:00 -0800376bool Field::alignment(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700377 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -0400378 WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700379 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700380
381 if (vp.IsSetting()) {
382 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700383 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700384
Ryan Harrison275e2602017-09-18 14:23:18 -0400385 ByteString alignStr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700386 vp >> alignStr;
387
388 if (m_bDelay) {
389 AddDelay_String(FP_ALIGNMENT, alignStr);
390 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700391 Field::SetAlignment(m_pFormFillEnv.Get(), m_FieldName,
392 m_nFormControlIndex, alignStr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700393 }
394 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800395 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
396 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700397 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700398
Lei Zhangd88a3642015-11-10 09:38:57 -0800399 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700400 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
tsepez4cf55152016-11-02 14:37:54 -0700401 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700402
403 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
404 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -0700405 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700406
407 switch (pFormControl->GetControlAlignment()) {
408 case 1:
409 vp << L"center";
410 break;
411 case 0:
412 vp << L"left";
413 break;
414 case 2:
415 vp << L"right";
416 break;
417 default:
418 vp << L"";
419 }
420 }
421
tsepez4cf55152016-11-02 14:37:54 -0700422 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700423}
424
dsinclair3a7741a2016-10-11 10:39:49 -0700425void Field::SetAlignment(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -0400426 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700427 int nControlIndex,
Ryan Harrison275e2602017-09-18 14:23:18 -0400428 const ByteString& string) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700429 // Not supported.
430}
431
Tom Sepezb1670b52017-02-16 17:01:00 -0800432bool Field::borderStyle(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700433 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -0400434 WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700435 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700436
437 if (vp.IsSetting()) {
438 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700439 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700440
Ryan Harrison275e2602017-09-18 14:23:18 -0400441 ByteString strType = "";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700442 vp >> strType;
443
444 if (m_bDelay) {
445 AddDelay_String(FP_BORDERSTYLE, strType);
446 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700447 Field::SetBorderStyle(m_pFormFillEnv.Get(), m_FieldName,
448 m_nFormControlIndex, strType);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700449 }
450 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800451 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
452 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700453 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700454
Lei Zhangd88a3642015-11-10 09:38:57 -0800455 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700456 if (!pFormField)
tsepez4cf55152016-11-02 14:37:54 -0700457 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700458
dsinclairc5267c52016-11-04 15:35:12 -0700459 CPDFSDK_Widget* pWidget =
460 GetWidget(m_pFormFillEnv.Get(), GetSmartFieldControl(pFormField));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700461 if (!pWidget)
tsepez4cf55152016-11-02 14:37:54 -0700462 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700463
dsinclair92cb5e52016-05-16 11:38:28 -0700464 switch (pWidget->GetBorderStyle()) {
465 case BorderStyle::SOLID:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700466 vp << L"solid";
467 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700468 case BorderStyle::DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700469 vp << L"dashed";
470 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700471 case BorderStyle::BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700472 vp << L"beveled";
473 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700474 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700475 vp << L"inset";
476 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700477 case BorderStyle::UNDERLINE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700478 vp << L"underline";
479 break;
480 default:
481 vp << L"";
482 break;
483 }
484 }
485
tsepez4cf55152016-11-02 14:37:54 -0700486 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700487}
488
dsinclair3a7741a2016-10-11 10:39:49 -0700489void Field::SetBorderStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -0400490 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700491 int nControlIndex,
Ryan Harrison275e2602017-09-18 14:23:18 -0400492 const ByteString& string) {
dsinclair3a7741a2016-10-11 10:39:49 -0700493 ASSERT(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700494
dsinclair92cb5e52016-05-16 11:38:28 -0700495 BorderStyle nBorderStyle = BorderStyle::SOLID;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700496 if (string == "solid")
dsinclair92cb5e52016-05-16 11:38:28 -0700497 nBorderStyle = BorderStyle::SOLID;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700498 else if (string == "beveled")
dsinclair92cb5e52016-05-16 11:38:28 -0700499 nBorderStyle = BorderStyle::BEVELED;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700500 else if (string == "dashed")
dsinclair92cb5e52016-05-16 11:38:28 -0700501 nBorderStyle = BorderStyle::DASH;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700502 else if (string == "inset")
dsinclair92cb5e52016-05-16 11:38:28 -0700503 nBorderStyle = BorderStyle::INSET;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700504 else if (string == "underline")
dsinclair92cb5e52016-05-16 11:38:28 -0700505 nBorderStyle = BorderStyle::UNDERLINE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700506 else
507 return;
508
Lei Zhangd88a3642015-11-10 09:38:57 -0800509 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -0700510 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -0800511 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700512 if (nControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -0700513 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -0800514 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700515 if (CPDFSDK_Widget* pWidget =
dsinclairc5267c52016-11-04 15:35:12 -0700516 GetWidget(pFormFillEnv, pFormField->GetControl(i))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700517 if (pWidget->GetBorderStyle() != nBorderStyle) {
518 pWidget->SetBorderStyle(nBorderStyle);
tsepez4cf55152016-11-02 14:37:54 -0700519 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700520 }
521 }
522 }
523 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -0700524 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700525 } else {
526 if (nControlIndex >= pFormField->CountControls())
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700527 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700528 if (CPDF_FormControl* pFormControl =
529 pFormField->GetControl(nControlIndex)) {
dsinclairc5267c52016-11-04 15:35:12 -0700530 if (CPDFSDK_Widget* pWidget = GetWidget(pFormFillEnv, pFormControl)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700531 if (pWidget->GetBorderStyle() != nBorderStyle) {
532 pWidget->SetBorderStyle(nBorderStyle);
tsepez4cf55152016-11-02 14:37:54 -0700533 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700534 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700535 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700536 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700537 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700538 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700539}
540
Tom Sepezb1670b52017-02-16 17:01:00 -0800541bool Field::buttonAlignX(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700542 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -0400543 WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700544 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700545
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700546 if (vp.IsSetting()) {
547 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700548 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700549
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700550 int nVP;
551 vp >> nVP;
552
553 if (m_bDelay) {
554 AddDelay_Int(FP_BUTTONALIGNX, nVP);
555 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700556 Field::SetButtonAlignX(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700557 m_nFormControlIndex, nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700558 }
559 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800560 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
561 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700562 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700563
Lei Zhangd88a3642015-11-10 09:38:57 -0800564 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700565 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -0700566 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700567
568 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
569 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -0700570 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700571
572 CPDF_IconFit IconFit = pFormControl->GetIconFit();
573
Dan Sinclair05df0752017-03-14 14:43:42 -0400574 float fLeft, fBottom;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700575 IconFit.GetIconPosition(fLeft, fBottom);
576
577 vp << (int32_t)fLeft;
578 }
579
tsepez4cf55152016-11-02 14:37:54 -0700580 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700581}
582
dsinclair3a7741a2016-10-11 10:39:49 -0700583void Field::SetButtonAlignX(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -0400584 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700585 int nControlIndex,
586 int number) {
587 // Not supported.
588}
589
Tom Sepezb1670b52017-02-16 17:01:00 -0800590bool Field::buttonAlignY(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700591 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -0400592 WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700593 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700594
595 if (vp.IsSetting()) {
596 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700597 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700598
599 int nVP;
600 vp >> nVP;
601
602 if (m_bDelay) {
603 AddDelay_Int(FP_BUTTONALIGNY, nVP);
604 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700605 Field::SetButtonAlignY(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700606 m_nFormControlIndex, nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700607 }
608 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800609 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
610 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700611 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700612
Lei Zhangd88a3642015-11-10 09:38:57 -0800613 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700614 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -0700615 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700616
617 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
618 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -0700619 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700620
621 CPDF_IconFit IconFit = pFormControl->GetIconFit();
622
Dan Sinclair05df0752017-03-14 14:43:42 -0400623 float fLeft, fBottom;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700624 IconFit.GetIconPosition(fLeft, fBottom);
625
626 vp << (int32_t)fBottom;
627 }
628
tsepez4cf55152016-11-02 14:37:54 -0700629 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700630}
631
dsinclair3a7741a2016-10-11 10:39:49 -0700632void Field::SetButtonAlignY(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -0400633 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700634 int nControlIndex,
635 int number) {
636 // Not supported.
637}
638
Tom Sepezb1670b52017-02-16 17:01:00 -0800639bool Field::buttonFitBounds(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700640 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -0400641 WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700642 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700643
644 if (vp.IsSetting()) {
645 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700646 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700647
648 bool bVP;
649 vp >> bVP;
650
651 if (m_bDelay) {
652 AddDelay_Bool(FP_BUTTONFITBOUNDS, bVP);
653 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700654 Field::SetButtonFitBounds(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700655 m_nFormControlIndex, bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700656 }
657 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800658 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
659 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700660 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700661
Lei Zhangd88a3642015-11-10 09:38:57 -0800662 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700663 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -0700664 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700665
666 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
667 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -0700668 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700669
thestigded36342016-05-23 17:54:02 -0700670 vp << pFormControl->GetIconFit().GetFittingBounds();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700671 }
672
tsepez4cf55152016-11-02 14:37:54 -0700673 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700674}
675
dsinclair3a7741a2016-10-11 10:39:49 -0700676void Field::SetButtonFitBounds(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -0400677 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700678 int nControlIndex,
679 bool b) {
680 // Not supported.
681}
682
Tom Sepezb1670b52017-02-16 17:01:00 -0800683bool Field::buttonPosition(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700684 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -0400685 WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700686 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700687
688 if (vp.IsSetting()) {
689 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700690 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700691
692 int nVP;
693 vp >> nVP;
694
695 if (m_bDelay) {
696 AddDelay_Int(FP_BUTTONPOSITION, nVP);
697 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700698 Field::SetButtonPosition(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700699 m_nFormControlIndex, nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700700 }
701 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800702 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
703 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700704 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700705
Lei Zhangd88a3642015-11-10 09:38:57 -0800706 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700707 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -0700708 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700709
710 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
711 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -0700712 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700713
714 vp << pFormControl->GetTextPosition();
715 }
tsepez4cf55152016-11-02 14:37:54 -0700716 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700717}
718
dsinclair3a7741a2016-10-11 10:39:49 -0700719void Field::SetButtonPosition(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -0400720 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700721 int nControlIndex,
722 int number) {
723 // Not supported.
724}
725
Tom Sepezb1670b52017-02-16 17:01:00 -0800726bool Field::buttonScaleHow(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700727 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -0400728 WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700729 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700730
731 if (vp.IsSetting()) {
732 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700733 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700734
735 int nVP;
736 vp >> nVP;
737
738 if (m_bDelay) {
739 AddDelay_Int(FP_BUTTONSCALEHOW, nVP);
740 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700741 Field::SetButtonScaleHow(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700742 m_nFormControlIndex, nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700743 }
744 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800745 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
746 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700747 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700748
Lei Zhangd88a3642015-11-10 09:38:57 -0800749 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700750 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -0700751 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700752
753 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
754 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -0700755 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700756
757 CPDF_IconFit IconFit = pFormControl->GetIconFit();
758 if (IconFit.IsProportionalScale())
759 vp << (int32_t)0;
760 else
761 vp << (int32_t)1;
762 }
763
tsepez4cf55152016-11-02 14:37:54 -0700764 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700765}
766
dsinclair3a7741a2016-10-11 10:39:49 -0700767void Field::SetButtonScaleHow(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -0400768 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700769 int nControlIndex,
770 int number) {
771 // Not supported.
772}
773
Tom Sepezb1670b52017-02-16 17:01:00 -0800774bool Field::buttonScaleWhen(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700775 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -0400776 WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700777 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700778
779 if (vp.IsSetting()) {
780 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700781 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700782
783 int nVP;
784 vp >> nVP;
785
786 if (m_bDelay) {
787 AddDelay_Int(FP_BUTTONSCALEWHEN, nVP);
788 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700789 Field::SetButtonScaleWhen(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700790 m_nFormControlIndex, nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700791 }
792 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800793 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
794 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700795 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700796
Lei Zhangd88a3642015-11-10 09:38:57 -0800797 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700798 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -0700799 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700800
801 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
802 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -0700803 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700804
805 CPDF_IconFit IconFit = pFormControl->GetIconFit();
806 int ScaleM = IconFit.GetScaleMethod();
807 switch (ScaleM) {
808 case CPDF_IconFit::Always:
809 vp << (int32_t)CPDF_IconFit::Always;
810 break;
811 case CPDF_IconFit::Bigger:
812 vp << (int32_t)CPDF_IconFit::Bigger;
813 break;
814 case CPDF_IconFit::Never:
815 vp << (int32_t)CPDF_IconFit::Never;
816 break;
817 case CPDF_IconFit::Smaller:
818 vp << (int32_t)CPDF_IconFit::Smaller;
819 break;
820 }
821 }
822
tsepez4cf55152016-11-02 14:37:54 -0700823 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700824}
825
dsinclair3a7741a2016-10-11 10:39:49 -0700826void Field::SetButtonScaleWhen(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -0400827 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700828 int nControlIndex,
829 int number) {
830 // Not supported.
831}
832
Tom Sepezb1670b52017-02-16 17:01:00 -0800833bool Field::calcOrderIndex(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700834 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -0400835 WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700836 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700837
838 if (vp.IsSetting()) {
839 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700840 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700841
842 int nVP;
843 vp >> nVP;
844
845 if (m_bDelay) {
846 AddDelay_Int(FP_CALCORDERINDEX, nVP);
847 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700848 Field::SetCalcOrderIndex(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700849 m_nFormControlIndex, nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700850 }
851 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800852 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
853 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700854 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700855
Lei Zhangd88a3642015-11-10 09:38:57 -0800856 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700857 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -0800858 pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) {
tsepez4cf55152016-11-02 14:37:54 -0700859 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -0800860 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700861
dsinclair7cbe68e2016-10-12 11:56:23 -0700862 CPDFSDK_InterForm* pRDInterForm = m_pFormFillEnv->GetInterForm();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700863 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700864 vp << (int32_t)pInterForm->FindFieldInCalculationOrder(pFormField);
865 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700866
tsepez4cf55152016-11-02 14:37:54 -0700867 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700868}
869
dsinclair3a7741a2016-10-11 10:39:49 -0700870void Field::SetCalcOrderIndex(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -0400871 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700872 int nControlIndex,
873 int number) {
874 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700875}
876
Tom Sepezb1670b52017-02-16 17:01:00 -0800877bool Field::charLimit(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700878 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -0400879 WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700880 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700881
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700882 if (vp.IsSetting()) {
883 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700884 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700885
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700886 int nVP;
887 vp >> nVP;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700888
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700889 if (m_bDelay) {
890 AddDelay_Int(FP_CHARLIMIT, nVP);
891 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700892 Field::SetCharLimit(m_pFormFillEnv.Get(), m_FieldName,
893 m_nFormControlIndex, nVP);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700894 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700895 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800896 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
897 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700898 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700899
Lei Zhangd88a3642015-11-10 09:38:57 -0800900 CPDF_FormField* pFormField = FieldArray[0];
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700901 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
tsepez4cf55152016-11-02 14:37:54 -0700902 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700903
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700904 vp << (int32_t)pFormField->GetMaxLen();
905 }
tsepez4cf55152016-11-02 14:37:54 -0700906 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700907}
908
dsinclair3a7741a2016-10-11 10:39:49 -0700909void Field::SetCharLimit(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -0400910 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700911 int nControlIndex,
912 int number) {
913 // Not supported.
914}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700915
Ryan Harrison275e2602017-09-18 14:23:18 -0400916bool Field::comb(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700917 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700918
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700919 if (vp.IsSetting()) {
920 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700921 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700922
923 bool bVP;
924 vp >> bVP;
925
926 if (m_bDelay) {
927 AddDelay_Bool(FP_COMB, bVP);
928 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700929 Field::SetComb(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
930 bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700931 }
932 } else {
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_TEXTFIELD)
tsepez4cf55152016-11-02 14:37:54 -0700939 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700940
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700941 if (pFormField->GetFieldFlags() & FIELDFLAG_COMB)
942 vp << true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700943 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700944 vp << false;
945 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700946
tsepez4cf55152016-11-02 14:37:54 -0700947 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700948}
949
dsinclair3a7741a2016-10-11 10:39:49 -0700950void Field::SetComb(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -0400951 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700952 int nControlIndex,
953 bool b) {
954 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700955}
956
Tom Sepezb1670b52017-02-16 17:01:00 -0800957bool Field::commitOnSelChange(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700958 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -0400959 WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700960 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700961
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700962 if (vp.IsSetting()) {
963 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700964 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700965
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700966 bool bVP;
967 vp >> bVP;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700968
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700969 if (m_bDelay) {
970 AddDelay_Bool(FP_COMMITONSELCHANGE, bVP);
971 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700972 Field::SetCommitOnSelChange(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700973 m_nFormControlIndex, bVP);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700974 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700975 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800976 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
977 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700978 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700979
Lei Zhangd88a3642015-11-10 09:38:57 -0800980 CPDF_FormField* pFormField = FieldArray[0];
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700981 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -0800982 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
tsepez4cf55152016-11-02 14:37:54 -0700983 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -0800984 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700985
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700986 if (pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE)
987 vp << true;
988 else
989 vp << false;
990 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700991
tsepez4cf55152016-11-02 14:37:54 -0700992 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700993}
994
dsinclair3a7741a2016-10-11 10:39:49 -0700995void Field::SetCommitOnSelChange(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -0400996 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700997 int nControlIndex,
998 bool b) {
999 // Not supported.
1000}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001001
Tom Sepezb1670b52017-02-16 17:01:00 -08001002bool Field::currentValueIndices(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001003 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04001004 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001005 if (vp.IsSetting()) {
1006 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001007 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001008
tsepez41a53ad2016-03-28 16:59:30 -07001009 std::vector<uint32_t> array;
tsepezf3dc8c62016-08-10 06:29:29 -07001010 if (vp.GetJSValue()->GetType() == CJS_Value::VT_number) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001011 int iSelecting = 0;
1012 vp >> iSelecting;
tsepez41a53ad2016-03-28 16:59:30 -07001013 array.push_back(iSelecting);
tsepezf3dc8c62016-08-10 06:29:29 -07001014 } else if (vp.GetJSValue()->IsArrayObject()) {
tsepeze5aff742016-08-08 09:49:42 -07001015 CJS_Array SelArray;
Tom Sepez67fd5df2015-10-08 12:24:19 -07001016 CJS_Value SelValue(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001017 int iSelecting;
1018 vp >> SelArray;
tsepezb4694242016-08-15 16:44:55 -07001019 for (int i = 0, sz = SelArray.GetLength(pRuntime); i < sz; i++) {
1020 SelArray.GetElement(pRuntime, i, SelValue);
1021 iSelecting = SelValue.ToInt(pRuntime);
tsepez41a53ad2016-03-28 16:59:30 -07001022 array.push_back(iSelecting);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001023 }
1024 }
1025
1026 if (m_bDelay) {
1027 AddDelay_WordArray(FP_CURRENTVALUEINDICES, array);
1028 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001029 Field::SetCurrentValueIndices(m_pFormFillEnv.Get(), m_FieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001030 m_nFormControlIndex, array);
1031 }
1032 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001033 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1034 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001035 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001036
Lei Zhangd88a3642015-11-10 09:38:57 -08001037 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001038 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001039 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
tsepez4cf55152016-11-02 14:37:54 -07001040 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001041 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001042
Lei Zhangd88a3642015-11-10 09:38:57 -08001043 if (pFormField->CountSelectedItems() == 1) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001044 vp << pFormField->GetSelectedIndex(0);
Lei Zhangd88a3642015-11-10 09:38:57 -08001045 } else if (pFormField->CountSelectedItems() > 1) {
tsepeze5aff742016-08-08 09:49:42 -07001046 CJS_Array SelArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001047 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
1048 SelArray.SetElement(
tsepezb4694242016-08-15 16:44:55 -07001049 pRuntime, i, CJS_Value(pRuntime, pFormField->GetSelectedIndex(i)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001050 }
1051 vp << SelArray;
Lei Zhangd88a3642015-11-10 09:38:57 -08001052 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001053 vp << -1;
Lei Zhangd88a3642015-11-10 09:38:57 -08001054 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001055 }
1056
tsepez4cf55152016-11-02 14:37:54 -07001057 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001058}
1059
dsinclair3a7741a2016-10-11 10:39:49 -07001060void Field::SetCurrentValueIndices(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04001061 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001062 int nControlIndex,
tsepez41a53ad2016-03-28 16:59:30 -07001063 const std::vector<uint32_t>& array) {
dsinclair3a7741a2016-10-11 10:39:49 -07001064 ASSERT(pFormFillEnv);
Lei Zhangd88a3642015-11-10 09:38:57 -08001065 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07001066 GetFormFields(pFormFillEnv, swFieldName);
tsepez41a53ad2016-03-28 16:59:30 -07001067
Lei Zhangd88a3642015-11-10 09:38:57 -08001068 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001069 int nFieldType = pFormField->GetFieldType();
1070 if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX) {
tsepezc3255f52016-03-25 14:52:27 -07001071 uint32_t dwFieldFlags = pFormField->GetFieldFlags();
tsepez4cf55152016-11-02 14:37:54 -07001072 pFormField->ClearSelection(true);
tsepez41a53ad2016-03-28 16:59:30 -07001073 for (size_t i = 0; i < array.size(); ++i) {
1074 if (i != 0 && !(dwFieldFlags & (1 << 21)))
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001075 break;
Wei Li05d53f02016-03-29 16:42:53 -07001076 if (array[i] < static_cast<uint32_t>(pFormField->CountOptions()) &&
tsepez41a53ad2016-03-28 16:59:30 -07001077 !pFormField->IsItemSelected(array[i])) {
tsepez4cf55152016-11-02 14:37:54 -07001078 pFormField->SetItemSelection(array[i], true);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001079 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001080 }
tsepez4cf55152016-11-02 14:37:54 -07001081 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001082 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001083 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001084}
1085
Tom Sepezb1670b52017-02-16 17:01:00 -08001086bool Field::defaultStyle(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001087 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04001088 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07001089 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001090}
1091
dsinclair3a7741a2016-10-11 10:39:49 -07001092void Field::SetDefaultStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04001093 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001094 int nControlIndex) {
1095 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001096}
1097
Tom Sepezb1670b52017-02-16 17:01:00 -08001098bool Field::defaultValue(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001099 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04001100 WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001101 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001102
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001103 if (vp.IsSetting()) {
1104 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001105 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001106
Ryan Harrison275e2602017-09-18 14:23:18 -04001107 WideString WideStr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001108 vp >> WideStr;
1109
1110 if (m_bDelay) {
1111 AddDelay_WideString(FP_DEFAULTVALUE, WideStr);
1112 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001113 Field::SetDefaultValue(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -07001114 m_nFormControlIndex, WideStr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001115 }
1116 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001117 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1118 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001119 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001120
Lei Zhangd88a3642015-11-10 09:38:57 -08001121 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001122 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON ||
Lei Zhangd88a3642015-11-10 09:38:57 -08001123 pFormField->GetFieldType() == FIELDTYPE_SIGNATURE) {
tsepez4cf55152016-11-02 14:37:54 -07001124 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001125 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001126
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001127 vp << pFormField->GetDefaultValue();
1128 }
tsepez4cf55152016-11-02 14:37:54 -07001129 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001130}
1131
dsinclair3a7741a2016-10-11 10:39:49 -07001132void Field::SetDefaultValue(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04001133 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001134 int nControlIndex,
Ryan Harrison275e2602017-09-18 14:23:18 -04001135 const WideString& string) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001136 // Not supported.
1137}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001138
Tom Sepezb1670b52017-02-16 17:01:00 -08001139bool Field::doNotScroll(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001140 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04001141 WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001142 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001143
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001144 if (vp.IsSetting()) {
1145 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001146 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001147
1148 bool bVP;
1149 vp >> bVP;
1150
1151 if (m_bDelay) {
1152 AddDelay_Bool(FP_DONOTSCROLL, bVP);
1153 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001154 Field::SetDoNotScroll(m_pFormFillEnv.Get(), m_FieldName,
1155 m_nFormControlIndex, bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001156 }
1157 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001158 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1159 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001160 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001161
Lei Zhangd88a3642015-11-10 09:38:57 -08001162 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001163 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
tsepez4cf55152016-11-02 14:37:54 -07001164 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001165
1166 if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL)
1167 vp << true;
1168 else
1169 vp << false;
1170 }
1171
tsepez4cf55152016-11-02 14:37:54 -07001172 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001173}
1174
dsinclair3a7741a2016-10-11 10:39:49 -07001175void Field::SetDoNotScroll(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04001176 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001177 int nControlIndex,
1178 bool b) {
1179 // Not supported.
1180}
1181
Tom Sepezb1670b52017-02-16 17:01:00 -08001182bool Field::doNotSpellCheck(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001183 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04001184 WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001185 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001186
1187 if (vp.IsSetting()) {
1188 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001189 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001190
1191 bool bVP;
1192 vp >> bVP;
1193 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001194 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1195 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001196 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001197
Lei Zhangd88a3642015-11-10 09:38:57 -08001198 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001199 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001200 pFormField->GetFieldType() != FIELDTYPE_COMBOBOX) {
tsepez4cf55152016-11-02 14:37:54 -07001201 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001202 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001203
1204 if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK)
1205 vp << true;
1206 else
1207 vp << false;
1208 }
1209
tsepez4cf55152016-11-02 14:37:54 -07001210 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001211}
1212
tsepez4cf55152016-11-02 14:37:54 -07001213void Field::SetDelay(bool bDelay) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001214 m_bDelay = bDelay;
1215
1216 if (!m_bDelay) {
1217 if (m_pJSDoc)
1218 m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex);
1219 }
1220}
1221
Tom Sepezb1670b52017-02-16 17:01:00 -08001222bool Field::delay(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001223 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04001224 WideString& sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001225 if (!vp.IsSetting()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001226 vp << m_bDelay;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001227 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001228 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001229 if (!m_bCanSet)
1230 return false;
1231
1232 bool bVP;
1233 vp >> bVP;
1234 SetDelay(bVP);
tsepez4cf55152016-11-02 14:37:54 -07001235 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001236}
1237
Tom Sepezb1670b52017-02-16 17:01:00 -08001238bool Field::display(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001239 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04001240 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001241 if (vp.IsSetting()) {
1242 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001243 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001244
1245 int nVP;
1246 vp >> nVP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001247 if (m_bDelay) {
1248 AddDelay_Int(FP_DISPLAY, nVP);
1249 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001250 Field::SetDisplay(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07001251 nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001252 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001253 return true;
1254 }
1255 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1256 if (FieldArray.empty())
1257 return false;
1258
1259 CPDF_FormField* pFormField = FieldArray[0];
1260 ASSERT(pFormField);
1261 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1262 CPDFSDK_Widget* pWidget =
1263 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1264 if (!pWidget)
1265 return false;
1266
1267 uint32_t dwFlag = pWidget->GetFlags();
1268 if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag) {
1269 vp << (int32_t)1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001270 } else {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001271 if (ANNOTFLAG_PRINT & dwFlag) {
1272 if (ANNOTFLAG_NOVIEW & dwFlag) {
1273 vp << (int32_t)3;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001274 } else {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001275 vp << (int32_t)0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001276 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001277 } else {
1278 vp << (int32_t)2;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001279 }
1280 }
tsepez4cf55152016-11-02 14:37:54 -07001281 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001282}
1283
dsinclair3a7741a2016-10-11 10:39:49 -07001284void Field::SetDisplay(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04001285 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001286 int nControlIndex,
1287 int number) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001288 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001289 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07001290 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -08001291 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001292 if (nControlIndex < 0) {
tonikitoo7c05a7a2016-08-17 11:08:46 -07001293 bool bAnySet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001294 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1295 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08001296 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001297
dsinclairc5267c52016-11-04 15:35:12 -07001298 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
tonikitoo7c05a7a2016-08-17 11:08:46 -07001299 if (SetWidgetDisplayStatus(pWidget, number))
1300 bAnySet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001301 }
1302
tonikitoo7c05a7a2016-08-17 11:08:46 -07001303 if (bAnySet)
tsepez4cf55152016-11-02 14:37:54 -07001304 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001305 } else {
1306 if (nControlIndex >= pFormField->CountControls())
1307 return;
tonikitoo7c05a7a2016-08-17 11:08:46 -07001308
1309 CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex);
1310 if (!pFormControl)
1311 return;
1312
dsinclairc5267c52016-11-04 15:35:12 -07001313 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
tonikitoo7c05a7a2016-08-17 11:08:46 -07001314 if (SetWidgetDisplayStatus(pWidget, number))
tsepez4cf55152016-11-02 14:37:54 -07001315 UpdateFormControl(pFormFillEnv, pFormControl, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001316 }
1317 }
1318}
1319
Ryan Harrison275e2602017-09-18 14:23:18 -04001320bool Field::doc(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001321 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -07001322 return false;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001323
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001324 vp << m_pJSDoc->GetCJSDoc();
tsepez4cf55152016-11-02 14:37:54 -07001325 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001326}
1327
Tom Sepezb1670b52017-02-16 17:01:00 -08001328bool Field::editable(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001329 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04001330 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001331 if (vp.IsSetting()) {
1332 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001333 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001334
1335 bool bVP;
1336 vp >> bVP;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001337 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001338 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001339 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1340 if (FieldArray.empty())
1341 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001342
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001343 CPDF_FormField* pFormField = FieldArray[0];
1344 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX)
1345 return false;
1346
1347 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_EDIT);
tsepez4cf55152016-11-02 14:37:54 -07001348 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001349}
1350
Tom Sepezb1670b52017-02-16 17:01:00 -08001351bool Field::exportValues(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001352 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04001353 WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001354 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1355 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001356 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001357
Lei Zhangd88a3642015-11-10 09:38:57 -08001358 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001359 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001360 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) {
tsepez4cf55152016-11-02 14:37:54 -07001361 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001362 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001363 if (vp.IsSetting())
1364 return m_bCanSet && vp.GetJSValue()->IsArrayObject();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001365
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001366 CJS_Array ExportValusArray;
1367 if (m_nFormControlIndex < 0) {
1368 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
1369 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001370 ExportValusArray.SetElement(
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001371 pRuntime, i,
tsepeze5aff742016-08-08 09:49:42 -07001372 CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001373 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001374 } else {
1375 if (m_nFormControlIndex >= pFormField->CountControls())
1376 return false;
1377
1378 CPDF_FormControl* pFormControl =
1379 pFormField->GetControl(m_nFormControlIndex);
1380 if (!pFormControl)
1381 return false;
1382
1383 ExportValusArray.SetElement(
1384 pRuntime, 0,
1385 CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001386 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001387 vp << ExportValusArray;
tsepez4cf55152016-11-02 14:37:54 -07001388 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001389}
1390
Tom Sepezb1670b52017-02-16 17:01:00 -08001391bool Field::fileSelect(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001392 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04001393 WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001394 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1395 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001396 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001397
Lei Zhangd88a3642015-11-10 09:38:57 -08001398 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001399 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
tsepez4cf55152016-11-02 14:37:54 -07001400 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001401
1402 if (vp.IsSetting()) {
1403 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001404 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001405
1406 bool bVP;
1407 vp >> bVP;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001408 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001409 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001410 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT);
tsepez4cf55152016-11-02 14:37:54 -07001411 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001412}
1413
Tom Sepezb1670b52017-02-16 17:01:00 -08001414bool Field::fillColor(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001415 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04001416 WideString& sError) {
tsepeze5aff742016-08-08 09:49:42 -07001417 CJS_Array crArray;
Lei Zhangd88a3642015-11-10 09:38:57 -08001418 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1419 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001420 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001421
1422 if (vp.IsSetting()) {
1423 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001424 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001425
tsepezf3dc8c62016-08-10 06:29:29 -07001426 if (!vp.GetJSValue()->IsArrayObject())
tsepez4cf55152016-11-02 14:37:54 -07001427 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001428
1429 vp >> crArray;
1430
Dan Sinclair7f55a542017-07-13 14:17:10 -04001431 CFX_Color color;
tsepeze5aff742016-08-08 09:49:42 -07001432 color::ConvertArrayToPWLColor(pRuntime, crArray, &color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001433 if (m_bDelay) {
1434 AddDelay_Color(FP_FILLCOLOR, color);
1435 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001436 Field::SetFillColor(m_pFormFillEnv.Get(), m_FieldName,
1437 m_nFormControlIndex, color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001438 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001439 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001440 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001441 CPDF_FormField* pFormField = FieldArray[0];
1442 ASSERT(pFormField);
1443 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1444 if (!pFormControl)
1445 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001446
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001447 int iColorType;
1448 pFormControl->GetBackgroundColor(iColorType);
1449
Dan Sinclair7f55a542017-07-13 14:17:10 -04001450 CFX_Color color;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001451 if (iColorType == COLORTYPE_TRANSPARENT) {
Dan Sinclair7f55a542017-07-13 14:17:10 -04001452 color = CFX_Color(COLORTYPE_TRANSPARENT);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001453 } else if (iColorType == COLORTYPE_GRAY) {
1454 color =
Dan Sinclair7f55a542017-07-13 14:17:10 -04001455 CFX_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBackgroundColor(0));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001456 } else if (iColorType == COLORTYPE_RGB) {
1457 color =
Dan Sinclair7f55a542017-07-13 14:17:10 -04001458 CFX_Color(COLORTYPE_RGB, pFormControl->GetOriginalBackgroundColor(0),
1459 pFormControl->GetOriginalBackgroundColor(1),
1460 pFormControl->GetOriginalBackgroundColor(2));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001461 } else if (iColorType == COLORTYPE_CMYK) {
1462 color =
Dan Sinclair7f55a542017-07-13 14:17:10 -04001463 CFX_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBackgroundColor(0),
1464 pFormControl->GetOriginalBackgroundColor(1),
1465 pFormControl->GetOriginalBackgroundColor(2),
1466 pFormControl->GetOriginalBackgroundColor(3));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001467 } else {
1468 return false;
1469 }
1470 color::ConvertPWLColorToArray(pRuntime, color, &crArray);
1471 vp << crArray;
tsepez4cf55152016-11-02 14:37:54 -07001472 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001473}
1474
dsinclair3a7741a2016-10-11 10:39:49 -07001475void Field::SetFillColor(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04001476 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001477 int nControlIndex,
Dan Sinclair7f55a542017-07-13 14:17:10 -04001478 const CFX_Color& color) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001479 // Not supported.
1480}
1481
Tom Sepezb1670b52017-02-16 17:01:00 -08001482bool Field::hidden(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001483 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04001484 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001485 if (vp.IsSetting()) {
1486 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001487 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001488
1489 bool bVP;
1490 vp >> bVP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001491 if (m_bDelay) {
1492 AddDelay_Bool(FP_HIDDEN, bVP);
1493 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001494 Field::SetHidden(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07001495 bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001496 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001497 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001498 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001499 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1500 if (FieldArray.empty())
1501 return false;
1502
1503 CPDF_FormField* pFormField = FieldArray[0];
1504 ASSERT(pFormField);
1505 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1506 CPDFSDK_Widget* pWidget =
1507 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1508 if (!pWidget)
1509 return false;
1510
1511 uint32_t dwFlags = pWidget->GetFlags();
1512 if (ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags)
1513 vp << true;
1514 else
1515 vp << false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001516
tsepez4cf55152016-11-02 14:37:54 -07001517 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001518}
1519
dsinclair3a7741a2016-10-11 10:39:49 -07001520void Field::SetHidden(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04001521 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001522 int nControlIndex,
1523 bool b) {
tonikitooa73b8fe2016-08-22 14:06:49 -07001524 int display = b ? 1 /*Hidden*/ : 0 /*Visible*/;
dsinclair3a7741a2016-10-11 10:39:49 -07001525 SetDisplay(pFormFillEnv, swFieldName, nControlIndex, display);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001526}
1527
Tom Sepezb1670b52017-02-16 17:01:00 -08001528bool Field::highlight(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001529 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04001530 WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001531 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001532 if (vp.IsSetting()) {
1533 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001534 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001535
Ryan Harrison275e2602017-09-18 14:23:18 -04001536 ByteString strMode;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001537 vp >> strMode;
1538
1539 if (m_bDelay) {
1540 AddDelay_String(FP_HIGHLIGHT, strMode);
1541 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001542 Field::SetHighlight(m_pFormFillEnv.Get(), m_FieldName,
1543 m_nFormControlIndex, strMode);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001544 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001545 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001546 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001547 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1548 if (FieldArray.empty())
1549 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001550
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001551 CPDF_FormField* pFormField = FieldArray[0];
1552 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
1553 return false;
1554
1555 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1556 if (!pFormControl)
1557 return false;
1558
1559 int eHM = pFormControl->GetHighlightingMode();
1560 switch (eHM) {
1561 case CPDF_FormControl::None:
1562 vp << L"none";
1563 break;
1564 case CPDF_FormControl::Push:
1565 vp << L"push";
1566 break;
1567 case CPDF_FormControl::Invert:
1568 vp << L"invert";
1569 break;
1570 case CPDF_FormControl::Outline:
1571 vp << L"outline";
1572 break;
1573 case CPDF_FormControl::Toggle:
1574 vp << L"toggle";
1575 break;
1576 }
tsepez4cf55152016-11-02 14:37:54 -07001577 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001578}
1579
dsinclair3a7741a2016-10-11 10:39:49 -07001580void Field::SetHighlight(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04001581 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001582 int nControlIndex,
Ryan Harrison275e2602017-09-18 14:23:18 -04001583 const ByteString& string) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001584 // Not supported.
1585}
1586
Tom Sepezb1670b52017-02-16 17:01:00 -08001587bool Field::lineWidth(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001588 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04001589 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001590 if (vp.IsSetting()) {
1591 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001592 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001593
1594 int iWidth;
1595 vp >> iWidth;
1596
1597 if (m_bDelay) {
1598 AddDelay_Int(FP_LINEWIDTH, iWidth);
1599 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001600 Field::SetLineWidth(m_pFormFillEnv.Get(), m_FieldName,
1601 m_nFormControlIndex, iWidth);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001602 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001603 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001604 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001605 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1606 if (FieldArray.empty())
1607 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001608
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001609 CPDF_FormField* pFormField = FieldArray[0];
1610 ASSERT(pFormField);
1611 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1612 if (!pFormControl)
1613 return false;
1614
1615 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1616 if (!pFormField->CountControls())
1617 return false;
1618
1619 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
1620 if (!pWidget)
1621 return false;
1622
1623 vp << (int32_t)pWidget->GetBorderWidth();
tsepez4cf55152016-11-02 14:37:54 -07001624 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001625}
1626
dsinclair3a7741a2016-10-11 10:39:49 -07001627void Field::SetLineWidth(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04001628 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001629 int nControlIndex,
1630 int number) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001631 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001632 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07001633 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -08001634 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001635 if (nControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -07001636 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001637 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1638 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08001639 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001640
dsinclairc5267c52016-11-04 15:35:12 -07001641 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001642 if (number != pWidget->GetBorderWidth()) {
1643 pWidget->SetBorderWidth(number);
tsepez4cf55152016-11-02 14:37:54 -07001644 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001645 }
1646 }
1647 }
1648 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -07001649 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001650 } else {
1651 if (nControlIndex >= pFormField->CountControls())
1652 return;
1653 if (CPDF_FormControl* pFormControl =
1654 pFormField->GetControl(nControlIndex)) {
dsinclairc5267c52016-11-04 15:35:12 -07001655 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001656 if (number != pWidget->GetBorderWidth()) {
1657 pWidget->SetBorderWidth(number);
tsepez4cf55152016-11-02 14:37:54 -07001658 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001659 }
1660 }
1661 }
1662 }
1663 }
1664}
1665
Tom Sepezb1670b52017-02-16 17:01:00 -08001666bool Field::multiline(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001667 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04001668 WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001669 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001670
1671 if (vp.IsSetting()) {
1672 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001673 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001674
1675 bool bVP;
1676 vp >> bVP;
1677
1678 if (m_bDelay) {
1679 AddDelay_Bool(FP_MULTILINE, bVP);
1680 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001681 Field::SetMultiline(m_pFormFillEnv.Get(), m_FieldName,
1682 m_nFormControlIndex, bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001683 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001684 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001685 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001686 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1687 if (FieldArray.empty())
1688 return false;
1689
1690 CPDF_FormField* pFormField = FieldArray[0];
1691 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1692 return false;
1693
1694 if (pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE)
1695 vp << true;
1696 else
1697 vp << false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001698
tsepez4cf55152016-11-02 14:37:54 -07001699 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001700}
1701
dsinclair3a7741a2016-10-11 10:39:49 -07001702void Field::SetMultiline(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04001703 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001704 int nControlIndex,
1705 bool b) {
1706 // Not supported.
1707}
1708
Tom Sepezb1670b52017-02-16 17:01:00 -08001709bool Field::multipleSelection(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001710 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04001711 WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001712 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001713 if (vp.IsSetting()) {
1714 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001715 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001716
1717 bool bVP;
1718 vp >> bVP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001719 if (m_bDelay) {
1720 AddDelay_Bool(FP_MULTIPLESELECTION, bVP);
1721 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001722 Field::SetMultipleSelection(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -07001723 m_nFormControlIndex, bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001724 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001725 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001726 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001727 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1728 if (FieldArray.empty())
1729 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001730
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001731 CPDF_FormField* pFormField = FieldArray[0];
1732 if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
1733 return false;
1734
1735 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT);
tsepez4cf55152016-11-02 14:37:54 -07001736 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001737}
1738
dsinclair3a7741a2016-10-11 10:39:49 -07001739void Field::SetMultipleSelection(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04001740 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001741 int nControlIndex,
1742 bool b) {
1743 // Not supported.
1744}
1745
Ryan Harrison275e2602017-09-18 14:23:18 -04001746bool Field::name(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001747 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -07001748 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001749
Lei Zhangd88a3642015-11-10 09:38:57 -08001750 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1751 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001752 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001753
1754 vp << m_FieldName;
tsepez4cf55152016-11-02 14:37:54 -07001755 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001756}
1757
Tom Sepezb1670b52017-02-16 17:01:00 -08001758bool Field::numItems(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001759 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04001760 WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07001761 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -07001762 return false;
Tom Sepez67fd5df2015-10-08 12:24:19 -07001763
Lei Zhangd88a3642015-11-10 09:38:57 -08001764 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1765 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001766 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001767
Lei Zhangd88a3642015-11-10 09:38:57 -08001768 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001769 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001770 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
tsepez4cf55152016-11-02 14:37:54 -07001771 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001772 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001773
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001774 vp << (int32_t)pFormField->CountOptions();
tsepez4cf55152016-11-02 14:37:54 -07001775 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001776}
1777
Ryan Harrison275e2602017-09-18 14:23:18 -04001778bool Field::page(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) {
tsepez8fa82792017-01-11 09:32:33 -08001779 if (!vp.IsGetting()) {
1780 sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
tsepez4cf55152016-11-02 14:37:54 -07001781 return false;
tsepez8fa82792017-01-11 09:32:33 -08001782 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001783
Lei Zhangd88a3642015-11-10 09:38:57 -08001784 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1785 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001786 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001787
Lei Zhangd88a3642015-11-10 09:38:57 -08001788 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001789 if (!pFormField)
tsepez4cf55152016-11-02 14:37:54 -07001790 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001791
tsepez8fa82792017-01-11 09:32:33 -08001792 std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
dsinclair7cbe68e2016-10-12 11:56:23 -07001793 m_pFormFillEnv->GetInterForm()->GetWidgets(pFormField, &widgets);
Lei Zhangd88a3642015-11-10 09:38:57 -08001794 if (widgets.empty()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001795 vp << (int32_t)-1;
tsepez4cf55152016-11-02 14:37:54 -07001796 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001797 }
1798
tsepeze5aff742016-08-08 09:49:42 -07001799 CJS_Array PageArray;
tsepez8fa82792017-01-11 09:32:33 -08001800 int i = 0;
1801 for (const auto& pObserved : widgets) {
1802 if (!pObserved) {
1803 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
1804 return false;
1805 }
1806
Lei Zhang375c2762017-03-10 14:37:14 -08001807 auto* pWidget = static_cast<CPDFSDK_Widget*>(pObserved.Get());
tsepez8fa82792017-01-11 09:32:33 -08001808 CPDFSDK_PageView* pPageView = pWidget->GetPageView();
Lei Zhangd88a3642015-11-10 09:38:57 -08001809 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -07001810 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001811
1812 PageArray.SetElement(
tsepezb4694242016-08-15 16:44:55 -07001813 pRuntime, i, CJS_Value(pRuntime, (int32_t)pPageView->GetPageIndex()));
tsepez8fa82792017-01-11 09:32:33 -08001814 ++i;
Lei Zhangd88a3642015-11-10 09:38:57 -08001815 }
1816
1817 vp << PageArray;
tsepez4cf55152016-11-02 14:37:54 -07001818 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001819}
1820
Tom Sepezb1670b52017-02-16 17:01:00 -08001821bool Field::password(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001822 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04001823 WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001824 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001825
1826 if (vp.IsSetting()) {
1827 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001828 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001829
1830 bool bVP;
1831 vp >> bVP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001832 if (m_bDelay) {
1833 AddDelay_Bool(FP_PASSWORD, bVP);
1834 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001835 Field::SetPassword(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07001836 bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001837 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001838 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001839 }
1840
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001841 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1842 if (FieldArray.empty())
1843 return false;
1844
1845 CPDF_FormField* pFormField = FieldArray[0];
1846 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1847 return false;
1848
1849 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD);
tsepez4cf55152016-11-02 14:37:54 -07001850 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001851}
1852
dsinclair3a7741a2016-10-11 10:39:49 -07001853void Field::SetPassword(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04001854 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001855 int nControlIndex,
1856 bool b) {
1857 // Not supported.
1858}
1859
Tom Sepezb1670b52017-02-16 17:01:00 -08001860bool Field::print(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001861 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04001862 WideString& sError) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001863 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001864 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1865 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001866 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001867
1868 if (vp.IsSetting()) {
1869 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001870 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001871
1872 bool bVP;
1873 vp >> bVP;
1874
Lei Zhangd88a3642015-11-10 09:38:57 -08001875 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001876 if (m_nFormControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -07001877 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001878 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001879 if (CPDFSDK_Widget* pWidget =
dsinclairc5267c52016-11-04 15:35:12 -07001880 pInterForm->GetWidget(pFormField->GetControl(i))) {
tsepezc3255f52016-03-25 14:52:27 -07001881 uint32_t dwFlags = pWidget->GetFlags();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001882 if (bVP)
1883 dwFlags |= ANNOTFLAG_PRINT;
1884 else
1885 dwFlags &= ~ANNOTFLAG_PRINT;
1886
1887 if (dwFlags != pWidget->GetFlags()) {
1888 pWidget->SetFlags(dwFlags);
tsepez4cf55152016-11-02 14:37:54 -07001889 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001890 }
1891 }
1892 }
1893
1894 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -07001895 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001896 } else {
1897 if (m_nFormControlIndex >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07001898 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001899 if (CPDF_FormControl* pFormControl =
1900 pFormField->GetControl(m_nFormControlIndex)) {
dsinclairc5267c52016-11-04 15:35:12 -07001901 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
tsepezc3255f52016-03-25 14:52:27 -07001902 uint32_t dwFlags = pWidget->GetFlags();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001903 if (bVP)
1904 dwFlags |= ANNOTFLAG_PRINT;
1905 else
1906 dwFlags &= ~ANNOTFLAG_PRINT;
1907
1908 if (dwFlags != pWidget->GetFlags()) {
1909 pWidget->SetFlags(dwFlags);
dsinclair3a7741a2016-10-11 10:39:49 -07001910 UpdateFormControl(m_pFormFillEnv.Get(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001911 pFormField->GetControl(m_nFormControlIndex),
tsepez4cf55152016-11-02 14:37:54 -07001912 true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001913 }
1914 }
1915 }
1916 }
1917 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001918 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001919 }
1920
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001921 CPDF_FormField* pFormField = FieldArray[0];
1922 CPDFSDK_Widget* pWidget =
1923 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1924 if (!pWidget)
1925 return false;
1926
1927 vp << !!(pWidget->GetFlags() & ANNOTFLAG_PRINT);
tsepez4cf55152016-11-02 14:37:54 -07001928 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001929}
1930
Tom Sepezb1670b52017-02-16 17:01:00 -08001931bool Field::radiosInUnison(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001932 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04001933 WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001934 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1935 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001936 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001937
1938 if (vp.IsSetting()) {
1939 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001940 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001941
1942 bool bVP;
1943 vp >> bVP;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001944 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001945 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001946 CPDF_FormField* pFormField = FieldArray[0];
1947 if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
1948 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001949
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001950 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON);
tsepez4cf55152016-11-02 14:37:54 -07001951 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001952}
1953
Tom Sepezb1670b52017-02-16 17:01:00 -08001954bool Field::readonly(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001955 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04001956 WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001957 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1958 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001959 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001960
1961 if (vp.IsSetting()) {
1962 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001963 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001964
1965 bool bVP;
1966 vp >> bVP;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001967 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001968 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001969 vp << !!(FieldArray[0]->GetFieldFlags() & FIELDFLAG_READONLY);
tsepez4cf55152016-11-02 14:37:54 -07001970 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001971}
1972
Ryan Harrison275e2602017-09-18 14:23:18 -04001973bool Field::rect(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07001974 CJS_Value Upper_Leftx(pRuntime);
1975 CJS_Value Upper_Lefty(pRuntime);
1976 CJS_Value Lower_Rightx(pRuntime);
1977 CJS_Value Lower_Righty(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001978
1979 if (vp.IsSetting()) {
1980 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001981 return false;
tsepezf3dc8c62016-08-10 06:29:29 -07001982 if (!vp.GetJSValue()->IsArrayObject())
tsepez4cf55152016-11-02 14:37:54 -07001983 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001984
tsepeze5aff742016-08-08 09:49:42 -07001985 CJS_Array rcArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001986 vp >> rcArray;
tsepezb4694242016-08-15 16:44:55 -07001987 rcArray.GetElement(pRuntime, 0, Upper_Leftx);
1988 rcArray.GetElement(pRuntime, 1, Upper_Lefty);
1989 rcArray.GetElement(pRuntime, 2, Lower_Rightx);
1990 rcArray.GetElement(pRuntime, 3, Lower_Righty);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001991
Dan Sinclair05df0752017-03-14 14:43:42 -04001992 float pArray[4] = {0.0f, 0.0f, 0.0f, 0.0f};
1993 pArray[0] = static_cast<float>(Upper_Leftx.ToInt(pRuntime));
1994 pArray[1] = static_cast<float>(Lower_Righty.ToInt(pRuntime));
1995 pArray[2] = static_cast<float>(Lower_Rightx.ToInt(pRuntime));
1996 pArray[3] = static_cast<float>(Upper_Lefty.ToInt(pRuntime));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001997
Tom Sepez281a9ea2016-02-26 14:24:28 -08001998 CFX_FloatRect crRect(pArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001999 if (m_bDelay) {
2000 AddDelay_Rect(FP_RECT, crRect);
2001 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002002 Field::SetRect(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07002003 crRect);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002004 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002005 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002006 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002007 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2008 if (FieldArray.empty())
2009 return false;
2010
2011 CPDF_FormField* pFormField = FieldArray[0];
2012 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
2013 CPDFSDK_Widget* pWidget =
2014 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
2015 if (!pWidget)
2016 return false;
2017
2018 CFX_FloatRect crRect = pWidget->GetRect();
2019 Upper_Leftx = CJS_Value(pRuntime, static_cast<int32_t>(crRect.left));
2020 Upper_Lefty = CJS_Value(pRuntime, static_cast<int32_t>(crRect.top));
2021 Lower_Rightx = CJS_Value(pRuntime, static_cast<int32_t>(crRect.right));
2022 Lower_Righty = CJS_Value(pRuntime, static_cast<int32_t>(crRect.bottom));
2023
2024 CJS_Array rcArray;
2025 rcArray.SetElement(pRuntime, 0, Upper_Leftx);
2026 rcArray.SetElement(pRuntime, 1, Upper_Lefty);
2027 rcArray.SetElement(pRuntime, 2, Lower_Rightx);
2028 rcArray.SetElement(pRuntime, 3, Lower_Righty);
2029 vp << rcArray;
tsepez4cf55152016-11-02 14:37:54 -07002030 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002031}
2032
dsinclair3a7741a2016-10-11 10:39:49 -07002033void Field::SetRect(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04002034 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002035 int nControlIndex,
Tom Sepez281a9ea2016-02-26 14:24:28 -08002036 const CFX_FloatRect& rect) {
dsinclair7cbe68e2016-10-12 11:56:23 -07002037 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08002038 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07002039 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -08002040 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002041 if (nControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -07002042 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08002043 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002044 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08002045 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002046
dsinclairc5267c52016-11-04 15:35:12 -07002047 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002048 CFX_FloatRect crRect = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002049
2050 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002051 crRect.Intersect(pPDFPage->GetPageBBox());
2052
2053 if (!crRect.IsEmpty()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002054 CFX_FloatRect rcOld = pWidget->GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002055 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
2056 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
2057 pWidget->SetRect(crRect);
tsepez4cf55152016-11-02 14:37:54 -07002058 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002059 }
2060 }
2061 }
2062 }
2063
2064 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -07002065 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002066 } else {
2067 if (nControlIndex >= pFormField->CountControls())
2068 return;
2069 if (CPDF_FormControl* pFormControl =
2070 pFormField->GetControl(nControlIndex)) {
dsinclairc5267c52016-11-04 15:35:12 -07002071 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002072 CFX_FloatRect crRect = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002073
2074 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002075 crRect.Intersect(pPDFPage->GetPageBBox());
2076
2077 if (!crRect.IsEmpty()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002078 CFX_FloatRect rcOld = pWidget->GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002079 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
2080 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
2081 pWidget->SetRect(crRect);
tsepez4cf55152016-11-02 14:37:54 -07002082 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002083 }
2084 }
2085 }
2086 }
2087 }
2088 }
2089}
2090
Tom Sepezb1670b52017-02-16 17:01:00 -08002091bool Field::required(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002092 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04002093 WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002094 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2095 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002096 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002097
2098 if (vp.IsSetting()) {
2099 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002100 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002101
2102 bool bVP;
2103 vp >> bVP;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002104 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002105 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002106 CPDF_FormField* pFormField = FieldArray[0];
2107 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
2108 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002109
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002110 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED);
tsepez4cf55152016-11-02 14:37:54 -07002111 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002112}
2113
Tom Sepezb1670b52017-02-16 17:01:00 -08002114bool Field::richText(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002115 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04002116 WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002117 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002118
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002119 if (vp.IsSetting()) {
2120 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002121 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002122
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002123 bool bVP;
2124 vp >> bVP;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002125 if (m_bDelay)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002126 AddDelay_Bool(FP_RICHTEXT, bVP);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002127
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002128 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002129 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002130
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002131 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2132 if (FieldArray.empty())
2133 return false;
2134
2135 CPDF_FormField* pFormField = FieldArray[0];
2136 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
2137 return false;
2138
2139 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT);
tsepez4cf55152016-11-02 14:37:54 -07002140 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002141}
2142
Tom Sepezb1670b52017-02-16 17:01:00 -08002143bool Field::richValue(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002144 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04002145 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002146 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002147}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002148
Tom Sepezb1670b52017-02-16 17:01:00 -08002149bool Field::rotation(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002150 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04002151 WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002152 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002153
2154 if (vp.IsSetting()) {
2155 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002156 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002157
2158 int nVP;
2159 vp >> nVP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002160 if (m_bDelay) {
2161 AddDelay_Int(FP_ROTATION, nVP);
2162 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002163 Field::SetRotation(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07002164 nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002165 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002166 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002167 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002168 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2169 if (FieldArray.empty())
2170 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002171
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002172 CPDF_FormField* pFormField = FieldArray[0];
2173 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2174 if (!pFormControl)
2175 return false;
2176
2177 vp << (int32_t)pFormControl->GetRotation();
tsepez4cf55152016-11-02 14:37:54 -07002178 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002179}
2180
dsinclair3a7741a2016-10-11 10:39:49 -07002181void Field::SetRotation(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04002182 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002183 int nControlIndex,
2184 int number) {
2185 // Not supported.
2186}
2187
Tom Sepezb1670b52017-02-16 17:01:00 -08002188bool Field::strokeColor(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002189 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04002190 WideString& sError) {
tsepeze5aff742016-08-08 09:49:42 -07002191 CJS_Array crArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002192
2193 if (vp.IsSetting()) {
2194 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002195 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002196
tsepezf3dc8c62016-08-10 06:29:29 -07002197 if (!vp.GetJSValue()->IsArrayObject())
tsepez4cf55152016-11-02 14:37:54 -07002198 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002199
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002200 vp >> crArray;
2201
Dan Sinclair7f55a542017-07-13 14:17:10 -04002202 CFX_Color color;
tsepeze5aff742016-08-08 09:49:42 -07002203 color::ConvertArrayToPWLColor(pRuntime, crArray, &color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002204 if (m_bDelay) {
2205 AddDelay_Color(FP_STROKECOLOR, color);
2206 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002207 Field::SetStrokeColor(m_pFormFillEnv.Get(), m_FieldName,
2208 m_nFormControlIndex, color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002209 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002210 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002211 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002212 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2213 if (FieldArray.empty())
2214 return false;
2215
2216 CPDF_FormField* pFormField = FieldArray[0];
2217 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2218 if (!pFormControl)
2219 return false;
2220
2221 int iColorType;
2222 pFormControl->GetBorderColor(iColorType);
2223
Dan Sinclair7f55a542017-07-13 14:17:10 -04002224 CFX_Color color;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002225 if (iColorType == COLORTYPE_TRANSPARENT) {
Dan Sinclair7f55a542017-07-13 14:17:10 -04002226 color = CFX_Color(COLORTYPE_TRANSPARENT);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002227 } else if (iColorType == COLORTYPE_GRAY) {
Dan Sinclair7f55a542017-07-13 14:17:10 -04002228 color = CFX_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBorderColor(0));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002229 } else if (iColorType == COLORTYPE_RGB) {
Dan Sinclair7f55a542017-07-13 14:17:10 -04002230 color = CFX_Color(COLORTYPE_RGB, pFormControl->GetOriginalBorderColor(0),
2231 pFormControl->GetOriginalBorderColor(1),
2232 pFormControl->GetOriginalBorderColor(2));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002233 } else if (iColorType == COLORTYPE_CMYK) {
Dan Sinclair7f55a542017-07-13 14:17:10 -04002234 color = CFX_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBorderColor(0),
2235 pFormControl->GetOriginalBorderColor(1),
2236 pFormControl->GetOriginalBorderColor(2),
2237 pFormControl->GetOriginalBorderColor(3));
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002238 } else {
2239 return false;
2240 }
2241
2242 color::ConvertPWLColorToArray(pRuntime, color, &crArray);
2243 vp << crArray;
tsepez4cf55152016-11-02 14:37:54 -07002244 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002245}
2246
dsinclair3a7741a2016-10-11 10:39:49 -07002247void Field::SetStrokeColor(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04002248 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002249 int nControlIndex,
Dan Sinclair7f55a542017-07-13 14:17:10 -04002250 const CFX_Color& color) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002251 // Not supported.
2252}
2253
Tom Sepezb1670b52017-02-16 17:01:00 -08002254bool Field::style(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002255 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04002256 WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002257 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002258
2259 if (vp.IsSetting()) {
2260 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002261 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002262
Ryan Harrison275e2602017-09-18 14:23:18 -04002263 ByteString csBCaption;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002264 vp >> csBCaption;
2265
2266 if (m_bDelay) {
2267 AddDelay_String(FP_STYLE, csBCaption);
2268 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002269 Field::SetStyle(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002270 csBCaption);
2271 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002272 return true;
2273 }
2274 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2275 if (FieldArray.empty())
2276 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002277
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002278 CPDF_FormField* pFormField = FieldArray[0];
2279 if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON &&
2280 pFormField->GetFieldType() != FIELDTYPE_CHECKBOX) {
2281 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002282 }
2283
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002284 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2285 if (!pFormControl)
2286 return false;
2287
Ryan Harrison275e2602017-09-18 14:23:18 -04002288 WideString csWCaption = pFormControl->GetNormalCaption();
2289 ByteString csBCaption;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002290
2291 switch (csWCaption[0]) {
2292 case L'l':
2293 csBCaption = "circle";
2294 break;
2295 case L'8':
2296 csBCaption = "cross";
2297 break;
2298 case L'u':
2299 csBCaption = "diamond";
2300 break;
2301 case L'n':
2302 csBCaption = "square";
2303 break;
2304 case L'H':
2305 csBCaption = "star";
2306 break;
2307 default: // L'4'
2308 csBCaption = "check";
2309 break;
2310 }
2311 vp << csBCaption;
tsepez4cf55152016-11-02 14:37:54 -07002312 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002313}
2314
dsinclair3a7741a2016-10-11 10:39:49 -07002315void Field::SetStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04002316 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002317 int nControlIndex,
Ryan Harrison275e2602017-09-18 14:23:18 -04002318 const ByteString& string) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002319 // Not supported.
2320}
2321
Tom Sepezb1670b52017-02-16 17:01:00 -08002322bool Field::submitName(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002323 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04002324 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002325 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002326}
2327
Tom Sepezb1670b52017-02-16 17:01:00 -08002328bool Field::textColor(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002329 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04002330 WideString& sError) {
tsepeze5aff742016-08-08 09:49:42 -07002331 CJS_Array crArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002332
2333 if (vp.IsSetting()) {
2334 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002335 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002336
tsepezf3dc8c62016-08-10 06:29:29 -07002337 if (!vp.GetJSValue()->IsArrayObject())
tsepez4cf55152016-11-02 14:37:54 -07002338 return false;
Tom Sepez67fd5df2015-10-08 12:24:19 -07002339
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002340 vp >> crArray;
2341
Dan Sinclair7f55a542017-07-13 14:17:10 -04002342 CFX_Color color;
tsepeze5aff742016-08-08 09:49:42 -07002343 color::ConvertArrayToPWLColor(pRuntime, crArray, &color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002344 if (m_bDelay) {
2345 AddDelay_Color(FP_TEXTCOLOR, color);
2346 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002347 Field::SetTextColor(m_pFormFillEnv.Get(), m_FieldName,
2348 m_nFormControlIndex, color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002349 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002350 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002351 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002352 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2353 if (FieldArray.empty())
2354 return false;
2355
2356 CPDF_FormField* pFormField = FieldArray[0];
2357 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2358 if (!pFormControl)
2359 return false;
2360
2361 int iColorType;
2362 FX_ARGB color;
2363 CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
2364 FieldAppearance.GetColor(color, iColorType);
2365
2366 int32_t a;
2367 int32_t r;
2368 int32_t g;
2369 int32_t b;
Nicolas Penaddfc3dc2017-04-20 15:29:25 -04002370 std::tie(a, r, g, b) = ArgbDecode(color);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002371
Dan Sinclair7f55a542017-07-13 14:17:10 -04002372 CFX_Color crRet =
2373 CFX_Color(COLORTYPE_RGB, r / 255.0f, g / 255.0f, b / 255.0f);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002374
2375 if (iColorType == COLORTYPE_TRANSPARENT)
Dan Sinclair7f55a542017-07-13 14:17:10 -04002376 crRet = CFX_Color(COLORTYPE_TRANSPARENT);
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002377
2378 color::ConvertPWLColorToArray(pRuntime, crRet, &crArray);
2379 vp << crArray;
tsepez4cf55152016-11-02 14:37:54 -07002380 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002381}
2382
dsinclair3a7741a2016-10-11 10:39:49 -07002383void Field::SetTextColor(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04002384 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002385 int nControlIndex,
Dan Sinclair7f55a542017-07-13 14:17:10 -04002386 const CFX_Color& color) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002387 // Not supported.
2388}
2389
Tom Sepezb1670b52017-02-16 17:01:00 -08002390bool Field::textFont(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002391 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04002392 WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002393 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002394
2395 if (vp.IsSetting()) {
2396 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002397 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002398
Ryan Harrison275e2602017-09-18 14:23:18 -04002399 ByteString csFontName;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002400 vp >> csFontName;
2401 if (csFontName.IsEmpty())
tsepez4cf55152016-11-02 14:37:54 -07002402 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002403
2404 if (m_bDelay) {
2405 AddDelay_String(FP_TEXTFONT, csFontName);
2406 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002407 Field::SetTextFont(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002408 csFontName);
2409 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002410 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002411 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002412 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2413 if (FieldArray.empty())
2414 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002415
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002416 CPDF_FormField* pFormField = FieldArray[0];
2417 ASSERT(pFormField);
2418 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2419 if (!pFormControl)
2420 return false;
2421
2422 int nFieldType = pFormField->GetFieldType();
2423 if (nFieldType != FIELDTYPE_PUSHBUTTON && nFieldType != FIELDTYPE_COMBOBOX &&
2424 nFieldType != FIELDTYPE_LISTBOX && nFieldType != FIELDTYPE_TEXTFIELD) {
2425 return false;
2426 }
2427 CPDF_Font* pFont = pFormControl->GetDefaultControlFont();
2428 if (!pFont)
2429 return false;
2430
2431 vp << pFont->GetBaseFont();
tsepez4cf55152016-11-02 14:37:54 -07002432 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002433}
2434
dsinclair3a7741a2016-10-11 10:39:49 -07002435void Field::SetTextFont(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04002436 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002437 int nControlIndex,
Ryan Harrison275e2602017-09-18 14:23:18 -04002438 const ByteString& string) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002439 // Not supported.
2440}
2441
Tom Sepezb1670b52017-02-16 17:01:00 -08002442bool Field::textSize(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002443 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04002444 WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002445 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002446
2447 if (vp.IsSetting()) {
2448 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002449 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002450
2451 int nVP;
2452 vp >> nVP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002453 if (m_bDelay) {
2454 AddDelay_Int(FP_TEXTSIZE, nVP);
2455 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002456 Field::SetTextSize(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07002457 nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002458 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002459 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002460 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002461 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2462 if (FieldArray.empty())
2463 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002464
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002465 CPDF_FormField* pFormField = FieldArray[0];
2466 ASSERT(pFormField);
2467 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2468 if (!pFormControl)
2469 return false;
2470
Dan Sinclair05df0752017-03-14 14:43:42 -04002471 float fFontSize;
Tom Sepezc4a2b752017-04-07 13:56:13 -07002472 CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
2473 FieldAppearance.GetFont(&fFontSize);
2474 vp << static_cast<int>(fFontSize);
tsepez4cf55152016-11-02 14:37:54 -07002475 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002476}
2477
dsinclair3a7741a2016-10-11 10:39:49 -07002478void Field::SetTextSize(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04002479 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002480 int nControlIndex,
2481 int number) {
2482 // Not supported.
2483}
2484
Ryan Harrison275e2602017-09-18 14:23:18 -04002485bool Field::type(CJS_Runtime* pRuntime, CJS_PropValue& vp, WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002486 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -07002487 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002488
Lei Zhangd88a3642015-11-10 09:38:57 -08002489 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2490 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002491 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002492
Lei Zhangd88a3642015-11-10 09:38:57 -08002493 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002494 switch (pFormField->GetFieldType()) {
2495 case FIELDTYPE_UNKNOWN:
2496 vp << L"unknown";
2497 break;
2498 case FIELDTYPE_PUSHBUTTON:
2499 vp << L"button";
2500 break;
2501 case FIELDTYPE_CHECKBOX:
2502 vp << L"checkbox";
2503 break;
2504 case FIELDTYPE_RADIOBUTTON:
2505 vp << L"radiobutton";
2506 break;
2507 case FIELDTYPE_COMBOBOX:
2508 vp << L"combobox";
2509 break;
2510 case FIELDTYPE_LISTBOX:
2511 vp << L"listbox";
2512 break;
2513 case FIELDTYPE_TEXTFIELD:
2514 vp << L"text";
2515 break;
2516 case FIELDTYPE_SIGNATURE:
2517 vp << L"signature";
2518 break;
2519 default:
2520 vp << L"unknown";
2521 break;
2522 }
tsepez4cf55152016-11-02 14:37:54 -07002523 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002524}
2525
Tom Sepezb1670b52017-02-16 17:01:00 -08002526bool Field::userName(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002527 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04002528 WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002529 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002530
2531 if (vp.IsSetting()) {
2532 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002533 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002534
Ryan Harrison275e2602017-09-18 14:23:18 -04002535 WideString swName;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002536 vp >> swName;
2537
2538 if (m_bDelay) {
2539 AddDelay_WideString(FP_USERNAME, swName);
2540 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002541 Field::SetUserName(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07002542 swName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002543 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002544 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002545 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002546 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2547 if (FieldArray.empty())
2548 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002549
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002550 vp << FieldArray[0]->GetAlternateName();
tsepez4cf55152016-11-02 14:37:54 -07002551 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002552}
2553
dsinclair3a7741a2016-10-11 10:39:49 -07002554void Field::SetUserName(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04002555 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002556 int nControlIndex,
Ryan Harrison275e2602017-09-18 14:23:18 -04002557 const WideString& string) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002558 // Not supported.
2559}
2560
Tom Sepezb1670b52017-02-16 17:01:00 -08002561bool Field::value(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002562 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04002563 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002564 if (vp.IsSetting()) {
2565 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002566 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002567
Ryan Harrison275e2602017-09-18 14:23:18 -04002568 std::vector<WideString> strArray;
tsepezf3dc8c62016-08-10 06:29:29 -07002569 if (vp.GetJSValue()->IsArrayObject()) {
tsepeze5aff742016-08-08 09:49:42 -07002570 CJS_Array ValueArray;
tsepezb4694242016-08-15 16:44:55 -07002571 vp.GetJSValue()->ConvertToArray(pRuntime, ValueArray);
2572 for (int i = 0, sz = ValueArray.GetLength(pRuntime); i < sz; i++) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002573 CJS_Value ElementValue(pRuntime);
tsepezb4694242016-08-15 16:44:55 -07002574 ValueArray.GetElement(pRuntime, i, ElementValue);
2575 strArray.push_back(ElementValue.ToCFXWideString(pRuntime));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002576 }
2577 } else {
Ryan Harrison275e2602017-09-18 14:23:18 -04002578 WideString swValue;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002579 vp >> swValue;
tsepez41a53ad2016-03-28 16:59:30 -07002580 strArray.push_back(swValue);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002581 }
2582
2583 if (m_bDelay) {
2584 AddDelay_WideStringArray(FP_VALUE, strArray);
2585 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002586 Field::SetValue(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07002587 strArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002588 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002589 return true;
2590 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002591
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002592 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2593 if (FieldArray.empty())
2594 return false;
2595
2596 CPDF_FormField* pFormField = FieldArray[0];
2597 switch (pFormField->GetFieldType()) {
2598 case FIELDTYPE_PUSHBUTTON:
2599 return false;
2600 case FIELDTYPE_COMBOBOX:
2601 case FIELDTYPE_TEXTFIELD: {
2602 vp << pFormField->GetValue();
2603 } break;
2604 case FIELDTYPE_LISTBOX: {
2605 if (pFormField->CountSelectedItems() > 1) {
2606 CJS_Array ValueArray;
2607 CJS_Value ElementValue(pRuntime);
2608 int iIndex;
2609 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
2610 iIndex = pFormField->GetSelectedIndex(i);
2611 ElementValue =
2612 CJS_Value(pRuntime, pFormField->GetOptionValue(iIndex).c_str());
Ryan Harrison8b1408e2017-09-27 11:07:51 -04002613 if (wcslen(ElementValue.ToCFXWideString(pRuntime).c_str()) == 0) {
tsepezf3dc8c62016-08-10 06:29:29 -07002614 ElementValue =
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002615 CJS_Value(pRuntime, pFormField->GetOptionLabel(iIndex).c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002616 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002617 ValueArray.SetElement(pRuntime, i, ElementValue);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002618 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002619 vp << ValueArray;
2620 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002621 vp << pFormField->GetValue();
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002622 }
2623 } break;
2624 case FIELDTYPE_CHECKBOX:
2625 case FIELDTYPE_RADIOBUTTON: {
2626 bool bFind = false;
2627 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2628 if (pFormField->GetControl(i)->IsChecked()) {
2629 vp << pFormField->GetControl(i)->GetExportValue();
2630 bFind = true;
2631 break;
2632 }
2633 }
2634 if (!bFind)
2635 vp << L"Off";
2636 } break;
2637 default:
2638 vp << pFormField->GetValue();
2639 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002640 }
tsepezb4694242016-08-15 16:44:55 -07002641 vp.GetJSValue()->MaybeCoerceToNumber(pRuntime);
tsepez4cf55152016-11-02 14:37:54 -07002642 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002643}
2644
dsinclair3a7741a2016-10-11 10:39:49 -07002645void Field::SetValue(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Ryan Harrison275e2602017-09-18 14:23:18 -04002646 const WideString& swFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002647 int nControlIndex,
Ryan Harrison275e2602017-09-18 14:23:18 -04002648 const std::vector<WideString>& strArray) {
dsinclair3a7741a2016-10-11 10:39:49 -07002649 ASSERT(pFormFillEnv);
tsepez41a53ad2016-03-28 16:59:30 -07002650 if (strArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002651 return;
2652
Lei Zhangd88a3642015-11-10 09:38:57 -08002653 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07002654 GetFormFields(pFormFillEnv, swFieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002655
Lei Zhangd88a3642015-11-10 09:38:57 -08002656 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002657 if (pFormField->GetFullName().Compare(swFieldName) != 0)
2658 continue;
2659
2660 switch (pFormField->GetFieldType()) {
2661 case FIELDTYPE_TEXTFIELD:
2662 case FIELDTYPE_COMBOBOX:
tsepez41a53ad2016-03-28 16:59:30 -07002663 if (pFormField->GetValue() != strArray[0]) {
tsepez4cf55152016-11-02 14:37:54 -07002664 pFormField->SetValue(strArray[0], true);
2665 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002666 }
2667 break;
tsepez41a53ad2016-03-28 16:59:30 -07002668 case FIELDTYPE_CHECKBOX:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002669 case FIELDTYPE_RADIOBUTTON: {
tsepez41a53ad2016-03-28 16:59:30 -07002670 if (pFormField->GetValue() != strArray[0]) {
tsepez4cf55152016-11-02 14:37:54 -07002671 pFormField->SetValue(strArray[0], true);
2672 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002673 }
2674 } break;
2675 case FIELDTYPE_LISTBOX: {
tsepez4cf55152016-11-02 14:37:54 -07002676 bool bModified = false;
tsepez41a53ad2016-03-28 16:59:30 -07002677 for (const auto& str : strArray) {
2678 if (!pFormField->IsItemSelected(pFormField->FindOption(str))) {
tsepez4cf55152016-11-02 14:37:54 -07002679 bModified = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002680 break;
2681 }
2682 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002683 if (bModified) {
tsepez4cf55152016-11-02 14:37:54 -07002684 pFormField->ClearSelection(true);
tsepez41a53ad2016-03-28 16:59:30 -07002685 for (const auto& str : strArray) {
2686 int index = pFormField->FindOption(str);
2687 if (!pFormField->IsItemSelected(index))
tsepez4cf55152016-11-02 14:37:54 -07002688 pFormField->SetItemSelection(index, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002689 }
tsepez4cf55152016-11-02 14:37:54 -07002690 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002691 }
2692 } break;
2693 default:
2694 break;
2695 }
2696 }
2697}
2698
Tom Sepezb1670b52017-02-16 17:01:00 -08002699bool Field::valueAsString(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002700 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04002701 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002702 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -07002703 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002704
Lei Zhangd88a3642015-11-10 09:38:57 -08002705 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2706 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002707 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002708
Lei Zhangd88a3642015-11-10 09:38:57 -08002709 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002710 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002711 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002712
2713 if (pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) {
2714 if (!pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002715 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002716
2717 if (pFormField->GetControl(0)->IsChecked())
2718 vp << L"Yes";
2719 else
2720 vp << L"Off";
2721 } else if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON &&
2722 !(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)) {
2723 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2724 if (pFormField->GetControl(i)->IsChecked()) {
2725 vp << pFormField->GetControl(i)->GetExportValue().c_str();
2726 break;
Lei Zhangd88a3642015-11-10 09:38:57 -08002727 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002728 vp << L"Off";
Lei Zhangd88a3642015-11-10 09:38:57 -08002729 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002730 }
2731 } else if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX &&
2732 (pFormField->CountSelectedItems() > 1)) {
2733 vp << L"";
Lei Zhangd88a3642015-11-10 09:38:57 -08002734 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002735 vp << pFormField->GetValue().c_str();
Lei Zhangd88a3642015-11-10 09:38:57 -08002736 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002737
tsepez4cf55152016-11-02 14:37:54 -07002738 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002739}
2740
Tom Sepezb1670b52017-02-16 17:01:00 -08002741bool Field::browseForFileToSubmit(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002742 const std::vector<CJS_Value>& params,
2743 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002744 WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002745 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2746 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002747 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002748
Lei Zhangd88a3642015-11-10 09:38:57 -08002749 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002750 if ((pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) &&
2751 (pFormField->GetFieldType() == FIELDTYPE_TEXTFIELD)) {
Ryan Harrison275e2602017-09-18 14:23:18 -04002752 WideString wsFileName = m_pFormFillEnv->JS_fieldBrowse();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002753 if (!wsFileName.IsEmpty()) {
2754 pFormField->SetValue(wsFileName);
tsepez4cf55152016-11-02 14:37:54 -07002755 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002756 }
tsepez4cf55152016-11-02 14:37:54 -07002757 return true;
Lei Zhangd88a3642015-11-10 09:38:57 -08002758 }
tsepez4cf55152016-11-02 14:37:54 -07002759 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002760}
2761
Tom Sepezb1670b52017-02-16 17:01:00 -08002762bool Field::buttonGetCaption(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002763 const std::vector<CJS_Value>& params,
2764 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002765 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002766 int nface = 0;
2767 int iSize = params.size();
2768 if (iSize >= 1)
tsepezb4694242016-08-15 16:44:55 -07002769 nface = params[0].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002770
Lei Zhangd88a3642015-11-10 09:38:57 -08002771 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2772 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002773 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002774
Lei Zhangd88a3642015-11-10 09:38:57 -08002775 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002776 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002777 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002778
2779 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2780 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -07002781 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002782
2783 if (nface == 0)
tsepezf3dc8c62016-08-10 06:29:29 -07002784 vRet = CJS_Value(pRuntime, pFormControl->GetNormalCaption().c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002785 else if (nface == 1)
tsepezf3dc8c62016-08-10 06:29:29 -07002786 vRet = CJS_Value(pRuntime, pFormControl->GetDownCaption().c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002787 else if (nface == 2)
tsepezf3dc8c62016-08-10 06:29:29 -07002788 vRet = CJS_Value(pRuntime, pFormControl->GetRolloverCaption().c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002789 else
tsepez4cf55152016-11-02 14:37:54 -07002790 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002791
tsepez4cf55152016-11-02 14:37:54 -07002792 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002793}
2794
Tom Sepezb1670b52017-02-16 17:01:00 -08002795bool Field::buttonGetIcon(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002796 const std::vector<CJS_Value>& params,
2797 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002798 WideString& sError) {
Tom Sepez40e0a812017-02-23 13:07:36 -08002799 if (params.size() >= 1) {
2800 int nFace = params[0].ToInt(pRuntime);
2801 if (nFace < 0 || nFace > 2)
2802 return false;
2803 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002804
Lei Zhangd88a3642015-11-10 09:38:57 -08002805 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2806 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002807 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002808
Lei Zhangd88a3642015-11-10 09:38:57 -08002809 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002810 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002811 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002812
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002813 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2814 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -07002815 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002816
tsepezb4694242016-08-15 16:44:55 -07002817 v8::Local<v8::Object> pObj =
2818 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID);
Tom Sepezc5a14722017-02-24 15:31:12 -08002819 if (pObj.IsEmpty())
2820 return false;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002821
tsepezb4694242016-08-15 16:44:55 -07002822 CJS_Icon* pJS_Icon = static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj));
tsepezf3dc8c62016-08-10 06:29:29 -07002823 vRet = CJS_Value(pRuntime, pJS_Icon);
tsepez4cf55152016-11-02 14:37:54 -07002824 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002825}
2826
Tom Sepezb1670b52017-02-16 17:01:00 -08002827bool Field::buttonImportIcon(CJS_Runtime* pRuntime,
Lei Zhang945fdb72015-11-11 10:18:16 -08002828 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002829 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002830 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002831 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002832}
2833
Tom Sepezb1670b52017-02-16 17:01:00 -08002834bool Field::buttonSetCaption(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002835 const std::vector<CJS_Value>& params,
2836 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002837 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002838 return false;
2839}
2840
Tom Sepezb1670b52017-02-16 17:01:00 -08002841bool Field::buttonSetIcon(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002842 const std::vector<CJS_Value>& params,
2843 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002844 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002845 return false;
2846}
2847
Tom Sepezb1670b52017-02-16 17:01:00 -08002848bool Field::checkThisBox(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002849 const std::vector<CJS_Value>& params,
2850 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002851 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002852 int iSize = params.size();
2853 if (iSize < 1)
tsepez4cf55152016-11-02 14:37:54 -07002854 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002855
tsepezf3dc8c62016-08-10 06:29:29 -07002856 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002857 return false;
tsepezf3dc8c62016-08-10 06:29:29 -07002858
tsepezb4694242016-08-15 16:44:55 -07002859 int nWidget = params[0].ToInt(pRuntime);
Wei Li97da9762016-03-11 17:00:48 -08002860 bool bCheckit = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002861 if (iSize >= 2)
tsepezb4694242016-08-15 16:44:55 -07002862 bCheckit = params[1].ToBool(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002863
Lei Zhangd88a3642015-11-10 09:38:57 -08002864 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2865 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002866 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002867
Lei Zhangd88a3642015-11-10 09:38:57 -08002868 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002869 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
2870 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002871 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002872 if (nWidget < 0 || nWidget >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002873 return false;
Wei Li97da9762016-03-11 17:00:48 -08002874 // TODO(weili): Check whether anything special needed for radio button,
2875 // otherwise merge these branches.
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002876 if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)
Wei Li97da9762016-03-11 17:00:48 -08002877 pFormField->CheckControl(nWidget, bCheckit, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002878 else
Wei Li97da9762016-03-11 17:00:48 -08002879 pFormField->CheckControl(nWidget, bCheckit, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002880
tsepez4cf55152016-11-02 14:37:54 -07002881 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true);
2882 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002883}
2884
Tom Sepezb1670b52017-02-16 17:01:00 -08002885bool Field::clearItems(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002886 const std::vector<CJS_Value>& params,
2887 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002888 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002889 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002890}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002891
Tom Sepezb1670b52017-02-16 17:01:00 -08002892bool Field::defaultIsChecked(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002893 const std::vector<CJS_Value>& params,
2894 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002895 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002896 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002897 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002898
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002899 int iSize = params.size();
2900 if (iSize < 1)
tsepez4cf55152016-11-02 14:37:54 -07002901 return false;
Tom Sepezf4ef3f92015-04-23 11:31:31 -07002902
tsepezb4694242016-08-15 16:44:55 -07002903 int nWidget = params[0].ToInt(pRuntime);
Lei Zhangd88a3642015-11-10 09:38:57 -08002904 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2905 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002906 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002907
Lei Zhangd88a3642015-11-10 09:38:57 -08002908 CPDF_FormField* pFormField = FieldArray[0];
tsepezf3dc8c62016-08-10 06:29:29 -07002909 if (nWidget < 0 || nWidget >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002910 return false;
tsepezf3dc8c62016-08-10 06:29:29 -07002911
2912 vRet = CJS_Value(pRuntime,
2913 pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
2914 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002915
tsepez4cf55152016-11-02 14:37:54 -07002916 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002917}
2918
Tom Sepezb1670b52017-02-16 17:01:00 -08002919bool Field::deleteItemAt(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002920 const std::vector<CJS_Value>& params,
2921 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002922 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002923 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002924}
2925
Tom Sepezb1670b52017-02-16 17:01:00 -08002926bool Field::getArray(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002927 const std::vector<CJS_Value>& params,
2928 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002929 WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002930 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2931 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002932 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002933
Ryan Harrison275e2602017-09-18 14:23:18 -04002934 std::vector<std::unique_ptr<WideString>> swSort;
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002935 for (CPDF_FormField* pFormField : FieldArray) {
Ryan Harrison275e2602017-09-18 14:23:18 -04002936 swSort.push_back(
2937 std::unique_ptr<WideString>(new WideString(pFormField->GetFullName())));
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002938 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002939
Ryan Harrison275e2602017-09-18 14:23:18 -04002940 std::sort(swSort.begin(), swSort.end(),
2941 [](const std::unique_ptr<WideString>& p1,
2942 const std::unique_ptr<WideString>& p2) { return *p1 < *p2; });
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002943
tsepeze5aff742016-08-08 09:49:42 -07002944 CJS_Array FormFieldArray;
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002945
2946 int j = 0;
2947 for (const auto& pStr : swSort) {
tsepezb4694242016-08-15 16:44:55 -07002948 v8::Local<v8::Object> pObj =
2949 pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID);
Tom Sepezc5a14722017-02-24 15:31:12 -08002950 if (pObj.IsEmpty())
2951 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002952
Tom Sepezd5a0e952015-09-17 15:40:06 -07002953 CJS_Field* pJSField =
tsepezb4694242016-08-15 16:44:55 -07002954 static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pObj));
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002955 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002956 pField->AttachField(m_pJSDoc, *pStr);
tsepezb4694242016-08-15 16:44:55 -07002957 FormFieldArray.SetElement(pRuntime, j++, CJS_Value(pRuntime, pJSField));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002958 }
2959
tsepeze5aff742016-08-08 09:49:42 -07002960 vRet = CJS_Value(pRuntime, FormFieldArray);
tsepez4cf55152016-11-02 14:37:54 -07002961 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002962}
2963
Tom Sepezb1670b52017-02-16 17:01:00 -08002964bool Field::getItemAt(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002965 const std::vector<CJS_Value>& params,
2966 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04002967 WideString& sError) {
tsepezf3dc8c62016-08-10 06:29:29 -07002968 int iSize = params.size();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002969 int nIdx = -1;
2970 if (iSize >= 1)
tsepezb4694242016-08-15 16:44:55 -07002971 nIdx = params[0].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002972
tsepez4cf55152016-11-02 14:37:54 -07002973 bool bExport = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002974 if (iSize >= 2)
tsepezb4694242016-08-15 16:44:55 -07002975 bExport = params[1].ToBool(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002976
Lei Zhangd88a3642015-11-10 09:38:57 -08002977 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2978 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002979 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002980
Lei Zhangd88a3642015-11-10 09:38:57 -08002981 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002982 if ((pFormField->GetFieldType() == FIELDTYPE_LISTBOX) ||
2983 (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX)) {
2984 if (nIdx == -1 || nIdx > pFormField->CountOptions())
2985 nIdx = pFormField->CountOptions() - 1;
2986 if (bExport) {
Ryan Harrison275e2602017-09-18 14:23:18 -04002987 WideString strval = pFormField->GetOptionValue(nIdx);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002988 if (strval.IsEmpty())
tsepezf3dc8c62016-08-10 06:29:29 -07002989 vRet = CJS_Value(pRuntime, pFormField->GetOptionLabel(nIdx).c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002990 else
tsepezf3dc8c62016-08-10 06:29:29 -07002991 vRet = CJS_Value(pRuntime, strval.c_str());
Lei Zhangd88a3642015-11-10 09:38:57 -08002992 } else {
tsepezf3dc8c62016-08-10 06:29:29 -07002993 vRet = CJS_Value(pRuntime, pFormField->GetOptionLabel(nIdx).c_str());
Lei Zhangd88a3642015-11-10 09:38:57 -08002994 }
2995 } else {
tsepez4cf55152016-11-02 14:37:54 -07002996 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08002997 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002998
tsepez4cf55152016-11-02 14:37:54 -07002999 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003000}
3001
Tom Sepezb1670b52017-02-16 17:01:00 -08003002bool Field::getLock(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003003 const std::vector<CJS_Value>& params,
3004 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04003005 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07003006 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003007}
3008
Tom Sepezb1670b52017-02-16 17:01:00 -08003009bool Field::insertItemAt(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003010 const std::vector<CJS_Value>& params,
3011 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04003012 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07003013 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003014}
3015
Tom Sepezb1670b52017-02-16 17:01:00 -08003016bool Field::isBoxChecked(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003017 const std::vector<CJS_Value>& params,
3018 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04003019 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003020 int nIndex = -1;
3021 if (params.size() >= 1)
tsepezb4694242016-08-15 16:44:55 -07003022 nIndex = params[0].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003023
Lei Zhangd88a3642015-11-10 09:38:57 -08003024 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3025 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07003026 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003027
Lei Zhangd88a3642015-11-10 09:38:57 -08003028 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003029 if (nIndex < 0 || nIndex >= pFormField->CountControls()) {
tsepez4cf55152016-11-02 14:37:54 -07003030 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003031 }
3032
tsepezf3dc8c62016-08-10 06:29:29 -07003033 vRet = CJS_Value(pRuntime,
3034 ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
3035 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) &&
3036 pFormField->GetControl(nIndex)->IsChecked() != 0));
tsepez4cf55152016-11-02 14:37:54 -07003037 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003038}
3039
Tom Sepezb1670b52017-02-16 17:01:00 -08003040bool Field::isDefaultChecked(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003041 const std::vector<CJS_Value>& params,
3042 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04003043 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003044 int nIndex = -1;
3045 if (params.size() >= 1)
tsepezb4694242016-08-15 16:44:55 -07003046 nIndex = params[0].ToInt(pRuntime);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003047
Lei Zhangd88a3642015-11-10 09:38:57 -08003048 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3049 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07003050 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003051
Lei Zhangd88a3642015-11-10 09:38:57 -08003052 CPDF_FormField* pFormField = FieldArray[0];
tsepezf3dc8c62016-08-10 06:29:29 -07003053 if (nIndex < 0 || nIndex >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07003054 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003055
tsepezf3dc8c62016-08-10 06:29:29 -07003056 vRet = CJS_Value(pRuntime,
3057 ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
3058 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) &&
3059 pFormField->GetControl(nIndex)->IsDefaultChecked() != 0));
tsepez4cf55152016-11-02 14:37:54 -07003060 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003061}
3062
Tom Sepezb1670b52017-02-16 17:01:00 -08003063bool Field::setAction(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003064 const std::vector<CJS_Value>& params,
3065 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04003066 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07003067 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003068}
3069
Tom Sepezb1670b52017-02-16 17:01:00 -08003070bool Field::setFocus(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003071 const std::vector<CJS_Value>& params,
3072 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04003073 WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08003074 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3075 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07003076 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003077
Lei Zhangd88a3642015-11-10 09:38:57 -08003078 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003079 int32_t nCount = pFormField->CountControls();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003080 if (nCount < 1)
tsepez4cf55152016-11-02 14:37:54 -07003081 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003082
dsinclair7cbe68e2016-10-12 11:56:23 -07003083 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
thestig1cd352e2016-06-07 17:53:06 -07003084 CPDFSDK_Widget* pWidget = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003085 if (nCount == 1) {
dsinclairc5267c52016-11-04 15:35:12 -07003086 pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003087 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07003088 UnderlyingPageType* pPage =
3089 UnderlyingFromFPDFPage(m_pFormFillEnv->GetCurrentPage(
3090 m_pFormFillEnv->GetUnderlyingDocument()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003091 if (!pPage)
tsepez4cf55152016-11-02 14:37:54 -07003092 return false;
dsinclair461eeaf2016-07-27 07:40:05 -07003093 if (CPDFSDK_PageView* pCurPageView =
dsinclair7cbe68e2016-10-12 11:56:23 -07003094 m_pFormFillEnv->GetPageView(pPage, true)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003095 for (int32_t i = 0; i < nCount; i++) {
3096 if (CPDFSDK_Widget* pTempWidget =
dsinclairc5267c52016-11-04 15:35:12 -07003097 pInterForm->GetWidget(pFormField->GetControl(i))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003098 if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage()) {
3099 pWidget = pTempWidget;
3100 break;
3101 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003102 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003103 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003104 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003105 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003106
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003107 if (pWidget) {
tsepezf8074ce2016-09-27 14:29:57 -07003108 CPDFSDK_Annot::ObservedPtr pObserved(pWidget);
dsinclair7cbe68e2016-10-12 11:56:23 -07003109 m_pFormFillEnv->SetFocusAnnot(&pObserved);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003110 }
3111
tsepez4cf55152016-11-02 14:37:54 -07003112 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003113}
3114
Tom Sepezb1670b52017-02-16 17:01:00 -08003115bool Field::setItems(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003116 const std::vector<CJS_Value>& params,
3117 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04003118 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07003119 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003120}
3121
Tom Sepezb1670b52017-02-16 17:01:00 -08003122bool Field::setLock(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003123 const std::vector<CJS_Value>& params,
3124 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04003125 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07003126 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003127}
3128
Tom Sepezb1670b52017-02-16 17:01:00 -08003129bool Field::signatureGetModifications(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003130 const std::vector<CJS_Value>& params,
3131 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04003132 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07003133 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003134}
3135
Tom Sepezb1670b52017-02-16 17:01:00 -08003136bool Field::signatureGetSeedValue(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003137 const std::vector<CJS_Value>& params,
3138 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04003139 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07003140 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003141}
3142
Tom Sepezb1670b52017-02-16 17:01:00 -08003143bool Field::signatureInfo(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003144 const std::vector<CJS_Value>& params,
3145 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04003146 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07003147 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003148}
3149
Tom Sepezb1670b52017-02-16 17:01:00 -08003150bool Field::signatureSetSeedValue(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003151 const std::vector<CJS_Value>& params,
3152 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04003153 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07003154 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003155}
3156
Tom Sepezb1670b52017-02-16 17:01:00 -08003157bool Field::signatureSign(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003158 const std::vector<CJS_Value>& params,
3159 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04003160 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07003161 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003162}
3163
Tom Sepezb1670b52017-02-16 17:01:00 -08003164bool Field::signatureValidate(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003165 const std::vector<CJS_Value>& params,
3166 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -04003167 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07003168 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003169}
3170
Tom Sepezb1670b52017-02-16 17:01:00 -08003171bool Field::source(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08003172 CJS_PropValue& vp,
Ryan Harrison275e2602017-09-18 14:23:18 -04003173 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003174 if (vp.IsGetting()) {
thestig1cd352e2016-06-07 17:53:06 -07003175 vp << (CJS_Object*)nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003176 }
3177
tsepez4cf55152016-11-02 14:37:54 -07003178 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003179}
3180
tsepez41a53ad2016-03-28 16:59:30 -07003181void Field::AddDelay_Int(FIELD_PROP prop, int32_t n) {
3182 CJS_DelayData* pNewData =
3183 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003184 pNewData->num = n;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003185 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003186}
3187
tsepez41a53ad2016-03-28 16:59:30 -07003188void Field::AddDelay_Bool(FIELD_PROP prop, bool b) {
3189 CJS_DelayData* pNewData =
3190 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003191 pNewData->b = b;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003192 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003193}
3194
Ryan Harrison275e2602017-09-18 14:23:18 -04003195void Field::AddDelay_String(FIELD_PROP prop, const ByteString& string) {
tsepez41a53ad2016-03-28 16:59:30 -07003196 CJS_DelayData* pNewData =
3197 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003198 pNewData->string = string;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003199 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003200}
3201
Ryan Harrison275e2602017-09-18 14:23:18 -04003202void Field::AddDelay_WideString(FIELD_PROP prop, const WideString& string) {
tsepez41a53ad2016-03-28 16:59:30 -07003203 CJS_DelayData* pNewData =
3204 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003205 pNewData->widestring = string;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003206 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003207}
3208
tsepez41a53ad2016-03-28 16:59:30 -07003209void Field::AddDelay_Rect(FIELD_PROP prop, const CFX_FloatRect& rect) {
3210 CJS_DelayData* pNewData =
3211 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003212 pNewData->rect = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003213 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003214}
3215
Dan Sinclair7f55a542017-07-13 14:17:10 -04003216void Field::AddDelay_Color(FIELD_PROP prop, const CFX_Color& color) {
tsepez41a53ad2016-03-28 16:59:30 -07003217 CJS_DelayData* pNewData =
3218 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003219 pNewData->color = color;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003220 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003221}
3222
tsepez41a53ad2016-03-28 16:59:30 -07003223void Field::AddDelay_WordArray(FIELD_PROP prop,
3224 const std::vector<uint32_t>& array) {
3225 CJS_DelayData* pNewData =
3226 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
3227 pNewData->wordarray = array;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003228 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003229}
3230
tsepez41a53ad2016-03-28 16:59:30 -07003231void Field::AddDelay_WideStringArray(FIELD_PROP prop,
Ryan Harrison275e2602017-09-18 14:23:18 -04003232 const std::vector<WideString>& array) {
tsepez41a53ad2016-03-28 16:59:30 -07003233 CJS_DelayData* pNewData =
3234 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
3235 pNewData->widestringarray = array;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003236 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003237}
3238
dsinclair3a7741a2016-10-11 10:39:49 -07003239void Field::DoDelay(CPDFSDK_FormFillEnvironment* pFormFillEnv,
3240 CJS_DelayData* pData) {
3241 ASSERT(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003242 switch (pData->eProp) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003243 case FP_ALIGNMENT:
dsinclair3a7741a2016-10-11 10:39:49 -07003244 Field::SetAlignment(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003245 pData->string);
3246 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003247 case FP_BORDERSTYLE:
dsinclair3a7741a2016-10-11 10:39:49 -07003248 Field::SetBorderStyle(pFormFillEnv, pData->sFieldName,
3249 pData->nControlIndex, pData->string);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003250 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003251 case FP_BUTTONALIGNX:
dsinclair3a7741a2016-10-11 10:39:49 -07003252 Field::SetButtonAlignX(pFormFillEnv, pData->sFieldName,
3253 pData->nControlIndex, pData->num);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003254 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003255 case FP_BUTTONALIGNY:
dsinclair3a7741a2016-10-11 10:39:49 -07003256 Field::SetButtonAlignY(pFormFillEnv, pData->sFieldName,
3257 pData->nControlIndex, pData->num);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003258 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003259 case FP_BUTTONFITBOUNDS:
dsinclair3a7741a2016-10-11 10:39:49 -07003260 Field::SetButtonFitBounds(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003261 pData->nControlIndex, pData->b);
3262 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003263 case FP_BUTTONPOSITION:
dsinclair3a7741a2016-10-11 10:39:49 -07003264 Field::SetButtonPosition(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003265 pData->nControlIndex, pData->num);
3266 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003267 case FP_BUTTONSCALEHOW:
dsinclair3a7741a2016-10-11 10:39:49 -07003268 Field::SetButtonScaleHow(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003269 pData->nControlIndex, pData->num);
3270 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003271 case FP_BUTTONSCALEWHEN:
dsinclair3a7741a2016-10-11 10:39:49 -07003272 Field::SetButtonScaleWhen(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003273 pData->nControlIndex, pData->num);
3274 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003275 case FP_CALCORDERINDEX:
dsinclair3a7741a2016-10-11 10:39:49 -07003276 Field::SetCalcOrderIndex(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003277 pData->nControlIndex, pData->num);
3278 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003279 case FP_CHARLIMIT:
dsinclair3a7741a2016-10-11 10:39:49 -07003280 Field::SetCharLimit(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003281 pData->num);
3282 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003283 case FP_COMB:
dsinclair3a7741a2016-10-11 10:39:49 -07003284 Field::SetComb(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003285 pData->b);
3286 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003287 case FP_COMMITONSELCHANGE:
dsinclair3a7741a2016-10-11 10:39:49 -07003288 Field::SetCommitOnSelChange(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003289 pData->nControlIndex, pData->b);
3290 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003291 case FP_CURRENTVALUEINDICES:
dsinclair3a7741a2016-10-11 10:39:49 -07003292 Field::SetCurrentValueIndices(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003293 pData->nControlIndex, pData->wordarray);
3294 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003295 case FP_DEFAULTVALUE:
dsinclair3a7741a2016-10-11 10:39:49 -07003296 Field::SetDefaultValue(pFormFillEnv, pData->sFieldName,
3297 pData->nControlIndex, pData->widestring);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003298 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003299 case FP_DONOTSCROLL:
dsinclair3a7741a2016-10-11 10:39:49 -07003300 Field::SetDoNotScroll(pFormFillEnv, pData->sFieldName,
3301 pData->nControlIndex, pData->b);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003302 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003303 case FP_DISPLAY:
dsinclair3a7741a2016-10-11 10:39:49 -07003304 Field::SetDisplay(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003305 pData->num);
3306 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003307 case FP_FILLCOLOR:
dsinclair3a7741a2016-10-11 10:39:49 -07003308 Field::SetFillColor(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003309 pData->color);
3310 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003311 case FP_HIDDEN:
dsinclair3a7741a2016-10-11 10:39:49 -07003312 Field::SetHidden(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003313 pData->b);
3314 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003315 case FP_HIGHLIGHT:
dsinclair3a7741a2016-10-11 10:39:49 -07003316 Field::SetHighlight(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003317 pData->string);
3318 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003319 case FP_LINEWIDTH:
dsinclair3a7741a2016-10-11 10:39:49 -07003320 Field::SetLineWidth(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003321 pData->num);
3322 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003323 case FP_MULTILINE:
dsinclair3a7741a2016-10-11 10:39:49 -07003324 Field::SetMultiline(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003325 pData->b);
3326 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003327 case FP_MULTIPLESELECTION:
dsinclair3a7741a2016-10-11 10:39:49 -07003328 Field::SetMultipleSelection(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003329 pData->nControlIndex, pData->b);
3330 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003331 case FP_PASSWORD:
dsinclair3a7741a2016-10-11 10:39:49 -07003332 Field::SetPassword(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003333 pData->b);
3334 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003335 case FP_RECT:
dsinclair3a7741a2016-10-11 10:39:49 -07003336 Field::SetRect(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003337 pData->rect);
3338 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003339 case FP_RICHTEXT:
dsinclaira2919b32016-07-13 10:55:48 -07003340 // Not supported.
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003341 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003342 case FP_RICHVALUE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003343 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003344 case FP_ROTATION:
dsinclair3a7741a2016-10-11 10:39:49 -07003345 Field::SetRotation(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003346 pData->num);
3347 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003348 case FP_STROKECOLOR:
dsinclair3a7741a2016-10-11 10:39:49 -07003349 Field::SetStrokeColor(pFormFillEnv, pData->sFieldName,
3350 pData->nControlIndex, pData->color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003351 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003352 case FP_STYLE:
dsinclair3a7741a2016-10-11 10:39:49 -07003353 Field::SetStyle(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003354 pData->string);
3355 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003356 case FP_TEXTCOLOR:
dsinclair3a7741a2016-10-11 10:39:49 -07003357 Field::SetTextColor(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003358 pData->color);
3359 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003360 case FP_TEXTFONT:
dsinclair3a7741a2016-10-11 10:39:49 -07003361 Field::SetTextFont(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003362 pData->string);
3363 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003364 case FP_TEXTSIZE:
dsinclair3a7741a2016-10-11 10:39:49 -07003365 Field::SetTextSize(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003366 pData->num);
3367 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003368 case FP_USERNAME:
dsinclair3a7741a2016-10-11 10:39:49 -07003369 Field::SetUserName(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003370 pData->widestring);
3371 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003372 case FP_VALUE:
dsinclair3a7741a2016-10-11 10:39:49 -07003373 Field::SetValue(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003374 pData->widestringarray);
3375 break;
3376 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003377}
3378
dsinclair3a7741a2016-10-11 10:39:49 -07003379void Field::AddField(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003380 int nPageIndex,
3381 int nFieldType,
Ryan Harrison275e2602017-09-18 14:23:18 -04003382 const WideString& sName,
Tom Sepez281a9ea2016-02-26 14:24:28 -08003383 const CFX_FloatRect& rcCoords) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003384 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003385}