Replace CFX_MapPtrTemplate with std::map.
[pdfium.git] / fpdfsdk / src / fpdfformfill.cpp
index 101146b..9358c9e 100644 (file)
-// Copyright 2014 PDFium Authors. All rights reserved.\r
-// Use of this source code is governed by a BSD-style license that can be\r
-// found in the LICENSE file.\r
\r
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
-\r
-#include "../include/fpdfview.h"\r
-#include "../include/fpdfformfill.h"\r
-#include "../include/fsdk_define.h"\r
-#include "../include/fsdk_mgr.h"\r
-\r
-\r
-#include "../include/javascript/IJavaScript.h"\r
-\r
-\r
-DLLEXPORT int STDCALL FPDPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, FPDF_PAGE page,double page_x, double page_y)\r
-{\r
-       if(!page || !hHandle)\r
-               return -1;\r
-       CPDF_Page * pPage = (CPDF_Page*) page;\r
-\r
-       CPDF_InterForm * pInterForm = NULL;\r
-       pInterForm = new CPDF_InterForm(pPage->m_pDocument,FALSE);\r
-       if (!pInterForm)\r
-               return -1;\r
-       CPDF_FormControl* pFormCtrl = pInterForm->GetControlAtPoint(pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y);\r
-       if(!pFormCtrl)\r
-       {\r
-               delete pInterForm;\r
-               return -1;\r
-       }\r
-       CPDF_FormField* pFormField = pFormCtrl->GetField();\r
-       if(!pFormField)\r
-       {\r
-               delete pInterForm;\r
-               return -1;\r
-       }\r
-       \r
-       int nType = pFormField->GetFieldType();\r
-       delete pInterForm;\r
-       return nType;\r
-}\r
-\r
-DLLEXPORT FPDF_FORMHANDLE STDCALL FPDFDOC_InitFormFillEnviroument(FPDF_DOCUMENT document, FPDF_FORMFILLINFO* formInfo)\r
-{\r
-       if(!document || !formInfo || formInfo->version!=1)\r
-               return NULL;\r
-       CPDF_Document * pDocument = (CPDF_Document*) document;\r
-       CPDFDoc_Environment * pEnv = NULL;\r
-       pEnv = new CPDFDoc_Environment(pDocument);\r
-       if (!pEnv)\r
-               return NULL;\r
-       pEnv->RegAppHandle(formInfo);\r
-\r
-       if(pEnv->GetPDFDocument())\r
-       {\r
-               CPDFSDK_Document* pSDKDoc = new CPDFSDK_Document(pEnv->GetPDFDocument(), pEnv);\r
-               if(pSDKDoc)\r
-                       pEnv->SetCurrentDoc(pSDKDoc);\r
-       }\r
-       return pEnv;\r
-}\r
-\r
-DLLEXPORT void STDCALL FPDFDOC_ExitFormFillEnviroument(FPDF_FORMHANDLE hHandle)\r
-{\r
-       if(!hHandle)\r
-               return; \r
-       CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();\r
-       if(pSDKDoc)\r
-       {\r
-               ((CPDFDoc_Environment*)hHandle)->SetCurrentDoc(NULL);\r
-               delete pSDKDoc;\r
-       }\r
-       delete (CPDFDoc_Environment*)hHandle;\r
-       hHandle = NULL;\r
-}\r
-\r
-DLLEXPORT FPDF_BOOL STDCALL FORM_OnMouseMove(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int modifier, double page_x, double page_y)\r
-{      \r
-       if (!hHandle || !page)\r
-               return FALSE;\r
-//     CPDF_Page * pPage = (CPDF_Page*) page;\r
-//     CPDF_Document * pDoc = pPage->m_pDocument;\r
-//     CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle;\r
-       CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();\r
-       if(!pFXDoc)\r
-               return FALSE;\r
-       CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDF_Page*)page);\r
-       if(!pPageView)\r
-               return FALSE;\r
-       \r
-//     double page_x = 0;\r
-//     double page_y = 0;\r
-//     pEnv->FFI_DeviceToPage(page, point_x, point_y, &page_x, &page_y);\r
-       CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);\r
-       return pPageView->OnMouseMove(pt, modifier);\r
-}\r
-\r
-DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonDown(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int modifier, double page_x, double page_y)\r
-{\r
-       if (!hHandle || !page)\r
-               return FALSE;\r
-       CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();\r
-       if(!pFXDoc)\r
-               return FALSE;\r
-       CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDF_Page*)page);\r
-       if(!pPageView)\r
-               return FALSE;\r
-//     double page_x = 0;\r
-//     double page_y = 0;\r
-//     pEnv->FFI_DeviceToPage(page, point_x, point_y, &page_x, &page_y);\r
-       CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);\r
-       return pPageView->OnLButtonDown(pt, modifier);\r
-}\r
-\r
-DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonUp(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int modifier, double page_x, double page_y)\r
-{\r
-       if (!hHandle || !page)\r
-               return FALSE;\r
-       CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();\r
-       if(!pFXDoc)\r
-               return FALSE;\r
-       CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDF_Page*)page);\r
-       if(!pPageView)\r
-               return FALSE;\r
-//     double page_x = 0;\r
-//     double page_y = 0;\r
-//     pEnv->FFI_DeviceToPage(page, point_x, point_y, &page_x, &page_y);\r
-       CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);\r
-       return pPageView->OnLButtonUp(pt, modifier);\r
-}\r
-\r
-DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyDown(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int nKeyCode, int modifier)\r
-{\r
-       if (!hHandle || !page)\r
-               return FALSE;\r
-       CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();\r
-       if(!pFXDoc)\r
-               return FALSE;\r
-       CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDF_Page*)page);\r
-       if(!pPageView)\r
-               return FALSE;\r
-       \r
-       \r
-       return pPageView->OnKeyDown(nKeyCode, modifier);\r
-}\r
-\r
-DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyUp(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int nKeyCode, int modifier)\r
-{\r
-       if (!hHandle || !page)\r
-               return FALSE;\r
-       CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();\r
-       if(!pFXDoc)\r
-               return FALSE;\r
-       CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDF_Page*)page);\r
-       if(!pPageView)\r
-               return FALSE;\r
-       \r
-       \r
-       return pPageView->OnKeyUp(nKeyCode, modifier);\r
-}\r
-\r
-\r
-DLLEXPORT FPDF_BOOL STDCALL FORM_OnChar(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int nChar,  int modifier)\r
-{\r
-       if (!hHandle || !page)\r
-               return FALSE;\r
-       CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();\r
-       if(!pFXDoc)\r
-               return FALSE;\r
-       CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDF_Page*)page);\r
-       if(!pPageView)\r
-               return FALSE;\r
-       return pPageView->OnChar(nChar, modifier);\r
-\r
-}\r
-\r
-DLLEXPORT FPDF_BOOL STDCALL FORM_ForceToKillFocus(FPDF_FORMHANDLE hHandle)\r
-{\r
-       if(!hHandle)\r
-               return FALSE;\r
-       CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();\r
-       if(!pSDKDoc)\r
-               return FALSE;\r
-       //Kill the current focus. \r
-       return pSDKDoc->KillFocusAnnot(0);\r
-}\r
-\r
-DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, FPDF_BITMAP bitmap, FPDF_PAGE page, int start_x, int start_y, \r
-                                                                                                 int size_x, int size_y, int rotate, int flags)\r
-{\r
-       if (!hHandle || !page)\r
-               return ;\r
-       CPDF_Page* pPage = (CPDF_Page*)page;\r
-       \r
-       CPDF_RenderOptions options;\r
-       if (flags & FPDF_LCD_TEXT)\r
-               options.m_Flags |= RENDER_CLEARTYPE;\r
-       else\r
-               options.m_Flags &= ~RENDER_CLEARTYPE;\r
-       \r
-       //Grayscale output\r
-       if (flags & FPDF_GRAYSCALE)\r
-       {\r
-               options.m_ColorMode = RENDER_COLOR_GRAY;\r
-               options.m_ForeColor = 0;\r
-               options.m_BackColor = 0xffffff;\r
-       }\r
-       \r
-       options.m_AddFlags = flags >> 8;\r
-\r
-       options.m_pOCContext = FX_NEW CPDF_OCContext(pPage->m_pDocument);\r
-\r
-       //FXMT_CSLOCK_OBJ(&pPage->m_PageLock);\r
-       \r
-       CFX_AffineMatrix matrix;\r
-       pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate); \r
-       \r
-       FX_RECT clip;\r
-       clip.left = start_x;\r
-       clip.right = start_x + size_x;\r
-       clip.top = start_y;\r
-       clip.bottom = start_y + size_y;\r
-\r
-#ifdef _SKIA_SUPPORT_\r
-       CFX_SkiaDevice* pDevice = FX_NEW CFX_SkiaDevice;\r
-#else\r
-       CFX_FxgeDevice* pDevice = NULL;\r
-       pDevice = FX_NEW CFX_FxgeDevice;\r
-#endif\r
-\r
-       if (!pDevice)\r
-               return;\r
-       pDevice->Attach((CFX_DIBitmap*)bitmap);\r
-       pDevice->SaveState();\r
-       pDevice->SetClip_Rect(&clip);\r
-       \r
-\r
-       CPDF_RenderContext* pContext = NULL;\r
-       pContext = FX_NEW CPDF_RenderContext;\r
-       if (!pContext)\r
-       {\r
-               delete pDevice;\r
-               pDevice = NULL;\r
-               return;\r
-       }\r
-\r
-\r
-//     CPDF_Document* pDoc = pPage->m_pDocument;\r
-       CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle;\r
-       CPDFSDK_Document* pFXDoc = pEnv->GetCurrentDoc();\r
-       if(!pFXDoc)\r
-       {\r
-               delete pContext;\r
-               delete pDevice;\r
-               pContext = NULL;\r
-               pDevice = NULL;\r
-               return;\r
-       }\r
-       if(CPDFSDK_PageView* pPageView = pFXDoc->GetPageView(pPage))\r
-       {\r
-               pPageView->PageView_OnDraw(pDevice, &matrix, &options);\r
-       }\r
-       pDevice->RestoreState();\r
-\r
-       if(options.m_pOCContext)\r
-       {\r
-               delete options.m_pOCContext;\r
-               options.m_pOCContext = NULL;\r
-       }\r
-       if(pContext)\r
-       {\r
-               delete pContext;\r
-               pContext = NULL;\r
-       }\r
-       if(pDevice)\r
-       {\r
-               delete pDevice;\r
-               pDevice = NULL;\r
-       }\r
-\r
-}\r
-\r
-DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightColor(FPDF_FORMHANDLE hHandle, int fieldType, unsigned long color)\r
-{\r
-       if (!hHandle)\r
-               return;\r
-//     CPDFDoc_Environment* pEnv = (CPDFDoc_Environment* )hHandle;\r
-       CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();\r
-       if(pSDKDoc)\r
-       {\r
-               if(CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm())\r
-               {\r
-                       pInterForm->SetHighlightColor(color, fieldType);\r
-               }\r
-       \r
-       }\r
-\r
-}\r
-\r
-DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightAlpha(FPDF_FORMHANDLE hHandle, unsigned char alpha)\r
-{\r
-       if (!hHandle)\r
-               return;\r
-       CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();\r
-       if(pSDKDoc)\r
-       {\r
-               if(CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm())\r
-                       pInterForm->SetHighlightAlpha(alpha);\r
-       }\r
-}\r
-\r
-DLLEXPORT void STDCALL FPDF_RemoveFormFieldHighlight(FPDF_FORMHANDLE hHandle)\r
-{\r
-       if (!hHandle)\r
-               return;\r
-       CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();\r
-       if(pSDKDoc)\r
-       {\r
-               if(CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm())\r
-                       pInterForm->RemoveAllHighLight();\r
-       }\r
-}\r
-\r
-DLLEXPORT void STDCALL FORM_OnAfterLoadPage(FPDF_PAGE page, FPDF_FORMHANDLE hHandle)\r
-{\r
-       if(!hHandle || !page)\r
-               return;\r
-       CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();\r
-       if(!pSDKDoc)\r
-               return;\r
-       CPDF_Page* pPage = (CPDF_Page*)page;\r
-       CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, TRUE);\r
-       if(pPageView)\r
-       {\r
-               pPageView->SetValid(TRUE);\r
-       }       \r
-}\r
-\r
-DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page, FPDF_FORMHANDLE hHandle)\r
-{\r
-       if(!hHandle || !page)\r
-               return;\r
-       CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();\r
-       CPDF_Page* pPage = (CPDF_Page*)page;\r
-       CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, FALSE);\r
-       if(pPageView)\r
-       {\r
-               pPageView->SetValid(FALSE);\r
-               // ReMovePageView() takes care of the delete for us.\r
-               pSDKDoc->ReMovePageView(pPage);\r
-       }\r
-}\r
-DLLEXPORT void STDCALL FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle)\r
-{\r
-       if(!hHandle)\r
-               return;\r
-       if( CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc())\r
-       {\r
-               pSDKDoc->InitPageView();\r
-               if(((CPDFDoc_Environment*)hHandle)->IsJSInitiated())\r
-                       pSDKDoc->ProcJavascriptFun();\r
-       }       \r
-}\r
-\r
-DLLEXPORT void STDCALL FORM_DoDocumentOpenAction(FPDF_FORMHANDLE hHandle)\r
-{\r
-       if(!hHandle)\r
-               return;\r
-       if( CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc())\r
-       {\r
-               if(((CPDFDoc_Environment*)hHandle)->IsJSInitiated())\r
-                       pSDKDoc->ProcOpenAction();\r
-       }\r
-}\r
-DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, int aaType)\r
-{\r
-       if(!hHandle)\r
-               return;\r
-       CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();\r
-       if(pSDKDoc)\r
-       {\r
-               CPDF_Document* pDoc = pSDKDoc->GetDocument();\r
-               CPDF_Dictionary* pDic = pDoc->GetRoot();\r
-               if (!pDic)\r
-                       return;\r
-               CPDF_AAction aa = pDic->GetDict(FX_BSTRC("AA"));\r
-               \r
-               if(aa.ActionExist((CPDF_AAction::AActionType)aaType))\r
-               {\r
-                       CPDF_Action action = aa.GetAction((CPDF_AAction::AActionType)aaType);\r
-                       CPDFSDK_ActionHandler *pActionHandler = ((CPDFDoc_Environment*)hHandle)->GetActionHander();\r
-                       ASSERT(pActionHandler != NULL);\r
-                       pActionHandler->DoAction_Document(action, (CPDF_AAction::AActionType)aaType, pSDKDoc);\r
-               }\r
-       }\r
-}\r
-DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page, FPDF_FORMHANDLE hHandle, int aaType)\r
-{\r
-       if(!hHandle || !page)\r
-               return;\r
-       CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();\r
-       CPDF_Page* pPage = (CPDF_Page*)page;\r
-       CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, FALSE);\r
-       if(pPageView)\r
-       {\r
-               CPDFDoc_Environment *pEnv = pSDKDoc->GetEnv();\r
-               ASSERT(pEnv != NULL);\r
-                       \r
-               CPDFSDK_ActionHandler *pActionHandler = pEnv->GetActionHander();\r
-               ASSERT(pActionHandler != NULL);\r
-               \r
-               CPDF_Dictionary *pPageDict = pPage->m_pFormDict;\r
-               ASSERT(pPageDict != NULL);\r
-                \r
-               CPDF_AAction aa = pPageDict->GetDict(FX_BSTRC("AA"));\r
-\r
-               FX_BOOL bExistOAAction = FALSE;\r
-               FX_BOOL bExistCAAction = FALSE;\r
-               if (FPDFPAGE_AACTION_OPEN == aaType)\r
-               {\r
-                       bExistOAAction = aa.ActionExist(CPDF_AAction::OpenPage);\r
-                       if (bExistOAAction)\r
-                       {\r
-                               CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage);\r
-                               pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, pSDKDoc);\r
-                       }\r
-               }\r
-               else\r
-               {\r
-                       bExistCAAction = aa.ActionExist(CPDF_AAction::ClosePage);\r
-                       if (bExistCAAction)\r
-                       {\r
-                               CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage);\r
-                               pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, pSDKDoc);\r
-                       }\r
-               }\r
-       }\r
-}\r
-\r
-\r
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../public/fpdf_formfill.h"
+#include "../../public/fpdfview.h"
+#include "../include/fsdk_define.h"
+#include "../include/fsdk_mgr.h"
+
+
+#include "../include/javascript/IJavaScript.h"
+
+
+DLLEXPORT int STDCALL FPDPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, FPDF_PAGE page,double page_x, double page_y)
+{
+       if(!page || !hHandle)
+               return -1;
+       CPDF_Page * pPage = (CPDF_Page*) page;
+
+       CPDF_InterForm * pInterForm = NULL;
+       pInterForm = new CPDF_InterForm(pPage->m_pDocument,FALSE);
+       if (!pInterForm)
+               return -1;
+       CPDF_FormControl* pFormCtrl = pInterForm->GetControlAtPoint(pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y);
+       if(!pFormCtrl)
+       {
+               delete pInterForm;
+               return -1;
+       }
+       CPDF_FormField* pFormField = pFormCtrl->GetField();
+       if(!pFormField)
+       {
+               delete pInterForm;
+               return -1;
+       }
+
+       int nType = pFormField->GetFieldType();
+       delete pInterForm;
+       return nType;
+}
+
+DLLEXPORT FPDF_FORMHANDLE STDCALL FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document, FPDF_FORMFILLINFO* formInfo)
+{
+       if(!document || !formInfo || formInfo->version!=1)
+               return NULL;
+       CPDF_Document * pDocument = (CPDF_Document*) document;
+       CPDFDoc_Environment * pEnv = NULL;
+       pEnv = new CPDFDoc_Environment(pDocument);
+       if (!pEnv)
+               return NULL;
+       pEnv->RegAppHandle(formInfo);
+
+       if(pEnv->GetPDFDocument())
+       {
+               CPDFSDK_Document* pSDKDoc = new CPDFSDK_Document(pEnv->GetPDFDocument(), pEnv);
+               if(pSDKDoc)
+                       pEnv->SetCurrentDoc(pSDKDoc);
+       }
+       return pEnv;
+}
+
+DLLEXPORT void STDCALL FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle)
+{
+       if(!hHandle)
+               return;
+       CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+       if(pSDKDoc)
+       {
+               ((CPDFDoc_Environment*)hHandle)->SetCurrentDoc(NULL);
+               delete pSDKDoc;
+       }
+       delete (CPDFDoc_Environment*)hHandle;
+       hHandle = NULL;
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FORM_OnMouseMove(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int modifier, double page_x, double page_y)
+{
+       if (!hHandle || !page)
+               return FALSE;
+//     CPDF_Page * pPage = (CPDF_Page*) page;
+//     CPDF_Document * pDoc = pPage->m_pDocument;
+//     CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle;
+       CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+       if(!pFXDoc)
+               return FALSE;
+       CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDF_Page*)page);
+       if(!pPageView)
+               return FALSE;
+
+//     double page_x = 0;
+//     double page_y = 0;
+//     pEnv->FFI_DeviceToPage(page, point_x, point_y, &page_x, &page_y);
+       CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
+       return pPageView->OnMouseMove(pt, modifier);
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonDown(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int modifier, double page_x, double page_y)
+{
+       if (!hHandle || !page)
+               return FALSE;
+       CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+       if(!pFXDoc)
+               return FALSE;
+       CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDF_Page*)page);
+       if(!pPageView)
+               return FALSE;
+//     double page_x = 0;
+//     double page_y = 0;
+//     pEnv->FFI_DeviceToPage(page, point_x, point_y, &page_x, &page_y);
+       CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
+       return pPageView->OnLButtonDown(pt, modifier);
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonUp(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int modifier, double page_x, double page_y)
+{
+       if (!hHandle || !page)
+               return FALSE;
+       CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+       if(!pFXDoc)
+               return FALSE;
+       CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDF_Page*)page);
+       if(!pPageView)
+               return FALSE;
+//     double page_x = 0;
+//     double page_y = 0;
+//     pEnv->FFI_DeviceToPage(page, point_x, point_y, &page_x, &page_y);
+       CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
+       return pPageView->OnLButtonUp(pt, modifier);
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyDown(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int nKeyCode, int modifier)
+{
+       if (!hHandle || !page)
+               return FALSE;
+       CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+       if(!pFXDoc)
+               return FALSE;
+       CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDF_Page*)page);
+       if(!pPageView)
+               return FALSE;
+
+
+       return pPageView->OnKeyDown(nKeyCode, modifier);
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyUp(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int nKeyCode, int modifier)
+{
+       if (!hHandle || !page)
+               return FALSE;
+       CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+       if(!pFXDoc)
+               return FALSE;
+       CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDF_Page*)page);
+       if(!pPageView)
+               return FALSE;
+
+
+       return pPageView->OnKeyUp(nKeyCode, modifier);
+}
+
+
+DLLEXPORT FPDF_BOOL STDCALL FORM_OnChar(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int nChar,  int modifier)
+{
+       if (!hHandle || !page)
+               return FALSE;
+       CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+       if(!pFXDoc)
+               return FALSE;
+       CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDF_Page*)page);
+       if(!pPageView)
+               return FALSE;
+       return pPageView->OnChar(nChar, modifier);
+
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FORM_ForceToKillFocus(FPDF_FORMHANDLE hHandle)
+{
+       if(!hHandle)
+               return FALSE;
+       CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+       if(!pSDKDoc)
+               return FALSE;
+       //Kill the current focus.
+       return pSDKDoc->KillFocusAnnot(0);
+}
+
+DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, FPDF_BITMAP bitmap, FPDF_PAGE page, int start_x, int start_y,
+                                                                                                 int size_x, int size_y, int rotate, int flags)
+{
+       if (!hHandle || !page)
+               return ;
+       CPDF_Page* pPage = (CPDF_Page*)page;
+
+       CPDF_RenderOptions options;
+       if (flags & FPDF_LCD_TEXT)
+               options.m_Flags |= RENDER_CLEARTYPE;
+       else
+               options.m_Flags &= ~RENDER_CLEARTYPE;
+
+       //Grayscale output
+       if (flags & FPDF_GRAYSCALE)
+       {
+               options.m_ColorMode = RENDER_COLOR_GRAY;
+               options.m_ForeColor = 0;
+               options.m_BackColor = 0xffffff;
+       }
+
+       options.m_AddFlags = flags >> 8;
+       options.m_pOCContext = new CPDF_OCContext(pPage->m_pDocument);
+
+       CFX_AffineMatrix matrix;
+       pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate);
+
+       FX_RECT clip;
+       clip.left = start_x;
+       clip.right = start_x + size_x;
+       clip.top = start_y;
+       clip.bottom = start_y + size_y;
+
+#ifdef _SKIA_SUPPORT_
+       CFX_SkiaDevice* pDevice = new CFX_SkiaDevice;
+#else
+       CFX_FxgeDevice* pDevice = new CFX_FxgeDevice;
+#endif
+       pDevice->Attach((CFX_DIBitmap*)bitmap);
+       pDevice->SaveState();
+       pDevice->SetClip_Rect(&clip);
+
+       CPDF_RenderContext* pContext = new CPDF_RenderContext;
+       CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle;
+       CPDFSDK_Document* pFXDoc = pEnv->GetCurrentDoc();
+       if(!pFXDoc)
+       {
+               delete pContext;
+               delete pDevice;
+               pContext = NULL;
+               pDevice = NULL;
+               return;
+       }
+       if(CPDFSDK_PageView* pPageView = pFXDoc->GetPageView(pPage))
+       {
+               pPageView->PageView_OnDraw(pDevice, &matrix, &options);
+       }
+       pDevice->RestoreState();
+
+       if(options.m_pOCContext)
+       {
+               delete options.m_pOCContext;
+               options.m_pOCContext = NULL;
+       }
+       if(pContext)
+       {
+               delete pContext;
+               pContext = NULL;
+       }
+       if(pDevice)
+       {
+               delete pDevice;
+               pDevice = NULL;
+       }
+
+}
+
+DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightColor(FPDF_FORMHANDLE hHandle, int fieldType, unsigned long color)
+{
+       if (!hHandle)
+               return;
+//     CPDFDoc_Environment* pEnv = (CPDFDoc_Environment* )hHandle;
+       CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+       if(pSDKDoc)
+       {
+               if(CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm())
+               {
+                       pInterForm->SetHighlightColor(color, fieldType);
+               }
+
+       }
+
+}
+
+DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightAlpha(FPDF_FORMHANDLE hHandle, unsigned char alpha)
+{
+       if (!hHandle)
+               return;
+       CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+       if(pSDKDoc)
+       {
+               if(CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm())
+                       pInterForm->SetHighlightAlpha(alpha);
+       }
+}
+
+DLLEXPORT void STDCALL FPDF_RemoveFormFieldHighlight(FPDF_FORMHANDLE hHandle)
+{
+       if (!hHandle)
+               return;
+       CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+       if(pSDKDoc)
+       {
+               if(CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm())
+                       pInterForm->RemoveAllHighLight();
+       }
+}
+
+DLLEXPORT void STDCALL FORM_OnAfterLoadPage(FPDF_PAGE page, FPDF_FORMHANDLE hHandle)
+{
+       if(!hHandle || !page)
+               return;
+       CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+       if(!pSDKDoc)
+               return;
+       CPDF_Page* pPage = (CPDF_Page*)page;
+       CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, TRUE);
+       if(pPageView)
+       {
+               pPageView->SetValid(TRUE);
+       }
+}
+
+DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page, FPDF_FORMHANDLE hHandle)
+{
+       if(!hHandle || !page)
+               return;
+       CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+       CPDF_Page* pPage = (CPDF_Page*)page;
+       CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, FALSE);
+       if(pPageView)
+       {
+               pPageView->SetValid(FALSE);
+               // ReMovePageView() takes care of the delete for us.
+               pSDKDoc->ReMovePageView(pPage);
+       }
+}
+DLLEXPORT void STDCALL FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle)
+{
+       if(!hHandle)
+               return;
+       if( CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc())
+       {
+               if(((CPDFDoc_Environment*)hHandle)->IsJSInitiated())
+                       pSDKDoc->ProcJavascriptFun();
+       }
+}
+
+DLLEXPORT void STDCALL FORM_DoDocumentOpenAction(FPDF_FORMHANDLE hHandle)
+{
+       if(!hHandle)
+               return;
+       if( CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc())
+       {
+               if(((CPDFDoc_Environment*)hHandle)->IsJSInitiated())
+                       pSDKDoc->ProcOpenAction();
+       }
+}
+DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, int aaType)
+{
+       if(!hHandle)
+               return;
+       CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+       if(pSDKDoc)
+       {
+               CPDF_Document* pDoc = pSDKDoc->GetDocument();
+               CPDF_Dictionary* pDic = pDoc->GetRoot();
+               if (!pDic)
+                       return;
+               CPDF_AAction aa = pDic->GetDict(FX_BSTRC("AA"));
+
+               if(aa.ActionExist((CPDF_AAction::AActionType)aaType))
+               {
+                       CPDF_Action action = aa.GetAction((CPDF_AAction::AActionType)aaType);
+                       CPDFSDK_ActionHandler *pActionHandler = ((CPDFDoc_Environment*)hHandle)->GetActionHander();
+                       ASSERT(pActionHandler != NULL);
+                       pActionHandler->DoAction_Document(action, (CPDF_AAction::AActionType)aaType, pSDKDoc);
+               }
+       }
+}
+DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page, FPDF_FORMHANDLE hHandle, int aaType)
+{
+       if(!hHandle || !page)
+               return;
+       CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+       CPDF_Page* pPage = (CPDF_Page*)page;
+       CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, FALSE);
+       if(pPageView)
+       {
+               CPDFDoc_Environment *pEnv = pSDKDoc->GetEnv();
+               ASSERT(pEnv != NULL);
+
+               CPDFSDK_ActionHandler *pActionHandler = pEnv->GetActionHander();
+               ASSERT(pActionHandler != NULL);
+
+               CPDF_Dictionary *pPageDict = pPage->m_pFormDict;
+               ASSERT(pPageDict != NULL);
+
+               CPDF_AAction aa = pPageDict->GetDict(FX_BSTRC("AA"));
+
+               FX_BOOL bExistOAAction = FALSE;
+               FX_BOOL bExistCAAction = FALSE;
+               if (FPDFPAGE_AACTION_OPEN == aaType)
+               {
+                       bExistOAAction = aa.ActionExist(CPDF_AAction::OpenPage);
+                       if (bExistOAAction)
+                       {
+                               CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage);
+                               pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, pSDKDoc);
+                       }
+               }
+               else
+               {
+                       bExistCAAction = aa.ActionExist(CPDF_AAction::ClosePage);
+                       if (bExistCAAction)
+                       {
+                               CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage);
+                               pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, pSDKDoc);
+                       }
+               }
+       }
+}
+
+