Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(598)

Side by Side Diff: fpdfsdk/src/javascript/Field.cpp

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

Powered by Google App Engine
This is Rietveld 408576698