blob: 82187c24538ceb3b71354594440b7841b83a45bc [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 Sinclairefbc1912016-02-17 16:54:43 -05007#include "fpdfsdk/src/javascript/Field.h"
Tom Sepez37458412015-10-06 11:33:46 -07008
Tom Sepezb9cc7a02016-02-01 13:42:30 -08009#include <algorithm>
10#include <memory>
11#include <vector>
12
Lei Zhangbde53d22015-11-12 22:21:30 -080013#include "fpdfsdk/include/fsdk_mgr.h" // For CPDFDoc_Environment.
14#include "fpdfsdk/include/javascript/IJavaScript.h"
Dan Sinclairefbc1912016-02-17 16:54:43 -050015#include "fpdfsdk/src/javascript/Document.h"
16#include "fpdfsdk/src/javascript/Icon.h"
17#include "fpdfsdk/src/javascript/JS_Context.h"
18#include "fpdfsdk/src/javascript/JS_Define.h"
19#include "fpdfsdk/src/javascript/JS_EventHandler.h"
20#include "fpdfsdk/src/javascript/JS_Object.h"
21#include "fpdfsdk/src/javascript/JS_Runtime.h"
22#include "fpdfsdk/src/javascript/JS_Value.h"
23#include "fpdfsdk/src/javascript/PublicMethods.h"
24#include "fpdfsdk/src/javascript/color.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070025
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070026BEGIN_JS_STATIC_CONST(CJS_Field)
27END_JS_STATIC_CONST()
28
29BEGIN_JS_STATIC_PROP(CJS_Field)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070030JS_STATIC_PROP_ENTRY(alignment)
31JS_STATIC_PROP_ENTRY(borderStyle)
32JS_STATIC_PROP_ENTRY(buttonAlignX)
33JS_STATIC_PROP_ENTRY(buttonAlignY)
34JS_STATIC_PROP_ENTRY(buttonFitBounds)
35JS_STATIC_PROP_ENTRY(buttonPosition)
36JS_STATIC_PROP_ENTRY(buttonScaleHow)
37JS_STATIC_PROP_ENTRY(buttonScaleWhen)
38JS_STATIC_PROP_ENTRY(calcOrderIndex)
39JS_STATIC_PROP_ENTRY(charLimit)
40JS_STATIC_PROP_ENTRY(comb)
41JS_STATIC_PROP_ENTRY(commitOnSelChange)
42JS_STATIC_PROP_ENTRY(currentValueIndices)
43JS_STATIC_PROP_ENTRY(defaultStyle)
44JS_STATIC_PROP_ENTRY(defaultValue)
45JS_STATIC_PROP_ENTRY(doNotScroll)
46JS_STATIC_PROP_ENTRY(doNotSpellCheck)
47JS_STATIC_PROP_ENTRY(delay)
48JS_STATIC_PROP_ENTRY(display)
49JS_STATIC_PROP_ENTRY(doc)
50JS_STATIC_PROP_ENTRY(editable)
51JS_STATIC_PROP_ENTRY(exportValues)
52JS_STATIC_PROP_ENTRY(hidden)
53JS_STATIC_PROP_ENTRY(fileSelect)
54JS_STATIC_PROP_ENTRY(fillColor)
55JS_STATIC_PROP_ENTRY(lineWidth)
56JS_STATIC_PROP_ENTRY(highlight)
57JS_STATIC_PROP_ENTRY(multiline)
58JS_STATIC_PROP_ENTRY(multipleSelection)
59JS_STATIC_PROP_ENTRY(name)
60JS_STATIC_PROP_ENTRY(numItems)
61JS_STATIC_PROP_ENTRY(page)
62JS_STATIC_PROP_ENTRY(password)
63JS_STATIC_PROP_ENTRY(print)
64JS_STATIC_PROP_ENTRY(radiosInUnison)
65JS_STATIC_PROP_ENTRY(readonly)
66JS_STATIC_PROP_ENTRY(rect)
67JS_STATIC_PROP_ENTRY(required)
68JS_STATIC_PROP_ENTRY(richText)
69JS_STATIC_PROP_ENTRY(richValue)
70JS_STATIC_PROP_ENTRY(rotation)
71JS_STATIC_PROP_ENTRY(strokeColor)
72JS_STATIC_PROP_ENTRY(style)
73JS_STATIC_PROP_ENTRY(submitName)
74JS_STATIC_PROP_ENTRY(textColor)
75JS_STATIC_PROP_ENTRY(textFont)
76JS_STATIC_PROP_ENTRY(textSize)
77JS_STATIC_PROP_ENTRY(type)
78JS_STATIC_PROP_ENTRY(userName)
79JS_STATIC_PROP_ENTRY(value)
80JS_STATIC_PROP_ENTRY(valueAsString)
81JS_STATIC_PROP_ENTRY(source)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070082END_JS_STATIC_PROP()
83
84BEGIN_JS_STATIC_METHOD(CJS_Field)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070085JS_STATIC_METHOD_ENTRY(browseForFileToSubmit)
86JS_STATIC_METHOD_ENTRY(buttonGetCaption)
87JS_STATIC_METHOD_ENTRY(buttonGetIcon)
88JS_STATIC_METHOD_ENTRY(buttonImportIcon)
89JS_STATIC_METHOD_ENTRY(buttonSetCaption)
90JS_STATIC_METHOD_ENTRY(buttonSetIcon)
91JS_STATIC_METHOD_ENTRY(checkThisBox)
92JS_STATIC_METHOD_ENTRY(clearItems)
93JS_STATIC_METHOD_ENTRY(defaultIsChecked)
94JS_STATIC_METHOD_ENTRY(deleteItemAt)
95JS_STATIC_METHOD_ENTRY(getArray)
96JS_STATIC_METHOD_ENTRY(getItemAt)
97JS_STATIC_METHOD_ENTRY(getLock)
98JS_STATIC_METHOD_ENTRY(insertItemAt)
99JS_STATIC_METHOD_ENTRY(isBoxChecked)
100JS_STATIC_METHOD_ENTRY(isDefaultChecked)
101JS_STATIC_METHOD_ENTRY(setAction)
102JS_STATIC_METHOD_ENTRY(setFocus)
103JS_STATIC_METHOD_ENTRY(setItems)
104JS_STATIC_METHOD_ENTRY(setLock)
105JS_STATIC_METHOD_ENTRY(signatureGetModifications)
106JS_STATIC_METHOD_ENTRY(signatureGetSeedValue)
107JS_STATIC_METHOD_ENTRY(signatureInfo)
108JS_STATIC_METHOD_ENTRY(signatureSetSeedValue)
109JS_STATIC_METHOD_ENTRY(signatureSign)
110JS_STATIC_METHOD_ENTRY(signatureValidate)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700111END_JS_STATIC_METHOD()
112
113IMPLEMENT_JS_CLASS(CJS_Field, Field)
114
Tom Sepez33420902015-10-13 15:00:10 -0700115void CJS_Field::InitInstance(IJS_Runtime* pIRuntime) {
116 CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime);
117 Field* pField = static_cast<Field*>(GetEmbedObject());
118 pField->SetIsolate(pRuntime->GetIsolate());
Lei Zhangd88a3642015-11-10 09:38:57 -0800119}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700120
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700121Field::Field(CJS_Object* pJSObject)
122 : CJS_EmbedObj(pJSObject),
123 m_pJSDoc(NULL),
124 m_pDocument(NULL),
125 m_nFormControlIndex(-1),
126 m_bCanSet(FALSE),
127 m_bDelay(FALSE),
128 m_isolate(NULL) {}
129
130Field::~Field() {}
131
132// note: iControlNo = -1, means not a widget.
133void Field::ParseFieldName(const std::wstring& strFieldNameParsed,
134 std::wstring& strFieldName,
135 int& iControlNo) {
136 int iStart = strFieldNameParsed.find_last_of(L'.');
137 if (iStart == -1) {
138 strFieldName = strFieldNameParsed;
139 iControlNo = -1;
140 return;
141 }
142 std::wstring suffixal = strFieldNameParsed.substr(iStart + 1);
143 iControlNo = FXSYS_wtoi(suffixal.c_str());
144 if (iControlNo == 0) {
145 int iStart;
146 while ((iStart = suffixal.find_last_of(L" ")) != -1) {
147 suffixal.erase(iStart, 1);
148 }
149
150 if (suffixal.compare(L"0") != 0) {
151 strFieldName = strFieldNameParsed;
152 iControlNo = -1;
153 return;
154 }
155 }
156 strFieldName = strFieldNameParsed.substr(0, iStart);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700157}
158
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700159FX_BOOL Field::AttachField(Document* pDocument,
160 const CFX_WideString& csFieldName) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700161 m_pJSDoc = pDocument;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700162 m_pDocument = pDocument->GetReaderDoc();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700163 m_bCanSet = m_pDocument->GetPermissions(FPDFPERM_FILL_FORM) ||
164 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
165 m_pDocument->GetPermissions(FPDFPERM_MODIFY);
166
167 CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700168 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700169 CFX_WideString swFieldNameTemp = csFieldName;
170 swFieldNameTemp.Replace(L"..", L".");
171
172 if (pInterForm->CountFields(swFieldNameTemp) <= 0) {
173 std::wstring strFieldName;
174 int iControlNo = -1;
175 ParseFieldName(swFieldNameTemp.c_str(), strFieldName, iControlNo);
176 if (iControlNo == -1)
177 return FALSE;
178
179 m_FieldName = strFieldName.c_str();
180 m_nFormControlIndex = iControlNo;
181 return TRUE;
182 }
183
184 m_FieldName = swFieldNameTemp;
185 m_nFormControlIndex = -1;
186
187 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700188}
189
Lei Zhangd88a3642015-11-10 09:38:57 -0800190std::vector<CPDF_FormField*> Field::GetFormFields(
191 CPDFSDK_Document* pDocument,
192 const CFX_WideString& csFieldName) {
193 std::vector<CPDF_FormField*> fields;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700194 CPDFSDK_InterForm* pReaderInterForm = pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700195 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -0800196 for (int i = 0, sz = pInterForm->CountFields(csFieldName); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700197 if (CPDF_FormField* pFormField = pInterForm->GetField(i, csFieldName))
Lei Zhangd88a3642015-11-10 09:38:57 -0800198 fields.push_back(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700199 }
Lei Zhangd88a3642015-11-10 09:38:57 -0800200 return fields;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700201}
202
Lei Zhangd88a3642015-11-10 09:38:57 -0800203std::vector<CPDF_FormField*> Field::GetFormFields(
204 const CFX_WideString& csFieldName) const {
205 return Field::GetFormFields(m_pDocument, csFieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700206}
207
208void Field::UpdateFormField(CPDFSDK_Document* pDocument,
209 CPDF_FormField* pFormField,
210 FX_BOOL bChangeMark,
211 FX_BOOL bResetAP,
212 FX_BOOL bRefresh) {
Lei Zhangd88a3642015-11-10 09:38:57 -0800213 std::vector<CPDFSDK_Widget*> widgets;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700214 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -0800215 pInterForm->GetWidgets(pFormField, &widgets);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700216
217 if (bResetAP) {
218 int nFieldType = pFormField->GetFieldType();
219 if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_TEXTFIELD) {
Lei Zhangd88a3642015-11-10 09:38:57 -0800220 for (CPDFSDK_Widget* pWidget : widgets) {
221 FX_BOOL bFormatted = FALSE;
222 CFX_WideString sValue = pWidget->OnFormat(bFormatted);
223 pWidget->ResetAppearance(bFormatted ? sValue.c_str() : nullptr, FALSE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700224 }
225 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800226 for (CPDFSDK_Widget* pWidget : widgets) {
227 pWidget->ResetAppearance(nullptr, FALSE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700228 }
229 }
230 }
231
232 if (bRefresh) {
Lei Zhangd88a3642015-11-10 09:38:57 -0800233 for (CPDFSDK_Widget* pWidget : widgets) {
234 CPDFSDK_Document* pDoc = pWidget->GetInterForm()->GetDocument();
235 pDoc->UpdateAllViews(nullptr, pWidget);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700236 }
237 }
238
239 if (bChangeMark)
240 pDocument->SetChangeMark();
241}
242
243void Field::UpdateFormControl(CPDFSDK_Document* pDocument,
244 CPDF_FormControl* pFormControl,
245 FX_BOOL bChangeMark,
246 FX_BOOL bResetAP,
247 FX_BOOL bRefresh) {
Lei Zhang96660d62015-12-14 18:27:25 -0800248 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700249
250 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700251 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
252
253 if (pWidget) {
254 if (bResetAP) {
255 int nFieldType = pWidget->GetFieldType();
256 if (nFieldType == FIELDTYPE_COMBOBOX ||
257 nFieldType == FIELDTYPE_TEXTFIELD) {
258 FX_BOOL bFormated = FALSE;
259 CFX_WideString sValue = pWidget->OnFormat(bFormated);
260 if (bFormated)
261 pWidget->ResetAppearance(sValue.c_str(), FALSE);
262 else
263 pWidget->ResetAppearance(NULL, FALSE);
264 } else {
265 pWidget->ResetAppearance(NULL, FALSE);
266 }
267 }
268
269 if (bRefresh) {
270 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
271 CPDFSDK_Document* pDoc = pInterForm->GetDocument();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700272 pDoc->UpdateAllViews(NULL, pWidget);
273 }
274 }
275
276 if (bChangeMark)
277 pDocument->SetChangeMark();
278}
279
280CPDFSDK_Widget* Field::GetWidget(CPDFSDK_Document* pDocument,
281 CPDF_FormControl* pFormControl) {
Jun Fang14b20db2015-12-01 12:35:24 +0800282 CPDFSDK_InterForm* pInterForm =
283 static_cast<CPDFSDK_InterForm*>(pDocument->GetInterForm());
284 return pInterForm ? pInterForm->GetWidget(pFormControl) : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700285}
286
287FX_BOOL Field::ValueIsOccur(CPDF_FormField* pFormField,
288 CFX_WideString csOptLabel) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700289 for (int i = 0, sz = pFormField->CountOptions(); i < sz; i++) {
290 if (csOptLabel.Compare(pFormField->GetOptionLabel(i)) == 0)
291 return TRUE;
292 }
293
294 return FALSE;
295}
296
297CPDF_FormControl* Field::GetSmartFieldControl(CPDF_FormField* pFormField) {
298 if (!pFormField->CountControls() ||
299 m_nFormControlIndex >= pFormField->CountControls())
300 return NULL;
301
302 if (m_nFormControlIndex < 0)
303 return pFormField->GetControl(0);
304
305 return pFormField->GetControl(m_nFormControlIndex);
306}
307
Tom Sepezba038bc2015-10-08 12:03:00 -0700308FX_BOOL Field::alignment(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700309 CJS_PropValue& vp,
310 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800311 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700312
313 if (vp.IsSetting()) {
314 if (!m_bCanSet)
315 return FALSE;
316
317 CFX_ByteString alignStr;
318 vp >> alignStr;
319
320 if (m_bDelay) {
321 AddDelay_String(FP_ALIGNMENT, alignStr);
322 } else {
323 Field::SetAlignment(m_pDocument, m_FieldName, m_nFormControlIndex,
324 alignStr);
325 }
326 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800327 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
328 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700329 return FALSE;
330
Lei Zhangd88a3642015-11-10 09:38:57 -0800331 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700332 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
333 return FALSE;
334
335 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
336 if (!pFormControl)
337 return FALSE;
338
339 switch (pFormControl->GetControlAlignment()) {
340 case 1:
341 vp << L"center";
342 break;
343 case 0:
344 vp << L"left";
345 break;
346 case 2:
347 vp << L"right";
348 break;
349 default:
350 vp << L"";
351 }
352 }
353
354 return TRUE;
355}
356
357void Field::SetAlignment(CPDFSDK_Document* pDocument,
358 const CFX_WideString& swFieldName,
359 int nControlIndex,
360 const CFX_ByteString& string) {
361 // Not supported.
362}
363
Tom Sepezba038bc2015-10-08 12:03:00 -0700364FX_BOOL Field::borderStyle(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700365 CJS_PropValue& vp,
366 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800367 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700368
369 if (vp.IsSetting()) {
370 if (!m_bCanSet)
371 return FALSE;
372
373 CFX_ByteString strType = "";
374 vp >> strType;
375
376 if (m_bDelay) {
377 AddDelay_String(FP_BORDERSTYLE, strType);
378 } else {
379 Field::SetBorderStyle(m_pDocument, m_FieldName, m_nFormControlIndex,
380 strType);
381 }
382 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800383 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
384 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700385 return FALSE;
386
Lei Zhangd88a3642015-11-10 09:38:57 -0800387 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700388 if (!pFormField)
389 return FALSE;
390
391 CPDFSDK_Widget* pWidget =
392 GetWidget(m_pDocument, GetSmartFieldControl(pFormField));
393 if (!pWidget)
394 return FALSE;
395
396 int nBorderstyle = pWidget->GetBorderStyle();
397
398 switch (nBorderstyle) {
399 case BBS_SOLID:
400 vp << L"solid";
401 break;
402 case BBS_DASH:
403 vp << L"dashed";
404 break;
405 case BBS_BEVELED:
406 vp << L"beveled";
407 break;
408 case BBS_INSET:
409 vp << L"inset";
410 break;
411 case BBS_UNDERLINE:
412 vp << L"underline";
413 break;
414 default:
415 vp << L"";
416 break;
417 }
418 }
419
420 return TRUE;
421}
422
423void Field::SetBorderStyle(CPDFSDK_Document* pDocument,
424 const CFX_WideString& swFieldName,
425 int nControlIndex,
426 const CFX_ByteString& string) {
Lei Zhang96660d62015-12-14 18:27:25 -0800427 ASSERT(pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700428
429 int nBorderStyle = 0;
430
431 if (string == "solid")
432 nBorderStyle = BBS_SOLID;
433 else if (string == "beveled")
434 nBorderStyle = BBS_BEVELED;
435 else if (string == "dashed")
436 nBorderStyle = BBS_DASH;
437 else if (string == "inset")
438 nBorderStyle = BBS_INSET;
439 else if (string == "underline")
440 nBorderStyle = BBS_UNDERLINE;
441 else
442 return;
443
Lei Zhangd88a3642015-11-10 09:38:57 -0800444 std::vector<CPDF_FormField*> FieldArray =
445 GetFormFields(pDocument, swFieldName);
446 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700447 if (nControlIndex < 0) {
448 FX_BOOL bSet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -0800449 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700450 if (CPDFSDK_Widget* pWidget =
Lei Zhangd88a3642015-11-10 09:38:57 -0800451 GetWidget(pDocument, pFormField->GetControl(i))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700452 if (pWidget->GetBorderStyle() != nBorderStyle) {
453 pWidget->SetBorderStyle(nBorderStyle);
454 bSet = TRUE;
455 }
456 }
457 }
458 if (bSet)
459 UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
460 } else {
461 if (nControlIndex >= pFormField->CountControls())
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700462 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700463 if (CPDF_FormControl* pFormControl =
464 pFormField->GetControl(nControlIndex)) {
465 if (CPDFSDK_Widget* pWidget = GetWidget(pDocument, pFormControl)) {
466 if (pWidget->GetBorderStyle() != nBorderStyle) {
467 pWidget->SetBorderStyle(nBorderStyle);
468 UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
469 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700470 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700471 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700472 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700473 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700474}
475
Tom Sepezba038bc2015-10-08 12:03:00 -0700476FX_BOOL Field::buttonAlignX(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700477 CJS_PropValue& vp,
478 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800479 ASSERT(m_pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700480
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700481 if (vp.IsSetting()) {
482 if (!m_bCanSet)
483 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700484
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700485 int nVP;
486 vp >> nVP;
487
488 if (m_bDelay) {
489 AddDelay_Int(FP_BUTTONALIGNX, nVP);
490 } else {
491 Field::SetButtonAlignX(m_pDocument, m_FieldName, m_nFormControlIndex,
492 nVP);
493 }
494 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800495 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
496 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700497 return FALSE;
498
Lei Zhangd88a3642015-11-10 09:38:57 -0800499 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700500 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
501 return FALSE;
502
503 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
504 if (!pFormControl)
505 return FALSE;
506
507 CPDF_IconFit IconFit = pFormControl->GetIconFit();
508
509 FX_FLOAT fLeft, fBottom;
510 IconFit.GetIconPosition(fLeft, fBottom);
511
512 vp << (int32_t)fLeft;
513 }
514
515 return TRUE;
516}
517
518void Field::SetButtonAlignX(CPDFSDK_Document* pDocument,
519 const CFX_WideString& swFieldName,
520 int nControlIndex,
521 int number) {
522 // Not supported.
523}
524
Tom Sepezba038bc2015-10-08 12:03:00 -0700525FX_BOOL Field::buttonAlignY(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700526 CJS_PropValue& vp,
527 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800528 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700529
530 if (vp.IsSetting()) {
531 if (!m_bCanSet)
532 return FALSE;
533
534 int nVP;
535 vp >> nVP;
536
537 if (m_bDelay) {
538 AddDelay_Int(FP_BUTTONALIGNY, nVP);
539 } else {
540 Field::SetButtonAlignY(m_pDocument, m_FieldName, m_nFormControlIndex,
541 nVP);
542 }
543 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800544 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
545 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700546 return FALSE;
547
Lei Zhangd88a3642015-11-10 09:38:57 -0800548 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700549 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
550 return FALSE;
551
552 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
553 if (!pFormControl)
554 return FALSE;
555
556 CPDF_IconFit IconFit = pFormControl->GetIconFit();
557
558 FX_FLOAT fLeft, fBottom;
559 IconFit.GetIconPosition(fLeft, fBottom);
560
561 vp << (int32_t)fBottom;
562 }
563
564 return TRUE;
565}
566
567void Field::SetButtonAlignY(CPDFSDK_Document* pDocument,
568 const CFX_WideString& swFieldName,
569 int nControlIndex,
570 int number) {
571 // Not supported.
572}
573
Tom Sepezba038bc2015-10-08 12:03:00 -0700574FX_BOOL Field::buttonFitBounds(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700575 CJS_PropValue& vp,
576 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800577 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700578
579 if (vp.IsSetting()) {
580 if (!m_bCanSet)
581 return FALSE;
582
583 bool bVP;
584 vp >> bVP;
585
586 if (m_bDelay) {
587 AddDelay_Bool(FP_BUTTONFITBOUNDS, bVP);
588 } else {
589 Field::SetButtonFitBounds(m_pDocument, m_FieldName, m_nFormControlIndex,
590 bVP);
591 }
592 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800593 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
594 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700595 return FALSE;
596
Lei Zhangd88a3642015-11-10 09:38:57 -0800597 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700598 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
599 return FALSE;
600
601 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
602 if (!pFormControl)
603 return FALSE;
604
605 CPDF_IconFit IconFit = pFormControl->GetIconFit();
606 vp << IconFit.GetFittingBounds();
607 }
608
609 return TRUE;
610}
611
612void Field::SetButtonFitBounds(CPDFSDK_Document* pDocument,
613 const CFX_WideString& swFieldName,
614 int nControlIndex,
615 bool b) {
616 // Not supported.
617}
618
Tom Sepezba038bc2015-10-08 12:03:00 -0700619FX_BOOL Field::buttonPosition(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700620 CJS_PropValue& vp,
621 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800622 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700623
624 if (vp.IsSetting()) {
625 if (!m_bCanSet)
626 return FALSE;
627
628 int nVP;
629 vp >> nVP;
630
631 if (m_bDelay) {
632 AddDelay_Int(FP_BUTTONPOSITION, nVP);
633 } else {
634 Field::SetButtonPosition(m_pDocument, m_FieldName, m_nFormControlIndex,
635 nVP);
636 }
637 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800638 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
639 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700640 return FALSE;
641
Lei Zhangd88a3642015-11-10 09:38:57 -0800642 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700643 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
644 return FALSE;
645
646 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
647 if (!pFormControl)
648 return FALSE;
649
650 vp << pFormControl->GetTextPosition();
651 }
652 return TRUE;
653}
654
655void Field::SetButtonPosition(CPDFSDK_Document* pDocument,
656 const CFX_WideString& swFieldName,
657 int nControlIndex,
658 int number) {
659 // Not supported.
660}
661
Tom Sepezba038bc2015-10-08 12:03:00 -0700662FX_BOOL Field::buttonScaleHow(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700663 CJS_PropValue& vp,
664 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800665 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700666
667 if (vp.IsSetting()) {
668 if (!m_bCanSet)
669 return FALSE;
670
671 int nVP;
672 vp >> nVP;
673
674 if (m_bDelay) {
675 AddDelay_Int(FP_BUTTONSCALEHOW, nVP);
676 } else {
677 Field::SetButtonScaleHow(m_pDocument, m_FieldName, m_nFormControlIndex,
678 nVP);
679 }
680 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800681 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
682 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700683 return FALSE;
684
Lei Zhangd88a3642015-11-10 09:38:57 -0800685 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700686 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
687 return FALSE;
688
689 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
690 if (!pFormControl)
691 return FALSE;
692
693 CPDF_IconFit IconFit = pFormControl->GetIconFit();
694 if (IconFit.IsProportionalScale())
695 vp << (int32_t)0;
696 else
697 vp << (int32_t)1;
698 }
699
700 return TRUE;
701}
702
703void Field::SetButtonScaleHow(CPDFSDK_Document* pDocument,
704 const CFX_WideString& swFieldName,
705 int nControlIndex,
706 int number) {
707 // Not supported.
708}
709
Tom Sepezba038bc2015-10-08 12:03:00 -0700710FX_BOOL Field::buttonScaleWhen(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700711 CJS_PropValue& vp,
712 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800713 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700714
715 if (vp.IsSetting()) {
716 if (!m_bCanSet)
717 return FALSE;
718
719 int nVP;
720 vp >> nVP;
721
722 if (m_bDelay) {
723 AddDelay_Int(FP_BUTTONSCALEWHEN, nVP);
724 } else {
725 Field::SetButtonScaleWhen(m_pDocument, m_FieldName, m_nFormControlIndex,
726 nVP);
727 }
728 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800729 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
730 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700731 return FALSE;
732
Lei Zhangd88a3642015-11-10 09:38:57 -0800733 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700734 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
735 return FALSE;
736
737 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
738 if (!pFormControl)
739 return FALSE;
740
741 CPDF_IconFit IconFit = pFormControl->GetIconFit();
742 int ScaleM = IconFit.GetScaleMethod();
743 switch (ScaleM) {
744 case CPDF_IconFit::Always:
745 vp << (int32_t)CPDF_IconFit::Always;
746 break;
747 case CPDF_IconFit::Bigger:
748 vp << (int32_t)CPDF_IconFit::Bigger;
749 break;
750 case CPDF_IconFit::Never:
751 vp << (int32_t)CPDF_IconFit::Never;
752 break;
753 case CPDF_IconFit::Smaller:
754 vp << (int32_t)CPDF_IconFit::Smaller;
755 break;
756 }
757 }
758
759 return TRUE;
760}
761
762void Field::SetButtonScaleWhen(CPDFSDK_Document* pDocument,
763 const CFX_WideString& swFieldName,
764 int nControlIndex,
765 int number) {
766 // Not supported.
767}
768
Tom Sepezba038bc2015-10-08 12:03:00 -0700769FX_BOOL Field::calcOrderIndex(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700770 CJS_PropValue& vp,
771 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800772 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700773
774 if (vp.IsSetting()) {
775 if (!m_bCanSet)
776 return FALSE;
777
778 int nVP;
779 vp >> nVP;
780
781 if (m_bDelay) {
782 AddDelay_Int(FP_CALCORDERINDEX, nVP);
783 } else {
784 Field::SetCalcOrderIndex(m_pDocument, m_FieldName, m_nFormControlIndex,
785 nVP);
786 }
787 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800788 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
789 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700790 return FALSE;
791
Lei Zhangd88a3642015-11-10 09:38:57 -0800792 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700793 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -0800794 pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700795 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -0800796 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700797
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700798 CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700799 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700800 vp << (int32_t)pInterForm->FindFieldInCalculationOrder(pFormField);
801 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700802
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700803 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700804}
805
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700806void Field::SetCalcOrderIndex(CPDFSDK_Document* pDocument,
807 const CFX_WideString& swFieldName,
808 int nControlIndex,
809 int number) {
810 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700811}
812
Tom Sepezba038bc2015-10-08 12:03:00 -0700813FX_BOOL Field::charLimit(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700814 CJS_PropValue& vp,
815 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800816 ASSERT(m_pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700817
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700818 if (vp.IsSetting()) {
819 if (!m_bCanSet)
820 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700821
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700822 int nVP;
823 vp >> nVP;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700824
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700825 if (m_bDelay) {
826 AddDelay_Int(FP_CHARLIMIT, nVP);
827 } else {
828 Field::SetCharLimit(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700829 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700830 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800831 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
832 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700833 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700834
Lei Zhangd88a3642015-11-10 09:38:57 -0800835 CPDF_FormField* pFormField = FieldArray[0];
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700836 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700837 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700838
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700839 vp << (int32_t)pFormField->GetMaxLen();
840 }
841 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700842}
843
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700844void Field::SetCharLimit(CPDFSDK_Document* pDocument,
845 const CFX_WideString& swFieldName,
846 int nControlIndex,
847 int number) {
848 // Not supported.
849}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700850
Tom Sepezba038bc2015-10-08 12:03:00 -0700851FX_BOOL Field::comb(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700852 CJS_PropValue& vp,
853 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800854 ASSERT(m_pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700855
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700856 if (vp.IsSetting()) {
857 if (!m_bCanSet)
858 return FALSE;
859
860 bool bVP;
861 vp >> bVP;
862
863 if (m_bDelay) {
864 AddDelay_Bool(FP_COMB, bVP);
865 } else {
866 Field::SetComb(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
867 }
868 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800869 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
870 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700871 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700872
Lei Zhangd88a3642015-11-10 09:38:57 -0800873 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700874 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
875 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700876
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700877 if (pFormField->GetFieldFlags() & FIELDFLAG_COMB)
878 vp << true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700879 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700880 vp << false;
881 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700882
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700883 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700884}
885
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700886void Field::SetComb(CPDFSDK_Document* pDocument,
887 const CFX_WideString& swFieldName,
888 int nControlIndex,
889 bool b) {
890 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700891}
892
Tom Sepezba038bc2015-10-08 12:03:00 -0700893FX_BOOL Field::commitOnSelChange(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700894 CJS_PropValue& vp,
895 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800896 ASSERT(m_pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700897
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700898 if (vp.IsSetting()) {
899 if (!m_bCanSet)
900 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700901
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700902 bool bVP;
903 vp >> bVP;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700904
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700905 if (m_bDelay) {
906 AddDelay_Bool(FP_COMMITONSELCHANGE, bVP);
907 } else {
908 Field::SetCommitOnSelChange(m_pDocument, m_FieldName, m_nFormControlIndex,
909 bVP);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700910 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700911 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800912 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
913 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700914 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700915
Lei Zhangd88a3642015-11-10 09:38:57 -0800916 CPDF_FormField* pFormField = FieldArray[0];
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700917 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -0800918 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700919 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -0800920 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700921
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700922 if (pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE)
923 vp << true;
924 else
925 vp << false;
926 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700927
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700928 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700929}
930
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700931void Field::SetCommitOnSelChange(CPDFSDK_Document* pDocument,
932 const CFX_WideString& swFieldName,
933 int nControlIndex,
934 bool b) {
935 // Not supported.
936}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700937
Tom Sepezba038bc2015-10-08 12:03:00 -0700938FX_BOOL Field::currentValueIndices(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700939 CJS_PropValue& vp,
940 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -0700941 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700942
943 if (vp.IsSetting()) {
944 if (!m_bCanSet)
945 return FALSE;
946
947 CFX_DWordArray array;
948
Tom Sepez39bfe122015-09-17 15:25:23 -0700949 if (vp.GetType() == CJS_Value::VT_number) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700950 int iSelecting = 0;
951 vp >> iSelecting;
952 array.Add(iSelecting);
953 } else if (vp.IsArrayObject()) {
Tom Sepez67fd5df2015-10-08 12:24:19 -0700954 CJS_Array SelArray(pRuntime);
955 CJS_Value SelValue(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700956 int iSelecting;
957 vp >> SelArray;
958 for (int i = 0, sz = SelArray.GetLength(); i < sz; i++) {
959 SelArray.GetElement(i, SelValue);
960 iSelecting = SelValue.ToInt();
961 array.Add(iSelecting);
962 }
963 }
964
965 if (m_bDelay) {
966 AddDelay_WordArray(FP_CURRENTVALUEINDICES, array);
967 } else {
968 Field::SetCurrentValueIndices(m_pDocument, m_FieldName,
969 m_nFormControlIndex, array);
970 }
971 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800972 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
973 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700974 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700975
Lei Zhangd88a3642015-11-10 09:38:57 -0800976 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700977 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -0800978 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700979 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -0800980 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700981
Lei Zhangd88a3642015-11-10 09:38:57 -0800982 if (pFormField->CountSelectedItems() == 1) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700983 vp << pFormField->GetSelectedIndex(0);
Lei Zhangd88a3642015-11-10 09:38:57 -0800984 } else if (pFormField->CountSelectedItems() > 1) {
Tom Sepez67fd5df2015-10-08 12:24:19 -0700985 CJS_Array SelArray(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700986 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
987 SelArray.SetElement(
Tom Sepez67fd5df2015-10-08 12:24:19 -0700988 i, CJS_Value(pRuntime, pFormField->GetSelectedIndex(i)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700989 }
990 vp << SelArray;
Lei Zhangd88a3642015-11-10 09:38:57 -0800991 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700992 vp << -1;
Lei Zhangd88a3642015-11-10 09:38:57 -0800993 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700994 }
995
996 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700997}
998
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700999void Field::SetCurrentValueIndices(CPDFSDK_Document* pDocument,
1000 const CFX_WideString& swFieldName,
1001 int nControlIndex,
1002 const CFX_DWordArray& array) {
Lei Zhang96660d62015-12-14 18:27:25 -08001003 ASSERT(pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001004
Lei Zhangd88a3642015-11-10 09:38:57 -08001005 std::vector<CPDF_FormField*> FieldArray =
1006 GetFormFields(pDocument, swFieldName);
1007 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001008 int nFieldType = pFormField->GetFieldType();
1009 if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX) {
1010 FX_DWORD dwFieldFlags = pFormField->GetFieldFlags();
1011 pFormField->ClearSelection(TRUE);
1012
1013 for (int i = 0, sz = array.GetSize(); i < sz; i++) {
1014 if (i > 0 && !(dwFieldFlags & (1 << 21))) {
1015 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001016 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001017
1018 int iSelecting = (int32_t)array.GetAt(i);
1019 if (iSelecting < pFormField->CountOptions() &&
1020 !pFormField->IsItemSelected(iSelecting))
1021 pFormField->SetItemSelection(iSelecting, TRUE);
1022 }
1023 UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001024 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001025 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001026}
1027
Tom Sepezba038bc2015-10-08 12:03:00 -07001028FX_BOOL Field::defaultStyle(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001029 CJS_PropValue& vp,
1030 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001031 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001032}
1033
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001034void Field::SetDefaultStyle(CPDFSDK_Document* pDocument,
1035 const CFX_WideString& swFieldName,
1036 int nControlIndex) {
1037 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001038}
1039
Tom Sepezba038bc2015-10-08 12:03:00 -07001040FX_BOOL Field::defaultValue(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001041 CJS_PropValue& vp,
1042 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08001043 ASSERT(m_pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001044
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001045 if (vp.IsSetting()) {
1046 if (!m_bCanSet)
1047 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001048
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001049 CFX_WideString WideStr;
1050 vp >> WideStr;
1051
1052 if (m_bDelay) {
1053 AddDelay_WideString(FP_DEFAULTVALUE, WideStr);
1054 } else {
1055 Field::SetDefaultValue(m_pDocument, m_FieldName, m_nFormControlIndex,
1056 WideStr);
1057 }
1058 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001059 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1060 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001061 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001062
Lei Zhangd88a3642015-11-10 09:38:57 -08001063 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001064 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON ||
Lei Zhangd88a3642015-11-10 09:38:57 -08001065 pFormField->GetFieldType() == FIELDTYPE_SIGNATURE) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001066 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001067 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001068
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001069 vp << pFormField->GetDefaultValue();
1070 }
1071 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001072}
1073
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001074void Field::SetDefaultValue(CPDFSDK_Document* pDocument,
1075 const CFX_WideString& swFieldName,
1076 int nControlIndex,
1077 const CFX_WideString& string) {
1078 // Not supported.
1079}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001080
Tom Sepezba038bc2015-10-08 12:03:00 -07001081FX_BOOL Field::doNotScroll(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001082 CJS_PropValue& vp,
1083 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08001084 ASSERT(m_pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001085
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001086 if (vp.IsSetting()) {
1087 if (!m_bCanSet)
1088 return FALSE;
1089
1090 bool bVP;
1091 vp >> bVP;
1092
1093 if (m_bDelay) {
1094 AddDelay_Bool(FP_DONOTSCROLL, bVP);
1095 } else {
1096 Field::SetDoNotScroll(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
1097 }
1098 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001099 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1100 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001101 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001102
Lei Zhangd88a3642015-11-10 09:38:57 -08001103 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001104 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1105 return FALSE;
1106
1107 if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL)
1108 vp << true;
1109 else
1110 vp << false;
1111 }
1112
1113 return TRUE;
1114}
1115
1116void Field::SetDoNotScroll(CPDFSDK_Document* pDocument,
1117 const CFX_WideString& swFieldName,
1118 int nControlIndex,
1119 bool b) {
1120 // Not supported.
1121}
1122
Tom Sepezba038bc2015-10-08 12:03:00 -07001123FX_BOOL Field::doNotSpellCheck(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001124 CJS_PropValue& vp,
1125 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08001126 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001127
1128 if (vp.IsSetting()) {
1129 if (!m_bCanSet)
1130 return FALSE;
1131
1132 bool bVP;
1133 vp >> bVP;
1134 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001135 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1136 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001137 return FALSE;
1138
Lei Zhangd88a3642015-11-10 09:38:57 -08001139 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001140 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001141 pFormField->GetFieldType() != FIELDTYPE_COMBOBOX) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001142 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001143 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001144
1145 if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK)
1146 vp << true;
1147 else
1148 vp << false;
1149 }
1150
1151 return TRUE;
1152}
1153
1154void Field::SetDelay(FX_BOOL bDelay) {
1155 m_bDelay = bDelay;
1156
1157 if (!m_bDelay) {
1158 if (m_pJSDoc)
1159 m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex);
1160 }
1161}
1162
Tom Sepezba038bc2015-10-08 12:03:00 -07001163FX_BOOL Field::delay(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001164 CJS_PropValue& vp,
1165 CFX_WideString& sError) {
1166 if (vp.IsSetting()) {
1167 if (!m_bCanSet)
1168 return FALSE;
1169
1170 bool bVP;
1171 vp >> bVP;
1172
1173 SetDelay(bVP);
1174 } else {
1175 vp << m_bDelay;
1176 }
1177 return TRUE;
1178}
1179
Tom Sepezba038bc2015-10-08 12:03:00 -07001180FX_BOOL Field::display(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001181 CJS_PropValue& vp,
1182 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001183 if (vp.IsSetting()) {
1184 if (!m_bCanSet)
1185 return FALSE;
1186
1187 int nVP;
1188 vp >> nVP;
1189
1190 if (m_bDelay) {
1191 AddDelay_Int(FP_DISPLAY, nVP);
1192 } else {
1193 Field::SetDisplay(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
1194 }
1195 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001196 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1197 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001198 return FALSE;
1199
Lei Zhangd88a3642015-11-10 09:38:57 -08001200 CPDF_FormField* pFormField = FieldArray[0];
1201 ASSERT(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001202 CPDFSDK_InterForm* pInterForm =
1203 (CPDFSDK_InterForm*)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
1209 FX_DWORD dwFlag = pWidget->GetFlags();
1210
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) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001233 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)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)) {
1244 FX_DWORD dwFlag = pWidget->GetFlags();
1245 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)) {
1285 FX_DWORD dwFlag = pWidget->GetFlags();
1286 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);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001518 CPDFSDK_InterForm* pInterForm =
1519 (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001520 CPDFSDK_Widget* pWidget =
1521 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1522 if (!pWidget)
1523 return FALSE;
1524
1525 FX_DWORD dwFlags = pWidget->GetFlags();
1526
Lei Zhangd88a3642015-11-10 09:38:57 -08001527 if (ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001528 vp << true;
Lei Zhangd88a3642015-11-10 09:38:57 -08001529 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001530 vp << false;
1531 }
1532
1533 return TRUE;
1534}
1535
1536void Field::SetHidden(CPDFSDK_Document* pDocument,
1537 const CFX_WideString& swFieldName,
1538 int nControlIndex,
1539 bool b) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001540 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001541 std::vector<CPDF_FormField*> FieldArray =
1542 GetFormFields(pDocument, swFieldName);
1543 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001544 if (nControlIndex < 0) {
1545 FX_BOOL bSet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001546 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001547 if (CPDFSDK_Widget* pWidget =
Lei Zhangd88a3642015-11-10 09:38:57 -08001548 pInterForm->GetWidget(pFormField->GetControl(i))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001549 FX_DWORD dwFlags = pWidget->GetFlags();
1550
1551 if (b) {
1552 dwFlags &= (~ANNOTFLAG_INVISIBLE);
1553 dwFlags &= (~ANNOTFLAG_NOVIEW);
1554 dwFlags |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
1555 } else {
1556 dwFlags &= (~ANNOTFLAG_INVISIBLE);
1557 dwFlags &= (~ANNOTFLAG_HIDDEN);
1558 dwFlags &= (~ANNOTFLAG_NOVIEW);
1559 dwFlags |= ANNOTFLAG_PRINT;
1560 }
1561
1562 if (dwFlags != pWidget->GetFlags()) {
1563 pWidget->SetFlags(dwFlags);
1564 bSet = TRUE;
1565 }
1566 }
1567 }
1568
1569 if (bSet)
1570 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
1571 } else {
1572 if (nControlIndex >= pFormField->CountControls())
1573 return;
1574 if (CPDF_FormControl* pFormControl =
1575 pFormField->GetControl(nControlIndex)) {
1576 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1577 FX_DWORD dwFlags = pWidget->GetFlags();
1578
1579 if (b) {
1580 dwFlags &= (~ANNOTFLAG_INVISIBLE);
1581 dwFlags &= (~ANNOTFLAG_NOVIEW);
1582 dwFlags |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
1583 } else {
1584 dwFlags &= (~ANNOTFLAG_INVISIBLE);
1585 dwFlags &= (~ANNOTFLAG_HIDDEN);
1586 dwFlags &= (~ANNOTFLAG_NOVIEW);
1587 dwFlags |= ANNOTFLAG_PRINT;
1588 }
1589
1590 if (dwFlags != pWidget->GetFlags()) {
1591 pWidget->SetFlags(dwFlags);
1592 UpdateFormControl(pDocument, pFormControl, TRUE, FALSE, TRUE);
1593 }
1594 }
1595 }
1596 }
1597 }
1598}
1599
Tom Sepezba038bc2015-10-08 12:03:00 -07001600FX_BOOL Field::highlight(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001601 CJS_PropValue& vp,
1602 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08001603 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001604
1605 if (vp.IsSetting()) {
1606 if (!m_bCanSet)
1607 return FALSE;
1608
1609 CFX_ByteString strMode;
1610 vp >> strMode;
1611
1612 if (m_bDelay) {
1613 AddDelay_String(FP_HIGHLIGHT, strMode);
1614 } else {
1615 Field::SetHighlight(m_pDocument, m_FieldName, m_nFormControlIndex,
1616 strMode);
1617 }
1618 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001619 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1620 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001621 return FALSE;
1622
Lei Zhangd88a3642015-11-10 09:38:57 -08001623 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001624 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
1625 return FALSE;
1626
1627 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1628 if (!pFormControl)
1629 return FALSE;
1630
1631 int eHM = pFormControl->GetHighlightingMode();
1632 switch (eHM) {
1633 case CPDF_FormControl::None:
1634 vp << L"none";
1635 break;
1636 case CPDF_FormControl::Push:
1637 vp << L"push";
1638 break;
1639 case CPDF_FormControl::Invert:
1640 vp << L"invert";
1641 break;
1642 case CPDF_FormControl::Outline:
1643 vp << L"outline";
1644 break;
1645 case CPDF_FormControl::Toggle:
1646 vp << L"toggle";
1647 break;
1648 }
1649 }
1650
1651 return TRUE;
1652}
1653
1654void Field::SetHighlight(CPDFSDK_Document* pDocument,
1655 const CFX_WideString& swFieldName,
1656 int nControlIndex,
1657 const CFX_ByteString& string) {
1658 // Not supported.
1659}
1660
Tom Sepezba038bc2015-10-08 12:03:00 -07001661FX_BOOL Field::lineWidth(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001662 CJS_PropValue& vp,
1663 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001664 if (vp.IsSetting()) {
1665 if (!m_bCanSet)
1666 return FALSE;
1667
1668 int iWidth;
1669 vp >> iWidth;
1670
1671 if (m_bDelay) {
1672 AddDelay_Int(FP_LINEWIDTH, iWidth);
1673 } else {
1674 Field::SetLineWidth(m_pDocument, m_FieldName, m_nFormControlIndex,
1675 iWidth);
1676 }
1677 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001678 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1679 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001680 return FALSE;
1681
Lei Zhangd88a3642015-11-10 09:38:57 -08001682 CPDF_FormField* pFormField = FieldArray[0];
1683 ASSERT(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001684 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1685 if (!pFormControl)
1686 return FALSE;
1687
1688 CPDFSDK_InterForm* pInterForm =
1689 (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001690 if (!pFormField->CountControls())
1691 return FALSE;
1692
1693 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
1694 if (!pWidget)
1695 return FALSE;
1696
1697 vp << (int32_t)pWidget->GetBorderWidth();
1698 }
1699
1700 return TRUE;
1701}
1702
1703void Field::SetLineWidth(CPDFSDK_Document* pDocument,
1704 const CFX_WideString& swFieldName,
1705 int nControlIndex,
1706 int number) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001707 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001708
Lei Zhangd88a3642015-11-10 09:38:57 -08001709 std::vector<CPDF_FormField*> FieldArray =
1710 GetFormFields(pDocument, swFieldName);
1711 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001712 if (nControlIndex < 0) {
1713 FX_BOOL bSet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001714 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1715 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08001716 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001717
1718 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1719 if (number != pWidget->GetBorderWidth()) {
1720 pWidget->SetBorderWidth(number);
1721 bSet = TRUE;
1722 }
1723 }
1724 }
1725 if (bSet)
1726 UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
1727 } else {
1728 if (nControlIndex >= pFormField->CountControls())
1729 return;
1730 if (CPDF_FormControl* pFormControl =
1731 pFormField->GetControl(nControlIndex)) {
1732 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1733 if (number != pWidget->GetBorderWidth()) {
1734 pWidget->SetBorderWidth(number);
1735 UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
1736 }
1737 }
1738 }
1739 }
1740 }
1741}
1742
Tom Sepezba038bc2015-10-08 12:03:00 -07001743FX_BOOL Field::multiline(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001744 CJS_PropValue& vp,
1745 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08001746 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001747
1748 if (vp.IsSetting()) {
1749 if (!m_bCanSet)
1750 return FALSE;
1751
1752 bool bVP;
1753 vp >> bVP;
1754
1755 if (m_bDelay) {
1756 AddDelay_Bool(FP_MULTILINE, bVP);
1757 } else {
1758 Field::SetMultiline(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
1759 }
1760 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001761 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1762 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001763 return FALSE;
1764
Lei Zhangd88a3642015-11-10 09:38:57 -08001765 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001766 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1767 return FALSE;
1768
1769 if (pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE)
1770 vp << true;
1771 else
1772 vp << false;
1773 }
1774
1775 return TRUE;
1776}
1777
1778void Field::SetMultiline(CPDFSDK_Document* pDocument,
1779 const CFX_WideString& swFieldName,
1780 int nControlIndex,
1781 bool b) {
1782 // Not supported.
1783}
1784
Tom Sepezba038bc2015-10-08 12:03:00 -07001785FX_BOOL Field::multipleSelection(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001786 CJS_PropValue& vp,
1787 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08001788 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001789
1790 if (vp.IsSetting()) {
1791 if (!m_bCanSet)
1792 return FALSE;
1793
1794 bool bVP;
1795 vp >> bVP;
1796
1797 if (m_bDelay) {
1798 AddDelay_Bool(FP_MULTIPLESELECTION, bVP);
1799 } else {
1800 Field::SetMultipleSelection(m_pDocument, m_FieldName, m_nFormControlIndex,
1801 bVP);
1802 }
1803 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001804 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1805 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001806 return FALSE;
1807
Lei Zhangd88a3642015-11-10 09:38:57 -08001808 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001809 if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
1810 return FALSE;
1811
1812 if (pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT)
1813 vp << true;
1814 else
1815 vp << false;
1816 }
1817
1818 return TRUE;
1819}
1820
1821void Field::SetMultipleSelection(CPDFSDK_Document* pDocument,
1822 const CFX_WideString& swFieldName,
1823 int nControlIndex,
1824 bool b) {
1825 // Not supported.
1826}
1827
Tom Sepezba038bc2015-10-08 12:03:00 -07001828FX_BOOL Field::name(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001829 CJS_PropValue& vp,
1830 CFX_WideString& sError) {
1831 if (!vp.IsGetting())
1832 return FALSE;
1833
Lei Zhangd88a3642015-11-10 09:38:57 -08001834 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1835 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001836 return FALSE;
1837
1838 vp << m_FieldName;
1839
1840 return TRUE;
1841}
1842
Tom Sepezba038bc2015-10-08 12:03:00 -07001843FX_BOOL Field::numItems(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001844 CJS_PropValue& vp,
1845 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07001846 if (!vp.IsGetting())
1847 return FALSE;
1848
Lei Zhangd88a3642015-11-10 09:38:57 -08001849 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1850 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001851 return FALSE;
1852
Lei Zhangd88a3642015-11-10 09:38:57 -08001853 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001854 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001855 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001856 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001857 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001858
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001859 vp << (int32_t)pFormField->CountOptions();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001860 return TRUE;
1861}
1862
Tom Sepezba038bc2015-10-08 12:03:00 -07001863FX_BOOL Field::page(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001864 CJS_PropValue& vp,
1865 CFX_WideString& sError) {
1866 if (!vp.IsGetting())
1867 return FALSE;
1868
Lei Zhangd88a3642015-11-10 09:38:57 -08001869 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1870 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001871 return FALSE;
1872
Lei Zhangd88a3642015-11-10 09:38:57 -08001873 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001874 if (!pFormField)
1875 return FALSE;
1876
Lei Zhangd88a3642015-11-10 09:38:57 -08001877 std::vector<CPDFSDK_Widget*> widgets;
1878 m_pDocument->GetInterForm()->GetWidgets(pFormField, &widgets);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001879
Lei Zhangd88a3642015-11-10 09:38:57 -08001880 if (widgets.empty()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001881 vp << (int32_t)-1;
Lei Zhangd88a3642015-11-10 09:38:57 -08001882 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001883 }
1884
Lei Zhangd88a3642015-11-10 09:38:57 -08001885 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
1886 CJS_Array PageArray(pRuntime);
1887 for (size_t i = 0; i < widgets.size(); ++i) {
1888 CPDFSDK_PageView* pPageView = widgets[i]->GetPageView();
1889 if (!pPageView)
1890 return FALSE;
1891
1892 PageArray.SetElement(
1893 i, CJS_Value(pRuntime, (int32_t)pPageView->GetPageIndex()));
1894 }
1895
1896 vp << PageArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001897 return TRUE;
1898}
1899
Tom Sepezba038bc2015-10-08 12:03:00 -07001900FX_BOOL Field::password(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001901 CJS_PropValue& vp,
1902 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08001903 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001904
1905 if (vp.IsSetting()) {
1906 if (!m_bCanSet)
1907 return FALSE;
1908
1909 bool bVP;
1910 vp >> bVP;
1911
1912 if (m_bDelay) {
1913 AddDelay_Bool(FP_PASSWORD, bVP);
1914 } else {
1915 Field::SetPassword(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
1916 }
1917 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001918 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1919 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001920 return FALSE;
1921
Lei Zhangd88a3642015-11-10 09:38:57 -08001922 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001923 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1924 return FALSE;
1925
1926 if (pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD)
1927 vp << true;
1928 else
1929 vp << false;
1930 }
1931
1932 return TRUE;
1933}
1934
1935void Field::SetPassword(CPDFSDK_Document* pDocument,
1936 const CFX_WideString& swFieldName,
1937 int nControlIndex,
1938 bool b) {
1939 // Not supported.
1940}
1941
Tom Sepezba038bc2015-10-08 12:03:00 -07001942FX_BOOL Field::print(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001943 CJS_PropValue& vp,
1944 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001945 CPDFSDK_InterForm* pInterForm =
1946 (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001947 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1948 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001949 return FALSE;
1950
1951 if (vp.IsSetting()) {
1952 if (!m_bCanSet)
1953 return FALSE;
1954
1955 bool bVP;
1956 vp >> bVP;
1957
Lei Zhangd88a3642015-11-10 09:38:57 -08001958 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001959 if (m_nFormControlIndex < 0) {
1960 FX_BOOL bSet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001961 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001962 if (CPDFSDK_Widget* pWidget =
Lei Zhangd88a3642015-11-10 09:38:57 -08001963 pInterForm->GetWidget(pFormField->GetControl(i))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001964 FX_DWORD dwFlags = pWidget->GetFlags();
1965 if (bVP)
1966 dwFlags |= ANNOTFLAG_PRINT;
1967 else
1968 dwFlags &= ~ANNOTFLAG_PRINT;
1969
1970 if (dwFlags != pWidget->GetFlags()) {
1971 pWidget->SetFlags(dwFlags);
1972 bSet = TRUE;
1973 }
1974 }
1975 }
1976
1977 if (bSet)
1978 UpdateFormField(m_pDocument, pFormField, TRUE, FALSE, TRUE);
1979 } else {
1980 if (m_nFormControlIndex >= pFormField->CountControls())
1981 return FALSE;
1982 if (CPDF_FormControl* pFormControl =
1983 pFormField->GetControl(m_nFormControlIndex)) {
1984 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1985 FX_DWORD dwFlags = pWidget->GetFlags();
1986 if (bVP)
1987 dwFlags |= ANNOTFLAG_PRINT;
1988 else
1989 dwFlags &= ~ANNOTFLAG_PRINT;
1990
1991 if (dwFlags != pWidget->GetFlags()) {
1992 pWidget->SetFlags(dwFlags);
1993 UpdateFormControl(m_pDocument,
1994 pFormField->GetControl(m_nFormControlIndex),
1995 TRUE, FALSE, TRUE);
1996 }
1997 }
1998 }
1999 }
2000 }
2001 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002002 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002003 CPDFSDK_Widget* pWidget =
2004 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
2005 if (!pWidget)
2006 return FALSE;
2007
2008 if (pWidget->GetFlags() & ANNOTFLAG_PRINT)
2009 vp << true;
2010 else
2011 vp << false;
2012 }
2013
2014 return TRUE;
2015}
2016
Tom Sepezba038bc2015-10-08 12:03:00 -07002017FX_BOOL Field::radiosInUnison(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002018 CJS_PropValue& vp,
2019 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002020 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2021 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002022 return FALSE;
2023
2024 if (vp.IsSetting()) {
2025 if (!m_bCanSet)
2026 return FALSE;
2027
2028 bool bVP;
2029 vp >> bVP;
2030
2031 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002032 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002033 if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
2034 return FALSE;
2035
2036 if (pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)
2037 vp << true;
2038 else
2039 vp << false;
2040 }
2041
2042 return TRUE;
2043}
2044
Tom Sepezba038bc2015-10-08 12:03:00 -07002045FX_BOOL Field::readonly(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002046 CJS_PropValue& vp,
2047 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002048 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2049 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002050 return FALSE;
2051
2052 if (vp.IsSetting()) {
2053 if (!m_bCanSet)
2054 return FALSE;
2055
2056 bool bVP;
2057 vp >> bVP;
2058
2059 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002060 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002061 if (pFormField->GetFieldFlags() & FIELDFLAG_READONLY)
2062 vp << true;
2063 else
2064 vp << false;
2065 }
2066
2067 return TRUE;
2068}
2069
Tom Sepezba038bc2015-10-08 12:03:00 -07002070FX_BOOL Field::rect(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002071 CJS_PropValue& vp,
2072 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002073 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
2074 CJS_Value Upper_Leftx(pRuntime);
2075 CJS_Value Upper_Lefty(pRuntime);
2076 CJS_Value Lower_Rightx(pRuntime);
2077 CJS_Value Lower_Righty(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002078
2079 if (vp.IsSetting()) {
2080 if (!m_bCanSet)
2081 return FALSE;
2082 if (!vp.IsArrayObject())
2083 return FALSE;
2084
Tom Sepez67fd5df2015-10-08 12:24:19 -07002085 CJS_Array rcArray(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002086 vp >> rcArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002087 rcArray.GetElement(0, Upper_Leftx);
2088 rcArray.GetElement(1, Upper_Lefty);
2089 rcArray.GetElement(2, Lower_Rightx);
2090 rcArray.GetElement(3, Lower_Righty);
2091
2092 FX_FLOAT pArray[4] = {0.0f, 0.0f, 0.0f, 0.0f};
2093 pArray[0] = (FX_FLOAT)Upper_Leftx.ToInt();
2094 pArray[1] = (FX_FLOAT)Lower_Righty.ToInt();
2095 pArray[2] = (FX_FLOAT)Lower_Rightx.ToInt();
2096 pArray[3] = (FX_FLOAT)Upper_Lefty.ToInt();
2097
2098 CPDF_Rect crRect(pArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002099 if (m_bDelay) {
2100 AddDelay_Rect(FP_RECT, crRect);
2101 } else {
2102 Field::SetRect(m_pDocument, m_FieldName, m_nFormControlIndex, crRect);
2103 }
2104 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002105 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2106 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002107 return FALSE;
2108
Lei Zhangd88a3642015-11-10 09:38:57 -08002109 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002110 CPDFSDK_InterForm* pInterForm =
2111 (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002112 CPDFSDK_Widget* pWidget =
2113 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
2114 if (!pWidget)
2115 return FALSE;
2116
2117 CFX_FloatRect crRect = pWidget->GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002118 Upper_Leftx = (int32_t)crRect.left;
2119 Upper_Lefty = (int32_t)crRect.top;
2120 Lower_Rightx = (int32_t)crRect.right;
2121 Lower_Righty = (int32_t)crRect.bottom;
2122
Tom Sepez67fd5df2015-10-08 12:24:19 -07002123 CJS_Array rcArray(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002124 rcArray.SetElement(0, Upper_Leftx);
2125 rcArray.SetElement(1, Upper_Lefty);
2126 rcArray.SetElement(2, Lower_Rightx);
2127 rcArray.SetElement(3, Lower_Righty);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002128 vp << rcArray;
2129 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002130 return TRUE;
2131}
2132
2133void Field::SetRect(CPDFSDK_Document* pDocument,
2134 const CFX_WideString& swFieldName,
2135 int nControlIndex,
2136 const CPDF_Rect& rect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002137 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002138
Lei Zhangd88a3642015-11-10 09:38:57 -08002139 std::vector<CPDF_FormField*> FieldArray =
2140 GetFormFields(pDocument, swFieldName);
2141 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002142 if (nControlIndex < 0) {
2143 FX_BOOL bSet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08002144 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002145 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08002146 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002147
2148 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
2149 CPDF_Rect crRect = rect;
2150
2151 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002152 crRect.Intersect(pPDFPage->GetPageBBox());
2153
2154 if (!crRect.IsEmpty()) {
2155 CPDF_Rect rcOld = pWidget->GetRect();
2156 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
2157 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
2158 pWidget->SetRect(crRect);
2159 bSet = TRUE;
2160 }
2161 }
2162 }
2163 }
2164
2165 if (bSet)
2166 UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
2167 } else {
2168 if (nControlIndex >= pFormField->CountControls())
2169 return;
2170 if (CPDF_FormControl* pFormControl =
2171 pFormField->GetControl(nControlIndex)) {
2172 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
2173 CPDF_Rect crRect = rect;
2174
2175 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002176 crRect.Intersect(pPDFPage->GetPageBBox());
2177
2178 if (!crRect.IsEmpty()) {
2179 CPDF_Rect rcOld = pWidget->GetRect();
2180 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
2181 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
2182 pWidget->SetRect(crRect);
2183 UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
2184 }
2185 }
2186 }
2187 }
2188 }
2189 }
2190}
2191
Tom Sepezba038bc2015-10-08 12:03:00 -07002192FX_BOOL Field::required(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002193 CJS_PropValue& vp,
2194 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002195 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2196 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002197 return FALSE;
2198
2199 if (vp.IsSetting()) {
2200 if (!m_bCanSet)
2201 return FALSE;
2202
2203 bool bVP;
2204 vp >> bVP;
2205
2206 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002207 CPDF_FormField* pFormField = FieldArray[0];
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002208 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002209 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002210
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002211 if (pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED)
2212 vp << true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002213 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002214 vp << false;
2215 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002216
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002217 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002218}
2219
Tom Sepezba038bc2015-10-08 12:03:00 -07002220FX_BOOL Field::richText(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002221 CJS_PropValue& vp,
2222 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08002223 ASSERT(m_pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002224
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002225 if (vp.IsSetting()) {
2226 if (!m_bCanSet)
2227 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002228
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002229 bool bVP;
2230 vp >> bVP;
2231
2232 if (m_bDelay) {
2233 AddDelay_Bool(FP_RICHTEXT, bVP);
2234 } else {
2235 Field::SetRichText(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
2236 }
2237 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002238 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2239 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002240 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002241
Lei Zhangd88a3642015-11-10 09:38:57 -08002242 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002243 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
2244 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002245
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002246 if (pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT)
2247 vp << true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002248 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002249 vp << false;
2250 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002251
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002252 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002253}
2254
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002255void Field::SetRichText(CPDFSDK_Document* pDocument,
2256 const CFX_WideString& swFieldName,
2257 int nControlIndex,
2258 bool b) {
2259 // Not supported.
2260}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002261
Tom Sepezba038bc2015-10-08 12:03:00 -07002262FX_BOOL Field::richValue(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002263 CJS_PropValue& vp,
2264 CFX_WideString& sError) {
2265 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002266}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002267
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002268void Field::SetRichValue(CPDFSDK_Document* pDocument,
2269 const CFX_WideString& swFieldName,
2270 int nControlIndex) {
2271 // Not supported.
2272}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002273
Tom Sepezba038bc2015-10-08 12:03:00 -07002274FX_BOOL Field::rotation(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002275 CJS_PropValue& vp,
2276 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08002277 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002278
2279 if (vp.IsSetting()) {
2280 if (!m_bCanSet)
2281 return FALSE;
2282
2283 int nVP;
2284 vp >> nVP;
2285
2286 if (m_bDelay) {
2287 AddDelay_Int(FP_ROTATION, nVP);
2288 } else {
2289 Field::SetRotation(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
2290 }
2291 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002292 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2293 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002294 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002295
Lei Zhangd88a3642015-11-10 09:38:57 -08002296 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002297 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2298 if (!pFormControl)
2299 return FALSE;
2300
2301 vp << (int32_t)pFormControl->GetRotation();
2302 }
2303
2304 return TRUE;
2305}
2306
2307void Field::SetRotation(CPDFSDK_Document* pDocument,
2308 const CFX_WideString& swFieldName,
2309 int nControlIndex,
2310 int number) {
2311 // Not supported.
2312}
2313
Tom Sepezba038bc2015-10-08 12:03:00 -07002314FX_BOOL Field::strokeColor(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002315 CJS_PropValue& vp,
2316 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002317 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
2318 CJS_Array crArray(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002319
2320 if (vp.IsSetting()) {
2321 if (!m_bCanSet)
2322 return FALSE;
2323
2324 if (!vp.IsArrayObject())
2325 return FALSE;
2326
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002327 vp >> crArray;
2328
2329 CPWL_Color color;
2330 color::ConvertArrayToPWLColor(crArray, color);
2331
2332 if (m_bDelay) {
2333 AddDelay_Color(FP_STROKECOLOR, color);
2334 } else {
2335 Field::SetStrokeColor(m_pDocument, m_FieldName, m_nFormControlIndex,
2336 color);
2337 }
2338 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002339 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2340 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002341 return FALSE;
2342
Lei Zhangd88a3642015-11-10 09:38:57 -08002343 CPDF_FormField* pFormField = FieldArray[0];
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002344 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002345 if (!pFormControl)
2346 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002347
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002348 int iColorType;
2349 pFormControl->GetBorderColor(iColorType);
2350
2351 CPWL_Color color;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002352 if (iColorType == COLORTYPE_TRANSPARENT) {
2353 color = CPWL_Color(COLORTYPE_TRANSPARENT);
2354 } else if (iColorType == COLORTYPE_GRAY) {
2355 color =
2356 CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBorderColor(0));
2357 } else if (iColorType == COLORTYPE_RGB) {
2358 color = CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBorderColor(0),
2359 pFormControl->GetOriginalBorderColor(1),
2360 pFormControl->GetOriginalBorderColor(2));
2361 } else if (iColorType == COLORTYPE_CMYK) {
2362 color =
2363 CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBorderColor(0),
2364 pFormControl->GetOriginalBorderColor(1),
2365 pFormControl->GetOriginalBorderColor(2),
2366 pFormControl->GetOriginalBorderColor(3));
Lei Zhangd88a3642015-11-10 09:38:57 -08002367 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002368 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08002369 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002370
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002371 color::ConvertPWLColorToArray(color, crArray);
2372 vp << crArray;
2373 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002374 return TRUE;
2375}
2376
2377void Field::SetStrokeColor(CPDFSDK_Document* pDocument,
2378 const CFX_WideString& swFieldName,
2379 int nControlIndex,
2380 const CPWL_Color& color) {
2381 // Not supported.
2382}
2383
Tom Sepezba038bc2015-10-08 12:03:00 -07002384FX_BOOL Field::style(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002385 CJS_PropValue& vp,
2386 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08002387 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002388
2389 if (vp.IsSetting()) {
2390 if (!m_bCanSet)
2391 return FALSE;
2392
2393 CFX_ByteString csBCaption;
2394 vp >> csBCaption;
2395
2396 if (m_bDelay) {
2397 AddDelay_String(FP_STYLE, csBCaption);
2398 } else {
2399 Field::SetStyle(m_pDocument, m_FieldName, m_nFormControlIndex,
2400 csBCaption);
2401 }
2402 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002403 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2404 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002405 return FALSE;
2406
Lei Zhangd88a3642015-11-10 09:38:57 -08002407 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002408 if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON &&
Lei Zhangd88a3642015-11-10 09:38:57 -08002409 pFormField->GetFieldType() != FIELDTYPE_CHECKBOX) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002410 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08002411 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002412
2413 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2414 if (!pFormControl)
2415 return FALSE;
2416
2417 CFX_WideString csWCaption = pFormControl->GetNormalCaption();
2418 CFX_ByteString csBCaption;
2419
2420 switch (csWCaption[0]) {
2421 case L'l':
2422 csBCaption = "circle";
2423 break;
2424 case L'8':
2425 csBCaption = "cross";
2426 break;
2427 case L'u':
2428 csBCaption = "diamond";
2429 break;
2430 case L'n':
2431 csBCaption = "square";
2432 break;
2433 case L'H':
2434 csBCaption = "star";
2435 break;
2436 default: // L'4'
2437 csBCaption = "check";
2438 break;
2439 }
2440 vp << csBCaption;
2441 }
2442
2443 return TRUE;
2444}
2445
2446void Field::SetStyle(CPDFSDK_Document* pDocument,
2447 const CFX_WideString& swFieldName,
2448 int nControlIndex,
2449 const CFX_ByteString& string) {
2450 // Not supported.
2451}
2452
Tom Sepezba038bc2015-10-08 12:03:00 -07002453FX_BOOL Field::submitName(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002454 CJS_PropValue& vp,
2455 CFX_WideString& sError) {
2456 return TRUE;
2457}
2458
Tom Sepezba038bc2015-10-08 12:03:00 -07002459FX_BOOL Field::textColor(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002460 CJS_PropValue& vp,
2461 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002462 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
2463 CJS_Array crArray(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002464
2465 if (vp.IsSetting()) {
2466 if (!m_bCanSet)
2467 return FALSE;
2468
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002469 if (!vp.IsArrayObject())
2470 return FALSE;
Tom Sepez67fd5df2015-10-08 12:24:19 -07002471
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002472 vp >> crArray;
2473
2474 CPWL_Color color;
2475 color::ConvertArrayToPWLColor(crArray, color);
2476
2477 if (m_bDelay) {
2478 AddDelay_Color(FP_TEXTCOLOR, color);
2479 } else {
2480 Field::SetTextColor(m_pDocument, m_FieldName, m_nFormControlIndex, color);
2481 }
2482 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002483 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2484 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002485 return FALSE;
2486
Lei Zhangd88a3642015-11-10 09:38:57 -08002487 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002488 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2489 if (!pFormControl)
2490 return FALSE;
2491
2492 int iColorType;
2493 FX_ARGB color;
2494 CPDF_DefaultAppearance FieldAppearance =
2495 pFormControl->GetDefaultAppearance();
2496 FieldAppearance.GetColor(color, iColorType);
2497 int32_t a, r, g, b;
2498 ArgbDecode(color, a, r, g, b);
2499
2500 CPWL_Color crRet =
2501 CPWL_Color(COLORTYPE_RGB, r / 255.0f, g / 255.0f, b / 255.0f);
2502
2503 if (iColorType == COLORTYPE_TRANSPARENT)
2504 crRet = CPWL_Color(COLORTYPE_TRANSPARENT);
2505
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002506 color::ConvertPWLColorToArray(crRet, crArray);
2507 vp << crArray;
2508 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002509 return TRUE;
2510}
2511
2512void Field::SetTextColor(CPDFSDK_Document* pDocument,
2513 const CFX_WideString& swFieldName,
2514 int nControlIndex,
2515 const CPWL_Color& color) {
2516 // Not supported.
2517}
2518
Tom Sepezba038bc2015-10-08 12:03:00 -07002519FX_BOOL Field::textFont(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002520 CJS_PropValue& vp,
2521 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08002522 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002523
2524 if (vp.IsSetting()) {
2525 if (!m_bCanSet)
2526 return FALSE;
2527
2528 CFX_ByteString csFontName;
2529 vp >> csFontName;
2530 if (csFontName.IsEmpty())
2531 return FALSE;
2532
2533 if (m_bDelay) {
2534 AddDelay_String(FP_TEXTFONT, csFontName);
2535 } else {
2536 Field::SetTextFont(m_pDocument, m_FieldName, m_nFormControlIndex,
2537 csFontName);
2538 }
2539 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002540 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2541 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002542 return FALSE;
2543
Lei Zhangd88a3642015-11-10 09:38:57 -08002544 CPDF_FormField* pFormField = FieldArray[0];
2545 ASSERT(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002546 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2547 if (!pFormControl)
2548 return FALSE;
2549
2550 int nFieldType = pFormField->GetFieldType();
2551
2552 if (nFieldType == FIELDTYPE_PUSHBUTTON ||
2553 nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX ||
2554 nFieldType == FIELDTYPE_TEXTFIELD) {
2555 CPDF_Font* pFont = pFormControl->GetDefaultControlFont();
2556 if (!pFont)
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002557 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002558
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002559 vp << pFont->GetBaseFont();
Lei Zhangd88a3642015-11-10 09:38:57 -08002560 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002561 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08002562 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002563 }
2564
2565 return TRUE;
2566}
2567
2568void Field::SetTextFont(CPDFSDK_Document* pDocument,
2569 const CFX_WideString& swFieldName,
2570 int nControlIndex,
2571 const CFX_ByteString& string) {
2572 // Not supported.
2573}
2574
Tom Sepezba038bc2015-10-08 12:03:00 -07002575FX_BOOL Field::textSize(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002576 CJS_PropValue& vp,
2577 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08002578 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002579
2580 if (vp.IsSetting()) {
2581 if (!m_bCanSet)
2582 return FALSE;
2583
2584 int nVP;
2585 vp >> nVP;
2586
2587 if (m_bDelay) {
2588 AddDelay_Int(FP_TEXTSIZE, nVP);
2589 } else {
2590 Field::SetTextSize(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
2591 }
2592 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002593 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2594 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002595 return FALSE;
2596
Lei Zhangd88a3642015-11-10 09:38:57 -08002597 CPDF_FormField* pFormField = FieldArray[0];
2598 ASSERT(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002599 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2600 if (!pFormControl)
2601 return FALSE;
2602
2603 CPDF_DefaultAppearance FieldAppearance =
2604 pFormControl->GetDefaultAppearance();
2605
2606 CFX_ByteString csFontNameTag;
2607 FX_FLOAT fFontSize;
2608 FieldAppearance.GetFont(csFontNameTag, fFontSize);
2609
2610 vp << (int)fFontSize;
2611 }
2612
2613 return TRUE;
2614}
2615
2616void Field::SetTextSize(CPDFSDK_Document* pDocument,
2617 const CFX_WideString& swFieldName,
2618 int nControlIndex,
2619 int number) {
2620 // Not supported.
2621}
2622
Tom Sepezba038bc2015-10-08 12:03:00 -07002623FX_BOOL Field::type(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002624 CJS_PropValue& vp,
2625 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002626 if (!vp.IsGetting())
2627 return FALSE;
2628
Lei Zhangd88a3642015-11-10 09:38:57 -08002629 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2630 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002631 return FALSE;
2632
Lei Zhangd88a3642015-11-10 09:38:57 -08002633 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002634 switch (pFormField->GetFieldType()) {
2635 case FIELDTYPE_UNKNOWN:
2636 vp << L"unknown";
2637 break;
2638 case FIELDTYPE_PUSHBUTTON:
2639 vp << L"button";
2640 break;
2641 case FIELDTYPE_CHECKBOX:
2642 vp << L"checkbox";
2643 break;
2644 case FIELDTYPE_RADIOBUTTON:
2645 vp << L"radiobutton";
2646 break;
2647 case FIELDTYPE_COMBOBOX:
2648 vp << L"combobox";
2649 break;
2650 case FIELDTYPE_LISTBOX:
2651 vp << L"listbox";
2652 break;
2653 case FIELDTYPE_TEXTFIELD:
2654 vp << L"text";
2655 break;
2656 case FIELDTYPE_SIGNATURE:
2657 vp << L"signature";
2658 break;
2659 default:
2660 vp << L"unknown";
2661 break;
2662 }
2663
2664 return TRUE;
2665}
2666
Tom Sepezba038bc2015-10-08 12:03:00 -07002667FX_BOOL Field::userName(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002668 CJS_PropValue& vp,
2669 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08002670 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002671
2672 if (vp.IsSetting()) {
2673 if (!m_bCanSet)
2674 return FALSE;
2675
2676 CFX_WideString swName;
2677 vp >> swName;
2678
2679 if (m_bDelay) {
2680 AddDelay_WideString(FP_USERNAME, swName);
2681 } else {
2682 Field::SetUserName(m_pDocument, m_FieldName, m_nFormControlIndex, swName);
2683 }
2684 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002685 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2686 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002687 return FALSE;
2688
Lei Zhangd88a3642015-11-10 09:38:57 -08002689 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002690 vp << (CFX_WideString)pFormField->GetAlternateName();
2691 }
2692
2693 return TRUE;
2694}
2695
2696void Field::SetUserName(CPDFSDK_Document* pDocument,
2697 const CFX_WideString& swFieldName,
2698 int nControlIndex,
2699 const CFX_WideString& string) {
2700 // Not supported.
2701}
2702
Tom Sepezba038bc2015-10-08 12:03:00 -07002703FX_BOOL Field::value(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002704 CJS_PropValue& vp,
2705 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002706 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002707
2708 if (vp.IsSetting()) {
2709 if (!m_bCanSet)
2710 return FALSE;
2711
2712 CJS_WideStringArray strArray;
2713
2714 if (vp.IsArrayObject()) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002715 CJS_Array ValueArray(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002716 vp.ConvertToArray(ValueArray);
2717 for (int i = 0, sz = ValueArray.GetLength(); i < sz; i++) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002718 CJS_Value ElementValue(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002719 ValueArray.GetElement(i, ElementValue);
2720 strArray.Add(ElementValue.ToCFXWideString());
2721 }
2722 } else {
2723 CFX_WideString swValue;
2724 vp >> swValue;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002725 strArray.Add(swValue);
2726 }
2727
2728 if (m_bDelay) {
2729 AddDelay_WideStringArray(FP_VALUE, strArray);
2730 } else {
2731 Field::SetValue(m_pDocument, m_FieldName, m_nFormControlIndex, strArray);
2732 }
2733 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002734 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2735 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002736 return FALSE;
2737
Lei Zhangd88a3642015-11-10 09:38:57 -08002738 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002739 switch (pFormField->GetFieldType()) {
2740 case FIELDTYPE_PUSHBUTTON:
2741 return FALSE;
2742 case FIELDTYPE_COMBOBOX:
2743 case FIELDTYPE_TEXTFIELD: {
Tom Sepez4246b002016-01-20 11:48:29 -08002744 vp << pFormField->GetValue();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002745 } break;
2746 case FIELDTYPE_LISTBOX: {
2747 if (pFormField->CountSelectedItems() > 1) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002748 CJS_Array ValueArray(pRuntime);
2749 CJS_Value ElementValue(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002750 int iIndex;
2751 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
2752 iIndex = pFormField->GetSelectedIndex(i);
2753 ElementValue = pFormField->GetOptionValue(iIndex).c_str();
2754 if (FXSYS_wcslen(ElementValue.ToCFXWideString().c_str()) == 0)
2755 ElementValue = pFormField->GetOptionLabel(iIndex).c_str();
2756 ValueArray.SetElement(i, ElementValue);
2757 }
2758 vp << ValueArray;
2759 } else {
Tom Sepez4246b002016-01-20 11:48:29 -08002760 vp << pFormField->GetValue();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002761 }
2762 } break;
2763 case FIELDTYPE_CHECKBOX:
2764 case FIELDTYPE_RADIOBUTTON: {
Tom Sepez4246b002016-01-20 11:48:29 -08002765 bool bFind = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002766 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
Tom Sepez4246b002016-01-20 11:48:29 -08002767 if (pFormField->GetControl(i)->IsChecked()) {
2768 vp << pFormField->GetControl(i)->GetExportValue();
2769 bFind = true;
2770 break;
Lei Zhangd88a3642015-11-10 09:38:57 -08002771 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002772 }
2773 if (!bFind)
2774 vp << L"Off";
2775 } break;
2776 default:
2777 vp << pFormField->GetValue();
2778 break;
2779 }
2780 }
Tom Sepez4246b002016-01-20 11:48:29 -08002781 vp.MaybeCoerceToNumber();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002782 return TRUE;
2783}
2784
2785void Field::SetValue(CPDFSDK_Document* pDocument,
2786 const CFX_WideString& swFieldName,
2787 int nControlIndex,
2788 const CJS_WideStringArray& strArray) {
Lei Zhang96660d62015-12-14 18:27:25 -08002789 ASSERT(pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002790
2791 if (strArray.GetSize() < 1)
2792 return;
2793
Lei Zhangd88a3642015-11-10 09:38:57 -08002794 std::vector<CPDF_FormField*> FieldArray =
2795 GetFormFields(pDocument, swFieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002796
Lei Zhangd88a3642015-11-10 09:38:57 -08002797 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002798 if (pFormField->GetFullName().Compare(swFieldName) != 0)
2799 continue;
2800
2801 switch (pFormField->GetFieldType()) {
2802 case FIELDTYPE_TEXTFIELD:
2803 case FIELDTYPE_COMBOBOX:
2804 if (pFormField->GetValue() != strArray.GetAt(0)) {
2805 CFX_WideString WideString = strArray.GetAt(0);
2806 pFormField->SetValue(strArray.GetAt(0), TRUE);
2807 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
2808 }
2809 break;
2810 case FIELDTYPE_CHECKBOX: // mantis: 0004493
2811 case FIELDTYPE_RADIOBUTTON: {
2812 if (pFormField->GetValue() != strArray.GetAt(0)) {
2813 pFormField->SetValue(strArray.GetAt(0), TRUE);
2814 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
2815 }
2816 } break;
2817 case FIELDTYPE_LISTBOX: {
2818 FX_BOOL bModified = FALSE;
2819
2820 for (int i = 0, sz = strArray.GetSize(); i < sz; i++) {
2821 int iIndex = pFormField->FindOption(strArray.GetAt(i));
2822
2823 if (!pFormField->IsItemSelected(iIndex)) {
2824 bModified = TRUE;
2825 break;
2826 }
2827 }
2828
2829 if (bModified) {
2830 pFormField->ClearSelection(TRUE);
2831 for (int i = 0, sz = strArray.GetSize(); i < sz; i++) {
2832 int iIndex = pFormField->FindOption(strArray.GetAt(i));
2833 pFormField->SetItemSelection(iIndex, TRUE, TRUE);
2834 }
2835
2836 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
2837 }
2838 } break;
2839 default:
2840 break;
2841 }
2842 }
2843}
2844
Tom Sepezba038bc2015-10-08 12:03:00 -07002845FX_BOOL Field::valueAsString(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002846 CJS_PropValue& vp,
2847 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002848 if (!vp.IsGetting())
2849 return FALSE;
2850
Lei Zhangd88a3642015-11-10 09:38:57 -08002851 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2852 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002853 return FALSE;
2854
Lei Zhangd88a3642015-11-10 09:38:57 -08002855 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002856 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
2857 return FALSE;
2858
2859 if (pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) {
2860 if (!pFormField->CountControls())
2861 return FALSE;
2862
2863 if (pFormField->GetControl(0)->IsChecked())
2864 vp << L"Yes";
2865 else
2866 vp << L"Off";
2867 } else if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON &&
2868 !(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)) {
2869 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2870 if (pFormField->GetControl(i)->IsChecked()) {
2871 vp << pFormField->GetControl(i)->GetExportValue().c_str();
2872 break;
Lei Zhangd88a3642015-11-10 09:38:57 -08002873 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002874 vp << L"Off";
Lei Zhangd88a3642015-11-10 09:38:57 -08002875 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002876 }
2877 } else if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX &&
2878 (pFormField->CountSelectedItems() > 1)) {
2879 vp << L"";
Lei Zhangd88a3642015-11-10 09:38:57 -08002880 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002881 vp << pFormField->GetValue().c_str();
Lei Zhangd88a3642015-11-10 09:38:57 -08002882 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002883
2884 return TRUE;
2885}
2886
Tom Sepezba038bc2015-10-08 12:03:00 -07002887FX_BOOL Field::browseForFileToSubmit(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08002888 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002889 CJS_Value& vRet,
2890 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002891 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2892 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002893 return FALSE;
2894
Lei Zhangd88a3642015-11-10 09:38:57 -08002895 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002896 CPDFDoc_Environment* pApp = m_pDocument->GetEnv();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002897 if ((pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) &&
2898 (pFormField->GetFieldType() == FIELDTYPE_TEXTFIELD)) {
2899 CFX_WideString wsFileName = pApp->JS_fieldBrowse();
2900 if (!wsFileName.IsEmpty()) {
2901 pFormField->SetValue(wsFileName);
2902 UpdateFormField(m_pDocument, pFormField, TRUE, TRUE, TRUE);
2903 }
Lei Zhangd88a3642015-11-10 09:38:57 -08002904 return TRUE;
2905 }
2906 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002907}
2908
Tom Sepezba038bc2015-10-08 12:03:00 -07002909FX_BOOL Field::buttonGetCaption(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08002910 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002911 CJS_Value& vRet,
2912 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002913 int nface = 0;
2914 int iSize = params.size();
2915 if (iSize >= 1)
2916 nface = params[0].ToInt();
2917
Lei Zhangd88a3642015-11-10 09:38:57 -08002918 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2919 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002920 return FALSE;
2921
Lei Zhangd88a3642015-11-10 09:38:57 -08002922 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002923 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
2924 return FALSE;
2925
2926 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2927 if (!pFormControl)
2928 return FALSE;
2929
2930 if (nface == 0)
2931 vRet = pFormControl->GetNormalCaption().c_str();
2932 else if (nface == 1)
2933 vRet = pFormControl->GetDownCaption().c_str();
2934 else if (nface == 2)
2935 vRet = pFormControl->GetRolloverCaption().c_str();
2936 else
2937 return FALSE;
2938
2939 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002940}
2941
Tom Sepezba038bc2015-10-08 12:03:00 -07002942FX_BOOL Field::buttonGetIcon(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08002943 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002944 CJS_Value& vRet,
2945 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002946 int nface = 0;
2947 int iSize = params.size();
2948 if (iSize >= 1)
2949 nface = params[0].ToInt();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002950
Lei Zhangd88a3642015-11-10 09:38:57 -08002951 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2952 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002953 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002954
Lei Zhangd88a3642015-11-10 09:38:57 -08002955 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002956 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
2957 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002958
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002959 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2960 if (!pFormControl)
2961 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002962
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002963 CJS_Context* pContext = (CJS_Context*)cc;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002964 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
Tom Sepezcd56a7d2015-10-06 11:45:28 -07002965 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
Tom Sepez33420902015-10-13 15:00:10 -07002966 pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002967 ASSERT(pObj.IsEmpty() == FALSE);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002968
Tom Sepezd5a0e952015-09-17 15:40:06 -07002969 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002970 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002971
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002972 CPDF_Stream* pIconStream = NULL;
2973 if (nface == 0)
2974 pIconStream = pFormControl->GetNormalIcon();
2975 else if (nface == 1)
2976 pIconStream = pFormControl->GetDownIcon();
2977 else if (nface == 2)
2978 pIconStream = pFormControl->GetRolloverIcon();
2979 else
2980 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002981
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002982 pIcon->SetStream(pIconStream);
2983 vRet = pJS_Icon;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002984
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002985 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002986}
2987
Tom Sepezba038bc2015-10-08 12:03:00 -07002988FX_BOOL Field::buttonImportIcon(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08002989 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002990 CJS_Value& vRet,
2991 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002992 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002993}
2994
Tom Sepezba038bc2015-10-08 12:03:00 -07002995FX_BOOL Field::buttonSetCaption(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08002996 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002997 CJS_Value& vRet,
2998 CFX_WideString& sError) {
2999 return FALSE;
3000}
3001
Tom Sepezba038bc2015-10-08 12:03:00 -07003002FX_BOOL Field::buttonSetIcon(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003003 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003004 CJS_Value& vRet,
3005 CFX_WideString& sError) {
3006 return FALSE;
3007}
3008
Tom Sepezba038bc2015-10-08 12:03:00 -07003009FX_BOOL Field::checkThisBox(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003010 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003011 CJS_Value& vRet,
3012 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08003013 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003014
3015 if (!m_bCanSet)
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003016 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003017
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003018 int iSize = params.size();
3019 if (iSize < 1)
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003020 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003021
3022 int nWidget = params[0].ToInt();
3023
3024 FX_BOOL bCheckit = TRUE;
3025 if (iSize >= 2)
3026 bCheckit = params[1].ToBool();
3027
Lei Zhangd88a3642015-11-10 09:38:57 -08003028 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3029 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003030 return FALSE;
3031
Lei Zhangd88a3642015-11-10 09:38:57 -08003032 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003033 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
3034 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
3035 return FALSE;
3036 if (nWidget < 0 || nWidget >= pFormField->CountControls())
3037 return FALSE;
3038 if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)
3039 pFormField->CheckControl(nWidget, bCheckit, TRUE);
3040 else
3041 pFormField->CheckControl(nWidget, bCheckit, TRUE);
3042
3043 UpdateFormField(m_pDocument, pFormField, TRUE, TRUE, TRUE);
3044 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003045}
3046
Tom Sepezba038bc2015-10-08 12:03:00 -07003047FX_BOOL Field::clearItems(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003048 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003049 CJS_Value& vRet,
3050 CFX_WideString& sError) {
3051 return TRUE;
3052}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003053
Tom Sepezba038bc2015-10-08 12:03:00 -07003054FX_BOOL Field::defaultIsChecked(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003055 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003056 CJS_Value& vRet,
3057 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003058 if (!m_bCanSet)
3059 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003060
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003061 int iSize = params.size();
3062 if (iSize < 1)
3063 return FALSE;
Tom Sepezf4ef3f92015-04-23 11:31:31 -07003064
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003065 int nWidget = params[0].ToInt();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003066
Lei Zhangd88a3642015-11-10 09:38:57 -08003067 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3068 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003069 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003070
Lei Zhangd88a3642015-11-10 09:38:57 -08003071 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003072 if (nWidget < 0 || nWidget >= pFormField->CountControls()) {
3073 vRet = FALSE;
3074 return FALSE;
3075 }
Lei Zhangd88a3642015-11-10 09:38:57 -08003076 vRet = pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
3077 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003078
3079 return TRUE;
3080}
3081
Tom Sepezba038bc2015-10-08 12:03:00 -07003082FX_BOOL Field::deleteItemAt(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003083 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003084 CJS_Value& vRet,
3085 CFX_WideString& sError) {
3086 return TRUE;
3087}
3088
Tom Sepezba038bc2015-10-08 12:03:00 -07003089FX_BOOL Field::getArray(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003090 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003091 CJS_Value& vRet,
3092 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08003093 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3094 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003095 return FALSE;
3096
Tom Sepezb9cc7a02016-02-01 13:42:30 -08003097 std::vector<std::unique_ptr<CFX_WideString>> swSort;
3098 for (CPDF_FormField* pFormField : FieldArray) {
3099 swSort.push_back(std::unique_ptr<CFX_WideString>(
3100 new CFX_WideString(pFormField->GetFullName())));
3101 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003102
Tom Sepezb9cc7a02016-02-01 13:42:30 -08003103 std::sort(
3104 swSort.begin(), swSort.end(),
3105 [](const std::unique_ptr<CFX_WideString>& p1,
3106 const std::unique_ptr<CFX_WideString>& p2) { return *p1 < *p2; });
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003107
3108 CJS_Context* pContext = (CJS_Context*)cc;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003109 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
Tom Sepez67fd5df2015-10-08 12:24:19 -07003110 CJS_Array FormFieldArray(pRuntime);
Tom Sepezb9cc7a02016-02-01 13:42:30 -08003111
3112 int j = 0;
3113 for (const auto& pStr : swSort) {
Tom Sepez39bfe122015-09-17 15:25:23 -07003114 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
Tom Sepez33420902015-10-13 15:00:10 -07003115 pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID);
Tom Sepezcd56a7d2015-10-06 11:45:28 -07003116 ASSERT(!pObj.IsEmpty());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003117
Tom Sepezd5a0e952015-09-17 15:40:06 -07003118 CJS_Field* pJSField =
Tom Sepezb9cc7a02016-02-01 13:42:30 -08003119 static_cast<CJS_Field*>(FXJS_GetPrivate(pRuntime->GetIsolate(), pObj));
3120 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003121 pField->AttachField(m_pJSDoc, *pStr);
3122
Tom Sepez67fd5df2015-10-08 12:24:19 -07003123 CJS_Value FormFieldValue(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003124 FormFieldValue = pJSField;
Tom Sepezb9cc7a02016-02-01 13:42:30 -08003125 FormFieldArray.SetElement(j++, FormFieldValue);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003126 }
3127
3128 vRet = FormFieldArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003129 return TRUE;
3130}
3131
Tom Sepezba038bc2015-10-08 12:03:00 -07003132FX_BOOL Field::getItemAt(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003133 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003134 CJS_Value& vRet,
3135 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003136 int iSize = params.size();
3137
3138 int nIdx = -1;
3139 if (iSize >= 1)
3140 nIdx = params[0].ToInt();
3141
3142 FX_BOOL bExport = TRUE;
3143 if (iSize >= 2)
3144 bExport = params[1].ToBool();
3145
Lei Zhangd88a3642015-11-10 09:38:57 -08003146 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3147 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003148 return FALSE;
3149
Lei Zhangd88a3642015-11-10 09:38:57 -08003150 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003151 if ((pFormField->GetFieldType() == FIELDTYPE_LISTBOX) ||
3152 (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX)) {
3153 if (nIdx == -1 || nIdx > pFormField->CountOptions())
3154 nIdx = pFormField->CountOptions() - 1;
3155 if (bExport) {
3156 CFX_WideString strval = pFormField->GetOptionValue(nIdx);
3157 if (strval.IsEmpty())
3158 vRet = pFormField->GetOptionLabel(nIdx).c_str();
3159 else
3160 vRet = strval.c_str();
Lei Zhangd88a3642015-11-10 09:38:57 -08003161 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003162 vRet = pFormField->GetOptionLabel(nIdx).c_str();
Lei Zhangd88a3642015-11-10 09:38:57 -08003163 }
3164 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003165 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08003166 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003167
3168 return TRUE;
3169}
3170
Tom Sepezba038bc2015-10-08 12:03:00 -07003171FX_BOOL Field::getLock(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003172 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003173 CJS_Value& vRet,
3174 CFX_WideString& sError) {
3175 return FALSE;
3176}
3177
Tom Sepezba038bc2015-10-08 12:03:00 -07003178FX_BOOL Field::insertItemAt(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003179 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003180 CJS_Value& vRet,
3181 CFX_WideString& sError) {
3182 return TRUE;
3183}
3184
Tom Sepezba038bc2015-10-08 12:03:00 -07003185FX_BOOL Field::isBoxChecked(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003186 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003187 CJS_Value& vRet,
3188 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003189 int nIndex = -1;
3190 if (params.size() >= 1)
3191 nIndex = params[0].ToInt();
3192
Lei Zhangd88a3642015-11-10 09:38:57 -08003193 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3194 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003195 return FALSE;
3196
Lei Zhangd88a3642015-11-10 09:38:57 -08003197 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003198 if (nIndex < 0 || nIndex >= pFormField->CountControls()) {
3199 vRet = FALSE;
3200 return FALSE;
3201 }
3202
3203 if ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) ||
3204 (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)) {
3205 if (pFormField->GetControl(nIndex)->IsChecked() != 0)
3206 vRet = TRUE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003207 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003208 vRet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08003209 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003210 vRet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08003211 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003212
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003213 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003214}
3215
Tom Sepezba038bc2015-10-08 12:03:00 -07003216FX_BOOL Field::isDefaultChecked(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003217 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003218 CJS_Value& vRet,
3219 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003220 int nIndex = -1;
3221 if (params.size() >= 1)
3222 nIndex = params[0].ToInt();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003223
Lei Zhangd88a3642015-11-10 09:38:57 -08003224 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3225 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003226 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003227
Lei Zhangd88a3642015-11-10 09:38:57 -08003228 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003229 if (nIndex < 0 || nIndex >= pFormField->CountControls()) {
3230 vRet = FALSE;
3231 return FALSE;
3232 }
3233 if ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) ||
3234 (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)) {
3235 if (pFormField->GetControl(nIndex)->IsDefaultChecked() != 0)
3236 vRet = TRUE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003237 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003238 vRet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08003239 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003240 vRet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08003241 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003242
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003243 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003244}
3245
Tom Sepezba038bc2015-10-08 12:03:00 -07003246FX_BOOL Field::setAction(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003247 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003248 CJS_Value& vRet,
3249 CFX_WideString& sError) {
3250 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003251}
3252
Tom Sepezba038bc2015-10-08 12:03:00 -07003253FX_BOOL Field::setFocus(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003254 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003255 CJS_Value& vRet,
3256 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08003257 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3258 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003259 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003260
Lei Zhangd88a3642015-11-10 09:38:57 -08003261 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003262 int32_t nCount = pFormField->CountControls();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003263 if (nCount < 1)
3264 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003265
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003266 CPDFSDK_InterForm* pInterForm =
3267 (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003268 CPDFSDK_Widget* pWidget = NULL;
3269 if (nCount == 1) {
3270 pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
3271 } else {
3272 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
Tom Sepez50d12ad2015-11-24 09:50:51 -08003273 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(
3274 pEnv->FFI_GetCurrentPage(m_pDocument->GetUnderlyingDocument()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003275 if (!pPage)
3276 return FALSE;
3277 if (CPDFSDK_PageView* pCurPageView = m_pDocument->GetPageView(pPage)) {
3278 for (int32_t i = 0; i < nCount; i++) {
3279 if (CPDFSDK_Widget* pTempWidget =
3280 pInterForm->GetWidget(pFormField->GetControl(i))) {
3281 if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage()) {
3282 pWidget = pTempWidget;
3283 break;
3284 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003285 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003286 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003287 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003288 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003289
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003290 if (pWidget) {
3291 m_pDocument->SetFocusAnnot(pWidget);
3292 }
3293
3294 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003295}
3296
Tom Sepezba038bc2015-10-08 12:03:00 -07003297FX_BOOL Field::setItems(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003298 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003299 CJS_Value& vRet,
3300 CFX_WideString& sError) {
3301 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003302}
3303
Tom Sepezba038bc2015-10-08 12:03:00 -07003304FX_BOOL Field::setLock(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003305 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003306 CJS_Value& vRet,
3307 CFX_WideString& sError) {
3308 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003309}
3310
Tom Sepezba038bc2015-10-08 12:03:00 -07003311FX_BOOL Field::signatureGetModifications(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003312 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003313 CJS_Value& vRet,
3314 CFX_WideString& sError) {
3315 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003316}
3317
Tom Sepezba038bc2015-10-08 12:03:00 -07003318FX_BOOL Field::signatureGetSeedValue(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003319 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003320 CJS_Value& vRet,
3321 CFX_WideString& sError) {
3322 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003323}
3324
Tom Sepezba038bc2015-10-08 12:03:00 -07003325FX_BOOL Field::signatureInfo(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003326 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003327 CJS_Value& vRet,
3328 CFX_WideString& sError) {
3329 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003330}
3331
Tom Sepezba038bc2015-10-08 12:03:00 -07003332FX_BOOL Field::signatureSetSeedValue(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003333 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003334 CJS_Value& vRet,
3335 CFX_WideString& sError) {
3336 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003337}
3338
Tom Sepezba038bc2015-10-08 12:03:00 -07003339FX_BOOL Field::signatureSign(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003340 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003341 CJS_Value& vRet,
3342 CFX_WideString& sError) {
3343 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003344}
3345
Tom Sepezba038bc2015-10-08 12:03:00 -07003346FX_BOOL Field::signatureValidate(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003347 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003348 CJS_Value& vRet,
3349 CFX_WideString& sError) {
3350 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003351}
3352
Tom Sepezba038bc2015-10-08 12:03:00 -07003353FX_BOOL Field::source(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003354 CJS_PropValue& vp,
3355 CFX_WideString& sError) {
3356 if (vp.IsGetting()) {
3357 vp << (CJS_Object*)NULL;
3358 }
3359
3360 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003361}
3362
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003363void Field::AddDelay_Int(enum FIELD_PROP prop, int32_t n) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003364 CJS_DelayData* pNewData = new CJS_DelayData;
3365 pNewData->sFieldName = m_FieldName;
3366 pNewData->nControlIndex = m_nFormControlIndex;
3367 pNewData->eProp = prop;
3368 pNewData->num = n;
3369
3370 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003371}
3372
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003373void Field::AddDelay_Bool(enum FIELD_PROP prop, bool b) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003374 CJS_DelayData* pNewData = new CJS_DelayData;
3375 pNewData->sFieldName = m_FieldName;
3376 pNewData->nControlIndex = m_nFormControlIndex;
3377 pNewData->eProp = prop;
3378 pNewData->b = b;
3379
3380 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003381}
3382
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003383void Field::AddDelay_String(enum FIELD_PROP prop,
3384 const CFX_ByteString& string) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003385 CJS_DelayData* pNewData = new CJS_DelayData;
3386 pNewData->sFieldName = m_FieldName;
3387 pNewData->nControlIndex = m_nFormControlIndex;
3388 pNewData->eProp = prop;
3389 pNewData->string = string;
3390
3391 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003392}
3393
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003394void Field::AddDelay_WideString(enum FIELD_PROP prop,
3395 const CFX_WideString& string) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003396 CJS_DelayData* pNewData = new CJS_DelayData;
3397 pNewData->sFieldName = m_FieldName;
3398 pNewData->nControlIndex = m_nFormControlIndex;
3399 pNewData->eProp = prop;
3400 pNewData->widestring = string;
3401
3402 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003403}
3404
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003405void Field::AddDelay_Rect(enum FIELD_PROP prop, const CPDF_Rect& rect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003406 CJS_DelayData* pNewData = new CJS_DelayData;
3407 pNewData->sFieldName = m_FieldName;
3408 pNewData->nControlIndex = m_nFormControlIndex;
3409 pNewData->eProp = prop;
3410 pNewData->rect = rect;
3411
3412 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003413}
3414
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003415void Field::AddDelay_Color(enum FIELD_PROP prop, const CPWL_Color& color) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003416 CJS_DelayData* pNewData = new CJS_DelayData;
3417 pNewData->sFieldName = m_FieldName;
3418 pNewData->nControlIndex = m_nFormControlIndex;
3419 pNewData->eProp = prop;
3420 pNewData->color = color;
3421
3422 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003423}
3424
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003425void Field::AddDelay_WordArray(enum FIELD_PROP prop,
3426 const CFX_DWordArray& array) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003427 CJS_DelayData* pNewData = new CJS_DelayData;
3428 pNewData->sFieldName = m_FieldName;
3429 pNewData->nControlIndex = m_nFormControlIndex;
3430 pNewData->eProp = prop;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003431
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003432 for (int i = 0, sz = array.GetSize(); i < sz; i++)
3433 pNewData->wordarray.Add(array.GetAt(i));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003434
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003435 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003436}
3437
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003438void Field::AddDelay_WideStringArray(enum FIELD_PROP prop,
3439 const CJS_WideStringArray& array) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003440 CJS_DelayData* pNewData = new CJS_DelayData;
3441 pNewData->sFieldName = m_FieldName;
3442 pNewData->nControlIndex = m_nFormControlIndex;
3443 pNewData->eProp = prop;
3444 for (int i = 0, sz = array.GetSize(); i < sz; i++)
3445 pNewData->widestringarray.Add(array.GetAt(i));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003446
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003447 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003448}
3449
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003450void Field::DoDelay(CPDFSDK_Document* pDocument, CJS_DelayData* pData) {
Lei Zhang96660d62015-12-14 18:27:25 -08003451 ASSERT(pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003452
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003453 switch (pData->eProp) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003454 case FP_ALIGNMENT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003455 Field::SetAlignment(pDocument, pData->sFieldName, pData->nControlIndex,
3456 pData->string);
3457 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003458 case FP_BORDERSTYLE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003459 Field::SetBorderStyle(pDocument, pData->sFieldName, pData->nControlIndex,
3460 pData->string);
3461 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003462 case FP_BUTTONALIGNX:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003463 Field::SetButtonAlignX(pDocument, pData->sFieldName, pData->nControlIndex,
3464 pData->num);
3465 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003466 case FP_BUTTONALIGNY:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003467 Field::SetButtonAlignY(pDocument, pData->sFieldName, pData->nControlIndex,
3468 pData->num);
3469 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003470 case FP_BUTTONFITBOUNDS:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003471 Field::SetButtonFitBounds(pDocument, pData->sFieldName,
3472 pData->nControlIndex, pData->b);
3473 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003474 case FP_BUTTONPOSITION:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003475 Field::SetButtonPosition(pDocument, pData->sFieldName,
3476 pData->nControlIndex, pData->num);
3477 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003478 case FP_BUTTONSCALEHOW:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003479 Field::SetButtonScaleHow(pDocument, pData->sFieldName,
3480 pData->nControlIndex, pData->num);
3481 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003482 case FP_BUTTONSCALEWHEN:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003483 Field::SetButtonScaleWhen(pDocument, pData->sFieldName,
3484 pData->nControlIndex, pData->num);
3485 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003486 case FP_CALCORDERINDEX:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003487 Field::SetCalcOrderIndex(pDocument, pData->sFieldName,
3488 pData->nControlIndex, pData->num);
3489 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003490 case FP_CHARLIMIT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003491 Field::SetCharLimit(pDocument, pData->sFieldName, pData->nControlIndex,
3492 pData->num);
3493 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003494 case FP_COMB:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003495 Field::SetComb(pDocument, pData->sFieldName, pData->nControlIndex,
3496 pData->b);
3497 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003498 case FP_COMMITONSELCHANGE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003499 Field::SetCommitOnSelChange(pDocument, pData->sFieldName,
3500 pData->nControlIndex, pData->b);
3501 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003502 case FP_CURRENTVALUEINDICES:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003503 Field::SetCurrentValueIndices(pDocument, pData->sFieldName,
3504 pData->nControlIndex, pData->wordarray);
3505 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003506 case FP_DEFAULTVALUE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003507 Field::SetDefaultValue(pDocument, pData->sFieldName, pData->nControlIndex,
3508 pData->widestring);
3509 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003510 case FP_DONOTSCROLL:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003511 Field::SetDoNotScroll(pDocument, pData->sFieldName, pData->nControlIndex,
3512 pData->b);
3513 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003514 case FP_DISPLAY:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003515 Field::SetDisplay(pDocument, pData->sFieldName, pData->nControlIndex,
3516 pData->num);
3517 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003518 case FP_FILLCOLOR:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003519 Field::SetFillColor(pDocument, pData->sFieldName, pData->nControlIndex,
3520 pData->color);
3521 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003522 case FP_HIDDEN:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003523 Field::SetHidden(pDocument, pData->sFieldName, pData->nControlIndex,
3524 pData->b);
3525 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003526 case FP_HIGHLIGHT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003527 Field::SetHighlight(pDocument, pData->sFieldName, pData->nControlIndex,
3528 pData->string);
3529 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003530 case FP_LINEWIDTH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003531 Field::SetLineWidth(pDocument, pData->sFieldName, pData->nControlIndex,
3532 pData->num);
3533 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003534 case FP_MULTILINE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003535 Field::SetMultiline(pDocument, pData->sFieldName, pData->nControlIndex,
3536 pData->b);
3537 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003538 case FP_MULTIPLESELECTION:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003539 Field::SetMultipleSelection(pDocument, pData->sFieldName,
3540 pData->nControlIndex, pData->b);
3541 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003542 case FP_PASSWORD:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003543 Field::SetPassword(pDocument, pData->sFieldName, pData->nControlIndex,
3544 pData->b);
3545 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003546 case FP_RECT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003547 Field::SetRect(pDocument, pData->sFieldName, pData->nControlIndex,
3548 pData->rect);
3549 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003550 case FP_RICHTEXT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003551 Field::SetRichText(pDocument, pData->sFieldName, pData->nControlIndex,
3552 pData->b);
3553 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003554 case FP_RICHVALUE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003555 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003556 case FP_ROTATION:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003557 Field::SetRotation(pDocument, pData->sFieldName, pData->nControlIndex,
3558 pData->num);
3559 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003560 case FP_STROKECOLOR:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003561 Field::SetStrokeColor(pDocument, pData->sFieldName, pData->nControlIndex,
3562 pData->color);
3563 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003564 case FP_STYLE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003565 Field::SetStyle(pDocument, pData->sFieldName, pData->nControlIndex,
3566 pData->string);
3567 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003568 case FP_TEXTCOLOR:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003569 Field::SetTextColor(pDocument, pData->sFieldName, pData->nControlIndex,
3570 pData->color);
3571 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003572 case FP_TEXTFONT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003573 Field::SetTextFont(pDocument, pData->sFieldName, pData->nControlIndex,
3574 pData->string);
3575 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003576 case FP_TEXTSIZE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003577 Field::SetTextSize(pDocument, pData->sFieldName, pData->nControlIndex,
3578 pData->num);
3579 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003580 case FP_USERNAME:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003581 Field::SetUserName(pDocument, pData->sFieldName, pData->nControlIndex,
3582 pData->widestring);
3583 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003584 case FP_VALUE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003585 Field::SetValue(pDocument, pData->sFieldName, pData->nControlIndex,
3586 pData->widestringarray);
3587 break;
3588 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003589}
3590
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003591void Field::AddField(CPDFSDK_Document* pDocument,
3592 int nPageIndex,
3593 int nFieldType,
3594 const CFX_WideString& sName,
3595 const CPDF_Rect& rcCoords) {
3596 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003597}