blob: 263e3a775e836d70b731e4bdd3ded4d3803d08e6 [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
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070075BEGIN_JS_STATIC_CONST(CJS_Field)
76END_JS_STATIC_CONST()
77
78BEGIN_JS_STATIC_PROP(CJS_Field)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070079JS_STATIC_PROP_ENTRY(alignment)
80JS_STATIC_PROP_ENTRY(borderStyle)
81JS_STATIC_PROP_ENTRY(buttonAlignX)
82JS_STATIC_PROP_ENTRY(buttonAlignY)
83JS_STATIC_PROP_ENTRY(buttonFitBounds)
84JS_STATIC_PROP_ENTRY(buttonPosition)
85JS_STATIC_PROP_ENTRY(buttonScaleHow)
86JS_STATIC_PROP_ENTRY(buttonScaleWhen)
87JS_STATIC_PROP_ENTRY(calcOrderIndex)
88JS_STATIC_PROP_ENTRY(charLimit)
89JS_STATIC_PROP_ENTRY(comb)
90JS_STATIC_PROP_ENTRY(commitOnSelChange)
91JS_STATIC_PROP_ENTRY(currentValueIndices)
92JS_STATIC_PROP_ENTRY(defaultStyle)
93JS_STATIC_PROP_ENTRY(defaultValue)
94JS_STATIC_PROP_ENTRY(doNotScroll)
95JS_STATIC_PROP_ENTRY(doNotSpellCheck)
96JS_STATIC_PROP_ENTRY(delay)
97JS_STATIC_PROP_ENTRY(display)
98JS_STATIC_PROP_ENTRY(doc)
99JS_STATIC_PROP_ENTRY(editable)
100JS_STATIC_PROP_ENTRY(exportValues)
101JS_STATIC_PROP_ENTRY(hidden)
102JS_STATIC_PROP_ENTRY(fileSelect)
103JS_STATIC_PROP_ENTRY(fillColor)
104JS_STATIC_PROP_ENTRY(lineWidth)
105JS_STATIC_PROP_ENTRY(highlight)
106JS_STATIC_PROP_ENTRY(multiline)
107JS_STATIC_PROP_ENTRY(multipleSelection)
108JS_STATIC_PROP_ENTRY(name)
109JS_STATIC_PROP_ENTRY(numItems)
110JS_STATIC_PROP_ENTRY(page)
111JS_STATIC_PROP_ENTRY(password)
112JS_STATIC_PROP_ENTRY(print)
113JS_STATIC_PROP_ENTRY(radiosInUnison)
114JS_STATIC_PROP_ENTRY(readonly)
115JS_STATIC_PROP_ENTRY(rect)
116JS_STATIC_PROP_ENTRY(required)
117JS_STATIC_PROP_ENTRY(richText)
118JS_STATIC_PROP_ENTRY(richValue)
119JS_STATIC_PROP_ENTRY(rotation)
120JS_STATIC_PROP_ENTRY(strokeColor)
121JS_STATIC_PROP_ENTRY(style)
122JS_STATIC_PROP_ENTRY(submitName)
123JS_STATIC_PROP_ENTRY(textColor)
124JS_STATIC_PROP_ENTRY(textFont)
125JS_STATIC_PROP_ENTRY(textSize)
126JS_STATIC_PROP_ENTRY(type)
127JS_STATIC_PROP_ENTRY(userName)
128JS_STATIC_PROP_ENTRY(value)
129JS_STATIC_PROP_ENTRY(valueAsString)
130JS_STATIC_PROP_ENTRY(source)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700131END_JS_STATIC_PROP()
132
133BEGIN_JS_STATIC_METHOD(CJS_Field)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700134JS_STATIC_METHOD_ENTRY(browseForFileToSubmit)
135JS_STATIC_METHOD_ENTRY(buttonGetCaption)
136JS_STATIC_METHOD_ENTRY(buttonGetIcon)
137JS_STATIC_METHOD_ENTRY(buttonImportIcon)
138JS_STATIC_METHOD_ENTRY(buttonSetCaption)
139JS_STATIC_METHOD_ENTRY(buttonSetIcon)
140JS_STATIC_METHOD_ENTRY(checkThisBox)
141JS_STATIC_METHOD_ENTRY(clearItems)
142JS_STATIC_METHOD_ENTRY(defaultIsChecked)
143JS_STATIC_METHOD_ENTRY(deleteItemAt)
144JS_STATIC_METHOD_ENTRY(getArray)
145JS_STATIC_METHOD_ENTRY(getItemAt)
146JS_STATIC_METHOD_ENTRY(getLock)
147JS_STATIC_METHOD_ENTRY(insertItemAt)
148JS_STATIC_METHOD_ENTRY(isBoxChecked)
149JS_STATIC_METHOD_ENTRY(isDefaultChecked)
150JS_STATIC_METHOD_ENTRY(setAction)
151JS_STATIC_METHOD_ENTRY(setFocus)
152JS_STATIC_METHOD_ENTRY(setItems)
153JS_STATIC_METHOD_ENTRY(setLock)
154JS_STATIC_METHOD_ENTRY(signatureGetModifications)
155JS_STATIC_METHOD_ENTRY(signatureGetSeedValue)
156JS_STATIC_METHOD_ENTRY(signatureInfo)
157JS_STATIC_METHOD_ENTRY(signatureSetSeedValue)
158JS_STATIC_METHOD_ENTRY(signatureSign)
159JS_STATIC_METHOD_ENTRY(signatureValidate)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700160END_JS_STATIC_METHOD()
161
162IMPLEMENT_JS_CLASS(CJS_Field, Field)
163
weili625ad662016-06-15 11:21:33 -0700164CJS_DelayData::CJS_DelayData(FIELD_PROP prop,
165 int idx,
166 const CFX_WideString& name)
167 : 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
tsepez4cf55152016-11-02 14:37:54 -0700211bool Field::AttachField(Document* pDocument,
212 const CFX_WideString& csFieldName) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700213 m_pJSDoc = pDocument;
dsinclair82e17672016-10-11 12:38:01 -0700214 m_pFormFillEnv.Reset(pDocument->GetFormFillEnv());
dsinclair7cbe68e2016-10-12 11:56:23 -0700215 m_bCanSet = m_pFormFillEnv->GetPermissions(FPDFPERM_FILL_FORM) ||
216 m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM) ||
217 m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700218
dsinclair7cbe68e2016-10-12 11:56:23 -0700219 CPDFSDK_InterForm* pRDInterForm = m_pFormFillEnv->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700220 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700221 CFX_WideString swFieldNameTemp = csFieldName;
222 swFieldNameTemp.Replace(L"..", L".");
223
224 if (pInterForm->CountFields(swFieldNameTemp) <= 0) {
225 std::wstring strFieldName;
226 int iControlNo = -1;
227 ParseFieldName(swFieldNameTemp.c_str(), strFieldName, iControlNo);
228 if (iControlNo == -1)
tsepez4cf55152016-11-02 14:37:54 -0700229 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700230
231 m_FieldName = strFieldName.c_str();
232 m_nFormControlIndex = iControlNo;
tsepez4cf55152016-11-02 14:37:54 -0700233 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700234 }
235
236 m_FieldName = swFieldNameTemp;
237 m_nFormControlIndex = -1;
238
tsepez4cf55152016-11-02 14:37:54 -0700239 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700240}
241
Lei Zhangd88a3642015-11-10 09:38:57 -0800242std::vector<CPDF_FormField*> Field::GetFormFields(
dsinclair3a7741a2016-10-11 10:39:49 -0700243 CPDFSDK_FormFillEnvironment* pFormFillEnv,
Lei Zhangd88a3642015-11-10 09:38:57 -0800244 const CFX_WideString& csFieldName) {
245 std::vector<CPDF_FormField*> fields;
dsinclair7cbe68e2016-10-12 11:56:23 -0700246 CPDFSDK_InterForm* pReaderInterForm = pFormFillEnv->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700247 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -0800248 for (int i = 0, sz = pInterForm->CountFields(csFieldName); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700249 if (CPDF_FormField* pFormField = pInterForm->GetField(i, csFieldName))
Lei Zhangd88a3642015-11-10 09:38:57 -0800250 fields.push_back(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700251 }
Lei Zhangd88a3642015-11-10 09:38:57 -0800252 return fields;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700253}
254
Lei Zhangd88a3642015-11-10 09:38:57 -0800255std::vector<CPDF_FormField*> Field::GetFormFields(
256 const CFX_WideString& csFieldName) const {
dsinclair3a7741a2016-10-11 10:39:49 -0700257 return Field::GetFormFields(m_pFormFillEnv.Get(), csFieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700258}
259
dsinclair3a7741a2016-10-11 10:39:49 -0700260void Field::UpdateFormField(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700261 CPDF_FormField* pFormField,
tsepez4cf55152016-11-02 14:37:54 -0700262 bool bChangeMark,
263 bool bResetAP,
264 bool bRefresh) {
dsinclair7cbe68e2016-10-12 11:56:23 -0700265 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700266
267 if (bResetAP) {
tsepez8fa82792017-01-11 09:32:33 -0800268 std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
dsinclair1df1efa2016-09-07 09:55:37 -0700269 pInterForm->GetWidgets(pFormField, &widgets);
270
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700271 int nFieldType = pFormField->GetFieldType();
272 if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_TEXTFIELD) {
tsepez8fa82792017-01-11 09:32:33 -0800273 for (auto& pObserved : widgets) {
tsepez1c620542016-09-12 09:47:52 -0700274 if (pObserved) {
tsepez8fa82792017-01-11 09:32:33 -0800275 bool bFormatted = false;
276 CFX_WideString sValue = static_cast<CPDFSDK_Widget*>(pObserved.Get())
277 ->OnFormat(bFormatted);
278 if (pObserved) { // Not redundant, may be clobbered by OnFormat.
279 static_cast<CPDFSDK_Widget*>(pObserved.Get())
280 ->ResetAppearance(bFormatted ? &sValue : nullptr, false);
281 }
tsepezca97a8e2016-08-01 10:10:36 -0700282 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700283 }
284 } else {
tsepez8fa82792017-01-11 09:32:33 -0800285 for (auto& pObserved : widgets) {
286 if (pObserved) {
287 static_cast<CPDFSDK_Widget*>(pObserved.Get())
288 ->ResetAppearance(nullptr, false);
289 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700290 }
291 }
292 }
293
294 if (bRefresh) {
dsinclair1df1efa2016-09-07 09:55:37 -0700295 // Refresh the widget list. The calls in |bResetAP| may have caused widgets
296 // to be removed from the list. We need to call |GetWidgets| again to be
297 // sure none of the widgets have been deleted.
tsepez8fa82792017-01-11 09:32:33 -0800298 std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
dsinclair1df1efa2016-09-07 09:55:37 -0700299 pInterForm->GetWidgets(pFormField, &widgets);
300
dsinclair690c0332016-10-11 09:13:01 -0700301 // TODO(dsinclair): Determine if all widgets share the same
302 // CPDFSDK_InterForm. If that's the case, we can move the code to
dsinclair7cbe68e2016-10-12 11:56:23 -0700303 // |GetFormFillEnv| out of the loop.
tsepez8fa82792017-01-11 09:32:33 -0800304 for (auto& pObserved : widgets) {
305 if (pObserved) {
306 CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pObserved.Get());
307 pWidget->GetInterForm()->GetFormFillEnv()->UpdateAllViews(nullptr,
308 pWidget);
309 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700310 }
311 }
312
313 if (bChangeMark)
dsinclair7cbe68e2016-10-12 11:56:23 -0700314 pFormFillEnv->SetChangeMark();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700315}
316
dsinclair3a7741a2016-10-11 10:39:49 -0700317void Field::UpdateFormControl(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700318 CPDF_FormControl* pFormControl,
tsepez4cf55152016-11-02 14:37:54 -0700319 bool bChangeMark,
320 bool bResetAP,
321 bool bRefresh) {
Lei Zhang96660d62015-12-14 18:27:25 -0800322 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700323
dsinclair7cbe68e2016-10-12 11:56:23 -0700324 CPDFSDK_InterForm* pForm = pFormFillEnv->GetInterForm();
dsinclairc5267c52016-11-04 15:35:12 -0700325 CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700326
327 if (pWidget) {
328 if (bResetAP) {
329 int nFieldType = pWidget->GetFieldType();
330 if (nFieldType == FIELDTYPE_COMBOBOX ||
331 nFieldType == FIELDTYPE_TEXTFIELD) {
tsepez4cf55152016-11-02 14:37:54 -0700332 bool bFormatted = false;
tsepez8c2a8cd2016-09-07 15:29:11 -0700333 CFX_WideString sValue = pWidget->OnFormat(bFormatted);
tsepez4cf55152016-11-02 14:37:54 -0700334 pWidget->ResetAppearance(bFormatted ? &sValue : nullptr, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700335 } else {
tsepez4cf55152016-11-02 14:37:54 -0700336 pWidget->ResetAppearance(nullptr, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700337 }
338 }
339
340 if (bRefresh) {
341 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
dsinclair7cbe68e2016-10-12 11:56:23 -0700342 pInterForm->GetFormFillEnv()->UpdateAllViews(nullptr, pWidget);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700343 }
344 }
345
346 if (bChangeMark)
dsinclair7cbe68e2016-10-12 11:56:23 -0700347 pFormFillEnv->SetChangeMark();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700348}
349
dsinclair3a7741a2016-10-11 10:39:49 -0700350CPDFSDK_Widget* Field::GetWidget(CPDFSDK_FormFillEnvironment* pFormFillEnv,
dsinclairc5267c52016-11-04 15:35:12 -0700351 CPDF_FormControl* pFormControl) {
dsinclair7cbe68e2016-10-12 11:56:23 -0700352 CPDFSDK_InterForm* pInterForm =
353 static_cast<CPDFSDK_InterForm*>(pFormFillEnv->GetInterForm());
dsinclairc5267c52016-11-04 15:35:12 -0700354 return pInterForm ? pInterForm->GetWidget(pFormControl) : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700355}
356
tsepez4cf55152016-11-02 14:37:54 -0700357bool Field::ValueIsOccur(CPDF_FormField* pFormField,
358 CFX_WideString csOptLabel) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700359 for (int i = 0, sz = pFormField->CountOptions(); i < sz; i++) {
360 if (csOptLabel.Compare(pFormField->GetOptionLabel(i)) == 0)
tsepez4cf55152016-11-02 14:37:54 -0700361 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700362 }
363
tsepez4cf55152016-11-02 14:37:54 -0700364 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700365}
366
367CPDF_FormControl* Field::GetSmartFieldControl(CPDF_FormField* pFormField) {
368 if (!pFormField->CountControls() ||
369 m_nFormControlIndex >= pFormField->CountControls())
thestig1cd352e2016-06-07 17:53:06 -0700370 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700371
372 if (m_nFormControlIndex < 0)
373 return pFormField->GetControl(0);
374
375 return pFormField->GetControl(m_nFormControlIndex);
376}
377
Tom Sepezb1670b52017-02-16 17:01:00 -0800378bool Field::alignment(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700379 CJS_PropValue& vp,
380 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700381 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700382
383 if (vp.IsSetting()) {
384 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700385 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700386
387 CFX_ByteString alignStr;
388 vp >> alignStr;
389
390 if (m_bDelay) {
391 AddDelay_String(FP_ALIGNMENT, alignStr);
392 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700393 Field::SetAlignment(m_pFormFillEnv.Get(), m_FieldName,
394 m_nFormControlIndex, alignStr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700395 }
396 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800397 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
398 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700399 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700400
Lei Zhangd88a3642015-11-10 09:38:57 -0800401 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700402 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
tsepez4cf55152016-11-02 14:37:54 -0700403 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700404
405 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
406 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -0700407 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700408
409 switch (pFormControl->GetControlAlignment()) {
410 case 1:
411 vp << L"center";
412 break;
413 case 0:
414 vp << L"left";
415 break;
416 case 2:
417 vp << L"right";
418 break;
419 default:
420 vp << L"";
421 }
422 }
423
tsepez4cf55152016-11-02 14:37:54 -0700424 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700425}
426
dsinclair3a7741a2016-10-11 10:39:49 -0700427void Field::SetAlignment(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700428 const CFX_WideString& swFieldName,
429 int nControlIndex,
430 const CFX_ByteString& string) {
431 // Not supported.
432}
433
Tom Sepezb1670b52017-02-16 17:01:00 -0800434bool Field::borderStyle(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700435 CJS_PropValue& vp,
436 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700437 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700438
439 if (vp.IsSetting()) {
440 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700441 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700442
443 CFX_ByteString strType = "";
444 vp >> strType;
445
446 if (m_bDelay) {
447 AddDelay_String(FP_BORDERSTYLE, strType);
448 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700449 Field::SetBorderStyle(m_pFormFillEnv.Get(), m_FieldName,
450 m_nFormControlIndex, strType);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700451 }
452 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800453 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
454 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700455 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700456
Lei Zhangd88a3642015-11-10 09:38:57 -0800457 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700458 if (!pFormField)
tsepez4cf55152016-11-02 14:37:54 -0700459 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700460
dsinclairc5267c52016-11-04 15:35:12 -0700461 CPDFSDK_Widget* pWidget =
462 GetWidget(m_pFormFillEnv.Get(), GetSmartFieldControl(pFormField));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700463 if (!pWidget)
tsepez4cf55152016-11-02 14:37:54 -0700464 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700465
dsinclair92cb5e52016-05-16 11:38:28 -0700466 switch (pWidget->GetBorderStyle()) {
467 case BorderStyle::SOLID:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700468 vp << L"solid";
469 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700470 case BorderStyle::DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700471 vp << L"dashed";
472 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700473 case BorderStyle::BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700474 vp << L"beveled";
475 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700476 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700477 vp << L"inset";
478 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700479 case BorderStyle::UNDERLINE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700480 vp << L"underline";
481 break;
482 default:
483 vp << L"";
484 break;
485 }
486 }
487
tsepez4cf55152016-11-02 14:37:54 -0700488 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700489}
490
dsinclair3a7741a2016-10-11 10:39:49 -0700491void Field::SetBorderStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700492 const CFX_WideString& swFieldName,
493 int nControlIndex,
494 const CFX_ByteString& string) {
dsinclair3a7741a2016-10-11 10:39:49 -0700495 ASSERT(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700496
dsinclair92cb5e52016-05-16 11:38:28 -0700497 BorderStyle nBorderStyle = BorderStyle::SOLID;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700498 if (string == "solid")
dsinclair92cb5e52016-05-16 11:38:28 -0700499 nBorderStyle = BorderStyle::SOLID;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700500 else if (string == "beveled")
dsinclair92cb5e52016-05-16 11:38:28 -0700501 nBorderStyle = BorderStyle::BEVELED;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700502 else if (string == "dashed")
dsinclair92cb5e52016-05-16 11:38:28 -0700503 nBorderStyle = BorderStyle::DASH;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700504 else if (string == "inset")
dsinclair92cb5e52016-05-16 11:38:28 -0700505 nBorderStyle = BorderStyle::INSET;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700506 else if (string == "underline")
dsinclair92cb5e52016-05-16 11:38:28 -0700507 nBorderStyle = BorderStyle::UNDERLINE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700508 else
509 return;
510
Lei Zhangd88a3642015-11-10 09:38:57 -0800511 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -0700512 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -0800513 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700514 if (nControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -0700515 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -0800516 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700517 if (CPDFSDK_Widget* pWidget =
dsinclairc5267c52016-11-04 15:35:12 -0700518 GetWidget(pFormFillEnv, pFormField->GetControl(i))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700519 if (pWidget->GetBorderStyle() != nBorderStyle) {
520 pWidget->SetBorderStyle(nBorderStyle);
tsepez4cf55152016-11-02 14:37:54 -0700521 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700522 }
523 }
524 }
525 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -0700526 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700527 } else {
528 if (nControlIndex >= pFormField->CountControls())
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700529 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700530 if (CPDF_FormControl* pFormControl =
531 pFormField->GetControl(nControlIndex)) {
dsinclairc5267c52016-11-04 15:35:12 -0700532 if (CPDFSDK_Widget* pWidget = GetWidget(pFormFillEnv, pFormControl)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700533 if (pWidget->GetBorderStyle() != nBorderStyle) {
534 pWidget->SetBorderStyle(nBorderStyle);
tsepez4cf55152016-11-02 14:37:54 -0700535 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700536 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700537 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700538 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700539 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700540 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700541}
542
Tom Sepezb1670b52017-02-16 17:01:00 -0800543bool Field::buttonAlignX(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700544 CJS_PropValue& vp,
545 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700546 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700547
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700548 if (vp.IsSetting()) {
549 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700550 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700551
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700552 int nVP;
553 vp >> nVP;
554
555 if (m_bDelay) {
556 AddDelay_Int(FP_BUTTONALIGNX, nVP);
557 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700558 Field::SetButtonAlignX(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700559 m_nFormControlIndex, nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700560 }
561 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800562 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
563 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700564 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700565
Lei Zhangd88a3642015-11-10 09:38:57 -0800566 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700567 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -0700568 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700569
570 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
571 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -0700572 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700573
574 CPDF_IconFit IconFit = pFormControl->GetIconFit();
575
576 FX_FLOAT fLeft, fBottom;
577 IconFit.GetIconPosition(fLeft, fBottom);
578
579 vp << (int32_t)fLeft;
580 }
581
tsepez4cf55152016-11-02 14:37:54 -0700582 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700583}
584
dsinclair3a7741a2016-10-11 10:39:49 -0700585void Field::SetButtonAlignX(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700586 const CFX_WideString& swFieldName,
587 int nControlIndex,
588 int number) {
589 // Not supported.
590}
591
Tom Sepezb1670b52017-02-16 17:01:00 -0800592bool Field::buttonAlignY(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700593 CJS_PropValue& vp,
594 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700595 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700596
597 if (vp.IsSetting()) {
598 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700599 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700600
601 int nVP;
602 vp >> nVP;
603
604 if (m_bDelay) {
605 AddDelay_Int(FP_BUTTONALIGNY, nVP);
606 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700607 Field::SetButtonAlignY(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700608 m_nFormControlIndex, nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700609 }
610 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800611 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
612 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700613 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700614
Lei Zhangd88a3642015-11-10 09:38:57 -0800615 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700616 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -0700617 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700618
619 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
620 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -0700621 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700622
623 CPDF_IconFit IconFit = pFormControl->GetIconFit();
624
625 FX_FLOAT fLeft, fBottom;
626 IconFit.GetIconPosition(fLeft, fBottom);
627
628 vp << (int32_t)fBottom;
629 }
630
tsepez4cf55152016-11-02 14:37:54 -0700631 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700632}
633
dsinclair3a7741a2016-10-11 10:39:49 -0700634void Field::SetButtonAlignY(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700635 const CFX_WideString& swFieldName,
636 int nControlIndex,
637 int number) {
638 // Not supported.
639}
640
Tom Sepezb1670b52017-02-16 17:01:00 -0800641bool Field::buttonFitBounds(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700642 CJS_PropValue& vp,
643 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700644 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700645
646 if (vp.IsSetting()) {
647 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700648 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700649
650 bool bVP;
651 vp >> bVP;
652
653 if (m_bDelay) {
654 AddDelay_Bool(FP_BUTTONFITBOUNDS, bVP);
655 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700656 Field::SetButtonFitBounds(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700657 m_nFormControlIndex, bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700658 }
659 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800660 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
661 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700662 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700663
Lei Zhangd88a3642015-11-10 09:38:57 -0800664 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700665 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -0700666 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700667
668 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
669 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -0700670 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700671
thestigded36342016-05-23 17:54:02 -0700672 vp << pFormControl->GetIconFit().GetFittingBounds();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700673 }
674
tsepez4cf55152016-11-02 14:37:54 -0700675 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700676}
677
dsinclair3a7741a2016-10-11 10:39:49 -0700678void Field::SetButtonFitBounds(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700679 const CFX_WideString& swFieldName,
680 int nControlIndex,
681 bool b) {
682 // Not supported.
683}
684
Tom Sepezb1670b52017-02-16 17:01:00 -0800685bool Field::buttonPosition(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700686 CJS_PropValue& vp,
687 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700688 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700689
690 if (vp.IsSetting()) {
691 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700692 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700693
694 int nVP;
695 vp >> nVP;
696
697 if (m_bDelay) {
698 AddDelay_Int(FP_BUTTONPOSITION, nVP);
699 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700700 Field::SetButtonPosition(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700701 m_nFormControlIndex, nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700702 }
703 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800704 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
705 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700706 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700707
Lei Zhangd88a3642015-11-10 09:38:57 -0800708 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700709 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -0700710 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700711
712 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
713 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -0700714 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700715
716 vp << pFormControl->GetTextPosition();
717 }
tsepez4cf55152016-11-02 14:37:54 -0700718 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700719}
720
dsinclair3a7741a2016-10-11 10:39:49 -0700721void Field::SetButtonPosition(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700722 const CFX_WideString& swFieldName,
723 int nControlIndex,
724 int number) {
725 // Not supported.
726}
727
Tom Sepezb1670b52017-02-16 17:01:00 -0800728bool Field::buttonScaleHow(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700729 CJS_PropValue& vp,
730 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700731 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700732
733 if (vp.IsSetting()) {
734 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700735 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700736
737 int nVP;
738 vp >> nVP;
739
740 if (m_bDelay) {
741 AddDelay_Int(FP_BUTTONSCALEHOW, nVP);
742 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700743 Field::SetButtonScaleHow(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700744 m_nFormControlIndex, nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700745 }
746 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800747 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
748 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700749 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700750
Lei Zhangd88a3642015-11-10 09:38:57 -0800751 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700752 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -0700753 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700754
755 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
756 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -0700757 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700758
759 CPDF_IconFit IconFit = pFormControl->GetIconFit();
760 if (IconFit.IsProportionalScale())
761 vp << (int32_t)0;
762 else
763 vp << (int32_t)1;
764 }
765
tsepez4cf55152016-11-02 14:37:54 -0700766 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700767}
768
dsinclair3a7741a2016-10-11 10:39:49 -0700769void Field::SetButtonScaleHow(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700770 const CFX_WideString& swFieldName,
771 int nControlIndex,
772 int number) {
773 // Not supported.
774}
775
Tom Sepezb1670b52017-02-16 17:01:00 -0800776bool Field::buttonScaleWhen(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700777 CJS_PropValue& vp,
778 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700779 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700780
781 if (vp.IsSetting()) {
782 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700783 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700784
785 int nVP;
786 vp >> nVP;
787
788 if (m_bDelay) {
789 AddDelay_Int(FP_BUTTONSCALEWHEN, nVP);
790 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700791 Field::SetButtonScaleWhen(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700792 m_nFormControlIndex, nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700793 }
794 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800795 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
796 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700797 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700798
Lei Zhangd88a3642015-11-10 09:38:57 -0800799 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700800 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -0700801 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700802
803 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
804 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -0700805 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700806
807 CPDF_IconFit IconFit = pFormControl->GetIconFit();
808 int ScaleM = IconFit.GetScaleMethod();
809 switch (ScaleM) {
810 case CPDF_IconFit::Always:
811 vp << (int32_t)CPDF_IconFit::Always;
812 break;
813 case CPDF_IconFit::Bigger:
814 vp << (int32_t)CPDF_IconFit::Bigger;
815 break;
816 case CPDF_IconFit::Never:
817 vp << (int32_t)CPDF_IconFit::Never;
818 break;
819 case CPDF_IconFit::Smaller:
820 vp << (int32_t)CPDF_IconFit::Smaller;
821 break;
822 }
823 }
824
tsepez4cf55152016-11-02 14:37:54 -0700825 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700826}
827
dsinclair3a7741a2016-10-11 10:39:49 -0700828void Field::SetButtonScaleWhen(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700829 const CFX_WideString& swFieldName,
830 int nControlIndex,
831 int number) {
832 // Not supported.
833}
834
Tom Sepezb1670b52017-02-16 17:01:00 -0800835bool Field::calcOrderIndex(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700836 CJS_PropValue& vp,
837 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700838 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700839
840 if (vp.IsSetting()) {
841 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700842 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700843
844 int nVP;
845 vp >> nVP;
846
847 if (m_bDelay) {
848 AddDelay_Int(FP_CALCORDERINDEX, nVP);
849 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700850 Field::SetCalcOrderIndex(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700851 m_nFormControlIndex, nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700852 }
853 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800854 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
855 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700856 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700857
Lei Zhangd88a3642015-11-10 09:38:57 -0800858 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700859 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -0800860 pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) {
tsepez4cf55152016-11-02 14:37:54 -0700861 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -0800862 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700863
dsinclair7cbe68e2016-10-12 11:56:23 -0700864 CPDFSDK_InterForm* pRDInterForm = m_pFormFillEnv->GetInterForm();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700865 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700866 vp << (int32_t)pInterForm->FindFieldInCalculationOrder(pFormField);
867 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700868
tsepez4cf55152016-11-02 14:37:54 -0700869 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700870}
871
dsinclair3a7741a2016-10-11 10:39:49 -0700872void Field::SetCalcOrderIndex(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700873 const CFX_WideString& swFieldName,
874 int nControlIndex,
875 int number) {
876 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700877}
878
Tom Sepezb1670b52017-02-16 17:01:00 -0800879bool Field::charLimit(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700880 CJS_PropValue& vp,
881 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700882 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700883
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700884 if (vp.IsSetting()) {
885 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700886 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700887
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700888 int nVP;
889 vp >> nVP;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700890
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700891 if (m_bDelay) {
892 AddDelay_Int(FP_CHARLIMIT, nVP);
893 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700894 Field::SetCharLimit(m_pFormFillEnv.Get(), m_FieldName,
895 m_nFormControlIndex, nVP);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700896 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700897 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800898 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
899 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700900 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700901
Lei Zhangd88a3642015-11-10 09:38:57 -0800902 CPDF_FormField* pFormField = FieldArray[0];
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700903 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
tsepez4cf55152016-11-02 14:37:54 -0700904 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700905
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700906 vp << (int32_t)pFormField->GetMaxLen();
907 }
tsepez4cf55152016-11-02 14:37:54 -0700908 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700909}
910
dsinclair3a7741a2016-10-11 10:39:49 -0700911void Field::SetCharLimit(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700912 const CFX_WideString& swFieldName,
913 int nControlIndex,
914 int number) {
915 // Not supported.
916}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700917
Tom Sepezb1670b52017-02-16 17:01:00 -0800918bool Field::comb(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800919 CJS_PropValue& vp,
920 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700921 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700922
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700923 if (vp.IsSetting()) {
924 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700925 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700926
927 bool bVP;
928 vp >> bVP;
929
930 if (m_bDelay) {
931 AddDelay_Bool(FP_COMB, bVP);
932 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700933 Field::SetComb(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
934 bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700935 }
936 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800937 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
938 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700939 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700940
Lei Zhangd88a3642015-11-10 09:38:57 -0800941 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700942 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
tsepez4cf55152016-11-02 14:37:54 -0700943 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700944
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700945 if (pFormField->GetFieldFlags() & FIELDFLAG_COMB)
946 vp << true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700947 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700948 vp << false;
949 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700950
tsepez4cf55152016-11-02 14:37:54 -0700951 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700952}
953
dsinclair3a7741a2016-10-11 10:39:49 -0700954void Field::SetComb(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700955 const CFX_WideString& swFieldName,
956 int nControlIndex,
957 bool b) {
958 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700959}
960
Tom Sepezb1670b52017-02-16 17:01:00 -0800961bool Field::commitOnSelChange(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700962 CJS_PropValue& vp,
963 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -0700964 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700965
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700966 if (vp.IsSetting()) {
967 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -0700968 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700969
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700970 bool bVP;
971 vp >> bVP;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700972
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700973 if (m_bDelay) {
974 AddDelay_Bool(FP_COMMITONSELCHANGE, bVP);
975 } else {
dsinclair3a7741a2016-10-11 10:39:49 -0700976 Field::SetCommitOnSelChange(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -0700977 m_nFormControlIndex, bVP);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700978 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700979 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800980 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
981 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -0700982 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700983
Lei Zhangd88a3642015-11-10 09:38:57 -0800984 CPDF_FormField* pFormField = FieldArray[0];
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700985 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -0800986 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
tsepez4cf55152016-11-02 14:37:54 -0700987 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -0800988 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700989
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700990 if (pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE)
991 vp << true;
992 else
993 vp << false;
994 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700995
tsepez4cf55152016-11-02 14:37:54 -0700996 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700997}
998
dsinclair3a7741a2016-10-11 10:39:49 -0700999void Field::SetCommitOnSelChange(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001000 const CFX_WideString& swFieldName,
1001 int nControlIndex,
1002 bool b) {
1003 // Not supported.
1004}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001005
Tom Sepezb1670b52017-02-16 17:01:00 -08001006bool Field::currentValueIndices(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001007 CJS_PropValue& vp,
1008 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001009 if (vp.IsSetting()) {
1010 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001011 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001012
tsepez41a53ad2016-03-28 16:59:30 -07001013 std::vector<uint32_t> array;
tsepezf3dc8c62016-08-10 06:29:29 -07001014 if (vp.GetJSValue()->GetType() == CJS_Value::VT_number) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001015 int iSelecting = 0;
1016 vp >> iSelecting;
tsepez41a53ad2016-03-28 16:59:30 -07001017 array.push_back(iSelecting);
tsepezf3dc8c62016-08-10 06:29:29 -07001018 } else if (vp.GetJSValue()->IsArrayObject()) {
tsepeze5aff742016-08-08 09:49:42 -07001019 CJS_Array SelArray;
Tom Sepez67fd5df2015-10-08 12:24:19 -07001020 CJS_Value SelValue(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001021 int iSelecting;
1022 vp >> SelArray;
tsepezb4694242016-08-15 16:44:55 -07001023 for (int i = 0, sz = SelArray.GetLength(pRuntime); i < sz; i++) {
1024 SelArray.GetElement(pRuntime, i, SelValue);
1025 iSelecting = SelValue.ToInt(pRuntime);
tsepez41a53ad2016-03-28 16:59:30 -07001026 array.push_back(iSelecting);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001027 }
1028 }
1029
1030 if (m_bDelay) {
1031 AddDelay_WordArray(FP_CURRENTVALUEINDICES, array);
1032 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001033 Field::SetCurrentValueIndices(m_pFormFillEnv.Get(), m_FieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001034 m_nFormControlIndex, array);
1035 }
1036 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001037 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1038 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001039 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001040
Lei Zhangd88a3642015-11-10 09:38:57 -08001041 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001042 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001043 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
tsepez4cf55152016-11-02 14:37:54 -07001044 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001045 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001046
Lei Zhangd88a3642015-11-10 09:38:57 -08001047 if (pFormField->CountSelectedItems() == 1) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001048 vp << pFormField->GetSelectedIndex(0);
Lei Zhangd88a3642015-11-10 09:38:57 -08001049 } else if (pFormField->CountSelectedItems() > 1) {
tsepeze5aff742016-08-08 09:49:42 -07001050 CJS_Array SelArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001051 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
1052 SelArray.SetElement(
tsepezb4694242016-08-15 16:44:55 -07001053 pRuntime, i, CJS_Value(pRuntime, pFormField->GetSelectedIndex(i)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001054 }
1055 vp << SelArray;
Lei Zhangd88a3642015-11-10 09:38:57 -08001056 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001057 vp << -1;
Lei Zhangd88a3642015-11-10 09:38:57 -08001058 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001059 }
1060
tsepez4cf55152016-11-02 14:37:54 -07001061 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001062}
1063
dsinclair3a7741a2016-10-11 10:39:49 -07001064void Field::SetCurrentValueIndices(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001065 const CFX_WideString& swFieldName,
1066 int nControlIndex,
tsepez41a53ad2016-03-28 16:59:30 -07001067 const std::vector<uint32_t>& array) {
dsinclair3a7741a2016-10-11 10:39:49 -07001068 ASSERT(pFormFillEnv);
Lei Zhangd88a3642015-11-10 09:38:57 -08001069 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07001070 GetFormFields(pFormFillEnv, swFieldName);
tsepez41a53ad2016-03-28 16:59:30 -07001071
Lei Zhangd88a3642015-11-10 09:38:57 -08001072 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001073 int nFieldType = pFormField->GetFieldType();
1074 if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX) {
tsepezc3255f52016-03-25 14:52:27 -07001075 uint32_t dwFieldFlags = pFormField->GetFieldFlags();
tsepez4cf55152016-11-02 14:37:54 -07001076 pFormField->ClearSelection(true);
tsepez41a53ad2016-03-28 16:59:30 -07001077 for (size_t i = 0; i < array.size(); ++i) {
1078 if (i != 0 && !(dwFieldFlags & (1 << 21)))
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001079 break;
Wei Li05d53f02016-03-29 16:42:53 -07001080 if (array[i] < static_cast<uint32_t>(pFormField->CountOptions()) &&
tsepez41a53ad2016-03-28 16:59:30 -07001081 !pFormField->IsItemSelected(array[i])) {
tsepez4cf55152016-11-02 14:37:54 -07001082 pFormField->SetItemSelection(array[i], true);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001083 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001084 }
tsepez4cf55152016-11-02 14:37:54 -07001085 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001086 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001087 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001088}
1089
Tom Sepezb1670b52017-02-16 17:01:00 -08001090bool Field::defaultStyle(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001091 CJS_PropValue& vp,
1092 CFX_WideString& sError) {
1093 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001094}
1095
dsinclair3a7741a2016-10-11 10:39:49 -07001096void Field::SetDefaultStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001097 const CFX_WideString& swFieldName,
1098 int nControlIndex) {
1099 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001100}
1101
Tom Sepezb1670b52017-02-16 17:01:00 -08001102bool Field::defaultValue(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001103 CJS_PropValue& vp,
1104 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001105 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001106
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001107 if (vp.IsSetting()) {
1108 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001109 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001110
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001111 CFX_WideString WideStr;
1112 vp >> WideStr;
1113
1114 if (m_bDelay) {
1115 AddDelay_WideString(FP_DEFAULTVALUE, WideStr);
1116 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001117 Field::SetDefaultValue(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -07001118 m_nFormControlIndex, WideStr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001119 }
1120 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001121 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1122 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001123 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001124
Lei Zhangd88a3642015-11-10 09:38:57 -08001125 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001126 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON ||
Lei Zhangd88a3642015-11-10 09:38:57 -08001127 pFormField->GetFieldType() == FIELDTYPE_SIGNATURE) {
tsepez4cf55152016-11-02 14:37:54 -07001128 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001129 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001130
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001131 vp << pFormField->GetDefaultValue();
1132 }
tsepez4cf55152016-11-02 14:37:54 -07001133 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001134}
1135
dsinclair3a7741a2016-10-11 10:39:49 -07001136void Field::SetDefaultValue(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001137 const CFX_WideString& swFieldName,
1138 int nControlIndex,
1139 const CFX_WideString& string) {
1140 // Not supported.
1141}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001142
Tom Sepezb1670b52017-02-16 17:01:00 -08001143bool Field::doNotScroll(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001144 CJS_PropValue& vp,
1145 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001146 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001147
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001148 if (vp.IsSetting()) {
1149 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001150 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001151
1152 bool bVP;
1153 vp >> bVP;
1154
1155 if (m_bDelay) {
1156 AddDelay_Bool(FP_DONOTSCROLL, bVP);
1157 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001158 Field::SetDoNotScroll(m_pFormFillEnv.Get(), m_FieldName,
1159 m_nFormControlIndex, bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001160 }
1161 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001162 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1163 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001164 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001165
Lei Zhangd88a3642015-11-10 09:38:57 -08001166 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001167 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
tsepez4cf55152016-11-02 14:37:54 -07001168 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001169
1170 if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL)
1171 vp << true;
1172 else
1173 vp << false;
1174 }
1175
tsepez4cf55152016-11-02 14:37:54 -07001176 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001177}
1178
dsinclair3a7741a2016-10-11 10:39:49 -07001179void Field::SetDoNotScroll(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001180 const CFX_WideString& swFieldName,
1181 int nControlIndex,
1182 bool b) {
1183 // Not supported.
1184}
1185
Tom Sepezb1670b52017-02-16 17:01:00 -08001186bool Field::doNotSpellCheck(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001187 CJS_PropValue& vp,
1188 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001189 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001190
1191 if (vp.IsSetting()) {
1192 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001193 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001194
1195 bool bVP;
1196 vp >> bVP;
1197 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001198 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1199 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001200 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001201
Lei Zhangd88a3642015-11-10 09:38:57 -08001202 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001203 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001204 pFormField->GetFieldType() != FIELDTYPE_COMBOBOX) {
tsepez4cf55152016-11-02 14:37:54 -07001205 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001206 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001207
1208 if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK)
1209 vp << true;
1210 else
1211 vp << false;
1212 }
1213
tsepez4cf55152016-11-02 14:37:54 -07001214 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001215}
1216
tsepez4cf55152016-11-02 14:37:54 -07001217void Field::SetDelay(bool bDelay) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001218 m_bDelay = bDelay;
1219
1220 if (!m_bDelay) {
1221 if (m_pJSDoc)
1222 m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex);
1223 }
1224}
1225
Tom Sepezb1670b52017-02-16 17:01:00 -08001226bool Field::delay(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001227 CJS_PropValue& vp,
1228 CFX_WideString& sError) {
1229 if (!vp.IsSetting()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001230 vp << m_bDelay;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001231 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001232 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001233 if (!m_bCanSet)
1234 return false;
1235
1236 bool bVP;
1237 vp >> bVP;
1238 SetDelay(bVP);
tsepez4cf55152016-11-02 14:37:54 -07001239 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001240}
1241
Tom Sepezb1670b52017-02-16 17:01:00 -08001242bool Field::display(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001243 CJS_PropValue& vp,
1244 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001245 if (vp.IsSetting()) {
1246 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001247 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001248
1249 int nVP;
1250 vp >> nVP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001251 if (m_bDelay) {
1252 AddDelay_Int(FP_DISPLAY, nVP);
1253 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001254 Field::SetDisplay(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07001255 nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001256 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001257 return true;
1258 }
1259 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1260 if (FieldArray.empty())
1261 return false;
1262
1263 CPDF_FormField* pFormField = FieldArray[0];
1264 ASSERT(pFormField);
1265 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1266 CPDFSDK_Widget* pWidget =
1267 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1268 if (!pWidget)
1269 return false;
1270
1271 uint32_t dwFlag = pWidget->GetFlags();
1272 if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag) {
1273 vp << (int32_t)1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001274 } else {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001275 if (ANNOTFLAG_PRINT & dwFlag) {
1276 if (ANNOTFLAG_NOVIEW & dwFlag) {
1277 vp << (int32_t)3;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001278 } else {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001279 vp << (int32_t)0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001280 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001281 } else {
1282 vp << (int32_t)2;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001283 }
1284 }
tsepez4cf55152016-11-02 14:37:54 -07001285 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001286}
1287
dsinclair3a7741a2016-10-11 10:39:49 -07001288void Field::SetDisplay(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001289 const CFX_WideString& swFieldName,
1290 int nControlIndex,
1291 int number) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001292 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001293 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07001294 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -08001295 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001296 if (nControlIndex < 0) {
tonikitoo7c05a7a2016-08-17 11:08:46 -07001297 bool bAnySet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001298 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1299 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08001300 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001301
dsinclairc5267c52016-11-04 15:35:12 -07001302 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
tonikitoo7c05a7a2016-08-17 11:08:46 -07001303 if (SetWidgetDisplayStatus(pWidget, number))
1304 bAnySet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001305 }
1306
tonikitoo7c05a7a2016-08-17 11:08:46 -07001307 if (bAnySet)
tsepez4cf55152016-11-02 14:37:54 -07001308 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001309 } else {
1310 if (nControlIndex >= pFormField->CountControls())
1311 return;
tonikitoo7c05a7a2016-08-17 11:08:46 -07001312
1313 CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex);
1314 if (!pFormControl)
1315 return;
1316
dsinclairc5267c52016-11-04 15:35:12 -07001317 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
tonikitoo7c05a7a2016-08-17 11:08:46 -07001318 if (SetWidgetDisplayStatus(pWidget, number))
tsepez4cf55152016-11-02 14:37:54 -07001319 UpdateFormControl(pFormFillEnv, pFormControl, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001320 }
1321 }
1322}
1323
Tom Sepezb1670b52017-02-16 17:01:00 -08001324bool Field::doc(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001325 CJS_PropValue& vp,
1326 CFX_WideString& sError) {
1327 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -07001328 return false;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001329
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001330 vp << m_pJSDoc->GetCJSDoc();
tsepez4cf55152016-11-02 14:37:54 -07001331 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001332}
1333
Tom Sepezb1670b52017-02-16 17:01:00 -08001334bool Field::editable(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001335 CJS_PropValue& vp,
1336 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001337 if (vp.IsSetting()) {
1338 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001339 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001340
1341 bool bVP;
1342 vp >> bVP;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001343 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001344 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001345 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1346 if (FieldArray.empty())
1347 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001348
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001349 CPDF_FormField* pFormField = FieldArray[0];
1350 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX)
1351 return false;
1352
1353 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_EDIT);
tsepez4cf55152016-11-02 14:37:54 -07001354 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001355}
1356
Tom Sepezb1670b52017-02-16 17:01:00 -08001357bool Field::exportValues(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001358 CJS_PropValue& vp,
1359 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001360 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1361 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001362 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001363
Lei Zhangd88a3642015-11-10 09:38:57 -08001364 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001365 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001366 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) {
tsepez4cf55152016-11-02 14:37:54 -07001367 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001368 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001369 if (vp.IsSetting())
1370 return m_bCanSet && vp.GetJSValue()->IsArrayObject();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001371
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001372 CJS_Array ExportValusArray;
1373 if (m_nFormControlIndex < 0) {
1374 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
1375 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001376 ExportValusArray.SetElement(
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001377 pRuntime, i,
tsepeze5aff742016-08-08 09:49:42 -07001378 CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001379 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001380 } else {
1381 if (m_nFormControlIndex >= pFormField->CountControls())
1382 return false;
1383
1384 CPDF_FormControl* pFormControl =
1385 pFormField->GetControl(m_nFormControlIndex);
1386 if (!pFormControl)
1387 return false;
1388
1389 ExportValusArray.SetElement(
1390 pRuntime, 0,
1391 CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001392 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001393 vp << ExportValusArray;
tsepez4cf55152016-11-02 14:37:54 -07001394 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001395}
1396
Tom Sepezb1670b52017-02-16 17:01:00 -08001397bool Field::fileSelect(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001398 CJS_PropValue& vp,
1399 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001400 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1401 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001402 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001403
Lei Zhangd88a3642015-11-10 09:38:57 -08001404 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001405 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
tsepez4cf55152016-11-02 14:37:54 -07001406 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001407
1408 if (vp.IsSetting()) {
1409 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001410 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001411
1412 bool bVP;
1413 vp >> bVP;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001414 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001415 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001416 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT);
tsepez4cf55152016-11-02 14:37:54 -07001417 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001418}
1419
Tom Sepezb1670b52017-02-16 17:01:00 -08001420bool Field::fillColor(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001421 CJS_PropValue& vp,
1422 CFX_WideString& sError) {
tsepeze5aff742016-08-08 09:49:42 -07001423 CJS_Array crArray;
Lei Zhangd88a3642015-11-10 09:38:57 -08001424 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1425 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001426 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001427
1428 if (vp.IsSetting()) {
1429 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001430 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001431
tsepezf3dc8c62016-08-10 06:29:29 -07001432 if (!vp.GetJSValue()->IsArrayObject())
tsepez4cf55152016-11-02 14:37:54 -07001433 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001434
1435 vp >> crArray;
1436
1437 CPWL_Color color;
tsepeze5aff742016-08-08 09:49:42 -07001438 color::ConvertArrayToPWLColor(pRuntime, crArray, &color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001439 if (m_bDelay) {
1440 AddDelay_Color(FP_FILLCOLOR, color);
1441 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001442 Field::SetFillColor(m_pFormFillEnv.Get(), m_FieldName,
1443 m_nFormControlIndex, color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001444 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001445 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001446 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001447 CPDF_FormField* pFormField = FieldArray[0];
1448 ASSERT(pFormField);
1449 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1450 if (!pFormControl)
1451 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001452
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001453 int iColorType;
1454 pFormControl->GetBackgroundColor(iColorType);
1455
1456 CPWL_Color color;
1457 if (iColorType == COLORTYPE_TRANSPARENT) {
1458 color = CPWL_Color(COLORTYPE_TRANSPARENT);
1459 } else if (iColorType == COLORTYPE_GRAY) {
1460 color =
1461 CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBackgroundColor(0));
1462 } else if (iColorType == COLORTYPE_RGB) {
1463 color =
1464 CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBackgroundColor(0),
1465 pFormControl->GetOriginalBackgroundColor(1),
1466 pFormControl->GetOriginalBackgroundColor(2));
1467 } else if (iColorType == COLORTYPE_CMYK) {
1468 color =
1469 CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBackgroundColor(0),
1470 pFormControl->GetOriginalBackgroundColor(1),
1471 pFormControl->GetOriginalBackgroundColor(2),
1472 pFormControl->GetOriginalBackgroundColor(3));
1473 } else {
1474 return false;
1475 }
1476 color::ConvertPWLColorToArray(pRuntime, color, &crArray);
1477 vp << crArray;
tsepez4cf55152016-11-02 14:37:54 -07001478 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001479}
1480
dsinclair3a7741a2016-10-11 10:39:49 -07001481void Field::SetFillColor(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001482 const CFX_WideString& swFieldName,
1483 int nControlIndex,
1484 const CPWL_Color& color) {
1485 // Not supported.
1486}
1487
Tom Sepezb1670b52017-02-16 17:01:00 -08001488bool Field::hidden(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001489 CJS_PropValue& vp,
1490 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001491 if (vp.IsSetting()) {
1492 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001493 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001494
1495 bool bVP;
1496 vp >> bVP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001497 if (m_bDelay) {
1498 AddDelay_Bool(FP_HIDDEN, bVP);
1499 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001500 Field::SetHidden(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07001501 bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001502 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001503 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001504 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001505 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1506 if (FieldArray.empty())
1507 return false;
1508
1509 CPDF_FormField* pFormField = FieldArray[0];
1510 ASSERT(pFormField);
1511 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1512 CPDFSDK_Widget* pWidget =
1513 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1514 if (!pWidget)
1515 return false;
1516
1517 uint32_t dwFlags = pWidget->GetFlags();
1518 if (ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags)
1519 vp << true;
1520 else
1521 vp << false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001522
tsepez4cf55152016-11-02 14:37:54 -07001523 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001524}
1525
dsinclair3a7741a2016-10-11 10:39:49 -07001526void Field::SetHidden(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001527 const CFX_WideString& swFieldName,
1528 int nControlIndex,
1529 bool b) {
tonikitooa73b8fe2016-08-22 14:06:49 -07001530 int display = b ? 1 /*Hidden*/ : 0 /*Visible*/;
dsinclair3a7741a2016-10-11 10:39:49 -07001531 SetDisplay(pFormFillEnv, swFieldName, nControlIndex, display);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001532}
1533
Tom Sepezb1670b52017-02-16 17:01:00 -08001534bool Field::highlight(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001535 CJS_PropValue& vp,
1536 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001537 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001538 if (vp.IsSetting()) {
1539 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001540 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001541
1542 CFX_ByteString strMode;
1543 vp >> strMode;
1544
1545 if (m_bDelay) {
1546 AddDelay_String(FP_HIGHLIGHT, strMode);
1547 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001548 Field::SetHighlight(m_pFormFillEnv.Get(), m_FieldName,
1549 m_nFormControlIndex, strMode);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001550 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001551 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001552 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001553 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1554 if (FieldArray.empty())
1555 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001556
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001557 CPDF_FormField* pFormField = FieldArray[0];
1558 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
1559 return false;
1560
1561 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1562 if (!pFormControl)
1563 return false;
1564
1565 int eHM = pFormControl->GetHighlightingMode();
1566 switch (eHM) {
1567 case CPDF_FormControl::None:
1568 vp << L"none";
1569 break;
1570 case CPDF_FormControl::Push:
1571 vp << L"push";
1572 break;
1573 case CPDF_FormControl::Invert:
1574 vp << L"invert";
1575 break;
1576 case CPDF_FormControl::Outline:
1577 vp << L"outline";
1578 break;
1579 case CPDF_FormControl::Toggle:
1580 vp << L"toggle";
1581 break;
1582 }
tsepez4cf55152016-11-02 14:37:54 -07001583 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001584}
1585
dsinclair3a7741a2016-10-11 10:39:49 -07001586void Field::SetHighlight(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001587 const CFX_WideString& swFieldName,
1588 int nControlIndex,
1589 const CFX_ByteString& string) {
1590 // Not supported.
1591}
1592
Tom Sepezb1670b52017-02-16 17:01:00 -08001593bool Field::lineWidth(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001594 CJS_PropValue& vp,
1595 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001596 if (vp.IsSetting()) {
1597 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001598 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001599
1600 int iWidth;
1601 vp >> iWidth;
1602
1603 if (m_bDelay) {
1604 AddDelay_Int(FP_LINEWIDTH, iWidth);
1605 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001606 Field::SetLineWidth(m_pFormFillEnv.Get(), m_FieldName,
1607 m_nFormControlIndex, iWidth);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001608 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001609 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001610 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001611 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1612 if (FieldArray.empty())
1613 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001614
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001615 CPDF_FormField* pFormField = FieldArray[0];
1616 ASSERT(pFormField);
1617 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1618 if (!pFormControl)
1619 return false;
1620
1621 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1622 if (!pFormField->CountControls())
1623 return false;
1624
1625 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
1626 if (!pWidget)
1627 return false;
1628
1629 vp << (int32_t)pWidget->GetBorderWidth();
tsepez4cf55152016-11-02 14:37:54 -07001630 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001631}
1632
dsinclair3a7741a2016-10-11 10:39:49 -07001633void Field::SetLineWidth(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001634 const CFX_WideString& swFieldName,
1635 int nControlIndex,
1636 int number) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001637 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001638 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07001639 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -08001640 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001641 if (nControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -07001642 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001643 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1644 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08001645 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001646
dsinclairc5267c52016-11-04 15:35:12 -07001647 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001648 if (number != pWidget->GetBorderWidth()) {
1649 pWidget->SetBorderWidth(number);
tsepez4cf55152016-11-02 14:37:54 -07001650 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001651 }
1652 }
1653 }
1654 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -07001655 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001656 } else {
1657 if (nControlIndex >= pFormField->CountControls())
1658 return;
1659 if (CPDF_FormControl* pFormControl =
1660 pFormField->GetControl(nControlIndex)) {
dsinclairc5267c52016-11-04 15:35:12 -07001661 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001662 if (number != pWidget->GetBorderWidth()) {
1663 pWidget->SetBorderWidth(number);
tsepez4cf55152016-11-02 14:37:54 -07001664 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001665 }
1666 }
1667 }
1668 }
1669 }
1670}
1671
Tom Sepezb1670b52017-02-16 17:01:00 -08001672bool Field::multiline(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001673 CJS_PropValue& vp,
1674 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001675 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001676
1677 if (vp.IsSetting()) {
1678 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001679 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001680
1681 bool bVP;
1682 vp >> bVP;
1683
1684 if (m_bDelay) {
1685 AddDelay_Bool(FP_MULTILINE, bVP);
1686 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001687 Field::SetMultiline(m_pFormFillEnv.Get(), m_FieldName,
1688 m_nFormControlIndex, bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001689 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001690 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001691 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001692 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1693 if (FieldArray.empty())
1694 return false;
1695
1696 CPDF_FormField* pFormField = FieldArray[0];
1697 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1698 return false;
1699
1700 if (pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE)
1701 vp << true;
1702 else
1703 vp << false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001704
tsepez4cf55152016-11-02 14:37:54 -07001705 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001706}
1707
dsinclair3a7741a2016-10-11 10:39:49 -07001708void Field::SetMultiline(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001709 const CFX_WideString& swFieldName,
1710 int nControlIndex,
1711 bool b) {
1712 // Not supported.
1713}
1714
Tom Sepezb1670b52017-02-16 17:01:00 -08001715bool Field::multipleSelection(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001716 CJS_PropValue& vp,
1717 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001718 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001719 if (vp.IsSetting()) {
1720 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001721 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001722
1723 bool bVP;
1724 vp >> bVP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001725 if (m_bDelay) {
1726 AddDelay_Bool(FP_MULTIPLESELECTION, bVP);
1727 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001728 Field::SetMultipleSelection(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -07001729 m_nFormControlIndex, bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001730 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001731 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001732 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001733 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1734 if (FieldArray.empty())
1735 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001736
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001737 CPDF_FormField* pFormField = FieldArray[0];
1738 if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
1739 return false;
1740
1741 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT);
tsepez4cf55152016-11-02 14:37:54 -07001742 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001743}
1744
dsinclair3a7741a2016-10-11 10:39:49 -07001745void Field::SetMultipleSelection(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001746 const CFX_WideString& swFieldName,
1747 int nControlIndex,
1748 bool b) {
1749 // Not supported.
1750}
1751
Tom Sepezb1670b52017-02-16 17:01:00 -08001752bool Field::name(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001753 CJS_PropValue& vp,
1754 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001755 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -07001756 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001757
Lei Zhangd88a3642015-11-10 09:38:57 -08001758 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1759 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001760 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001761
1762 vp << m_FieldName;
tsepez4cf55152016-11-02 14:37:54 -07001763 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001764}
1765
Tom Sepezb1670b52017-02-16 17:01:00 -08001766bool Field::numItems(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001767 CJS_PropValue& vp,
1768 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07001769 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -07001770 return false;
Tom Sepez67fd5df2015-10-08 12:24:19 -07001771
Lei Zhangd88a3642015-11-10 09:38:57 -08001772 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1773 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001774 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001775
Lei Zhangd88a3642015-11-10 09:38:57 -08001776 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001777 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001778 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
tsepez4cf55152016-11-02 14:37:54 -07001779 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001780 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001781
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001782 vp << (int32_t)pFormField->CountOptions();
tsepez4cf55152016-11-02 14:37:54 -07001783 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001784}
1785
Tom Sepezb1670b52017-02-16 17:01:00 -08001786bool Field::page(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001787 CJS_PropValue& vp,
1788 CFX_WideString& sError) {
tsepez8fa82792017-01-11 09:32:33 -08001789 if (!vp.IsGetting()) {
1790 sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
tsepez4cf55152016-11-02 14:37:54 -07001791 return false;
tsepez8fa82792017-01-11 09:32:33 -08001792 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001793
Lei Zhangd88a3642015-11-10 09:38:57 -08001794 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1795 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001796 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001797
Lei Zhangd88a3642015-11-10 09:38:57 -08001798 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001799 if (!pFormField)
tsepez4cf55152016-11-02 14:37:54 -07001800 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001801
tsepez8fa82792017-01-11 09:32:33 -08001802 std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
dsinclair7cbe68e2016-10-12 11:56:23 -07001803 m_pFormFillEnv->GetInterForm()->GetWidgets(pFormField, &widgets);
Lei Zhangd88a3642015-11-10 09:38:57 -08001804 if (widgets.empty()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001805 vp << (int32_t)-1;
tsepez4cf55152016-11-02 14:37:54 -07001806 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001807 }
1808
tsepeze5aff742016-08-08 09:49:42 -07001809 CJS_Array PageArray;
tsepez8fa82792017-01-11 09:32:33 -08001810 int i = 0;
1811 for (const auto& pObserved : widgets) {
1812 if (!pObserved) {
1813 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
1814 return false;
1815 }
1816
1817 auto pWidget = static_cast<CPDFSDK_Widget*>(pObserved.Get());
1818 CPDFSDK_PageView* pPageView = pWidget->GetPageView();
Lei Zhangd88a3642015-11-10 09:38:57 -08001819 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -07001820 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001821
1822 PageArray.SetElement(
tsepezb4694242016-08-15 16:44:55 -07001823 pRuntime, i, CJS_Value(pRuntime, (int32_t)pPageView->GetPageIndex()));
tsepez8fa82792017-01-11 09:32:33 -08001824 ++i;
Lei Zhangd88a3642015-11-10 09:38:57 -08001825 }
1826
1827 vp << PageArray;
tsepez4cf55152016-11-02 14:37:54 -07001828 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001829}
1830
Tom Sepezb1670b52017-02-16 17:01:00 -08001831bool Field::password(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001832 CJS_PropValue& vp,
1833 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001834 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001835
1836 if (vp.IsSetting()) {
1837 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001838 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001839
1840 bool bVP;
1841 vp >> bVP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001842 if (m_bDelay) {
1843 AddDelay_Bool(FP_PASSWORD, bVP);
1844 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001845 Field::SetPassword(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07001846 bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001847 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001848 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001849 }
1850
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001851 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1852 if (FieldArray.empty())
1853 return false;
1854
1855 CPDF_FormField* pFormField = FieldArray[0];
1856 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1857 return false;
1858
1859 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD);
tsepez4cf55152016-11-02 14:37:54 -07001860 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001861}
1862
dsinclair3a7741a2016-10-11 10:39:49 -07001863void Field::SetPassword(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001864 const CFX_WideString& swFieldName,
1865 int nControlIndex,
1866 bool b) {
1867 // Not supported.
1868}
1869
Tom Sepezb1670b52017-02-16 17:01:00 -08001870bool Field::print(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001871 CJS_PropValue& vp,
1872 CFX_WideString& sError) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001873 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001874 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1875 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001876 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001877
1878 if (vp.IsSetting()) {
1879 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001880 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001881
1882 bool bVP;
1883 vp >> bVP;
1884
Lei Zhangd88a3642015-11-10 09:38:57 -08001885 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001886 if (m_nFormControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -07001887 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001888 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001889 if (CPDFSDK_Widget* pWidget =
dsinclairc5267c52016-11-04 15:35:12 -07001890 pInterForm->GetWidget(pFormField->GetControl(i))) {
tsepezc3255f52016-03-25 14:52:27 -07001891 uint32_t dwFlags = pWidget->GetFlags();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001892 if (bVP)
1893 dwFlags |= ANNOTFLAG_PRINT;
1894 else
1895 dwFlags &= ~ANNOTFLAG_PRINT;
1896
1897 if (dwFlags != pWidget->GetFlags()) {
1898 pWidget->SetFlags(dwFlags);
tsepez4cf55152016-11-02 14:37:54 -07001899 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001900 }
1901 }
1902 }
1903
1904 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -07001905 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001906 } else {
1907 if (m_nFormControlIndex >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07001908 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001909 if (CPDF_FormControl* pFormControl =
1910 pFormField->GetControl(m_nFormControlIndex)) {
dsinclairc5267c52016-11-04 15:35:12 -07001911 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
tsepezc3255f52016-03-25 14:52:27 -07001912 uint32_t dwFlags = pWidget->GetFlags();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001913 if (bVP)
1914 dwFlags |= ANNOTFLAG_PRINT;
1915 else
1916 dwFlags &= ~ANNOTFLAG_PRINT;
1917
1918 if (dwFlags != pWidget->GetFlags()) {
1919 pWidget->SetFlags(dwFlags);
dsinclair3a7741a2016-10-11 10:39:49 -07001920 UpdateFormControl(m_pFormFillEnv.Get(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001921 pFormField->GetControl(m_nFormControlIndex),
tsepez4cf55152016-11-02 14:37:54 -07001922 true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001923 }
1924 }
1925 }
1926 }
1927 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001928 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001929 }
1930
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001931 CPDF_FormField* pFormField = FieldArray[0];
1932 CPDFSDK_Widget* pWidget =
1933 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1934 if (!pWidget)
1935 return false;
1936
1937 vp << !!(pWidget->GetFlags() & ANNOTFLAG_PRINT);
tsepez4cf55152016-11-02 14:37:54 -07001938 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001939}
1940
Tom Sepezb1670b52017-02-16 17:01:00 -08001941bool Field::radiosInUnison(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001942 CJS_PropValue& vp,
1943 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001944 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1945 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001946 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001947
1948 if (vp.IsSetting()) {
1949 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001950 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001951
1952 bool bVP;
1953 vp >> bVP;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001954 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001955 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001956 CPDF_FormField* pFormField = FieldArray[0];
1957 if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
1958 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001959
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001960 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON);
tsepez4cf55152016-11-02 14:37:54 -07001961 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001962}
1963
Tom Sepezb1670b52017-02-16 17:01:00 -08001964bool Field::readonly(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07001965 CJS_PropValue& vp,
1966 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001967 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1968 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001969 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001970
1971 if (vp.IsSetting()) {
1972 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001973 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001974
1975 bool bVP;
1976 vp >> bVP;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001977 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001978 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001979 vp << !!(FieldArray[0]->GetFieldFlags() & FIELDFLAG_READONLY);
tsepez4cf55152016-11-02 14:37:54 -07001980 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001981}
1982
Tom Sepezb1670b52017-02-16 17:01:00 -08001983bool Field::rect(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001984 CJS_PropValue& vp,
1985 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07001986 CJS_Value Upper_Leftx(pRuntime);
1987 CJS_Value Upper_Lefty(pRuntime);
1988 CJS_Value Lower_Rightx(pRuntime);
1989 CJS_Value Lower_Righty(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001990
1991 if (vp.IsSetting()) {
1992 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001993 return false;
tsepezf3dc8c62016-08-10 06:29:29 -07001994 if (!vp.GetJSValue()->IsArrayObject())
tsepez4cf55152016-11-02 14:37:54 -07001995 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001996
tsepeze5aff742016-08-08 09:49:42 -07001997 CJS_Array rcArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001998 vp >> rcArray;
tsepezb4694242016-08-15 16:44:55 -07001999 rcArray.GetElement(pRuntime, 0, Upper_Leftx);
2000 rcArray.GetElement(pRuntime, 1, Upper_Lefty);
2001 rcArray.GetElement(pRuntime, 2, Lower_Rightx);
2002 rcArray.GetElement(pRuntime, 3, Lower_Righty);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002003
2004 FX_FLOAT pArray[4] = {0.0f, 0.0f, 0.0f, 0.0f};
tsepezb4694242016-08-15 16:44:55 -07002005 pArray[0] = static_cast<FX_FLOAT>(Upper_Leftx.ToInt(pRuntime));
2006 pArray[1] = static_cast<FX_FLOAT>(Lower_Righty.ToInt(pRuntime));
2007 pArray[2] = static_cast<FX_FLOAT>(Lower_Rightx.ToInt(pRuntime));
2008 pArray[3] = static_cast<FX_FLOAT>(Upper_Lefty.ToInt(pRuntime));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002009
Tom Sepez281a9ea2016-02-26 14:24:28 -08002010 CFX_FloatRect crRect(pArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002011 if (m_bDelay) {
2012 AddDelay_Rect(FP_RECT, crRect);
2013 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002014 Field::SetRect(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07002015 crRect);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002016 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002017 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002018 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002019 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2020 if (FieldArray.empty())
2021 return false;
2022
2023 CPDF_FormField* pFormField = FieldArray[0];
2024 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
2025 CPDFSDK_Widget* pWidget =
2026 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
2027 if (!pWidget)
2028 return false;
2029
2030 CFX_FloatRect crRect = pWidget->GetRect();
2031 Upper_Leftx = CJS_Value(pRuntime, static_cast<int32_t>(crRect.left));
2032 Upper_Lefty = CJS_Value(pRuntime, static_cast<int32_t>(crRect.top));
2033 Lower_Rightx = CJS_Value(pRuntime, static_cast<int32_t>(crRect.right));
2034 Lower_Righty = CJS_Value(pRuntime, static_cast<int32_t>(crRect.bottom));
2035
2036 CJS_Array rcArray;
2037 rcArray.SetElement(pRuntime, 0, Upper_Leftx);
2038 rcArray.SetElement(pRuntime, 1, Upper_Lefty);
2039 rcArray.SetElement(pRuntime, 2, Lower_Rightx);
2040 rcArray.SetElement(pRuntime, 3, Lower_Righty);
2041 vp << rcArray;
tsepez4cf55152016-11-02 14:37:54 -07002042 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002043}
2044
dsinclair3a7741a2016-10-11 10:39:49 -07002045void Field::SetRect(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002046 const CFX_WideString& swFieldName,
2047 int nControlIndex,
Tom Sepez281a9ea2016-02-26 14:24:28 -08002048 const CFX_FloatRect& rect) {
dsinclair7cbe68e2016-10-12 11:56:23 -07002049 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08002050 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07002051 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -08002052 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002053 if (nControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -07002054 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08002055 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002056 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08002057 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002058
dsinclairc5267c52016-11-04 15:35:12 -07002059 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002060 CFX_FloatRect crRect = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002061
2062 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002063 crRect.Intersect(pPDFPage->GetPageBBox());
2064
2065 if (!crRect.IsEmpty()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002066 CFX_FloatRect rcOld = pWidget->GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002067 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
2068 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
2069 pWidget->SetRect(crRect);
tsepez4cf55152016-11-02 14:37:54 -07002070 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002071 }
2072 }
2073 }
2074 }
2075
2076 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -07002077 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002078 } else {
2079 if (nControlIndex >= pFormField->CountControls())
2080 return;
2081 if (CPDF_FormControl* pFormControl =
2082 pFormField->GetControl(nControlIndex)) {
dsinclairc5267c52016-11-04 15:35:12 -07002083 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002084 CFX_FloatRect crRect = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002085
2086 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002087 crRect.Intersect(pPDFPage->GetPageBBox());
2088
2089 if (!crRect.IsEmpty()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002090 CFX_FloatRect rcOld = pWidget->GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002091 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
2092 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
2093 pWidget->SetRect(crRect);
tsepez4cf55152016-11-02 14:37:54 -07002094 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002095 }
2096 }
2097 }
2098 }
2099 }
2100 }
2101}
2102
Tom Sepezb1670b52017-02-16 17:01:00 -08002103bool Field::required(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002104 CJS_PropValue& vp,
2105 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002106 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2107 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002108 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002109
2110 if (vp.IsSetting()) {
2111 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002112 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002113
2114 bool bVP;
2115 vp >> bVP;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002116 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002117 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002118 CPDF_FormField* pFormField = FieldArray[0];
2119 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
2120 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002121
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002122 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED);
tsepez4cf55152016-11-02 14:37:54 -07002123 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002124}
2125
Tom Sepezb1670b52017-02-16 17:01:00 -08002126bool Field::richText(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002127 CJS_PropValue& vp,
2128 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002129 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002130
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002131 if (vp.IsSetting()) {
2132 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002133 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002134
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002135 bool bVP;
2136 vp >> bVP;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002137 if (m_bDelay)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002138 AddDelay_Bool(FP_RICHTEXT, bVP);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002139
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002140 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002141 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002142
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002143 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2144 if (FieldArray.empty())
2145 return false;
2146
2147 CPDF_FormField* pFormField = FieldArray[0];
2148 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
2149 return false;
2150
2151 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT);
tsepez4cf55152016-11-02 14:37:54 -07002152 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002153}
2154
Tom Sepezb1670b52017-02-16 17:01:00 -08002155bool Field::richValue(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002156 CJS_PropValue& vp,
2157 CFX_WideString& sError) {
2158 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002159}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002160
Tom Sepezb1670b52017-02-16 17:01:00 -08002161bool Field::rotation(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002162 CJS_PropValue& vp,
2163 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002164 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002165
2166 if (vp.IsSetting()) {
2167 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002168 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002169
2170 int nVP;
2171 vp >> nVP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002172 if (m_bDelay) {
2173 AddDelay_Int(FP_ROTATION, nVP);
2174 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002175 Field::SetRotation(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07002176 nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002177 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002178 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002179 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002180 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2181 if (FieldArray.empty())
2182 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002183
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002184 CPDF_FormField* pFormField = FieldArray[0];
2185 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2186 if (!pFormControl)
2187 return false;
2188
2189 vp << (int32_t)pFormControl->GetRotation();
tsepez4cf55152016-11-02 14:37:54 -07002190 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002191}
2192
dsinclair3a7741a2016-10-11 10:39:49 -07002193void Field::SetRotation(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002194 const CFX_WideString& swFieldName,
2195 int nControlIndex,
2196 int number) {
2197 // Not supported.
2198}
2199
Tom Sepezb1670b52017-02-16 17:01:00 -08002200bool Field::strokeColor(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002201 CJS_PropValue& vp,
2202 CFX_WideString& sError) {
tsepeze5aff742016-08-08 09:49:42 -07002203 CJS_Array crArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002204
2205 if (vp.IsSetting()) {
2206 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002207 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002208
tsepezf3dc8c62016-08-10 06:29:29 -07002209 if (!vp.GetJSValue()->IsArrayObject())
tsepez4cf55152016-11-02 14:37:54 -07002210 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002211
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002212 vp >> crArray;
2213
2214 CPWL_Color color;
tsepeze5aff742016-08-08 09:49:42 -07002215 color::ConvertArrayToPWLColor(pRuntime, crArray, &color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002216 if (m_bDelay) {
2217 AddDelay_Color(FP_STROKECOLOR, color);
2218 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002219 Field::SetStrokeColor(m_pFormFillEnv.Get(), m_FieldName,
2220 m_nFormControlIndex, color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002221 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002222 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002223 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002224 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2225 if (FieldArray.empty())
2226 return false;
2227
2228 CPDF_FormField* pFormField = FieldArray[0];
2229 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2230 if (!pFormControl)
2231 return false;
2232
2233 int iColorType;
2234 pFormControl->GetBorderColor(iColorType);
2235
2236 CPWL_Color color;
2237 if (iColorType == COLORTYPE_TRANSPARENT) {
2238 color = CPWL_Color(COLORTYPE_TRANSPARENT);
2239 } else if (iColorType == COLORTYPE_GRAY) {
2240 color = CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBorderColor(0));
2241 } else if (iColorType == COLORTYPE_RGB) {
2242 color = CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBorderColor(0),
2243 pFormControl->GetOriginalBorderColor(1),
2244 pFormControl->GetOriginalBorderColor(2));
2245 } else if (iColorType == COLORTYPE_CMYK) {
2246 color = CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBorderColor(0),
2247 pFormControl->GetOriginalBorderColor(1),
2248 pFormControl->GetOriginalBorderColor(2),
2249 pFormControl->GetOriginalBorderColor(3));
2250 } else {
2251 return false;
2252 }
2253
2254 color::ConvertPWLColorToArray(pRuntime, color, &crArray);
2255 vp << crArray;
tsepez4cf55152016-11-02 14:37:54 -07002256 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002257}
2258
dsinclair3a7741a2016-10-11 10:39:49 -07002259void Field::SetStrokeColor(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002260 const CFX_WideString& swFieldName,
2261 int nControlIndex,
2262 const CPWL_Color& color) {
2263 // Not supported.
2264}
2265
Tom Sepezb1670b52017-02-16 17:01:00 -08002266bool Field::style(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002267 CJS_PropValue& vp,
2268 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002269 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002270
2271 if (vp.IsSetting()) {
2272 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002273 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002274
2275 CFX_ByteString csBCaption;
2276 vp >> csBCaption;
2277
2278 if (m_bDelay) {
2279 AddDelay_String(FP_STYLE, csBCaption);
2280 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002281 Field::SetStyle(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002282 csBCaption);
2283 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002284 return true;
2285 }
2286 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2287 if (FieldArray.empty())
2288 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002289
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002290 CPDF_FormField* pFormField = FieldArray[0];
2291 if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON &&
2292 pFormField->GetFieldType() != FIELDTYPE_CHECKBOX) {
2293 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002294 }
2295
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002296 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2297 if (!pFormControl)
2298 return false;
2299
2300 CFX_WideString csWCaption = pFormControl->GetNormalCaption();
2301 CFX_ByteString csBCaption;
2302
2303 switch (csWCaption[0]) {
2304 case L'l':
2305 csBCaption = "circle";
2306 break;
2307 case L'8':
2308 csBCaption = "cross";
2309 break;
2310 case L'u':
2311 csBCaption = "diamond";
2312 break;
2313 case L'n':
2314 csBCaption = "square";
2315 break;
2316 case L'H':
2317 csBCaption = "star";
2318 break;
2319 default: // L'4'
2320 csBCaption = "check";
2321 break;
2322 }
2323 vp << csBCaption;
tsepez4cf55152016-11-02 14:37:54 -07002324 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002325}
2326
dsinclair3a7741a2016-10-11 10:39:49 -07002327void Field::SetStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002328 const CFX_WideString& swFieldName,
2329 int nControlIndex,
2330 const CFX_ByteString& string) {
2331 // Not supported.
2332}
2333
Tom Sepezb1670b52017-02-16 17:01:00 -08002334bool Field::submitName(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002335 CJS_PropValue& vp,
2336 CFX_WideString& sError) {
2337 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002338}
2339
Tom Sepezb1670b52017-02-16 17:01:00 -08002340bool Field::textColor(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002341 CJS_PropValue& vp,
2342 CFX_WideString& sError) {
tsepeze5aff742016-08-08 09:49:42 -07002343 CJS_Array crArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002344
2345 if (vp.IsSetting()) {
2346 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002347 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002348
tsepezf3dc8c62016-08-10 06:29:29 -07002349 if (!vp.GetJSValue()->IsArrayObject())
tsepez4cf55152016-11-02 14:37:54 -07002350 return false;
Tom Sepez67fd5df2015-10-08 12:24:19 -07002351
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002352 vp >> crArray;
2353
2354 CPWL_Color color;
tsepeze5aff742016-08-08 09:49:42 -07002355 color::ConvertArrayToPWLColor(pRuntime, crArray, &color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002356 if (m_bDelay) {
2357 AddDelay_Color(FP_TEXTCOLOR, color);
2358 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002359 Field::SetTextColor(m_pFormFillEnv.Get(), m_FieldName,
2360 m_nFormControlIndex, color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002361 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002362 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002363 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002364 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2365 if (FieldArray.empty())
2366 return false;
2367
2368 CPDF_FormField* pFormField = FieldArray[0];
2369 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2370 if (!pFormControl)
2371 return false;
2372
2373 int iColorType;
2374 FX_ARGB color;
2375 CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
2376 FieldAppearance.GetColor(color, iColorType);
2377
2378 int32_t a;
2379 int32_t r;
2380 int32_t g;
2381 int32_t b;
2382 ArgbDecode(color, a, r, g, b);
2383
2384 CPWL_Color crRet =
2385 CPWL_Color(COLORTYPE_RGB, r / 255.0f, g / 255.0f, b / 255.0f);
2386
2387 if (iColorType == COLORTYPE_TRANSPARENT)
2388 crRet = CPWL_Color(COLORTYPE_TRANSPARENT);
2389
2390 color::ConvertPWLColorToArray(pRuntime, crRet, &crArray);
2391 vp << crArray;
tsepez4cf55152016-11-02 14:37:54 -07002392 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002393}
2394
dsinclair3a7741a2016-10-11 10:39:49 -07002395void Field::SetTextColor(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002396 const CFX_WideString& swFieldName,
2397 int nControlIndex,
2398 const CPWL_Color& color) {
2399 // Not supported.
2400}
2401
Tom Sepezb1670b52017-02-16 17:01:00 -08002402bool Field::textFont(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002403 CJS_PropValue& vp,
2404 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002405 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002406
2407 if (vp.IsSetting()) {
2408 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002409 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002410
2411 CFX_ByteString csFontName;
2412 vp >> csFontName;
2413 if (csFontName.IsEmpty())
tsepez4cf55152016-11-02 14:37:54 -07002414 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002415
2416 if (m_bDelay) {
2417 AddDelay_String(FP_TEXTFONT, csFontName);
2418 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002419 Field::SetTextFont(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002420 csFontName);
2421 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002422 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002423 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002424 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2425 if (FieldArray.empty())
2426 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002427
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002428 CPDF_FormField* pFormField = FieldArray[0];
2429 ASSERT(pFormField);
2430 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2431 if (!pFormControl)
2432 return false;
2433
2434 int nFieldType = pFormField->GetFieldType();
2435 if (nFieldType != FIELDTYPE_PUSHBUTTON && nFieldType != FIELDTYPE_COMBOBOX &&
2436 nFieldType != FIELDTYPE_LISTBOX && nFieldType != FIELDTYPE_TEXTFIELD) {
2437 return false;
2438 }
2439 CPDF_Font* pFont = pFormControl->GetDefaultControlFont();
2440 if (!pFont)
2441 return false;
2442
2443 vp << pFont->GetBaseFont();
tsepez4cf55152016-11-02 14:37:54 -07002444 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002445}
2446
dsinclair3a7741a2016-10-11 10:39:49 -07002447void Field::SetTextFont(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002448 const CFX_WideString& swFieldName,
2449 int nControlIndex,
2450 const CFX_ByteString& string) {
2451 // Not supported.
2452}
2453
Tom Sepezb1670b52017-02-16 17:01:00 -08002454bool Field::textSize(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002455 CJS_PropValue& vp,
2456 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002457 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002458
2459 if (vp.IsSetting()) {
2460 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002461 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002462
2463 int nVP;
2464 vp >> nVP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002465 if (m_bDelay) {
2466 AddDelay_Int(FP_TEXTSIZE, nVP);
2467 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002468 Field::SetTextSize(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07002469 nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002470 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002471 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002472 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002473 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2474 if (FieldArray.empty())
2475 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002476
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002477 CPDF_FormField* pFormField = FieldArray[0];
2478 ASSERT(pFormField);
2479 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2480 if (!pFormControl)
2481 return false;
2482
2483 CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
2484
2485 CFX_ByteString csFontNameTag;
2486 FX_FLOAT fFontSize;
2487 FieldAppearance.GetFont(csFontNameTag, fFontSize);
2488 vp << (int)fFontSize;
tsepez4cf55152016-11-02 14:37:54 -07002489 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002490}
2491
dsinclair3a7741a2016-10-11 10:39:49 -07002492void Field::SetTextSize(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002493 const CFX_WideString& swFieldName,
2494 int nControlIndex,
2495 int number) {
2496 // Not supported.
2497}
2498
Tom Sepezb1670b52017-02-16 17:01:00 -08002499bool Field::type(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002500 CJS_PropValue& vp,
2501 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002502 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -07002503 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002504
Lei Zhangd88a3642015-11-10 09:38:57 -08002505 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2506 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002507 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002508
Lei Zhangd88a3642015-11-10 09:38:57 -08002509 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002510 switch (pFormField->GetFieldType()) {
2511 case FIELDTYPE_UNKNOWN:
2512 vp << L"unknown";
2513 break;
2514 case FIELDTYPE_PUSHBUTTON:
2515 vp << L"button";
2516 break;
2517 case FIELDTYPE_CHECKBOX:
2518 vp << L"checkbox";
2519 break;
2520 case FIELDTYPE_RADIOBUTTON:
2521 vp << L"radiobutton";
2522 break;
2523 case FIELDTYPE_COMBOBOX:
2524 vp << L"combobox";
2525 break;
2526 case FIELDTYPE_LISTBOX:
2527 vp << L"listbox";
2528 break;
2529 case FIELDTYPE_TEXTFIELD:
2530 vp << L"text";
2531 break;
2532 case FIELDTYPE_SIGNATURE:
2533 vp << L"signature";
2534 break;
2535 default:
2536 vp << L"unknown";
2537 break;
2538 }
tsepez4cf55152016-11-02 14:37:54 -07002539 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002540}
2541
Tom Sepezb1670b52017-02-16 17:01:00 -08002542bool Field::userName(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002543 CJS_PropValue& vp,
2544 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002545 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002546
2547 if (vp.IsSetting()) {
2548 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002549 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002550
2551 CFX_WideString swName;
2552 vp >> swName;
2553
2554 if (m_bDelay) {
2555 AddDelay_WideString(FP_USERNAME, swName);
2556 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002557 Field::SetUserName(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07002558 swName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002559 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002560 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002561 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002562 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2563 if (FieldArray.empty())
2564 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002565
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002566 vp << FieldArray[0]->GetAlternateName();
tsepez4cf55152016-11-02 14:37:54 -07002567 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002568}
2569
dsinclair3a7741a2016-10-11 10:39:49 -07002570void Field::SetUserName(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002571 const CFX_WideString& swFieldName,
2572 int nControlIndex,
2573 const CFX_WideString& string) {
2574 // Not supported.
2575}
2576
Tom Sepezb1670b52017-02-16 17:01:00 -08002577bool Field::value(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002578 CJS_PropValue& vp,
2579 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002580 if (vp.IsSetting()) {
2581 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002582 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002583
tsepez41a53ad2016-03-28 16:59:30 -07002584 std::vector<CFX_WideString> strArray;
tsepezf3dc8c62016-08-10 06:29:29 -07002585 if (vp.GetJSValue()->IsArrayObject()) {
tsepeze5aff742016-08-08 09:49:42 -07002586 CJS_Array ValueArray;
tsepezb4694242016-08-15 16:44:55 -07002587 vp.GetJSValue()->ConvertToArray(pRuntime, ValueArray);
2588 for (int i = 0, sz = ValueArray.GetLength(pRuntime); i < sz; i++) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002589 CJS_Value ElementValue(pRuntime);
tsepezb4694242016-08-15 16:44:55 -07002590 ValueArray.GetElement(pRuntime, i, ElementValue);
2591 strArray.push_back(ElementValue.ToCFXWideString(pRuntime));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002592 }
2593 } else {
2594 CFX_WideString swValue;
2595 vp >> swValue;
tsepez41a53ad2016-03-28 16:59:30 -07002596 strArray.push_back(swValue);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002597 }
2598
2599 if (m_bDelay) {
2600 AddDelay_WideStringArray(FP_VALUE, strArray);
2601 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002602 Field::SetValue(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07002603 strArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002604 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002605 return true;
2606 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002607
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002608 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2609 if (FieldArray.empty())
2610 return false;
2611
2612 CPDF_FormField* pFormField = FieldArray[0];
2613 switch (pFormField->GetFieldType()) {
2614 case FIELDTYPE_PUSHBUTTON:
2615 return false;
2616 case FIELDTYPE_COMBOBOX:
2617 case FIELDTYPE_TEXTFIELD: {
2618 vp << pFormField->GetValue();
2619 } break;
2620 case FIELDTYPE_LISTBOX: {
2621 if (pFormField->CountSelectedItems() > 1) {
2622 CJS_Array ValueArray;
2623 CJS_Value ElementValue(pRuntime);
2624 int iIndex;
2625 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
2626 iIndex = pFormField->GetSelectedIndex(i);
2627 ElementValue =
2628 CJS_Value(pRuntime, pFormField->GetOptionValue(iIndex).c_str());
2629 if (FXSYS_wcslen(ElementValue.ToCFXWideString(pRuntime).c_str()) ==
2630 0) {
tsepezf3dc8c62016-08-10 06:29:29 -07002631 ElementValue =
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002632 CJS_Value(pRuntime, pFormField->GetOptionLabel(iIndex).c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002633 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002634 ValueArray.SetElement(pRuntime, i, ElementValue);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002635 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002636 vp << ValueArray;
2637 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002638 vp << pFormField->GetValue();
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002639 }
2640 } break;
2641 case FIELDTYPE_CHECKBOX:
2642 case FIELDTYPE_RADIOBUTTON: {
2643 bool bFind = false;
2644 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2645 if (pFormField->GetControl(i)->IsChecked()) {
2646 vp << pFormField->GetControl(i)->GetExportValue();
2647 bFind = true;
2648 break;
2649 }
2650 }
2651 if (!bFind)
2652 vp << L"Off";
2653 } break;
2654 default:
2655 vp << pFormField->GetValue();
2656 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002657 }
tsepezb4694242016-08-15 16:44:55 -07002658 vp.GetJSValue()->MaybeCoerceToNumber(pRuntime);
tsepez4cf55152016-11-02 14:37:54 -07002659 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002660}
2661
dsinclair3a7741a2016-10-11 10:39:49 -07002662void Field::SetValue(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002663 const CFX_WideString& swFieldName,
2664 int nControlIndex,
tsepez41a53ad2016-03-28 16:59:30 -07002665 const std::vector<CFX_WideString>& strArray) {
dsinclair3a7741a2016-10-11 10:39:49 -07002666 ASSERT(pFormFillEnv);
tsepez41a53ad2016-03-28 16:59:30 -07002667 if (strArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002668 return;
2669
Lei Zhangd88a3642015-11-10 09:38:57 -08002670 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07002671 GetFormFields(pFormFillEnv, swFieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002672
Lei Zhangd88a3642015-11-10 09:38:57 -08002673 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002674 if (pFormField->GetFullName().Compare(swFieldName) != 0)
2675 continue;
2676
2677 switch (pFormField->GetFieldType()) {
2678 case FIELDTYPE_TEXTFIELD:
2679 case FIELDTYPE_COMBOBOX:
tsepez41a53ad2016-03-28 16:59:30 -07002680 if (pFormField->GetValue() != strArray[0]) {
tsepez4cf55152016-11-02 14:37:54 -07002681 pFormField->SetValue(strArray[0], true);
2682 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002683 }
2684 break;
tsepez41a53ad2016-03-28 16:59:30 -07002685 case FIELDTYPE_CHECKBOX:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002686 case FIELDTYPE_RADIOBUTTON: {
tsepez41a53ad2016-03-28 16:59:30 -07002687 if (pFormField->GetValue() != strArray[0]) {
tsepez4cf55152016-11-02 14:37:54 -07002688 pFormField->SetValue(strArray[0], true);
2689 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002690 }
2691 } break;
2692 case FIELDTYPE_LISTBOX: {
tsepez4cf55152016-11-02 14:37:54 -07002693 bool bModified = false;
tsepez41a53ad2016-03-28 16:59:30 -07002694 for (const auto& str : strArray) {
2695 if (!pFormField->IsItemSelected(pFormField->FindOption(str))) {
tsepez4cf55152016-11-02 14:37:54 -07002696 bModified = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002697 break;
2698 }
2699 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002700 if (bModified) {
tsepez4cf55152016-11-02 14:37:54 -07002701 pFormField->ClearSelection(true);
tsepez41a53ad2016-03-28 16:59:30 -07002702 for (const auto& str : strArray) {
2703 int index = pFormField->FindOption(str);
2704 if (!pFormField->IsItemSelected(index))
tsepez4cf55152016-11-02 14:37:54 -07002705 pFormField->SetItemSelection(index, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002706 }
tsepez4cf55152016-11-02 14:37:54 -07002707 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002708 }
2709 } break;
2710 default:
2711 break;
2712 }
2713 }
2714}
2715
Tom Sepezb1670b52017-02-16 17:01:00 -08002716bool Field::valueAsString(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002717 CJS_PropValue& vp,
2718 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002719 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -07002720 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002721
Lei Zhangd88a3642015-11-10 09:38:57 -08002722 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2723 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002724 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002725
Lei Zhangd88a3642015-11-10 09:38:57 -08002726 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002727 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002728 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002729
2730 if (pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) {
2731 if (!pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002732 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002733
2734 if (pFormField->GetControl(0)->IsChecked())
2735 vp << L"Yes";
2736 else
2737 vp << L"Off";
2738 } else if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON &&
2739 !(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)) {
2740 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2741 if (pFormField->GetControl(i)->IsChecked()) {
2742 vp << pFormField->GetControl(i)->GetExportValue().c_str();
2743 break;
Lei Zhangd88a3642015-11-10 09:38:57 -08002744 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002745 vp << L"Off";
Lei Zhangd88a3642015-11-10 09:38:57 -08002746 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002747 }
2748 } else if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX &&
2749 (pFormField->CountSelectedItems() > 1)) {
2750 vp << L"";
Lei Zhangd88a3642015-11-10 09:38:57 -08002751 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002752 vp << pFormField->GetValue().c_str();
Lei Zhangd88a3642015-11-10 09:38:57 -08002753 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002754
tsepez4cf55152016-11-02 14:37:54 -07002755 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002756}
2757
Tom Sepezb1670b52017-02-16 17:01:00 -08002758bool Field::browseForFileToSubmit(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002759 const std::vector<CJS_Value>& params,
2760 CJS_Value& vRet,
2761 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002762 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2763 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002764 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002765
Lei Zhangd88a3642015-11-10 09:38:57 -08002766 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002767 if ((pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) &&
2768 (pFormField->GetFieldType() == FIELDTYPE_TEXTFIELD)) {
dsinclair3a7741a2016-10-11 10:39:49 -07002769 CFX_WideString wsFileName = m_pFormFillEnv->JS_fieldBrowse();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002770 if (!wsFileName.IsEmpty()) {
2771 pFormField->SetValue(wsFileName);
tsepez4cf55152016-11-02 14:37:54 -07002772 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002773 }
tsepez4cf55152016-11-02 14:37:54 -07002774 return true;
Lei Zhangd88a3642015-11-10 09:38:57 -08002775 }
tsepez4cf55152016-11-02 14:37:54 -07002776 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002777}
2778
Tom Sepezb1670b52017-02-16 17:01:00 -08002779bool Field::buttonGetCaption(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002780 const std::vector<CJS_Value>& params,
2781 CJS_Value& vRet,
2782 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002783 int nface = 0;
2784 int iSize = params.size();
2785 if (iSize >= 1)
tsepezb4694242016-08-15 16:44:55 -07002786 nface = params[0].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002787
Lei Zhangd88a3642015-11-10 09:38:57 -08002788 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2789 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002790 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002791
Lei Zhangd88a3642015-11-10 09:38:57 -08002792 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002793 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002794 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002795
2796 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2797 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -07002798 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002799
2800 if (nface == 0)
tsepezf3dc8c62016-08-10 06:29:29 -07002801 vRet = CJS_Value(pRuntime, pFormControl->GetNormalCaption().c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002802 else if (nface == 1)
tsepezf3dc8c62016-08-10 06:29:29 -07002803 vRet = CJS_Value(pRuntime, pFormControl->GetDownCaption().c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002804 else if (nface == 2)
tsepezf3dc8c62016-08-10 06:29:29 -07002805 vRet = CJS_Value(pRuntime, pFormControl->GetRolloverCaption().c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002806 else
tsepez4cf55152016-11-02 14:37:54 -07002807 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002808
tsepez4cf55152016-11-02 14:37:54 -07002809 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002810}
2811
Tom Sepezb1670b52017-02-16 17:01:00 -08002812bool Field::buttonGetIcon(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002813 const std::vector<CJS_Value>& params,
2814 CJS_Value& vRet,
2815 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002816 int nface = 0;
2817 int iSize = params.size();
2818 if (iSize >= 1)
tsepezb4694242016-08-15 16:44:55 -07002819 nface = params[0].ToInt(pRuntime);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002820
Lei Zhangd88a3642015-11-10 09:38:57 -08002821 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2822 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002823 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002824
Lei Zhangd88a3642015-11-10 09:38:57 -08002825 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002826 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002827 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002828
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002829 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2830 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -07002831 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002832
tsepezb4694242016-08-15 16:44:55 -07002833 v8::Local<v8::Object> pObj =
2834 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID);
tsepez4cf55152016-11-02 14:37:54 -07002835 ASSERT(pObj.IsEmpty() == false);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002836
tsepezb4694242016-08-15 16:44:55 -07002837 CJS_Icon* pJS_Icon = static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002838 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002839
thestig1cd352e2016-06-07 17:53:06 -07002840 CPDF_Stream* pIconStream = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002841 if (nface == 0)
2842 pIconStream = pFormControl->GetNormalIcon();
2843 else if (nface == 1)
2844 pIconStream = pFormControl->GetDownIcon();
2845 else if (nface == 2)
2846 pIconStream = pFormControl->GetRolloverIcon();
2847 else
tsepez4cf55152016-11-02 14:37:54 -07002848 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002849
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002850 pIcon->SetStream(pIconStream);
tsepezf3dc8c62016-08-10 06:29:29 -07002851 vRet = CJS_Value(pRuntime, pJS_Icon);
tsepez4cf55152016-11-02 14:37:54 -07002852 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002853}
2854
Tom Sepezb1670b52017-02-16 17:01:00 -08002855bool Field::buttonImportIcon(CJS_Runtime* pRuntime,
Lei Zhang945fdb72015-11-11 10:18:16 -08002856 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002857 CJS_Value& vRet,
2858 CFX_WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002859 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002860}
2861
Tom Sepezb1670b52017-02-16 17:01:00 -08002862bool Field::buttonSetCaption(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002863 const std::vector<CJS_Value>& params,
2864 CJS_Value& vRet,
2865 CFX_WideString& sError) {
2866 return false;
2867}
2868
Tom Sepezb1670b52017-02-16 17:01:00 -08002869bool Field::buttonSetIcon(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002870 const std::vector<CJS_Value>& params,
2871 CJS_Value& vRet,
2872 CFX_WideString& sError) {
2873 return false;
2874}
2875
Tom Sepezb1670b52017-02-16 17:01:00 -08002876bool Field::checkThisBox(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002877 const std::vector<CJS_Value>& params,
2878 CJS_Value& vRet,
2879 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002880 int iSize = params.size();
2881 if (iSize < 1)
tsepez4cf55152016-11-02 14:37:54 -07002882 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002883
tsepezf3dc8c62016-08-10 06:29:29 -07002884 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002885 return false;
tsepezf3dc8c62016-08-10 06:29:29 -07002886
tsepezb4694242016-08-15 16:44:55 -07002887 int nWidget = params[0].ToInt(pRuntime);
Wei Li97da9762016-03-11 17:00:48 -08002888 bool bCheckit = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002889 if (iSize >= 2)
tsepezb4694242016-08-15 16:44:55 -07002890 bCheckit = params[1].ToBool(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002891
Lei Zhangd88a3642015-11-10 09:38:57 -08002892 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2893 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002894 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002895
Lei Zhangd88a3642015-11-10 09:38:57 -08002896 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002897 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
2898 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002899 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002900 if (nWidget < 0 || nWidget >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002901 return false;
Wei Li97da9762016-03-11 17:00:48 -08002902 // TODO(weili): Check whether anything special needed for radio button,
2903 // otherwise merge these branches.
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002904 if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)
Wei Li97da9762016-03-11 17:00:48 -08002905 pFormField->CheckControl(nWidget, bCheckit, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002906 else
Wei Li97da9762016-03-11 17:00:48 -08002907 pFormField->CheckControl(nWidget, bCheckit, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002908
tsepez4cf55152016-11-02 14:37:54 -07002909 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true);
2910 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002911}
2912
Tom Sepezb1670b52017-02-16 17:01:00 -08002913bool Field::clearItems(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002914 const std::vector<CJS_Value>& params,
2915 CJS_Value& vRet,
2916 CFX_WideString& sError) {
2917 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002918}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002919
Tom Sepezb1670b52017-02-16 17:01:00 -08002920bool Field::defaultIsChecked(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002921 const std::vector<CJS_Value>& params,
2922 CJS_Value& vRet,
2923 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002924 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002925 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002926
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002927 int iSize = params.size();
2928 if (iSize < 1)
tsepez4cf55152016-11-02 14:37:54 -07002929 return false;
Tom Sepezf4ef3f92015-04-23 11:31:31 -07002930
tsepezb4694242016-08-15 16:44:55 -07002931 int nWidget = params[0].ToInt(pRuntime);
Lei Zhangd88a3642015-11-10 09:38:57 -08002932 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2933 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002934 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002935
Lei Zhangd88a3642015-11-10 09:38:57 -08002936 CPDF_FormField* pFormField = FieldArray[0];
tsepezf3dc8c62016-08-10 06:29:29 -07002937 if (nWidget < 0 || nWidget >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002938 return false;
tsepezf3dc8c62016-08-10 06:29:29 -07002939
2940 vRet = CJS_Value(pRuntime,
2941 pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
2942 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002943
tsepez4cf55152016-11-02 14:37:54 -07002944 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002945}
2946
Tom Sepezb1670b52017-02-16 17:01:00 -08002947bool Field::deleteItemAt(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002948 const std::vector<CJS_Value>& params,
2949 CJS_Value& vRet,
2950 CFX_WideString& sError) {
2951 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002952}
2953
Tom Sepezb1670b52017-02-16 17:01:00 -08002954bool Field::getArray(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002955 const std::vector<CJS_Value>& params,
2956 CJS_Value& vRet,
2957 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002958 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2959 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002960 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002961
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002962 std::vector<std::unique_ptr<CFX_WideString>> swSort;
2963 for (CPDF_FormField* pFormField : FieldArray) {
2964 swSort.push_back(std::unique_ptr<CFX_WideString>(
2965 new CFX_WideString(pFormField->GetFullName())));
2966 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002967
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002968 std::sort(
2969 swSort.begin(), swSort.end(),
2970 [](const std::unique_ptr<CFX_WideString>& p1,
2971 const std::unique_ptr<CFX_WideString>& p2) { return *p1 < *p2; });
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002972
tsepeze5aff742016-08-08 09:49:42 -07002973 CJS_Array FormFieldArray;
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002974
2975 int j = 0;
2976 for (const auto& pStr : swSort) {
tsepezb4694242016-08-15 16:44:55 -07002977 v8::Local<v8::Object> pObj =
2978 pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID);
Tom Sepezcd56a7d2015-10-06 11:45:28 -07002979 ASSERT(!pObj.IsEmpty());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002980
Tom Sepezd5a0e952015-09-17 15:40:06 -07002981 CJS_Field* pJSField =
tsepezb4694242016-08-15 16:44:55 -07002982 static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pObj));
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002983 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002984 pField->AttachField(m_pJSDoc, *pStr);
tsepezb4694242016-08-15 16:44:55 -07002985 FormFieldArray.SetElement(pRuntime, j++, CJS_Value(pRuntime, pJSField));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002986 }
2987
tsepeze5aff742016-08-08 09:49:42 -07002988 vRet = CJS_Value(pRuntime, FormFieldArray);
tsepez4cf55152016-11-02 14:37:54 -07002989 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002990}
2991
Tom Sepezb1670b52017-02-16 17:01:00 -08002992bool Field::getItemAt(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07002993 const std::vector<CJS_Value>& params,
2994 CJS_Value& vRet,
2995 CFX_WideString& sError) {
tsepezf3dc8c62016-08-10 06:29:29 -07002996 int iSize = params.size();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002997 int nIdx = -1;
2998 if (iSize >= 1)
tsepezb4694242016-08-15 16:44:55 -07002999 nIdx = params[0].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003000
tsepez4cf55152016-11-02 14:37:54 -07003001 bool bExport = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003002 if (iSize >= 2)
tsepezb4694242016-08-15 16:44:55 -07003003 bExport = params[1].ToBool(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003004
Lei Zhangd88a3642015-11-10 09:38:57 -08003005 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3006 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07003007 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003008
Lei Zhangd88a3642015-11-10 09:38:57 -08003009 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003010 if ((pFormField->GetFieldType() == FIELDTYPE_LISTBOX) ||
3011 (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX)) {
3012 if (nIdx == -1 || nIdx > pFormField->CountOptions())
3013 nIdx = pFormField->CountOptions() - 1;
3014 if (bExport) {
3015 CFX_WideString strval = pFormField->GetOptionValue(nIdx);
3016 if (strval.IsEmpty())
tsepezf3dc8c62016-08-10 06:29:29 -07003017 vRet = CJS_Value(pRuntime, pFormField->GetOptionLabel(nIdx).c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003018 else
tsepezf3dc8c62016-08-10 06:29:29 -07003019 vRet = CJS_Value(pRuntime, strval.c_str());
Lei Zhangd88a3642015-11-10 09:38:57 -08003020 } else {
tsepezf3dc8c62016-08-10 06:29:29 -07003021 vRet = CJS_Value(pRuntime, pFormField->GetOptionLabel(nIdx).c_str());
Lei Zhangd88a3642015-11-10 09:38:57 -08003022 }
3023 } else {
tsepez4cf55152016-11-02 14:37:54 -07003024 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08003025 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003026
tsepez4cf55152016-11-02 14:37:54 -07003027 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003028}
3029
Tom Sepezb1670b52017-02-16 17:01:00 -08003030bool Field::getLock(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003031 const std::vector<CJS_Value>& params,
3032 CJS_Value& vRet,
3033 CFX_WideString& sError) {
3034 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003035}
3036
Tom Sepezb1670b52017-02-16 17:01:00 -08003037bool Field::insertItemAt(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003038 const std::vector<CJS_Value>& params,
3039 CJS_Value& vRet,
3040 CFX_WideString& sError) {
3041 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003042}
3043
Tom Sepezb1670b52017-02-16 17:01:00 -08003044bool Field::isBoxChecked(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003045 const std::vector<CJS_Value>& params,
3046 CJS_Value& vRet,
3047 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003048 int nIndex = -1;
3049 if (params.size() >= 1)
tsepezb4694242016-08-15 16:44:55 -07003050 nIndex = params[0].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003051
Lei Zhangd88a3642015-11-10 09:38:57 -08003052 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3053 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07003054 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003055
Lei Zhangd88a3642015-11-10 09:38:57 -08003056 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003057 if (nIndex < 0 || nIndex >= pFormField->CountControls()) {
tsepez4cf55152016-11-02 14:37:54 -07003058 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003059 }
3060
tsepezf3dc8c62016-08-10 06:29:29 -07003061 vRet = CJS_Value(pRuntime,
3062 ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
3063 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) &&
3064 pFormField->GetControl(nIndex)->IsChecked() != 0));
tsepez4cf55152016-11-02 14:37:54 -07003065 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003066}
3067
Tom Sepezb1670b52017-02-16 17:01:00 -08003068bool Field::isDefaultChecked(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003069 const std::vector<CJS_Value>& params,
3070 CJS_Value& vRet,
3071 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003072 int nIndex = -1;
3073 if (params.size() >= 1)
tsepezb4694242016-08-15 16:44:55 -07003074 nIndex = params[0].ToInt(pRuntime);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003075
Lei Zhangd88a3642015-11-10 09:38:57 -08003076 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3077 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07003078 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003079
Lei Zhangd88a3642015-11-10 09:38:57 -08003080 CPDF_FormField* pFormField = FieldArray[0];
tsepezf3dc8c62016-08-10 06:29:29 -07003081 if (nIndex < 0 || nIndex >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07003082 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003083
tsepezf3dc8c62016-08-10 06:29:29 -07003084 vRet = CJS_Value(pRuntime,
3085 ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
3086 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) &&
3087 pFormField->GetControl(nIndex)->IsDefaultChecked() != 0));
tsepez4cf55152016-11-02 14:37:54 -07003088 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003089}
3090
Tom Sepezb1670b52017-02-16 17:01:00 -08003091bool Field::setAction(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003092 const std::vector<CJS_Value>& params,
3093 CJS_Value& vRet,
3094 CFX_WideString& sError) {
3095 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003096}
3097
Tom Sepezb1670b52017-02-16 17:01:00 -08003098bool Field::setFocus(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003099 const std::vector<CJS_Value>& params,
3100 CJS_Value& vRet,
3101 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08003102 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3103 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07003104 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003105
Lei Zhangd88a3642015-11-10 09:38:57 -08003106 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003107 int32_t nCount = pFormField->CountControls();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003108 if (nCount < 1)
tsepez4cf55152016-11-02 14:37:54 -07003109 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003110
dsinclair7cbe68e2016-10-12 11:56:23 -07003111 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
thestig1cd352e2016-06-07 17:53:06 -07003112 CPDFSDK_Widget* pWidget = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003113 if (nCount == 1) {
dsinclairc5267c52016-11-04 15:35:12 -07003114 pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003115 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07003116 UnderlyingPageType* pPage =
3117 UnderlyingFromFPDFPage(m_pFormFillEnv->GetCurrentPage(
3118 m_pFormFillEnv->GetUnderlyingDocument()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003119 if (!pPage)
tsepez4cf55152016-11-02 14:37:54 -07003120 return false;
dsinclair461eeaf2016-07-27 07:40:05 -07003121 if (CPDFSDK_PageView* pCurPageView =
dsinclair7cbe68e2016-10-12 11:56:23 -07003122 m_pFormFillEnv->GetPageView(pPage, true)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003123 for (int32_t i = 0; i < nCount; i++) {
3124 if (CPDFSDK_Widget* pTempWidget =
dsinclairc5267c52016-11-04 15:35:12 -07003125 pInterForm->GetWidget(pFormField->GetControl(i))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003126 if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage()) {
3127 pWidget = pTempWidget;
3128 break;
3129 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003130 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003131 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003132 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003133 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003134
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003135 if (pWidget) {
tsepezf8074ce2016-09-27 14:29:57 -07003136 CPDFSDK_Annot::ObservedPtr pObserved(pWidget);
dsinclair7cbe68e2016-10-12 11:56:23 -07003137 m_pFormFillEnv->SetFocusAnnot(&pObserved);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003138 }
3139
tsepez4cf55152016-11-02 14:37:54 -07003140 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003141}
3142
Tom Sepezb1670b52017-02-16 17:01:00 -08003143bool Field::setItems(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003144 const std::vector<CJS_Value>& params,
3145 CJS_Value& vRet,
3146 CFX_WideString& sError) {
3147 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003148}
3149
Tom Sepezb1670b52017-02-16 17:01:00 -08003150bool Field::setLock(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003151 const std::vector<CJS_Value>& params,
3152 CJS_Value& vRet,
3153 CFX_WideString& sError) {
3154 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003155}
3156
Tom Sepezb1670b52017-02-16 17:01:00 -08003157bool Field::signatureGetModifications(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003158 const std::vector<CJS_Value>& params,
3159 CJS_Value& vRet,
3160 CFX_WideString& sError) {
3161 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003162}
3163
Tom Sepezb1670b52017-02-16 17:01:00 -08003164bool Field::signatureGetSeedValue(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003165 const std::vector<CJS_Value>& params,
3166 CJS_Value& vRet,
3167 CFX_WideString& sError) {
3168 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003169}
3170
Tom Sepezb1670b52017-02-16 17:01:00 -08003171bool Field::signatureInfo(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003172 const std::vector<CJS_Value>& params,
3173 CJS_Value& vRet,
3174 CFX_WideString& sError) {
3175 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003176}
3177
Tom Sepezb1670b52017-02-16 17:01:00 -08003178bool Field::signatureSetSeedValue(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003179 const std::vector<CJS_Value>& params,
3180 CJS_Value& vRet,
3181 CFX_WideString& sError) {
3182 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003183}
3184
Tom Sepezb1670b52017-02-16 17:01:00 -08003185bool Field::signatureSign(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003186 const std::vector<CJS_Value>& params,
3187 CJS_Value& vRet,
3188 CFX_WideString& sError) {
3189 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003190}
3191
Tom Sepezb1670b52017-02-16 17:01:00 -08003192bool Field::signatureValidate(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -07003193 const std::vector<CJS_Value>& params,
3194 CJS_Value& vRet,
3195 CFX_WideString& sError) {
3196 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003197}
3198
Tom Sepezb1670b52017-02-16 17:01:00 -08003199bool Field::source(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -08003200 CJS_PropValue& vp,
3201 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003202 if (vp.IsGetting()) {
thestig1cd352e2016-06-07 17:53:06 -07003203 vp << (CJS_Object*)nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003204 }
3205
tsepez4cf55152016-11-02 14:37:54 -07003206 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003207}
3208
tsepez41a53ad2016-03-28 16:59:30 -07003209void Field::AddDelay_Int(FIELD_PROP prop, int32_t n) {
3210 CJS_DelayData* pNewData =
3211 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003212 pNewData->num = n;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003213 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003214}
3215
tsepez41a53ad2016-03-28 16:59:30 -07003216void Field::AddDelay_Bool(FIELD_PROP prop, bool b) {
3217 CJS_DelayData* pNewData =
3218 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003219 pNewData->b = b;
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_String(FIELD_PROP prop, const CFX_ByteString& string) {
3224 CJS_DelayData* pNewData =
3225 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003226 pNewData->string = string;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003227 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003228}
3229
tsepez41a53ad2016-03-28 16:59:30 -07003230void Field::AddDelay_WideString(FIELD_PROP prop, const CFX_WideString& string) {
3231 CJS_DelayData* pNewData =
3232 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003233 pNewData->widestring = string;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003234 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003235}
3236
tsepez41a53ad2016-03-28 16:59:30 -07003237void Field::AddDelay_Rect(FIELD_PROP prop, const CFX_FloatRect& rect) {
3238 CJS_DelayData* pNewData =
3239 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003240 pNewData->rect = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003241 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003242}
3243
tsepez41a53ad2016-03-28 16:59:30 -07003244void Field::AddDelay_Color(FIELD_PROP prop, const CPWL_Color& color) {
3245 CJS_DelayData* pNewData =
3246 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003247 pNewData->color = color;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003248 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003249}
3250
tsepez41a53ad2016-03-28 16:59:30 -07003251void Field::AddDelay_WordArray(FIELD_PROP prop,
3252 const std::vector<uint32_t>& array) {
3253 CJS_DelayData* pNewData =
3254 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
3255 pNewData->wordarray = array;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003256 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003257}
3258
tsepez41a53ad2016-03-28 16:59:30 -07003259void Field::AddDelay_WideStringArray(FIELD_PROP prop,
3260 const std::vector<CFX_WideString>& array) {
3261 CJS_DelayData* pNewData =
3262 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
3263 pNewData->widestringarray = array;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003264 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003265}
3266
dsinclair3a7741a2016-10-11 10:39:49 -07003267void Field::DoDelay(CPDFSDK_FormFillEnvironment* pFormFillEnv,
3268 CJS_DelayData* pData) {
3269 ASSERT(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003270 switch (pData->eProp) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003271 case FP_ALIGNMENT:
dsinclair3a7741a2016-10-11 10:39:49 -07003272 Field::SetAlignment(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003273 pData->string);
3274 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003275 case FP_BORDERSTYLE:
dsinclair3a7741a2016-10-11 10:39:49 -07003276 Field::SetBorderStyle(pFormFillEnv, pData->sFieldName,
3277 pData->nControlIndex, pData->string);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003278 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003279 case FP_BUTTONALIGNX:
dsinclair3a7741a2016-10-11 10:39:49 -07003280 Field::SetButtonAlignX(pFormFillEnv, pData->sFieldName,
3281 pData->nControlIndex, pData->num);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003282 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003283 case FP_BUTTONALIGNY:
dsinclair3a7741a2016-10-11 10:39:49 -07003284 Field::SetButtonAlignY(pFormFillEnv, pData->sFieldName,
3285 pData->nControlIndex, pData->num);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003286 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003287 case FP_BUTTONFITBOUNDS:
dsinclair3a7741a2016-10-11 10:39:49 -07003288 Field::SetButtonFitBounds(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_BUTTONPOSITION:
dsinclair3a7741a2016-10-11 10:39:49 -07003292 Field::SetButtonPosition(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003293 pData->nControlIndex, pData->num);
3294 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003295 case FP_BUTTONSCALEHOW:
dsinclair3a7741a2016-10-11 10:39:49 -07003296 Field::SetButtonScaleHow(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003297 pData->nControlIndex, pData->num);
3298 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003299 case FP_BUTTONSCALEWHEN:
dsinclair3a7741a2016-10-11 10:39:49 -07003300 Field::SetButtonScaleWhen(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003301 pData->nControlIndex, pData->num);
3302 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003303 case FP_CALCORDERINDEX:
dsinclair3a7741a2016-10-11 10:39:49 -07003304 Field::SetCalcOrderIndex(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003305 pData->nControlIndex, pData->num);
3306 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003307 case FP_CHARLIMIT:
dsinclair3a7741a2016-10-11 10:39:49 -07003308 Field::SetCharLimit(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003309 pData->num);
3310 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003311 case FP_COMB:
dsinclair3a7741a2016-10-11 10:39:49 -07003312 Field::SetComb(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_COMMITONSELCHANGE:
dsinclair3a7741a2016-10-11 10:39:49 -07003316 Field::SetCommitOnSelChange(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003317 pData->nControlIndex, pData->b);
3318 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003319 case FP_CURRENTVALUEINDICES:
dsinclair3a7741a2016-10-11 10:39:49 -07003320 Field::SetCurrentValueIndices(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003321 pData->nControlIndex, pData->wordarray);
3322 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003323 case FP_DEFAULTVALUE:
dsinclair3a7741a2016-10-11 10:39:49 -07003324 Field::SetDefaultValue(pFormFillEnv, pData->sFieldName,
3325 pData->nControlIndex, pData->widestring);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003326 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003327 case FP_DONOTSCROLL:
dsinclair3a7741a2016-10-11 10:39:49 -07003328 Field::SetDoNotScroll(pFormFillEnv, pData->sFieldName,
3329 pData->nControlIndex, pData->b);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003330 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003331 case FP_DISPLAY:
dsinclair3a7741a2016-10-11 10:39:49 -07003332 Field::SetDisplay(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003333 pData->num);
3334 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003335 case FP_FILLCOLOR:
dsinclair3a7741a2016-10-11 10:39:49 -07003336 Field::SetFillColor(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003337 pData->color);
3338 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003339 case FP_HIDDEN:
dsinclair3a7741a2016-10-11 10:39:49 -07003340 Field::SetHidden(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003341 pData->b);
3342 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003343 case FP_HIGHLIGHT:
dsinclair3a7741a2016-10-11 10:39:49 -07003344 Field::SetHighlight(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003345 pData->string);
3346 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003347 case FP_LINEWIDTH:
dsinclair3a7741a2016-10-11 10:39:49 -07003348 Field::SetLineWidth(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003349 pData->num);
3350 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003351 case FP_MULTILINE:
dsinclair3a7741a2016-10-11 10:39:49 -07003352 Field::SetMultiline(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003353 pData->b);
3354 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003355 case FP_MULTIPLESELECTION:
dsinclair3a7741a2016-10-11 10:39:49 -07003356 Field::SetMultipleSelection(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003357 pData->nControlIndex, pData->b);
3358 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003359 case FP_PASSWORD:
dsinclair3a7741a2016-10-11 10:39:49 -07003360 Field::SetPassword(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003361 pData->b);
3362 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003363 case FP_RECT:
dsinclair3a7741a2016-10-11 10:39:49 -07003364 Field::SetRect(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003365 pData->rect);
3366 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003367 case FP_RICHTEXT:
dsinclaira2919b32016-07-13 10:55:48 -07003368 // Not supported.
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003369 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003370 case FP_RICHVALUE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003371 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003372 case FP_ROTATION:
dsinclair3a7741a2016-10-11 10:39:49 -07003373 Field::SetRotation(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003374 pData->num);
3375 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003376 case FP_STROKECOLOR:
dsinclair3a7741a2016-10-11 10:39:49 -07003377 Field::SetStrokeColor(pFormFillEnv, pData->sFieldName,
3378 pData->nControlIndex, pData->color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003379 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003380 case FP_STYLE:
dsinclair3a7741a2016-10-11 10:39:49 -07003381 Field::SetStyle(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003382 pData->string);
3383 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003384 case FP_TEXTCOLOR:
dsinclair3a7741a2016-10-11 10:39:49 -07003385 Field::SetTextColor(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003386 pData->color);
3387 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003388 case FP_TEXTFONT:
dsinclair3a7741a2016-10-11 10:39:49 -07003389 Field::SetTextFont(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003390 pData->string);
3391 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003392 case FP_TEXTSIZE:
dsinclair3a7741a2016-10-11 10:39:49 -07003393 Field::SetTextSize(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003394 pData->num);
3395 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003396 case FP_USERNAME:
dsinclair3a7741a2016-10-11 10:39:49 -07003397 Field::SetUserName(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003398 pData->widestring);
3399 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003400 case FP_VALUE:
dsinclair3a7741a2016-10-11 10:39:49 -07003401 Field::SetValue(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003402 pData->widestringarray);
3403 break;
3404 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003405}
3406
dsinclair3a7741a2016-10-11 10:39:49 -07003407void Field::AddField(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003408 int nPageIndex,
3409 int nFieldType,
3410 const CFX_WideString& sName,
Tom Sepez281a9ea2016-02-26 14:24:28 -08003411 const CFX_FloatRect& rcCoords) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003412 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003413}