blob: 198c833db59c90e28904e65e22919d60c80e71ec [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// Copyright 2014 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Dan Sinclairf766ad22016-03-14 13:51:24 -04007#include "fpdfsdk/javascript/Field.h"
Tom Sepez37458412015-10-06 11:33:46 -07008
Tom Sepezb9cc7a02016-02-01 13:42:30 -08009#include <algorithm>
10#include <memory>
Dan Sinclair3ebd1212016-03-09 09:59:23 -050011#include <string>
Tom Sepezb9cc7a02016-02-01 13:42:30 -080012#include <vector>
13
dan sinclair61b2fc72016-03-23 19:21:44 -040014#include "core/fpdfapi/fpdf_font/include/cpdf_font.h"
Dan Sinclair455a4192016-03-16 09:48:56 -040015#include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
Dan Sinclairaa403d32016-03-15 14:57:22 -040016#include "fpdfsdk/include/fsdk_mgr.h"
Lei Zhangbde53d22015-11-12 22:21:30 -080017#include "fpdfsdk/include/javascript/IJavaScript.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040018#include "fpdfsdk/javascript/Document.h"
19#include "fpdfsdk/javascript/Icon.h"
20#include "fpdfsdk/javascript/JS_Context.h"
21#include "fpdfsdk/javascript/JS_Define.h"
22#include "fpdfsdk/javascript/JS_EventHandler.h"
23#include "fpdfsdk/javascript/JS_Object.h"
24#include "fpdfsdk/javascript/JS_Runtime.h"
25#include "fpdfsdk/javascript/JS_Value.h"
26#include "fpdfsdk/javascript/PublicMethods.h"
27#include "fpdfsdk/javascript/color.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070028
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070029BEGIN_JS_STATIC_CONST(CJS_Field)
30END_JS_STATIC_CONST()
31
32BEGIN_JS_STATIC_PROP(CJS_Field)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070033JS_STATIC_PROP_ENTRY(alignment)
34JS_STATIC_PROP_ENTRY(borderStyle)
35JS_STATIC_PROP_ENTRY(buttonAlignX)
36JS_STATIC_PROP_ENTRY(buttonAlignY)
37JS_STATIC_PROP_ENTRY(buttonFitBounds)
38JS_STATIC_PROP_ENTRY(buttonPosition)
39JS_STATIC_PROP_ENTRY(buttonScaleHow)
40JS_STATIC_PROP_ENTRY(buttonScaleWhen)
41JS_STATIC_PROP_ENTRY(calcOrderIndex)
42JS_STATIC_PROP_ENTRY(charLimit)
43JS_STATIC_PROP_ENTRY(comb)
44JS_STATIC_PROP_ENTRY(commitOnSelChange)
45JS_STATIC_PROP_ENTRY(currentValueIndices)
46JS_STATIC_PROP_ENTRY(defaultStyle)
47JS_STATIC_PROP_ENTRY(defaultValue)
48JS_STATIC_PROP_ENTRY(doNotScroll)
49JS_STATIC_PROP_ENTRY(doNotSpellCheck)
50JS_STATIC_PROP_ENTRY(delay)
51JS_STATIC_PROP_ENTRY(display)
52JS_STATIC_PROP_ENTRY(doc)
53JS_STATIC_PROP_ENTRY(editable)
54JS_STATIC_PROP_ENTRY(exportValues)
55JS_STATIC_PROP_ENTRY(hidden)
56JS_STATIC_PROP_ENTRY(fileSelect)
57JS_STATIC_PROP_ENTRY(fillColor)
58JS_STATIC_PROP_ENTRY(lineWidth)
59JS_STATIC_PROP_ENTRY(highlight)
60JS_STATIC_PROP_ENTRY(multiline)
61JS_STATIC_PROP_ENTRY(multipleSelection)
62JS_STATIC_PROP_ENTRY(name)
63JS_STATIC_PROP_ENTRY(numItems)
64JS_STATIC_PROP_ENTRY(page)
65JS_STATIC_PROP_ENTRY(password)
66JS_STATIC_PROP_ENTRY(print)
67JS_STATIC_PROP_ENTRY(radiosInUnison)
68JS_STATIC_PROP_ENTRY(readonly)
69JS_STATIC_PROP_ENTRY(rect)
70JS_STATIC_PROP_ENTRY(required)
71JS_STATIC_PROP_ENTRY(richText)
72JS_STATIC_PROP_ENTRY(richValue)
73JS_STATIC_PROP_ENTRY(rotation)
74JS_STATIC_PROP_ENTRY(strokeColor)
75JS_STATIC_PROP_ENTRY(style)
76JS_STATIC_PROP_ENTRY(submitName)
77JS_STATIC_PROP_ENTRY(textColor)
78JS_STATIC_PROP_ENTRY(textFont)
79JS_STATIC_PROP_ENTRY(textSize)
80JS_STATIC_PROP_ENTRY(type)
81JS_STATIC_PROP_ENTRY(userName)
82JS_STATIC_PROP_ENTRY(value)
83JS_STATIC_PROP_ENTRY(valueAsString)
84JS_STATIC_PROP_ENTRY(source)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070085END_JS_STATIC_PROP()
86
87BEGIN_JS_STATIC_METHOD(CJS_Field)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070088JS_STATIC_METHOD_ENTRY(browseForFileToSubmit)
89JS_STATIC_METHOD_ENTRY(buttonGetCaption)
90JS_STATIC_METHOD_ENTRY(buttonGetIcon)
91JS_STATIC_METHOD_ENTRY(buttonImportIcon)
92JS_STATIC_METHOD_ENTRY(buttonSetCaption)
93JS_STATIC_METHOD_ENTRY(buttonSetIcon)
94JS_STATIC_METHOD_ENTRY(checkThisBox)
95JS_STATIC_METHOD_ENTRY(clearItems)
96JS_STATIC_METHOD_ENTRY(defaultIsChecked)
97JS_STATIC_METHOD_ENTRY(deleteItemAt)
98JS_STATIC_METHOD_ENTRY(getArray)
99JS_STATIC_METHOD_ENTRY(getItemAt)
100JS_STATIC_METHOD_ENTRY(getLock)
101JS_STATIC_METHOD_ENTRY(insertItemAt)
102JS_STATIC_METHOD_ENTRY(isBoxChecked)
103JS_STATIC_METHOD_ENTRY(isDefaultChecked)
104JS_STATIC_METHOD_ENTRY(setAction)
105JS_STATIC_METHOD_ENTRY(setFocus)
106JS_STATIC_METHOD_ENTRY(setItems)
107JS_STATIC_METHOD_ENTRY(setLock)
108JS_STATIC_METHOD_ENTRY(signatureGetModifications)
109JS_STATIC_METHOD_ENTRY(signatureGetSeedValue)
110JS_STATIC_METHOD_ENTRY(signatureInfo)
111JS_STATIC_METHOD_ENTRY(signatureSetSeedValue)
112JS_STATIC_METHOD_ENTRY(signatureSign)
113JS_STATIC_METHOD_ENTRY(signatureValidate)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700114END_JS_STATIC_METHOD()
115
116IMPLEMENT_JS_CLASS(CJS_Field, Field)
117
Tom Sepez33420902015-10-13 15:00:10 -0700118void CJS_Field::InitInstance(IJS_Runtime* pIRuntime) {
119 CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime);
120 Field* pField = static_cast<Field*>(GetEmbedObject());
121 pField->SetIsolate(pRuntime->GetIsolate());
Lei Zhangd88a3642015-11-10 09:38:57 -0800122}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700123
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700124Field::Field(CJS_Object* pJSObject)
125 : CJS_EmbedObj(pJSObject),
126 m_pJSDoc(NULL),
127 m_pDocument(NULL),
128 m_nFormControlIndex(-1),
129 m_bCanSet(FALSE),
130 m_bDelay(FALSE),
131 m_isolate(NULL) {}
132
133Field::~Field() {}
134
135// note: iControlNo = -1, means not a widget.
136void Field::ParseFieldName(const std::wstring& strFieldNameParsed,
137 std::wstring& strFieldName,
138 int& iControlNo) {
139 int iStart = strFieldNameParsed.find_last_of(L'.');
140 if (iStart == -1) {
141 strFieldName = strFieldNameParsed;
142 iControlNo = -1;
143 return;
144 }
145 std::wstring suffixal = strFieldNameParsed.substr(iStart + 1);
146 iControlNo = FXSYS_wtoi(suffixal.c_str());
147 if (iControlNo == 0) {
148 int iStart;
149 while ((iStart = suffixal.find_last_of(L" ")) != -1) {
150 suffixal.erase(iStart, 1);
151 }
152
153 if (suffixal.compare(L"0") != 0) {
154 strFieldName = strFieldNameParsed;
155 iControlNo = -1;
156 return;
157 }
158 }
159 strFieldName = strFieldNameParsed.substr(0, iStart);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700160}
161
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700162FX_BOOL Field::AttachField(Document* pDocument,
163 const CFX_WideString& csFieldName) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700164 m_pJSDoc = pDocument;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700165 m_pDocument = pDocument->GetReaderDoc();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700166 m_bCanSet = m_pDocument->GetPermissions(FPDFPERM_FILL_FORM) ||
167 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
168 m_pDocument->GetPermissions(FPDFPERM_MODIFY);
169
170 CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700171 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700172 CFX_WideString swFieldNameTemp = csFieldName;
173 swFieldNameTemp.Replace(L"..", L".");
174
175 if (pInterForm->CountFields(swFieldNameTemp) <= 0) {
176 std::wstring strFieldName;
177 int iControlNo = -1;
178 ParseFieldName(swFieldNameTemp.c_str(), strFieldName, iControlNo);
179 if (iControlNo == -1)
180 return FALSE;
181
182 m_FieldName = strFieldName.c_str();
183 m_nFormControlIndex = iControlNo;
184 return TRUE;
185 }
186
187 m_FieldName = swFieldNameTemp;
188 m_nFormControlIndex = -1;
189
190 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700191}
192
Lei Zhangd88a3642015-11-10 09:38:57 -0800193std::vector<CPDF_FormField*> Field::GetFormFields(
194 CPDFSDK_Document* pDocument,
195 const CFX_WideString& csFieldName) {
196 std::vector<CPDF_FormField*> fields;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700197 CPDFSDK_InterForm* pReaderInterForm = pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700198 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -0800199 for (int i = 0, sz = pInterForm->CountFields(csFieldName); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700200 if (CPDF_FormField* pFormField = pInterForm->GetField(i, csFieldName))
Lei Zhangd88a3642015-11-10 09:38:57 -0800201 fields.push_back(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700202 }
Lei Zhangd88a3642015-11-10 09:38:57 -0800203 return fields;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700204}
205
Lei Zhangd88a3642015-11-10 09:38:57 -0800206std::vector<CPDF_FormField*> Field::GetFormFields(
207 const CFX_WideString& csFieldName) const {
208 return Field::GetFormFields(m_pDocument, csFieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700209}
210
211void Field::UpdateFormField(CPDFSDK_Document* pDocument,
212 CPDF_FormField* pFormField,
213 FX_BOOL bChangeMark,
214 FX_BOOL bResetAP,
215 FX_BOOL bRefresh) {
Lei Zhangd88a3642015-11-10 09:38:57 -0800216 std::vector<CPDFSDK_Widget*> widgets;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700217 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -0800218 pInterForm->GetWidgets(pFormField, &widgets);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700219
220 if (bResetAP) {
221 int nFieldType = pFormField->GetFieldType();
222 if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_TEXTFIELD) {
Lei Zhangd88a3642015-11-10 09:38:57 -0800223 for (CPDFSDK_Widget* pWidget : widgets) {
224 FX_BOOL bFormatted = FALSE;
225 CFX_WideString sValue = pWidget->OnFormat(bFormatted);
226 pWidget->ResetAppearance(bFormatted ? sValue.c_str() : nullptr, FALSE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700227 }
228 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800229 for (CPDFSDK_Widget* pWidget : widgets) {
230 pWidget->ResetAppearance(nullptr, FALSE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700231 }
232 }
233 }
234
235 if (bRefresh) {
Lei Zhangd88a3642015-11-10 09:38:57 -0800236 for (CPDFSDK_Widget* pWidget : widgets) {
237 CPDFSDK_Document* pDoc = pWidget->GetInterForm()->GetDocument();
238 pDoc->UpdateAllViews(nullptr, pWidget);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700239 }
240 }
241
242 if (bChangeMark)
243 pDocument->SetChangeMark();
244}
245
246void Field::UpdateFormControl(CPDFSDK_Document* pDocument,
247 CPDF_FormControl* pFormControl,
248 FX_BOOL bChangeMark,
249 FX_BOOL bResetAP,
250 FX_BOOL bRefresh) {
Lei Zhang96660d62015-12-14 18:27:25 -0800251 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700252
253 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700254 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
255
256 if (pWidget) {
257 if (bResetAP) {
258 int nFieldType = pWidget->GetFieldType();
259 if (nFieldType == FIELDTYPE_COMBOBOX ||
260 nFieldType == FIELDTYPE_TEXTFIELD) {
261 FX_BOOL bFormated = FALSE;
262 CFX_WideString sValue = pWidget->OnFormat(bFormated);
263 if (bFormated)
264 pWidget->ResetAppearance(sValue.c_str(), FALSE);
265 else
266 pWidget->ResetAppearance(NULL, FALSE);
267 } else {
268 pWidget->ResetAppearance(NULL, FALSE);
269 }
270 }
271
272 if (bRefresh) {
273 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
274 CPDFSDK_Document* pDoc = pInterForm->GetDocument();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700275 pDoc->UpdateAllViews(NULL, pWidget);
276 }
277 }
278
279 if (bChangeMark)
280 pDocument->SetChangeMark();
281}
282
283CPDFSDK_Widget* Field::GetWidget(CPDFSDK_Document* pDocument,
284 CPDF_FormControl* pFormControl) {
Jun Fang14b20db2015-12-01 12:35:24 +0800285 CPDFSDK_InterForm* pInterForm =
286 static_cast<CPDFSDK_InterForm*>(pDocument->GetInterForm());
287 return pInterForm ? pInterForm->GetWidget(pFormControl) : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700288}
289
290FX_BOOL Field::ValueIsOccur(CPDF_FormField* pFormField,
291 CFX_WideString csOptLabel) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700292 for (int i = 0, sz = pFormField->CountOptions(); i < sz; i++) {
293 if (csOptLabel.Compare(pFormField->GetOptionLabel(i)) == 0)
294 return TRUE;
295 }
296
297 return FALSE;
298}
299
300CPDF_FormControl* Field::GetSmartFieldControl(CPDF_FormField* pFormField) {
301 if (!pFormField->CountControls() ||
302 m_nFormControlIndex >= pFormField->CountControls())
303 return NULL;
304
305 if (m_nFormControlIndex < 0)
306 return pFormField->GetControl(0);
307
308 return pFormField->GetControl(m_nFormControlIndex);
309}
310
Tom Sepezba038bc2015-10-08 12:03:00 -0700311FX_BOOL Field::alignment(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700312 CJS_PropValue& vp,
313 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800314 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700315
316 if (vp.IsSetting()) {
317 if (!m_bCanSet)
318 return FALSE;
319
320 CFX_ByteString alignStr;
321 vp >> alignStr;
322
323 if (m_bDelay) {
324 AddDelay_String(FP_ALIGNMENT, alignStr);
325 } else {
326 Field::SetAlignment(m_pDocument, m_FieldName, m_nFormControlIndex,
327 alignStr);
328 }
329 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800330 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
331 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700332 return FALSE;
333
Lei Zhangd88a3642015-11-10 09:38:57 -0800334 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700335 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
336 return FALSE;
337
338 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
339 if (!pFormControl)
340 return FALSE;
341
342 switch (pFormControl->GetControlAlignment()) {
343 case 1:
344 vp << L"center";
345 break;
346 case 0:
347 vp << L"left";
348 break;
349 case 2:
350 vp << L"right";
351 break;
352 default:
353 vp << L"";
354 }
355 }
356
357 return TRUE;
358}
359
360void Field::SetAlignment(CPDFSDK_Document* pDocument,
361 const CFX_WideString& swFieldName,
362 int nControlIndex,
363 const CFX_ByteString& string) {
364 // Not supported.
365}
366
Tom Sepezba038bc2015-10-08 12:03:00 -0700367FX_BOOL Field::borderStyle(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700368 CJS_PropValue& vp,
369 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800370 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700371
372 if (vp.IsSetting()) {
373 if (!m_bCanSet)
374 return FALSE;
375
376 CFX_ByteString strType = "";
377 vp >> strType;
378
379 if (m_bDelay) {
380 AddDelay_String(FP_BORDERSTYLE, strType);
381 } else {
382 Field::SetBorderStyle(m_pDocument, m_FieldName, m_nFormControlIndex,
383 strType);
384 }
385 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800386 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
387 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700388 return FALSE;
389
Lei Zhangd88a3642015-11-10 09:38:57 -0800390 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700391 if (!pFormField)
392 return FALSE;
393
394 CPDFSDK_Widget* pWidget =
395 GetWidget(m_pDocument, GetSmartFieldControl(pFormField));
396 if (!pWidget)
397 return FALSE;
398
399 int nBorderstyle = pWidget->GetBorderStyle();
400
401 switch (nBorderstyle) {
402 case BBS_SOLID:
403 vp << L"solid";
404 break;
405 case BBS_DASH:
406 vp << L"dashed";
407 break;
408 case BBS_BEVELED:
409 vp << L"beveled";
410 break;
411 case BBS_INSET:
412 vp << L"inset";
413 break;
414 case BBS_UNDERLINE:
415 vp << L"underline";
416 break;
417 default:
418 vp << L"";
419 break;
420 }
421 }
422
423 return TRUE;
424}
425
426void Field::SetBorderStyle(CPDFSDK_Document* pDocument,
427 const CFX_WideString& swFieldName,
428 int nControlIndex,
429 const CFX_ByteString& string) {
Lei Zhang96660d62015-12-14 18:27:25 -0800430 ASSERT(pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700431
432 int nBorderStyle = 0;
433
434 if (string == "solid")
435 nBorderStyle = BBS_SOLID;
436 else if (string == "beveled")
437 nBorderStyle = BBS_BEVELED;
438 else if (string == "dashed")
439 nBorderStyle = BBS_DASH;
440 else if (string == "inset")
441 nBorderStyle = BBS_INSET;
442 else if (string == "underline")
443 nBorderStyle = BBS_UNDERLINE;
444 else
445 return;
446
Lei Zhangd88a3642015-11-10 09:38:57 -0800447 std::vector<CPDF_FormField*> FieldArray =
448 GetFormFields(pDocument, swFieldName);
449 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700450 if (nControlIndex < 0) {
451 FX_BOOL bSet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -0800452 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700453 if (CPDFSDK_Widget* pWidget =
Lei Zhangd88a3642015-11-10 09:38:57 -0800454 GetWidget(pDocument, pFormField->GetControl(i))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700455 if (pWidget->GetBorderStyle() != nBorderStyle) {
456 pWidget->SetBorderStyle(nBorderStyle);
457 bSet = TRUE;
458 }
459 }
460 }
461 if (bSet)
462 UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
463 } else {
464 if (nControlIndex >= pFormField->CountControls())
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700465 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700466 if (CPDF_FormControl* pFormControl =
467 pFormField->GetControl(nControlIndex)) {
468 if (CPDFSDK_Widget* pWidget = GetWidget(pDocument, pFormControl)) {
469 if (pWidget->GetBorderStyle() != nBorderStyle) {
470 pWidget->SetBorderStyle(nBorderStyle);
471 UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
472 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700473 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700474 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700475 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700476 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700477}
478
Tom Sepezba038bc2015-10-08 12:03:00 -0700479FX_BOOL Field::buttonAlignX(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700480 CJS_PropValue& vp,
481 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800482 ASSERT(m_pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700483
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700484 if (vp.IsSetting()) {
485 if (!m_bCanSet)
486 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700487
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700488 int nVP;
489 vp >> nVP;
490
491 if (m_bDelay) {
492 AddDelay_Int(FP_BUTTONALIGNX, nVP);
493 } else {
494 Field::SetButtonAlignX(m_pDocument, m_FieldName, m_nFormControlIndex,
495 nVP);
496 }
497 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800498 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
499 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700500 return FALSE;
501
Lei Zhangd88a3642015-11-10 09:38:57 -0800502 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700503 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
504 return FALSE;
505
506 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
507 if (!pFormControl)
508 return FALSE;
509
510 CPDF_IconFit IconFit = pFormControl->GetIconFit();
511
512 FX_FLOAT fLeft, fBottom;
513 IconFit.GetIconPosition(fLeft, fBottom);
514
515 vp << (int32_t)fLeft;
516 }
517
518 return TRUE;
519}
520
521void Field::SetButtonAlignX(CPDFSDK_Document* pDocument,
522 const CFX_WideString& swFieldName,
523 int nControlIndex,
524 int number) {
525 // Not supported.
526}
527
Tom Sepezba038bc2015-10-08 12:03:00 -0700528FX_BOOL Field::buttonAlignY(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700529 CJS_PropValue& vp,
530 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800531 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700532
533 if (vp.IsSetting()) {
534 if (!m_bCanSet)
535 return FALSE;
536
537 int nVP;
538 vp >> nVP;
539
540 if (m_bDelay) {
541 AddDelay_Int(FP_BUTTONALIGNY, nVP);
542 } else {
543 Field::SetButtonAlignY(m_pDocument, m_FieldName, m_nFormControlIndex,
544 nVP);
545 }
546 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800547 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
548 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700549 return FALSE;
550
Lei Zhangd88a3642015-11-10 09:38:57 -0800551 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700552 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
553 return FALSE;
554
555 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
556 if (!pFormControl)
557 return FALSE;
558
559 CPDF_IconFit IconFit = pFormControl->GetIconFit();
560
561 FX_FLOAT fLeft, fBottom;
562 IconFit.GetIconPosition(fLeft, fBottom);
563
564 vp << (int32_t)fBottom;
565 }
566
567 return TRUE;
568}
569
570void Field::SetButtonAlignY(CPDFSDK_Document* pDocument,
571 const CFX_WideString& swFieldName,
572 int nControlIndex,
573 int number) {
574 // Not supported.
575}
576
Tom Sepezba038bc2015-10-08 12:03:00 -0700577FX_BOOL Field::buttonFitBounds(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700578 CJS_PropValue& vp,
579 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800580 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700581
582 if (vp.IsSetting()) {
583 if (!m_bCanSet)
584 return FALSE;
585
586 bool bVP;
587 vp >> bVP;
588
589 if (m_bDelay) {
590 AddDelay_Bool(FP_BUTTONFITBOUNDS, bVP);
591 } else {
592 Field::SetButtonFitBounds(m_pDocument, m_FieldName, m_nFormControlIndex,
593 bVP);
594 }
595 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800596 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
597 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700598 return FALSE;
599
Lei Zhangd88a3642015-11-10 09:38:57 -0800600 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700601 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
602 return FALSE;
603
604 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
605 if (!pFormControl)
606 return FALSE;
607
608 CPDF_IconFit IconFit = pFormControl->GetIconFit();
609 vp << IconFit.GetFittingBounds();
610 }
611
612 return TRUE;
613}
614
615void Field::SetButtonFitBounds(CPDFSDK_Document* pDocument,
616 const CFX_WideString& swFieldName,
617 int nControlIndex,
618 bool b) {
619 // Not supported.
620}
621
Tom Sepezba038bc2015-10-08 12:03:00 -0700622FX_BOOL Field::buttonPosition(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700623 CJS_PropValue& vp,
624 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800625 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700626
627 if (vp.IsSetting()) {
628 if (!m_bCanSet)
629 return FALSE;
630
631 int nVP;
632 vp >> nVP;
633
634 if (m_bDelay) {
635 AddDelay_Int(FP_BUTTONPOSITION, nVP);
636 } else {
637 Field::SetButtonPosition(m_pDocument, m_FieldName, m_nFormControlIndex,
638 nVP);
639 }
640 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800641 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
642 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700643 return FALSE;
644
Lei Zhangd88a3642015-11-10 09:38:57 -0800645 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700646 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
647 return FALSE;
648
649 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
650 if (!pFormControl)
651 return FALSE;
652
653 vp << pFormControl->GetTextPosition();
654 }
655 return TRUE;
656}
657
658void Field::SetButtonPosition(CPDFSDK_Document* pDocument,
659 const CFX_WideString& swFieldName,
660 int nControlIndex,
661 int number) {
662 // Not supported.
663}
664
Tom Sepezba038bc2015-10-08 12:03:00 -0700665FX_BOOL Field::buttonScaleHow(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700666 CJS_PropValue& vp,
667 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800668 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700669
670 if (vp.IsSetting()) {
671 if (!m_bCanSet)
672 return FALSE;
673
674 int nVP;
675 vp >> nVP;
676
677 if (m_bDelay) {
678 AddDelay_Int(FP_BUTTONSCALEHOW, nVP);
679 } else {
680 Field::SetButtonScaleHow(m_pDocument, m_FieldName, m_nFormControlIndex,
681 nVP);
682 }
683 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800684 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
685 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700686 return FALSE;
687
Lei Zhangd88a3642015-11-10 09:38:57 -0800688 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700689 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
690 return FALSE;
691
692 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
693 if (!pFormControl)
694 return FALSE;
695
696 CPDF_IconFit IconFit = pFormControl->GetIconFit();
697 if (IconFit.IsProportionalScale())
698 vp << (int32_t)0;
699 else
700 vp << (int32_t)1;
701 }
702
703 return TRUE;
704}
705
706void Field::SetButtonScaleHow(CPDFSDK_Document* pDocument,
707 const CFX_WideString& swFieldName,
708 int nControlIndex,
709 int number) {
710 // Not supported.
711}
712
Tom Sepezba038bc2015-10-08 12:03:00 -0700713FX_BOOL Field::buttonScaleWhen(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700714 CJS_PropValue& vp,
715 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800716 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700717
718 if (vp.IsSetting()) {
719 if (!m_bCanSet)
720 return FALSE;
721
722 int nVP;
723 vp >> nVP;
724
725 if (m_bDelay) {
726 AddDelay_Int(FP_BUTTONSCALEWHEN, nVP);
727 } else {
728 Field::SetButtonScaleWhen(m_pDocument, m_FieldName, m_nFormControlIndex,
729 nVP);
730 }
731 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800732 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
733 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700734 return FALSE;
735
Lei Zhangd88a3642015-11-10 09:38:57 -0800736 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700737 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
738 return FALSE;
739
740 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
741 if (!pFormControl)
742 return FALSE;
743
744 CPDF_IconFit IconFit = pFormControl->GetIconFit();
745 int ScaleM = IconFit.GetScaleMethod();
746 switch (ScaleM) {
747 case CPDF_IconFit::Always:
748 vp << (int32_t)CPDF_IconFit::Always;
749 break;
750 case CPDF_IconFit::Bigger:
751 vp << (int32_t)CPDF_IconFit::Bigger;
752 break;
753 case CPDF_IconFit::Never:
754 vp << (int32_t)CPDF_IconFit::Never;
755 break;
756 case CPDF_IconFit::Smaller:
757 vp << (int32_t)CPDF_IconFit::Smaller;
758 break;
759 }
760 }
761
762 return TRUE;
763}
764
765void Field::SetButtonScaleWhen(CPDFSDK_Document* pDocument,
766 const CFX_WideString& swFieldName,
767 int nControlIndex,
768 int number) {
769 // Not supported.
770}
771
Tom Sepezba038bc2015-10-08 12:03:00 -0700772FX_BOOL Field::calcOrderIndex(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700773 CJS_PropValue& vp,
774 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800775 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700776
777 if (vp.IsSetting()) {
778 if (!m_bCanSet)
779 return FALSE;
780
781 int nVP;
782 vp >> nVP;
783
784 if (m_bDelay) {
785 AddDelay_Int(FP_CALCORDERINDEX, nVP);
786 } else {
787 Field::SetCalcOrderIndex(m_pDocument, m_FieldName, m_nFormControlIndex,
788 nVP);
789 }
790 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800791 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
792 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700793 return FALSE;
794
Lei Zhangd88a3642015-11-10 09:38:57 -0800795 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700796 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -0800797 pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700798 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -0800799 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700800
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700801 CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm();
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700802 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700803 vp << (int32_t)pInterForm->FindFieldInCalculationOrder(pFormField);
804 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700805
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700806 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700807}
808
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700809void Field::SetCalcOrderIndex(CPDFSDK_Document* pDocument,
810 const CFX_WideString& swFieldName,
811 int nControlIndex,
812 int number) {
813 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700814}
815
Tom Sepezba038bc2015-10-08 12:03:00 -0700816FX_BOOL Field::charLimit(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700817 CJS_PropValue& vp,
818 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800819 ASSERT(m_pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700820
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700821 if (vp.IsSetting()) {
822 if (!m_bCanSet)
823 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700824
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700825 int nVP;
826 vp >> nVP;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700827
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700828 if (m_bDelay) {
829 AddDelay_Int(FP_CHARLIMIT, nVP);
830 } else {
831 Field::SetCharLimit(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700832 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700833 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800834 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
835 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700836 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700837
Lei Zhangd88a3642015-11-10 09:38:57 -0800838 CPDF_FormField* pFormField = FieldArray[0];
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700839 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700840 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700841
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700842 vp << (int32_t)pFormField->GetMaxLen();
843 }
844 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700845}
846
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700847void Field::SetCharLimit(CPDFSDK_Document* pDocument,
848 const CFX_WideString& swFieldName,
849 int nControlIndex,
850 int number) {
851 // Not supported.
852}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700853
Tom Sepezba038bc2015-10-08 12:03:00 -0700854FX_BOOL Field::comb(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700855 CJS_PropValue& vp,
856 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800857 ASSERT(m_pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700858
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700859 if (vp.IsSetting()) {
860 if (!m_bCanSet)
861 return FALSE;
862
863 bool bVP;
864 vp >> bVP;
865
866 if (m_bDelay) {
867 AddDelay_Bool(FP_COMB, bVP);
868 } else {
869 Field::SetComb(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
870 }
871 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800872 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
873 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700874 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700875
Lei Zhangd88a3642015-11-10 09:38:57 -0800876 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700877 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
878 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700879
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700880 if (pFormField->GetFieldFlags() & FIELDFLAG_COMB)
881 vp << true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700882 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700883 vp << false;
884 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700885
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700886 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700887}
888
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700889void Field::SetComb(CPDFSDK_Document* pDocument,
890 const CFX_WideString& swFieldName,
891 int nControlIndex,
892 bool b) {
893 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700894}
895
Tom Sepezba038bc2015-10-08 12:03:00 -0700896FX_BOOL Field::commitOnSelChange(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700897 CJS_PropValue& vp,
898 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -0800899 ASSERT(m_pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700900
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700901 if (vp.IsSetting()) {
902 if (!m_bCanSet)
903 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700904
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700905 bool bVP;
906 vp >> bVP;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700907
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700908 if (m_bDelay) {
909 AddDelay_Bool(FP_COMMITONSELCHANGE, bVP);
910 } else {
911 Field::SetCommitOnSelChange(m_pDocument, m_FieldName, m_nFormControlIndex,
912 bVP);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700913 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700914 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800915 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
916 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700917 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700918
Lei Zhangd88a3642015-11-10 09:38:57 -0800919 CPDF_FormField* pFormField = FieldArray[0];
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700920 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -0800921 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700922 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -0800923 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700924
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700925 if (pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE)
926 vp << true;
927 else
928 vp << false;
929 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700930
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700931 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700932}
933
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700934void Field::SetCommitOnSelChange(CPDFSDK_Document* pDocument,
935 const CFX_WideString& swFieldName,
936 int nControlIndex,
937 bool b) {
938 // Not supported.
939}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700940
Tom Sepezba038bc2015-10-08 12:03:00 -0700941FX_BOOL Field::currentValueIndices(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700942 CJS_PropValue& vp,
943 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -0700944 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700945
946 if (vp.IsSetting()) {
947 if (!m_bCanSet)
948 return FALSE;
949
950 CFX_DWordArray array;
951
Tom Sepez39bfe122015-09-17 15:25:23 -0700952 if (vp.GetType() == CJS_Value::VT_number) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700953 int iSelecting = 0;
954 vp >> iSelecting;
955 array.Add(iSelecting);
956 } else if (vp.IsArrayObject()) {
Tom Sepez67fd5df2015-10-08 12:24:19 -0700957 CJS_Array SelArray(pRuntime);
958 CJS_Value SelValue(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700959 int iSelecting;
960 vp >> SelArray;
961 for (int i = 0, sz = SelArray.GetLength(); i < sz; i++) {
962 SelArray.GetElement(i, SelValue);
963 iSelecting = SelValue.ToInt();
964 array.Add(iSelecting);
965 }
966 }
967
968 if (m_bDelay) {
969 AddDelay_WordArray(FP_CURRENTVALUEINDICES, array);
970 } else {
971 Field::SetCurrentValueIndices(m_pDocument, m_FieldName,
972 m_nFormControlIndex, array);
973 }
974 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800975 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
976 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700977 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700978
Lei Zhangd88a3642015-11-10 09:38:57 -0800979 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700980 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -0800981 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700982 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -0800983 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700984
Lei Zhangd88a3642015-11-10 09:38:57 -0800985 if (pFormField->CountSelectedItems() == 1) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700986 vp << pFormField->GetSelectedIndex(0);
Lei Zhangd88a3642015-11-10 09:38:57 -0800987 } else if (pFormField->CountSelectedItems() > 1) {
Tom Sepez67fd5df2015-10-08 12:24:19 -0700988 CJS_Array SelArray(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700989 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
990 SelArray.SetElement(
Tom Sepez67fd5df2015-10-08 12:24:19 -0700991 i, CJS_Value(pRuntime, pFormField->GetSelectedIndex(i)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700992 }
993 vp << SelArray;
Lei Zhangd88a3642015-11-10 09:38:57 -0800994 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700995 vp << -1;
Lei Zhangd88a3642015-11-10 09:38:57 -0800996 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700997 }
998
999 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001000}
1001
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001002void Field::SetCurrentValueIndices(CPDFSDK_Document* pDocument,
1003 const CFX_WideString& swFieldName,
1004 int nControlIndex,
1005 const CFX_DWordArray& array) {
Lei Zhang96660d62015-12-14 18:27:25 -08001006 ASSERT(pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001007
Lei Zhangd88a3642015-11-10 09:38:57 -08001008 std::vector<CPDF_FormField*> FieldArray =
1009 GetFormFields(pDocument, swFieldName);
1010 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001011 int nFieldType = pFormField->GetFieldType();
1012 if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX) {
1013 FX_DWORD dwFieldFlags = pFormField->GetFieldFlags();
1014 pFormField->ClearSelection(TRUE);
1015
1016 for (int i = 0, sz = array.GetSize(); i < sz; i++) {
1017 if (i > 0 && !(dwFieldFlags & (1 << 21))) {
1018 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001019 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001020
1021 int iSelecting = (int32_t)array.GetAt(i);
1022 if (iSelecting < pFormField->CountOptions() &&
1023 !pFormField->IsItemSelected(iSelecting))
1024 pFormField->SetItemSelection(iSelecting, TRUE);
1025 }
1026 UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001027 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001028 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001029}
1030
Tom Sepezba038bc2015-10-08 12:03:00 -07001031FX_BOOL Field::defaultStyle(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001032 CJS_PropValue& vp,
1033 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001034 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001035}
1036
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001037void Field::SetDefaultStyle(CPDFSDK_Document* pDocument,
1038 const CFX_WideString& swFieldName,
1039 int nControlIndex) {
1040 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001041}
1042
Tom Sepezba038bc2015-10-08 12:03:00 -07001043FX_BOOL Field::defaultValue(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001044 CJS_PropValue& vp,
1045 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08001046 ASSERT(m_pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001047
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001048 if (vp.IsSetting()) {
1049 if (!m_bCanSet)
1050 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001051
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001052 CFX_WideString WideStr;
1053 vp >> WideStr;
1054
1055 if (m_bDelay) {
1056 AddDelay_WideString(FP_DEFAULTVALUE, WideStr);
1057 } else {
1058 Field::SetDefaultValue(m_pDocument, m_FieldName, m_nFormControlIndex,
1059 WideStr);
1060 }
1061 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001062 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1063 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001064 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001065
Lei Zhangd88a3642015-11-10 09:38:57 -08001066 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001067 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON ||
Lei Zhangd88a3642015-11-10 09:38:57 -08001068 pFormField->GetFieldType() == FIELDTYPE_SIGNATURE) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001069 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001070 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001071
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001072 vp << pFormField->GetDefaultValue();
1073 }
1074 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001075}
1076
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001077void Field::SetDefaultValue(CPDFSDK_Document* pDocument,
1078 const CFX_WideString& swFieldName,
1079 int nControlIndex,
1080 const CFX_WideString& string) {
1081 // Not supported.
1082}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001083
Tom Sepezba038bc2015-10-08 12:03:00 -07001084FX_BOOL Field::doNotScroll(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001085 CJS_PropValue& vp,
1086 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08001087 ASSERT(m_pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001088
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001089 if (vp.IsSetting()) {
1090 if (!m_bCanSet)
1091 return FALSE;
1092
1093 bool bVP;
1094 vp >> bVP;
1095
1096 if (m_bDelay) {
1097 AddDelay_Bool(FP_DONOTSCROLL, bVP);
1098 } else {
1099 Field::SetDoNotScroll(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
1100 }
1101 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001102 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1103 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001104 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001105
Lei Zhangd88a3642015-11-10 09:38:57 -08001106 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001107 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1108 return FALSE;
1109
1110 if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL)
1111 vp << true;
1112 else
1113 vp << false;
1114 }
1115
1116 return TRUE;
1117}
1118
1119void Field::SetDoNotScroll(CPDFSDK_Document* pDocument,
1120 const CFX_WideString& swFieldName,
1121 int nControlIndex,
1122 bool b) {
1123 // Not supported.
1124}
1125
Tom Sepezba038bc2015-10-08 12:03:00 -07001126FX_BOOL Field::doNotSpellCheck(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001127 CJS_PropValue& vp,
1128 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08001129 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001130
1131 if (vp.IsSetting()) {
1132 if (!m_bCanSet)
1133 return FALSE;
1134
1135 bool bVP;
1136 vp >> bVP;
1137 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001138 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1139 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001140 return FALSE;
1141
Lei Zhangd88a3642015-11-10 09:38:57 -08001142 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001143 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001144 pFormField->GetFieldType() != FIELDTYPE_COMBOBOX) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001145 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001146 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001147
1148 if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK)
1149 vp << true;
1150 else
1151 vp << false;
1152 }
1153
1154 return TRUE;
1155}
1156
1157void Field::SetDelay(FX_BOOL bDelay) {
1158 m_bDelay = bDelay;
1159
1160 if (!m_bDelay) {
1161 if (m_pJSDoc)
1162 m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex);
1163 }
1164}
1165
Tom Sepezba038bc2015-10-08 12:03:00 -07001166FX_BOOL Field::delay(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001167 CJS_PropValue& vp,
1168 CFX_WideString& sError) {
1169 if (vp.IsSetting()) {
1170 if (!m_bCanSet)
1171 return FALSE;
1172
1173 bool bVP;
1174 vp >> bVP;
1175
1176 SetDelay(bVP);
1177 } else {
1178 vp << m_bDelay;
1179 }
1180 return TRUE;
1181}
1182
Tom Sepezba038bc2015-10-08 12:03:00 -07001183FX_BOOL Field::display(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001184 CJS_PropValue& vp,
1185 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001186 if (vp.IsSetting()) {
1187 if (!m_bCanSet)
1188 return FALSE;
1189
1190 int nVP;
1191 vp >> nVP;
1192
1193 if (m_bDelay) {
1194 AddDelay_Int(FP_DISPLAY, nVP);
1195 } else {
1196 Field::SetDisplay(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
1197 }
1198 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001199 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1200 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001201 return FALSE;
1202
Lei Zhangd88a3642015-11-10 09:38:57 -08001203 CPDF_FormField* pFormField = FieldArray[0];
1204 ASSERT(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001205 CPDFSDK_InterForm* pInterForm =
1206 (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001207 CPDFSDK_Widget* pWidget =
1208 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1209 if (!pWidget)
1210 return FALSE;
1211
1212 FX_DWORD dwFlag = pWidget->GetFlags();
1213
1214 if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag) {
1215 vp << (int32_t)1;
1216 } else {
1217 if (ANNOTFLAG_PRINT & dwFlag) {
1218 if (ANNOTFLAG_NOVIEW & dwFlag) {
1219 vp << (int32_t)3;
1220 } else {
1221 vp << (int32_t)0;
1222 }
1223 } else {
1224 vp << (int32_t)2;
1225 }
1226 }
1227 }
1228
1229 return TRUE;
1230}
1231
1232void Field::SetDisplay(CPDFSDK_Document* pDocument,
1233 const CFX_WideString& swFieldName,
1234 int nControlIndex,
1235 int number) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001236 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001237 std::vector<CPDF_FormField*> FieldArray =
1238 GetFormFields(pDocument, swFieldName);
1239 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001240 if (nControlIndex < 0) {
1241 FX_BOOL bSet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001242 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1243 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08001244 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001245
1246 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1247 FX_DWORD dwFlag = pWidget->GetFlags();
1248 switch (number) {
1249 case 0:
1250 dwFlag &= (~ANNOTFLAG_INVISIBLE);
1251 dwFlag &= (~ANNOTFLAG_HIDDEN);
1252 dwFlag &= (~ANNOTFLAG_NOVIEW);
1253 dwFlag |= ANNOTFLAG_PRINT;
1254 break;
1255 case 1:
1256 dwFlag &= (~ANNOTFLAG_INVISIBLE);
1257 dwFlag &= (~ANNOTFLAG_NOVIEW);
1258 dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
1259 break;
1260 case 2:
1261 dwFlag &= (~ANNOTFLAG_INVISIBLE);
1262 dwFlag &= (~ANNOTFLAG_PRINT);
1263 dwFlag &= (~ANNOTFLAG_HIDDEN);
1264 dwFlag &= (~ANNOTFLAG_NOVIEW);
1265 break;
1266 case 3:
1267 dwFlag |= ANNOTFLAG_NOVIEW;
1268 dwFlag |= ANNOTFLAG_PRINT;
1269 dwFlag &= (~ANNOTFLAG_HIDDEN);
1270 break;
1271 }
1272
1273 if (dwFlag != pWidget->GetFlags()) {
1274 pWidget->SetFlags(dwFlag);
1275 bSet = TRUE;
1276 }
1277 }
1278 }
1279
1280 if (bSet)
1281 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
1282 } else {
1283 if (nControlIndex >= pFormField->CountControls())
1284 return;
1285 if (CPDF_FormControl* pFormControl =
1286 pFormField->GetControl(nControlIndex)) {
1287 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1288 FX_DWORD dwFlag = pWidget->GetFlags();
1289 switch (number) {
1290 case 0:
1291 dwFlag &= (~ANNOTFLAG_INVISIBLE);
1292 dwFlag &= (~ANNOTFLAG_HIDDEN);
1293 dwFlag &= (~ANNOTFLAG_NOVIEW);
1294 dwFlag |= ANNOTFLAG_PRINT;
1295 break;
1296 case 1:
1297 dwFlag &= (~ANNOTFLAG_INVISIBLE);
1298 dwFlag &= (~ANNOTFLAG_NOVIEW);
1299 dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
1300 break;
1301 case 2:
1302 dwFlag &= (~ANNOTFLAG_INVISIBLE);
1303 dwFlag &= (~ANNOTFLAG_PRINT);
1304 dwFlag &= (~ANNOTFLAG_HIDDEN);
1305 dwFlag &= (~ANNOTFLAG_NOVIEW);
1306 break;
1307 case 3:
1308 dwFlag |= ANNOTFLAG_NOVIEW;
1309 dwFlag |= ANNOTFLAG_PRINT;
1310 dwFlag &= (~ANNOTFLAG_HIDDEN);
1311 break;
1312 }
1313 if (dwFlag != pWidget->GetFlags()) {
1314 pWidget->SetFlags(dwFlag);
1315 UpdateFormControl(pDocument, pFormControl, TRUE, FALSE, TRUE);
1316 }
1317 }
1318 }
1319 }
1320 }
1321}
1322
Tom Sepezba038bc2015-10-08 12:03:00 -07001323FX_BOOL Field::doc(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001324 if (!vp.IsGetting()) {
1325 return FALSE;
1326 }
1327 vp << m_pJSDoc->GetCJSDoc();
1328 return TRUE;
1329}
1330
Tom Sepezba038bc2015-10-08 12:03:00 -07001331FX_BOOL Field::editable(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001332 CJS_PropValue& vp,
1333 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001334 if (vp.IsSetting()) {
1335 if (!m_bCanSet)
1336 return FALSE;
1337
1338 bool bVP;
1339 vp >> bVP;
1340 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001341 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1342 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001343 return FALSE;
1344
Lei Zhangd88a3642015-11-10 09:38:57 -08001345 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001346 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX)
1347 return FALSE;
1348
1349 if (pFormField->GetFieldFlags() & FIELDFLAG_EDIT)
1350 vp << true;
1351 else
1352 vp << false;
1353 }
1354
1355 return TRUE;
1356}
1357
Tom Sepezba038bc2015-10-08 12:03:00 -07001358FX_BOOL Field::exportValues(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001359 CJS_PropValue& vp,
1360 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001361 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1362 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001363 return FALSE;
1364
Lei Zhangd88a3642015-11-10 09:38:57 -08001365 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001366 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001367 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001368 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001369 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001370
1371 if (vp.IsSetting()) {
1372 if (!m_bCanSet)
1373 return FALSE;
1374
1375 if (!vp.IsArrayObject())
1376 return FALSE;
1377 } else {
Tom Sepez67fd5df2015-10-08 12:24:19 -07001378 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
1379 CJS_Array ExportValusArray(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001380 if (m_nFormControlIndex < 0) {
1381 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
1382 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
1383 ExportValusArray.SetElement(
Tom Sepez67fd5df2015-10-08 12:24:19 -07001384 i, CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001385 }
1386 } else {
1387 if (m_nFormControlIndex >= pFormField->CountControls())
1388 return FALSE;
1389
1390 CPDF_FormControl* pFormControl =
1391 pFormField->GetControl(m_nFormControlIndex);
1392 if (!pFormControl)
1393 return FALSE;
1394
1395 ExportValusArray.SetElement(
Tom Sepez67fd5df2015-10-08 12:24:19 -07001396 0, CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001397 }
1398 vp << ExportValusArray;
1399 }
1400 return TRUE;
1401}
1402
Tom Sepezba038bc2015-10-08 12:03:00 -07001403FX_BOOL Field::fileSelect(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001404 CJS_PropValue& vp,
1405 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001406 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1407 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001408 return FALSE;
1409
Lei Zhangd88a3642015-11-10 09:38:57 -08001410 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001411 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1412 return FALSE;
1413
1414 if (vp.IsSetting()) {
1415 if (!m_bCanSet)
1416 return FALSE;
1417
1418 bool bVP;
1419 vp >> bVP;
1420 } else {
1421 if (pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT)
1422 vp << true;
1423 else
1424 vp << false;
1425 }
1426 return TRUE;
1427}
1428
Tom Sepezba038bc2015-10-08 12:03:00 -07001429FX_BOOL Field::fillColor(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001430 CJS_PropValue& vp,
1431 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07001432 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
1433 CJS_Array crArray(pRuntime);
Lei Zhangd88a3642015-11-10 09:38:57 -08001434 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1435 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001436 return FALSE;
1437
1438 if (vp.IsSetting()) {
1439 if (!m_bCanSet)
1440 return FALSE;
1441
1442 if (!vp.IsArrayObject())
1443 return FALSE;
1444
1445 vp >> crArray;
1446
1447 CPWL_Color color;
1448 color::ConvertArrayToPWLColor(crArray, color);
1449 if (m_bDelay) {
1450 AddDelay_Color(FP_FILLCOLOR, color);
1451 } else {
1452 Field::SetFillColor(m_pDocument, m_FieldName, m_nFormControlIndex, color);
1453 }
1454 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001455 CPDF_FormField* pFormField = FieldArray[0];
1456 ASSERT(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001457 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1458 if (!pFormControl)
1459 return FALSE;
1460
1461 int iColorType;
1462 pFormControl->GetBackgroundColor(iColorType);
1463
1464 CPWL_Color color;
1465 if (iColorType == COLORTYPE_TRANSPARENT) {
1466 color = CPWL_Color(COLORTYPE_TRANSPARENT);
1467 } else if (iColorType == COLORTYPE_GRAY) {
1468 color = CPWL_Color(COLORTYPE_GRAY,
1469 pFormControl->GetOriginalBackgroundColor(0));
1470 } else if (iColorType == COLORTYPE_RGB) {
1471 color =
1472 CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBackgroundColor(0),
1473 pFormControl->GetOriginalBackgroundColor(1),
1474 pFormControl->GetOriginalBackgroundColor(2));
1475 } else if (iColorType == COLORTYPE_CMYK) {
1476 color = CPWL_Color(COLORTYPE_CMYK,
1477 pFormControl->GetOriginalBackgroundColor(0),
1478 pFormControl->GetOriginalBackgroundColor(1),
1479 pFormControl->GetOriginalBackgroundColor(2),
1480 pFormControl->GetOriginalBackgroundColor(3));
Lei Zhangd88a3642015-11-10 09:38:57 -08001481 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001482 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001483 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001484
1485 color::ConvertPWLColorToArray(color, crArray);
1486 vp << crArray;
1487 }
1488
1489 return TRUE;
1490}
1491
1492void Field::SetFillColor(CPDFSDK_Document* pDocument,
1493 const CFX_WideString& swFieldName,
1494 int nControlIndex,
1495 const CPWL_Color& color) {
1496 // Not supported.
1497}
1498
Tom Sepezba038bc2015-10-08 12:03:00 -07001499FX_BOOL Field::hidden(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001500 CJS_PropValue& vp,
1501 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001502 if (vp.IsSetting()) {
1503 if (!m_bCanSet)
1504 return FALSE;
1505
1506 bool bVP;
1507 vp >> bVP;
1508
1509 if (m_bDelay) {
1510 AddDelay_Bool(FP_HIDDEN, bVP);
1511 } else {
1512 Field::SetHidden(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
1513 }
1514 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001515 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1516 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001517 return FALSE;
1518
Lei Zhangd88a3642015-11-10 09:38:57 -08001519 CPDF_FormField* pFormField = FieldArray[0];
1520 ASSERT(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001521 CPDFSDK_InterForm* pInterForm =
1522 (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001523 CPDFSDK_Widget* pWidget =
1524 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1525 if (!pWidget)
1526 return FALSE;
1527
1528 FX_DWORD dwFlags = pWidget->GetFlags();
1529
Lei Zhangd88a3642015-11-10 09:38:57 -08001530 if (ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001531 vp << true;
Lei Zhangd88a3642015-11-10 09:38:57 -08001532 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001533 vp << false;
1534 }
1535
1536 return TRUE;
1537}
1538
1539void Field::SetHidden(CPDFSDK_Document* pDocument,
1540 const CFX_WideString& swFieldName,
1541 int nControlIndex,
1542 bool b) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001543 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001544 std::vector<CPDF_FormField*> FieldArray =
1545 GetFormFields(pDocument, swFieldName);
1546 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001547 if (nControlIndex < 0) {
1548 FX_BOOL bSet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001549 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001550 if (CPDFSDK_Widget* pWidget =
Lei Zhangd88a3642015-11-10 09:38:57 -08001551 pInterForm->GetWidget(pFormField->GetControl(i))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001552 FX_DWORD dwFlags = pWidget->GetFlags();
1553
1554 if (b) {
1555 dwFlags &= (~ANNOTFLAG_INVISIBLE);
1556 dwFlags &= (~ANNOTFLAG_NOVIEW);
1557 dwFlags |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
1558 } else {
1559 dwFlags &= (~ANNOTFLAG_INVISIBLE);
1560 dwFlags &= (~ANNOTFLAG_HIDDEN);
1561 dwFlags &= (~ANNOTFLAG_NOVIEW);
1562 dwFlags |= ANNOTFLAG_PRINT;
1563 }
1564
1565 if (dwFlags != pWidget->GetFlags()) {
1566 pWidget->SetFlags(dwFlags);
1567 bSet = TRUE;
1568 }
1569 }
1570 }
1571
1572 if (bSet)
1573 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
1574 } else {
1575 if (nControlIndex >= pFormField->CountControls())
1576 return;
1577 if (CPDF_FormControl* pFormControl =
1578 pFormField->GetControl(nControlIndex)) {
1579 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1580 FX_DWORD dwFlags = pWidget->GetFlags();
1581
1582 if (b) {
1583 dwFlags &= (~ANNOTFLAG_INVISIBLE);
1584 dwFlags &= (~ANNOTFLAG_NOVIEW);
1585 dwFlags |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
1586 } else {
1587 dwFlags &= (~ANNOTFLAG_INVISIBLE);
1588 dwFlags &= (~ANNOTFLAG_HIDDEN);
1589 dwFlags &= (~ANNOTFLAG_NOVIEW);
1590 dwFlags |= ANNOTFLAG_PRINT;
1591 }
1592
1593 if (dwFlags != pWidget->GetFlags()) {
1594 pWidget->SetFlags(dwFlags);
1595 UpdateFormControl(pDocument, pFormControl, TRUE, FALSE, TRUE);
1596 }
1597 }
1598 }
1599 }
1600 }
1601}
1602
Tom Sepezba038bc2015-10-08 12:03:00 -07001603FX_BOOL Field::highlight(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001604 CJS_PropValue& vp,
1605 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08001606 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001607
1608 if (vp.IsSetting()) {
1609 if (!m_bCanSet)
1610 return FALSE;
1611
1612 CFX_ByteString strMode;
1613 vp >> strMode;
1614
1615 if (m_bDelay) {
1616 AddDelay_String(FP_HIGHLIGHT, strMode);
1617 } else {
1618 Field::SetHighlight(m_pDocument, m_FieldName, m_nFormControlIndex,
1619 strMode);
1620 }
1621 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001622 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1623 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001624 return FALSE;
1625
Lei Zhangd88a3642015-11-10 09:38:57 -08001626 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001627 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
1628 return FALSE;
1629
1630 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1631 if (!pFormControl)
1632 return FALSE;
1633
1634 int eHM = pFormControl->GetHighlightingMode();
1635 switch (eHM) {
1636 case CPDF_FormControl::None:
1637 vp << L"none";
1638 break;
1639 case CPDF_FormControl::Push:
1640 vp << L"push";
1641 break;
1642 case CPDF_FormControl::Invert:
1643 vp << L"invert";
1644 break;
1645 case CPDF_FormControl::Outline:
1646 vp << L"outline";
1647 break;
1648 case CPDF_FormControl::Toggle:
1649 vp << L"toggle";
1650 break;
1651 }
1652 }
1653
1654 return TRUE;
1655}
1656
1657void Field::SetHighlight(CPDFSDK_Document* pDocument,
1658 const CFX_WideString& swFieldName,
1659 int nControlIndex,
1660 const CFX_ByteString& string) {
1661 // Not supported.
1662}
1663
Tom Sepezba038bc2015-10-08 12:03:00 -07001664FX_BOOL Field::lineWidth(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001665 CJS_PropValue& vp,
1666 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001667 if (vp.IsSetting()) {
1668 if (!m_bCanSet)
1669 return FALSE;
1670
1671 int iWidth;
1672 vp >> iWidth;
1673
1674 if (m_bDelay) {
1675 AddDelay_Int(FP_LINEWIDTH, iWidth);
1676 } else {
1677 Field::SetLineWidth(m_pDocument, m_FieldName, m_nFormControlIndex,
1678 iWidth);
1679 }
1680 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001681 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1682 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001683 return FALSE;
1684
Lei Zhangd88a3642015-11-10 09:38:57 -08001685 CPDF_FormField* pFormField = FieldArray[0];
1686 ASSERT(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001687 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1688 if (!pFormControl)
1689 return FALSE;
1690
1691 CPDFSDK_InterForm* pInterForm =
1692 (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001693 if (!pFormField->CountControls())
1694 return FALSE;
1695
1696 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
1697 if (!pWidget)
1698 return FALSE;
1699
1700 vp << (int32_t)pWidget->GetBorderWidth();
1701 }
1702
1703 return TRUE;
1704}
1705
1706void Field::SetLineWidth(CPDFSDK_Document* pDocument,
1707 const CFX_WideString& swFieldName,
1708 int nControlIndex,
1709 int number) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001710 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001711
Lei Zhangd88a3642015-11-10 09:38:57 -08001712 std::vector<CPDF_FormField*> FieldArray =
1713 GetFormFields(pDocument, swFieldName);
1714 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001715 if (nControlIndex < 0) {
1716 FX_BOOL bSet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001717 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1718 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08001719 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001720
1721 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1722 if (number != pWidget->GetBorderWidth()) {
1723 pWidget->SetBorderWidth(number);
1724 bSet = TRUE;
1725 }
1726 }
1727 }
1728 if (bSet)
1729 UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
1730 } else {
1731 if (nControlIndex >= pFormField->CountControls())
1732 return;
1733 if (CPDF_FormControl* pFormControl =
1734 pFormField->GetControl(nControlIndex)) {
1735 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1736 if (number != pWidget->GetBorderWidth()) {
1737 pWidget->SetBorderWidth(number);
1738 UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
1739 }
1740 }
1741 }
1742 }
1743 }
1744}
1745
Tom Sepezba038bc2015-10-08 12:03:00 -07001746FX_BOOL Field::multiline(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001747 CJS_PropValue& vp,
1748 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08001749 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001750
1751 if (vp.IsSetting()) {
1752 if (!m_bCanSet)
1753 return FALSE;
1754
1755 bool bVP;
1756 vp >> bVP;
1757
1758 if (m_bDelay) {
1759 AddDelay_Bool(FP_MULTILINE, bVP);
1760 } else {
1761 Field::SetMultiline(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
1762 }
1763 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001764 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1765 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001766 return FALSE;
1767
Lei Zhangd88a3642015-11-10 09:38:57 -08001768 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001769 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1770 return FALSE;
1771
1772 if (pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE)
1773 vp << true;
1774 else
1775 vp << false;
1776 }
1777
1778 return TRUE;
1779}
1780
1781void Field::SetMultiline(CPDFSDK_Document* pDocument,
1782 const CFX_WideString& swFieldName,
1783 int nControlIndex,
1784 bool b) {
1785 // Not supported.
1786}
1787
Tom Sepezba038bc2015-10-08 12:03:00 -07001788FX_BOOL Field::multipleSelection(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001789 CJS_PropValue& vp,
1790 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08001791 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001792
1793 if (vp.IsSetting()) {
1794 if (!m_bCanSet)
1795 return FALSE;
1796
1797 bool bVP;
1798 vp >> bVP;
1799
1800 if (m_bDelay) {
1801 AddDelay_Bool(FP_MULTIPLESELECTION, bVP);
1802 } else {
1803 Field::SetMultipleSelection(m_pDocument, m_FieldName, m_nFormControlIndex,
1804 bVP);
1805 }
1806 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001807 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1808 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001809 return FALSE;
1810
Lei Zhangd88a3642015-11-10 09:38:57 -08001811 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001812 if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
1813 return FALSE;
1814
1815 if (pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT)
1816 vp << true;
1817 else
1818 vp << false;
1819 }
1820
1821 return TRUE;
1822}
1823
1824void Field::SetMultipleSelection(CPDFSDK_Document* pDocument,
1825 const CFX_WideString& swFieldName,
1826 int nControlIndex,
1827 bool b) {
1828 // Not supported.
1829}
1830
Tom Sepezba038bc2015-10-08 12:03:00 -07001831FX_BOOL Field::name(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001832 CJS_PropValue& vp,
1833 CFX_WideString& sError) {
1834 if (!vp.IsGetting())
1835 return FALSE;
1836
Lei Zhangd88a3642015-11-10 09:38:57 -08001837 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1838 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001839 return FALSE;
1840
1841 vp << m_FieldName;
1842
1843 return TRUE;
1844}
1845
Tom Sepezba038bc2015-10-08 12:03:00 -07001846FX_BOOL Field::numItems(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001847 CJS_PropValue& vp,
1848 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07001849 if (!vp.IsGetting())
1850 return FALSE;
1851
Lei Zhangd88a3642015-11-10 09:38:57 -08001852 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1853 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001854 return FALSE;
1855
Lei Zhangd88a3642015-11-10 09:38:57 -08001856 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001857 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001858 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001859 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001860 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001861
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001862 vp << (int32_t)pFormField->CountOptions();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001863 return TRUE;
1864}
1865
Tom Sepezba038bc2015-10-08 12:03:00 -07001866FX_BOOL Field::page(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001867 CJS_PropValue& vp,
1868 CFX_WideString& sError) {
1869 if (!vp.IsGetting())
1870 return FALSE;
1871
Lei Zhangd88a3642015-11-10 09:38:57 -08001872 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1873 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001874 return FALSE;
1875
Lei Zhangd88a3642015-11-10 09:38:57 -08001876 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001877 if (!pFormField)
1878 return FALSE;
1879
Lei Zhangd88a3642015-11-10 09:38:57 -08001880 std::vector<CPDFSDK_Widget*> widgets;
1881 m_pDocument->GetInterForm()->GetWidgets(pFormField, &widgets);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001882
Lei Zhangd88a3642015-11-10 09:38:57 -08001883 if (widgets.empty()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001884 vp << (int32_t)-1;
Lei Zhangd88a3642015-11-10 09:38:57 -08001885 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001886 }
1887
Lei Zhangd88a3642015-11-10 09:38:57 -08001888 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
1889 CJS_Array PageArray(pRuntime);
1890 for (size_t i = 0; i < widgets.size(); ++i) {
1891 CPDFSDK_PageView* pPageView = widgets[i]->GetPageView();
1892 if (!pPageView)
1893 return FALSE;
1894
1895 PageArray.SetElement(
1896 i, CJS_Value(pRuntime, (int32_t)pPageView->GetPageIndex()));
1897 }
1898
1899 vp << PageArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001900 return TRUE;
1901}
1902
Tom Sepezba038bc2015-10-08 12:03:00 -07001903FX_BOOL Field::password(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001904 CJS_PropValue& vp,
1905 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08001906 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001907
1908 if (vp.IsSetting()) {
1909 if (!m_bCanSet)
1910 return FALSE;
1911
1912 bool bVP;
1913 vp >> bVP;
1914
1915 if (m_bDelay) {
1916 AddDelay_Bool(FP_PASSWORD, bVP);
1917 } else {
1918 Field::SetPassword(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
1919 }
1920 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001921 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1922 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001923 return FALSE;
1924
Lei Zhangd88a3642015-11-10 09:38:57 -08001925 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001926 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1927 return FALSE;
1928
1929 if (pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD)
1930 vp << true;
1931 else
1932 vp << false;
1933 }
1934
1935 return TRUE;
1936}
1937
1938void Field::SetPassword(CPDFSDK_Document* pDocument,
1939 const CFX_WideString& swFieldName,
1940 int nControlIndex,
1941 bool b) {
1942 // Not supported.
1943}
1944
Tom Sepezba038bc2015-10-08 12:03:00 -07001945FX_BOOL Field::print(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001946 CJS_PropValue& vp,
1947 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001948 CPDFSDK_InterForm* pInterForm =
1949 (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -08001950 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1951 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001952 return FALSE;
1953
1954 if (vp.IsSetting()) {
1955 if (!m_bCanSet)
1956 return FALSE;
1957
1958 bool bVP;
1959 vp >> bVP;
1960
Lei Zhangd88a3642015-11-10 09:38:57 -08001961 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001962 if (m_nFormControlIndex < 0) {
1963 FX_BOOL bSet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001964 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001965 if (CPDFSDK_Widget* pWidget =
Lei Zhangd88a3642015-11-10 09:38:57 -08001966 pInterForm->GetWidget(pFormField->GetControl(i))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001967 FX_DWORD dwFlags = pWidget->GetFlags();
1968 if (bVP)
1969 dwFlags |= ANNOTFLAG_PRINT;
1970 else
1971 dwFlags &= ~ANNOTFLAG_PRINT;
1972
1973 if (dwFlags != pWidget->GetFlags()) {
1974 pWidget->SetFlags(dwFlags);
1975 bSet = TRUE;
1976 }
1977 }
1978 }
1979
1980 if (bSet)
1981 UpdateFormField(m_pDocument, pFormField, TRUE, FALSE, TRUE);
1982 } else {
1983 if (m_nFormControlIndex >= pFormField->CountControls())
1984 return FALSE;
1985 if (CPDF_FormControl* pFormControl =
1986 pFormField->GetControl(m_nFormControlIndex)) {
1987 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1988 FX_DWORD dwFlags = pWidget->GetFlags();
1989 if (bVP)
1990 dwFlags |= ANNOTFLAG_PRINT;
1991 else
1992 dwFlags &= ~ANNOTFLAG_PRINT;
1993
1994 if (dwFlags != pWidget->GetFlags()) {
1995 pWidget->SetFlags(dwFlags);
1996 UpdateFormControl(m_pDocument,
1997 pFormField->GetControl(m_nFormControlIndex),
1998 TRUE, FALSE, TRUE);
1999 }
2000 }
2001 }
2002 }
2003 }
2004 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002005 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002006 CPDFSDK_Widget* pWidget =
2007 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
2008 if (!pWidget)
2009 return FALSE;
2010
2011 if (pWidget->GetFlags() & ANNOTFLAG_PRINT)
2012 vp << true;
2013 else
2014 vp << false;
2015 }
2016
2017 return TRUE;
2018}
2019
Tom Sepezba038bc2015-10-08 12:03:00 -07002020FX_BOOL Field::radiosInUnison(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002021 CJS_PropValue& vp,
2022 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002023 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2024 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002025 return FALSE;
2026
2027 if (vp.IsSetting()) {
2028 if (!m_bCanSet)
2029 return FALSE;
2030
2031 bool bVP;
2032 vp >> bVP;
2033
2034 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002035 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002036 if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
2037 return FALSE;
2038
2039 if (pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)
2040 vp << true;
2041 else
2042 vp << false;
2043 }
2044
2045 return TRUE;
2046}
2047
Tom Sepezba038bc2015-10-08 12:03:00 -07002048FX_BOOL Field::readonly(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002049 CJS_PropValue& vp,
2050 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002051 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2052 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002053 return FALSE;
2054
2055 if (vp.IsSetting()) {
2056 if (!m_bCanSet)
2057 return FALSE;
2058
2059 bool bVP;
2060 vp >> bVP;
2061
2062 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002063 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002064 if (pFormField->GetFieldFlags() & FIELDFLAG_READONLY)
2065 vp << true;
2066 else
2067 vp << false;
2068 }
2069
2070 return TRUE;
2071}
2072
Tom Sepezba038bc2015-10-08 12:03:00 -07002073FX_BOOL Field::rect(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002074 CJS_PropValue& vp,
2075 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002076 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
2077 CJS_Value Upper_Leftx(pRuntime);
2078 CJS_Value Upper_Lefty(pRuntime);
2079 CJS_Value Lower_Rightx(pRuntime);
2080 CJS_Value Lower_Righty(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002081
2082 if (vp.IsSetting()) {
2083 if (!m_bCanSet)
2084 return FALSE;
2085 if (!vp.IsArrayObject())
2086 return FALSE;
2087
Tom Sepez67fd5df2015-10-08 12:24:19 -07002088 CJS_Array rcArray(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002089 vp >> rcArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002090 rcArray.GetElement(0, Upper_Leftx);
2091 rcArray.GetElement(1, Upper_Lefty);
2092 rcArray.GetElement(2, Lower_Rightx);
2093 rcArray.GetElement(3, Lower_Righty);
2094
2095 FX_FLOAT pArray[4] = {0.0f, 0.0f, 0.0f, 0.0f};
2096 pArray[0] = (FX_FLOAT)Upper_Leftx.ToInt();
2097 pArray[1] = (FX_FLOAT)Lower_Righty.ToInt();
2098 pArray[2] = (FX_FLOAT)Lower_Rightx.ToInt();
2099 pArray[3] = (FX_FLOAT)Upper_Lefty.ToInt();
2100
Tom Sepez281a9ea2016-02-26 14:24:28 -08002101 CFX_FloatRect crRect(pArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002102 if (m_bDelay) {
2103 AddDelay_Rect(FP_RECT, crRect);
2104 } else {
2105 Field::SetRect(m_pDocument, m_FieldName, m_nFormControlIndex, crRect);
2106 }
2107 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002108 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2109 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002110 return FALSE;
2111
Lei Zhangd88a3642015-11-10 09:38:57 -08002112 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002113 CPDFSDK_InterForm* pInterForm =
2114 (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002115 CPDFSDK_Widget* pWidget =
2116 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
2117 if (!pWidget)
2118 return FALSE;
2119
2120 CFX_FloatRect crRect = pWidget->GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002121 Upper_Leftx = (int32_t)crRect.left;
2122 Upper_Lefty = (int32_t)crRect.top;
2123 Lower_Rightx = (int32_t)crRect.right;
2124 Lower_Righty = (int32_t)crRect.bottom;
2125
Tom Sepez67fd5df2015-10-08 12:24:19 -07002126 CJS_Array rcArray(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002127 rcArray.SetElement(0, Upper_Leftx);
2128 rcArray.SetElement(1, Upper_Lefty);
2129 rcArray.SetElement(2, Lower_Rightx);
2130 rcArray.SetElement(3, Lower_Righty);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002131 vp << rcArray;
2132 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002133 return TRUE;
2134}
2135
2136void Field::SetRect(CPDFSDK_Document* pDocument,
2137 const CFX_WideString& swFieldName,
2138 int nControlIndex,
Tom Sepez281a9ea2016-02-26 14:24:28 -08002139 const CFX_FloatRect& rect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002140 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002141
Lei Zhangd88a3642015-11-10 09:38:57 -08002142 std::vector<CPDF_FormField*> FieldArray =
2143 GetFormFields(pDocument, swFieldName);
2144 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002145 if (nControlIndex < 0) {
2146 FX_BOOL bSet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08002147 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002148 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Lei Zhang96660d62015-12-14 18:27:25 -08002149 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002150
2151 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002152 CFX_FloatRect crRect = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002153
2154 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002155 crRect.Intersect(pPDFPage->GetPageBBox());
2156
2157 if (!crRect.IsEmpty()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002158 CFX_FloatRect rcOld = pWidget->GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002159 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
2160 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
2161 pWidget->SetRect(crRect);
2162 bSet = TRUE;
2163 }
2164 }
2165 }
2166 }
2167
2168 if (bSet)
2169 UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
2170 } else {
2171 if (nControlIndex >= pFormField->CountControls())
2172 return;
2173 if (CPDF_FormControl* pFormControl =
2174 pFormField->GetControl(nControlIndex)) {
2175 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002176 CFX_FloatRect crRect = rect;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002177
2178 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002179 crRect.Intersect(pPDFPage->GetPageBBox());
2180
2181 if (!crRect.IsEmpty()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002182 CFX_FloatRect rcOld = pWidget->GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002183 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
2184 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
2185 pWidget->SetRect(crRect);
2186 UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
2187 }
2188 }
2189 }
2190 }
2191 }
2192 }
2193}
2194
Tom Sepezba038bc2015-10-08 12:03:00 -07002195FX_BOOL Field::required(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002196 CJS_PropValue& vp,
2197 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002198 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2199 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002200 return FALSE;
2201
2202 if (vp.IsSetting()) {
2203 if (!m_bCanSet)
2204 return FALSE;
2205
2206 bool bVP;
2207 vp >> bVP;
2208
2209 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002210 CPDF_FormField* pFormField = FieldArray[0];
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002211 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002212 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002213
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002214 if (pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED)
2215 vp << true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002216 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002217 vp << false;
2218 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002219
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002220 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002221}
2222
Tom Sepezba038bc2015-10-08 12:03:00 -07002223FX_BOOL Field::richText(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002224 CJS_PropValue& vp,
2225 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08002226 ASSERT(m_pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002227
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002228 if (vp.IsSetting()) {
2229 if (!m_bCanSet)
2230 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002231
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002232 bool bVP;
2233 vp >> bVP;
2234
2235 if (m_bDelay) {
2236 AddDelay_Bool(FP_RICHTEXT, bVP);
2237 } else {
2238 Field::SetRichText(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
2239 }
2240 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002241 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2242 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002243 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002244
Lei Zhangd88a3642015-11-10 09:38:57 -08002245 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002246 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
2247 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002248
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002249 if (pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT)
2250 vp << true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002251 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002252 vp << false;
2253 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002254
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002255 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002256}
2257
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002258void Field::SetRichText(CPDFSDK_Document* pDocument,
2259 const CFX_WideString& swFieldName,
2260 int nControlIndex,
2261 bool b) {
2262 // Not supported.
2263}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002264
Tom Sepezba038bc2015-10-08 12:03:00 -07002265FX_BOOL Field::richValue(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002266 CJS_PropValue& vp,
2267 CFX_WideString& sError) {
2268 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002269}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002270
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002271void Field::SetRichValue(CPDFSDK_Document* pDocument,
2272 const CFX_WideString& swFieldName,
2273 int nControlIndex) {
2274 // Not supported.
2275}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002276
Tom Sepezba038bc2015-10-08 12:03:00 -07002277FX_BOOL Field::rotation(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002278 CJS_PropValue& vp,
2279 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08002280 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002281
2282 if (vp.IsSetting()) {
2283 if (!m_bCanSet)
2284 return FALSE;
2285
2286 int nVP;
2287 vp >> nVP;
2288
2289 if (m_bDelay) {
2290 AddDelay_Int(FP_ROTATION, nVP);
2291 } else {
2292 Field::SetRotation(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
2293 }
2294 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002295 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2296 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002297 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002298
Lei Zhangd88a3642015-11-10 09:38:57 -08002299 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002300 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2301 if (!pFormControl)
2302 return FALSE;
2303
2304 vp << (int32_t)pFormControl->GetRotation();
2305 }
2306
2307 return TRUE;
2308}
2309
2310void Field::SetRotation(CPDFSDK_Document* pDocument,
2311 const CFX_WideString& swFieldName,
2312 int nControlIndex,
2313 int number) {
2314 // Not supported.
2315}
2316
Tom Sepezba038bc2015-10-08 12:03:00 -07002317FX_BOOL Field::strokeColor(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002318 CJS_PropValue& vp,
2319 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002320 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
2321 CJS_Array crArray(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002322
2323 if (vp.IsSetting()) {
2324 if (!m_bCanSet)
2325 return FALSE;
2326
2327 if (!vp.IsArrayObject())
2328 return FALSE;
2329
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002330 vp >> crArray;
2331
2332 CPWL_Color color;
2333 color::ConvertArrayToPWLColor(crArray, color);
2334
2335 if (m_bDelay) {
2336 AddDelay_Color(FP_STROKECOLOR, color);
2337 } else {
2338 Field::SetStrokeColor(m_pDocument, m_FieldName, m_nFormControlIndex,
2339 color);
2340 }
2341 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002342 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2343 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002344 return FALSE;
2345
Lei Zhangd88a3642015-11-10 09:38:57 -08002346 CPDF_FormField* pFormField = FieldArray[0];
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002347 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002348 if (!pFormControl)
2349 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002350
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002351 int iColorType;
2352 pFormControl->GetBorderColor(iColorType);
2353
2354 CPWL_Color color;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002355 if (iColorType == COLORTYPE_TRANSPARENT) {
2356 color = CPWL_Color(COLORTYPE_TRANSPARENT);
2357 } else if (iColorType == COLORTYPE_GRAY) {
2358 color =
2359 CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBorderColor(0));
2360 } else if (iColorType == COLORTYPE_RGB) {
2361 color = CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBorderColor(0),
2362 pFormControl->GetOriginalBorderColor(1),
2363 pFormControl->GetOriginalBorderColor(2));
2364 } else if (iColorType == COLORTYPE_CMYK) {
2365 color =
2366 CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBorderColor(0),
2367 pFormControl->GetOriginalBorderColor(1),
2368 pFormControl->GetOriginalBorderColor(2),
2369 pFormControl->GetOriginalBorderColor(3));
Lei Zhangd88a3642015-11-10 09:38:57 -08002370 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002371 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08002372 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002373
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002374 color::ConvertPWLColorToArray(color, crArray);
2375 vp << crArray;
2376 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002377 return TRUE;
2378}
2379
2380void Field::SetStrokeColor(CPDFSDK_Document* pDocument,
2381 const CFX_WideString& swFieldName,
2382 int nControlIndex,
2383 const CPWL_Color& color) {
2384 // Not supported.
2385}
2386
Tom Sepezba038bc2015-10-08 12:03:00 -07002387FX_BOOL Field::style(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002388 CJS_PropValue& vp,
2389 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08002390 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002391
2392 if (vp.IsSetting()) {
2393 if (!m_bCanSet)
2394 return FALSE;
2395
2396 CFX_ByteString csBCaption;
2397 vp >> csBCaption;
2398
2399 if (m_bDelay) {
2400 AddDelay_String(FP_STYLE, csBCaption);
2401 } else {
2402 Field::SetStyle(m_pDocument, m_FieldName, m_nFormControlIndex,
2403 csBCaption);
2404 }
2405 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002406 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2407 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002408 return FALSE;
2409
Lei Zhangd88a3642015-11-10 09:38:57 -08002410 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002411 if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON &&
Lei Zhangd88a3642015-11-10 09:38:57 -08002412 pFormField->GetFieldType() != FIELDTYPE_CHECKBOX) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002413 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08002414 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002415
2416 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2417 if (!pFormControl)
2418 return FALSE;
2419
2420 CFX_WideString csWCaption = pFormControl->GetNormalCaption();
2421 CFX_ByteString csBCaption;
2422
2423 switch (csWCaption[0]) {
2424 case L'l':
2425 csBCaption = "circle";
2426 break;
2427 case L'8':
2428 csBCaption = "cross";
2429 break;
2430 case L'u':
2431 csBCaption = "diamond";
2432 break;
2433 case L'n':
2434 csBCaption = "square";
2435 break;
2436 case L'H':
2437 csBCaption = "star";
2438 break;
2439 default: // L'4'
2440 csBCaption = "check";
2441 break;
2442 }
2443 vp << csBCaption;
2444 }
2445
2446 return TRUE;
2447}
2448
2449void Field::SetStyle(CPDFSDK_Document* pDocument,
2450 const CFX_WideString& swFieldName,
2451 int nControlIndex,
2452 const CFX_ByteString& string) {
2453 // Not supported.
2454}
2455
Tom Sepezba038bc2015-10-08 12:03:00 -07002456FX_BOOL Field::submitName(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002457 CJS_PropValue& vp,
2458 CFX_WideString& sError) {
2459 return TRUE;
2460}
2461
Tom Sepezba038bc2015-10-08 12:03:00 -07002462FX_BOOL Field::textColor(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002463 CJS_PropValue& vp,
2464 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002465 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
2466 CJS_Array crArray(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002467
2468 if (vp.IsSetting()) {
2469 if (!m_bCanSet)
2470 return FALSE;
2471
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002472 if (!vp.IsArrayObject())
2473 return FALSE;
Tom Sepez67fd5df2015-10-08 12:24:19 -07002474
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002475 vp >> crArray;
2476
2477 CPWL_Color color;
2478 color::ConvertArrayToPWLColor(crArray, color);
2479
2480 if (m_bDelay) {
2481 AddDelay_Color(FP_TEXTCOLOR, color);
2482 } else {
2483 Field::SetTextColor(m_pDocument, m_FieldName, m_nFormControlIndex, color);
2484 }
2485 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002486 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2487 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002488 return FALSE;
2489
Lei Zhangd88a3642015-11-10 09:38:57 -08002490 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002491 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2492 if (!pFormControl)
2493 return FALSE;
2494
2495 int iColorType;
2496 FX_ARGB color;
2497 CPDF_DefaultAppearance FieldAppearance =
2498 pFormControl->GetDefaultAppearance();
2499 FieldAppearance.GetColor(color, iColorType);
2500 int32_t a, r, g, b;
2501 ArgbDecode(color, a, r, g, b);
2502
2503 CPWL_Color crRet =
2504 CPWL_Color(COLORTYPE_RGB, r / 255.0f, g / 255.0f, b / 255.0f);
2505
2506 if (iColorType == COLORTYPE_TRANSPARENT)
2507 crRet = CPWL_Color(COLORTYPE_TRANSPARENT);
2508
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002509 color::ConvertPWLColorToArray(crRet, crArray);
2510 vp << crArray;
2511 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002512 return TRUE;
2513}
2514
2515void Field::SetTextColor(CPDFSDK_Document* pDocument,
2516 const CFX_WideString& swFieldName,
2517 int nControlIndex,
2518 const CPWL_Color& color) {
2519 // Not supported.
2520}
2521
Tom Sepezba038bc2015-10-08 12:03:00 -07002522FX_BOOL Field::textFont(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002523 CJS_PropValue& vp,
2524 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08002525 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002526
2527 if (vp.IsSetting()) {
2528 if (!m_bCanSet)
2529 return FALSE;
2530
2531 CFX_ByteString csFontName;
2532 vp >> csFontName;
2533 if (csFontName.IsEmpty())
2534 return FALSE;
2535
2536 if (m_bDelay) {
2537 AddDelay_String(FP_TEXTFONT, csFontName);
2538 } else {
2539 Field::SetTextFont(m_pDocument, m_FieldName, m_nFormControlIndex,
2540 csFontName);
2541 }
2542 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002543 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2544 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002545 return FALSE;
2546
Lei Zhangd88a3642015-11-10 09:38:57 -08002547 CPDF_FormField* pFormField = FieldArray[0];
2548 ASSERT(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002549 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2550 if (!pFormControl)
2551 return FALSE;
2552
2553 int nFieldType = pFormField->GetFieldType();
2554
2555 if (nFieldType == FIELDTYPE_PUSHBUTTON ||
2556 nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX ||
2557 nFieldType == FIELDTYPE_TEXTFIELD) {
2558 CPDF_Font* pFont = pFormControl->GetDefaultControlFont();
2559 if (!pFont)
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002560 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002561
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002562 vp << pFont->GetBaseFont();
Lei Zhangd88a3642015-11-10 09:38:57 -08002563 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002564 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08002565 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002566 }
2567
2568 return TRUE;
2569}
2570
2571void Field::SetTextFont(CPDFSDK_Document* pDocument,
2572 const CFX_WideString& swFieldName,
2573 int nControlIndex,
2574 const CFX_ByteString& string) {
2575 // Not supported.
2576}
2577
Tom Sepezba038bc2015-10-08 12:03:00 -07002578FX_BOOL Field::textSize(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002579 CJS_PropValue& vp,
2580 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08002581 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002582
2583 if (vp.IsSetting()) {
2584 if (!m_bCanSet)
2585 return FALSE;
2586
2587 int nVP;
2588 vp >> nVP;
2589
2590 if (m_bDelay) {
2591 AddDelay_Int(FP_TEXTSIZE, nVP);
2592 } else {
2593 Field::SetTextSize(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
2594 }
2595 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002596 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2597 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002598 return FALSE;
2599
Lei Zhangd88a3642015-11-10 09:38:57 -08002600 CPDF_FormField* pFormField = FieldArray[0];
2601 ASSERT(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002602 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2603 if (!pFormControl)
2604 return FALSE;
2605
2606 CPDF_DefaultAppearance FieldAppearance =
2607 pFormControl->GetDefaultAppearance();
2608
2609 CFX_ByteString csFontNameTag;
2610 FX_FLOAT fFontSize;
2611 FieldAppearance.GetFont(csFontNameTag, fFontSize);
2612
2613 vp << (int)fFontSize;
2614 }
2615
2616 return TRUE;
2617}
2618
2619void Field::SetTextSize(CPDFSDK_Document* pDocument,
2620 const CFX_WideString& swFieldName,
2621 int nControlIndex,
2622 int number) {
2623 // Not supported.
2624}
2625
Tom Sepezba038bc2015-10-08 12:03:00 -07002626FX_BOOL Field::type(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002627 CJS_PropValue& vp,
2628 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002629 if (!vp.IsGetting())
2630 return FALSE;
2631
Lei Zhangd88a3642015-11-10 09:38:57 -08002632 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2633 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002634 return FALSE;
2635
Lei Zhangd88a3642015-11-10 09:38:57 -08002636 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002637 switch (pFormField->GetFieldType()) {
2638 case FIELDTYPE_UNKNOWN:
2639 vp << L"unknown";
2640 break;
2641 case FIELDTYPE_PUSHBUTTON:
2642 vp << L"button";
2643 break;
2644 case FIELDTYPE_CHECKBOX:
2645 vp << L"checkbox";
2646 break;
2647 case FIELDTYPE_RADIOBUTTON:
2648 vp << L"radiobutton";
2649 break;
2650 case FIELDTYPE_COMBOBOX:
2651 vp << L"combobox";
2652 break;
2653 case FIELDTYPE_LISTBOX:
2654 vp << L"listbox";
2655 break;
2656 case FIELDTYPE_TEXTFIELD:
2657 vp << L"text";
2658 break;
2659 case FIELDTYPE_SIGNATURE:
2660 vp << L"signature";
2661 break;
2662 default:
2663 vp << L"unknown";
2664 break;
2665 }
2666
2667 return TRUE;
2668}
2669
Tom Sepezba038bc2015-10-08 12:03:00 -07002670FX_BOOL Field::userName(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002671 CJS_PropValue& vp,
2672 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08002673 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002674
2675 if (vp.IsSetting()) {
2676 if (!m_bCanSet)
2677 return FALSE;
2678
2679 CFX_WideString swName;
2680 vp >> swName;
2681
2682 if (m_bDelay) {
2683 AddDelay_WideString(FP_USERNAME, swName);
2684 } else {
2685 Field::SetUserName(m_pDocument, m_FieldName, m_nFormControlIndex, swName);
2686 }
2687 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002688 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2689 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002690 return FALSE;
2691
Lei Zhangd88a3642015-11-10 09:38:57 -08002692 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002693 vp << (CFX_WideString)pFormField->GetAlternateName();
2694 }
2695
2696 return TRUE;
2697}
2698
2699void Field::SetUserName(CPDFSDK_Document* pDocument,
2700 const CFX_WideString& swFieldName,
2701 int nControlIndex,
2702 const CFX_WideString& string) {
2703 // Not supported.
2704}
2705
Tom Sepezba038bc2015-10-08 12:03:00 -07002706FX_BOOL Field::value(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002707 CJS_PropValue& vp,
2708 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002709 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002710
2711 if (vp.IsSetting()) {
2712 if (!m_bCanSet)
2713 return FALSE;
2714
2715 CJS_WideStringArray strArray;
2716
2717 if (vp.IsArrayObject()) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002718 CJS_Array ValueArray(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002719 vp.ConvertToArray(ValueArray);
2720 for (int i = 0, sz = ValueArray.GetLength(); i < sz; i++) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002721 CJS_Value ElementValue(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002722 ValueArray.GetElement(i, ElementValue);
2723 strArray.Add(ElementValue.ToCFXWideString());
2724 }
2725 } else {
2726 CFX_WideString swValue;
2727 vp >> swValue;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002728 strArray.Add(swValue);
2729 }
2730
2731 if (m_bDelay) {
2732 AddDelay_WideStringArray(FP_VALUE, strArray);
2733 } else {
2734 Field::SetValue(m_pDocument, m_FieldName, m_nFormControlIndex, strArray);
2735 }
2736 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002737 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2738 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002739 return FALSE;
2740
Lei Zhangd88a3642015-11-10 09:38:57 -08002741 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002742 switch (pFormField->GetFieldType()) {
2743 case FIELDTYPE_PUSHBUTTON:
2744 return FALSE;
2745 case FIELDTYPE_COMBOBOX:
2746 case FIELDTYPE_TEXTFIELD: {
Tom Sepez4246b002016-01-20 11:48:29 -08002747 vp << pFormField->GetValue();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002748 } break;
2749 case FIELDTYPE_LISTBOX: {
2750 if (pFormField->CountSelectedItems() > 1) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002751 CJS_Array ValueArray(pRuntime);
2752 CJS_Value ElementValue(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002753 int iIndex;
2754 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
2755 iIndex = pFormField->GetSelectedIndex(i);
2756 ElementValue = pFormField->GetOptionValue(iIndex).c_str();
2757 if (FXSYS_wcslen(ElementValue.ToCFXWideString().c_str()) == 0)
2758 ElementValue = pFormField->GetOptionLabel(iIndex).c_str();
2759 ValueArray.SetElement(i, ElementValue);
2760 }
2761 vp << ValueArray;
2762 } else {
Tom Sepez4246b002016-01-20 11:48:29 -08002763 vp << pFormField->GetValue();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002764 }
2765 } break;
2766 case FIELDTYPE_CHECKBOX:
2767 case FIELDTYPE_RADIOBUTTON: {
Tom Sepez4246b002016-01-20 11:48:29 -08002768 bool bFind = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002769 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
Tom Sepez4246b002016-01-20 11:48:29 -08002770 if (pFormField->GetControl(i)->IsChecked()) {
2771 vp << pFormField->GetControl(i)->GetExportValue();
2772 bFind = true;
2773 break;
Lei Zhangd88a3642015-11-10 09:38:57 -08002774 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002775 }
2776 if (!bFind)
2777 vp << L"Off";
2778 } break;
2779 default:
2780 vp << pFormField->GetValue();
2781 break;
2782 }
2783 }
Tom Sepez4246b002016-01-20 11:48:29 -08002784 vp.MaybeCoerceToNumber();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002785 return TRUE;
2786}
2787
2788void Field::SetValue(CPDFSDK_Document* pDocument,
2789 const CFX_WideString& swFieldName,
2790 int nControlIndex,
2791 const CJS_WideStringArray& strArray) {
Lei Zhang96660d62015-12-14 18:27:25 -08002792 ASSERT(pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002793
2794 if (strArray.GetSize() < 1)
2795 return;
2796
Lei Zhangd88a3642015-11-10 09:38:57 -08002797 std::vector<CPDF_FormField*> FieldArray =
2798 GetFormFields(pDocument, swFieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002799
Lei Zhangd88a3642015-11-10 09:38:57 -08002800 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002801 if (pFormField->GetFullName().Compare(swFieldName) != 0)
2802 continue;
2803
2804 switch (pFormField->GetFieldType()) {
2805 case FIELDTYPE_TEXTFIELD:
2806 case FIELDTYPE_COMBOBOX:
2807 if (pFormField->GetValue() != strArray.GetAt(0)) {
2808 CFX_WideString WideString = strArray.GetAt(0);
2809 pFormField->SetValue(strArray.GetAt(0), TRUE);
2810 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
2811 }
2812 break;
2813 case FIELDTYPE_CHECKBOX: // mantis: 0004493
2814 case FIELDTYPE_RADIOBUTTON: {
2815 if (pFormField->GetValue() != strArray.GetAt(0)) {
2816 pFormField->SetValue(strArray.GetAt(0), TRUE);
2817 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
2818 }
2819 } break;
2820 case FIELDTYPE_LISTBOX: {
2821 FX_BOOL bModified = FALSE;
2822
2823 for (int i = 0, sz = strArray.GetSize(); i < sz; i++) {
2824 int iIndex = pFormField->FindOption(strArray.GetAt(i));
2825
2826 if (!pFormField->IsItemSelected(iIndex)) {
2827 bModified = TRUE;
2828 break;
2829 }
2830 }
2831
2832 if (bModified) {
2833 pFormField->ClearSelection(TRUE);
2834 for (int i = 0, sz = strArray.GetSize(); i < sz; i++) {
2835 int iIndex = pFormField->FindOption(strArray.GetAt(i));
2836 pFormField->SetItemSelection(iIndex, TRUE, TRUE);
2837 }
2838
2839 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
2840 }
2841 } break;
2842 default:
2843 break;
2844 }
2845 }
2846}
2847
Tom Sepezba038bc2015-10-08 12:03:00 -07002848FX_BOOL Field::valueAsString(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002849 CJS_PropValue& vp,
2850 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002851 if (!vp.IsGetting())
2852 return FALSE;
2853
Lei Zhangd88a3642015-11-10 09:38:57 -08002854 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2855 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002856 return FALSE;
2857
Lei Zhangd88a3642015-11-10 09:38:57 -08002858 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002859 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
2860 return FALSE;
2861
2862 if (pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) {
2863 if (!pFormField->CountControls())
2864 return FALSE;
2865
2866 if (pFormField->GetControl(0)->IsChecked())
2867 vp << L"Yes";
2868 else
2869 vp << L"Off";
2870 } else if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON &&
2871 !(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)) {
2872 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2873 if (pFormField->GetControl(i)->IsChecked()) {
2874 vp << pFormField->GetControl(i)->GetExportValue().c_str();
2875 break;
Lei Zhangd88a3642015-11-10 09:38:57 -08002876 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002877 vp << L"Off";
Lei Zhangd88a3642015-11-10 09:38:57 -08002878 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002879 }
2880 } else if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX &&
2881 (pFormField->CountSelectedItems() > 1)) {
2882 vp << L"";
Lei Zhangd88a3642015-11-10 09:38:57 -08002883 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002884 vp << pFormField->GetValue().c_str();
Lei Zhangd88a3642015-11-10 09:38:57 -08002885 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002886
2887 return TRUE;
2888}
2889
Tom Sepezba038bc2015-10-08 12:03:00 -07002890FX_BOOL Field::browseForFileToSubmit(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08002891 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002892 CJS_Value& vRet,
2893 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002894 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2895 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002896 return FALSE;
2897
Lei Zhangd88a3642015-11-10 09:38:57 -08002898 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002899 CPDFDoc_Environment* pApp = m_pDocument->GetEnv();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002900 if ((pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) &&
2901 (pFormField->GetFieldType() == FIELDTYPE_TEXTFIELD)) {
2902 CFX_WideString wsFileName = pApp->JS_fieldBrowse();
2903 if (!wsFileName.IsEmpty()) {
2904 pFormField->SetValue(wsFileName);
2905 UpdateFormField(m_pDocument, pFormField, TRUE, TRUE, TRUE);
2906 }
Lei Zhangd88a3642015-11-10 09:38:57 -08002907 return TRUE;
2908 }
2909 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002910}
2911
Tom Sepezba038bc2015-10-08 12:03:00 -07002912FX_BOOL Field::buttonGetCaption(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08002913 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002914 CJS_Value& vRet,
2915 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002916 int nface = 0;
2917 int iSize = params.size();
2918 if (iSize >= 1)
2919 nface = params[0].ToInt();
2920
Lei Zhangd88a3642015-11-10 09:38:57 -08002921 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2922 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002923 return FALSE;
2924
Lei Zhangd88a3642015-11-10 09:38:57 -08002925 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002926 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
2927 return FALSE;
2928
2929 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2930 if (!pFormControl)
2931 return FALSE;
2932
2933 if (nface == 0)
2934 vRet = pFormControl->GetNormalCaption().c_str();
2935 else if (nface == 1)
2936 vRet = pFormControl->GetDownCaption().c_str();
2937 else if (nface == 2)
2938 vRet = pFormControl->GetRolloverCaption().c_str();
2939 else
2940 return FALSE;
2941
2942 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002943}
2944
Tom Sepezba038bc2015-10-08 12:03:00 -07002945FX_BOOL Field::buttonGetIcon(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08002946 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002947 CJS_Value& vRet,
2948 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002949 int nface = 0;
2950 int iSize = params.size();
2951 if (iSize >= 1)
2952 nface = params[0].ToInt();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002953
Lei Zhangd88a3642015-11-10 09:38:57 -08002954 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2955 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002956 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002957
Lei Zhangd88a3642015-11-10 09:38:57 -08002958 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002959 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
2960 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002961
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002962 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2963 if (!pFormControl)
2964 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002965
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002966 CJS_Context* pContext = (CJS_Context*)cc;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002967 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
Tom Sepezcd56a7d2015-10-06 11:45:28 -07002968 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
Tom Sepez33420902015-10-13 15:00:10 -07002969 pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002970 ASSERT(pObj.IsEmpty() == FALSE);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002971
Tom Sepezd5a0e952015-09-17 15:40:06 -07002972 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002973 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002974
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002975 CPDF_Stream* pIconStream = NULL;
2976 if (nface == 0)
2977 pIconStream = pFormControl->GetNormalIcon();
2978 else if (nface == 1)
2979 pIconStream = pFormControl->GetDownIcon();
2980 else if (nface == 2)
2981 pIconStream = pFormControl->GetRolloverIcon();
2982 else
2983 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002984
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002985 pIcon->SetStream(pIconStream);
2986 vRet = pJS_Icon;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002987
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002988 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002989}
2990
Tom Sepezba038bc2015-10-08 12:03:00 -07002991FX_BOOL Field::buttonImportIcon(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08002992 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002993 CJS_Value& vRet,
2994 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002995 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002996}
2997
Tom Sepezba038bc2015-10-08 12:03:00 -07002998FX_BOOL Field::buttonSetCaption(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08002999 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003000 CJS_Value& vRet,
3001 CFX_WideString& sError) {
3002 return FALSE;
3003}
3004
Tom Sepezba038bc2015-10-08 12:03:00 -07003005FX_BOOL Field::buttonSetIcon(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003006 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003007 CJS_Value& vRet,
3008 CFX_WideString& sError) {
3009 return FALSE;
3010}
3011
Tom Sepezba038bc2015-10-08 12:03:00 -07003012FX_BOOL Field::checkThisBox(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003013 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003014 CJS_Value& vRet,
3015 CFX_WideString& sError) {
Lei Zhang96660d62015-12-14 18:27:25 -08003016 ASSERT(m_pDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003017
3018 if (!m_bCanSet)
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003019 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003020
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003021 int iSize = params.size();
3022 if (iSize < 1)
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003023 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003024
3025 int nWidget = params[0].ToInt();
3026
Wei Li97da9762016-03-11 17:00:48 -08003027 bool bCheckit = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003028 if (iSize >= 2)
3029 bCheckit = params[1].ToBool();
3030
Lei Zhangd88a3642015-11-10 09:38:57 -08003031 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3032 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003033 return FALSE;
3034
Lei Zhangd88a3642015-11-10 09:38:57 -08003035 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003036 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
3037 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
3038 return FALSE;
3039 if (nWidget < 0 || nWidget >= pFormField->CountControls())
3040 return FALSE;
Wei Li97da9762016-03-11 17:00:48 -08003041 // TODO(weili): Check whether anything special needed for radio button,
3042 // otherwise merge these branches.
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003043 if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)
Wei Li97da9762016-03-11 17:00:48 -08003044 pFormField->CheckControl(nWidget, bCheckit, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003045 else
Wei Li97da9762016-03-11 17:00:48 -08003046 pFormField->CheckControl(nWidget, bCheckit, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003047
3048 UpdateFormField(m_pDocument, pFormField, TRUE, TRUE, TRUE);
3049 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003050}
3051
Tom Sepezba038bc2015-10-08 12:03:00 -07003052FX_BOOL Field::clearItems(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003053 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003054 CJS_Value& vRet,
3055 CFX_WideString& sError) {
3056 return TRUE;
3057}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003058
Tom Sepezba038bc2015-10-08 12:03:00 -07003059FX_BOOL Field::defaultIsChecked(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003060 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003061 CJS_Value& vRet,
3062 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003063 if (!m_bCanSet)
3064 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003065
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003066 int iSize = params.size();
3067 if (iSize < 1)
3068 return FALSE;
Tom Sepezf4ef3f92015-04-23 11:31:31 -07003069
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003070 int nWidget = params[0].ToInt();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003071
Lei Zhangd88a3642015-11-10 09:38:57 -08003072 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3073 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003074 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003075
Lei Zhangd88a3642015-11-10 09:38:57 -08003076 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003077 if (nWidget < 0 || nWidget >= pFormField->CountControls()) {
3078 vRet = FALSE;
3079 return FALSE;
3080 }
Lei Zhangd88a3642015-11-10 09:38:57 -08003081 vRet = pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
3082 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003083
3084 return TRUE;
3085}
3086
Tom Sepezba038bc2015-10-08 12:03:00 -07003087FX_BOOL Field::deleteItemAt(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003088 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003089 CJS_Value& vRet,
3090 CFX_WideString& sError) {
3091 return TRUE;
3092}
3093
Tom Sepezba038bc2015-10-08 12:03:00 -07003094FX_BOOL Field::getArray(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003095 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003096 CJS_Value& vRet,
3097 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08003098 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3099 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003100 return FALSE;
3101
Tom Sepezb9cc7a02016-02-01 13:42:30 -08003102 std::vector<std::unique_ptr<CFX_WideString>> swSort;
3103 for (CPDF_FormField* pFormField : FieldArray) {
3104 swSort.push_back(std::unique_ptr<CFX_WideString>(
3105 new CFX_WideString(pFormField->GetFullName())));
3106 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003107
Tom Sepezb9cc7a02016-02-01 13:42:30 -08003108 std::sort(
3109 swSort.begin(), swSort.end(),
3110 [](const std::unique_ptr<CFX_WideString>& p1,
3111 const std::unique_ptr<CFX_WideString>& p2) { return *p1 < *p2; });
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003112
3113 CJS_Context* pContext = (CJS_Context*)cc;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003114 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
Tom Sepez67fd5df2015-10-08 12:24:19 -07003115 CJS_Array FormFieldArray(pRuntime);
Tom Sepezb9cc7a02016-02-01 13:42:30 -08003116
3117 int j = 0;
3118 for (const auto& pStr : swSort) {
Tom Sepez39bfe122015-09-17 15:25:23 -07003119 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
Tom Sepez33420902015-10-13 15:00:10 -07003120 pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID);
Tom Sepezcd56a7d2015-10-06 11:45:28 -07003121 ASSERT(!pObj.IsEmpty());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003122
Tom Sepezd5a0e952015-09-17 15:40:06 -07003123 CJS_Field* pJSField =
Tom Sepezb9cc7a02016-02-01 13:42:30 -08003124 static_cast<CJS_Field*>(FXJS_GetPrivate(pRuntime->GetIsolate(), pObj));
3125 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003126 pField->AttachField(m_pJSDoc, *pStr);
3127
Tom Sepez67fd5df2015-10-08 12:24:19 -07003128 CJS_Value FormFieldValue(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003129 FormFieldValue = pJSField;
Tom Sepezb9cc7a02016-02-01 13:42:30 -08003130 FormFieldArray.SetElement(j++, FormFieldValue);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003131 }
3132
3133 vRet = FormFieldArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003134 return TRUE;
3135}
3136
Tom Sepezba038bc2015-10-08 12:03:00 -07003137FX_BOOL Field::getItemAt(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003138 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003139 CJS_Value& vRet,
3140 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003141 int iSize = params.size();
3142
3143 int nIdx = -1;
3144 if (iSize >= 1)
3145 nIdx = params[0].ToInt();
3146
3147 FX_BOOL bExport = TRUE;
3148 if (iSize >= 2)
3149 bExport = params[1].ToBool();
3150
Lei Zhangd88a3642015-11-10 09:38:57 -08003151 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3152 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003153 return FALSE;
3154
Lei Zhangd88a3642015-11-10 09:38:57 -08003155 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003156 if ((pFormField->GetFieldType() == FIELDTYPE_LISTBOX) ||
3157 (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX)) {
3158 if (nIdx == -1 || nIdx > pFormField->CountOptions())
3159 nIdx = pFormField->CountOptions() - 1;
3160 if (bExport) {
3161 CFX_WideString strval = pFormField->GetOptionValue(nIdx);
3162 if (strval.IsEmpty())
3163 vRet = pFormField->GetOptionLabel(nIdx).c_str();
3164 else
3165 vRet = strval.c_str();
Lei Zhangd88a3642015-11-10 09:38:57 -08003166 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003167 vRet = pFormField->GetOptionLabel(nIdx).c_str();
Lei Zhangd88a3642015-11-10 09:38:57 -08003168 }
3169 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003170 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08003171 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003172
3173 return TRUE;
3174}
3175
Tom Sepezba038bc2015-10-08 12:03:00 -07003176FX_BOOL Field::getLock(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003177 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003178 CJS_Value& vRet,
3179 CFX_WideString& sError) {
3180 return FALSE;
3181}
3182
Tom Sepezba038bc2015-10-08 12:03:00 -07003183FX_BOOL Field::insertItemAt(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003184 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003185 CJS_Value& vRet,
3186 CFX_WideString& sError) {
3187 return TRUE;
3188}
3189
Tom Sepezba038bc2015-10-08 12:03:00 -07003190FX_BOOL Field::isBoxChecked(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003191 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003192 CJS_Value& vRet,
3193 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003194 int nIndex = -1;
3195 if (params.size() >= 1)
3196 nIndex = params[0].ToInt();
3197
Lei Zhangd88a3642015-11-10 09:38:57 -08003198 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3199 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003200 return FALSE;
3201
Lei Zhangd88a3642015-11-10 09:38:57 -08003202 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003203 if (nIndex < 0 || nIndex >= pFormField->CountControls()) {
3204 vRet = FALSE;
3205 return FALSE;
3206 }
3207
3208 if ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) ||
3209 (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)) {
3210 if (pFormField->GetControl(nIndex)->IsChecked() != 0)
3211 vRet = TRUE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003212 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003213 vRet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08003214 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003215 vRet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08003216 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003217
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003218 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003219}
3220
Tom Sepezba038bc2015-10-08 12:03:00 -07003221FX_BOOL Field::isDefaultChecked(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003222 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003223 CJS_Value& vRet,
3224 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003225 int nIndex = -1;
3226 if (params.size() >= 1)
3227 nIndex = params[0].ToInt();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003228
Lei Zhangd88a3642015-11-10 09:38:57 -08003229 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3230 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003231 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003232
Lei Zhangd88a3642015-11-10 09:38:57 -08003233 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003234 if (nIndex < 0 || nIndex >= pFormField->CountControls()) {
3235 vRet = FALSE;
3236 return FALSE;
3237 }
3238 if ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) ||
3239 (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)) {
3240 if (pFormField->GetControl(nIndex)->IsDefaultChecked() != 0)
3241 vRet = TRUE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003242 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003243 vRet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08003244 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003245 vRet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08003246 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003247
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003248 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003249}
3250
Tom Sepezba038bc2015-10-08 12:03:00 -07003251FX_BOOL Field::setAction(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003252 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003253 CJS_Value& vRet,
3254 CFX_WideString& sError) {
3255 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003256}
3257
Tom Sepezba038bc2015-10-08 12:03:00 -07003258FX_BOOL Field::setFocus(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003259 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003260 CJS_Value& vRet,
3261 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08003262 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3263 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003264 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003265
Lei Zhangd88a3642015-11-10 09:38:57 -08003266 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003267 int32_t nCount = pFormField->CountControls();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003268 if (nCount < 1)
3269 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003270
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003271 CPDFSDK_InterForm* pInterForm =
3272 (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003273 CPDFSDK_Widget* pWidget = NULL;
3274 if (nCount == 1) {
3275 pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
3276 } else {
3277 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
Tom Sepez50d12ad2015-11-24 09:50:51 -08003278 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(
3279 pEnv->FFI_GetCurrentPage(m_pDocument->GetUnderlyingDocument()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003280 if (!pPage)
3281 return FALSE;
3282 if (CPDFSDK_PageView* pCurPageView = m_pDocument->GetPageView(pPage)) {
3283 for (int32_t i = 0; i < nCount; i++) {
3284 if (CPDFSDK_Widget* pTempWidget =
3285 pInterForm->GetWidget(pFormField->GetControl(i))) {
3286 if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage()) {
3287 pWidget = pTempWidget;
3288 break;
3289 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003290 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003291 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003292 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003293 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003294
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003295 if (pWidget) {
3296 m_pDocument->SetFocusAnnot(pWidget);
3297 }
3298
3299 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003300}
3301
Tom Sepezba038bc2015-10-08 12:03:00 -07003302FX_BOOL Field::setItems(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003303 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003304 CJS_Value& vRet,
3305 CFX_WideString& sError) {
3306 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003307}
3308
Tom Sepezba038bc2015-10-08 12:03:00 -07003309FX_BOOL Field::setLock(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003310 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003311 CJS_Value& vRet,
3312 CFX_WideString& sError) {
3313 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003314}
3315
Tom Sepezba038bc2015-10-08 12:03:00 -07003316FX_BOOL Field::signatureGetModifications(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003317 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003318 CJS_Value& vRet,
3319 CFX_WideString& sError) {
3320 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003321}
3322
Tom Sepezba038bc2015-10-08 12:03:00 -07003323FX_BOOL Field::signatureGetSeedValue(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003324 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003325 CJS_Value& vRet,
3326 CFX_WideString& sError) {
3327 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003328}
3329
Tom Sepezba038bc2015-10-08 12:03:00 -07003330FX_BOOL Field::signatureInfo(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003331 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003332 CJS_Value& vRet,
3333 CFX_WideString& sError) {
3334 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003335}
3336
Tom Sepezba038bc2015-10-08 12:03:00 -07003337FX_BOOL Field::signatureSetSeedValue(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003338 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003339 CJS_Value& vRet,
3340 CFX_WideString& sError) {
3341 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003342}
3343
Tom Sepezba038bc2015-10-08 12:03:00 -07003344FX_BOOL Field::signatureSign(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003345 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003346 CJS_Value& vRet,
3347 CFX_WideString& sError) {
3348 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003349}
3350
Tom Sepezba038bc2015-10-08 12:03:00 -07003351FX_BOOL Field::signatureValidate(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003352 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003353 CJS_Value& vRet,
3354 CFX_WideString& sError) {
3355 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003356}
3357
Tom Sepezba038bc2015-10-08 12:03:00 -07003358FX_BOOL Field::source(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003359 CJS_PropValue& vp,
3360 CFX_WideString& sError) {
3361 if (vp.IsGetting()) {
3362 vp << (CJS_Object*)NULL;
3363 }
3364
3365 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003366}
3367
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003368void Field::AddDelay_Int(enum FIELD_PROP prop, int32_t n) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003369 CJS_DelayData* pNewData = new CJS_DelayData;
3370 pNewData->sFieldName = m_FieldName;
3371 pNewData->nControlIndex = m_nFormControlIndex;
3372 pNewData->eProp = prop;
3373 pNewData->num = n;
3374
3375 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003376}
3377
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003378void Field::AddDelay_Bool(enum FIELD_PROP prop, bool b) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003379 CJS_DelayData* pNewData = new CJS_DelayData;
3380 pNewData->sFieldName = m_FieldName;
3381 pNewData->nControlIndex = m_nFormControlIndex;
3382 pNewData->eProp = prop;
3383 pNewData->b = b;
3384
3385 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003386}
3387
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003388void Field::AddDelay_String(enum FIELD_PROP prop,
3389 const CFX_ByteString& string) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003390 CJS_DelayData* pNewData = new CJS_DelayData;
3391 pNewData->sFieldName = m_FieldName;
3392 pNewData->nControlIndex = m_nFormControlIndex;
3393 pNewData->eProp = prop;
3394 pNewData->string = string;
3395
3396 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003397}
3398
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003399void Field::AddDelay_WideString(enum FIELD_PROP prop,
3400 const CFX_WideString& string) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003401 CJS_DelayData* pNewData = new CJS_DelayData;
3402 pNewData->sFieldName = m_FieldName;
3403 pNewData->nControlIndex = m_nFormControlIndex;
3404 pNewData->eProp = prop;
3405 pNewData->widestring = string;
3406
3407 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003408}
3409
Tom Sepez281a9ea2016-02-26 14:24:28 -08003410void Field::AddDelay_Rect(enum FIELD_PROP prop, const CFX_FloatRect& rect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003411 CJS_DelayData* pNewData = new CJS_DelayData;
3412 pNewData->sFieldName = m_FieldName;
3413 pNewData->nControlIndex = m_nFormControlIndex;
3414 pNewData->eProp = prop;
3415 pNewData->rect = rect;
3416
3417 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003418}
3419
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003420void Field::AddDelay_Color(enum FIELD_PROP prop, const CPWL_Color& color) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003421 CJS_DelayData* pNewData = new CJS_DelayData;
3422 pNewData->sFieldName = m_FieldName;
3423 pNewData->nControlIndex = m_nFormControlIndex;
3424 pNewData->eProp = prop;
3425 pNewData->color = color;
3426
3427 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003428}
3429
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003430void Field::AddDelay_WordArray(enum FIELD_PROP prop,
3431 const CFX_DWordArray& array) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003432 CJS_DelayData* pNewData = new CJS_DelayData;
3433 pNewData->sFieldName = m_FieldName;
3434 pNewData->nControlIndex = m_nFormControlIndex;
3435 pNewData->eProp = prop;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003436
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003437 for (int i = 0, sz = array.GetSize(); i < sz; i++)
3438 pNewData->wordarray.Add(array.GetAt(i));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003439
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003440 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003441}
3442
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003443void Field::AddDelay_WideStringArray(enum FIELD_PROP prop,
3444 const CJS_WideStringArray& array) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003445 CJS_DelayData* pNewData = new CJS_DelayData;
3446 pNewData->sFieldName = m_FieldName;
3447 pNewData->nControlIndex = m_nFormControlIndex;
3448 pNewData->eProp = prop;
3449 for (int i = 0, sz = array.GetSize(); i < sz; i++)
3450 pNewData->widestringarray.Add(array.GetAt(i));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003451
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003452 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003453}
3454
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003455void Field::DoDelay(CPDFSDK_Document* pDocument, CJS_DelayData* pData) {
Lei Zhang96660d62015-12-14 18:27:25 -08003456 ASSERT(pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003457
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003458 switch (pData->eProp) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003459 case FP_ALIGNMENT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003460 Field::SetAlignment(pDocument, pData->sFieldName, pData->nControlIndex,
3461 pData->string);
3462 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003463 case FP_BORDERSTYLE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003464 Field::SetBorderStyle(pDocument, pData->sFieldName, pData->nControlIndex,
3465 pData->string);
3466 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003467 case FP_BUTTONALIGNX:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003468 Field::SetButtonAlignX(pDocument, pData->sFieldName, pData->nControlIndex,
3469 pData->num);
3470 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003471 case FP_BUTTONALIGNY:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003472 Field::SetButtonAlignY(pDocument, pData->sFieldName, pData->nControlIndex,
3473 pData->num);
3474 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003475 case FP_BUTTONFITBOUNDS:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003476 Field::SetButtonFitBounds(pDocument, pData->sFieldName,
3477 pData->nControlIndex, pData->b);
3478 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003479 case FP_BUTTONPOSITION:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003480 Field::SetButtonPosition(pDocument, pData->sFieldName,
3481 pData->nControlIndex, pData->num);
3482 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003483 case FP_BUTTONSCALEHOW:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003484 Field::SetButtonScaleHow(pDocument, pData->sFieldName,
3485 pData->nControlIndex, pData->num);
3486 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003487 case FP_BUTTONSCALEWHEN:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003488 Field::SetButtonScaleWhen(pDocument, pData->sFieldName,
3489 pData->nControlIndex, pData->num);
3490 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003491 case FP_CALCORDERINDEX:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003492 Field::SetCalcOrderIndex(pDocument, pData->sFieldName,
3493 pData->nControlIndex, pData->num);
3494 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003495 case FP_CHARLIMIT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003496 Field::SetCharLimit(pDocument, pData->sFieldName, pData->nControlIndex,
3497 pData->num);
3498 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003499 case FP_COMB:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003500 Field::SetComb(pDocument, pData->sFieldName, pData->nControlIndex,
3501 pData->b);
3502 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003503 case FP_COMMITONSELCHANGE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003504 Field::SetCommitOnSelChange(pDocument, pData->sFieldName,
3505 pData->nControlIndex, pData->b);
3506 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003507 case FP_CURRENTVALUEINDICES:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003508 Field::SetCurrentValueIndices(pDocument, pData->sFieldName,
3509 pData->nControlIndex, pData->wordarray);
3510 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003511 case FP_DEFAULTVALUE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003512 Field::SetDefaultValue(pDocument, pData->sFieldName, pData->nControlIndex,
3513 pData->widestring);
3514 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003515 case FP_DONOTSCROLL:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003516 Field::SetDoNotScroll(pDocument, pData->sFieldName, pData->nControlIndex,
3517 pData->b);
3518 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003519 case FP_DISPLAY:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003520 Field::SetDisplay(pDocument, pData->sFieldName, pData->nControlIndex,
3521 pData->num);
3522 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003523 case FP_FILLCOLOR:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003524 Field::SetFillColor(pDocument, pData->sFieldName, pData->nControlIndex,
3525 pData->color);
3526 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003527 case FP_HIDDEN:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003528 Field::SetHidden(pDocument, pData->sFieldName, pData->nControlIndex,
3529 pData->b);
3530 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003531 case FP_HIGHLIGHT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003532 Field::SetHighlight(pDocument, pData->sFieldName, pData->nControlIndex,
3533 pData->string);
3534 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003535 case FP_LINEWIDTH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003536 Field::SetLineWidth(pDocument, pData->sFieldName, pData->nControlIndex,
3537 pData->num);
3538 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003539 case FP_MULTILINE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003540 Field::SetMultiline(pDocument, pData->sFieldName, pData->nControlIndex,
3541 pData->b);
3542 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003543 case FP_MULTIPLESELECTION:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003544 Field::SetMultipleSelection(pDocument, pData->sFieldName,
3545 pData->nControlIndex, pData->b);
3546 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003547 case FP_PASSWORD:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003548 Field::SetPassword(pDocument, pData->sFieldName, pData->nControlIndex,
3549 pData->b);
3550 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003551 case FP_RECT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003552 Field::SetRect(pDocument, pData->sFieldName, pData->nControlIndex,
3553 pData->rect);
3554 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003555 case FP_RICHTEXT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003556 Field::SetRichText(pDocument, pData->sFieldName, pData->nControlIndex,
3557 pData->b);
3558 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003559 case FP_RICHVALUE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003560 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003561 case FP_ROTATION:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003562 Field::SetRotation(pDocument, pData->sFieldName, pData->nControlIndex,
3563 pData->num);
3564 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003565 case FP_STROKECOLOR:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003566 Field::SetStrokeColor(pDocument, pData->sFieldName, pData->nControlIndex,
3567 pData->color);
3568 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003569 case FP_STYLE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003570 Field::SetStyle(pDocument, pData->sFieldName, pData->nControlIndex,
3571 pData->string);
3572 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003573 case FP_TEXTCOLOR:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003574 Field::SetTextColor(pDocument, pData->sFieldName, pData->nControlIndex,
3575 pData->color);
3576 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003577 case FP_TEXTFONT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003578 Field::SetTextFont(pDocument, pData->sFieldName, pData->nControlIndex,
3579 pData->string);
3580 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003581 case FP_TEXTSIZE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003582 Field::SetTextSize(pDocument, pData->sFieldName, pData->nControlIndex,
3583 pData->num);
3584 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003585 case FP_USERNAME:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003586 Field::SetUserName(pDocument, pData->sFieldName, pData->nControlIndex,
3587 pData->widestring);
3588 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003589 case FP_VALUE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003590 Field::SetValue(pDocument, pData->sFieldName, pData->nControlIndex,
3591 pData->widestringarray);
3592 break;
3593 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003594}
3595
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003596void Field::AddField(CPDFSDK_Document* pDocument,
3597 int nPageIndex,
3598 int nFieldType,
3599 const CFX_WideString& sName,
Tom Sepez281a9ea2016-02-26 14:24:28 -08003600 const CFX_FloatRect& rcCoords) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003601 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003602}