blob: 6287850bb6f80dd1361fd1f82f1a6f0ceb71971d [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
Tom Sepez37458412015-10-06 11:33:46 -07007#include "Field.h"
8
9#include "../../include/fsdk_mgr.h" // For CPDFDoc_Environment.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070010#include "../../include/javascript/IJavaScript.h"
Tom Sepez37458412015-10-06 11:33:46 -070011#include "Document.h"
12#include "Icon.h"
13#include "JS_Context.h"
14#include "JS_Define.h"
15#include "JS_EventHandler.h"
16#include "JS_Object.h"
17#include "JS_Runtime.h"
18#include "JS_Value.h"
19#include "PublicMethods.h"
20#include "color.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070021
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070022/* ---------------------- Field ---------------------- */
23
24BEGIN_JS_STATIC_CONST(CJS_Field)
25END_JS_STATIC_CONST()
26
27BEGIN_JS_STATIC_PROP(CJS_Field)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070028JS_STATIC_PROP_ENTRY(alignment)
29JS_STATIC_PROP_ENTRY(borderStyle)
30JS_STATIC_PROP_ENTRY(buttonAlignX)
31JS_STATIC_PROP_ENTRY(buttonAlignY)
32JS_STATIC_PROP_ENTRY(buttonFitBounds)
33JS_STATIC_PROP_ENTRY(buttonPosition)
34JS_STATIC_PROP_ENTRY(buttonScaleHow)
35JS_STATIC_PROP_ENTRY(buttonScaleWhen)
36JS_STATIC_PROP_ENTRY(calcOrderIndex)
37JS_STATIC_PROP_ENTRY(charLimit)
38JS_STATIC_PROP_ENTRY(comb)
39JS_STATIC_PROP_ENTRY(commitOnSelChange)
40JS_STATIC_PROP_ENTRY(currentValueIndices)
41JS_STATIC_PROP_ENTRY(defaultStyle)
42JS_STATIC_PROP_ENTRY(defaultValue)
43JS_STATIC_PROP_ENTRY(doNotScroll)
44JS_STATIC_PROP_ENTRY(doNotSpellCheck)
45JS_STATIC_PROP_ENTRY(delay)
46JS_STATIC_PROP_ENTRY(display)
47JS_STATIC_PROP_ENTRY(doc)
48JS_STATIC_PROP_ENTRY(editable)
49JS_STATIC_PROP_ENTRY(exportValues)
50JS_STATIC_PROP_ENTRY(hidden)
51JS_STATIC_PROP_ENTRY(fileSelect)
52JS_STATIC_PROP_ENTRY(fillColor)
53JS_STATIC_PROP_ENTRY(lineWidth)
54JS_STATIC_PROP_ENTRY(highlight)
55JS_STATIC_PROP_ENTRY(multiline)
56JS_STATIC_PROP_ENTRY(multipleSelection)
57JS_STATIC_PROP_ENTRY(name)
58JS_STATIC_PROP_ENTRY(numItems)
59JS_STATIC_PROP_ENTRY(page)
60JS_STATIC_PROP_ENTRY(password)
61JS_STATIC_PROP_ENTRY(print)
62JS_STATIC_PROP_ENTRY(radiosInUnison)
63JS_STATIC_PROP_ENTRY(readonly)
64JS_STATIC_PROP_ENTRY(rect)
65JS_STATIC_PROP_ENTRY(required)
66JS_STATIC_PROP_ENTRY(richText)
67JS_STATIC_PROP_ENTRY(richValue)
68JS_STATIC_PROP_ENTRY(rotation)
69JS_STATIC_PROP_ENTRY(strokeColor)
70JS_STATIC_PROP_ENTRY(style)
71JS_STATIC_PROP_ENTRY(submitName)
72JS_STATIC_PROP_ENTRY(textColor)
73JS_STATIC_PROP_ENTRY(textFont)
74JS_STATIC_PROP_ENTRY(textSize)
75JS_STATIC_PROP_ENTRY(type)
76JS_STATIC_PROP_ENTRY(userName)
77JS_STATIC_PROP_ENTRY(value)
78JS_STATIC_PROP_ENTRY(valueAsString)
79JS_STATIC_PROP_ENTRY(source)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070080END_JS_STATIC_PROP()
81
82BEGIN_JS_STATIC_METHOD(CJS_Field)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070083JS_STATIC_METHOD_ENTRY(browseForFileToSubmit)
84JS_STATIC_METHOD_ENTRY(buttonGetCaption)
85JS_STATIC_METHOD_ENTRY(buttonGetIcon)
86JS_STATIC_METHOD_ENTRY(buttonImportIcon)
87JS_STATIC_METHOD_ENTRY(buttonSetCaption)
88JS_STATIC_METHOD_ENTRY(buttonSetIcon)
89JS_STATIC_METHOD_ENTRY(checkThisBox)
90JS_STATIC_METHOD_ENTRY(clearItems)
91JS_STATIC_METHOD_ENTRY(defaultIsChecked)
92JS_STATIC_METHOD_ENTRY(deleteItemAt)
93JS_STATIC_METHOD_ENTRY(getArray)
94JS_STATIC_METHOD_ENTRY(getItemAt)
95JS_STATIC_METHOD_ENTRY(getLock)
96JS_STATIC_METHOD_ENTRY(insertItemAt)
97JS_STATIC_METHOD_ENTRY(isBoxChecked)
98JS_STATIC_METHOD_ENTRY(isDefaultChecked)
99JS_STATIC_METHOD_ENTRY(setAction)
100JS_STATIC_METHOD_ENTRY(setFocus)
101JS_STATIC_METHOD_ENTRY(setItems)
102JS_STATIC_METHOD_ENTRY(setLock)
103JS_STATIC_METHOD_ENTRY(signatureGetModifications)
104JS_STATIC_METHOD_ENTRY(signatureGetSeedValue)
105JS_STATIC_METHOD_ENTRY(signatureInfo)
106JS_STATIC_METHOD_ENTRY(signatureSetSeedValue)
107JS_STATIC_METHOD_ENTRY(signatureSign)
108JS_STATIC_METHOD_ENTRY(signatureValidate)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700109END_JS_STATIC_METHOD()
110
111IMPLEMENT_JS_CLASS(CJS_Field, Field)
112
Tom Sepez33420902015-10-13 15:00:10 -0700113void CJS_Field::InitInstance(IJS_Runtime* pIRuntime) {
114 CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime);
115 Field* pField = static_cast<Field*>(GetEmbedObject());
116 pField->SetIsolate(pRuntime->GetIsolate());
Lei Zhangd88a3642015-11-10 09:38:57 -0800117}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700118
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700119Field::Field(CJS_Object* pJSObject)
120 : CJS_EmbedObj(pJSObject),
121 m_pJSDoc(NULL),
122 m_pDocument(NULL),
123 m_nFormControlIndex(-1),
124 m_bCanSet(FALSE),
125 m_bDelay(FALSE),
126 m_isolate(NULL) {}
127
128Field::~Field() {}
129
130// note: iControlNo = -1, means not a widget.
131void Field::ParseFieldName(const std::wstring& strFieldNameParsed,
132 std::wstring& strFieldName,
133 int& iControlNo) {
134 int iStart = strFieldNameParsed.find_last_of(L'.');
135 if (iStart == -1) {
136 strFieldName = strFieldNameParsed;
137 iControlNo = -1;
138 return;
139 }
140 std::wstring suffixal = strFieldNameParsed.substr(iStart + 1);
141 iControlNo = FXSYS_wtoi(suffixal.c_str());
142 if (iControlNo == 0) {
143 int iStart;
144 while ((iStart = suffixal.find_last_of(L" ")) != -1) {
145 suffixal.erase(iStart, 1);
146 }
147
148 if (suffixal.compare(L"0") != 0) {
149 strFieldName = strFieldNameParsed;
150 iControlNo = -1;
151 return;
152 }
153 }
154 strFieldName = strFieldNameParsed.substr(0, iStart);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700155}
156
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700157FX_BOOL Field::AttachField(Document* pDocument,
158 const CFX_WideString& csFieldName) {
159 ASSERT(pDocument != NULL);
160 m_pJSDoc = pDocument;
161
162 m_pDocument = pDocument->GetReaderDoc();
163 ASSERT(m_pDocument != NULL);
164
165 m_bCanSet = m_pDocument->GetPermissions(FPDFPERM_FILL_FORM) ||
166 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
167 m_pDocument->GetPermissions(FPDFPERM_MODIFY);
168
169 CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm();
170 ASSERT(pRDInterForm != NULL);
171
172 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
173 ASSERT(pInterForm != NULL);
174
175 CFX_WideString swFieldNameTemp = csFieldName;
176 swFieldNameTemp.Replace(L"..", L".");
177
178 if (pInterForm->CountFields(swFieldNameTemp) <= 0) {
179 std::wstring strFieldName;
180 int iControlNo = -1;
181 ParseFieldName(swFieldNameTemp.c_str(), strFieldName, iControlNo);
182 if (iControlNo == -1)
183 return FALSE;
184
185 m_FieldName = strFieldName.c_str();
186 m_nFormControlIndex = iControlNo;
187 return TRUE;
188 }
189
190 m_FieldName = swFieldNameTemp;
191 m_nFormControlIndex = -1;
192
193 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700194}
195
Lei Zhangd88a3642015-11-10 09:38:57 -0800196std::vector<CPDF_FormField*> Field::GetFormFields(
197 CPDFSDK_Document* pDocument,
198 const CFX_WideString& csFieldName) {
199 std::vector<CPDF_FormField*> fields;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700200 CPDFSDK_InterForm* pReaderInterForm = pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700201 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -0800202 for (int i = 0, sz = pInterForm->CountFields(csFieldName); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700203 if (CPDF_FormField* pFormField = pInterForm->GetField(i, csFieldName))
Lei Zhangd88a3642015-11-10 09:38:57 -0800204 fields.push_back(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700205 }
Lei Zhangd88a3642015-11-10 09:38:57 -0800206 return fields;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700207}
208
Lei Zhangd88a3642015-11-10 09:38:57 -0800209std::vector<CPDF_FormField*> Field::GetFormFields(
210 const CFX_WideString& csFieldName) const {
211 return Field::GetFormFields(m_pDocument, csFieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700212}
213
214void Field::UpdateFormField(CPDFSDK_Document* pDocument,
215 CPDF_FormField* pFormField,
216 FX_BOOL bChangeMark,
217 FX_BOOL bResetAP,
218 FX_BOOL bRefresh) {
Lei Zhangd88a3642015-11-10 09:38:57 -0800219 std::vector<CPDFSDK_Widget*> widgets;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700220 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
Lei Zhangd88a3642015-11-10 09:38:57 -0800221 pInterForm->GetWidgets(pFormField, &widgets);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700222
223 if (bResetAP) {
224 int nFieldType = pFormField->GetFieldType();
225 if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_TEXTFIELD) {
Lei Zhangd88a3642015-11-10 09:38:57 -0800226 for (CPDFSDK_Widget* pWidget : widgets) {
227 FX_BOOL bFormatted = FALSE;
228 CFX_WideString sValue = pWidget->OnFormat(bFormatted);
229 pWidget->ResetAppearance(bFormatted ? sValue.c_str() : nullptr, FALSE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700230 }
231 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800232 for (CPDFSDK_Widget* pWidget : widgets) {
233 pWidget->ResetAppearance(nullptr, FALSE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700234 }
235 }
236 }
237
238 if (bRefresh) {
Lei Zhangd88a3642015-11-10 09:38:57 -0800239 for (CPDFSDK_Widget* pWidget : widgets) {
240 CPDFSDK_Document* pDoc = pWidget->GetInterForm()->GetDocument();
241 pDoc->UpdateAllViews(nullptr, pWidget);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700242 }
243 }
244
245 if (bChangeMark)
246 pDocument->SetChangeMark();
247}
248
249void Field::UpdateFormControl(CPDFSDK_Document* pDocument,
250 CPDF_FormControl* pFormControl,
251 FX_BOOL bChangeMark,
252 FX_BOOL bResetAP,
253 FX_BOOL bRefresh) {
254 ASSERT(pDocument != NULL);
255 ASSERT(pFormControl != NULL);
256
257 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
258 ASSERT(pInterForm != NULL);
259
260 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
261
262 if (pWidget) {
263 if (bResetAP) {
264 int nFieldType = pWidget->GetFieldType();
265 if (nFieldType == FIELDTYPE_COMBOBOX ||
266 nFieldType == FIELDTYPE_TEXTFIELD) {
267 FX_BOOL bFormated = FALSE;
268 CFX_WideString sValue = pWidget->OnFormat(bFormated);
269 if (bFormated)
270 pWidget->ResetAppearance(sValue.c_str(), FALSE);
271 else
272 pWidget->ResetAppearance(NULL, FALSE);
273 } else {
274 pWidget->ResetAppearance(NULL, FALSE);
275 }
276 }
277
278 if (bRefresh) {
279 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
280 CPDFSDK_Document* pDoc = pInterForm->GetDocument();
281 ASSERT(pDoc != NULL);
282 pDoc->UpdateAllViews(NULL, pWidget);
283 }
284 }
285
286 if (bChangeMark)
287 pDocument->SetChangeMark();
288}
289
290CPDFSDK_Widget* Field::GetWidget(CPDFSDK_Document* pDocument,
291 CPDF_FormControl* pFormControl) {
292 ASSERT(pDocument != NULL);
293 ASSERT(pFormControl != NULL);
294
295 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
296 ASSERT(pInterForm != NULL);
297
298 return pInterForm->GetWidget(pFormControl);
299}
300
301FX_BOOL Field::ValueIsOccur(CPDF_FormField* pFormField,
302 CFX_WideString csOptLabel) {
303 ASSERT(pFormField != NULL);
304
305 for (int i = 0, sz = pFormField->CountOptions(); i < sz; i++) {
306 if (csOptLabel.Compare(pFormField->GetOptionLabel(i)) == 0)
307 return TRUE;
308 }
309
310 return FALSE;
311}
312
313CPDF_FormControl* Field::GetSmartFieldControl(CPDF_FormField* pFormField) {
314 if (!pFormField->CountControls() ||
315 m_nFormControlIndex >= pFormField->CountControls())
316 return NULL;
317
318 if (m_nFormControlIndex < 0)
319 return pFormField->GetControl(0);
320
321 return pFormField->GetControl(m_nFormControlIndex);
322}
323
324/* ---------------------------------------- property
325 * ---------------------------------------- */
326
Tom Sepezba038bc2015-10-08 12:03:00 -0700327FX_BOOL Field::alignment(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700328 CJS_PropValue& vp,
329 CFX_WideString& sError) {
330 ASSERT(m_pDocument != NULL);
331
332 if (vp.IsSetting()) {
333 if (!m_bCanSet)
334 return FALSE;
335
336 CFX_ByteString alignStr;
337 vp >> alignStr;
338
339 if (m_bDelay) {
340 AddDelay_String(FP_ALIGNMENT, alignStr);
341 } else {
342 Field::SetAlignment(m_pDocument, m_FieldName, m_nFormControlIndex,
343 alignStr);
344 }
345 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800346 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
347 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700348 return FALSE;
349
Lei Zhangd88a3642015-11-10 09:38:57 -0800350 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700351 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
352 return FALSE;
353
354 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
355 if (!pFormControl)
356 return FALSE;
357
358 switch (pFormControl->GetControlAlignment()) {
359 case 1:
360 vp << L"center";
361 break;
362 case 0:
363 vp << L"left";
364 break;
365 case 2:
366 vp << L"right";
367 break;
368 default:
369 vp << L"";
370 }
371 }
372
373 return TRUE;
374}
375
376void Field::SetAlignment(CPDFSDK_Document* pDocument,
377 const CFX_WideString& swFieldName,
378 int nControlIndex,
379 const CFX_ByteString& string) {
380 // Not supported.
381}
382
Tom Sepezba038bc2015-10-08 12:03:00 -0700383FX_BOOL Field::borderStyle(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700384 CJS_PropValue& vp,
385 CFX_WideString& sError) {
386 ASSERT(m_pDocument != NULL);
387
388 if (vp.IsSetting()) {
389 if (!m_bCanSet)
390 return FALSE;
391
392 CFX_ByteString strType = "";
393 vp >> strType;
394
395 if (m_bDelay) {
396 AddDelay_String(FP_BORDERSTYLE, strType);
397 } else {
398 Field::SetBorderStyle(m_pDocument, m_FieldName, m_nFormControlIndex,
399 strType);
400 }
401 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800402 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
403 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700404 return FALSE;
405
Lei Zhangd88a3642015-11-10 09:38:57 -0800406 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700407 if (!pFormField)
408 return FALSE;
409
410 CPDFSDK_Widget* pWidget =
411 GetWidget(m_pDocument, GetSmartFieldControl(pFormField));
412 if (!pWidget)
413 return FALSE;
414
415 int nBorderstyle = pWidget->GetBorderStyle();
416
417 switch (nBorderstyle) {
418 case BBS_SOLID:
419 vp << L"solid";
420 break;
421 case BBS_DASH:
422 vp << L"dashed";
423 break;
424 case BBS_BEVELED:
425 vp << L"beveled";
426 break;
427 case BBS_INSET:
428 vp << L"inset";
429 break;
430 case BBS_UNDERLINE:
431 vp << L"underline";
432 break;
433 default:
434 vp << L"";
435 break;
436 }
437 }
438
439 return TRUE;
440}
441
442void Field::SetBorderStyle(CPDFSDK_Document* pDocument,
443 const CFX_WideString& swFieldName,
444 int nControlIndex,
445 const CFX_ByteString& string) {
446 ASSERT(pDocument != NULL);
447
448 int nBorderStyle = 0;
449
450 if (string == "solid")
451 nBorderStyle = BBS_SOLID;
452 else if (string == "beveled")
453 nBorderStyle = BBS_BEVELED;
454 else if (string == "dashed")
455 nBorderStyle = BBS_DASH;
456 else if (string == "inset")
457 nBorderStyle = BBS_INSET;
458 else if (string == "underline")
459 nBorderStyle = BBS_UNDERLINE;
460 else
461 return;
462
Lei Zhangd88a3642015-11-10 09:38:57 -0800463 std::vector<CPDF_FormField*> FieldArray =
464 GetFormFields(pDocument, swFieldName);
465 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700466 if (nControlIndex < 0) {
467 FX_BOOL bSet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -0800468 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700469 if (CPDFSDK_Widget* pWidget =
Lei Zhangd88a3642015-11-10 09:38:57 -0800470 GetWidget(pDocument, pFormField->GetControl(i))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700471 if (pWidget->GetBorderStyle() != nBorderStyle) {
472 pWidget->SetBorderStyle(nBorderStyle);
473 bSet = TRUE;
474 }
475 }
476 }
477 if (bSet)
478 UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
479 } else {
480 if (nControlIndex >= pFormField->CountControls())
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700481 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700482 if (CPDF_FormControl* pFormControl =
483 pFormField->GetControl(nControlIndex)) {
484 if (CPDFSDK_Widget* pWidget = GetWidget(pDocument, pFormControl)) {
485 if (pWidget->GetBorderStyle() != nBorderStyle) {
486 pWidget->SetBorderStyle(nBorderStyle);
487 UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
488 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700489 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700490 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700491 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700492 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700493}
494
Tom Sepezba038bc2015-10-08 12:03:00 -0700495FX_BOOL Field::buttonAlignX(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700496 CJS_PropValue& vp,
497 CFX_WideString& sError) {
498 ASSERT(m_pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700499
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700500 if (vp.IsSetting()) {
501 if (!m_bCanSet)
502 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700503
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700504 int nVP;
505 vp >> nVP;
506
507 if (m_bDelay) {
508 AddDelay_Int(FP_BUTTONALIGNX, nVP);
509 } else {
510 Field::SetButtonAlignX(m_pDocument, m_FieldName, m_nFormControlIndex,
511 nVP);
512 }
513 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800514 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
515 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700516 return FALSE;
517
Lei Zhangd88a3642015-11-10 09:38:57 -0800518 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700519 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
520 return FALSE;
521
522 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
523 if (!pFormControl)
524 return FALSE;
525
526 CPDF_IconFit IconFit = pFormControl->GetIconFit();
527
528 FX_FLOAT fLeft, fBottom;
529 IconFit.GetIconPosition(fLeft, fBottom);
530
531 vp << (int32_t)fLeft;
532 }
533
534 return TRUE;
535}
536
537void Field::SetButtonAlignX(CPDFSDK_Document* pDocument,
538 const CFX_WideString& swFieldName,
539 int nControlIndex,
540 int number) {
541 // Not supported.
542}
543
Tom Sepezba038bc2015-10-08 12:03:00 -0700544FX_BOOL Field::buttonAlignY(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700545 CJS_PropValue& vp,
546 CFX_WideString& sError) {
547 ASSERT(m_pDocument != NULL);
548
549 if (vp.IsSetting()) {
550 if (!m_bCanSet)
551 return FALSE;
552
553 int nVP;
554 vp >> nVP;
555
556 if (m_bDelay) {
557 AddDelay_Int(FP_BUTTONALIGNY, nVP);
558 } else {
559 Field::SetButtonAlignY(m_pDocument, m_FieldName, m_nFormControlIndex,
560 nVP);
561 }
562 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800563 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
564 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700565 return FALSE;
566
Lei Zhangd88a3642015-11-10 09:38:57 -0800567 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700568 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
569 return FALSE;
570
571 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
572 if (!pFormControl)
573 return FALSE;
574
575 CPDF_IconFit IconFit = pFormControl->GetIconFit();
576
577 FX_FLOAT fLeft, fBottom;
578 IconFit.GetIconPosition(fLeft, fBottom);
579
580 vp << (int32_t)fBottom;
581 }
582
583 return TRUE;
584}
585
586void Field::SetButtonAlignY(CPDFSDK_Document* pDocument,
587 const CFX_WideString& swFieldName,
588 int nControlIndex,
589 int number) {
590 // Not supported.
591}
592
Tom Sepezba038bc2015-10-08 12:03:00 -0700593FX_BOOL Field::buttonFitBounds(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700594 CJS_PropValue& vp,
595 CFX_WideString& sError) {
596 ASSERT(m_pDocument != NULL);
597
598 if (vp.IsSetting()) {
599 if (!m_bCanSet)
600 return FALSE;
601
602 bool bVP;
603 vp >> bVP;
604
605 if (m_bDelay) {
606 AddDelay_Bool(FP_BUTTONFITBOUNDS, bVP);
607 } else {
608 Field::SetButtonFitBounds(m_pDocument, m_FieldName, m_nFormControlIndex,
609 bVP);
610 }
611 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800612 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
613 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700614 return FALSE;
615
Lei Zhangd88a3642015-11-10 09:38:57 -0800616 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700617 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
618 return FALSE;
619
620 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
621 if (!pFormControl)
622 return FALSE;
623
624 CPDF_IconFit IconFit = pFormControl->GetIconFit();
625 vp << IconFit.GetFittingBounds();
626 }
627
628 return TRUE;
629}
630
631void Field::SetButtonFitBounds(CPDFSDK_Document* pDocument,
632 const CFX_WideString& swFieldName,
633 int nControlIndex,
634 bool b) {
635 // Not supported.
636}
637
Tom Sepezba038bc2015-10-08 12:03:00 -0700638FX_BOOL Field::buttonPosition(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700639 CJS_PropValue& vp,
640 CFX_WideString& sError) {
641 ASSERT(m_pDocument != NULL);
642
643 if (vp.IsSetting()) {
644 if (!m_bCanSet)
645 return FALSE;
646
647 int nVP;
648 vp >> nVP;
649
650 if (m_bDelay) {
651 AddDelay_Int(FP_BUTTONPOSITION, nVP);
652 } else {
653 Field::SetButtonPosition(m_pDocument, m_FieldName, m_nFormControlIndex,
654 nVP);
655 }
656 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800657 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
658 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700659 return FALSE;
660
Lei Zhangd88a3642015-11-10 09:38:57 -0800661 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700662 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
663 return FALSE;
664
665 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
666 if (!pFormControl)
667 return FALSE;
668
669 vp << pFormControl->GetTextPosition();
670 }
671 return TRUE;
672}
673
674void Field::SetButtonPosition(CPDFSDK_Document* pDocument,
675 const CFX_WideString& swFieldName,
676 int nControlIndex,
677 int number) {
678 // Not supported.
679}
680
Tom Sepezba038bc2015-10-08 12:03:00 -0700681FX_BOOL Field::buttonScaleHow(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700682 CJS_PropValue& vp,
683 CFX_WideString& sError) {
684 ASSERT(m_pDocument != NULL);
685
686 if (vp.IsSetting()) {
687 if (!m_bCanSet)
688 return FALSE;
689
690 int nVP;
691 vp >> nVP;
692
693 if (m_bDelay) {
694 AddDelay_Int(FP_BUTTONSCALEHOW, nVP);
695 } else {
696 Field::SetButtonScaleHow(m_pDocument, m_FieldName, m_nFormControlIndex,
697 nVP);
698 }
699 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800700 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
701 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700702 return FALSE;
703
Lei Zhangd88a3642015-11-10 09:38:57 -0800704 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700705 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
706 return FALSE;
707
708 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
709 if (!pFormControl)
710 return FALSE;
711
712 CPDF_IconFit IconFit = pFormControl->GetIconFit();
713 if (IconFit.IsProportionalScale())
714 vp << (int32_t)0;
715 else
716 vp << (int32_t)1;
717 }
718
719 return TRUE;
720}
721
722void Field::SetButtonScaleHow(CPDFSDK_Document* pDocument,
723 const CFX_WideString& swFieldName,
724 int nControlIndex,
725 int number) {
726 // Not supported.
727}
728
Tom Sepezba038bc2015-10-08 12:03:00 -0700729FX_BOOL Field::buttonScaleWhen(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700730 CJS_PropValue& vp,
731 CFX_WideString& sError) {
732 ASSERT(m_pDocument != NULL);
733
734 if (vp.IsSetting()) {
735 if (!m_bCanSet)
736 return FALSE;
737
738 int nVP;
739 vp >> nVP;
740
741 if (m_bDelay) {
742 AddDelay_Int(FP_BUTTONSCALEWHEN, nVP);
743 } else {
744 Field::SetButtonScaleWhen(m_pDocument, m_FieldName, m_nFormControlIndex,
745 nVP);
746 }
747 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800748 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
749 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700750 return FALSE;
751
Lei Zhangd88a3642015-11-10 09:38:57 -0800752 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700753 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
754 return FALSE;
755
756 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
757 if (!pFormControl)
758 return FALSE;
759
760 CPDF_IconFit IconFit = pFormControl->GetIconFit();
761 int ScaleM = IconFit.GetScaleMethod();
762 switch (ScaleM) {
763 case CPDF_IconFit::Always:
764 vp << (int32_t)CPDF_IconFit::Always;
765 break;
766 case CPDF_IconFit::Bigger:
767 vp << (int32_t)CPDF_IconFit::Bigger;
768 break;
769 case CPDF_IconFit::Never:
770 vp << (int32_t)CPDF_IconFit::Never;
771 break;
772 case CPDF_IconFit::Smaller:
773 vp << (int32_t)CPDF_IconFit::Smaller;
774 break;
775 }
776 }
777
778 return TRUE;
779}
780
781void Field::SetButtonScaleWhen(CPDFSDK_Document* pDocument,
782 const CFX_WideString& swFieldName,
783 int nControlIndex,
784 int number) {
785 // Not supported.
786}
787
Tom Sepezba038bc2015-10-08 12:03:00 -0700788FX_BOOL Field::calcOrderIndex(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700789 CJS_PropValue& vp,
790 CFX_WideString& sError) {
791 ASSERT(m_pDocument != NULL);
792
793 if (vp.IsSetting()) {
794 if (!m_bCanSet)
795 return FALSE;
796
797 int nVP;
798 vp >> nVP;
799
800 if (m_bDelay) {
801 AddDelay_Int(FP_CALCORDERINDEX, nVP);
802 } else {
803 Field::SetCalcOrderIndex(m_pDocument, m_FieldName, m_nFormControlIndex,
804 nVP);
805 }
806 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800807 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
808 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700809 return FALSE;
810
Lei Zhangd88a3642015-11-10 09:38:57 -0800811 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700812 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -0800813 pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700814 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -0800815 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700816
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700817 CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm();
818 ASSERT(pRDInterForm != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700819
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700820 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
821 ASSERT(pInterForm != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700822
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700823 vp << (int32_t)pInterForm->FindFieldInCalculationOrder(pFormField);
824 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700825
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700826 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700827}
828
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700829void Field::SetCalcOrderIndex(CPDFSDK_Document* pDocument,
830 const CFX_WideString& swFieldName,
831 int nControlIndex,
832 int number) {
833 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700834}
835
Tom Sepezba038bc2015-10-08 12:03:00 -0700836FX_BOOL Field::charLimit(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700837 CJS_PropValue& vp,
838 CFX_WideString& sError) {
839 ASSERT(m_pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700840
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700841 if (vp.IsSetting()) {
842 if (!m_bCanSet)
843 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700844
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700845 int nVP;
846 vp >> nVP;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700847
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700848 if (m_bDelay) {
849 AddDelay_Int(FP_CHARLIMIT, nVP);
850 } else {
851 Field::SetCharLimit(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700852 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700853 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800854 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
855 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700856 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700857
Lei Zhangd88a3642015-11-10 09:38:57 -0800858 CPDF_FormField* pFormField = FieldArray[0];
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700859 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700860 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700861
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700862 vp << (int32_t)pFormField->GetMaxLen();
863 }
864 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700865}
866
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700867void Field::SetCharLimit(CPDFSDK_Document* pDocument,
868 const CFX_WideString& swFieldName,
869 int nControlIndex,
870 int number) {
871 // Not supported.
872}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700873
Tom Sepezba038bc2015-10-08 12:03:00 -0700874FX_BOOL Field::comb(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700875 CJS_PropValue& vp,
876 CFX_WideString& sError) {
877 ASSERT(m_pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700878
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700879 if (vp.IsSetting()) {
880 if (!m_bCanSet)
881 return FALSE;
882
883 bool bVP;
884 vp >> bVP;
885
886 if (m_bDelay) {
887 AddDelay_Bool(FP_COMB, bVP);
888 } else {
889 Field::SetComb(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
890 }
891 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800892 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
893 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700894 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700895
Lei Zhangd88a3642015-11-10 09:38:57 -0800896 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700897 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
898 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700899
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700900 if (pFormField->GetFieldFlags() & FIELDFLAG_COMB)
901 vp << true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700902 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700903 vp << false;
904 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700905
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700906 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700907}
908
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700909void Field::SetComb(CPDFSDK_Document* pDocument,
910 const CFX_WideString& swFieldName,
911 int nControlIndex,
912 bool b) {
913 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700914}
915
Tom Sepezba038bc2015-10-08 12:03:00 -0700916FX_BOOL Field::commitOnSelChange(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700917 CJS_PropValue& vp,
918 CFX_WideString& sError) {
919 ASSERT(m_pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700920
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700921 if (vp.IsSetting()) {
922 if (!m_bCanSet)
923 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700924
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700925 bool bVP;
926 vp >> bVP;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700927
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700928 if (m_bDelay) {
929 AddDelay_Bool(FP_COMMITONSELCHANGE, bVP);
930 } else {
931 Field::SetCommitOnSelChange(m_pDocument, m_FieldName, m_nFormControlIndex,
932 bVP);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700933 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700934 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800935 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
936 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700937 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700938
Lei Zhangd88a3642015-11-10 09:38:57 -0800939 CPDF_FormField* pFormField = FieldArray[0];
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700940 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -0800941 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700942 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -0800943 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700944
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700945 if (pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE)
946 vp << true;
947 else
948 vp << false;
949 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700950
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700951 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700952}
953
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700954void Field::SetCommitOnSelChange(CPDFSDK_Document* pDocument,
955 const CFX_WideString& swFieldName,
956 int nControlIndex,
957 bool b) {
958 // Not supported.
959}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700960
Tom Sepezba038bc2015-10-08 12:03:00 -0700961FX_BOOL Field::currentValueIndices(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700962 CJS_PropValue& vp,
963 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -0700964 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700965
966 if (vp.IsSetting()) {
967 if (!m_bCanSet)
968 return FALSE;
969
970 CFX_DWordArray array;
971
Tom Sepez39bfe122015-09-17 15:25:23 -0700972 if (vp.GetType() == CJS_Value::VT_number) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700973 int iSelecting = 0;
974 vp >> iSelecting;
975 array.Add(iSelecting);
976 } else if (vp.IsArrayObject()) {
Tom Sepez67fd5df2015-10-08 12:24:19 -0700977 CJS_Array SelArray(pRuntime);
978 CJS_Value SelValue(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700979 int iSelecting;
980 vp >> SelArray;
981 for (int i = 0, sz = SelArray.GetLength(); i < sz; i++) {
982 SelArray.GetElement(i, SelValue);
983 iSelecting = SelValue.ToInt();
984 array.Add(iSelecting);
985 }
986 }
987
988 if (m_bDelay) {
989 AddDelay_WordArray(FP_CURRENTVALUEINDICES, array);
990 } else {
991 Field::SetCurrentValueIndices(m_pDocument, m_FieldName,
992 m_nFormControlIndex, array);
993 }
994 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -0800995 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
996 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700997 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700998
Lei Zhangd88a3642015-11-10 09:38:57 -0800999 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001000 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001001 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001002 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001003 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001004
Lei Zhangd88a3642015-11-10 09:38:57 -08001005 if (pFormField->CountSelectedItems() == 1) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001006 vp << pFormField->GetSelectedIndex(0);
Lei Zhangd88a3642015-11-10 09:38:57 -08001007 } else if (pFormField->CountSelectedItems() > 1) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07001008 CJS_Array SelArray(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001009 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
1010 SelArray.SetElement(
Tom Sepez67fd5df2015-10-08 12:24:19 -07001011 i, CJS_Value(pRuntime, pFormField->GetSelectedIndex(i)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001012 }
1013 vp << SelArray;
Lei Zhangd88a3642015-11-10 09:38:57 -08001014 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001015 vp << -1;
Lei Zhangd88a3642015-11-10 09:38:57 -08001016 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001017 }
1018
1019 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001020}
1021
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001022void Field::SetCurrentValueIndices(CPDFSDK_Document* pDocument,
1023 const CFX_WideString& swFieldName,
1024 int nControlIndex,
1025 const CFX_DWordArray& array) {
1026 ASSERT(pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001027
Lei Zhangd88a3642015-11-10 09:38:57 -08001028 std::vector<CPDF_FormField*> FieldArray =
1029 GetFormFields(pDocument, swFieldName);
1030 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001031 int nFieldType = pFormField->GetFieldType();
1032 if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX) {
1033 FX_DWORD dwFieldFlags = pFormField->GetFieldFlags();
1034 pFormField->ClearSelection(TRUE);
1035
1036 for (int i = 0, sz = array.GetSize(); i < sz; i++) {
1037 if (i > 0 && !(dwFieldFlags & (1 << 21))) {
1038 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001039 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001040
1041 int iSelecting = (int32_t)array.GetAt(i);
1042 if (iSelecting < pFormField->CountOptions() &&
1043 !pFormField->IsItemSelected(iSelecting))
1044 pFormField->SetItemSelection(iSelecting, TRUE);
1045 }
1046 UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001047 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001048 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001049}
1050
Tom Sepezba038bc2015-10-08 12:03:00 -07001051FX_BOOL Field::defaultStyle(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001052 CJS_PropValue& vp,
1053 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001054 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001055}
1056
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001057void Field::SetDefaultStyle(CPDFSDK_Document* pDocument,
1058 const CFX_WideString& swFieldName,
1059 int nControlIndex) {
1060 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001061}
1062
Tom Sepezba038bc2015-10-08 12:03:00 -07001063FX_BOOL Field::defaultValue(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001064 CJS_PropValue& vp,
1065 CFX_WideString& sError) {
1066 ASSERT(m_pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001067
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001068 if (vp.IsSetting()) {
1069 if (!m_bCanSet)
1070 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001071
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001072 CFX_WideString WideStr;
1073 vp >> WideStr;
1074
1075 if (m_bDelay) {
1076 AddDelay_WideString(FP_DEFAULTVALUE, WideStr);
1077 } else {
1078 Field::SetDefaultValue(m_pDocument, m_FieldName, m_nFormControlIndex,
1079 WideStr);
1080 }
1081 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001082 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1083 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001084 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001085
Lei Zhangd88a3642015-11-10 09:38:57 -08001086 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001087 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON ||
Lei Zhangd88a3642015-11-10 09:38:57 -08001088 pFormField->GetFieldType() == FIELDTYPE_SIGNATURE) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001089 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001090 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001091
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001092 vp << pFormField->GetDefaultValue();
1093 }
1094 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001095}
1096
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001097void Field::SetDefaultValue(CPDFSDK_Document* pDocument,
1098 const CFX_WideString& swFieldName,
1099 int nControlIndex,
1100 const CFX_WideString& string) {
1101 // Not supported.
1102}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001103
Tom Sepezba038bc2015-10-08 12:03:00 -07001104FX_BOOL Field::doNotScroll(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001105 CJS_PropValue& vp,
1106 CFX_WideString& sError) {
1107 ASSERT(m_pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001108
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001109 if (vp.IsSetting()) {
1110 if (!m_bCanSet)
1111 return FALSE;
1112
1113 bool bVP;
1114 vp >> bVP;
1115
1116 if (m_bDelay) {
1117 AddDelay_Bool(FP_DONOTSCROLL, bVP);
1118 } else {
1119 Field::SetDoNotScroll(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
1120 }
1121 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001122 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1123 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001124 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001125
Lei Zhangd88a3642015-11-10 09:38:57 -08001126 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001127 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1128 return FALSE;
1129
1130 if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL)
1131 vp << true;
1132 else
1133 vp << false;
1134 }
1135
1136 return TRUE;
1137}
1138
1139void Field::SetDoNotScroll(CPDFSDK_Document* pDocument,
1140 const CFX_WideString& swFieldName,
1141 int nControlIndex,
1142 bool b) {
1143 // Not supported.
1144}
1145
Tom Sepezba038bc2015-10-08 12:03:00 -07001146FX_BOOL Field::doNotSpellCheck(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001147 CJS_PropValue& vp,
1148 CFX_WideString& sError) {
1149 ASSERT(m_pDocument != NULL);
1150
1151 if (vp.IsSetting()) {
1152 if (!m_bCanSet)
1153 return FALSE;
1154
1155 bool bVP;
1156 vp >> bVP;
1157 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001158 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1159 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001160 return FALSE;
1161
Lei Zhangd88a3642015-11-10 09:38:57 -08001162 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001163 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001164 pFormField->GetFieldType() != FIELDTYPE_COMBOBOX) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001165 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001166 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001167
1168 if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK)
1169 vp << true;
1170 else
1171 vp << false;
1172 }
1173
1174 return TRUE;
1175}
1176
1177void Field::SetDelay(FX_BOOL bDelay) {
1178 m_bDelay = bDelay;
1179
1180 if (!m_bDelay) {
1181 if (m_pJSDoc)
1182 m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex);
1183 }
1184}
1185
Tom Sepezba038bc2015-10-08 12:03:00 -07001186FX_BOOL Field::delay(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001187 CJS_PropValue& vp,
1188 CFX_WideString& sError) {
1189 if (vp.IsSetting()) {
1190 if (!m_bCanSet)
1191 return FALSE;
1192
1193 bool bVP;
1194 vp >> bVP;
1195
1196 SetDelay(bVP);
1197 } else {
1198 vp << m_bDelay;
1199 }
1200 return TRUE;
1201}
1202
Tom Sepezba038bc2015-10-08 12:03:00 -07001203FX_BOOL Field::display(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001204 CJS_PropValue& vp,
1205 CFX_WideString& sError) {
1206 ASSERT(m_pDocument != NULL);
1207
1208 if (vp.IsSetting()) {
1209 if (!m_bCanSet)
1210 return FALSE;
1211
1212 int nVP;
1213 vp >> nVP;
1214
1215 if (m_bDelay) {
1216 AddDelay_Int(FP_DISPLAY, nVP);
1217 } else {
1218 Field::SetDisplay(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
1219 }
1220 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001221 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1222 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001223 return FALSE;
1224
Lei Zhangd88a3642015-11-10 09:38:57 -08001225 CPDF_FormField* pFormField = FieldArray[0];
1226 ASSERT(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001227 CPDFSDK_InterForm* pInterForm =
1228 (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001229 CPDFSDK_Widget* pWidget =
1230 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1231 if (!pWidget)
1232 return FALSE;
1233
1234 FX_DWORD dwFlag = pWidget->GetFlags();
1235
1236 if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag) {
1237 vp << (int32_t)1;
1238 } else {
1239 if (ANNOTFLAG_PRINT & dwFlag) {
1240 if (ANNOTFLAG_NOVIEW & dwFlag) {
1241 vp << (int32_t)3;
1242 } else {
1243 vp << (int32_t)0;
1244 }
1245 } else {
1246 vp << (int32_t)2;
1247 }
1248 }
1249 }
1250
1251 return TRUE;
1252}
1253
1254void Field::SetDisplay(CPDFSDK_Document* pDocument,
1255 const CFX_WideString& swFieldName,
1256 int nControlIndex,
1257 int number) {
1258 ASSERT(pDocument != NULL);
1259
1260 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
1261 ASSERT(pInterForm != NULL);
1262
Lei Zhangd88a3642015-11-10 09:38:57 -08001263 std::vector<CPDF_FormField*> FieldArray =
1264 GetFormFields(pDocument, swFieldName);
1265 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001266 if (nControlIndex < 0) {
1267 FX_BOOL bSet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001268 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1269 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001270 ASSERT(pFormControl != NULL);
1271
1272 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1273 FX_DWORD dwFlag = pWidget->GetFlags();
1274 switch (number) {
1275 case 0:
1276 dwFlag &= (~ANNOTFLAG_INVISIBLE);
1277 dwFlag &= (~ANNOTFLAG_HIDDEN);
1278 dwFlag &= (~ANNOTFLAG_NOVIEW);
1279 dwFlag |= ANNOTFLAG_PRINT;
1280 break;
1281 case 1:
1282 dwFlag &= (~ANNOTFLAG_INVISIBLE);
1283 dwFlag &= (~ANNOTFLAG_NOVIEW);
1284 dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
1285 break;
1286 case 2:
1287 dwFlag &= (~ANNOTFLAG_INVISIBLE);
1288 dwFlag &= (~ANNOTFLAG_PRINT);
1289 dwFlag &= (~ANNOTFLAG_HIDDEN);
1290 dwFlag &= (~ANNOTFLAG_NOVIEW);
1291 break;
1292 case 3:
1293 dwFlag |= ANNOTFLAG_NOVIEW;
1294 dwFlag |= ANNOTFLAG_PRINT;
1295 dwFlag &= (~ANNOTFLAG_HIDDEN);
1296 break;
1297 }
1298
1299 if (dwFlag != pWidget->GetFlags()) {
1300 pWidget->SetFlags(dwFlag);
1301 bSet = TRUE;
1302 }
1303 }
1304 }
1305
1306 if (bSet)
1307 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
1308 } else {
1309 if (nControlIndex >= pFormField->CountControls())
1310 return;
1311 if (CPDF_FormControl* pFormControl =
1312 pFormField->GetControl(nControlIndex)) {
1313 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1314 FX_DWORD dwFlag = pWidget->GetFlags();
1315 switch (number) {
1316 case 0:
1317 dwFlag &= (~ANNOTFLAG_INVISIBLE);
1318 dwFlag &= (~ANNOTFLAG_HIDDEN);
1319 dwFlag &= (~ANNOTFLAG_NOVIEW);
1320 dwFlag |= ANNOTFLAG_PRINT;
1321 break;
1322 case 1:
1323 dwFlag &= (~ANNOTFLAG_INVISIBLE);
1324 dwFlag &= (~ANNOTFLAG_NOVIEW);
1325 dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
1326 break;
1327 case 2:
1328 dwFlag &= (~ANNOTFLAG_INVISIBLE);
1329 dwFlag &= (~ANNOTFLAG_PRINT);
1330 dwFlag &= (~ANNOTFLAG_HIDDEN);
1331 dwFlag &= (~ANNOTFLAG_NOVIEW);
1332 break;
1333 case 3:
1334 dwFlag |= ANNOTFLAG_NOVIEW;
1335 dwFlag |= ANNOTFLAG_PRINT;
1336 dwFlag &= (~ANNOTFLAG_HIDDEN);
1337 break;
1338 }
1339 if (dwFlag != pWidget->GetFlags()) {
1340 pWidget->SetFlags(dwFlag);
1341 UpdateFormControl(pDocument, pFormControl, TRUE, FALSE, TRUE);
1342 }
1343 }
1344 }
1345 }
1346 }
1347}
1348
Tom Sepezba038bc2015-10-08 12:03:00 -07001349FX_BOOL Field::doc(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001350 if (!vp.IsGetting()) {
1351 return FALSE;
1352 }
1353 vp << m_pJSDoc->GetCJSDoc();
1354 return TRUE;
1355}
1356
Tom Sepezba038bc2015-10-08 12:03:00 -07001357FX_BOOL Field::editable(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001358 CJS_PropValue& vp,
1359 CFX_WideString& sError) {
1360 ASSERT(m_pDocument != NULL);
1361 if (vp.IsSetting()) {
1362 if (!m_bCanSet)
1363 return FALSE;
1364
1365 bool bVP;
1366 vp >> bVP;
1367 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001368 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1369 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001370 return FALSE;
1371
Lei Zhangd88a3642015-11-10 09:38:57 -08001372 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001373 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX)
1374 return FALSE;
1375
1376 if (pFormField->GetFieldFlags() & FIELDFLAG_EDIT)
1377 vp << true;
1378 else
1379 vp << false;
1380 }
1381
1382 return TRUE;
1383}
1384
Tom Sepezba038bc2015-10-08 12:03:00 -07001385FX_BOOL Field::exportValues(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001386 CJS_PropValue& vp,
1387 CFX_WideString& sError) {
Lei Zhangd88a3642015-11-10 09:38:57 -08001388 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1389 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001390 return FALSE;
1391
Lei Zhangd88a3642015-11-10 09:38:57 -08001392 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001393 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001394 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001395 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001396 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001397
1398 if (vp.IsSetting()) {
1399 if (!m_bCanSet)
1400 return FALSE;
1401
1402 if (!vp.IsArrayObject())
1403 return FALSE;
1404 } else {
Tom Sepez67fd5df2015-10-08 12:24:19 -07001405 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
1406 CJS_Array ExportValusArray(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001407 if (m_nFormControlIndex < 0) {
1408 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
1409 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
1410 ExportValusArray.SetElement(
Tom Sepez67fd5df2015-10-08 12:24:19 -07001411 i, CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001412 }
1413 } else {
1414 if (m_nFormControlIndex >= pFormField->CountControls())
1415 return FALSE;
1416
1417 CPDF_FormControl* pFormControl =
1418 pFormField->GetControl(m_nFormControlIndex);
1419 if (!pFormControl)
1420 return FALSE;
1421
1422 ExportValusArray.SetElement(
Tom Sepez67fd5df2015-10-08 12:24:19 -07001423 0, CJS_Value(pRuntime, pFormControl->GetExportValue().c_str()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001424 }
1425 vp << ExportValusArray;
1426 }
1427 return TRUE;
1428}
1429
Tom Sepezba038bc2015-10-08 12:03:00 -07001430FX_BOOL Field::fileSelect(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001431 CJS_PropValue& vp,
1432 CFX_WideString& sError) {
1433 ASSERT(m_pDocument != NULL);
1434
Lei Zhangd88a3642015-11-10 09:38:57 -08001435 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1436 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001437 return FALSE;
1438
Lei Zhangd88a3642015-11-10 09:38:57 -08001439 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001440 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1441 return FALSE;
1442
1443 if (vp.IsSetting()) {
1444 if (!m_bCanSet)
1445 return FALSE;
1446
1447 bool bVP;
1448 vp >> bVP;
1449 } else {
1450 if (pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT)
1451 vp << true;
1452 else
1453 vp << false;
1454 }
1455 return TRUE;
1456}
1457
Tom Sepezba038bc2015-10-08 12:03:00 -07001458FX_BOOL Field::fillColor(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001459 CJS_PropValue& vp,
1460 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07001461 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
1462 CJS_Array crArray(pRuntime);
Lei Zhangd88a3642015-11-10 09:38:57 -08001463 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1464 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001465 return FALSE;
1466
1467 if (vp.IsSetting()) {
1468 if (!m_bCanSet)
1469 return FALSE;
1470
1471 if (!vp.IsArrayObject())
1472 return FALSE;
1473
1474 vp >> crArray;
1475
1476 CPWL_Color color;
1477 color::ConvertArrayToPWLColor(crArray, color);
1478 if (m_bDelay) {
1479 AddDelay_Color(FP_FILLCOLOR, color);
1480 } else {
1481 Field::SetFillColor(m_pDocument, m_FieldName, m_nFormControlIndex, color);
1482 }
1483 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001484 CPDF_FormField* pFormField = FieldArray[0];
1485 ASSERT(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001486 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1487 if (!pFormControl)
1488 return FALSE;
1489
1490 int iColorType;
1491 pFormControl->GetBackgroundColor(iColorType);
1492
1493 CPWL_Color color;
1494 if (iColorType == COLORTYPE_TRANSPARENT) {
1495 color = CPWL_Color(COLORTYPE_TRANSPARENT);
1496 } else if (iColorType == COLORTYPE_GRAY) {
1497 color = CPWL_Color(COLORTYPE_GRAY,
1498 pFormControl->GetOriginalBackgroundColor(0));
1499 } else if (iColorType == COLORTYPE_RGB) {
1500 color =
1501 CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBackgroundColor(0),
1502 pFormControl->GetOriginalBackgroundColor(1),
1503 pFormControl->GetOriginalBackgroundColor(2));
1504 } else if (iColorType == COLORTYPE_CMYK) {
1505 color = CPWL_Color(COLORTYPE_CMYK,
1506 pFormControl->GetOriginalBackgroundColor(0),
1507 pFormControl->GetOriginalBackgroundColor(1),
1508 pFormControl->GetOriginalBackgroundColor(2),
1509 pFormControl->GetOriginalBackgroundColor(3));
Lei Zhangd88a3642015-11-10 09:38:57 -08001510 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001511 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001512 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001513
1514 color::ConvertPWLColorToArray(color, crArray);
1515 vp << crArray;
1516 }
1517
1518 return TRUE;
1519}
1520
1521void Field::SetFillColor(CPDFSDK_Document* pDocument,
1522 const CFX_WideString& swFieldName,
1523 int nControlIndex,
1524 const CPWL_Color& color) {
1525 // Not supported.
1526}
1527
Tom Sepezba038bc2015-10-08 12:03:00 -07001528FX_BOOL Field::hidden(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001529 CJS_PropValue& vp,
1530 CFX_WideString& sError) {
1531 ASSERT(m_pDocument != NULL);
1532
1533 if (vp.IsSetting()) {
1534 if (!m_bCanSet)
1535 return FALSE;
1536
1537 bool bVP;
1538 vp >> bVP;
1539
1540 if (m_bDelay) {
1541 AddDelay_Bool(FP_HIDDEN, bVP);
1542 } else {
1543 Field::SetHidden(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
1544 }
1545 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001546 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1547 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001548 return FALSE;
1549
Lei Zhangd88a3642015-11-10 09:38:57 -08001550 CPDF_FormField* pFormField = FieldArray[0];
1551 ASSERT(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001552 CPDFSDK_InterForm* pInterForm =
1553 (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001554 CPDFSDK_Widget* pWidget =
1555 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
1556 if (!pWidget)
1557 return FALSE;
1558
1559 FX_DWORD dwFlags = pWidget->GetFlags();
1560
Lei Zhangd88a3642015-11-10 09:38:57 -08001561 if (ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001562 vp << true;
Lei Zhangd88a3642015-11-10 09:38:57 -08001563 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001564 vp << false;
1565 }
1566
1567 return TRUE;
1568}
1569
1570void Field::SetHidden(CPDFSDK_Document* pDocument,
1571 const CFX_WideString& swFieldName,
1572 int nControlIndex,
1573 bool b) {
1574 ASSERT(pDocument != NULL);
1575
1576 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
1577 ASSERT(pInterForm != NULL);
1578
Lei Zhangd88a3642015-11-10 09:38:57 -08001579 std::vector<CPDF_FormField*> FieldArray =
1580 GetFormFields(pDocument, swFieldName);
1581 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001582 if (nControlIndex < 0) {
1583 FX_BOOL bSet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001584 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001585 if (CPDFSDK_Widget* pWidget =
Lei Zhangd88a3642015-11-10 09:38:57 -08001586 pInterForm->GetWidget(pFormField->GetControl(i))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001587 FX_DWORD dwFlags = pWidget->GetFlags();
1588
1589 if (b) {
1590 dwFlags &= (~ANNOTFLAG_INVISIBLE);
1591 dwFlags &= (~ANNOTFLAG_NOVIEW);
1592 dwFlags |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
1593 } else {
1594 dwFlags &= (~ANNOTFLAG_INVISIBLE);
1595 dwFlags &= (~ANNOTFLAG_HIDDEN);
1596 dwFlags &= (~ANNOTFLAG_NOVIEW);
1597 dwFlags |= ANNOTFLAG_PRINT;
1598 }
1599
1600 if (dwFlags != pWidget->GetFlags()) {
1601 pWidget->SetFlags(dwFlags);
1602 bSet = TRUE;
1603 }
1604 }
1605 }
1606
1607 if (bSet)
1608 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
1609 } else {
1610 if (nControlIndex >= pFormField->CountControls())
1611 return;
1612 if (CPDF_FormControl* pFormControl =
1613 pFormField->GetControl(nControlIndex)) {
1614 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1615 FX_DWORD dwFlags = pWidget->GetFlags();
1616
1617 if (b) {
1618 dwFlags &= (~ANNOTFLAG_INVISIBLE);
1619 dwFlags &= (~ANNOTFLAG_NOVIEW);
1620 dwFlags |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
1621 } else {
1622 dwFlags &= (~ANNOTFLAG_INVISIBLE);
1623 dwFlags &= (~ANNOTFLAG_HIDDEN);
1624 dwFlags &= (~ANNOTFLAG_NOVIEW);
1625 dwFlags |= ANNOTFLAG_PRINT;
1626 }
1627
1628 if (dwFlags != pWidget->GetFlags()) {
1629 pWidget->SetFlags(dwFlags);
1630 UpdateFormControl(pDocument, pFormControl, TRUE, FALSE, TRUE);
1631 }
1632 }
1633 }
1634 }
1635 }
1636}
1637
Tom Sepezba038bc2015-10-08 12:03:00 -07001638FX_BOOL Field::highlight(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001639 CJS_PropValue& vp,
1640 CFX_WideString& sError) {
1641 ASSERT(m_pDocument != NULL);
1642
1643 if (vp.IsSetting()) {
1644 if (!m_bCanSet)
1645 return FALSE;
1646
1647 CFX_ByteString strMode;
1648 vp >> strMode;
1649
1650 if (m_bDelay) {
1651 AddDelay_String(FP_HIGHLIGHT, strMode);
1652 } else {
1653 Field::SetHighlight(m_pDocument, m_FieldName, m_nFormControlIndex,
1654 strMode);
1655 }
1656 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001657 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1658 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001659 return FALSE;
1660
Lei Zhangd88a3642015-11-10 09:38:57 -08001661 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001662 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
1663 return FALSE;
1664
1665 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1666 if (!pFormControl)
1667 return FALSE;
1668
1669 int eHM = pFormControl->GetHighlightingMode();
1670 switch (eHM) {
1671 case CPDF_FormControl::None:
1672 vp << L"none";
1673 break;
1674 case CPDF_FormControl::Push:
1675 vp << L"push";
1676 break;
1677 case CPDF_FormControl::Invert:
1678 vp << L"invert";
1679 break;
1680 case CPDF_FormControl::Outline:
1681 vp << L"outline";
1682 break;
1683 case CPDF_FormControl::Toggle:
1684 vp << L"toggle";
1685 break;
1686 }
1687 }
1688
1689 return TRUE;
1690}
1691
1692void Field::SetHighlight(CPDFSDK_Document* pDocument,
1693 const CFX_WideString& swFieldName,
1694 int nControlIndex,
1695 const CFX_ByteString& string) {
1696 // Not supported.
1697}
1698
Tom Sepezba038bc2015-10-08 12:03:00 -07001699FX_BOOL Field::lineWidth(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001700 CJS_PropValue& vp,
1701 CFX_WideString& sError) {
1702 ASSERT(m_pDocument != NULL);
1703
1704 if (vp.IsSetting()) {
1705 if (!m_bCanSet)
1706 return FALSE;
1707
1708 int iWidth;
1709 vp >> iWidth;
1710
1711 if (m_bDelay) {
1712 AddDelay_Int(FP_LINEWIDTH, iWidth);
1713 } else {
1714 Field::SetLineWidth(m_pDocument, m_FieldName, m_nFormControlIndex,
1715 iWidth);
1716 }
1717 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001718 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1719 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001720 return FALSE;
1721
Lei Zhangd88a3642015-11-10 09:38:57 -08001722 CPDF_FormField* pFormField = FieldArray[0];
1723 ASSERT(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001724 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
1725 if (!pFormControl)
1726 return FALSE;
1727
1728 CPDFSDK_InterForm* pInterForm =
1729 (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
1730 ASSERT(pInterForm != NULL);
1731
1732 if (!pFormField->CountControls())
1733 return FALSE;
1734
1735 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
1736 if (!pWidget)
1737 return FALSE;
1738
1739 vp << (int32_t)pWidget->GetBorderWidth();
1740 }
1741
1742 return TRUE;
1743}
1744
1745void Field::SetLineWidth(CPDFSDK_Document* pDocument,
1746 const CFX_WideString& swFieldName,
1747 int nControlIndex,
1748 int number) {
1749 ASSERT(pDocument != NULL);
1750
1751 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
1752 ASSERT(pInterForm != NULL);
1753
Lei Zhangd88a3642015-11-10 09:38:57 -08001754 std::vector<CPDF_FormField*> FieldArray =
1755 GetFormFields(pDocument, swFieldName);
1756 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001757 if (nControlIndex < 0) {
1758 FX_BOOL bSet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001759 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
1760 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001761 ASSERT(pFormControl != NULL);
1762
1763 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1764 if (number != pWidget->GetBorderWidth()) {
1765 pWidget->SetBorderWidth(number);
1766 bSet = TRUE;
1767 }
1768 }
1769 }
1770 if (bSet)
1771 UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
1772 } else {
1773 if (nControlIndex >= pFormField->CountControls())
1774 return;
1775 if (CPDF_FormControl* pFormControl =
1776 pFormField->GetControl(nControlIndex)) {
1777 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
1778 if (number != pWidget->GetBorderWidth()) {
1779 pWidget->SetBorderWidth(number);
1780 UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
1781 }
1782 }
1783 }
1784 }
1785 }
1786}
1787
Tom Sepezba038bc2015-10-08 12:03:00 -07001788FX_BOOL Field::multiline(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001789 CJS_PropValue& vp,
1790 CFX_WideString& sError) {
1791 ASSERT(m_pDocument != NULL);
1792
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_MULTILINE, bVP);
1802 } else {
1803 Field::SetMultiline(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
1804 }
1805 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001806 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1807 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001808 return FALSE;
1809
Lei Zhangd88a3642015-11-10 09:38:57 -08001810 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001811 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1812 return FALSE;
1813
1814 if (pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE)
1815 vp << true;
1816 else
1817 vp << false;
1818 }
1819
1820 return TRUE;
1821}
1822
1823void Field::SetMultiline(CPDFSDK_Document* pDocument,
1824 const CFX_WideString& swFieldName,
1825 int nControlIndex,
1826 bool b) {
1827 // Not supported.
1828}
1829
Tom Sepezba038bc2015-10-08 12:03:00 -07001830FX_BOOL Field::multipleSelection(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001831 CJS_PropValue& vp,
1832 CFX_WideString& sError) {
1833 ASSERT(m_pDocument != NULL);
1834
1835 if (vp.IsSetting()) {
1836 if (!m_bCanSet)
1837 return FALSE;
1838
1839 bool bVP;
1840 vp >> bVP;
1841
1842 if (m_bDelay) {
1843 AddDelay_Bool(FP_MULTIPLESELECTION, bVP);
1844 } else {
1845 Field::SetMultipleSelection(m_pDocument, m_FieldName, m_nFormControlIndex,
1846 bVP);
1847 }
1848 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001849 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1850 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001851 return FALSE;
1852
Lei Zhangd88a3642015-11-10 09:38:57 -08001853 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001854 if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
1855 return FALSE;
1856
1857 if (pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT)
1858 vp << true;
1859 else
1860 vp << false;
1861 }
1862
1863 return TRUE;
1864}
1865
1866void Field::SetMultipleSelection(CPDFSDK_Document* pDocument,
1867 const CFX_WideString& swFieldName,
1868 int nControlIndex,
1869 bool b) {
1870 // Not supported.
1871}
1872
Tom Sepezba038bc2015-10-08 12:03:00 -07001873FX_BOOL Field::name(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001874 CJS_PropValue& vp,
1875 CFX_WideString& sError) {
1876 if (!vp.IsGetting())
1877 return FALSE;
1878
Lei Zhangd88a3642015-11-10 09:38:57 -08001879 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1880 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001881 return FALSE;
1882
1883 vp << m_FieldName;
1884
1885 return TRUE;
1886}
1887
Tom Sepezba038bc2015-10-08 12:03:00 -07001888FX_BOOL Field::numItems(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001889 CJS_PropValue& vp,
1890 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07001891 if (!vp.IsGetting())
1892 return FALSE;
1893
Lei Zhangd88a3642015-11-10 09:38:57 -08001894 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1895 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001896 return FALSE;
1897
Lei Zhangd88a3642015-11-10 09:38:57 -08001898 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001899 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
Lei Zhangd88a3642015-11-10 09:38:57 -08001900 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001901 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08001902 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001903
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001904 vp << (int32_t)pFormField->CountOptions();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001905 return TRUE;
1906}
1907
Tom Sepezba038bc2015-10-08 12:03:00 -07001908FX_BOOL Field::page(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001909 CJS_PropValue& vp,
1910 CFX_WideString& sError) {
1911 if (!vp.IsGetting())
1912 return FALSE;
1913
Lei Zhangd88a3642015-11-10 09:38:57 -08001914 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1915 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001916 return FALSE;
1917
Lei Zhangd88a3642015-11-10 09:38:57 -08001918 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001919 if (!pFormField)
1920 return FALSE;
1921
Lei Zhangd88a3642015-11-10 09:38:57 -08001922 std::vector<CPDFSDK_Widget*> widgets;
1923 m_pDocument->GetInterForm()->GetWidgets(pFormField, &widgets);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001924
Lei Zhangd88a3642015-11-10 09:38:57 -08001925 if (widgets.empty()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001926 vp << (int32_t)-1;
Lei Zhangd88a3642015-11-10 09:38:57 -08001927 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001928 }
1929
Lei Zhangd88a3642015-11-10 09:38:57 -08001930 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
1931 CJS_Array PageArray(pRuntime);
1932 for (size_t i = 0; i < widgets.size(); ++i) {
1933 CPDFSDK_PageView* pPageView = widgets[i]->GetPageView();
1934 if (!pPageView)
1935 return FALSE;
1936
1937 PageArray.SetElement(
1938 i, CJS_Value(pRuntime, (int32_t)pPageView->GetPageIndex()));
1939 }
1940
1941 vp << PageArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001942 return TRUE;
1943}
1944
Tom Sepezba038bc2015-10-08 12:03:00 -07001945FX_BOOL Field::password(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001946 CJS_PropValue& vp,
1947 CFX_WideString& sError) {
1948 ASSERT(m_pDocument != NULL);
1949
1950 if (vp.IsSetting()) {
1951 if (!m_bCanSet)
1952 return FALSE;
1953
1954 bool bVP;
1955 vp >> bVP;
1956
1957 if (m_bDelay) {
1958 AddDelay_Bool(FP_PASSWORD, bVP);
1959 } else {
1960 Field::SetPassword(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
1961 }
1962 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08001963 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1964 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001965 return FALSE;
1966
Lei Zhangd88a3642015-11-10 09:38:57 -08001967 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001968 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
1969 return FALSE;
1970
1971 if (pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD)
1972 vp << true;
1973 else
1974 vp << false;
1975 }
1976
1977 return TRUE;
1978}
1979
1980void Field::SetPassword(CPDFSDK_Document* pDocument,
1981 const CFX_WideString& swFieldName,
1982 int nControlIndex,
1983 bool b) {
1984 // Not supported.
1985}
1986
Tom Sepezba038bc2015-10-08 12:03:00 -07001987FX_BOOL Field::print(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001988 CJS_PropValue& vp,
1989 CFX_WideString& sError) {
1990 ASSERT(m_pDocument != NULL);
1991
1992 CPDFSDK_InterForm* pInterForm =
1993 (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
1994 ASSERT(pInterForm != NULL);
1995
Lei Zhangd88a3642015-11-10 09:38:57 -08001996 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
1997 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001998 return FALSE;
1999
2000 if (vp.IsSetting()) {
2001 if (!m_bCanSet)
2002 return FALSE;
2003
2004 bool bVP;
2005 vp >> bVP;
2006
Lei Zhangd88a3642015-11-10 09:38:57 -08002007 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002008 if (m_nFormControlIndex < 0) {
2009 FX_BOOL bSet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08002010 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002011 if (CPDFSDK_Widget* pWidget =
Lei Zhangd88a3642015-11-10 09:38:57 -08002012 pInterForm->GetWidget(pFormField->GetControl(i))) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002013 FX_DWORD dwFlags = pWidget->GetFlags();
2014 if (bVP)
2015 dwFlags |= ANNOTFLAG_PRINT;
2016 else
2017 dwFlags &= ~ANNOTFLAG_PRINT;
2018
2019 if (dwFlags != pWidget->GetFlags()) {
2020 pWidget->SetFlags(dwFlags);
2021 bSet = TRUE;
2022 }
2023 }
2024 }
2025
2026 if (bSet)
2027 UpdateFormField(m_pDocument, pFormField, TRUE, FALSE, TRUE);
2028 } else {
2029 if (m_nFormControlIndex >= pFormField->CountControls())
2030 return FALSE;
2031 if (CPDF_FormControl* pFormControl =
2032 pFormField->GetControl(m_nFormControlIndex)) {
2033 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
2034 FX_DWORD dwFlags = pWidget->GetFlags();
2035 if (bVP)
2036 dwFlags |= ANNOTFLAG_PRINT;
2037 else
2038 dwFlags &= ~ANNOTFLAG_PRINT;
2039
2040 if (dwFlags != pWidget->GetFlags()) {
2041 pWidget->SetFlags(dwFlags);
2042 UpdateFormControl(m_pDocument,
2043 pFormField->GetControl(m_nFormControlIndex),
2044 TRUE, FALSE, TRUE);
2045 }
2046 }
2047 }
2048 }
2049 }
2050 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002051 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002052 CPDFSDK_Widget* pWidget =
2053 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
2054 if (!pWidget)
2055 return FALSE;
2056
2057 if (pWidget->GetFlags() & ANNOTFLAG_PRINT)
2058 vp << true;
2059 else
2060 vp << false;
2061 }
2062
2063 return TRUE;
2064}
2065
Tom Sepezba038bc2015-10-08 12:03:00 -07002066FX_BOOL Field::radiosInUnison(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002067 CJS_PropValue& vp,
2068 CFX_WideString& sError) {
2069 ASSERT(m_pDocument != NULL);
2070
Lei Zhangd88a3642015-11-10 09:38:57 -08002071 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2072 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002073 return FALSE;
2074
2075 if (vp.IsSetting()) {
2076 if (!m_bCanSet)
2077 return FALSE;
2078
2079 bool bVP;
2080 vp >> bVP;
2081
2082 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002083 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002084 if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
2085 return FALSE;
2086
2087 if (pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)
2088 vp << true;
2089 else
2090 vp << false;
2091 }
2092
2093 return TRUE;
2094}
2095
Tom Sepezba038bc2015-10-08 12:03:00 -07002096FX_BOOL Field::readonly(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002097 CJS_PropValue& vp,
2098 CFX_WideString& sError) {
2099 ASSERT(m_pDocument != NULL);
2100
Lei Zhangd88a3642015-11-10 09:38:57 -08002101 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2102 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002103 return FALSE;
2104
2105 if (vp.IsSetting()) {
2106 if (!m_bCanSet)
2107 return FALSE;
2108
2109 bool bVP;
2110 vp >> bVP;
2111
2112 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002113 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002114 if (pFormField->GetFieldFlags() & FIELDFLAG_READONLY)
2115 vp << true;
2116 else
2117 vp << false;
2118 }
2119
2120 return TRUE;
2121}
2122
Tom Sepezba038bc2015-10-08 12:03:00 -07002123FX_BOOL Field::rect(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002124 CJS_PropValue& vp,
2125 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002126 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
2127 CJS_Value Upper_Leftx(pRuntime);
2128 CJS_Value Upper_Lefty(pRuntime);
2129 CJS_Value Lower_Rightx(pRuntime);
2130 CJS_Value Lower_Righty(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002131
2132 if (vp.IsSetting()) {
2133 if (!m_bCanSet)
2134 return FALSE;
2135 if (!vp.IsArrayObject())
2136 return FALSE;
2137
Tom Sepez67fd5df2015-10-08 12:24:19 -07002138 CJS_Array rcArray(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002139 vp >> rcArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002140 rcArray.GetElement(0, Upper_Leftx);
2141 rcArray.GetElement(1, Upper_Lefty);
2142 rcArray.GetElement(2, Lower_Rightx);
2143 rcArray.GetElement(3, Lower_Righty);
2144
2145 FX_FLOAT pArray[4] = {0.0f, 0.0f, 0.0f, 0.0f};
2146 pArray[0] = (FX_FLOAT)Upper_Leftx.ToInt();
2147 pArray[1] = (FX_FLOAT)Lower_Righty.ToInt();
2148 pArray[2] = (FX_FLOAT)Lower_Rightx.ToInt();
2149 pArray[3] = (FX_FLOAT)Upper_Lefty.ToInt();
2150
2151 CPDF_Rect crRect(pArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002152 if (m_bDelay) {
2153 AddDelay_Rect(FP_RECT, crRect);
2154 } else {
2155 Field::SetRect(m_pDocument, m_FieldName, m_nFormControlIndex, crRect);
2156 }
2157 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002158 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2159 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002160 return FALSE;
2161
Lei Zhangd88a3642015-11-10 09:38:57 -08002162 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002163 CPDFSDK_InterForm* pInterForm =
2164 (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002165 CPDFSDK_Widget* pWidget =
2166 pInterForm->GetWidget(GetSmartFieldControl(pFormField));
2167 if (!pWidget)
2168 return FALSE;
2169
2170 CFX_FloatRect crRect = pWidget->GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002171 Upper_Leftx = (int32_t)crRect.left;
2172 Upper_Lefty = (int32_t)crRect.top;
2173 Lower_Rightx = (int32_t)crRect.right;
2174 Lower_Righty = (int32_t)crRect.bottom;
2175
Tom Sepez67fd5df2015-10-08 12:24:19 -07002176 CJS_Array rcArray(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002177 rcArray.SetElement(0, Upper_Leftx);
2178 rcArray.SetElement(1, Upper_Lefty);
2179 rcArray.SetElement(2, Lower_Rightx);
2180 rcArray.SetElement(3, Lower_Righty);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002181 vp << rcArray;
2182 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002183 return TRUE;
2184}
2185
2186void Field::SetRect(CPDFSDK_Document* pDocument,
2187 const CFX_WideString& swFieldName,
2188 int nControlIndex,
2189 const CPDF_Rect& rect) {
2190 ASSERT(pDocument != NULL);
2191
2192 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
2193 ASSERT(pInterForm != NULL);
2194
Lei Zhangd88a3642015-11-10 09:38:57 -08002195 std::vector<CPDF_FormField*> FieldArray =
2196 GetFormFields(pDocument, swFieldName);
2197 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002198 if (nControlIndex < 0) {
2199 FX_BOOL bSet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08002200 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002201 CPDF_FormControl* pFormControl = pFormField->GetControl(i);
2202 ASSERT(pFormControl != NULL);
2203
2204 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
2205 CPDF_Rect crRect = rect;
2206
2207 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002208 crRect.Intersect(pPDFPage->GetPageBBox());
2209
2210 if (!crRect.IsEmpty()) {
2211 CPDF_Rect rcOld = pWidget->GetRect();
2212 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
2213 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
2214 pWidget->SetRect(crRect);
2215 bSet = TRUE;
2216 }
2217 }
2218 }
2219 }
2220
2221 if (bSet)
2222 UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
2223 } else {
2224 if (nControlIndex >= pFormField->CountControls())
2225 return;
2226 if (CPDF_FormControl* pFormControl =
2227 pFormField->GetControl(nControlIndex)) {
2228 if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) {
2229 CPDF_Rect crRect = rect;
2230
2231 CPDF_Page* pPDFPage = pWidget->GetPDFPage();
2232 ASSERT(pPDFPage != NULL);
2233
2234 // CPDF_Page* pPDFPage = pPage->GetPage();
2235 // ASSERT(pPDFPage != NULL);
2236
2237 crRect.Intersect(pPDFPage->GetPageBBox());
2238
2239 if (!crRect.IsEmpty()) {
2240 CPDF_Rect rcOld = pWidget->GetRect();
2241 if (crRect.left != rcOld.left || crRect.right != rcOld.right ||
2242 crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) {
2243 pWidget->SetRect(crRect);
2244 UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
2245 }
2246 }
2247 }
2248 }
2249 }
2250 }
2251}
2252
Tom Sepezba038bc2015-10-08 12:03:00 -07002253FX_BOOL Field::required(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002254 CJS_PropValue& vp,
2255 CFX_WideString& sError) {
2256 ASSERT(m_pDocument != NULL);
2257
Lei Zhangd88a3642015-11-10 09:38:57 -08002258 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2259 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002260 return FALSE;
2261
2262 if (vp.IsSetting()) {
2263 if (!m_bCanSet)
2264 return FALSE;
2265
2266 bool bVP;
2267 vp >> bVP;
2268
2269 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002270 CPDF_FormField* pFormField = FieldArray[0];
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002271 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002272 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002273
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002274 if (pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED)
2275 vp << true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002276 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002277 vp << false;
2278 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002279
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002280 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002281}
2282
Tom Sepezba038bc2015-10-08 12:03:00 -07002283FX_BOOL Field::richText(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002284 CJS_PropValue& vp,
2285 CFX_WideString& sError) {
2286 ASSERT(m_pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002287
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002288 if (vp.IsSetting()) {
2289 if (!m_bCanSet)
2290 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002291
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002292 bool bVP;
2293 vp >> bVP;
2294
2295 if (m_bDelay) {
2296 AddDelay_Bool(FP_RICHTEXT, bVP);
2297 } else {
2298 Field::SetRichText(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
2299 }
2300 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002301 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2302 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002303 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002304
Lei Zhangd88a3642015-11-10 09:38:57 -08002305 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002306 if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
2307 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002308
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002309 if (pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT)
2310 vp << true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002311 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002312 vp << false;
2313 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002314
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002315 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002316}
2317
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002318void Field::SetRichText(CPDFSDK_Document* pDocument,
2319 const CFX_WideString& swFieldName,
2320 int nControlIndex,
2321 bool b) {
2322 // Not supported.
2323}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002324
Tom Sepezba038bc2015-10-08 12:03:00 -07002325FX_BOOL Field::richValue(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002326 CJS_PropValue& vp,
2327 CFX_WideString& sError) {
2328 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002329}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002330
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002331void Field::SetRichValue(CPDFSDK_Document* pDocument,
2332 const CFX_WideString& swFieldName,
2333 int nControlIndex) {
2334 // Not supported.
2335}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002336
Tom Sepezba038bc2015-10-08 12:03:00 -07002337FX_BOOL Field::rotation(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002338 CJS_PropValue& vp,
2339 CFX_WideString& sError) {
2340 ASSERT(m_pDocument != NULL);
2341
2342 if (vp.IsSetting()) {
2343 if (!m_bCanSet)
2344 return FALSE;
2345
2346 int nVP;
2347 vp >> nVP;
2348
2349 if (m_bDelay) {
2350 AddDelay_Int(FP_ROTATION, nVP);
2351 } else {
2352 Field::SetRotation(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
2353 }
2354 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002355 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2356 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002357 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002358
Lei Zhangd88a3642015-11-10 09:38:57 -08002359 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002360 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2361 if (!pFormControl)
2362 return FALSE;
2363
2364 vp << (int32_t)pFormControl->GetRotation();
2365 }
2366
2367 return TRUE;
2368}
2369
2370void Field::SetRotation(CPDFSDK_Document* pDocument,
2371 const CFX_WideString& swFieldName,
2372 int nControlIndex,
2373 int number) {
2374 // Not supported.
2375}
2376
Tom Sepezba038bc2015-10-08 12:03:00 -07002377FX_BOOL Field::strokeColor(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002378 CJS_PropValue& vp,
2379 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002380 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
2381 CJS_Array crArray(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002382
2383 if (vp.IsSetting()) {
2384 if (!m_bCanSet)
2385 return FALSE;
2386
2387 if (!vp.IsArrayObject())
2388 return FALSE;
2389
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002390 vp >> crArray;
2391
2392 CPWL_Color color;
2393 color::ConvertArrayToPWLColor(crArray, color);
2394
2395 if (m_bDelay) {
2396 AddDelay_Color(FP_STROKECOLOR, color);
2397 } else {
2398 Field::SetStrokeColor(m_pDocument, m_FieldName, m_nFormControlIndex,
2399 color);
2400 }
2401 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002402 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2403 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002404 return FALSE;
2405
Lei Zhangd88a3642015-11-10 09:38:57 -08002406 CPDF_FormField* pFormField = FieldArray[0];
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002407 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002408 if (!pFormControl)
2409 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07002410
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002411 int iColorType;
2412 pFormControl->GetBorderColor(iColorType);
2413
2414 CPWL_Color color;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002415 if (iColorType == COLORTYPE_TRANSPARENT) {
2416 color = CPWL_Color(COLORTYPE_TRANSPARENT);
2417 } else if (iColorType == COLORTYPE_GRAY) {
2418 color =
2419 CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBorderColor(0));
2420 } else if (iColorType == COLORTYPE_RGB) {
2421 color = CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBorderColor(0),
2422 pFormControl->GetOriginalBorderColor(1),
2423 pFormControl->GetOriginalBorderColor(2));
2424 } else if (iColorType == COLORTYPE_CMYK) {
2425 color =
2426 CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBorderColor(0),
2427 pFormControl->GetOriginalBorderColor(1),
2428 pFormControl->GetOriginalBorderColor(2),
2429 pFormControl->GetOriginalBorderColor(3));
Lei Zhangd88a3642015-11-10 09:38:57 -08002430 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002431 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08002432 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002433
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002434 color::ConvertPWLColorToArray(color, crArray);
2435 vp << crArray;
2436 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002437 return TRUE;
2438}
2439
2440void Field::SetStrokeColor(CPDFSDK_Document* pDocument,
2441 const CFX_WideString& swFieldName,
2442 int nControlIndex,
2443 const CPWL_Color& color) {
2444 // Not supported.
2445}
2446
Tom Sepezba038bc2015-10-08 12:03:00 -07002447FX_BOOL Field::style(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002448 CJS_PropValue& vp,
2449 CFX_WideString& sError) {
2450 ASSERT(m_pDocument != NULL);
2451
2452 if (vp.IsSetting()) {
2453 if (!m_bCanSet)
2454 return FALSE;
2455
2456 CFX_ByteString csBCaption;
2457 vp >> csBCaption;
2458
2459 if (m_bDelay) {
2460 AddDelay_String(FP_STYLE, csBCaption);
2461 } else {
2462 Field::SetStyle(m_pDocument, m_FieldName, m_nFormControlIndex,
2463 csBCaption);
2464 }
2465 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002466 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2467 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002468 return FALSE;
2469
Lei Zhangd88a3642015-11-10 09:38:57 -08002470 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002471 if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON &&
Lei Zhangd88a3642015-11-10 09:38:57 -08002472 pFormField->GetFieldType() != FIELDTYPE_CHECKBOX) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002473 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08002474 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002475
2476 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2477 if (!pFormControl)
2478 return FALSE;
2479
2480 CFX_WideString csWCaption = pFormControl->GetNormalCaption();
2481 CFX_ByteString csBCaption;
2482
2483 switch (csWCaption[0]) {
2484 case L'l':
2485 csBCaption = "circle";
2486 break;
2487 case L'8':
2488 csBCaption = "cross";
2489 break;
2490 case L'u':
2491 csBCaption = "diamond";
2492 break;
2493 case L'n':
2494 csBCaption = "square";
2495 break;
2496 case L'H':
2497 csBCaption = "star";
2498 break;
2499 default: // L'4'
2500 csBCaption = "check";
2501 break;
2502 }
2503 vp << csBCaption;
2504 }
2505
2506 return TRUE;
2507}
2508
2509void Field::SetStyle(CPDFSDK_Document* pDocument,
2510 const CFX_WideString& swFieldName,
2511 int nControlIndex,
2512 const CFX_ByteString& string) {
2513 // Not supported.
2514}
2515
Tom Sepezba038bc2015-10-08 12:03:00 -07002516FX_BOOL Field::submitName(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002517 CJS_PropValue& vp,
2518 CFX_WideString& sError) {
2519 return TRUE;
2520}
2521
Tom Sepezba038bc2015-10-08 12:03:00 -07002522FX_BOOL Field::textColor(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002523 CJS_PropValue& vp,
2524 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002525 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
2526 CJS_Array crArray(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002527
2528 if (vp.IsSetting()) {
2529 if (!m_bCanSet)
2530 return FALSE;
2531
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002532 if (!vp.IsArrayObject())
2533 return FALSE;
Tom Sepez67fd5df2015-10-08 12:24:19 -07002534
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002535 vp >> crArray;
2536
2537 CPWL_Color color;
2538 color::ConvertArrayToPWLColor(crArray, color);
2539
2540 if (m_bDelay) {
2541 AddDelay_Color(FP_TEXTCOLOR, color);
2542 } else {
2543 Field::SetTextColor(m_pDocument, m_FieldName, m_nFormControlIndex, color);
2544 }
2545 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002546 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2547 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002548 return FALSE;
2549
Lei Zhangd88a3642015-11-10 09:38:57 -08002550 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002551 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2552 if (!pFormControl)
2553 return FALSE;
2554
2555 int iColorType;
2556 FX_ARGB color;
2557 CPDF_DefaultAppearance FieldAppearance =
2558 pFormControl->GetDefaultAppearance();
2559 FieldAppearance.GetColor(color, iColorType);
2560 int32_t a, r, g, b;
2561 ArgbDecode(color, a, r, g, b);
2562
2563 CPWL_Color crRet =
2564 CPWL_Color(COLORTYPE_RGB, r / 255.0f, g / 255.0f, b / 255.0f);
2565
2566 if (iColorType == COLORTYPE_TRANSPARENT)
2567 crRet = CPWL_Color(COLORTYPE_TRANSPARENT);
2568
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002569 color::ConvertPWLColorToArray(crRet, crArray);
2570 vp << crArray;
2571 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002572 return TRUE;
2573}
2574
2575void Field::SetTextColor(CPDFSDK_Document* pDocument,
2576 const CFX_WideString& swFieldName,
2577 int nControlIndex,
2578 const CPWL_Color& color) {
2579 // Not supported.
2580}
2581
Tom Sepezba038bc2015-10-08 12:03:00 -07002582FX_BOOL Field::textFont(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002583 CJS_PropValue& vp,
2584 CFX_WideString& sError) {
2585 ASSERT(m_pDocument != NULL);
2586
2587 if (vp.IsSetting()) {
2588 if (!m_bCanSet)
2589 return FALSE;
2590
2591 CFX_ByteString csFontName;
2592 vp >> csFontName;
2593 if (csFontName.IsEmpty())
2594 return FALSE;
2595
2596 if (m_bDelay) {
2597 AddDelay_String(FP_TEXTFONT, csFontName);
2598 } else {
2599 Field::SetTextFont(m_pDocument, m_FieldName, m_nFormControlIndex,
2600 csFontName);
2601 }
2602 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002603 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2604 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002605 return FALSE;
2606
Lei Zhangd88a3642015-11-10 09:38:57 -08002607 CPDF_FormField* pFormField = FieldArray[0];
2608 ASSERT(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002609 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2610 if (!pFormControl)
2611 return FALSE;
2612
2613 int nFieldType = pFormField->GetFieldType();
2614
2615 if (nFieldType == FIELDTYPE_PUSHBUTTON ||
2616 nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX ||
2617 nFieldType == FIELDTYPE_TEXTFIELD) {
2618 CPDF_Font* pFont = pFormControl->GetDefaultControlFont();
2619 if (!pFont)
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002620 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002621
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002622 vp << pFont->GetBaseFont();
Lei Zhangd88a3642015-11-10 09:38:57 -08002623 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002624 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08002625 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002626 }
2627
2628 return TRUE;
2629}
2630
2631void Field::SetTextFont(CPDFSDK_Document* pDocument,
2632 const CFX_WideString& swFieldName,
2633 int nControlIndex,
2634 const CFX_ByteString& string) {
2635 // Not supported.
2636}
2637
Tom Sepezba038bc2015-10-08 12:03:00 -07002638FX_BOOL Field::textSize(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002639 CJS_PropValue& vp,
2640 CFX_WideString& sError) {
2641 ASSERT(m_pDocument != NULL);
2642
2643 if (vp.IsSetting()) {
2644 if (!m_bCanSet)
2645 return FALSE;
2646
2647 int nVP;
2648 vp >> nVP;
2649
2650 if (m_bDelay) {
2651 AddDelay_Int(FP_TEXTSIZE, nVP);
2652 } else {
2653 Field::SetTextSize(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
2654 }
2655 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002656 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2657 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002658 return FALSE;
2659
Lei Zhangd88a3642015-11-10 09:38:57 -08002660 CPDF_FormField* pFormField = FieldArray[0];
2661 ASSERT(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002662 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
2663 if (!pFormControl)
2664 return FALSE;
2665
2666 CPDF_DefaultAppearance FieldAppearance =
2667 pFormControl->GetDefaultAppearance();
2668
2669 CFX_ByteString csFontNameTag;
2670 FX_FLOAT fFontSize;
2671 FieldAppearance.GetFont(csFontNameTag, fFontSize);
2672
2673 vp << (int)fFontSize;
2674 }
2675
2676 return TRUE;
2677}
2678
2679void Field::SetTextSize(CPDFSDK_Document* pDocument,
2680 const CFX_WideString& swFieldName,
2681 int nControlIndex,
2682 int number) {
2683 // Not supported.
2684}
2685
Tom Sepezba038bc2015-10-08 12:03:00 -07002686FX_BOOL Field::type(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002687 CJS_PropValue& vp,
2688 CFX_WideString& sError) {
2689 ASSERT(m_pDocument != NULL);
2690
2691 if (!vp.IsGetting())
2692 return FALSE;
2693
Lei Zhangd88a3642015-11-10 09:38:57 -08002694 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2695 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002696 return FALSE;
2697
Lei Zhangd88a3642015-11-10 09:38:57 -08002698 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002699 switch (pFormField->GetFieldType()) {
2700 case FIELDTYPE_UNKNOWN:
2701 vp << L"unknown";
2702 break;
2703 case FIELDTYPE_PUSHBUTTON:
2704 vp << L"button";
2705 break;
2706 case FIELDTYPE_CHECKBOX:
2707 vp << L"checkbox";
2708 break;
2709 case FIELDTYPE_RADIOBUTTON:
2710 vp << L"radiobutton";
2711 break;
2712 case FIELDTYPE_COMBOBOX:
2713 vp << L"combobox";
2714 break;
2715 case FIELDTYPE_LISTBOX:
2716 vp << L"listbox";
2717 break;
2718 case FIELDTYPE_TEXTFIELD:
2719 vp << L"text";
2720 break;
2721 case FIELDTYPE_SIGNATURE:
2722 vp << L"signature";
2723 break;
2724 default:
2725 vp << L"unknown";
2726 break;
2727 }
2728
2729 return TRUE;
2730}
2731
Tom Sepezba038bc2015-10-08 12:03:00 -07002732FX_BOOL Field::userName(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002733 CJS_PropValue& vp,
2734 CFX_WideString& sError) {
2735 ASSERT(m_pDocument != NULL);
2736
2737 if (vp.IsSetting()) {
2738 if (!m_bCanSet)
2739 return FALSE;
2740
2741 CFX_WideString swName;
2742 vp >> swName;
2743
2744 if (m_bDelay) {
2745 AddDelay_WideString(FP_USERNAME, swName);
2746 } else {
2747 Field::SetUserName(m_pDocument, m_FieldName, m_nFormControlIndex, swName);
2748 }
2749 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002750 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2751 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002752 return FALSE;
2753
Lei Zhangd88a3642015-11-10 09:38:57 -08002754 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002755 vp << (CFX_WideString)pFormField->GetAlternateName();
2756 }
2757
2758 return TRUE;
2759}
2760
2761void Field::SetUserName(CPDFSDK_Document* pDocument,
2762 const CFX_WideString& swFieldName,
2763 int nControlIndex,
2764 const CFX_WideString& string) {
2765 // Not supported.
2766}
2767
Tom Sepezba038bc2015-10-08 12:03:00 -07002768FX_BOOL Field::value(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002769 CJS_PropValue& vp,
2770 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002771 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002772
2773 if (vp.IsSetting()) {
2774 if (!m_bCanSet)
2775 return FALSE;
2776
2777 CJS_WideStringArray strArray;
2778
2779 if (vp.IsArrayObject()) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002780 CJS_Array ValueArray(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002781 vp.ConvertToArray(ValueArray);
2782 for (int i = 0, sz = ValueArray.GetLength(); i < sz; i++) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002783 CJS_Value ElementValue(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002784 ValueArray.GetElement(i, ElementValue);
2785 strArray.Add(ElementValue.ToCFXWideString());
2786 }
2787 } else {
2788 CFX_WideString swValue;
2789 vp >> swValue;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002790 strArray.Add(swValue);
2791 }
2792
2793 if (m_bDelay) {
2794 AddDelay_WideStringArray(FP_VALUE, strArray);
2795 } else {
2796 Field::SetValue(m_pDocument, m_FieldName, m_nFormControlIndex, strArray);
2797 }
2798 } else {
Lei Zhangd88a3642015-11-10 09:38:57 -08002799 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2800 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002801 return FALSE;
2802
Lei Zhangd88a3642015-11-10 09:38:57 -08002803 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002804 switch (pFormField->GetFieldType()) {
2805 case FIELDTYPE_PUSHBUTTON:
2806 return FALSE;
2807 case FIELDTYPE_COMBOBOX:
2808 case FIELDTYPE_TEXTFIELD: {
2809 CFX_WideString swValue = pFormField->GetValue();
2810
2811 double dRet;
2812 FX_BOOL bDot;
2813 if (CJS_PublicMethods::ConvertStringToNumber(swValue.c_str(), dRet,
2814 bDot)) {
2815 if (bDot)
2816 vp << dRet;
2817 else
2818 vp << dRet;
Lei Zhangd88a3642015-11-10 09:38:57 -08002819 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002820 vp << swValue;
Lei Zhangd88a3642015-11-10 09:38:57 -08002821 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002822 } break;
2823 case FIELDTYPE_LISTBOX: {
2824 if (pFormField->CountSelectedItems() > 1) {
Tom Sepez67fd5df2015-10-08 12:24:19 -07002825 CJS_Array ValueArray(pRuntime);
2826 CJS_Value ElementValue(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002827 int iIndex;
2828 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
2829 iIndex = pFormField->GetSelectedIndex(i);
2830 ElementValue = pFormField->GetOptionValue(iIndex).c_str();
2831 if (FXSYS_wcslen(ElementValue.ToCFXWideString().c_str()) == 0)
2832 ElementValue = pFormField->GetOptionLabel(iIndex).c_str();
2833 ValueArray.SetElement(i, ElementValue);
2834 }
2835 vp << ValueArray;
2836 } else {
2837 CFX_WideString swValue = pFormField->GetValue();
2838
2839 double dRet;
2840 FX_BOOL bDot;
2841 if (CJS_PublicMethods::ConvertStringToNumber(swValue.c_str(), dRet,
2842 bDot)) {
2843 if (bDot)
2844 vp << dRet;
2845 else
2846 vp << dRet;
Lei Zhangd88a3642015-11-10 09:38:57 -08002847 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002848 vp << swValue;
Lei Zhangd88a3642015-11-10 09:38:57 -08002849 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002850 }
2851 } break;
2852 case FIELDTYPE_CHECKBOX:
2853 case FIELDTYPE_RADIOBUTTON: {
2854 FX_BOOL bFind = FALSE;
2855 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
Lei Zhangd88a3642015-11-10 09:38:57 -08002856 if (!pFormField->GetControl(i)->IsChecked())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002857 continue;
Lei Zhangd88a3642015-11-10 09:38:57 -08002858
2859 CFX_WideString swValue = pFormField->GetControl(i)->GetExportValue();
2860 double dRet;
2861 FX_BOOL bDotDummy;
2862 if (CJS_PublicMethods::ConvertStringToNumber(swValue.c_str(), dRet,
2863 bDotDummy)) {
2864 vp << dRet;
2865 } else {
2866 vp << swValue;
2867 }
2868
2869 bFind = TRUE;
2870 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002871 }
2872 if (!bFind)
2873 vp << L"Off";
2874 } break;
2875 default:
2876 vp << pFormField->GetValue();
2877 break;
2878 }
2879 }
2880
2881 return TRUE;
2882}
2883
2884void Field::SetValue(CPDFSDK_Document* pDocument,
2885 const CFX_WideString& swFieldName,
2886 int nControlIndex,
2887 const CJS_WideStringArray& strArray) {
2888 ASSERT(pDocument != NULL);
2889
2890 if (strArray.GetSize() < 1)
2891 return;
2892
Lei Zhangd88a3642015-11-10 09:38:57 -08002893 std::vector<CPDF_FormField*> FieldArray =
2894 GetFormFields(pDocument, swFieldName);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002895
Lei Zhangd88a3642015-11-10 09:38:57 -08002896 for (CPDF_FormField* pFormField : FieldArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002897 if (pFormField->GetFullName().Compare(swFieldName) != 0)
2898 continue;
2899
2900 switch (pFormField->GetFieldType()) {
2901 case FIELDTYPE_TEXTFIELD:
2902 case FIELDTYPE_COMBOBOX:
2903 if (pFormField->GetValue() != strArray.GetAt(0)) {
2904 CFX_WideString WideString = strArray.GetAt(0);
2905 pFormField->SetValue(strArray.GetAt(0), TRUE);
2906 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
2907 }
2908 break;
2909 case FIELDTYPE_CHECKBOX: // mantis: 0004493
2910 case FIELDTYPE_RADIOBUTTON: {
2911 if (pFormField->GetValue() != strArray.GetAt(0)) {
2912 pFormField->SetValue(strArray.GetAt(0), TRUE);
2913 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
2914 }
2915 } break;
2916 case FIELDTYPE_LISTBOX: {
2917 FX_BOOL bModified = FALSE;
2918
2919 for (int i = 0, sz = strArray.GetSize(); i < sz; i++) {
2920 int iIndex = pFormField->FindOption(strArray.GetAt(i));
2921
2922 if (!pFormField->IsItemSelected(iIndex)) {
2923 bModified = TRUE;
2924 break;
2925 }
2926 }
2927
2928 if (bModified) {
2929 pFormField->ClearSelection(TRUE);
2930 for (int i = 0, sz = strArray.GetSize(); i < sz; i++) {
2931 int iIndex = pFormField->FindOption(strArray.GetAt(i));
2932 pFormField->SetItemSelection(iIndex, TRUE, TRUE);
2933 }
2934
2935 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
2936 }
2937 } break;
2938 default:
2939 break;
2940 }
2941 }
2942}
2943
Tom Sepezba038bc2015-10-08 12:03:00 -07002944FX_BOOL Field::valueAsString(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002945 CJS_PropValue& vp,
2946 CFX_WideString& sError) {
2947 ASSERT(m_pDocument != NULL);
2948
2949 if (!vp.IsGetting())
2950 return FALSE;
2951
Lei Zhangd88a3642015-11-10 09:38:57 -08002952 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2953 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002954 return FALSE;
2955
Lei Zhangd88a3642015-11-10 09:38:57 -08002956 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002957 if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
2958 return FALSE;
2959
2960 if (pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) {
2961 if (!pFormField->CountControls())
2962 return FALSE;
2963
2964 if (pFormField->GetControl(0)->IsChecked())
2965 vp << L"Yes";
2966 else
2967 vp << L"Off";
2968 } else if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON &&
2969 !(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)) {
2970 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2971 if (pFormField->GetControl(i)->IsChecked()) {
2972 vp << pFormField->GetControl(i)->GetExportValue().c_str();
2973 break;
Lei Zhangd88a3642015-11-10 09:38:57 -08002974 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002975 vp << L"Off";
Lei Zhangd88a3642015-11-10 09:38:57 -08002976 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002977 }
2978 } else if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX &&
2979 (pFormField->CountSelectedItems() > 1)) {
2980 vp << L"";
Lei Zhangd88a3642015-11-10 09:38:57 -08002981 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002982 vp << pFormField->GetValue().c_str();
Lei Zhangd88a3642015-11-10 09:38:57 -08002983 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002984
2985 return TRUE;
2986}
2987
2988/* --------------------------------- methods ---------------------------------
2989 */
2990
Tom Sepezba038bc2015-10-08 12:03:00 -07002991FX_BOOL Field::browseForFileToSubmit(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) {
2995 ASSERT(m_pDocument != NULL);
2996
Lei Zhangd88a3642015-11-10 09:38:57 -08002997 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
2998 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002999 return FALSE;
3000
Lei Zhangd88a3642015-11-10 09:38:57 -08003001 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003002 CPDFDoc_Environment* pApp = m_pDocument->GetEnv();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003003 if ((pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) &&
3004 (pFormField->GetFieldType() == FIELDTYPE_TEXTFIELD)) {
3005 CFX_WideString wsFileName = pApp->JS_fieldBrowse();
3006 if (!wsFileName.IsEmpty()) {
3007 pFormField->SetValue(wsFileName);
3008 UpdateFormField(m_pDocument, pFormField, TRUE, TRUE, TRUE);
3009 }
Lei Zhangd88a3642015-11-10 09:38:57 -08003010 return TRUE;
3011 }
3012 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003013}
3014
Tom Sepezba038bc2015-10-08 12:03:00 -07003015FX_BOOL Field::buttonGetCaption(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003016 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003017 CJS_Value& vRet,
3018 CFX_WideString& sError) {
3019 ASSERT(m_pDocument != NULL);
3020
3021 int nface = 0;
3022 int iSize = params.size();
3023 if (iSize >= 1)
3024 nface = params[0].ToInt();
3025
Lei Zhangd88a3642015-11-10 09:38:57 -08003026 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3027 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003028 return FALSE;
3029
Lei Zhangd88a3642015-11-10 09:38:57 -08003030 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003031 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
3032 return FALSE;
3033
3034 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
3035 if (!pFormControl)
3036 return FALSE;
3037
3038 if (nface == 0)
3039 vRet = pFormControl->GetNormalCaption().c_str();
3040 else if (nface == 1)
3041 vRet = pFormControl->GetDownCaption().c_str();
3042 else if (nface == 2)
3043 vRet = pFormControl->GetRolloverCaption().c_str();
3044 else
3045 return FALSE;
3046
3047 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003048}
3049
Tom Sepezba038bc2015-10-08 12:03:00 -07003050FX_BOOL Field::buttonGetIcon(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003051 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003052 CJS_Value& vRet,
3053 CFX_WideString& sError) {
3054 ASSERT(m_pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003055
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003056 int nface = 0;
3057 int iSize = params.size();
3058 if (iSize >= 1)
3059 nface = params[0].ToInt();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07003060
Lei Zhangd88a3642015-11-10 09:38:57 -08003061 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3062 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003063 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003064
Lei Zhangd88a3642015-11-10 09:38:57 -08003065 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003066 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
3067 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003068
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003069 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
3070 if (!pFormControl)
3071 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003072
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003073 CJS_Context* pContext = (CJS_Context*)cc;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003074 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
Tom Sepezcd56a7d2015-10-06 11:45:28 -07003075 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
Tom Sepez33420902015-10-13 15:00:10 -07003076 pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003077 ASSERT(pObj.IsEmpty() == FALSE);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07003078
Tom Sepezd5a0e952015-09-17 15:40:06 -07003079 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003080 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003081
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003082 CPDF_Stream* pIconStream = NULL;
3083 if (nface == 0)
3084 pIconStream = pFormControl->GetNormalIcon();
3085 else if (nface == 1)
3086 pIconStream = pFormControl->GetDownIcon();
3087 else if (nface == 2)
3088 pIconStream = pFormControl->GetRolloverIcon();
3089 else
3090 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003091
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003092 pIcon->SetStream(pIconStream);
3093 vRet = pJS_Icon;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003094
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003095 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003096}
3097
Tom Sepezba038bc2015-10-08 12:03:00 -07003098FX_BOOL Field::buttonImportIcon(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003099 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003100 CJS_Value& vRet,
3101 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003102 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003103}
3104
Tom Sepezba038bc2015-10-08 12:03:00 -07003105FX_BOOL Field::buttonSetCaption(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003106 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003107 CJS_Value& vRet,
3108 CFX_WideString& sError) {
3109 return FALSE;
3110}
3111
Tom Sepezba038bc2015-10-08 12:03:00 -07003112FX_BOOL Field::buttonSetIcon(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003113 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003114 CJS_Value& vRet,
3115 CFX_WideString& sError) {
3116 return FALSE;
3117}
3118
Tom Sepezba038bc2015-10-08 12:03:00 -07003119FX_BOOL Field::checkThisBox(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003120 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003121 CJS_Value& vRet,
3122 CFX_WideString& sError) {
3123 ASSERT(m_pDocument != NULL);
3124
3125 if (!m_bCanSet)
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003126 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003127
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003128 int iSize = params.size();
3129 if (iSize < 1)
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003130 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003131
3132 int nWidget = params[0].ToInt();
3133
3134 FX_BOOL bCheckit = TRUE;
3135 if (iSize >= 2)
3136 bCheckit = params[1].ToBool();
3137
Lei Zhangd88a3642015-11-10 09:38:57 -08003138 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3139 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003140 return FALSE;
3141
Lei Zhangd88a3642015-11-10 09:38:57 -08003142 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003143 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
3144 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
3145 return FALSE;
3146 if (nWidget < 0 || nWidget >= pFormField->CountControls())
3147 return FALSE;
3148 if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)
3149 pFormField->CheckControl(nWidget, bCheckit, TRUE);
3150 else
3151 pFormField->CheckControl(nWidget, bCheckit, TRUE);
3152
3153 UpdateFormField(m_pDocument, pFormField, TRUE, TRUE, TRUE);
3154 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003155}
3156
Tom Sepezba038bc2015-10-08 12:03:00 -07003157FX_BOOL Field::clearItems(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003158 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003159 CJS_Value& vRet,
3160 CFX_WideString& sError) {
3161 return TRUE;
3162}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003163
Tom Sepezba038bc2015-10-08 12:03:00 -07003164FX_BOOL Field::defaultIsChecked(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003165 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003166 CJS_Value& vRet,
3167 CFX_WideString& sError) {
3168 ASSERT(m_pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003169
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003170 if (!m_bCanSet)
3171 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003172
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003173 int iSize = params.size();
3174 if (iSize < 1)
3175 return FALSE;
Tom Sepezf4ef3f92015-04-23 11:31:31 -07003176
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003177 int nWidget = params[0].ToInt();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003178
Lei Zhangd88a3642015-11-10 09:38:57 -08003179 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3180 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003181 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003182
Lei Zhangd88a3642015-11-10 09:38:57 -08003183 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003184 if (nWidget < 0 || nWidget >= pFormField->CountControls()) {
3185 vRet = FALSE;
3186 return FALSE;
3187 }
Lei Zhangd88a3642015-11-10 09:38:57 -08003188 vRet = pFormField->GetFieldType() == FIELDTYPE_CHECKBOX ||
3189 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003190
3191 return TRUE;
3192}
3193
Tom Sepezba038bc2015-10-08 12:03:00 -07003194FX_BOOL Field::deleteItemAt(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003195 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003196 CJS_Value& vRet,
3197 CFX_WideString& sError) {
3198 return TRUE;
3199}
3200
3201int JS_COMPARESTRING(CFX_WideString* ps1, CFX_WideString* ps2) {
3202 ASSERT(ps1 != NULL);
3203 ASSERT(ps2 != NULL);
3204
3205 return ps1->Compare(*ps2);
3206}
3207
Tom Sepezba038bc2015-10-08 12:03:00 -07003208FX_BOOL Field::getArray(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003209 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003210 CJS_Value& vRet,
3211 CFX_WideString& sError) {
3212 ASSERT(m_pDocument != NULL);
3213
Lei Zhangd88a3642015-11-10 09:38:57 -08003214 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3215 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003216 return FALSE;
3217
3218 CGW_ArrayTemplate<CFX_WideString*> swSort;
3219
Lei Zhangd88a3642015-11-10 09:38:57 -08003220 for (CPDF_FormField* pFormField : FieldArray)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003221 swSort.Add(new CFX_WideString(pFormField->GetFullName()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003222 swSort.Sort(JS_COMPARESTRING);
3223
3224 CJS_Context* pContext = (CJS_Context*)cc;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003225 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
Lei Zhangd88a3642015-11-10 09:38:57 -08003226 ASSERT(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003227
Tom Sepez67fd5df2015-10-08 12:24:19 -07003228 CJS_Array FormFieldArray(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003229 for (int j = 0, jsz = swSort.GetSize(); j < jsz; j++) {
Tom Sepezd5a0e952015-09-17 15:40:06 -07003230 nonstd::unique_ptr<CFX_WideString> pStr(swSort.GetAt(j));
Tom Sepez39bfe122015-09-17 15:25:23 -07003231 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
Tom Sepez33420902015-10-13 15:00:10 -07003232 pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID);
Tom Sepezcd56a7d2015-10-06 11:45:28 -07003233 ASSERT(!pObj.IsEmpty());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003234
Tom Sepezd5a0e952015-09-17 15:40:06 -07003235 CJS_Field* pJSField =
3236 (CJS_Field*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003237 Field* pField = (Field*)pJSField->GetEmbedObject();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003238 pField->AttachField(m_pJSDoc, *pStr);
3239
Tom Sepez67fd5df2015-10-08 12:24:19 -07003240 CJS_Value FormFieldValue(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003241 FormFieldValue = pJSField;
3242 FormFieldArray.SetElement(j, FormFieldValue);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003243 }
3244
3245 vRet = FormFieldArray;
3246 swSort.RemoveAll();
3247 return TRUE;
3248}
3249
Tom Sepezba038bc2015-10-08 12:03:00 -07003250FX_BOOL Field::getItemAt(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003251 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003252 CJS_Value& vRet,
3253 CFX_WideString& sError) {
3254 ASSERT(m_pDocument != NULL);
3255 int iSize = params.size();
3256
3257 int nIdx = -1;
3258 if (iSize >= 1)
3259 nIdx = params[0].ToInt();
3260
3261 FX_BOOL bExport = TRUE;
3262 if (iSize >= 2)
3263 bExport = params[1].ToBool();
3264
Lei Zhangd88a3642015-11-10 09:38:57 -08003265 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3266 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003267 return FALSE;
3268
Lei Zhangd88a3642015-11-10 09:38:57 -08003269 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003270 if ((pFormField->GetFieldType() == FIELDTYPE_LISTBOX) ||
3271 (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX)) {
3272 if (nIdx == -1 || nIdx > pFormField->CountOptions())
3273 nIdx = pFormField->CountOptions() - 1;
3274 if (bExport) {
3275 CFX_WideString strval = pFormField->GetOptionValue(nIdx);
3276 if (strval.IsEmpty())
3277 vRet = pFormField->GetOptionLabel(nIdx).c_str();
3278 else
3279 vRet = strval.c_str();
Lei Zhangd88a3642015-11-10 09:38:57 -08003280 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003281 vRet = pFormField->GetOptionLabel(nIdx).c_str();
Lei Zhangd88a3642015-11-10 09:38:57 -08003282 }
3283 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003284 return FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08003285 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003286
3287 return TRUE;
3288}
3289
Tom Sepezba038bc2015-10-08 12:03:00 -07003290FX_BOOL Field::getLock(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003291 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003292 CJS_Value& vRet,
3293 CFX_WideString& sError) {
3294 return FALSE;
3295}
3296
Tom Sepezba038bc2015-10-08 12:03:00 -07003297FX_BOOL Field::insertItemAt(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003298 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003299 CJS_Value& vRet,
3300 CFX_WideString& sError) {
3301 return TRUE;
3302}
3303
Tom Sepezba038bc2015-10-08 12:03:00 -07003304FX_BOOL Field::isBoxChecked(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003305 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003306 CJS_Value& vRet,
3307 CFX_WideString& sError) {
3308 ASSERT(m_pDocument != NULL);
3309
3310 int nIndex = -1;
3311 if (params.size() >= 1)
3312 nIndex = params[0].ToInt();
3313
Lei Zhangd88a3642015-11-10 09:38:57 -08003314 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3315 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003316 return FALSE;
3317
Lei Zhangd88a3642015-11-10 09:38:57 -08003318 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003319 if (nIndex < 0 || nIndex >= pFormField->CountControls()) {
3320 vRet = FALSE;
3321 return FALSE;
3322 }
3323
3324 if ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) ||
3325 (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)) {
3326 if (pFormField->GetControl(nIndex)->IsChecked() != 0)
3327 vRet = TRUE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003328 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003329 vRet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08003330 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003331 vRet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08003332 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003333
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003334 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003335}
3336
Tom Sepezba038bc2015-10-08 12:03:00 -07003337FX_BOOL Field::isDefaultChecked(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 ASSERT(m_pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003342
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003343 int nIndex = -1;
3344 if (params.size() >= 1)
3345 nIndex = params[0].ToInt();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003346
Lei Zhangd88a3642015-11-10 09:38:57 -08003347 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3348 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003349 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003350
Lei Zhangd88a3642015-11-10 09:38:57 -08003351 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003352 if (nIndex < 0 || nIndex >= pFormField->CountControls()) {
3353 vRet = FALSE;
3354 return FALSE;
3355 }
3356 if ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) ||
3357 (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)) {
3358 if (pFormField->GetControl(nIndex)->IsDefaultChecked() != 0)
3359 vRet = TRUE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003360 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003361 vRet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08003362 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003363 vRet = FALSE;
Lei Zhangd88a3642015-11-10 09:38:57 -08003364 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003365
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003366 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003367}
3368
Tom Sepezba038bc2015-10-08 12:03:00 -07003369FX_BOOL Field::setAction(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003370 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003371 CJS_Value& vRet,
3372 CFX_WideString& sError) {
3373 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003374}
3375
Tom Sepezba038bc2015-10-08 12:03:00 -07003376FX_BOOL Field::setFocus(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003377 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003378 CJS_Value& vRet,
3379 CFX_WideString& sError) {
3380 ASSERT(m_pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003381
Lei Zhangd88a3642015-11-10 09:38:57 -08003382 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName);
3383 if (FieldArray.empty())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003384 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003385
Lei Zhangd88a3642015-11-10 09:38:57 -08003386 CPDF_FormField* pFormField = FieldArray[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003387 int32_t nCount = pFormField->CountControls();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003388 if (nCount < 1)
3389 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003390
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003391 CPDFSDK_InterForm* pInterForm =
3392 (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
3393 ASSERT(pInterForm != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003394
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003395 CPDFSDK_Widget* pWidget = NULL;
3396 if (nCount == 1) {
3397 pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
3398 } else {
3399 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
3400 ASSERT(pEnv);
3401 CPDFXFA_Page* pPage =
3402 (CPDFXFA_Page*)pEnv->FFI_GetCurrentPage(m_pDocument->GetDocument());
3403 if (!pPage)
3404 return FALSE;
3405 if (CPDFSDK_PageView* pCurPageView = m_pDocument->GetPageView(pPage)) {
3406 for (int32_t i = 0; i < nCount; i++) {
3407 if (CPDFSDK_Widget* pTempWidget =
3408 pInterForm->GetWidget(pFormField->GetControl(i))) {
3409 if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage()) {
3410 pWidget = pTempWidget;
3411 break;
3412 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003413 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003414 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003415 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003416 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003417
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003418 if (pWidget) {
3419 m_pDocument->SetFocusAnnot(pWidget);
3420 }
3421
3422 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003423}
3424
Tom Sepezba038bc2015-10-08 12:03:00 -07003425FX_BOOL Field::setItems(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003426 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003427 CJS_Value& vRet,
3428 CFX_WideString& sError) {
3429 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003430}
3431
Tom Sepezba038bc2015-10-08 12:03:00 -07003432FX_BOOL Field::setLock(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003433 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003434 CJS_Value& vRet,
3435 CFX_WideString& sError) {
3436 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003437}
3438
Tom Sepezba038bc2015-10-08 12:03:00 -07003439FX_BOOL Field::signatureGetModifications(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003440 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003441 CJS_Value& vRet,
3442 CFX_WideString& sError) {
3443 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003444}
3445
Tom Sepezba038bc2015-10-08 12:03:00 -07003446FX_BOOL Field::signatureGetSeedValue(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003447 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003448 CJS_Value& vRet,
3449 CFX_WideString& sError) {
3450 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003451}
3452
Tom Sepezba038bc2015-10-08 12:03:00 -07003453FX_BOOL Field::signatureInfo(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003454 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003455 CJS_Value& vRet,
3456 CFX_WideString& sError) {
3457 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003458}
3459
Tom Sepezba038bc2015-10-08 12:03:00 -07003460FX_BOOL Field::signatureSetSeedValue(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003461 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003462 CJS_Value& vRet,
3463 CFX_WideString& sError) {
3464 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003465}
3466
Tom Sepezba038bc2015-10-08 12:03:00 -07003467FX_BOOL Field::signatureSign(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003468 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003469 CJS_Value& vRet,
3470 CFX_WideString& sError) {
3471 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003472}
3473
Tom Sepezba038bc2015-10-08 12:03:00 -07003474FX_BOOL Field::signatureValidate(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -08003475 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003476 CJS_Value& vRet,
3477 CFX_WideString& sError) {
3478 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003479}
3480
Tom Sepezba038bc2015-10-08 12:03:00 -07003481FX_BOOL Field::source(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003482 CJS_PropValue& vp,
3483 CFX_WideString& sError) {
3484 if (vp.IsGetting()) {
3485 vp << (CJS_Object*)NULL;
3486 }
3487
3488 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003489}
3490
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003491/////////////////////////////////////////// delay
3492////////////////////////////////////////////////
3493
3494void Field::AddDelay_Int(enum FIELD_PROP prop, int32_t n) {
3495 ASSERT(m_pJSDoc != NULL);
3496
3497 CJS_DelayData* pNewData = new CJS_DelayData;
3498 pNewData->sFieldName = m_FieldName;
3499 pNewData->nControlIndex = m_nFormControlIndex;
3500 pNewData->eProp = prop;
3501 pNewData->num = n;
3502
3503 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003504}
3505
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003506void Field::AddDelay_Bool(enum FIELD_PROP prop, bool b) {
3507 ASSERT(m_pJSDoc != NULL);
3508
3509 CJS_DelayData* pNewData = new CJS_DelayData;
3510 pNewData->sFieldName = m_FieldName;
3511 pNewData->nControlIndex = m_nFormControlIndex;
3512 pNewData->eProp = prop;
3513 pNewData->b = b;
3514
3515 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003516}
3517
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003518void Field::AddDelay_String(enum FIELD_PROP prop,
3519 const CFX_ByteString& string) {
3520 ASSERT(m_pJSDoc != NULL);
3521
3522 CJS_DelayData* pNewData = new CJS_DelayData;
3523 pNewData->sFieldName = m_FieldName;
3524 pNewData->nControlIndex = m_nFormControlIndex;
3525 pNewData->eProp = prop;
3526 pNewData->string = string;
3527
3528 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003529}
3530
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003531void Field::AddDelay_WideString(enum FIELD_PROP prop,
3532 const CFX_WideString& string) {
3533 ASSERT(m_pJSDoc != NULL);
3534
3535 CJS_DelayData* pNewData = new CJS_DelayData;
3536 pNewData->sFieldName = m_FieldName;
3537 pNewData->nControlIndex = m_nFormControlIndex;
3538 pNewData->eProp = prop;
3539 pNewData->widestring = string;
3540
3541 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003542}
3543
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003544void Field::AddDelay_Rect(enum FIELD_PROP prop, const CPDF_Rect& rect) {
3545 ASSERT(m_pJSDoc != NULL);
3546
3547 CJS_DelayData* pNewData = new CJS_DelayData;
3548 pNewData->sFieldName = m_FieldName;
3549 pNewData->nControlIndex = m_nFormControlIndex;
3550 pNewData->eProp = prop;
3551 pNewData->rect = rect;
3552
3553 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003554}
3555
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003556void Field::AddDelay_Color(enum FIELD_PROP prop, const CPWL_Color& color) {
3557 ASSERT(m_pJSDoc != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003558
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003559 CJS_DelayData* pNewData = new CJS_DelayData;
3560 pNewData->sFieldName = m_FieldName;
3561 pNewData->nControlIndex = m_nFormControlIndex;
3562 pNewData->eProp = prop;
3563 pNewData->color = color;
3564
3565 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003566}
3567
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003568void Field::AddDelay_WordArray(enum FIELD_PROP prop,
3569 const CFX_DWordArray& array) {
3570 ASSERT(m_pJSDoc != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003571
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003572 CJS_DelayData* pNewData = new CJS_DelayData;
3573 pNewData->sFieldName = m_FieldName;
3574 pNewData->nControlIndex = m_nFormControlIndex;
3575 pNewData->eProp = prop;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003576
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003577 for (int i = 0, sz = array.GetSize(); i < sz; i++)
3578 pNewData->wordarray.Add(array.GetAt(i));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003579
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003580 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003581}
3582
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003583void Field::AddDelay_WideStringArray(enum FIELD_PROP prop,
3584 const CJS_WideStringArray& array) {
3585 ASSERT(m_pJSDoc != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003586
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003587 CJS_DelayData* pNewData = new CJS_DelayData;
3588 pNewData->sFieldName = m_FieldName;
3589 pNewData->nControlIndex = m_nFormControlIndex;
3590 pNewData->eProp = prop;
3591 for (int i = 0, sz = array.GetSize(); i < sz; i++)
3592 pNewData->widestringarray.Add(array.GetAt(i));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003593
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003594 m_pJSDoc->AddDelayData(pNewData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003595}
3596
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003597void Field::DoDelay(CPDFSDK_Document* pDocument, CJS_DelayData* pData) {
3598 ASSERT(pDocument != NULL);
3599 ASSERT(pData != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003600
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003601 switch (pData->eProp) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003602 case FP_ALIGNMENT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003603 Field::SetAlignment(pDocument, pData->sFieldName, pData->nControlIndex,
3604 pData->string);
3605 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003606 case FP_BORDERSTYLE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003607 Field::SetBorderStyle(pDocument, pData->sFieldName, pData->nControlIndex,
3608 pData->string);
3609 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003610 case FP_BUTTONALIGNX:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003611 Field::SetButtonAlignX(pDocument, pData->sFieldName, pData->nControlIndex,
3612 pData->num);
3613 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003614 case FP_BUTTONALIGNY:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003615 Field::SetButtonAlignY(pDocument, pData->sFieldName, pData->nControlIndex,
3616 pData->num);
3617 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003618 case FP_BUTTONFITBOUNDS:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003619 Field::SetButtonFitBounds(pDocument, pData->sFieldName,
3620 pData->nControlIndex, pData->b);
3621 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003622 case FP_BUTTONPOSITION:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003623 Field::SetButtonPosition(pDocument, pData->sFieldName,
3624 pData->nControlIndex, pData->num);
3625 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003626 case FP_BUTTONSCALEHOW:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003627 Field::SetButtonScaleHow(pDocument, pData->sFieldName,
3628 pData->nControlIndex, pData->num);
3629 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003630 case FP_BUTTONSCALEWHEN:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003631 Field::SetButtonScaleWhen(pDocument, pData->sFieldName,
3632 pData->nControlIndex, pData->num);
3633 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003634 case FP_CALCORDERINDEX:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003635 Field::SetCalcOrderIndex(pDocument, pData->sFieldName,
3636 pData->nControlIndex, pData->num);
3637 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003638 case FP_CHARLIMIT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003639 Field::SetCharLimit(pDocument, pData->sFieldName, pData->nControlIndex,
3640 pData->num);
3641 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003642 case FP_COMB:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003643 Field::SetComb(pDocument, pData->sFieldName, pData->nControlIndex,
3644 pData->b);
3645 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003646 case FP_COMMITONSELCHANGE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003647 Field::SetCommitOnSelChange(pDocument, pData->sFieldName,
3648 pData->nControlIndex, pData->b);
3649 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003650 case FP_CURRENTVALUEINDICES:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003651 Field::SetCurrentValueIndices(pDocument, pData->sFieldName,
3652 pData->nControlIndex, pData->wordarray);
3653 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003654 case FP_DEFAULTVALUE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003655 Field::SetDefaultValue(pDocument, pData->sFieldName, pData->nControlIndex,
3656 pData->widestring);
3657 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003658 case FP_DONOTSCROLL:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003659 Field::SetDoNotScroll(pDocument, pData->sFieldName, pData->nControlIndex,
3660 pData->b);
3661 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003662 case FP_DISPLAY:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003663 Field::SetDisplay(pDocument, pData->sFieldName, pData->nControlIndex,
3664 pData->num);
3665 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003666 case FP_FILLCOLOR:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003667 Field::SetFillColor(pDocument, pData->sFieldName, pData->nControlIndex,
3668 pData->color);
3669 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003670 case FP_HIDDEN:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003671 Field::SetHidden(pDocument, pData->sFieldName, pData->nControlIndex,
3672 pData->b);
3673 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003674 case FP_HIGHLIGHT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003675 Field::SetHighlight(pDocument, pData->sFieldName, pData->nControlIndex,
3676 pData->string);
3677 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003678 case FP_LINEWIDTH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003679 Field::SetLineWidth(pDocument, pData->sFieldName, pData->nControlIndex,
3680 pData->num);
3681 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003682 case FP_MULTILINE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003683 Field::SetMultiline(pDocument, pData->sFieldName, pData->nControlIndex,
3684 pData->b);
3685 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003686 case FP_MULTIPLESELECTION:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003687 Field::SetMultipleSelection(pDocument, pData->sFieldName,
3688 pData->nControlIndex, pData->b);
3689 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003690 case FP_PASSWORD:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003691 Field::SetPassword(pDocument, pData->sFieldName, pData->nControlIndex,
3692 pData->b);
3693 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003694 case FP_RECT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003695 Field::SetRect(pDocument, pData->sFieldName, pData->nControlIndex,
3696 pData->rect);
3697 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003698 case FP_RICHTEXT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003699 Field::SetRichText(pDocument, pData->sFieldName, pData->nControlIndex,
3700 pData->b);
3701 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003702 case FP_RICHVALUE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003703 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003704 case FP_ROTATION:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003705 Field::SetRotation(pDocument, pData->sFieldName, pData->nControlIndex,
3706 pData->num);
3707 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003708 case FP_STROKECOLOR:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003709 Field::SetStrokeColor(pDocument, pData->sFieldName, pData->nControlIndex,
3710 pData->color);
3711 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003712 case FP_STYLE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003713 Field::SetStyle(pDocument, pData->sFieldName, pData->nControlIndex,
3714 pData->string);
3715 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003716 case FP_TEXTCOLOR:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003717 Field::SetTextColor(pDocument, pData->sFieldName, pData->nControlIndex,
3718 pData->color);
3719 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003720 case FP_TEXTFONT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003721 Field::SetTextFont(pDocument, pData->sFieldName, pData->nControlIndex,
3722 pData->string);
3723 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003724 case FP_TEXTSIZE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003725 Field::SetTextSize(pDocument, pData->sFieldName, pData->nControlIndex,
3726 pData->num);
3727 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003728 case FP_USERNAME:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003729 Field::SetUserName(pDocument, pData->sFieldName, pData->nControlIndex,
3730 pData->widestring);
3731 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07003732 case FP_VALUE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003733 Field::SetValue(pDocument, pData->sFieldName, pData->nControlIndex,
3734 pData->widestringarray);
3735 break;
3736 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003737}
3738
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003739#define JS_FIELD_MINWIDTH 1
3740#define JS_FIELD_MINHEIGHT 1
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003741
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003742void Field::AddField(CPDFSDK_Document* pDocument,
3743 int nPageIndex,
3744 int nFieldType,
3745 const CFX_WideString& sName,
3746 const CPDF_Rect& rcCoords) {
3747 // Not supported.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07003748}