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 "xfa/fxfa/parser/cscript_hostpseudomodel.h" 8 9 #include <memory> 10 11 #include "fxjs/cfxjse_arguments.h" 12 #include "xfa/fxfa/app/xfa_ffnotify.h" 13 #include "xfa/fxfa/parser/cxfa_document.h" 14 #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" 15 #include "xfa/fxfa/parser/cxfa_scriptcontext.h" 16 #include "xfa/fxfa/parser/xfa_localemgr.h" 17 #include "xfa/fxfa/parser/xfa_object.h" 18 #include "xfa/fxfa/parser/xfa_resolvenode_rs.h" 19 #include "xfa/fxfa/parser/xfa_utils.h" 20 21 namespace { 22 23 CXFA_Node* ToNode(CFXJSE_Value* pValue, CFXJSE_Class* pClass) { 24 return static_cast<CXFA_Node*>(pValue->ToHostObject(pClass)); 25 } 26 27 } // namespace 28 29 CScript_HostPseudoModel::CScript_HostPseudoModel(CXFA_Document* pDocument) 30 : CXFA_Object(pDocument, 31 XFA_ObjectType::Object, 32 XFA_Element::HostPseudoModel, 33 CFX_WideStringC(L"hostPseudoModel")) {} 34 35 CScript_HostPseudoModel::~CScript_HostPseudoModel() {} 36 37 void CScript_HostPseudoModel::AppType(CFXJSE_Value* pValue, 38 bool bSetting, 39 XFA_ATTRIBUTE eAttribute) { 40 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); 41 if (!pNotify) 42 return; 43 if (bSetting) { 44 ThrowInvalidPropertyException(); 45 return; 46 } 47 pValue->SetString("Exchange"); 48 } 49 50 void CScript_HostPseudoModel::CalculationsEnabled(CFXJSE_Value* pValue, 51 bool bSetting, 52 XFA_ATTRIBUTE eAttribute) { 53 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); 54 if (!pNotify) { 55 return; 56 } 57 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); 58 if (bSetting) { 59 pNotify->GetDocEnvironment()->SetCalculationsEnabled(hDoc, 60 pValue->ToBoolean()); 61 return; 62 } 63 pValue->SetBoolean(pNotify->GetDocEnvironment()->IsCalculationsEnabled(hDoc)); 64 } 65 66 void CScript_HostPseudoModel::CurrentPage(CFXJSE_Value* pValue, 67 bool bSetting, 68 XFA_ATTRIBUTE eAttribute) { 69 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); 70 if (!pNotify) { 71 return; 72 } 73 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); 74 if (bSetting) { 75 pNotify->GetDocEnvironment()->SetCurrentPage(hDoc, pValue->ToInteger()); 76 return; 77 } 78 pValue->SetInteger(pNotify->GetDocEnvironment()->GetCurrentPage(hDoc)); 79 } 80 81 void CScript_HostPseudoModel::Language(CFXJSE_Value* pValue, 82 bool bSetting, 83 XFA_ATTRIBUTE eAttribute) { 84 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); 85 if (!pNotify) 86 return; 87 if (bSetting) { 88 ThrowSetLanguageException(); 89 return; 90 } 91 pValue->SetString( 92 pNotify->GetAppProvider()->GetLanguage().UTF8Encode().AsStringC()); 93 } 94 95 void CScript_HostPseudoModel::NumPages(CFXJSE_Value* pValue, 96 bool bSetting, 97 XFA_ATTRIBUTE eAttribute) { 98 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); 99 if (!pNotify) { 100 return; 101 } 102 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); 103 if (bSetting) { 104 ThrowSetNumPagesException(); 105 return; 106 } 107 pValue->SetInteger(pNotify->GetDocEnvironment()->CountPages(hDoc)); 108 } 109 110 void CScript_HostPseudoModel::Platform(CFXJSE_Value* pValue, 111 bool bSetting, 112 XFA_ATTRIBUTE eAttribute) { 113 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); 114 if (!pNotify) 115 return; 116 if (bSetting) { 117 ThrowSetPlatformException(); 118 return; 119 } 120 pValue->SetString( 121 pNotify->GetAppProvider()->GetPlatform().UTF8Encode().AsStringC()); 122 } 123 124 void CScript_HostPseudoModel::Title(CFXJSE_Value* pValue, 125 bool bSetting, 126 XFA_ATTRIBUTE eAttribute) { 127 if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { 128 return; 129 } 130 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); 131 if (!pNotify) { 132 return; 133 } 134 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); 135 if (bSetting) { 136 pNotify->GetDocEnvironment()->SetTitle(hDoc, pValue->ToWideString()); 137 return; 138 } 139 CFX_WideString wsTitle; 140 pNotify->GetDocEnvironment()->GetTitle(hDoc, wsTitle); 141 pValue->SetString(wsTitle.UTF8Encode().AsStringC()); 142 } 143 144 void CScript_HostPseudoModel::ValidationsEnabled(CFXJSE_Value* pValue, 145 bool bSetting, 146 XFA_ATTRIBUTE eAttribute) { 147 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); 148 if (!pNotify) { 149 return; 150 } 151 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); 152 if (bSetting) { 153 pNotify->GetDocEnvironment()->SetValidationsEnabled(hDoc, 154 pValue->ToBoolean()); 155 return; 156 } 157 bool bEnabled = pNotify->GetDocEnvironment()->IsValidationsEnabled(hDoc); 158 pValue->SetBoolean(bEnabled); 159 } 160 161 void CScript_HostPseudoModel::Variation(CFXJSE_Value* pValue, 162 bool bSetting, 163 XFA_ATTRIBUTE eAttribute) { 164 if (!m_pDocument->GetScriptContext()->IsRunAtClient()) 165 return; 166 167 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); 168 if (!pNotify) 169 return; 170 if (bSetting) { 171 ThrowSetVariationException(); 172 return; 173 } 174 pValue->SetString("Full"); 175 } 176 177 void CScript_HostPseudoModel::Version(CFXJSE_Value* pValue, 178 bool bSetting, 179 XFA_ATTRIBUTE eAttribute) { 180 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); 181 if (!pNotify) { 182 return; 183 } 184 if (bSetting) { 185 ThrowSetVersionException(); 186 return; 187 } 188 pValue->SetString("11"); 189 } 190 191 void CScript_HostPseudoModel::Name(CFXJSE_Value* pValue, 192 bool bSetting, 193 XFA_ATTRIBUTE eAttribute) { 194 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); 195 if (!pNotify) { 196 return; 197 } 198 if (bSetting) { 199 ThrowInvalidPropertyException(); 200 return; 201 } 202 pValue->SetString( 203 pNotify->GetAppProvider()->GetAppName().UTF8Encode().AsStringC()); 204 } 205 206 void CScript_HostPseudoModel::GotoURL(CFXJSE_Arguments* pArguments) { 207 if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { 208 return; 209 } 210 int32_t iLength = pArguments->GetLength(); 211 if (iLength != 1) { 212 ThrowParamCountMismatchException(L"gotoURL"); 213 return; 214 } 215 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); 216 if (!pNotify) { 217 return; 218 } 219 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); 220 CFX_WideString wsURL; 221 if (iLength >= 1) { 222 CFX_ByteString bsURL = pArguments->GetUTF8String(0); 223 wsURL = CFX_WideString::FromUTF8(bsURL.AsStringC()); 224 } 225 pNotify->GetDocEnvironment()->GotoURL(hDoc, wsURL); 226 } 227 void CScript_HostPseudoModel::OpenList(CFXJSE_Arguments* pArguments) { 228 if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { 229 return; 230 } 231 int32_t iLength = pArguments->GetLength(); 232 if (iLength != 1) { 233 ThrowParamCountMismatchException(L"openList"); 234 return; 235 } 236 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); 237 if (!pNotify) { 238 return; 239 } 240 CXFA_Node* pNode = nullptr; 241 if (iLength >= 1) { 242 std::unique_ptr<CFXJSE_Value> pValue(pArguments->GetValue(0)); 243 if (pValue->IsObject()) { 244 pNode = ToNode(pValue.get(), nullptr); 245 } else if (pValue->IsString()) { 246 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); 247 if (!pScriptContext) 248 return; 249 250 CXFA_Object* pObject = pScriptContext->GetThisObject(); 251 if (!pObject) 252 return; 253 254 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Parent | 255 XFA_RESOLVENODE_Siblings; 256 XFA_RESOLVENODE_RS resoveNodeRS; 257 int32_t iRet = pScriptContext->ResolveObjects( 258 pObject, pValue->ToWideString().AsStringC(), resoveNodeRS, dwFlag); 259 if (iRet < 1 || !resoveNodeRS.nodes[0]->IsNode()) 260 return; 261 262 pNode = resoveNodeRS.nodes[0]->AsNode(); 263 } 264 } 265 CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout(); 266 if (!pDocLayout) { 267 return; 268 } 269 CXFA_FFWidget* hWidget = 270 pNotify->GetHWidget(pDocLayout->GetLayoutItem(pNode)); 271 if (!hWidget) { 272 return; 273 } 274 pNotify->GetDocEnvironment()->SetFocusWidget(pNotify->GetHDOC(), hWidget); 275 pNotify->OpenDropDownList(hWidget); 276 } 277 void CScript_HostPseudoModel::Response(CFXJSE_Arguments* pArguments) { 278 int32_t iLength = pArguments->GetLength(); 279 if (iLength < 1 || iLength > 4) { 280 ThrowParamCountMismatchException(L"response"); 281 return; 282 } 283 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); 284 if (!pNotify) { 285 return; 286 } 287 CFX_WideString wsQuestion; 288 CFX_WideString wsTitle; 289 CFX_WideString wsDefaultAnswer; 290 bool bMark = false; 291 if (iLength >= 1) { 292 CFX_ByteString bsQuestion = pArguments->GetUTF8String(0); 293 wsQuestion = CFX_WideString::FromUTF8(bsQuestion.AsStringC()); 294 } 295 if (iLength >= 2) { 296 CFX_ByteString bsTitle = pArguments->GetUTF8String(1); 297 wsTitle = CFX_WideString::FromUTF8(bsTitle.AsStringC()); 298 } 299 if (iLength >= 3) { 300 CFX_ByteString bsDefaultAnswer = pArguments->GetUTF8String(2); 301 wsDefaultAnswer = CFX_WideString::FromUTF8(bsDefaultAnswer.AsStringC()); 302 } 303 if (iLength >= 4) { 304 bMark = pArguments->GetInt32(3) == 0 ? false : true; 305 } 306 CFX_WideString wsAnswer = pNotify->GetAppProvider()->Response( 307 wsQuestion, wsTitle, wsDefaultAnswer, bMark); 308 CFXJSE_Value* pValue = pArguments->GetReturnValue(); 309 if (pValue) 310 pValue->SetString(wsAnswer.UTF8Encode().AsStringC()); 311 } 312 313 void CScript_HostPseudoModel::DocumentInBatch(CFXJSE_Arguments* pArguments) { 314 if (CFXJSE_Value* pValue = pArguments->GetReturnValue()) 315 pValue->SetInteger(0); 316 } 317 static int32_t XFA_FilterName(const CFX_WideStringC& wsExpression, 318 int32_t nStart, 319 CFX_WideString& wsFilter) { 320 ASSERT(nStart > -1); 321 int32_t iLength = wsExpression.GetLength(); 322 if (nStart >= iLength) { 323 return iLength; 324 } 325 FX_WCHAR* pBuf = wsFilter.GetBuffer(iLength - nStart); 326 int32_t nCount = 0; 327 const FX_WCHAR* pSrc = wsExpression.c_str(); 328 FX_WCHAR wCur; 329 while (nStart < iLength) { 330 wCur = pSrc[nStart++]; 331 if (wCur == ',') { 332 break; 333 } 334 pBuf[nCount++] = wCur; 335 } 336 wsFilter.ReleaseBuffer(nCount); 337 wsFilter.TrimLeft(); 338 wsFilter.TrimRight(); 339 return nStart; 340 } 341 void CScript_HostPseudoModel::ResetData(CFXJSE_Arguments* pArguments) { 342 int32_t iLength = pArguments->GetLength(); 343 if (iLength < 0 || iLength > 1) { 344 ThrowParamCountMismatchException(L"resetData"); 345 return; 346 } 347 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); 348 if (!pNotify) { 349 return; 350 } 351 CFX_WideString wsExpression; 352 if (iLength >= 1) { 353 CFX_ByteString bsExpression = pArguments->GetUTF8String(0); 354 wsExpression = CFX_WideString::FromUTF8(bsExpression.AsStringC()); 355 } 356 if (wsExpression.IsEmpty()) { 357 pNotify->ResetData(); 358 return; 359 } 360 int32_t iStart = 0; 361 CFX_WideString wsName; 362 CXFA_Node* pNode = nullptr; 363 int32_t iExpLength = wsExpression.GetLength(); 364 while (iStart < iExpLength) { 365 iStart = XFA_FilterName(wsExpression.AsStringC(), iStart, wsName); 366 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); 367 if (!pScriptContext) { 368 return; 369 } 370 CXFA_Object* pObject = pScriptContext->GetThisObject(); 371 if (!pObject) { 372 return; 373 } 374 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Parent | 375 XFA_RESOLVENODE_Siblings; 376 XFA_RESOLVENODE_RS resoveNodeRS; 377 int32_t iRet = pScriptContext->ResolveObjects(pObject, wsName.AsStringC(), 378 resoveNodeRS, dwFlag); 379 if (iRet < 1 || !resoveNodeRS.nodes[0]->IsNode()) { 380 continue; 381 } 382 pNode = resoveNodeRS.nodes[0]->AsNode(); 383 pNotify->ResetData(pNode->GetWidgetData()); 384 } 385 if (!pNode) { 386 pNotify->ResetData(); 387 } 388 } 389 void CScript_HostPseudoModel::Beep(CFXJSE_Arguments* pArguments) { 390 if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { 391 return; 392 } 393 int32_t iLength = pArguments->GetLength(); 394 if (iLength < 0 || iLength > 1) { 395 ThrowParamCountMismatchException(L"beep"); 396 return; 397 } 398 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); 399 if (!pNotify) { 400 return; 401 } 402 uint32_t dwType = 4; 403 if (iLength >= 1) { 404 dwType = pArguments->GetInt32(0); 405 } 406 pNotify->GetAppProvider()->Beep(dwType); 407 } 408 void CScript_HostPseudoModel::SetFocus(CFXJSE_Arguments* pArguments) { 409 if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { 410 return; 411 } 412 int32_t iLength = pArguments->GetLength(); 413 if (iLength != 1) { 414 ThrowParamCountMismatchException(L"setFocus"); 415 return; 416 } 417 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); 418 if (!pNotify) { 419 return; 420 } 421 CXFA_Node* pNode = nullptr; 422 if (iLength >= 1) { 423 std::unique_ptr<CFXJSE_Value> pValue(pArguments->GetValue(0)); 424 if (pValue->IsObject()) { 425 pNode = ToNode(pValue.get(), nullptr); 426 } else if (pValue->IsString()) { 427 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); 428 if (!pScriptContext) 429 return; 430 431 CXFA_Object* pObject = pScriptContext->GetThisObject(); 432 if (!pObject) 433 return; 434 435 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Parent | 436 XFA_RESOLVENODE_Siblings; 437 XFA_RESOLVENODE_RS resoveNodeRS; 438 int32_t iRet = pScriptContext->ResolveObjects( 439 pObject, pValue->ToWideString().AsStringC(), resoveNodeRS, dwFlag); 440 if (iRet < 1 || !resoveNodeRS.nodes[0]->IsNode()) 441 return; 442 443 pNode = resoveNodeRS.nodes[0]->AsNode(); 444 } 445 } 446 pNotify->SetFocusWidgetNode(pNode); 447 } 448 449 void CScript_HostPseudoModel::GetFocus(CFXJSE_Arguments* pArguments) { 450 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); 451 if (!pNotify) { 452 return; 453 } 454 CXFA_Node* pNode = pNotify->GetFocusWidgetNode(); 455 if (!pNode) { 456 return; 457 } 458 pArguments->GetReturnValue()->Assign( 459 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode)); 460 } 461 void CScript_HostPseudoModel::MessageBox(CFXJSE_Arguments* pArguments) { 462 if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { 463 return; 464 } 465 int32_t iLength = pArguments->GetLength(); 466 if (iLength < 1 || iLength > 4) { 467 ThrowParamCountMismatchException(L"messageBox"); 468 return; 469 } 470 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); 471 if (!pNotify) { 472 return; 473 } 474 CFX_WideString wsMessage; 475 CFX_WideString bsTitle; 476 uint32_t dwMessageType = XFA_MBICON_Error; 477 uint32_t dwButtonType = XFA_MB_OK; 478 if (iLength >= 1) { 479 if (!ValidateArgsForMsg(pArguments, 0, wsMessage)) { 480 return; 481 } 482 } 483 if (iLength >= 2) { 484 if (!ValidateArgsForMsg(pArguments, 1, bsTitle)) { 485 return; 486 } 487 } 488 if (iLength >= 3) { 489 dwMessageType = pArguments->GetInt32(2); 490 if (dwMessageType > XFA_MBICON_Status) { 491 dwMessageType = XFA_MBICON_Error; 492 } 493 } 494 if (iLength >= 4) { 495 dwButtonType = pArguments->GetInt32(3); 496 if (dwButtonType > XFA_MB_YesNoCancel) { 497 dwButtonType = XFA_MB_OK; 498 } 499 } 500 int32_t iValue = pNotify->GetAppProvider()->MsgBox( 501 wsMessage, bsTitle, dwMessageType, dwButtonType); 502 CFXJSE_Value* pValue = pArguments->GetReturnValue(); 503 if (pValue) 504 pValue->SetInteger(iValue); 505 } 506 bool CScript_HostPseudoModel::ValidateArgsForMsg(CFXJSE_Arguments* pArguments, 507 int32_t iArgIndex, 508 CFX_WideString& wsValue) { 509 if (!pArguments || iArgIndex < 0) { 510 return false; 511 } 512 bool bIsJsType = false; 513 if (m_pDocument->GetScriptContext()->GetType() == 514 XFA_SCRIPTLANGTYPE_Javascript) { 515 bIsJsType = true; 516 } 517 std::unique_ptr<CFXJSE_Value> pValueArg(pArguments->GetValue(iArgIndex)); 518 if (!pValueArg->IsString() && bIsJsType) { 519 ThrowArgumentMismatchException(); 520 return false; 521 } 522 if (pValueArg->IsNull()) { 523 wsValue = L""; 524 } else { 525 wsValue = pValueArg->ToWideString(); 526 } 527 return true; 528 } 529 void CScript_HostPseudoModel::DocumentCountInBatch( 530 CFXJSE_Arguments* pArguments) { 531 if (CFXJSE_Value* pValue = pArguments->GetReturnValue()) 532 pValue->SetInteger(0); 533 } 534 void CScript_HostPseudoModel::Print(CFXJSE_Arguments* pArguments) { 535 if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { 536 return; 537 } 538 int32_t iLength = pArguments->GetLength(); 539 if (iLength != 8) { 540 ThrowParamCountMismatchException(L"print"); 541 return; 542 } 543 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); 544 if (!pNotify) { 545 return; 546 } 547 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); 548 uint32_t dwOptions = 0; 549 bool bShowDialog = true; 550 if (iLength >= 1) { 551 bShowDialog = pArguments->GetInt32(0) == 0 ? false : true; 552 } 553 if (bShowDialog) { 554 dwOptions |= XFA_PRINTOPT_ShowDialog; 555 } 556 int32_t nStartPage = 0; 557 if (iLength >= 2) { 558 nStartPage = pArguments->GetInt32(1); 559 } 560 int32_t nEndPage = 0; 561 if (iLength >= 3) { 562 nEndPage = pArguments->GetInt32(2); 563 } 564 bool bCanCancel = true; 565 if (iLength >= 4) { 566 bCanCancel = pArguments->GetInt32(3) == 0 ? false : true; 567 } 568 if (bCanCancel) { 569 dwOptions |= XFA_PRINTOPT_CanCancel; 570 } 571 bool bShrinkPage = true; 572 if (iLength >= 5) { 573 bShrinkPage = pArguments->GetInt32(4) == 0 ? false : true; 574 } 575 if (bShrinkPage) { 576 dwOptions |= XFA_PRINTOPT_ShrinkPage; 577 } 578 bool bAsImage = true; 579 if (iLength >= 6) { 580 bAsImage = pArguments->GetInt32(5) == 0 ? false : true; 581 } 582 if (bAsImage) { 583 dwOptions |= XFA_PRINTOPT_AsImage; 584 } 585 bool bReverseOrder = true; 586 if (iLength >= 7) { 587 bAsImage = pArguments->GetInt32(5) == 0 ? false : true; 588 } 589 bReverseOrder = pArguments->GetInt32(6) == 0 ? false : true; 590 if (bReverseOrder) { 591 dwOptions |= XFA_PRINTOPT_ReverseOrder; 592 } 593 bool bPrintAnnot = true; 594 if (iLength >= 8) { 595 bPrintAnnot = pArguments->GetInt32(7) == 0 ? false : true; 596 } 597 if (bPrintAnnot) { 598 dwOptions |= XFA_PRINTOPT_PrintAnnot; 599 } 600 pNotify->GetDocEnvironment()->Print(hDoc, nStartPage, nEndPage, dwOptions); 601 } 602 603 void CScript_HostPseudoModel::ImportData(CFXJSE_Arguments* pArguments) { 604 int32_t iLength = pArguments->GetLength(); 605 if (iLength < 0 || iLength > 1) { 606 ThrowParamCountMismatchException(L"importData"); 607 return; 608 } 609 // Not implemented. 610 } 611 612 void CScript_HostPseudoModel::ExportData(CFXJSE_Arguments* pArguments) { 613 int32_t iLength = pArguments->GetLength(); 614 if (iLength < 0 || iLength > 2) { 615 ThrowParamCountMismatchException(L"exportData"); 616 return; 617 } 618 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); 619 if (!pNotify) { 620 return; 621 } 622 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); 623 CFX_WideString wsFilePath; 624 bool bXDP = true; 625 if (iLength >= 1) { 626 CFX_ByteString bsFilePath = pArguments->GetUTF8String(0); 627 wsFilePath = CFX_WideString::FromUTF8(bsFilePath.AsStringC()); 628 } 629 if (iLength >= 2) { 630 bXDP = pArguments->GetInt32(1) == 0 ? false : true; 631 } 632 pNotify->GetDocEnvironment()->ExportData(hDoc, wsFilePath, bXDP); 633 } 634 635 void CScript_HostPseudoModel::PageUp(CFXJSE_Arguments* pArguments) { 636 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); 637 if (!pNotify) { 638 return; 639 } 640 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); 641 int32_t nCurPage = pNotify->GetDocEnvironment()->GetCurrentPage(hDoc); 642 int32_t nNewPage = 0; 643 if (nCurPage <= 1) { 644 return; 645 } 646 nNewPage = nCurPage - 1; 647 pNotify->GetDocEnvironment()->SetCurrentPage(hDoc, nNewPage); 648 } 649 650 void CScript_HostPseudoModel::PageDown(CFXJSE_Arguments* pArguments) { 651 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); 652 if (!pNotify) { 653 return; 654 } 655 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); 656 int32_t nCurPage = pNotify->GetDocEnvironment()->GetCurrentPage(hDoc); 657 int32_t nPageCount = pNotify->GetDocEnvironment()->CountPages(hDoc); 658 if (!nPageCount || nCurPage == nPageCount) { 659 return; 660 } 661 int32_t nNewPage = 0; 662 if (nCurPage >= nPageCount) { 663 nNewPage = nPageCount - 1; 664 } else { 665 nNewPage = nCurPage + 1; 666 } 667 pNotify->GetDocEnvironment()->SetCurrentPage(hDoc, nNewPage); 668 } 669 670 void CScript_HostPseudoModel::CurrentDateTime(CFXJSE_Arguments* pArguments) { 671 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); 672 if (!pNotify) { 673 return; 674 } 675 CFX_WideString wsDataTime = pNotify->GetCurrentDateTime(); 676 CFXJSE_Value* pValue = pArguments->GetReturnValue(); 677 if (pValue) 678 pValue->SetString(wsDataTime.UTF8Encode().AsStringC()); 679 } 680 681 void CScript_HostPseudoModel::ThrowSetLanguageException() const { 682 ThrowException(L"Unable to set language value."); 683 } 684 685 void CScript_HostPseudoModel::ThrowSetNumPagesException() const { 686 ThrowException(L"Unable to set numPages value."); 687 } 688 689 void CScript_HostPseudoModel::ThrowSetPlatformException() const { 690 ThrowException(L"Unable to set platform value."); 691 } 692 693 void CScript_HostPseudoModel::ThrowSetVariationException() const { 694 ThrowException(L"Unable to set variation value."); 695 } 696 697 void CScript_HostPseudoModel::ThrowSetVersionException() const { 698 ThrowException(L"Unable to set version value."); 699 } 700