blob: 0e65b16619b0e806829074cb2439b74af3e58ee7 [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
dsinclair166bc162016-09-29 11:58:38 -070014#include "core/fpdfapi/fpdf_font/cpdf_font.h"
dsinclair8a752ab2016-09-29 11:59:54 -070015#include "core/fpdfapi/fpdf_page/cpdf_page.h"
dsinclairc6c425a2016-09-29 12:01:30 -070016#include "core/fpdfapi/fpdf_parser/cpdf_document.h"
dsinclair1727aee2016-09-29 13:12:56 -070017#include "core/fpdfdoc/cpdf_interform.h"
dsinclairf34518b2016-09-13 12:03:48 -070018#include "fpdfsdk/include/cpdfsdk_document.h"
dsinclair79db6092016-09-14 07:27:21 -070019#include "fpdfsdk/include/cpdfsdk_environment.h"
jaepark611adb82016-08-17 11:34:36 -070020#include "fpdfsdk/include/cpdfsdk_interform.h"
dsinclairf34518b2016-09-13 12:03:48 -070021#include "fpdfsdk/include/cpdfsdk_pageview.h"
jaepark611adb82016-08-17 11:34:36 -070022#include "fpdfsdk/include/cpdfsdk_widget.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040023#include "fpdfsdk/javascript/Document.h"
24#include "fpdfsdk/javascript/Icon.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040025#include "fpdfsdk/javascript/JS_Define.h"
26#include "fpdfsdk/javascript/JS_EventHandler.h"
27#include "fpdfsdk/javascript/JS_Object.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040028#include "fpdfsdk/javascript/JS_Value.h"
29#include "fpdfsdk/javascript/PublicMethods.h"
dsinclair64376be2016-03-31 20:03:24 -070030#include "fpdfsdk/javascript/cjs_context.h"
31#include "fpdfsdk/javascript/cjs_runtime.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040032#include "fpdfsdk/javascript/color.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070033
tonikitoo7c05a7a2016-08-17 11:08:46 -070034namespace {
35
36bool SetWidgetDisplayStatus(CPDFSDK_Widget* pWidget, int value) {
37 if (!pWidget)
38 return false;
39
40 uint32_t dwFlag = pWidget->GetFlags();
41 switch (value) {
42 case 0:
43 dwFlag &= ~ANNOTFLAG_INVISIBLE;
44 dwFlag &= ~ANNOTFLAG_HIDDEN;
45 dwFlag &= ~ANNOTFLAG_NOVIEW;
46 dwFlag |= ANNOTFLAG_PRINT;
47 break;
48 case 1:
49 dwFlag &= ~ANNOTFLAG_INVISIBLE;
50 dwFlag &= ~ANNOTFLAG_NOVIEW;
51 dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
52 break;
53 case 2:
54 dwFlag &= ~ANNOTFLAG_INVISIBLE;
55 dwFlag &= ~ANNOTFLAG_PRINT;
56 dwFlag &= ~ANNOTFLAG_HIDDEN;
57 dwFlag &= ~ANNOTFLAG_NOVIEW;
58 break;
59 case 3:
60 dwFlag |= ANNOTFLAG_NOVIEW;
61 dwFlag |= ANNOTFLAG_PRINT;
62 dwFlag &= ~ANNOTFLAG_HIDDEN;
63 break;
64 }
65
66 if (dwFlag != pWidget->GetFlags()) {
67 pWidget->SetFlags(dwFlag);
68 return true;
69 }
70
71 return false;
72}
73
74} // namespace
75
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070076BEGIN_JS_STATIC_CONST(CJS_Field)
77END_JS_STATIC_CONST()
78
79BEGIN_JS_STATIC_PROP(CJS_Field)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070080JS_STATIC_PROP_ENTRY(alignment)
81JS_STATIC_PROP_ENTRY(borderStyle)
82JS_STATIC_PROP_ENTRY(buttonAlignX)
83JS_STATIC_PROP_ENTRY(buttonAlignY)
84JS_STATIC_PROP_ENTRY(buttonFitBounds)
85JS_STATIC_PROP_ENTRY(buttonPosition)
86JS_STATIC_PROP_ENTRY(buttonScaleHow)
87JS_STATIC_PROP_ENTRY(buttonScaleWhen)
88JS_STATIC_PROP_ENTRY(calcOrderIndex)
89JS_STATIC_PROP_ENTRY(charLimit)
90JS_STATIC_PROP_ENTRY(comb)
91JS_STATIC_PROP_ENTRY(commitOnSelChange)
92JS_STATIC_PROP_ENTRY(currentValueIndices)
93JS_STATIC_PROP_ENTRY(defaultStyle)
94JS_STATIC_PROP_ENTRY(defaultValue)
95JS_STATIC_PROP_ENTRY(doNotScroll)
96JS_STATIC_PROP_ENTRY(doNotSpellCheck)
97JS_STATIC_PROP_ENTRY(delay)
98JS_STATIC_PROP_ENTRY(display)
99JS_STATIC_PROP_ENTRY(doc)
100JS_STATIC_PROP_ENTRY(editable)
101JS_STATIC_PROP_ENTRY(exportValues)
102JS_STATIC_PROP_ENTRY(hidden)
103JS_STATIC_PROP_ENTRY(fileSelect)
104JS_STATIC_PROP_ENTRY(fillColor)
105JS_STATIC_PROP_ENTRY(lineWidth)
106JS_STATIC_PROP_ENTRY(highlight)
107JS_STATIC_PROP_ENTRY(multiline)
108JS_STATIC_PROP_ENTRY(multipleSelection)
109JS_STATIC_PROP_ENTRY(name)
110JS_STATIC_PROP_ENTRY(numItems)
111JS_STATIC_PROP_ENTRY(page)
112JS_STATIC_PROP_ENTRY(password)
113JS_STATIC_PROP_ENTRY(print)
114JS_STATIC_PROP_ENTRY(radiosInUnison)
115JS_STATIC_PROP_ENTRY(readonly)
116JS_STATIC_PROP_ENTRY(rect)
117JS_STATIC_PROP_ENTRY(required)
118JS_STATIC_PROP_ENTRY(richText)
119JS_STATIC_PROP_ENTRY(richValue)
120JS_STATIC_PROP_ENTRY(rotation)
121JS_STATIC_PROP_ENTRY(strokeColor)
122JS_STATIC_PROP_ENTRY(style)
123JS_STATIC_PROP_ENTRY(submitName)
124JS_STATIC_PROP_ENTRY(textColor)
125JS_STATIC_PROP_ENTRY(textFont)
126JS_STATIC_PROP_ENTRY(textSize)
127JS_STATIC_PROP_ENTRY(type)
128JS_STATIC_PROP_ENTRY(userName)
129JS_STATIC_PROP_ENTRY(value)
130JS_STATIC_PROP_ENTRY(valueAsString)
131JS_STATIC_PROP_ENTRY(source)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700132END_JS_STATIC_PROP()
133
134BEGIN_JS_STATIC_METHOD(CJS_Field)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700135JS_STATIC_METHOD_ENTRY(browseForFileToSubmit)
136JS_STATIC_METHOD_ENTRY(buttonGetCaption)
137JS_STATIC_METHOD_ENTRY(buttonGetIcon)
138JS_STATIC_METHOD_ENTRY(buttonImportIcon)
139JS_STATIC_METHOD_ENTRY(buttonSetCaption)
140JS_STATIC_METHOD_ENTRY(buttonSetIcon)
141JS_STATIC_METHOD_ENTRY(checkThisBox)
142JS_STATIC_METHOD_ENTRY(clearItems)
143JS_STATIC_METHOD_ENTRY(defaultIsChecked)
144JS_STATIC_METHOD_ENTRY(deleteItemAt)
145JS_STATIC_METHOD_ENTRY(getArray)
146JS_STATIC_METHOD_ENTRY(getItemAt)
147JS_STATIC_METHOD_ENTRY(getLock)
148JS_STATIC_METHOD_ENTRY(insertItemAt)
149JS_STATIC_METHOD_ENTRY(isBoxChecked)
150JS_STATIC_METHOD_ENTRY(isDefaultChecked)
151JS_STATIC_METHOD_ENTRY(setAction)
152JS_STATIC_METHOD_ENTRY(setFocus)
153JS_STATIC_METHOD_ENTRY(setItems)
154JS_STATIC_METHOD_ENTRY(setLock)
155JS_STATIC_METHOD_ENTRY(signatureGetModifications)
156JS_STATIC_METHOD_ENTRY(signatureGetSeedValue)
157JS_STATIC_METHOD_ENTRY(signatureInfo)
158JS_STATIC_METHOD_ENTRY(signatureSetSeedValue)
159JS_STATIC_METHOD_ENTRY(signatureSign)
160JS_STATIC_METHOD_ENTRY(signatureValidate)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700161END_JS_STATIC_METHOD()
162
163IMPLEMENT_JS_CLASS(CJS_Field, Field)
164
weili625ad662016-06-15 11:21:33 -0700165CJS_DelayData::CJS_DelayData(FIELD_PROP prop,
166 int idx,
167 const CFX_WideString& name)
168 : eProp(prop), nControlIndex(idx), sFieldName(name) {}
169
170CJS_DelayData::~CJS_DelayData() {}
171
Tom Sepez33420902015-10-13 15:00:10 -0700172void CJS_Field::InitInstance(IJS_Runtime* pIRuntime) {
Lei Zhangd88a3642015-11-10 09:38:57 -0800173}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700174
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700175Field::Field(CJS_Object* pJSObject)
176 : CJS_EmbedObj(pJSObject),
thestig1cd352e2016-06-07 17:53:06 -0700177 m_pJSDoc(nullptr),
178 m_pDocument(nullptr),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700179 m_nFormControlIndex(-1),
180 m_bCanSet(FALSE),
tsepezb4694242016-08-15 16:44:55 -0700181 m_bDelay(FALSE) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700182
183Field::~Field() {}
184
185// note: iControlNo = -1, means not a widget.
186void Field::ParseFieldName(const std::wstring& strFieldNameParsed,
187 std::wstring& strFieldName,
188 int& iControlNo) {
189 int iStart = strFieldNameParsed.find_last_of(L'.');
190 if (iStart == -1) {
191 strFieldName = strFieldNameParsed;
192 iControlNo = -1;
193 return;
194 }
195 std::wstring suffixal = strFieldNameParsed.substr(iStart + 1);
196 iControlNo = FXSYS_wtoi(suffixal.c_str());
197 if (iControlNo == 0) {
weilidb444d22016-06-02 15:48:15 -0700198 int iSpaceStart;
199 while ((iSpaceStart = suffixal.find_last_of(L" ")) != -1) {
200 suffixal.erase(iSpaceStart, 1);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700201 }
202
203 if (suffixal.compare(L"0") != 0) {
204 strFieldName = strFieldNameParsed;
205 iControlNo = -1;
206 return;
207 }
208 }
209 strFieldName = strFieldNameParsed.substr(0, iStart);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700210}
211
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700212FX_BOOL Field::AttachField(Document* pDocument,
213 const CFX_WideString& csFieldName) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700214 m_pJSDoc = pDocument;
tsepez56cf5192016-09-12 11:59:30 -0700215 m_pDocument.Reset(pDocument->GetReaderDoc());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700216 m_bCanSet = m_pDocument->GetPermissions(FPDFPERM_FILL_FORM) ||
217 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
218 m_pDocument->GetPermissions(FPDFPERM_MODIFY);
219
220 CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700221 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700222 CFX_WideString swFieldNameTemp = csFieldName;
223 swFieldNameTemp.Replace(L"..", L".");
224
225 if (pInterForm->CountFields(swFieldNameTemp) <= 0) {
226 std::wstring strFieldName;
227 int iControlNo = -1;
228 ParseFieldName(swFieldNameTemp.c_str(), strFieldName, iControlNo);
229 if (iControlNo == -1)
230 return FALSE;
231
232 m_FieldName = strFieldName.c_str();
233 m_nFormControlIndex = iControlNo;
234 return TRUE;
235 }
236
237 m_FieldName = swFieldNameTemp;
238 m_nFormControlIndex = -1;
239
240 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700241}
242
Lei Zhangd88a3642015-11-10 09:38:57 -0800243std::vector<CPDF_FormField*> Field::GetFormFields(
244 CPDFSDK_Document* pDocument,
245 const CFX_WideString& csFieldName) {
246 std::vector<CPDF_FormField*> fields;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700247 CPDFSDK_InterForm* pReaderInterForm = pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700248 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -0800249 for (int i = 0, sz = pInterForm->CountFields(csFieldName); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700250 if (CPDF_FormField* pFormField = pInterForm->GetField(i, csFieldName))
Lei Zhangd88a3642015-11-10 09:38:57 -0800251 fields.push_back(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700252 }
Lei Zhangd88a3642015-11-10 09:38:57 -0800253 return fields;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700254}
255
Lei Zhangd88a3642015-11-10 09:38:57 -0800256std::vector<CPDF_FormField*> Field::GetFormFields(
257 const CFX_WideString& csFieldName) const {
tsepez56cf5192016-09-12 11:59:30 -0700258 return Field::GetFormFields(m_pDocument.Get(), csFieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700259}
260
261void Field::UpdateFormField(CPDFSDK_Document* pDocument,
262 CPDF_FormField* pFormField,
263 FX_BOOL bChangeMark,
264 FX_BOOL bResetAP,
265 FX_BOOL bRefresh) {
tsepez23ae4a52016-06-08 20:44:54 -0700266 CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700267
268 if (bResetAP) {
dsinclair1df1efa2016-09-07 09:55:37 -0700269 std::vector<CPDFSDK_Widget*> widgets;
270 pInterForm->GetWidgets(pFormField, &widgets);
271
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700272 int nFieldType = pFormField->GetFieldType();
273 if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_TEXTFIELD) {
dsinclairce04a452016-09-07 05:46:55 -0700274 for (CPDFSDK_Annot* pAnnot : widgets) {
Lei Zhangd88a3642015-11-10 09:38:57 -0800275 FX_BOOL bFormatted = FALSE;
tsepez1c620542016-09-12 09:47:52 -0700276 CPDFSDK_Annot::ObservedPtr pObserved(pAnnot);
tsepez7b68f612016-09-07 14:11:27 -0700277 CFX_WideString sValue =
tsepez1c620542016-09-12 09:47:52 -0700278 static_cast<CPDFSDK_Widget*>(pObserved.Get())->OnFormat(bFormatted);
279 if (pObserved) {
280 static_cast<CPDFSDK_Widget*>(pObserved.Get())
281 ->ResetAppearance(bFormatted ? &sValue : nullptr, FALSE);
tsepezca97a8e2016-08-01 10:10:36 -0700282 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700283 }
284 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800285 for (CPDFSDK_Widget* pWidget : widgets) {
286 pWidget->ResetAppearance(nullptr, FALSE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700287 }
288 }
289 }
290
291 if (bRefresh) {
dsinclair1df1efa2016-09-07 09:55:37 -0700292 // Refresh the widget list. The calls in |bResetAP| may have caused widgets
293 // to be removed from the list. We need to call |GetWidgets| again to be
294 // sure none of the widgets have been deleted.
295 std::vector<CPDFSDK_Widget*> widgets;
296 pInterForm->GetWidgets(pFormField, &widgets);
297
Lei Zhangd88a3642015-11-10 09:38:57 -0800298 for (CPDFSDK_Widget* pWidget : widgets) {
299 CPDFSDK_Document* pDoc = pWidget->GetInterForm()->GetDocument();
300 pDoc->UpdateAllViews(nullptr, pWidget);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700301 }
302 }
303
304 if (bChangeMark)
305 pDocument->SetChangeMark();
306}
307
308void Field::UpdateFormControl(CPDFSDK_Document* pDocument,
309 CPDF_FormControl* pFormControl,
310 FX_BOOL bChangeMark,
311 FX_BOOL bResetAP,
312 FX_BOOL bRefresh) {
Lei Zhang96660d62015-12-14 18:27:25 -0800313 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700314
tsepez23ae4a52016-06-08 20:44:54 -0700315 CPDFSDK_InterForm* pForm = pDocument->GetInterForm();
dsinclairef523dd2016-08-15 13:10:03 -0700316 CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700317
318 if (pWidget) {
319 if (bResetAP) {
320 int nFieldType = pWidget->GetFieldType();
321 if (nFieldType == FIELDTYPE_COMBOBOX ||
322 nFieldType == FIELDTYPE_TEXTFIELD) {
tsepez8c2a8cd2016-09-07 15:29:11 -0700323 FX_BOOL bFormatted = FALSE;
324 CFX_WideString sValue = pWidget->OnFormat(bFormatted);
tsepeza31da742016-09-08 11:28:14 -0700325 pWidget->ResetAppearance(bFormatted ? &sValue : nullptr, FALSE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700326 } else {
thestig1cd352e2016-06-07 17:53:06 -0700327 pWidget->ResetAppearance(nullptr, FALSE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700328 }
329 }
330
331 if (bRefresh) {
332 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
333 CPDFSDK_Document* pDoc = pInterForm->GetDocument();
thestig1cd352e2016-06-07 17:53:06 -0700334 pDoc->UpdateAllViews(nullptr, pWidget);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700335 }
336 }
337
338 if (bChangeMark)
339 pDocument->SetChangeMark();
340}
341
342CPDFSDK_Widget* Field::GetWidget(CPDFSDK_Document* pDocument,
dsinclairef523dd2016-08-15 13:10:03 -0700343 CPDF_FormControl* pFormControl,
344 bool createIfNeeded) {
Jun Fang14b20db2015-12-01 12:35:24 +0800345 CPDFSDK_InterForm* pInterForm =
346 static_cast<CPDFSDK_InterForm*>(pDocument->GetInterForm());
dsinclairef523dd2016-08-15 13:10:03 -0700347 return pInterForm ? pInterForm->GetWidget(pFormControl, createIfNeeded)
348 : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700349}
350
351FX_BOOL Field::ValueIsOccur(CPDF_FormField* pFormField,
352 CFX_WideString csOptLabel) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700353 for (int i = 0, sz = pFormField->CountOptions(); i < sz; i++) {
354 if (csOptLabel.Compare(pFormField->GetOptionLabel(i)) == 0)
355 return TRUE;
356 }
357
358 return FALSE;
359}
360
361CPDF_FormControl* Field::GetSmartFieldControl(CPDF_FormField* pFormField) {
362 if (!pFormField->CountControls() ||
363 m_nFormControlIndex >= pFormField->CountControls())
thestig1cd352e2016-06-07 17:53:06 -0700364 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700365
366 if (m_nFormControlIndex < 0)
367 return pFormField->GetControl(0);
368
369 return pFormField->GetControl(m_nFormControlIndex);
370}
371
Tom Sepezba038bc2015-10-08 12:03:00 -0700372FX_BOOL Field::alignment(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700373 CJS_PropValue& vp,
374 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800375 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700376
377 if (vp.IsSetting()) {
378 if (!m_bCanSet)
379 return FALSE;
380
381 CFX_ByteString alignStr;
382 vp >> alignStr;
383
384 if (m_bDelay) {
385 AddDelay_String(FP_ALIGNMENT, alignStr);
386 } else {
tsepez56cf5192016-09-12 11:59:30 -0700387 Field::SetAlignment(m_pDocument.Get(), m_FieldName, m_nFormControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700388 alignStr);
389 }
390 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800391 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
392 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700393 return FALSE;
394
Lei Zhangd88a3642015-11-10 09:38:57 -0800395 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700396 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
397 return FALSE;
398
399 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
400 if (!pFormControl)
401 return FALSE;
402
403 switch (pFormControl->GetControlAlignment()) {
404 case 1:
405 vp << L"center";
406 break;
407 case 0:
408 vp << L"left";
409 break;
410 case 2:
411 vp << L"right";
412 break;
413 default:
414 vp << L"";
415 }
416 }
417
418 return TRUE;
419}
420
421void Field::SetAlignment(CPDFSDK_Document* pDocument,
422 const CFX_WideString& swFieldName,
423 int nControlIndex,
424 const CFX_ByteString& string) {
425 // Not supported.
426}
427
Tom Sepezba038bc2015-10-08 12:03:00 -0700428FX_BOOL Field::borderStyle(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700429 CJS_PropValue& vp,
430 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800431 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700432
433 if (vp.IsSetting()) {
434 if (!m_bCanSet)
435 return FALSE;
436
437 CFX_ByteString strType = "";
438 vp >> strType;
439
440 if (m_bDelay) {
441 AddDelay_String(FP_BORDERSTYLE, strType);
442 } else {
tsepez56cf5192016-09-12 11:59:30 -0700443 Field::SetBorderStyle(m_pDocument.Get(), m_FieldName, m_nFormControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700444 strType);
445 }
446 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800447 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
448 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700449 return FALSE;
450
Lei Zhangd88a3642015-11-10 09:38:57 -0800451 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700452 if (!pFormField)
453 return FALSE;
454
455 CPDFSDK_Widget* pWidget =
tsepez56cf5192016-09-12 11:59:30 -0700456 GetWidget(m_pDocument.Get(), GetSmartFieldControl(pFormField), false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700457 if (!pWidget)
458 return FALSE;
459
dsinclair92cb5e52016-05-16 11:38:28 -0700460 switch (pWidget->GetBorderStyle()) {
461 case BorderStyle::SOLID:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700462 vp << L"solid";
463 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700464 case BorderStyle::DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700465 vp << L"dashed";
466 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700467 case BorderStyle::BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700468 vp << L"beveled";
469 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700470 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700471 vp << L"inset";
472 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700473 case BorderStyle::UNDERLINE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700474 vp << L"underline";
475 break;
476 default:
477 vp << L"";
478 break;
479 }
480 }
481
482 return TRUE;
483}
484
485void Field::SetBorderStyle(CPDFSDK_Document* pDocument,
486 const CFX_WideString& swFieldName,
487 int nControlIndex,
488 const CFX_ByteString& string) {
Lei Zhang96660d62015-12-14 18:27:25 -0800489 ASSERT(pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700490
dsinclair92cb5e52016-05-16 11:38:28 -0700491 BorderStyle nBorderStyle = BorderStyle::SOLID;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700492 if (string == "solid")
dsinclair92cb5e52016-05-16 11:38:28 -0700493 nBorderStyle = BorderStyle::SOLID;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700494 else if (string == "beveled")
dsinclair92cb5e52016-05-16 11:38:28 -0700495 nBorderStyle = BorderStyle::BEVELED;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700496 else if (string == "dashed")
dsinclair92cb5e52016-05-16 11:38:28 -0700497 nBorderStyle = BorderStyle::DASH;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700498 else if (string == "inset")
dsinclair92cb5e52016-05-16 11:38:28 -0700499 nBorderStyle = BorderStyle::INSET;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700500 else if (string == "underline")
dsinclair92cb5e52016-05-16 11:38:28 -0700501 nBorderStyle = BorderStyle::UNDERLINE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700502 else
503 return;
504
Lei Zhangd88a3642015-11-10 09:38:57 -0800505 std::vector<CPDF_FormField*> FieldArray =
506 GetFormFields(pDocument, swFieldName);
507 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700508 if (nControlIndex < 0) {
509 FX_BOOL bSet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -0800510 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700511 if (CPDFSDK_Widget* pWidget =
dsinclairef523dd2016-08-15 13:10:03 -0700512 GetWidget(pDocument, pFormField->GetControl(i), false)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700513 if (pWidget->GetBorderStyle() != nBorderStyle) {
514 pWidget->SetBorderStyle(nBorderStyle);
515 bSet = TRUE;
516 }
517 }
518 }
519 if (bSet)
520 UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
521 } else {
522 if (nControlIndex >= pFormField->CountControls())
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700523 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700524 if (CPDF_FormControl* pFormControl =
525 pFormField->GetControl(nControlIndex)) {
dsinclairef523dd2016-08-15 13:10:03 -0700526 if (CPDFSDK_Widget* pWidget =
527 GetWidget(pDocument, pFormControl, false)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700528 if (pWidget->GetBorderStyle() != nBorderStyle) {
529 pWidget->SetBorderStyle(nBorderStyle);
530 UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
531 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700532 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700533 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700534 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700535 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700536}
537
Tom Sepezba038bc2015-10-08 12:03:00 -0700538FX_BOOL Field::buttonAlignX(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700539 CJS_PropValue& vp,
540 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800541 ASSERT(m_pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700542
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700543 if (vp.IsSetting()) {
544 if (!m_bCanSet)
545 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700546
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700547 int nVP;
548 vp >> nVP;
549
550 if (m_bDelay) {
551 AddDelay_Int(FP_BUTTONALIGNX, nVP);
552 } else {
tsepez56cf5192016-09-12 11:59:30 -0700553 Field::SetButtonAlignX(m_pDocument.Get(), m_FieldName,
554 m_nFormControlIndex, nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700555 }
556 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800557 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
558 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700559 return FALSE;
560
Lei Zhangd88a3642015-11-10 09:38:57 -0800561 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700562 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
563 return FALSE;
564
565 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
566 if (!pFormControl)
567 return FALSE;
568
569 CPDF_IconFit IconFit = pFormControl->GetIconFit();
570
571 FX_FLOAT fLeft, fBottom;
572 IconFit.GetIconPosition(fLeft, fBottom);
573
574 vp << (int32_t)fLeft;
575 }
576
577 return TRUE;
578}
579
580void Field::SetButtonAlignX(CPDFSDK_Document* pDocument,
581 const CFX_WideString& swFieldName,
582 int nControlIndex,
583 int number) {
584 // Not supported.
585}
586
Tom Sepezba038bc2015-10-08 12:03:00 -0700587FX_BOOL Field::buttonAlignY(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700588 CJS_PropValue& vp,
589 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800590 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700591
592 if (vp.IsSetting()) {
593 if (!m_bCanSet)
594 return FALSE;
595
596 int nVP;
597 vp >> nVP;
598
599 if (m_bDelay) {
600 AddDelay_Int(FP_BUTTONALIGNY, nVP);
601 } else {
tsepez56cf5192016-09-12 11:59:30 -0700602 Field::SetButtonAlignY(m_pDocument.Get(), m_FieldName,
603 m_nFormControlIndex, nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700604 }
605 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800606 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
607 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700608 return FALSE;
609
Lei Zhangd88a3642015-11-10 09:38:57 -0800610 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700611 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
612 return FALSE;
613
614 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
615 if (!pFormControl)
616 return FALSE;
617
618 CPDF_IconFit IconFit = pFormControl->GetIconFit();
619
620 FX_FLOAT fLeft, fBottom;
621 IconFit.GetIconPosition(fLeft, fBottom);
622
623 vp << (int32_t)fBottom;
624 }
625
626 return TRUE;
627}
628
629void Field::SetButtonAlignY(CPDFSDK_Document* pDocument,
630 const CFX_WideString& swFieldName,
631 int nControlIndex,
632 int number) {
633 // Not supported.
634}
635
Tom Sepezba038bc2015-10-08 12:03:00 -0700636FX_BOOL Field::buttonFitBounds(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700637 CJS_PropValue& vp,
638 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800639 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700640
641 if (vp.IsSetting()) {
642 if (!m_bCanSet)
643 return FALSE;
644
645 bool bVP;
646 vp >> bVP;
647
648 if (m_bDelay) {
649 AddDelay_Bool(FP_BUTTONFITBOUNDS, bVP);
650 } else {
tsepez56cf5192016-09-12 11:59:30 -0700651 Field::SetButtonFitBounds(m_pDocument.Get(), m_FieldName,
652 m_nFormControlIndex, bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700653 }
654 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800655 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
656 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700657 return FALSE;
658
Lei Zhangd88a3642015-11-10 09:38:57 -0800659 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700660 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
661 return FALSE;
662
663 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
664 if (!pFormControl)
665 return FALSE;
666
thestigded36342016-05-23 17:54:02 -0700667 vp << pFormControl->GetIconFit().GetFittingBounds();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700668 }
669
670 return TRUE;
671}
672
673void Field::SetButtonFitBounds(CPDFSDK_Document* pDocument,
674 const CFX_WideString& swFieldName,
675 int nControlIndex,
676 bool b) {
677 // Not supported.
678}
679
Tom Sepezba038bc2015-10-08 12:03:00 -0700680FX_BOOL Field::buttonPosition(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700681 CJS_PropValue& vp,
682 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800683 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700684
685 if (vp.IsSetting()) {
686 if (!m_bCanSet)
687 return FALSE;
688
689 int nVP;
690 vp >> nVP;
691
692 if (m_bDelay) {
693 AddDelay_Int(FP_BUTTONPOSITION, nVP);
694 } else {
tsepez56cf5192016-09-12 11:59:30 -0700695 Field::SetButtonPosition(m_pDocument.Get(), m_FieldName,
696 m_nFormControlIndex, nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700697 }
698 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800699 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
700 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700701 return FALSE;
702
Lei Zhangd88a3642015-11-10 09:38:57 -0800703 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700704 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
705 return FALSE;
706
707 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
708 if (!pFormControl)
709 return FALSE;
710
711 vp << pFormControl->GetTextPosition();
712 }
713 return TRUE;
714}
715
716void Field::SetButtonPosition(CPDFSDK_Document* pDocument,
717 const CFX_WideString& swFieldName,
718 int nControlIndex,
719 int number) {
720 // Not supported.
721}
722
Tom Sepezba038bc2015-10-08 12:03:00 -0700723FX_BOOL Field::buttonScaleHow(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700724 CJS_PropValue& vp,
725 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800726 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700727
728 if (vp.IsSetting()) {
729 if (!m_bCanSet)
730 return FALSE;
731
732 int nVP;
733 vp >> nVP;
734
735 if (m_bDelay) {
736 AddDelay_Int(FP_BUTTONSCALEHOW, nVP);
737 } else {
tsepez56cf5192016-09-12 11:59:30 -0700738 Field::SetButtonScaleHow(m_pDocument.Get(), m_FieldName,
739 m_nFormControlIndex, nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700740 }
741 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800742 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
743 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700744 return FALSE;
745
Lei Zhangd88a3642015-11-10 09:38:57 -0800746 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700747 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
748 return FALSE;
749
750 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
751 if (!pFormControl)
752 return FALSE;
753
754 CPDF_IconFit IconFit = pFormControl->GetIconFit();
755 if (IconFit.IsProportionalScale())
756 vp << (int32_t)0;
757 else
758 vp << (int32_t)1;
759 }
760
761 return TRUE;
762}
763
764void Field::SetButtonScaleHow(CPDFSDK_Document* pDocument,
765 const CFX_WideString& swFieldName,
766 int nControlIndex,
767 int number) {
768 // Not supported.
769}
770
Tom Sepezba038bc2015-10-08 12:03:00 -0700771FX_BOOL Field::buttonScaleWhen(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700772 CJS_PropValue& vp,
773 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800774 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700775
776 if (vp.IsSetting()) {
777 if (!m_bCanSet)
778 return FALSE;
779
780 int nVP;
781 vp >> nVP;
782
783 if (m_bDelay) {
784 AddDelay_Int(FP_BUTTONSCALEWHEN, nVP);
785 } else {
tsepez56cf5192016-09-12 11:59:30 -0700786 Field::SetButtonScaleWhen(m_pDocument.Get(), m_FieldName,
787 m_nFormControlIndex, nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700788 }
789 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800790 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
791 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700792 return FALSE;
793
Lei Zhangd88a3642015-11-10 09:38:57 -0800794 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700795 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
796 return FALSE;
797
798 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
799 if (!pFormControl)
800 return FALSE;
801
802 CPDF_IconFit IconFit = pFormControl->GetIconFit();
803 int ScaleM = IconFit.GetScaleMethod();
804 switch (ScaleM) {
805 case CPDF_IconFit::Always:
806 vp << (int32_t)CPDF_IconFit::Always;
807 break;
808 case CPDF_IconFit::Bigger:
809 vp << (int32_t)CPDF_IconFit::Bigger;
810 break;
811 case CPDF_IconFit::Never:
812 vp << (int32_t)CPDF_IconFit::Never;
813 break;
814 case CPDF_IconFit::Smaller:
815 vp << (int32_t)CPDF_IconFit::Smaller;
816 break;
817 }
818 }
819
820 return TRUE;
821}
822
823void Field::SetButtonScaleWhen(CPDFSDK_Document* pDocument,
824 const CFX_WideString& swFieldName,
825 int nControlIndex,
826 int number) {
827 // Not supported.
828}
829
Tom Sepezba038bc2015-10-08 12:03:00 -0700830FX_BOOL Field::calcOrderIndex(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700831 CJS_PropValue& vp,
832 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800833 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700834
835 if (vp.IsSetting()) {
836 if (!m_bCanSet)
837 return FALSE;
838
839 int nVP;
840 vp >> nVP;
841
842 if (m_bDelay) {
843 AddDelay_Int(FP_CALCORDERINDEX, nVP);
844 } else {
tsepez56cf5192016-09-12 11:59:30 -0700845 Field::SetCalcOrderIndex(m_pDocument.Get(), m_FieldName,
846 m_nFormControlIndex, nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700847 }
848 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800849 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
850 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700851 return FALSE;
852
Lei Zhangd88a3642015-11-10 09:38:57 -0800853 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700854 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -0800855 pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700856 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -0800857 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700858
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700859 CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700860 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700861 vp << (int32_t)pInterForm->FindFieldInCalculationOrder(pFormField);
862 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700863
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700864 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700865}
866
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700867void Field::SetCalcOrderIndex(CPDFSDK_Document* pDocument,
868 const CFX_WideString& swFieldName,
869 int nControlIndex,
870 int number) {
871 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700872}
873
Tom Sepezba038bc2015-10-08 12:03:00 -0700874FX_BOOL Field::charLimit(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700875 CJS_PropValue& vp,
876 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800877 ASSERT(m_pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700878
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700879 if (vp.IsSetting()) {
880 if (!m_bCanSet)
881 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700882
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700883 int nVP;
884 vp >> nVP;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700885
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700886 if (m_bDelay) {
887 AddDelay_Int(FP_CHARLIMIT, nVP);
888 } else {
tsepez56cf5192016-09-12 11:59:30 -0700889 Field::SetCharLimit(m_pDocument.Get(), m_FieldName, m_nFormControlIndex,
890 nVP);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700891 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700892 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800893 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
894 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700895 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700896
Lei Zhangd88a3642015-11-10 09:38:57 -0800897 CPDF_FormField* pFormField = FieldArray[0];
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700898 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700899 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700900
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700901 vp << (int32_t)pFormField->GetMaxLen();
902 }
903 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700904}
905
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700906void Field::SetCharLimit(CPDFSDK_Document* pDocument,
907 const CFX_WideString& swFieldName,
908 int nControlIndex,
909 int number) {
910 // Not supported.
911}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700912
Tom Sepezba038bc2015-10-08 12:03:00 -0700913FX_BOOL Field::comb(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700914 CJS_PropValue& vp,
915 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800916 ASSERT(m_pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700917
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700918 if (vp.IsSetting()) {
919 if (!m_bCanSet)
920 return FALSE;
921
922 bool bVP;
923 vp >> bVP;
924
925 if (m_bDelay) {
926 AddDelay_Bool(FP_COMB, bVP);
927 } else {
tsepez56cf5192016-09-12 11:59:30 -0700928 Field::SetComb(m_pDocument.Get(), m_FieldName, m_nFormControlIndex, bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700929 }
930 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800931 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
932 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700933 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700934
Lei Zhangd88a3642015-11-10 09:38:57 -0800935 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700936 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
937 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700938
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700939 if (pFormField->GetFieldFlags() & FIELDFLAG_COMB)
940 vp << true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700941 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700942 vp << false;
943 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700944
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700945 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700946}
947
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700948void Field::SetComb(CPDFSDK_Document* pDocument,
949 const CFX_WideString& swFieldName,
950 int nControlIndex,
951 bool b) {
952 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700953}
954
Tom Sepezba038bc2015-10-08 12:03:00 -0700955FX_BOOL Field::commitOnSelChange(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700956 CJS_PropValue& vp,
957 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800958 ASSERT(m_pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700959
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700960 if (vp.IsSetting()) {
961 if (!m_bCanSet)
962 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700963
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700964 bool bVP;
965 vp >> bVP;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700966
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700967 if (m_bDelay) {
968 AddDelay_Bool(FP_COMMITONSELCHANGE, bVP);
969 } else {
tsepez56cf5192016-09-12 11:59:30 -0700970 Field::SetCommitOnSelChange(m_pDocument.Get(), m_FieldName,
971 m_nFormControlIndex, bVP);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700972 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700973 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800974 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
975 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700976 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700977
Lei Zhangd88a3642015-11-10 09:38:57 -0800978 CPDF_FormField* pFormField = FieldArray[0];
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700979 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -0800980 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700981 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -0800982 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700983
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700984 if (pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE)
985 vp << true;
986 else
987 vp << false;
988 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700989
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700990 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700991}
992
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700993void Field::SetCommitOnSelChange(CPDFSDK_Document* pDocument,
994 const CFX_WideString& swFieldName,
995 int nControlIndex,
996 bool b) {
997 // Not supported.
998}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700999
Tom Sepezba038bc2015-10-08 12:03:00 -07001000FX_BOOL Field::currentValueIndices(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001001 CJS_PropValue& vp,
1002 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07001003 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001004
1005 if (vp.IsSetting()) {
1006 if (!m_bCanSet)
1007 return FALSE;
1008
tsepez41a53ad2016-03-28 16:59:30 -07001009 std::vector<uint32_t> array;
tsepezf3dc8c62016-08-10 06:29:29 -07001010 if (vp.GetJSValue()->GetType() == CJS_Value::VT_number) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001011 int iSelecting = 0;
1012 vp >> iSelecting;
tsepez41a53ad2016-03-28 16:59:30 -07001013 array.push_back(iSelecting);
tsepezf3dc8c62016-08-10 06:29:29 -07001014 } else if (vp.GetJSValue()->IsArrayObject()) {
tsepeze5aff742016-08-08 09:49:42 -07001015 CJS_Array SelArray;
Tom Sepez67fd5df2015-10-08 12:24:19 -07001016 CJS_Value SelValue(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001017 int iSelecting;
1018 vp >> SelArray;
tsepezb4694242016-08-15 16:44:55 -07001019 for (int i = 0, sz = SelArray.GetLength(pRuntime); i < sz; i++) {
1020 SelArray.GetElement(pRuntime, i, SelValue);
1021 iSelecting = SelValue.ToInt(pRuntime);
tsepez41a53ad2016-03-28 16:59:30 -07001022 array.push_back(iSelecting);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001023 }
1024 }
1025
1026 if (m_bDelay) {
1027 AddDelay_WordArray(FP_CURRENTVALUEINDICES, array);
1028 } else {
tsepez56cf5192016-09-12 11:59:30 -07001029 Field::SetCurrentValueIndices(m_pDocument.Get(), m_FieldName,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001030 m_nFormControlIndex, array);
1031 }
1032 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001033 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1034 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001035 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001036
Lei Zhangd88a3642015-11-10 09:38:57 -08001037 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001038 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001039 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001040 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001041 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001042
Lei Zhangd88a3642015-11-10 09:38:57 -08001043 if (pFormField->CountSelectedItems() == 1) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001044 vp << pFormField->GetSelectedIndex(0);
Lei Zhangd88a3642015-11-10 09:38:57 -08001045 } else if (pFormField->CountSelectedItems() > 1) {
tsepeze5aff742016-08-08 09:49:42 -07001046 CJS_Array SelArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001047 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
1048 SelArray.SetElement(
tsepezb4694242016-08-15 16:44:55 -07001049 pRuntime, i, CJS_Value(pRuntime, pFormField->GetSelectedIndex(i)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001050 }
1051 vp << SelArray;
Lei Zhangd88a3642015-11-10 09:38:57 -08001052 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001053 vp << -1;
Lei Zhangd88a3642015-11-10 09:38:57 -08001054 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001055 }
1056
1057 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001058}
1059
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001060void Field::SetCurrentValueIndices(CPDFSDK_Document* pDocument,
1061 const CFX_WideString& swFieldName,
1062 int nControlIndex,
tsepez41a53ad2016-03-28 16:59:30 -07001063 const std::vector<uint32_t>& array) {
Lei Zhang96660d62015-12-14 18:27:25 -08001064 ASSERT(pDocument);
Lei Zhangd88a3642015-11-10 09:38:57 -08001065 std::vector<CPDF_FormField*> FieldArray =
1066 GetFormFields(pDocument, swFieldName);
tsepez41a53ad2016-03-28 16:59:30 -07001067
Lei Zhangd88a3642015-11-10 09:38:57 -08001068 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001069 int nFieldType = pFormField->GetFieldType();
1070 if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX) {
tsepezc3255f52016-03-25 14:52:27 -07001071 uint32_t dwFieldFlags = pFormField->GetFieldFlags();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001072 pFormField->ClearSelection(TRUE);
tsepez41a53ad2016-03-28 16:59:30 -07001073 for (size_t i = 0; i < array.size(); ++i) {
1074 if (i != 0 && !(dwFieldFlags & (1 << 21)))
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001075 break;
Wei Li05d53f02016-03-29 16:42:53 -07001076 if (array[i] < static_cast<uint32_t>(pFormField->CountOptions()) &&
tsepez41a53ad2016-03-28 16:59:30 -07001077 !pFormField->IsItemSelected(array[i])) {
1078 pFormField->SetItemSelection(array[i], TRUE);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001079 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001080 }
1081 UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001082 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001083 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001084}
1085
Tom Sepezba038bc2015-10-08 12:03:00 -07001086FX_BOOL Field::defaultStyle(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001087 CJS_PropValue& vp,
1088 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001089 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001090}
1091
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001092void Field::SetDefaultStyle(CPDFSDK_Document* pDocument,
1093 const CFX_WideString& swFieldName,
1094 int nControlIndex) {
1095 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001096}
1097
Tom Sepezba038bc2015-10-08 12:03:00 -07001098FX_BOOL Field::defaultValue(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001099 CJS_PropValue& vp,
1100 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08001101 ASSERT(m_pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001102
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001103 if (vp.IsSetting()) {
1104 if (!m_bCanSet)
1105 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001106
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001107 CFX_WideString WideStr;
1108 vp >> WideStr;
1109
1110 if (m_bDelay) {
1111 AddDelay_WideString(FP_DEFAULTVALUE, WideStr);
1112 } else {
tsepez56cf5192016-09-12 11:59:30 -07001113 Field::SetDefaultValue(m_pDocument.Get(), m_FieldName,
1114 m_nFormControlIndex, WideStr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001115 }
1116 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001117 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1118 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001119 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001120
Lei Zhangd88a3642015-11-10 09:38:57 -08001121 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001122 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON ||
Lei Zhangd88a3642015-11-10 09:38:57 -08001123 pFormField->GetFieldType() == FIELDTYPE_SIGNATURE) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001124 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001125 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001126
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001127 vp << pFormField->GetDefaultValue();
1128 }
1129 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001130}
1131
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001132void Field::SetDefaultValue(CPDFSDK_Document* pDocument,
1133 const CFX_WideString& swFieldName,
1134 int nControlIndex,
1135 const CFX_WideString& string) {
1136 // Not supported.
1137}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001138
Tom Sepezba038bc2015-10-08 12:03:00 -07001139FX_BOOL Field::doNotScroll(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001140 CJS_PropValue& vp,
1141 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08001142 ASSERT(m_pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001143
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001144 if (vp.IsSetting()) {
1145 if (!m_bCanSet)
1146 return FALSE;
1147
1148 bool bVP;
1149 vp >> bVP;
1150
1151 if (m_bDelay) {
1152 AddDelay_Bool(FP_DONOTSCROLL, bVP);
1153 } else {
tsepez56cf5192016-09-12 11:59:30 -07001154 Field::SetDoNotScroll(m_pDocument.Get(), m_FieldName, m_nFormControlIndex,
1155 bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001156 }
1157 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001158 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1159 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001160 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001161
Lei Zhangd88a3642015-11-10 09:38:57 -08001162 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001163 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1164 return FALSE;
1165
1166 if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL)
1167 vp << true;
1168 else
1169 vp << false;
1170 }
1171
1172 return TRUE;
1173}
1174
1175void Field::SetDoNotScroll(CPDFSDK_Document* pDocument,
1176 const CFX_WideString& swFieldName,
1177 int nControlIndex,
1178 bool b) {
1179 // Not supported.
1180}
1181
Tom Sepezba038bc2015-10-08 12:03:00 -07001182FX_BOOL Field::doNotSpellCheck(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001183 CJS_PropValue& vp,
1184 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08001185 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001186
1187 if (vp.IsSetting()) {
1188 if (!m_bCanSet)
1189 return FALSE;
1190
1191 bool bVP;
1192 vp >> bVP;
1193 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001194 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1195 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001196 return FALSE;
1197
Lei Zhangd88a3642015-11-10 09:38:57 -08001198 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001199 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001200 pFormField->GetFieldType() != FIELDTYPE_COMBOBOX) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001201 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001202 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001203
1204 if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK)
1205 vp << true;
1206 else
1207 vp << false;
1208 }
1209
1210 return TRUE;
1211}
1212
1213void Field::SetDelay(FX_BOOL bDelay) {
1214 m_bDelay = bDelay;
1215
1216 if (!m_bDelay) {
1217 if (m_pJSDoc)
1218 m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex);
1219 }
1220}
1221
Tom Sepezba038bc2015-10-08 12:03:00 -07001222FX_BOOL Field::delay(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001223 CJS_PropValue& vp,
1224 CFX_WideString& sError) {
1225 if (vp.IsSetting()) {
1226 if (!m_bCanSet)
1227 return FALSE;
1228
1229 bool bVP;
1230 vp >> bVP;
1231
1232 SetDelay(bVP);
1233 } else {
1234 vp << m_bDelay;
1235 }
1236 return TRUE;
1237}
1238
Tom Sepezba038bc2015-10-08 12:03:00 -07001239FX_BOOL Field::display(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001240 CJS_PropValue& vp,
1241 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001242 if (vp.IsSetting()) {
1243 if (!m_bCanSet)
1244 return FALSE;
1245
1246 int nVP;
1247 vp >> nVP;
1248
1249 if (m_bDelay) {
1250 AddDelay_Int(FP_DISPLAY, nVP);
1251 } else {
tsepez56cf5192016-09-12 11:59:30 -07001252 Field::SetDisplay(m_pDocument.Get(), m_FieldName, m_nFormControlIndex,
1253 nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001254 }
1255 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001256 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1257 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001258 return FALSE;
1259
Lei Zhangd88a3642015-11-10 09:38:57 -08001260 CPDF_FormField* pFormField = FieldArray[0];
1261 ASSERT(pFormField);
tsepez23ae4a52016-06-08 20:44:54 -07001262 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001263 CPDFSDK_Widget* pWidget =
dsinclairef523dd2016-08-15 13:10:03 -07001264 pInterForm->GetWidget(GetSmartFieldControl(pFormField), true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001265 if (!pWidget)
1266 return FALSE;
1267
tsepezc3255f52016-03-25 14:52:27 -07001268 uint32_t dwFlag = pWidget->GetFlags();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001269
1270 if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag) {
1271 vp << (int32_t)1;
1272 } else {
1273 if (ANNOTFLAG_PRINT & dwFlag) {
1274 if (ANNOTFLAG_NOVIEW & dwFlag) {
1275 vp << (int32_t)3;
1276 } else {
1277 vp << (int32_t)0;
1278 }
1279 } else {
1280 vp << (int32_t)2;
1281 }
1282 }
1283 }
1284
1285 return TRUE;
1286}
1287
1288void Field::SetDisplay(CPDFSDK_Document* pDocument,
1289 const CFX_WideString& swFieldName,
1290 int nControlIndex,
1291 int number) {
tsepez23ae4a52016-06-08 20:44:54 -07001292 CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001293 std::vector<CPDF_FormField*> FieldArray =
1294 GetFormFields(pDocument, swFieldName);
1295 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001296 if (nControlIndex < 0) {
tonikitoo7c05a7a2016-08-17 11:08:46 -07001297 bool bAnySet = false;
Lei Zhangd88a3642015-11-10 09:38:57 -08001298 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1299 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08001300 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001301
tonikitoo7c05a7a2016-08-17 11:08:46 -07001302 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl, true);
1303 if (SetWidgetDisplayStatus(pWidget, number))
1304 bAnySet = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001305 }
1306
tonikitoo7c05a7a2016-08-17 11:08:46 -07001307 if (bAnySet)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001308 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
1309 } else {
1310 if (nControlIndex >= pFormField->CountControls())
1311 return;
tonikitoo7c05a7a2016-08-17 11:08:46 -07001312
1313 CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex);
1314 if (!pFormControl)
1315 return;
1316
1317 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl, true);
1318 if (SetWidgetDisplayStatus(pWidget, number))
1319 UpdateFormControl(pDocument, pFormControl, TRUE, FALSE, TRUE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001320 }
1321 }
1322}
1323
Tom Sepezba038bc2015-10-08 12:03:00 -07001324FX_BOOL Field::doc(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001325 if (!vp.IsGetting()) {
1326 return FALSE;
1327 }
1328 vp << m_pJSDoc->GetCJSDoc();
1329 return TRUE;
1330}
1331
Tom Sepezba038bc2015-10-08 12:03:00 -07001332FX_BOOL Field::editable(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001333 CJS_PropValue& vp,
1334 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001335 if (vp.IsSetting()) {
1336 if (!m_bCanSet)
1337 return FALSE;
1338
1339 bool bVP;
1340 vp >> bVP;
1341 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001342 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1343 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001344 return FALSE;
1345
Lei Zhangd88a3642015-11-10 09:38:57 -08001346 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001347 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX)
1348 return FALSE;
1349
1350 if (pFormField->GetFieldFlags() & FIELDFLAG_EDIT)
1351 vp << true;
1352 else
1353 vp << false;
1354 }
1355
1356 return TRUE;
1357}
1358
Tom Sepezba038bc2015-10-08 12:03:00 -07001359FX_BOOL Field::exportValues(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -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())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001364 return FALSE;
1365
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) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001369 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001370 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001371
1372 if (vp.IsSetting()) {
1373 if (!m_bCanSet)
1374 return FALSE;
1375
tsepezf3dc8c62016-08-10 06:29:29 -07001376 if (!vp.GetJSValue()->IsArrayObject())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001377 return FALSE;
1378 } else {
Tom Sepez67fd5df2015-10-08 12:24:19 -07001379 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
tsepeze5aff742016-08-08 09:49:42 -07001380 CJS_Array ExportValusArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001381 if (m_nFormControlIndex < 0) {
1382 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
1383 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
1384 ExportValusArray.SetElement(
tsepezb4694242016-08-15 16:44:55 -07001385 pRuntime, i,
tsepeze5aff742016-08-08 09:49:42 -07001386 CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001387 }
1388 } else {
1389 if (m_nFormControlIndex >= pFormField->CountControls())
1390 return FALSE;
1391
1392 CPDF_FormControl* pFormControl =
1393 pFormField->GetControl(m_nFormControlIndex);
1394 if (!pFormControl)
1395 return FALSE;
1396
1397 ExportValusArray.SetElement(
tsepezb4694242016-08-15 16:44:55 -07001398 pRuntime, 0,
tsepeze5aff742016-08-08 09:49:42 -07001399 CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001400 }
1401 vp << ExportValusArray;
1402 }
1403 return TRUE;
1404}
1405
Tom Sepezba038bc2015-10-08 12:03:00 -07001406FX_BOOL Field::fileSelect(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001407 CJS_PropValue& vp,
1408 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001409 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1410 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001411 return FALSE;
1412
Lei Zhangd88a3642015-11-10 09:38:57 -08001413 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001414 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1415 return FALSE;
1416
1417 if (vp.IsSetting()) {
1418 if (!m_bCanSet)
1419 return FALSE;
1420
1421 bool bVP;
1422 vp >> bVP;
1423 } else {
1424 if (pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT)
1425 vp << true;
1426 else
1427 vp << false;
1428 }
1429 return TRUE;
1430}
1431
Tom Sepezba038bc2015-10-08 12:03:00 -07001432FX_BOOL Field::fillColor(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001433 CJS_PropValue& vp,
1434 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07001435 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
tsepeze5aff742016-08-08 09:49:42 -07001436 CJS_Array crArray;
Lei Zhangd88a3642015-11-10 09:38:57 -08001437 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1438 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001439 return FALSE;
1440
1441 if (vp.IsSetting()) {
1442 if (!m_bCanSet)
1443 return FALSE;
1444
tsepezf3dc8c62016-08-10 06:29:29 -07001445 if (!vp.GetJSValue()->IsArrayObject())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001446 return FALSE;
1447
1448 vp >> crArray;
1449
1450 CPWL_Color color;
tsepeze5aff742016-08-08 09:49:42 -07001451 color::ConvertArrayToPWLColor(pRuntime, crArray, &color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001452 if (m_bDelay) {
1453 AddDelay_Color(FP_FILLCOLOR, color);
1454 } else {
tsepez56cf5192016-09-12 11:59:30 -07001455 Field::SetFillColor(m_pDocument.Get(), m_FieldName, m_nFormControlIndex,
1456 color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001457 }
1458 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001459 CPDF_FormField* pFormField = FieldArray[0];
1460 ASSERT(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001461 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1462 if (!pFormControl)
1463 return FALSE;
1464
1465 int iColorType;
1466 pFormControl->GetBackgroundColor(iColorType);
1467
1468 CPWL_Color color;
1469 if (iColorType == COLORTYPE_TRANSPARENT) {
1470 color = CPWL_Color(COLORTYPE_TRANSPARENT);
1471 } else if (iColorType == COLORTYPE_GRAY) {
1472 color = CPWL_Color(COLORTYPE_GRAY,
1473 pFormControl->GetOriginalBackgroundColor(0));
1474 } else if (iColorType == COLORTYPE_RGB) {
1475 color =
1476 CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBackgroundColor(0),
1477 pFormControl->GetOriginalBackgroundColor(1),
1478 pFormControl->GetOriginalBackgroundColor(2));
1479 } else if (iColorType == COLORTYPE_CMYK) {
1480 color = CPWL_Color(COLORTYPE_CMYK,
1481 pFormControl->GetOriginalBackgroundColor(0),
1482 pFormControl->GetOriginalBackgroundColor(1),
1483 pFormControl->GetOriginalBackgroundColor(2),
1484 pFormControl->GetOriginalBackgroundColor(3));
Lei Zhangd88a3642015-11-10 09:38:57 -08001485 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001486 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001487 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001488
tsepeze5aff742016-08-08 09:49:42 -07001489 color::ConvertPWLColorToArray(pRuntime, color, &crArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001490 vp << crArray;
1491 }
1492
1493 return TRUE;
1494}
1495
1496void Field::SetFillColor(CPDFSDK_Document* pDocument,
1497 const CFX_WideString& swFieldName,
1498 int nControlIndex,
1499 const CPWL_Color& color) {
1500 // Not supported.
1501}
1502
Tom Sepezba038bc2015-10-08 12:03:00 -07001503FX_BOOL Field::hidden(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001504 CJS_PropValue& vp,
1505 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001506 if (vp.IsSetting()) {
1507 if (!m_bCanSet)
1508 return FALSE;
1509
1510 bool bVP;
1511 vp >> bVP;
1512
1513 if (m_bDelay) {
1514 AddDelay_Bool(FP_HIDDEN, bVP);
1515 } else {
tsepez56cf5192016-09-12 11:59:30 -07001516 Field::SetHidden(m_pDocument.Get(), m_FieldName, m_nFormControlIndex,
1517 bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001518 }
1519 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001520 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1521 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001522 return FALSE;
1523
Lei Zhangd88a3642015-11-10 09:38:57 -08001524 CPDF_FormField* pFormField = FieldArray[0];
1525 ASSERT(pFormField);
tsepez23ae4a52016-06-08 20:44:54 -07001526 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001527 CPDFSDK_Widget* pWidget =
dsinclairef523dd2016-08-15 13:10:03 -07001528 pInterForm->GetWidget(GetSmartFieldControl(pFormField), false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001529 if (!pWidget)
1530 return FALSE;
1531
tsepezc3255f52016-03-25 14:52:27 -07001532 uint32_t dwFlags = pWidget->GetFlags();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001533
Lei Zhangd88a3642015-11-10 09:38:57 -08001534 if (ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001535 vp << true;
Lei Zhangd88a3642015-11-10 09:38:57 -08001536 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001537 vp << false;
1538 }
1539
1540 return TRUE;
1541}
1542
1543void Field::SetHidden(CPDFSDK_Document* pDocument,
1544 const CFX_WideString& swFieldName,
1545 int nControlIndex,
1546 bool b) {
tonikitooa73b8fe2016-08-22 14:06:49 -07001547 int display = b ? 1 /*Hidden*/ : 0 /*Visible*/;
1548 SetDisplay(pDocument, swFieldName, nControlIndex, display);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001549}
1550
Tom Sepezba038bc2015-10-08 12:03:00 -07001551FX_BOOL Field::highlight(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001552 CJS_PropValue& vp,
1553 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08001554 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001555
1556 if (vp.IsSetting()) {
1557 if (!m_bCanSet)
1558 return FALSE;
1559
1560 CFX_ByteString strMode;
1561 vp >> strMode;
1562
1563 if (m_bDelay) {
1564 AddDelay_String(FP_HIGHLIGHT, strMode);
1565 } else {
tsepez56cf5192016-09-12 11:59:30 -07001566 Field::SetHighlight(m_pDocument.Get(), m_FieldName, m_nFormControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001567 strMode);
1568 }
1569 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001570 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1571 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001572 return FALSE;
1573
Lei Zhangd88a3642015-11-10 09:38:57 -08001574 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001575 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
1576 return FALSE;
1577
1578 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1579 if (!pFormControl)
1580 return FALSE;
1581
1582 int eHM = pFormControl->GetHighlightingMode();
1583 switch (eHM) {
1584 case CPDF_FormControl::None:
1585 vp << L"none";
1586 break;
1587 case CPDF_FormControl::Push:
1588 vp << L"push";
1589 break;
1590 case CPDF_FormControl::Invert:
1591 vp << L"invert";
1592 break;
1593 case CPDF_FormControl::Outline:
1594 vp << L"outline";
1595 break;
1596 case CPDF_FormControl::Toggle:
1597 vp << L"toggle";
1598 break;
1599 }
1600 }
1601
1602 return TRUE;
1603}
1604
1605void Field::SetHighlight(CPDFSDK_Document* pDocument,
1606 const CFX_WideString& swFieldName,
1607 int nControlIndex,
1608 const CFX_ByteString& string) {
1609 // Not supported.
1610}
1611
Tom Sepezba038bc2015-10-08 12:03:00 -07001612FX_BOOL Field::lineWidth(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001613 CJS_PropValue& vp,
1614 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001615 if (vp.IsSetting()) {
1616 if (!m_bCanSet)
1617 return FALSE;
1618
1619 int iWidth;
1620 vp >> iWidth;
1621
1622 if (m_bDelay) {
1623 AddDelay_Int(FP_LINEWIDTH, iWidth);
1624 } else {
tsepez56cf5192016-09-12 11:59:30 -07001625 Field::SetLineWidth(m_pDocument.Get(), m_FieldName, m_nFormControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001626 iWidth);
1627 }
1628 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001629 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1630 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001631 return FALSE;
1632
Lei Zhangd88a3642015-11-10 09:38:57 -08001633 CPDF_FormField* pFormField = FieldArray[0];
1634 ASSERT(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001635 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1636 if (!pFormControl)
1637 return FALSE;
1638
tsepez23ae4a52016-06-08 20:44:54 -07001639 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001640 if (!pFormField->CountControls())
1641 return FALSE;
1642
dsinclairef523dd2016-08-15 13:10:03 -07001643 CPDFSDK_Widget* pWidget =
1644 pInterForm->GetWidget(pFormField->GetControl(0), false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001645 if (!pWidget)
1646 return FALSE;
1647
1648 vp << (int32_t)pWidget->GetBorderWidth();
1649 }
1650
1651 return TRUE;
1652}
1653
1654void Field::SetLineWidth(CPDFSDK_Document* pDocument,
1655 const CFX_WideString& swFieldName,
1656 int nControlIndex,
1657 int number) {
tsepez23ae4a52016-06-08 20:44:54 -07001658 CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001659 std::vector<CPDF_FormField*> FieldArray =
1660 GetFormFields(pDocument, swFieldName);
1661 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001662 if (nControlIndex < 0) {
1663 FX_BOOL bSet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001664 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1665 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08001666 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001667
dsinclairef523dd2016-08-15 13:10:03 -07001668 if (CPDFSDK_Widget* pWidget =
1669 pInterForm->GetWidget(pFormControl, false)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001670 if (number != pWidget->GetBorderWidth()) {
1671 pWidget->SetBorderWidth(number);
1672 bSet = TRUE;
1673 }
1674 }
1675 }
1676 if (bSet)
1677 UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
1678 } else {
1679 if (nControlIndex >= pFormField->CountControls())
1680 return;
1681 if (CPDF_FormControl* pFormControl =
1682 pFormField->GetControl(nControlIndex)) {
dsinclairef523dd2016-08-15 13:10:03 -07001683 if (CPDFSDK_Widget* pWidget =
1684 pInterForm->GetWidget(pFormControl, false)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001685 if (number != pWidget->GetBorderWidth()) {
1686 pWidget->SetBorderWidth(number);
1687 UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
1688 }
1689 }
1690 }
1691 }
1692 }
1693}
1694
Tom Sepezba038bc2015-10-08 12:03:00 -07001695FX_BOOL Field::multiline(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001696 CJS_PropValue& vp,
1697 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08001698 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001699
1700 if (vp.IsSetting()) {
1701 if (!m_bCanSet)
1702 return FALSE;
1703
1704 bool bVP;
1705 vp >> bVP;
1706
1707 if (m_bDelay) {
1708 AddDelay_Bool(FP_MULTILINE, bVP);
1709 } else {
tsepez56cf5192016-09-12 11:59:30 -07001710 Field::SetMultiline(m_pDocument.Get(), m_FieldName, m_nFormControlIndex,
1711 bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001712 }
1713 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001714 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1715 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001716 return FALSE;
1717
Lei Zhangd88a3642015-11-10 09:38:57 -08001718 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001719 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1720 return FALSE;
1721
1722 if (pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE)
1723 vp << true;
1724 else
1725 vp << false;
1726 }
1727
1728 return TRUE;
1729}
1730
1731void Field::SetMultiline(CPDFSDK_Document* pDocument,
1732 const CFX_WideString& swFieldName,
1733 int nControlIndex,
1734 bool b) {
1735 // Not supported.
1736}
1737
Tom Sepezba038bc2015-10-08 12:03:00 -07001738FX_BOOL Field::multipleSelection(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001739 CJS_PropValue& vp,
1740 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08001741 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001742
1743 if (vp.IsSetting()) {
1744 if (!m_bCanSet)
1745 return FALSE;
1746
1747 bool bVP;
1748 vp >> bVP;
1749
1750 if (m_bDelay) {
1751 AddDelay_Bool(FP_MULTIPLESELECTION, bVP);
1752 } else {
tsepez56cf5192016-09-12 11:59:30 -07001753 Field::SetMultipleSelection(m_pDocument.Get(), m_FieldName,
1754 m_nFormControlIndex, bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001755 }
1756 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001757 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1758 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001759 return FALSE;
1760
Lei Zhangd88a3642015-11-10 09:38:57 -08001761 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001762 if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
1763 return FALSE;
1764
1765 if (pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT)
1766 vp << true;
1767 else
1768 vp << false;
1769 }
1770
1771 return TRUE;
1772}
1773
1774void Field::SetMultipleSelection(CPDFSDK_Document* pDocument,
1775 const CFX_WideString& swFieldName,
1776 int nControlIndex,
1777 bool b) {
1778 // Not supported.
1779}
1780
Tom Sepezba038bc2015-10-08 12:03:00 -07001781FX_BOOL Field::name(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001782 CJS_PropValue& vp,
1783 CFX_WideString& sError) {
1784 if (!vp.IsGetting())
1785 return FALSE;
1786
Lei Zhangd88a3642015-11-10 09:38:57 -08001787 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1788 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001789 return FALSE;
1790
1791 vp << m_FieldName;
1792
1793 return TRUE;
1794}
1795
Tom Sepezba038bc2015-10-08 12:03:00 -07001796FX_BOOL Field::numItems(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001797 CJS_PropValue& vp,
1798 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07001799 if (!vp.IsGetting())
1800 return FALSE;
1801
Lei Zhangd88a3642015-11-10 09:38:57 -08001802 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1803 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001804 return FALSE;
1805
Lei Zhangd88a3642015-11-10 09:38:57 -08001806 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001807 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001808 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001809 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001810 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001811
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001812 vp << (int32_t)pFormField->CountOptions();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001813 return TRUE;
1814}
1815
Tom Sepezba038bc2015-10-08 12:03:00 -07001816FX_BOOL Field::page(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001817 CJS_PropValue& vp,
1818 CFX_WideString& sError) {
1819 if (!vp.IsGetting())
1820 return FALSE;
1821
Lei Zhangd88a3642015-11-10 09:38:57 -08001822 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1823 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001824 return FALSE;
1825
Lei Zhangd88a3642015-11-10 09:38:57 -08001826 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001827 if (!pFormField)
1828 return FALSE;
1829
Lei Zhangd88a3642015-11-10 09:38:57 -08001830 std::vector<CPDFSDK_Widget*> widgets;
1831 m_pDocument->GetInterForm()->GetWidgets(pFormField, &widgets);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001832
Lei Zhangd88a3642015-11-10 09:38:57 -08001833 if (widgets.empty()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001834 vp << (int32_t)-1;
Lei Zhangd88a3642015-11-10 09:38:57 -08001835 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001836 }
1837
Lei Zhangd88a3642015-11-10 09:38:57 -08001838 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
tsepeze5aff742016-08-08 09:49:42 -07001839 CJS_Array PageArray;
Lei Zhangd88a3642015-11-10 09:38:57 -08001840 for (size_t i = 0; i < widgets.size(); ++i) {
1841 CPDFSDK_PageView* pPageView = widgets[i]->GetPageView();
1842 if (!pPageView)
1843 return FALSE;
1844
1845 PageArray.SetElement(
tsepezb4694242016-08-15 16:44:55 -07001846 pRuntime, i, CJS_Value(pRuntime, (int32_t)pPageView->GetPageIndex()));
Lei Zhangd88a3642015-11-10 09:38:57 -08001847 }
1848
1849 vp << PageArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001850 return TRUE;
1851}
1852
Tom Sepezba038bc2015-10-08 12:03:00 -07001853FX_BOOL Field::password(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001854 CJS_PropValue& vp,
1855 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08001856 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001857
1858 if (vp.IsSetting()) {
1859 if (!m_bCanSet)
1860 return FALSE;
1861
1862 bool bVP;
1863 vp >> bVP;
1864
1865 if (m_bDelay) {
1866 AddDelay_Bool(FP_PASSWORD, bVP);
1867 } else {
tsepez56cf5192016-09-12 11:59:30 -07001868 Field::SetPassword(m_pDocument.Get(), m_FieldName, m_nFormControlIndex,
1869 bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001870 }
1871 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001872 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1873 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001874 return FALSE;
1875
Lei Zhangd88a3642015-11-10 09:38:57 -08001876 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001877 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1878 return FALSE;
1879
1880 if (pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD)
1881 vp << true;
1882 else
1883 vp << false;
1884 }
1885
1886 return TRUE;
1887}
1888
1889void Field::SetPassword(CPDFSDK_Document* pDocument,
1890 const CFX_WideString& swFieldName,
1891 int nControlIndex,
1892 bool b) {
1893 // Not supported.
1894}
1895
Tom Sepezba038bc2015-10-08 12:03:00 -07001896FX_BOOL Field::print(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001897 CJS_PropValue& vp,
1898 CFX_WideString& sError) {
tsepez23ae4a52016-06-08 20:44:54 -07001899 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001900 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1901 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001902 return FALSE;
1903
1904 if (vp.IsSetting()) {
1905 if (!m_bCanSet)
1906 return FALSE;
1907
1908 bool bVP;
1909 vp >> bVP;
1910
Lei Zhangd88a3642015-11-10 09:38:57 -08001911 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001912 if (m_nFormControlIndex < 0) {
1913 FX_BOOL bSet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001914 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001915 if (CPDFSDK_Widget* pWidget =
dsinclairef523dd2016-08-15 13:10:03 -07001916 pInterForm->GetWidget(pFormField->GetControl(i), false)) {
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);
1925 bSet = TRUE;
1926 }
1927 }
1928 }
1929
1930 if (bSet)
tsepez56cf5192016-09-12 11:59:30 -07001931 UpdateFormField(m_pDocument.Get(), pFormField, TRUE, FALSE, TRUE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001932 } else {
1933 if (m_nFormControlIndex >= pFormField->CountControls())
1934 return FALSE;
1935 if (CPDF_FormControl* pFormControl =
1936 pFormField->GetControl(m_nFormControlIndex)) {
dsinclairef523dd2016-08-15 13:10:03 -07001937 if (CPDFSDK_Widget* pWidget =
1938 pInterForm->GetWidget(pFormControl, true)) {
tsepezc3255f52016-03-25 14:52:27 -07001939 uint32_t dwFlags = pWidget->GetFlags();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001940 if (bVP)
1941 dwFlags |= ANNOTFLAG_PRINT;
1942 else
1943 dwFlags &= ~ANNOTFLAG_PRINT;
1944
1945 if (dwFlags != pWidget->GetFlags()) {
1946 pWidget->SetFlags(dwFlags);
tsepez56cf5192016-09-12 11:59:30 -07001947 UpdateFormControl(m_pDocument.Get(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001948 pFormField->GetControl(m_nFormControlIndex),
1949 TRUE, FALSE, TRUE);
1950 }
1951 }
1952 }
1953 }
1954 }
1955 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001956 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001957 CPDFSDK_Widget* pWidget =
dsinclairef523dd2016-08-15 13:10:03 -07001958 pInterForm->GetWidget(GetSmartFieldControl(pFormField), true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001959 if (!pWidget)
1960 return FALSE;
1961
1962 if (pWidget->GetFlags() & ANNOTFLAG_PRINT)
1963 vp << true;
1964 else
1965 vp << false;
1966 }
1967
1968 return TRUE;
1969}
1970
Tom Sepezba038bc2015-10-08 12:03:00 -07001971FX_BOOL Field::radiosInUnison(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001972 CJS_PropValue& vp,
1973 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001974 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1975 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001976 return FALSE;
1977
1978 if (vp.IsSetting()) {
1979 if (!m_bCanSet)
1980 return FALSE;
1981
1982 bool bVP;
1983 vp >> bVP;
1984
1985 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001986 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001987 if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
1988 return FALSE;
1989
1990 if (pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)
1991 vp << true;
1992 else
1993 vp << false;
1994 }
1995
1996 return TRUE;
1997}
1998
Tom Sepezba038bc2015-10-08 12:03:00 -07001999FX_BOOL Field::readonly(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002000 CJS_PropValue& vp,
2001 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002002 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2003 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002004 return FALSE;
2005
2006 if (vp.IsSetting()) {
2007 if (!m_bCanSet)
2008 return FALSE;
2009
2010 bool bVP;
2011 vp >> bVP;
2012
2013 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002014 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002015 if (pFormField->GetFieldFlags() & FIELDFLAG_READONLY)
2016 vp << true;
2017 else
2018 vp << false;
2019 }
2020
2021 return TRUE;
2022}
2023
Tom Sepezba038bc2015-10-08 12:03:00 -07002024FX_BOOL Field::rect(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002025 CJS_PropValue& vp,
2026 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002027 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
2028 CJS_Value Upper_Leftx(pRuntime);
2029 CJS_Value Upper_Lefty(pRuntime);
2030 CJS_Value Lower_Rightx(pRuntime);
2031 CJS_Value Lower_Righty(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002032
2033 if (vp.IsSetting()) {
2034 if (!m_bCanSet)
2035 return FALSE;
tsepezf3dc8c62016-08-10 06:29:29 -07002036 if (!vp.GetJSValue()->IsArrayObject())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002037 return FALSE;
2038
tsepeze5aff742016-08-08 09:49:42 -07002039 CJS_Array rcArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002040 vp >> rcArray;
tsepezb4694242016-08-15 16:44:55 -07002041 rcArray.GetElement(pRuntime, 0, Upper_Leftx);
2042 rcArray.GetElement(pRuntime, 1, Upper_Lefty);
2043 rcArray.GetElement(pRuntime, 2, Lower_Rightx);
2044 rcArray.GetElement(pRuntime, 3, Lower_Righty);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002045
2046 FX_FLOAT pArray[4] = {0.0f, 0.0f, 0.0f, 0.0f};
tsepezb4694242016-08-15 16:44:55 -07002047 pArray[0] = static_cast<FX_FLOAT>(Upper_Leftx.ToInt(pRuntime));
2048 pArray[1] = static_cast<FX_FLOAT>(Lower_Righty.ToInt(pRuntime));
2049 pArray[2] = static_cast<FX_FLOAT>(Lower_Rightx.ToInt(pRuntime));
2050 pArray[3] = static_cast<FX_FLOAT>(Upper_Lefty.ToInt(pRuntime));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002051
Tom Sepez281a9ea2016-02-26 14:24:28 -08002052 CFX_FloatRect crRect(pArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002053 if (m_bDelay) {
2054 AddDelay_Rect(FP_RECT, crRect);
2055 } else {
tsepez56cf5192016-09-12 11:59:30 -07002056 Field::SetRect(m_pDocument.Get(), m_FieldName, m_nFormControlIndex,
2057 crRect);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002058 }
2059 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002060 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2061 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002062 return FALSE;
2063
Lei Zhangd88a3642015-11-10 09:38:57 -08002064 CPDF_FormField* pFormField = FieldArray[0];
tsepez23ae4a52016-06-08 20:44:54 -07002065 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002066 CPDFSDK_Widget* pWidget =
dsinclairef523dd2016-08-15 13:10:03 -07002067 pInterForm->GetWidget(GetSmartFieldControl(pFormField), true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002068 if (!pWidget)
2069 return FALSE;
2070
2071 CFX_FloatRect crRect = pWidget->GetRect();
tsepezf3dc8c62016-08-10 06:29:29 -07002072 Upper_Leftx = CJS_Value(pRuntime, static_cast<int32_t>(crRect.left));
2073 Upper_Lefty = CJS_Value(pRuntime, static_cast<int32_t>(crRect.top));
2074 Lower_Rightx = CJS_Value(pRuntime, static_cast<int32_t>(crRect.right));
2075 Lower_Righty = CJS_Value(pRuntime, static_cast<int32_t>(crRect.bottom));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002076
tsepeze5aff742016-08-08 09:49:42 -07002077 CJS_Array rcArray;
tsepezb4694242016-08-15 16:44:55 -07002078 rcArray.SetElement(pRuntime, 0, Upper_Leftx);
2079 rcArray.SetElement(pRuntime, 1, Upper_Lefty);
2080 rcArray.SetElement(pRuntime, 2, Lower_Rightx);
2081 rcArray.SetElement(pRuntime, 3, Lower_Righty);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002082 vp << rcArray;
2083 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002084 return TRUE;
2085}
2086
2087void Field::SetRect(CPDFSDK_Document* pDocument,
2088 const CFX_WideString& swFieldName,
2089 int nControlIndex,
Tom Sepez281a9ea2016-02-26 14:24:28 -08002090 const CFX_FloatRect& rect) {
tsepez23ae4a52016-06-08 20:44:54 -07002091 CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08002092 std::vector<CPDF_FormField*> FieldArray =
2093 GetFormFields(pDocument, swFieldName);
2094 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002095 if (nControlIndex < 0) {
2096 FX_BOOL bSet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08002097 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002098 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08002099 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002100
dsinclairef523dd2016-08-15 13:10:03 -07002101 if (CPDFSDK_Widget* pWidget =
2102 pInterForm->GetWidget(pFormControl, false)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002103 CFX_FloatRect crRect = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002104
2105 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002106 crRect.Intersect(pPDFPage->GetPageBBox());
2107
2108 if (!crRect.IsEmpty()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002109 CFX_FloatRect rcOld = pWidget->GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002110 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
2111 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
2112 pWidget->SetRect(crRect);
2113 bSet = TRUE;
2114 }
2115 }
2116 }
2117 }
2118
2119 if (bSet)
2120 UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
2121 } else {
2122 if (nControlIndex >= pFormField->CountControls())
2123 return;
2124 if (CPDF_FormControl* pFormControl =
2125 pFormField->GetControl(nControlIndex)) {
dsinclairef523dd2016-08-15 13:10:03 -07002126 if (CPDFSDK_Widget* pWidget =
2127 pInterForm->GetWidget(pFormControl, false)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002128 CFX_FloatRect crRect = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002129
2130 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002131 crRect.Intersect(pPDFPage->GetPageBBox());
2132
2133 if (!crRect.IsEmpty()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002134 CFX_FloatRect rcOld = pWidget->GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002135 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
2136 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
2137 pWidget->SetRect(crRect);
2138 UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
2139 }
2140 }
2141 }
2142 }
2143 }
2144 }
2145}
2146
Tom Sepezba038bc2015-10-08 12:03:00 -07002147FX_BOOL Field::required(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002148 CJS_PropValue& vp,
2149 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002150 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2151 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002152 return FALSE;
2153
2154 if (vp.IsSetting()) {
2155 if (!m_bCanSet)
2156 return FALSE;
2157
2158 bool bVP;
2159 vp >> bVP;
2160
2161 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002162 CPDF_FormField* pFormField = FieldArray[0];
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002163 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002164 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002165
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002166 if (pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED)
2167 vp << true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002168 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002169 vp << false;
2170 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002171
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002172 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002173}
2174
Tom Sepezba038bc2015-10-08 12:03:00 -07002175FX_BOOL Field::richText(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002176 CJS_PropValue& vp,
2177 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08002178 ASSERT(m_pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002179
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002180 if (vp.IsSetting()) {
2181 if (!m_bCanSet)
2182 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002183
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002184 bool bVP;
2185 vp >> bVP;
2186
2187 if (m_bDelay) {
2188 AddDelay_Bool(FP_RICHTEXT, bVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002189 }
2190 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002191 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2192 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002193 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002194
Lei Zhangd88a3642015-11-10 09:38:57 -08002195 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002196 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
2197 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002198
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002199 if (pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT)
2200 vp << true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002201 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002202 vp << false;
2203 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002204
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002205 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002206}
2207
Tom Sepezba038bc2015-10-08 12:03:00 -07002208FX_BOOL Field::richValue(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002209 CJS_PropValue& vp,
2210 CFX_WideString& sError) {
2211 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002212}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002213
Tom Sepezba038bc2015-10-08 12:03:00 -07002214FX_BOOL Field::rotation(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002215 CJS_PropValue& vp,
2216 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08002217 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002218
2219 if (vp.IsSetting()) {
2220 if (!m_bCanSet)
2221 return FALSE;
2222
2223 int nVP;
2224 vp >> nVP;
2225
2226 if (m_bDelay) {
2227 AddDelay_Int(FP_ROTATION, nVP);
2228 } else {
tsepez56cf5192016-09-12 11:59:30 -07002229 Field::SetRotation(m_pDocument.Get(), m_FieldName, m_nFormControlIndex,
2230 nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002231 }
2232 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002233 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2234 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002235 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002236
Lei Zhangd88a3642015-11-10 09:38:57 -08002237 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002238 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2239 if (!pFormControl)
2240 return FALSE;
2241
2242 vp << (int32_t)pFormControl->GetRotation();
2243 }
2244
2245 return TRUE;
2246}
2247
2248void Field::SetRotation(CPDFSDK_Document* pDocument,
2249 const CFX_WideString& swFieldName,
2250 int nControlIndex,
2251 int number) {
2252 // Not supported.
2253}
2254
Tom Sepezba038bc2015-10-08 12:03:00 -07002255FX_BOOL Field::strokeColor(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002256 CJS_PropValue& vp,
2257 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002258 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
tsepeze5aff742016-08-08 09:49:42 -07002259 CJS_Array crArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002260
2261 if (vp.IsSetting()) {
2262 if (!m_bCanSet)
2263 return FALSE;
2264
tsepezf3dc8c62016-08-10 06:29:29 -07002265 if (!vp.GetJSValue()->IsArrayObject())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002266 return FALSE;
2267
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002268 vp >> crArray;
2269
2270 CPWL_Color color;
tsepeze5aff742016-08-08 09:49:42 -07002271 color::ConvertArrayToPWLColor(pRuntime, crArray, &color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002272
2273 if (m_bDelay) {
2274 AddDelay_Color(FP_STROKECOLOR, color);
2275 } else {
tsepez56cf5192016-09-12 11:59:30 -07002276 Field::SetStrokeColor(m_pDocument.Get(), m_FieldName, m_nFormControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002277 color);
2278 }
2279 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002280 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2281 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002282 return FALSE;
2283
Lei Zhangd88a3642015-11-10 09:38:57 -08002284 CPDF_FormField* pFormField = FieldArray[0];
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002285 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002286 if (!pFormControl)
2287 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002288
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002289 int iColorType;
2290 pFormControl->GetBorderColor(iColorType);
2291
2292 CPWL_Color color;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002293 if (iColorType == COLORTYPE_TRANSPARENT) {
2294 color = CPWL_Color(COLORTYPE_TRANSPARENT);
2295 } else if (iColorType == COLORTYPE_GRAY) {
2296 color =
2297 CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBorderColor(0));
2298 } else if (iColorType == COLORTYPE_RGB) {
2299 color = CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBorderColor(0),
2300 pFormControl->GetOriginalBorderColor(1),
2301 pFormControl->GetOriginalBorderColor(2));
2302 } else if (iColorType == COLORTYPE_CMYK) {
2303 color =
2304 CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBorderColor(0),
2305 pFormControl->GetOriginalBorderColor(1),
2306 pFormControl->GetOriginalBorderColor(2),
2307 pFormControl->GetOriginalBorderColor(3));
Lei Zhangd88a3642015-11-10 09:38:57 -08002308 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002309 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08002310 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002311
tsepeze5aff742016-08-08 09:49:42 -07002312 color::ConvertPWLColorToArray(pRuntime, color, &crArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002313 vp << crArray;
2314 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002315 return TRUE;
2316}
2317
2318void Field::SetStrokeColor(CPDFSDK_Document* pDocument,
2319 const CFX_WideString& swFieldName,
2320 int nControlIndex,
2321 const CPWL_Color& color) {
2322 // Not supported.
2323}
2324
Tom Sepezba038bc2015-10-08 12:03:00 -07002325FX_BOOL Field::style(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002326 CJS_PropValue& vp,
2327 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08002328 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002329
2330 if (vp.IsSetting()) {
2331 if (!m_bCanSet)
2332 return FALSE;
2333
2334 CFX_ByteString csBCaption;
2335 vp >> csBCaption;
2336
2337 if (m_bDelay) {
2338 AddDelay_String(FP_STYLE, csBCaption);
2339 } else {
tsepez56cf5192016-09-12 11:59:30 -07002340 Field::SetStyle(m_pDocument.Get(), m_FieldName, m_nFormControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002341 csBCaption);
2342 }
2343 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002344 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2345 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002346 return FALSE;
2347
Lei Zhangd88a3642015-11-10 09:38:57 -08002348 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002349 if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON &&
Lei Zhangd88a3642015-11-10 09:38:57 -08002350 pFormField->GetFieldType() != FIELDTYPE_CHECKBOX) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002351 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08002352 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002353
2354 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2355 if (!pFormControl)
2356 return FALSE;
2357
2358 CFX_WideString csWCaption = pFormControl->GetNormalCaption();
2359 CFX_ByteString csBCaption;
2360
2361 switch (csWCaption[0]) {
2362 case L'l':
2363 csBCaption = "circle";
2364 break;
2365 case L'8':
2366 csBCaption = "cross";
2367 break;
2368 case L'u':
2369 csBCaption = "diamond";
2370 break;
2371 case L'n':
2372 csBCaption = "square";
2373 break;
2374 case L'H':
2375 csBCaption = "star";
2376 break;
2377 default: // L'4'
2378 csBCaption = "check";
2379 break;
2380 }
2381 vp << csBCaption;
2382 }
2383
2384 return TRUE;
2385}
2386
2387void Field::SetStyle(CPDFSDK_Document* pDocument,
2388 const CFX_WideString& swFieldName,
2389 int nControlIndex,
2390 const CFX_ByteString& string) {
2391 // Not supported.
2392}
2393
Tom Sepezba038bc2015-10-08 12:03:00 -07002394FX_BOOL Field::submitName(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002395 CJS_PropValue& vp,
2396 CFX_WideString& sError) {
2397 return TRUE;
2398}
2399
Tom Sepezba038bc2015-10-08 12:03:00 -07002400FX_BOOL Field::textColor(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002401 CJS_PropValue& vp,
2402 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002403 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
tsepeze5aff742016-08-08 09:49:42 -07002404 CJS_Array crArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002405
2406 if (vp.IsSetting()) {
2407 if (!m_bCanSet)
2408 return FALSE;
2409
tsepezf3dc8c62016-08-10 06:29:29 -07002410 if (!vp.GetJSValue()->IsArrayObject())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002411 return FALSE;
Tom Sepez67fd5df2015-10-08 12:24:19 -07002412
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002413 vp >> crArray;
2414
2415 CPWL_Color color;
tsepeze5aff742016-08-08 09:49:42 -07002416 color::ConvertArrayToPWLColor(pRuntime, crArray, &color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002417
2418 if (m_bDelay) {
2419 AddDelay_Color(FP_TEXTCOLOR, color);
2420 } else {
tsepez56cf5192016-09-12 11:59:30 -07002421 Field::SetTextColor(m_pDocument.Get(), m_FieldName, m_nFormControlIndex,
2422 color);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002423 }
2424 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002425 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2426 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002427 return FALSE;
2428
Lei Zhangd88a3642015-11-10 09:38:57 -08002429 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002430 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2431 if (!pFormControl)
2432 return FALSE;
2433
2434 int iColorType;
2435 FX_ARGB color;
2436 CPDF_DefaultAppearance FieldAppearance =
2437 pFormControl->GetDefaultAppearance();
2438 FieldAppearance.GetColor(color, iColorType);
2439 int32_t a, r, g, b;
2440 ArgbDecode(color, a, r, g, b);
2441
2442 CPWL_Color crRet =
2443 CPWL_Color(COLORTYPE_RGB, r / 255.0f, g / 255.0f, b / 255.0f);
2444
2445 if (iColorType == COLORTYPE_TRANSPARENT)
2446 crRet = CPWL_Color(COLORTYPE_TRANSPARENT);
2447
tsepeze5aff742016-08-08 09:49:42 -07002448 color::ConvertPWLColorToArray(pRuntime, crRet, &crArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002449 vp << crArray;
2450 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002451 return TRUE;
2452}
2453
2454void Field::SetTextColor(CPDFSDK_Document* pDocument,
2455 const CFX_WideString& swFieldName,
2456 int nControlIndex,
2457 const CPWL_Color& color) {
2458 // Not supported.
2459}
2460
Tom Sepezba038bc2015-10-08 12:03:00 -07002461FX_BOOL Field::textFont(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002462 CJS_PropValue& vp,
2463 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08002464 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002465
2466 if (vp.IsSetting()) {
2467 if (!m_bCanSet)
2468 return FALSE;
2469
2470 CFX_ByteString csFontName;
2471 vp >> csFontName;
2472 if (csFontName.IsEmpty())
2473 return FALSE;
2474
2475 if (m_bDelay) {
2476 AddDelay_String(FP_TEXTFONT, csFontName);
2477 } else {
tsepez56cf5192016-09-12 11:59:30 -07002478 Field::SetTextFont(m_pDocument.Get(), m_FieldName, m_nFormControlIndex,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002479 csFontName);
2480 }
2481 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002482 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2483 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002484 return FALSE;
2485
Lei Zhangd88a3642015-11-10 09:38:57 -08002486 CPDF_FormField* pFormField = FieldArray[0];
2487 ASSERT(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002488 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2489 if (!pFormControl)
2490 return FALSE;
2491
2492 int nFieldType = pFormField->GetFieldType();
2493
2494 if (nFieldType == FIELDTYPE_PUSHBUTTON ||
2495 nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX ||
2496 nFieldType == FIELDTYPE_TEXTFIELD) {
2497 CPDF_Font* pFont = pFormControl->GetDefaultControlFont();
2498 if (!pFont)
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002499 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002500
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002501 vp << pFont->GetBaseFont();
Lei Zhangd88a3642015-11-10 09:38:57 -08002502 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002503 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08002504 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002505 }
2506
2507 return TRUE;
2508}
2509
2510void Field::SetTextFont(CPDFSDK_Document* pDocument,
2511 const CFX_WideString& swFieldName,
2512 int nControlIndex,
2513 const CFX_ByteString& string) {
2514 // Not supported.
2515}
2516
Tom Sepezba038bc2015-10-08 12:03:00 -07002517FX_BOOL Field::textSize(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002518 CJS_PropValue& vp,
2519 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08002520 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002521
2522 if (vp.IsSetting()) {
2523 if (!m_bCanSet)
2524 return FALSE;
2525
2526 int nVP;
2527 vp >> nVP;
2528
2529 if (m_bDelay) {
2530 AddDelay_Int(FP_TEXTSIZE, nVP);
2531 } else {
tsepez56cf5192016-09-12 11:59:30 -07002532 Field::SetTextSize(m_pDocument.Get(), m_FieldName, m_nFormControlIndex,
2533 nVP);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002534 }
2535 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002536 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2537 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002538 return FALSE;
2539
Lei Zhangd88a3642015-11-10 09:38:57 -08002540 CPDF_FormField* pFormField = FieldArray[0];
2541 ASSERT(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002542 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2543 if (!pFormControl)
2544 return FALSE;
2545
2546 CPDF_DefaultAppearance FieldAppearance =
2547 pFormControl->GetDefaultAppearance();
2548
2549 CFX_ByteString csFontNameTag;
2550 FX_FLOAT fFontSize;
2551 FieldAppearance.GetFont(csFontNameTag, fFontSize);
2552
2553 vp << (int)fFontSize;
2554 }
2555
2556 return TRUE;
2557}
2558
2559void Field::SetTextSize(CPDFSDK_Document* pDocument,
2560 const CFX_WideString& swFieldName,
2561 int nControlIndex,
2562 int number) {
2563 // Not supported.
2564}
2565
Tom Sepezba038bc2015-10-08 12:03:00 -07002566FX_BOOL Field::type(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002567 CJS_PropValue& vp,
2568 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002569 if (!vp.IsGetting())
2570 return FALSE;
2571
Lei Zhangd88a3642015-11-10 09:38:57 -08002572 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2573 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002574 return FALSE;
2575
Lei Zhangd88a3642015-11-10 09:38:57 -08002576 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002577 switch (pFormField->GetFieldType()) {
2578 case FIELDTYPE_UNKNOWN:
2579 vp << L"unknown";
2580 break;
2581 case FIELDTYPE_PUSHBUTTON:
2582 vp << L"button";
2583 break;
2584 case FIELDTYPE_CHECKBOX:
2585 vp << L"checkbox";
2586 break;
2587 case FIELDTYPE_RADIOBUTTON:
2588 vp << L"radiobutton";
2589 break;
2590 case FIELDTYPE_COMBOBOX:
2591 vp << L"combobox";
2592 break;
2593 case FIELDTYPE_LISTBOX:
2594 vp << L"listbox";
2595 break;
2596 case FIELDTYPE_TEXTFIELD:
2597 vp << L"text";
2598 break;
2599 case FIELDTYPE_SIGNATURE:
2600 vp << L"signature";
2601 break;
2602 default:
2603 vp << L"unknown";
2604 break;
2605 }
2606
2607 return TRUE;
2608}
2609
Tom Sepezba038bc2015-10-08 12:03:00 -07002610FX_BOOL Field::userName(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002611 CJS_PropValue& vp,
2612 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08002613 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002614
2615 if (vp.IsSetting()) {
2616 if (!m_bCanSet)
2617 return FALSE;
2618
2619 CFX_WideString swName;
2620 vp >> swName;
2621
2622 if (m_bDelay) {
2623 AddDelay_WideString(FP_USERNAME, swName);
2624 } else {
tsepez56cf5192016-09-12 11:59:30 -07002625 Field::SetUserName(m_pDocument.Get(), m_FieldName, m_nFormControlIndex,
2626 swName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002627 }
2628 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002629 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2630 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002631 return FALSE;
2632
Lei Zhangd88a3642015-11-10 09:38:57 -08002633 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002634 vp << (CFX_WideString)pFormField->GetAlternateName();
2635 }
2636
2637 return TRUE;
2638}
2639
2640void Field::SetUserName(CPDFSDK_Document* pDocument,
2641 const CFX_WideString& swFieldName,
2642 int nControlIndex,
2643 const CFX_WideString& string) {
2644 // Not supported.
2645}
2646
Tom Sepezba038bc2015-10-08 12:03:00 -07002647FX_BOOL Field::value(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002648 CJS_PropValue& vp,
2649 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002650 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002651
2652 if (vp.IsSetting()) {
2653 if (!m_bCanSet)
2654 return FALSE;
2655
tsepez41a53ad2016-03-28 16:59:30 -07002656 std::vector<CFX_WideString> strArray;
tsepezf3dc8c62016-08-10 06:29:29 -07002657 if (vp.GetJSValue()->IsArrayObject()) {
tsepeze5aff742016-08-08 09:49:42 -07002658 CJS_Array ValueArray;
tsepezb4694242016-08-15 16:44:55 -07002659 vp.GetJSValue()->ConvertToArray(pRuntime, ValueArray);
2660 for (int i = 0, sz = ValueArray.GetLength(pRuntime); i < sz; i++) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002661 CJS_Value ElementValue(pRuntime);
tsepezb4694242016-08-15 16:44:55 -07002662 ValueArray.GetElement(pRuntime, i, ElementValue);
2663 strArray.push_back(ElementValue.ToCFXWideString(pRuntime));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002664 }
2665 } else {
2666 CFX_WideString swValue;
2667 vp >> swValue;
tsepez41a53ad2016-03-28 16:59:30 -07002668 strArray.push_back(swValue);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002669 }
2670
2671 if (m_bDelay) {
2672 AddDelay_WideStringArray(FP_VALUE, strArray);
2673 } else {
tsepez56cf5192016-09-12 11:59:30 -07002674 Field::SetValue(m_pDocument.Get(), m_FieldName, m_nFormControlIndex,
2675 strArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002676 }
2677 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002678 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2679 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002680 return FALSE;
2681
Lei Zhangd88a3642015-11-10 09:38:57 -08002682 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002683 switch (pFormField->GetFieldType()) {
2684 case FIELDTYPE_PUSHBUTTON:
2685 return FALSE;
2686 case FIELDTYPE_COMBOBOX:
2687 case FIELDTYPE_TEXTFIELD: {
Tom Sepez4246b002016-01-20 11:48:29 -08002688 vp << pFormField->GetValue();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002689 } break;
2690 case FIELDTYPE_LISTBOX: {
2691 if (pFormField->CountSelectedItems() > 1) {
tsepeze5aff742016-08-08 09:49:42 -07002692 CJS_Array ValueArray;
Tom Sepez67fd5df2015-10-08 12:24:19 -07002693 CJS_Value ElementValue(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002694 int iIndex;
2695 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
2696 iIndex = pFormField->GetSelectedIndex(i);
tsepezf3dc8c62016-08-10 06:29:29 -07002697 ElementValue =
2698 CJS_Value(pRuntime, pFormField->GetOptionValue(iIndex).c_str());
tsepezb4694242016-08-15 16:44:55 -07002699 if (FXSYS_wcslen(ElementValue.ToCFXWideString(pRuntime).c_str()) ==
2700 0) {
tsepezf3dc8c62016-08-10 06:29:29 -07002701 ElementValue = CJS_Value(
2702 pRuntime, pFormField->GetOptionLabel(iIndex).c_str());
2703 }
tsepezb4694242016-08-15 16:44:55 -07002704 ValueArray.SetElement(pRuntime, i, ElementValue);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002705 }
2706 vp << ValueArray;
2707 } else {
Tom Sepez4246b002016-01-20 11:48:29 -08002708 vp << pFormField->GetValue();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002709 }
2710 } break;
2711 case FIELDTYPE_CHECKBOX:
2712 case FIELDTYPE_RADIOBUTTON: {
Tom Sepez4246b002016-01-20 11:48:29 -08002713 bool bFind = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002714 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
Tom Sepez4246b002016-01-20 11:48:29 -08002715 if (pFormField->GetControl(i)->IsChecked()) {
2716 vp << pFormField->GetControl(i)->GetExportValue();
2717 bFind = true;
2718 break;
Lei Zhangd88a3642015-11-10 09:38:57 -08002719 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002720 }
2721 if (!bFind)
2722 vp << L"Off";
2723 } break;
2724 default:
2725 vp << pFormField->GetValue();
2726 break;
2727 }
2728 }
tsepezb4694242016-08-15 16:44:55 -07002729 vp.GetJSValue()->MaybeCoerceToNumber(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002730 return TRUE;
2731}
2732
2733void Field::SetValue(CPDFSDK_Document* pDocument,
2734 const CFX_WideString& swFieldName,
2735 int nControlIndex,
tsepez41a53ad2016-03-28 16:59:30 -07002736 const std::vector<CFX_WideString>& strArray) {
Lei Zhang96660d62015-12-14 18:27:25 -08002737 ASSERT(pDocument);
tsepez41a53ad2016-03-28 16:59:30 -07002738 if (strArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002739 return;
2740
Lei Zhangd88a3642015-11-10 09:38:57 -08002741 std::vector<CPDF_FormField*> FieldArray =
2742 GetFormFields(pDocument, swFieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002743
Lei Zhangd88a3642015-11-10 09:38:57 -08002744 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002745 if (pFormField->GetFullName().Compare(swFieldName) != 0)
2746 continue;
2747
2748 switch (pFormField->GetFieldType()) {
2749 case FIELDTYPE_TEXTFIELD:
2750 case FIELDTYPE_COMBOBOX:
tsepez41a53ad2016-03-28 16:59:30 -07002751 if (pFormField->GetValue() != strArray[0]) {
2752 pFormField->SetValue(strArray[0], TRUE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002753 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
2754 }
2755 break;
tsepez41a53ad2016-03-28 16:59:30 -07002756 case FIELDTYPE_CHECKBOX:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002757 case FIELDTYPE_RADIOBUTTON: {
tsepez41a53ad2016-03-28 16:59:30 -07002758 if (pFormField->GetValue() != strArray[0]) {
2759 pFormField->SetValue(strArray[0], TRUE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002760 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
2761 }
2762 } break;
2763 case FIELDTYPE_LISTBOX: {
2764 FX_BOOL bModified = FALSE;
tsepez41a53ad2016-03-28 16:59:30 -07002765 for (const auto& str : strArray) {
2766 if (!pFormField->IsItemSelected(pFormField->FindOption(str))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002767 bModified = TRUE;
2768 break;
2769 }
2770 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002771 if (bModified) {
2772 pFormField->ClearSelection(TRUE);
tsepez41a53ad2016-03-28 16:59:30 -07002773 for (const auto& str : strArray) {
2774 int index = pFormField->FindOption(str);
2775 if (!pFormField->IsItemSelected(index))
2776 pFormField->SetItemSelection(index, TRUE, TRUE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002777 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002778 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
2779 }
2780 } break;
2781 default:
2782 break;
2783 }
2784 }
2785}
2786
Tom Sepezba038bc2015-10-08 12:03:00 -07002787FX_BOOL Field::valueAsString(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002788 CJS_PropValue& vp,
2789 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002790 if (!vp.IsGetting())
2791 return FALSE;
2792
Lei Zhangd88a3642015-11-10 09:38:57 -08002793 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2794 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002795 return FALSE;
2796
Lei Zhangd88a3642015-11-10 09:38:57 -08002797 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002798 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
2799 return FALSE;
2800
2801 if (pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) {
2802 if (!pFormField->CountControls())
2803 return FALSE;
2804
2805 if (pFormField->GetControl(0)->IsChecked())
2806 vp << L"Yes";
2807 else
2808 vp << L"Off";
2809 } else if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON &&
2810 !(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)) {
2811 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2812 if (pFormField->GetControl(i)->IsChecked()) {
2813 vp << pFormField->GetControl(i)->GetExportValue().c_str();
2814 break;
Lei Zhangd88a3642015-11-10 09:38:57 -08002815 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002816 vp << L"Off";
Lei Zhangd88a3642015-11-10 09:38:57 -08002817 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002818 }
2819 } else if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX &&
2820 (pFormField->CountSelectedItems() > 1)) {
2821 vp << L"";
Lei Zhangd88a3642015-11-10 09:38:57 -08002822 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002823 vp << pFormField->GetValue().c_str();
Lei Zhangd88a3642015-11-10 09:38:57 -08002824 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002825
2826 return TRUE;
2827}
2828
Tom Sepezba038bc2015-10-08 12:03:00 -07002829FX_BOOL Field::browseForFileToSubmit(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08002830 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002831 CJS_Value& vRet,
2832 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002833 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2834 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002835 return FALSE;
2836
Lei Zhangd88a3642015-11-10 09:38:57 -08002837 CPDF_FormField* pFormField = FieldArray[0];
dsinclair79db6092016-09-14 07:27:21 -07002838 CPDFSDK_Environment* pApp = m_pDocument->GetEnv();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002839 if ((pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) &&
2840 (pFormField->GetFieldType() == FIELDTYPE_TEXTFIELD)) {
2841 CFX_WideString wsFileName = pApp->JS_fieldBrowse();
2842 if (!wsFileName.IsEmpty()) {
2843 pFormField->SetValue(wsFileName);
tsepez56cf5192016-09-12 11:59:30 -07002844 UpdateFormField(m_pDocument.Get(), pFormField, TRUE, TRUE, TRUE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002845 }
Lei Zhangd88a3642015-11-10 09:38:57 -08002846 return TRUE;
2847 }
2848 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002849}
2850
Tom Sepezba038bc2015-10-08 12:03:00 -07002851FX_BOOL Field::buttonGetCaption(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08002852 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002853 CJS_Value& vRet,
2854 CFX_WideString& sError) {
tsepezf3dc8c62016-08-10 06:29:29 -07002855 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
2856
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002857 int nface = 0;
2858 int iSize = params.size();
2859 if (iSize >= 1)
tsepezb4694242016-08-15 16:44:55 -07002860 nface = params[0].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002861
Lei Zhangd88a3642015-11-10 09:38:57 -08002862 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2863 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002864 return FALSE;
2865
Lei Zhangd88a3642015-11-10 09:38:57 -08002866 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002867 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
2868 return FALSE;
2869
2870 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2871 if (!pFormControl)
2872 return FALSE;
2873
2874 if (nface == 0)
tsepezf3dc8c62016-08-10 06:29:29 -07002875 vRet = CJS_Value(pRuntime, pFormControl->GetNormalCaption().c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002876 else if (nface == 1)
tsepezf3dc8c62016-08-10 06:29:29 -07002877 vRet = CJS_Value(pRuntime, pFormControl->GetDownCaption().c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002878 else if (nface == 2)
tsepezf3dc8c62016-08-10 06:29:29 -07002879 vRet = CJS_Value(pRuntime, pFormControl->GetRolloverCaption().c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002880 else
2881 return FALSE;
2882
2883 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002884}
2885
Tom Sepezba038bc2015-10-08 12:03:00 -07002886FX_BOOL Field::buttonGetIcon(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08002887 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002888 CJS_Value& vRet,
2889 CFX_WideString& sError) {
tsepezf3dc8c62016-08-10 06:29:29 -07002890 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
2891 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
2892
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002893 int nface = 0;
2894 int iSize = params.size();
2895 if (iSize >= 1)
tsepezb4694242016-08-15 16:44:55 -07002896 nface = params[0].ToInt(pRuntime);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002897
Lei Zhangd88a3642015-11-10 09:38:57 -08002898 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2899 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002900 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002901
Lei Zhangd88a3642015-11-10 09:38:57 -08002902 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002903 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
2904 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002905
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002906 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2907 if (!pFormControl)
2908 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002909
tsepezb4694242016-08-15 16:44:55 -07002910 v8::Local<v8::Object> pObj =
2911 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002912 ASSERT(pObj.IsEmpty() == FALSE);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002913
tsepezb4694242016-08-15 16:44:55 -07002914 CJS_Icon* pJS_Icon = static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002915 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002916
thestig1cd352e2016-06-07 17:53:06 -07002917 CPDF_Stream* pIconStream = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002918 if (nface == 0)
2919 pIconStream = pFormControl->GetNormalIcon();
2920 else if (nface == 1)
2921 pIconStream = pFormControl->GetDownIcon();
2922 else if (nface == 2)
2923 pIconStream = pFormControl->GetRolloverIcon();
2924 else
2925 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002926
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002927 pIcon->SetStream(pIconStream);
tsepezf3dc8c62016-08-10 06:29:29 -07002928 vRet = CJS_Value(pRuntime, pJS_Icon);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002929 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002930}
2931
Tom Sepezba038bc2015-10-08 12:03:00 -07002932FX_BOOL Field::buttonImportIcon(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08002933 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002934 CJS_Value& vRet,
2935 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002936 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002937}
2938
Tom Sepezba038bc2015-10-08 12:03:00 -07002939FX_BOOL Field::buttonSetCaption(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08002940 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002941 CJS_Value& vRet,
2942 CFX_WideString& sError) {
2943 return FALSE;
2944}
2945
Tom Sepezba038bc2015-10-08 12:03:00 -07002946FX_BOOL Field::buttonSetIcon(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08002947 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002948 CJS_Value& vRet,
2949 CFX_WideString& sError) {
2950 return FALSE;
2951}
2952
Tom Sepezba038bc2015-10-08 12:03:00 -07002953FX_BOOL Field::checkThisBox(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08002954 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002955 CJS_Value& vRet,
2956 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002957 int iSize = params.size();
2958 if (iSize < 1)
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002959 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002960
tsepezf3dc8c62016-08-10 06:29:29 -07002961 if (!m_bCanSet)
2962 return FALSE;
2963
2964 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
tsepezb4694242016-08-15 16:44:55 -07002965 int nWidget = params[0].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002966
Wei Li97da9762016-03-11 17:00:48 -08002967 bool bCheckit = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002968 if (iSize >= 2)
tsepezb4694242016-08-15 16:44:55 -07002969 bCheckit = params[1].ToBool(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002970
Lei Zhangd88a3642015-11-10 09:38:57 -08002971 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2972 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002973 return FALSE;
2974
Lei Zhangd88a3642015-11-10 09:38:57 -08002975 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002976 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
2977 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
2978 return FALSE;
2979 if (nWidget < 0 || nWidget >= pFormField->CountControls())
2980 return FALSE;
Wei Li97da9762016-03-11 17:00:48 -08002981 // TODO(weili): Check whether anything special needed for radio button,
2982 // otherwise merge these branches.
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002983 if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)
Wei Li97da9762016-03-11 17:00:48 -08002984 pFormField->CheckControl(nWidget, bCheckit, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002985 else
Wei Li97da9762016-03-11 17:00:48 -08002986 pFormField->CheckControl(nWidget, bCheckit, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002987
tsepez56cf5192016-09-12 11:59:30 -07002988 UpdateFormField(m_pDocument.Get(), pFormField, TRUE, TRUE, TRUE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002989 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002990}
2991
Tom Sepezba038bc2015-10-08 12:03:00 -07002992FX_BOOL Field::clearItems(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08002993 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002994 CJS_Value& vRet,
2995 CFX_WideString& sError) {
2996 return TRUE;
2997}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002998
Tom Sepezba038bc2015-10-08 12:03:00 -07002999FX_BOOL Field::defaultIsChecked(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003000 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003001 CJS_Value& vRet,
3002 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003003 if (!m_bCanSet)
3004 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003005
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003006 int iSize = params.size();
3007 if (iSize < 1)
3008 return FALSE;
Tom Sepezf4ef3f92015-04-23 11:31:31 -07003009
tsepezf3dc8c62016-08-10 06:29:29 -07003010 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
tsepezb4694242016-08-15 16:44:55 -07003011 int nWidget = params[0].ToInt(pRuntime);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003012
Lei Zhangd88a3642015-11-10 09:38:57 -08003013 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3014 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003015 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003016
Lei Zhangd88a3642015-11-10 09:38:57 -08003017 CPDF_FormField* pFormField = FieldArray[0];
tsepezf3dc8c62016-08-10 06:29:29 -07003018 if (nWidget < 0 || nWidget >= pFormField->CountControls())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003019 return FALSE;
tsepezf3dc8c62016-08-10 06:29:29 -07003020
3021 vRet = CJS_Value(pRuntime,
3022 pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
3023 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003024
3025 return TRUE;
3026}
3027
Tom Sepezba038bc2015-10-08 12:03:00 -07003028FX_BOOL Field::deleteItemAt(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003029 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003030 CJS_Value& vRet,
3031 CFX_WideString& sError) {
3032 return TRUE;
3033}
3034
Tom Sepezba038bc2015-10-08 12:03:00 -07003035FX_BOOL Field::getArray(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003036 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003037 CJS_Value& vRet,
3038 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08003039 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3040 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003041 return FALSE;
3042
Tom Sepezb9cc7a02016-02-01 13:42:30 -08003043 std::vector<std::unique_ptr<CFX_WideString>> swSort;
3044 for (CPDF_FormField* pFormField : FieldArray) {
3045 swSort.push_back(std::unique_ptr<CFX_WideString>(
3046 new CFX_WideString(pFormField->GetFullName())));
3047 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003048
Tom Sepezb9cc7a02016-02-01 13:42:30 -08003049 std::sort(
3050 swSort.begin(), swSort.end(),
3051 [](const std::unique_ptr<CFX_WideString>& p1,
3052 const std::unique_ptr<CFX_WideString>& p2) { return *p1 < *p2; });
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003053
3054 CJS_Context* pContext = (CJS_Context*)cc;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003055 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
tsepeze5aff742016-08-08 09:49:42 -07003056 CJS_Array FormFieldArray;
Tom Sepezb9cc7a02016-02-01 13:42:30 -08003057
3058 int j = 0;
3059 for (const auto& pStr : swSort) {
tsepezb4694242016-08-15 16:44:55 -07003060 v8::Local<v8::Object> pObj =
3061 pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID);
Tom Sepezcd56a7d2015-10-06 11:45:28 -07003062 ASSERT(!pObj.IsEmpty());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003063
Tom Sepezd5a0e952015-09-17 15:40:06 -07003064 CJS_Field* pJSField =
tsepezb4694242016-08-15 16:44:55 -07003065 static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pObj));
Tom Sepezb9cc7a02016-02-01 13:42:30 -08003066 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003067 pField->AttachField(m_pJSDoc, *pStr);
tsepezb4694242016-08-15 16:44:55 -07003068 FormFieldArray.SetElement(pRuntime, j++, CJS_Value(pRuntime, pJSField));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003069 }
3070
tsepeze5aff742016-08-08 09:49:42 -07003071 vRet = CJS_Value(pRuntime, FormFieldArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003072 return TRUE;
3073}
3074
Tom Sepezba038bc2015-10-08 12:03:00 -07003075FX_BOOL Field::getItemAt(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003076 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003077 CJS_Value& vRet,
3078 CFX_WideString& sError) {
tsepezf3dc8c62016-08-10 06:29:29 -07003079 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003080
tsepezf3dc8c62016-08-10 06:29:29 -07003081 int iSize = params.size();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003082 int nIdx = -1;
3083 if (iSize >= 1)
tsepezb4694242016-08-15 16:44:55 -07003084 nIdx = params[0].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003085
3086 FX_BOOL bExport = TRUE;
3087 if (iSize >= 2)
tsepezb4694242016-08-15 16:44:55 -07003088 bExport = params[1].ToBool(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003089
Lei Zhangd88a3642015-11-10 09:38:57 -08003090 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3091 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003092 return FALSE;
3093
Lei Zhangd88a3642015-11-10 09:38:57 -08003094 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003095 if ((pFormField->GetFieldType() == FIELDTYPE_LISTBOX) ||
3096 (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX)) {
3097 if (nIdx == -1 || nIdx > pFormField->CountOptions())
3098 nIdx = pFormField->CountOptions() - 1;
3099 if (bExport) {
3100 CFX_WideString strval = pFormField->GetOptionValue(nIdx);
3101 if (strval.IsEmpty())
tsepezf3dc8c62016-08-10 06:29:29 -07003102 vRet = CJS_Value(pRuntime, pFormField->GetOptionLabel(nIdx).c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003103 else
tsepezf3dc8c62016-08-10 06:29:29 -07003104 vRet = CJS_Value(pRuntime, strval.c_str());
Lei Zhangd88a3642015-11-10 09:38:57 -08003105 } else {
tsepezf3dc8c62016-08-10 06:29:29 -07003106 vRet = CJS_Value(pRuntime, pFormField->GetOptionLabel(nIdx).c_str());
Lei Zhangd88a3642015-11-10 09:38:57 -08003107 }
3108 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003109 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08003110 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003111
3112 return TRUE;
3113}
3114
Tom Sepezba038bc2015-10-08 12:03:00 -07003115FX_BOOL Field::getLock(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003116 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003117 CJS_Value& vRet,
3118 CFX_WideString& sError) {
3119 return FALSE;
3120}
3121
Tom Sepezba038bc2015-10-08 12:03:00 -07003122FX_BOOL Field::insertItemAt(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003123 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003124 CJS_Value& vRet,
3125 CFX_WideString& sError) {
3126 return TRUE;
3127}
3128
Tom Sepezba038bc2015-10-08 12:03:00 -07003129FX_BOOL Field::isBoxChecked(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003130 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003131 CJS_Value& vRet,
3132 CFX_WideString& sError) {
tsepezf3dc8c62016-08-10 06:29:29 -07003133 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
3134
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003135 int nIndex = -1;
3136 if (params.size() >= 1)
tsepezb4694242016-08-15 16:44:55 -07003137 nIndex = params[0].ToInt(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003138
Lei Zhangd88a3642015-11-10 09:38:57 -08003139 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3140 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003141 return FALSE;
3142
Lei Zhangd88a3642015-11-10 09:38:57 -08003143 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003144 if (nIndex < 0 || nIndex >= pFormField->CountControls()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003145 return FALSE;
3146 }
3147
tsepezf3dc8c62016-08-10 06:29:29 -07003148 vRet = CJS_Value(pRuntime,
3149 ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
3150 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) &&
3151 pFormField->GetControl(nIndex)->IsChecked() != 0));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003152 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003153}
3154
Tom Sepezba038bc2015-10-08 12:03:00 -07003155FX_BOOL Field::isDefaultChecked(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003156 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003157 CJS_Value& vRet,
3158 CFX_WideString& sError) {
tsepezf3dc8c62016-08-10 06:29:29 -07003159 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
3160
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003161 int nIndex = -1;
3162 if (params.size() >= 1)
tsepezb4694242016-08-15 16:44:55 -07003163 nIndex = params[0].ToInt(pRuntime);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003164
Lei Zhangd88a3642015-11-10 09:38:57 -08003165 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3166 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003167 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003168
Lei Zhangd88a3642015-11-10 09:38:57 -08003169 CPDF_FormField* pFormField = FieldArray[0];
tsepezf3dc8c62016-08-10 06:29:29 -07003170 if (nIndex < 0 || nIndex >= pFormField->CountControls())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003171 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003172
tsepezf3dc8c62016-08-10 06:29:29 -07003173 vRet = CJS_Value(pRuntime,
3174 ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
3175 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) &&
3176 pFormField->GetControl(nIndex)->IsDefaultChecked() != 0));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003177 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003178}
3179
Tom Sepezba038bc2015-10-08 12:03:00 -07003180FX_BOOL Field::setAction(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003181 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003182 CJS_Value& vRet,
3183 CFX_WideString& sError) {
3184 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003185}
3186
Tom Sepezba038bc2015-10-08 12:03:00 -07003187FX_BOOL Field::setFocus(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003188 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003189 CJS_Value& vRet,
3190 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08003191 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3192 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003193 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003194
Lei Zhangd88a3642015-11-10 09:38:57 -08003195 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003196 int32_t nCount = pFormField->CountControls();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003197 if (nCount < 1)
3198 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003199
tsepez23ae4a52016-06-08 20:44:54 -07003200 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
thestig1cd352e2016-06-07 17:53:06 -07003201 CPDFSDK_Widget* pWidget = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003202 if (nCount == 1) {
dsinclairef523dd2016-08-15 13:10:03 -07003203 pWidget = pInterForm->GetWidget(pFormField->GetControl(0), false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003204 } else {
dsinclair79db6092016-09-14 07:27:21 -07003205 CPDFSDK_Environment* pEnv = m_pDocument->GetEnv();
Tom Sepez50d12ad2015-11-24 09:50:51 -08003206 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(
dsinclair1f248902016-09-14 10:38:17 -07003207 pEnv->GetCurrentPage(m_pDocument->GetUnderlyingDocument()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003208 if (!pPage)
3209 return FALSE;
dsinclair461eeaf2016-07-27 07:40:05 -07003210 if (CPDFSDK_PageView* pCurPageView =
3211 m_pDocument->GetPageView(pPage, true)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003212 for (int32_t i = 0; i < nCount; i++) {
3213 if (CPDFSDK_Widget* pTempWidget =
dsinclairef523dd2016-08-15 13:10:03 -07003214 pInterForm->GetWidget(pFormField->GetControl(i), false)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003215 if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage()) {
3216 pWidget = pTempWidget;
3217 break;
3218 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003219 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003220 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003221 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003222 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003223
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003224 if (pWidget) {
tsepezf8074ce2016-09-27 14:29:57 -07003225 CPDFSDK_Annot::ObservedPtr pObserved(pWidget);
3226 m_pDocument->SetFocusAnnot(&pObserved);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003227 }
3228
3229 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003230}
3231
Tom Sepezba038bc2015-10-08 12:03:00 -07003232FX_BOOL Field::setItems(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003233 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003234 CJS_Value& vRet,
3235 CFX_WideString& sError) {
3236 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003237}
3238
Tom Sepezba038bc2015-10-08 12:03:00 -07003239FX_BOOL Field::setLock(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003240 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003241 CJS_Value& vRet,
3242 CFX_WideString& sError) {
3243 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003244}
3245
Tom Sepezba038bc2015-10-08 12:03:00 -07003246FX_BOOL Field::signatureGetModifications(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003247 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003248 CJS_Value& vRet,
3249 CFX_WideString& sError) {
3250 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003251}
3252
Tom Sepezba038bc2015-10-08 12:03:00 -07003253FX_BOOL Field::signatureGetSeedValue(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003254 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003255 CJS_Value& vRet,
3256 CFX_WideString& sError) {
3257 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003258}
3259
Tom Sepezba038bc2015-10-08 12:03:00 -07003260FX_BOOL Field::signatureInfo(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003261 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003262 CJS_Value& vRet,
3263 CFX_WideString& sError) {
3264 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003265}
3266
Tom Sepezba038bc2015-10-08 12:03:00 -07003267FX_BOOL Field::signatureSetSeedValue(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003268 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003269 CJS_Value& vRet,
3270 CFX_WideString& sError) {
3271 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003272}
3273
Tom Sepezba038bc2015-10-08 12:03:00 -07003274FX_BOOL Field::signatureSign(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003275 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003276 CJS_Value& vRet,
3277 CFX_WideString& sError) {
3278 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003279}
3280
Tom Sepezba038bc2015-10-08 12:03:00 -07003281FX_BOOL Field::signatureValidate(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003282 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003283 CJS_Value& vRet,
3284 CFX_WideString& sError) {
3285 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003286}
3287
Tom Sepezba038bc2015-10-08 12:03:00 -07003288FX_BOOL Field::source(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003289 CJS_PropValue& vp,
3290 CFX_WideString& sError) {
3291 if (vp.IsGetting()) {
thestig1cd352e2016-06-07 17:53:06 -07003292 vp << (CJS_Object*)nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003293 }
3294
3295 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003296}
3297
tsepez41a53ad2016-03-28 16:59:30 -07003298void Field::AddDelay_Int(FIELD_PROP prop, int32_t n) {
3299 CJS_DelayData* pNewData =
3300 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003301 pNewData->num = n;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003302 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003303}
3304
tsepez41a53ad2016-03-28 16:59:30 -07003305void Field::AddDelay_Bool(FIELD_PROP prop, bool b) {
3306 CJS_DelayData* pNewData =
3307 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003308 pNewData->b = b;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003309 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003310}
3311
tsepez41a53ad2016-03-28 16:59:30 -07003312void Field::AddDelay_String(FIELD_PROP prop, const CFX_ByteString& string) {
3313 CJS_DelayData* pNewData =
3314 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003315 pNewData->string = string;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003316 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003317}
3318
tsepez41a53ad2016-03-28 16:59:30 -07003319void Field::AddDelay_WideString(FIELD_PROP prop, const CFX_WideString& string) {
3320 CJS_DelayData* pNewData =
3321 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003322 pNewData->widestring = string;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003323 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003324}
3325
tsepez41a53ad2016-03-28 16:59:30 -07003326void Field::AddDelay_Rect(FIELD_PROP prop, const CFX_FloatRect& rect) {
3327 CJS_DelayData* pNewData =
3328 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003329 pNewData->rect = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003330 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003331}
3332
tsepez41a53ad2016-03-28 16:59:30 -07003333void Field::AddDelay_Color(FIELD_PROP prop, const CPWL_Color& color) {
3334 CJS_DelayData* pNewData =
3335 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003336 pNewData->color = color;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003337 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003338}
3339
tsepez41a53ad2016-03-28 16:59:30 -07003340void Field::AddDelay_WordArray(FIELD_PROP prop,
3341 const std::vector<uint32_t>& array) {
3342 CJS_DelayData* pNewData =
3343 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
3344 pNewData->wordarray = array;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003345 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003346}
3347
tsepez41a53ad2016-03-28 16:59:30 -07003348void Field::AddDelay_WideStringArray(FIELD_PROP prop,
3349 const std::vector<CFX_WideString>& array) {
3350 CJS_DelayData* pNewData =
3351 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
3352 pNewData->widestringarray = array;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003353 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003354}
3355
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003356void Field::DoDelay(CPDFSDK_Document* pDocument, CJS_DelayData* pData) {
Lei Zhang96660d62015-12-14 18:27:25 -08003357 ASSERT(pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003358 switch (pData->eProp) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003359 case FP_ALIGNMENT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003360 Field::SetAlignment(pDocument, pData->sFieldName, pData->nControlIndex,
3361 pData->string);
3362 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003363 case FP_BORDERSTYLE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003364 Field::SetBorderStyle(pDocument, pData->sFieldName, pData->nControlIndex,
3365 pData->string);
3366 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003367 case FP_BUTTONALIGNX:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003368 Field::SetButtonAlignX(pDocument, pData->sFieldName, pData->nControlIndex,
3369 pData->num);
3370 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003371 case FP_BUTTONALIGNY:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003372 Field::SetButtonAlignY(pDocument, pData->sFieldName, pData->nControlIndex,
3373 pData->num);
3374 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003375 case FP_BUTTONFITBOUNDS:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003376 Field::SetButtonFitBounds(pDocument, pData->sFieldName,
3377 pData->nControlIndex, pData->b);
3378 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003379 case FP_BUTTONPOSITION:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003380 Field::SetButtonPosition(pDocument, pData->sFieldName,
3381 pData->nControlIndex, pData->num);
3382 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003383 case FP_BUTTONSCALEHOW:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003384 Field::SetButtonScaleHow(pDocument, pData->sFieldName,
3385 pData->nControlIndex, pData->num);
3386 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003387 case FP_BUTTONSCALEWHEN:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003388 Field::SetButtonScaleWhen(pDocument, pData->sFieldName,
3389 pData->nControlIndex, pData->num);
3390 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003391 case FP_CALCORDERINDEX:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003392 Field::SetCalcOrderIndex(pDocument, pData->sFieldName,
3393 pData->nControlIndex, pData->num);
3394 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003395 case FP_CHARLIMIT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003396 Field::SetCharLimit(pDocument, pData->sFieldName, pData->nControlIndex,
3397 pData->num);
3398 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003399 case FP_COMB:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003400 Field::SetComb(pDocument, pData->sFieldName, pData->nControlIndex,
3401 pData->b);
3402 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003403 case FP_COMMITONSELCHANGE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003404 Field::SetCommitOnSelChange(pDocument, pData->sFieldName,
3405 pData->nControlIndex, pData->b);
3406 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003407 case FP_CURRENTVALUEINDICES:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003408 Field::SetCurrentValueIndices(pDocument, pData->sFieldName,
3409 pData->nControlIndex, pData->wordarray);
3410 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003411 case FP_DEFAULTVALUE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003412 Field::SetDefaultValue(pDocument, pData->sFieldName, pData->nControlIndex,
3413 pData->widestring);
3414 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003415 case FP_DONOTSCROLL:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003416 Field::SetDoNotScroll(pDocument, pData->sFieldName, pData->nControlIndex,
3417 pData->b);
3418 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003419 case FP_DISPLAY:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003420 Field::SetDisplay(pDocument, pData->sFieldName, pData->nControlIndex,
3421 pData->num);
3422 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003423 case FP_FILLCOLOR:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003424 Field::SetFillColor(pDocument, pData->sFieldName, pData->nControlIndex,
3425 pData->color);
3426 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003427 case FP_HIDDEN:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003428 Field::SetHidden(pDocument, pData->sFieldName, pData->nControlIndex,
3429 pData->b);
3430 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003431 case FP_HIGHLIGHT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003432 Field::SetHighlight(pDocument, pData->sFieldName, pData->nControlIndex,
3433 pData->string);
3434 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003435 case FP_LINEWIDTH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003436 Field::SetLineWidth(pDocument, pData->sFieldName, pData->nControlIndex,
3437 pData->num);
3438 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003439 case FP_MULTILINE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003440 Field::SetMultiline(pDocument, pData->sFieldName, pData->nControlIndex,
3441 pData->b);
3442 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003443 case FP_MULTIPLESELECTION:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003444 Field::SetMultipleSelection(pDocument, pData->sFieldName,
3445 pData->nControlIndex, pData->b);
3446 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003447 case FP_PASSWORD:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003448 Field::SetPassword(pDocument, pData->sFieldName, pData->nControlIndex,
3449 pData->b);
3450 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003451 case FP_RECT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003452 Field::SetRect(pDocument, pData->sFieldName, pData->nControlIndex,
3453 pData->rect);
3454 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003455 case FP_RICHTEXT:
dsinclaira2919b32016-07-13 10:55:48 -07003456 // Not supported.
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003457 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003458 case FP_RICHVALUE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003459 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003460 case FP_ROTATION:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003461 Field::SetRotation(pDocument, pData->sFieldName, pData->nControlIndex,
3462 pData->num);
3463 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003464 case FP_STROKECOLOR:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003465 Field::SetStrokeColor(pDocument, pData->sFieldName, pData->nControlIndex,
3466 pData->color);
3467 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003468 case FP_STYLE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003469 Field::SetStyle(pDocument, pData->sFieldName, pData->nControlIndex,
3470 pData->string);
3471 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003472 case FP_TEXTCOLOR:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003473 Field::SetTextColor(pDocument, pData->sFieldName, pData->nControlIndex,
3474 pData->color);
3475 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003476 case FP_TEXTFONT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003477 Field::SetTextFont(pDocument, pData->sFieldName, pData->nControlIndex,
3478 pData->string);
3479 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003480 case FP_TEXTSIZE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003481 Field::SetTextSize(pDocument, pData->sFieldName, pData->nControlIndex,
3482 pData->num);
3483 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003484 case FP_USERNAME:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003485 Field::SetUserName(pDocument, pData->sFieldName, pData->nControlIndex,
3486 pData->widestring);
3487 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003488 case FP_VALUE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003489 Field::SetValue(pDocument, pData->sFieldName, pData->nControlIndex,
3490 pData->widestringarray);
3491 break;
3492 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003493}
3494
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003495void Field::AddField(CPDFSDK_Document* pDocument,
3496 int nPageIndex,
3497 int nFieldType,
3498 const CFX_WideString& sName,
Tom Sepez281a9ea2016-02-26 14:24:28 -08003499 const CFX_FloatRect& rcCoords) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003500 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003501}