blob: 3eb3f8e35b59166bd7d30e1b9af6dcf9604ed164 [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 Sepezd6ae2af2017-02-16 11:49:55 -0800378bool Field::alignment(IJS_EventContext* cc,
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 Sepezd6ae2af2017-02-16 11:49:55 -0800434bool Field::borderStyle(IJS_EventContext* cc,
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 Sepezd6ae2af2017-02-16 11:49:55 -0800543bool Field::buttonAlignX(IJS_EventContext* cc,
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 Sepezd6ae2af2017-02-16 11:49:55 -0800592bool Field::buttonAlignY(IJS_EventContext* cc,
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 Sepezd6ae2af2017-02-16 11:49:55 -0800641bool Field::buttonFitBounds(IJS_EventContext* cc,
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 Sepezd6ae2af2017-02-16 11:49:55 -0800685bool Field::buttonPosition(IJS_EventContext* cc,
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 Sepezd6ae2af2017-02-16 11:49:55 -0800728bool Field::buttonScaleHow(IJS_EventContext* cc,
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 Sepezd6ae2af2017-02-16 11:49:55 -0800776bool Field::buttonScaleWhen(IJS_EventContext* cc,
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 Sepezd6ae2af2017-02-16 11:49:55 -0800835bool Field::calcOrderIndex(IJS_EventContext* cc,
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 Sepezd6ae2af2017-02-16 11:49:55 -0800879bool Field::charLimit(IJS_EventContext* cc,
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 Sepezd6ae2af2017-02-16 11:49:55 -0800918bool Field::comb(IJS_EventContext* cc,
919 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 Sepezd6ae2af2017-02-16 11:49:55 -0800961bool Field::commitOnSelChange(IJS_EventContext* cc,
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 Sepezd6ae2af2017-02-16 11:49:55 -08001006bool Field::currentValueIndices(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07001007 CJS_PropValue& vp,
1008 CFX_WideString& sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001009 CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001010
1011 if (vp.IsSetting()) {
1012 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001013 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001014
tsepez41a53ad2016-03-28 16:59:30 -07001015 std::vector<uint32_t> array;
tsepezf3dc8c62016-08-10 06:29:29 -07001016 if (vp.GetJSValue()->GetType() == CJS_Value::VT_number) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001017 int iSelecting = 0;
1018 vp >> iSelecting;
tsepez41a53ad2016-03-28 16:59:30 -07001019 array.push_back(iSelecting);
tsepezf3dc8c62016-08-10 06:29:29 -07001020 } else if (vp.GetJSValue()->IsArrayObject()) {
tsepeze5aff742016-08-08 09:49:42 -07001021 CJS_Array SelArray;
Tom Sepez67fd5df2015-10-08 12:24:19 -07001022 CJS_Value SelValue(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001023 int iSelecting;
1024 vp >> SelArray;
tsepezb4694242016-08-15 16:44:55 -07001025 for (int i = 0, sz = SelArray.GetLength(pRuntime); i < sz; i++) {
1026 SelArray.GetElement(pRuntime, i, SelValue);
1027 iSelecting = SelValue.ToInt(pRuntime);
tsepez41a53ad2016-03-28 16:59:30 -07001028 array.push_back(iSelecting);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001029 }
1030 }
1031
1032 if (m_bDelay) {
1033 AddDelay_WordArray(FP_CURRENTVALUEINDICES, array);
1034 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001035 Field::SetCurrentValueIndices(m_pFormFillEnv.Get(), m_FieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001036 m_nFormControlIndex, array);
1037 }
1038 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001039 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1040 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001041 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001042
Lei Zhangd88a3642015-11-10 09:38:57 -08001043 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001044 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001045 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
tsepez4cf55152016-11-02 14:37:54 -07001046 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001047 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001048
Lei Zhangd88a3642015-11-10 09:38:57 -08001049 if (pFormField->CountSelectedItems() == 1) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001050 vp << pFormField->GetSelectedIndex(0);
Lei Zhangd88a3642015-11-10 09:38:57 -08001051 } else if (pFormField->CountSelectedItems() > 1) {
tsepeze5aff742016-08-08 09:49:42 -07001052 CJS_Array SelArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001053 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
1054 SelArray.SetElement(
tsepezb4694242016-08-15 16:44:55 -07001055 pRuntime, i, CJS_Value(pRuntime, pFormField->GetSelectedIndex(i)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001056 }
1057 vp << SelArray;
Lei Zhangd88a3642015-11-10 09:38:57 -08001058 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001059 vp << -1;
Lei Zhangd88a3642015-11-10 09:38:57 -08001060 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001061 }
1062
tsepez4cf55152016-11-02 14:37:54 -07001063 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001064}
1065
dsinclair3a7741a2016-10-11 10:39:49 -07001066void Field::SetCurrentValueIndices(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001067 const CFX_WideString& swFieldName,
1068 int nControlIndex,
tsepez41a53ad2016-03-28 16:59:30 -07001069 const std::vector<uint32_t>& array) {
dsinclair3a7741a2016-10-11 10:39:49 -07001070 ASSERT(pFormFillEnv);
Lei Zhangd88a3642015-11-10 09:38:57 -08001071 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07001072 GetFormFields(pFormFillEnv, swFieldName);
tsepez41a53ad2016-03-28 16:59:30 -07001073
Lei Zhangd88a3642015-11-10 09:38:57 -08001074 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001075 int nFieldType = pFormField->GetFieldType();
1076 if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX) {
tsepezc3255f52016-03-25 14:52:27 -07001077 uint32_t dwFieldFlags = pFormField->GetFieldFlags();
tsepez4cf55152016-11-02 14:37:54 -07001078 pFormField->ClearSelection(true);
tsepez41a53ad2016-03-28 16:59:30 -07001079 for (size_t i = 0; i < array.size(); ++i) {
1080 if (i != 0 && !(dwFieldFlags & (1 << 21)))
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001081 break;
Wei Li05d53f02016-03-29 16:42:53 -07001082 if (array[i] < static_cast<uint32_t>(pFormField->CountOptions()) &&
tsepez41a53ad2016-03-28 16:59:30 -07001083 !pFormField->IsItemSelected(array[i])) {
tsepez4cf55152016-11-02 14:37:54 -07001084 pFormField->SetItemSelection(array[i], true);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001085 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001086 }
tsepez4cf55152016-11-02 14:37:54 -07001087 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001088 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001089 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001090}
1091
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001092bool Field::defaultStyle(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07001093 CJS_PropValue& vp,
1094 CFX_WideString& sError) {
1095 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001096}
1097
dsinclair3a7741a2016-10-11 10:39:49 -07001098void Field::SetDefaultStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001099 const CFX_WideString& swFieldName,
1100 int nControlIndex) {
1101 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001102}
1103
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001104bool Field::defaultValue(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07001105 CJS_PropValue& vp,
1106 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001107 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001108
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001109 if (vp.IsSetting()) {
1110 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001111 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001112
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001113 CFX_WideString WideStr;
1114 vp >> WideStr;
1115
1116 if (m_bDelay) {
1117 AddDelay_WideString(FP_DEFAULTVALUE, WideStr);
1118 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001119 Field::SetDefaultValue(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -07001120 m_nFormControlIndex, WideStr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001121 }
1122 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001123 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1124 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001125 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001126
Lei Zhangd88a3642015-11-10 09:38:57 -08001127 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001128 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON ||
Lei Zhangd88a3642015-11-10 09:38:57 -08001129 pFormField->GetFieldType() == FIELDTYPE_SIGNATURE) {
tsepez4cf55152016-11-02 14:37:54 -07001130 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001131 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001132
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001133 vp << pFormField->GetDefaultValue();
1134 }
tsepez4cf55152016-11-02 14:37:54 -07001135 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001136}
1137
dsinclair3a7741a2016-10-11 10:39:49 -07001138void Field::SetDefaultValue(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001139 const CFX_WideString& swFieldName,
1140 int nControlIndex,
1141 const CFX_WideString& string) {
1142 // Not supported.
1143}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001144
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001145bool Field::doNotScroll(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07001146 CJS_PropValue& vp,
1147 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001148 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001149
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001150 if (vp.IsSetting()) {
1151 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001152 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001153
1154 bool bVP;
1155 vp >> bVP;
1156
1157 if (m_bDelay) {
1158 AddDelay_Bool(FP_DONOTSCROLL, bVP);
1159 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001160 Field::SetDoNotScroll(m_pFormFillEnv.Get(), m_FieldName,
1161 m_nFormControlIndex, bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001162 }
1163 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001164 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1165 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001166 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001167
Lei Zhangd88a3642015-11-10 09:38:57 -08001168 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001169 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
tsepez4cf55152016-11-02 14:37:54 -07001170 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001171
1172 if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL)
1173 vp << true;
1174 else
1175 vp << false;
1176 }
1177
tsepez4cf55152016-11-02 14:37:54 -07001178 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001179}
1180
dsinclair3a7741a2016-10-11 10:39:49 -07001181void Field::SetDoNotScroll(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001182 const CFX_WideString& swFieldName,
1183 int nControlIndex,
1184 bool b) {
1185 // Not supported.
1186}
1187
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001188bool Field::doNotSpellCheck(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07001189 CJS_PropValue& vp,
1190 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001191 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001192
1193 if (vp.IsSetting()) {
1194 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001195 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001196
1197 bool bVP;
1198 vp >> bVP;
1199 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001200 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1201 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001202 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001203
Lei Zhangd88a3642015-11-10 09:38:57 -08001204 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001205 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001206 pFormField->GetFieldType() != FIELDTYPE_COMBOBOX) {
tsepez4cf55152016-11-02 14:37:54 -07001207 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001208 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001209
1210 if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK)
1211 vp << true;
1212 else
1213 vp << false;
1214 }
1215
tsepez4cf55152016-11-02 14:37:54 -07001216 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001217}
1218
tsepez4cf55152016-11-02 14:37:54 -07001219void Field::SetDelay(bool bDelay) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001220 m_bDelay = bDelay;
1221
1222 if (!m_bDelay) {
1223 if (m_pJSDoc)
1224 m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex);
1225 }
1226}
1227
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001228bool Field::delay(IJS_EventContext* cc,
1229 CJS_PropValue& vp,
1230 CFX_WideString& sError) {
1231 if (!vp.IsSetting()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001232 vp << m_bDelay;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001233 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001234 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001235 if (!m_bCanSet)
1236 return false;
1237
1238 bool bVP;
1239 vp >> bVP;
1240 SetDelay(bVP);
tsepez4cf55152016-11-02 14:37:54 -07001241 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001242}
1243
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001244bool Field::display(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07001245 CJS_PropValue& vp,
1246 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001247 if (vp.IsSetting()) {
1248 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001249 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001250
1251 int nVP;
1252 vp >> nVP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001253 if (m_bDelay) {
1254 AddDelay_Int(FP_DISPLAY, nVP);
1255 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001256 Field::SetDisplay(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07001257 nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001258 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001259 return true;
1260 }
1261 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1262 if (FieldArray.empty())
1263 return false;
1264
1265 CPDF_FormField* pFormField = FieldArray[0];
1266 ASSERT(pFormField);
1267 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1268 CPDFSDK_Widget* pWidget =
1269 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1270 if (!pWidget)
1271 return false;
1272
1273 uint32_t dwFlag = pWidget->GetFlags();
1274 if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag) {
1275 vp << (int32_t)1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001276 } else {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001277 if (ANNOTFLAG_PRINT & dwFlag) {
1278 if (ANNOTFLAG_NOVIEW & dwFlag) {
1279 vp << (int32_t)3;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001280 } else {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001281 vp << (int32_t)0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001282 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001283 } else {
1284 vp << (int32_t)2;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001285 }
1286 }
tsepez4cf55152016-11-02 14:37:54 -07001287 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001288}
1289
dsinclair3a7741a2016-10-11 10:39:49 -07001290void Field::SetDisplay(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001291 const CFX_WideString& swFieldName,
1292 int nControlIndex,
1293 int number) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001294 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001295 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07001296 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -08001297 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001298 if (nControlIndex < 0) {
tonikitoo7c05a7a2016-08-17 11:08:46 -07001299 bool bAnySet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001300 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1301 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08001302 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001303
dsinclairc5267c52016-11-04 15:35:12 -07001304 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
tonikitoo7c05a7a2016-08-17 11:08:46 -07001305 if (SetWidgetDisplayStatus(pWidget, number))
1306 bAnySet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001307 }
1308
tonikitoo7c05a7a2016-08-17 11:08:46 -07001309 if (bAnySet)
tsepez4cf55152016-11-02 14:37:54 -07001310 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001311 } else {
1312 if (nControlIndex >= pFormField->CountControls())
1313 return;
tonikitoo7c05a7a2016-08-17 11:08:46 -07001314
1315 CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex);
1316 if (!pFormControl)
1317 return;
1318
dsinclairc5267c52016-11-04 15:35:12 -07001319 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
tonikitoo7c05a7a2016-08-17 11:08:46 -07001320 if (SetWidgetDisplayStatus(pWidget, number))
tsepez4cf55152016-11-02 14:37:54 -07001321 UpdateFormControl(pFormFillEnv, pFormControl, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001322 }
1323 }
1324}
1325
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001326bool Field::doc(IJS_EventContext* cc,
1327 CJS_PropValue& vp,
1328 CFX_WideString& sError) {
1329 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -07001330 return false;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001331
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001332 vp << m_pJSDoc->GetCJSDoc();
tsepez4cf55152016-11-02 14:37:54 -07001333 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001334}
1335
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001336bool Field::editable(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07001337 CJS_PropValue& vp,
1338 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001339 if (vp.IsSetting()) {
1340 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001341 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001342
1343 bool bVP;
1344 vp >> bVP;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001345 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001346 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001347 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1348 if (FieldArray.empty())
1349 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001350
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001351 CPDF_FormField* pFormField = FieldArray[0];
1352 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX)
1353 return false;
1354
1355 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_EDIT);
tsepez4cf55152016-11-02 14:37:54 -07001356 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001357}
1358
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001359bool Field::exportValues(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07001360 CJS_PropValue& vp,
1361 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001362 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1363 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001364 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001365
Lei Zhangd88a3642015-11-10 09:38:57 -08001366 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001367 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001368 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) {
tsepez4cf55152016-11-02 14:37:54 -07001369 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001370 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001371 if (vp.IsSetting())
1372 return m_bCanSet && vp.GetJSValue()->IsArrayObject();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001373
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001374 CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
1375 CJS_Array ExportValusArray;
1376 if (m_nFormControlIndex < 0) {
1377 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
1378 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001379 ExportValusArray.SetElement(
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001380 pRuntime, i,
tsepeze5aff742016-08-08 09:49:42 -07001381 CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001382 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001383 } else {
1384 if (m_nFormControlIndex >= pFormField->CountControls())
1385 return false;
1386
1387 CPDF_FormControl* pFormControl =
1388 pFormField->GetControl(m_nFormControlIndex);
1389 if (!pFormControl)
1390 return false;
1391
1392 ExportValusArray.SetElement(
1393 pRuntime, 0,
1394 CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001395 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001396 vp << ExportValusArray;
tsepez4cf55152016-11-02 14:37:54 -07001397 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001398}
1399
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001400bool Field::fileSelect(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07001401 CJS_PropValue& vp,
1402 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001403 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1404 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001405 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001406
Lei Zhangd88a3642015-11-10 09:38:57 -08001407 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001408 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
tsepez4cf55152016-11-02 14:37:54 -07001409 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001410
1411 if (vp.IsSetting()) {
1412 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001413 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001414
1415 bool bVP;
1416 vp >> bVP;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001417 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001418 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001419 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT);
tsepez4cf55152016-11-02 14:37:54 -07001420 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001421}
1422
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001423bool Field::fillColor(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07001424 CJS_PropValue& vp,
1425 CFX_WideString& sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001426 CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
tsepeze5aff742016-08-08 09:49:42 -07001427 CJS_Array crArray;
Lei Zhangd88a3642015-11-10 09:38:57 -08001428 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1429 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001430 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001431
1432 if (vp.IsSetting()) {
1433 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001434 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001435
tsepezf3dc8c62016-08-10 06:29:29 -07001436 if (!vp.GetJSValue()->IsArrayObject())
tsepez4cf55152016-11-02 14:37:54 -07001437 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001438
1439 vp >> crArray;
1440
1441 CPWL_Color color;
tsepeze5aff742016-08-08 09:49:42 -07001442 color::ConvertArrayToPWLColor(pRuntime, crArray, &color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001443 if (m_bDelay) {
1444 AddDelay_Color(FP_FILLCOLOR, color);
1445 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001446 Field::SetFillColor(m_pFormFillEnv.Get(), m_FieldName,
1447 m_nFormControlIndex, color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001448 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001449 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001450 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001451 CPDF_FormField* pFormField = FieldArray[0];
1452 ASSERT(pFormField);
1453 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1454 if (!pFormControl)
1455 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001456
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001457 int iColorType;
1458 pFormControl->GetBackgroundColor(iColorType);
1459
1460 CPWL_Color color;
1461 if (iColorType == COLORTYPE_TRANSPARENT) {
1462 color = CPWL_Color(COLORTYPE_TRANSPARENT);
1463 } else if (iColorType == COLORTYPE_GRAY) {
1464 color =
1465 CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBackgroundColor(0));
1466 } else if (iColorType == COLORTYPE_RGB) {
1467 color =
1468 CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBackgroundColor(0),
1469 pFormControl->GetOriginalBackgroundColor(1),
1470 pFormControl->GetOriginalBackgroundColor(2));
1471 } else if (iColorType == COLORTYPE_CMYK) {
1472 color =
1473 CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBackgroundColor(0),
1474 pFormControl->GetOriginalBackgroundColor(1),
1475 pFormControl->GetOriginalBackgroundColor(2),
1476 pFormControl->GetOriginalBackgroundColor(3));
1477 } else {
1478 return false;
1479 }
1480 color::ConvertPWLColorToArray(pRuntime, color, &crArray);
1481 vp << crArray;
tsepez4cf55152016-11-02 14:37:54 -07001482 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001483}
1484
dsinclair3a7741a2016-10-11 10:39:49 -07001485void Field::SetFillColor(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001486 const CFX_WideString& swFieldName,
1487 int nControlIndex,
1488 const CPWL_Color& color) {
1489 // Not supported.
1490}
1491
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001492bool Field::hidden(IJS_EventContext* cc,
1493 CJS_PropValue& vp,
1494 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001495 if (vp.IsSetting()) {
1496 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001497 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001498
1499 bool bVP;
1500 vp >> bVP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001501 if (m_bDelay) {
1502 AddDelay_Bool(FP_HIDDEN, bVP);
1503 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001504 Field::SetHidden(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07001505 bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001506 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001507 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001508 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001509 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1510 if (FieldArray.empty())
1511 return false;
1512
1513 CPDF_FormField* pFormField = FieldArray[0];
1514 ASSERT(pFormField);
1515 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1516 CPDFSDK_Widget* pWidget =
1517 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1518 if (!pWidget)
1519 return false;
1520
1521 uint32_t dwFlags = pWidget->GetFlags();
1522 if (ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags)
1523 vp << true;
1524 else
1525 vp << false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001526
tsepez4cf55152016-11-02 14:37:54 -07001527 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001528}
1529
dsinclair3a7741a2016-10-11 10:39:49 -07001530void Field::SetHidden(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001531 const CFX_WideString& swFieldName,
1532 int nControlIndex,
1533 bool b) {
tonikitooa73b8fe2016-08-22 14:06:49 -07001534 int display = b ? 1 /*Hidden*/ : 0 /*Visible*/;
dsinclair3a7741a2016-10-11 10:39:49 -07001535 SetDisplay(pFormFillEnv, swFieldName, nControlIndex, display);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001536}
1537
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001538bool Field::highlight(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07001539 CJS_PropValue& vp,
1540 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001541 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001542 if (vp.IsSetting()) {
1543 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001544 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001545
1546 CFX_ByteString strMode;
1547 vp >> strMode;
1548
1549 if (m_bDelay) {
1550 AddDelay_String(FP_HIGHLIGHT, strMode);
1551 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001552 Field::SetHighlight(m_pFormFillEnv.Get(), m_FieldName,
1553 m_nFormControlIndex, strMode);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001554 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001555 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001556 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001557 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1558 if (FieldArray.empty())
1559 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001560
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001561 CPDF_FormField* pFormField = FieldArray[0];
1562 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
1563 return false;
1564
1565 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1566 if (!pFormControl)
1567 return false;
1568
1569 int eHM = pFormControl->GetHighlightingMode();
1570 switch (eHM) {
1571 case CPDF_FormControl::None:
1572 vp << L"none";
1573 break;
1574 case CPDF_FormControl::Push:
1575 vp << L"push";
1576 break;
1577 case CPDF_FormControl::Invert:
1578 vp << L"invert";
1579 break;
1580 case CPDF_FormControl::Outline:
1581 vp << L"outline";
1582 break;
1583 case CPDF_FormControl::Toggle:
1584 vp << L"toggle";
1585 break;
1586 }
tsepez4cf55152016-11-02 14:37:54 -07001587 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001588}
1589
dsinclair3a7741a2016-10-11 10:39:49 -07001590void Field::SetHighlight(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001591 const CFX_WideString& swFieldName,
1592 int nControlIndex,
1593 const CFX_ByteString& string) {
1594 // Not supported.
1595}
1596
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001597bool Field::lineWidth(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07001598 CJS_PropValue& vp,
1599 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001600 if (vp.IsSetting()) {
1601 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001602 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001603
1604 int iWidth;
1605 vp >> iWidth;
1606
1607 if (m_bDelay) {
1608 AddDelay_Int(FP_LINEWIDTH, iWidth);
1609 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001610 Field::SetLineWidth(m_pFormFillEnv.Get(), m_FieldName,
1611 m_nFormControlIndex, iWidth);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001612 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001613 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001614 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001615 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1616 if (FieldArray.empty())
1617 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001618
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001619 CPDF_FormField* pFormField = FieldArray[0];
1620 ASSERT(pFormField);
1621 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1622 if (!pFormControl)
1623 return false;
1624
1625 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
1626 if (!pFormField->CountControls())
1627 return false;
1628
1629 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
1630 if (!pWidget)
1631 return false;
1632
1633 vp << (int32_t)pWidget->GetBorderWidth();
tsepez4cf55152016-11-02 14:37:54 -07001634 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001635}
1636
dsinclair3a7741a2016-10-11 10:39:49 -07001637void Field::SetLineWidth(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001638 const CFX_WideString& swFieldName,
1639 int nControlIndex,
1640 int number) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001641 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001642 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07001643 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -08001644 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001645 if (nControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -07001646 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001647 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1648 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08001649 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001650
dsinclairc5267c52016-11-04 15:35:12 -07001651 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001652 if (number != pWidget->GetBorderWidth()) {
1653 pWidget->SetBorderWidth(number);
tsepez4cf55152016-11-02 14:37:54 -07001654 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001655 }
1656 }
1657 }
1658 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -07001659 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001660 } else {
1661 if (nControlIndex >= pFormField->CountControls())
1662 return;
1663 if (CPDF_FormControl* pFormControl =
1664 pFormField->GetControl(nControlIndex)) {
dsinclairc5267c52016-11-04 15:35:12 -07001665 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001666 if (number != pWidget->GetBorderWidth()) {
1667 pWidget->SetBorderWidth(number);
tsepez4cf55152016-11-02 14:37:54 -07001668 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001669 }
1670 }
1671 }
1672 }
1673 }
1674}
1675
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001676bool Field::multiline(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07001677 CJS_PropValue& vp,
1678 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001679 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001680
1681 if (vp.IsSetting()) {
1682 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001683 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001684
1685 bool bVP;
1686 vp >> bVP;
1687
1688 if (m_bDelay) {
1689 AddDelay_Bool(FP_MULTILINE, bVP);
1690 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001691 Field::SetMultiline(m_pFormFillEnv.Get(), m_FieldName,
1692 m_nFormControlIndex, bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001693 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001694 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001695 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001696 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1697 if (FieldArray.empty())
1698 return false;
1699
1700 CPDF_FormField* pFormField = FieldArray[0];
1701 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1702 return false;
1703
1704 if (pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE)
1705 vp << true;
1706 else
1707 vp << false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001708
tsepez4cf55152016-11-02 14:37:54 -07001709 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001710}
1711
dsinclair3a7741a2016-10-11 10:39:49 -07001712void Field::SetMultiline(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001713 const CFX_WideString& swFieldName,
1714 int nControlIndex,
1715 bool b) {
1716 // Not supported.
1717}
1718
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001719bool Field::multipleSelection(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07001720 CJS_PropValue& vp,
1721 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001722 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001723 if (vp.IsSetting()) {
1724 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001725 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001726
1727 bool bVP;
1728 vp >> bVP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001729 if (m_bDelay) {
1730 AddDelay_Bool(FP_MULTIPLESELECTION, bVP);
1731 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001732 Field::SetMultipleSelection(m_pFormFillEnv.Get(), m_FieldName,
tsepez56cf5192016-09-12 11:59:30 -07001733 m_nFormControlIndex, bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001734 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001735 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001736 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001737 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1738 if (FieldArray.empty())
1739 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001740
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001741 CPDF_FormField* pFormField = FieldArray[0];
1742 if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
1743 return false;
1744
1745 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT);
tsepez4cf55152016-11-02 14:37:54 -07001746 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001747}
1748
dsinclair3a7741a2016-10-11 10:39:49 -07001749void Field::SetMultipleSelection(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001750 const CFX_WideString& swFieldName,
1751 int nControlIndex,
1752 bool b) {
1753 // Not supported.
1754}
1755
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001756bool Field::name(IJS_EventContext* cc,
1757 CJS_PropValue& vp,
1758 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001759 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -07001760 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001761
Lei Zhangd88a3642015-11-10 09:38:57 -08001762 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1763 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001764 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001765
1766 vp << m_FieldName;
tsepez4cf55152016-11-02 14:37:54 -07001767 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001768}
1769
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001770bool Field::numItems(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07001771 CJS_PropValue& vp,
1772 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07001773 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -07001774 return false;
Tom Sepez67fd5df2015-10-08 12:24:19 -07001775
Lei Zhangd88a3642015-11-10 09:38:57 -08001776 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1777 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001778 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001779
Lei Zhangd88a3642015-11-10 09:38:57 -08001780 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001781 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001782 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
tsepez4cf55152016-11-02 14:37:54 -07001783 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001784 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001785
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001786 vp << (int32_t)pFormField->CountOptions();
tsepez4cf55152016-11-02 14:37:54 -07001787 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001788}
1789
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001790bool Field::page(IJS_EventContext* cc,
1791 CJS_PropValue& vp,
1792 CFX_WideString& sError) {
tsepez8fa82792017-01-11 09:32:33 -08001793 if (!vp.IsGetting()) {
1794 sError = JSGetStringFromID(IDS_STRING_JSREADONLY);
tsepez4cf55152016-11-02 14:37:54 -07001795 return false;
tsepez8fa82792017-01-11 09:32:33 -08001796 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001797
Lei Zhangd88a3642015-11-10 09:38:57 -08001798 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1799 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001800 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001801
Lei Zhangd88a3642015-11-10 09:38:57 -08001802 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001803 if (!pFormField)
tsepez4cf55152016-11-02 14:37:54 -07001804 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001805
tsepez8fa82792017-01-11 09:32:33 -08001806 std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
dsinclair7cbe68e2016-10-12 11:56:23 -07001807 m_pFormFillEnv->GetInterForm()->GetWidgets(pFormField, &widgets);
Lei Zhangd88a3642015-11-10 09:38:57 -08001808 if (widgets.empty()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001809 vp << (int32_t)-1;
tsepez4cf55152016-11-02 14:37:54 -07001810 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001811 }
1812
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001813 CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
tsepeze5aff742016-08-08 09:49:42 -07001814 CJS_Array PageArray;
tsepez8fa82792017-01-11 09:32:33 -08001815 int i = 0;
1816 for (const auto& pObserved : widgets) {
1817 if (!pObserved) {
1818 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT);
1819 return false;
1820 }
1821
1822 auto pWidget = static_cast<CPDFSDK_Widget*>(pObserved.Get());
1823 CPDFSDK_PageView* pPageView = pWidget->GetPageView();
Lei Zhangd88a3642015-11-10 09:38:57 -08001824 if (!pPageView)
tsepez4cf55152016-11-02 14:37:54 -07001825 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001826
1827 PageArray.SetElement(
tsepezb4694242016-08-15 16:44:55 -07001828 pRuntime, i, CJS_Value(pRuntime, (int32_t)pPageView->GetPageIndex()));
tsepez8fa82792017-01-11 09:32:33 -08001829 ++i;
Lei Zhangd88a3642015-11-10 09:38:57 -08001830 }
1831
1832 vp << PageArray;
tsepez4cf55152016-11-02 14:37:54 -07001833 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001834}
1835
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001836bool Field::password(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07001837 CJS_PropValue& vp,
1838 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07001839 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001840
1841 if (vp.IsSetting()) {
1842 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001843 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001844
1845 bool bVP;
1846 vp >> bVP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001847 if (m_bDelay) {
1848 AddDelay_Bool(FP_PASSWORD, bVP);
1849 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07001850 Field::SetPassword(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07001851 bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001852 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001853 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001854 }
1855
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001856 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1857 if (FieldArray.empty())
1858 return false;
1859
1860 CPDF_FormField* pFormField = FieldArray[0];
1861 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1862 return false;
1863
1864 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD);
tsepez4cf55152016-11-02 14:37:54 -07001865 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001866}
1867
dsinclair3a7741a2016-10-11 10:39:49 -07001868void Field::SetPassword(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001869 const CFX_WideString& swFieldName,
1870 int nControlIndex,
1871 bool b) {
1872 // Not supported.
1873}
1874
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001875bool Field::print(IJS_EventContext* cc,
1876 CJS_PropValue& vp,
1877 CFX_WideString& sError) {
dsinclair7cbe68e2016-10-12 11:56:23 -07001878 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001879 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1880 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001881 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001882
1883 if (vp.IsSetting()) {
1884 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001885 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001886
1887 bool bVP;
1888 vp >> bVP;
1889
Lei Zhangd88a3642015-11-10 09:38:57 -08001890 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001891 if (m_nFormControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -07001892 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001893 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001894 if (CPDFSDK_Widget* pWidget =
dsinclairc5267c52016-11-04 15:35:12 -07001895 pInterForm->GetWidget(pFormField->GetControl(i))) {
tsepezc3255f52016-03-25 14:52:27 -07001896 uint32_t dwFlags = pWidget->GetFlags();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001897 if (bVP)
1898 dwFlags |= ANNOTFLAG_PRINT;
1899 else
1900 dwFlags &= ~ANNOTFLAG_PRINT;
1901
1902 if (dwFlags != pWidget->GetFlags()) {
1903 pWidget->SetFlags(dwFlags);
tsepez4cf55152016-11-02 14:37:54 -07001904 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001905 }
1906 }
1907 }
1908
1909 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -07001910 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001911 } else {
1912 if (m_nFormControlIndex >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07001913 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001914 if (CPDF_FormControl* pFormControl =
1915 pFormField->GetControl(m_nFormControlIndex)) {
dsinclairc5267c52016-11-04 15:35:12 -07001916 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
tsepezc3255f52016-03-25 14:52:27 -07001917 uint32_t dwFlags = pWidget->GetFlags();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001918 if (bVP)
1919 dwFlags |= ANNOTFLAG_PRINT;
1920 else
1921 dwFlags &= ~ANNOTFLAG_PRINT;
1922
1923 if (dwFlags != pWidget->GetFlags()) {
1924 pWidget->SetFlags(dwFlags);
dsinclair3a7741a2016-10-11 10:39:49 -07001925 UpdateFormControl(m_pFormFillEnv.Get(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001926 pFormField->GetControl(m_nFormControlIndex),
tsepez4cf55152016-11-02 14:37:54 -07001927 true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001928 }
1929 }
1930 }
1931 }
1932 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001933 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001934 }
1935
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001936 CPDF_FormField* pFormField = FieldArray[0];
1937 CPDFSDK_Widget* pWidget =
1938 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1939 if (!pWidget)
1940 return false;
1941
1942 vp << !!(pWidget->GetFlags() & ANNOTFLAG_PRINT);
tsepez4cf55152016-11-02 14:37:54 -07001943 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001944}
1945
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001946bool Field::radiosInUnison(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07001947 CJS_PropValue& vp,
1948 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001949 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1950 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001951 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001952
1953 if (vp.IsSetting()) {
1954 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001955 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001956
1957 bool bVP;
1958 vp >> bVP;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001959 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001960 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001961 CPDF_FormField* pFormField = FieldArray[0];
1962 if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
1963 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001964
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001965 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON);
tsepez4cf55152016-11-02 14:37:54 -07001966 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001967}
1968
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001969bool Field::readonly(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07001970 CJS_PropValue& vp,
1971 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001972 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1973 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07001974 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001975
1976 if (vp.IsSetting()) {
1977 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001978 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001979
1980 bool bVP;
1981 vp >> bVP;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001982 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001983 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001984 vp << !!(FieldArray[0]->GetFieldFlags() & FIELDFLAG_READONLY);
tsepez4cf55152016-11-02 14:37:54 -07001985 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001986}
1987
Tom Sepezd6ae2af2017-02-16 11:49:55 -08001988bool Field::rect(IJS_EventContext* cc,
1989 CJS_PropValue& vp,
1990 CFX_WideString& sError) {
1991 CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
Tom Sepez67fd5df2015-10-08 12:24:19 -07001992 CJS_Value Upper_Leftx(pRuntime);
1993 CJS_Value Upper_Lefty(pRuntime);
1994 CJS_Value Lower_Rightx(pRuntime);
1995 CJS_Value Lower_Righty(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001996
1997 if (vp.IsSetting()) {
1998 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07001999 return false;
tsepezf3dc8c62016-08-10 06:29:29 -07002000 if (!vp.GetJSValue()->IsArrayObject())
tsepez4cf55152016-11-02 14:37:54 -07002001 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002002
tsepeze5aff742016-08-08 09:49:42 -07002003 CJS_Array rcArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002004 vp >> rcArray;
tsepezb4694242016-08-15 16:44:55 -07002005 rcArray.GetElement(pRuntime, 0, Upper_Leftx);
2006 rcArray.GetElement(pRuntime, 1, Upper_Lefty);
2007 rcArray.GetElement(pRuntime, 2, Lower_Rightx);
2008 rcArray.GetElement(pRuntime, 3, Lower_Righty);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002009
2010 FX_FLOAT pArray[4] = {0.0f, 0.0f, 0.0f, 0.0f};
tsepezb4694242016-08-15 16:44:55 -07002011 pArray[0] = static_cast<FX_FLOAT>(Upper_Leftx.ToInt(pRuntime));
2012 pArray[1] = static_cast<FX_FLOAT>(Lower_Righty.ToInt(pRuntime));
2013 pArray[2] = static_cast<FX_FLOAT>(Lower_Rightx.ToInt(pRuntime));
2014 pArray[3] = static_cast<FX_FLOAT>(Upper_Lefty.ToInt(pRuntime));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002015
Tom Sepez281a9ea2016-02-26 14:24:28 -08002016 CFX_FloatRect crRect(pArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002017 if (m_bDelay) {
2018 AddDelay_Rect(FP_RECT, crRect);
2019 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002020 Field::SetRect(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07002021 crRect);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002022 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002023 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002024 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002025 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2026 if (FieldArray.empty())
2027 return false;
2028
2029 CPDF_FormField* pFormField = FieldArray[0];
2030 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
2031 CPDFSDK_Widget* pWidget =
2032 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
2033 if (!pWidget)
2034 return false;
2035
2036 CFX_FloatRect crRect = pWidget->GetRect();
2037 Upper_Leftx = CJS_Value(pRuntime, static_cast<int32_t>(crRect.left));
2038 Upper_Lefty = CJS_Value(pRuntime, static_cast<int32_t>(crRect.top));
2039 Lower_Rightx = CJS_Value(pRuntime, static_cast<int32_t>(crRect.right));
2040 Lower_Righty = CJS_Value(pRuntime, static_cast<int32_t>(crRect.bottom));
2041
2042 CJS_Array rcArray;
2043 rcArray.SetElement(pRuntime, 0, Upper_Leftx);
2044 rcArray.SetElement(pRuntime, 1, Upper_Lefty);
2045 rcArray.SetElement(pRuntime, 2, Lower_Rightx);
2046 rcArray.SetElement(pRuntime, 3, Lower_Righty);
2047 vp << rcArray;
tsepez4cf55152016-11-02 14:37:54 -07002048 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002049}
2050
dsinclair3a7741a2016-10-11 10:39:49 -07002051void Field::SetRect(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002052 const CFX_WideString& swFieldName,
2053 int nControlIndex,
Tom Sepez281a9ea2016-02-26 14:24:28 -08002054 const CFX_FloatRect& rect) {
dsinclair7cbe68e2016-10-12 11:56:23 -07002055 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08002056 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07002057 GetFormFields(pFormFillEnv, swFieldName);
Lei Zhangd88a3642015-11-10 09:38:57 -08002058 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002059 if (nControlIndex < 0) {
tsepez4cf55152016-11-02 14:37:54 -07002060 bool bSet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08002061 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002062 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08002063 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002064
dsinclairc5267c52016-11-04 15:35:12 -07002065 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002066 CFX_FloatRect crRect = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002067
2068 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002069 crRect.Intersect(pPDFPage->GetPageBBox());
2070
2071 if (!crRect.IsEmpty()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002072 CFX_FloatRect rcOld = pWidget->GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002073 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
2074 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
2075 pWidget->SetRect(crRect);
tsepez4cf55152016-11-02 14:37:54 -07002076 bSet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002077 }
2078 }
2079 }
2080 }
2081
2082 if (bSet)
tsepez4cf55152016-11-02 14:37:54 -07002083 UpdateFormField(pFormFillEnv, pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002084 } else {
2085 if (nControlIndex >= pFormField->CountControls())
2086 return;
2087 if (CPDF_FormControl* pFormControl =
2088 pFormField->GetControl(nControlIndex)) {
dsinclairc5267c52016-11-04 15:35:12 -07002089 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002090 CFX_FloatRect crRect = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002091
2092 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002093 crRect.Intersect(pPDFPage->GetPageBBox());
2094
2095 if (!crRect.IsEmpty()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002096 CFX_FloatRect rcOld = pWidget->GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002097 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
2098 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
2099 pWidget->SetRect(crRect);
tsepez4cf55152016-11-02 14:37:54 -07002100 UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002101 }
2102 }
2103 }
2104 }
2105 }
2106 }
2107}
2108
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002109bool Field::required(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07002110 CJS_PropValue& vp,
2111 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002112 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2113 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002114 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002115
2116 if (vp.IsSetting()) {
2117 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002118 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002119
2120 bool bVP;
2121 vp >> bVP;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002122 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002123 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002124 CPDF_FormField* pFormField = FieldArray[0];
2125 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
2126 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002127
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002128 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED);
tsepez4cf55152016-11-02 14:37:54 -07002129 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002130}
2131
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002132bool Field::richText(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07002133 CJS_PropValue& vp,
2134 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002135 ASSERT(m_pFormFillEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002136
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002137 if (vp.IsSetting()) {
2138 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002139 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002140
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002141 bool bVP;
2142 vp >> bVP;
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002143 if (m_bDelay)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002144 AddDelay_Bool(FP_RICHTEXT, bVP);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002145
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002146 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002147 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002148
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002149 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2150 if (FieldArray.empty())
2151 return false;
2152
2153 CPDF_FormField* pFormField = FieldArray[0];
2154 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
2155 return false;
2156
2157 vp << !!(pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT);
tsepez4cf55152016-11-02 14:37:54 -07002158 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002159}
2160
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002161bool Field::richValue(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07002162 CJS_PropValue& vp,
2163 CFX_WideString& sError) {
2164 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002165}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002166
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002167bool Field::rotation(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07002168 CJS_PropValue& vp,
2169 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002170 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002171
2172 if (vp.IsSetting()) {
2173 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002174 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002175
2176 int nVP;
2177 vp >> nVP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002178 if (m_bDelay) {
2179 AddDelay_Int(FP_ROTATION, nVP);
2180 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002181 Field::SetRotation(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07002182 nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002183 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002184 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002185 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002186 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2187 if (FieldArray.empty())
2188 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002189
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002190 CPDF_FormField* pFormField = FieldArray[0];
2191 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2192 if (!pFormControl)
2193 return false;
2194
2195 vp << (int32_t)pFormControl->GetRotation();
tsepez4cf55152016-11-02 14:37:54 -07002196 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002197}
2198
dsinclair3a7741a2016-10-11 10:39:49 -07002199void Field::SetRotation(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002200 const CFX_WideString& swFieldName,
2201 int nControlIndex,
2202 int number) {
2203 // Not supported.
2204}
2205
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002206bool Field::strokeColor(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07002207 CJS_PropValue& vp,
2208 CFX_WideString& sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002209 CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
tsepeze5aff742016-08-08 09:49:42 -07002210 CJS_Array crArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002211
2212 if (vp.IsSetting()) {
2213 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002214 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002215
tsepezf3dc8c62016-08-10 06:29:29 -07002216 if (!vp.GetJSValue()->IsArrayObject())
tsepez4cf55152016-11-02 14:37:54 -07002217 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002218
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002219 vp >> crArray;
2220
2221 CPWL_Color color;
tsepeze5aff742016-08-08 09:49:42 -07002222 color::ConvertArrayToPWLColor(pRuntime, crArray, &color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002223 if (m_bDelay) {
2224 AddDelay_Color(FP_STROKECOLOR, color);
2225 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002226 Field::SetStrokeColor(m_pFormFillEnv.Get(), m_FieldName,
2227 m_nFormControlIndex, color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002228 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002229 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002230 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002231 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2232 if (FieldArray.empty())
2233 return false;
2234
2235 CPDF_FormField* pFormField = FieldArray[0];
2236 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2237 if (!pFormControl)
2238 return false;
2239
2240 int iColorType;
2241 pFormControl->GetBorderColor(iColorType);
2242
2243 CPWL_Color color;
2244 if (iColorType == COLORTYPE_TRANSPARENT) {
2245 color = CPWL_Color(COLORTYPE_TRANSPARENT);
2246 } else if (iColorType == COLORTYPE_GRAY) {
2247 color = CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBorderColor(0));
2248 } else if (iColorType == COLORTYPE_RGB) {
2249 color = CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBorderColor(0),
2250 pFormControl->GetOriginalBorderColor(1),
2251 pFormControl->GetOriginalBorderColor(2));
2252 } else if (iColorType == COLORTYPE_CMYK) {
2253 color = CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBorderColor(0),
2254 pFormControl->GetOriginalBorderColor(1),
2255 pFormControl->GetOriginalBorderColor(2),
2256 pFormControl->GetOriginalBorderColor(3));
2257 } else {
2258 return false;
2259 }
2260
2261 color::ConvertPWLColorToArray(pRuntime, color, &crArray);
2262 vp << crArray;
tsepez4cf55152016-11-02 14:37:54 -07002263 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002264}
2265
dsinclair3a7741a2016-10-11 10:39:49 -07002266void Field::SetStrokeColor(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002267 const CFX_WideString& swFieldName,
2268 int nControlIndex,
2269 const CPWL_Color& color) {
2270 // Not supported.
2271}
2272
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002273bool Field::style(IJS_EventContext* cc,
2274 CJS_PropValue& vp,
2275 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002276 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002277
2278 if (vp.IsSetting()) {
2279 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002280 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002281
2282 CFX_ByteString csBCaption;
2283 vp >> csBCaption;
2284
2285 if (m_bDelay) {
2286 AddDelay_String(FP_STYLE, csBCaption);
2287 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002288 Field::SetStyle(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002289 csBCaption);
2290 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002291 return true;
2292 }
2293 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2294 if (FieldArray.empty())
2295 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002296
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002297 CPDF_FormField* pFormField = FieldArray[0];
2298 if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON &&
2299 pFormField->GetFieldType() != FIELDTYPE_CHECKBOX) {
2300 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002301 }
2302
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002303 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2304 if (!pFormControl)
2305 return false;
2306
2307 CFX_WideString csWCaption = pFormControl->GetNormalCaption();
2308 CFX_ByteString csBCaption;
2309
2310 switch (csWCaption[0]) {
2311 case L'l':
2312 csBCaption = "circle";
2313 break;
2314 case L'8':
2315 csBCaption = "cross";
2316 break;
2317 case L'u':
2318 csBCaption = "diamond";
2319 break;
2320 case L'n':
2321 csBCaption = "square";
2322 break;
2323 case L'H':
2324 csBCaption = "star";
2325 break;
2326 default: // L'4'
2327 csBCaption = "check";
2328 break;
2329 }
2330 vp << csBCaption;
tsepez4cf55152016-11-02 14:37:54 -07002331 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002332}
2333
dsinclair3a7741a2016-10-11 10:39:49 -07002334void Field::SetStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002335 const CFX_WideString& swFieldName,
2336 int nControlIndex,
2337 const CFX_ByteString& string) {
2338 // Not supported.
2339}
2340
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002341bool Field::submitName(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07002342 CJS_PropValue& vp,
2343 CFX_WideString& sError) {
2344 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002345}
2346
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002347bool Field::textColor(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07002348 CJS_PropValue& vp,
2349 CFX_WideString& sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002350 CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
tsepeze5aff742016-08-08 09:49:42 -07002351 CJS_Array crArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002352
2353 if (vp.IsSetting()) {
2354 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002355 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002356
tsepezf3dc8c62016-08-10 06:29:29 -07002357 if (!vp.GetJSValue()->IsArrayObject())
tsepez4cf55152016-11-02 14:37:54 -07002358 return false;
Tom Sepez67fd5df2015-10-08 12:24:19 -07002359
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002360 vp >> crArray;
2361
2362 CPWL_Color color;
tsepeze5aff742016-08-08 09:49:42 -07002363 color::ConvertArrayToPWLColor(pRuntime, crArray, &color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002364 if (m_bDelay) {
2365 AddDelay_Color(FP_TEXTCOLOR, color);
2366 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002367 Field::SetTextColor(m_pFormFillEnv.Get(), m_FieldName,
2368 m_nFormControlIndex, color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002369 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002370 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002371 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002372 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2373 if (FieldArray.empty())
2374 return false;
2375
2376 CPDF_FormField* pFormField = FieldArray[0];
2377 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2378 if (!pFormControl)
2379 return false;
2380
2381 int iColorType;
2382 FX_ARGB color;
2383 CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
2384 FieldAppearance.GetColor(color, iColorType);
2385
2386 int32_t a;
2387 int32_t r;
2388 int32_t g;
2389 int32_t b;
2390 ArgbDecode(color, a, r, g, b);
2391
2392 CPWL_Color crRet =
2393 CPWL_Color(COLORTYPE_RGB, r / 255.0f, g / 255.0f, b / 255.0f);
2394
2395 if (iColorType == COLORTYPE_TRANSPARENT)
2396 crRet = CPWL_Color(COLORTYPE_TRANSPARENT);
2397
2398 color::ConvertPWLColorToArray(pRuntime, crRet, &crArray);
2399 vp << crArray;
tsepez4cf55152016-11-02 14:37:54 -07002400 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002401}
2402
dsinclair3a7741a2016-10-11 10:39:49 -07002403void Field::SetTextColor(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002404 const CFX_WideString& swFieldName,
2405 int nControlIndex,
2406 const CPWL_Color& color) {
2407 // Not supported.
2408}
2409
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002410bool Field::textFont(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07002411 CJS_PropValue& vp,
2412 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002413 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002414
2415 if (vp.IsSetting()) {
2416 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002417 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002418
2419 CFX_ByteString csFontName;
2420 vp >> csFontName;
2421 if (csFontName.IsEmpty())
tsepez4cf55152016-11-02 14:37:54 -07002422 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002423
2424 if (m_bDelay) {
2425 AddDelay_String(FP_TEXTFONT, csFontName);
2426 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002427 Field::SetTextFont(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002428 csFontName);
2429 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002430 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002431 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002432 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2433 if (FieldArray.empty())
2434 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002435
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002436 CPDF_FormField* pFormField = FieldArray[0];
2437 ASSERT(pFormField);
2438 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2439 if (!pFormControl)
2440 return false;
2441
2442 int nFieldType = pFormField->GetFieldType();
2443 if (nFieldType != FIELDTYPE_PUSHBUTTON && nFieldType != FIELDTYPE_COMBOBOX &&
2444 nFieldType != FIELDTYPE_LISTBOX && nFieldType != FIELDTYPE_TEXTFIELD) {
2445 return false;
2446 }
2447 CPDF_Font* pFont = pFormControl->GetDefaultControlFont();
2448 if (!pFont)
2449 return false;
2450
2451 vp << pFont->GetBaseFont();
tsepez4cf55152016-11-02 14:37:54 -07002452 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002453}
2454
dsinclair3a7741a2016-10-11 10:39:49 -07002455void Field::SetTextFont(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002456 const CFX_WideString& swFieldName,
2457 int nControlIndex,
2458 const CFX_ByteString& string) {
2459 // Not supported.
2460}
2461
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002462bool Field::textSize(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07002463 CJS_PropValue& vp,
2464 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002465 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002466
2467 if (vp.IsSetting()) {
2468 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002469 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002470
2471 int nVP;
2472 vp >> nVP;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002473 if (m_bDelay) {
2474 AddDelay_Int(FP_TEXTSIZE, nVP);
2475 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002476 Field::SetTextSize(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07002477 nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002478 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002479 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002480 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002481 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2482 if (FieldArray.empty())
2483 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002484
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002485 CPDF_FormField* pFormField = FieldArray[0];
2486 ASSERT(pFormField);
2487 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2488 if (!pFormControl)
2489 return false;
2490
2491 CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
2492
2493 CFX_ByteString csFontNameTag;
2494 FX_FLOAT fFontSize;
2495 FieldAppearance.GetFont(csFontNameTag, fFontSize);
2496 vp << (int)fFontSize;
tsepez4cf55152016-11-02 14:37:54 -07002497 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002498}
2499
dsinclair3a7741a2016-10-11 10:39:49 -07002500void Field::SetTextSize(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002501 const CFX_WideString& swFieldName,
2502 int nControlIndex,
2503 int number) {
2504 // Not supported.
2505}
2506
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002507bool Field::type(IJS_EventContext* cc,
2508 CJS_PropValue& vp,
2509 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002510 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -07002511 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002512
Lei Zhangd88a3642015-11-10 09:38:57 -08002513 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2514 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002515 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002516
Lei Zhangd88a3642015-11-10 09:38:57 -08002517 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002518 switch (pFormField->GetFieldType()) {
2519 case FIELDTYPE_UNKNOWN:
2520 vp << L"unknown";
2521 break;
2522 case FIELDTYPE_PUSHBUTTON:
2523 vp << L"button";
2524 break;
2525 case FIELDTYPE_CHECKBOX:
2526 vp << L"checkbox";
2527 break;
2528 case FIELDTYPE_RADIOBUTTON:
2529 vp << L"radiobutton";
2530 break;
2531 case FIELDTYPE_COMBOBOX:
2532 vp << L"combobox";
2533 break;
2534 case FIELDTYPE_LISTBOX:
2535 vp << L"listbox";
2536 break;
2537 case FIELDTYPE_TEXTFIELD:
2538 vp << L"text";
2539 break;
2540 case FIELDTYPE_SIGNATURE:
2541 vp << L"signature";
2542 break;
2543 default:
2544 vp << L"unknown";
2545 break;
2546 }
tsepez4cf55152016-11-02 14:37:54 -07002547 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002548}
2549
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002550bool Field::userName(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07002551 CJS_PropValue& vp,
2552 CFX_WideString& sError) {
dsinclair3a7741a2016-10-11 10:39:49 -07002553 ASSERT(m_pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002554
2555 if (vp.IsSetting()) {
2556 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002557 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002558
2559 CFX_WideString swName;
2560 vp >> swName;
2561
2562 if (m_bDelay) {
2563 AddDelay_WideString(FP_USERNAME, swName);
2564 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002565 Field::SetUserName(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07002566 swName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002567 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002568 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002569 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002570 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2571 if (FieldArray.empty())
2572 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002573
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002574 vp << FieldArray[0]->GetAlternateName();
tsepez4cf55152016-11-02 14:37:54 -07002575 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002576}
2577
dsinclair3a7741a2016-10-11 10:39:49 -07002578void Field::SetUserName(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002579 const CFX_WideString& swFieldName,
2580 int nControlIndex,
2581 const CFX_WideString& string) {
2582 // Not supported.
2583}
2584
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002585bool Field::value(IJS_EventContext* cc,
2586 CJS_PropValue& vp,
2587 CFX_WideString& sError) {
2588 CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002589
2590 if (vp.IsSetting()) {
2591 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002592 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002593
tsepez41a53ad2016-03-28 16:59:30 -07002594 std::vector<CFX_WideString> strArray;
tsepezf3dc8c62016-08-10 06:29:29 -07002595 if (vp.GetJSValue()->IsArrayObject()) {
tsepeze5aff742016-08-08 09:49:42 -07002596 CJS_Array ValueArray;
tsepezb4694242016-08-15 16:44:55 -07002597 vp.GetJSValue()->ConvertToArray(pRuntime, ValueArray);
2598 for (int i = 0, sz = ValueArray.GetLength(pRuntime); i < sz; i++) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002599 CJS_Value ElementValue(pRuntime);
tsepezb4694242016-08-15 16:44:55 -07002600 ValueArray.GetElement(pRuntime, i, ElementValue);
2601 strArray.push_back(ElementValue.ToCFXWideString(pRuntime));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002602 }
2603 } else {
2604 CFX_WideString swValue;
2605 vp >> swValue;
tsepez41a53ad2016-03-28 16:59:30 -07002606 strArray.push_back(swValue);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002607 }
2608
2609 if (m_bDelay) {
2610 AddDelay_WideStringArray(FP_VALUE, strArray);
2611 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07002612 Field::SetValue(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex,
tsepez56cf5192016-09-12 11:59:30 -07002613 strArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002614 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002615 return true;
2616 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002617
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002618 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2619 if (FieldArray.empty())
2620 return false;
2621
2622 CPDF_FormField* pFormField = FieldArray[0];
2623 switch (pFormField->GetFieldType()) {
2624 case FIELDTYPE_PUSHBUTTON:
2625 return false;
2626 case FIELDTYPE_COMBOBOX:
2627 case FIELDTYPE_TEXTFIELD: {
2628 vp << pFormField->GetValue();
2629 } break;
2630 case FIELDTYPE_LISTBOX: {
2631 if (pFormField->CountSelectedItems() > 1) {
2632 CJS_Array ValueArray;
2633 CJS_Value ElementValue(pRuntime);
2634 int iIndex;
2635 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
2636 iIndex = pFormField->GetSelectedIndex(i);
2637 ElementValue =
2638 CJS_Value(pRuntime, pFormField->GetOptionValue(iIndex).c_str());
2639 if (FXSYS_wcslen(ElementValue.ToCFXWideString(pRuntime).c_str()) ==
2640 0) {
tsepezf3dc8c62016-08-10 06:29:29 -07002641 ElementValue =
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002642 CJS_Value(pRuntime, pFormField->GetOptionLabel(iIndex).c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002643 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002644 ValueArray.SetElement(pRuntime, i, ElementValue);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002645 }
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002646 vp << ValueArray;
2647 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002648 vp << pFormField->GetValue();
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002649 }
2650 } break;
2651 case FIELDTYPE_CHECKBOX:
2652 case FIELDTYPE_RADIOBUTTON: {
2653 bool bFind = false;
2654 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2655 if (pFormField->GetControl(i)->IsChecked()) {
2656 vp << pFormField->GetControl(i)->GetExportValue();
2657 bFind = true;
2658 break;
2659 }
2660 }
2661 if (!bFind)
2662 vp << L"Off";
2663 } break;
2664 default:
2665 vp << pFormField->GetValue();
2666 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002667 }
tsepezb4694242016-08-15 16:44:55 -07002668 vp.GetJSValue()->MaybeCoerceToNumber(pRuntime);
tsepez4cf55152016-11-02 14:37:54 -07002669 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002670}
2671
dsinclair3a7741a2016-10-11 10:39:49 -07002672void Field::SetValue(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002673 const CFX_WideString& swFieldName,
2674 int nControlIndex,
tsepez41a53ad2016-03-28 16:59:30 -07002675 const std::vector<CFX_WideString>& strArray) {
dsinclair3a7741a2016-10-11 10:39:49 -07002676 ASSERT(pFormFillEnv);
tsepez41a53ad2016-03-28 16:59:30 -07002677 if (strArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002678 return;
2679
Lei Zhangd88a3642015-11-10 09:38:57 -08002680 std::vector<CPDF_FormField*> FieldArray =
dsinclair3a7741a2016-10-11 10:39:49 -07002681 GetFormFields(pFormFillEnv, swFieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002682
Lei Zhangd88a3642015-11-10 09:38:57 -08002683 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002684 if (pFormField->GetFullName().Compare(swFieldName) != 0)
2685 continue;
2686
2687 switch (pFormField->GetFieldType()) {
2688 case FIELDTYPE_TEXTFIELD:
2689 case FIELDTYPE_COMBOBOX:
tsepez41a53ad2016-03-28 16:59:30 -07002690 if (pFormField->GetValue() != strArray[0]) {
tsepez4cf55152016-11-02 14:37:54 -07002691 pFormField->SetValue(strArray[0], true);
2692 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002693 }
2694 break;
tsepez41a53ad2016-03-28 16:59:30 -07002695 case FIELDTYPE_CHECKBOX:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002696 case FIELDTYPE_RADIOBUTTON: {
tsepez41a53ad2016-03-28 16:59:30 -07002697 if (pFormField->GetValue() != strArray[0]) {
tsepez4cf55152016-11-02 14:37:54 -07002698 pFormField->SetValue(strArray[0], true);
2699 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002700 }
2701 } break;
2702 case FIELDTYPE_LISTBOX: {
tsepez4cf55152016-11-02 14:37:54 -07002703 bool bModified = false;
tsepez41a53ad2016-03-28 16:59:30 -07002704 for (const auto& str : strArray) {
2705 if (!pFormField->IsItemSelected(pFormField->FindOption(str))) {
tsepez4cf55152016-11-02 14:37:54 -07002706 bModified = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002707 break;
2708 }
2709 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002710 if (bModified) {
tsepez4cf55152016-11-02 14:37:54 -07002711 pFormField->ClearSelection(true);
tsepez41a53ad2016-03-28 16:59:30 -07002712 for (const auto& str : strArray) {
2713 int index = pFormField->FindOption(str);
2714 if (!pFormField->IsItemSelected(index))
tsepez4cf55152016-11-02 14:37:54 -07002715 pFormField->SetItemSelection(index, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002716 }
tsepez4cf55152016-11-02 14:37:54 -07002717 UpdateFormField(pFormFillEnv, pFormField, true, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002718 }
2719 } break;
2720 default:
2721 break;
2722 }
2723 }
2724}
2725
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002726bool Field::valueAsString(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07002727 CJS_PropValue& vp,
2728 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002729 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -07002730 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002731
Lei Zhangd88a3642015-11-10 09:38:57 -08002732 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2733 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002734 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002735
Lei Zhangd88a3642015-11-10 09:38:57 -08002736 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002737 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002738 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002739
2740 if (pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) {
2741 if (!pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002742 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002743
2744 if (pFormField->GetControl(0)->IsChecked())
2745 vp << L"Yes";
2746 else
2747 vp << L"Off";
2748 } else if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON &&
2749 !(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)) {
2750 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2751 if (pFormField->GetControl(i)->IsChecked()) {
2752 vp << pFormField->GetControl(i)->GetExportValue().c_str();
2753 break;
Lei Zhangd88a3642015-11-10 09:38:57 -08002754 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002755 vp << L"Off";
Lei Zhangd88a3642015-11-10 09:38:57 -08002756 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002757 }
2758 } else if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX &&
2759 (pFormField->CountSelectedItems() > 1)) {
2760 vp << L"";
Lei Zhangd88a3642015-11-10 09:38:57 -08002761 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002762 vp << pFormField->GetValue().c_str();
Lei Zhangd88a3642015-11-10 09:38:57 -08002763 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002764
tsepez4cf55152016-11-02 14:37:54 -07002765 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002766}
2767
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002768bool Field::browseForFileToSubmit(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07002769 const std::vector<CJS_Value>& params,
2770 CJS_Value& vRet,
2771 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002772 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2773 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002774 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002775
Lei Zhangd88a3642015-11-10 09:38:57 -08002776 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002777 if ((pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) &&
2778 (pFormField->GetFieldType() == FIELDTYPE_TEXTFIELD)) {
dsinclair3a7741a2016-10-11 10:39:49 -07002779 CFX_WideString wsFileName = m_pFormFillEnv->JS_fieldBrowse();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002780 if (!wsFileName.IsEmpty()) {
2781 pFormField->SetValue(wsFileName);
tsepez4cf55152016-11-02 14:37:54 -07002782 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002783 }
tsepez4cf55152016-11-02 14:37:54 -07002784 return true;
Lei Zhangd88a3642015-11-10 09:38:57 -08002785 }
tsepez4cf55152016-11-02 14:37:54 -07002786 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002787}
2788
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002789bool Field::buttonGetCaption(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07002790 const std::vector<CJS_Value>& params,
2791 CJS_Value& vRet,
2792 CFX_WideString& sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002793 CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
tsepezf3dc8c62016-08-10 06:29:29 -07002794
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002795 int nface = 0;
2796 int iSize = params.size();
2797 if (iSize >= 1)
tsepezb4694242016-08-15 16:44:55 -07002798 nface = params[0].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002799
Lei Zhangd88a3642015-11-10 09:38:57 -08002800 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2801 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002802 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002803
Lei Zhangd88a3642015-11-10 09:38:57 -08002804 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002805 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002806 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002807
2808 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2809 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -07002810 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002811
2812 if (nface == 0)
tsepezf3dc8c62016-08-10 06:29:29 -07002813 vRet = CJS_Value(pRuntime, pFormControl->GetNormalCaption().c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002814 else if (nface == 1)
tsepezf3dc8c62016-08-10 06:29:29 -07002815 vRet = CJS_Value(pRuntime, pFormControl->GetDownCaption().c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002816 else if (nface == 2)
tsepezf3dc8c62016-08-10 06:29:29 -07002817 vRet = CJS_Value(pRuntime, pFormControl->GetRolloverCaption().c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002818 else
tsepez4cf55152016-11-02 14:37:54 -07002819 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002820
tsepez4cf55152016-11-02 14:37:54 -07002821 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002822}
2823
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002824bool Field::buttonGetIcon(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07002825 const std::vector<CJS_Value>& params,
2826 CJS_Value& vRet,
2827 CFX_WideString& sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002828 CJS_EventContext* pContext = static_cast<CJS_EventContext*>(cc);
tsepezf3dc8c62016-08-10 06:29:29 -07002829 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
2830
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002831 int nface = 0;
2832 int iSize = params.size();
2833 if (iSize >= 1)
tsepezb4694242016-08-15 16:44:55 -07002834 nface = params[0].ToInt(pRuntime);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002835
Lei Zhangd88a3642015-11-10 09:38:57 -08002836 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2837 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002838 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002839
Lei Zhangd88a3642015-11-10 09:38:57 -08002840 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002841 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002842 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002843
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002844 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2845 if (!pFormControl)
tsepez4cf55152016-11-02 14:37:54 -07002846 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002847
tsepezb4694242016-08-15 16:44:55 -07002848 v8::Local<v8::Object> pObj =
2849 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID);
tsepez4cf55152016-11-02 14:37:54 -07002850 ASSERT(pObj.IsEmpty() == false);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002851
tsepezb4694242016-08-15 16:44:55 -07002852 CJS_Icon* pJS_Icon = static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002853 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002854
thestig1cd352e2016-06-07 17:53:06 -07002855 CPDF_Stream* pIconStream = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002856 if (nface == 0)
2857 pIconStream = pFormControl->GetNormalIcon();
2858 else if (nface == 1)
2859 pIconStream = pFormControl->GetDownIcon();
2860 else if (nface == 2)
2861 pIconStream = pFormControl->GetRolloverIcon();
2862 else
tsepez4cf55152016-11-02 14:37:54 -07002863 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002864
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002865 pIcon->SetStream(pIconStream);
tsepezf3dc8c62016-08-10 06:29:29 -07002866 vRet = CJS_Value(pRuntime, pJS_Icon);
tsepez4cf55152016-11-02 14:37:54 -07002867 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002868}
2869
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002870bool Field::buttonImportIcon(IJS_EventContext* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08002871 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002872 CJS_Value& vRet,
2873 CFX_WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -07002874 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002875}
2876
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002877bool Field::buttonSetCaption(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07002878 const std::vector<CJS_Value>& params,
2879 CJS_Value& vRet,
2880 CFX_WideString& sError) {
2881 return false;
2882}
2883
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002884bool Field::buttonSetIcon(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07002885 const std::vector<CJS_Value>& params,
2886 CJS_Value& vRet,
2887 CFX_WideString& sError) {
2888 return false;
2889}
2890
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002891bool Field::checkThisBox(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07002892 const std::vector<CJS_Value>& params,
2893 CJS_Value& vRet,
2894 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002895 int iSize = params.size();
2896 if (iSize < 1)
tsepez4cf55152016-11-02 14:37:54 -07002897 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002898
tsepezf3dc8c62016-08-10 06:29:29 -07002899 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002900 return false;
tsepezf3dc8c62016-08-10 06:29:29 -07002901
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002902 CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
tsepezb4694242016-08-15 16:44:55 -07002903 int nWidget = params[0].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002904
Wei Li97da9762016-03-11 17:00:48 -08002905 bool bCheckit = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002906 if (iSize >= 2)
tsepezb4694242016-08-15 16:44:55 -07002907 bCheckit = params[1].ToBool(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002908
Lei Zhangd88a3642015-11-10 09:38:57 -08002909 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2910 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002911 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002912
Lei Zhangd88a3642015-11-10 09:38:57 -08002913 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002914 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
2915 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
tsepez4cf55152016-11-02 14:37:54 -07002916 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002917 if (nWidget < 0 || nWidget >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002918 return false;
Wei Li97da9762016-03-11 17:00:48 -08002919 // TODO(weili): Check whether anything special needed for radio button,
2920 // otherwise merge these branches.
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002921 if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)
Wei Li97da9762016-03-11 17:00:48 -08002922 pFormField->CheckControl(nWidget, bCheckit, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002923 else
Wei Li97da9762016-03-11 17:00:48 -08002924 pFormField->CheckControl(nWidget, bCheckit, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002925
tsepez4cf55152016-11-02 14:37:54 -07002926 UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true);
2927 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002928}
2929
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002930bool Field::clearItems(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07002931 const std::vector<CJS_Value>& params,
2932 CJS_Value& vRet,
2933 CFX_WideString& sError) {
2934 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002935}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002936
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002937bool Field::defaultIsChecked(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07002938 const std::vector<CJS_Value>& params,
2939 CJS_Value& vRet,
2940 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002941 if (!m_bCanSet)
tsepez4cf55152016-11-02 14:37:54 -07002942 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002943
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002944 int iSize = params.size();
2945 if (iSize < 1)
tsepez4cf55152016-11-02 14:37:54 -07002946 return false;
Tom Sepezf4ef3f92015-04-23 11:31:31 -07002947
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002948 CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
tsepezb4694242016-08-15 16:44:55 -07002949 int nWidget = params[0].ToInt(pRuntime);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002950
Lei Zhangd88a3642015-11-10 09:38:57 -08002951 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2952 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002953 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002954
Lei Zhangd88a3642015-11-10 09:38:57 -08002955 CPDF_FormField* pFormField = FieldArray[0];
tsepezf3dc8c62016-08-10 06:29:29 -07002956 if (nWidget < 0 || nWidget >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07002957 return false;
tsepezf3dc8c62016-08-10 06:29:29 -07002958
2959 vRet = CJS_Value(pRuntime,
2960 pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
2961 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002962
tsepez4cf55152016-11-02 14:37:54 -07002963 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002964}
2965
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002966bool Field::deleteItemAt(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07002967 const std::vector<CJS_Value>& params,
2968 CJS_Value& vRet,
2969 CFX_WideString& sError) {
2970 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002971}
2972
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002973bool Field::getArray(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07002974 const std::vector<CJS_Value>& params,
2975 CJS_Value& vRet,
2976 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002977 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2978 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07002979 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002980
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002981 std::vector<std::unique_ptr<CFX_WideString>> swSort;
2982 for (CPDF_FormField* pFormField : FieldArray) {
2983 swSort.push_back(std::unique_ptr<CFX_WideString>(
2984 new CFX_WideString(pFormField->GetFullName())));
2985 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002986
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002987 std::sort(
2988 swSort.begin(), swSort.end(),
2989 [](const std::unique_ptr<CFX_WideString>& p1,
2990 const std::unique_ptr<CFX_WideString>& p2) { return *p1 < *p2; });
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002991
Tom Sepezd6ae2af2017-02-16 11:49:55 -08002992 CJS_EventContext* pContext = (CJS_EventContext*)cc;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002993 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
tsepeze5aff742016-08-08 09:49:42 -07002994 CJS_Array FormFieldArray;
Tom Sepezb9cc7a02016-02-01 13:42:30 -08002995
2996 int j = 0;
2997 for (const auto& pStr : swSort) {
tsepezb4694242016-08-15 16:44:55 -07002998 v8::Local<v8::Object> pObj =
2999 pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID);
Tom Sepezcd56a7d2015-10-06 11:45:28 -07003000 ASSERT(!pObj.IsEmpty());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003001
Tom Sepezd5a0e952015-09-17 15:40:06 -07003002 CJS_Field* pJSField =
tsepezb4694242016-08-15 16:44:55 -07003003 static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pObj));
Tom Sepezb9cc7a02016-02-01 13:42:30 -08003004 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003005 pField->AttachField(m_pJSDoc, *pStr);
tsepezb4694242016-08-15 16:44:55 -07003006 FormFieldArray.SetElement(pRuntime, j++, CJS_Value(pRuntime, pJSField));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003007 }
3008
tsepeze5aff742016-08-08 09:49:42 -07003009 vRet = CJS_Value(pRuntime, FormFieldArray);
tsepez4cf55152016-11-02 14:37:54 -07003010 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003011}
3012
Tom Sepezd6ae2af2017-02-16 11:49:55 -08003013bool Field::getItemAt(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07003014 const std::vector<CJS_Value>& params,
3015 CJS_Value& vRet,
3016 CFX_WideString& sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08003017 CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003018
tsepezf3dc8c62016-08-10 06:29:29 -07003019 int iSize = params.size();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003020 int nIdx = -1;
3021 if (iSize >= 1)
tsepezb4694242016-08-15 16:44:55 -07003022 nIdx = params[0].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003023
tsepez4cf55152016-11-02 14:37:54 -07003024 bool bExport = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003025 if (iSize >= 2)
tsepezb4694242016-08-15 16:44:55 -07003026 bExport = params[1].ToBool(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003027
Lei Zhangd88a3642015-11-10 09:38:57 -08003028 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3029 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07003030 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003031
Lei Zhangd88a3642015-11-10 09:38:57 -08003032 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003033 if ((pFormField->GetFieldType() == FIELDTYPE_LISTBOX) ||
3034 (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX)) {
3035 if (nIdx == -1 || nIdx > pFormField->CountOptions())
3036 nIdx = pFormField->CountOptions() - 1;
3037 if (bExport) {
3038 CFX_WideString strval = pFormField->GetOptionValue(nIdx);
3039 if (strval.IsEmpty())
tsepezf3dc8c62016-08-10 06:29:29 -07003040 vRet = CJS_Value(pRuntime, pFormField->GetOptionLabel(nIdx).c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003041 else
tsepezf3dc8c62016-08-10 06:29:29 -07003042 vRet = CJS_Value(pRuntime, strval.c_str());
Lei Zhangd88a3642015-11-10 09:38:57 -08003043 } else {
tsepezf3dc8c62016-08-10 06:29:29 -07003044 vRet = CJS_Value(pRuntime, pFormField->GetOptionLabel(nIdx).c_str());
Lei Zhangd88a3642015-11-10 09:38:57 -08003045 }
3046 } else {
tsepez4cf55152016-11-02 14:37:54 -07003047 return false;
Lei Zhangd88a3642015-11-10 09:38:57 -08003048 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003049
tsepez4cf55152016-11-02 14:37:54 -07003050 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003051}
3052
Tom Sepezd6ae2af2017-02-16 11:49:55 -08003053bool Field::getLock(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07003054 const std::vector<CJS_Value>& params,
3055 CJS_Value& vRet,
3056 CFX_WideString& sError) {
3057 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003058}
3059
Tom Sepezd6ae2af2017-02-16 11:49:55 -08003060bool Field::insertItemAt(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07003061 const std::vector<CJS_Value>& params,
3062 CJS_Value& vRet,
3063 CFX_WideString& sError) {
3064 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003065}
3066
Tom Sepezd6ae2af2017-02-16 11:49:55 -08003067bool Field::isBoxChecked(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07003068 const std::vector<CJS_Value>& params,
3069 CJS_Value& vRet,
3070 CFX_WideString& sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08003071 CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
tsepezf3dc8c62016-08-10 06:29:29 -07003072
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003073 int nIndex = -1;
3074 if (params.size() >= 1)
tsepezb4694242016-08-15 16:44:55 -07003075 nIndex = params[0].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003076
Lei Zhangd88a3642015-11-10 09:38:57 -08003077 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3078 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07003079 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003080
Lei Zhangd88a3642015-11-10 09:38:57 -08003081 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003082 if (nIndex < 0 || nIndex >= pFormField->CountControls()) {
tsepez4cf55152016-11-02 14:37:54 -07003083 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003084 }
3085
tsepezf3dc8c62016-08-10 06:29:29 -07003086 vRet = CJS_Value(pRuntime,
3087 ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
3088 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) &&
3089 pFormField->GetControl(nIndex)->IsChecked() != 0));
tsepez4cf55152016-11-02 14:37:54 -07003090 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003091}
3092
Tom Sepezd6ae2af2017-02-16 11:49:55 -08003093bool Field::isDefaultChecked(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07003094 const std::vector<CJS_Value>& params,
3095 CJS_Value& vRet,
3096 CFX_WideString& sError) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -08003097 CJS_Runtime* pRuntime = CJS_Runtime::FromEventContext(cc);
tsepezf3dc8c62016-08-10 06:29:29 -07003098
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003099 int nIndex = -1;
3100 if (params.size() >= 1)
tsepezb4694242016-08-15 16:44:55 -07003101 nIndex = params[0].ToInt(pRuntime);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003102
Lei Zhangd88a3642015-11-10 09:38:57 -08003103 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3104 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07003105 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003106
Lei Zhangd88a3642015-11-10 09:38:57 -08003107 CPDF_FormField* pFormField = FieldArray[0];
tsepezf3dc8c62016-08-10 06:29:29 -07003108 if (nIndex < 0 || nIndex >= pFormField->CountControls())
tsepez4cf55152016-11-02 14:37:54 -07003109 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003110
tsepezf3dc8c62016-08-10 06:29:29 -07003111 vRet = CJS_Value(pRuntime,
3112 ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
3113 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) &&
3114 pFormField->GetControl(nIndex)->IsDefaultChecked() != 0));
tsepez4cf55152016-11-02 14:37:54 -07003115 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003116}
3117
Tom Sepezd6ae2af2017-02-16 11:49:55 -08003118bool Field::setAction(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07003119 const std::vector<CJS_Value>& params,
3120 CJS_Value& vRet,
3121 CFX_WideString& sError) {
3122 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003123}
3124
Tom Sepezd6ae2af2017-02-16 11:49:55 -08003125bool Field::setFocus(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07003126 const std::vector<CJS_Value>& params,
3127 CJS_Value& vRet,
3128 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08003129 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3130 if (FieldArray.empty())
tsepez4cf55152016-11-02 14:37:54 -07003131 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003132
Lei Zhangd88a3642015-11-10 09:38:57 -08003133 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003134 int32_t nCount = pFormField->CountControls();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003135 if (nCount < 1)
tsepez4cf55152016-11-02 14:37:54 -07003136 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003137
dsinclair7cbe68e2016-10-12 11:56:23 -07003138 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
thestig1cd352e2016-06-07 17:53:06 -07003139 CPDFSDK_Widget* pWidget = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003140 if (nCount == 1) {
dsinclairc5267c52016-11-04 15:35:12 -07003141 pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003142 } else {
dsinclair3a7741a2016-10-11 10:39:49 -07003143 UnderlyingPageType* pPage =
3144 UnderlyingFromFPDFPage(m_pFormFillEnv->GetCurrentPage(
3145 m_pFormFillEnv->GetUnderlyingDocument()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003146 if (!pPage)
tsepez4cf55152016-11-02 14:37:54 -07003147 return false;
dsinclair461eeaf2016-07-27 07:40:05 -07003148 if (CPDFSDK_PageView* pCurPageView =
dsinclair7cbe68e2016-10-12 11:56:23 -07003149 m_pFormFillEnv->GetPageView(pPage, true)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003150 for (int32_t i = 0; i < nCount; i++) {
3151 if (CPDFSDK_Widget* pTempWidget =
dsinclairc5267c52016-11-04 15:35:12 -07003152 pInterForm->GetWidget(pFormField->GetControl(i))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003153 if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage()) {
3154 pWidget = pTempWidget;
3155 break;
3156 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003157 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003158 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003159 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003160 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003161
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003162 if (pWidget) {
tsepezf8074ce2016-09-27 14:29:57 -07003163 CPDFSDK_Annot::ObservedPtr pObserved(pWidget);
dsinclair7cbe68e2016-10-12 11:56:23 -07003164 m_pFormFillEnv->SetFocusAnnot(&pObserved);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003165 }
3166
tsepez4cf55152016-11-02 14:37:54 -07003167 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003168}
3169
Tom Sepezd6ae2af2017-02-16 11:49:55 -08003170bool Field::setItems(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07003171 const std::vector<CJS_Value>& params,
3172 CJS_Value& vRet,
3173 CFX_WideString& sError) {
3174 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003175}
3176
Tom Sepezd6ae2af2017-02-16 11:49:55 -08003177bool Field::setLock(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07003178 const std::vector<CJS_Value>& params,
3179 CJS_Value& vRet,
3180 CFX_WideString& sError) {
3181 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003182}
3183
Tom Sepezd6ae2af2017-02-16 11:49:55 -08003184bool Field::signatureGetModifications(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07003185 const std::vector<CJS_Value>& params,
3186 CJS_Value& vRet,
3187 CFX_WideString& sError) {
3188 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003189}
3190
Tom Sepezd6ae2af2017-02-16 11:49:55 -08003191bool Field::signatureGetSeedValue(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07003192 const std::vector<CJS_Value>& params,
3193 CJS_Value& vRet,
3194 CFX_WideString& sError) {
3195 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003196}
3197
Tom Sepezd6ae2af2017-02-16 11:49:55 -08003198bool Field::signatureInfo(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07003199 const std::vector<CJS_Value>& params,
3200 CJS_Value& vRet,
3201 CFX_WideString& sError) {
3202 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003203}
3204
Tom Sepezd6ae2af2017-02-16 11:49:55 -08003205bool Field::signatureSetSeedValue(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07003206 const std::vector<CJS_Value>& params,
3207 CJS_Value& vRet,
3208 CFX_WideString& sError) {
3209 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003210}
3211
Tom Sepezd6ae2af2017-02-16 11:49:55 -08003212bool Field::signatureSign(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07003213 const std::vector<CJS_Value>& params,
3214 CJS_Value& vRet,
3215 CFX_WideString& sError) {
3216 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003217}
3218
Tom Sepezd6ae2af2017-02-16 11:49:55 -08003219bool Field::signatureValidate(IJS_EventContext* cc,
tsepez4cf55152016-11-02 14:37:54 -07003220 const std::vector<CJS_Value>& params,
3221 CJS_Value& vRet,
3222 CFX_WideString& sError) {
3223 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003224}
3225
Tom Sepezd6ae2af2017-02-16 11:49:55 -08003226bool Field::source(IJS_EventContext* cc,
3227 CJS_PropValue& vp,
3228 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003229 if (vp.IsGetting()) {
thestig1cd352e2016-06-07 17:53:06 -07003230 vp << (CJS_Object*)nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003231 }
3232
tsepez4cf55152016-11-02 14:37:54 -07003233 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003234}
3235
tsepez41a53ad2016-03-28 16:59:30 -07003236void Field::AddDelay_Int(FIELD_PROP prop, int32_t n) {
3237 CJS_DelayData* pNewData =
3238 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003239 pNewData->num = n;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003240 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003241}
3242
tsepez41a53ad2016-03-28 16:59:30 -07003243void Field::AddDelay_Bool(FIELD_PROP prop, bool b) {
3244 CJS_DelayData* pNewData =
3245 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003246 pNewData->b = b;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003247 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003248}
3249
tsepez41a53ad2016-03-28 16:59:30 -07003250void Field::AddDelay_String(FIELD_PROP prop, const CFX_ByteString& string) {
3251 CJS_DelayData* pNewData =
3252 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003253 pNewData->string = string;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003254 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003255}
3256
tsepez41a53ad2016-03-28 16:59:30 -07003257void Field::AddDelay_WideString(FIELD_PROP prop, const CFX_WideString& string) {
3258 CJS_DelayData* pNewData =
3259 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003260 pNewData->widestring = string;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003261 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003262}
3263
tsepez41a53ad2016-03-28 16:59:30 -07003264void Field::AddDelay_Rect(FIELD_PROP prop, const CFX_FloatRect& rect) {
3265 CJS_DelayData* pNewData =
3266 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003267 pNewData->rect = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003268 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003269}
3270
tsepez41a53ad2016-03-28 16:59:30 -07003271void Field::AddDelay_Color(FIELD_PROP prop, const CPWL_Color& color) {
3272 CJS_DelayData* pNewData =
3273 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003274 pNewData->color = color;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003275 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003276}
3277
tsepez41a53ad2016-03-28 16:59:30 -07003278void Field::AddDelay_WordArray(FIELD_PROP prop,
3279 const std::vector<uint32_t>& array) {
3280 CJS_DelayData* pNewData =
3281 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
3282 pNewData->wordarray = array;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003283 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003284}
3285
tsepez41a53ad2016-03-28 16:59:30 -07003286void Field::AddDelay_WideStringArray(FIELD_PROP prop,
3287 const std::vector<CFX_WideString>& array) {
3288 CJS_DelayData* pNewData =
3289 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
3290 pNewData->widestringarray = array;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003291 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003292}
3293
dsinclair3a7741a2016-10-11 10:39:49 -07003294void Field::DoDelay(CPDFSDK_FormFillEnvironment* pFormFillEnv,
3295 CJS_DelayData* pData) {
3296 ASSERT(pFormFillEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003297 switch (pData->eProp) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003298 case FP_ALIGNMENT:
dsinclair3a7741a2016-10-11 10:39:49 -07003299 Field::SetAlignment(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003300 pData->string);
3301 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003302 case FP_BORDERSTYLE:
dsinclair3a7741a2016-10-11 10:39:49 -07003303 Field::SetBorderStyle(pFormFillEnv, pData->sFieldName,
3304 pData->nControlIndex, pData->string);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003305 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003306 case FP_BUTTONALIGNX:
dsinclair3a7741a2016-10-11 10:39:49 -07003307 Field::SetButtonAlignX(pFormFillEnv, pData->sFieldName,
3308 pData->nControlIndex, pData->num);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003309 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003310 case FP_BUTTONALIGNY:
dsinclair3a7741a2016-10-11 10:39:49 -07003311 Field::SetButtonAlignY(pFormFillEnv, pData->sFieldName,
3312 pData->nControlIndex, pData->num);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003313 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003314 case FP_BUTTONFITBOUNDS:
dsinclair3a7741a2016-10-11 10:39:49 -07003315 Field::SetButtonFitBounds(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003316 pData->nControlIndex, pData->b);
3317 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003318 case FP_BUTTONPOSITION:
dsinclair3a7741a2016-10-11 10:39:49 -07003319 Field::SetButtonPosition(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003320 pData->nControlIndex, pData->num);
3321 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003322 case FP_BUTTONSCALEHOW:
dsinclair3a7741a2016-10-11 10:39:49 -07003323 Field::SetButtonScaleHow(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003324 pData->nControlIndex, pData->num);
3325 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003326 case FP_BUTTONSCALEWHEN:
dsinclair3a7741a2016-10-11 10:39:49 -07003327 Field::SetButtonScaleWhen(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003328 pData->nControlIndex, pData->num);
3329 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003330 case FP_CALCORDERINDEX:
dsinclair3a7741a2016-10-11 10:39:49 -07003331 Field::SetCalcOrderIndex(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003332 pData->nControlIndex, pData->num);
3333 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003334 case FP_CHARLIMIT:
dsinclair3a7741a2016-10-11 10:39:49 -07003335 Field::SetCharLimit(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003336 pData->num);
3337 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003338 case FP_COMB:
dsinclair3a7741a2016-10-11 10:39:49 -07003339 Field::SetComb(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003340 pData->b);
3341 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003342 case FP_COMMITONSELCHANGE:
dsinclair3a7741a2016-10-11 10:39:49 -07003343 Field::SetCommitOnSelChange(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003344 pData->nControlIndex, pData->b);
3345 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003346 case FP_CURRENTVALUEINDICES:
dsinclair3a7741a2016-10-11 10:39:49 -07003347 Field::SetCurrentValueIndices(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003348 pData->nControlIndex, pData->wordarray);
3349 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003350 case FP_DEFAULTVALUE:
dsinclair3a7741a2016-10-11 10:39:49 -07003351 Field::SetDefaultValue(pFormFillEnv, pData->sFieldName,
3352 pData->nControlIndex, pData->widestring);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003353 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003354 case FP_DONOTSCROLL:
dsinclair3a7741a2016-10-11 10:39:49 -07003355 Field::SetDoNotScroll(pFormFillEnv, pData->sFieldName,
3356 pData->nControlIndex, pData->b);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003357 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003358 case FP_DISPLAY:
dsinclair3a7741a2016-10-11 10:39:49 -07003359 Field::SetDisplay(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003360 pData->num);
3361 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003362 case FP_FILLCOLOR:
dsinclair3a7741a2016-10-11 10:39:49 -07003363 Field::SetFillColor(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003364 pData->color);
3365 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003366 case FP_HIDDEN:
dsinclair3a7741a2016-10-11 10:39:49 -07003367 Field::SetHidden(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003368 pData->b);
3369 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003370 case FP_HIGHLIGHT:
dsinclair3a7741a2016-10-11 10:39:49 -07003371 Field::SetHighlight(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003372 pData->string);
3373 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003374 case FP_LINEWIDTH:
dsinclair3a7741a2016-10-11 10:39:49 -07003375 Field::SetLineWidth(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003376 pData->num);
3377 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003378 case FP_MULTILINE:
dsinclair3a7741a2016-10-11 10:39:49 -07003379 Field::SetMultiline(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003380 pData->b);
3381 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003382 case FP_MULTIPLESELECTION:
dsinclair3a7741a2016-10-11 10:39:49 -07003383 Field::SetMultipleSelection(pFormFillEnv, pData->sFieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003384 pData->nControlIndex, pData->b);
3385 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003386 case FP_PASSWORD:
dsinclair3a7741a2016-10-11 10:39:49 -07003387 Field::SetPassword(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003388 pData->b);
3389 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003390 case FP_RECT:
dsinclair3a7741a2016-10-11 10:39:49 -07003391 Field::SetRect(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003392 pData->rect);
3393 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003394 case FP_RICHTEXT:
dsinclaira2919b32016-07-13 10:55:48 -07003395 // Not supported.
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003396 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003397 case FP_RICHVALUE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003398 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003399 case FP_ROTATION:
dsinclair3a7741a2016-10-11 10:39:49 -07003400 Field::SetRotation(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003401 pData->num);
3402 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003403 case FP_STROKECOLOR:
dsinclair3a7741a2016-10-11 10:39:49 -07003404 Field::SetStrokeColor(pFormFillEnv, pData->sFieldName,
3405 pData->nControlIndex, pData->color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003406 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003407 case FP_STYLE:
dsinclair3a7741a2016-10-11 10:39:49 -07003408 Field::SetStyle(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003409 pData->string);
3410 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003411 case FP_TEXTCOLOR:
dsinclair3a7741a2016-10-11 10:39:49 -07003412 Field::SetTextColor(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003413 pData->color);
3414 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003415 case FP_TEXTFONT:
dsinclair3a7741a2016-10-11 10:39:49 -07003416 Field::SetTextFont(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003417 pData->string);
3418 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003419 case FP_TEXTSIZE:
dsinclair3a7741a2016-10-11 10:39:49 -07003420 Field::SetTextSize(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003421 pData->num);
3422 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003423 case FP_USERNAME:
dsinclair3a7741a2016-10-11 10:39:49 -07003424 Field::SetUserName(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003425 pData->widestring);
3426 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003427 case FP_VALUE:
dsinclair3a7741a2016-10-11 10:39:49 -07003428 Field::SetValue(pFormFillEnv, pData->sFieldName, pData->nControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003429 pData->widestringarray);
3430 break;
3431 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003432}
3433
dsinclair3a7741a2016-10-11 10:39:49 -07003434void Field::AddField(CPDFSDK_FormFillEnvironment* pFormFillEnv,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003435 int nPageIndex,
3436 int nFieldType,
3437 const CFX_WideString& sName,
Tom Sepez281a9ea2016-02-26 14:24:28 -08003438 const CFX_FloatRect& rcCoords) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003439 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003440}