1 // 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.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #include "fpdfsdk/javascript/Field.h"
8 
9 #include <algorithm>
10 #include <memory>
11 #include <string>
12 #include <vector>
13 
14 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h"
15 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
16 #include "fpdfsdk/include/fsdk_mgr.h"
17 #include "fpdfsdk/javascript/Document.h"
18 #include "fpdfsdk/javascript/Icon.h"
19 #include "fpdfsdk/javascript/JS_Define.h"
20 #include "fpdfsdk/javascript/JS_EventHandler.h"
21 #include "fpdfsdk/javascript/JS_Object.h"
22 #include "fpdfsdk/javascript/JS_Value.h"
23 #include "fpdfsdk/javascript/PublicMethods.h"
24 #include "fpdfsdk/javascript/cjs_context.h"
25 #include "fpdfsdk/javascript/cjs_runtime.h"
26 #include "fpdfsdk/javascript/color.h"
27 
28 BEGIN_JS_STATIC_CONST(CJS_Field)
END_JS_STATIC_CONST()29 END_JS_STATIC_CONST()
30 
31 BEGIN_JS_STATIC_PROP(CJS_Field)
32 JS_STATIC_PROP_ENTRY(alignment)
33 JS_STATIC_PROP_ENTRY(borderStyle)
34 JS_STATIC_PROP_ENTRY(buttonAlignX)
35 JS_STATIC_PROP_ENTRY(buttonAlignY)
36 JS_STATIC_PROP_ENTRY(buttonFitBounds)
37 JS_STATIC_PROP_ENTRY(buttonPosition)
38 JS_STATIC_PROP_ENTRY(buttonScaleHow)
39 JS_STATIC_PROP_ENTRY(buttonScaleWhen)
40 JS_STATIC_PROP_ENTRY(calcOrderIndex)
41 JS_STATIC_PROP_ENTRY(charLimit)
42 JS_STATIC_PROP_ENTRY(comb)
43 JS_STATIC_PROP_ENTRY(commitOnSelChange)
44 JS_STATIC_PROP_ENTRY(currentValueIndices)
45 JS_STATIC_PROP_ENTRY(defaultStyle)
46 JS_STATIC_PROP_ENTRY(defaultValue)
47 JS_STATIC_PROP_ENTRY(doNotScroll)
48 JS_STATIC_PROP_ENTRY(doNotSpellCheck)
49 JS_STATIC_PROP_ENTRY(delay)
50 JS_STATIC_PROP_ENTRY(display)
51 JS_STATIC_PROP_ENTRY(doc)
52 JS_STATIC_PROP_ENTRY(editable)
53 JS_STATIC_PROP_ENTRY(exportValues)
54 JS_STATIC_PROP_ENTRY(hidden)
55 JS_STATIC_PROP_ENTRY(fileSelect)
56 JS_STATIC_PROP_ENTRY(fillColor)
57 JS_STATIC_PROP_ENTRY(lineWidth)
58 JS_STATIC_PROP_ENTRY(highlight)
59 JS_STATIC_PROP_ENTRY(multiline)
60 JS_STATIC_PROP_ENTRY(multipleSelection)
61 JS_STATIC_PROP_ENTRY(name)
62 JS_STATIC_PROP_ENTRY(numItems)
63 JS_STATIC_PROP_ENTRY(page)
64 JS_STATIC_PROP_ENTRY(password)
65 JS_STATIC_PROP_ENTRY(print)
66 JS_STATIC_PROP_ENTRY(radiosInUnison)
67 JS_STATIC_PROP_ENTRY(readonly)
68 JS_STATIC_PROP_ENTRY(rect)
69 JS_STATIC_PROP_ENTRY(required)
70 JS_STATIC_PROP_ENTRY(richText)
71 JS_STATIC_PROP_ENTRY(richValue)
72 JS_STATIC_PROP_ENTRY(rotation)
73 JS_STATIC_PROP_ENTRY(strokeColor)
74 JS_STATIC_PROP_ENTRY(style)
75 JS_STATIC_PROP_ENTRY(submitName)
76 JS_STATIC_PROP_ENTRY(textColor)
77 JS_STATIC_PROP_ENTRY(textFont)
78 JS_STATIC_PROP_ENTRY(textSize)
79 JS_STATIC_PROP_ENTRY(type)
80 JS_STATIC_PROP_ENTRY(userName)
81 JS_STATIC_PROP_ENTRY(value)
82 JS_STATIC_PROP_ENTRY(valueAsString)
83 JS_STATIC_PROP_ENTRY(source)
84 END_JS_STATIC_PROP()
85 
86 BEGIN_JS_STATIC_METHOD(CJS_Field)
87 JS_STATIC_METHOD_ENTRY(browseForFileToSubmit)
88 JS_STATIC_METHOD_ENTRY(buttonGetCaption)
89 JS_STATIC_METHOD_ENTRY(buttonGetIcon)
90 JS_STATIC_METHOD_ENTRY(buttonImportIcon)
91 JS_STATIC_METHOD_ENTRY(buttonSetCaption)
92 JS_STATIC_METHOD_ENTRY(buttonSetIcon)
93 JS_STATIC_METHOD_ENTRY(checkThisBox)
94 JS_STATIC_METHOD_ENTRY(clearItems)
95 JS_STATIC_METHOD_ENTRY(defaultIsChecked)
96 JS_STATIC_METHOD_ENTRY(deleteItemAt)
97 JS_STATIC_METHOD_ENTRY(getArray)
98 JS_STATIC_METHOD_ENTRY(getItemAt)
99 JS_STATIC_METHOD_ENTRY(getLock)
100 JS_STATIC_METHOD_ENTRY(insertItemAt)
101 JS_STATIC_METHOD_ENTRY(isBoxChecked)
102 JS_STATIC_METHOD_ENTRY(isDefaultChecked)
103 JS_STATIC_METHOD_ENTRY(setAction)
104 JS_STATIC_METHOD_ENTRY(setFocus)
105 JS_STATIC_METHOD_ENTRY(setItems)
106 JS_STATIC_METHOD_ENTRY(setLock)
107 JS_STATIC_METHOD_ENTRY(signatureGetModifications)
108 JS_STATIC_METHOD_ENTRY(signatureGetSeedValue)
109 JS_STATIC_METHOD_ENTRY(signatureInfo)
110 JS_STATIC_METHOD_ENTRY(signatureSetSeedValue)
111 JS_STATIC_METHOD_ENTRY(signatureSign)
112 JS_STATIC_METHOD_ENTRY(signatureValidate)
113 END_JS_STATIC_METHOD()
114 
115 IMPLEMENT_JS_CLASS(CJS_Field, Field)
116 
117 CJS_DelayData::CJS_DelayData(FIELD_PROP prop,
118                              int idx,
119                              const CFX_WideString& name)
120     : eProp(prop), nControlIndex(idx), sFieldName(name) {}
121 
~CJS_DelayData()122 CJS_DelayData::~CJS_DelayData() {}
123 
InitInstance(IJS_Runtime * pIRuntime)124 void CJS_Field::InitInstance(IJS_Runtime* pIRuntime) {
125   CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime);
126   Field* pField = static_cast<Field*>(GetEmbedObject());
127   pField->SetIsolate(pRuntime->GetIsolate());
128 }
129 
Field(CJS_Object * pJSObject)130 Field::Field(CJS_Object* pJSObject)
131     : CJS_EmbedObj(pJSObject),
132       m_pJSDoc(nullptr),
133       m_pDocument(nullptr),
134       m_nFormControlIndex(-1),
135       m_bCanSet(FALSE),
136       m_bDelay(FALSE),
137       m_isolate(nullptr) {}
138 
~Field()139 Field::~Field() {}
140 
141 // note: iControlNo = -1, means not a widget.
ParseFieldName(const std::wstring & strFieldNameParsed,std::wstring & strFieldName,int & iControlNo)142 void Field::ParseFieldName(const std::wstring& strFieldNameParsed,
143                            std::wstring& strFieldName,
144                            int& iControlNo) {
145   int iStart = strFieldNameParsed.find_last_of(L'.');
146   if (iStart == -1) {
147     strFieldName = strFieldNameParsed;
148     iControlNo = -1;
149     return;
150   }
151   std::wstring suffixal = strFieldNameParsed.substr(iStart + 1);
152   iControlNo = FXSYS_wtoi(suffixal.c_str());
153   if (iControlNo == 0) {
154     int iSpaceStart;
155     while ((iSpaceStart = suffixal.find_last_of(L" ")) != -1) {
156       suffixal.erase(iSpaceStart, 1);
157     }
158 
159     if (suffixal.compare(L"0") != 0) {
160       strFieldName = strFieldNameParsed;
161       iControlNo = -1;
162       return;
163     }
164   }
165   strFieldName = strFieldNameParsed.substr(0, iStart);
166 }
167 
AttachField(Document * pDocument,const CFX_WideString & csFieldName)168 FX_BOOL Field::AttachField(Document* pDocument,
169                            const CFX_WideString& csFieldName) {
170   m_pJSDoc = pDocument;
171   m_pDocument = pDocument->GetReaderDoc();
172   m_bCanSet = m_pDocument->GetPermissions(FPDFPERM_FILL_FORM) ||
173               m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
174               m_pDocument->GetPermissions(FPDFPERM_MODIFY);
175 
176   CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm();
177   CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
178   CFX_WideString swFieldNameTemp = csFieldName;
179   swFieldNameTemp.Replace(L"..", L".");
180 
181   if (pInterForm->CountFields(swFieldNameTemp) <= 0) {
182     std::wstring strFieldName;
183     int iControlNo = -1;
184     ParseFieldName(swFieldNameTemp.c_str(), strFieldName, iControlNo);
185     if (iControlNo == -1)
186       return FALSE;
187 
188     m_FieldName = strFieldName.c_str();
189     m_nFormControlIndex = iControlNo;
190     return TRUE;
191   }
192 
193   m_FieldName = swFieldNameTemp;
194   m_nFormControlIndex = -1;
195 
196   return TRUE;
197 }
198 
GetFormFields(CPDFSDK_Document * pDocument,const CFX_WideString & csFieldName)199 std::vector<CPDF_FormField*> Field::GetFormFields(
200     CPDFSDK_Document* pDocument,
201     const CFX_WideString& csFieldName) {
202   std::vector<CPDF_FormField*> fields;
203   CPDFSDK_InterForm* pReaderInterForm = pDocument->GetInterForm();
204   CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
205   for (int i = 0, sz = pInterForm->CountFields(csFieldName); i < sz; ++i) {
206     if (CPDF_FormField* pFormField = pInterForm->GetField(i, csFieldName))
207       fields.push_back(pFormField);
208   }
209   return fields;
210 }
211 
GetFormFields(const CFX_WideString & csFieldName) const212 std::vector<CPDF_FormField*> Field::GetFormFields(
213     const CFX_WideString& csFieldName) const {
214   return Field::GetFormFields(m_pDocument, csFieldName);
215 }
216 
UpdateFormField(CPDFSDK_Document * pDocument,CPDF_FormField * pFormField,FX_BOOL bChangeMark,FX_BOOL bResetAP,FX_BOOL bRefresh)217 void Field::UpdateFormField(CPDFSDK_Document* pDocument,
218                             CPDF_FormField* pFormField,
219                             FX_BOOL bChangeMark,
220                             FX_BOOL bResetAP,
221                             FX_BOOL bRefresh) {
222   std::vector<CPDFSDK_Widget*> widgets;
223   CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm();
224   pInterForm->GetWidgets(pFormField, &widgets);
225 
226   if (bResetAP) {
227     int nFieldType = pFormField->GetFieldType();
228     if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_TEXTFIELD) {
229       for (CPDFSDK_Widget* pWidget : widgets) {
230         FX_BOOL bFormatted = FALSE;
231         CFX_WideString sValue = pWidget->OnFormat(bFormatted);
232         pWidget->ResetAppearance(bFormatted ? sValue.c_str() : nullptr, FALSE);
233       }
234     } else {
235       for (CPDFSDK_Widget* pWidget : widgets) {
236         pWidget->ResetAppearance(nullptr, FALSE);
237       }
238     }
239   }
240 
241   if (bRefresh) {
242     for (CPDFSDK_Widget* pWidget : widgets) {
243       CPDFSDK_Document* pDoc = pWidget->GetInterForm()->GetDocument();
244       pDoc->UpdateAllViews(nullptr, pWidget);
245     }
246   }
247 
248   if (bChangeMark)
249     pDocument->SetChangeMark();
250 }
251 
UpdateFormControl(CPDFSDK_Document * pDocument,CPDF_FormControl * pFormControl,FX_BOOL bChangeMark,FX_BOOL bResetAP,FX_BOOL bRefresh)252 void Field::UpdateFormControl(CPDFSDK_Document* pDocument,
253                               CPDF_FormControl* pFormControl,
254                               FX_BOOL bChangeMark,
255                               FX_BOOL bResetAP,
256                               FX_BOOL bRefresh) {
257   ASSERT(pFormControl);
258 
259   CPDFSDK_InterForm* pForm = pDocument->GetInterForm();
260   CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl);
261 
262   if (pWidget) {
263     if (bResetAP) {
264       int nFieldType = pWidget->GetFieldType();
265       if (nFieldType == FIELDTYPE_COMBOBOX ||
266           nFieldType == FIELDTYPE_TEXTFIELD) {
267         FX_BOOL bFormated = FALSE;
268         CFX_WideString sValue = pWidget->OnFormat(bFormated);
269         if (bFormated)
270           pWidget->ResetAppearance(sValue.c_str(), FALSE);
271         else
272           pWidget->ResetAppearance(nullptr, FALSE);
273       } else {
274         pWidget->ResetAppearance(nullptr, FALSE);
275       }
276     }
277 
278     if (bRefresh) {
279       CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
280       CPDFSDK_Document* pDoc = pInterForm->GetDocument();
281       pDoc->UpdateAllViews(nullptr, pWidget);
282     }
283   }
284 
285   if (bChangeMark)
286     pDocument->SetChangeMark();
287 }
288 
GetWidget(CPDFSDK_Document * pDocument,CPDF_FormControl * pFormControl)289 CPDFSDK_Widget* Field::GetWidget(CPDFSDK_Document* pDocument,
290                                  CPDF_FormControl* pFormControl) {
291   CPDFSDK_InterForm* pInterForm =
292       static_cast<CPDFSDK_InterForm*>(pDocument->GetInterForm());
293   return pInterForm ? pInterForm->GetWidget(pFormControl) : nullptr;
294 }
295 
ValueIsOccur(CPDF_FormField * pFormField,CFX_WideString csOptLabel)296 FX_BOOL Field::ValueIsOccur(CPDF_FormField* pFormField,
297                             CFX_WideString csOptLabel) {
298   for (int i = 0, sz = pFormField->CountOptions(); i < sz; i++) {
299     if (csOptLabel.Compare(pFormField->GetOptionLabel(i)) == 0)
300       return TRUE;
301   }
302 
303   return FALSE;
304 }
305 
GetSmartFieldControl(CPDF_FormField * pFormField)306 CPDF_FormControl* Field::GetSmartFieldControl(CPDF_FormField* pFormField) {
307   if (!pFormField->CountControls() ||
308       m_nFormControlIndex >= pFormField->CountControls())
309     return nullptr;
310 
311   if (m_nFormControlIndex < 0)
312     return pFormField->GetControl(0);
313 
314   return pFormField->GetControl(m_nFormControlIndex);
315 }
316 
alignment(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)317 FX_BOOL Field::alignment(IJS_Context* cc,
318                          CJS_PropValue& vp,
319                          CFX_WideString& sError) {
320   ASSERT(m_pDocument);
321 
322   if (vp.IsSetting()) {
323     if (!m_bCanSet)
324       return FALSE;
325 
326     CFX_ByteString alignStr;
327     vp >> alignStr;
328 
329     if (m_bDelay) {
330       AddDelay_String(FP_ALIGNMENT, alignStr);
331     } else {
332       Field::SetAlignment(m_pDocument, m_FieldName, m_nFormControlIndex,
333                           alignStr);
334     }
335   } else {
336     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
337     if (FieldArray.empty())
338       return FALSE;
339 
340     CPDF_FormField* pFormField = FieldArray[0];
341     if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
342       return FALSE;
343 
344     CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
345     if (!pFormControl)
346       return FALSE;
347 
348     switch (pFormControl->GetControlAlignment()) {
349       case 1:
350         vp << L"center";
351         break;
352       case 0:
353         vp << L"left";
354         break;
355       case 2:
356         vp << L"right";
357         break;
358       default:
359         vp << L"";
360     }
361   }
362 
363   return TRUE;
364 }
365 
SetAlignment(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,const CFX_ByteString & string)366 void Field::SetAlignment(CPDFSDK_Document* pDocument,
367                          const CFX_WideString& swFieldName,
368                          int nControlIndex,
369                          const CFX_ByteString& string) {
370   // Not supported.
371 }
372 
borderStyle(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)373 FX_BOOL Field::borderStyle(IJS_Context* cc,
374                            CJS_PropValue& vp,
375                            CFX_WideString& sError) {
376   ASSERT(m_pDocument);
377 
378   if (vp.IsSetting()) {
379     if (!m_bCanSet)
380       return FALSE;
381 
382     CFX_ByteString strType = "";
383     vp >> strType;
384 
385     if (m_bDelay) {
386       AddDelay_String(FP_BORDERSTYLE, strType);
387     } else {
388       Field::SetBorderStyle(m_pDocument, m_FieldName, m_nFormControlIndex,
389                             strType);
390     }
391   } else {
392     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
393     if (FieldArray.empty())
394       return FALSE;
395 
396     CPDF_FormField* pFormField = FieldArray[0];
397     if (!pFormField)
398       return FALSE;
399 
400     CPDFSDK_Widget* pWidget =
401         GetWidget(m_pDocument, GetSmartFieldControl(pFormField));
402     if (!pWidget)
403       return FALSE;
404 
405     switch (pWidget->GetBorderStyle()) {
406       case BorderStyle::SOLID:
407         vp << L"solid";
408         break;
409       case BorderStyle::DASH:
410         vp << L"dashed";
411         break;
412       case BorderStyle::BEVELED:
413         vp << L"beveled";
414         break;
415       case BorderStyle::INSET:
416         vp << L"inset";
417         break;
418       case BorderStyle::UNDERLINE:
419         vp << L"underline";
420         break;
421       default:
422         vp << L"";
423         break;
424     }
425   }
426 
427   return TRUE;
428 }
429 
SetBorderStyle(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,const CFX_ByteString & string)430 void Field::SetBorderStyle(CPDFSDK_Document* pDocument,
431                            const CFX_WideString& swFieldName,
432                            int nControlIndex,
433                            const CFX_ByteString& string) {
434   ASSERT(pDocument);
435 
436   BorderStyle nBorderStyle = BorderStyle::SOLID;
437   if (string == "solid")
438     nBorderStyle = BorderStyle::SOLID;
439   else if (string == "beveled")
440     nBorderStyle = BorderStyle::BEVELED;
441   else if (string == "dashed")
442     nBorderStyle = BorderStyle::DASH;
443   else if (string == "inset")
444     nBorderStyle = BorderStyle::INSET;
445   else if (string == "underline")
446     nBorderStyle = BorderStyle::UNDERLINE;
447   else
448     return;
449 
450   std::vector<CPDF_FormField*> FieldArray =
451       GetFormFields(pDocument, swFieldName);
452   for (CPDF_FormField* pFormField : FieldArray) {
453     if (nControlIndex < 0) {
454       FX_BOOL bSet = FALSE;
455       for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
456         if (CPDFSDK_Widget* pWidget =
457                 GetWidget(pDocument, pFormField->GetControl(i))) {
458           if (pWidget->GetBorderStyle() != nBorderStyle) {
459             pWidget->SetBorderStyle(nBorderStyle);
460             bSet = TRUE;
461           }
462         }
463       }
464       if (bSet)
465         UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
466     } else {
467       if (nControlIndex >= pFormField->CountControls())
468         return;
469       if (CPDF_FormControl* pFormControl =
470               pFormField->GetControl(nControlIndex)) {
471         if (CPDFSDK_Widget* pWidget = GetWidget(pDocument, pFormControl)) {
472           if (pWidget->GetBorderStyle() != nBorderStyle) {
473             pWidget->SetBorderStyle(nBorderStyle);
474             UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
475           }
476         }
477       }
478     }
479   }
480 }
481 
buttonAlignX(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)482 FX_BOOL Field::buttonAlignX(IJS_Context* cc,
483                             CJS_PropValue& vp,
484                             CFX_WideString& sError) {
485   ASSERT(m_pDocument);
486 
487   if (vp.IsSetting()) {
488     if (!m_bCanSet)
489       return FALSE;
490 
491     int nVP;
492     vp >> nVP;
493 
494     if (m_bDelay) {
495       AddDelay_Int(FP_BUTTONALIGNX, nVP);
496     } else {
497       Field::SetButtonAlignX(m_pDocument, m_FieldName, m_nFormControlIndex,
498                              nVP);
499     }
500   } else {
501     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
502     if (FieldArray.empty())
503       return FALSE;
504 
505     CPDF_FormField* pFormField = FieldArray[0];
506     if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
507       return FALSE;
508 
509     CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
510     if (!pFormControl)
511       return FALSE;
512 
513     CPDF_IconFit IconFit = pFormControl->GetIconFit();
514 
515     FX_FLOAT fLeft, fBottom;
516     IconFit.GetIconPosition(fLeft, fBottom);
517 
518     vp << (int32_t)fLeft;
519   }
520 
521   return TRUE;
522 }
523 
SetButtonAlignX(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,int number)524 void Field::SetButtonAlignX(CPDFSDK_Document* pDocument,
525                             const CFX_WideString& swFieldName,
526                             int nControlIndex,
527                             int number) {
528   // Not supported.
529 }
530 
buttonAlignY(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)531 FX_BOOL Field::buttonAlignY(IJS_Context* cc,
532                             CJS_PropValue& vp,
533                             CFX_WideString& sError) {
534   ASSERT(m_pDocument);
535 
536   if (vp.IsSetting()) {
537     if (!m_bCanSet)
538       return FALSE;
539 
540     int nVP;
541     vp >> nVP;
542 
543     if (m_bDelay) {
544       AddDelay_Int(FP_BUTTONALIGNY, nVP);
545     } else {
546       Field::SetButtonAlignY(m_pDocument, m_FieldName, m_nFormControlIndex,
547                              nVP);
548     }
549   } else {
550     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
551     if (FieldArray.empty())
552       return FALSE;
553 
554     CPDF_FormField* pFormField = FieldArray[0];
555     if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
556       return FALSE;
557 
558     CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
559     if (!pFormControl)
560       return FALSE;
561 
562     CPDF_IconFit IconFit = pFormControl->GetIconFit();
563 
564     FX_FLOAT fLeft, fBottom;
565     IconFit.GetIconPosition(fLeft, fBottom);
566 
567     vp << (int32_t)fBottom;
568   }
569 
570   return TRUE;
571 }
572 
SetButtonAlignY(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,int number)573 void Field::SetButtonAlignY(CPDFSDK_Document* pDocument,
574                             const CFX_WideString& swFieldName,
575                             int nControlIndex,
576                             int number) {
577   // Not supported.
578 }
579 
buttonFitBounds(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)580 FX_BOOL Field::buttonFitBounds(IJS_Context* cc,
581                                CJS_PropValue& vp,
582                                CFX_WideString& sError) {
583   ASSERT(m_pDocument);
584 
585   if (vp.IsSetting()) {
586     if (!m_bCanSet)
587       return FALSE;
588 
589     bool bVP;
590     vp >> bVP;
591 
592     if (m_bDelay) {
593       AddDelay_Bool(FP_BUTTONFITBOUNDS, bVP);
594     } else {
595       Field::SetButtonFitBounds(m_pDocument, m_FieldName, m_nFormControlIndex,
596                                 bVP);
597     }
598   } else {
599     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
600     if (FieldArray.empty())
601       return FALSE;
602 
603     CPDF_FormField* pFormField = FieldArray[0];
604     if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
605       return FALSE;
606 
607     CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
608     if (!pFormControl)
609       return FALSE;
610 
611     vp << pFormControl->GetIconFit().GetFittingBounds();
612   }
613 
614   return TRUE;
615 }
616 
SetButtonFitBounds(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,bool b)617 void Field::SetButtonFitBounds(CPDFSDK_Document* pDocument,
618                                const CFX_WideString& swFieldName,
619                                int nControlIndex,
620                                bool b) {
621   // Not supported.
622 }
623 
buttonPosition(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)624 FX_BOOL Field::buttonPosition(IJS_Context* cc,
625                               CJS_PropValue& vp,
626                               CFX_WideString& sError) {
627   ASSERT(m_pDocument);
628 
629   if (vp.IsSetting()) {
630     if (!m_bCanSet)
631       return FALSE;
632 
633     int nVP;
634     vp >> nVP;
635 
636     if (m_bDelay) {
637       AddDelay_Int(FP_BUTTONPOSITION, nVP);
638     } else {
639       Field::SetButtonPosition(m_pDocument, m_FieldName, m_nFormControlIndex,
640                                nVP);
641     }
642   } else {
643     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
644     if (FieldArray.empty())
645       return FALSE;
646 
647     CPDF_FormField* pFormField = FieldArray[0];
648     if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
649       return FALSE;
650 
651     CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
652     if (!pFormControl)
653       return FALSE;
654 
655     vp << pFormControl->GetTextPosition();
656   }
657   return TRUE;
658 }
659 
SetButtonPosition(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,int number)660 void Field::SetButtonPosition(CPDFSDK_Document* pDocument,
661                               const CFX_WideString& swFieldName,
662                               int nControlIndex,
663                               int number) {
664   // Not supported.
665 }
666 
buttonScaleHow(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)667 FX_BOOL Field::buttonScaleHow(IJS_Context* cc,
668                               CJS_PropValue& vp,
669                               CFX_WideString& sError) {
670   ASSERT(m_pDocument);
671 
672   if (vp.IsSetting()) {
673     if (!m_bCanSet)
674       return FALSE;
675 
676     int nVP;
677     vp >> nVP;
678 
679     if (m_bDelay) {
680       AddDelay_Int(FP_BUTTONSCALEHOW, nVP);
681     } else {
682       Field::SetButtonScaleHow(m_pDocument, m_FieldName, m_nFormControlIndex,
683                                nVP);
684     }
685   } else {
686     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
687     if (FieldArray.empty())
688       return FALSE;
689 
690     CPDF_FormField* pFormField = FieldArray[0];
691     if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
692       return FALSE;
693 
694     CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
695     if (!pFormControl)
696       return FALSE;
697 
698     CPDF_IconFit IconFit = pFormControl->GetIconFit();
699     if (IconFit.IsProportionalScale())
700       vp << (int32_t)0;
701     else
702       vp << (int32_t)1;
703   }
704 
705   return TRUE;
706 }
707 
SetButtonScaleHow(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,int number)708 void Field::SetButtonScaleHow(CPDFSDK_Document* pDocument,
709                               const CFX_WideString& swFieldName,
710                               int nControlIndex,
711                               int number) {
712   // Not supported.
713 }
714 
buttonScaleWhen(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)715 FX_BOOL Field::buttonScaleWhen(IJS_Context* cc,
716                                CJS_PropValue& vp,
717                                CFX_WideString& sError) {
718   ASSERT(m_pDocument);
719 
720   if (vp.IsSetting()) {
721     if (!m_bCanSet)
722       return FALSE;
723 
724     int nVP;
725     vp >> nVP;
726 
727     if (m_bDelay) {
728       AddDelay_Int(FP_BUTTONSCALEWHEN, nVP);
729     } else {
730       Field::SetButtonScaleWhen(m_pDocument, m_FieldName, m_nFormControlIndex,
731                                 nVP);
732     }
733   } else {
734     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
735     if (FieldArray.empty())
736       return FALSE;
737 
738     CPDF_FormField* pFormField = FieldArray[0];
739     if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
740       return FALSE;
741 
742     CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
743     if (!pFormControl)
744       return FALSE;
745 
746     CPDF_IconFit IconFit = pFormControl->GetIconFit();
747     int ScaleM = IconFit.GetScaleMethod();
748     switch (ScaleM) {
749       case CPDF_IconFit::Always:
750         vp << (int32_t)CPDF_IconFit::Always;
751         break;
752       case CPDF_IconFit::Bigger:
753         vp << (int32_t)CPDF_IconFit::Bigger;
754         break;
755       case CPDF_IconFit::Never:
756         vp << (int32_t)CPDF_IconFit::Never;
757         break;
758       case CPDF_IconFit::Smaller:
759         vp << (int32_t)CPDF_IconFit::Smaller;
760         break;
761     }
762   }
763 
764   return TRUE;
765 }
766 
SetButtonScaleWhen(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,int number)767 void Field::SetButtonScaleWhen(CPDFSDK_Document* pDocument,
768                                const CFX_WideString& swFieldName,
769                                int nControlIndex,
770                                int number) {
771   // Not supported.
772 }
773 
calcOrderIndex(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)774 FX_BOOL Field::calcOrderIndex(IJS_Context* cc,
775                               CJS_PropValue& vp,
776                               CFX_WideString& sError) {
777   ASSERT(m_pDocument);
778 
779   if (vp.IsSetting()) {
780     if (!m_bCanSet)
781       return FALSE;
782 
783     int nVP;
784     vp >> nVP;
785 
786     if (m_bDelay) {
787       AddDelay_Int(FP_CALCORDERINDEX, nVP);
788     } else {
789       Field::SetCalcOrderIndex(m_pDocument, m_FieldName, m_nFormControlIndex,
790                                nVP);
791     }
792   } else {
793     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
794     if (FieldArray.empty())
795       return FALSE;
796 
797     CPDF_FormField* pFormField = FieldArray[0];
798     if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
799         pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) {
800       return FALSE;
801     }
802 
803     CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm();
804     CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
805     vp << (int32_t)pInterForm->FindFieldInCalculationOrder(pFormField);
806   }
807 
808   return TRUE;
809 }
810 
SetCalcOrderIndex(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,int number)811 void Field::SetCalcOrderIndex(CPDFSDK_Document* pDocument,
812                               const CFX_WideString& swFieldName,
813                               int nControlIndex,
814                               int number) {
815   // Not supported.
816 }
817 
charLimit(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)818 FX_BOOL Field::charLimit(IJS_Context* cc,
819                          CJS_PropValue& vp,
820                          CFX_WideString& sError) {
821   ASSERT(m_pDocument);
822 
823   if (vp.IsSetting()) {
824     if (!m_bCanSet)
825       return FALSE;
826 
827     int nVP;
828     vp >> nVP;
829 
830     if (m_bDelay) {
831       AddDelay_Int(FP_CHARLIMIT, nVP);
832     } else {
833       Field::SetCharLimit(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
834     }
835   } else {
836     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
837     if (FieldArray.empty())
838       return FALSE;
839 
840     CPDF_FormField* pFormField = FieldArray[0];
841     if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
842       return FALSE;
843 
844     vp << (int32_t)pFormField->GetMaxLen();
845   }
846   return TRUE;
847 }
848 
SetCharLimit(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,int number)849 void Field::SetCharLimit(CPDFSDK_Document* pDocument,
850                          const CFX_WideString& swFieldName,
851                          int nControlIndex,
852                          int number) {
853   // Not supported.
854 }
855 
comb(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)856 FX_BOOL Field::comb(IJS_Context* cc,
857                     CJS_PropValue& vp,
858                     CFX_WideString& sError) {
859   ASSERT(m_pDocument);
860 
861   if (vp.IsSetting()) {
862     if (!m_bCanSet)
863       return FALSE;
864 
865     bool bVP;
866     vp >> bVP;
867 
868     if (m_bDelay) {
869       AddDelay_Bool(FP_COMB, bVP);
870     } else {
871       Field::SetComb(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
872     }
873   } else {
874     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
875     if (FieldArray.empty())
876       return FALSE;
877 
878     CPDF_FormField* pFormField = FieldArray[0];
879     if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
880       return FALSE;
881 
882     if (pFormField->GetFieldFlags() & FIELDFLAG_COMB)
883       vp << true;
884     else
885       vp << false;
886   }
887 
888   return TRUE;
889 }
890 
SetComb(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,bool b)891 void Field::SetComb(CPDFSDK_Document* pDocument,
892                     const CFX_WideString& swFieldName,
893                     int nControlIndex,
894                     bool b) {
895   // Not supported.
896 }
897 
commitOnSelChange(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)898 FX_BOOL Field::commitOnSelChange(IJS_Context* cc,
899                                  CJS_PropValue& vp,
900                                  CFX_WideString& sError) {
901   ASSERT(m_pDocument);
902 
903   if (vp.IsSetting()) {
904     if (!m_bCanSet)
905       return FALSE;
906 
907     bool bVP;
908     vp >> bVP;
909 
910     if (m_bDelay) {
911       AddDelay_Bool(FP_COMMITONSELCHANGE, bVP);
912     } else {
913       Field::SetCommitOnSelChange(m_pDocument, m_FieldName, m_nFormControlIndex,
914                                   bVP);
915     }
916   } else {
917     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
918     if (FieldArray.empty())
919       return FALSE;
920 
921     CPDF_FormField* pFormField = FieldArray[0];
922     if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
923         pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
924       return FALSE;
925     }
926 
927     if (pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE)
928       vp << true;
929     else
930       vp << false;
931   }
932 
933   return TRUE;
934 }
935 
SetCommitOnSelChange(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,bool b)936 void Field::SetCommitOnSelChange(CPDFSDK_Document* pDocument,
937                                  const CFX_WideString& swFieldName,
938                                  int nControlIndex,
939                                  bool b) {
940   // Not supported.
941 }
942 
currentValueIndices(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)943 FX_BOOL Field::currentValueIndices(IJS_Context* cc,
944                                    CJS_PropValue& vp,
945                                    CFX_WideString& sError) {
946   CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
947 
948   if (vp.IsSetting()) {
949     if (!m_bCanSet)
950       return FALSE;
951 
952     std::vector<uint32_t> array;
953     if (vp.GetType() == CJS_Value::VT_number) {
954       int iSelecting = 0;
955       vp >> iSelecting;
956       array.push_back(iSelecting);
957     } else if (vp.IsArrayObject()) {
958       CJS_Array SelArray(pRuntime);
959       CJS_Value SelValue(pRuntime);
960       int iSelecting;
961       vp >> SelArray;
962       for (int i = 0, sz = SelArray.GetLength(); i < sz; i++) {
963         SelArray.GetElement(i, SelValue);
964         iSelecting = SelValue.ToInt();
965         array.push_back(iSelecting);
966       }
967     }
968 
969     if (m_bDelay) {
970       AddDelay_WordArray(FP_CURRENTVALUEINDICES, array);
971     } else {
972       Field::SetCurrentValueIndices(m_pDocument, m_FieldName,
973                                     m_nFormControlIndex, array);
974     }
975   } else {
976     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
977     if (FieldArray.empty())
978       return FALSE;
979 
980     CPDF_FormField* pFormField = FieldArray[0];
981     if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
982         pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
983       return FALSE;
984     }
985 
986     if (pFormField->CountSelectedItems() == 1) {
987       vp << pFormField->GetSelectedIndex(0);
988     } else if (pFormField->CountSelectedItems() > 1) {
989       CJS_Array SelArray(pRuntime);
990       for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
991         SelArray.SetElement(
992             i, CJS_Value(pRuntime, pFormField->GetSelectedIndex(i)));
993       }
994       vp << SelArray;
995     } else {
996       vp << -1;
997     }
998   }
999 
1000   return TRUE;
1001 }
1002 
SetCurrentValueIndices(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,const std::vector<uint32_t> & array)1003 void Field::SetCurrentValueIndices(CPDFSDK_Document* pDocument,
1004                                    const CFX_WideString& swFieldName,
1005                                    int nControlIndex,
1006                                    const std::vector<uint32_t>& array) {
1007   ASSERT(pDocument);
1008   std::vector<CPDF_FormField*> FieldArray =
1009       GetFormFields(pDocument, swFieldName);
1010 
1011   for (CPDF_FormField* pFormField : FieldArray) {
1012     int nFieldType = pFormField->GetFieldType();
1013     if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX) {
1014       uint32_t dwFieldFlags = pFormField->GetFieldFlags();
1015       pFormField->ClearSelection(TRUE);
1016       for (size_t i = 0; i < array.size(); ++i) {
1017         if (i != 0 && !(dwFieldFlags & (1 << 21)))
1018           break;
1019         if (array[i] < static_cast<uint32_t>(pFormField->CountOptions()) &&
1020             !pFormField->IsItemSelected(array[i])) {
1021           pFormField->SetItemSelection(array[i], TRUE);
1022         }
1023       }
1024       UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
1025     }
1026   }
1027 }
1028 
defaultStyle(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)1029 FX_BOOL Field::defaultStyle(IJS_Context* cc,
1030                             CJS_PropValue& vp,
1031                             CFX_WideString& sError) {
1032   return FALSE;
1033 }
1034 
SetDefaultStyle(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex)1035 void Field::SetDefaultStyle(CPDFSDK_Document* pDocument,
1036                             const CFX_WideString& swFieldName,
1037                             int nControlIndex) {
1038   // Not supported.
1039 }
1040 
defaultValue(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)1041 FX_BOOL Field::defaultValue(IJS_Context* cc,
1042                             CJS_PropValue& vp,
1043                             CFX_WideString& sError) {
1044   ASSERT(m_pDocument);
1045 
1046   if (vp.IsSetting()) {
1047     if (!m_bCanSet)
1048       return FALSE;
1049 
1050     CFX_WideString WideStr;
1051     vp >> WideStr;
1052 
1053     if (m_bDelay) {
1054       AddDelay_WideString(FP_DEFAULTVALUE, WideStr);
1055     } else {
1056       Field::SetDefaultValue(m_pDocument, m_FieldName, m_nFormControlIndex,
1057                              WideStr);
1058     }
1059   } else {
1060     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1061     if (FieldArray.empty())
1062       return FALSE;
1063 
1064     CPDF_FormField* pFormField = FieldArray[0];
1065     if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON ||
1066         pFormField->GetFieldType() == FIELDTYPE_SIGNATURE) {
1067       return FALSE;
1068     }
1069 
1070     vp << pFormField->GetDefaultValue();
1071   }
1072   return TRUE;
1073 }
1074 
SetDefaultValue(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,const CFX_WideString & string)1075 void Field::SetDefaultValue(CPDFSDK_Document* pDocument,
1076                             const CFX_WideString& swFieldName,
1077                             int nControlIndex,
1078                             const CFX_WideString& string) {
1079   // Not supported.
1080 }
1081 
doNotScroll(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)1082 FX_BOOL Field::doNotScroll(IJS_Context* cc,
1083                            CJS_PropValue& vp,
1084                            CFX_WideString& sError) {
1085   ASSERT(m_pDocument);
1086 
1087   if (vp.IsSetting()) {
1088     if (!m_bCanSet)
1089       return FALSE;
1090 
1091     bool bVP;
1092     vp >> bVP;
1093 
1094     if (m_bDelay) {
1095       AddDelay_Bool(FP_DONOTSCROLL, bVP);
1096     } else {
1097       Field::SetDoNotScroll(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
1098     }
1099   } else {
1100     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1101     if (FieldArray.empty())
1102       return FALSE;
1103 
1104     CPDF_FormField* pFormField = FieldArray[0];
1105     if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1106       return FALSE;
1107 
1108     if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL)
1109       vp << true;
1110     else
1111       vp << false;
1112   }
1113 
1114   return TRUE;
1115 }
1116 
SetDoNotScroll(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,bool b)1117 void Field::SetDoNotScroll(CPDFSDK_Document* pDocument,
1118                            const CFX_WideString& swFieldName,
1119                            int nControlIndex,
1120                            bool b) {
1121   // Not supported.
1122 }
1123 
doNotSpellCheck(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)1124 FX_BOOL Field::doNotSpellCheck(IJS_Context* cc,
1125                                CJS_PropValue& vp,
1126                                CFX_WideString& sError) {
1127   ASSERT(m_pDocument);
1128 
1129   if (vp.IsSetting()) {
1130     if (!m_bCanSet)
1131       return FALSE;
1132 
1133     bool bVP;
1134     vp >> bVP;
1135   } else {
1136     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1137     if (FieldArray.empty())
1138       return FALSE;
1139 
1140     CPDF_FormField* pFormField = FieldArray[0];
1141     if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD &&
1142         pFormField->GetFieldType() != FIELDTYPE_COMBOBOX) {
1143       return FALSE;
1144     }
1145 
1146     if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK)
1147       vp << true;
1148     else
1149       vp << false;
1150   }
1151 
1152   return TRUE;
1153 }
1154 
SetDelay(FX_BOOL bDelay)1155 void Field::SetDelay(FX_BOOL bDelay) {
1156   m_bDelay = bDelay;
1157 
1158   if (!m_bDelay) {
1159     if (m_pJSDoc)
1160       m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex);
1161   }
1162 }
1163 
delay(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)1164 FX_BOOL Field::delay(IJS_Context* cc,
1165                      CJS_PropValue& vp,
1166                      CFX_WideString& sError) {
1167   if (vp.IsSetting()) {
1168     if (!m_bCanSet)
1169       return FALSE;
1170 
1171     bool bVP;
1172     vp >> bVP;
1173 
1174     SetDelay(bVP);
1175   } else {
1176     vp << m_bDelay;
1177   }
1178   return TRUE;
1179 }
1180 
display(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)1181 FX_BOOL Field::display(IJS_Context* cc,
1182                        CJS_PropValue& vp,
1183                        CFX_WideString& sError) {
1184   if (vp.IsSetting()) {
1185     if (!m_bCanSet)
1186       return FALSE;
1187 
1188     int nVP;
1189     vp >> nVP;
1190 
1191     if (m_bDelay) {
1192       AddDelay_Int(FP_DISPLAY, nVP);
1193     } else {
1194       Field::SetDisplay(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
1195     }
1196   } else {
1197     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1198     if (FieldArray.empty())
1199       return FALSE;
1200 
1201     CPDF_FormField* pFormField = FieldArray[0];
1202     ASSERT(pFormField);
1203     CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
1204     CPDFSDK_Widget* pWidget =
1205         pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1206     if (!pWidget)
1207       return FALSE;
1208 
1209     uint32_t 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 
SetDisplay(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,int number)1229 void Field::SetDisplay(CPDFSDK_Document* pDocument,
1230                        const CFX_WideString& swFieldName,
1231                        int nControlIndex,
1232                        int number) {
1233   CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm();
1234   std::vector<CPDF_FormField*> FieldArray =
1235       GetFormFields(pDocument, swFieldName);
1236   for (CPDF_FormField* pFormField : FieldArray) {
1237     if (nControlIndex < 0) {
1238       FX_BOOL bSet = FALSE;
1239       for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1240         CPDF_FormControl* pFormControl = pFormField->GetControl(i);
1241         ASSERT(pFormControl);
1242 
1243         if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1244           uint32_t 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           uint32_t 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 
doc(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)1320 FX_BOOL Field::doc(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) {
1321   if (!vp.IsGetting()) {
1322     return FALSE;
1323   }
1324   vp << m_pJSDoc->GetCJSDoc();
1325   return TRUE;
1326 }
1327 
editable(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)1328 FX_BOOL Field::editable(IJS_Context* cc,
1329                         CJS_PropValue& vp,
1330                         CFX_WideString& sError) {
1331   if (vp.IsSetting()) {
1332     if (!m_bCanSet)
1333       return FALSE;
1334 
1335     bool bVP;
1336     vp >> bVP;
1337   } else {
1338     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1339     if (FieldArray.empty())
1340       return FALSE;
1341 
1342     CPDF_FormField* pFormField = FieldArray[0];
1343     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 
exportValues(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)1355 FX_BOOL Field::exportValues(IJS_Context* cc,
1356                             CJS_PropValue& vp,
1357                             CFX_WideString& sError) {
1358   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1359   if (FieldArray.empty())
1360     return FALSE;
1361 
1362   CPDF_FormField* pFormField = FieldArray[0];
1363   if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
1364       pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) {
1365     return FALSE;
1366   }
1367 
1368   if (vp.IsSetting()) {
1369     if (!m_bCanSet)
1370       return FALSE;
1371 
1372     if (!vp.IsArrayObject())
1373       return FALSE;
1374   } else {
1375     CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
1376     CJS_Array ExportValusArray(pRuntime);
1377     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(
1381             i, CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
1382       }
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(
1393           0, CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
1394     }
1395     vp << ExportValusArray;
1396   }
1397   return TRUE;
1398 }
1399 
fileSelect(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)1400 FX_BOOL Field::fileSelect(IJS_Context* cc,
1401                           CJS_PropValue& vp,
1402                           CFX_WideString& sError) {
1403   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1404   if (FieldArray.empty())
1405     return FALSE;
1406 
1407   CPDF_FormField* pFormField = FieldArray[0];
1408   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 
fillColor(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)1426 FX_BOOL Field::fillColor(IJS_Context* cc,
1427                          CJS_PropValue& vp,
1428                          CFX_WideString& sError) {
1429   CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
1430   CJS_Array crArray(pRuntime);
1431   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1432   if (FieldArray.empty())
1433     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 {
1452     CPDF_FormField* pFormField = FieldArray[0];
1453     ASSERT(pFormField);
1454     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));
1478     } else {
1479       return FALSE;
1480     }
1481 
1482     color::ConvertPWLColorToArray(color, crArray);
1483     vp << crArray;
1484   }
1485 
1486   return TRUE;
1487 }
1488 
SetFillColor(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,const CPWL_Color & color)1489 void Field::SetFillColor(CPDFSDK_Document* pDocument,
1490                          const CFX_WideString& swFieldName,
1491                          int nControlIndex,
1492                          const CPWL_Color& color) {
1493   // Not supported.
1494 }
1495 
hidden(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)1496 FX_BOOL Field::hidden(IJS_Context* cc,
1497                       CJS_PropValue& vp,
1498                       CFX_WideString& sError) {
1499   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 {
1512     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1513     if (FieldArray.empty())
1514       return FALSE;
1515 
1516     CPDF_FormField* pFormField = FieldArray[0];
1517     ASSERT(pFormField);
1518     CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
1519     CPDFSDK_Widget* pWidget =
1520         pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1521     if (!pWidget)
1522       return FALSE;
1523 
1524     uint32_t dwFlags = pWidget->GetFlags();
1525 
1526     if (ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags)
1527       vp << true;
1528     else
1529       vp << false;
1530   }
1531 
1532   return TRUE;
1533 }
1534 
SetHidden(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,bool b)1535 void Field::SetHidden(CPDFSDK_Document* pDocument,
1536                       const CFX_WideString& swFieldName,
1537                       int nControlIndex,
1538                       bool b) {
1539   CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm();
1540   std::vector<CPDF_FormField*> FieldArray =
1541       GetFormFields(pDocument, swFieldName);
1542   for (CPDF_FormField* pFormField : FieldArray) {
1543     if (nControlIndex < 0) {
1544       FX_BOOL bSet = FALSE;
1545       for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1546         if (CPDFSDK_Widget* pWidget =
1547                 pInterForm->GetWidget(pFormField->GetControl(i))) {
1548           uint32_t dwFlags = pWidget->GetFlags();
1549 
1550           if (b) {
1551             dwFlags &= (~ANNOTFLAG_INVISIBLE);
1552             dwFlags &= (~ANNOTFLAG_NOVIEW);
1553             dwFlags |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
1554           } else {
1555             dwFlags &= (~ANNOTFLAG_INVISIBLE);
1556             dwFlags &= (~ANNOTFLAG_HIDDEN);
1557             dwFlags &= (~ANNOTFLAG_NOVIEW);
1558             dwFlags |= ANNOTFLAG_PRINT;
1559           }
1560 
1561           if (dwFlags != pWidget->GetFlags()) {
1562             pWidget->SetFlags(dwFlags);
1563             bSet = TRUE;
1564           }
1565         }
1566       }
1567 
1568       if (bSet)
1569         UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
1570     } else {
1571       if (nControlIndex >= pFormField->CountControls())
1572         return;
1573       if (CPDF_FormControl* pFormControl =
1574               pFormField->GetControl(nControlIndex)) {
1575         if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1576           uint32_t dwFlags = pWidget->GetFlags();
1577 
1578           if (b) {
1579             dwFlags &= (~ANNOTFLAG_INVISIBLE);
1580             dwFlags &= (~ANNOTFLAG_NOVIEW);
1581             dwFlags |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
1582           } else {
1583             dwFlags &= (~ANNOTFLAG_INVISIBLE);
1584             dwFlags &= (~ANNOTFLAG_HIDDEN);
1585             dwFlags &= (~ANNOTFLAG_NOVIEW);
1586             dwFlags |= ANNOTFLAG_PRINT;
1587           }
1588 
1589           if (dwFlags != pWidget->GetFlags()) {
1590             pWidget->SetFlags(dwFlags);
1591             UpdateFormControl(pDocument, pFormControl, TRUE, FALSE, TRUE);
1592           }
1593         }
1594       }
1595     }
1596   }
1597 }
1598 
highlight(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)1599 FX_BOOL Field::highlight(IJS_Context* cc,
1600                          CJS_PropValue& vp,
1601                          CFX_WideString& sError) {
1602   ASSERT(m_pDocument);
1603 
1604   if (vp.IsSetting()) {
1605     if (!m_bCanSet)
1606       return FALSE;
1607 
1608     CFX_ByteString strMode;
1609     vp >> strMode;
1610 
1611     if (m_bDelay) {
1612       AddDelay_String(FP_HIGHLIGHT, strMode);
1613     } else {
1614       Field::SetHighlight(m_pDocument, m_FieldName, m_nFormControlIndex,
1615                           strMode);
1616     }
1617   } else {
1618     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1619     if (FieldArray.empty())
1620       return FALSE;
1621 
1622     CPDF_FormField* pFormField = FieldArray[0];
1623     if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
1624       return FALSE;
1625 
1626     CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1627     if (!pFormControl)
1628       return FALSE;
1629 
1630     int eHM = pFormControl->GetHighlightingMode();
1631     switch (eHM) {
1632       case CPDF_FormControl::None:
1633         vp << L"none";
1634         break;
1635       case CPDF_FormControl::Push:
1636         vp << L"push";
1637         break;
1638       case CPDF_FormControl::Invert:
1639         vp << L"invert";
1640         break;
1641       case CPDF_FormControl::Outline:
1642         vp << L"outline";
1643         break;
1644       case CPDF_FormControl::Toggle:
1645         vp << L"toggle";
1646         break;
1647     }
1648   }
1649 
1650   return TRUE;
1651 }
1652 
SetHighlight(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,const CFX_ByteString & string)1653 void Field::SetHighlight(CPDFSDK_Document* pDocument,
1654                          const CFX_WideString& swFieldName,
1655                          int nControlIndex,
1656                          const CFX_ByteString& string) {
1657   // Not supported.
1658 }
1659 
lineWidth(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)1660 FX_BOOL Field::lineWidth(IJS_Context* cc,
1661                          CJS_PropValue& vp,
1662                          CFX_WideString& sError) {
1663   if (vp.IsSetting()) {
1664     if (!m_bCanSet)
1665       return FALSE;
1666 
1667     int iWidth;
1668     vp >> iWidth;
1669 
1670     if (m_bDelay) {
1671       AddDelay_Int(FP_LINEWIDTH, iWidth);
1672     } else {
1673       Field::SetLineWidth(m_pDocument, m_FieldName, m_nFormControlIndex,
1674                           iWidth);
1675     }
1676   } else {
1677     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1678     if (FieldArray.empty())
1679       return FALSE;
1680 
1681     CPDF_FormField* pFormField = FieldArray[0];
1682     ASSERT(pFormField);
1683     CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1684     if (!pFormControl)
1685       return FALSE;
1686 
1687     CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
1688     if (!pFormField->CountControls())
1689       return FALSE;
1690 
1691     CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
1692     if (!pWidget)
1693       return FALSE;
1694 
1695     vp << (int32_t)pWidget->GetBorderWidth();
1696   }
1697 
1698   return TRUE;
1699 }
1700 
SetLineWidth(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,int number)1701 void Field::SetLineWidth(CPDFSDK_Document* pDocument,
1702                          const CFX_WideString& swFieldName,
1703                          int nControlIndex,
1704                          int number) {
1705   CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm();
1706   std::vector<CPDF_FormField*> FieldArray =
1707       GetFormFields(pDocument, swFieldName);
1708   for (CPDF_FormField* pFormField : FieldArray) {
1709     if (nControlIndex < 0) {
1710       FX_BOOL bSet = FALSE;
1711       for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1712         CPDF_FormControl* pFormControl = pFormField->GetControl(i);
1713         ASSERT(pFormControl);
1714 
1715         if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1716           if (number != pWidget->GetBorderWidth()) {
1717             pWidget->SetBorderWidth(number);
1718             bSet = TRUE;
1719           }
1720         }
1721       }
1722       if (bSet)
1723         UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
1724     } else {
1725       if (nControlIndex >= pFormField->CountControls())
1726         return;
1727       if (CPDF_FormControl* pFormControl =
1728               pFormField->GetControl(nControlIndex)) {
1729         if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1730           if (number != pWidget->GetBorderWidth()) {
1731             pWidget->SetBorderWidth(number);
1732             UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
1733           }
1734         }
1735       }
1736     }
1737   }
1738 }
1739 
multiline(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)1740 FX_BOOL Field::multiline(IJS_Context* cc,
1741                          CJS_PropValue& vp,
1742                          CFX_WideString& sError) {
1743   ASSERT(m_pDocument);
1744 
1745   if (vp.IsSetting()) {
1746     if (!m_bCanSet)
1747       return FALSE;
1748 
1749     bool bVP;
1750     vp >> bVP;
1751 
1752     if (m_bDelay) {
1753       AddDelay_Bool(FP_MULTILINE, bVP);
1754     } else {
1755       Field::SetMultiline(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
1756     }
1757   } else {
1758     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1759     if (FieldArray.empty())
1760       return FALSE;
1761 
1762     CPDF_FormField* pFormField = FieldArray[0];
1763     if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1764       return FALSE;
1765 
1766     if (pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE)
1767       vp << true;
1768     else
1769       vp << false;
1770   }
1771 
1772   return TRUE;
1773 }
1774 
SetMultiline(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,bool b)1775 void Field::SetMultiline(CPDFSDK_Document* pDocument,
1776                          const CFX_WideString& swFieldName,
1777                          int nControlIndex,
1778                          bool b) {
1779   // Not supported.
1780 }
1781 
multipleSelection(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)1782 FX_BOOL Field::multipleSelection(IJS_Context* cc,
1783                                  CJS_PropValue& vp,
1784                                  CFX_WideString& sError) {
1785   ASSERT(m_pDocument);
1786 
1787   if (vp.IsSetting()) {
1788     if (!m_bCanSet)
1789       return FALSE;
1790 
1791     bool bVP;
1792     vp >> bVP;
1793 
1794     if (m_bDelay) {
1795       AddDelay_Bool(FP_MULTIPLESELECTION, bVP);
1796     } else {
1797       Field::SetMultipleSelection(m_pDocument, m_FieldName, m_nFormControlIndex,
1798                                   bVP);
1799     }
1800   } else {
1801     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1802     if (FieldArray.empty())
1803       return FALSE;
1804 
1805     CPDF_FormField* pFormField = FieldArray[0];
1806     if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
1807       return FALSE;
1808 
1809     if (pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT)
1810       vp << true;
1811     else
1812       vp << false;
1813   }
1814 
1815   return TRUE;
1816 }
1817 
SetMultipleSelection(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,bool b)1818 void Field::SetMultipleSelection(CPDFSDK_Document* pDocument,
1819                                  const CFX_WideString& swFieldName,
1820                                  int nControlIndex,
1821                                  bool b) {
1822   // Not supported.
1823 }
1824 
name(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)1825 FX_BOOL Field::name(IJS_Context* cc,
1826                     CJS_PropValue& vp,
1827                     CFX_WideString& sError) {
1828   if (!vp.IsGetting())
1829     return FALSE;
1830 
1831   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1832   if (FieldArray.empty())
1833     return FALSE;
1834 
1835   vp << m_FieldName;
1836 
1837   return TRUE;
1838 }
1839 
numItems(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)1840 FX_BOOL Field::numItems(IJS_Context* cc,
1841                         CJS_PropValue& vp,
1842                         CFX_WideString& sError) {
1843   if (!vp.IsGetting())
1844     return FALSE;
1845 
1846   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1847   if (FieldArray.empty())
1848     return FALSE;
1849 
1850   CPDF_FormField* pFormField = FieldArray[0];
1851   if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
1852       pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
1853     return FALSE;
1854   }
1855 
1856   vp << (int32_t)pFormField->CountOptions();
1857   return TRUE;
1858 }
1859 
page(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)1860 FX_BOOL Field::page(IJS_Context* cc,
1861                     CJS_PropValue& vp,
1862                     CFX_WideString& sError) {
1863   if (!vp.IsGetting())
1864     return FALSE;
1865 
1866   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1867   if (FieldArray.empty())
1868     return FALSE;
1869 
1870   CPDF_FormField* pFormField = FieldArray[0];
1871   if (!pFormField)
1872     return FALSE;
1873 
1874   std::vector<CPDFSDK_Widget*> widgets;
1875   m_pDocument->GetInterForm()->GetWidgets(pFormField, &widgets);
1876 
1877   if (widgets.empty()) {
1878     vp << (int32_t)-1;
1879     return TRUE;
1880   }
1881 
1882   CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
1883   CJS_Array PageArray(pRuntime);
1884   for (size_t i = 0; i < widgets.size(); ++i) {
1885     CPDFSDK_PageView* pPageView = widgets[i]->GetPageView();
1886     if (!pPageView)
1887       return FALSE;
1888 
1889     PageArray.SetElement(
1890         i, CJS_Value(pRuntime, (int32_t)pPageView->GetPageIndex()));
1891   }
1892 
1893   vp << PageArray;
1894   return TRUE;
1895 }
1896 
password(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)1897 FX_BOOL Field::password(IJS_Context* cc,
1898                         CJS_PropValue& vp,
1899                         CFX_WideString& sError) {
1900   ASSERT(m_pDocument);
1901 
1902   if (vp.IsSetting()) {
1903     if (!m_bCanSet)
1904       return FALSE;
1905 
1906     bool bVP;
1907     vp >> bVP;
1908 
1909     if (m_bDelay) {
1910       AddDelay_Bool(FP_PASSWORD, bVP);
1911     } else {
1912       Field::SetPassword(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
1913     }
1914   } else {
1915     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1916     if (FieldArray.empty())
1917       return FALSE;
1918 
1919     CPDF_FormField* pFormField = FieldArray[0];
1920     if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1921       return FALSE;
1922 
1923     if (pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD)
1924       vp << true;
1925     else
1926       vp << false;
1927   }
1928 
1929   return TRUE;
1930 }
1931 
SetPassword(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,bool b)1932 void Field::SetPassword(CPDFSDK_Document* pDocument,
1933                         const CFX_WideString& swFieldName,
1934                         int nControlIndex,
1935                         bool b) {
1936   // Not supported.
1937 }
1938 
print(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)1939 FX_BOOL Field::print(IJS_Context* cc,
1940                      CJS_PropValue& vp,
1941                      CFX_WideString& sError) {
1942   CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
1943   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1944   if (FieldArray.empty())
1945     return FALSE;
1946 
1947   if (vp.IsSetting()) {
1948     if (!m_bCanSet)
1949       return FALSE;
1950 
1951     bool bVP;
1952     vp >> bVP;
1953 
1954     for (CPDF_FormField* pFormField : FieldArray) {
1955       if (m_nFormControlIndex < 0) {
1956         FX_BOOL bSet = FALSE;
1957         for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1958           if (CPDFSDK_Widget* pWidget =
1959                   pInterForm->GetWidget(pFormField->GetControl(i))) {
1960             uint32_t dwFlags = pWidget->GetFlags();
1961             if (bVP)
1962               dwFlags |= ANNOTFLAG_PRINT;
1963             else
1964               dwFlags &= ~ANNOTFLAG_PRINT;
1965 
1966             if (dwFlags != pWidget->GetFlags()) {
1967               pWidget->SetFlags(dwFlags);
1968               bSet = TRUE;
1969             }
1970           }
1971         }
1972 
1973         if (bSet)
1974           UpdateFormField(m_pDocument, pFormField, TRUE, FALSE, TRUE);
1975       } else {
1976         if (m_nFormControlIndex >= pFormField->CountControls())
1977           return FALSE;
1978         if (CPDF_FormControl* pFormControl =
1979                 pFormField->GetControl(m_nFormControlIndex)) {
1980           if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1981             uint32_t dwFlags = pWidget->GetFlags();
1982             if (bVP)
1983               dwFlags |= ANNOTFLAG_PRINT;
1984             else
1985               dwFlags &= ~ANNOTFLAG_PRINT;
1986 
1987             if (dwFlags != pWidget->GetFlags()) {
1988               pWidget->SetFlags(dwFlags);
1989               UpdateFormControl(m_pDocument,
1990                                 pFormField->GetControl(m_nFormControlIndex),
1991                                 TRUE, FALSE, TRUE);
1992             }
1993           }
1994         }
1995       }
1996     }
1997   } else {
1998     CPDF_FormField* pFormField = FieldArray[0];
1999     CPDFSDK_Widget* pWidget =
2000         pInterForm->GetWidget(GetSmartFieldControl(pFormField));
2001     if (!pWidget)
2002       return FALSE;
2003 
2004     if (pWidget->GetFlags() & ANNOTFLAG_PRINT)
2005       vp << true;
2006     else
2007       vp << false;
2008   }
2009 
2010   return TRUE;
2011 }
2012 
radiosInUnison(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)2013 FX_BOOL Field::radiosInUnison(IJS_Context* cc,
2014                               CJS_PropValue& vp,
2015                               CFX_WideString& sError) {
2016   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2017   if (FieldArray.empty())
2018     return FALSE;
2019 
2020   if (vp.IsSetting()) {
2021     if (!m_bCanSet)
2022       return FALSE;
2023 
2024     bool bVP;
2025     vp >> bVP;
2026 
2027   } else {
2028     CPDF_FormField* pFormField = FieldArray[0];
2029     if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
2030       return FALSE;
2031 
2032     if (pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)
2033       vp << true;
2034     else
2035       vp << false;
2036   }
2037 
2038   return TRUE;
2039 }
2040 
readonly(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)2041 FX_BOOL Field::readonly(IJS_Context* cc,
2042                         CJS_PropValue& vp,
2043                         CFX_WideString& sError) {
2044   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2045   if (FieldArray.empty())
2046     return FALSE;
2047 
2048   if (vp.IsSetting()) {
2049     if (!m_bCanSet)
2050       return FALSE;
2051 
2052     bool bVP;
2053     vp >> bVP;
2054 
2055   } else {
2056     CPDF_FormField* pFormField = FieldArray[0];
2057     if (pFormField->GetFieldFlags() & FIELDFLAG_READONLY)
2058       vp << true;
2059     else
2060       vp << false;
2061   }
2062 
2063   return TRUE;
2064 }
2065 
rect(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)2066 FX_BOOL Field::rect(IJS_Context* cc,
2067                     CJS_PropValue& vp,
2068                     CFX_WideString& sError) {
2069   CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
2070   CJS_Value Upper_Leftx(pRuntime);
2071   CJS_Value Upper_Lefty(pRuntime);
2072   CJS_Value Lower_Rightx(pRuntime);
2073   CJS_Value Lower_Righty(pRuntime);
2074 
2075   if (vp.IsSetting()) {
2076     if (!m_bCanSet)
2077       return FALSE;
2078     if (!vp.IsArrayObject())
2079       return FALSE;
2080 
2081     CJS_Array rcArray(pRuntime);
2082     vp >> rcArray;
2083     rcArray.GetElement(0, Upper_Leftx);
2084     rcArray.GetElement(1, Upper_Lefty);
2085     rcArray.GetElement(2, Lower_Rightx);
2086     rcArray.GetElement(3, Lower_Righty);
2087 
2088     FX_FLOAT pArray[4] = {0.0f, 0.0f, 0.0f, 0.0f};
2089     pArray[0] = (FX_FLOAT)Upper_Leftx.ToInt();
2090     pArray[1] = (FX_FLOAT)Lower_Righty.ToInt();
2091     pArray[2] = (FX_FLOAT)Lower_Rightx.ToInt();
2092     pArray[3] = (FX_FLOAT)Upper_Lefty.ToInt();
2093 
2094     CFX_FloatRect crRect(pArray);
2095     if (m_bDelay) {
2096       AddDelay_Rect(FP_RECT, crRect);
2097     } else {
2098       Field::SetRect(m_pDocument, m_FieldName, m_nFormControlIndex, crRect);
2099     }
2100   } else {
2101     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2102     if (FieldArray.empty())
2103       return FALSE;
2104 
2105     CPDF_FormField* pFormField = FieldArray[0];
2106     CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
2107     CPDFSDK_Widget* pWidget =
2108         pInterForm->GetWidget(GetSmartFieldControl(pFormField));
2109     if (!pWidget)
2110       return FALSE;
2111 
2112     CFX_FloatRect crRect = pWidget->GetRect();
2113     Upper_Leftx = (int32_t)crRect.left;
2114     Upper_Lefty = (int32_t)crRect.top;
2115     Lower_Rightx = (int32_t)crRect.right;
2116     Lower_Righty = (int32_t)crRect.bottom;
2117 
2118     CJS_Array rcArray(pRuntime);
2119     rcArray.SetElement(0, Upper_Leftx);
2120     rcArray.SetElement(1, Upper_Lefty);
2121     rcArray.SetElement(2, Lower_Rightx);
2122     rcArray.SetElement(3, Lower_Righty);
2123     vp << rcArray;
2124   }
2125   return TRUE;
2126 }
2127 
SetRect(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,const CFX_FloatRect & rect)2128 void Field::SetRect(CPDFSDK_Document* pDocument,
2129                     const CFX_WideString& swFieldName,
2130                     int nControlIndex,
2131                     const CFX_FloatRect& rect) {
2132   CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm();
2133   std::vector<CPDF_FormField*> FieldArray =
2134       GetFormFields(pDocument, swFieldName);
2135   for (CPDF_FormField* pFormField : FieldArray) {
2136     if (nControlIndex < 0) {
2137       FX_BOOL bSet = FALSE;
2138       for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
2139         CPDF_FormControl* pFormControl = pFormField->GetControl(i);
2140         ASSERT(pFormControl);
2141 
2142         if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
2143           CFX_FloatRect crRect = rect;
2144 
2145           CPDF_Page* pPDFPage = pWidget->GetPDFPage();
2146           crRect.Intersect(pPDFPage->GetPageBBox());
2147 
2148           if (!crRect.IsEmpty()) {
2149             CFX_FloatRect rcOld = pWidget->GetRect();
2150             if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
2151                 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
2152               pWidget->SetRect(crRect);
2153               bSet = TRUE;
2154             }
2155           }
2156         }
2157       }
2158 
2159       if (bSet)
2160         UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
2161     } else {
2162       if (nControlIndex >= pFormField->CountControls())
2163         return;
2164       if (CPDF_FormControl* pFormControl =
2165               pFormField->GetControl(nControlIndex)) {
2166         if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
2167           CFX_FloatRect crRect = rect;
2168 
2169           CPDF_Page* pPDFPage = pWidget->GetPDFPage();
2170           crRect.Intersect(pPDFPage->GetPageBBox());
2171 
2172           if (!crRect.IsEmpty()) {
2173             CFX_FloatRect rcOld = pWidget->GetRect();
2174             if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
2175                 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
2176               pWidget->SetRect(crRect);
2177               UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
2178             }
2179           }
2180         }
2181       }
2182     }
2183   }
2184 }
2185 
required(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)2186 FX_BOOL Field::required(IJS_Context* cc,
2187                         CJS_PropValue& vp,
2188                         CFX_WideString& sError) {
2189   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2190   if (FieldArray.empty())
2191     return FALSE;
2192 
2193   if (vp.IsSetting()) {
2194     if (!m_bCanSet)
2195       return FALSE;
2196 
2197     bool bVP;
2198     vp >> bVP;
2199 
2200   } else {
2201     CPDF_FormField* pFormField = FieldArray[0];
2202     if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
2203       return FALSE;
2204 
2205     if (pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED)
2206       vp << true;
2207     else
2208       vp << false;
2209   }
2210 
2211   return TRUE;
2212 }
2213 
richText(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)2214 FX_BOOL Field::richText(IJS_Context* cc,
2215                         CJS_PropValue& vp,
2216                         CFX_WideString& sError) {
2217   ASSERT(m_pDocument);
2218 
2219   if (vp.IsSetting()) {
2220     if (!m_bCanSet)
2221       return FALSE;
2222 
2223     bool bVP;
2224     vp >> bVP;
2225 
2226     if (m_bDelay) {
2227       AddDelay_Bool(FP_RICHTEXT, bVP);
2228     }
2229   } else {
2230     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2231     if (FieldArray.empty())
2232       return FALSE;
2233 
2234     CPDF_FormField* pFormField = FieldArray[0];
2235     if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
2236       return FALSE;
2237 
2238     if (pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT)
2239       vp << true;
2240     else
2241       vp << false;
2242   }
2243 
2244   return TRUE;
2245 }
2246 
richValue(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)2247 FX_BOOL Field::richValue(IJS_Context* cc,
2248                          CJS_PropValue& vp,
2249                          CFX_WideString& sError) {
2250   return TRUE;
2251 }
2252 
rotation(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)2253 FX_BOOL Field::rotation(IJS_Context* cc,
2254                         CJS_PropValue& vp,
2255                         CFX_WideString& sError) {
2256   ASSERT(m_pDocument);
2257 
2258   if (vp.IsSetting()) {
2259     if (!m_bCanSet)
2260       return FALSE;
2261 
2262     int nVP;
2263     vp >> nVP;
2264 
2265     if (m_bDelay) {
2266       AddDelay_Int(FP_ROTATION, nVP);
2267     } else {
2268       Field::SetRotation(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
2269     }
2270   } else {
2271     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2272     if (FieldArray.empty())
2273       return FALSE;
2274 
2275     CPDF_FormField* pFormField = FieldArray[0];
2276     CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2277     if (!pFormControl)
2278       return FALSE;
2279 
2280     vp << (int32_t)pFormControl->GetRotation();
2281   }
2282 
2283   return TRUE;
2284 }
2285 
SetRotation(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,int number)2286 void Field::SetRotation(CPDFSDK_Document* pDocument,
2287                         const CFX_WideString& swFieldName,
2288                         int nControlIndex,
2289                         int number) {
2290   // Not supported.
2291 }
2292 
strokeColor(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)2293 FX_BOOL Field::strokeColor(IJS_Context* cc,
2294                            CJS_PropValue& vp,
2295                            CFX_WideString& sError) {
2296   CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
2297   CJS_Array crArray(pRuntime);
2298 
2299   if (vp.IsSetting()) {
2300     if (!m_bCanSet)
2301       return FALSE;
2302 
2303     if (!vp.IsArrayObject())
2304       return FALSE;
2305 
2306     vp >> crArray;
2307 
2308     CPWL_Color color;
2309     color::ConvertArrayToPWLColor(crArray, color);
2310 
2311     if (m_bDelay) {
2312       AddDelay_Color(FP_STROKECOLOR, color);
2313     } else {
2314       Field::SetStrokeColor(m_pDocument, m_FieldName, m_nFormControlIndex,
2315                             color);
2316     }
2317   } else {
2318     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2319     if (FieldArray.empty())
2320       return FALSE;
2321 
2322     CPDF_FormField* pFormField = FieldArray[0];
2323     CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2324     if (!pFormControl)
2325       return FALSE;
2326 
2327     int iColorType;
2328     pFormControl->GetBorderColor(iColorType);
2329 
2330     CPWL_Color color;
2331     if (iColorType == COLORTYPE_TRANSPARENT) {
2332       color = CPWL_Color(COLORTYPE_TRANSPARENT);
2333     } else if (iColorType == COLORTYPE_GRAY) {
2334       color =
2335           CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBorderColor(0));
2336     } else if (iColorType == COLORTYPE_RGB) {
2337       color = CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBorderColor(0),
2338                          pFormControl->GetOriginalBorderColor(1),
2339                          pFormControl->GetOriginalBorderColor(2));
2340     } else if (iColorType == COLORTYPE_CMYK) {
2341       color =
2342           CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBorderColor(0),
2343                      pFormControl->GetOriginalBorderColor(1),
2344                      pFormControl->GetOriginalBorderColor(2),
2345                      pFormControl->GetOriginalBorderColor(3));
2346     } else {
2347       return FALSE;
2348     }
2349 
2350     color::ConvertPWLColorToArray(color, crArray);
2351     vp << crArray;
2352   }
2353   return TRUE;
2354 }
2355 
SetStrokeColor(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,const CPWL_Color & color)2356 void Field::SetStrokeColor(CPDFSDK_Document* pDocument,
2357                            const CFX_WideString& swFieldName,
2358                            int nControlIndex,
2359                            const CPWL_Color& color) {
2360   // Not supported.
2361 }
2362 
style(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)2363 FX_BOOL Field::style(IJS_Context* cc,
2364                      CJS_PropValue& vp,
2365                      CFX_WideString& sError) {
2366   ASSERT(m_pDocument);
2367 
2368   if (vp.IsSetting()) {
2369     if (!m_bCanSet)
2370       return FALSE;
2371 
2372     CFX_ByteString csBCaption;
2373     vp >> csBCaption;
2374 
2375     if (m_bDelay) {
2376       AddDelay_String(FP_STYLE, csBCaption);
2377     } else {
2378       Field::SetStyle(m_pDocument, m_FieldName, m_nFormControlIndex,
2379                       csBCaption);
2380     }
2381   } else {
2382     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2383     if (FieldArray.empty())
2384       return FALSE;
2385 
2386     CPDF_FormField* pFormField = FieldArray[0];
2387     if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON &&
2388         pFormField->GetFieldType() != FIELDTYPE_CHECKBOX) {
2389       return FALSE;
2390     }
2391 
2392     CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2393     if (!pFormControl)
2394       return FALSE;
2395 
2396     CFX_WideString csWCaption = pFormControl->GetNormalCaption();
2397     CFX_ByteString csBCaption;
2398 
2399     switch (csWCaption[0]) {
2400       case L'l':
2401         csBCaption = "circle";
2402         break;
2403       case L'8':
2404         csBCaption = "cross";
2405         break;
2406       case L'u':
2407         csBCaption = "diamond";
2408         break;
2409       case L'n':
2410         csBCaption = "square";
2411         break;
2412       case L'H':
2413         csBCaption = "star";
2414         break;
2415       default:  // L'4'
2416         csBCaption = "check";
2417         break;
2418     }
2419     vp << csBCaption;
2420   }
2421 
2422   return TRUE;
2423 }
2424 
SetStyle(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,const CFX_ByteString & string)2425 void Field::SetStyle(CPDFSDK_Document* pDocument,
2426                      const CFX_WideString& swFieldName,
2427                      int nControlIndex,
2428                      const CFX_ByteString& string) {
2429   // Not supported.
2430 }
2431 
submitName(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)2432 FX_BOOL Field::submitName(IJS_Context* cc,
2433                           CJS_PropValue& vp,
2434                           CFX_WideString& sError) {
2435   return TRUE;
2436 }
2437 
textColor(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)2438 FX_BOOL Field::textColor(IJS_Context* cc,
2439                          CJS_PropValue& vp,
2440                          CFX_WideString& sError) {
2441   CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
2442   CJS_Array crArray(pRuntime);
2443 
2444   if (vp.IsSetting()) {
2445     if (!m_bCanSet)
2446       return FALSE;
2447 
2448     if (!vp.IsArrayObject())
2449       return FALSE;
2450 
2451     vp >> crArray;
2452 
2453     CPWL_Color color;
2454     color::ConvertArrayToPWLColor(crArray, color);
2455 
2456     if (m_bDelay) {
2457       AddDelay_Color(FP_TEXTCOLOR, color);
2458     } else {
2459       Field::SetTextColor(m_pDocument, m_FieldName, m_nFormControlIndex, color);
2460     }
2461   } else {
2462     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2463     if (FieldArray.empty())
2464       return FALSE;
2465 
2466     CPDF_FormField* pFormField = FieldArray[0];
2467     CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2468     if (!pFormControl)
2469       return FALSE;
2470 
2471     int iColorType;
2472     FX_ARGB color;
2473     CPDF_DefaultAppearance FieldAppearance =
2474         pFormControl->GetDefaultAppearance();
2475     FieldAppearance.GetColor(color, iColorType);
2476     int32_t a, r, g, b;
2477     ArgbDecode(color, a, r, g, b);
2478 
2479     CPWL_Color crRet =
2480         CPWL_Color(COLORTYPE_RGB, r / 255.0f, g / 255.0f, b / 255.0f);
2481 
2482     if (iColorType == COLORTYPE_TRANSPARENT)
2483       crRet = CPWL_Color(COLORTYPE_TRANSPARENT);
2484 
2485     color::ConvertPWLColorToArray(crRet, crArray);
2486     vp << crArray;
2487   }
2488   return TRUE;
2489 }
2490 
SetTextColor(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,const CPWL_Color & color)2491 void Field::SetTextColor(CPDFSDK_Document* pDocument,
2492                          const CFX_WideString& swFieldName,
2493                          int nControlIndex,
2494                          const CPWL_Color& color) {
2495   // Not supported.
2496 }
2497 
textFont(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)2498 FX_BOOL Field::textFont(IJS_Context* cc,
2499                         CJS_PropValue& vp,
2500                         CFX_WideString& sError) {
2501   ASSERT(m_pDocument);
2502 
2503   if (vp.IsSetting()) {
2504     if (!m_bCanSet)
2505       return FALSE;
2506 
2507     CFX_ByteString csFontName;
2508     vp >> csFontName;
2509     if (csFontName.IsEmpty())
2510       return FALSE;
2511 
2512     if (m_bDelay) {
2513       AddDelay_String(FP_TEXTFONT, csFontName);
2514     } else {
2515       Field::SetTextFont(m_pDocument, m_FieldName, m_nFormControlIndex,
2516                          csFontName);
2517     }
2518   } else {
2519     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2520     if (FieldArray.empty())
2521       return FALSE;
2522 
2523     CPDF_FormField* pFormField = FieldArray[0];
2524     ASSERT(pFormField);
2525     CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2526     if (!pFormControl)
2527       return FALSE;
2528 
2529     int nFieldType = pFormField->GetFieldType();
2530 
2531     if (nFieldType == FIELDTYPE_PUSHBUTTON ||
2532         nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX ||
2533         nFieldType == FIELDTYPE_TEXTFIELD) {
2534       CPDF_Font* pFont = pFormControl->GetDefaultControlFont();
2535       if (!pFont)
2536         return FALSE;
2537 
2538       vp << pFont->GetBaseFont();
2539     } else {
2540       return FALSE;
2541     }
2542   }
2543 
2544   return TRUE;
2545 }
2546 
SetTextFont(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,const CFX_ByteString & string)2547 void Field::SetTextFont(CPDFSDK_Document* pDocument,
2548                         const CFX_WideString& swFieldName,
2549                         int nControlIndex,
2550                         const CFX_ByteString& string) {
2551   // Not supported.
2552 }
2553 
textSize(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)2554 FX_BOOL Field::textSize(IJS_Context* cc,
2555                         CJS_PropValue& vp,
2556                         CFX_WideString& sError) {
2557   ASSERT(m_pDocument);
2558 
2559   if (vp.IsSetting()) {
2560     if (!m_bCanSet)
2561       return FALSE;
2562 
2563     int nVP;
2564     vp >> nVP;
2565 
2566     if (m_bDelay) {
2567       AddDelay_Int(FP_TEXTSIZE, nVP);
2568     } else {
2569       Field::SetTextSize(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
2570     }
2571   } else {
2572     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2573     if (FieldArray.empty())
2574       return FALSE;
2575 
2576     CPDF_FormField* pFormField = FieldArray[0];
2577     ASSERT(pFormField);
2578     CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2579     if (!pFormControl)
2580       return FALSE;
2581 
2582     CPDF_DefaultAppearance FieldAppearance =
2583         pFormControl->GetDefaultAppearance();
2584 
2585     CFX_ByteString csFontNameTag;
2586     FX_FLOAT fFontSize;
2587     FieldAppearance.GetFont(csFontNameTag, fFontSize);
2588 
2589     vp << (int)fFontSize;
2590   }
2591 
2592   return TRUE;
2593 }
2594 
SetTextSize(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,int number)2595 void Field::SetTextSize(CPDFSDK_Document* pDocument,
2596                         const CFX_WideString& swFieldName,
2597                         int nControlIndex,
2598                         int number) {
2599   // Not supported.
2600 }
2601 
type(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)2602 FX_BOOL Field::type(IJS_Context* cc,
2603                     CJS_PropValue& vp,
2604                     CFX_WideString& sError) {
2605   if (!vp.IsGetting())
2606     return FALSE;
2607 
2608   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2609   if (FieldArray.empty())
2610     return FALSE;
2611 
2612   CPDF_FormField* pFormField = FieldArray[0];
2613   switch (pFormField->GetFieldType()) {
2614     case FIELDTYPE_UNKNOWN:
2615       vp << L"unknown";
2616       break;
2617     case FIELDTYPE_PUSHBUTTON:
2618       vp << L"button";
2619       break;
2620     case FIELDTYPE_CHECKBOX:
2621       vp << L"checkbox";
2622       break;
2623     case FIELDTYPE_RADIOBUTTON:
2624       vp << L"radiobutton";
2625       break;
2626     case FIELDTYPE_COMBOBOX:
2627       vp << L"combobox";
2628       break;
2629     case FIELDTYPE_LISTBOX:
2630       vp << L"listbox";
2631       break;
2632     case FIELDTYPE_TEXTFIELD:
2633       vp << L"text";
2634       break;
2635     case FIELDTYPE_SIGNATURE:
2636       vp << L"signature";
2637       break;
2638     default:
2639       vp << L"unknown";
2640       break;
2641   }
2642 
2643   return TRUE;
2644 }
2645 
userName(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)2646 FX_BOOL Field::userName(IJS_Context* cc,
2647                         CJS_PropValue& vp,
2648                         CFX_WideString& sError) {
2649   ASSERT(m_pDocument);
2650 
2651   if (vp.IsSetting()) {
2652     if (!m_bCanSet)
2653       return FALSE;
2654 
2655     CFX_WideString swName;
2656     vp >> swName;
2657 
2658     if (m_bDelay) {
2659       AddDelay_WideString(FP_USERNAME, swName);
2660     } else {
2661       Field::SetUserName(m_pDocument, m_FieldName, m_nFormControlIndex, swName);
2662     }
2663   } else {
2664     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2665     if (FieldArray.empty())
2666       return FALSE;
2667 
2668     CPDF_FormField* pFormField = FieldArray[0];
2669     vp << (CFX_WideString)pFormField->GetAlternateName();
2670   }
2671 
2672   return TRUE;
2673 }
2674 
SetUserName(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,const CFX_WideString & string)2675 void Field::SetUserName(CPDFSDK_Document* pDocument,
2676                         const CFX_WideString& swFieldName,
2677                         int nControlIndex,
2678                         const CFX_WideString& string) {
2679   // Not supported.
2680 }
2681 
value(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)2682 FX_BOOL Field::value(IJS_Context* cc,
2683                      CJS_PropValue& vp,
2684                      CFX_WideString& sError) {
2685   CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
2686 
2687   if (vp.IsSetting()) {
2688     if (!m_bCanSet)
2689       return FALSE;
2690 
2691     std::vector<CFX_WideString> strArray;
2692     if (vp.IsArrayObject()) {
2693       CJS_Array ValueArray(pRuntime);
2694       vp.ConvertToArray(ValueArray);
2695       for (int i = 0, sz = ValueArray.GetLength(); i < sz; i++) {
2696         CJS_Value ElementValue(pRuntime);
2697         ValueArray.GetElement(i, ElementValue);
2698         strArray.push_back(ElementValue.ToCFXWideString());
2699       }
2700     } else {
2701       CFX_WideString swValue;
2702       vp >> swValue;
2703       strArray.push_back(swValue);
2704     }
2705 
2706     if (m_bDelay) {
2707       AddDelay_WideStringArray(FP_VALUE, strArray);
2708     } else {
2709       Field::SetValue(m_pDocument, m_FieldName, m_nFormControlIndex, strArray);
2710     }
2711   } else {
2712     std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2713     if (FieldArray.empty())
2714       return FALSE;
2715 
2716     CPDF_FormField* pFormField = FieldArray[0];
2717     switch (pFormField->GetFieldType()) {
2718       case FIELDTYPE_PUSHBUTTON:
2719         return FALSE;
2720       case FIELDTYPE_COMBOBOX:
2721       case FIELDTYPE_TEXTFIELD: {
2722         vp << pFormField->GetValue();
2723       } break;
2724       case FIELDTYPE_LISTBOX: {
2725         if (pFormField->CountSelectedItems() > 1) {
2726           CJS_Array ValueArray(pRuntime);
2727           CJS_Value ElementValue(pRuntime);
2728           int iIndex;
2729           for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
2730             iIndex = pFormField->GetSelectedIndex(i);
2731             ElementValue = pFormField->GetOptionValue(iIndex).c_str();
2732             if (FXSYS_wcslen(ElementValue.ToCFXWideString().c_str()) == 0)
2733               ElementValue = pFormField->GetOptionLabel(iIndex).c_str();
2734             ValueArray.SetElement(i, ElementValue);
2735           }
2736           vp << ValueArray;
2737         } else {
2738           vp << pFormField->GetValue();
2739         }
2740       } break;
2741       case FIELDTYPE_CHECKBOX:
2742       case FIELDTYPE_RADIOBUTTON: {
2743         bool bFind = false;
2744         for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2745           if (pFormField->GetControl(i)->IsChecked()) {
2746             vp << pFormField->GetControl(i)->GetExportValue();
2747             bFind = true;
2748             break;
2749           }
2750         }
2751         if (!bFind)
2752           vp << L"Off";
2753       } break;
2754       default:
2755         vp << pFormField->GetValue();
2756         break;
2757     }
2758   }
2759   vp.MaybeCoerceToNumber();
2760   return TRUE;
2761 }
2762 
SetValue(CPDFSDK_Document * pDocument,const CFX_WideString & swFieldName,int nControlIndex,const std::vector<CFX_WideString> & strArray)2763 void Field::SetValue(CPDFSDK_Document* pDocument,
2764                      const CFX_WideString& swFieldName,
2765                      int nControlIndex,
2766                      const std::vector<CFX_WideString>& strArray) {
2767   ASSERT(pDocument);
2768   if (strArray.empty())
2769     return;
2770 
2771   std::vector<CPDF_FormField*> FieldArray =
2772       GetFormFields(pDocument, swFieldName);
2773 
2774   for (CPDF_FormField* pFormField : FieldArray) {
2775     if (pFormField->GetFullName().Compare(swFieldName) != 0)
2776       continue;
2777 
2778     switch (pFormField->GetFieldType()) {
2779       case FIELDTYPE_TEXTFIELD:
2780       case FIELDTYPE_COMBOBOX:
2781         if (pFormField->GetValue() != strArray[0]) {
2782           pFormField->SetValue(strArray[0], TRUE);
2783           UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
2784         }
2785         break;
2786       case FIELDTYPE_CHECKBOX:
2787       case FIELDTYPE_RADIOBUTTON: {
2788         if (pFormField->GetValue() != strArray[0]) {
2789           pFormField->SetValue(strArray[0], TRUE);
2790           UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
2791         }
2792       } break;
2793       case FIELDTYPE_LISTBOX: {
2794         FX_BOOL bModified = FALSE;
2795         for (const auto& str : strArray) {
2796           if (!pFormField->IsItemSelected(pFormField->FindOption(str))) {
2797             bModified = TRUE;
2798             break;
2799           }
2800         }
2801         if (bModified) {
2802           pFormField->ClearSelection(TRUE);
2803           for (const auto& str : strArray) {
2804             int index = pFormField->FindOption(str);
2805             if (!pFormField->IsItemSelected(index))
2806               pFormField->SetItemSelection(index, TRUE, TRUE);
2807           }
2808           UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
2809         }
2810       } break;
2811       default:
2812         break;
2813     }
2814   }
2815 }
2816 
valueAsString(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)2817 FX_BOOL Field::valueAsString(IJS_Context* cc,
2818                              CJS_PropValue& vp,
2819                              CFX_WideString& sError) {
2820   if (!vp.IsGetting())
2821     return FALSE;
2822 
2823   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2824   if (FieldArray.empty())
2825     return FALSE;
2826 
2827   CPDF_FormField* pFormField = FieldArray[0];
2828   if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
2829     return FALSE;
2830 
2831   if (pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) {
2832     if (!pFormField->CountControls())
2833       return FALSE;
2834 
2835     if (pFormField->GetControl(0)->IsChecked())
2836       vp << L"Yes";
2837     else
2838       vp << L"Off";
2839   } else if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON &&
2840              !(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)) {
2841     for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2842       if (pFormField->GetControl(i)->IsChecked()) {
2843         vp << pFormField->GetControl(i)->GetExportValue().c_str();
2844         break;
2845       } else {
2846         vp << L"Off";
2847       }
2848     }
2849   } else if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX &&
2850              (pFormField->CountSelectedItems() > 1)) {
2851     vp << L"";
2852   } else {
2853     vp << pFormField->GetValue().c_str();
2854   }
2855 
2856   return TRUE;
2857 }
2858 
browseForFileToSubmit(IJS_Context * cc,const std::vector<CJS_Value> & params,CJS_Value & vRet,CFX_WideString & sError)2859 FX_BOOL Field::browseForFileToSubmit(IJS_Context* cc,
2860                                      const std::vector<CJS_Value>& params,
2861                                      CJS_Value& vRet,
2862                                      CFX_WideString& sError) {
2863   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2864   if (FieldArray.empty())
2865     return FALSE;
2866 
2867   CPDF_FormField* pFormField = FieldArray[0];
2868   CPDFDoc_Environment* pApp = m_pDocument->GetEnv();
2869   if ((pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) &&
2870       (pFormField->GetFieldType() == FIELDTYPE_TEXTFIELD)) {
2871     CFX_WideString wsFileName = pApp->JS_fieldBrowse();
2872     if (!wsFileName.IsEmpty()) {
2873       pFormField->SetValue(wsFileName);
2874       UpdateFormField(m_pDocument, pFormField, TRUE, TRUE, TRUE);
2875     }
2876     return TRUE;
2877   }
2878   return FALSE;
2879 }
2880 
buttonGetCaption(IJS_Context * cc,const std::vector<CJS_Value> & params,CJS_Value & vRet,CFX_WideString & sError)2881 FX_BOOL Field::buttonGetCaption(IJS_Context* cc,
2882                                 const std::vector<CJS_Value>& params,
2883                                 CJS_Value& vRet,
2884                                 CFX_WideString& sError) {
2885   int nface = 0;
2886   int iSize = params.size();
2887   if (iSize >= 1)
2888     nface = params[0].ToInt();
2889 
2890   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2891   if (FieldArray.empty())
2892     return FALSE;
2893 
2894   CPDF_FormField* pFormField = FieldArray[0];
2895   if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
2896     return FALSE;
2897 
2898   CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2899   if (!pFormControl)
2900     return FALSE;
2901 
2902   if (nface == 0)
2903     vRet = pFormControl->GetNormalCaption().c_str();
2904   else if (nface == 1)
2905     vRet = pFormControl->GetDownCaption().c_str();
2906   else if (nface == 2)
2907     vRet = pFormControl->GetRolloverCaption().c_str();
2908   else
2909     return FALSE;
2910 
2911   return TRUE;
2912 }
2913 
buttonGetIcon(IJS_Context * cc,const std::vector<CJS_Value> & params,CJS_Value & vRet,CFX_WideString & sError)2914 FX_BOOL Field::buttonGetIcon(IJS_Context* cc,
2915                              const std::vector<CJS_Value>& params,
2916                              CJS_Value& vRet,
2917                              CFX_WideString& sError) {
2918   int nface = 0;
2919   int iSize = params.size();
2920   if (iSize >= 1)
2921     nface = params[0].ToInt();
2922 
2923   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2924   if (FieldArray.empty())
2925     return FALSE;
2926 
2927   CPDF_FormField* pFormField = FieldArray[0];
2928   if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
2929     return FALSE;
2930 
2931   CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2932   if (!pFormControl)
2933     return FALSE;
2934 
2935   CJS_Context* pContext = (CJS_Context*)cc;
2936   CJS_Runtime* pRuntime = pContext->GetJSRuntime();
2937   v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
2938       pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID);
2939   ASSERT(pObj.IsEmpty() == FALSE);
2940 
2941   CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
2942   Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
2943 
2944   CPDF_Stream* pIconStream = nullptr;
2945   if (nface == 0)
2946     pIconStream = pFormControl->GetNormalIcon();
2947   else if (nface == 1)
2948     pIconStream = pFormControl->GetDownIcon();
2949   else if (nface == 2)
2950     pIconStream = pFormControl->GetRolloverIcon();
2951   else
2952     return FALSE;
2953 
2954   pIcon->SetStream(pIconStream);
2955   vRet = pJS_Icon;
2956 
2957   return TRUE;
2958 }
2959 
buttonImportIcon(IJS_Context * cc,const std::vector<CJS_Value> & params,CJS_Value & vRet,CFX_WideString & sError)2960 FX_BOOL Field::buttonImportIcon(IJS_Context* cc,
2961                                 const std::vector<CJS_Value>& params,
2962                                 CJS_Value& vRet,
2963                                 CFX_WideString& sError) {
2964   return TRUE;
2965 }
2966 
buttonSetCaption(IJS_Context * cc,const std::vector<CJS_Value> & params,CJS_Value & vRet,CFX_WideString & sError)2967 FX_BOOL Field::buttonSetCaption(IJS_Context* cc,
2968                                 const std::vector<CJS_Value>& params,
2969                                 CJS_Value& vRet,
2970                                 CFX_WideString& sError) {
2971   return FALSE;
2972 }
2973 
buttonSetIcon(IJS_Context * cc,const std::vector<CJS_Value> & params,CJS_Value & vRet,CFX_WideString & sError)2974 FX_BOOL Field::buttonSetIcon(IJS_Context* cc,
2975                              const std::vector<CJS_Value>& params,
2976                              CJS_Value& vRet,
2977                              CFX_WideString& sError) {
2978   return FALSE;
2979 }
2980 
checkThisBox(IJS_Context * cc,const std::vector<CJS_Value> & params,CJS_Value & vRet,CFX_WideString & sError)2981 FX_BOOL Field::checkThisBox(IJS_Context* cc,
2982                             const std::vector<CJS_Value>& params,
2983                             CJS_Value& vRet,
2984                             CFX_WideString& sError) {
2985   ASSERT(m_pDocument);
2986 
2987   if (!m_bCanSet)
2988     return FALSE;
2989 
2990   int iSize = params.size();
2991   if (iSize < 1)
2992     return FALSE;
2993 
2994   int nWidget = params[0].ToInt();
2995 
2996   bool bCheckit = true;
2997   if (iSize >= 2)
2998     bCheckit = params[1].ToBool();
2999 
3000   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3001   if (FieldArray.empty())
3002     return FALSE;
3003 
3004   CPDF_FormField* pFormField = FieldArray[0];
3005   if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
3006       pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
3007     return FALSE;
3008   if (nWidget < 0 || nWidget >= pFormField->CountControls())
3009     return FALSE;
3010   // TODO(weili): Check whether anything special needed for radio button,
3011   // otherwise merge these branches.
3012   if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)
3013     pFormField->CheckControl(nWidget, bCheckit, true);
3014   else
3015     pFormField->CheckControl(nWidget, bCheckit, true);
3016 
3017   UpdateFormField(m_pDocument, pFormField, TRUE, TRUE, TRUE);
3018   return TRUE;
3019 }
3020 
clearItems(IJS_Context * cc,const std::vector<CJS_Value> & params,CJS_Value & vRet,CFX_WideString & sError)3021 FX_BOOL Field::clearItems(IJS_Context* cc,
3022                           const std::vector<CJS_Value>& params,
3023                           CJS_Value& vRet,
3024                           CFX_WideString& sError) {
3025   return TRUE;
3026 }
3027 
defaultIsChecked(IJS_Context * cc,const std::vector<CJS_Value> & params,CJS_Value & vRet,CFX_WideString & sError)3028 FX_BOOL Field::defaultIsChecked(IJS_Context* cc,
3029                                 const std::vector<CJS_Value>& params,
3030                                 CJS_Value& vRet,
3031                                 CFX_WideString& sError) {
3032   if (!m_bCanSet)
3033     return FALSE;
3034 
3035   int iSize = params.size();
3036   if (iSize < 1)
3037     return FALSE;
3038 
3039   int nWidget = params[0].ToInt();
3040 
3041   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3042   if (FieldArray.empty())
3043     return FALSE;
3044 
3045   CPDF_FormField* pFormField = FieldArray[0];
3046   if (nWidget < 0 || nWidget >= pFormField->CountControls()) {
3047     vRet = FALSE;
3048     return FALSE;
3049   }
3050   vRet = pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
3051          pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON;
3052 
3053   return TRUE;
3054 }
3055 
deleteItemAt(IJS_Context * cc,const std::vector<CJS_Value> & params,CJS_Value & vRet,CFX_WideString & sError)3056 FX_BOOL Field::deleteItemAt(IJS_Context* cc,
3057                             const std::vector<CJS_Value>& params,
3058                             CJS_Value& vRet,
3059                             CFX_WideString& sError) {
3060   return TRUE;
3061 }
3062 
getArray(IJS_Context * cc,const std::vector<CJS_Value> & params,CJS_Value & vRet,CFX_WideString & sError)3063 FX_BOOL Field::getArray(IJS_Context* cc,
3064                         const std::vector<CJS_Value>& params,
3065                         CJS_Value& vRet,
3066                         CFX_WideString& sError) {
3067   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3068   if (FieldArray.empty())
3069     return FALSE;
3070 
3071   std::vector<std::unique_ptr<CFX_WideString>> swSort;
3072   for (CPDF_FormField* pFormField : FieldArray) {
3073     swSort.push_back(std::unique_ptr<CFX_WideString>(
3074         new CFX_WideString(pFormField->GetFullName())));
3075   }
3076 
3077   std::sort(
3078       swSort.begin(), swSort.end(),
3079       [](const std::unique_ptr<CFX_WideString>& p1,
3080          const std::unique_ptr<CFX_WideString>& p2) { return *p1 < *p2; });
3081 
3082   CJS_Context* pContext = (CJS_Context*)cc;
3083   CJS_Runtime* pRuntime = pContext->GetJSRuntime();
3084   CJS_Array FormFieldArray(pRuntime);
3085 
3086   int j = 0;
3087   for (const auto& pStr : swSort) {
3088     v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
3089         pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID);
3090     ASSERT(!pObj.IsEmpty());
3091 
3092     CJS_Field* pJSField =
3093         static_cast<CJS_Field*>(FXJS_GetPrivate(pRuntime->GetIsolate(), pObj));
3094     Field* pField = static_cast<Field*>(pJSField->GetEmbedObject());
3095     pField->AttachField(m_pJSDoc, *pStr);
3096 
3097     CJS_Value FormFieldValue(pRuntime);
3098     FormFieldValue = pJSField;
3099     FormFieldArray.SetElement(j++, FormFieldValue);
3100   }
3101 
3102   vRet = FormFieldArray;
3103   return TRUE;
3104 }
3105 
getItemAt(IJS_Context * cc,const std::vector<CJS_Value> & params,CJS_Value & vRet,CFX_WideString & sError)3106 FX_BOOL Field::getItemAt(IJS_Context* cc,
3107                          const std::vector<CJS_Value>& params,
3108                          CJS_Value& vRet,
3109                          CFX_WideString& sError) {
3110   int iSize = params.size();
3111 
3112   int nIdx = -1;
3113   if (iSize >= 1)
3114     nIdx = params[0].ToInt();
3115 
3116   FX_BOOL bExport = TRUE;
3117   if (iSize >= 2)
3118     bExport = params[1].ToBool();
3119 
3120   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3121   if (FieldArray.empty())
3122     return FALSE;
3123 
3124   CPDF_FormField* pFormField = FieldArray[0];
3125   if ((pFormField->GetFieldType() == FIELDTYPE_LISTBOX) ||
3126       (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX)) {
3127     if (nIdx == -1 || nIdx > pFormField->CountOptions())
3128       nIdx = pFormField->CountOptions() - 1;
3129     if (bExport) {
3130       CFX_WideString strval = pFormField->GetOptionValue(nIdx);
3131       if (strval.IsEmpty())
3132         vRet = pFormField->GetOptionLabel(nIdx).c_str();
3133       else
3134         vRet = strval.c_str();
3135     } else {
3136       vRet = pFormField->GetOptionLabel(nIdx).c_str();
3137     }
3138   } else {
3139     return FALSE;
3140   }
3141 
3142   return TRUE;
3143 }
3144 
getLock(IJS_Context * cc,const std::vector<CJS_Value> & params,CJS_Value & vRet,CFX_WideString & sError)3145 FX_BOOL Field::getLock(IJS_Context* cc,
3146                        const std::vector<CJS_Value>& params,
3147                        CJS_Value& vRet,
3148                        CFX_WideString& sError) {
3149   return FALSE;
3150 }
3151 
insertItemAt(IJS_Context * cc,const std::vector<CJS_Value> & params,CJS_Value & vRet,CFX_WideString & sError)3152 FX_BOOL Field::insertItemAt(IJS_Context* cc,
3153                             const std::vector<CJS_Value>& params,
3154                             CJS_Value& vRet,
3155                             CFX_WideString& sError) {
3156   return TRUE;
3157 }
3158 
isBoxChecked(IJS_Context * cc,const std::vector<CJS_Value> & params,CJS_Value & vRet,CFX_WideString & sError)3159 FX_BOOL Field::isBoxChecked(IJS_Context* cc,
3160                             const std::vector<CJS_Value>& params,
3161                             CJS_Value& vRet,
3162                             CFX_WideString& sError) {
3163   int nIndex = -1;
3164   if (params.size() >= 1)
3165     nIndex = params[0].ToInt();
3166 
3167   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3168   if (FieldArray.empty())
3169     return FALSE;
3170 
3171   CPDF_FormField* pFormField = FieldArray[0];
3172   if (nIndex < 0 || nIndex >= pFormField->CountControls()) {
3173     vRet = FALSE;
3174     return FALSE;
3175   }
3176 
3177   if ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) ||
3178       (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)) {
3179     if (pFormField->GetControl(nIndex)->IsChecked() != 0)
3180       vRet = TRUE;
3181     else
3182       vRet = FALSE;
3183   } else {
3184     vRet = FALSE;
3185   }
3186 
3187   return TRUE;
3188 }
3189 
isDefaultChecked(IJS_Context * cc,const std::vector<CJS_Value> & params,CJS_Value & vRet,CFX_WideString & sError)3190 FX_BOOL Field::isDefaultChecked(IJS_Context* cc,
3191                                 const std::vector<CJS_Value>& params,
3192                                 CJS_Value& vRet,
3193                                 CFX_WideString& sError) {
3194   int nIndex = -1;
3195   if (params.size() >= 1)
3196     nIndex = params[0].ToInt();
3197 
3198   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3199   if (FieldArray.empty())
3200     return FALSE;
3201 
3202   CPDF_FormField* pFormField = FieldArray[0];
3203   if (nIndex < 0 || nIndex >= pFormField->CountControls()) {
3204     vRet = FALSE;
3205     return FALSE;
3206   }
3207   if ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) ||
3208       (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)) {
3209     if (pFormField->GetControl(nIndex)->IsDefaultChecked() != 0)
3210       vRet = TRUE;
3211     else
3212       vRet = FALSE;
3213   } else {
3214     vRet = FALSE;
3215   }
3216 
3217   return TRUE;
3218 }
3219 
setAction(IJS_Context * cc,const std::vector<CJS_Value> & params,CJS_Value & vRet,CFX_WideString & sError)3220 FX_BOOL Field::setAction(IJS_Context* cc,
3221                          const std::vector<CJS_Value>& params,
3222                          CJS_Value& vRet,
3223                          CFX_WideString& sError) {
3224   return TRUE;
3225 }
3226 
setFocus(IJS_Context * cc,const std::vector<CJS_Value> & params,CJS_Value & vRet,CFX_WideString & sError)3227 FX_BOOL Field::setFocus(IJS_Context* cc,
3228                         const std::vector<CJS_Value>& params,
3229                         CJS_Value& vRet,
3230                         CFX_WideString& sError) {
3231   std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3232   if (FieldArray.empty())
3233     return FALSE;
3234 
3235   CPDF_FormField* pFormField = FieldArray[0];
3236   int32_t nCount = pFormField->CountControls();
3237   if (nCount < 1)
3238     return FALSE;
3239 
3240   CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
3241   CPDFSDK_Widget* pWidget = nullptr;
3242   if (nCount == 1) {
3243     pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
3244   } else {
3245     CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
3246     UnderlyingPageType* pPage = UnderlyingFromFPDFPage(
3247         pEnv->FFI_GetCurrentPage(m_pDocument->GetUnderlyingDocument()));
3248     if (!pPage)
3249       return FALSE;
3250     if (CPDFSDK_PageView* pCurPageView = m_pDocument->GetPageView(pPage)) {
3251       for (int32_t i = 0; i < nCount; i++) {
3252         if (CPDFSDK_Widget* pTempWidget =
3253                 pInterForm->GetWidget(pFormField->GetControl(i))) {
3254           if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage()) {
3255             pWidget = pTempWidget;
3256             break;
3257           }
3258         }
3259       }
3260     }
3261   }
3262 
3263   if (pWidget) {
3264     m_pDocument->SetFocusAnnot(pWidget);
3265   }
3266 
3267   return TRUE;
3268 }
3269 
setItems(IJS_Context * cc,const std::vector<CJS_Value> & params,CJS_Value & vRet,CFX_WideString & sError)3270 FX_BOOL Field::setItems(IJS_Context* cc,
3271                         const std::vector<CJS_Value>& params,
3272                         CJS_Value& vRet,
3273                         CFX_WideString& sError) {
3274   return TRUE;
3275 }
3276 
setLock(IJS_Context * cc,const std::vector<CJS_Value> & params,CJS_Value & vRet,CFX_WideString & sError)3277 FX_BOOL Field::setLock(IJS_Context* cc,
3278                        const std::vector<CJS_Value>& params,
3279                        CJS_Value& vRet,
3280                        CFX_WideString& sError) {
3281   return FALSE;
3282 }
3283 
signatureGetModifications(IJS_Context * cc,const std::vector<CJS_Value> & params,CJS_Value & vRet,CFX_WideString & sError)3284 FX_BOOL Field::signatureGetModifications(IJS_Context* cc,
3285                                          const std::vector<CJS_Value>& params,
3286                                          CJS_Value& vRet,
3287                                          CFX_WideString& sError) {
3288   return FALSE;
3289 }
3290 
signatureGetSeedValue(IJS_Context * cc,const std::vector<CJS_Value> & params,CJS_Value & vRet,CFX_WideString & sError)3291 FX_BOOL Field::signatureGetSeedValue(IJS_Context* cc,
3292                                      const std::vector<CJS_Value>& params,
3293                                      CJS_Value& vRet,
3294                                      CFX_WideString& sError) {
3295   return FALSE;
3296 }
3297 
signatureInfo(IJS_Context * cc,const std::vector<CJS_Value> & params,CJS_Value & vRet,CFX_WideString & sError)3298 FX_BOOL Field::signatureInfo(IJS_Context* cc,
3299                              const std::vector<CJS_Value>& params,
3300                              CJS_Value& vRet,
3301                              CFX_WideString& sError) {
3302   return FALSE;
3303 }
3304 
signatureSetSeedValue(IJS_Context * cc,const std::vector<CJS_Value> & params,CJS_Value & vRet,CFX_WideString & sError)3305 FX_BOOL Field::signatureSetSeedValue(IJS_Context* cc,
3306                                      const std::vector<CJS_Value>& params,
3307                                      CJS_Value& vRet,
3308                                      CFX_WideString& sError) {
3309   return FALSE;
3310 }
3311 
signatureSign(IJS_Context * cc,const std::vector<CJS_Value> & params,CJS_Value & vRet,CFX_WideString & sError)3312 FX_BOOL Field::signatureSign(IJS_Context* cc,
3313                              const std::vector<CJS_Value>& params,
3314                              CJS_Value& vRet,
3315                              CFX_WideString& sError) {
3316   return FALSE;
3317 }
3318 
signatureValidate(IJS_Context * cc,const std::vector<CJS_Value> & params,CJS_Value & vRet,CFX_WideString & sError)3319 FX_BOOL Field::signatureValidate(IJS_Context* cc,
3320                                  const std::vector<CJS_Value>& params,
3321                                  CJS_Value& vRet,
3322                                  CFX_WideString& sError) {
3323   return FALSE;
3324 }
3325 
source(IJS_Context * cc,CJS_PropValue & vp,CFX_WideString & sError)3326 FX_BOOL Field::source(IJS_Context* cc,
3327                       CJS_PropValue& vp,
3328                       CFX_WideString& sError) {
3329   if (vp.IsGetting()) {
3330     vp << (CJS_Object*)nullptr;
3331   }
3332 
3333   return TRUE;
3334 }
3335 
AddDelay_Int(FIELD_PROP prop,int32_t n)3336 void Field::AddDelay_Int(FIELD_PROP prop, int32_t n) {
3337   CJS_DelayData* pNewData =
3338       new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
3339   pNewData->num = n;
3340   m_pJSDoc->AddDelayData(pNewData);
3341 }
3342 
AddDelay_Bool(FIELD_PROP prop,bool b)3343 void Field::AddDelay_Bool(FIELD_PROP prop, bool b) {
3344   CJS_DelayData* pNewData =
3345       new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
3346   pNewData->b = b;
3347   m_pJSDoc->AddDelayData(pNewData);
3348 }
3349 
AddDelay_String(FIELD_PROP prop,const CFX_ByteString & string)3350 void Field::AddDelay_String(FIELD_PROP prop, const CFX_ByteString& string) {
3351   CJS_DelayData* pNewData =
3352       new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
3353   pNewData->string = string;
3354   m_pJSDoc->AddDelayData(pNewData);
3355 }
3356 
AddDelay_WideString(FIELD_PROP prop,const CFX_WideString & string)3357 void Field::AddDelay_WideString(FIELD_PROP prop, const CFX_WideString& string) {
3358   CJS_DelayData* pNewData =
3359       new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
3360   pNewData->widestring = string;
3361   m_pJSDoc->AddDelayData(pNewData);
3362 }
3363 
AddDelay_Rect(FIELD_PROP prop,const CFX_FloatRect & rect)3364 void Field::AddDelay_Rect(FIELD_PROP prop, const CFX_FloatRect& rect) {
3365   CJS_DelayData* pNewData =
3366       new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
3367   pNewData->rect = rect;
3368   m_pJSDoc->AddDelayData(pNewData);
3369 }
3370 
AddDelay_Color(FIELD_PROP prop,const CPWL_Color & color)3371 void Field::AddDelay_Color(FIELD_PROP prop, const CPWL_Color& color) {
3372   CJS_DelayData* pNewData =
3373       new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
3374   pNewData->color = color;
3375   m_pJSDoc->AddDelayData(pNewData);
3376 }
3377 
AddDelay_WordArray(FIELD_PROP prop,const std::vector<uint32_t> & array)3378 void Field::AddDelay_WordArray(FIELD_PROP prop,
3379                                const std::vector<uint32_t>& array) {
3380   CJS_DelayData* pNewData =
3381       new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
3382   pNewData->wordarray = array;
3383   m_pJSDoc->AddDelayData(pNewData);
3384 }
3385 
AddDelay_WideStringArray(FIELD_PROP prop,const std::vector<CFX_WideString> & array)3386 void Field::AddDelay_WideStringArray(FIELD_PROP prop,
3387                                      const std::vector<CFX_WideString>& array) {
3388   CJS_DelayData* pNewData =
3389       new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName);
3390   pNewData->widestringarray = array;
3391   m_pJSDoc->AddDelayData(pNewData);
3392 }
3393 
DoDelay(CPDFSDK_Document * pDocument,CJS_DelayData * pData)3394 void Field::DoDelay(CPDFSDK_Document* pDocument, CJS_DelayData* pData) {
3395   ASSERT(pDocument);
3396   switch (pData->eProp) {
3397     case FP_ALIGNMENT:
3398       Field::SetAlignment(pDocument, pData->sFieldName, pData->nControlIndex,
3399                           pData->string);
3400       break;
3401     case FP_BORDERSTYLE:
3402       Field::SetBorderStyle(pDocument, pData->sFieldName, pData->nControlIndex,
3403                             pData->string);
3404       break;
3405     case FP_BUTTONALIGNX:
3406       Field::SetButtonAlignX(pDocument, pData->sFieldName, pData->nControlIndex,
3407                              pData->num);
3408       break;
3409     case FP_BUTTONALIGNY:
3410       Field::SetButtonAlignY(pDocument, pData->sFieldName, pData->nControlIndex,
3411                              pData->num);
3412       break;
3413     case FP_BUTTONFITBOUNDS:
3414       Field::SetButtonFitBounds(pDocument, pData->sFieldName,
3415                                 pData->nControlIndex, pData->b);
3416       break;
3417     case FP_BUTTONPOSITION:
3418       Field::SetButtonPosition(pDocument, pData->sFieldName,
3419                                pData->nControlIndex, pData->num);
3420       break;
3421     case FP_BUTTONSCALEHOW:
3422       Field::SetButtonScaleHow(pDocument, pData->sFieldName,
3423                                pData->nControlIndex, pData->num);
3424       break;
3425     case FP_BUTTONSCALEWHEN:
3426       Field::SetButtonScaleWhen(pDocument, pData->sFieldName,
3427                                 pData->nControlIndex, pData->num);
3428       break;
3429     case FP_CALCORDERINDEX:
3430       Field::SetCalcOrderIndex(pDocument, pData->sFieldName,
3431                                pData->nControlIndex, pData->num);
3432       break;
3433     case FP_CHARLIMIT:
3434       Field::SetCharLimit(pDocument, pData->sFieldName, pData->nControlIndex,
3435                           pData->num);
3436       break;
3437     case FP_COMB:
3438       Field::SetComb(pDocument, pData->sFieldName, pData->nControlIndex,
3439                      pData->b);
3440       break;
3441     case FP_COMMITONSELCHANGE:
3442       Field::SetCommitOnSelChange(pDocument, pData->sFieldName,
3443                                   pData->nControlIndex, pData->b);
3444       break;
3445     case FP_CURRENTVALUEINDICES:
3446       Field::SetCurrentValueIndices(pDocument, pData->sFieldName,
3447                                     pData->nControlIndex, pData->wordarray);
3448       break;
3449     case FP_DEFAULTVALUE:
3450       Field::SetDefaultValue(pDocument, pData->sFieldName, pData->nControlIndex,
3451                              pData->widestring);
3452       break;
3453     case FP_DONOTSCROLL:
3454       Field::SetDoNotScroll(pDocument, pData->sFieldName, pData->nControlIndex,
3455                             pData->b);
3456       break;
3457     case FP_DISPLAY:
3458       Field::SetDisplay(pDocument, pData->sFieldName, pData->nControlIndex,
3459                         pData->num);
3460       break;
3461     case FP_FILLCOLOR:
3462       Field::SetFillColor(pDocument, pData->sFieldName, pData->nControlIndex,
3463                           pData->color);
3464       break;
3465     case FP_HIDDEN:
3466       Field::SetHidden(pDocument, pData->sFieldName, pData->nControlIndex,
3467                        pData->b);
3468       break;
3469     case FP_HIGHLIGHT:
3470       Field::SetHighlight(pDocument, pData->sFieldName, pData->nControlIndex,
3471                           pData->string);
3472       break;
3473     case FP_LINEWIDTH:
3474       Field::SetLineWidth(pDocument, pData->sFieldName, pData->nControlIndex,
3475                           pData->num);
3476       break;
3477     case FP_MULTILINE:
3478       Field::SetMultiline(pDocument, pData->sFieldName, pData->nControlIndex,
3479                           pData->b);
3480       break;
3481     case FP_MULTIPLESELECTION:
3482       Field::SetMultipleSelection(pDocument, pData->sFieldName,
3483                                   pData->nControlIndex, pData->b);
3484       break;
3485     case FP_PASSWORD:
3486       Field::SetPassword(pDocument, pData->sFieldName, pData->nControlIndex,
3487                          pData->b);
3488       break;
3489     case FP_RECT:
3490       Field::SetRect(pDocument, pData->sFieldName, pData->nControlIndex,
3491                      pData->rect);
3492       break;
3493     case FP_RICHTEXT:
3494       // Not supported.
3495       break;
3496     case FP_RICHVALUE:
3497       break;
3498     case FP_ROTATION:
3499       Field::SetRotation(pDocument, pData->sFieldName, pData->nControlIndex,
3500                          pData->num);
3501       break;
3502     case FP_STROKECOLOR:
3503       Field::SetStrokeColor(pDocument, pData->sFieldName, pData->nControlIndex,
3504                             pData->color);
3505       break;
3506     case FP_STYLE:
3507       Field::SetStyle(pDocument, pData->sFieldName, pData->nControlIndex,
3508                       pData->string);
3509       break;
3510     case FP_TEXTCOLOR:
3511       Field::SetTextColor(pDocument, pData->sFieldName, pData->nControlIndex,
3512                           pData->color);
3513       break;
3514     case FP_TEXTFONT:
3515       Field::SetTextFont(pDocument, pData->sFieldName, pData->nControlIndex,
3516                          pData->string);
3517       break;
3518     case FP_TEXTSIZE:
3519       Field::SetTextSize(pDocument, pData->sFieldName, pData->nControlIndex,
3520                          pData->num);
3521       break;
3522     case FP_USERNAME:
3523       Field::SetUserName(pDocument, pData->sFieldName, pData->nControlIndex,
3524                          pData->widestring);
3525       break;
3526     case FP_VALUE:
3527       Field::SetValue(pDocument, pData->sFieldName, pData->nControlIndex,
3528                       pData->widestringarray);
3529       break;
3530   }
3531 }
3532 
AddField(CPDFSDK_Document * pDocument,int nPageIndex,int nFieldType,const CFX_WideString & sName,const CFX_FloatRect & rcCoords)3533 void Field::AddField(CPDFSDK_Document* pDocument,
3534                      int nPageIndex,
3535                      int nFieldType,
3536                      const CFX_WideString& sName,
3537                      const CFX_FloatRect& rcCoords) {
3538   // Not supported.
3539 }
3540