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