fsdk_actionhandler.cpp revision ee451cb395940862dad63c85adfe8f2fd55e864c
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 "../include/fsdk_define.h" 8#include "../include/fsdk_mgr.h" 9#include "../include/fsdk_actionhandler.h" 10#include "../include/javascript/IJavaScript.h" 11 12/* -------------------------- CBA_ActionHandler -------------------------- */ 13 14CPDFSDK_ActionHandler::CPDFSDK_ActionHandler(CPDFDoc_Environment* pEvi) : 15 m_pEvi(pEvi), 16 m_pFormActionHandler(NULL), 17 m_pMediaActionHandler(NULL) 18{ 19 m_pFormActionHandler = new CPDFSDK_FormActionHandler; 20} 21 22CPDFSDK_ActionHandler::~CPDFSDK_ActionHandler() 23{ 24 if(m_pFormActionHandler) 25 { 26 delete m_pFormActionHandler; 27 m_pFormActionHandler = NULL; 28 } 29} 30 31void CPDFSDK_ActionHandler::SetFormActionHandler(CPDFSDK_FormActionHandler* pHandler) 32{ 33 ASSERT(pHandler != NULL); 34 ASSERT(m_pFormActionHandler == NULL); 35 m_pFormActionHandler = pHandler; 36} 37 38void CPDFSDK_ActionHandler::SetMediaActionHandler(CPDFSDK_MediaActionHandler* pHandler) 39{ 40 ASSERT(pHandler != NULL); 41 ASSERT(m_pMediaActionHandler == NULL); 42 m_pMediaActionHandler = pHandler; 43} 44 45void CPDFSDK_ActionHandler::Destroy() 46{ 47 delete this; 48} 49 50//document open 51FX_BOOL CPDFSDK_ActionHandler::DoAction_DocOpen(const CPDF_Action& action, CPDFSDK_Document* pDocument 52 /*CReader_Document* pDocument, CReader_DocView *pDocView*/) 53{ 54 CFX_PtrList list; 55 return ExecuteDocumentOpenAction(action, pDocument, /*pDocView, */list); 56} 57 58//document open 59FX_BOOL CPDFSDK_ActionHandler::DoAction_JavaScript(const CPDF_Action& JsAction,CFX_WideString csJSName, 60 CPDFSDK_Document* pDocument/*, CReader_DocView *pDocView*/) 61{ 62 if (JsAction.GetType() == CPDF_Action::JavaScript) 63 { 64 CFX_WideString swJS = JsAction.GetJavaScript(); 65 if (!swJS.IsEmpty()) 66 { 67 RunDocumentOpenJavaScript(pDocument, csJSName, swJS); 68 return TRUE; 69 } 70 } 71 72 return FALSE; 73} 74 75FX_BOOL CPDFSDK_ActionHandler::DoAction_FieldJavaScript(const CPDF_Action& JsAction, CPDF_AAction::AActionType type, 76 CPDFSDK_Document* pDocument, CPDF_FormField* pFormField, 77 PDFSDK_FieldAction& data) 78{ 79 CPDFDoc_Environment* pEnv = pDocument->GetEnv(); 80 ASSERT(pEnv); 81 if (pEnv->IsJSInitiated() && JsAction.GetType() == CPDF_Action::JavaScript) 82 { 83 CFX_WideString swJS = JsAction.GetJavaScript(); 84 if (!swJS.IsEmpty()) 85 { 86 RunFieldJavaScript(pDocument, pFormField, type, data, swJS); 87 return TRUE; 88 } 89 } 90 return FALSE; 91} 92 93FX_BOOL CPDFSDK_ActionHandler::DoAction_Page(const CPDF_Action& action, enum CPDF_AAction::AActionType eType, 94 CPDFSDK_Document* pDocument/*, CReader_DocView *pDocView*/) 95{ 96 CFX_PtrList list; 97 return ExecuteDocumentPageAction(action, eType, pDocument,/* pDocView,*/ list); 98} 99 100FX_BOOL CPDFSDK_ActionHandler::DoAction_Document(const CPDF_Action& action, enum CPDF_AAction::AActionType eType, 101 CPDFSDK_Document* pDocument/*, CReader_DocView *pDocView*/) 102{ 103 CFX_PtrList list; 104 return ExecuteDocumentPageAction(action, eType, pDocument,/* pDocView,*/ list); 105} 106 107FX_BOOL CPDFSDK_ActionHandler::DoAction_BookMark(CPDF_Bookmark *pBookMark, const CPDF_Action& action, CPDF_AAction::AActionType type, 108 CPDFSDK_Document* pDocument/*, CReader_DocView *pDocView*/) 109{ 110 CFX_PtrList list; 111 return this->ExecuteBookMark(action, pDocument,/* pDocView,*/ pBookMark, list); 112} 113 114FX_BOOL CPDFSDK_ActionHandler::DoAction_Screen(const CPDF_Action& action, CPDF_AAction::AActionType type, 115 CPDFSDK_Document* pDocument,/* CReader_DocView *pDocView,*/ CPDFSDK_Annot* pScreen) 116{ 117 CFX_PtrList list; 118 return this->ExecuteScreenAction(action, type, pDocument,/* pDocView,*/ pScreen, list); 119} 120 121FX_BOOL CPDFSDK_ActionHandler::DoAction_Link(const CPDF_Action& action, 122 CPDFSDK_Document* pDocument/*, CReader_DocView *pDocView*/) 123{ 124 CFX_PtrList list; 125 return ExecuteLinkAction(action, pDocument,/* pDocView,*/ list); 126} 127 128FX_BOOL CPDFSDK_ActionHandler::DoAction_Field(const CPDF_Action& action, CPDF_AAction::AActionType type, 129 CPDFSDK_Document* pDocument,/* CReader_DocView *pDocView,*/ 130 CPDF_FormField* pFormField, PDFSDK_FieldAction& data) 131{ 132 CFX_PtrList list; 133 return ExecuteFieldAction(action, type, pDocument,/* pDocView,*/ pFormField, data, list); 134} 135 136FX_BOOL CPDFSDK_ActionHandler::ExecuteDocumentOpenAction(const CPDF_Action& action, CPDFSDK_Document* pDocument, 137 /*CReader_DocView *pDocView,*/ CFX_PtrList& list) 138{ 139 ASSERT(pDocument != NULL); 140 141 if (list.Find((CPDF_Dictionary*)action)) 142 return FALSE; 143 list.AddTail((CPDF_Dictionary*)action); 144 145 CPDFDoc_Environment* pEnv = pDocument->GetEnv(); 146 ASSERT(pEnv); 147 if (action.GetType() == CPDF_Action::JavaScript) 148 { 149 if(pEnv->IsJSInitiated()) 150 { 151 CFX_WideString swJS = action.GetJavaScript(); 152 if (!swJS.IsEmpty()) 153 { 154 RunDocumentOpenJavaScript(pDocument, L"", swJS); 155 } 156 } 157 } 158 else 159 { 160 DoAction_NoJs(action, pDocument/*, pDocView*/); 161 } 162 163// if (!IsValidDocView(pDocument, pDocView)) 164// return FALSE; 165 166 for (FX_INT32 i=0,sz=action.GetSubActionsCount(); i<sz; i++) 167 { 168 CPDF_Action subaction = action.GetSubAction(i); 169 if (!ExecuteDocumentOpenAction(subaction, pDocument,/* pDocView,*/ list)) return FALSE; 170 } 171 172 return TRUE; 173} 174 175FX_BOOL CPDFSDK_ActionHandler::ExecuteLinkAction(const CPDF_Action& action, CPDFSDK_Document* pDocument, 176 /*CReader_DocView* pDocView,*/ CFX_PtrList& list) 177{ 178 ASSERT(pDocument != NULL); 179 180 if (list.Find((CPDF_Dictionary*)action)) 181 return FALSE; 182 list.AddTail((CPDF_Dictionary*)action); 183 184 CPDFDoc_Environment* pEnv = pDocument->GetEnv(); 185 ASSERT(pEnv); 186 if (action.GetType() == CPDF_Action::JavaScript) 187 { 188 if(pEnv->IsJSInitiated()) 189 { 190 CFX_WideString swJS = action.GetJavaScript(); 191 if (!swJS.IsEmpty()) 192 { 193 IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime(); //???? 194 ASSERT(pRuntime != NULL); 195 196 pRuntime->SetReaderDocument(pDocument); 197 198 IFXJS_Context* pContext = pRuntime->NewContext(); 199 ASSERT(pContext != NULL); 200 201 pContext->OnLink_MouseUp(pDocument); 202 203 CFX_WideString csInfo; 204 FX_BOOL bRet = pContext->RunScript(swJS, csInfo); 205 if (!bRet) 206 { 207 //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo); 208 } 209 210 pRuntime->ReleaseContext(pContext); 211 } 212 } 213 } 214 else 215 { 216 DoAction_NoJs(action, pDocument/*, pDocView*/); 217 } 218 219// if (!IsValidDocView(pDocument, pDocView)) 220// return FALSE; 221 222 for (FX_INT32 i=0,sz=action.GetSubActionsCount(); i<sz; i++) 223 { 224 CPDF_Action subaction = action.GetSubAction(i); 225 if (!ExecuteLinkAction(subaction, pDocument,/* pDocView,*/ list)) return FALSE; 226 } 227 228 return TRUE; 229} 230 231FX_BOOL CPDFSDK_ActionHandler::ExecuteDocumentPageAction(const CPDF_Action& action, CPDF_AAction::AActionType type, 232 CPDFSDK_Document* pDocument,/* CReader_DocView* pDocView,*/ CFX_PtrList& list) 233{ 234 ASSERT(pDocument != NULL); 235 236 if (list.Find((CPDF_Dictionary*)action)) 237 return FALSE; 238 list.AddTail((CPDF_Dictionary*)action); 239 240 CPDFDoc_Environment* pEnv = pDocument->GetEnv(); 241 ASSERT(pEnv); 242 if (action.GetType() == CPDF_Action::JavaScript) 243 { 244 if(pEnv->IsJSInitiated()) 245 { 246 CFX_WideString swJS = action.GetJavaScript(); 247 if (!swJS.IsEmpty()) 248 { 249 RunDocumentPageJavaScript(pDocument, type, swJS); 250 } 251 } 252 } 253 else 254 { 255 DoAction_NoJs(action, pDocument/*, pDocView*/); 256 } 257 258 if (!IsValidDocView(pDocument/*, pDocView*/)) 259 return FALSE; 260 261 for (FX_INT32 i=0,sz=action.GetSubActionsCount(); i<sz; i++) 262 { 263 CPDF_Action subaction = action.GetSubAction(i); 264 if (!ExecuteDocumentPageAction(subaction, type, pDocument,/* pDocView,*/ list)) return FALSE; 265 } 266 267 return TRUE; 268} 269 270FX_BOOL CPDFSDK_ActionHandler::IsValidField(CPDFSDK_Document* pDocument, CPDF_Dictionary* pFieldDict) 271{ 272 ASSERT(m_pEvi != NULL); 273 ASSERT(pDocument != NULL); 274 ASSERT(pFieldDict != NULL); 275 276 if (1/*m_pApp->IsValidDocument(pDocument)*/) 277 { 278 CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm(); 279 ASSERT(pInterForm != NULL); 280 281 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); 282 ASSERT(pPDFInterForm != NULL); 283 284 return pPDFInterForm->GetFieldByDict(pFieldDict) != NULL; 285 } 286 287 return FALSE; 288} 289 290FX_BOOL CPDFSDK_ActionHandler::ExecuteFieldAction(const CPDF_Action& action, CPDF_AAction::AActionType type, 291 CPDFSDK_Document* pDocument,/* CReader_DocView* pDocView,*/ CPDF_FormField* pFormField, 292 PDFSDK_FieldAction& data, CFX_PtrList& list) 293{ 294 ASSERT(pDocument != NULL); 295 296 if (list.Find((CPDF_Dictionary*)action)) 297 return FALSE; 298 list.AddTail((CPDF_Dictionary*)action); 299 300 CPDFDoc_Environment* pEnv = pDocument->GetEnv(); 301 ASSERT(pEnv); 302 if (action.GetType() == CPDF_Action::JavaScript) 303 { 304 if(pEnv->IsJSInitiated()) 305 { 306 CFX_WideString swJS = action.GetJavaScript(); 307 if (!swJS.IsEmpty()) 308 { 309 RunFieldJavaScript(pDocument, pFormField, type, data, swJS); 310 if (!IsValidField(pDocument, pFormField->GetFieldDict())) 311 return FALSE; 312 } 313 } 314 } 315 else 316 { 317 DoAction_NoJs(action, pDocument/*, pDocView*/); 318// if (!IsValidDocView(pDocument, pDocView)) 319// return FALSE; 320 } 321 322 for (FX_INT32 i=0,sz=action.GetSubActionsCount(); i<sz; i++) 323 { 324 CPDF_Action subaction = action.GetSubAction(i); 325 if (!ExecuteFieldAction(subaction, type, pDocument,/* pDocView,*/ pFormField, data, list)) return FALSE; 326 } 327 328 return TRUE; 329} 330 331FX_BOOL CPDFSDK_ActionHandler::ExecuteScreenAction(const CPDF_Action& action, CPDF_AAction::AActionType type, 332 CPDFSDK_Document* pDocument,/* CReader_DocView* pDocView,*/ CPDFSDK_Annot* pScreen, CFX_PtrList& list) 333{ 334 ASSERT(pDocument != NULL); 335 336 if (list.Find((CPDF_Dictionary*)action)) 337 return FALSE; 338 list.AddTail((CPDF_Dictionary*)action); 339 340 CPDFDoc_Environment* pEnv = pDocument->GetEnv(); 341 ASSERT(pEnv); 342 if (action.GetType() == CPDF_Action::JavaScript) 343 { 344 if(pEnv->IsJSInitiated()) 345 { 346 CFX_WideString swJS = action.GetJavaScript(); 347 if (!swJS.IsEmpty()) 348 { 349 IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime(); 350 ASSERT(pRuntime != NULL); 351 352 pRuntime->SetReaderDocument(pDocument); 353 354 IFXJS_Context* pContext = pRuntime->NewContext(); 355 ASSERT(pContext != NULL); 356 357 // switch (type) 358 // { 359 // case CPDF_AAction::CursorEnter: 360 // pContext->OnScreen_MouseEnter(IsCTRLpressed(), IsSHIFTpressed(), pScreen); 361 // break; 362 // case CPDF_AAction::CursorExit: 363 // pContext->OnScreen_MouseExit(IsCTRLpressed(), IsSHIFTpressed(), pScreen); 364 // break; 365 // case CPDF_AAction::ButtonDown: 366 // pContext->OnScreen_MouseDown(IsCTRLpressed(), IsSHIFTpressed(), pScreen); 367 // break; 368 // case CPDF_AAction::ButtonUp: 369 // pContext->OnScreen_MouseUp(IsCTRLpressed(), IsSHIFTpressed(), pScreen); 370 // break; 371 // case CPDF_AAction::GetFocus: 372 // pContext->OnScreen_Focus(IsCTRLpressed(), IsSHIFTpressed(), pScreen); 373 // break; 374 // case CPDF_AAction::LoseFocus: 375 // pContext->OnScreen_Blur(IsCTRLpressed(), IsSHIFTpressed(), pScreen); 376 // break; 377 // case CPDF_AAction::PageOpen: 378 // pContext->OnScreen_Open(IsCTRLpressed(), IsSHIFTpressed(), pScreen); 379 // break; 380 // case CPDF_AAction::PageClose: 381 // pContext->OnScreen_Close(IsCTRLpressed(), IsSHIFTpressed(), pScreen); 382 // break; 383 // case CPDF_AAction::PageVisible: 384 // pContext->OnScreen_InView(IsCTRLpressed(), IsSHIFTpressed(), pScreen); 385 // break; 386 // case CPDF_AAction::PageInvisible: 387 // pContext->OnScreen_OutView(IsCTRLpressed(), IsSHIFTpressed(), pScreen); 388 // break; 389 // default: 390 // ASSERT(FALSE); 391 // break; 392 // } 393 394 CFX_WideString csInfo; 395 FX_BOOL bRet = pContext->RunScript(swJS, csInfo); 396 if (!bRet) 397 { 398 //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo); 399 } 400 401 pRuntime->ReleaseContext(pContext); 402 } 403 } 404 } 405 else 406 { 407 DoAction_NoJs(action, pDocument/*, pDocView*/); 408 } 409 410// if (!IsValidDocView(pDocument, pDocView)) 411// return FALSE; 412 413 for (FX_INT32 i=0,sz=action.GetSubActionsCount(); i<sz; i++) 414 { 415 CPDF_Action subaction = action.GetSubAction(i); 416 if (!ExecuteScreenAction(subaction, type, pDocument,/* pDocView,*/ pScreen, list)) return FALSE; 417 } 418 419 return TRUE; 420} 421 422FX_BOOL CPDFSDK_ActionHandler::ExecuteBookMark(const CPDF_Action& action, CPDFSDK_Document* pDocument, 423 /*CReader_DocView* pDocView,*/ CPDF_Bookmark* pBookmark, CFX_PtrList& list) 424{ 425 ASSERT(pDocument != NULL); 426 427 if (list.Find((CPDF_Dictionary*)action)) 428 return FALSE; 429 list.AddTail((CPDF_Dictionary*)action); 430 431 CPDFDoc_Environment* pEnv = pDocument->GetEnv(); 432 ASSERT(pEnv); 433 if (action.GetType() == CPDF_Action::JavaScript) 434 { 435 if(pEnv->IsJSInitiated()) 436 { 437 CFX_WideString swJS = action.GetJavaScript(); 438 if (!swJS.IsEmpty()) 439 { 440 IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime(); 441 ASSERT(pRuntime != NULL); 442 443 pRuntime->SetReaderDocument(pDocument); 444 445 IFXJS_Context* pContext = pRuntime->NewContext(); 446 ASSERT(pContext != NULL); 447 448 pContext->OnBookmark_MouseUp(pBookmark); 449 450 CFX_WideString csInfo; 451 FX_BOOL bRet = pContext->RunScript(swJS, csInfo); 452 if (!bRet) 453 { 454 //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo); 455 } 456 457 pRuntime->ReleaseContext(pContext); 458 } 459 } 460 } 461 else 462 { 463 DoAction_NoJs(action, pDocument/*, pDocView*/); 464 } 465 466// if (!IsValidDocView(pDocument, pDocView)) 467// return FALSE; 468 469 for (FX_INT32 i=0,sz=action.GetSubActionsCount(); i<sz; i++) 470 { 471 CPDF_Action subaction = action.GetSubAction(i); 472 if (!ExecuteBookMark(subaction, pDocument,/* pDocView,*/ pBookmark, list)) return FALSE; 473 } 474 475 return TRUE; 476} 477 478void CPDFSDK_ActionHandler::DoAction_NoJs(const CPDF_Action& action, CPDFSDK_Document* pDocument/*, CReader_DocView* pDocView*/) 479{ 480 ASSERT(pDocument != NULL); 481 482 switch (action.GetType()) 483 { 484 case CPDF_Action::GoTo: 485 DoAction_GoTo(pDocument,/* pDocView,*/ action); 486 break; 487 case CPDF_Action::GoToR: 488 DoAction_GoToR(pDocument, action); 489 break; 490 case CPDF_Action::GoToE: 491 break; 492 case CPDF_Action::Launch: 493 DoAction_Launch(pDocument, action); 494 break; 495 case CPDF_Action::Thread: 496 break; 497 case CPDF_Action::URI: 498 DoAction_URI(pDocument, action); 499 break; 500 case CPDF_Action::Sound: 501 if (m_pMediaActionHandler) 502 { 503 m_pMediaActionHandler->DoAction_Sound(action, pDocument/*, pDocView*/); 504 } 505 break; 506 case CPDF_Action::Movie: 507 if (m_pMediaActionHandler) 508 { 509 m_pMediaActionHandler->DoAction_Movie(action, pDocument/*, pDocView*/); 510 } 511 break; 512 case CPDF_Action::Hide: 513 if (m_pFormActionHandler) 514 { 515 m_pFormActionHandler->DoAction_Hide(action, pDocument); 516 } 517 break; 518 case CPDF_Action::Named: 519 DoAction_Named(pDocument, action); 520 break; 521 case CPDF_Action::SubmitForm: 522 if (m_pFormActionHandler) 523 { 524 m_pFormActionHandler->DoAction_SubmitForm(action, pDocument/*, pDocView*/); 525 } 526 break; 527 case CPDF_Action::ResetForm: 528 if (m_pFormActionHandler) 529 { 530 m_pFormActionHandler->DoAction_ResetForm(action, pDocument); 531 } 532 break; 533 case CPDF_Action::ImportData: 534 if (m_pFormActionHandler) 535 { 536 m_pFormActionHandler->DoAction_ImportData(action, pDocument/*, pDocView*/); 537 } 538 break; 539 case CPDF_Action::JavaScript: 540 ASSERT(FALSE); 541 break; 542 case CPDF_Action::SetOCGState: 543 DoAction_SetOCGState(pDocument, /*pDocView,*/ action); 544 break; 545 case CPDF_Action::Rendition: 546 if (m_pMediaActionHandler) 547 { 548 m_pMediaActionHandler->DoAction_Rendition(action, pDocument/*, pDocView*/); 549 } 550 break; 551 case CPDF_Action::Trans: 552 break; 553 case CPDF_Action::GoTo3DView: 554 break; 555 default: 556 break; 557 } 558} 559 560FX_BOOL CPDFSDK_ActionHandler::IsValidDocView(CPDFSDK_Document* pDocument/*, CReader_DocView* pDocView*/) 561{ 562 ASSERT(pDocument != NULL); 563 //ASSERT(pDocView != NULL); 564 565 //return pDocument->IsValidDocView(pDocView); 566 return TRUE; 567} 568 569void CPDFSDK_ActionHandler::DoAction_GoTo(CPDFSDK_Document* pDocument, /*CReader_DocView* pDocView,*/ 570 const CPDF_Action& action) 571{ 572 ASSERT(pDocument != NULL); 573// ASSERT(pDocView != NULL); 574 ASSERT(action != NULL); 575 576 CPDF_Document* pPDFDocument = pDocument->GetDocument(); 577 ASSERT(pPDFDocument != NULL); 578 CPDFDoc_Environment* pApp = pDocument->GetEnv(); 579 ASSERT(pApp != NULL); 580 581 CPDF_Dest MyDest = action.GetDest(pPDFDocument); 582 int nPageIndex = MyDest.GetPageIndex(pPDFDocument); 583 int nFitType = MyDest.GetZoomMode(); 584 const CPDF_Array * pMyArray = (CPDF_Array*)MyDest.m_pObj; 585 float* pPosAry = NULL; 586 int sizeOfAry = 0; 587 if (pMyArray != NULL) 588 { 589 pPosAry = new float[pMyArray->GetCount()]; 590 int j = 0; 591 for (int i = 2; i < (int)pMyArray->GetCount(); i++) 592 { 593 pPosAry[j++] = pMyArray->GetFloat(i); 594 } 595 sizeOfAry = j; 596 } 597 pApp->FFI_DoGoToAction(nPageIndex, nFitType, pPosAry, sizeOfAry); 598 if(pPosAry) 599 delete[] pPosAry; 600} 601 602void CPDFSDK_ActionHandler::DoAction_GoToR(CPDFSDK_Document* pDocument, const CPDF_Action& action) 603{ 604 605} 606 607void CPDFSDK_ActionHandler::DoAction_Launch(CPDFSDK_Document* pDocument, const CPDF_Action& action) 608{ 609 610} 611 612void CPDFSDK_ActionHandler::DoAction_URI(CPDFSDK_Document* pDocument, const CPDF_Action& action) 613{ 614 ASSERT(pDocument != NULL); 615 ASSERT(action != NULL); 616 617 CPDFDoc_Environment* pApp = pDocument->GetEnv(); 618 ASSERT(pApp != NULL); 619 620 CFX_ByteString sURI = action.GetURI(pDocument->GetDocument()); 621 pApp->FFI_DoURIAction(FX_LPCSTR(sURI)); 622} 623 624void CPDFSDK_ActionHandler::DoAction_Named(CPDFSDK_Document* pDocument, const CPDF_Action& action) 625{ 626 ASSERT(pDocument != NULL); 627 ASSERT(action != NULL); 628 629 CFX_ByteString csName = action.GetNamedAction(); 630 pDocument->GetEnv()->FFI_ExecuteNamedAction(csName); 631} 632 633 634void CPDFSDK_ActionHandler::DoAction_SetOCGState(CPDFSDK_Document* pDocument,/* CReader_DocView* pDocView,*/ const CPDF_Action& action) 635{ 636} 637 638void CPDFSDK_ActionHandler::RunFieldJavaScript(CPDFSDK_Document* pDocument, CPDF_FormField* pFormField, CPDF_AAction::AActionType type, 639 PDFSDK_FieldAction& data, const CFX_WideString& script) 640{ 641 ASSERT(type != CPDF_AAction::Calculate); 642 ASSERT(type != CPDF_AAction::Format); 643 644 ASSERT(pDocument != NULL); 645 646 IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime(); 647 ASSERT(pRuntime != NULL); 648 649 pRuntime->SetReaderDocument(pDocument); 650 651 IFXJS_Context* pContext = pRuntime->NewContext(); 652 ASSERT(pContext != NULL); 653 654 switch (type) 655 { 656 case CPDF_AAction::CursorEnter: 657 pContext->OnField_MouseEnter(data.bModifier, data.bShift, pFormField); 658 break; 659 case CPDF_AAction::CursorExit: 660 pContext->OnField_MouseExit(data.bModifier, data.bShift, pFormField); 661 break; 662 case CPDF_AAction::ButtonDown: 663 pContext->OnField_MouseDown(data.bModifier, data.bShift, pFormField); 664 break; 665 case CPDF_AAction::ButtonUp: 666 pContext->OnField_MouseUp(data.bModifier, data.bShift, pFormField); 667 break; 668 case CPDF_AAction::GetFocus: 669 pContext->OnField_Focus(data.bModifier, data.bShift, pFormField, data.sValue); 670 break; 671 case CPDF_AAction::LoseFocus: 672 pContext->OnField_Blur(data.bModifier, data.bShift, pFormField, data.sValue); 673 break; 674 case CPDF_AAction::KeyStroke: 675 pContext->OnField_Keystroke(data.nCommitKey, data.sChange, data.sChangeEx, data.bKeyDown, 676 data.bModifier, data.nSelEnd, data.nSelStart, data.bShift, pFormField, data.sValue, 677 data.bWillCommit, data.bFieldFull, data.bRC); 678 break; 679 case CPDF_AAction::Validate: 680 pContext->OnField_Validate(data.sChange, data.sChangeEx, data.bKeyDown, data.bModifier, 681 data.bShift, pFormField, data.sValue, data.bRC); 682 break; 683 default: 684 ASSERT(FALSE); 685 break; 686 } 687 688 CFX_WideString csInfo; 689 FX_BOOL bRet = pContext->RunScript(script, csInfo); 690 if (!bRet) 691 { 692 //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo); 693 } 694 695 pRuntime->ReleaseContext(pContext); 696} 697 698void CPDFSDK_ActionHandler::RunDocumentOpenJavaScript(CPDFSDK_Document* pDocument, const CFX_WideString& sScriptName, const CFX_WideString& script) 699{ 700 ASSERT(pDocument != NULL); 701 702 IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime(); 703 ASSERT(pRuntime != NULL); 704 705 pRuntime->SetReaderDocument(pDocument); 706 707 IFXJS_Context* pContext = pRuntime->NewContext(); 708 ASSERT(pContext != NULL); 709 710 pContext->OnDoc_Open(pDocument, sScriptName); 711 712 CFX_WideString csInfo; 713 FX_BOOL bRet = pContext->RunScript(script, csInfo); 714 if (!bRet) 715 { 716 //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo); 717 } 718 719 pRuntime->ReleaseContext(pContext); 720} 721 722void CPDFSDK_ActionHandler::RunDocumentPageJavaScript(CPDFSDK_Document* pDocument, CPDF_AAction::AActionType type, const CFX_WideString& script) 723{ 724 ASSERT(pDocument != NULL); 725 726 IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime(); 727 ASSERT(pRuntime != NULL); 728 729 pRuntime->SetReaderDocument(pDocument); 730 731 IFXJS_Context* pContext = pRuntime->NewContext(); 732 ASSERT(pContext != NULL); 733 734 switch (type) 735 { 736 case CPDF_AAction::OpenPage: 737 pContext->OnPage_Open(pDocument); 738 break; 739 case CPDF_AAction::ClosePage: 740 pContext->OnPage_Close(pDocument); 741 break; 742 case CPDF_AAction::CloseDocument: 743 pContext->OnDoc_WillClose(pDocument); 744 break; 745 case CPDF_AAction::SaveDocument: 746 pContext->OnDoc_WillSave(pDocument); 747 break; 748 case CPDF_AAction::DocumentSaved: 749 pContext->OnDoc_DidSave(pDocument); 750 break; 751 case CPDF_AAction::PrintDocument: 752 pContext->OnDoc_WillPrint(pDocument); 753 break; 754 case CPDF_AAction::DocumentPrinted: 755 pContext->OnDoc_DidPrint(pDocument); 756 break; 757 case CPDF_AAction::PageVisible: 758 pContext->OnPage_InView(pDocument); 759 break; 760 case CPDF_AAction::PageInvisible: 761 pContext->OnPage_OutView(pDocument); 762 break; 763 default: 764 ASSERT(FALSE); 765 break; 766 } 767 768 CFX_WideString csInfo; 769 FX_BOOL bRet = pContext->RunScript(script, csInfo); 770 if (!bRet) 771 { 772 //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo); 773 } 774 775 pRuntime->ReleaseContext(pContext); 776} 777 778 779FX_BOOL CPDFSDK_FormActionHandler::DoAction_Hide(const CPDF_Action& action, CPDFSDK_Document* pDocument) 780{ 781 ASSERT(pDocument != NULL); 782 783 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); 784 ASSERT(pInterForm != NULL); 785 786 if (pInterForm->DoAction_Hide(action)) 787 { 788 pDocument->SetChangeMark(); 789 return TRUE; 790 } 791 792 return FALSE; 793} 794 795FX_BOOL CPDFSDK_FormActionHandler::DoAction_SubmitForm(const CPDF_Action& action, CPDFSDK_Document* pDocument) 796{ 797 ASSERT(pDocument != NULL); 798 799 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); 800 ASSERT(pInterForm != NULL); 801 802 return pInterForm->DoAction_SubmitForm(action); 803} 804 805FX_BOOL CPDFSDK_FormActionHandler::DoAction_ResetForm(const CPDF_Action& action, CPDFSDK_Document* pDocument) 806{ 807 ASSERT(pDocument != NULL); 808 809 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); 810 ASSERT(pInterForm != NULL); 811 812 if (pInterForm->DoAction_ResetForm(action)) 813 { 814 return TRUE; 815 } 816 817 return FALSE; 818} 819 820FX_BOOL CPDFSDK_FormActionHandler::DoAction_ImportData(const CPDF_Action& action, CPDFSDK_Document* pDocument) 821{ 822 ASSERT(pDocument != NULL); 823 824 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); 825 ASSERT(pInterForm != NULL); 826 827 if (pInterForm->DoAction_ImportData(action)) 828 { 829 pDocument->SetChangeMark(); 830 return TRUE; 831 } 832 833 return FALSE; 834} 835 836FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Rendition(const CPDF_Action& action, CPDFSDK_Document* pDocument) 837{ 838 return FALSE; 839} 840 841FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Sound(const CPDF_Action& action, CPDFSDK_Document* pDocument) 842{ 843 return FALSE; 844} 845 846FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Movie(const CPDF_Action& action, CPDFSDK_Document* pDocument) 847{ 848 return FALSE; 849} 850 851