blob: 8d7fe1b1865206fcb48b6048ba1df0aeb3492528 [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
dan sinclair61b2fc72016-03-23 19:21:44 -040014#include "core/fpdfapi/fpdf_font/include/cpdf_font.h"
Dan Sinclair455a4192016-03-16 09:48:56 -040015#include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
Dan Sinclairaa403d32016-03-15 14:57:22 -040016#include "fpdfsdk/include/fsdk_mgr.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040017#include "fpdfsdk/javascript/Document.h"
18#include "fpdfsdk/javascript/Icon.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040019#include "fpdfsdk/javascript/JS_Define.h"
20#include "fpdfsdk/javascript/JS_EventHandler.h"
21#include "fpdfsdk/javascript/JS_Object.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040022#include "fpdfsdk/javascript/JS_Value.h"
23#include "fpdfsdk/javascript/PublicMethods.h"
dsinclair64376be2016-03-31 20:03:24 -070024#include "fpdfsdk/javascript/cjs_context.h"
25#include "fpdfsdk/javascript/cjs_runtime.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040026#include "fpdfsdk/javascript/color.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070027
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070028BEGIN_JS_STATIC_CONST(CJS_Field)
29END_JS_STATIC_CONST()
30
31BEGIN_JS_STATIC_PROP(CJS_Field)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070032JS_STATIC_PROP_ENTRY(alignment)
33JS_STATIC_PROP_ENTRY(borderStyle)
34JS_STATIC_PROP_ENTRY(buttonAlignX)
35JS_STATIC_PROP_ENTRY(buttonAlignY)
36JS_STATIC_PROP_ENTRY(buttonFitBounds)
37JS_STATIC_PROP_ENTRY(buttonPosition)
38JS_STATIC_PROP_ENTRY(buttonScaleHow)
39JS_STATIC_PROP_ENTRY(buttonScaleWhen)
40JS_STATIC_PROP_ENTRY(calcOrderIndex)
41JS_STATIC_PROP_ENTRY(charLimit)
42JS_STATIC_PROP_ENTRY(comb)
43JS_STATIC_PROP_ENTRY(commitOnSelChange)
44JS_STATIC_PROP_ENTRY(currentValueIndices)
45JS_STATIC_PROP_ENTRY(defaultStyle)
46JS_STATIC_PROP_ENTRY(defaultValue)
47JS_STATIC_PROP_ENTRY(doNotScroll)
48JS_STATIC_PROP_ENTRY(doNotSpellCheck)
49JS_STATIC_PROP_ENTRY(delay)
50JS_STATIC_PROP_ENTRY(display)
51JS_STATIC_PROP_ENTRY(doc)
52JS_STATIC_PROP_ENTRY(editable)
53JS_STATIC_PROP_ENTRY(exportValues)
54JS_STATIC_PROP_ENTRY(hidden)
55JS_STATIC_PROP_ENTRY(fileSelect)
56JS_STATIC_PROP_ENTRY(fillColor)
57JS_STATIC_PROP_ENTRY(lineWidth)
58JS_STATIC_PROP_ENTRY(highlight)
59JS_STATIC_PROP_ENTRY(multiline)
60JS_STATIC_PROP_ENTRY(multipleSelection)
61JS_STATIC_PROP_ENTRY(name)
62JS_STATIC_PROP_ENTRY(numItems)
63JS_STATIC_PROP_ENTRY(page)
64JS_STATIC_PROP_ENTRY(password)
65JS_STATIC_PROP_ENTRY(print)
66JS_STATIC_PROP_ENTRY(radiosInUnison)
67JS_STATIC_PROP_ENTRY(readonly)
68JS_STATIC_PROP_ENTRY(rect)
69JS_STATIC_PROP_ENTRY(required)
70JS_STATIC_PROP_ENTRY(richText)
71JS_STATIC_PROP_ENTRY(richValue)
72JS_STATIC_PROP_ENTRY(rotation)
73JS_STATIC_PROP_ENTRY(strokeColor)
74JS_STATIC_PROP_ENTRY(style)
75JS_STATIC_PROP_ENTRY(submitName)
76JS_STATIC_PROP_ENTRY(textColor)
77JS_STATIC_PROP_ENTRY(textFont)
78JS_STATIC_PROP_ENTRY(textSize)
79JS_STATIC_PROP_ENTRY(type)
80JS_STATIC_PROP_ENTRY(userName)
81JS_STATIC_PROP_ENTRY(value)
82JS_STATIC_PROP_ENTRY(valueAsString)
83JS_STATIC_PROP_ENTRY(source)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070084END_JS_STATIC_PROP()
85
86BEGIN_JS_STATIC_METHOD(CJS_Field)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070087JS_STATIC_METHOD_ENTRY(browseForFileToSubmit)
88JS_STATIC_METHOD_ENTRY(buttonGetCaption)
89JS_STATIC_METHOD_ENTRY(buttonGetIcon)
90JS_STATIC_METHOD_ENTRY(buttonImportIcon)
91JS_STATIC_METHOD_ENTRY(buttonSetCaption)
92JS_STATIC_METHOD_ENTRY(buttonSetIcon)
93JS_STATIC_METHOD_ENTRY(checkThisBox)
94JS_STATIC_METHOD_ENTRY(clearItems)
95JS_STATIC_METHOD_ENTRY(defaultIsChecked)
96JS_STATIC_METHOD_ENTRY(deleteItemAt)
97JS_STATIC_METHOD_ENTRY(getArray)
98JS_STATIC_METHOD_ENTRY(getItemAt)
99JS_STATIC_METHOD_ENTRY(getLock)
100JS_STATIC_METHOD_ENTRY(insertItemAt)
101JS_STATIC_METHOD_ENTRY(isBoxChecked)
102JS_STATIC_METHOD_ENTRY(isDefaultChecked)
103JS_STATIC_METHOD_ENTRY(setAction)
104JS_STATIC_METHOD_ENTRY(setFocus)
105JS_STATIC_METHOD_ENTRY(setItems)
106JS_STATIC_METHOD_ENTRY(setLock)
107JS_STATIC_METHOD_ENTRY(signatureGetModifications)
108JS_STATIC_METHOD_ENTRY(signatureGetSeedValue)
109JS_STATIC_METHOD_ENTRY(signatureInfo)
110JS_STATIC_METHOD_ENTRY(signatureSetSeedValue)
111JS_STATIC_METHOD_ENTRY(signatureSign)
112JS_STATIC_METHOD_ENTRY(signatureValidate)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700113END_JS_STATIC_METHOD()
114
115IMPLEMENT_JS_CLASS(CJS_Field, Field)
116
weili625ad662016-06-15 11:21:33 -0700117CJS_DelayData::CJS_DelayData(FIELD_PROP prop,
118 int idx,
119 const CFX_WideString& name)
120 : eProp(prop), nControlIndex(idx), sFieldName(name) {}
121
122CJS_DelayData::~CJS_DelayData() {}
123
Tom Sepez33420902015-10-13 15:00:10 -0700124void CJS_Field::InitInstance(IJS_Runtime* pIRuntime) {
125 CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime);
126 Field* pField = static_cast<Field*>(GetEmbedObject());
127 pField->SetIsolate(pRuntime->GetIsolate());
Lei Zhangd88a3642015-11-10 09:38:57 -0800128}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700129
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700130Field::Field(CJS_Object* pJSObject)
131 : CJS_EmbedObj(pJSObject),
thestig1cd352e2016-06-07 17:53:06 -0700132 m_pJSDoc(nullptr),
133 m_pDocument(nullptr),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700134 m_nFormControlIndex(-1),
135 m_bCanSet(FALSE),
136 m_bDelay(FALSE),
thestig1cd352e2016-06-07 17:53:06 -0700137 m_isolate(nullptr) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700138
139Field::~Field() {}
140
141// note: iControlNo = -1, means not a widget.
142void Field::ParseFieldName(const std::wstring& strFieldNameParsed,
143 std::wstring& strFieldName,
144 int& iControlNo) {
145 int iStart = strFieldNameParsed.find_last_of(L'.');
146 if (iStart == -1) {
147 strFieldName = strFieldNameParsed;
148 iControlNo = -1;
149 return;
150 }
151 std::wstring suffixal = strFieldNameParsed.substr(iStart + 1);
152 iControlNo = FXSYS_wtoi(suffixal.c_str());
153 if (iControlNo == 0) {
weilidb444d22016-06-02 15:48:15 -0700154 int iSpaceStart;
155 while ((iSpaceStart = suffixal.find_last_of(L" ")) != -1) {
156 suffixal.erase(iSpaceStart, 1);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700157 }
158
159 if (suffixal.compare(L"0") != 0) {
160 strFieldName = strFieldNameParsed;
161 iControlNo = -1;
162 return;
163 }
164 }
165 strFieldName = strFieldNameParsed.substr(0, iStart);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700166}
167
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700168FX_BOOL Field::AttachField(Document* pDocument,
169 const CFX_WideString& csFieldName) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700170 m_pJSDoc = pDocument;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700171 m_pDocument = pDocument->GetReaderDoc();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700172 m_bCanSet = m_pDocument->GetPermissions(FPDFPERM_FILL_FORM) ||
173 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
174 m_pDocument->GetPermissions(FPDFPERM_MODIFY);
175
176 CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700177 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700178 CFX_WideString swFieldNameTemp = csFieldName;
179 swFieldNameTemp.Replace(L"..", L".");
180
181 if (pInterForm->CountFields(swFieldNameTemp) <= 0) {
182 std::wstring strFieldName;
183 int iControlNo = -1;
184 ParseFieldName(swFieldNameTemp.c_str(), strFieldName, iControlNo);
185 if (iControlNo == -1)
186 return FALSE;
187
188 m_FieldName = strFieldName.c_str();
189 m_nFormControlIndex = iControlNo;
190 return TRUE;
191 }
192
193 m_FieldName = swFieldNameTemp;
194 m_nFormControlIndex = -1;
195
196 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700197}
198
Lei Zhangd88a3642015-11-10 09:38:57 -0800199std::vector<CPDF_FormField*> Field::GetFormFields(
200 CPDFSDK_Document* pDocument,
201 const CFX_WideString& csFieldName) {
202 std::vector<CPDF_FormField*> fields;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700203 CPDFSDK_InterForm* pReaderInterForm = pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700204 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -0800205 for (int i = 0, sz = pInterForm->CountFields(csFieldName); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700206 if (CPDF_FormField* pFormField = pInterForm->GetField(i, csFieldName))
Lei Zhangd88a3642015-11-10 09:38:57 -0800207 fields.push_back(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700208 }
Lei Zhangd88a3642015-11-10 09:38:57 -0800209 return fields;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700210}
211
Lei Zhangd88a3642015-11-10 09:38:57 -0800212std::vector<CPDF_FormField*> Field::GetFormFields(
213 const CFX_WideString& csFieldName) const {
214 return Field::GetFormFields(m_pDocument, csFieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700215}
216
217void Field::UpdateFormField(CPDFSDK_Document* pDocument,
218 CPDF_FormField* pFormField,
219 FX_BOOL bChangeMark,
220 FX_BOOL bResetAP,
221 FX_BOOL bRefresh) {
Lei Zhangd88a3642015-11-10 09:38:57 -0800222 std::vector<CPDFSDK_Widget*> widgets;
tsepez23ae4a52016-06-08 20:44:54 -0700223 CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -0800224 pInterForm->GetWidgets(pFormField, &widgets);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700225
226 if (bResetAP) {
227 int nFieldType = pFormField->GetFieldType();
228 if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_TEXTFIELD) {
Lei Zhangd88a3642015-11-10 09:38:57 -0800229 for (CPDFSDK_Widget* pWidget : widgets) {
230 FX_BOOL bFormatted = FALSE;
231 CFX_WideString sValue = pWidget->OnFormat(bFormatted);
232 pWidget->ResetAppearance(bFormatted ? sValue.c_str() : nullptr, FALSE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700233 }
234 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800235 for (CPDFSDK_Widget* pWidget : widgets) {
236 pWidget->ResetAppearance(nullptr, FALSE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700237 }
238 }
239 }
240
241 if (bRefresh) {
Lei Zhangd88a3642015-11-10 09:38:57 -0800242 for (CPDFSDK_Widget* pWidget : widgets) {
243 CPDFSDK_Document* pDoc = pWidget->GetInterForm()->GetDocument();
244 pDoc->UpdateAllViews(nullptr, pWidget);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700245 }
246 }
247
248 if (bChangeMark)
249 pDocument->SetChangeMark();
250}
251
252void Field::UpdateFormControl(CPDFSDK_Document* pDocument,
253 CPDF_FormControl* pFormControl,
254 FX_BOOL bChangeMark,
255 FX_BOOL bResetAP,
256 FX_BOOL bRefresh) {
Lei Zhang96660d62015-12-14 18:27:25 -0800257 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700258
tsepez23ae4a52016-06-08 20:44:54 -0700259 CPDFSDK_InterForm* pForm = pDocument->GetInterForm();
weilidb444d22016-06-02 15:48:15 -0700260 CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700261
262 if (pWidget) {
263 if (bResetAP) {
264 int nFieldType = pWidget->GetFieldType();
265 if (nFieldType == FIELDTYPE_COMBOBOX ||
266 nFieldType == FIELDTYPE_TEXTFIELD) {
267 FX_BOOL bFormated = FALSE;
268 CFX_WideString sValue = pWidget->OnFormat(bFormated);
269 if (bFormated)
270 pWidget->ResetAppearance(sValue.c_str(), FALSE);
271 else
thestig1cd352e2016-06-07 17:53:06 -0700272 pWidget->ResetAppearance(nullptr, FALSE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700273 } else {
thestig1cd352e2016-06-07 17:53:06 -0700274 pWidget->ResetAppearance(nullptr, FALSE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700275 }
276 }
277
278 if (bRefresh) {
279 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
280 CPDFSDK_Document* pDoc = pInterForm->GetDocument();
thestig1cd352e2016-06-07 17:53:06 -0700281 pDoc->UpdateAllViews(nullptr, pWidget);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700282 }
283 }
284
285 if (bChangeMark)
286 pDocument->SetChangeMark();
287}
288
289CPDFSDK_Widget* Field::GetWidget(CPDFSDK_Document* pDocument,
290 CPDF_FormControl* pFormControl) {
Jun Fang14b20db2015-12-01 12:35:24 +0800291 CPDFSDK_InterForm* pInterForm =
292 static_cast<CPDFSDK_InterForm*>(pDocument->GetInterForm());
293 return pInterForm ? pInterForm->GetWidget(pFormControl) : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700294}
295
296FX_BOOL Field::ValueIsOccur(CPDF_FormField* pFormField,
297 CFX_WideString csOptLabel) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700298 for (int i = 0, sz = pFormField->CountOptions(); i < sz; i++) {
299 if (csOptLabel.Compare(pFormField->GetOptionLabel(i)) == 0)
300 return TRUE;
301 }
302
303 return FALSE;
304}
305
306CPDF_FormControl* Field::GetSmartFieldControl(CPDF_FormField* pFormField) {
307 if (!pFormField->CountControls() ||
308 m_nFormControlIndex >= pFormField->CountControls())
thestig1cd352e2016-06-07 17:53:06 -0700309 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700310
311 if (m_nFormControlIndex < 0)
312 return pFormField->GetControl(0);
313
314 return pFormField->GetControl(m_nFormControlIndex);
315}
316
Tom Sepezba038bc2015-10-08 12:03:00 -0700317FX_BOOL Field::alignment(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700318 CJS_PropValue& vp,
319 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800320 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700321
322 if (vp.IsSetting()) {
323 if (!m_bCanSet)
324 return FALSE;
325
326 CFX_ByteString alignStr;
327 vp >> alignStr;
328
329 if (m_bDelay) {
330 AddDelay_String(FP_ALIGNMENT, alignStr);
331 } else {
332 Field::SetAlignment(m_pDocument, m_FieldName, m_nFormControlIndex,
333 alignStr);
334 }
335 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800336 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
337 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700338 return FALSE;
339
Lei Zhangd88a3642015-11-10 09:38:57 -0800340 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700341 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
342 return FALSE;
343
344 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
345 if (!pFormControl)
346 return FALSE;
347
348 switch (pFormControl->GetControlAlignment()) {
349 case 1:
350 vp << L"center";
351 break;
352 case 0:
353 vp << L"left";
354 break;
355 case 2:
356 vp << L"right";
357 break;
358 default:
359 vp << L"";
360 }
361 }
362
363 return TRUE;
364}
365
366void Field::SetAlignment(CPDFSDK_Document* pDocument,
367 const CFX_WideString& swFieldName,
368 int nControlIndex,
369 const CFX_ByteString& string) {
370 // Not supported.
371}
372
Tom Sepezba038bc2015-10-08 12:03:00 -0700373FX_BOOL Field::borderStyle(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700374 CJS_PropValue& vp,
375 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800376 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700377
378 if (vp.IsSetting()) {
379 if (!m_bCanSet)
380 return FALSE;
381
382 CFX_ByteString strType = "";
383 vp >> strType;
384
385 if (m_bDelay) {
386 AddDelay_String(FP_BORDERSTYLE, strType);
387 } else {
388 Field::SetBorderStyle(m_pDocument, m_FieldName, m_nFormControlIndex,
389 strType);
390 }
391 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800392 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
393 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700394 return FALSE;
395
Lei Zhangd88a3642015-11-10 09:38:57 -0800396 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700397 if (!pFormField)
398 return FALSE;
399
400 CPDFSDK_Widget* pWidget =
401 GetWidget(m_pDocument, GetSmartFieldControl(pFormField));
402 if (!pWidget)
403 return FALSE;
404
dsinclair92cb5e52016-05-16 11:38:28 -0700405 switch (pWidget->GetBorderStyle()) {
406 case BorderStyle::SOLID:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700407 vp << L"solid";
408 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700409 case BorderStyle::DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700410 vp << L"dashed";
411 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700412 case BorderStyle::BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700413 vp << L"beveled";
414 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700415 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700416 vp << L"inset";
417 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700418 case BorderStyle::UNDERLINE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700419 vp << L"underline";
420 break;
421 default:
422 vp << L"";
423 break;
424 }
425 }
426
427 return TRUE;
428}
429
430void Field::SetBorderStyle(CPDFSDK_Document* pDocument,
431 const CFX_WideString& swFieldName,
432 int nControlIndex,
433 const CFX_ByteString& string) {
Lei Zhang96660d62015-12-14 18:27:25 -0800434 ASSERT(pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700435
dsinclair92cb5e52016-05-16 11:38:28 -0700436 BorderStyle nBorderStyle = BorderStyle::SOLID;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700437 if (string == "solid")
dsinclair92cb5e52016-05-16 11:38:28 -0700438 nBorderStyle = BorderStyle::SOLID;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700439 else if (string == "beveled")
dsinclair92cb5e52016-05-16 11:38:28 -0700440 nBorderStyle = BorderStyle::BEVELED;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700441 else if (string == "dashed")
dsinclair92cb5e52016-05-16 11:38:28 -0700442 nBorderStyle = BorderStyle::DASH;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700443 else if (string == "inset")
dsinclair92cb5e52016-05-16 11:38:28 -0700444 nBorderStyle = BorderStyle::INSET;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700445 else if (string == "underline")
dsinclair92cb5e52016-05-16 11:38:28 -0700446 nBorderStyle = BorderStyle::UNDERLINE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700447 else
448 return;
449
Lei Zhangd88a3642015-11-10 09:38:57 -0800450 std::vector<CPDF_FormField*> FieldArray =
451 GetFormFields(pDocument, swFieldName);
452 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700453 if (nControlIndex < 0) {
454 FX_BOOL bSet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -0800455 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700456 if (CPDFSDK_Widget* pWidget =
Lei Zhangd88a3642015-11-10 09:38:57 -0800457 GetWidget(pDocument, pFormField->GetControl(i))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700458 if (pWidget->GetBorderStyle() != nBorderStyle) {
459 pWidget->SetBorderStyle(nBorderStyle);
460 bSet = TRUE;
461 }
462 }
463 }
464 if (bSet)
465 UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
466 } else {
467 if (nControlIndex >= pFormField->CountControls())
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700468 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700469 if (CPDF_FormControl* pFormControl =
470 pFormField->GetControl(nControlIndex)) {
471 if (CPDFSDK_Widget* pWidget = GetWidget(pDocument, pFormControl)) {
472 if (pWidget->GetBorderStyle() != nBorderStyle) {
473 pWidget->SetBorderStyle(nBorderStyle);
474 UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
475 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700476 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700477 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700478 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700479 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700480}
481
Tom Sepezba038bc2015-10-08 12:03:00 -0700482FX_BOOL Field::buttonAlignX(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700483 CJS_PropValue& vp,
484 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800485 ASSERT(m_pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700486
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700487 if (vp.IsSetting()) {
488 if (!m_bCanSet)
489 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700490
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700491 int nVP;
492 vp >> nVP;
493
494 if (m_bDelay) {
495 AddDelay_Int(FP_BUTTONALIGNX, nVP);
496 } else {
497 Field::SetButtonAlignX(m_pDocument, m_FieldName, m_nFormControlIndex,
498 nVP);
499 }
500 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800501 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
502 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700503 return FALSE;
504
Lei Zhangd88a3642015-11-10 09:38:57 -0800505 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700506 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
507 return FALSE;
508
509 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
510 if (!pFormControl)
511 return FALSE;
512
513 CPDF_IconFit IconFit = pFormControl->GetIconFit();
514
515 FX_FLOAT fLeft, fBottom;
516 IconFit.GetIconPosition(fLeft, fBottom);
517
518 vp << (int32_t)fLeft;
519 }
520
521 return TRUE;
522}
523
524void Field::SetButtonAlignX(CPDFSDK_Document* pDocument,
525 const CFX_WideString& swFieldName,
526 int nControlIndex,
527 int number) {
528 // Not supported.
529}
530
Tom Sepezba038bc2015-10-08 12:03:00 -0700531FX_BOOL Field::buttonAlignY(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700532 CJS_PropValue& vp,
533 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800534 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700535
536 if (vp.IsSetting()) {
537 if (!m_bCanSet)
538 return FALSE;
539
540 int nVP;
541 vp >> nVP;
542
543 if (m_bDelay) {
544 AddDelay_Int(FP_BUTTONALIGNY, nVP);
545 } else {
546 Field::SetButtonAlignY(m_pDocument, m_FieldName, m_nFormControlIndex,
547 nVP);
548 }
549 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800550 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
551 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700552 return FALSE;
553
Lei Zhangd88a3642015-11-10 09:38:57 -0800554 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700555 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
556 return FALSE;
557
558 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
559 if (!pFormControl)
560 return FALSE;
561
562 CPDF_IconFit IconFit = pFormControl->GetIconFit();
563
564 FX_FLOAT fLeft, fBottom;
565 IconFit.GetIconPosition(fLeft, fBottom);
566
567 vp << (int32_t)fBottom;
568 }
569
570 return TRUE;
571}
572
573void Field::SetButtonAlignY(CPDFSDK_Document* pDocument,
574 const CFX_WideString& swFieldName,
575 int nControlIndex,
576 int number) {
577 // Not supported.
578}
579
Tom Sepezba038bc2015-10-08 12:03:00 -0700580FX_BOOL Field::buttonFitBounds(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700581 CJS_PropValue& vp,
582 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800583 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700584
585 if (vp.IsSetting()) {
586 if (!m_bCanSet)
587 return FALSE;
588
589 bool bVP;
590 vp >> bVP;
591
592 if (m_bDelay) {
593 AddDelay_Bool(FP_BUTTONFITBOUNDS, bVP);
594 } else {
595 Field::SetButtonFitBounds(m_pDocument, m_FieldName, m_nFormControlIndex,
596 bVP);
597 }
598 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800599 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
600 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700601 return FALSE;
602
Lei Zhangd88a3642015-11-10 09:38:57 -0800603 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700604 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
605 return FALSE;
606
607 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
608 if (!pFormControl)
609 return FALSE;
610
thestigded36342016-05-23 17:54:02 -0700611 vp << pFormControl->GetIconFit().GetFittingBounds();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700612 }
613
614 return TRUE;
615}
616
617void Field::SetButtonFitBounds(CPDFSDK_Document* pDocument,
618 const CFX_WideString& swFieldName,
619 int nControlIndex,
620 bool b) {
621 // Not supported.
622}
623
Tom Sepezba038bc2015-10-08 12:03:00 -0700624FX_BOOL Field::buttonPosition(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700625 CJS_PropValue& vp,
626 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800627 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700628
629 if (vp.IsSetting()) {
630 if (!m_bCanSet)
631 return FALSE;
632
633 int nVP;
634 vp >> nVP;
635
636 if (m_bDelay) {
637 AddDelay_Int(FP_BUTTONPOSITION, nVP);
638 } else {
639 Field::SetButtonPosition(m_pDocument, m_FieldName, m_nFormControlIndex,
640 nVP);
641 }
642 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800643 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
644 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700645 return FALSE;
646
Lei Zhangd88a3642015-11-10 09:38:57 -0800647 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700648 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
649 return FALSE;
650
651 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
652 if (!pFormControl)
653 return FALSE;
654
655 vp << pFormControl->GetTextPosition();
656 }
657 return TRUE;
658}
659
660void Field::SetButtonPosition(CPDFSDK_Document* pDocument,
661 const CFX_WideString& swFieldName,
662 int nControlIndex,
663 int number) {
664 // Not supported.
665}
666
Tom Sepezba038bc2015-10-08 12:03:00 -0700667FX_BOOL Field::buttonScaleHow(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700668 CJS_PropValue& vp,
669 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800670 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700671
672 if (vp.IsSetting()) {
673 if (!m_bCanSet)
674 return FALSE;
675
676 int nVP;
677 vp >> nVP;
678
679 if (m_bDelay) {
680 AddDelay_Int(FP_BUTTONSCALEHOW, nVP);
681 } else {
682 Field::SetButtonScaleHow(m_pDocument, m_FieldName, m_nFormControlIndex,
683 nVP);
684 }
685 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800686 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
687 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700688 return FALSE;
689
Lei Zhangd88a3642015-11-10 09:38:57 -0800690 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700691 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
692 return FALSE;
693
694 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
695 if (!pFormControl)
696 return FALSE;
697
698 CPDF_IconFit IconFit = pFormControl->GetIconFit();
699 if (IconFit.IsProportionalScale())
700 vp << (int32_t)0;
701 else
702 vp << (int32_t)1;
703 }
704
705 return TRUE;
706}
707
708void Field::SetButtonScaleHow(CPDFSDK_Document* pDocument,
709 const CFX_WideString& swFieldName,
710 int nControlIndex,
711 int number) {
712 // Not supported.
713}
714
Tom Sepezba038bc2015-10-08 12:03:00 -0700715FX_BOOL Field::buttonScaleWhen(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700716 CJS_PropValue& vp,
717 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800718 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700719
720 if (vp.IsSetting()) {
721 if (!m_bCanSet)
722 return FALSE;
723
724 int nVP;
725 vp >> nVP;
726
727 if (m_bDelay) {
728 AddDelay_Int(FP_BUTTONSCALEWHEN, nVP);
729 } else {
730 Field::SetButtonScaleWhen(m_pDocument, m_FieldName, m_nFormControlIndex,
731 nVP);
732 }
733 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800734 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
735 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700736 return FALSE;
737
Lei Zhangd88a3642015-11-10 09:38:57 -0800738 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700739 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
740 return FALSE;
741
742 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
743 if (!pFormControl)
744 return FALSE;
745
746 CPDF_IconFit IconFit = pFormControl->GetIconFit();
747 int ScaleM = IconFit.GetScaleMethod();
748 switch (ScaleM) {
749 case CPDF_IconFit::Always:
750 vp << (int32_t)CPDF_IconFit::Always;
751 break;
752 case CPDF_IconFit::Bigger:
753 vp << (int32_t)CPDF_IconFit::Bigger;
754 break;
755 case CPDF_IconFit::Never:
756 vp << (int32_t)CPDF_IconFit::Never;
757 break;
758 case CPDF_IconFit::Smaller:
759 vp << (int32_t)CPDF_IconFit::Smaller;
760 break;
761 }
762 }
763
764 return TRUE;
765}
766
767void Field::SetButtonScaleWhen(CPDFSDK_Document* pDocument,
768 const CFX_WideString& swFieldName,
769 int nControlIndex,
770 int number) {
771 // Not supported.
772}
773
Tom Sepezba038bc2015-10-08 12:03:00 -0700774FX_BOOL Field::calcOrderIndex(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700775 CJS_PropValue& vp,
776 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800777 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700778
779 if (vp.IsSetting()) {
780 if (!m_bCanSet)
781 return FALSE;
782
783 int nVP;
784 vp >> nVP;
785
786 if (m_bDelay) {
787 AddDelay_Int(FP_CALCORDERINDEX, nVP);
788 } else {
789 Field::SetCalcOrderIndex(m_pDocument, m_FieldName, m_nFormControlIndex,
790 nVP);
791 }
792 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800793 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
794 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700795 return FALSE;
796
Lei Zhangd88a3642015-11-10 09:38:57 -0800797 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700798 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -0800799 pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700800 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -0800801 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700802
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700803 CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700804 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700805 vp << (int32_t)pInterForm->FindFieldInCalculationOrder(pFormField);
806 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700807
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700808 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700809}
810
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700811void Field::SetCalcOrderIndex(CPDFSDK_Document* pDocument,
812 const CFX_WideString& swFieldName,
813 int nControlIndex,
814 int number) {
815 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700816}
817
Tom Sepezba038bc2015-10-08 12:03:00 -0700818FX_BOOL Field::charLimit(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700819 CJS_PropValue& vp,
820 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800821 ASSERT(m_pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700822
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700823 if (vp.IsSetting()) {
824 if (!m_bCanSet)
825 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700826
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700827 int nVP;
828 vp >> nVP;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700829
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700830 if (m_bDelay) {
831 AddDelay_Int(FP_CHARLIMIT, nVP);
832 } else {
833 Field::SetCharLimit(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700834 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700835 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800836 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
837 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700838 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700839
Lei Zhangd88a3642015-11-10 09:38:57 -0800840 CPDF_FormField* pFormField = FieldArray[0];
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700841 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700842 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700843
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700844 vp << (int32_t)pFormField->GetMaxLen();
845 }
846 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700847}
848
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700849void Field::SetCharLimit(CPDFSDK_Document* pDocument,
850 const CFX_WideString& swFieldName,
851 int nControlIndex,
852 int number) {
853 // Not supported.
854}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700855
Tom Sepezba038bc2015-10-08 12:03:00 -0700856FX_BOOL Field::comb(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700857 CJS_PropValue& vp,
858 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800859 ASSERT(m_pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700860
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700861 if (vp.IsSetting()) {
862 if (!m_bCanSet)
863 return FALSE;
864
865 bool bVP;
866 vp >> bVP;
867
868 if (m_bDelay) {
869 AddDelay_Bool(FP_COMB, bVP);
870 } else {
871 Field::SetComb(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
872 }
873 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800874 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
875 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700876 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700877
Lei Zhangd88a3642015-11-10 09:38:57 -0800878 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700879 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
880 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700881
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700882 if (pFormField->GetFieldFlags() & FIELDFLAG_COMB)
883 vp << true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700884 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700885 vp << false;
886 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700887
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700888 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700889}
890
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700891void Field::SetComb(CPDFSDK_Document* pDocument,
892 const CFX_WideString& swFieldName,
893 int nControlIndex,
894 bool b) {
895 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700896}
897
Tom Sepezba038bc2015-10-08 12:03:00 -0700898FX_BOOL Field::commitOnSelChange(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700899 CJS_PropValue& vp,
900 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800901 ASSERT(m_pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700902
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700903 if (vp.IsSetting()) {
904 if (!m_bCanSet)
905 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700906
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700907 bool bVP;
908 vp >> bVP;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700909
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700910 if (m_bDelay) {
911 AddDelay_Bool(FP_COMMITONSELCHANGE, bVP);
912 } else {
913 Field::SetCommitOnSelChange(m_pDocument, m_FieldName, m_nFormControlIndex,
914 bVP);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700915 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700916 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800917 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
918 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700919 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700920
Lei Zhangd88a3642015-11-10 09:38:57 -0800921 CPDF_FormField* pFormField = FieldArray[0];
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700922 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -0800923 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700924 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -0800925 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700926
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700927 if (pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE)
928 vp << true;
929 else
930 vp << false;
931 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700932
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700933 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700934}
935
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700936void Field::SetCommitOnSelChange(CPDFSDK_Document* pDocument,
937 const CFX_WideString& swFieldName,
938 int nControlIndex,
939 bool b) {
940 // Not supported.
941}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700942
Tom Sepezba038bc2015-10-08 12:03:00 -0700943FX_BOOL Field::currentValueIndices(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700944 CJS_PropValue& vp,
945 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -0700946 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700947
948 if (vp.IsSetting()) {
949 if (!m_bCanSet)
950 return FALSE;
951
tsepez41a53ad2016-03-28 16:59:30 -0700952 std::vector<uint32_t> array;
Tom Sepez39bfe122015-09-17 15:25:23 -0700953 if (vp.GetType() == CJS_Value::VT_number) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700954 int iSelecting = 0;
955 vp >> iSelecting;
tsepez41a53ad2016-03-28 16:59:30 -0700956 array.push_back(iSelecting);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700957 } else if (vp.IsArrayObject()) {
Tom Sepez67fd5df2015-10-08 12:24:19 -0700958 CJS_Array SelArray(pRuntime);
959 CJS_Value SelValue(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700960 int iSelecting;
961 vp >> SelArray;
962 for (int i = 0, sz = SelArray.GetLength(); i < sz; i++) {
963 SelArray.GetElement(i, SelValue);
964 iSelecting = SelValue.ToInt();
tsepez41a53ad2016-03-28 16:59:30 -0700965 array.push_back(iSelecting);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700966 }
967 }
968
969 if (m_bDelay) {
970 AddDelay_WordArray(FP_CURRENTVALUEINDICES, array);
971 } else {
972 Field::SetCurrentValueIndices(m_pDocument, m_FieldName,
973 m_nFormControlIndex, array);
974 }
975 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800976 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
977 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700978 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700979
Lei Zhangd88a3642015-11-10 09:38:57 -0800980 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700981 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -0800982 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700983 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -0800984 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700985
Lei Zhangd88a3642015-11-10 09:38:57 -0800986 if (pFormField->CountSelectedItems() == 1) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700987 vp << pFormField->GetSelectedIndex(0);
Lei Zhangd88a3642015-11-10 09:38:57 -0800988 } else if (pFormField->CountSelectedItems() > 1) {
Tom Sepez67fd5df2015-10-08 12:24:19 -0700989 CJS_Array SelArray(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700990 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
991 SelArray.SetElement(
Tom Sepez67fd5df2015-10-08 12:24:19 -0700992 i, CJS_Value(pRuntime, pFormField->GetSelectedIndex(i)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700993 }
994 vp << SelArray;
Lei Zhangd88a3642015-11-10 09:38:57 -0800995 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700996 vp << -1;
Lei Zhangd88a3642015-11-10 09:38:57 -0800997 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700998 }
999
1000 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001001}
1002
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001003void Field::SetCurrentValueIndices(CPDFSDK_Document* pDocument,
1004 const CFX_WideString& swFieldName,
1005 int nControlIndex,
tsepez41a53ad2016-03-28 16:59:30 -07001006 const std::vector<uint32_t>& array) {
Lei Zhang96660d62015-12-14 18:27:25 -08001007 ASSERT(pDocument);
Lei Zhangd88a3642015-11-10 09:38:57 -08001008 std::vector<CPDF_FormField*> FieldArray =
1009 GetFormFields(pDocument, swFieldName);
tsepez41a53ad2016-03-28 16:59:30 -07001010
Lei Zhangd88a3642015-11-10 09:38:57 -08001011 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001012 int nFieldType = pFormField->GetFieldType();
1013 if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX) {
tsepezc3255f52016-03-25 14:52:27 -07001014 uint32_t dwFieldFlags = pFormField->GetFieldFlags();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001015 pFormField->ClearSelection(TRUE);
tsepez41a53ad2016-03-28 16:59:30 -07001016 for (size_t i = 0; i < array.size(); ++i) {
1017 if (i != 0 && !(dwFieldFlags & (1 << 21)))
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001018 break;
Wei Li05d53f02016-03-29 16:42:53 -07001019 if (array[i] < static_cast<uint32_t>(pFormField->CountOptions()) &&
tsepez41a53ad2016-03-28 16:59:30 -07001020 !pFormField->IsItemSelected(array[i])) {
1021 pFormField->SetItemSelection(array[i], TRUE);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001022 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001023 }
1024 UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001025 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001026 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001027}
1028
Tom Sepezba038bc2015-10-08 12:03:00 -07001029FX_BOOL Field::defaultStyle(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001030 CJS_PropValue& vp,
1031 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001032 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001033}
1034
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001035void Field::SetDefaultStyle(CPDFSDK_Document* pDocument,
1036 const CFX_WideString& swFieldName,
1037 int nControlIndex) {
1038 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001039}
1040
Tom Sepezba038bc2015-10-08 12:03:00 -07001041FX_BOOL Field::defaultValue(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001042 CJS_PropValue& vp,
1043 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08001044 ASSERT(m_pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001045
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001046 if (vp.IsSetting()) {
1047 if (!m_bCanSet)
1048 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001049
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001050 CFX_WideString WideStr;
1051 vp >> WideStr;
1052
1053 if (m_bDelay) {
1054 AddDelay_WideString(FP_DEFAULTVALUE, WideStr);
1055 } else {
1056 Field::SetDefaultValue(m_pDocument, m_FieldName, m_nFormControlIndex,
1057 WideStr);
1058 }
1059 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001060 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1061 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001062 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001063
Lei Zhangd88a3642015-11-10 09:38:57 -08001064 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001065 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON ||
Lei Zhangd88a3642015-11-10 09:38:57 -08001066 pFormField->GetFieldType() == FIELDTYPE_SIGNATURE) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001067 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001068 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001069
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001070 vp << pFormField->GetDefaultValue();
1071 }
1072 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001073}
1074
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001075void Field::SetDefaultValue(CPDFSDK_Document* pDocument,
1076 const CFX_WideString& swFieldName,
1077 int nControlIndex,
1078 const CFX_WideString& string) {
1079 // Not supported.
1080}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001081
Tom Sepezba038bc2015-10-08 12:03:00 -07001082FX_BOOL Field::doNotScroll(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001083 CJS_PropValue& vp,
1084 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08001085 ASSERT(m_pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001086
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001087 if (vp.IsSetting()) {
1088 if (!m_bCanSet)
1089 return FALSE;
1090
1091 bool bVP;
1092 vp >> bVP;
1093
1094 if (m_bDelay) {
1095 AddDelay_Bool(FP_DONOTSCROLL, bVP);
1096 } else {
1097 Field::SetDoNotScroll(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
1098 }
1099 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001100 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1101 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001102 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001103
Lei Zhangd88a3642015-11-10 09:38:57 -08001104 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001105 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1106 return FALSE;
1107
1108 if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL)
1109 vp << true;
1110 else
1111 vp << false;
1112 }
1113
1114 return TRUE;
1115}
1116
1117void Field::SetDoNotScroll(CPDFSDK_Document* pDocument,
1118 const CFX_WideString& swFieldName,
1119 int nControlIndex,
1120 bool b) {
1121 // Not supported.
1122}
1123
Tom Sepezba038bc2015-10-08 12:03:00 -07001124FX_BOOL Field::doNotSpellCheck(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001125 CJS_PropValue& vp,
1126 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08001127 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001128
1129 if (vp.IsSetting()) {
1130 if (!m_bCanSet)
1131 return FALSE;
1132
1133 bool bVP;
1134 vp >> bVP;
1135 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001136 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1137 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001138 return FALSE;
1139
Lei Zhangd88a3642015-11-10 09:38:57 -08001140 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001141 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001142 pFormField->GetFieldType() != FIELDTYPE_COMBOBOX) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001143 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001144 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001145
1146 if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK)
1147 vp << true;
1148 else
1149 vp << false;
1150 }
1151
1152 return TRUE;
1153}
1154
1155void Field::SetDelay(FX_BOOL bDelay) {
1156 m_bDelay = bDelay;
1157
1158 if (!m_bDelay) {
1159 if (m_pJSDoc)
1160 m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex);
1161 }
1162}
1163
Tom Sepezba038bc2015-10-08 12:03:00 -07001164FX_BOOL Field::delay(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001165 CJS_PropValue& vp,
1166 CFX_WideString& sError) {
1167 if (vp.IsSetting()) {
1168 if (!m_bCanSet)
1169 return FALSE;
1170
1171 bool bVP;
1172 vp >> bVP;
1173
1174 SetDelay(bVP);
1175 } else {
1176 vp << m_bDelay;
1177 }
1178 return TRUE;
1179}
1180
Tom Sepezba038bc2015-10-08 12:03:00 -07001181FX_BOOL Field::display(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001182 CJS_PropValue& vp,
1183 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001184 if (vp.IsSetting()) {
1185 if (!m_bCanSet)
1186 return FALSE;
1187
1188 int nVP;
1189 vp >> nVP;
1190
1191 if (m_bDelay) {
1192 AddDelay_Int(FP_DISPLAY, nVP);
1193 } else {
1194 Field::SetDisplay(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
1195 }
1196 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001197 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1198 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001199 return FALSE;
1200
Lei Zhangd88a3642015-11-10 09:38:57 -08001201 CPDF_FormField* pFormField = FieldArray[0];
1202 ASSERT(pFormField);
tsepez23ae4a52016-06-08 20:44:54 -07001203 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001204 CPDFSDK_Widget* pWidget =
1205 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1206 if (!pWidget)
1207 return FALSE;
1208
tsepezc3255f52016-03-25 14:52:27 -07001209 uint32_t dwFlag = pWidget->GetFlags();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001210
1211 if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag) {
1212 vp << (int32_t)1;
1213 } else {
1214 if (ANNOTFLAG_PRINT & dwFlag) {
1215 if (ANNOTFLAG_NOVIEW & dwFlag) {
1216 vp << (int32_t)3;
1217 } else {
1218 vp << (int32_t)0;
1219 }
1220 } else {
1221 vp << (int32_t)2;
1222 }
1223 }
1224 }
1225
1226 return TRUE;
1227}
1228
1229void Field::SetDisplay(CPDFSDK_Document* pDocument,
1230 const CFX_WideString& swFieldName,
1231 int nControlIndex,
1232 int number) {
tsepez23ae4a52016-06-08 20:44:54 -07001233 CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001234 std::vector<CPDF_FormField*> FieldArray =
1235 GetFormFields(pDocument, swFieldName);
1236 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001237 if (nControlIndex < 0) {
1238 FX_BOOL bSet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001239 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1240 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08001241 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001242
1243 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
tsepezc3255f52016-03-25 14:52:27 -07001244 uint32_t dwFlag = pWidget->GetFlags();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001245 switch (number) {
1246 case 0:
1247 dwFlag &= (~ANNOTFLAG_INVISIBLE);
1248 dwFlag &= (~ANNOTFLAG_HIDDEN);
1249 dwFlag &= (~ANNOTFLAG_NOVIEW);
1250 dwFlag |= ANNOTFLAG_PRINT;
1251 break;
1252 case 1:
1253 dwFlag &= (~ANNOTFLAG_INVISIBLE);
1254 dwFlag &= (~ANNOTFLAG_NOVIEW);
1255 dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
1256 break;
1257 case 2:
1258 dwFlag &= (~ANNOTFLAG_INVISIBLE);
1259 dwFlag &= (~ANNOTFLAG_PRINT);
1260 dwFlag &= (~ANNOTFLAG_HIDDEN);
1261 dwFlag &= (~ANNOTFLAG_NOVIEW);
1262 break;
1263 case 3:
1264 dwFlag |= ANNOTFLAG_NOVIEW;
1265 dwFlag |= ANNOTFLAG_PRINT;
1266 dwFlag &= (~ANNOTFLAG_HIDDEN);
1267 break;
1268 }
1269
1270 if (dwFlag != pWidget->GetFlags()) {
1271 pWidget->SetFlags(dwFlag);
1272 bSet = TRUE;
1273 }
1274 }
1275 }
1276
1277 if (bSet)
1278 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
1279 } else {
1280 if (nControlIndex >= pFormField->CountControls())
1281 return;
1282 if (CPDF_FormControl* pFormControl =
1283 pFormField->GetControl(nControlIndex)) {
1284 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
tsepezc3255f52016-03-25 14:52:27 -07001285 uint32_t dwFlag = pWidget->GetFlags();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001286 switch (number) {
1287 case 0:
1288 dwFlag &= (~ANNOTFLAG_INVISIBLE);
1289 dwFlag &= (~ANNOTFLAG_HIDDEN);
1290 dwFlag &= (~ANNOTFLAG_NOVIEW);
1291 dwFlag |= ANNOTFLAG_PRINT;
1292 break;
1293 case 1:
1294 dwFlag &= (~ANNOTFLAG_INVISIBLE);
1295 dwFlag &= (~ANNOTFLAG_NOVIEW);
1296 dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
1297 break;
1298 case 2:
1299 dwFlag &= (~ANNOTFLAG_INVISIBLE);
1300 dwFlag &= (~ANNOTFLAG_PRINT);
1301 dwFlag &= (~ANNOTFLAG_HIDDEN);
1302 dwFlag &= (~ANNOTFLAG_NOVIEW);
1303 break;
1304 case 3:
1305 dwFlag |= ANNOTFLAG_NOVIEW;
1306 dwFlag |= ANNOTFLAG_PRINT;
1307 dwFlag &= (~ANNOTFLAG_HIDDEN);
1308 break;
1309 }
1310 if (dwFlag != pWidget->GetFlags()) {
1311 pWidget->SetFlags(dwFlag);
1312 UpdateFormControl(pDocument, pFormControl, TRUE, FALSE, TRUE);
1313 }
1314 }
1315 }
1316 }
1317 }
1318}
1319
Tom Sepezba038bc2015-10-08 12:03:00 -07001320FX_BOOL Field::doc(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001321 if (!vp.IsGetting()) {
1322 return FALSE;
1323 }
1324 vp << m_pJSDoc->GetCJSDoc();
1325 return TRUE;
1326}
1327
Tom Sepezba038bc2015-10-08 12:03:00 -07001328FX_BOOL Field::editable(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001329 CJS_PropValue& vp,
1330 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001331 if (vp.IsSetting()) {
1332 if (!m_bCanSet)
1333 return FALSE;
1334
1335 bool bVP;
1336 vp >> bVP;
1337 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001338 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1339 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001340 return FALSE;
1341
Lei Zhangd88a3642015-11-10 09:38:57 -08001342 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001343 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX)
1344 return FALSE;
1345
1346 if (pFormField->GetFieldFlags() & FIELDFLAG_EDIT)
1347 vp << true;
1348 else
1349 vp << false;
1350 }
1351
1352 return TRUE;
1353}
1354
Tom Sepezba038bc2015-10-08 12:03:00 -07001355FX_BOOL Field::exportValues(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001356 CJS_PropValue& vp,
1357 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001358 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1359 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001360 return FALSE;
1361
Lei Zhangd88a3642015-11-10 09:38:57 -08001362 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001363 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001364 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001365 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001366 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001367
1368 if (vp.IsSetting()) {
1369 if (!m_bCanSet)
1370 return FALSE;
1371
1372 if (!vp.IsArrayObject())
1373 return FALSE;
1374 } else {
Tom Sepez67fd5df2015-10-08 12:24:19 -07001375 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
1376 CJS_Array ExportValusArray(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001377 if (m_nFormControlIndex < 0) {
1378 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
1379 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
1380 ExportValusArray.SetElement(
Tom Sepez67fd5df2015-10-08 12:24:19 -07001381 i, CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001382 }
1383 } else {
1384 if (m_nFormControlIndex >= pFormField->CountControls())
1385 return FALSE;
1386
1387 CPDF_FormControl* pFormControl =
1388 pFormField->GetControl(m_nFormControlIndex);
1389 if (!pFormControl)
1390 return FALSE;
1391
1392 ExportValusArray.SetElement(
Tom Sepez67fd5df2015-10-08 12:24:19 -07001393 0, CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001394 }
1395 vp << ExportValusArray;
1396 }
1397 return TRUE;
1398}
1399
Tom Sepezba038bc2015-10-08 12:03:00 -07001400FX_BOOL Field::fileSelect(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001401 CJS_PropValue& vp,
1402 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001403 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1404 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001405 return FALSE;
1406
Lei Zhangd88a3642015-11-10 09:38:57 -08001407 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001408 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1409 return FALSE;
1410
1411 if (vp.IsSetting()) {
1412 if (!m_bCanSet)
1413 return FALSE;
1414
1415 bool bVP;
1416 vp >> bVP;
1417 } else {
1418 if (pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT)
1419 vp << true;
1420 else
1421 vp << false;
1422 }
1423 return TRUE;
1424}
1425
Tom Sepezba038bc2015-10-08 12:03:00 -07001426FX_BOOL Field::fillColor(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001427 CJS_PropValue& vp,
1428 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07001429 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
1430 CJS_Array crArray(pRuntime);
Lei Zhangd88a3642015-11-10 09:38:57 -08001431 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1432 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001433 return FALSE;
1434
1435 if (vp.IsSetting()) {
1436 if (!m_bCanSet)
1437 return FALSE;
1438
1439 if (!vp.IsArrayObject())
1440 return FALSE;
1441
1442 vp >> crArray;
1443
1444 CPWL_Color color;
1445 color::ConvertArrayToPWLColor(crArray, color);
1446 if (m_bDelay) {
1447 AddDelay_Color(FP_FILLCOLOR, color);
1448 } else {
1449 Field::SetFillColor(m_pDocument, m_FieldName, m_nFormControlIndex, color);
1450 }
1451 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001452 CPDF_FormField* pFormField = FieldArray[0];
1453 ASSERT(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001454 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1455 if (!pFormControl)
1456 return FALSE;
1457
1458 int iColorType;
1459 pFormControl->GetBackgroundColor(iColorType);
1460
1461 CPWL_Color color;
1462 if (iColorType == COLORTYPE_TRANSPARENT) {
1463 color = CPWL_Color(COLORTYPE_TRANSPARENT);
1464 } else if (iColorType == COLORTYPE_GRAY) {
1465 color = CPWL_Color(COLORTYPE_GRAY,
1466 pFormControl->GetOriginalBackgroundColor(0));
1467 } else if (iColorType == COLORTYPE_RGB) {
1468 color =
1469 CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBackgroundColor(0),
1470 pFormControl->GetOriginalBackgroundColor(1),
1471 pFormControl->GetOriginalBackgroundColor(2));
1472 } else if (iColorType == COLORTYPE_CMYK) {
1473 color = CPWL_Color(COLORTYPE_CMYK,
1474 pFormControl->GetOriginalBackgroundColor(0),
1475 pFormControl->GetOriginalBackgroundColor(1),
1476 pFormControl->GetOriginalBackgroundColor(2),
1477 pFormControl->GetOriginalBackgroundColor(3));
Lei Zhangd88a3642015-11-10 09:38:57 -08001478 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001479 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001480 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001481
1482 color::ConvertPWLColorToArray(color, crArray);
1483 vp << crArray;
1484 }
1485
1486 return TRUE;
1487}
1488
1489void Field::SetFillColor(CPDFSDK_Document* pDocument,
1490 const CFX_WideString& swFieldName,
1491 int nControlIndex,
1492 const CPWL_Color& color) {
1493 // Not supported.
1494}
1495
Tom Sepezba038bc2015-10-08 12:03:00 -07001496FX_BOOL Field::hidden(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001497 CJS_PropValue& vp,
1498 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001499 if (vp.IsSetting()) {
1500 if (!m_bCanSet)
1501 return FALSE;
1502
1503 bool bVP;
1504 vp >> bVP;
1505
1506 if (m_bDelay) {
1507 AddDelay_Bool(FP_HIDDEN, bVP);
1508 } else {
1509 Field::SetHidden(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
1510 }
1511 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001512 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1513 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001514 return FALSE;
1515
Lei Zhangd88a3642015-11-10 09:38:57 -08001516 CPDF_FormField* pFormField = FieldArray[0];
1517 ASSERT(pFormField);
tsepez23ae4a52016-06-08 20:44:54 -07001518 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001519 CPDFSDK_Widget* pWidget =
1520 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1521 if (!pWidget)
1522 return FALSE;
1523
tsepezc3255f52016-03-25 14:52:27 -07001524 uint32_t dwFlags = pWidget->GetFlags();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001525
Lei Zhangd88a3642015-11-10 09:38:57 -08001526 if (ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001527 vp << true;
Lei Zhangd88a3642015-11-10 09:38:57 -08001528 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001529 vp << false;
1530 }
1531
1532 return TRUE;
1533}
1534
1535void Field::SetHidden(CPDFSDK_Document* pDocument,
1536 const CFX_WideString& swFieldName,
1537 int nControlIndex,
1538 bool b) {
tsepez23ae4a52016-06-08 20:44:54 -07001539 CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001540 std::vector<CPDF_FormField*> FieldArray =
1541 GetFormFields(pDocument, swFieldName);
1542 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001543 if (nControlIndex < 0) {
1544 FX_BOOL bSet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001545 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001546 if (CPDFSDK_Widget* pWidget =
Lei Zhangd88a3642015-11-10 09:38:57 -08001547 pInterForm->GetWidget(pFormField->GetControl(i))) {
tsepezc3255f52016-03-25 14:52:27 -07001548 uint32_t dwFlags = pWidget->GetFlags();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001549
1550 if (b) {
1551 dwFlags &= (~ANNOTFLAG_INVISIBLE);
1552 dwFlags &= (~ANNOTFLAG_NOVIEW);
1553 dwFlags |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
1554 } else {
1555 dwFlags &= (~ANNOTFLAG_INVISIBLE);
1556 dwFlags &= (~ANNOTFLAG_HIDDEN);
1557 dwFlags &= (~ANNOTFLAG_NOVIEW);
1558 dwFlags |= ANNOTFLAG_PRINT;
1559 }
1560
1561 if (dwFlags != pWidget->GetFlags()) {
1562 pWidget->SetFlags(dwFlags);
1563 bSet = TRUE;
1564 }
1565 }
1566 }
1567
1568 if (bSet)
1569 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
1570 } else {
1571 if (nControlIndex >= pFormField->CountControls())
1572 return;
1573 if (CPDF_FormControl* pFormControl =
1574 pFormField->GetControl(nControlIndex)) {
1575 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
tsepezc3255f52016-03-25 14:52:27 -07001576 uint32_t dwFlags = pWidget->GetFlags();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001577
1578 if (b) {
1579 dwFlags &= (~ANNOTFLAG_INVISIBLE);
1580 dwFlags &= (~ANNOTFLAG_NOVIEW);
1581 dwFlags |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
1582 } else {
1583 dwFlags &= (~ANNOTFLAG_INVISIBLE);
1584 dwFlags &= (~ANNOTFLAG_HIDDEN);
1585 dwFlags &= (~ANNOTFLAG_NOVIEW);
1586 dwFlags |= ANNOTFLAG_PRINT;
1587 }
1588
1589 if (dwFlags != pWidget->GetFlags()) {
1590 pWidget->SetFlags(dwFlags);
1591 UpdateFormControl(pDocument, pFormControl, TRUE, FALSE, TRUE);
1592 }
1593 }
1594 }
1595 }
1596 }
1597}
1598
Tom Sepezba038bc2015-10-08 12:03:00 -07001599FX_BOOL Field::highlight(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001600 CJS_PropValue& vp,
1601 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08001602 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001603
1604 if (vp.IsSetting()) {
1605 if (!m_bCanSet)
1606 return FALSE;
1607
1608 CFX_ByteString strMode;
1609 vp >> strMode;
1610
1611 if (m_bDelay) {
1612 AddDelay_String(FP_HIGHLIGHT, strMode);
1613 } else {
1614 Field::SetHighlight(m_pDocument, m_FieldName, m_nFormControlIndex,
1615 strMode);
1616 }
1617 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001618 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1619 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001620 return FALSE;
1621
Lei Zhangd88a3642015-11-10 09:38:57 -08001622 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001623 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
1624 return FALSE;
1625
1626 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1627 if (!pFormControl)
1628 return FALSE;
1629
1630 int eHM = pFormControl->GetHighlightingMode();
1631 switch (eHM) {
1632 case CPDF_FormControl::None:
1633 vp << L"none";
1634 break;
1635 case CPDF_FormControl::Push:
1636 vp << L"push";
1637 break;
1638 case CPDF_FormControl::Invert:
1639 vp << L"invert";
1640 break;
1641 case CPDF_FormControl::Outline:
1642 vp << L"outline";
1643 break;
1644 case CPDF_FormControl::Toggle:
1645 vp << L"toggle";
1646 break;
1647 }
1648 }
1649
1650 return TRUE;
1651}
1652
1653void Field::SetHighlight(CPDFSDK_Document* pDocument,
1654 const CFX_WideString& swFieldName,
1655 int nControlIndex,
1656 const CFX_ByteString& string) {
1657 // Not supported.
1658}
1659
Tom Sepezba038bc2015-10-08 12:03:00 -07001660FX_BOOL Field::lineWidth(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001661 CJS_PropValue& vp,
1662 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001663 if (vp.IsSetting()) {
1664 if (!m_bCanSet)
1665 return FALSE;
1666
1667 int iWidth;
1668 vp >> iWidth;
1669
1670 if (m_bDelay) {
1671 AddDelay_Int(FP_LINEWIDTH, iWidth);
1672 } else {
1673 Field::SetLineWidth(m_pDocument, m_FieldName, m_nFormControlIndex,
1674 iWidth);
1675 }
1676 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001677 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1678 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001679 return FALSE;
1680
Lei Zhangd88a3642015-11-10 09:38:57 -08001681 CPDF_FormField* pFormField = FieldArray[0];
1682 ASSERT(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001683 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1684 if (!pFormControl)
1685 return FALSE;
1686
tsepez23ae4a52016-06-08 20:44:54 -07001687 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001688 if (!pFormField->CountControls())
1689 return FALSE;
1690
1691 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
1692 if (!pWidget)
1693 return FALSE;
1694
1695 vp << (int32_t)pWidget->GetBorderWidth();
1696 }
1697
1698 return TRUE;
1699}
1700
1701void Field::SetLineWidth(CPDFSDK_Document* pDocument,
1702 const CFX_WideString& swFieldName,
1703 int nControlIndex,
1704 int number) {
tsepez23ae4a52016-06-08 20:44:54 -07001705 CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001706 std::vector<CPDF_FormField*> FieldArray =
1707 GetFormFields(pDocument, swFieldName);
1708 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001709 if (nControlIndex < 0) {
1710 FX_BOOL bSet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001711 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1712 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08001713 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001714
1715 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1716 if (number != pWidget->GetBorderWidth()) {
1717 pWidget->SetBorderWidth(number);
1718 bSet = TRUE;
1719 }
1720 }
1721 }
1722 if (bSet)
1723 UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
1724 } else {
1725 if (nControlIndex >= pFormField->CountControls())
1726 return;
1727 if (CPDF_FormControl* pFormControl =
1728 pFormField->GetControl(nControlIndex)) {
1729 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1730 if (number != pWidget->GetBorderWidth()) {
1731 pWidget->SetBorderWidth(number);
1732 UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
1733 }
1734 }
1735 }
1736 }
1737 }
1738}
1739
Tom Sepezba038bc2015-10-08 12:03:00 -07001740FX_BOOL Field::multiline(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001741 CJS_PropValue& vp,
1742 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08001743 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001744
1745 if (vp.IsSetting()) {
1746 if (!m_bCanSet)
1747 return FALSE;
1748
1749 bool bVP;
1750 vp >> bVP;
1751
1752 if (m_bDelay) {
1753 AddDelay_Bool(FP_MULTILINE, bVP);
1754 } else {
1755 Field::SetMultiline(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
1756 }
1757 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001758 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1759 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001760 return FALSE;
1761
Lei Zhangd88a3642015-11-10 09:38:57 -08001762 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001763 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1764 return FALSE;
1765
1766 if (pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE)
1767 vp << true;
1768 else
1769 vp << false;
1770 }
1771
1772 return TRUE;
1773}
1774
1775void Field::SetMultiline(CPDFSDK_Document* pDocument,
1776 const CFX_WideString& swFieldName,
1777 int nControlIndex,
1778 bool b) {
1779 // Not supported.
1780}
1781
Tom Sepezba038bc2015-10-08 12:03:00 -07001782FX_BOOL Field::multipleSelection(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001783 CJS_PropValue& vp,
1784 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08001785 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001786
1787 if (vp.IsSetting()) {
1788 if (!m_bCanSet)
1789 return FALSE;
1790
1791 bool bVP;
1792 vp >> bVP;
1793
1794 if (m_bDelay) {
1795 AddDelay_Bool(FP_MULTIPLESELECTION, bVP);
1796 } else {
1797 Field::SetMultipleSelection(m_pDocument, m_FieldName, m_nFormControlIndex,
1798 bVP);
1799 }
1800 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001801 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1802 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001803 return FALSE;
1804
Lei Zhangd88a3642015-11-10 09:38:57 -08001805 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001806 if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
1807 return FALSE;
1808
1809 if (pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT)
1810 vp << true;
1811 else
1812 vp << false;
1813 }
1814
1815 return TRUE;
1816}
1817
1818void Field::SetMultipleSelection(CPDFSDK_Document* pDocument,
1819 const CFX_WideString& swFieldName,
1820 int nControlIndex,
1821 bool b) {
1822 // Not supported.
1823}
1824
Tom Sepezba038bc2015-10-08 12:03:00 -07001825FX_BOOL Field::name(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001826 CJS_PropValue& vp,
1827 CFX_WideString& sError) {
1828 if (!vp.IsGetting())
1829 return FALSE;
1830
Lei Zhangd88a3642015-11-10 09:38:57 -08001831 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1832 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001833 return FALSE;
1834
1835 vp << m_FieldName;
1836
1837 return TRUE;
1838}
1839
Tom Sepezba038bc2015-10-08 12:03:00 -07001840FX_BOOL Field::numItems(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001841 CJS_PropValue& vp,
1842 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07001843 if (!vp.IsGetting())
1844 return FALSE;
1845
Lei Zhangd88a3642015-11-10 09:38:57 -08001846 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1847 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001848 return FALSE;
1849
Lei Zhangd88a3642015-11-10 09:38:57 -08001850 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001851 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001852 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001853 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001854 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001855
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001856 vp << (int32_t)pFormField->CountOptions();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001857 return TRUE;
1858}
1859
Tom Sepezba038bc2015-10-08 12:03:00 -07001860FX_BOOL Field::page(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001861 CJS_PropValue& vp,
1862 CFX_WideString& sError) {
1863 if (!vp.IsGetting())
1864 return FALSE;
1865
Lei Zhangd88a3642015-11-10 09:38:57 -08001866 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1867 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001868 return FALSE;
1869
Lei Zhangd88a3642015-11-10 09:38:57 -08001870 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001871 if (!pFormField)
1872 return FALSE;
1873
Lei Zhangd88a3642015-11-10 09:38:57 -08001874 std::vector<CPDFSDK_Widget*> widgets;
1875 m_pDocument->GetInterForm()->GetWidgets(pFormField, &widgets);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001876
Lei Zhangd88a3642015-11-10 09:38:57 -08001877 if (widgets.empty()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001878 vp << (int32_t)-1;
Lei Zhangd88a3642015-11-10 09:38:57 -08001879 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001880 }
1881
Lei Zhangd88a3642015-11-10 09:38:57 -08001882 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
1883 CJS_Array PageArray(pRuntime);
1884 for (size_t i = 0; i < widgets.size(); ++i) {
1885 CPDFSDK_PageView* pPageView = widgets[i]->GetPageView();
1886 if (!pPageView)
1887 return FALSE;
1888
1889 PageArray.SetElement(
1890 i, CJS_Value(pRuntime, (int32_t)pPageView->GetPageIndex()));
1891 }
1892
1893 vp << PageArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001894 return TRUE;
1895}
1896
Tom Sepezba038bc2015-10-08 12:03:00 -07001897FX_BOOL Field::password(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001898 CJS_PropValue& vp,
1899 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08001900 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001901
1902 if (vp.IsSetting()) {
1903 if (!m_bCanSet)
1904 return FALSE;
1905
1906 bool bVP;
1907 vp >> bVP;
1908
1909 if (m_bDelay) {
1910 AddDelay_Bool(FP_PASSWORD, bVP);
1911 } else {
1912 Field::SetPassword(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
1913 }
1914 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001915 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1916 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001917 return FALSE;
1918
Lei Zhangd88a3642015-11-10 09:38:57 -08001919 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001920 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1921 return FALSE;
1922
1923 if (pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD)
1924 vp << true;
1925 else
1926 vp << false;
1927 }
1928
1929 return TRUE;
1930}
1931
1932void Field::SetPassword(CPDFSDK_Document* pDocument,
1933 const CFX_WideString& swFieldName,
1934 int nControlIndex,
1935 bool b) {
1936 // Not supported.
1937}
1938
Tom Sepezba038bc2015-10-08 12:03:00 -07001939FX_BOOL Field::print(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001940 CJS_PropValue& vp,
1941 CFX_WideString& sError) {
tsepez23ae4a52016-06-08 20:44:54 -07001942 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001943 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1944 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001945 return FALSE;
1946
1947 if (vp.IsSetting()) {
1948 if (!m_bCanSet)
1949 return FALSE;
1950
1951 bool bVP;
1952 vp >> bVP;
1953
Lei Zhangd88a3642015-11-10 09:38:57 -08001954 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001955 if (m_nFormControlIndex < 0) {
1956 FX_BOOL bSet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001957 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001958 if (CPDFSDK_Widget* pWidget =
Lei Zhangd88a3642015-11-10 09:38:57 -08001959 pInterForm->GetWidget(pFormField->GetControl(i))) {
tsepezc3255f52016-03-25 14:52:27 -07001960 uint32_t dwFlags = pWidget->GetFlags();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001961 if (bVP)
1962 dwFlags |= ANNOTFLAG_PRINT;
1963 else
1964 dwFlags &= ~ANNOTFLAG_PRINT;
1965
1966 if (dwFlags != pWidget->GetFlags()) {
1967 pWidget->SetFlags(dwFlags);
1968 bSet = TRUE;
1969 }
1970 }
1971 }
1972
1973 if (bSet)
1974 UpdateFormField(m_pDocument, pFormField, TRUE, FALSE, TRUE);
1975 } else {
1976 if (m_nFormControlIndex >= pFormField->CountControls())
1977 return FALSE;
1978 if (CPDF_FormControl* pFormControl =
1979 pFormField->GetControl(m_nFormControlIndex)) {
1980 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
tsepezc3255f52016-03-25 14:52:27 -07001981 uint32_t dwFlags = pWidget->GetFlags();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001982 if (bVP)
1983 dwFlags |= ANNOTFLAG_PRINT;
1984 else
1985 dwFlags &= ~ANNOTFLAG_PRINT;
1986
1987 if (dwFlags != pWidget->GetFlags()) {
1988 pWidget->SetFlags(dwFlags);
1989 UpdateFormControl(m_pDocument,
1990 pFormField->GetControl(m_nFormControlIndex),
1991 TRUE, FALSE, TRUE);
1992 }
1993 }
1994 }
1995 }
1996 }
1997 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001998 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001999 CPDFSDK_Widget* pWidget =
2000 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
2001 if (!pWidget)
2002 return FALSE;
2003
2004 if (pWidget->GetFlags() & ANNOTFLAG_PRINT)
2005 vp << true;
2006 else
2007 vp << false;
2008 }
2009
2010 return TRUE;
2011}
2012
Tom Sepezba038bc2015-10-08 12:03:00 -07002013FX_BOOL Field::radiosInUnison(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002014 CJS_PropValue& vp,
2015 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002016 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2017 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002018 return FALSE;
2019
2020 if (vp.IsSetting()) {
2021 if (!m_bCanSet)
2022 return FALSE;
2023
2024 bool bVP;
2025 vp >> bVP;
2026
2027 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002028 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002029 if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
2030 return FALSE;
2031
2032 if (pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)
2033 vp << true;
2034 else
2035 vp << false;
2036 }
2037
2038 return TRUE;
2039}
2040
Tom Sepezba038bc2015-10-08 12:03:00 -07002041FX_BOOL Field::readonly(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002042 CJS_PropValue& vp,
2043 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002044 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2045 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002046 return FALSE;
2047
2048 if (vp.IsSetting()) {
2049 if (!m_bCanSet)
2050 return FALSE;
2051
2052 bool bVP;
2053 vp >> bVP;
2054
2055 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002056 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002057 if (pFormField->GetFieldFlags() & FIELDFLAG_READONLY)
2058 vp << true;
2059 else
2060 vp << false;
2061 }
2062
2063 return TRUE;
2064}
2065
Tom Sepezba038bc2015-10-08 12:03:00 -07002066FX_BOOL Field::rect(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002067 CJS_PropValue& vp,
2068 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002069 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
2070 CJS_Value Upper_Leftx(pRuntime);
2071 CJS_Value Upper_Lefty(pRuntime);
2072 CJS_Value Lower_Rightx(pRuntime);
2073 CJS_Value Lower_Righty(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002074
2075 if (vp.IsSetting()) {
2076 if (!m_bCanSet)
2077 return FALSE;
2078 if (!vp.IsArrayObject())
2079 return FALSE;
2080
Tom Sepez67fd5df2015-10-08 12:24:19 -07002081 CJS_Array rcArray(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002082 vp >> rcArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002083 rcArray.GetElement(0, Upper_Leftx);
2084 rcArray.GetElement(1, Upper_Lefty);
2085 rcArray.GetElement(2, Lower_Rightx);
2086 rcArray.GetElement(3, Lower_Righty);
2087
2088 FX_FLOAT pArray[4] = {0.0f, 0.0f, 0.0f, 0.0f};
2089 pArray[0] = (FX_FLOAT)Upper_Leftx.ToInt();
2090 pArray[1] = (FX_FLOAT)Lower_Righty.ToInt();
2091 pArray[2] = (FX_FLOAT)Lower_Rightx.ToInt();
2092 pArray[3] = (FX_FLOAT)Upper_Lefty.ToInt();
2093
Tom Sepez281a9ea2016-02-26 14:24:28 -08002094 CFX_FloatRect crRect(pArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002095 if (m_bDelay) {
2096 AddDelay_Rect(FP_RECT, crRect);
2097 } else {
2098 Field::SetRect(m_pDocument, m_FieldName, m_nFormControlIndex, crRect);
2099 }
2100 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002101 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2102 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002103 return FALSE;
2104
Lei Zhangd88a3642015-11-10 09:38:57 -08002105 CPDF_FormField* pFormField = FieldArray[0];
tsepez23ae4a52016-06-08 20:44:54 -07002106 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002107 CPDFSDK_Widget* pWidget =
2108 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
2109 if (!pWidget)
2110 return FALSE;
2111
2112 CFX_FloatRect crRect = pWidget->GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002113 Upper_Leftx = (int32_t)crRect.left;
2114 Upper_Lefty = (int32_t)crRect.top;
2115 Lower_Rightx = (int32_t)crRect.right;
2116 Lower_Righty = (int32_t)crRect.bottom;
2117
Tom Sepez67fd5df2015-10-08 12:24:19 -07002118 CJS_Array rcArray(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002119 rcArray.SetElement(0, Upper_Leftx);
2120 rcArray.SetElement(1, Upper_Lefty);
2121 rcArray.SetElement(2, Lower_Rightx);
2122 rcArray.SetElement(3, Lower_Righty);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002123 vp << rcArray;
2124 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002125 return TRUE;
2126}
2127
2128void Field::SetRect(CPDFSDK_Document* pDocument,
2129 const CFX_WideString& swFieldName,
2130 int nControlIndex,
Tom Sepez281a9ea2016-02-26 14:24:28 -08002131 const CFX_FloatRect& rect) {
tsepez23ae4a52016-06-08 20:44:54 -07002132 CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08002133 std::vector<CPDF_FormField*> FieldArray =
2134 GetFormFields(pDocument, swFieldName);
2135 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002136 if (nControlIndex < 0) {
2137 FX_BOOL bSet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08002138 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002139 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08002140 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002141
2142 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002143 CFX_FloatRect crRect = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002144
2145 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002146 crRect.Intersect(pPDFPage->GetPageBBox());
2147
2148 if (!crRect.IsEmpty()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002149 CFX_FloatRect rcOld = pWidget->GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002150 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
2151 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
2152 pWidget->SetRect(crRect);
2153 bSet = TRUE;
2154 }
2155 }
2156 }
2157 }
2158
2159 if (bSet)
2160 UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
2161 } else {
2162 if (nControlIndex >= pFormField->CountControls())
2163 return;
2164 if (CPDF_FormControl* pFormControl =
2165 pFormField->GetControl(nControlIndex)) {
2166 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002167 CFX_FloatRect crRect = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002168
2169 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002170 crRect.Intersect(pPDFPage->GetPageBBox());
2171
2172 if (!crRect.IsEmpty()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002173 CFX_FloatRect rcOld = pWidget->GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002174 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
2175 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
2176 pWidget->SetRect(crRect);
2177 UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
2178 }
2179 }
2180 }
2181 }
2182 }
2183 }
2184}
2185
Tom Sepezba038bc2015-10-08 12:03:00 -07002186FX_BOOL Field::required(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002187 CJS_PropValue& vp,
2188 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002189 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2190 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002191 return FALSE;
2192
2193 if (vp.IsSetting()) {
2194 if (!m_bCanSet)
2195 return FALSE;
2196
2197 bool bVP;
2198 vp >> bVP;
2199
2200 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002201 CPDF_FormField* pFormField = FieldArray[0];
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002202 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002203 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002204
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002205 if (pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED)
2206 vp << true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002207 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002208 vp << false;
2209 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002210
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002211 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002212}
2213
Tom Sepezba038bc2015-10-08 12:03:00 -07002214FX_BOOL Field::richText(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);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002218
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002219 if (vp.IsSetting()) {
2220 if (!m_bCanSet)
2221 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002222
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002223 bool bVP;
2224 vp >> bVP;
2225
2226 if (m_bDelay) {
2227 AddDelay_Bool(FP_RICHTEXT, bVP);
2228 } else {
2229 Field::SetRichText(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
2230 }
2231 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002232 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2233 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002234 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002235
Lei Zhangd88a3642015-11-10 09:38:57 -08002236 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002237 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
2238 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002239
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002240 if (pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT)
2241 vp << true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002242 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002243 vp << false;
2244 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002245
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002246 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002247}
2248
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002249void Field::SetRichText(CPDFSDK_Document* pDocument,
2250 const CFX_WideString& swFieldName,
2251 int nControlIndex,
2252 bool b) {
2253 // Not supported.
2254}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002255
Tom Sepezba038bc2015-10-08 12:03:00 -07002256FX_BOOL Field::richValue(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002257 CJS_PropValue& vp,
2258 CFX_WideString& sError) {
2259 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002260}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002261
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002262void Field::SetRichValue(CPDFSDK_Document* pDocument,
2263 const CFX_WideString& swFieldName,
2264 int nControlIndex) {
2265 // Not supported.
2266}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002267
Tom Sepezba038bc2015-10-08 12:03:00 -07002268FX_BOOL Field::rotation(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002269 CJS_PropValue& vp,
2270 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08002271 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002272
2273 if (vp.IsSetting()) {
2274 if (!m_bCanSet)
2275 return FALSE;
2276
2277 int nVP;
2278 vp >> nVP;
2279
2280 if (m_bDelay) {
2281 AddDelay_Int(FP_ROTATION, nVP);
2282 } else {
2283 Field::SetRotation(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
2284 }
2285 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002286 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2287 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002288 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002289
Lei Zhangd88a3642015-11-10 09:38:57 -08002290 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002291 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2292 if (!pFormControl)
2293 return FALSE;
2294
2295 vp << (int32_t)pFormControl->GetRotation();
2296 }
2297
2298 return TRUE;
2299}
2300
2301void Field::SetRotation(CPDFSDK_Document* pDocument,
2302 const CFX_WideString& swFieldName,
2303 int nControlIndex,
2304 int number) {
2305 // Not supported.
2306}
2307
Tom Sepezba038bc2015-10-08 12:03:00 -07002308FX_BOOL Field::strokeColor(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002309 CJS_PropValue& vp,
2310 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002311 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
2312 CJS_Array crArray(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002313
2314 if (vp.IsSetting()) {
2315 if (!m_bCanSet)
2316 return FALSE;
2317
2318 if (!vp.IsArrayObject())
2319 return FALSE;
2320
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002321 vp >> crArray;
2322
2323 CPWL_Color color;
2324 color::ConvertArrayToPWLColor(crArray, color);
2325
2326 if (m_bDelay) {
2327 AddDelay_Color(FP_STROKECOLOR, color);
2328 } else {
2329 Field::SetStrokeColor(m_pDocument, m_FieldName, m_nFormControlIndex,
2330 color);
2331 }
2332 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002333 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2334 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002335 return FALSE;
2336
Lei Zhangd88a3642015-11-10 09:38:57 -08002337 CPDF_FormField* pFormField = FieldArray[0];
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002338 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002339 if (!pFormControl)
2340 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002341
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002342 int iColorType;
2343 pFormControl->GetBorderColor(iColorType);
2344
2345 CPWL_Color color;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002346 if (iColorType == COLORTYPE_TRANSPARENT) {
2347 color = CPWL_Color(COLORTYPE_TRANSPARENT);
2348 } else if (iColorType == COLORTYPE_GRAY) {
2349 color =
2350 CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBorderColor(0));
2351 } else if (iColorType == COLORTYPE_RGB) {
2352 color = CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBorderColor(0),
2353 pFormControl->GetOriginalBorderColor(1),
2354 pFormControl->GetOriginalBorderColor(2));
2355 } else if (iColorType == COLORTYPE_CMYK) {
2356 color =
2357 CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBorderColor(0),
2358 pFormControl->GetOriginalBorderColor(1),
2359 pFormControl->GetOriginalBorderColor(2),
2360 pFormControl->GetOriginalBorderColor(3));
Lei Zhangd88a3642015-11-10 09:38:57 -08002361 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002362 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08002363 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002364
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002365 color::ConvertPWLColorToArray(color, crArray);
2366 vp << crArray;
2367 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002368 return TRUE;
2369}
2370
2371void Field::SetStrokeColor(CPDFSDK_Document* pDocument,
2372 const CFX_WideString& swFieldName,
2373 int nControlIndex,
2374 const CPWL_Color& color) {
2375 // Not supported.
2376}
2377
Tom Sepezba038bc2015-10-08 12:03:00 -07002378FX_BOOL Field::style(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002379 CJS_PropValue& vp,
2380 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08002381 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002382
2383 if (vp.IsSetting()) {
2384 if (!m_bCanSet)
2385 return FALSE;
2386
2387 CFX_ByteString csBCaption;
2388 vp >> csBCaption;
2389
2390 if (m_bDelay) {
2391 AddDelay_String(FP_STYLE, csBCaption);
2392 } else {
2393 Field::SetStyle(m_pDocument, m_FieldName, m_nFormControlIndex,
2394 csBCaption);
2395 }
2396 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002397 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2398 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002399 return FALSE;
2400
Lei Zhangd88a3642015-11-10 09:38:57 -08002401 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002402 if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON &&
Lei Zhangd88a3642015-11-10 09:38:57 -08002403 pFormField->GetFieldType() != FIELDTYPE_CHECKBOX) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002404 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08002405 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002406
2407 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2408 if (!pFormControl)
2409 return FALSE;
2410
2411 CFX_WideString csWCaption = pFormControl->GetNormalCaption();
2412 CFX_ByteString csBCaption;
2413
2414 switch (csWCaption[0]) {
2415 case L'l':
2416 csBCaption = "circle";
2417 break;
2418 case L'8':
2419 csBCaption = "cross";
2420 break;
2421 case L'u':
2422 csBCaption = "diamond";
2423 break;
2424 case L'n':
2425 csBCaption = "square";
2426 break;
2427 case L'H':
2428 csBCaption = "star";
2429 break;
2430 default: // L'4'
2431 csBCaption = "check";
2432 break;
2433 }
2434 vp << csBCaption;
2435 }
2436
2437 return TRUE;
2438}
2439
2440void Field::SetStyle(CPDFSDK_Document* pDocument,
2441 const CFX_WideString& swFieldName,
2442 int nControlIndex,
2443 const CFX_ByteString& string) {
2444 // Not supported.
2445}
2446
Tom Sepezba038bc2015-10-08 12:03:00 -07002447FX_BOOL Field::submitName(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002448 CJS_PropValue& vp,
2449 CFX_WideString& sError) {
2450 return TRUE;
2451}
2452
Tom Sepezba038bc2015-10-08 12:03:00 -07002453FX_BOOL Field::textColor(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002454 CJS_PropValue& vp,
2455 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002456 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
2457 CJS_Array crArray(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002458
2459 if (vp.IsSetting()) {
2460 if (!m_bCanSet)
2461 return FALSE;
2462
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002463 if (!vp.IsArrayObject())
2464 return FALSE;
Tom Sepez67fd5df2015-10-08 12:24:19 -07002465
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002466 vp >> crArray;
2467
2468 CPWL_Color color;
2469 color::ConvertArrayToPWLColor(crArray, color);
2470
2471 if (m_bDelay) {
2472 AddDelay_Color(FP_TEXTCOLOR, color);
2473 } else {
2474 Field::SetTextColor(m_pDocument, m_FieldName, m_nFormControlIndex, color);
2475 }
2476 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002477 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2478 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002479 return FALSE;
2480
Lei Zhangd88a3642015-11-10 09:38:57 -08002481 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002482 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2483 if (!pFormControl)
2484 return FALSE;
2485
2486 int iColorType;
2487 FX_ARGB color;
2488 CPDF_DefaultAppearance FieldAppearance =
2489 pFormControl->GetDefaultAppearance();
2490 FieldAppearance.GetColor(color, iColorType);
2491 int32_t a, r, g, b;
2492 ArgbDecode(color, a, r, g, b);
2493
2494 CPWL_Color crRet =
2495 CPWL_Color(COLORTYPE_RGB, r / 255.0f, g / 255.0f, b / 255.0f);
2496
2497 if (iColorType == COLORTYPE_TRANSPARENT)
2498 crRet = CPWL_Color(COLORTYPE_TRANSPARENT);
2499
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002500 color::ConvertPWLColorToArray(crRet, crArray);
2501 vp << crArray;
2502 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002503 return TRUE;
2504}
2505
2506void Field::SetTextColor(CPDFSDK_Document* pDocument,
2507 const CFX_WideString& swFieldName,
2508 int nControlIndex,
2509 const CPWL_Color& color) {
2510 // Not supported.
2511}
2512
Tom Sepezba038bc2015-10-08 12:03:00 -07002513FX_BOOL Field::textFont(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002514 CJS_PropValue& vp,
2515 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08002516 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002517
2518 if (vp.IsSetting()) {
2519 if (!m_bCanSet)
2520 return FALSE;
2521
2522 CFX_ByteString csFontName;
2523 vp >> csFontName;
2524 if (csFontName.IsEmpty())
2525 return FALSE;
2526
2527 if (m_bDelay) {
2528 AddDelay_String(FP_TEXTFONT, csFontName);
2529 } else {
2530 Field::SetTextFont(m_pDocument, m_FieldName, m_nFormControlIndex,
2531 csFontName);
2532 }
2533 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002534 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2535 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002536 return FALSE;
2537
Lei Zhangd88a3642015-11-10 09:38:57 -08002538 CPDF_FormField* pFormField = FieldArray[0];
2539 ASSERT(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002540 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2541 if (!pFormControl)
2542 return FALSE;
2543
2544 int nFieldType = pFormField->GetFieldType();
2545
2546 if (nFieldType == FIELDTYPE_PUSHBUTTON ||
2547 nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX ||
2548 nFieldType == FIELDTYPE_TEXTFIELD) {
2549 CPDF_Font* pFont = pFormControl->GetDefaultControlFont();
2550 if (!pFont)
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002551 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002552
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002553 vp << pFont->GetBaseFont();
Lei Zhangd88a3642015-11-10 09:38:57 -08002554 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002555 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08002556 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002557 }
2558
2559 return TRUE;
2560}
2561
2562void Field::SetTextFont(CPDFSDK_Document* pDocument,
2563 const CFX_WideString& swFieldName,
2564 int nControlIndex,
2565 const CFX_ByteString& string) {
2566 // Not supported.
2567}
2568
Tom Sepezba038bc2015-10-08 12:03:00 -07002569FX_BOOL Field::textSize(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002570 CJS_PropValue& vp,
2571 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08002572 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002573
2574 if (vp.IsSetting()) {
2575 if (!m_bCanSet)
2576 return FALSE;
2577
2578 int nVP;
2579 vp >> nVP;
2580
2581 if (m_bDelay) {
2582 AddDelay_Int(FP_TEXTSIZE, nVP);
2583 } else {
2584 Field::SetTextSize(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
2585 }
2586 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002587 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2588 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002589 return FALSE;
2590
Lei Zhangd88a3642015-11-10 09:38:57 -08002591 CPDF_FormField* pFormField = FieldArray[0];
2592 ASSERT(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002593 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2594 if (!pFormControl)
2595 return FALSE;
2596
2597 CPDF_DefaultAppearance FieldAppearance =
2598 pFormControl->GetDefaultAppearance();
2599
2600 CFX_ByteString csFontNameTag;
2601 FX_FLOAT fFontSize;
2602 FieldAppearance.GetFont(csFontNameTag, fFontSize);
2603
2604 vp << (int)fFontSize;
2605 }
2606
2607 return TRUE;
2608}
2609
2610void Field::SetTextSize(CPDFSDK_Document* pDocument,
2611 const CFX_WideString& swFieldName,
2612 int nControlIndex,
2613 int number) {
2614 // Not supported.
2615}
2616
Tom Sepezba038bc2015-10-08 12:03:00 -07002617FX_BOOL Field::type(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002618 CJS_PropValue& vp,
2619 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002620 if (!vp.IsGetting())
2621 return FALSE;
2622
Lei Zhangd88a3642015-11-10 09:38:57 -08002623 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2624 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002625 return FALSE;
2626
Lei Zhangd88a3642015-11-10 09:38:57 -08002627 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002628 switch (pFormField->GetFieldType()) {
2629 case FIELDTYPE_UNKNOWN:
2630 vp << L"unknown";
2631 break;
2632 case FIELDTYPE_PUSHBUTTON:
2633 vp << L"button";
2634 break;
2635 case FIELDTYPE_CHECKBOX:
2636 vp << L"checkbox";
2637 break;
2638 case FIELDTYPE_RADIOBUTTON:
2639 vp << L"radiobutton";
2640 break;
2641 case FIELDTYPE_COMBOBOX:
2642 vp << L"combobox";
2643 break;
2644 case FIELDTYPE_LISTBOX:
2645 vp << L"listbox";
2646 break;
2647 case FIELDTYPE_TEXTFIELD:
2648 vp << L"text";
2649 break;
2650 case FIELDTYPE_SIGNATURE:
2651 vp << L"signature";
2652 break;
2653 default:
2654 vp << L"unknown";
2655 break;
2656 }
2657
2658 return TRUE;
2659}
2660
Tom Sepezba038bc2015-10-08 12:03:00 -07002661FX_BOOL Field::userName(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002662 CJS_PropValue& vp,
2663 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08002664 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002665
2666 if (vp.IsSetting()) {
2667 if (!m_bCanSet)
2668 return FALSE;
2669
2670 CFX_WideString swName;
2671 vp >> swName;
2672
2673 if (m_bDelay) {
2674 AddDelay_WideString(FP_USERNAME, swName);
2675 } else {
2676 Field::SetUserName(m_pDocument, m_FieldName, m_nFormControlIndex, swName);
2677 }
2678 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002679 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2680 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002681 return FALSE;
2682
Lei Zhangd88a3642015-11-10 09:38:57 -08002683 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002684 vp << (CFX_WideString)pFormField->GetAlternateName();
2685 }
2686
2687 return TRUE;
2688}
2689
2690void Field::SetUserName(CPDFSDK_Document* pDocument,
2691 const CFX_WideString& swFieldName,
2692 int nControlIndex,
2693 const CFX_WideString& string) {
2694 // Not supported.
2695}
2696
Tom Sepezba038bc2015-10-08 12:03:00 -07002697FX_BOOL Field::value(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002698 CJS_PropValue& vp,
2699 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002700 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002701
2702 if (vp.IsSetting()) {
2703 if (!m_bCanSet)
2704 return FALSE;
2705
tsepez41a53ad2016-03-28 16:59:30 -07002706 std::vector<CFX_WideString> strArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002707 if (vp.IsArrayObject()) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002708 CJS_Array ValueArray(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002709 vp.ConvertToArray(ValueArray);
2710 for (int i = 0, sz = ValueArray.GetLength(); i < sz; i++) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002711 CJS_Value ElementValue(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002712 ValueArray.GetElement(i, ElementValue);
tsepez41a53ad2016-03-28 16:59:30 -07002713 strArray.push_back(ElementValue.ToCFXWideString());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002714 }
2715 } else {
2716 CFX_WideString swValue;
2717 vp >> swValue;
tsepez41a53ad2016-03-28 16:59:30 -07002718 strArray.push_back(swValue);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002719 }
2720
2721 if (m_bDelay) {
2722 AddDelay_WideStringArray(FP_VALUE, strArray);
2723 } else {
2724 Field::SetValue(m_pDocument, m_FieldName, m_nFormControlIndex, strArray);
2725 }
2726 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002727 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2728 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002729 return FALSE;
2730
Lei Zhangd88a3642015-11-10 09:38:57 -08002731 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002732 switch (pFormField->GetFieldType()) {
2733 case FIELDTYPE_PUSHBUTTON:
2734 return FALSE;
2735 case FIELDTYPE_COMBOBOX:
2736 case FIELDTYPE_TEXTFIELD: {
Tom Sepez4246b002016-01-20 11:48:29 -08002737 vp << pFormField->GetValue();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002738 } break;
2739 case FIELDTYPE_LISTBOX: {
2740 if (pFormField->CountSelectedItems() > 1) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002741 CJS_Array ValueArray(pRuntime);
2742 CJS_Value ElementValue(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002743 int iIndex;
2744 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
2745 iIndex = pFormField->GetSelectedIndex(i);
2746 ElementValue = pFormField->GetOptionValue(iIndex).c_str();
2747 if (FXSYS_wcslen(ElementValue.ToCFXWideString().c_str()) == 0)
2748 ElementValue = pFormField->GetOptionLabel(iIndex).c_str();
2749 ValueArray.SetElement(i, ElementValue);
2750 }
2751 vp << ValueArray;
2752 } else {
Tom Sepez4246b002016-01-20 11:48:29 -08002753 vp << pFormField->GetValue();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002754 }
2755 } break;
2756 case FIELDTYPE_CHECKBOX:
2757 case FIELDTYPE_RADIOBUTTON: {
Tom Sepez4246b002016-01-20 11:48:29 -08002758 bool bFind = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002759 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
Tom Sepez4246b002016-01-20 11:48:29 -08002760 if (pFormField->GetControl(i)->IsChecked()) {
2761 vp << pFormField->GetControl(i)->GetExportValue();
2762 bFind = true;
2763 break;
Lei Zhangd88a3642015-11-10 09:38:57 -08002764 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002765 }
2766 if (!bFind)
2767 vp << L"Off";
2768 } break;
2769 default:
2770 vp << pFormField->GetValue();
2771 break;
2772 }
2773 }
Tom Sepez4246b002016-01-20 11:48:29 -08002774 vp.MaybeCoerceToNumber();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002775 return TRUE;
2776}
2777
2778void Field::SetValue(CPDFSDK_Document* pDocument,
2779 const CFX_WideString& swFieldName,
2780 int nControlIndex,
tsepez41a53ad2016-03-28 16:59:30 -07002781 const std::vector<CFX_WideString>& strArray) {
Lei Zhang96660d62015-12-14 18:27:25 -08002782 ASSERT(pDocument);
tsepez41a53ad2016-03-28 16:59:30 -07002783 if (strArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002784 return;
2785
Lei Zhangd88a3642015-11-10 09:38:57 -08002786 std::vector<CPDF_FormField*> FieldArray =
2787 GetFormFields(pDocument, swFieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002788
Lei Zhangd88a3642015-11-10 09:38:57 -08002789 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002790 if (pFormField->GetFullName().Compare(swFieldName) != 0)
2791 continue;
2792
2793 switch (pFormField->GetFieldType()) {
2794 case FIELDTYPE_TEXTFIELD:
2795 case FIELDTYPE_COMBOBOX:
tsepez41a53ad2016-03-28 16:59:30 -07002796 if (pFormField->GetValue() != strArray[0]) {
2797 pFormField->SetValue(strArray[0], TRUE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002798 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
2799 }
2800 break;
tsepez41a53ad2016-03-28 16:59:30 -07002801 case FIELDTYPE_CHECKBOX:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002802 case FIELDTYPE_RADIOBUTTON: {
tsepez41a53ad2016-03-28 16:59:30 -07002803 if (pFormField->GetValue() != strArray[0]) {
2804 pFormField->SetValue(strArray[0], TRUE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002805 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
2806 }
2807 } break;
2808 case FIELDTYPE_LISTBOX: {
2809 FX_BOOL bModified = FALSE;
tsepez41a53ad2016-03-28 16:59:30 -07002810 for (const auto& str : strArray) {
2811 if (!pFormField->IsItemSelected(pFormField->FindOption(str))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002812 bModified = TRUE;
2813 break;
2814 }
2815 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002816 if (bModified) {
2817 pFormField->ClearSelection(TRUE);
tsepez41a53ad2016-03-28 16:59:30 -07002818 for (const auto& str : strArray) {
2819 int index = pFormField->FindOption(str);
2820 if (!pFormField->IsItemSelected(index))
2821 pFormField->SetItemSelection(index, TRUE, TRUE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002822 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002823 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
2824 }
2825 } break;
2826 default:
2827 break;
2828 }
2829 }
2830}
2831
Tom Sepezba038bc2015-10-08 12:03:00 -07002832FX_BOOL Field::valueAsString(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002833 CJS_PropValue& vp,
2834 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002835 if (!vp.IsGetting())
2836 return FALSE;
2837
Lei Zhangd88a3642015-11-10 09:38:57 -08002838 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2839 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002840 return FALSE;
2841
Lei Zhangd88a3642015-11-10 09:38:57 -08002842 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002843 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
2844 return FALSE;
2845
2846 if (pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) {
2847 if (!pFormField->CountControls())
2848 return FALSE;
2849
2850 if (pFormField->GetControl(0)->IsChecked())
2851 vp << L"Yes";
2852 else
2853 vp << L"Off";
2854 } else if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON &&
2855 !(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)) {
2856 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2857 if (pFormField->GetControl(i)->IsChecked()) {
2858 vp << pFormField->GetControl(i)->GetExportValue().c_str();
2859 break;
Lei Zhangd88a3642015-11-10 09:38:57 -08002860 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002861 vp << L"Off";
Lei Zhangd88a3642015-11-10 09:38:57 -08002862 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002863 }
2864 } else if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX &&
2865 (pFormField->CountSelectedItems() > 1)) {
2866 vp << L"";
Lei Zhangd88a3642015-11-10 09:38:57 -08002867 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002868 vp << pFormField->GetValue().c_str();
Lei Zhangd88a3642015-11-10 09:38:57 -08002869 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002870
2871 return TRUE;
2872}
2873
Tom Sepezba038bc2015-10-08 12:03:00 -07002874FX_BOOL Field::browseForFileToSubmit(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08002875 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002876 CJS_Value& vRet,
2877 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002878 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2879 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002880 return FALSE;
2881
Lei Zhangd88a3642015-11-10 09:38:57 -08002882 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002883 CPDFDoc_Environment* pApp = m_pDocument->GetEnv();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002884 if ((pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) &&
2885 (pFormField->GetFieldType() == FIELDTYPE_TEXTFIELD)) {
2886 CFX_WideString wsFileName = pApp->JS_fieldBrowse();
2887 if (!wsFileName.IsEmpty()) {
2888 pFormField->SetValue(wsFileName);
2889 UpdateFormField(m_pDocument, pFormField, TRUE, TRUE, TRUE);
2890 }
Lei Zhangd88a3642015-11-10 09:38:57 -08002891 return TRUE;
2892 }
2893 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002894}
2895
Tom Sepezba038bc2015-10-08 12:03:00 -07002896FX_BOOL Field::buttonGetCaption(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08002897 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002898 CJS_Value& vRet,
2899 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002900 int nface = 0;
2901 int iSize = params.size();
2902 if (iSize >= 1)
2903 nface = params[0].ToInt();
2904
Lei Zhangd88a3642015-11-10 09:38:57 -08002905 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2906 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002907 return FALSE;
2908
Lei Zhangd88a3642015-11-10 09:38:57 -08002909 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002910 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
2911 return FALSE;
2912
2913 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2914 if (!pFormControl)
2915 return FALSE;
2916
2917 if (nface == 0)
2918 vRet = pFormControl->GetNormalCaption().c_str();
2919 else if (nface == 1)
2920 vRet = pFormControl->GetDownCaption().c_str();
2921 else if (nface == 2)
2922 vRet = pFormControl->GetRolloverCaption().c_str();
2923 else
2924 return FALSE;
2925
2926 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002927}
2928
Tom Sepezba038bc2015-10-08 12:03:00 -07002929FX_BOOL Field::buttonGetIcon(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08002930 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002931 CJS_Value& vRet,
2932 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002933 int nface = 0;
2934 int iSize = params.size();
2935 if (iSize >= 1)
2936 nface = params[0].ToInt();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002937
Lei Zhangd88a3642015-11-10 09:38:57 -08002938 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2939 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002940 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002941
Lei Zhangd88a3642015-11-10 09:38:57 -08002942 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002943 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
2944 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002945
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002946 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2947 if (!pFormControl)
2948 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002949
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002950 CJS_Context* pContext = (CJS_Context*)cc;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002951 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
Tom Sepezcd56a7d2015-10-06 11:45:28 -07002952 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
Tom Sepez33420902015-10-13 15:00:10 -07002953 pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002954 ASSERT(pObj.IsEmpty() == FALSE);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002955
Tom Sepezd5a0e952015-09-17 15:40:06 -07002956 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002957 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002958
thestig1cd352e2016-06-07 17:53:06 -07002959 CPDF_Stream* pIconStream = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002960 if (nface == 0)
2961 pIconStream = pFormControl->GetNormalIcon();
2962 else if (nface == 1)
2963 pIconStream = pFormControl->GetDownIcon();
2964 else if (nface == 2)
2965 pIconStream = pFormControl->GetRolloverIcon();
2966 else
2967 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002968
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002969 pIcon->SetStream(pIconStream);
2970 vRet = pJS_Icon;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002971
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002972 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002973}
2974
Tom Sepezba038bc2015-10-08 12:03:00 -07002975FX_BOOL Field::buttonImportIcon(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08002976 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002977 CJS_Value& vRet,
2978 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002979 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002980}
2981
Tom Sepezba038bc2015-10-08 12:03:00 -07002982FX_BOOL Field::buttonSetCaption(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08002983 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002984 CJS_Value& vRet,
2985 CFX_WideString& sError) {
2986 return FALSE;
2987}
2988
Tom Sepezba038bc2015-10-08 12:03:00 -07002989FX_BOOL Field::buttonSetIcon(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08002990 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002991 CJS_Value& vRet,
2992 CFX_WideString& sError) {
2993 return FALSE;
2994}
2995
Tom Sepezba038bc2015-10-08 12:03:00 -07002996FX_BOOL Field::checkThisBox(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08002997 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002998 CJS_Value& vRet,
2999 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08003000 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003001
3002 if (!m_bCanSet)
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003003 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003004
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003005 int iSize = params.size();
3006 if (iSize < 1)
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003007 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003008
3009 int nWidget = params[0].ToInt();
3010
Wei Li97da9762016-03-11 17:00:48 -08003011 bool bCheckit = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003012 if (iSize >= 2)
3013 bCheckit = params[1].ToBool();
3014
Lei Zhangd88a3642015-11-10 09:38:57 -08003015 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3016 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003017 return FALSE;
3018
Lei Zhangd88a3642015-11-10 09:38:57 -08003019 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003020 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
3021 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
3022 return FALSE;
3023 if (nWidget < 0 || nWidget >= pFormField->CountControls())
3024 return FALSE;
Wei Li97da9762016-03-11 17:00:48 -08003025 // TODO(weili): Check whether anything special needed for radio button,
3026 // otherwise merge these branches.
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003027 if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)
Wei Li97da9762016-03-11 17:00:48 -08003028 pFormField->CheckControl(nWidget, bCheckit, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003029 else
Wei Li97da9762016-03-11 17:00:48 -08003030 pFormField->CheckControl(nWidget, bCheckit, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003031
3032 UpdateFormField(m_pDocument, pFormField, TRUE, TRUE, TRUE);
3033 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003034}
3035
Tom Sepezba038bc2015-10-08 12:03:00 -07003036FX_BOOL Field::clearItems(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003037 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003038 CJS_Value& vRet,
3039 CFX_WideString& sError) {
3040 return TRUE;
3041}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003042
Tom Sepezba038bc2015-10-08 12:03:00 -07003043FX_BOOL Field::defaultIsChecked(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003044 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003045 CJS_Value& vRet,
3046 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003047 if (!m_bCanSet)
3048 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003049
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003050 int iSize = params.size();
3051 if (iSize < 1)
3052 return FALSE;
Tom Sepezf4ef3f92015-04-23 11:31:31 -07003053
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003054 int nWidget = params[0].ToInt();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003055
Lei Zhangd88a3642015-11-10 09:38:57 -08003056 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3057 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003058 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003059
Lei Zhangd88a3642015-11-10 09:38:57 -08003060 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003061 if (nWidget < 0 || nWidget >= pFormField->CountControls()) {
3062 vRet = FALSE;
3063 return FALSE;
3064 }
Lei Zhangd88a3642015-11-10 09:38:57 -08003065 vRet = pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
3066 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003067
3068 return TRUE;
3069}
3070
Tom Sepezba038bc2015-10-08 12:03:00 -07003071FX_BOOL Field::deleteItemAt(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003072 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003073 CJS_Value& vRet,
3074 CFX_WideString& sError) {
3075 return TRUE;
3076}
3077
Tom Sepezba038bc2015-10-08 12:03:00 -07003078FX_BOOL Field::getArray(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003079 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003080 CJS_Value& vRet,
3081 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08003082 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3083 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003084 return FALSE;
3085
Tom Sepezb9cc7a02016-02-01 13:42:30 -08003086 std::vector<std::unique_ptr<CFX_WideString>> swSort;
3087 for (CPDF_FormField* pFormField : FieldArray) {
3088 swSort.push_back(std::unique_ptr<CFX_WideString>(
3089 new CFX_WideString(pFormField->GetFullName())));
3090 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003091
Tom Sepezb9cc7a02016-02-01 13:42:30 -08003092 std::sort(
3093 swSort.begin(), swSort.end(),
3094 [](const std::unique_ptr<CFX_WideString>& p1,
3095 const std::unique_ptr<CFX_WideString>& p2) { return *p1 < *p2; });
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003096
3097 CJS_Context* pContext = (CJS_Context*)cc;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003098 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
Tom Sepez67fd5df2015-10-08 12:24:19 -07003099 CJS_Array FormFieldArray(pRuntime);
Tom Sepezb9cc7a02016-02-01 13:42:30 -08003100
3101 int j = 0;
3102 for (const auto& pStr : swSort) {
Tom Sepez39bfe122015-09-17 15:25:23 -07003103 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
Tom Sepez33420902015-10-13 15:00:10 -07003104 pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID);
Tom Sepezcd56a7d2015-10-06 11:45:28 -07003105 ASSERT(!pObj.IsEmpty());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003106
Tom Sepezd5a0e952015-09-17 15:40:06 -07003107 CJS_Field* pJSField =
Tom Sepezb9cc7a02016-02-01 13:42:30 -08003108 static_cast<CJS_Field*>(FXJS_GetPrivate(pRuntime->GetIsolate(), pObj));
3109 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003110 pField->AttachField(m_pJSDoc, *pStr);
3111
Tom Sepez67fd5df2015-10-08 12:24:19 -07003112 CJS_Value FormFieldValue(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003113 FormFieldValue = pJSField;
Tom Sepezb9cc7a02016-02-01 13:42:30 -08003114 FormFieldArray.SetElement(j++, FormFieldValue);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003115 }
3116
3117 vRet = FormFieldArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003118 return TRUE;
3119}
3120
Tom Sepezba038bc2015-10-08 12:03:00 -07003121FX_BOOL Field::getItemAt(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003122 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003123 CJS_Value& vRet,
3124 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003125 int iSize = params.size();
3126
3127 int nIdx = -1;
3128 if (iSize >= 1)
3129 nIdx = params[0].ToInt();
3130
3131 FX_BOOL bExport = TRUE;
3132 if (iSize >= 2)
3133 bExport = params[1].ToBool();
3134
Lei Zhangd88a3642015-11-10 09:38:57 -08003135 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3136 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003137 return FALSE;
3138
Lei Zhangd88a3642015-11-10 09:38:57 -08003139 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003140 if ((pFormField->GetFieldType() == FIELDTYPE_LISTBOX) ||
3141 (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX)) {
3142 if (nIdx == -1 || nIdx > pFormField->CountOptions())
3143 nIdx = pFormField->CountOptions() - 1;
3144 if (bExport) {
3145 CFX_WideString strval = pFormField->GetOptionValue(nIdx);
3146 if (strval.IsEmpty())
3147 vRet = pFormField->GetOptionLabel(nIdx).c_str();
3148 else
3149 vRet = strval.c_str();
Lei Zhangd88a3642015-11-10 09:38:57 -08003150 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003151 vRet = pFormField->GetOptionLabel(nIdx).c_str();
Lei Zhangd88a3642015-11-10 09:38:57 -08003152 }
3153 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003154 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08003155 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003156
3157 return TRUE;
3158}
3159
Tom Sepezba038bc2015-10-08 12:03:00 -07003160FX_BOOL Field::getLock(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003161 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003162 CJS_Value& vRet,
3163 CFX_WideString& sError) {
3164 return FALSE;
3165}
3166
Tom Sepezba038bc2015-10-08 12:03:00 -07003167FX_BOOL Field::insertItemAt(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003168 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003169 CJS_Value& vRet,
3170 CFX_WideString& sError) {
3171 return TRUE;
3172}
3173
Tom Sepezba038bc2015-10-08 12:03:00 -07003174FX_BOOL Field::isBoxChecked(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003175 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003176 CJS_Value& vRet,
3177 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003178 int nIndex = -1;
3179 if (params.size() >= 1)
3180 nIndex = params[0].ToInt();
3181
Lei Zhangd88a3642015-11-10 09:38:57 -08003182 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3183 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003184 return FALSE;
3185
Lei Zhangd88a3642015-11-10 09:38:57 -08003186 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003187 if (nIndex < 0 || nIndex >= pFormField->CountControls()) {
3188 vRet = FALSE;
3189 return FALSE;
3190 }
3191
3192 if ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) ||
3193 (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)) {
3194 if (pFormField->GetControl(nIndex)->IsChecked() != 0)
3195 vRet = TRUE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003196 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003197 vRet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08003198 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003199 vRet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08003200 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003201
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003202 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003203}
3204
Tom Sepezba038bc2015-10-08 12:03:00 -07003205FX_BOOL Field::isDefaultChecked(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003206 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003207 CJS_Value& vRet,
3208 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003209 int nIndex = -1;
3210 if (params.size() >= 1)
3211 nIndex = params[0].ToInt();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003212
Lei Zhangd88a3642015-11-10 09:38:57 -08003213 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3214 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003215 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003216
Lei Zhangd88a3642015-11-10 09:38:57 -08003217 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003218 if (nIndex < 0 || nIndex >= pFormField->CountControls()) {
3219 vRet = FALSE;
3220 return FALSE;
3221 }
3222 if ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) ||
3223 (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)) {
3224 if (pFormField->GetControl(nIndex)->IsDefaultChecked() != 0)
3225 vRet = TRUE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003226 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003227 vRet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08003228 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003229 vRet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08003230 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003231
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003232 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003233}
3234
Tom Sepezba038bc2015-10-08 12:03:00 -07003235FX_BOOL Field::setAction(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003236 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003237 CJS_Value& vRet,
3238 CFX_WideString& sError) {
3239 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003240}
3241
Tom Sepezba038bc2015-10-08 12:03:00 -07003242FX_BOOL Field::setFocus(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003243 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003244 CJS_Value& vRet,
3245 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08003246 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3247 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003248 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003249
Lei Zhangd88a3642015-11-10 09:38:57 -08003250 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003251 int32_t nCount = pFormField->CountControls();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003252 if (nCount < 1)
3253 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003254
tsepez23ae4a52016-06-08 20:44:54 -07003255 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
thestig1cd352e2016-06-07 17:53:06 -07003256 CPDFSDK_Widget* pWidget = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003257 if (nCount == 1) {
3258 pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
3259 } else {
3260 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
Tom Sepez50d12ad2015-11-24 09:50:51 -08003261 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(
3262 pEnv->FFI_GetCurrentPage(m_pDocument->GetUnderlyingDocument()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003263 if (!pPage)
3264 return FALSE;
3265 if (CPDFSDK_PageView* pCurPageView = m_pDocument->GetPageView(pPage)) {
3266 for (int32_t i = 0; i < nCount; i++) {
3267 if (CPDFSDK_Widget* pTempWidget =
3268 pInterForm->GetWidget(pFormField->GetControl(i))) {
3269 if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage()) {
3270 pWidget = pTempWidget;
3271 break;
3272 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003273 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003274 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003275 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003276 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003277
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003278 if (pWidget) {
3279 m_pDocument->SetFocusAnnot(pWidget);
3280 }
3281
3282 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003283}
3284
Tom Sepezba038bc2015-10-08 12:03:00 -07003285FX_BOOL Field::setItems(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003286 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003287 CJS_Value& vRet,
3288 CFX_WideString& sError) {
3289 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003290}
3291
Tom Sepezba038bc2015-10-08 12:03:00 -07003292FX_BOOL Field::setLock(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003293 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003294 CJS_Value& vRet,
3295 CFX_WideString& sError) {
3296 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003297}
3298
Tom Sepezba038bc2015-10-08 12:03:00 -07003299FX_BOOL Field::signatureGetModifications(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003300 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003301 CJS_Value& vRet,
3302 CFX_WideString& sError) {
3303 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003304}
3305
Tom Sepezba038bc2015-10-08 12:03:00 -07003306FX_BOOL Field::signatureGetSeedValue(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003307 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003308 CJS_Value& vRet,
3309 CFX_WideString& sError) {
3310 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003311}
3312
Tom Sepezba038bc2015-10-08 12:03:00 -07003313FX_BOOL Field::signatureInfo(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003314 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003315 CJS_Value& vRet,
3316 CFX_WideString& sError) {
3317 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003318}
3319
Tom Sepezba038bc2015-10-08 12:03:00 -07003320FX_BOOL Field::signatureSetSeedValue(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003321 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003322 CJS_Value& vRet,
3323 CFX_WideString& sError) {
3324 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003325}
3326
Tom Sepezba038bc2015-10-08 12:03:00 -07003327FX_BOOL Field::signatureSign(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003328 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003329 CJS_Value& vRet,
3330 CFX_WideString& sError) {
3331 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003332}
3333
Tom Sepezba038bc2015-10-08 12:03:00 -07003334FX_BOOL Field::signatureValidate(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003335 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003336 CJS_Value& vRet,
3337 CFX_WideString& sError) {
3338 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003339}
3340
Tom Sepezba038bc2015-10-08 12:03:00 -07003341FX_BOOL Field::source(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003342 CJS_PropValue& vp,
3343 CFX_WideString& sError) {
3344 if (vp.IsGetting()) {
thestig1cd352e2016-06-07 17:53:06 -07003345 vp << (CJS_Object*)nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003346 }
3347
3348 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003349}
3350
tsepez41a53ad2016-03-28 16:59:30 -07003351void Field::AddDelay_Int(FIELD_PROP prop, int32_t n) {
3352 CJS_DelayData* pNewData =
3353 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003354 pNewData->num = n;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003355 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003356}
3357
tsepez41a53ad2016-03-28 16:59:30 -07003358void Field::AddDelay_Bool(FIELD_PROP prop, bool b) {
3359 CJS_DelayData* pNewData =
3360 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003361 pNewData->b = b;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003362 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003363}
3364
tsepez41a53ad2016-03-28 16:59:30 -07003365void Field::AddDelay_String(FIELD_PROP prop, const CFX_ByteString& string) {
3366 CJS_DelayData* pNewData =
3367 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003368 pNewData->string = string;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003369 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003370}
3371
tsepez41a53ad2016-03-28 16:59:30 -07003372void Field::AddDelay_WideString(FIELD_PROP prop, const CFX_WideString& string) {
3373 CJS_DelayData* pNewData =
3374 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003375 pNewData->widestring = string;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003376 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003377}
3378
tsepez41a53ad2016-03-28 16:59:30 -07003379void Field::AddDelay_Rect(FIELD_PROP prop, const CFX_FloatRect& rect) {
3380 CJS_DelayData* pNewData =
3381 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003382 pNewData->rect = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003383 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003384}
3385
tsepez41a53ad2016-03-28 16:59:30 -07003386void Field::AddDelay_Color(FIELD_PROP prop, const CPWL_Color& color) {
3387 CJS_DelayData* pNewData =
3388 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003389 pNewData->color = color;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003390 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003391}
3392
tsepez41a53ad2016-03-28 16:59:30 -07003393void Field::AddDelay_WordArray(FIELD_PROP prop,
3394 const std::vector<uint32_t>& array) {
3395 CJS_DelayData* pNewData =
3396 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
3397 pNewData->wordarray = array;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003398 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003399}
3400
tsepez41a53ad2016-03-28 16:59:30 -07003401void Field::AddDelay_WideStringArray(FIELD_PROP prop,
3402 const std::vector<CFX_WideString>& array) {
3403 CJS_DelayData* pNewData =
3404 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
3405 pNewData->widestringarray = array;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003406 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003407}
3408
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003409void Field::DoDelay(CPDFSDK_Document* pDocument, CJS_DelayData* pData) {
Lei Zhang96660d62015-12-14 18:27:25 -08003410 ASSERT(pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003411 switch (pData->eProp) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003412 case FP_ALIGNMENT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003413 Field::SetAlignment(pDocument, pData->sFieldName, pData->nControlIndex,
3414 pData->string);
3415 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003416 case FP_BORDERSTYLE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003417 Field::SetBorderStyle(pDocument, pData->sFieldName, pData->nControlIndex,
3418 pData->string);
3419 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003420 case FP_BUTTONALIGNX:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003421 Field::SetButtonAlignX(pDocument, pData->sFieldName, pData->nControlIndex,
3422 pData->num);
3423 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003424 case FP_BUTTONALIGNY:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003425 Field::SetButtonAlignY(pDocument, pData->sFieldName, pData->nControlIndex,
3426 pData->num);
3427 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003428 case FP_BUTTONFITBOUNDS:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003429 Field::SetButtonFitBounds(pDocument, pData->sFieldName,
3430 pData->nControlIndex, pData->b);
3431 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003432 case FP_BUTTONPOSITION:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003433 Field::SetButtonPosition(pDocument, pData->sFieldName,
3434 pData->nControlIndex, pData->num);
3435 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003436 case FP_BUTTONSCALEHOW:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003437 Field::SetButtonScaleHow(pDocument, pData->sFieldName,
3438 pData->nControlIndex, pData->num);
3439 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003440 case FP_BUTTONSCALEWHEN:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003441 Field::SetButtonScaleWhen(pDocument, pData->sFieldName,
3442 pData->nControlIndex, pData->num);
3443 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003444 case FP_CALCORDERINDEX:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003445 Field::SetCalcOrderIndex(pDocument, pData->sFieldName,
3446 pData->nControlIndex, pData->num);
3447 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003448 case FP_CHARLIMIT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003449 Field::SetCharLimit(pDocument, pData->sFieldName, pData->nControlIndex,
3450 pData->num);
3451 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003452 case FP_COMB:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003453 Field::SetComb(pDocument, pData->sFieldName, pData->nControlIndex,
3454 pData->b);
3455 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003456 case FP_COMMITONSELCHANGE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003457 Field::SetCommitOnSelChange(pDocument, pData->sFieldName,
3458 pData->nControlIndex, pData->b);
3459 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003460 case FP_CURRENTVALUEINDICES:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003461 Field::SetCurrentValueIndices(pDocument, pData->sFieldName,
3462 pData->nControlIndex, pData->wordarray);
3463 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003464 case FP_DEFAULTVALUE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003465 Field::SetDefaultValue(pDocument, pData->sFieldName, pData->nControlIndex,
3466 pData->widestring);
3467 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003468 case FP_DONOTSCROLL:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003469 Field::SetDoNotScroll(pDocument, pData->sFieldName, pData->nControlIndex,
3470 pData->b);
3471 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003472 case FP_DISPLAY:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003473 Field::SetDisplay(pDocument, pData->sFieldName, pData->nControlIndex,
3474 pData->num);
3475 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003476 case FP_FILLCOLOR:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003477 Field::SetFillColor(pDocument, pData->sFieldName, pData->nControlIndex,
3478 pData->color);
3479 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003480 case FP_HIDDEN:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003481 Field::SetHidden(pDocument, pData->sFieldName, pData->nControlIndex,
3482 pData->b);
3483 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003484 case FP_HIGHLIGHT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003485 Field::SetHighlight(pDocument, pData->sFieldName, pData->nControlIndex,
3486 pData->string);
3487 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003488 case FP_LINEWIDTH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003489 Field::SetLineWidth(pDocument, pData->sFieldName, pData->nControlIndex,
3490 pData->num);
3491 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003492 case FP_MULTILINE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003493 Field::SetMultiline(pDocument, pData->sFieldName, pData->nControlIndex,
3494 pData->b);
3495 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003496 case FP_MULTIPLESELECTION:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003497 Field::SetMultipleSelection(pDocument, pData->sFieldName,
3498 pData->nControlIndex, pData->b);
3499 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003500 case FP_PASSWORD:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003501 Field::SetPassword(pDocument, pData->sFieldName, pData->nControlIndex,
3502 pData->b);
3503 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003504 case FP_RECT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003505 Field::SetRect(pDocument, pData->sFieldName, pData->nControlIndex,
3506 pData->rect);
3507 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003508 case FP_RICHTEXT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003509 Field::SetRichText(pDocument, pData->sFieldName, pData->nControlIndex,
3510 pData->b);
3511 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003512 case FP_RICHVALUE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003513 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003514 case FP_ROTATION:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003515 Field::SetRotation(pDocument, pData->sFieldName, pData->nControlIndex,
3516 pData->num);
3517 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003518 case FP_STROKECOLOR:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003519 Field::SetStrokeColor(pDocument, pData->sFieldName, pData->nControlIndex,
3520 pData->color);
3521 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003522 case FP_STYLE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003523 Field::SetStyle(pDocument, pData->sFieldName, pData->nControlIndex,
3524 pData->string);
3525 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003526 case FP_TEXTCOLOR:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003527 Field::SetTextColor(pDocument, pData->sFieldName, pData->nControlIndex,
3528 pData->color);
3529 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003530 case FP_TEXTFONT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003531 Field::SetTextFont(pDocument, pData->sFieldName, pData->nControlIndex,
3532 pData->string);
3533 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003534 case FP_TEXTSIZE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003535 Field::SetTextSize(pDocument, pData->sFieldName, pData->nControlIndex,
3536 pData->num);
3537 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003538 case FP_USERNAME:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003539 Field::SetUserName(pDocument, pData->sFieldName, pData->nControlIndex,
3540 pData->widestring);
3541 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003542 case FP_VALUE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003543 Field::SetValue(pDocument, pData->sFieldName, pData->nControlIndex,
3544 pData->widestringarray);
3545 break;
3546 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003547}
3548
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003549void Field::AddField(CPDFSDK_Document* pDocument,
3550 int nPageIndex,
3551 int nFieldType,
3552 const CFX_WideString& sName,
Tom Sepez281a9ea2016-02-26 14:24:28 -08003553 const CFX_FloatRect& rcCoords) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003554 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003555}