diff options
author | Tom Sepez <tsepez@chromium.org> | 2015-07-17 09:16:17 -0700 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2015-07-17 09:16:17 -0700 |
commit | dcbc02f15e767e7d427fe6346d415c48da53afe0 (patch) | |
tree | 0a751aeef7e5f21f702dc9bff05848883ea370ea /fpdfsdk | |
parent | d44f1074fa672f1765c69945eb37157279154999 (diff) | |
download | pdfium-dcbc02f15e767e7d427fe6346d415c48da53afe0.tar.xz |
Merge to XFA: Tidy up CPDFDOC_Environment.
Original Review URL: https://codereview.chromium.org/1235393002 .
(cherry picked from commit fb07e2843dad0774d5842c2b08e7792164efc14a)
R=thestig@chromium.org
Review URL: https://codereview.chromium.org/1244503002 .
Diffstat (limited to 'fpdfsdk')
-rw-r--r-- | fpdfsdk/include/formfiller/FFL_FormFiller.h | 29 | ||||
-rw-r--r-- | fpdfsdk/include/fsdk_mgr.h | 1419 | ||||
-rw-r--r-- | fpdfsdk/src/formfiller/FFL_FormFiller.cpp | 924 | ||||
-rw-r--r-- | fpdfsdk/src/formfiller/FFL_IFormFiller.cpp | 23 | ||||
-rw-r--r-- | fpdfsdk/src/fpdfformfill.cpp | 960 | ||||
-rw-r--r-- | fpdfsdk/src/fsdk_annothandler.cpp | 1738 | ||||
-rw-r--r-- | fpdfsdk/src/fsdk_mgr.cpp | 1590 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/JS_Object.cpp | 92 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/app.cpp | 135 | ||||
-rw-r--r-- | fpdfsdk/src/javascript/global.cpp | 9 |
10 files changed, 3246 insertions, 3673 deletions
diff --git a/fpdfsdk/include/formfiller/FFL_FormFiller.h b/fpdfsdk/include/formfiller/FFL_FormFiller.h index cf0617598c..a477b34ded 100644 --- a/fpdfsdk/include/formfiller/FFL_FormFiller.h +++ b/fpdfsdk/include/formfiller/FFL_FormFiller.h @@ -18,7 +18,6 @@ class CPDFSDK_PageView; class CPDFSDK_Document; class CPDFSDK_Widget; - struct FFL_KeyStrokeData { CFX_WideString swValue; @@ -27,21 +26,19 @@ struct FFL_KeyStrokeData int nSelEnd; }; - - -class CFFL_FormFiller : /*public IBA_AnnotFiller,*/ public IPWL_Provider, public CPWL_TimerHandler +class CFFL_FormFiller : public IPWL_Provider, public CPWL_TimerHandler { public: CFFL_FormFiller(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot); virtual ~CFFL_FormFiller(); virtual FX_RECT GetViewBBox(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot); - virtual void OnDraw(CPDFSDK_PageView *pPageView, /*HDC hDC,*/ CPDFSDK_Annot* pAnnot, + virtual void OnDraw(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, + FX_DWORD dwFlags); + virtual void OnDrawDeactive(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, - /*const CRect& rcWindow, */FX_DWORD dwFlags); - virtual void OnDrawDeactive(CPDFSDK_PageView *pPageView, /*HDC hDC,*/ CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, - /*const CRect& rcWindow, */FX_DWORD dwFlags); + FX_DWORD dwFlags); virtual void OnCreate(CPDFSDK_Annot* pAnnot); virtual void OnLoad(CPDFSDK_Annot* pAnnot); @@ -110,8 +107,6 @@ public: void SetWindowRect(CPDFSDK_PageView* pPageView, const CPDF_Rect& rcWindow); CPDF_Rect GetWindowRect(CPDFSDK_PageView* pPageView); - static void FFL_FreeData(void* pData); - FX_BOOL CommitData(CPDFSDK_PageView* pPageView, FX_UINT nFlag); virtual FX_BOOL IsDataChanged(CPDFSDK_PageView* pPageView); virtual void SaveData(CPDFSDK_PageView* pPageView); @@ -160,13 +155,13 @@ public: virtual FX_BOOL OnLButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point); virtual FX_BOOL OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point); virtual FX_BOOL OnMouseMove(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point); - virtual void OnDraw(CPDFSDK_PageView *pPageView/*, HDC hDC*/, CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, - /*const CRect& rcWindow,*/ FX_DWORD dwFlags); + virtual void OnDraw(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, + FX_DWORD dwFlags); - virtual void OnDrawDeactive(CPDFSDK_PageView *pPageView, /*HDC hDC,*/ CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, - /*const CRect& rcWindow, */FX_DWORD dwFlags); + virtual void OnDrawDeactive(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, + FX_DWORD dwFlags); protected: FX_BOOL m_bMouseIn; FX_BOOL m_bMouseDown; diff --git a/fpdfsdk/include/fsdk_mgr.h b/fpdfsdk/include/fsdk_mgr.h index 29da5030a0..bd158bc1fe 100644 --- a/fpdfsdk/include/fsdk_mgr.h +++ b/fpdfsdk/include/fsdk_mgr.h @@ -23,737 +23,476 @@ #include "fsdk_actionhandler.h" #include "javascript/IJavaScript.h" +class CFFL_IFormFiller; +class CJS_RuntimeFactory; +class CPDFSDK_ActionHandler; +class CPDFSDK_Annot; class CPDFSDK_Document; +class CPDFSDK_InterForm; class CPDFSDK_PageView; -class CPDFSDK_Annot; -class CFFL_IFormFiller; class CPDFSDK_Widget; class IFX_SystemHandler; -class CPDFSDK_ActionHandler; -class CJS_RuntimeFactory; class CPDFDoc_Environment final { public: - CPDFDoc_Environment(CPDFXFA_Document * pDoc); - virtual ~CPDFDoc_Environment(); - - int RegAppHandle(FPDF_FORMFILLINFO* pFFinfo); - - virtual void Release() - { - if (m_pInfo && m_pInfo->Release) - m_pInfo->Release(m_pInfo); - delete this; - } - void FFI_Invalidate(FPDF_PAGE page, double left, double top, double right, double bottom) - { - if (m_pInfo && m_pInfo->FFI_Invalidate) - { - m_pInfo->FFI_Invalidate(m_pInfo, page, left, top, right, bottom); - } - } - void FFI_OutputSelectedRect(FPDF_PAGE page, double left, double top, double right, double bottom) - { - if (m_pInfo && m_pInfo->FFI_OutputSelectedRect) - { - m_pInfo->FFI_OutputSelectedRect(m_pInfo, page, left, top, right, bottom); - } - } - - void FFI_SetCursor(int nCursorType) - { - if (m_pInfo && m_pInfo->FFI_SetCursor) - { - m_pInfo->FFI_SetCursor(m_pInfo, nCursorType); - } - } - - int FFI_SetTimer(int uElapse, TimerCallback lpTimerFunc) - { - if (m_pInfo && m_pInfo->FFI_SetTimer) - { - return m_pInfo->FFI_SetTimer(m_pInfo, uElapse, lpTimerFunc); - } - return -1; - } - - void FFI_KillTimer(int nTimerID) - { - if (m_pInfo && m_pInfo->FFI_KillTimer) - { - m_pInfo->FFI_KillTimer(m_pInfo, nTimerID); - } - } - FX_SYSTEMTIME FFI_GetLocalTime() - { - FX_SYSTEMTIME fxtime; - if(m_pInfo && m_pInfo->FFI_GetLocalTime) - { - FPDF_SYSTEMTIME systime = m_pInfo->FFI_GetLocalTime(m_pInfo); - fxtime.wDay = systime.wDay; - fxtime.wDayOfWeek = systime.wDayOfWeek; - fxtime.wHour = systime.wHour; - fxtime.wMilliseconds = systime.wMilliseconds; - fxtime.wMinute = systime.wMinute; - fxtime.wMonth = systime.wMonth; - fxtime.wSecond = systime.wSecond; - fxtime.wYear = systime.wYear; - } - return fxtime; - } - - void FFI_OnChange() - { - if(m_pInfo && m_pInfo->FFI_OnChange) - { - m_pInfo->FFI_OnChange(m_pInfo); - } - } - - FX_BOOL FFI_IsSHIFTKeyDown(FX_DWORD nFlag) - { - - return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0; - } - FX_BOOL FFI_IsCTRLKeyDown(FX_DWORD nFlag) - { - - return (nFlag & FWL_EVENTFLAG_ControlKey) != 0; - } - FX_BOOL FFI_IsALTKeyDown(FX_DWORD nFlag) - { - - return (nFlag & FWL_EVENTFLAG_AltKey) != 0; - } - FX_BOOL FFI_IsINSERTKeyDown(FX_DWORD nFlag) - { - return FALSE; - } - - int JS_appAlert(const FX_WCHAR* Msg, const FX_WCHAR* Title, FX_UINT Type, FX_UINT Icon) - { - if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert) - { - CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode(); - CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode(); - FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength()); - FPDF_WIDESTRING pTitle = (FPDF_WIDESTRING)bsTitle.GetBuffer(bsTitle.GetLength()); - int ret = m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, pMsg, pTitle, Type, Icon); - bsMsg.ReleaseBuffer(); - bsTitle.ReleaseBuffer(); - return ret; - } - return -1; - } - - int JS_appResponse(const FX_WCHAR* Question, const FX_WCHAR* Title, const FX_WCHAR* Default, const FX_WCHAR* cLabel, FPDF_BOOL bPassword, void* response, int length) - { - if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_response) - { - CFX_ByteString bsQuestion = CFX_WideString(Question).UTF16LE_Encode(); - CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode(); - CFX_ByteString bsDefault = CFX_WideString(Default).UTF16LE_Encode(); - CFX_ByteString bsLabel = CFX_WideString(cLabel).UTF16LE_Encode(); - FPDF_WIDESTRING pQuestion = (FPDF_WIDESTRING)bsQuestion.GetBuffer(bsQuestion.GetLength()); - FPDF_WIDESTRING pTitle = (FPDF_WIDESTRING)bsTitle.GetBuffer(bsTitle.GetLength()); - FPDF_WIDESTRING pDefault = (FPDF_WIDESTRING)bsDefault.GetBuffer(bsDefault.GetLength()); - FPDF_WIDESTRING pLabel = (FPDF_WIDESTRING)bsLabel.GetBuffer(bsLabel.GetLength()); - int ret = m_pInfo->m_pJsPlatform->app_response(m_pInfo->m_pJsPlatform, pQuestion, pTitle, - pDefault, pLabel, bPassword, response, length); - bsQuestion.ReleaseBuffer(); - bsTitle.ReleaseBuffer(); - bsDefault.ReleaseBuffer(); - bsLabel.ReleaseBuffer(); - return ret; - } - return -1; - } - - void JS_appBeep(int nType) - { - if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_beep) - { - m_pInfo->m_pJsPlatform->app_beep(m_pInfo->m_pJsPlatform, nType); - } - } - - CFX_WideString JS_fieldBrowse() - { - if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Field_browse) - { - int nRequiredLen = m_pInfo->m_pJsPlatform->Field_browse(m_pInfo->m_pJsPlatform, NULL, 0); - if (nRequiredLen <= 0) - return L""; - - char* pbuff = new char[nRequiredLen]; - if (!pbuff) - return L""; - - memset(pbuff, 0, nRequiredLen); - int nActualLen = m_pInfo->m_pJsPlatform->Field_browse(m_pInfo->m_pJsPlatform, pbuff, nRequiredLen); - if (nActualLen <= 0 || nActualLen > nRequiredLen) - { - delete[] pbuff; - return L""; - } - CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen); - CFX_WideString wsRet = CFX_WideString::FromLocal(bsRet); - delete[] pbuff; - return wsRet; - } - return L""; - } - - CFX_WideString JS_docGetFilePath() - { - if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_getFilePath) - { - int nRequiredLen = m_pInfo->m_pJsPlatform->Doc_getFilePath(m_pInfo->m_pJsPlatform, NULL, 0); - if (nRequiredLen <= 0) - return L""; - - char* pbuff = new char[nRequiredLen]; - if (!pbuff) - return L""; - - memset(pbuff, 0, nRequiredLen); - int nActualLen = m_pInfo->m_pJsPlatform->Doc_getFilePath(m_pInfo->m_pJsPlatform, pbuff, nRequiredLen); - if (nActualLen <= 0 || nActualLen > nRequiredLen) - { - delete[] pbuff; - return L""; - } - CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen); - CFX_WideString wsRet = CFX_WideString::FromLocal(bsRet); - delete[] pbuff; - return wsRet; - } - return L""; - } - - void JS_docSubmitForm(void* formData, int length, const FX_WCHAR* URL) - { - if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_submitForm) - { - CFX_ByteString bsDestination = CFX_WideString(URL).UTF16LE_Encode(); - FPDF_WIDESTRING pDestination = (FPDF_WIDESTRING)bsDestination.GetBuffer(bsDestination.GetLength()); - m_pInfo->m_pJsPlatform->Doc_submitForm(m_pInfo->m_pJsPlatform, formData, length, pDestination); - bsDestination.ReleaseBuffer(); - } - } - - void JS_docmailForm(void* mailData, int length, FPDF_BOOL bUI,const FX_WCHAR* To, const FX_WCHAR* Subject, const FX_WCHAR* CC, const FX_WCHAR* BCC, const FX_WCHAR* Msg) - { - if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_mail) - { - CFX_ByteString bsTo = CFX_WideString(To).UTF16LE_Encode(); - CFX_ByteString bsCC = CFX_WideString(Subject).UTF16LE_Encode(); - CFX_ByteString bsBcc = CFX_WideString(BCC).UTF16LE_Encode(); - CFX_ByteString bsSubject = CFX_WideString(Subject).UTF16LE_Encode(); - CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode(); - FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(bsTo.GetLength()); - FPDF_WIDESTRING pCC = (FPDF_WIDESTRING)bsCC.GetBuffer(bsCC.GetLength()); - FPDF_WIDESTRING pBcc = (FPDF_WIDESTRING)bsBcc.GetBuffer(bsBcc.GetLength()); - FPDF_WIDESTRING pSubject = (FPDF_WIDESTRING)bsSubject.GetBuffer(bsSubject.GetLength()); - FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength()); - m_pInfo->m_pJsPlatform->Doc_mail(m_pInfo->m_pJsPlatform, mailData, length, bUI, pTo, pSubject, - pCC, pBcc, pMsg); - bsTo.ReleaseBuffer(); - bsCC.ReleaseBuffer(); - bsBcc.ReleaseBuffer(); - bsSubject.ReleaseBuffer(); - bsMsg.ReleaseBuffer(); - } - } - - void JS_docprint(FPDF_BOOL bUI , int nStart, int nEnd, FPDF_BOOL bSilent ,FPDF_BOOL bShrinkToFit,FPDF_BOOL bPrintAsImage ,FPDF_BOOL bReverse ,FPDF_BOOL bAnnotations) - { - if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_print) - { - m_pInfo->m_pJsPlatform->Doc_print(m_pInfo->m_pJsPlatform, bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage, bReverse, bAnnotations); - } - } - void JS_docgotoPage(int nPageNum) - { - if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_gotoPage) - { - m_pInfo->m_pJsPlatform->Doc_gotoPage(m_pInfo->m_pJsPlatform, nPageNum); - } - } - - FPDF_PAGE FFI_GetPage(FPDF_DOCUMENT document,int nPageIndex) - { - if(m_pInfo && m_pInfo->FFI_GetPage) - { - return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex); - } - return NULL; - } - - FPDF_PAGE FFI_GetCurrentPage(FPDF_DOCUMENT document) - { - if(m_pInfo && m_pInfo->FFI_GetCurrentPage) - { - return m_pInfo->FFI_GetCurrentPage(m_pInfo, document); - } - return NULL; - } - - int FFI_GetRotation(FPDF_PAGE page) - { - if(m_pInfo && m_pInfo->FFI_GetRotation) - { - return m_pInfo->FFI_GetRotation(m_pInfo, page); - } - return 0; - } - void FFI_ExecuteNamedAction(const FX_CHAR* namedAction) - { - if(m_pInfo && m_pInfo->FFI_ExecuteNamedAction) - { - m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction); - } - } - void FFI_OnSetFieldInputFocus(void* field,FPDF_WIDESTRING focusText, FPDF_DWORD nTextLen, FX_BOOL bFocus) - { - if(m_pInfo && m_pInfo->FFI_SetTextFieldFocus) - { - m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus); - } - } - - void FFI_DoURIAction(const FX_CHAR* bsURI) - { - if(m_pInfo && m_pInfo->FFI_DoURIAction) - { - m_pInfo->FFI_DoURIAction(m_pInfo, bsURI); - } - } - - void FFI_DoGoToAction(int nPageIndex, int zoomMode, float* fPosArray, int sizeOfArray) - { - if(m_pInfo && m_pInfo->FFI_DoGoToAction) - { - m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray, sizeOfArray); - } - } - - void FFI_DisplayCaret(FPDF_PAGE page, FPDF_BOOL bVisible, double left, double top, double right, double bottom) - { - if (m_pInfo && m_pInfo->FFI_DisplayCaret) - { - m_pInfo->FFI_DisplayCaret(m_pInfo, page, bVisible, left, top, right, bottom); - } - } - int FFI_GetCurrentPageIndex(FPDF_DOCUMENT document) - { - if (m_pInfo && m_pInfo->FFI_GetCurrentPageIndex) - { - m_pInfo->FFI_GetCurrentPageIndex(m_pInfo, document); - } - return -1; - } - int FFI_SetCurrentPage(FPDF_DOCUMENT document, int iCurPage) - { - if (m_pInfo && m_pInfo->FFI_SetCurrentPage) - { - m_pInfo->FFI_SetCurrentPage(m_pInfo, document, iCurPage); - } - return -1; - } - - CFX_WideString FFI_GetAppName() - { - return CFX_WideString(L"Acrobat"); - - //if (m_pInfo && m_pInfo->FFI_GetAppName) - //{ - // int nLen = m_pInfo->FFI_GetAppName(m_pInfo, NULL, 0); - // if(nLen <= 0) - // return L""; - // char* pbuff = new char[nLen]; - // if(pbuff) - // memset(pbuff, 0, nLen); - // else - // return L""; - // nLen = m_pInfo->FFI_GetAppName(m_pInfo, pbuff, nLen); - // CFX_ByteString bsRet = CFX_ByteString(pbuff, nLen); - // CFX_WideString wsRet = CFX_WideString::FromLocal(bsRet); - // delete[] pbuff; - // return wsRet; - //} - - //return L""; - } - - CFX_WideString FFI_GetPlatform() - { - if (m_pInfo && m_pInfo->FFI_GetPlatform) - { - int nRequiredLen = m_pInfo->FFI_GetPlatform(m_pInfo, NULL, 0); - if (nRequiredLen <= 0) - return L""; - - char* pbuff = new char[nRequiredLen]; - if (!pbuff) - return L""; - - memset(pbuff, 0, nRequiredLen); - int nActualLen = m_pInfo->FFI_GetPlatform(m_pInfo, pbuff, nRequiredLen); - if (nActualLen <= 0 || nActualLen > nRequiredLen) - { - delete[] pbuff; - return L""; - } - CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen); - CFX_WideString wsRet = CFX_WideString::FromUTF16LE((unsigned short*)bsRet.GetBuffer(bsRet.GetLength()), bsRet.GetLength()/sizeof(unsigned short)); - delete[] pbuff; - return wsRet; - } - return L""; - } - - void FFI_GotoURL(FPDF_DOCUMENT document, const CFX_WideStringC& wsURL, FX_BOOL bAppend) - { - if (m_pInfo && m_pInfo->FFI_GotoURL) - { - CFX_ByteString bsTo = CFX_WideString(wsURL).UTF16LE_Encode(); - FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(wsURL.GetLength()); - m_pInfo->FFI_GotoURL(m_pInfo, document, pTo); - bsTo.ReleaseBuffer(); - } - } - void FFI_GetURL(FPDF_DOCUMENT document, CFX_WideString& wsURL) - { - wsURL = CFX_WideString(); - return; - //if (m_pInfo && m_pInfo->FFI_GetURL) - //{ - // FPDF_WIDESTRING url = m_pInfo->FFI_GetURL(m_pInfo, document); - // CFX_WideString tmp; - // tmp.FromUTF16LE(url); - // wsURL = tmp; - //} - } - - void FFI_AddDoRecord(FPDF_DOCUMENT document, FPDF_WIDGET hWidget) - { - //if (m_pInfo && m_pInfo->FFI_AddDoRecord) - //{ - // m_pInfo->FFI_AddDoRecord(m_pInfo, document, hWidget); - //} - } - void FFI_PageEvent(FPDF_PAGE page, FPDF_DWORD flag) - { - //if (m_pInfo && m_pInfo->FFI_PageEvent) - //{ - // m_pInfo->FFI_PageEvent(m_pInfo, page, flag); - //} - } - - void FFI_GetPageViewRect(FPDF_PAGE page, FS_RECTF& dstRect) - { - if (m_pInfo && m_pInfo->FFI_GetPageViewRect) - { - double left; - double top; - double right; - double bottom; - m_pInfo->FFI_GetPageViewRect(m_pInfo, page, &left, &top, &right, &bottom); - - dstRect.left = static_cast<float>(left); - dstRect.top = static_cast<float>(top < bottom ? bottom : top); - dstRect.bottom = static_cast<float>(top < bottom ? top : bottom); - dstRect.right = static_cast<float>(right); - } - } - - - FX_BOOL FFI_PopupMenu(FPDF_PAGE page, FPDF_WIDGET hWidget, int menuFlag, CFX_PointF ptPopup, const CFX_PointF* pRectExclude) - { - if (m_pInfo && m_pInfo->FFI_PopupMenu) - { - return m_pInfo->FFI_PopupMenu(m_pInfo, page, hWidget, menuFlag, ptPopup.x, ptPopup.y); - } - return FALSE; - } - - void FFI_Alert(FPDF_WIDESTRING Msg, FPDF_WIDESTRING Title, int Type, int Icon) - { - if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert) - { - m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, Msg, Title, Type, Icon); - } - } - void FFI_EmailTo(FPDF_FILEHANDLER* fileHandler, FPDF_WIDESTRING pTo, FPDF_WIDESTRING pSubject, FPDF_WIDESTRING pCC, FPDF_WIDESTRING pBcc, FPDF_WIDESTRING pMsg) - { - if(m_pInfo && m_pInfo->FFI_EmailTo) - { - m_pInfo->FFI_EmailTo(m_pInfo, fileHandler, pTo, pSubject, pCC, pBcc, pMsg); - } - } - void FFI_UploadTo(FPDF_FILEHANDLER* fileHandler, int fileFlag, FPDF_WIDESTRING uploadTo) - { - if(m_pInfo && m_pInfo->FFI_UploadTo) - { - m_pInfo->FFI_UploadTo(m_pInfo, fileHandler, fileFlag, uploadTo); - } - } - FPDF_FILEHANDLER* FFI_OpenFile(int fileType, FPDF_WIDESTRING wsURL, const char* mode) - { - if(m_pInfo && m_pInfo->FFI_OpenFile) - { - return m_pInfo->FFI_OpenFile(m_pInfo, fileType, wsURL, mode); - } - return NULL; - } - CFX_WideString FFI_GetFilePath(FPDF_FILEHANDLER* pFileHandler) - { -#if 0 - if (m_pInfo && m_pInfo->FFI_GetFilePath) - { - int nRequiredLen = m_pInfo->FFI_GetFilePath(m_pInfo, pFileHandler, NULL, 0); - if (nRequiredLen <= 0) - return L""; - - char* pbuff = new char[nRequiredLen]; - if (!pbuff) - return L""; - - memset(pbuff, 0, nRequiredLen); - int nActualLen = m_pInfo->FFI_GetFilePath(m_pInfo, pFileHandler, pbuff, nRequiredLen); - if (nActualLen <= 0 || nActualLen > nRequiredLen) - { - delete[] pbuff; - return L""; - } - CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen); - CFX_WideString wsRet = CFX_WideString::FromUTF16LE((unsigned short*)bsRet.GetBuffer(bsRet.GetLength()), bsRet.GetLength()/sizeof(unsigned short)); - delete[] pbuff; - return wsRet; - } - return L""; -#else - return L""; -#endif - } - int FFI_GetDocumentCount() - { - //if (m_pInfo && m_pInfo->FFI_GetDocumentCount) - //{ - //return m_pInfo->FFI_GetDocumentCount(m_pInfo); - //} - return 0; - } - - int FFI_GetCurDocument() - { - //if (m_pInfo && m_pInfo->FFI_GetCurDocumentIndex) - //{ - // return m_pInfo->FFI_GetCurDocumentIndex(m_pInfo); - //} - return 0; - } - - IFX_FileRead* FFI_DownloadFromURL(const FX_WCHAR* url) - { - if (m_pInfo && m_pInfo->FFI_DownloadFromURL) - { - CFX_ByteString bstrURL = CFX_WideString(url).UTF16LE_Encode(); - FPDF_WIDESTRING wsURL = (FPDF_WIDESTRING)bstrURL.GetBuffer(bstrURL.GetLength()); - - FPDF_LPFILEHANDLER fileHandler = m_pInfo->FFI_DownloadFromURL(m_pInfo, wsURL); - - CFPDF_FileStream* fileStream = FX_NEW CFPDF_FileStream(fileHandler); - return fileStream; - } - return NULL; - } - - CFX_WideString FFI_PostRequestURL(const FX_WCHAR* wsURL, const FX_WCHAR* wsData, const FX_WCHAR* wsContentType, const FX_WCHAR* wsEncode, const FX_WCHAR* wsHeader) - { - if (m_pInfo && m_pInfo->FFI_PostRequestURL) - { - CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode(); - FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength()); - - CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode(); - FPDF_WIDESTRING data = (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength()); - - CFX_ByteString bsContentType = CFX_WideString(wsContentType).UTF16LE_Encode(); - FPDF_WIDESTRING contentType = (FPDF_WIDESTRING)bsContentType.GetBuffer(bsContentType.GetLength()); - - CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode(); - FPDF_WIDESTRING encode = (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength()); - - CFX_ByteString bsHeader = CFX_WideString(wsHeader).UTF16LE_Encode(); - FPDF_WIDESTRING header = (FPDF_WIDESTRING)bsHeader.GetBuffer(bsHeader.GetLength()); - - FPDF_BSTR respone; - FPDF_BStr_Init(&respone); - FPDF_BOOL bRet = m_pInfo->FFI_PostRequestURL(m_pInfo, URL, data, contentType, encode, header, &respone); - - CFX_WideString wsRet = CFX_WideString::FromUTF16LE((unsigned short*)respone.str, respone.len/sizeof(unsigned short)); - FPDF_BStr_Clear(&respone); - - return wsRet; - } - return L""; - } - - FPDF_BOOL FFI_PutRequestURL(const FX_WCHAR* wsURL, const FX_WCHAR* wsData, const FX_WCHAR* wsEncode) - { - if (m_pInfo && m_pInfo->FFI_PutRequestURL) - { - CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode(); - FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength()); - - CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode(); - FPDF_WIDESTRING data = (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength()); - - CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode(); - FPDF_WIDESTRING encode = (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength()); - - return m_pInfo->FFI_PutRequestURL(m_pInfo, URL, data, encode); - } - return FALSE; - } - - FPDF_BOOL FFI_ShowFileDialog(const FX_WCHAR* wsTitle, const FX_WCHAR* wsFilter, CFX_WideStringArray &wsPathArr, FX_BOOL bOpen) - { - /*CFX_ByteString bsTitle = CFX_WideString(wsTitle).UTF16LE_Encode(); - FPDF_WIDESTRING title = (FPDF_WIDESTRING)bsTitle.GetBuffer(bsTitle.GetLength()); - - CFX_ByteString bsFilter = CFX_WideString(wsFilter).UTF16LE_Encode(); - FPDF_WIDESTRING filter = (FPDF_WIDESTRING)bsFilter.GetBuffer(bsFilter.GetLength()); - - CFX_ByteStringArray* strPathArr = FX_NEW CFX_ByteStringArray(); - if (m_pInfo && m_pInfo->FFI_ShowFileDialog) - { - FPDF_BOOL bRet = m_pInfo->FFI_ShowFileDialog(m_pInfo, title, filter, bOpen, (FPDF_STRINGHANDLE)strPathArr); - if (bRet) - { - int count = strPathArr->GetSize(); - for (int i=0; i<count; i++) - { - CFX_ByteString bsPath = *strPathArr->GetDataPtr(i); - CFX_WideString wsPath = CFX_WideString::FromUTF16LE((unsigned short*)bsPath.GetBuffer(bsPath.GetLength()), bsPath.GetLength()/sizeof(unsigned short)); - if (!wsPath.IsEmpty()) - wsPathArr.Add(wsPath); - wsPath = L""; - } - return TRUE; - } - - return FALSE; - } - */ - - return FALSE; - } - CFX_WideString FFI_GetLanguage() - { - if (m_pInfo && m_pInfo->FFI_GetLanguage) - { - int nRequiredLen = m_pInfo->FFI_GetLanguage(m_pInfo, NULL, 0); - if (nRequiredLen <= 0) - return L""; - - char* pbuff = new char[nRequiredLen]; - if (!pbuff) - return L""; - - memset(pbuff, 0, nRequiredLen); - int nActualLen = m_pInfo->FFI_GetLanguage(m_pInfo, pbuff, nRequiredLen); - if (nActualLen <= 0 || nActualLen > nRequiredLen) - { - delete[] pbuff; - return L""; - } - CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen); - CFX_WideString wsRet = CFX_WideString::FromUTF16LE((unsigned short*)bsRet.GetBuffer(bsRet.GetLength()), bsRet.GetLength()/sizeof(unsigned short)); - delete[] pbuff; - return wsRet; - } - return L""; - } - - FX_BOOL IsJSInitiated(); - - void SetCurrentDoc(CPDFSDK_Document* pFXDoc) {m_pSDKDoc = pFXDoc;} - CPDFSDK_Document* GetCurrentDoc(); - CPDFXFA_Document* GetPDFXFADocument() {return m_pDoc;} - - CFX_ByteString GetAppName() {return "";} - - CFFL_IFormFiller* GetIFormFiller(); - IFX_SystemHandler* GetSysHandler() {return m_pSysHandler;} - - CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr(); - IFXJS_Runtime* GetJSRuntime(); - CPDFSDK_ActionHandler* GetActionHander(); - FPDF_FORMFILLINFO* GetFormFillInfo() {return m_pInfo;} + CPDFDoc_Environment(CPDFXFA_Document* pDoc, FPDF_FORMFILLINFO* pFFinfo); + virtual ~CPDFDoc_Environment(); + + virtual void Release() + { + if (m_pInfo && m_pInfo->Release) + m_pInfo->Release(m_pInfo); + delete this; + } + + void FFI_Invalidate(FPDF_PAGE page, double left, double top, double right, double bottom) + { + if (m_pInfo && m_pInfo->FFI_Invalidate) + m_pInfo->FFI_Invalidate(m_pInfo, page, left, top, right, bottom); + } + + void FFI_OutputSelectedRect(FPDF_PAGE page, double left, double top, double right, double bottom) + { + if (m_pInfo && m_pInfo->FFI_OutputSelectedRect) + m_pInfo->FFI_OutputSelectedRect(m_pInfo, page, left, top, right, bottom); + } + + void FFI_SetCursor(int nCursorType) + { + if (m_pInfo && m_pInfo->FFI_SetCursor) + m_pInfo->FFI_SetCursor(m_pInfo, nCursorType); + } + + int FFI_SetTimer(int uElapse, TimerCallback lpTimerFunc) + { + if (m_pInfo && m_pInfo->FFI_SetTimer) + return m_pInfo->FFI_SetTimer(m_pInfo, uElapse, lpTimerFunc); + return -1; + } + + void FFI_KillTimer(int nTimerID) + { + if (m_pInfo && m_pInfo->FFI_KillTimer) + m_pInfo->FFI_KillTimer(m_pInfo, nTimerID); + } + + FX_SYSTEMTIME FFI_GetLocalTime() + { + FX_SYSTEMTIME fxtime; + if(m_pInfo && m_pInfo->FFI_GetLocalTime) + { + FPDF_SYSTEMTIME systime = m_pInfo->FFI_GetLocalTime(m_pInfo); + fxtime.wDay = systime.wDay; + fxtime.wDayOfWeek = systime.wDayOfWeek; + fxtime.wHour = systime.wHour; + fxtime.wMilliseconds = systime.wMilliseconds; + fxtime.wMinute = systime.wMinute; + fxtime.wMonth = systime.wMonth; + fxtime.wSecond = systime.wSecond; + fxtime.wYear = systime.wYear; + } + return fxtime; + } + + void FFI_OnChange() + { + if (m_pInfo && m_pInfo->FFI_OnChange) + m_pInfo->FFI_OnChange(m_pInfo); + } + + FX_BOOL FFI_IsSHIFTKeyDown(FX_DWORD nFlag) + { + return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0; + } + + FX_BOOL FFI_IsCTRLKeyDown(FX_DWORD nFlag) + { + return (nFlag & FWL_EVENTFLAG_ControlKey) != 0; + } + + FX_BOOL FFI_IsALTKeyDown(FX_DWORD nFlag) + { + return (nFlag & FWL_EVENTFLAG_AltKey) != 0; + } + + FX_BOOL FFI_IsINSERTKeyDown(FX_DWORD nFlag) + { + return FALSE; + } + + int JS_appAlert(const FX_WCHAR* Msg, const FX_WCHAR* Title, FX_UINT Type, FX_UINT Icon); + int JS_appResponse(const FX_WCHAR* Question, const FX_WCHAR* Title, const FX_WCHAR* Default, + const FX_WCHAR* cLabel, FPDF_BOOL bPassword, void* response, int length); + + void JS_appBeep(int nType) + { + if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_beep) + m_pInfo->m_pJsPlatform->app_beep(m_pInfo->m_pJsPlatform, nType); + } + + CFX_WideString JS_fieldBrowse(); + CFX_WideString JS_docGetFilePath(); + + void JS_docSubmitForm(void* formData, int length, const FX_WCHAR* URL); + void JS_docmailForm(void* mailData, int length, FPDF_BOOL bUI, + const FX_WCHAR* To, const FX_WCHAR* Subject, + const FX_WCHAR* CC, const FX_WCHAR* BCC, + const FX_WCHAR* Msg); + + void JS_docprint(FPDF_BOOL bUI, int nStart, int nEnd, FPDF_BOOL bSilent, + FPDF_BOOL bShrinkToFit, FPDF_BOOL bPrintAsImage, + FPDF_BOOL bReverse, FPDF_BOOL bAnnotations) + { + if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_print) + m_pInfo->m_pJsPlatform->Doc_print( + m_pInfo->m_pJsPlatform, bUI, nStart, nEnd, bSilent, bShrinkToFit, + bPrintAsImage, bReverse, bAnnotations); + } + + void JS_docgotoPage(int nPageNum) + { + if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_gotoPage) + m_pInfo->m_pJsPlatform->Doc_gotoPage(m_pInfo->m_pJsPlatform, nPageNum); + } + + FPDF_PAGE FFI_GetPage(FPDF_DOCUMENT document,int nPageIndex) + { + if (m_pInfo && m_pInfo->FFI_GetPage) + return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex); + return NULL; + } + + FPDF_PAGE FFI_GetCurrentPage(FPDF_DOCUMENT document) + { + if (m_pInfo && m_pInfo->FFI_GetCurrentPage) + return m_pInfo->FFI_GetCurrentPage(m_pInfo, document); + return NULL; + } + + int FFI_GetRotation(FPDF_PAGE page) + { + if (m_pInfo && m_pInfo->FFI_GetRotation) + return m_pInfo->FFI_GetRotation(m_pInfo, page); + return 0; + } + + void FFI_ExecuteNamedAction(const FX_CHAR* namedAction) + { + if (m_pInfo && m_pInfo->FFI_ExecuteNamedAction) + m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction); + } + + void FFI_OnSetFieldInputFocus(void* field,FPDF_WIDESTRING focusText, FPDF_DWORD nTextLen, FX_BOOL bFocus) + { + if (m_pInfo && m_pInfo->FFI_SetTextFieldFocus) + m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus); + } + + void FFI_DoURIAction(const FX_CHAR* bsURI) + { + if (m_pInfo && m_pInfo->FFI_DoURIAction) + m_pInfo->FFI_DoURIAction(m_pInfo, bsURI); + } + + void FFI_DoGoToAction(int nPageIndex, int zoomMode, float* fPosArray, int sizeOfArray) + { + if (m_pInfo && m_pInfo->FFI_DoGoToAction) + m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray, sizeOfArray); + } + + void FFI_DisplayCaret(FPDF_PAGE page, FPDF_BOOL bVisible, double left, double top, double right, double bottom) + { + if (m_pInfo && m_pInfo->FFI_DisplayCaret) + m_pInfo->FFI_DisplayCaret(m_pInfo, page, bVisible, left, top, right, bottom); + } + + int FFI_GetCurrentPageIndex(FPDF_DOCUMENT document) + { + if (m_pInfo && m_pInfo->FFI_GetCurrentPageIndex) + m_pInfo->FFI_GetCurrentPageIndex(m_pInfo, document); + return -1; + } + + int FFI_SetCurrentPage(FPDF_DOCUMENT document, int iCurPage) + { + if (m_pInfo && m_pInfo->FFI_SetCurrentPage) + m_pInfo->FFI_SetCurrentPage(m_pInfo, document, iCurPage); + return -1; + } + + CFX_WideString FFI_GetAppName() const { return CFX_WideString(L"Acrobat"); } + + CFX_WideString FFI_GetPlatform() + { + if (m_pInfo && m_pInfo->FFI_GetPlatform) + { + int nRequiredLen = m_pInfo->FFI_GetPlatform(m_pInfo, NULL, 0); + if (nRequiredLen <= 0) + return L""; + + char* pbuff = new char[nRequiredLen]; + if (!pbuff) + return L""; + + memset(pbuff, 0, nRequiredLen); + int nActualLen = m_pInfo->FFI_GetPlatform(m_pInfo, pbuff, nRequiredLen); + if (nActualLen <= 0 || nActualLen > nRequiredLen) + { + delete[] pbuff; + return L""; + } + CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen); + CFX_WideString wsRet = CFX_WideString::FromUTF16LE((unsigned short*)bsRet.GetBuffer(bsRet.GetLength()), bsRet.GetLength()/sizeof(unsigned short)); + delete[] pbuff; + return wsRet; + } + return L""; + } + + void FFI_GotoURL(FPDF_DOCUMENT document, const CFX_WideStringC& wsURL, FX_BOOL bAppend) + { + if (m_pInfo && m_pInfo->FFI_GotoURL) + { + CFX_ByteString bsTo = CFX_WideString(wsURL).UTF16LE_Encode(); + FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(wsURL.GetLength()); + m_pInfo->FFI_GotoURL(m_pInfo, document, pTo); + bsTo.ReleaseBuffer(); + } + } + + void FFI_GetURL(FPDF_DOCUMENT document, CFX_WideString& wsURL) + { + wsURL = CFX_WideString(); + } + + void FFI_AddDoRecord(FPDF_DOCUMENT document, FPDF_WIDGET hWidget) {} + void FFI_PageEvent(FPDF_PAGE page, FPDF_DWORD flag) {} + + void FFI_GetPageViewRect(FPDF_PAGE page, FS_RECTF& dstRect) + { + if (m_pInfo && m_pInfo->FFI_GetPageViewRect) + { + double left; + double top; + double right; + double bottom; + m_pInfo->FFI_GetPageViewRect(m_pInfo, page, &left, &top, &right, &bottom); + + dstRect.left = static_cast<float>(left); + dstRect.top = static_cast<float>(top < bottom ? bottom : top); + dstRect.bottom = static_cast<float>(top < bottom ? top : bottom); + dstRect.right = static_cast<float>(right); + } + } + + FX_BOOL FFI_PopupMenu(FPDF_PAGE page, FPDF_WIDGET hWidget, int menuFlag, CFX_PointF ptPopup, const CFX_PointF* pRectExclude) + { + if (m_pInfo && m_pInfo->FFI_PopupMenu) + return m_pInfo->FFI_PopupMenu(m_pInfo, page, hWidget, menuFlag, ptPopup.x, ptPopup.y); + return FALSE; + } + + void FFI_Alert(FPDF_WIDESTRING Msg, FPDF_WIDESTRING Title, int Type, int Icon) + { + if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert) + m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, Msg, Title, Type, Icon); + } + + void FFI_EmailTo(FPDF_FILEHANDLER* fileHandler, FPDF_WIDESTRING pTo, + FPDF_WIDESTRING pSubject, FPDF_WIDESTRING pCC, + FPDF_WIDESTRING pBcc, FPDF_WIDESTRING pMsg) + { + if (m_pInfo && m_pInfo->FFI_EmailTo) + m_pInfo->FFI_EmailTo(m_pInfo, fileHandler, pTo, pSubject, pCC, pBcc, pMsg); + } + + void FFI_UploadTo(FPDF_FILEHANDLER* fileHandler, int fileFlag, FPDF_WIDESTRING uploadTo) + { + if (m_pInfo && m_pInfo->FFI_UploadTo) + m_pInfo->FFI_UploadTo(m_pInfo, fileHandler, fileFlag, uploadTo); + } + + FPDF_FILEHANDLER* FFI_OpenFile(int fileType, FPDF_WIDESTRING wsURL, const char* mode) + { + if (m_pInfo && m_pInfo->FFI_OpenFile) + return m_pInfo->FFI_OpenFile(m_pInfo, fileType, wsURL, mode); + return NULL; + } + + CFX_WideString FFI_GetFilePath(FPDF_FILEHANDLER* pFileHandler) const + { + return L""; + } + + int FFI_GetDocumentCount() const { return 0; } + int FFI_GetCurDocument() const { return 0; } + + IFX_FileRead* FFI_DownloadFromURL(const FX_WCHAR* url) + { + if (m_pInfo && m_pInfo->FFI_DownloadFromURL) + { + CFX_ByteString bstrURL = CFX_WideString(url).UTF16LE_Encode(); + FPDF_WIDESTRING wsURL = (FPDF_WIDESTRING)bstrURL.GetBuffer(bstrURL.GetLength()); + + FPDF_LPFILEHANDLER fileHandler = m_pInfo->FFI_DownloadFromURL(m_pInfo, wsURL); + + CFPDF_FileStream* fileStream = FX_NEW CFPDF_FileStream(fileHandler); + return fileStream; + } + return NULL; + } + + CFX_WideString FFI_PostRequestURL(const FX_WCHAR* wsURL, + const FX_WCHAR* wsData, + const FX_WCHAR* wsContentType, + const FX_WCHAR* wsEncode, + const FX_WCHAR* wsHeader) + { + if (m_pInfo && m_pInfo->FFI_PostRequestURL) + { + CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode(); + FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength()); + + CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode(); + FPDF_WIDESTRING data = (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength()); + + CFX_ByteString bsContentType = CFX_WideString(wsContentType).UTF16LE_Encode(); + FPDF_WIDESTRING contentType = (FPDF_WIDESTRING)bsContentType.GetBuffer(bsContentType.GetLength()); + + CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode(); + FPDF_WIDESTRING encode = (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength()); + + CFX_ByteString bsHeader = CFX_WideString(wsHeader).UTF16LE_Encode(); + FPDF_WIDESTRING header = (FPDF_WIDESTRING)bsHeader.GetBuffer(bsHeader.GetLength()); + + FPDF_BSTR respone; + FPDF_BStr_Init(&respone); + m_pInfo->FFI_PostRequestURL(m_pInfo, URL, data, contentType, encode, header, &respone); + + CFX_WideString wsRet = CFX_WideString::FromUTF16LE((unsigned short*)respone.str, respone.len/sizeof(unsigned short)); + FPDF_BStr_Clear(&respone); + + return wsRet; + } + return L""; + } + + FPDF_BOOL FFI_PutRequestURL(const FX_WCHAR* wsURL, const FX_WCHAR* wsData, const FX_WCHAR* wsEncode) + { + if (m_pInfo && m_pInfo->FFI_PutRequestURL) + { + CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode(); + FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength()); + + CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode(); + FPDF_WIDESTRING data = (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength()); + + CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode(); + FPDF_WIDESTRING encode = (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength()); + + return m_pInfo->FFI_PutRequestURL(m_pInfo, URL, data, encode); + } + return FALSE; + } + + FPDF_BOOL FFI_ShowFileDialog(const FX_WCHAR* wsTitle, const FX_WCHAR* wsFilter, CFX_WideStringArray &wsPathArr, FX_BOOL bOpen) + { + return FALSE; + } + + CFX_WideString FFI_GetLanguage() + { + if (m_pInfo && m_pInfo->FFI_GetLanguage) + { + int nRequiredLen = m_pInfo->FFI_GetLanguage(m_pInfo, NULL, 0); + if (nRequiredLen <= 0) + return L""; + + char* pbuff = new char[nRequiredLen]; + if (!pbuff) + return L""; + + memset(pbuff, 0, nRequiredLen); + int nActualLen = m_pInfo->FFI_GetLanguage(m_pInfo, pbuff, nRequiredLen); + if (nActualLen <= 0 || nActualLen > nRequiredLen) + { + delete[] pbuff; + return L""; + } + CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen); + CFX_WideString wsRet = CFX_WideString::FromUTF16LE((unsigned short*)bsRet.GetBuffer(bsRet.GetLength()), bsRet.GetLength()/sizeof(unsigned short)); + delete[] pbuff; + return wsRet; + } + return L""; + } + + FX_BOOL IsJSInitiated() const { return m_pInfo && m_pInfo->m_pJsPlatform; } + void SetSDKDocument(CPDFSDK_Document* pFXDoc) { m_pSDKDoc = pFXDoc; } + CPDFSDK_Document* GetSDKDocument() const { return m_pSDKDoc; } + CPDFXFA_Document* GetPDFXFADocument() const { return m_pXFADoc; } + CFX_ByteString GetAppName() const { return ""; } + IFX_SystemHandler* GetSysHandler() const { return m_pSysHandler; } + FPDF_FORMFILLINFO* GetFormFillInfo() const { return m_pInfo; } + + CFFL_IFormFiller* GetIFormFiller(); // Creates if not present. + CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr(); // Creates if not present. + IFXJS_Runtime* GetJSRuntime(); // Creates if not present. + CPDFSDK_ActionHandler* GetActionHander(); // Creates if not present. private: - CPDFSDK_AnnotHandlerMgr* m_pAnnotHandlerMgr; - CPDFSDK_ActionHandler* m_pActionHandler; - IFXJS_Runtime* m_pJSRuntime; - FPDF_FORMFILLINFO* m_pInfo; - CPDFSDK_Document* m_pSDKDoc; - CPDFXFA_Document* m_pDoc; - - CFFL_IFormFiller* m_pIFormFiller; - IFX_SystemHandler* m_pSysHandler; - -public: - //CJS_RuntimeFactory* m_pJSRuntimeFactory; + CPDFSDK_AnnotHandlerMgr* m_pAnnotHandlerMgr; + CPDFSDK_ActionHandler* m_pActionHandler; + IFXJS_Runtime* m_pJSRuntime; + FPDF_FORMFILLINFO* const m_pInfo; + CPDFSDK_Document* m_pSDKDoc; + CPDFXFA_Document* const m_pXFADoc; + CFFL_IFormFiller* m_pIFormFiller; + IFX_SystemHandler* m_pSysHandler; }; - - -class CPDFSDK_InterForm; class CPDFSDK_Document { public: - CPDFSDK_Document(CPDFXFA_Document* pDoc, CPDFDoc_Environment* pEnv); - ~CPDFSDK_Document(); + CPDFSDK_Document(CPDFXFA_Document* pDoc, CPDFDoc_Environment* pEnv); + ~CPDFSDK_Document(); - CPDFSDK_InterForm* GetInterForm() ; - CPDFXFA_Document* GetDocument() {return m_pDoc;} + CPDFSDK_InterForm* GetInterForm() ; + CPDFXFA_Document* GetDocument() {return m_pDoc;} int GetPageViewCount() const { return m_pageMap.size(); } - CPDFSDK_PageView* GetPageView(CPDFXFA_Page* pPDFXFAPage, FX_BOOL ReNew = TRUE); - CPDFSDK_PageView* GetPageView(int nIndex); - CPDFSDK_PageView* GetCurrentView(); - void ReMovePageView(CPDFXFA_Page* pPDFPage); - void UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot); - - CPDFSDK_Annot* GetFocusAnnot(); - - IFXJS_Runtime * GetJsRuntime(); - - FX_BOOL SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag = 0); - FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0); - - FX_BOOL ExtractPages(const CFX_WordArray &arrExtraPages, CPDF_Document* pDstDoc); - FX_BOOL InsertPages(int nInsertAt, const CPDF_Document* pSrcDoc, const CFX_WordArray &arrSrcPages); - FX_BOOL DeletePages(int nStart, int nCount); - FX_BOOL ReplacePages(int nPage, const CPDF_Document* pSrcDoc, const CFX_WordArray &arrSrcPages); - - void OnCloseDocument(); - - int GetPageCount() {return m_pDoc->GetPageCount();} - FX_BOOL GetPermissions(int nFlag); - FX_BOOL GetChangeMark() {return m_bChangeMask;} - void SetChangeMark() {m_bChangeMask = TRUE;} - void ClearChangeMark() {m_bChangeMask= FALSE;} - CFX_WideString GetPath() ; - CPDFXFA_Page* GetPage(int nIndex); - CPDFDoc_Environment * GetEnv() {return m_pEnv; } - void ProcJavascriptFun(); - FX_BOOL ProcOpenAction(); - CPDF_OCContext* GetOCContext(); + CPDFSDK_PageView* GetPageView(CPDFXFA_Page* pPDFXFAPage, FX_BOOL ReNew = TRUE); + CPDFSDK_PageView* GetPageView(int nIndex); + CPDFSDK_PageView* GetCurrentView(); + void ReMovePageView(CPDFXFA_Page* pPDFPage); + void UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot); + + CPDFSDK_Annot* GetFocusAnnot(); + + IFXJS_Runtime * GetJsRuntime(); + + FX_BOOL SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag = 0); + FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0); + + FX_BOOL ExtractPages(const CFX_WordArray &arrExtraPages, CPDF_Document* pDstDoc); + FX_BOOL InsertPages(int nInsertAt, const CPDF_Document* pSrcDoc, const CFX_WordArray &arrSrcPages); + FX_BOOL DeletePages(int nStart, int nCount); + FX_BOOL ReplacePages(int nPage, const CPDF_Document* pSrcDoc, const CFX_WordArray &arrSrcPages); + + void OnCloseDocument(); + + int GetPageCount() {return m_pDoc->GetPageCount();} + FX_BOOL GetPermissions(int nFlag); + FX_BOOL GetChangeMark() {return m_bChangeMask;} + void SetChangeMark() {m_bChangeMask = TRUE;} + void ClearChangeMark() {m_bChangeMask= FALSE;} + CFX_WideString GetPath() ; + CPDFXFA_Page* GetPage(int nIndex); + CPDFDoc_Environment * GetEnv() {return m_pEnv; } + void ProcJavascriptFun(); + FX_BOOL ProcOpenAction(); + CPDF_OCContext* GetOCContext(); private: std::map<CPDFXFA_Page*, CPDFSDK_PageView*> m_pageMap; CPDFXFA_Document* m_pDoc; @@ -766,67 +505,67 @@ private: class CPDFSDK_PageView final { public: - CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,CPDFXFA_Page* page); - ~CPDFSDK_PageView(); - void PageView_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,CPDF_RenderOptions* pOptions, FX_RECT* pClip = NULL) ; - CPDF_Annot* GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); - CPDFSDK_Annot* GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); - CPDF_Annot* GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); - CPDFSDK_Annot* GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); - CPDFSDK_Annot* GetFocusAnnot() ; - void SetFocusAnnot(CPDFSDK_Annot* pSDKAnnot,FX_UINT nFlag = 0) {m_pSDKDoc->SetFocusAnnot(pSDKAnnot, nFlag);} - FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0) {return m_pSDKDoc->KillFocusAnnot(nFlag);} - FX_BOOL Annot_HasAppearance(CPDF_Annot* pAnnot); - - CPDFSDK_Annot* AddAnnot(CPDF_Dictionary * pDict); - CPDFSDK_Annot* AddAnnot(const FX_CHAR* lpSubType,CPDF_Dictionary * pDict); - CPDFSDK_Annot* AddAnnot(CPDF_Annot * pPDFAnnot); - CPDFSDK_Annot* AddAnnot(IXFA_Widget* pPDFAnnot); - FX_BOOL DeleteAnnot(CPDFSDK_Annot* pAnnot); - - int CountAnnots(); - CPDFSDK_Annot* GetAnnot(int nIndex); - CPDFSDK_Annot* GetAnnotByDict(CPDF_Dictionary * pDict); - CPDFSDK_Annot* GetAnnotByXFAWidget(IXFA_Widget* hWidget); - CPDFXFA_Page* GetPDFXFAPage(){return m_page;} - CPDF_Page* GetPDFPage(); - CPDF_Document* GetPDFDocument(); - CPDFSDK_Document* GetSDKDocument() {return m_pSDKDoc;} - FX_BOOL OnLButtonDown(const CPDF_Point & point, FX_UINT nFlag); - FX_BOOL OnLButtonUp(const CPDF_Point & point, FX_UINT nFlag); - FX_BOOL OnRButtonDown(const CPDF_Point & point, FX_UINT nFlag); - FX_BOOL OnRButtonUp(const CPDF_Point & point, FX_UINT nFlag); - FX_BOOL OnChar(int nChar, FX_UINT nFlag); - FX_BOOL OnKeyDown(int nKeyCode, int nFlag); - FX_BOOL OnKeyUp(int nKeyCode, int nFlag); - - FX_BOOL OnMouseMove(const CPDF_Point & point, int nFlag); - FX_BOOL OnMouseWheel(double deltaX, double deltaY,const CPDF_Point& point, int nFlag); - FX_BOOL IsValidAnnot(void* p); - void GetCurrentMatrix(CPDF_Matrix& matrix) {matrix = m_curMatrix;} - void UpdateRects(CFX_RectArray& rects); - void UpdateView(CPDFSDK_Annot* pAnnot); - CFX_PtrArray* GetAnnotList(){ return &m_fxAnnotArray; } - - int GetPageIndex(); - void LoadFXAnnots(); - void SetValid(FX_BOOL bValid) {m_bValid = bValid;} + CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,CPDFXFA_Page* page); + ~CPDFSDK_PageView(); + void PageView_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,CPDF_RenderOptions* pOptions, FX_RECT* pClip = NULL) ; + CPDF_Annot* GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); + CPDFSDK_Annot* GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); + CPDF_Annot* GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); + CPDFSDK_Annot* GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); + CPDFSDK_Annot* GetFocusAnnot() ; + void SetFocusAnnot(CPDFSDK_Annot* pSDKAnnot,FX_UINT nFlag = 0) {m_pSDKDoc->SetFocusAnnot(pSDKAnnot, nFlag);} + FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0) {return m_pSDKDoc->KillFocusAnnot(nFlag);} + FX_BOOL Annot_HasAppearance(CPDF_Annot* pAnnot); + + CPDFSDK_Annot* AddAnnot(CPDF_Dictionary * pDict); + CPDFSDK_Annot* AddAnnot(const FX_CHAR* lpSubType,CPDF_Dictionary * pDict); + CPDFSDK_Annot* AddAnnot(CPDF_Annot * pPDFAnnot); + CPDFSDK_Annot* AddAnnot(IXFA_Widget* pPDFAnnot); + FX_BOOL DeleteAnnot(CPDFSDK_Annot* pAnnot); + + int CountAnnots(); + CPDFSDK_Annot* GetAnnot(int nIndex); + CPDFSDK_Annot* GetAnnotByDict(CPDF_Dictionary * pDict); + CPDFSDK_Annot* GetAnnotByXFAWidget(IXFA_Widget* hWidget); + CPDFXFA_Page* GetPDFXFAPage(){return m_page;} + CPDF_Page* GetPDFPage(); + CPDF_Document* GetPDFDocument(); + CPDFSDK_Document* GetSDKDocument() {return m_pSDKDoc;} + FX_BOOL OnLButtonDown(const CPDF_Point & point, FX_UINT nFlag); + FX_BOOL OnLButtonUp(const CPDF_Point & point, FX_UINT nFlag); + FX_BOOL OnRButtonDown(const CPDF_Point & point, FX_UINT nFlag); + FX_BOOL OnRButtonUp(const CPDF_Point & point, FX_UINT nFlag); + FX_BOOL OnChar(int nChar, FX_UINT nFlag); + FX_BOOL OnKeyDown(int nKeyCode, int nFlag); + FX_BOOL OnKeyUp(int nKeyCode, int nFlag); + + FX_BOOL OnMouseMove(const CPDF_Point & point, int nFlag); + FX_BOOL OnMouseWheel(double deltaX, double deltaY,const CPDF_Point& point, int nFlag); + FX_BOOL IsValidAnnot(void* p); + void GetCurrentMatrix(CPDF_Matrix& matrix) {matrix = m_curMatrix;} + void UpdateRects(CFX_RectArray& rects); + void UpdateView(CPDFSDK_Annot* pAnnot); + CFX_PtrArray* GetAnnotList(){ return &m_fxAnnotArray; } + + int GetPageIndex(); + void LoadFXAnnots(); + void SetValid(FX_BOOL bValid) {m_bValid = bValid;} FX_BOOL IsValid() {return m_bValid;} void SetLock(FX_BOOL bLocked) {m_bLocked= bLocked;} FX_BOOL IsLocked() {return m_bLocked;} private: - void PageView_OnHighlightFormFields(CFX_RenderDevice* pDevice, CPDFSDK_Widget* pWidget); - CPDF_Matrix m_curMatrix; - CPDFXFA_Page* m_page; - CPDF_AnnotList* m_pAnnotList; - //CPDFSDK_Annot* m_pFocusAnnot; - CFX_PtrArray m_fxAnnotArray; - CPDFSDK_Document* m_pSDKDoc; - CPDFSDK_Annot* m_CaptureWidget; - FX_BOOL m_bEnterWidget; - FX_BOOL m_bExitWidget; - FX_BOOL m_bOnWidget; - FX_BOOL m_bValid; + void PageView_OnHighlightFormFields(CFX_RenderDevice* pDevice, CPDFSDK_Widget* pWidget); + CPDF_Matrix m_curMatrix; + CPDFXFA_Page* m_page; + CPDF_AnnotList* m_pAnnotList; + //CPDFSDK_Annot* m_pFocusAnnot; + CFX_PtrArray m_fxAnnotArray; + CPDFSDK_Document* m_pSDKDoc; + CPDFSDK_Annot* m_CaptureWidget; + FX_BOOL m_bEnterWidget; + FX_BOOL m_bExitWidget; + FX_BOOL m_bOnWidget; + FX_BOOL m_bValid; FX_BOOL m_bLocked; }; @@ -835,80 +574,80 @@ template<class TYPE> class CGW_ArrayTemplate : public CFX_ArrayTemplate<TYPE> { public: - CGW_ArrayTemplate(){} - virtual ~CGW_ArrayTemplate(){} + CGW_ArrayTemplate(){} + virtual ~CGW_ArrayTemplate(){} - typedef int (*LP_COMPARE)(TYPE p1, TYPE p2); + typedef int (*LP_COMPARE)(TYPE p1, TYPE p2); - void Sort(LP_COMPARE pCompare, FX_BOOL bAscent = TRUE) - { - int nSize = this->GetSize(); - QuickSort(0, nSize -1, bAscent, pCompare); - } + void Sort(LP_COMPARE pCompare, FX_BOOL bAscent = TRUE) + { + int nSize = this->GetSize(); + QuickSort(0, nSize -1, bAscent, pCompare); + } private: - void QuickSort(FX_UINT nStartPos, FX_UINT nStopPos, FX_BOOL bAscend, LP_COMPARE pCompare) - { - if (nStartPos >= nStopPos) return; - - if ((nStopPos - nStartPos) == 1) - { - TYPE Value1 = this->GetAt(nStartPos); - TYPE Value2 = this->GetAt(nStopPos); - - int iGreate = (*pCompare)(Value1, Value2); - if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0)) - { - this->SetAt(nStartPos, Value2); - this->SetAt(nStopPos, Value1); - } - return; - } - - FX_UINT m = nStartPos + (nStopPos - nStartPos) / 2; - FX_UINT i = nStartPos; - - TYPE Value = this->GetAt(m); - - while (i < m) - { - TYPE temp = this->GetAt(i); - - int iGreate = (*pCompare)(temp, Value); - if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0)) - { - this->InsertAt(m+1, temp); - this->RemoveAt(i); - m--; - } - else - { - i++; - } - } - - FX_UINT j = nStopPos; - - while (j > m) - { - TYPE temp = this->GetAt(j); - - int iGreate = (*pCompare)(temp, Value); - if ((bAscend && iGreate < 0) || (!bAscend && iGreate > 0)) - { - this->RemoveAt(j); - this->InsertAt(m, temp); - m++; - } - else - { - j--; - } - } - - if (nStartPos < m) QuickSort(nStartPos, m, bAscend, pCompare); - if (nStopPos > m) QuickSort(m, nStopPos, bAscend, pCompare); - } + void QuickSort(FX_UINT nStartPos, FX_UINT nStopPos, FX_BOOL bAscend, LP_COMPARE pCompare) + { + if (nStartPos >= nStopPos) return; + + if ((nStopPos - nStartPos) == 1) + { + TYPE Value1 = this->GetAt(nStartPos); + TYPE Value2 = this->GetAt(nStopPos); + + int iGreate = (*pCompare)(Value1, Value2); + if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0)) + { + this->SetAt(nStartPos, Value2); + this->SetAt(nStopPos, Value1); + } + return; + } + + FX_UINT m = nStartPos + (nStopPos - nStartPos) / 2; + FX_UINT i = nStartPos; + + TYPE Value = this->GetAt(m); + + while (i < m) + { + TYPE temp = this->GetAt(i); + + int iGreate = (*pCompare)(temp, Value); + if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0)) + { + this->InsertAt(m+1, temp); + this->RemoveAt(i); + m--; + } + else + { + i++; + } + } + + FX_UINT j = nStopPos; + + while (j > m) + { + TYPE temp = this->GetAt(j); + + int iGreate = (*pCompare)(temp, Value); + if ((bAscend && iGreate < 0) || (!bAscend && iGreate > 0)) + { + this->RemoveAt(j); + this->InsertAt(m, temp); + m++; + } + else + { + j--; + } + } + + if (nStartPos < m) QuickSort(nStartPos, m, bAscend, pCompare); + if (nStopPos > m) QuickSort(m, nStopPos, bAscend, pCompare); + } }; #endif // FPDFSDK_INCLUDE_FSDK_MGR_H_ diff --git a/fpdfsdk/src/formfiller/FFL_FormFiller.cpp b/fpdfsdk/src/formfiller/FFL_FormFiller.cpp index 7a70493d4c..17c6fc1b5c 100644 --- a/fpdfsdk/src/formfiller/FFL_FormFiller.cpp +++ b/fpdfsdk/src/formfiller/FFL_FormFiller.cpp @@ -9,21 +9,21 @@ #include "../../include/formfiller/FFL_Notify.h" #include "../../include/formfiller/FFL_CBA_Fontmap.h" -#define GetRed(rgb) ((uint8_t)(rgb)) -#define GetGreen(rgb) ((uint8_t)(((FX_WORD)(rgb)) >> 8)) -#define GetBlue(rgb) ((uint8_t)((rgb)>>16)) +#define GetRed(rgb) ((uint8_t)(rgb)) +#define GetGreen(rgb) ((uint8_t)(((FX_WORD)(rgb)) >> 8)) +#define GetBlue(rgb) ((uint8_t)((rgb)>>16)) -#define FFL_HINT_ELAPSE 800 +#define FFL_HINT_ELAPSE 800 /* ------------------------- CFFL_FormFiller ------------------------- */ CFFL_FormFiller::CFFL_FormFiller(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot) - :m_pApp(pApp), - m_pAnnot(pAnnot), - m_bValid(FALSE), - m_ptOldPos(0,0) + : m_pApp(pApp), + m_pAnnot(pAnnot), + m_bValid(FALSE), + m_ptOldPos(0,0) { - m_pWidget = (CPDFSDK_Widget*) pAnnot; + m_pWidget = (CPDFSDK_Widget*) pAnnot; } CFFL_FormFiller::~CFFL_FormFiller() @@ -40,75 +40,72 @@ CFFL_FormFiller::~CFFL_FormFiller() void CFFL_FormFiller::SetWindowRect(CPDFSDK_PageView* pPageView, const CPDF_Rect& rcWindow) { - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) - { - pWnd->Move(CPDF_Rect(rcWindow), TRUE, FALSE); - } + if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) + { + pWnd->Move(CPDF_Rect(rcWindow), TRUE, FALSE); + } } CPDF_Rect CFFL_FormFiller::GetWindowRect(CPDFSDK_PageView* pPageView) { - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) - { - return pWnd->GetWindowRect(); - } + if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) + { + return pWnd->GetWindowRect(); + } - return CPDF_Rect(0,0,0,0); + return CPDF_Rect(0,0,0,0); } FX_RECT CFFL_FormFiller::GetViewBBox(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot) { - ASSERT(pPageView != NULL); - ASSERT(pAnnot != NULL); + ASSERT(pPageView != NULL); + ASSERT(pAnnot != NULL); - CPDF_Rect rcAnnot = m_pWidget->GetRect(); + CPDF_Rect rcAnnot = m_pWidget->GetRect(); - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) - { - CPDF_Rect rcWindow = pWnd->GetWindowRect(); - rcAnnot = PWLtoFFL(rcWindow); - } + if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) + { + CPDF_Rect rcWindow = pWnd->GetWindowRect(); + rcAnnot = PWLtoFFL(rcWindow); + } - CPDF_Rect rcWin = rcAnnot; + CPDF_Rect rcWin = rcAnnot; - CPDF_Rect rcFocus = GetFocusBox(pPageView); - if (!rcFocus.IsEmpty()) - rcWin.Union(rcFocus); + CPDF_Rect rcFocus = GetFocusBox(pPageView); + if (!rcFocus.IsEmpty()) + rcWin.Union(rcFocus); - CPDF_Rect rect = CPWL_Utils::InflateRect(rcWin,1); + CPDF_Rect rect = CPWL_Utils::InflateRect(rcWin,1); - return rect.GetOutterRect(); + return rect.GetOutterRect(); } -void CFFL_FormFiller::OnDraw(CPDFSDK_PageView *pPageView, /*HDC hDC,*/ CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, - /*const CRect& rcWindow,*/ FX_DWORD dwFlags) +void CFFL_FormFiller::OnDraw(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, + FX_DWORD dwFlags) { - ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget"); + ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget"); - if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE)) - { - CPDF_Matrix mt = GetCurMatrix(); - mt.Concat(*pUser2Device); - pWnd->DrawAppearance(pDevice,&mt); - } - else - { - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - if (CFFL_IFormFiller::IsVisible(pWidget)) - pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); - } + if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE)) + { + CPDF_Matrix mt = GetCurMatrix(); + mt.Concat(*pUser2Device); + pWnd->DrawAppearance(pDevice,&mt); + } + else + { + CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; + if (CFFL_IFormFiller::IsVisible(pWidget)) + pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); + } } -void CFFL_FormFiller::OnDrawDeactive(CPDFSDK_PageView *pPageView, /*HDC hDC,*/ CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, - /*const CRect& rcWindow,*/ FX_DWORD dwFlags) +void CFFL_FormFiller::OnDrawDeactive(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, + FX_DWORD dwFlags) { - ASSERT(pAnnot != NULL); - - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - - pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); + CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; + pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); } @@ -130,293 +127,268 @@ void CFFL_FormFiller::OnMouseEnter(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* p void CFFL_FormFiller::OnMouseExit(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot) { - EndTimer(); - ASSERT(m_pWidget != NULL); + EndTimer(); + ASSERT(m_pWidget != NULL); } FX_BOOL CFFL_FormFiller::OnLButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point) { - if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, TRUE)) - { - m_bValid = TRUE; - FX_RECT rect = GetViewBBox(pPageView,pAnnot); - InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); + if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, TRUE)) + { + m_bValid = TRUE; + FX_RECT rect = GetViewBBox(pPageView,pAnnot); + InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); - if(!rect.Contains((int)point.x, (int)point.y)) - return FALSE; + if(!rect.Contains((int)point.x, (int)point.y)) + return FALSE; - return pWnd->OnLButtonDown(WndtoPWL(pPageView, point),nFlags); - } + return pWnd->OnLButtonDown(WndtoPWL(pPageView, point),nFlags); + } - return FALSE; + return FALSE; } -FX_BOOL CFFL_FormFiller::OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point) +FX_BOOL CFFL_FormFiller::OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point) { - if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE)) - { - FX_RECT rcFFL = GetViewBBox(pPageView, pAnnot); - InvalidateRect(rcFFL.left, rcFFL.top, rcFFL.right, rcFFL.bottom); - pWnd->OnLButtonUp(WndtoPWL(pPageView, point),nFlags); - return TRUE; - } + if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE)) + { + FX_RECT rcFFL = GetViewBBox(pPageView, pAnnot); + InvalidateRect(rcFFL.left, rcFFL.top, rcFFL.right, rcFFL.bottom); + pWnd->OnLButtonUp(WndtoPWL(pPageView, point),nFlags); + return TRUE; + } - return FALSE; + return FALSE; } -FX_BOOL CFFL_FormFiller::OnLButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point) +FX_BOOL CFFL_FormFiller::OnLButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point) { - if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE)) - { - pWnd->OnLButtonDblClk(WndtoPWL(pPageView, point),nFlags); - return TRUE; - } + if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE)) + { + pWnd->OnLButtonDblClk(WndtoPWL(pPageView, point),nFlags); + return TRUE; + } - return FALSE; + return FALSE; } FX_BOOL CFFL_FormFiller::OnMouseMove(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point) { - if ((m_ptOldPos.x != point.x) || (m_ptOldPos.y != point.y)) - { - m_ptOldPos = point; - } + if ((m_ptOldPos.x != point.x) || (m_ptOldPos.y != point.y)) + { + m_ptOldPos = point; + } - if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE)) - { - pWnd->OnMouseMove(WndtoPWL(pPageView, point),nFlags); - return TRUE; - } + if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE)) + { + pWnd->OnMouseMove(WndtoPWL(pPageView, point),nFlags); + return TRUE; + } - return FALSE; + return FALSE; } FX_BOOL CFFL_FormFiller::OnMouseWheel(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, short zDelta, const CPDF_Point& point) { - if (!IsValid()) return FALSE; + if (!IsValid()) return FALSE; - if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, TRUE)) - { - return pWnd->OnMouseWheel(zDelta, WndtoPWL(pPageView, point),nFlags); - } + if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, TRUE)) + { + return pWnd->OnMouseWheel(zDelta, WndtoPWL(pPageView, point),nFlags); + } - return FALSE; + return FALSE; } FX_BOOL CFFL_FormFiller::OnRButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point) { - if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, TRUE)) - { - pWnd->OnRButtonDown(WndtoPWL(pPageView, point),nFlags); - return TRUE; - } + if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, TRUE)) + { + pWnd->OnRButtonDown(WndtoPWL(pPageView, point),nFlags); + return TRUE; + } - return FALSE; + return FALSE; } -FX_BOOL CFFL_FormFiller::OnRButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point) +FX_BOOL CFFL_FormFiller::OnRButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point) { - if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE)) - { - pWnd->OnRButtonUp(WndtoPWL(pPageView, point),nFlags); - return TRUE; - } + if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE)) + { + pWnd->OnRButtonUp(WndtoPWL(pPageView, point),nFlags); + return TRUE; + } - return FALSE; + return FALSE; } -FX_BOOL CFFL_FormFiller::OnRButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point) +FX_BOOL CFFL_FormFiller::OnRButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point) { - if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE)) - { - pWnd->OnRButtonDblClk(WndtoPWL(pPageView, point),nFlags); - return TRUE; - } + if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE)) + { + pWnd->OnRButtonDblClk(WndtoPWL(pPageView, point),nFlags); + return TRUE; + } - return FALSE; + return FALSE; } FX_BOOL CFFL_FormFiller::OnKeyDown(CPDFSDK_Annot* pAnnot, FX_UINT nKeyCode, FX_UINT nFlags) { - if (IsValid()) - { - CPDFSDK_PageView* pPageView = GetCurPageView(); - ASSERT(pPageView != NULL); + if (IsValid()) + { + CPDFSDK_PageView* pPageView = GetCurPageView(); + ASSERT(pPageView != NULL); - if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE)) - { - return pWnd->OnKeyDown(nKeyCode,nFlags); - } - } + if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE)) + { + return pWnd->OnKeyDown(nKeyCode,nFlags); + } + } - return FALSE; + return FALSE; } -FX_BOOL CFFL_FormFiller::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags) +FX_BOOL CFFL_FormFiller::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags) { - if (IsValid()) - { - CPDFSDK_PageView* pPageView = GetCurPageView(); - ASSERT(pPageView != NULL); + if (IsValid()) + { + CPDFSDK_PageView* pPageView = GetCurPageView(); + ASSERT(pPageView != NULL); - if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE)) - { - return pWnd->OnChar(nChar,nFlags); - } - } + if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE)) + { + return pWnd->OnChar(nChar,nFlags); + } + } - return FALSE; + return FALSE; } void CFFL_FormFiller::OnDeSelected(CPDFSDK_Annot* pAnnot) { - ASSERT(FALSE); + ASSERT(FALSE); } void CFFL_FormFiller::OnSelected(CPDFSDK_Annot* pAnnot) { - ASSERT(FALSE); + ASSERT(FALSE); } -FX_BOOL CFFL_FormFiller::OnSetFocus(CPDFSDK_Annot* pAnnot, FX_UINT nFlag) +FX_BOOL CFFL_FormFiller::OnSetFocus(CPDFSDK_Annot* pAnnot, FX_UINT nFlag) { - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - - CPDFXFA_Page * pPage = pWidget->GetPDFXFAPage(); - CPDFSDK_Document * pDoc = m_pApp->GetCurrentDoc(); - CPDFSDK_PageView* pPageView = pDoc->GetPageView(pPage); - ASSERT(pPageView != NULL); - - - - CPWL_Wnd * pWnd = NULL; - if ( (pWnd = GetPDFWindow(pPageView, TRUE))) - { - pWnd->SetFocus(); - } - - m_bValid = TRUE; - - + CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; + CPDFXFA_Page* pPage = pWidget->GetPDFXFAPage(); + CPDFSDK_Document* pDoc = m_pApp->GetSDKDocument(); + CPDFSDK_PageView* pPageView = pDoc->GetPageView(pPage); + if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, TRUE)) + pWnd->SetFocus(); - - m_bValid = TRUE; - FX_RECT rcRect = GetViewBBox(pPageView,pAnnot); - InvalidateRect(rcRect.left, rcRect.top, rcRect.right, rcRect.bottom); - - return TRUE; + m_bValid = TRUE; + FX_RECT rcRect = GetViewBBox(pPageView,pAnnot); + InvalidateRect(rcRect.left, rcRect.top, rcRect.right, rcRect.bottom); + return TRUE; } -FX_BOOL CFFL_FormFiller::OnKillFocus(CPDFSDK_Annot* pAnnot, FX_UINT nFlag) +FX_BOOL CFFL_FormFiller::OnKillFocus(CPDFSDK_Annot* pAnnot, FX_UINT nFlag) { - if (IsValid()) - { - CPDFSDK_PageView* pPageView = GetCurPageView(); - ASSERT(pPageView != NULL); + if (!IsValid()) + return TRUE; - CommitData(pPageView, nFlag); + CPDFSDK_PageView* pPageView = GetCurPageView(); + CommitData(pPageView, nFlag); - if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) - { - pWnd->KillFocus(); - } + if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) + pWnd->KillFocus(); - switch (m_pWidget->GetFieldType()) - { - case FIELDTYPE_PUSHBUTTON: - case FIELDTYPE_CHECKBOX: - case FIELDTYPE_RADIOBUTTON: - EscapeFiller(pPageView, TRUE); - break; - default: - EscapeFiller(pPageView, FALSE); - break; - } - } - - return TRUE; + switch (m_pWidget->GetFieldType()) + { + case FIELDTYPE_PUSHBUTTON: + case FIELDTYPE_CHECKBOX: + case FIELDTYPE_RADIOBUTTON: + EscapeFiller(pPageView, TRUE); + break; + default: + EscapeFiller(pPageView, FALSE); + break; + } + return TRUE; } -FX_BOOL CFFL_FormFiller::IsValid() const +FX_BOOL CFFL_FormFiller::IsValid() const { - return m_bValid; + return m_bValid; } -PWL_CREATEPARAM CFFL_FormFiller::GetCreateParam() +PWL_CREATEPARAM CFFL_FormFiller::GetCreateParam() { - ASSERT(m_pApp != NULL); - - PWL_CREATEPARAM cp; - - cp.pParentWnd = NULL; - cp.pProvider = this; - cp.rcRectWnd = GetPDFWindowRect(); - - FX_DWORD dwCreateFlags = PWS_BORDER | PWS_BACKGROUND | PWS_VISIBLE; - - ASSERT(m_pWidget != NULL); + ASSERT(m_pApp != NULL); + PWL_CREATEPARAM cp; + cp.pParentWnd = NULL; + cp.pProvider = this; + cp.rcRectWnd = GetPDFWindowRect(); - FX_DWORD dwFieldFlag = m_pWidget->GetFieldFlags(); - - if (dwFieldFlag & FIELDFLAG_READONLY) - { - dwCreateFlags |= PWS_READONLY; - } - - FX_COLORREF color; - if (m_pWidget->GetFillColor(color)) - { - cp.sBackgroundColor = CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color)); - } - - if (m_pWidget->GetBorderColor(color)) - { - cp.sBorderColor = CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color)); - } + FX_DWORD dwCreateFlags = PWS_BORDER | PWS_BACKGROUND | PWS_VISIBLE; + FX_DWORD dwFieldFlag = m_pWidget->GetFieldFlags(); + if (dwFieldFlag & FIELDFLAG_READONLY) + { + dwCreateFlags |= PWS_READONLY; + } - cp.sTextColor = CPWL_Color(COLORTYPE_GRAY,0); + FX_COLORREF color; + if (m_pWidget->GetFillColor(color)) + { + cp.sBackgroundColor = CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color)); + } - if (m_pWidget->GetTextColor(color)) - { - cp.sTextColor = CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color)); - } + if (m_pWidget->GetBorderColor(color)) + { + cp.sBorderColor = CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color)); + } - cp.fFontSize = m_pWidget->GetFontSize(); - cp.dwBorderWidth = m_pWidget->GetBorderWidth(); + cp.sTextColor = CPWL_Color(COLORTYPE_GRAY,0); - int nBorderStyle = m_pWidget->GetBorderStyle(); + if (m_pWidget->GetTextColor(color)) + { + cp.sTextColor = CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color)); + } - switch (nBorderStyle) - { - case BBS_SOLID: - cp.nBorderStyle = PBS_SOLID; - break; - case BBS_DASH: - cp.nBorderStyle = PBS_DASH; - cp.sDash = CPWL_Dash(3,3,0); - break; - case BBS_BEVELED: - cp.nBorderStyle = PBS_BEVELED; - cp.dwBorderWidth *= 2; - break; - case BBS_INSET: - cp.nBorderStyle = PBS_INSET; - cp.dwBorderWidth *= 2; - break; - case BBS_UNDERLINE: - cp.nBorderStyle = PBS_UNDERLINED; - break; - } + cp.fFontSize = m_pWidget->GetFontSize(); + cp.dwBorderWidth = m_pWidget->GetBorderWidth(); + + int nBorderStyle = m_pWidget->GetBorderStyle(); + + switch (nBorderStyle) + { + case BBS_SOLID: + cp.nBorderStyle = PBS_SOLID; + break; + case BBS_DASH: + cp.nBorderStyle = PBS_DASH; + cp.sDash = CPWL_Dash(3,3,0); + break; + case BBS_BEVELED: + cp.nBorderStyle = PBS_BEVELED; + cp.dwBorderWidth *= 2; + break; + case BBS_INSET: + cp.nBorderStyle = PBS_INSET; + cp.dwBorderWidth *= 2; + break; + case BBS_UNDERLINE: + cp.nBorderStyle = PBS_UNDERLINED; + break; + } - if (cp.fFontSize <= 0) - { - dwCreateFlags |= PWS_AUTOFONTSIZE; - } + if (cp.fFontSize <= 0) + { + dwCreateFlags |= PWS_AUTOFONTSIZE; + } - cp.dwFlags = dwCreateFlags; - cp.pSystemHandler = m_pApp->GetSysHandler(); - return cp; + cp.dwFlags = dwCreateFlags; + cp.pSystemHandler = m_pApp->GetSysHandler(); + return cp; } CPWL_Wnd* CFFL_FormFiller::GetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bNew) @@ -470,218 +442,186 @@ void CFFL_FormFiller::DestroyPDFWindow(CPDFSDK_PageView* pPageView) m_Maps.erase(it); } -CPDF_Matrix CFFL_FormFiller::GetWindowMatrix(void* pAttachedData) +CPDF_Matrix CFFL_FormFiller::GetWindowMatrix(void* pAttachedData) { - if (CFFL_PrivateData* pPrivateData = (CFFL_PrivateData*)pAttachedData) - { - if (pPrivateData->pPageView) - { - CPDF_Matrix mtPageView; - pPrivateData->pPageView->GetCurrentMatrix(mtPageView); - CPDF_Matrix mt = GetCurMatrix(); - mt.Concat(mtPageView); + if (CFFL_PrivateData* pPrivateData = (CFFL_PrivateData*)pAttachedData) + { + if (pPrivateData->pPageView) + { + CPDF_Matrix mtPageView; + pPrivateData->pPageView->GetCurrentMatrix(mtPageView); + CPDF_Matrix mt = GetCurMatrix(); + mt.Concat(mtPageView); - return mt; - } - } - return CPDF_Matrix(1,0,0,1,0,0); + return mt; + } + } + return CPDF_Matrix(1,0,0,1,0,0); } -CPDF_Matrix CFFL_FormFiller::GetCurMatrix() +CPDF_Matrix CFFL_FormFiller::GetCurMatrix() { - CPDF_Matrix mt; + CPDF_Matrix mt; - ASSERT(m_pWidget != NULL); + ASSERT(m_pWidget != NULL); - CPDF_Rect rcDA ; - m_pWidget->GetPDFAnnot()->GetRect(rcDA); + CPDF_Rect rcDA ; + m_pWidget->GetPDFAnnot()->GetRect(rcDA); - switch (m_pWidget->GetRotate()) - { - default: - case 0: - mt = CPDF_Matrix(1,0,0,1,0,0); - break; - case 90: - mt = CPDF_Matrix(0,1,-1,0,rcDA.right - rcDA.left,0); - break; - case 180: - mt = CPDF_Matrix(-1,0,0,-1,rcDA.right - rcDA.left,rcDA.top - rcDA.bottom); - break; - case 270: - mt = CPDF_Matrix(0,-1,1,0,0,rcDA.top - rcDA.bottom); - break; - } - mt.e += rcDA.left; - mt.f += rcDA.bottom; + switch (m_pWidget->GetRotate()) + { + default: + case 0: + mt = CPDF_Matrix(1,0,0,1,0,0); + break; + case 90: + mt = CPDF_Matrix(0,1,-1,0,rcDA.right - rcDA.left,0); + break; + case 180: + mt = CPDF_Matrix(-1,0,0,-1,rcDA.right - rcDA.left,rcDA.top - rcDA.bottom); + break; + case 270: + mt = CPDF_Matrix(0,-1,1,0,0,rcDA.top - rcDA.bottom); + break; + } + mt.e += rcDA.left; + mt.f += rcDA.bottom; - return mt; + return mt; } CFX_WideString CFFL_FormFiller::LoadPopupMenuString(int nIndex) { - ASSERT(m_pApp != NULL); + ASSERT(m_pApp != NULL); - return L""; + return L""; } CPDF_Rect CFFL_FormFiller::GetPDFWindowRect() const { - ASSERT(m_pWidget != NULL); - - CPDF_Rect rectAnnot; - m_pWidget->GetPDFAnnot()->GetRect(rectAnnot); + CPDF_Rect rectAnnot; + m_pWidget->GetPDFAnnot()->GetRect(rectAnnot); - FX_FLOAT fWidth = rectAnnot.right - rectAnnot.left; - FX_FLOAT fHeight = rectAnnot.top - rectAnnot.bottom; + FX_FLOAT fWidth = rectAnnot.right - rectAnnot.left; + FX_FLOAT fHeight = rectAnnot.top - rectAnnot.bottom; + if ((m_pWidget->GetRotate() / 90) & 0x01) + return CPDF_Rect(0, 0, fHeight, fWidth); - - if ((m_pWidget->GetRotate() / 90) & 0x01) - return CPDF_Rect(0,0,fHeight,fWidth); - else - return CPDF_Rect(0,0,fWidth,fHeight); + return CPDF_Rect(0, 0, fWidth, fHeight); } CPDFSDK_PageView* CFFL_FormFiller::GetCurPageView() { - - CPDFXFA_Page* pPage = m_pAnnot->GetPDFXFAPage(); - CPDFSDK_Document* pSDKDoc = m_pApp->GetCurrentDoc(); - if(pSDKDoc) - { - return pSDKDoc->GetPageView(pPage); - } - return NULL; + CPDFXFA_Page* pPage = m_pAnnot->GetPDFXFAPage(); + CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument(); + if (!pSDKDoc) + return NULL; + return pSDKDoc->GetPageView(pPage); } CPDF_Rect CFFL_FormFiller::GetFocusBox(CPDFSDK_PageView* pPageView) { - if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE)) - { - CPDF_Rect rcFocus = FFLtoWnd(pPageView, PWLtoFFL(pWnd->GetFocusRect())); - ASSERT(pPageView); - CPDF_Rect rcPage = pPageView->GetPDFPage()->GetPageBBox(); - if(rcPage.Contains(rcFocus)) - return rcFocus; - else - return CPDF_Rect(0,0,0,0); - } - return CPDF_Rect(0,0,0,0); + if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) + { + CPDF_Rect rcFocus = FFLtoWnd(pPageView, PWLtoFFL(pWnd->GetFocusRect())); + CPDF_Rect rcPage = pPageView->GetPDFPage()->GetPageBBox(); + if (rcPage.Contains(rcFocus)) + return rcFocus; + } + return CPDF_Rect(0,0,0,0); } CPDF_Rect CFFL_FormFiller::FFLtoPWL(const CPDF_Rect& rect) { - CPDF_Matrix mt; - mt.SetReverse(GetCurMatrix()); + CPDF_Matrix mt; + mt.SetReverse(GetCurMatrix()); - CPDF_Rect temp = rect; - mt.TransformRect(temp); + CPDF_Rect temp = rect; + mt.TransformRect(temp); - return temp; + return temp; } CPDF_Rect CFFL_FormFiller::PWLtoFFL(const CPDF_Rect& rect) { - CPDF_Matrix mt = GetCurMatrix(); + CPDF_Matrix mt = GetCurMatrix(); - CPDF_Rect temp = rect; - mt.TransformRect(temp); + CPDF_Rect temp = rect; + mt.TransformRect(temp); - return temp; + return temp; } CPDF_Point CFFL_FormFiller::FFLtoPWL(const CPDF_Point& point) { - CPDF_Matrix mt; - mt.SetReverse(GetCurMatrix()); + CPDF_Matrix mt; + mt.SetReverse(GetCurMatrix()); - CPDF_Point pt = point; - mt.Transform(pt.x,pt.y); + CPDF_Point pt = point; + mt.Transform(pt.x,pt.y); - return pt; + return pt; } CPDF_Point CFFL_FormFiller::PWLtoFFL(const CPDF_Point & point) { - CPDF_Matrix mt = GetCurMatrix(); + CPDF_Matrix mt = GetCurMatrix(); - CPDF_Point pt = point; - mt.Transform(pt.x,pt.y); + CPDF_Point pt = point; + mt.Transform(pt.x,pt.y); - return pt; + return pt; } CPDF_Point CFFL_FormFiller::WndtoPWL(CPDFSDK_PageView* pPageView, const CPDF_Point& pt) { -// ASSERT(pPageView != NULL); -// -// CPDF_Point point(0.0f, 0.0f); -// pPageView->WindowToDoc(pt.x, pt.y, point.x, point.y); -// - return FFLtoPWL(pt); -// return CPDF_Point(0, 0); + return FFLtoPWL(pt); } CPDF_Rect CFFL_FormFiller::FFLtoWnd(CPDFSDK_PageView* pPageView, const CPDF_Rect & rect) { -// FX_RECT rcRet(0,0,0,0); -// -// ASSERT(pPageView != NULL); -// pPageView->DocToWindow(rect, rcRet); -// - return rect; - -} - -void CFFL_FormFiller::FFL_FreeData(void* pData) -{ - ASSERT(pData != NULL); - - delete (CFFL_PrivateData*)pData; + return rect; } FX_BOOL CFFL_FormFiller::CommitData(CPDFSDK_PageView* pPageView, FX_UINT nFlag) { - if (IsDataChanged(pPageView)) - { - //CFFL_IFormFiller* pIFormFiller = CFFL_Module::GetFormFiller(m_pApp); - CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller();//NULL; - ASSERT(pIFormFiller != NULL); - - FX_BOOL bRC = TRUE; - FX_BOOL bExit = FALSE; - - pIFormFiller->OnKeyStrokeCommit(m_pWidget, pPageView, bRC, bExit, nFlag); - if (bExit) return TRUE; - if (!bRC) - { - ResetPDFWindow(pPageView, FALSE); - return TRUE; - } - - pIFormFiller->OnValidate(m_pWidget, pPageView, bRC, bExit, nFlag); - if (bExit) return TRUE; - if (!bRC) - { - ResetPDFWindow(pPageView, FALSE); - return TRUE; - } - - SaveData(pPageView); - - pIFormFiller->OnCalculate(m_pWidget, pPageView, bExit,nFlag); - if (bExit) return TRUE; - - pIFormFiller->OnFormat(m_pWidget, pPageView, bExit,nFlag); - } - - return TRUE; + if (IsDataChanged(pPageView)) + { + FX_BOOL bRC = TRUE; + FX_BOOL bExit = FALSE; + CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller(); + pIFormFiller->OnKeyStrokeCommit(m_pWidget, pPageView, bRC, bExit, nFlag); + if (bExit) + return TRUE; + if (!bRC) + { + ResetPDFWindow(pPageView, FALSE); + return TRUE; + } + + pIFormFiller->OnValidate(m_pWidget, pPageView, bRC, bExit, nFlag); + if (bExit) + return TRUE; + if (!bRC) + { + ResetPDFWindow(pPageView, FALSE); + return TRUE; + } + + SaveData(pPageView); + pIFormFiller->OnCalculate(m_pWidget, pPageView, bExit,nFlag); + if (bExit) + return TRUE; + + pIFormFiller->OnFormat(m_pWidget, pPageView, bExit,nFlag); + } + return TRUE; } -FX_BOOL CFFL_FormFiller::IsDataChanged(CPDFSDK_PageView* pPageView) +FX_BOOL CFFL_FormFiller::IsDataChanged(CPDFSDK_PageView* pPageView) { - return FALSE; + return FALSE; } void CFFL_FormFiller::SaveData(CPDFSDK_PageView* pPageView) @@ -694,29 +634,29 @@ void CFFL_FormFiller::GetKeyStrokeData(CPDFSDK_PageView* pPageView, FFL_KeyStrok FX_BOOL CFFL_FormFiller::IsFieldFull(CPDFSDK_PageView* pPageView) { - return FALSE; + return FALSE; } void CFFL_FormFiller::SetChangeMark() { - m_pApp->FFI_OnChange(); + m_pApp->FFI_OnChange(); } void CFFL_FormFiller::GetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type, - PDFSDK_FieldAction& fa) + PDFSDK_FieldAction& fa) { - fa.sValue = m_pWidget->GetValue(); + fa.sValue = m_pWidget->GetValue(); } void CFFL_FormFiller::SetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type, - const PDFSDK_FieldAction& fa) + const PDFSDK_FieldAction& fa) { } -FX_BOOL CFFL_FormFiller::IsActionDataChanged(CPDF_AAction::AActionType type, const PDFSDK_FieldAction& faOld, - const PDFSDK_FieldAction& faNew) +FX_BOOL CFFL_FormFiller::IsActionDataChanged(CPDF_AAction::AActionType type, const PDFSDK_FieldAction& faOld, + const PDFSDK_FieldAction& faNew) { - return FALSE; + return FALSE; } void CFFL_FormFiller::SaveState(CPDFSDK_PageView* pPageView) @@ -729,7 +669,7 @@ void CFFL_FormFiller::RestoreState(CPDFSDK_PageView* pPageView) CPWL_Wnd* CFFL_FormFiller::ResetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bRestoreValue) { - return GetPDFWindow(pPageView, FALSE); + return GetPDFWindow(pPageView, FALSE); } void CFFL_FormFiller::TimerProc() @@ -739,8 +679,7 @@ void CFFL_FormFiller::TimerProc() IFX_SystemHandler* CFFL_FormFiller::GetSystemHandler() const { - return m_pApp->GetSysHandler(); -// return NULL; + return m_pApp->GetSysHandler(); } void CFFL_FormFiller::OnKeyStroke(FX_BOOL bKeyDown) @@ -749,28 +688,28 @@ void CFFL_FormFiller::OnKeyStroke(FX_BOOL bKeyDown) void CFFL_FormFiller::EscapeFiller(CPDFSDK_PageView* pPageView, FX_BOOL bDestroyPDFWindow) { - m_bValid = FALSE; + m_bValid = FALSE; - FX_RECT rcRect = GetViewBBox(pPageView, m_pWidget); - InvalidateRect(rcRect.left, rcRect.top, rcRect.right, rcRect.bottom); + FX_RECT rcRect = GetViewBBox(pPageView, m_pWidget); + InvalidateRect(rcRect.left, rcRect.top, rcRect.right, rcRect.bottom); - if(bDestroyPDFWindow) - DestroyPDFWindow(pPageView); + if(bDestroyPDFWindow) + DestroyPDFWindow(pPageView); } FX_BOOL CFFL_FormFiller::CanCopy(CPDFSDK_Document* pDocument) { - return FALSE; + return FALSE; } FX_BOOL CFFL_FormFiller::CanCut(CPDFSDK_Document* pDocument) { - return FALSE; + return FALSE; } -FX_BOOL CFFL_FormFiller::CanPaste(CPDFSDK_Document* pDocument) +FX_BOOL CFFL_FormFiller::CanPaste(CPDFSDK_Document* pDocument) { - return FALSE; + return FALSE; } void CFFL_FormFiller::DoCopy(CPDFSDK_Document* pDocument) @@ -787,16 +726,16 @@ void CFFL_FormFiller::DoPaste(CPDFSDK_Document* pDocument) void CFFL_FormFiller::InvalidateRect(double left, double top, double right, double bottom) { - CPDFXFA_Page * pPage = m_pWidget->GetPDFXFAPage(); - m_pApp->FFI_Invalidate(pPage, left, top, right, bottom); + CPDFXFA_Page* pPage = m_pWidget->GetPDFXFAPage(); + m_pApp->FFI_Invalidate(pPage, left, top, right, bottom); } /* ------------------------- CFFL_Button ------------------------- */ CFFL_Button::CFFL_Button(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget) : - CFFL_FormFiller(pApp, pWidget), - m_bMouseIn(FALSE), - m_bMouseDown(FALSE) + CFFL_FormFiller(pApp, pWidget), + m_bMouseIn(FALSE), + m_bMouseDown(FALSE) { } @@ -806,99 +745,94 @@ CFFL_Button::~CFFL_Button() void CFFL_Button::OnMouseEnter(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot) { - m_bMouseIn = TRUE; - FX_RECT rect = GetViewBBox(pPageView,pAnnot); - InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); + m_bMouseIn = TRUE; + FX_RECT rect = GetViewBBox(pPageView,pAnnot); + InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); } void CFFL_Button::OnMouseExit(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot) { - m_bMouseIn = FALSE; + m_bMouseIn = FALSE; - FX_RECT rect = GetViewBBox(pPageView,pAnnot); - InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); - EndTimer(); - ASSERT(m_pWidget != NULL); + FX_RECT rect = GetViewBBox(pPageView,pAnnot); + InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); + EndTimer(); + ASSERT(m_pWidget != NULL); } FX_BOOL CFFL_Button::OnLButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point) { - CPDF_Rect rcAnnot = pAnnot->GetRect(); - if(!rcAnnot.Contains(point.x, point.y)) - return FALSE; + CPDF_Rect rcAnnot = pAnnot->GetRect(); + if(!rcAnnot.Contains(point.x, point.y)) + return FALSE; - m_bMouseDown = TRUE; - m_bValid = TRUE; - FX_RECT rect = GetViewBBox(pPageView, pAnnot); - InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); - return TRUE; + m_bMouseDown = TRUE; + m_bValid = TRUE; + FX_RECT rect = GetViewBBox(pPageView, pAnnot); + InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); + return TRUE; } -FX_BOOL CFFL_Button::OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point) +FX_BOOL CFFL_Button::OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point) { - CPDF_Rect rcAnnot = pAnnot->GetRect(); - if(!rcAnnot.Contains(point.x, point.y)) - return FALSE; + CPDF_Rect rcAnnot = pAnnot->GetRect(); + if(!rcAnnot.Contains(point.x, point.y)) + return FALSE; - m_bMouseDown = FALSE; - m_pWidget->GetPDFPage(); + m_bMouseDown = FALSE; + m_pWidget->GetPDFPage(); - FX_RECT rect = GetViewBBox(pPageView, pAnnot); - InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); - return TRUE; + FX_RECT rect = GetViewBBox(pPageView, pAnnot); + InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); + return TRUE; } -FX_BOOL CFFL_Button::OnMouseMove(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point) +FX_BOOL CFFL_Button::OnMouseMove(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point) { - ASSERT(m_pApp != NULL); + ASSERT(m_pApp != NULL); - return TRUE; + return TRUE; } -void CFFL_Button::OnDraw(CPDFSDK_PageView *pPageView, /*HDC hDC,*/ CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, - /*const CRect& rcWindow,*/ FX_DWORD dwFlags) +void CFFL_Button::OnDraw(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, + FX_DWORD dwFlags) { - ASSERT(pPageView != NULL); - ASSERT(pAnnot != NULL); + ASSERT(pPageView != NULL); + CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; + CPDF_FormControl* pCtrl = pWidget->GetFormControl(); + CPDF_FormControl::HighlightingMode eHM = pCtrl->GetHighlightingMode(); - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - - CPDF_FormControl* pCtrl = pWidget->GetFormControl(); - ASSERT(pCtrl != NULL); - - CPDF_FormControl::HighlightingMode eHM = pCtrl->GetHighlightingMode(); - - if (eHM == CPDF_FormControl::Push) - { - if (m_bMouseDown) - { - if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::Down)) - pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Down, NULL); - else - pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); - } - else if (m_bMouseIn) - { - if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::Rollover)) - pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Rollover, NULL); - else - pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); - } - else - { - pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); - } - } - else - pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); + if (eHM == CPDF_FormControl::Push) + { + if (m_bMouseDown) + { + if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::Down)) + pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Down, NULL); + else + pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); + } + else if (m_bMouseIn) + { + if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::Rollover)) + pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Rollover, NULL); + else + pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); + } + else + { + pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); + } + } + else + pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); } -void CFFL_Button::OnDrawDeactive(CPDFSDK_PageView *pPageView, /*HDC hDC,*/ CPDFSDK_Annot* pAnnot, - CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, - /*const CRect& rcWindow, */FX_DWORD dwFlags) +void CFFL_Button::OnDrawDeactive(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, + CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, + FX_DWORD dwFlags) { - OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags); + OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags); } diff --git a/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp b/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp index 66ae237a31..dccb0408cf 100644 --- a/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp +++ b/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp @@ -81,20 +81,15 @@ void CFFL_IFormFiller::OnDraw(CPDFSDK_PageView* pPageView, /*HDC hDC,*/ CPDFSDK_ if (pFormFiller->IsValid()) { pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags); - pAnnot->GetPDFPage(); - - CPDFSDK_Document* pDocument = m_pApp->GetCurrentDoc(); - ASSERT(pDocument != NULL); - + CPDFSDK_Document* pDocument = m_pApp->GetSDKDocument(); if (pDocument->GetFocusAnnot() == pAnnot) { CPDF_Rect rcFocus = pFormFiller->GetFocusBox(pPageView); if (!rcFocus.IsEmpty()) { CFX_PathData path; - path.SetPointCount(5); path.SetPoint(0, rcFocus.left, rcFocus.top, FXPT_MOVETO); path.SetPoint(1, rcFocus.left, rcFocus.bottom, FXPT_LINETO); @@ -106,14 +101,10 @@ void CFFL_IFormFiller::OnDraw(CPDFSDK_PageView* pPageView, /*HDC hDC,*/ CPDFSDK_ gsd.SetDashCount(1); gsd.m_DashArray[0] = 1.0f; gsd.m_DashPhase = 0; - gsd.m_LineWidth = 1.0f; pDevice->DrawPath(&path, pUser2Device, &gsd, 0, ArgbEncode(255,0,0,0), FXFILL_ALTERNATE); - - // ::DrawFocusRect(hDC, &rcFocus); } } - return; } } @@ -124,10 +115,7 @@ void CFFL_IFormFiller::OnDraw(CPDFSDK_PageView* pPageView, /*HDC hDC,*/ CPDFSDK_ pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); if (!IsReadOnly(pWidget) && IsFillingAllowed(pWidget)) - { pWidget->DrawShadow(pDevice, pPageView); - } - } } @@ -292,14 +280,9 @@ FX_BOOL CFFL_IFormFiller::OnLButtonDown(CPDFSDK_PageView* pPageView, CPDFSDK_Ann FX_BOOL CFFL_IFormFiller::OnLButtonUp(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point) { - ASSERT(pAnnot != NULL); ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget"); - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - // CReader_Page* pPage = pAnnot->GetPage(); - // ASSERT(pPage != NULL); - CPDFSDK_Document* pDocument = m_pApp->GetCurrentDoc(); - ASSERT(pDocument != NULL); + CPDFSDK_Document* pDocument = m_pApp->GetSDKDocument(); switch (pWidget->GetFieldType()) { @@ -307,9 +290,7 @@ FX_BOOL CFFL_IFormFiller::OnLButtonUp(CPDFSDK_PageView* pPageView, CPDFSDK_Annot case FIELDTYPE_CHECKBOX: case FIELDTYPE_RADIOBUTTON: if (GetViewBBox(pPageView, pAnnot).Contains((int)point.x, (int)point.y)) - { pDocument->SetFocusAnnot(pAnnot); - } break; default: pDocument->SetFocusAnnot(pAnnot); diff --git a/fpdfsdk/src/fpdfformfill.cpp b/fpdfsdk/src/fpdfformfill.cpp index 8087bb1d70..20beedd84a 100644 --- a/fpdfsdk/src/fpdfformfill.cpp +++ b/fpdfsdk/src/fpdfformfill.cpp @@ -15,701 +15,597 @@ #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 = ((CPDFXFA_Page*) page)->GetPDFPage(); - if (pPage) - { - 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; - } - - IXFA_PageView* pPageView = ((CPDFXFA_Page*)page)->GetXFAPageView(); - if (pPageView) - { - IXFA_WidgetHandler* pWidgetHandler = NULL; - IXFA_DocView* pDocView = pPageView->GetDocView(); - if (!pDocView) - return -1; - - pWidgetHandler = pDocView->GetWidgetHandler(); - if (!pWidgetHandler) - return -1; - - IXFA_Widget* pXFAAnnot = NULL; - IXFA_WidgetIterator* pWidgetIterator = pPageView->CreateWidgetIterator(XFA_TRAVERSEWAY_Form, XFA_WIDGETFILTER_Viewable|XFA_WIDGETFILTER_AllType); - if (!pWidgetIterator) - return -1; - pXFAAnnot = pWidgetIterator->MoveToNext(); - while (pXFAAnnot) { - CFX_RectF rcBBox; - pWidgetHandler->GetBBox (pXFAAnnot, rcBBox, 0); - CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width, rcBBox.top+rcBBox.height); - rcWidget.left -= 1.0f; - rcWidget.right += 1.0f; - rcWidget.bottom -= 1.0f; - rcWidget.top += 1.0f; - - if (rcWidget.Contains(static_cast<FX_FLOAT>(page_x), - static_cast<FX_FLOAT>(page_y))) { - pWidgetIterator->Release(); - return FPDF_FORMFIELD_XFA; - } - pXFAAnnot = pWidgetIterator->MoveToNext(); - } - - pWidgetIterator->Release(); - } - - return -1; +namespace { + +CPDFSDK_Document* FormHandleToSDKDoc(FPDF_FORMHANDLE hHandle) +{ + CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle; + return pEnv ? pEnv->GetSDKDocument() : nullptr; +} + +CPDFSDK_InterForm* FormHandleToInterForm(FPDF_FORMHANDLE hHandle) +{ + CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle); + return pSDKDoc ? pSDKDoc->GetInterForm() : nullptr; +} + +CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle, FPDF_PAGE page) +{ + CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle); + return pSDKDoc ? pSDKDoc->GetPageView((CPDFXFA_Page*)page, TRUE) : nullptr; +} + +} // namespace + +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 = ((CPDFXFA_Page*) page)->GetPDFPage(); + if (pPage) + { + 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; + } + + IXFA_PageView* pPageView = ((CPDFXFA_Page*)page)->GetXFAPageView(); + if (pPageView) + { + IXFA_WidgetHandler* pWidgetHandler = NULL; + IXFA_DocView* pDocView = pPageView->GetDocView(); + if (!pDocView) + return -1; + + pWidgetHandler = pDocView->GetWidgetHandler(); + if (!pWidgetHandler) + return -1; + + IXFA_Widget* pXFAAnnot = NULL; + IXFA_WidgetIterator* pWidgetIterator = pPageView->CreateWidgetIterator(XFA_TRAVERSEWAY_Form, XFA_WIDGETFILTER_Viewable|XFA_WIDGETFILTER_AllType); + if (!pWidgetIterator) + return -1; + pXFAAnnot = pWidgetIterator->MoveToNext(); + while (pXFAAnnot) { + CFX_RectF rcBBox; + pWidgetHandler->GetBBox (pXFAAnnot, rcBBox, 0); + CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width, rcBBox.top+rcBBox.height); + rcWidget.left -= 1.0f; + rcWidget.right += 1.0f; + rcWidget.bottom -= 1.0f; + rcWidget.top += 1.0f; + + if (rcWidget.Contains(static_cast<FX_FLOAT>(page_x), + static_cast<FX_FLOAT>(page_y))) { + pWidgetIterator->Release(); + return FPDF_FORMFIELD_XFA; + } + pXFAAnnot = pWidgetIterator->MoveToNext(); + } + + pWidgetIterator->Release(); + } + + return -1; } DLLEXPORT FPDF_FORMHANDLE STDCALL FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document, FPDF_FORMFILLINFO* formInfo) { - if(!document || !formInfo || formInfo->version!=2) - return NULL; - CPDFXFA_Document * pDocument = (CPDFXFA_Document*) document; - CPDFDoc_Environment * pEnv = NULL; - pEnv = new CPDFDoc_Environment(pDocument); - if (!pEnv) - return NULL; - pEnv->RegAppHandle(formInfo); - - CPDFXFA_App* pApp = CPDFXFA_App::GetInstance(); - pApp->AddFormFillEnv(pEnv); - - if(pEnv->GetPDFXFADocument()) - { - //CPDFSDK_Document* pSDKDoc = new CPDFSDK_Document(pEnv->GetPDFXFADocument(), pEnv); - CPDFSDK_Document* pSDKDoc = pDocument->GetSDKDocument(pEnv); - if(pSDKDoc) { - pEnv->SetCurrentDoc(pSDKDoc); - } - } - return pEnv; + if (!document || !formInfo || formInfo->version != 2) + return nullptr; + + CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; + CPDFDoc_Environment* pEnv = new CPDFDoc_Environment(pDocument, formInfo); + pEnv->SetSDKDocument(pDocument->GetSDKDocument(pEnv)); + + CPDFXFA_App* pApp = CPDFXFA_App::GetInstance(); + pApp->AddFormFillEnv(pEnv); + + return pEnv; } DLLEXPORT void STDCALL FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) { - if (!hHandle) - return; - CPDFXFA_App* pApp = CPDFXFA_App::GetInstance(); - pApp->RemoveFormFillEnv((CPDFDoc_Environment*)hHandle); - delete (CPDFDoc_Environment*)hHandle; - hHandle = NULL; + if (!hHandle) + return; + CPDFXFA_App* pApp = CPDFXFA_App::GetInstance(); + pApp->RemoveFormFillEnv((CPDFDoc_Environment*)hHandle); + delete (CPDFDoc_Environment*)hHandle; } 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((CPDFXFA_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); + CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); + if (!pPageView) + return FALSE; + + 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((CPDFXFA_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); + CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); + if (!pPageView) + return FALSE; + + 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((CPDFXFA_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); + CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); + if (!pPageView) + return FALSE; + + CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y); + return pPageView->OnLButtonUp(pt, modifier); } DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonDown(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int modifier, double page_x, double page_y) { - if (!hHandle || !page) - return FALSE; + CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); + if (!pPageView) + return FALSE; - CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc(); - if(!pFXDoc) - return FALSE; - CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDFXFA_Page*)page); - if(!pPageView) - return FALSE; - - CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y); - return pPageView->OnRButtonDown(pt, modifier); + CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y); + return pPageView->OnRButtonDown(pt, modifier); } DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonUp(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((CPDFXFA_Page*)page); - if(!pPageView) - return FALSE; + CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); + if (!pPageView) + return FALSE; - CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y); - return pPageView->OnRButtonUp(pt, modifier); + CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y); + return pPageView->OnRButtonUp(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((CPDFXFA_Page*)page); - if(!pPageView) - return FALSE; + CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); + if (!pPageView) + return FALSE; - - return pPageView->OnKeyDown(nKeyCode, modifier); + 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((CPDFXFA_Page*)page); - if(!pPageView) - return FALSE; - + CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); + if (!pPageView) + return FALSE; - return pPageView->OnKeyUp(nKeyCode, modifier); + 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((CPDFXFA_Page*)page); - if(!pPageView) - return FALSE; - return pPageView->OnChar(nChar, modifier); + CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, 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); + CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle); + if (!pSDKDoc) + return FALSE; + + 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) +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 ; + if (!hHandle || !page) + return ; - CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; - CPDFXFA_Document* pDocument = pPage->GetDocument(); - if (!pDocument) - return; - CPDF_Document* pPDFDoc = pDocument->GetPDFDoc(); - if (!pPDFDoc) - return; + CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; + CPDFXFA_Document* pDocument = pPage->GetDocument(); + if (!pDocument) + return; + CPDF_Document* pPDFDoc = pDocument->GetPDFDoc(); + if (!pPDFDoc) + return; - CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle; - CPDFSDK_Document* pFXDoc = pEnv->GetCurrentDoc(); - if (!pFXDoc) - return; + CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle; + CPDFSDK_Document* pFXDoc = pEnv->GetSDKDocument(); + if (!pFXDoc) + return; - CFX_AffineMatrix matrix; - pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate); + 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; + 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 = FX_NEW CFX_SkiaDevice; + nonstd::unique_ptr<CFX_SkiaDevice> pDevice(new CFX_SkiaDevice); #else - CFX_FxgeDevice* pDevice = NULL; - pDevice = FX_NEW CFX_FxgeDevice; + nonstd::unique_ptr<CFX_FxgeDevice> pDevice(new CFX_FxgeDevice); #endif - if (!pDevice) - return; - pDevice->Attach((CFX_DIBitmap*)bitmap); - pDevice->SaveState(); - pDevice->SetClip_Rect(&clip); - - 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 = FX_NEW CPDF_OCContext(pPDFDoc); - - if(CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDFXFA_Page*)page)) - { - pPageView->PageView_OnDraw(pDevice, &matrix, &options, &clip); - } - pDevice->RestoreState(); - - if(options.m_pOCContext) - { - delete options.m_pOCContext; - options.m_pOCContext = NULL; - } - if(pDevice) - { - delete pDevice; - pDevice = NULL; - } + if (!pDevice) + return; + pDevice->Attach((CFX_DIBitmap*)bitmap); + pDevice->SaveState(); + pDevice->SetClip_Rect(&clip); + + 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 = FX_NEW CPDF_OCContext(pPDFDoc); + + if (CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDFXFA_Page*)page)) + pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options, &clip); + + pDevice->RestoreState(); + + delete options.m_pOCContext; + options.m_pOCContext = NULL; } DLLEXPORT void STDCALL FPDF_Widget_Undo(FPDF_DOCUMENT document, FPDF_WIDGET hWidget) { - if (NULL == hWidget || NULL == document) - return; + if (NULL == hWidget || NULL == document) + return; - CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; - if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static) - return; + CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; + if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static) + return; - IXFA_MenuHandler* pXFAMenuHander = CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); - if (pXFAMenuHander == NULL) - return; + IXFA_MenuHandler* pXFAMenuHander = CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); + if (pXFAMenuHander == NULL) + return; - pXFAMenuHander->Undo((IXFA_Widget*)hWidget); + pXFAMenuHander->Undo((IXFA_Widget*)hWidget); } DLLEXPORT void STDCALL FPDF_Widget_Redo(FPDF_DOCUMENT document, FPDF_WIDGET hWidget) { - if (NULL == hWidget || NULL == document) - return; + if (NULL == hWidget || NULL == document) + return; - CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; - if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static) - return; + CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; + if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static) + return; - IXFA_MenuHandler* pXFAMenuHander = CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); - if (pXFAMenuHander == NULL) - return; + IXFA_MenuHandler* pXFAMenuHander = CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); + if (pXFAMenuHander == NULL) + return; - pXFAMenuHander->Redo((IXFA_Widget*)hWidget); + pXFAMenuHander->Redo((IXFA_Widget*)hWidget); } DLLEXPORT void STDCALL FPDF_Widget_SelectAll(FPDF_DOCUMENT document, FPDF_WIDGET hWidget) { - if (NULL == hWidget || NULL == document) - return; + if (NULL == hWidget || NULL == document) + return; - CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; - if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static) - return; + CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; + if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static) + return; - IXFA_MenuHandler* pXFAMenuHander = CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); - if (pXFAMenuHander == NULL) - return; + IXFA_MenuHandler* pXFAMenuHander = CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); + if (pXFAMenuHander == NULL) + return; - pXFAMenuHander->SelectAll((IXFA_Widget*)hWidget); + pXFAMenuHander->SelectAll((IXFA_Widget*)hWidget); } DLLEXPORT void STDCALL FPDF_Widget_Copy(FPDF_DOCUMENT document, FPDF_WIDGET hWidget, FPDF_WIDESTRING wsText, FPDF_DWORD* size) { - if (NULL == hWidget || NULL == document) - return; + if (NULL == hWidget || NULL == document) + return; - CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; - if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static) - return; + CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; + if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static) + return; - IXFA_MenuHandler* pXFAMenuHander = CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); - if (pXFAMenuHander == NULL) - return; + IXFA_MenuHandler* pXFAMenuHander = CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); + if (pXFAMenuHander == NULL) + return; - CFX_WideString wsCpText; - pXFAMenuHander->Copy((IXFA_Widget*)hWidget, wsCpText); + CFX_WideString wsCpText; + pXFAMenuHander->Copy((IXFA_Widget*)hWidget, wsCpText); - CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode(); - int len = bsCpText.GetLength()/sizeof(unsigned short); - if (wsText == NULL) { - *size = len; - return; - } + CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode(); + int len = bsCpText.GetLength()/sizeof(unsigned short); + if (wsText == NULL) { + *size = len; + return; + } - int real_size = len < *size ? len : *size; - if (real_size > 0) - { - FXSYS_memcpy((void*)wsText,bsCpText.GetBuffer(real_size*sizeof(unsigned short)),real_size*sizeof(unsigned short)); - bsCpText.ReleaseBuffer(real_size*sizeof(unsigned short)); - } - *size = real_size; + int real_size = len < *size ? len : *size; + if (real_size > 0) + { + FXSYS_memcpy((void*)wsText,bsCpText.GetBuffer(real_size*sizeof(unsigned short)),real_size*sizeof(unsigned short)); + bsCpText.ReleaseBuffer(real_size*sizeof(unsigned short)); + } + *size = real_size; } DLLEXPORT void STDCALL FPDF_Widget_Cut(FPDF_DOCUMENT document, FPDF_WIDGET hWidget, FPDF_WIDESTRING wsText, FPDF_DWORD* size) { - if (NULL == hWidget || NULL == document) - return; - CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; - if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static) - return; - - IXFA_MenuHandler* pXFAMenuHander = CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); - if (pXFAMenuHander == NULL) - return; - - CFX_WideString wsCpText; - pXFAMenuHander->Cut((IXFA_Widget*)hWidget, wsCpText); - - CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode(); - int len = bsCpText.GetLength()/sizeof(unsigned short); - if (wsText == NULL) { - *size = len; - return; - } - - int real_size = len < *size ? len : *size; - if (real_size > 0) - { - FXSYS_memcpy((void*)wsText,bsCpText.GetBuffer(real_size*sizeof(unsigned short)),real_size*sizeof(unsigned short)); - bsCpText.ReleaseBuffer(real_size*sizeof(unsigned short)); - } - *size = real_size; + if (NULL == hWidget || NULL == document) + return; + CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; + if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static) + return; + + IXFA_MenuHandler* pXFAMenuHander = CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); + if (pXFAMenuHander == NULL) + return; + + CFX_WideString wsCpText; + pXFAMenuHander->Cut((IXFA_Widget*)hWidget, wsCpText); + + CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode(); + int len = bsCpText.GetLength()/sizeof(unsigned short); + if (wsText == NULL) { + *size = len; + return; + } + + int real_size = len < *size ? len : *size; + if (real_size > 0) + { + FXSYS_memcpy((void*)wsText,bsCpText.GetBuffer(real_size*sizeof(unsigned short)),real_size*sizeof(unsigned short)); + bsCpText.ReleaseBuffer(real_size*sizeof(unsigned short)); + } + *size = real_size; } DLLEXPORT void STDCALL FPDF_Widget_Paste(FPDF_DOCUMENT document, FPDF_WIDGET hWidget, FPDF_WIDESTRING wsText, FPDF_DWORD size) { - if (NULL == hWidget || NULL == document) - return; + if (NULL == hWidget || NULL == document) + return; - CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; - if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static) - return; + CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; + if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static) + return; - IXFA_MenuHandler* pXFAMenuHander = CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); - if (pXFAMenuHander == NULL) - return; + IXFA_MenuHandler* pXFAMenuHander = CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); + if (pXFAMenuHander == NULL) + return; - CFX_WideString wstr = CFX_WideString::FromUTF16LE(wsText, size); - pXFAMenuHander->Paste((IXFA_Widget*)hWidget, wstr); + CFX_WideString wstr = CFX_WideString::FromUTF16LE(wsText, size); + pXFAMenuHander->Paste((IXFA_Widget*)hWidget, wstr); } DLLEXPORT void STDCALL FPDF_Widget_ReplaceSpellCheckWord(FPDF_DOCUMENT document, FPDF_WIDGET hWidget, float x, float y, FPDF_BYTESTRING bsText) { - if (NULL == hWidget || NULL == document) - return; + if (NULL == hWidget || NULL == document) + return; - CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; - if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static) - return; + CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; + if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static) + return; - IXFA_MenuHandler* pXFAMenuHander = CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); - if (pXFAMenuHander == NULL) - return; + IXFA_MenuHandler* pXFAMenuHander = CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); + if (pXFAMenuHander == NULL) + return; - CFX_PointF ptPopup; - ptPopup.x = x; - ptPopup.y = y; - CFX_ByteStringC bs(bsText); - pXFAMenuHander->ReplaceSpellCheckWord((IXFA_Widget*)hWidget,ptPopup,bs); + CFX_PointF ptPopup; + ptPopup.x = x; + ptPopup.y = y; + CFX_ByteStringC bs(bsText); + pXFAMenuHander->ReplaceSpellCheckWord((IXFA_Widget*)hWidget,ptPopup,bs); } DLLEXPORT void STDCALL FPDF_Widget_GetSpellCheckWords(FPDF_DOCUMENT document, FPDF_WIDGET hWidget, float x, float y, FPDF_STRINGHANDLE* stringHandle) { - if (NULL == hWidget || NULL == document) - return; + if (NULL == hWidget || NULL == document) + return; - CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; - if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static) - return; + CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; + if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static) + return; - IXFA_MenuHandler* pXFAMenuHander = CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); - if (pXFAMenuHander == NULL) - return; + IXFA_MenuHandler* pXFAMenuHander = CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); + if (pXFAMenuHander == NULL) + return; - CFX_ByteStringArray* sSuggestWords = FX_NEW CFX_ByteStringArray; - CFX_PointF ptPopup; - ptPopup.x = x; - ptPopup.y = y; - pXFAMenuHander->GetSuggestWords((IXFA_Widget*)hWidget, ptPopup, *sSuggestWords); - *stringHandle = (FPDF_STRINGHANDLE)sSuggestWords; + CFX_ByteStringArray* sSuggestWords = FX_NEW CFX_ByteStringArray; + CFX_PointF ptPopup; + ptPopup.x = x; + ptPopup.y = y; + pXFAMenuHander->GetSuggestWords((IXFA_Widget*)hWidget, ptPopup, *sSuggestWords); + *stringHandle = (FPDF_STRINGHANDLE)sSuggestWords; } DLLEXPORT int STDCALL FPDF_StringHandleCounts(FPDF_STRINGHANDLE stringHandle) { - if (stringHandle == NULL) - return -1; - CFX_ByteStringArray* sSuggestWords = (CFX_ByteStringArray*)stringHandle; - return sSuggestWords->GetSize(); + if (stringHandle == NULL) + return -1; + CFX_ByteStringArray* sSuggestWords = (CFX_ByteStringArray*)stringHandle; + return sSuggestWords->GetSize(); } DLLEXPORT FPDF_BOOL STDCALL FPDF_StringHandleGetStringByIndex(FPDF_STRINGHANDLE stringHandle, int index, FPDF_BYTESTRING bsText, FPDF_DWORD* size) { - if (stringHandle == NULL || size == NULL) - return FALSE; - int count = FPDF_StringHandleCounts(stringHandle); - if (index < 0|| index >= count) - return FALSE; + if (stringHandle == NULL || size == NULL) + return FALSE; + int count = FPDF_StringHandleCounts(stringHandle); + if (index < 0|| index >= count) + return FALSE; - CFX_ByteStringArray sSuggestWords = *(CFX_ByteStringArray*)stringHandle; - int len = sSuggestWords[index].GetLength(); + CFX_ByteStringArray sSuggestWords = *(CFX_ByteStringArray*)stringHandle; + int len = sSuggestWords[index].GetLength(); - if (bsText == NULL) { - *size = len; - return TRUE; - } + if (bsText == NULL) { + *size = len; + return TRUE; + } - int real_size = len < *size ? len : *size; - if (real_size > 0) - FXSYS_memcpy((void*)bsText, (const FX_CHAR*)(sSuggestWords[index]), real_size); - *size = real_size; + int real_size = len < *size ? len : *size; + if (real_size > 0) + FXSYS_memcpy((void*)bsText, (const FX_CHAR*)(sSuggestWords[index]), real_size); + *size = real_size; - return TRUE; + return TRUE; } DLLEXPORT void STDCALL FPDF_StringHandleRelease(FPDF_STRINGHANDLE stringHandle) { - if (stringHandle == NULL) - return; - CFX_ByteStringArray* sSuggestWords = (CFX_ByteStringArray*)stringHandle; - delete sSuggestWords; + if (stringHandle == NULL) + return; + CFX_ByteStringArray* sSuggestWords = (CFX_ByteStringArray*)stringHandle; + delete sSuggestWords; } DLLEXPORT FPDF_BOOL STDCALL FPDF_StringHandleAddString(FPDF_STRINGHANDLE stringHandle, FPDF_BYTESTRING bsText, FPDF_DWORD size) { - if (stringHandle == NULL || bsText == NULL || size <= 0) - return FALSE; + if (stringHandle == NULL || bsText == NULL || size <= 0) + return FALSE; - CFX_ByteStringArray* stringArr = (CFX_ByteStringArray*)stringHandle; - CFX_ByteString bsStr(bsText, size); + CFX_ByteStringArray* stringArr = (CFX_ByteStringArray*)stringHandle; + CFX_ByteString bsStr(bsText, size); - stringArr->Add(bsStr); - return TRUE; + stringArr->Add(bsStr); + return TRUE; } 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); - } - - } - + if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle)) + 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); - } + if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle)) + 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(); - } + if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle)) + 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; - CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; - CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, TRUE); - if(pPageView) - { - pPageView->SetValid(TRUE); - } + if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page)) + 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(); - CPDFXFA_Page* pPage = (CPDFXFA_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); - } + if (!hHandle || !page) + return; + + CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetSDKDocument(); + if (!pSDKDoc) + return; + + CPDFXFA_Page* pPage = (CPDFXFA_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(); - } + CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle); + if (pSDKDoc && ((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(); - } + CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle); + if (pSDKDoc && ((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()->GetPDFDoc(); - 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); - } - } + CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle); + if (!pSDKDoc) + return; + + CPDF_Document* pDoc = pSDKDoc->GetDocument()->GetPDFDoc(); + 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(); - CPDFXFA_Page* pPage = (CPDFXFA_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); - - if (!pPage->GetPDFPage()) - return; - CPDF_Dictionary *pPageDict = pPage->GetPDFPage()->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); - } - } - } + if(!hHandle || !page) + return; + CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetSDKDocument(); + CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; + CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, FALSE); + if(pPageView) + { + CPDFDoc_Environment *pEnv = pSDKDoc->GetEnv(); + CPDFSDK_ActionHandler *pActionHandler = pEnv->GetActionHander(); + CPDF_Dictionary *pPageDict = pPage->GetPDFPage()->m_pFormDict; + 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); + } + } + } } - - diff --git a/fpdfsdk/src/fsdk_annothandler.cpp b/fpdfsdk/src/fsdk_annothandler.cpp index 574302302a..50ef9cf3c1 100644 --- a/fpdfsdk/src/fsdk_annothandler.cpp +++ b/fpdfsdk/src/fsdk_annothandler.cpp @@ -14,1393 +14,1375 @@ CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp) { - m_pApp = pApp; + m_pApp = pApp; - CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp); - pHandler->SetFormFiller(m_pApp->GetIFormFiller()); - RegisterAnnotHandler(pHandler); + CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp); + pHandler->SetFormFiller(m_pApp->GetIFormFiller()); + RegisterAnnotHandler(pHandler); - CPDFSDK_XFAAnnotHandler* pXFAAnnotHandler = new CPDFSDK_XFAAnnotHandler(m_pApp); - RegisterAnnotHandler(pXFAAnnotHandler); + CPDFSDK_XFAAnnotHandler* pXFAAnnotHandler = new CPDFSDK_XFAAnnotHandler(m_pApp); + RegisterAnnotHandler(pXFAAnnotHandler); } CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() { - for(int i=0; i<m_Handlers.GetSize(); i++) - { - IPDFSDK_AnnotHandler* pHandler = m_Handlers.GetAt(i); - delete pHandler; - } - m_Handlers.RemoveAll(); - m_mapType2Handler.RemoveAll(); + for(int i=0; i<m_Handlers.GetSize(); i++) + { + IPDFSDK_AnnotHandler* pHandler = m_Handlers.GetAt(i); + delete pHandler; + } + m_Handlers.RemoveAll(); + m_mapType2Handler.RemoveAll(); } -void CPDFSDK_AnnotHandlerMgr::RegisterAnnotHandler(IPDFSDK_AnnotHandler* pAnnotHandler) +void CPDFSDK_AnnotHandlerMgr::RegisterAnnotHandler(IPDFSDK_AnnotHandler* pAnnotHandler) { - ASSERT(pAnnotHandler != NULL); + ASSERT(pAnnotHandler != NULL); - ASSERT(GetAnnotHandler(pAnnotHandler->GetType()) == NULL); + ASSERT(GetAnnotHandler(pAnnotHandler->GetType()) == NULL); - m_Handlers.Add(pAnnotHandler); - m_mapType2Handler.SetAt(pAnnotHandler->GetType(), (void*)pAnnotHandler); + m_Handlers.Add(pAnnotHandler); + m_mapType2Handler.SetAt(pAnnotHandler->GetType(), (void*)pAnnotHandler); } void CPDFSDK_AnnotHandlerMgr::UnRegisterAnnotHandler(IPDFSDK_AnnotHandler* pAnnotHandler) { - ASSERT(pAnnotHandler != NULL); + ASSERT(pAnnotHandler != NULL); - m_mapType2Handler.RemoveKey(pAnnotHandler->GetType()); + m_mapType2Handler.RemoveKey(pAnnotHandler->GetType()); - for (int i=0, sz=m_Handlers.GetSize(); i<sz; i++) - { - if (m_Handlers.GetAt(i) == pAnnotHandler) - { - m_Handlers.RemoveAt(i); - break; - } - } + for (int i=0, sz=m_Handlers.GetSize(); i<sz; i++) + { + if (m_Handlers.GetAt(i) == pAnnotHandler) + { + m_Handlers.RemoveAt(i); + break; + } + } } CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot * pAnnot, CPDFSDK_PageView *pPageView) { - ASSERT(pAnnot != NULL); - ASSERT(pPageView != NULL); + ASSERT(pAnnot != NULL); + ASSERT(pPageView != NULL); - if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot->GetSubType())) - { - return pAnnotHandler->NewAnnot(pAnnot, pPageView); - } + if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot->GetSubType())) + { + return pAnnotHandler->NewAnnot(pAnnot, pPageView); + } - return new CPDFSDK_BAAnnot(pAnnot, pPageView); + return new CPDFSDK_BAAnnot(pAnnot, pPageView); } CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(IXFA_Widget* pAnnot, CPDFSDK_PageView* pPageView) { - ASSERT(pAnnot != NULL); - ASSERT(pPageView != NULL); + ASSERT(pAnnot != NULL); + ASSERT(pPageView != NULL); - if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME)) - { - return pAnnotHandler->NewAnnot(pAnnot, pPageView); - } + if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME)) + { + return pAnnotHandler->NewAnnot(pAnnot, pPageView); + } - return NULL; + return NULL; } void CPDFSDK_AnnotHandlerMgr::ReleaseAnnot(CPDFSDK_Annot* pAnnot) { - ASSERT(pAnnot != NULL); + ASSERT(pAnnot != NULL); - pAnnot->GetPDFPage(); + pAnnot->GetPDFPage(); - if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) - { - pAnnotHandler->OnRelease(pAnnot); - pAnnotHandler->ReleaseAnnot(pAnnot); - } - else - { - delete (CPDFSDK_Annot*)pAnnot; - } + if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) + { + pAnnotHandler->OnRelease(pAnnot); + pAnnotHandler->ReleaseAnnot(pAnnot); + } + else + { + delete (CPDFSDK_Annot*)pAnnot; + } } void CPDFSDK_AnnotHandlerMgr::Annot_OnCreate(CPDFSDK_Annot* pAnnot) { - ASSERT(pAnnot != NULL); + ASSERT(pAnnot != NULL); - CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot(); + CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot(); - CPDFSDK_DateTime curTime; - pPDFAnnot->GetAnnotDict()->SetAtString("M", curTime.ToPDFDateTimeString()); - pPDFAnnot->GetAnnotDict()->SetAtNumber("F", 0); + CPDFSDK_DateTime curTime; + pPDFAnnot->GetAnnotDict()->SetAtString("M", curTime.ToPDFDateTimeString()); + pPDFAnnot->GetAnnotDict()->SetAtNumber("F", 0); - if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) - { - pAnnotHandler->OnCreate(pAnnot); - } + if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) + { + pAnnotHandler->OnCreate(pAnnot); + } } void CPDFSDK_AnnotHandlerMgr::Annot_OnLoad(CPDFSDK_Annot* pAnnot) { - ASSERT(pAnnot != NULL); + ASSERT(pAnnot != NULL); - if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) - { - pAnnotHandler->OnLoad(pAnnot); - } + if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) + { + pAnnotHandler->OnLoad(pAnnot); + } } IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(CPDFSDK_Annot* pAnnot) const { - ASSERT(pAnnot != NULL); + ASSERT(pAnnot != NULL); - CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot(); - if (pPDFAnnot) - return GetAnnotHandler(pPDFAnnot->GetSubType()); - else if (pAnnot->GetXFAWidget()) - return GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME); - return NULL; + CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot(); + if (pPDFAnnot) + return GetAnnotHandler(pPDFAnnot->GetSubType()); + else if (pAnnot->GetXFAWidget()) + return GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME); + return NULL; } IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(const CFX_ByteString& sType) const { - void* pRet = NULL; - m_mapType2Handler.Lookup(sType, pRet); - return (IPDFSDK_AnnotHandler*)pRet; + void* pRet = NULL; + m_mapType2Handler.Lookup(sType, pRet); + return (IPDFSDK_AnnotHandler*)pRet; } void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,FX_DWORD dwFlags) { - ASSERT(pAnnot != NULL); + ASSERT(pAnnot != NULL); - if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) - { - pAnnotHandler->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags); - } - else - { - if (!pAnnot->IsXFAField()) - ((CPDFSDK_BAAnnot*)pAnnot)->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); - } + if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) + { + pAnnotHandler->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags); + } + else + { + if (!pAnnot->IsXFAField()) + ((CPDFSDK_BAAnnot*)pAnnot)->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); + } } FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) { - ASSERT(pAnnot != NULL); + ASSERT(pAnnot != NULL); - if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) - { - return pAnnotHandler->OnLButtonDown(pPageView, pAnnot, nFlags, point); - } - return FALSE; + if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) + { + return pAnnotHandler->OnLButtonDown(pPageView, pAnnot, nFlags, point); + } + return FALSE; } FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonUp(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) { - ASSERT(pAnnot != NULL); + ASSERT(pAnnot != NULL); - if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) - { - return pAnnotHandler->OnLButtonUp(pPageView, pAnnot, nFlags, point); - } - return FALSE; + if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) + { + return pAnnotHandler->OnLButtonUp(pPageView, pAnnot, nFlags, point); + } + return FALSE; } FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDblClk(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) { - ASSERT(pAnnot != NULL); + ASSERT(pAnnot != NULL); - if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) - { - return pAnnotHandler->OnLButtonDblClk(pPageView, pAnnot, nFlags, point); - } - return FALSE; + if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) + { + return pAnnotHandler->OnLButtonDblClk(pPageView, pAnnot, nFlags, point); + } + return FALSE; } FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseMove(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) { - ASSERT(pAnnot != NULL); + ASSERT(pAnnot != NULL); - if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) - { - return pAnnotHandler->OnMouseMove(pPageView, pAnnot, nFlags, point); - } - return FALSE; + if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) + { + return pAnnotHandler->OnMouseMove(pPageView, pAnnot, nFlags, point); + } + return FALSE; } FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseWheel(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, short zDelta, const CPDF_Point& point) { - ASSERT(pAnnot != NULL); + ASSERT(pAnnot != NULL); - if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) - { - return pAnnotHandler->OnMouseWheel(pPageView, pAnnot,nFlags,zDelta, point); - } - return FALSE; + if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) + { + return pAnnotHandler->OnMouseWheel(pPageView, pAnnot,nFlags,zDelta, point); + } + return FALSE; } FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonDown(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) { - ASSERT(pAnnot != NULL); + ASSERT(pAnnot != NULL); - if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) - { - return pAnnotHandler->OnRButtonDown(pPageView, pAnnot, nFlags, point); - } - return FALSE; + if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) + { + return pAnnotHandler->OnRButtonDown(pPageView, pAnnot, nFlags, point); + } + return FALSE; } FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonUp(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) { - ASSERT(pAnnot != NULL); + ASSERT(pAnnot != NULL); - if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) - { - return pAnnotHandler->OnRButtonUp(pPageView, pAnnot, nFlags, point); - } - return FALSE; + if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) + { + return pAnnotHandler->OnRButtonUp(pPageView, pAnnot, nFlags, point); + } + return FALSE; } void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseEnter(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) { - ASSERT(pAnnot != NULL); + ASSERT(pAnnot != NULL); - if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) - { - pAnnotHandler->OnMouseEnter(pPageView, pAnnot, nFlag); - } - return ; + if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) + { + pAnnotHandler->OnMouseEnter(pPageView, pAnnot, nFlag); + } + return ; } void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseExit(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) { - ASSERT(pAnnot != NULL); + ASSERT(pAnnot != NULL); - if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) - { - pAnnotHandler->OnMouseExit(pPageView, pAnnot, nFlag); - } - return; + if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) + { + pAnnotHandler->OnMouseExit(pPageView, pAnnot, nFlag); + } + return; } FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnChar(CPDFSDK_Annot* pAnnot, FX_DWORD nChar, FX_DWORD nFlags) { - if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) - { - return pAnnotHandler->OnChar(pAnnot,nChar, nFlags); - } - return FALSE; + if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) + { + return pAnnotHandler->OnChar(pAnnot,nChar, nFlags); + } + return FALSE; } -FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag) +FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag) { - if (!m_pApp->FFI_IsCTRLKeyDown(nFlag) && !m_pApp->FFI_IsALTKeyDown(nFlag)) - { - CPDFSDK_PageView* pPage = pAnnot->GetPageView(); - CPDFSDK_Annot* pFocusAnnot = pPage->GetFocusAnnot(); - if (pFocusAnnot && (nKeyCode == FWL_VKEY_Tab)) - { - CPDFSDK_Annot* pNext = GetNextAnnot(pFocusAnnot, !m_pApp->FFI_IsSHIFTKeyDown(nFlag)); + if (!m_pApp->FFI_IsCTRLKeyDown(nFlag) && !m_pApp->FFI_IsALTKeyDown(nFlag)) + { + CPDFSDK_PageView* pPage = pAnnot->GetPageView(); + CPDFSDK_Annot* pFocusAnnot = pPage->GetFocusAnnot(); + if (pFocusAnnot && (nKeyCode == FWL_VKEY_Tab)) + { + CPDFSDK_Annot* pNext = GetNextAnnot(pFocusAnnot, !m_pApp->FFI_IsSHIFTKeyDown(nFlag)); - if(pNext && pNext != pFocusAnnot) - { - CPDFSDK_Document* pDocument = pPage->GetSDKDocument(); - pDocument->SetFocusAnnot(pNext); - return TRUE; - } - } - } + if(pNext && pNext != pFocusAnnot) + { + CPDFSDK_Document* pDocument = pPage->GetSDKDocument(); + pDocument->SetFocusAnnot(pNext); + return TRUE; + } + } + } - if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) - { - return pAnnotHandler->OnKeyDown(pAnnot,nKeyCode, nFlag); - } - return FALSE; + if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) + { + return pAnnotHandler->OnKeyDown(pAnnot,nKeyCode, nFlag); + } + return FALSE; } -FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyUp(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag) +FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyUp(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag) { - return FALSE; + return FALSE; } -FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) +FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) { - ASSERT(pAnnot != NULL); + ASSERT(pAnnot != NULL); - if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) - { - if (pAnnotHandler->OnSetFocus(pAnnot, nFlag)) - { - CPDFSDK_PageView* pPage = pAnnot->GetPageView(); - ASSERT(pPage != NULL); + if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) + { + if (pAnnotHandler->OnSetFocus(pAnnot, nFlag)) + { + CPDFSDK_PageView* pPage = pAnnot->GetPageView(); + ASSERT(pPage != NULL); - pPage->GetSDKDocument(); - // pDocument->SetTopmostAnnot(pAnnot); + pPage->GetSDKDocument(); + // pDocument->SetTopmostAnnot(pAnnot); - return TRUE; - } - else - { - return FALSE; - } - } + return TRUE; + } + else + { + return FALSE; + } + } - return FALSE; + return FALSE; } -FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) +FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) { - ASSERT(pAnnot != NULL); + ASSERT(pAnnot != NULL); - if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) - { - if (pAnnotHandler->OnKillFocus(pAnnot, nFlag)) - { - return TRUE; - } - else - return FALSE; - } + if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) + { + if (pAnnotHandler->OnKillFocus(pAnnot, nFlag)) + { + return TRUE; + } + else + return FALSE; + } - return FALSE; + return FALSE; } FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnChangeFocus(CPDFSDK_Annot* pSetAnnot,CPDFSDK_Annot* pKillAnnot) { - FX_BOOL bXFA = (pSetAnnot && pSetAnnot->GetXFAWidget()) || - (pKillAnnot && pKillAnnot->GetXFAWidget()); + FX_BOOL bXFA = (pSetAnnot && pSetAnnot->GetXFAWidget()) || + (pKillAnnot && pKillAnnot->GetXFAWidget()); - if (bXFA) - { - if (IPDFSDK_AnnotHandler* pXFAAnnotHandler = GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME)) - return pXFAAnnotHandler->OnXFAChangedFocus(pKillAnnot, pSetAnnot); - } + if (bXFA) + { + if (IPDFSDK_AnnotHandler* pXFAAnnotHandler = GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME)) + return pXFAAnnotHandler->OnXFAChangedFocus(pKillAnnot, pSetAnnot); + } - return TRUE; + return TRUE; } -CPDF_Rect CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot) +CPDF_Rect CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot) { - ASSERT(pAnnot); - if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) - { - return pAnnotHandler->GetViewBBox(pPageView, pAnnot); - } - return pAnnot->GetRect(); + ASSERT(pAnnot); + if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) + { + return pAnnotHandler->GetViewBBox(pPageView, pAnnot); + } + return pAnnot->GetRect(); } -FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnHitTest(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, const CPDF_Point& point) +FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnHitTest(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, const CPDF_Point& point) { - ASSERT(pAnnot); - if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) - { - if(pAnnotHandler->CanAnswer(pAnnot)) - return pAnnotHandler->HitTest(pPageView, pAnnot, point); - } - return FALSE; + ASSERT(pAnnot); + if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) + { + if(pAnnotHandler->CanAnswer(pAnnot)) + return pAnnotHandler->HitTest(pPageView, pAnnot, point); + } + return FALSE; } -CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot,FX_BOOL bNext) +CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot,FX_BOOL bNext) { - CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView(); - CPDFXFA_Page* pPage = pPageView->GetPDFXFAPage(); - if (pPage == NULL) - return NULL; - if (pPage->GetPDFPage()) { // for pdf annots. - CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), pSDKAnnot->GetType(), ""); - CPDFSDK_Annot* pNext = bNext ? - ai.GetNextAnnot(pSDKAnnot) : - ai.GetPrevAnnot(pSDKAnnot); - return pNext; - } - // for xfa annots - IXFA_WidgetIterator* pWidgetIterator = pPage->GetXFAPageView()->CreateWidgetIterator(XFA_TRAVERSEWAY_Tranvalse, XFA_WIDGETFILTER_Visible | XFA_WIDGETFILTER_Viewable | XFA_WIDGETFILTER_Field); - if (pWidgetIterator == NULL) - return NULL; - if (pWidgetIterator->GetCurrentWidget() != pSDKAnnot->GetXFAWidget()) - pWidgetIterator->SetCurrentWidget(pSDKAnnot->GetXFAWidget()); - IXFA_Widget* hNextFocus = NULL; - hNextFocus = bNext?pWidgetIterator->MoveToNext():pWidgetIterator->MoveToPrevious(); - if (hNextFocus == NULL && pSDKAnnot != NULL) - hNextFocus = pWidgetIterator->MoveToFirst(); + CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView(); + CPDFXFA_Page* pPage = pPageView->GetPDFXFAPage(); + if (pPage == NULL) + return NULL; + if (pPage->GetPDFPage()) { // for pdf annots. + CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), pSDKAnnot->GetType(), ""); + CPDFSDK_Annot* pNext = bNext ? + ai.GetNextAnnot(pSDKAnnot) : + ai.GetPrevAnnot(pSDKAnnot); + return pNext; + } + // for xfa annots + IXFA_WidgetIterator* pWidgetIterator = pPage->GetXFAPageView()->CreateWidgetIterator(XFA_TRAVERSEWAY_Tranvalse, XFA_WIDGETFILTER_Visible | XFA_WIDGETFILTER_Viewable | XFA_WIDGETFILTER_Field); + if (pWidgetIterator == NULL) + return NULL; + if (pWidgetIterator->GetCurrentWidget() != pSDKAnnot->GetXFAWidget()) + pWidgetIterator->SetCurrentWidget(pSDKAnnot->GetXFAWidget()); + IXFA_Widget* hNextFocus = NULL; + hNextFocus = bNext?pWidgetIterator->MoveToNext():pWidgetIterator->MoveToPrevious(); + if (hNextFocus == NULL && pSDKAnnot != NULL) + hNextFocus = pWidgetIterator->MoveToFirst(); - pWidgetIterator->Release(); - return pPageView->GetAnnotByXFAWidget(hNextFocus); + pWidgetIterator->Release(); + return pPageView->GetAnnotByXFAWidget(hNextFocus); } FX_BOOL CPDFSDK_BFAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) { - ASSERT(pAnnot); - ASSERT(pAnnot->GetType() == "Widget"); - CFX_ByteString sSubType = pAnnot->GetSubType(); + ASSERT(pAnnot); + ASSERT(pAnnot->GetType() == "Widget"); + CFX_ByteString sSubType = pAnnot->GetSubType(); - if (sSubType == BFFT_SIGNATURE) - { - } - else - { - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - if (!pWidget->IsVisible()) return FALSE; + if (sSubType == BFFT_SIGNATURE) + { + } + else + { + CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; + if (!pWidget->IsVisible()) return FALSE; - int nFieldFlags = pWidget->GetFieldFlags(); - if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY) return FALSE; - if (pWidget->GetFieldType() == FIELDTYPE_PUSHBUTTON) - return TRUE; - else - { - CPDF_Page* pPage = pWidget->GetPDFPage(); - ASSERT(pPage != NULL); + int nFieldFlags = pWidget->GetFieldFlags(); + if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY) return FALSE; + if (pWidget->GetFieldType() == FIELDTYPE_PUSHBUTTON) + return TRUE; + else + { + CPDF_Page* pPage = pWidget->GetPDFPage(); + ASSERT(pPage != NULL); - CPDF_Document* pDocument = pPage->m_pDocument; - ASSERT(pDocument != NULL); + CPDF_Document* pDocument = pPage->m_pDocument; + ASSERT(pDocument != NULL); - FX_DWORD dwPermissions = pDocument->GetUserPermissions(); - return (dwPermissions&FPDFPERM_FILL_FORM) || - (dwPermissions&FPDFPERM_ANNOT_FORM) || - (dwPermissions&FPDFPERM_ANNOT_FORM); - } - } + FX_DWORD dwPermissions = pDocument->GetUserPermissions(); + return (dwPermissions&FPDFPERM_FILL_FORM) || + (dwPermissions&FPDFPERM_ANNOT_FORM) || + (dwPermissions&FPDFPERM_ANNOT_FORM); + } + } - return FALSE; + return FALSE; } -CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPage) +CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPage) { - ASSERT(pPage != NULL); - pPage->GetPDFDocument(); + CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument(); + CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pSDKDoc->GetInterForm(); + CPDF_FormControl* pCtrl = CPDFSDK_Widget::GetFormControl(pInterForm->GetInterForm(), pAnnot->GetAnnotDict()); + if (!pCtrl) + return nullptr; - CPDFSDK_Document* pSDKDoc = m_pApp->GetCurrentDoc(); - ASSERT(pSDKDoc); - CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pSDKDoc->GetInterForm(); - ASSERT(pInterForm != NULL); + CPDFSDK_Widget* pWidget = new CPDFSDK_Widget(pAnnot, pPage, pInterForm); + pInterForm->AddMap(pCtrl, pWidget); + CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); + if (pPDFInterForm && pPDFInterForm->NeedConstructAP()) + pWidget->ResetAppearance(nullptr, FALSE); - CPDFSDK_Widget* pWidget = NULL; - if (CPDF_FormControl* pCtrl = CPDFSDK_Widget::GetFormControl(pInterForm->GetInterForm(), pAnnot->GetAnnotDict())) - { - pWidget = new CPDFSDK_Widget(pAnnot, pPage, pInterForm); - pInterForm->AddMap(pCtrl, pWidget); - CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); - if(pPDFInterForm && pPDFInterForm->NeedConstructAP()) - pWidget->ResetAppearance(NULL,FALSE); - } - - return pWidget; + return pWidget; } -CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(IXFA_Widget* hWidget, CPDFSDK_PageView* pPage) +CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(IXFA_Widget* hWidget, CPDFSDK_PageView* pPage) { - return NULL; + return NULL; } void CPDFSDK_BFAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) { - ASSERT(pAnnot != NULL); + ASSERT(pAnnot != NULL); - if (m_pFormFiller) - m_pFormFiller->OnDelete(pAnnot); + if (m_pFormFiller) + m_pFormFiller->OnDelete(pAnnot); - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm(); - ASSERT(pInterForm != NULL); + CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; + CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm(); + ASSERT(pInterForm != NULL); - CPDF_FormControl* pCtrol = pWidget->GetFormControl(); - pInterForm->RemoveMap(pCtrol); + CPDF_FormControl* pCtrol = pWidget->GetFormControl(); + pInterForm->RemoveMap(pCtrol); - delete pWidget; + delete pWidget; } void CPDFSDK_BFAnnotHandler::OnDraw(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, FX_DWORD dwFlags) { - ASSERT(pAnnot != NULL); - CFX_ByteString sSubType = pAnnot->GetSubType(); + ASSERT(pAnnot != NULL); + CFX_ByteString sSubType = pAnnot->GetSubType(); - if (sSubType == BFFT_SIGNATURE) - { - ((CPDFSDK_BAAnnot*)pAnnot)->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); - } - else - { - if (m_pFormFiller) - { - m_pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags); - } - } + if (sSubType == BFFT_SIGNATURE) + { + ((CPDFSDK_BAAnnot*)pAnnot)->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); + } + else + { + if (m_pFormFiller) + { + m_pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags); + } + } } void CPDFSDK_BFAnnotHandler::OnMouseEnter(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) { - ASSERT(pAnnot != NULL); - CFX_ByteString sSubType = pAnnot->GetSubType(); + ASSERT(pAnnot != NULL); + CFX_ByteString sSubType = pAnnot->GetSubType(); - if (sSubType == BFFT_SIGNATURE) - { - } - else - { - if (m_pFormFiller) - m_pFormFiller->OnMouseEnter(pPageView, pAnnot, nFlag); - } + if (sSubType == BFFT_SIGNATURE) + { + } + else + { + if (m_pFormFiller) + m_pFormFiller->OnMouseEnter(pPageView, pAnnot, nFlag); + } } void CPDFSDK_BFAnnotHandler::OnMouseExit(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) { - ASSERT(pAnnot != NULL); - CFX_ByteString sSubType = pAnnot->GetSubType(); + ASSERT(pAnnot != NULL); + CFX_ByteString sSubType = pAnnot->GetSubType(); - if (sSubType == BFFT_SIGNATURE) - { - } - else - { - if (m_pFormFiller) - m_pFormFiller->OnMouseExit(pPageView, pAnnot, nFlag); - } + if (sSubType == BFFT_SIGNATURE) + { + } + else + { + if (m_pFormFiller) + m_pFormFiller->OnMouseExit(pPageView, pAnnot, nFlag); + } } FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) { - ASSERT(pAnnot != NULL); - CFX_ByteString sSubType = pAnnot->GetSubType(); + ASSERT(pAnnot != NULL); + CFX_ByteString sSubType = pAnnot->GetSubType(); - if (sSubType == BFFT_SIGNATURE) - { - } - else - { - if (m_pFormFiller) - return m_pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point); - } + if (sSubType == BFFT_SIGNATURE) + { + } + else + { + if (m_pFormFiller) + return m_pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point); + } - return FALSE; + return FALSE; } FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) { - ASSERT(pAnnot != NULL); - CFX_ByteString sSubType = pAnnot->GetSubType(); + ASSERT(pAnnot != NULL); + CFX_ByteString sSubType = pAnnot->GetSubType(); - if (sSubType == BFFT_SIGNATURE) - { - } - else - { - if (m_pFormFiller) - return m_pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point); - } + if (sSubType == BFFT_SIGNATURE) + { + } + else + { + if (m_pFormFiller) + return m_pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point); + } - return FALSE; + return FALSE; } FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) { - ASSERT(pAnnot != NULL); - CFX_ByteString sSubType = pAnnot->GetSubType(); + ASSERT(pAnnot != NULL); + CFX_ByteString sSubType = pAnnot->GetSubType(); - if (sSubType == BFFT_SIGNATURE) - { - } - else - { - if (m_pFormFiller) - return m_pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, point); - } + if (sSubType == BFFT_SIGNATURE) + { + } + else + { + if (m_pFormFiller) + return m_pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, point); + } - return FALSE; + return FALSE; } FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseMove(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) { - ASSERT(pAnnot != NULL); - CFX_ByteString sSubType = pAnnot->GetSubType(); + ASSERT(pAnnot != NULL); + CFX_ByteString sSubType = pAnnot->GetSubType(); - if (sSubType == BFFT_SIGNATURE) - { - } - else - { - if (m_pFormFiller) - return m_pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point); - } + if (sSubType == BFFT_SIGNATURE) + { + } + else + { + if (m_pFormFiller) + return m_pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point); + } - return FALSE; + return FALSE; } FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseWheel(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, short zDelta, const CPDF_Point& point) { - ASSERT(pAnnot != NULL); - CFX_ByteString sSubType = pAnnot->GetSubType(); + ASSERT(pAnnot != NULL); + CFX_ByteString sSubType = pAnnot->GetSubType(); - if (sSubType == BFFT_SIGNATURE) - { - } - else - { - if (m_pFormFiller) - return m_pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta,point); - } + if (sSubType == BFFT_SIGNATURE) + { + } + else + { + if (m_pFormFiller) + return m_pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta,point); + } - return FALSE; + return FALSE; } FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) { - ASSERT(pAnnot != NULL); - CFX_ByteString sSubType = pAnnot->GetSubType(); + ASSERT(pAnnot != NULL); + CFX_ByteString sSubType = pAnnot->GetSubType(); - if (sSubType == BFFT_SIGNATURE) - { - } - else - { - if (m_pFormFiller) - return m_pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point); - } + if (sSubType == BFFT_SIGNATURE) + { + } + else + { + if (m_pFormFiller) + return m_pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point); + } - return FALSE; + return FALSE; } FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) { - ASSERT(pAnnot != NULL); - CFX_ByteString sSubType = pAnnot->GetSubType(); + ASSERT(pAnnot != NULL); + CFX_ByteString sSubType = pAnnot->GetSubType(); - if (sSubType == BFFT_SIGNATURE) - { - } - else - { - if (m_pFormFiller) - return m_pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point); - } + if (sSubType == BFFT_SIGNATURE) + { + } + else + { + if (m_pFormFiller) + return m_pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point); + } - return FALSE; + return FALSE; } FX_BOOL CPDFSDK_BFAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot, FX_DWORD nChar, FX_DWORD nFlags) { - ASSERT(pAnnot != NULL); - CFX_ByteString sSubType = pAnnot->GetSubType(); + ASSERT(pAnnot != NULL); + CFX_ByteString sSubType = pAnnot->GetSubType(); - if (sSubType == BFFT_SIGNATURE) - { - } - else - { - if (m_pFormFiller) - return m_pFormFiller->OnChar(pAnnot,nChar, nFlags); - } + if (sSubType == BFFT_SIGNATURE) + { + } + else + { + if (m_pFormFiller) + return m_pFormFiller->OnChar(pAnnot,nChar, nFlags); + } - return FALSE; + return FALSE; } FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag) { - ASSERT(pAnnot != NULL); - CFX_ByteString sSubType = pAnnot->GetSubType(); + ASSERT(pAnnot != NULL); + CFX_ByteString sSubType = pAnnot->GetSubType(); - if (sSubType == BFFT_SIGNATURE) - { - } - else - { - if (m_pFormFiller) - return m_pFormFiller->OnKeyDown(pAnnot,nKeyCode, nFlag); - } + if (sSubType == BFFT_SIGNATURE) + { + } + else + { + if (m_pFormFiller) + return m_pFormFiller->OnKeyDown(pAnnot,nKeyCode, nFlag); + } - return FALSE; + return FALSE; } FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag) { - return FALSE; + return FALSE; } -void CPDFSDK_BFAnnotHandler::OnCreate(CPDFSDK_Annot* pAnnot) +void CPDFSDK_BFAnnotHandler::OnCreate(CPDFSDK_Annot* pAnnot) { - ASSERT(pAnnot != NULL); - CFX_ByteString sSubType = pAnnot->GetSubType(); + ASSERT(pAnnot != NULL); + CFX_ByteString sSubType = pAnnot->GetSubType(); - if (sSubType == BFFT_SIGNATURE) - { - } - else - { - if (m_pFormFiller) - m_pFormFiller->OnCreate(pAnnot); - } + if (sSubType == BFFT_SIGNATURE) + { + } + else + { + if (m_pFormFiller) + m_pFormFiller->OnCreate(pAnnot); + } } void CPDFSDK_BFAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) { - ASSERT(pAnnot != NULL); + ASSERT(pAnnot != NULL); - CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); - ASSERT(pPageView != NULL); + CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); + ASSERT(pPageView != NULL); - CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); - ASSERT(pSDKDoc != NULL); + CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); + ASSERT(pSDKDoc != NULL); - CPDFXFA_Document* pDoc = pSDKDoc->GetDocument(); - ASSERT(pDoc != NULL); + CPDFXFA_Document* pDoc = pSDKDoc->GetDocument(); + ASSERT(pDoc != NULL); - CFX_ByteString sSubType = pAnnot->GetSubType(); + CFX_ByteString sSubType = pAnnot->GetSubType(); - if (sSubType == BFFT_SIGNATURE) - { - } - else - { - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; - if (!pWidget->IsAppearanceValid()) - pWidget->ResetAppearance(NULL, FALSE); + if (sSubType == BFFT_SIGNATURE) + { + } + else + { + CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; + if (!pWidget->IsAppearanceValid()) + pWidget->ResetAppearance(NULL, FALSE); - int nFieldType = pWidget->GetFieldType(); - if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX) - { - FX_BOOL bFormated = FALSE; - CFX_WideString sValue = pWidget->OnFormat(bFormated); - if (bFormated && nFieldType == FIELDTYPE_COMBOBOX) - { - pWidget->ResetAppearance(sValue.c_str(), FALSE); - } - } + int nFieldType = pWidget->GetFieldType(); + if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX) + { + FX_BOOL bFormated = FALSE; + CFX_WideString sValue = pWidget->OnFormat(bFormated); + if (bFormated && nFieldType == FIELDTYPE_COMBOBOX) + { + pWidget->ResetAppearance(sValue.c_str(), FALSE); + } + } - if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) - { - if (!pWidget->IsAppearanceValid() && !pWidget->GetValue().IsEmpty()) - pWidget->ResetAppearance(FALSE); - } + if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) + { + if (!pWidget->IsAppearanceValid() && !pWidget->GetValue().IsEmpty()) + pWidget->ResetAppearance(FALSE); + } - if (m_pFormFiller) - m_pFormFiller->OnLoad(pAnnot); - } + if (m_pFormFiller) + m_pFormFiller->OnLoad(pAnnot); + } } -FX_BOOL CPDFSDK_BFAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) +FX_BOOL CPDFSDK_BFAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) { - ASSERT(pAnnot != NULL); - CFX_ByteString sSubType = pAnnot->GetSubType(); + ASSERT(pAnnot != NULL); + CFX_ByteString sSubType = pAnnot->GetSubType(); - if (sSubType == BFFT_SIGNATURE) - { - } - else - { - if (m_pFormFiller) - return m_pFormFiller->OnSetFocus(pAnnot,nFlag); - } + if (sSubType == BFFT_SIGNATURE) + { + } + else + { + if (m_pFormFiller) + return m_pFormFiller->OnSetFocus(pAnnot,nFlag); + } - return TRUE; + return TRUE; } -FX_BOOL CPDFSDK_BFAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) +FX_BOOL CPDFSDK_BFAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) { - ASSERT(pAnnot != NULL); - CFX_ByteString sSubType = pAnnot->GetSubType(); + ASSERT(pAnnot != NULL); + CFX_ByteString sSubType = pAnnot->GetSubType(); - if (sSubType == BFFT_SIGNATURE) - { - } - else - { - if (m_pFormFiller) - return m_pFormFiller->OnKillFocus(pAnnot,nFlag); - } + if (sSubType == BFFT_SIGNATURE) + { + } + else + { + if (m_pFormFiller) + return m_pFormFiller->OnKillFocus(pAnnot,nFlag); + } - return TRUE; + return TRUE; } CPDF_Rect CPDFSDK_BFAnnotHandler::GetViewBBox(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot) { - ASSERT(pAnnot != NULL); - CFX_ByteString sSubType = pAnnot->GetSubType(); + ASSERT(pAnnot != NULL); + CFX_ByteString sSubType = pAnnot->GetSubType(); - if (sSubType == BFFT_SIGNATURE) - { - } - else - { - if (m_pFormFiller) - return m_pFormFiller->GetViewBBox(pPageView, pAnnot); + if (sSubType == BFFT_SIGNATURE) + { + } + else + { + if (m_pFormFiller) + return m_pFormFiller->GetViewBBox(pPageView, pAnnot); - } + } - return CPDF_Rect(0,0,0,0); + return CPDF_Rect(0,0,0,0); } -FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, const CPDF_Point& point) +FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, const CPDF_Point& point) { - ASSERT(pPageView); - ASSERT(pAnnot); + ASSERT(pPageView); + ASSERT(pAnnot); - CPDF_Rect rect = GetViewBBox(pPageView, pAnnot); - return rect.Contains(point.x, point.y); + CPDF_Rect rect = GetViewBBox(pPageView, pAnnot); + return rect.Contains(point.x, point.y); } //CPDFSDK_XFAAnnotHandler -#define FWL_WGTHITTEST_Unknown 0 -#define FWL_WGTHITTEST_Client 1 //arrow -#define FWL_WGTHITTEST_Titlebar 11 //caption -#define FWL_WGTHITTEST_HScrollBar 15 -#define FWL_WGTHITTEST_VScrollBar 16 -#define FWL_WGTHITTEST_Border 17 -#define FWL_WGTHITTEST_Edit 19 +#define FWL_WGTHITTEST_Unknown 0 +#define FWL_WGTHITTEST_Client 1 //arrow +#define FWL_WGTHITTEST_Titlebar 11 //caption +#define FWL_WGTHITTEST_HScrollBar 15 +#define FWL_WGTHITTEST_VScrollBar 16 +#define FWL_WGTHITTEST_Border 17 +#define FWL_WGTHITTEST_Edit 19 #define FWL_WGTHITTEST_HyperLink 20 CPDFSDK_XFAAnnotHandler::CPDFSDK_XFAAnnotHandler(CPDFDoc_Environment* pApp) : - m_pApp(pApp) + m_pApp(pApp) { } CPDFSDK_Annot* CPDFSDK_XFAAnnotHandler::NewAnnot(IXFA_Widget* pAnnot, CPDFSDK_PageView* pPage) { - ASSERT(pPage != NULL); - ASSERT(pAnnot != NULL); - - CPDFSDK_Document* pSDKDoc = m_pApp->GetCurrentDoc(); - ASSERT(pSDKDoc); - CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pSDKDoc->GetInterForm(); - ASSERT(pInterForm != NULL); - - CPDFSDK_XFAWidget* pWidget = NULL; - pWidget = new CPDFSDK_XFAWidget(pAnnot, pPage, pInterForm); - ASSERT(pWidget != NULL); - pInterForm->AddXFAMap(pAnnot, pWidget); - - return pWidget; + CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument(); + CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pSDKDoc->GetInterForm(); + CPDFSDK_XFAWidget* pWidget = new CPDFSDK_XFAWidget(pAnnot, pPage, pInterForm); + pInterForm->AddXFAMap(pAnnot, pWidget); + return pWidget; } FX_BOOL CPDFSDK_XFAAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) { - ASSERT(pAnnot != NULL); - - return pAnnot->GetXFAWidget() != NULL; + return pAnnot->GetXFAWidget() != NULL; } void CPDFSDK_XFAAnnotHandler::OnDraw(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, FX_DWORD dwFlags) { - ASSERT(pPageView != NULL); - ASSERT(pAnnot != NULL); + ASSERT(pPageView != NULL); + ASSERT(pAnnot != NULL); - CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); - ASSERT(pSDKDoc != NULL); + CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); + ASSERT(pSDKDoc != NULL); - IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); - ASSERT(pWidgetHandler != NULL); + IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); + ASSERT(pWidgetHandler != NULL); - CFX_Graphics gs; - gs.Create(pDevice); + CFX_Graphics gs; + gs.Create(pDevice); - CFX_Matrix mt; - mt = *(CFX_Matrix*)pUser2Device; + CFX_Matrix mt; + mt = *(CFX_Matrix*)pUser2Device; - IXFA_Widget* hWidget = pAnnot->GetXFAWidget(); - ASSERT(hWidget != NULL); + IXFA_Widget* hWidget = pAnnot->GetXFAWidget(); + ASSERT(hWidget != NULL); - FX_BOOL bIsHighlight = FALSE; - if (pSDKDoc->GetFocusAnnot() != pAnnot) - bIsHighlight = TRUE; + FX_BOOL bIsHighlight = FALSE; + if (pSDKDoc->GetFocusAnnot() != pAnnot) + bIsHighlight = TRUE; - pWidgetHandler->RenderWidget(pAnnot->GetXFAWidget(), &gs, &mt, bIsHighlight); + pWidgetHandler->RenderWidget(pAnnot->GetXFAWidget(), &gs, &mt, bIsHighlight); - // to do highlight and shadow + // to do highlight and shadow } void CPDFSDK_XFAAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) { - ASSERT(pAnnot != NULL); + ASSERT(pAnnot != NULL); - CPDFSDK_XFAWidget* pWidget = (CPDFSDK_XFAWidget*)pAnnot; - CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm(); - ASSERT(pInterForm != NULL); + CPDFSDK_XFAWidget* pWidget = (CPDFSDK_XFAWidget*)pAnnot; + CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm(); + ASSERT(pInterForm != NULL); - pInterForm->RemoveXFAMap(pWidget->GetXFAWidget()); + pInterForm->RemoveXFAMap(pWidget->GetXFAWidget()); - delete pWidget; + delete pWidget; } CPDF_Rect CPDFSDK_XFAAnnotHandler::GetViewBBox(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot) { - ASSERT(pAnnot != NULL); + ASSERT(pAnnot != NULL); - IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); - ASSERT(pWidgetHandler != NULL); + IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); + ASSERT(pWidgetHandler != NULL); - XFA_ELEMENT eType = pWidgetHandler->GetDataAcc(pAnnot->GetXFAWidget())->GetUIType(); - CFX_RectF rcBBox; - if (eType == XFA_ELEMENT_Signature) - pWidgetHandler->GetBBox (pAnnot->GetXFAWidget(), rcBBox, XFA_WIDGETSTATUS_Visible, TRUE); - else - pWidgetHandler->GetBBox (pAnnot->GetXFAWidget(), rcBBox, 0); + XFA_ELEMENT eType = pWidgetHandler->GetDataAcc(pAnnot->GetXFAWidget())->GetUIType(); + CFX_RectF rcBBox; + if (eType == XFA_ELEMENT_Signature) + pWidgetHandler->GetBBox (pAnnot->GetXFAWidget(), rcBBox, XFA_WIDGETSTATUS_Visible, TRUE); + else + pWidgetHandler->GetBBox (pAnnot->GetXFAWidget(), rcBBox, 0); - CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width, rcBBox.top+rcBBox.height); - rcWidget.left -= 1.0f; - rcWidget.right += 1.0f; - rcWidget.bottom -= 1.0f; - rcWidget.top += 1.0f; + CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width, rcBBox.top+rcBBox.height); + rcWidget.left -= 1.0f; + rcWidget.right += 1.0f; + rcWidget.bottom -= 1.0f; + rcWidget.top += 1.0f; - return rcWidget; + return rcWidget; } FX_BOOL CPDFSDK_XFAAnnotHandler::HitTest(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, const CPDF_Point& point) { - if (!pPageView || !pAnnot) - return FALSE; + if (!pPageView || !pAnnot) + return FALSE; - CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); - if (!pSDKDoc) - return FALSE; + CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); + if (!pSDKDoc) + return FALSE; - CPDFXFA_Document* pDoc = pSDKDoc->GetDocument(); - if (!pDoc) - return FALSE; + CPDFXFA_Document* pDoc = pSDKDoc->GetDocument(); + if (!pDoc) + return FALSE; - IXFA_DocView* pDocView = pDoc->GetXFADocView(); - if (!pDocView) - return FALSE; + IXFA_DocView* pDocView = pDoc->GetXFADocView(); + if (!pDocView) + return FALSE; - IXFA_WidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler(); - if (!pWidgetHandler) - return FALSE; + IXFA_WidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler(); + if (!pWidgetHandler) + return FALSE; - FX_DWORD dwHitTest = pWidgetHandler->OnHitTest(pAnnot->GetXFAWidget(), point.x, point.y); - return (dwHitTest != FWL_WGTHITTEST_Unknown); + FX_DWORD dwHitTest = pWidgetHandler->OnHitTest(pAnnot->GetXFAWidget(), point.x, point.y); + return (dwHitTest != FWL_WGTHITTEST_Unknown); } void CPDFSDK_XFAAnnotHandler::OnMouseEnter(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) { - if (!pPageView || !pAnnot) - return; - IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); - ASSERT(pWidgetHandler != NULL); + if (!pPageView || !pAnnot) + return; + IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); + ASSERT(pWidgetHandler != NULL); - pWidgetHandler->OnMouseEnter(pAnnot->GetXFAWidget()); + pWidgetHandler->OnMouseEnter(pAnnot->GetXFAWidget()); } void CPDFSDK_XFAAnnotHandler::OnMouseExit(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) { - if (!pPageView || !pAnnot) - return; + if (!pPageView || !pAnnot) + return; - IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); - ASSERT(pWidgetHandler != NULL); + IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); + ASSERT(pWidgetHandler != NULL); - pWidgetHandler->OnMouseExit(pAnnot->GetXFAWidget()); + pWidgetHandler->OnMouseExit(pAnnot->GetXFAWidget()); } FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) { - if (!pPageView || !pAnnot) - return FALSE; + if (!pPageView || !pAnnot) + return FALSE; - IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); - ASSERT(pWidgetHandler != NULL); + IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); + ASSERT(pWidgetHandler != NULL); - FX_BOOL bRet = FALSE; - bRet = pWidgetHandler->OnLButtonDown(pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), point.x, point.y); + FX_BOOL bRet = FALSE; + bRet = pWidgetHandler->OnLButtonDown(pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), point.x, point.y); - return bRet; + return bRet; } FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) { - if (!pPageView || !pAnnot) - return FALSE; + if (!pPageView || !pAnnot) + return FALSE; - IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); - ASSERT(pWidgetHandler != NULL); + IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); + ASSERT(pWidgetHandler != NULL); - FX_BOOL bRet = FALSE; - bRet = pWidgetHandler->OnLButtonUp(pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), point.x, point.y); + FX_BOOL bRet = FALSE; + bRet = pWidgetHandler->OnLButtonUp(pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), point.x, point.y); - return bRet; + return bRet; } FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) { - if (!pPageView || !pAnnot) - return FALSE; + if (!pPageView || !pAnnot) + return FALSE; - IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); - ASSERT(pWidgetHandler != NULL); + IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); + ASSERT(pWidgetHandler != NULL); - FX_BOOL bRet = FALSE; - bRet = pWidgetHandler->OnLButtonDblClk(pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), point.x, point.y); + FX_BOOL bRet = FALSE; + bRet = pWidgetHandler->OnLButtonDblClk(pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), point.x, point.y); - return bRet; + return bRet; } FX_BOOL CPDFSDK_XFAAnnotHandler::OnMouseMove(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) { - if (!pPageView || !pAnnot) - return FALSE; + if (!pPageView || !pAnnot) + return FALSE; - IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); - ASSERT(pWidgetHandler != NULL); + IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); + ASSERT(pWidgetHandler != NULL); - FX_BOOL bRet = FALSE; - bRet = pWidgetHandler->OnMouseMove(pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), point.x, point.y); + FX_BOOL bRet = FALSE; + bRet = pWidgetHandler->OnMouseMove(pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), point.x, point.y); - return bRet; + return bRet; } FX_BOOL CPDFSDK_XFAAnnotHandler::OnMouseWheel(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, short zDelta, const CPDF_Point& point) { - if (!pPageView || !pAnnot) - return FALSE; + if (!pPageView || !pAnnot) + return FALSE; - IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); - ASSERT(pWidgetHandler != NULL); + IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); + ASSERT(pWidgetHandler != NULL); - FX_BOOL bRet = FALSE; - bRet = pWidgetHandler->OnMouseWheel(pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), zDelta, point.x, point.y); + FX_BOOL bRet = FALSE; + bRet = pWidgetHandler->OnMouseWheel(pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), zDelta, point.x, point.y); - return bRet; + return bRet; } FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) { - if (!pPageView || !pAnnot) - return FALSE; + if (!pPageView || !pAnnot) + return FALSE; - IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); - ASSERT(pWidgetHandler != NULL); + IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); + ASSERT(pWidgetHandler != NULL); - FX_BOOL bRet = FALSE; - bRet = pWidgetHandler->OnRButtonDown(pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), point.x, point.y); + FX_BOOL bRet = FALSE; + bRet = pWidgetHandler->OnRButtonDown(pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), point.x, point.y); - return bRet; + return bRet; } FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) { - if (!pPageView || !pAnnot) - return FALSE; + if (!pPageView || !pAnnot) + return FALSE; - IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); - ASSERT(pWidgetHandler != NULL); + IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); + ASSERT(pWidgetHandler != NULL); - FX_BOOL bRet = FALSE; - bRet = pWidgetHandler->OnRButtonUp(pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), point.x, point.y); + FX_BOOL bRet = FALSE; + bRet = pWidgetHandler->OnRButtonUp(pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), point.x, point.y); - return bRet; + return bRet; } FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) { - if (!pPageView || !pAnnot) - return FALSE; + if (!pPageView || !pAnnot) + return FALSE; - IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); - ASSERT(pWidgetHandler != NULL); + IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); + ASSERT(pWidgetHandler != NULL); - FX_BOOL bRet = FALSE; - bRet = pWidgetHandler->OnRButtonDblClk(pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), point.x, point.y); + FX_BOOL bRet = FALSE; + bRet = pWidgetHandler->OnRButtonDblClk(pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), point.x, point.y); - return bRet; + return bRet; } FX_BOOL CPDFSDK_XFAAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot, FX_DWORD nChar, FX_DWORD nFlags) { - if (!pAnnot) - return FALSE; + if (!pAnnot) + return FALSE; - IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); - ASSERT(pWidgetHandler != NULL); + IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); + ASSERT(pWidgetHandler != NULL); - FX_BOOL bRet = FALSE; - bRet = pWidgetHandler->OnChar(pAnnot->GetXFAWidget(), nChar, GetFWLFlags(nFlags)); + FX_BOOL bRet = FALSE; + bRet = pWidgetHandler->OnChar(pAnnot->GetXFAWidget(), nChar, GetFWLFlags(nFlags)); - return bRet; + return bRet; } FX_BOOL CPDFSDK_XFAAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag) { - if (!pAnnot) - return FALSE; + if (!pAnnot) + return FALSE; - IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); - ASSERT(pWidgetHandler != NULL); + IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); + ASSERT(pWidgetHandler != NULL); - FX_BOOL bRet = FALSE; - bRet = pWidgetHandler->OnKeyDown(pAnnot->GetXFAWidget(), nKeyCode, GetFWLFlags(nFlag)); + FX_BOOL bRet = FALSE; + bRet = pWidgetHandler->OnKeyDown(pAnnot->GetXFAWidget(), nKeyCode, GetFWLFlags(nFlag)); - return bRet; + return bRet; } FX_BOOL CPDFSDK_XFAAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag) { - if (!pAnnot) - return FALSE; + if (!pAnnot) + return FALSE; - IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); - ASSERT(pWidgetHandler != NULL); + IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); + ASSERT(pWidgetHandler != NULL); - FX_BOOL bRet = FALSE; - bRet = pWidgetHandler->OnKeyUp(pAnnot->GetXFAWidget(), nKeyCode, GetFWLFlags(nFlag)); + FX_BOOL bRet = FALSE; + bRet = pWidgetHandler->OnKeyUp(pAnnot->GetXFAWidget(), nKeyCode, GetFWLFlags(nFlag)); - return bRet; + return bRet; } FX_BOOL CPDFSDK_XFAAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) { - return TRUE; + return TRUE; } FX_BOOL CPDFSDK_XFAAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag) { - return TRUE; + return TRUE; } FX_BOOL CPDFSDK_XFAAnnotHandler::OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot, CPDFSDK_Annot* pNewAnnot) { - IXFA_WidgetHandler* pWidgetHandler = NULL; - - if (pOldAnnot) - pWidgetHandler = GetXFAWidgetHandler(pOldAnnot); - else if (pNewAnnot) - pWidgetHandler = GetXFAWidgetHandler(pNewAnnot); - - if (pWidgetHandler) - { - FX_BOOL bRet = TRUE; - IXFA_Widget* hWidget = pNewAnnot ? pNewAnnot->GetXFAWidget() : NULL; - if (hWidget) - { - IXFA_PageView* pXFAPageView = pWidgetHandler->GetPageView(hWidget); - if (pXFAPageView) - { - bRet = pXFAPageView->GetDocView()->SetFocus(hWidget); - if (pXFAPageView->GetDocView()->GetFocusWidget() == hWidget) - bRet = TRUE; - } - } - return bRet; - } - - return TRUE; + IXFA_WidgetHandler* pWidgetHandler = NULL; + + if (pOldAnnot) + pWidgetHandler = GetXFAWidgetHandler(pOldAnnot); + else if (pNewAnnot) + pWidgetHandler = GetXFAWidgetHandler(pNewAnnot); + + if (pWidgetHandler) + { + FX_BOOL bRet = TRUE; + IXFA_Widget* hWidget = pNewAnnot ? pNewAnnot->GetXFAWidget() : NULL; + if (hWidget) + { + IXFA_PageView* pXFAPageView = pWidgetHandler->GetPageView(hWidget); + if (pXFAPageView) + { + bRet = pXFAPageView->GetDocView()->SetFocus(hWidget); + if (pXFAPageView->GetDocView()->GetFocusWidget() == hWidget) + bRet = TRUE; + } + } + return bRet; + } + + return TRUE; } IXFA_WidgetHandler* CPDFSDK_XFAAnnotHandler::GetXFAWidgetHandler(CPDFSDK_Annot* pAnnot) { - if (!pAnnot) - return NULL; + if (!pAnnot) + return NULL; - CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); - if (!pPageView) - return NULL; + CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); + if (!pPageView) + return NULL; - CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); - if (!pSDKDoc) - return NULL; + CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); + if (!pSDKDoc) + return NULL; - CPDFXFA_Document* pDoc = pSDKDoc->GetDocument(); - if (!pDoc) - return NULL; + CPDFXFA_Document* pDoc = pSDKDoc->GetDocument(); + if (!pDoc) + return NULL; - IXFA_DocView* pDocView = pDoc->GetXFADocView(); - if (!pDocView) - return NULL; + IXFA_DocView* pDocView = pDoc->GetXFADocView(); + if (!pDocView) + return NULL; - return pDocView->GetWidgetHandler(); + return pDocView->GetWidgetHandler(); } -#define FWL_KEYFLAG_Ctrl (1 << 0) -#define FWL_KEYFLAG_Alt (1 << 1) -#define FWL_KEYFLAG_Shift (1 << 2) -#define FWL_KEYFLAG_LButton (1 << 3) -#define FWL_KEYFLAG_RButton (1 << 4) -#define FWL_KEYFLAG_MButton (1 << 5) +#define FWL_KEYFLAG_Ctrl (1 << 0) +#define FWL_KEYFLAG_Alt (1 << 1) +#define FWL_KEYFLAG_Shift (1 << 2) +#define FWL_KEYFLAG_LButton (1 << 3) +#define FWL_KEYFLAG_RButton (1 << 4) +#define FWL_KEYFLAG_MButton (1 << 5) FX_DWORD CPDFSDK_XFAAnnotHandler::GetFWLFlags(FX_DWORD dwFlag) { - FX_DWORD dwFWLFlag = 0; + FX_DWORD dwFWLFlag = 0; - if (dwFlag & FWL_EVENTFLAG_ControlKey) - dwFWLFlag |= FWL_KEYFLAG_Ctrl; - if (dwFlag & FWL_EVENTFLAG_LeftButtonDown) - dwFWLFlag |= FWL_KEYFLAG_LButton; - if (dwFlag & FWL_EVENTFLAG_MiddleButtonDown) - dwFWLFlag |= FWL_KEYFLAG_MButton; - if (dwFlag & FWL_EVENTFLAG_RightButtonDown) - dwFWLFlag |= FWL_KEYFLAG_RButton; - if (dwFlag & FWL_EVENTFLAG_ShiftKey) - dwFWLFlag |= FWL_KEYFLAG_Shift; - if (dwFlag & FWL_EVENTFLAG_AltKey) - dwFWLFlag |= FWL_KEYFLAG_Alt; + if (dwFlag & FWL_EVENTFLAG_ControlKey) + dwFWLFlag |= FWL_KEYFLAG_Ctrl; + if (dwFlag & FWL_EVENTFLAG_LeftButtonDown) + dwFWLFlag |= FWL_KEYFLAG_LButton; + if (dwFlag & FWL_EVENTFLAG_MiddleButtonDown) + dwFWLFlag |= FWL_KEYFLAG_MButton; + if (dwFlag & FWL_EVENTFLAG_RightButtonDown) + dwFWLFlag |= FWL_KEYFLAG_RButton; + if (dwFlag & FWL_EVENTFLAG_ShiftKey) + dwFWLFlag |= FWL_KEYFLAG_Shift; + if (dwFlag & FWL_EVENTFLAG_AltKey) + dwFWLFlag |= FWL_KEYFLAG_Alt; - return dwFWLFlag; + return dwFWLFlag; } //CReader_AnnotIteratorEx CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView * pPageView,FX_BOOL bReverse, - FX_BOOL bIgnoreTopmost/*=FALSE*/, - FX_BOOL bCircle/*=FALSE*/, - CFX_PtrArray *pList/*=NULL*/) -{ - ASSERT(pPageView); - m_bReverse=bReverse; - m_bIgnoreTopmost= bIgnoreTopmost; - m_bCircle=bCircle; - m_pIteratorAnnotList.RemoveAll(); - InitIteratorAnnotList(pPageView,pList); -} - -CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot (const CPDFSDK_Annot* pCurrent) -{ - - int index = -1; - int nCount = m_pIteratorAnnotList.GetSize(); - if (pCurrent) { - for(int i=0;i<nCount;i++){ - CPDFSDK_Annot * pReaderAnnot= (CPDFSDK_Annot *)m_pIteratorAnnotList.GetAt(i); - if(pReaderAnnot ==pCurrent){ - index=i; - break; - } - } - } - return NextAnnot(index); -} -CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot (const CPDFSDK_Annot*pCurrent) -{ - int index = -1; - int nCount = m_pIteratorAnnotList.GetSize(); - if(pCurrent){ - for(int i=0;i<nCount;i++){ - CPDFSDK_Annot * pReaderAnnot= (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(i); - if(pReaderAnnot ==pCurrent){ - index=i; - break; - } - } - } - return PrevAnnot(index); -} -CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot (int& index) -{ - - int nCount=m_pIteratorAnnotList.GetSize(); + FX_BOOL bIgnoreTopmost/*=FALSE*/, + FX_BOOL bCircle/*=FALSE*/, + CFX_PtrArray *pList/*=NULL*/) +{ + ASSERT(pPageView); + m_bReverse=bReverse; + m_bIgnoreTopmost= bIgnoreTopmost; + m_bCircle=bCircle; + m_pIteratorAnnotList.RemoveAll(); + InitIteratorAnnotList(pPageView,pList); +} + +CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot (const CPDFSDK_Annot* pCurrent) +{ + + int index = -1; + int nCount = m_pIteratorAnnotList.GetSize(); + if (pCurrent) { + for(int i=0;i<nCount;i++){ + CPDFSDK_Annot * pReaderAnnot= (CPDFSDK_Annot *)m_pIteratorAnnotList.GetAt(i); + if(pReaderAnnot ==pCurrent){ + index=i; + break; + } + } + } + return NextAnnot(index); +} +CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot (const CPDFSDK_Annot*pCurrent) +{ + int index = -1; + int nCount = m_pIteratorAnnotList.GetSize(); + if(pCurrent){ + for(int i=0;i<nCount;i++){ + CPDFSDK_Annot * pReaderAnnot= (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(i); + if(pReaderAnnot ==pCurrent){ + index=i; + break; + } + } + } + return PrevAnnot(index); +} +CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot (int& index) +{ + + int nCount=m_pIteratorAnnotList.GetSize(); if(nCount<=0) index=-1; else{ - if(index<0){ - index=0; - } - else{ - if(m_bCircle){ - index=( index <nCount-1) ? (index+1) :0; - } - else{ - index=( index <nCount-1) ? (index+1) :-1; - } + if(index<0){ + index=0; + } + else{ + if(m_bCircle){ + index=( index <nCount-1) ? (index+1) :0; + } + else{ + index=( index <nCount-1) ? (index+1) :-1; + } - } - } - return (index <0) ? NULL : (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(index); + } + } + return (index <0) ? NULL : (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(index); } -CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot (int& index) +CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot (int& index) { - int nCount=m_pIteratorAnnotList.GetSize(); + int nCount=m_pIteratorAnnotList.GetSize(); if(nCount<=0) index=-1; - else{ - if(index<0){ - index=nCount-1; - } - else{ - if(m_bCircle){ - index = ( index >0) ? (index-1) :nCount-1; - } - else{ - index = ( index >0) ? (index-1) :-1; - } - } - } - return (index <0) ? NULL : (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(index); + else{ + if(index<0){ + index=nCount-1; + } + else{ + if(m_bCircle){ + index = ( index >0) ? (index-1) :nCount-1; + } + else{ + index = ( index >0) ? (index-1) :-1; + } + } + } + return (index <0) ? NULL : (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(index); } CPDFSDK_Annot*CPDFSDK_AnnotIterator::Next(const CPDFSDK_Annot* pCurrent) { - return (m_bReverse) ? PrevAnnot(pCurrent):NextAnnot(pCurrent); + return (m_bReverse) ? PrevAnnot(pCurrent):NextAnnot(pCurrent); } -CPDFSDK_Annot* CPDFSDK_AnnotIterator::Prev(const CPDFSDK_Annot* pCurrent) +CPDFSDK_Annot* CPDFSDK_AnnotIterator::Prev(const CPDFSDK_Annot* pCurrent) { - return (m_bReverse) ? NextAnnot(pCurrent):PrevAnnot(pCurrent); + return (m_bReverse) ? NextAnnot(pCurrent):PrevAnnot(pCurrent); } CPDFSDK_Annot*CPDFSDK_AnnotIterator::Next(int& index ) { - return (m_bReverse) ? PrevAnnot(index):NextAnnot(index); + return (m_bReverse) ? PrevAnnot(index):NextAnnot(index); } -CPDFSDK_Annot* CPDFSDK_AnnotIterator::Prev(int& index ) +CPDFSDK_Annot* CPDFSDK_AnnotIterator::Prev(int& index ) { - return (m_bReverse) ? NextAnnot(index):PrevAnnot(index); + return (m_bReverse) ? NextAnnot(index):PrevAnnot(index); } void CPDFSDK_AnnotIterator::InsertSort(CFX_PtrArray &arrayList, AI_COMPARE pCompare) { - for (int i = 1; i < arrayList.GetSize(); i++) - { - if (pCompare((CPDFSDK_Annot*)(arrayList[i]) , (CPDFSDK_Annot*)(arrayList[i-1])) < 0) - { - int j = i-1; - CPDFSDK_Annot* pTemp = (CPDFSDK_Annot*)arrayList[i]; + for (int i = 1; i < arrayList.GetSize(); i++) + { + if (pCompare((CPDFSDK_Annot*)(arrayList[i]) , (CPDFSDK_Annot*)(arrayList[i-1])) < 0) + { + int j = i-1; + CPDFSDK_Annot* pTemp = (CPDFSDK_Annot*)arrayList[i]; - do - { - arrayList[j + 1] = arrayList[j]; - } while (--j >= 0 && pCompare(pTemp, (CPDFSDK_Annot*)arrayList[j]) < 0); + do + { + arrayList[j + 1] = arrayList[j]; + } while (--j >= 0 && pCompare(pTemp, (CPDFSDK_Annot*)arrayList[j]) < 0); - arrayList[j+1] = pTemp; - } - } + arrayList[j+1] = pTemp; + } + } } int LyOrderCompare(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2) { - if(p1->GetLayoutOrder() < p2->GetLayoutOrder()) - return -1; - else if (p1->GetLayoutOrder() == p2->GetLayoutOrder()) - return 0; - else - return 1; + if(p1->GetLayoutOrder() < p2->GetLayoutOrder()) + return -1; + else if (p1->GetLayoutOrder() == p2->GetLayoutOrder()) + return 0; + else + return 1; } FX_BOOL CPDFSDK_AnnotIterator::InitIteratorAnnotList(CPDFSDK_PageView* pPageView,CFX_PtrArray * pAnnotList) { - ASSERT(pPageView); + ASSERT(pPageView); - if(pAnnotList==NULL){ - pAnnotList=pPageView->GetAnnotList(); - } + if(pAnnotList==NULL){ + pAnnotList=pPageView->GetAnnotList(); + } - m_pIteratorAnnotList.RemoveAll(); - if(!pAnnotList) return FALSE; + m_pIteratorAnnotList.RemoveAll(); + if(!pAnnotList) return FALSE; - CPDFSDK_Annot * pTopMostAnnot= (m_bIgnoreTopmost) ? NULL : pPageView->GetFocusAnnot(); + CPDFSDK_Annot * pTopMostAnnot= (m_bIgnoreTopmost) ? NULL : pPageView->GetFocusAnnot(); - int nCount =pAnnotList->GetSize(); + int nCount =pAnnotList->GetSize(); - for(int i = nCount- 1 ;i >= 0;i--) - { - CPDFSDK_Annot * pReaderAnnot= (CPDFSDK_Annot*)pAnnotList->GetAt(i); - m_pIteratorAnnotList.Add(pReaderAnnot); - } + for(int i = nCount- 1 ;i >= 0;i--) + { + CPDFSDK_Annot * pReaderAnnot= (CPDFSDK_Annot*)pAnnotList->GetAt(i); + m_pIteratorAnnotList.Add(pReaderAnnot); + } - InsertSort(m_pIteratorAnnotList,&LyOrderCompare); + InsertSort(m_pIteratorAnnotList,&LyOrderCompare); - if(pTopMostAnnot) - { - for(int i=0 ;i<nCount;i++) - { - CPDFSDK_Annot * pReaderAnnot = (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(i); - if(pReaderAnnot == pTopMostAnnot) - { - m_pIteratorAnnotList.RemoveAt(i); - m_pIteratorAnnotList.InsertAt(0, pReaderAnnot); - break; - } - } - } + if(pTopMostAnnot) + { + for(int i=0 ;i<nCount;i++) + { + CPDFSDK_Annot * pReaderAnnot = (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(i); + if(pReaderAnnot == pTopMostAnnot) + { + m_pIteratorAnnotList.RemoveAt(i); + m_pIteratorAnnotList.InsertAt(0, pReaderAnnot); + break; + } + } + } - return TRUE; + return TRUE; } - diff --git a/fpdfsdk/src/fsdk_mgr.cpp b/fpdfsdk/src/fsdk_mgr.cpp index 1169d79a22..234f1fe2d4 100644 --- a/fpdfsdk/src/fsdk_mgr.cpp +++ b/fpdfsdk/src/fsdk_mgr.cpp @@ -24,208 +24,204 @@ class CFX_SystemHandler:public IFX_SystemHandler { public: - CFX_SystemHandler(CPDFDoc_Environment* pEnv):m_pEnv(pEnv),m_nCharSet(-1) {} + CFX_SystemHandler(CPDFDoc_Environment* pEnv):m_pEnv(pEnv),m_nCharSet(-1) {} public: - virtual void InvalidateRect(FX_HWND hWnd, FX_RECT rect) ; - virtual void OutputSelectedRect(void* pFormFiller, CPDF_Rect& rect); + virtual void InvalidateRect(FX_HWND hWnd, FX_RECT rect) ; + virtual void OutputSelectedRect(void* pFormFiller, CPDF_Rect& rect); - virtual FX_BOOL IsSelectionImplemented(); + virtual FX_BOOL IsSelectionImplemented(); - virtual CFX_WideString GetClipboardText(FX_HWND hWnd){return L"";} - virtual FX_BOOL SetClipboardText(FX_HWND hWnd, CFX_WideString string) {return FALSE;} + virtual CFX_WideString GetClipboardText(FX_HWND hWnd){return L"";} + virtual FX_BOOL SetClipboardText(FX_HWND hWnd, CFX_WideString string) {return FALSE;} - virtual void ClientToScreen(FX_HWND hWnd, int32_t& x, int32_t& y) {} - virtual void ScreenToClient(FX_HWND hWnd, int32_t& x, int32_t& y) {} + virtual void ClientToScreen(FX_HWND hWnd, int32_t& x, int32_t& y) {} + virtual void ScreenToClient(FX_HWND hWnd, int32_t& x, int32_t& y) {} - /*cursor style - FXCT_ARROW - FXCT_NESW - FXCT_NWSE - FXCT_VBEAM - FXCT_HBEAM - FXCT_HAND - */ - virtual void SetCursor(int32_t nCursorType); + /*cursor style + FXCT_ARROW + FXCT_NESW + FXCT_NWSE + FXCT_VBEAM + FXCT_HBEAM + FXCT_HAND + */ + virtual void SetCursor(int32_t nCursorType); - virtual FX_HMENU CreatePopupMenu() {return NULL;} - virtual FX_BOOL AppendMenuItem(FX_HMENU hMenu, int32_t nIDNewItem, CFX_WideString string) {return FALSE;} - virtual FX_BOOL EnableMenuItem(FX_HMENU hMenu, int32_t nIDItem, FX_BOOL bEnabled) {return FALSE;} - virtual int32_t TrackPopupMenu(FX_HMENU hMenu, int32_t x, int32_t y, FX_HWND hParent) {return -1;} - virtual void DestroyMenu(FX_HMENU hMenu) {} + virtual FX_HMENU CreatePopupMenu() {return NULL;} + virtual FX_BOOL AppendMenuItem(FX_HMENU hMenu, int32_t nIDNewItem, CFX_WideString string) {return FALSE;} + virtual FX_BOOL EnableMenuItem(FX_HMENU hMenu, int32_t nIDItem, FX_BOOL bEnabled) {return FALSE;} + virtual int32_t TrackPopupMenu(FX_HMENU hMenu, int32_t x, int32_t y, FX_HWND hParent) {return -1;} + virtual void DestroyMenu(FX_HMENU hMenu) {} - virtual CFX_ByteString GetNativeTrueTypeFont(int32_t nCharset); - virtual FX_BOOL FindNativeTrueTypeFont(int32_t nCharset, CFX_ByteString sFontFaceName); - virtual CPDF_Font* AddNativeTrueTypeFontToPDF(CPDF_Document* pDoc, CFX_ByteString sFontFaceName, uint8_t nCharset); + virtual CFX_ByteString GetNativeTrueTypeFont(int32_t nCharset); + virtual FX_BOOL FindNativeTrueTypeFont(int32_t nCharset, CFX_ByteString sFontFaceName); + virtual CPDF_Font* AddNativeTrueTypeFontToPDF(CPDF_Document* pDoc, CFX_ByteString sFontFaceName, uint8_t nCharset); - virtual int32_t SetTimer(int32_t uElapse, TimerCallback lpTimerFunc) ; - virtual void KillTimer(int32_t nID) ; + virtual int32_t SetTimer(int32_t uElapse, TimerCallback lpTimerFunc) ; + virtual void KillTimer(int32_t nID) ; - virtual FX_BOOL IsSHIFTKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsSHIFTKeyDown(nFlag);} - virtual FX_BOOL IsCTRLKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsCTRLKeyDown(nFlag);} - virtual FX_BOOL IsALTKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsALTKeyDown(nFlag);} - virtual FX_BOOL IsINSERTKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsINSERTKeyDown(nFlag);} + virtual FX_BOOL IsSHIFTKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsSHIFTKeyDown(nFlag);} + virtual FX_BOOL IsCTRLKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsCTRLKeyDown(nFlag);} + virtual FX_BOOL IsALTKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsALTKeyDown(nFlag);} + virtual FX_BOOL IsINSERTKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsINSERTKeyDown(nFlag);} - virtual FX_SYSTEMTIME GetLocalTime(); + virtual FX_SYSTEMTIME GetLocalTime(); - virtual int32_t GetCharSet() {return m_nCharSet;} - virtual void SetCharSet(int32_t nCharSet) {m_nCharSet = nCharSet;} + virtual int32_t GetCharSet() {return m_nCharSet;} + virtual void SetCharSet(int32_t nCharSet) {m_nCharSet = nCharSet;} private: - CPDFDoc_Environment* m_pEnv; - int m_nCharSet; + CPDFDoc_Environment* m_pEnv; + int m_nCharSet; }; void CFX_SystemHandler::SetCursor(int32_t nCursorType) { - m_pEnv->FFI_SetCursor(nCursorType); + m_pEnv->FFI_SetCursor(nCursorType); } void CFX_SystemHandler::InvalidateRect(FX_HWND hWnd, FX_RECT rect) { - //g_pFormFillApp->FFI_Invalidate(); - CPDFSDK_Annot* pSDKAnnot = (CPDFSDK_Annot*)hWnd; - CPDFXFA_Page* pPage = NULL; - CPDFSDK_PageView* pPageView = NULL; - pPageView = pSDKAnnot->GetPageView(); - pPage = pSDKAnnot->GetPDFXFAPage(); - if(!pPage || !pPageView) - return; - CPDF_Matrix page2device; - pPageView->GetCurrentMatrix(page2device); - CPDF_Matrix device2page; - device2page.SetReverse(page2device); - FX_FLOAT left, top, right,bottom; - device2page.Transform((FX_FLOAT)rect.left, (FX_FLOAT)rect.top, left, top); - device2page.Transform((FX_FLOAT)rect.right, (FX_FLOAT)rect.bottom, right, bottom); -// m_pEnv->FFI_DeviceToPage(pPage, rect.left, rect.top, (double*)&left, (double*)&top); -// m_pEnv->FFI_DeviceToPage(pPage, rect.right, rect.bottom, (double*)&right, (double*)&bottom); - CPDF_Rect rcPDF(left, bottom, right, top); - rcPDF.Normalize(); - - m_pEnv->FFI_Invalidate(pPage, rcPDF.left, rcPDF.top, rcPDF.right, rcPDF.bottom); + //g_pFormFillApp->FFI_Invalidate(); + CPDFSDK_Annot* pSDKAnnot = (CPDFSDK_Annot*)hWnd; + CPDFXFA_Page* pPage = NULL; + CPDFSDK_PageView* pPageView = NULL; + pPageView = pSDKAnnot->GetPageView(); + pPage = pSDKAnnot->GetPDFXFAPage(); + if(!pPage || !pPageView) + return; + CPDF_Matrix page2device; + pPageView->GetCurrentMatrix(page2device); + CPDF_Matrix device2page; + device2page.SetReverse(page2device); + FX_FLOAT left, top, right,bottom; + device2page.Transform((FX_FLOAT)rect.left, (FX_FLOAT)rect.top, left, top); + device2page.Transform((FX_FLOAT)rect.right, (FX_FLOAT)rect.bottom, right, bottom); +// m_pEnv->FFI_DeviceToPage(pPage, rect.left, rect.top, (double*)&left, (double*)&top); +// m_pEnv->FFI_DeviceToPage(pPage, rect.right, rect.bottom, (double*)&right, (double*)&bottom); + CPDF_Rect rcPDF(left, bottom, right, top); + rcPDF.Normalize(); + + m_pEnv->FFI_Invalidate(pPage, rcPDF.left, rcPDF.top, rcPDF.right, rcPDF.bottom); } void CFX_SystemHandler::OutputSelectedRect(void* pFormFiller, CPDF_Rect& rect) { - CFFL_FormFiller* pFFL = (CFFL_FormFiller*)pFormFiller; - if(pFFL) - { - CPDF_Point leftbottom = CPDF_Point(rect.left, rect.bottom); - CPDF_Point righttop = CPDF_Point(rect.right, rect.top); - CPDF_Point ptA = pFFL->PWLtoFFL(leftbottom); - CPDF_Point ptB = pFFL->PWLtoFFL(righttop); - - - CPDFSDK_Annot* pAnnot = pFFL->GetSDKAnnot(); - ASSERT(pAnnot); - CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage(); - ASSERT(pPage); - m_pEnv->FFI_OutputSelectedRect(pPage, ptA.x, ptB.y, ptB.x, ptA.y); - } - + CFFL_FormFiller* pFFL = (CFFL_FormFiller*)pFormFiller; + if(pFFL) + { + CPDF_Point leftbottom = CPDF_Point(rect.left, rect.bottom); + CPDF_Point righttop = CPDF_Point(rect.right, rect.top); + CPDF_Point ptA = pFFL->PWLtoFFL(leftbottom); + CPDF_Point ptB = pFFL->PWLtoFFL(righttop); + CPDFSDK_Annot* pAnnot = pFFL->GetSDKAnnot(); + ASSERT(pAnnot); + CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage(); + ASSERT(pPage); + m_pEnv->FFI_OutputSelectedRect(pPage, ptA.x, ptB.y, ptB.x, ptA.y); + } } FX_BOOL CFX_SystemHandler::IsSelectionImplemented() { - if(m_pEnv) - { - FPDF_FORMFILLINFO* pInfo = m_pEnv->GetFormFillInfo(); - if(pInfo && pInfo->FFI_OutputSelectedRect) - return TRUE; - } - return FALSE; + if(m_pEnv) + { + FPDF_FORMFILLINFO* pInfo = m_pEnv->GetFormFillInfo(); + if(pInfo && pInfo->FFI_OutputSelectedRect) + return TRUE; + } + return FALSE; } CFX_ByteString CFX_SystemHandler::GetNativeTrueTypeFont(int32_t nCharset) { - return ""; + return ""; } -FX_BOOL CFX_SystemHandler::FindNativeTrueTypeFont(int32_t nCharset, CFX_ByteString sFontFaceName) +FX_BOOL CFX_SystemHandler::FindNativeTrueTypeFont(int32_t nCharset, CFX_ByteString sFontFaceName) { - CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); -// FXFT_Face nFace = pFontMgr->FindSubstFont(sFontFaceName,TRUE,0,0,0,0,NULL); -// FXFT_Face nFace = pFontMgr->m_pBuiltinMapper->FindSubstFont(sFontFaceName,TRUE,0,0,0,0,NULL); - - if(pFontMgr) - { - CFX_FontMapper* pFontMapper = pFontMgr->m_pBuiltinMapper; - if(pFontMapper) - { - int nSize = pFontMapper->m_InstalledTTFonts.GetSize(); - if(nSize ==0) - { - pFontMapper->LoadInstalledFonts(); - nSize = pFontMapper->m_InstalledTTFonts.GetSize(); - } + CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); +// FXFT_Face nFace = pFontMgr->FindSubstFont(sFontFaceName,TRUE,0,0,0,0,NULL); +// FXFT_Face nFace = pFontMgr->m_pBuiltinMapper->FindSubstFont(sFontFaceName,TRUE,0,0,0,0,NULL); - for(int i=0; i<nSize; i++) - { - if(pFontMapper->m_InstalledTTFonts[i].Compare(sFontFaceName)) - return TRUE; - } - } + if(pFontMgr) + { + CFX_FontMapper* pFontMapper = pFontMgr->m_pBuiltinMapper; + if(pFontMapper) + { + int nSize = pFontMapper->m_InstalledTTFonts.GetSize(); + if(nSize ==0) + { + pFontMapper->LoadInstalledFonts(); + nSize = pFontMapper->m_InstalledTTFonts.GetSize(); + } + + for(int i=0; i<nSize; i++) + { + if(pFontMapper->m_InstalledTTFonts[i].Compare(sFontFaceName)) + return TRUE; + } + } - } + } - return FALSE; -// pFontMgr->m_FaceMap.Lookup(sFontFaceName,pFont); -// return (pFont!=NULL); + return FALSE; +// pFontMgr->m_FaceMap.Lookup(sFontFaceName,pFont); +// return (pFont!=NULL); } static int CharSet2CP(int charset) { - if(charset == 128) - return 932; - else if(charset == 134) - return 936; - else if(charset == 129) - return 949; - else if(charset == 136) - return 950; - return 0; + if(charset == 128) + return 932; + else if(charset == 134) + return 936; + else if(charset == 129) + return 949; + else if(charset == 136) + return 950; + return 0; } CPDF_Font* CFX_SystemHandler::AddNativeTrueTypeFontToPDF(CPDF_Document* pDoc, CFX_ByteString sFontFaceName, - uint8_t nCharset) + uint8_t nCharset) { - if(pDoc) - { - CFX_Font* pFXFont = new CFX_Font(); - pFXFont->LoadSubst(sFontFaceName,TRUE,0,0,0,CharSet2CP(nCharset),FALSE); - CPDF_Font* pFont = pDoc->AddFont(pFXFont,nCharset,FALSE); - delete pFXFont; - return pFont; - } + if(pDoc) + { + CFX_Font* pFXFont = new CFX_Font(); + pFXFont->LoadSubst(sFontFaceName,TRUE,0,0,0,CharSet2CP(nCharset),FALSE); + CPDF_Font* pFont = pDoc->AddFont(pFXFont,nCharset,FALSE); + delete pFXFont; + return pFont; + } - return NULL; + return NULL; } int32_t CFX_SystemHandler::SetTimer(int32_t uElapse, TimerCallback lpTimerFunc) { - return m_pEnv->FFI_SetTimer(uElapse, lpTimerFunc); + return m_pEnv->FFI_SetTimer(uElapse, lpTimerFunc); } void CFX_SystemHandler::KillTimer(int32_t nID) { - m_pEnv->FFI_KillTimer(nID); + m_pEnv->FFI_KillTimer(nID); } FX_SYSTEMTIME CFX_SystemHandler::GetLocalTime() { - return m_pEnv->FFI_GetLocalTime(); + return m_pEnv->FFI_GetLocalTime(); } -CPDFDoc_Environment::CPDFDoc_Environment(CPDFXFA_Document* pDoc) : - m_pAnnotHandlerMgr(NULL), - m_pActionHandler(NULL), - m_pJSRuntime(NULL), - m_pInfo(NULL), - m_pSDKDoc(NULL), - m_pDoc(pDoc), - m_pIFormFiller(NULL) +CPDFDoc_Environment::CPDFDoc_Environment(CPDFXFA_Document* pDoc, FPDF_FORMFILLINFO* pFFinfo) : + m_pAnnotHandlerMgr(NULL), + m_pActionHandler(NULL), + m_pJSRuntime(NULL), + m_pInfo(pFFinfo), + m_pSDKDoc(NULL), + m_pXFADoc(pDoc), + m_pIFormFiller(NULL) { - m_pSysHandler = NULL; - m_pSysHandler = new CFX_SystemHandler(this); + m_pSysHandler = new CFX_SystemHandler(this); } CPDFDoc_Environment::~CPDFDoc_Environment() @@ -253,64 +249,172 @@ CPDFDoc_Environment::~CPDFDoc_Environment() m_pActionHandler = NULL; } +int CPDFDoc_Environment::JS_appAlert(const FX_WCHAR* Msg, const FX_WCHAR* Title, FX_UINT Type, FX_UINT Icon) +{ + if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert) + { + CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode(); + CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode(); + FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength()); + FPDF_WIDESTRING pTitle = (FPDF_WIDESTRING)bsTitle.GetBuffer(bsTitle.GetLength()); + int ret = m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, pMsg, pTitle, Type, Icon); + bsMsg.ReleaseBuffer(); + bsTitle.ReleaseBuffer(); + return ret; + } + return -1; +} -IFXJS_Runtime* CPDFDoc_Environment::GetJSRuntime() +int CPDFDoc_Environment::JS_appResponse(const FX_WCHAR* Question, const FX_WCHAR* Title, const FX_WCHAR* Default, + const FX_WCHAR* cLabel, FPDF_BOOL bPassword, void* response, int length) { - if(!IsJSInitiated()) - return NULL; - if(!m_pJSRuntime) - m_pJSRuntime = CPDFXFA_App::GetInstance()->GetRuntimeFactory()->NewJSRuntime(this); - return m_pJSRuntime; + if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_response) + { + CFX_ByteString bsQuestion = CFX_WideString(Question).UTF16LE_Encode(); + CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode(); + CFX_ByteString bsDefault = CFX_WideString(Default).UTF16LE_Encode(); + CFX_ByteString bsLabel = CFX_WideString(cLabel).UTF16LE_Encode(); + FPDF_WIDESTRING pQuestion = (FPDF_WIDESTRING)bsQuestion.GetBuffer(bsQuestion.GetLength()); + FPDF_WIDESTRING pTitle = (FPDF_WIDESTRING)bsTitle.GetBuffer(bsTitle.GetLength()); + FPDF_WIDESTRING pDefault = (FPDF_WIDESTRING)bsDefault.GetBuffer(bsDefault.GetLength()); + FPDF_WIDESTRING pLabel = (FPDF_WIDESTRING)bsLabel.GetBuffer(bsLabel.GetLength()); + int ret = m_pInfo->m_pJsPlatform->app_response(m_pInfo->m_pJsPlatform, pQuestion, pTitle, + pDefault, pLabel, bPassword, response, length); + bsQuestion.ReleaseBuffer(); + bsTitle.ReleaseBuffer(); + bsDefault.ReleaseBuffer(); + bsLabel.ReleaseBuffer(); + return ret; + } + return -1; } -CPDFSDK_AnnotHandlerMgr* CPDFDoc_Environment::GetAnnotHandlerMgr() +CFX_WideString CPDFDoc_Environment::JS_fieldBrowse() { - if(!m_pAnnotHandlerMgr) - m_pAnnotHandlerMgr = new CPDFSDK_AnnotHandlerMgr(this); - return m_pAnnotHandlerMgr; + if (!m_pInfo || + !m_pInfo->m_pJsPlatform || + !m_pInfo->m_pJsPlatform->Field_browse) { + return L""; + } + + const int nRequiredLen = m_pInfo->m_pJsPlatform->Field_browse( + m_pInfo->m_pJsPlatform, nullptr, 0); + if (nRequiredLen <= 0) + return L""; + + nonstd::unique_ptr<char[]> pBuff(new char[nRequiredLen]); + memset(pBuff.get(), 0, nRequiredLen); + const int nActualLen = m_pInfo->m_pJsPlatform->Field_browse( + m_pInfo->m_pJsPlatform, pBuff.get(), nRequiredLen); + if (nActualLen <= 0 || nActualLen > nRequiredLen) + return L""; + + CFX_ByteString bsRet = CFX_ByteString(pBuff.get(), nActualLen); + CFX_WideString wsRet = CFX_WideString::FromLocal(bsRet); + return wsRet; } -CPDFSDK_ActionHandler* CPDFDoc_Environment::GetActionHander() +CFX_WideString CPDFDoc_Environment::JS_docGetFilePath() { - if(!m_pActionHandler) - m_pActionHandler = new CPDFSDK_ActionHandler(this); - return m_pActionHandler; + if (!m_pInfo || + !m_pInfo->m_pJsPlatform || + !m_pInfo->m_pJsPlatform->Doc_getFilePath) { + return L""; + } + + const int nRequiredLen = m_pInfo->m_pJsPlatform->Doc_getFilePath( + m_pInfo->m_pJsPlatform, nullptr, 0); + if (nRequiredLen <= 0) + return L""; + + nonstd::unique_ptr<char[]> pBuff(new char[nRequiredLen]); + memset(pBuff.get(), 0, nRequiredLen); + const int nActualLen = m_pInfo->m_pJsPlatform->Doc_getFilePath( + m_pInfo->m_pJsPlatform, pBuff.get(), nRequiredLen); + if (nActualLen <= 0 || nActualLen > nRequiredLen) + return L""; + + CFX_ByteString bsRet = CFX_ByteString(pBuff.get(), nActualLen); + CFX_WideString wsRet = CFX_WideString::FromLocal(bsRet); + return wsRet; } -int CPDFDoc_Environment::RegAppHandle(FPDF_FORMFILLINFO* pFFinfo) +void CPDFDoc_Environment::JS_docSubmitForm(void* formData, int length, const FX_WCHAR* URL) { - m_pInfo = pFFinfo; - return TRUE; + if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_submitForm) + { + CFX_ByteString bsDestination = CFX_WideString(URL).UTF16LE_Encode(); + FPDF_WIDESTRING pDestination = (FPDF_WIDESTRING)bsDestination.GetBuffer(bsDestination.GetLength()); + m_pInfo->m_pJsPlatform->Doc_submitForm(m_pInfo->m_pJsPlatform, formData, length, pDestination); + bsDestination.ReleaseBuffer(); + } } -CPDFSDK_Document* CPDFDoc_Environment::GetCurrentDoc() +void CPDFDoc_Environment::JS_docmailForm(void* mailData, int length, FPDF_BOOL bUI, + const FX_WCHAR* To, const FX_WCHAR* Subject, + const FX_WCHAR* CC, const FX_WCHAR* BCC, + const FX_WCHAR* Msg) { - return m_pSDKDoc; + if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_mail) + { + CFX_ByteString bsTo = CFX_WideString(To).UTF16LE_Encode(); + CFX_ByteString bsCC = CFX_WideString(Subject).UTF16LE_Encode(); + CFX_ByteString bsBcc = CFX_WideString(BCC).UTF16LE_Encode(); + CFX_ByteString bsSubject = CFX_WideString(Subject).UTF16LE_Encode(); + CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode(); + FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(bsTo.GetLength()); + FPDF_WIDESTRING pCC = (FPDF_WIDESTRING)bsCC.GetBuffer(bsCC.GetLength()); + FPDF_WIDESTRING pBcc = (FPDF_WIDESTRING)bsBcc.GetBuffer(bsBcc.GetLength()); + FPDF_WIDESTRING pSubject = (FPDF_WIDESTRING)bsSubject.GetBuffer(bsSubject.GetLength()); + FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength()); + m_pInfo->m_pJsPlatform->Doc_mail(m_pInfo->m_pJsPlatform, mailData, length, bUI, pTo, pSubject, + pCC, pBcc, pMsg); + bsTo.ReleaseBuffer(); + bsCC.ReleaseBuffer(); + bsBcc.ReleaseBuffer(); + bsSubject.ReleaseBuffer(); + bsMsg.ReleaseBuffer(); + } } -CFFL_IFormFiller* CPDFDoc_Environment::GetIFormFiller() +IFXJS_Runtime* CPDFDoc_Environment::GetJSRuntime() { - if(!m_pIFormFiller) - m_pIFormFiller = new CFFL_IFormFiller(this); - return m_pIFormFiller; + if (!IsJSInitiated()) + return NULL; + if (!m_pJSRuntime) + m_pJSRuntime = CPDFXFA_App::GetInstance()->GetRuntimeFactory()->NewJSRuntime(this); + return m_pJSRuntime; } -FX_BOOL CPDFDoc_Environment::IsJSInitiated() +CPDFSDK_AnnotHandlerMgr* CPDFDoc_Environment::GetAnnotHandlerMgr() { - if(m_pInfo) - { - if(m_pInfo->m_pJsPlatform) - return TRUE; - else - return FALSE; - } - return FALSE; + if (!m_pAnnotHandlerMgr) + m_pAnnotHandlerMgr = new CPDFSDK_AnnotHandlerMgr(this); + return m_pAnnotHandlerMgr; } -CPDFSDK_Document::CPDFSDK_Document(CPDFXFA_Document* pDoc,CPDFDoc_Environment* pEnv):m_pDoc(pDoc), - m_pInterForm(NULL),m_pEnv(pEnv),m_pOccontent(NULL),m_bChangeMask(FALSE) +CPDFSDK_ActionHandler* CPDFDoc_Environment::GetActionHander() +{ + if (!m_pActionHandler) + m_pActionHandler = new CPDFSDK_ActionHandler(this); + return m_pActionHandler; +} + +CFFL_IFormFiller* CPDFDoc_Environment::GetIFormFiller() +{ + if (!m_pIFormFiller) + m_pIFormFiller = new CFFL_IFormFiller(this); + return m_pIFormFiller; +} + +CPDFSDK_Document::CPDFSDK_Document(CPDFXFA_Document* pDoc,CPDFDoc_Environment* pEnv) : + m_pDoc(pDoc), + m_pInterForm(nullptr), + m_pFocusAnnot(nullptr), + m_pEnv(pEnv), + m_pOccontent(nullptr), + m_bChangeMask(FALSE) { - m_pFocusAnnot = NULL; } CPDFSDK_Document::~CPDFSDK_Document() @@ -361,55 +465,54 @@ CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex) void CPDFSDK_Document:: ProcJavascriptFun() { - CPDFXFA_Document* pPDFDoc = GetDocument(); - CPDF_DocJSActions docJS(pPDFDoc->GetPDFDoc()); - int iCount = docJS.CountJSActions(); - if (iCount < 1) return; - for (int i = 0; i < iCount; i ++) - { - CFX_ByteString csJSName; - CPDF_Action jsAction = docJS.GetJSAction(i, csJSName); - if(m_pEnv->GetActionHander()) - m_pEnv->GetActionHander()->DoAction_JavaScript(jsAction,CFX_WideString::FromLocal(csJSName),this); - } - + CPDFXFA_Document* pPDFDoc = GetDocument(); + CPDF_DocJSActions docJS(pPDFDoc->GetPDFDoc()); + int iCount = docJS.CountJSActions(); + if (iCount < 1) return; + for (int i = 0; i < iCount; i ++) + { + CFX_ByteString csJSName; + CPDF_Action jsAction = docJS.GetJSAction(i, csJSName); + if(m_pEnv->GetActionHander()) + m_pEnv->GetActionHander()->DoAction_JavaScript(jsAction,CFX_WideString::FromLocal(csJSName),this); + } } FX_BOOL CPDFSDK_Document::ProcOpenAction() { - if(!m_pDoc) - return FALSE; + if(!m_pDoc) + return FALSE; - CPDF_Dictionary* pRoot = m_pDoc->GetPDFDoc()->GetRoot(); - if (!pRoot) - return FALSE; + CPDF_Dictionary* pRoot = m_pDoc->GetPDFDoc()->GetRoot(); + if (!pRoot) + return FALSE; - CPDF_Object* pOpenAction = pRoot->GetDict("OpenAction"); - if(!pOpenAction) - pOpenAction = pRoot->GetArray("OpenAction"); + CPDF_Object* pOpenAction = pRoot->GetDict("OpenAction"); + if(!pOpenAction) + pOpenAction = pRoot->GetArray("OpenAction"); - if(!pOpenAction) - return FALSE; + if(!pOpenAction) + return FALSE; - if(pOpenAction->GetType()==PDFOBJ_ARRAY) - return TRUE; + if(pOpenAction->GetType()==PDFOBJ_ARRAY) + return TRUE; - if(pOpenAction->GetType()==PDFOBJ_DICTIONARY) - { - CPDF_Dictionary * pDict=(CPDF_Dictionary*)pOpenAction; - CPDF_Action action(pDict); - if(m_pEnv->GetActionHander()) - m_pEnv->GetActionHander()->DoAction_DocOpen(action, this); - return TRUE; - } - return FALSE; + if(pOpenAction->GetType()==PDFOBJ_DICTIONARY) + { + CPDF_Dictionary * pDict=(CPDF_Dictionary*)pOpenAction; + CPDF_Action action(pDict); + if(m_pEnv->GetActionHander()) + m_pEnv->GetActionHander()->DoAction_DocOpen(action, this); + return TRUE; + } + return FALSE; } -CPDF_OCContext* CPDFSDK_Document::GetOCContext() +CPDF_OCContext* CPDFSDK_Document::GetOCContext() { - if(!m_pOccontent) - m_pOccontent = new CPDF_OCContext(m_pDoc->GetPDFDoc()); - return m_pOccontent; + if(!m_pOccontent) + m_pOccontent = new CPDF_OCContext(m_pDoc->GetPDFDoc()); + return m_pOccontent; } void CPDFSDK_Document::ReMovePageView(CPDFXFA_Page* pPDFXFAPage) @@ -428,17 +531,17 @@ void CPDFSDK_Document::ReMovePageView(CPDFXFA_Page* pPDFXFAPage) CPDFXFA_Page * CPDFSDK_Document::GetPage(int nIndex) { - CPDFXFA_Page * pTempPage = (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex); - if(!pTempPage) - return NULL; - return pTempPage; + CPDFXFA_Page * pTempPage = (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex); + if(!pTempPage) + return NULL; + return pTempPage; } CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm() { - if(!m_pInterForm) - m_pInterForm = new CPDFSDK_InterForm(this); - return m_pInterForm; + if(!m_pInterForm) + m_pInterForm = new CPDFSDK_InterForm(this); + return m_pInterForm; } void CPDFSDK_Document::UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot) @@ -459,337 +562,335 @@ CPDFSDK_Annot* CPDFSDK_Document::GetFocusAnnot() FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot* pAnnot,FX_UINT nFlag) { - if(m_pFocusAnnot==pAnnot) return TRUE; - - CPDFSDK_Annot* pLastFocusAnnot = m_pFocusAnnot; - - if(m_pFocusAnnot) - { - if(!KillFocusAnnot(nFlag) ) return FALSE; - } - CPDFSDK_PageView* pPageView = NULL; - if (pAnnot) - pPageView = pAnnot->GetPageView(); - if(pAnnot && pPageView->IsValid()) - { - CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr(); + if(m_pFocusAnnot==pAnnot) return TRUE; - if(pAnnotHandler&&!m_pFocusAnnot) - { - if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot,pLastFocusAnnot)) - return FALSE; + CPDFSDK_Annot* pLastFocusAnnot = m_pFocusAnnot; - if (!pAnnotHandler->Annot_OnSetFocus(pAnnot,nFlag)) - return FALSE; - if(!m_pFocusAnnot) - { - m_pFocusAnnot=pAnnot; - return TRUE; - } - } - } - return FALSE; + if(m_pFocusAnnot) + { + if(!KillFocusAnnot(nFlag) ) return FALSE; + } + CPDFSDK_PageView* pPageView = NULL; + if (pAnnot) + pPageView = pAnnot->GetPageView(); + if(pAnnot && pPageView->IsValid()) + { + CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr(); + + if(pAnnotHandler&&!m_pFocusAnnot) + { + if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot,pLastFocusAnnot)) + return FALSE; + + if (!pAnnotHandler->Annot_OnSetFocus(pAnnot,nFlag)) + return FALSE; + if(!m_pFocusAnnot) + { + m_pFocusAnnot=pAnnot; + return TRUE; + } + } + } + return FALSE; } FX_BOOL CPDFSDK_Document::KillFocusAnnot(FX_UINT nFlag) { - if(m_pFocusAnnot) - { - CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr(); - if(pAnnotHandler) - { - CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot; - m_pFocusAnnot = NULL; - - if (!pAnnotHandler->Annot_OnChangeFocus(NULL, pFocusAnnot)) - return FALSE; - - if(pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag)) - { - - if(pFocusAnnot->GetType() == FX_BSTRC("Widget")) - { - CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot; - int nFieldType = pWidget->GetFieldType(); - if(FIELDTYPE_TEXTFIELD == nFieldType || FIELDTYPE_COMBOBOX == nFieldType) - m_pEnv->FFI_OnSetFieldInputFocus(NULL, NULL, 0, FALSE); - } - - if(!m_pFocusAnnot) - return TRUE; - } - else - { - m_pFocusAnnot = pFocusAnnot; - } - } - } - return FALSE; -} - -FX_BOOL CPDFSDK_Document::DeletePages(int nStart, int nCount) -{ - if ( nStart < 0 || nStart >= GetPageCount() || nCount <= 0 ) - { - return FALSE; - } - - CPDFXFA_Page * pTempPage = NULL; - for ( int i = nCount-1; i >= 0; i-- ) - { - pTempPage = GetPage(nStart+i); - if ( pTempPage != NULL ) - { - ReMovePageView(pTempPage); - } - } - return TRUE; + if(m_pFocusAnnot) + { + CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr(); + if(pAnnotHandler) + { + CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot; + m_pFocusAnnot = NULL; + + if (!pAnnotHandler->Annot_OnChangeFocus(NULL, pFocusAnnot)) + return FALSE; + + if(pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag)) + { + + if(pFocusAnnot->GetType() == FX_BSTRC("Widget")) + { + CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot; + int nFieldType = pWidget->GetFieldType(); + if(FIELDTYPE_TEXTFIELD == nFieldType || FIELDTYPE_COMBOBOX == nFieldType) + m_pEnv->FFI_OnSetFieldInputFocus(NULL, NULL, 0, FALSE); + } + + if(!m_pFocusAnnot) + return TRUE; + } + else + { + m_pFocusAnnot = pFocusAnnot; + } + } + } + return FALSE; +} + +FX_BOOL CPDFSDK_Document::DeletePages(int nStart, int nCount) +{ + if ( nStart < 0 || nStart >= GetPageCount() || nCount <= 0 ) + { + return FALSE; + } + + CPDFXFA_Page * pTempPage = NULL; + for ( int i = nCount-1; i >= 0; i-- ) + { + pTempPage = GetPage(nStart+i); + if ( pTempPage != NULL ) + { + ReMovePageView(pTempPage); + } + } + return TRUE; } void CPDFSDK_Document::OnCloseDocument() { - KillFocusAnnot(); + KillFocusAnnot(); } FX_BOOL CPDFSDK_Document::GetPermissions(int nFlag) { - FX_DWORD dwPermissions = m_pDoc->GetPDFDoc()->GetUserPermissions(); - return dwPermissions&nFlag; + FX_DWORD dwPermissions = m_pDoc->GetPDFDoc()->GetUserPermissions(); + return dwPermissions&nFlag; } IFXJS_Runtime * CPDFSDK_Document::GetJsRuntime() { - ASSERT(m_pEnv!=NULL); - return m_pEnv->GetJSRuntime(); + ASSERT(m_pEnv!=NULL); + return m_pEnv->GetJSRuntime(); } -CFX_WideString CPDFSDK_Document::GetPath() +CFX_WideString CPDFSDK_Document::GetPath() { - ASSERT(m_pEnv != NULL); - return m_pEnv->JS_docGetFilePath(); + ASSERT(m_pEnv != NULL); + return m_pEnv->JS_docGetFilePath(); } CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,CPDFXFA_Page* page):m_page(page),m_pSDKDoc(pSDKDoc) { - CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm(); - if(pInterForm) - { - CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); - if (page->GetPDFPage()) - pPDFInterForm->FixPageFields(page->GetPDFPage()); - } - m_fxAnnotArray.RemoveAll(); + CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm(); + if(pInterForm) + { + CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); + if (page->GetPDFPage()) + pPDFInterForm->FixPageFields(page->GetPDFPage()); + } + m_fxAnnotArray.RemoveAll(); - m_bEnterWidget = FALSE; - m_bExitWidget = FALSE; - m_bOnWidget = FALSE; - m_CaptureWidget = NULL; - m_bValid = FALSE; - m_bLocked = FALSE; - m_pAnnotList = NULL; + m_bEnterWidget = FALSE; + m_bExitWidget = FALSE; + m_bOnWidget = FALSE; + m_CaptureWidget = NULL; + m_bValid = FALSE; + m_bLocked = FALSE; + m_pAnnotList = NULL; } CPDFSDK_PageView::~CPDFSDK_PageView() { - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - int nAnnotCount = m_fxAnnotArray.GetSize(); - for (int i=0; i<nAnnotCount; i++) - { - CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i); - //if there is a focused annot on the page, we should kill the focus first. - if(pAnnot == m_pSDKDoc->GetFocusAnnot()) - KillFocusAnnot(); - CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); - ASSERT(pAnnotHandlerMgr); - pAnnotHandlerMgr->ReleaseAnnot(pAnnot); - } - m_fxAnnotArray.RemoveAll(); + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + int nAnnotCount = m_fxAnnotArray.GetSize(); + for (int i=0; i<nAnnotCount; i++) + { + CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i); + //if there is a focused annot on the page, we should kill the focus first. + if(pAnnot == m_pSDKDoc->GetFocusAnnot()) + KillFocusAnnot(); + CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); + ASSERT(pAnnotHandlerMgr); + pAnnotHandlerMgr->ReleaseAnnot(pAnnot); + } + m_fxAnnotArray.RemoveAll(); - delete m_pAnnotList; - m_pAnnotList = NULL; + delete m_pAnnotList; + m_pAnnotList = NULL; } void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,CPDF_RenderOptions* pOptions, FX_RECT* pClip) { - m_curMatrix = *pUser2Device; - // m_pAnnotList->DisplayAnnots(m_page, pDevice, pUser2Device, FALSE, pOptions); - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - CPDFXFA_Page* pPage = GetPDFXFAPage(); - - if (pPage == NULL) return; - - if (pPage->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA) { - CFX_Graphics gs; - gs.Create(pDevice); - if (pClip) { - CFX_RectF rectClip; - rectClip.Set(static_cast<FX_FLOAT>(pClip->left), - static_cast<FX_FLOAT>(pClip->top), - static_cast<FX_FLOAT>(pClip->Width()), - static_cast<FX_FLOAT>(pClip->Height())); - gs.SetClipRect(rectClip); - } - IXFA_RenderContext* pRenderContext = XFA_RenderContext_Create(); - if (!pRenderContext) - return; - CXFA_RenderOptions renderOptions; - renderOptions.m_bHighlight = TRUE; - pRenderContext->StartRender(pPage->GetXFAPageView(), &gs, *pUser2Device, renderOptions); - pRenderContext->DoRender(); - pRenderContext->StopRender(); - pRenderContext->Release(); - return; - } - // for pdf/static xfa. - CPDFSDK_AnnotIterator annotIterator(this, TRUE); - CPDFSDK_Annot * pSDKAnnot=NULL; - int index=-1; - pSDKAnnot = annotIterator.Next(index); - while(pSDKAnnot) - { - CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); - ASSERT(pAnnotHandlerMgr); - pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, 0); - pSDKAnnot = annotIterator.Next(index); - } + m_curMatrix = *pUser2Device; + // m_pAnnotList->DisplayAnnots(m_page, pDevice, pUser2Device, FALSE, pOptions); + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + CPDFXFA_Page* pPage = GetPDFXFAPage(); + + if (pPage == NULL) return; + + if (pPage->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA) { + CFX_Graphics gs; + gs.Create(pDevice); + if (pClip) { + CFX_RectF rectClip; + rectClip.Set(static_cast<FX_FLOAT>(pClip->left), + static_cast<FX_FLOAT>(pClip->top), + static_cast<FX_FLOAT>(pClip->Width()), + static_cast<FX_FLOAT>(pClip->Height())); + gs.SetClipRect(rectClip); + } + IXFA_RenderContext* pRenderContext = XFA_RenderContext_Create(); + if (!pRenderContext) + return; + CXFA_RenderOptions renderOptions; + renderOptions.m_bHighlight = TRUE; + pRenderContext->StartRender(pPage->GetXFAPageView(), &gs, *pUser2Device, renderOptions); + pRenderContext->DoRender(); + pRenderContext->StopRender(); + pRenderContext->Release(); + return; + } + // for pdf/static xfa. + CPDFSDK_AnnotIterator annotIterator(this, TRUE); + CPDFSDK_Annot * pSDKAnnot=NULL; + int index=-1; + pSDKAnnot = annotIterator.Next(index); + while(pSDKAnnot) + { + CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); + ASSERT(pAnnotHandlerMgr); + pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, 0); + pSDKAnnot = annotIterator.Next(index); + } } CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY) { - int nCount = m_pAnnotList->Count(); - for(int i = 0 ; i<nCount; i++) - { - CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i); - CFX_FloatRect annotRect; - pAnnot->GetRect(annotRect); - if(annotRect.Contains(pageX, pageY)) - return pAnnot; - } - return NULL; + int nCount = m_pAnnotList->Count(); + for(int i = 0 ; i<nCount; i++) + { + CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i); + CFX_FloatRect annotRect; + pAnnot->GetRect(annotRect); + if(annotRect.Contains(pageX, pageY)) + return pAnnot; + } + return NULL; } CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY) { - int nCount = m_pAnnotList->Count(); - for(int i = 0 ; i<nCount; i++) - { - CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i); - if(pAnnot->GetSubType() == "Widget") - { - CFX_FloatRect annotRect; - pAnnot->GetRect(annotRect); - if(annotRect.Contains(pageX, pageY)) - return pAnnot; - } - } - return NULL; + int nCount = m_pAnnotList->Count(); + for(int i = 0 ; i<nCount; i++) + { + CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i); + if(pAnnot->GetSubType() == "Widget") + { + CFX_FloatRect annotRect; + pAnnot->GetRect(annotRect); + if(annotRect.Contains(pageX, pageY)) + return pAnnot; + } + } + return NULL; } CPDFSDK_Annot* CPDFSDK_PageView::GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY) { + CPDFSDK_AnnotIterator annotIterator(this, FALSE); + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr(); + CPDFSDK_Annot* pSDKAnnot = NULL; + int index = -1; + pSDKAnnot = annotIterator.Next(index); + while(pSDKAnnot) + { + CPDF_Rect rc = pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot); + if(rc.Contains(pageX, pageY)) + return pSDKAnnot; + pSDKAnnot = annotIterator.Next(index); + } - CPDFSDK_AnnotIterator annotIterator(this, FALSE); - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr(); - CPDFSDK_Annot* pSDKAnnot = NULL; - int index = -1; - pSDKAnnot = annotIterator.Next(index); - while(pSDKAnnot) - { - CPDF_Rect rc = pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot); - if(rc.Contains(pageX, pageY)) - return pSDKAnnot; - pSDKAnnot = annotIterator.Next(index); - } - - return NULL; + return NULL; } CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY) { + CPDFSDK_AnnotIterator annotIterator(this, FALSE); + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr(); + CPDFSDK_Annot* pSDKAnnot = NULL; + int index = -1; + pSDKAnnot = annotIterator.Next(index); + while(pSDKAnnot) + { + if(pSDKAnnot->GetType() == "Widget" || pSDKAnnot->GetType() == FSDK_XFAWIDGET_TYPENAME) + { + pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot); + CPDF_Point point(pageX, pageY); + if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point)) + return pSDKAnnot; + } + pSDKAnnot = annotIterator.Next(index); + } - CPDFSDK_AnnotIterator annotIterator(this, FALSE); - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr(); - CPDFSDK_Annot* pSDKAnnot = NULL; - int index = -1; - pSDKAnnot = annotIterator.Next(index); - while(pSDKAnnot) - { - if(pSDKAnnot->GetType() == "Widget" || pSDKAnnot->GetType() == FSDK_XFAWIDGET_TYPENAME) - { - pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot); - CPDF_Point point(pageX, pageY); - if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point)) - return pSDKAnnot; - } - pSDKAnnot = annotIterator.Next(index); - } - - return NULL; + return NULL; } FX_BOOL CPDFSDK_PageView::Annot_HasAppearance(CPDF_Annot* pAnnot) { - CPDF_Dictionary* pAnnotDic = pAnnot->GetAnnotDict(); - if(pAnnotDic) - return pAnnotDic->KeyExist("AS"); - return FALSE; + CPDF_Dictionary* pAnnotDic = pAnnot->GetAnnotDict(); + if(pAnnotDic) + return pAnnotDic->KeyExist("AS"); + return FALSE; } -CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Annot * pPDFAnnot) +CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Annot * pPDFAnnot) { - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - ASSERT(pEnv); - CPDFSDK_AnnotHandlerMgr * pAnnotHandler= pEnv->GetAnnotHandlerMgr(); + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + ASSERT(pEnv); + CPDFSDK_AnnotHandlerMgr * pAnnotHandler= pEnv->GetAnnotHandlerMgr(); - CPDFSDK_Annot* pSDKAnnot =NULL; + CPDFSDK_Annot* pSDKAnnot =NULL; - if(pAnnotHandler) - { - pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this); - } - if(!pSDKAnnot) - return NULL; + if(pAnnotHandler) + { + pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this); + } + if(!pSDKAnnot) + return NULL; - m_fxAnnotArray.Add(pSDKAnnot); + m_fxAnnotArray.Add(pSDKAnnot); - if(pAnnotHandler) - { - pAnnotHandler->Annot_OnCreate(pSDKAnnot); + if(pAnnotHandler) + { + pAnnotHandler->Annot_OnCreate(pSDKAnnot); - } + } - return pSDKAnnot; + return pSDKAnnot; } CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(IXFA_Widget* pPDFAnnot) { - if (!pPDFAnnot) return NULL; + if (!pPDFAnnot) return NULL; - CPDFSDK_Annot* pSDKAnnot = GetAnnotByXFAWidget(pPDFAnnot); - if (pSDKAnnot) - return pSDKAnnot; + CPDFSDK_Annot* pSDKAnnot = GetAnnotByXFAWidget(pPDFAnnot); + if (pSDKAnnot) + return pSDKAnnot; - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - ASSERT(pEnv); - CPDFSDK_AnnotHandlerMgr * pAnnotHandler= pEnv->GetAnnotHandlerMgr(); + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + ASSERT(pEnv); + CPDFSDK_AnnotHandlerMgr * pAnnotHandler= pEnv->GetAnnotHandlerMgr(); - pSDKAnnot =NULL; + pSDKAnnot =NULL; - if(pAnnotHandler) - { - pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this); - } - if(!pSDKAnnot) - return NULL; + if(pAnnotHandler) + { + pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this); + } + if(!pSDKAnnot) + return NULL; - m_fxAnnotArray.Add(pSDKAnnot); + m_fxAnnotArray.Add(pSDKAnnot); - return pSDKAnnot; + return pSDKAnnot; } CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary * pDict) @@ -799,349 +900,349 @@ CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary * pDict) CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(const FX_CHAR* lpSubType,CPDF_Dictionary * pDict) { - return NULL; + return NULL; } FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot) { - if (!pAnnot) - return FALSE; - CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage(); - if (!pPage || (pPage->GetDocument()->GetDocType() != DOCTYPE_STATIC_XFA && pPage->GetDocument()->GetDocType() != DOCTYPE_DYNIMIC_XFA)) - return FALSE; + if (!pAnnot) + return FALSE; + CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage(); + if (!pPage || (pPage->GetDocument()->GetDocType() != DOCTYPE_STATIC_XFA && pPage->GetDocument()->GetDocType() != DOCTYPE_DYNIMIC_XFA)) + return FALSE; - int index = m_fxAnnotArray.Find(pAnnot); - m_fxAnnotArray.RemoveAt(index); - if (m_CaptureWidget == pAnnot) - m_CaptureWidget = NULL; + int index = m_fxAnnotArray.Find(pAnnot); + m_fxAnnotArray.RemoveAt(index); + if (m_CaptureWidget == pAnnot) + m_CaptureWidget = NULL; - return TRUE; + return TRUE; } CPDF_Document* CPDFSDK_PageView::GetPDFDocument() { - if(m_page) - { - return m_page->GetDocument()->GetPDFDoc(); - } - return NULL; + if(m_page) + { + return m_page->GetDocument()->GetPDFDoc(); + } + return NULL; } CPDF_Page* CPDFSDK_PageView::GetPDFPage() { - if (m_page) - { - return m_page->GetPDFPage(); - } + if (m_page) + { + return m_page->GetPDFPage(); + } - return NULL; + return NULL; } -int CPDFSDK_PageView::CountAnnots() +int CPDFSDK_PageView::CountAnnots() { - return m_fxAnnotArray.GetSize(); + return m_fxAnnotArray.GetSize(); } -CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(int nIndex) +CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(int nIndex) { - int nCount = m_fxAnnotArray.GetSize(); - if ( nIndex < 0 || nIndex >= nCount ) - { - return NULL; - } + int nCount = m_fxAnnotArray.GetSize(); + if ( nIndex < 0 || nIndex >= nCount ) + { + return NULL; + } - return (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(nIndex); + return (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(nIndex); } CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary * pDict) { - int nCount = m_fxAnnotArray.GetSize(); - for(int i=0; i<nCount; i++) - { - CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i); - if (pDict == pAnnot->GetPDFAnnot()->GetAnnotDict()) - return pAnnot; - } - return NULL; + int nCount = m_fxAnnotArray.GetSize(); + for(int i=0; i<nCount; i++) + { + CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i); + if (pDict == pAnnot->GetPDFAnnot()->GetAnnotDict()) + return pAnnot; + } + return NULL; } CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(IXFA_Widget* hWidget) { - if (hWidget == NULL) - return NULL; - int annotCount = m_fxAnnotArray.GetSize(); + if (hWidget == NULL) + return NULL; + int annotCount = m_fxAnnotArray.GetSize(); - for(int i = 0; i < annotCount; i++) - { - CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i); - if(pAnnot->GetXFAWidget() == hWidget) - return pAnnot; - } - return NULL; + for(int i = 0; i < annotCount; i++) + { + CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i); + if(pAnnot->GetXFAWidget() == hWidget) + return pAnnot; + } + return NULL; } FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point & point, FX_UINT nFlag) { - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - ASSERT(pEnv); - CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); - if(!pFXAnnot) - { - KillFocusAnnot(nFlag); - } - else - { - CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); - ASSERT(pAnnotHandlerMgr); - - FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnLButtonDown(this, pFXAnnot, nFlag,point); - if(bRet) - { - SetFocusAnnot(pFXAnnot); - } - return bRet; - } - return FALSE; + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + ASSERT(pEnv); + CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); + if(!pFXAnnot) + { + KillFocusAnnot(nFlag); + } + else + { + CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); + ASSERT(pAnnotHandlerMgr); + + FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnLButtonDown(this, pFXAnnot, nFlag,point); + if(bRet) + { + SetFocusAnnot(pFXAnnot); + } + return bRet; + } + return FALSE; } FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CPDF_Point & point, FX_UINT nFlag) { - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - ASSERT(pEnv); - CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); - ASSERT(pAnnotHandlerMgr); + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + ASSERT(pEnv); + CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); + ASSERT(pAnnotHandlerMgr); - CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); + CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); - if (pFXAnnot == NULL) - return FALSE; + if (pFXAnnot == NULL) + return FALSE; - FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnRButtonDown(this, pFXAnnot, nFlag,point); - if (bRet) - { - SetFocusAnnot(pFXAnnot); - } - return TRUE; + FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnRButtonDown(this, pFXAnnot, nFlag,point); + if (bRet) + { + SetFocusAnnot(pFXAnnot); + } + return TRUE; } FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CPDF_Point & point, FX_UINT nFlag) { - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - ASSERT(pEnv); - CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); - ASSERT(pAnnotHandlerMgr); + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + ASSERT(pEnv); + CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); + ASSERT(pAnnotHandlerMgr); - CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); + CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); - if (pFXAnnot == NULL) - return FALSE; + if (pFXAnnot == NULL) + return FALSE; - FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnRButtonUp(this, pFXAnnot, nFlag,point); - if (bRet) - { - SetFocusAnnot(pFXAnnot); - } - return TRUE; + FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnRButtonUp(this, pFXAnnot, nFlag,point); + if (bRet) + { + SetFocusAnnot(pFXAnnot); + } + return TRUE; } FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CPDF_Point & point, FX_UINT nFlag) { - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - ASSERT(pEnv); - CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); - ASSERT(pAnnotHandlerMgr); - CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); - CPDFSDK_Annot* pFocusAnnot = GetFocusAnnot(); - FX_BOOL bRet = FALSE; - if(pFocusAnnot && pFocusAnnot != pFXAnnot) - { - //Last focus Annot gets a chance to handle the event. - bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFocusAnnot, nFlag,point); - } - if(pFXAnnot && !bRet) - { - bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFXAnnot, nFlag,point); - return bRet; - } - return bRet; + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + ASSERT(pEnv); + CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); + ASSERT(pAnnotHandlerMgr); + CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); + CPDFSDK_Annot* pFocusAnnot = GetFocusAnnot(); + FX_BOOL bRet = FALSE; + if(pFocusAnnot && pFocusAnnot != pFXAnnot) + { + //Last focus Annot gets a chance to handle the event. + bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFocusAnnot, nFlag,point); + } + if(pFXAnnot && !bRet) + { + bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFXAnnot, nFlag,point); + return bRet; + } + return bRet; } FX_BOOL CPDFSDK_PageView::OnMouseMove(const CPDF_Point & point, int nFlag) { - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); - ASSERT(pAnnotHandlerMgr); - if(CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y)) - { - if(m_CaptureWidget && m_CaptureWidget != pFXAnnot) - { - m_bExitWidget = TRUE; - m_bEnterWidget = FALSE; - pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag); - } - m_CaptureWidget = (CPDFSDK_Widget*)pFXAnnot; - m_bOnWidget = TRUE; - if(!m_bEnterWidget) - { - m_bEnterWidget = TRUE; - m_bExitWidget = FALSE; - pAnnotHandlerMgr->Annot_OnMouseEnter(this, pFXAnnot,nFlag); - } - pAnnotHandlerMgr->Annot_OnMouseMove(this, pFXAnnot, nFlag, point); - return TRUE; - } - else - { - if(m_bOnWidget) - { - m_bOnWidget = FALSE; - m_bExitWidget = TRUE; - m_bEnterWidget = FALSE; - if(m_CaptureWidget) - { - pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag); - m_CaptureWidget = NULL; - } - } - return FALSE; - } - - return FALSE;; + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); + ASSERT(pAnnotHandlerMgr); + if(CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y)) + { + if(m_CaptureWidget && m_CaptureWidget != pFXAnnot) + { + m_bExitWidget = TRUE; + m_bEnterWidget = FALSE; + pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag); + } + m_CaptureWidget = (CPDFSDK_Widget*)pFXAnnot; + m_bOnWidget = TRUE; + if(!m_bEnterWidget) + { + m_bEnterWidget = TRUE; + m_bExitWidget = FALSE; + pAnnotHandlerMgr->Annot_OnMouseEnter(this, pFXAnnot,nFlag); + } + pAnnotHandlerMgr->Annot_OnMouseMove(this, pFXAnnot, nFlag, point); + return TRUE; + } + else + { + if(m_bOnWidget) + { + m_bOnWidget = FALSE; + m_bExitWidget = TRUE; + m_bEnterWidget = FALSE; + if(m_CaptureWidget) + { + pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag); + m_CaptureWidget = NULL; + } + } + return FALSE; + } + + return FALSE;; } FX_BOOL CPDFSDK_PageView::OnMouseWheel(double deltaX, double deltaY,const CPDF_Point& point, int nFlag) { - if(CPDFSDK_Annot* pAnnot = GetFXWidgetAtPoint(point.x, point.y)) - { - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); - ASSERT(pAnnotHandlerMgr); - return pAnnotHandlerMgr->Annot_OnMouseWheel(this, pAnnot, nFlag, (int)deltaY, point); - } - return FALSE; + if(CPDFSDK_Annot* pAnnot = GetFXWidgetAtPoint(point.x, point.y)) + { + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); + ASSERT(pAnnotHandlerMgr); + return pAnnotHandlerMgr->Annot_OnMouseWheel(this, pAnnot, nFlag, (int)deltaY, point); + } + return FALSE; } FX_BOOL CPDFSDK_PageView::OnChar(int nChar, FX_UINT nFlag) { - if(CPDFSDK_Annot* pAnnot = GetFocusAnnot()) - { - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); - ASSERT(pAnnotHandlerMgr); - return pAnnotHandlerMgr->Annot_OnChar(pAnnot, nChar, nFlag); - } + if(CPDFSDK_Annot* pAnnot = GetFocusAnnot()) + { + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); + ASSERT(pAnnotHandlerMgr); + return pAnnotHandlerMgr->Annot_OnChar(pAnnot, nChar, nFlag); + } - return FALSE; + return FALSE; } FX_BOOL CPDFSDK_PageView::OnKeyDown(int nKeyCode, int nFlag) { - if(CPDFSDK_Annot* pAnnot = GetFocusAnnot()) - { - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); - ASSERT(pAnnotHandlerMgr); - return pAnnotHandlerMgr->Annot_OnKeyDown(pAnnot, nKeyCode, nFlag); - } - return FALSE; + if(CPDFSDK_Annot* pAnnot = GetFocusAnnot()) + { + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); + ASSERT(pAnnotHandlerMgr); + return pAnnotHandlerMgr->Annot_OnKeyDown(pAnnot, nKeyCode, nFlag); + } + return FALSE; } FX_BOOL CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag) { -// if(CPDFSDK_Annot* pAnnot = GetFocusAnnot()) -// { -// CFFL_IFormFiller* pIFormFiller = g_pFormFillApp->GetIFormFiller(); -// return pIFormFiller->OnKeyUp(pAnnot, nKeyCode, nFlag); -// } - return FALSE; +// if(CPDFSDK_Annot* pAnnot = GetFocusAnnot()) +// { +// CFFL_IFormFiller* pIFormFiller = g_pFormFillApp->GetIFormFiller(); +// return pIFormFiller->OnKeyUp(pAnnot, nKeyCode, nFlag); +// } + return FALSE; } extern void CheckUnSupportAnnot(CPDF_Document * pDoc, CPDF_Annot* pPDFAnnot); void CPDFSDK_PageView::LoadFXAnnots() { - ASSERT(m_page != NULL); - - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - ASSERT(pEnv != NULL); + ASSERT(m_page != NULL); - CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); - ASSERT(pAnnotHandlerMgr != NULL); + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + ASSERT(pEnv != NULL); - SetLock(TRUE); - m_page->AddRef(); - if (m_pSDKDoc->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA) - { - IXFA_PageView* pageView = NULL; - pageView = m_page->GetXFAPageView(); - ASSERT(pageView != NULL); + CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); + ASSERT(pAnnotHandlerMgr != NULL); - IXFA_WidgetIterator* pWidgetHander = pageView->CreateWidgetIterator(XFA_TRAVERSEWAY_Form, XFA_WIDGETFILTER_Visible|XFA_WIDGETFILTER_Viewable|XFA_WIDGETFILTER_AllType); - if (!pWidgetHander) - { - m_page->Release(); - SetLock(FALSE); - return; - } + SetLock(TRUE); + m_page->AddRef(); + if (m_pSDKDoc->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA) + { + IXFA_PageView* pageView = NULL; + pageView = m_page->GetXFAPageView(); + ASSERT(pageView != NULL); + + IXFA_WidgetIterator* pWidgetHander = pageView->CreateWidgetIterator(XFA_TRAVERSEWAY_Form, XFA_WIDGETFILTER_Visible|XFA_WIDGETFILTER_Viewable|XFA_WIDGETFILTER_AllType); + if (!pWidgetHander) + { + m_page->Release(); + SetLock(FALSE); + return; + } IXFA_Widget* pXFAAnnot = pWidgetHander->MoveToNext(); - while (pXFAAnnot) { - CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pXFAAnnot, this); - if(!pAnnot) { - pXFAAnnot = pWidgetHander->MoveToNext(); - continue; - } - m_fxAnnotArray.Add(pAnnot); + while (pXFAAnnot) { + CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pXFAAnnot, this); + if(!pAnnot) { + pXFAAnnot = pWidgetHander->MoveToNext(); + continue; + } + m_fxAnnotArray.Add(pAnnot); - pAnnotHandlerMgr->Annot_OnLoad(pAnnot); + pAnnotHandlerMgr->Annot_OnLoad(pAnnot); - pXFAAnnot = pWidgetHander->MoveToNext(); + pXFAAnnot = pWidgetHander->MoveToNext(); - } + } - pWidgetHander->Release(); - } - else - { - CPDF_Page* pPage = m_page->GetPDFPage(); - ASSERT(pPage != NULL); + pWidgetHander->Release(); + } + else + { + CPDF_Page* pPage = m_page->GetPDFPage(); + ASSERT(pPage != NULL); - FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled(); - //Disable the default AP construction. - CPDF_InterForm::EnableUpdateAP(FALSE); - m_pAnnotList = new CPDF_AnnotList(pPage); - CPDF_InterForm::EnableUpdateAP(enableAPUpdate); + FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled(); + //Disable the default AP construction. + CPDF_InterForm::EnableUpdateAP(FALSE); + m_pAnnotList = new CPDF_AnnotList(pPage); + CPDF_InterForm::EnableUpdateAP(enableAPUpdate); - int nCount = m_pAnnotList->Count(); - for(int i=0; i<nCount; i++) - { - CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); - CPDF_Document * pDoc = GetPDFDocument(); + int nCount = m_pAnnotList->Count(); + for(int i=0; i<nCount; i++) + { + CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); + CPDF_Document * pDoc = GetPDFDocument(); - CheckUnSupportAnnot(pDoc, pPDFAnnot); + CheckUnSupportAnnot(pDoc, pPDFAnnot); - CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); - if(!pAnnot) - continue; - m_fxAnnotArray.Add(pAnnot); + CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); + if(!pAnnot) + continue; + m_fxAnnotArray.Add(pAnnot); - pAnnotHandlerMgr->Annot_OnLoad(pAnnot); - } + pAnnotHandlerMgr->Annot_OnLoad(pAnnot); + } - } - m_page->Release(); - SetLock(FALSE); + } + m_page->Release(); + SetLock(FALSE); } -void CPDFSDK_PageView::UpdateRects(CFX_RectArray& rects) +void CPDFSDK_PageView::UpdateRects(CFX_RectArray& rects) { - for(int i=0; i<rects.GetSize(); i++) - { - CPDF_Rect rc = rects.GetAt(i); - CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); - pEnv->FFI_Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom); - } + for(int i=0; i<rects.GetSize(); i++) + { + CPDF_Rect rc = rects.GetAt(i); + CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); + pEnv->FFI_Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom); + } } void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot) @@ -1154,43 +1255,42 @@ void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot) int CPDFSDK_PageView::GetPageIndex() { - if(m_page) - { - CPDF_Dictionary* pDic = m_page->GetPDFPage()->m_pFormDict; - CPDFXFA_Document* pDoc = m_pSDKDoc->GetDocument(); - if(pDoc && pDic) - { - return pDoc->GetPDFDoc()->GetPageIndex(pDic->GetObjNum()); - } - } - return -1; + if(m_page) + { + CPDF_Dictionary* pDic = m_page->GetPDFPage()->m_pFormDict; + CPDFXFA_Document* pDoc = m_pSDKDoc->GetDocument(); + if(pDoc && pDic) + { + return pDoc->GetPDFDoc()->GetPageIndex(pDic->GetObjNum()); + } + } + return -1; } -FX_BOOL CPDFSDK_PageView::IsValidAnnot(void* p) +FX_BOOL CPDFSDK_PageView::IsValidAnnot(void* p) { - if (p == NULL) return FALSE; - int iCount = m_pAnnotList->Count(); - for (int i = 0; i < iCount; i++) - { - if (m_pAnnotList->GetAt(i) == p) - return TRUE; - } - return FALSE; + if (p == NULL) return FALSE; + int iCount = m_pAnnotList->Count(); + for (int i = 0; i < iCount; i++) + { + if (m_pAnnotList->GetAt(i) == p) + return TRUE; + } + return FALSE; } CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() { - CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot(); - if(!pFocusAnnot) - return NULL; + CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot(); + if(!pFocusAnnot) + return NULL; - for(int i=0; i<m_fxAnnotArray.GetSize(); i++) - { - CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i); - if(pAnnot == pFocusAnnot) - return pAnnot; - } - return NULL; + for(int i=0; i<m_fxAnnotArray.GetSize(); i++) + { + CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i); + if(pAnnot == pFocusAnnot) + return pAnnot; + } + return NULL; } - diff --git a/fpdfsdk/src/javascript/JS_Object.cpp b/fpdfsdk/src/javascript/JS_Object.cpp index bb7d6c4108..2ee23f8877 100644 --- a/fpdfsdk/src/javascript/JS_Object.cpp +++ b/fpdfsdk/src/javascript/JS_Object.cpp @@ -8,8 +8,6 @@ #include "../../include/javascript/IJavaScript.h" #include "../../include/javascript/JS_Define.h" #include "../../include/javascript/JS_Object.h" -// #include "../../include/javascript/JS_MsgBox.h" -// #include "../../include/javascript/JS_ResMgr.h" #include "../../include/javascript/JS_Context.h" JS_TIMER_MAPARRAY& GetTimeMap() @@ -21,106 +19,102 @@ JS_TIMER_MAPARRAY& GetTimeMap() int FXJS_MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView, const FX_WCHAR* swMsg, const FX_WCHAR* swTitle, FX_UINT nType, FX_UINT nIcon) { - int nRet = 0; + if (!pApp) + return 0; - if (pApp) - { - CPDFSDK_Document* pDoc = pApp->GetCurrentDoc(); - if(pDoc) - pDoc->KillFocusAnnot(); - nRet = pApp->JS_appAlert(swMsg, swTitle, nType, nIcon); - } + if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) + pDoc->KillFocusAnnot(); - return nRet; + return pApp->JS_appAlert(swMsg, swTitle, nType, nIcon); } CPDFSDK_PageView* FXJS_GetPageView(IFXJS_Context* cc) { - if (CJS_Context* pContext = (CJS_Context *)cc) - { - if (pContext->GetReaderDocument()) - return NULL; - } - return NULL; + if (CJS_Context* pContext = (CJS_Context *)cc) + { + if (pContext->GetReaderDocument()) + return NULL; + } + return NULL; } /* --------------------------------- CJS_EmbedObj --------------------------------- */ CJS_EmbedObj::CJS_EmbedObj(CJS_Object* pJSObject) : - m_pJSObject(pJSObject) + m_pJSObject(pJSObject) { } CJS_EmbedObj::~CJS_EmbedObj() { - m_pJSObject = NULL; + m_pJSObject = NULL; } CPDFSDK_PageView* CJS_EmbedObj::JSGetPageView(IFXJS_Context* cc) { - return FXJS_GetPageView(cc); + return FXJS_GetPageView(cc); } int CJS_EmbedObj::MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView,const FX_WCHAR* swMsg,const FX_WCHAR* swTitle,FX_UINT nType,FX_UINT nIcon) { - return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon); + return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon); } void CJS_EmbedObj::Alert(CJS_Context* pContext, const FX_WCHAR* swMsg) { - CJS_Object::Alert(pContext, swMsg); + CJS_Object::Alert(pContext, swMsg); } CJS_Timer* CJS_EmbedObj::BeginTimer(CPDFDoc_Environment* pApp, FX_UINT nElapse) { - CJS_Timer* pTimer = new CJS_Timer(this,pApp); - pTimer->SetJSTimer(nElapse); + CJS_Timer* pTimer = new CJS_Timer(this,pApp); + pTimer->SetJSTimer(nElapse); - return pTimer; + return pTimer; } void CJS_EmbedObj::EndTimer(CJS_Timer* pTimer) { - ASSERT(pTimer != NULL); - pTimer->KillJSTimer(); - delete pTimer; + ASSERT(pTimer != NULL); + pTimer->KillJSTimer(); + delete pTimer; } /* --------------------------------- CJS_Object --------------------------------- */ void FreeObject(const v8::WeakCallbackInfo<CJS_Object>& data) { - CJS_Object* pJSObj = data.GetParameter(); + CJS_Object* pJSObj = data.GetParameter(); pJSObj->ExitInstance(); delete pJSObj; - JS_FreePrivate(data.GetInternalField(0)); + JS_FreePrivate(data.GetInternalField(0)); } void DisposeObject(const v8::WeakCallbackInfo<CJS_Object>& data) { - CJS_Object* pJSObj = data.GetParameter(); + CJS_Object* pJSObj = data.GetParameter(); pJSObj->Dispose(); data.SetSecondPassCallback(FreeObject); } CJS_Object::CJS_Object(JSFXObject pObject) :m_pEmbedObj(NULL) { - v8::Local<v8::Context> context = pObject->CreationContext(); - m_pIsolate = context->GetIsolate(); - m_pObject.Reset(m_pIsolate, pObject); + v8::Local<v8::Context> context = pObject->CreationContext(); + m_pIsolate = context->GetIsolate(); + m_pObject.Reset(m_pIsolate, pObject); }; CJS_Object::~CJS_Object(void) { - delete m_pEmbedObj; - m_pEmbedObj = NULL; + delete m_pEmbedObj; + m_pEmbedObj = NULL; - m_pObject.Reset(); + m_pObject.Reset(); }; -void CJS_Object::MakeWeak() +void CJS_Object::MakeWeak() { - m_pObject.SetWeak( + m_pObject.SetWeak( this, DisposeObject, v8::WeakCallbackType::kInternalFields); } @@ -131,24 +125,22 @@ void CJS_Object::Dispose() CPDFSDK_PageView* CJS_Object::JSGetPageView(IFXJS_Context* cc) { - return FXJS_GetPageView(cc); + return FXJS_GetPageView(cc); } int CJS_Object::MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView, const FX_WCHAR* swMsg, const FX_WCHAR* swTitle, FX_UINT nType, FX_UINT nIcon) { - return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon); + return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon); } void CJS_Object::Alert(CJS_Context* pContext, const FX_WCHAR* swMsg) { - ASSERT(pContext != NULL); + ASSERT(pContext != NULL); - if (pContext->IsMsgBoxEnabled()) - { - CPDFDoc_Environment* pApp = pContext->GetReaderApp(); - if(pApp) - pApp->JS_appAlert(swMsg, NULL, 0, 3); - } + if (pContext->IsMsgBoxEnabled()) + { + CPDFDoc_Environment* pApp = pContext->GetReaderApp(); + if(pApp) + pApp->JS_appAlert(swMsg, NULL, 0, 3); + } } - - diff --git a/fpdfsdk/src/javascript/app.cpp b/fpdfsdk/src/javascript/app.cpp index 1438661c23..c5139696c1 100644 --- a/fpdfsdk/src/javascript/app.cpp +++ b/fpdfsdk/src/javascript/app.cpp @@ -119,10 +119,10 @@ END_JS_STATIC_METHOD() IMPLEMENT_JS_CLASS(CJS_App,app) -app::app(CJS_Object * pJSObject) : CJS_EmbedObj(pJSObject) , - m_bCalculate(true), - m_bRuntimeHighLight(false) -// m_pMenuHead(NULL) +app::app(CJS_Object * pJSObject) + : CJS_EmbedObj(pJSObject), + m_bCalculate(true), + m_bRuntimeHighLight(false) { } @@ -136,60 +136,37 @@ app::~app(void) FX_BOOL app::activeDocs(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { - if (vp.IsGetting()) - { - - CJS_Context* pContext = (CJS_Context *)cc; - ASSERT(pContext != NULL); - - CPDFDoc_Environment* pApp = pContext->GetReaderApp(); - ASSERT(pApp != NULL); - - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - ASSERT(pRuntime != NULL); - - CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument(); - - CJS_Array aDocs(pRuntime->GetIsolate()); -// int iNumDocs = pApp->CountDocuments(); - -// for(int iIndex = 0; iIndex<iNumDocs; iIndex++) -// { - CPDFSDK_Document* pDoc = pApp->GetCurrentDoc(); - if (pDoc) - { - CJS_Document * pJSDocument = NULL; - - if (pDoc == pCurDoc) - { - JSFXObject pObj = JS_GetThisObj(*pRuntime); - - if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"Document")) - { - pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj); - } - } - else - { - JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime,L"Document")); - pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj); - ASSERT(pJSDocument != NULL); - - - // pDocument->AttachDoc(pDoc); - } - - aDocs.SetElement(0,CJS_Value(pRuntime->GetIsolate(),pJSDocument)); - } - // } - - if (aDocs.GetLength() > 0) - vp << aDocs; - else - vp.SetNull(); - return TRUE; - } - return FALSE; + if (!vp.IsGetting()) + return FALSE; + + CJS_Context* pContext = (CJS_Context *)cc; + CPDFDoc_Environment* pApp = pContext->GetReaderApp(); + CJS_Runtime* pRuntime = pContext->GetJSRuntime(); + CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument(); + CJS_Array aDocs(pRuntime->GetIsolate()); + if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) + { + CJS_Document* pJSDocument = NULL; + if (pDoc == pCurDoc) + { + JSFXObject pObj = JS_GetThisObj(*pRuntime); + if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"Document")) + pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj); + } + else + { + JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime,L"Document")); + pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj); + ASSERT(pJSDocument != NULL); + } + aDocs.SetElement(0,CJS_Value(pRuntime->GetIsolate(),pJSDocument)); + } + if (aDocs.GetLength() > 0) + vp << aDocs; + else + vp.SetNull(); + + return TRUE; } FX_BOOL app::calculate(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) @@ -201,27 +178,16 @@ FX_BOOL app::calculate(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sEr m_bCalculate = (FX_BOOL)bVP; CJS_Context* pContext = (CJS_Context*)cc; - ASSERT(pContext != NULL); - CPDFDoc_Environment* pApp = pContext->GetReaderApp(); - ASSERT(pApp != NULL); - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - ASSERT(pRuntime != NULL); - CJS_Array aDocs(pRuntime->GetIsolate()); - if (CPDFSDK_Document* pDoc = pApp->GetCurrentDoc()) - { - CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDoc->GetInterForm(); - ASSERT(pInterForm != NULL); - pInterForm->EnableCalculate((FX_BOOL)m_bCalculate); - } + if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) + pDoc->GetInterForm()->EnableCalculate((FX_BOOL)m_bCalculate); } else { vp << (bool)m_bCalculate; } - return TRUE; } @@ -260,25 +226,18 @@ FX_BOOL app::viewerVariation(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideStrin FX_BOOL app::viewerVersion(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { - if (vp.IsGetting()) - { - CJS_Context* pContext = (CJS_Context *)cc; - ASSERT(pContext != NULL); - - CPDFDoc_Environment* pApp = pContext->GetReaderApp(); - ASSERT(pApp != NULL); + if (!vp.IsGetting()) + return FALSE; - CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument(); + CJS_Context* pContext = (CJS_Context *)cc; + CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument(); + CPDFXFA_Document* pDoc = pCurDoc->GetDocument(); + if (pDoc->GetDocType() == 1 || pDoc->GetDocType() == 2) + vp << JS_STR_VIEWERVERSION_XFA; + else + vp << JS_STR_VIEWERVERSION; - CPDFXFA_Document* pDoc = pCurDoc->GetDocument(); - if (pDoc->GetDocType() == 1 || pDoc->GetDocType() == 2) - vp << JS_STR_VIEWERVERSION_XFA; - else - vp << JS_STR_VIEWERVERSION; - return TRUE; - } - - return FALSE; + return TRUE; } FX_BOOL app::platform(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) diff --git a/fpdfsdk/src/javascript/global.cpp b/fpdfsdk/src/javascript/global.cpp index e829d7fb19..52b79d3910 100644 --- a/fpdfsdk/src/javascript/global.cpp +++ b/fpdfsdk/src/javascript/global.cpp @@ -118,19 +118,14 @@ global_alternate::global_alternate(CJS_Object* pJSObject) global_alternate::~global_alternate(void) { - ASSERT(m_pApp != NULL); DestroyGlobalPersisitentVariables(); - - CJS_RuntimeFactory* pFactory = CPDFXFA_App::GetInstance()->GetRuntimeFactory(); - pFactory->ReleaseGlobalData(); + CPDFXFA_App::GetInstance()->GetRuntimeFactory()->ReleaseGlobalData(); } void global_alternate::Initial(CPDFDoc_Environment* pApp) { m_pApp = pApp; - - CJS_RuntimeFactory* pFactory = CPDFXFA_App::GetInstance()->GetRuntimeFactory(); - m_pGlobalData = pFactory->NewGlobalData(pApp); + m_pGlobalData = CPDFXFA_App::GetInstance()->GetRuntimeFactory()->NewGlobalData(pApp); UpdateGlobalPersistentVariables(); } |