494b5298d36bb160a7e0fcd2b5f23f3d38f5b51d
[pdfium.git] / fpdfsdk / src / fsdk_actionhandler.cpp
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/fpdfxfa/fpdfxfa_doc.h"
9 #include "../include/fsdk_mgr.h"
10 #include "../include/fsdk_actionhandler.h"
11 #include "../include/javascript/IJavaScript.h"
12
13 /* -------------------------- CBA_ActionHandler -------------------------- */
14
15 CPDFSDK_ActionHandler::CPDFSDK_ActionHandler(CPDFDoc_Environment* pEvi) : 
16         m_pFormActionHandler(NULL),
17         m_pMediaActionHandler(NULL)
18 {
19                 m_pFormActionHandler = new CPDFSDK_FormActionHandler;
20 }
21
22 CPDFSDK_ActionHandler::~CPDFSDK_ActionHandler()
23 {
24         if(m_pFormActionHandler)
25         {
26                 delete m_pFormActionHandler;
27                 m_pFormActionHandler = NULL;
28         }
29 }
30
31 void CPDFSDK_ActionHandler::SetFormActionHandler(CPDFSDK_FormActionHandler* pHandler)
32 {
33         ASSERT(pHandler != NULL);
34         ASSERT(m_pFormActionHandler == NULL);
35         m_pFormActionHandler = pHandler;
36 }
37
38 void CPDFSDK_ActionHandler::SetMediaActionHandler(CPDFSDK_MediaActionHandler* pHandler)
39 {
40         ASSERT(pHandler != NULL);
41         ASSERT(m_pMediaActionHandler == NULL);
42         m_pMediaActionHandler = pHandler;
43 }
44
45 void CPDFSDK_ActionHandler::Destroy()
46 {
47         delete this;
48 }
49
50 //document open
51 FX_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
59 FX_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
75 FX_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
93 FX_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
100 FX_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
107 FX_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
114 FX_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
121 FX_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
128 FX_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
136 FX_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
175 FX_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
231 FX_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
270 FX_BOOL CPDFSDK_ActionHandler::IsValidField(CPDFSDK_Document* pDocument, CPDF_Dictionary* pFieldDict)
271 {
272   ASSERT(pDocument != NULL);
273   ASSERT(pFieldDict != NULL);
274
275   CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm();
276   ASSERT(pInterForm != NULL);
277
278   CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
279   ASSERT(pPDFInterForm != NULL);
280
281   return pPDFInterForm->GetFieldByDict(pFieldDict) != NULL;
282 }
283
284 FX_BOOL CPDFSDK_ActionHandler::ExecuteFieldAction(const CPDF_Action& action, CPDF_AAction::AActionType type, 
285                                                                                   CPDFSDK_Document* pDocument,/* CReader_DocView* pDocView,*/ CPDF_FormField* pFormField, 
286                                                                                   PDFSDK_FieldAction& data, CFX_PtrList& list)
287 {
288         ASSERT(pDocument != NULL);
289
290         if (list.Find((CPDF_Dictionary*)action))
291                 return FALSE;
292         list.AddTail((CPDF_Dictionary*)action);
293
294         CPDFDoc_Environment* pEnv = pDocument->GetEnv();
295         ASSERT(pEnv);
296         if (action.GetType() == CPDF_Action::JavaScript)
297         {
298                 if(pEnv->IsJSInitiated())
299                 {
300                         CFX_WideString swJS = action.GetJavaScript();
301                         if (!swJS.IsEmpty())
302                         {
303                                 RunFieldJavaScript(pDocument, pFormField, type, data, swJS);
304                                 if (!IsValidField(pDocument, pFormField->GetFieldDict()))
305                                         return FALSE;
306                         }
307                 }
308         }
309         else
310         {
311                 DoAction_NoJs(action, pDocument/*, pDocView*/);
312 //              if (!IsValidDocView(pDocument, pDocView))
313 //                      return FALSE;
314         }
315
316         for (FX_INT32 i=0,sz=action.GetSubActionsCount(); i<sz; i++)
317         {
318                 CPDF_Action subaction = action.GetSubAction(i);
319                 if (!ExecuteFieldAction(subaction, type, pDocument,/* pDocView,*/ pFormField, data, list)) return FALSE;
320         }
321
322         return TRUE;
323 }
324
325 FX_BOOL CPDFSDK_ActionHandler::ExecuteScreenAction(const CPDF_Action& action, CPDF_AAction::AActionType type, 
326                                                                                 CPDFSDK_Document* pDocument,/* CReader_DocView* pDocView,*/ CPDFSDK_Annot* pScreen, CFX_PtrList& list)
327 {
328         ASSERT(pDocument != NULL);
329
330         if (list.Find((CPDF_Dictionary*)action))
331                 return FALSE;
332         list.AddTail((CPDF_Dictionary*)action);
333
334         CPDFDoc_Environment* pEnv = pDocument->GetEnv();
335         ASSERT(pEnv);
336         if (action.GetType() == CPDF_Action::JavaScript)
337         {
338                 if(pEnv->IsJSInitiated())
339                 {
340                         CFX_WideString swJS = action.GetJavaScript();
341                         if (!swJS.IsEmpty())
342                         {
343                                 IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
344                                 ASSERT(pRuntime != NULL);
345
346                                 pRuntime->SetReaderDocument(pDocument);
347
348                                 IFXJS_Context* pContext = pRuntime->NewContext();
349                                 ASSERT(pContext != NULL);
350
351         //                      switch (type)
352         //                      {
353         //                      case CPDF_AAction::CursorEnter:
354         //                              pContext->OnScreen_MouseEnter(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
355         //                              break;
356         //                      case CPDF_AAction::CursorExit:
357         //                              pContext->OnScreen_MouseExit(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
358         //                              break;
359         //                      case CPDF_AAction::ButtonDown:
360         //                              pContext->OnScreen_MouseDown(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
361         //                              break;
362         //                      case CPDF_AAction::ButtonUp:
363         //                              pContext->OnScreen_MouseUp(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
364         //                              break;
365         //                      case CPDF_AAction::GetFocus:
366         //                              pContext->OnScreen_Focus(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
367         //                              break;
368         //                      case CPDF_AAction::LoseFocus:
369         //                              pContext->OnScreen_Blur(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
370         //                              break;
371         //                      case CPDF_AAction::PageOpen:
372         //                              pContext->OnScreen_Open(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
373         //                              break;
374         //                      case CPDF_AAction::PageClose:
375         //                              pContext->OnScreen_Close(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
376         //                              break;
377         //                      case CPDF_AAction::PageVisible:
378         //                              pContext->OnScreen_InView(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
379         //                              break;
380         //                      case CPDF_AAction::PageInvisible:
381         //                              pContext->OnScreen_OutView(IsCTRLpressed(), IsSHIFTpressed(), pScreen);
382         //                              break;
383         //                      default:
384         //                              ASSERT(FALSE);
385         //                              break;
386         //                      }
387
388                                 CFX_WideString csInfo;
389                                 FX_BOOL bRet = pContext->RunScript(swJS, csInfo);
390                                 if (!bRet)
391                                 {
392                                         //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
393                                 }
394
395                                 pRuntime->ReleaseContext(pContext);
396                         }
397                 }
398         }
399         else
400         {
401                 DoAction_NoJs(action, pDocument/*, pDocView*/);
402         }
403
404 //      if (!IsValidDocView(pDocument, pDocView))
405 //              return FALSE;
406
407         for (FX_INT32 i=0,sz=action.GetSubActionsCount(); i<sz; i++)
408         {
409                 CPDF_Action subaction = action.GetSubAction(i);
410                 if (!ExecuteScreenAction(subaction, type, pDocument,/* pDocView,*/ pScreen, list)) return FALSE;
411         }
412
413         return TRUE;
414 }
415
416 FX_BOOL CPDFSDK_ActionHandler::ExecuteBookMark(const CPDF_Action& action, CPDFSDK_Document* pDocument, 
417                                                                                 /*CReader_DocView* pDocView,*/ CPDF_Bookmark* pBookmark, CFX_PtrList& list)
418 {
419         ASSERT(pDocument != NULL);
420
421         if (list.Find((CPDF_Dictionary*)action))
422                 return FALSE;
423         list.AddTail((CPDF_Dictionary*)action);
424
425         CPDFDoc_Environment* pEnv = pDocument->GetEnv();
426         ASSERT(pEnv);
427         if (action.GetType() == CPDF_Action::JavaScript)
428         {
429                 if(pEnv->IsJSInitiated())
430                 {
431                         CFX_WideString swJS = action.GetJavaScript();
432                         if (!swJS.IsEmpty())
433                         {
434                                 IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
435                                 ASSERT(pRuntime != NULL);
436
437                                 pRuntime->SetReaderDocument(pDocument);
438
439                                 IFXJS_Context* pContext = pRuntime->NewContext();
440                                 ASSERT(pContext != NULL);
441
442                                 pContext->OnBookmark_MouseUp(pBookmark);
443
444                                 CFX_WideString csInfo;
445                                 FX_BOOL bRet = pContext->RunScript(swJS, csInfo);
446                                 if (!bRet)
447                                 {
448                                         //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
449                                 }
450
451                                 pRuntime->ReleaseContext(pContext);
452                         }
453                 }
454         }
455         else
456         {
457                 DoAction_NoJs(action, pDocument/*, pDocView*/);
458         }
459
460 //      if (!IsValidDocView(pDocument, pDocView))
461 //              return FALSE;
462
463         for (FX_INT32 i=0,sz=action.GetSubActionsCount(); i<sz; i++)
464         {
465                 CPDF_Action subaction = action.GetSubAction(i);
466                 if (!ExecuteBookMark(subaction, pDocument,/* pDocView,*/ pBookmark, list)) return FALSE;
467         }
468
469         return TRUE;
470 }
471
472 void CPDFSDK_ActionHandler::DoAction_NoJs(const CPDF_Action& action, CPDFSDK_Document* pDocument/*, CReader_DocView* pDocView*/)
473 {
474         ASSERT(pDocument != NULL);
475
476         switch (action.GetType())
477         {
478         case CPDF_Action::GoTo:
479                 DoAction_GoTo(pDocument,/* pDocView,*/ action);
480                 break;
481         case CPDF_Action::GoToR:
482                 DoAction_GoToR(pDocument, action);
483                 break;
484         case CPDF_Action::GoToE:
485                 break;
486         case CPDF_Action::Launch:
487                 DoAction_Launch(pDocument, action);
488                 break;
489         case CPDF_Action::Thread:
490                 break;
491         case CPDF_Action::URI:
492                 DoAction_URI(pDocument, action);
493                 break;
494         case CPDF_Action::Sound:
495                 if (m_pMediaActionHandler)
496                 {
497                         m_pMediaActionHandler->DoAction_Sound(action, pDocument/*, pDocView*/);
498                 }
499                 break;
500         case CPDF_Action::Movie:
501                 if (m_pMediaActionHandler)
502                 {
503                         m_pMediaActionHandler->DoAction_Movie(action, pDocument/*, pDocView*/);
504                 }
505                 break;
506         case CPDF_Action::Hide:
507                 if (m_pFormActionHandler)
508                 {
509                         m_pFormActionHandler->DoAction_Hide(action, pDocument);
510                 }
511                 break;
512         case CPDF_Action::Named:
513                 DoAction_Named(pDocument, action);
514                 break;
515         case CPDF_Action::SubmitForm:
516                 if (m_pFormActionHandler)
517                 {
518                         m_pFormActionHandler->DoAction_SubmitForm(action, pDocument/*, pDocView*/);
519                 }
520                 break;
521         case CPDF_Action::ResetForm:
522                 if (m_pFormActionHandler)
523                 {
524                         m_pFormActionHandler->DoAction_ResetForm(action, pDocument);
525                 }
526                 break;
527         case CPDF_Action::ImportData:
528                 if (m_pFormActionHandler)
529                 {
530                         m_pFormActionHandler->DoAction_ImportData(action, pDocument/*, pDocView*/);
531                 }
532                 break;
533         case CPDF_Action::JavaScript:
534                 ASSERT(FALSE);
535                 break;
536         case CPDF_Action::SetOCGState:
537                 DoAction_SetOCGState(pDocument, /*pDocView,*/ action);
538                 break;
539         case CPDF_Action::Rendition:
540                 if (m_pMediaActionHandler)
541                 {
542                         m_pMediaActionHandler->DoAction_Rendition(action, pDocument/*, pDocView*/);
543                 }
544                 break;
545         case CPDF_Action::Trans:
546                 break;
547         case CPDF_Action::GoTo3DView:
548                 break;
549         default:
550                 break;
551         }
552 }
553
554 FX_BOOL CPDFSDK_ActionHandler::IsValidDocView(CPDFSDK_Document* pDocument/*, CReader_DocView* pDocView*/)
555 {
556         ASSERT(pDocument != NULL);
557         //ASSERT(pDocView != NULL);
558
559         //return pDocument->IsValidDocView(pDocView);
560         return TRUE;
561 }
562
563 void CPDFSDK_ActionHandler::DoAction_GoTo(CPDFSDK_Document* pDocument, /*CReader_DocView* pDocView,*/
564                                                                   const CPDF_Action& action)
565 {
566         ASSERT(pDocument != NULL);
567 //      ASSERT(pDocView != NULL);
568         ASSERT(action != NULL);
569
570         CPDF_Document* pPDFDocument = pDocument->GetDocument()->GetPDFDoc();
571         ASSERT(pPDFDocument != NULL);
572         CPDFDoc_Environment* pApp = pDocument->GetEnv();
573         ASSERT(pApp != NULL);
574
575         CPDF_Dest MyDest = action.GetDest(pPDFDocument);
576         int nPageIndex = MyDest.GetPageIndex(pPDFDocument);
577         int nFitType = MyDest.GetZoomMode();
578         const CPDF_Array * pMyArray = (CPDF_Array*)MyDest.m_pObj;
579         float* pPosAry = NULL;
580         int sizeOfAry = 0;
581         if (pMyArray != NULL)
582         {
583                 pPosAry = new float[pMyArray->GetCount()];
584                 int j = 0;
585                 for (int i = 2; i < (int)pMyArray->GetCount(); i++)
586                 {
587                         pPosAry[j++] = pMyArray->GetFloat(i);
588                 }
589                 sizeOfAry = j;
590         }
591         pApp->FFI_DoGoToAction(nPageIndex, nFitType, pPosAry, sizeOfAry);
592         if(pPosAry)
593                 delete[] pPosAry;
594 }
595
596 void CPDFSDK_ActionHandler::DoAction_GoToR(CPDFSDK_Document* pDocument, const CPDF_Action& action)
597 {
598
599 }
600
601 void CPDFSDK_ActionHandler::DoAction_Launch(CPDFSDK_Document* pDocument, const CPDF_Action& action)
602 {
603
604 }
605
606 void CPDFSDK_ActionHandler::DoAction_URI(CPDFSDK_Document* pDocument, const CPDF_Action& action)
607 {
608         ASSERT(pDocument != NULL);
609         ASSERT(action != NULL);
610
611         CPDFDoc_Environment* pApp = pDocument->GetEnv();
612         ASSERT(pApp != NULL);
613  
614         CFX_ByteString sURI = action.GetURI(pDocument->GetDocument()->GetPDFDoc());
615         pApp->FFI_DoURIAction(FX_LPCSTR(sURI));
616 }
617
618 void CPDFSDK_ActionHandler::DoAction_Named(CPDFSDK_Document* pDocument, const CPDF_Action& action)
619 {
620         ASSERT(pDocument != NULL);
621         ASSERT(action != NULL);
622  
623         CFX_ByteString csName = action.GetNamedAction();
624         pDocument->GetEnv()->FFI_ExecuteNamedAction(csName);
625 }
626
627
628 void CPDFSDK_ActionHandler::DoAction_SetOCGState(CPDFSDK_Document* pDocument,/* CReader_DocView* pDocView,*/ const CPDF_Action& action)
629 {
630 }
631
632 void CPDFSDK_ActionHandler::RunFieldJavaScript(CPDFSDK_Document* pDocument, CPDF_FormField* pFormField, CPDF_AAction::AActionType type,
633                                                                                 PDFSDK_FieldAction& data, const CFX_WideString& script)
634 {
635         ASSERT(type != CPDF_AAction::Calculate);
636         ASSERT(type != CPDF_AAction::Format);
637
638         ASSERT(pDocument != NULL);
639
640         IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
641         ASSERT(pRuntime != NULL);
642
643         pRuntime->SetReaderDocument(pDocument);
644
645         IFXJS_Context* pContext = pRuntime->NewContext();
646         ASSERT(pContext != NULL);
647
648         switch (type)
649         {
650         case CPDF_AAction::CursorEnter:
651                 pContext->OnField_MouseEnter(data.bModifier, data.bShift, pFormField);
652                 break;
653         case CPDF_AAction::CursorExit:
654                 pContext->OnField_MouseExit(data.bModifier, data.bShift, pFormField);
655                 break;
656         case CPDF_AAction::ButtonDown:
657                 pContext->OnField_MouseDown(data.bModifier, data.bShift, pFormField);
658                 break;
659         case CPDF_AAction::ButtonUp:
660                 pContext->OnField_MouseUp(data.bModifier, data.bShift, pFormField);
661                 break;
662         case CPDF_AAction::GetFocus:
663                 pContext->OnField_Focus(data.bModifier, data.bShift, pFormField, data.sValue);
664                 break;
665         case CPDF_AAction::LoseFocus:
666                 pContext->OnField_Blur(data.bModifier, data.bShift, pFormField, data.sValue);
667                 break;
668         case CPDF_AAction::KeyStroke:
669                 pContext->OnField_Keystroke(data.nCommitKey, data.sChange, data.sChangeEx, data.bKeyDown, 
670                         data.bModifier, data.nSelEnd, data.nSelStart, data.bShift, pFormField, data.sValue,
671                         data.bWillCommit, data.bFieldFull, data.bRC);
672                 break;
673         case CPDF_AAction::Validate:
674                 pContext->OnField_Validate(data.sChange, data.sChangeEx, data.bKeyDown, data.bModifier,
675                         data.bShift, pFormField, data.sValue, data.bRC);
676                 break;
677         default:
678                 ASSERT(FALSE);
679                 break;
680         }
681
682         CFX_WideString csInfo;
683         FX_BOOL bRet = pContext->RunScript(script, csInfo);
684         if (!bRet)
685         {
686                 //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
687         }
688
689         pRuntime->ReleaseContext(pContext);
690 }
691
692 void CPDFSDK_ActionHandler::RunDocumentOpenJavaScript(CPDFSDK_Document* pDocument, const CFX_WideString& sScriptName, const CFX_WideString& script)
693 {
694         ASSERT(pDocument != NULL);
695
696         IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
697         ASSERT(pRuntime != NULL);
698
699         pRuntime->SetReaderDocument(pDocument);
700
701         IFXJS_Context* pContext = pRuntime->NewContext();
702         ASSERT(pContext != NULL);
703
704         pContext->OnDoc_Open(pDocument, sScriptName);
705
706         CFX_WideString csInfo;
707         FX_BOOL bRet = pContext->RunScript(script, csInfo);
708         if (!bRet)
709         {
710                 //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
711         }
712
713         pRuntime->ReleaseContext(pContext);
714 }
715
716 void CPDFSDK_ActionHandler::RunDocumentPageJavaScript(CPDFSDK_Document* pDocument, CPDF_AAction::AActionType type, const CFX_WideString& script)
717 {
718         ASSERT(pDocument != NULL);
719
720         IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
721         ASSERT(pRuntime != NULL);
722
723         pRuntime->SetReaderDocument(pDocument);
724
725         IFXJS_Context* pContext = pRuntime->NewContext();
726         ASSERT(pContext != NULL);
727
728         switch (type)
729         {       
730         case CPDF_AAction::OpenPage:
731                 pContext->OnPage_Open(pDocument);
732                 break;
733         case CPDF_AAction::ClosePage:
734                 pContext->OnPage_Close(pDocument);
735                 break;
736         case CPDF_AAction::CloseDocument:
737                 pContext->OnDoc_WillClose(pDocument);
738                 break;
739         case CPDF_AAction::SaveDocument:
740                 pContext->OnDoc_WillSave(pDocument);
741                 break;
742         case CPDF_AAction::DocumentSaved:
743                 pContext->OnDoc_DidSave(pDocument);
744                 break;
745         case CPDF_AAction::PrintDocument:
746                 pContext->OnDoc_WillPrint(pDocument);
747                 break;
748         case CPDF_AAction::DocumentPrinted:
749                 pContext->OnDoc_DidPrint(pDocument);
750                 break;
751         case CPDF_AAction::PageVisible:
752                 pContext->OnPage_InView(pDocument);
753                 break;
754         case CPDF_AAction::PageInvisible:
755                 pContext->OnPage_OutView(pDocument);
756                 break;
757         default:
758                 ASSERT(FALSE);
759                 break;
760         }
761
762         CFX_WideString csInfo;
763         FX_BOOL bRet = pContext->RunScript(script, csInfo);
764         if (!bRet)
765         {
766                 //CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
767         }
768
769         pRuntime->ReleaseContext(pContext);
770 }
771
772
773 FX_BOOL CPDFSDK_FormActionHandler::DoAction_Hide(const CPDF_Action& action, CPDFSDK_Document* pDocument)
774 {
775         ASSERT(pDocument != NULL);
776         
777         CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
778         ASSERT(pInterForm != NULL);
779         
780         if (pInterForm->DoAction_Hide(action))
781         {
782                 pDocument->SetChangeMark();
783                 return TRUE;
784         }
785         
786         return FALSE;
787 }
788
789 FX_BOOL CPDFSDK_FormActionHandler::DoAction_SubmitForm(const CPDF_Action& action, CPDFSDK_Document* pDocument)
790 {
791         ASSERT(pDocument != NULL);
792         
793         CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
794         ASSERT(pInterForm != NULL);
795         
796         return pInterForm->DoAction_SubmitForm(action);
797 }
798
799 FX_BOOL CPDFSDK_FormActionHandler::DoAction_ResetForm(const CPDF_Action& action, CPDFSDK_Document* pDocument)
800 {
801         ASSERT(pDocument != NULL);
802         
803         CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
804         ASSERT(pInterForm != NULL);
805         
806         if (pInterForm->DoAction_ResetForm(action))
807         {       
808                 return TRUE;
809         }
810         
811         return FALSE;
812 }
813
814 FX_BOOL CPDFSDK_FormActionHandler::DoAction_ImportData(const CPDF_Action& action, CPDFSDK_Document* pDocument)
815 {
816         ASSERT(pDocument != NULL);
817         
818         CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
819         ASSERT(pInterForm != NULL);
820         
821         if (pInterForm->DoAction_ImportData(action))
822         {
823                 pDocument->SetChangeMark();     
824                 return TRUE;
825         }
826         
827         return FALSE;
828 }
829
830 FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Rendition(const CPDF_Action& action, CPDFSDK_Document* pDocument)
831 {
832         return FALSE;
833 }
834
835 FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Sound(const CPDF_Action& action, CPDFSDK_Document* pDocument)
836 {
837         return FALSE;
838 }
839
840 FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Movie(const CPDF_Action& action, CPDFSDK_Document* pDocument)
841 {
842         return FALSE;
843 }
844