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