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