John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Tom Sepez | 1ed8a21 | 2015-05-11 15:25:39 -0700 | [diff] [blame] | 7 | #include "../../public/fpdf_ext.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 8 | #include "../include/fsdk_define.h" |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 9 | #include "../include/fpdfxfa/fpdfxfa_doc.h" |
| 10 | #include "../include/fpdfxfa/fpdfxfa_page.h" |
| 11 | #include "../include/fpdfxfa/fpdfxfa_util.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 12 | #include "../include/fsdk_mgr.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 13 | #include "../include/formfiller/FFL_FormFiller.h" |
| 14 | #include "../include/javascript/IJavaScript.h" |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 15 | #include "../include/fpdfxfa/fpdfxfa_app.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 16 | |
| 17 | #if _FX_OS_ == _FX_ANDROID_ |
| 18 | #include "time.h" |
| 19 | #else |
| 20 | #include <ctime> |
| 21 | #endif |
| 22 | |
| 23 | //extern CPDFDoc_Environment* g_pFormFillApp; |
| 24 | class CFX_SystemHandler:public IFX_SystemHandler |
| 25 | { |
| 26 | public: |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 27 | CFX_SystemHandler(CPDFDoc_Environment* pEnv):m_pEnv(pEnv),m_nCharSet(-1) {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 28 | public: |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 29 | virtual void InvalidateRect(FX_HWND hWnd, FX_RECT rect) ; |
| 30 | virtual void OutputSelectedRect(void* pFormFiller, CPDF_Rect& rect); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 31 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 32 | virtual FX_BOOL IsSelectionImplemented(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 33 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 34 | virtual CFX_WideString GetClipboardText(FX_HWND hWnd){return L"";} |
| 35 | virtual FX_BOOL SetClipboardText(FX_HWND hWnd, CFX_WideString string) {return FALSE;} |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 36 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 37 | virtual void ClientToScreen(FX_HWND hWnd, int32_t& x, int32_t& y) {} |
| 38 | virtual void ScreenToClient(FX_HWND hWnd, int32_t& x, int32_t& y) {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 39 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 40 | /*cursor style |
| 41 | FXCT_ARROW |
| 42 | FXCT_NESW |
| 43 | FXCT_NWSE |
| 44 | FXCT_VBEAM |
| 45 | FXCT_HBEAM |
| 46 | FXCT_HAND |
| 47 | */ |
| 48 | virtual void SetCursor(int32_t nCursorType); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 49 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 50 | virtual FX_HMENU CreatePopupMenu() {return NULL;} |
| 51 | virtual FX_BOOL AppendMenuItem(FX_HMENU hMenu, int32_t nIDNewItem, CFX_WideString string) {return FALSE;} |
| 52 | virtual FX_BOOL EnableMenuItem(FX_HMENU hMenu, int32_t nIDItem, FX_BOOL bEnabled) {return FALSE;} |
| 53 | virtual int32_t TrackPopupMenu(FX_HMENU hMenu, int32_t x, int32_t y, FX_HWND hParent) {return -1;} |
| 54 | virtual void DestroyMenu(FX_HMENU hMenu) {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 55 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 56 | virtual CFX_ByteString GetNativeTrueTypeFont(int32_t nCharset); |
| 57 | virtual FX_BOOL FindNativeTrueTypeFont(int32_t nCharset, CFX_ByteString sFontFaceName); |
| 58 | virtual CPDF_Font* AddNativeTrueTypeFontToPDF(CPDF_Document* pDoc, CFX_ByteString sFontFaceName, uint8_t nCharset); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 59 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 60 | virtual int32_t SetTimer(int32_t uElapse, TimerCallback lpTimerFunc) ; |
| 61 | virtual void KillTimer(int32_t nID) ; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 62 | |
| 63 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 64 | virtual FX_BOOL IsSHIFTKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsSHIFTKeyDown(nFlag);} |
| 65 | virtual FX_BOOL IsCTRLKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsCTRLKeyDown(nFlag);} |
| 66 | virtual FX_BOOL IsALTKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsALTKeyDown(nFlag);} |
| 67 | virtual FX_BOOL IsINSERTKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsINSERTKeyDown(nFlag);} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 68 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 69 | virtual FX_SYSTEMTIME GetLocalTime(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 70 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 71 | virtual int32_t GetCharSet() {return m_nCharSet;} |
| 72 | virtual void SetCharSet(int32_t nCharSet) {m_nCharSet = nCharSet;} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 73 | private: |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 74 | CPDFDoc_Environment* m_pEnv; |
| 75 | int m_nCharSet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 76 | }; |
| 77 | |
Tom Sepez | bfa9a82 | 2015-06-09 13:24:12 -0700 | [diff] [blame] | 78 | void CFX_SystemHandler::SetCursor(int32_t nCursorType) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 79 | { |
| 80 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 81 | m_pEnv->FFI_SetCursor(nCursorType); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | void CFX_SystemHandler::InvalidateRect(FX_HWND hWnd, FX_RECT rect) |
| 85 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 86 | //g_pFormFillApp->FFI_Invalidate(); |
| 87 | CPDFSDK_Annot* pSDKAnnot = (CPDFSDK_Annot*)hWnd; |
| 88 | CPDFXFA_Page* pPage = NULL; |
| 89 | CPDFSDK_PageView* pPageView = NULL; |
| 90 | pPageView = pSDKAnnot->GetPageView(); |
| 91 | pPage = pSDKAnnot->GetPDFXFAPage(); |
| 92 | if(!pPage || !pPageView) |
| 93 | return; |
| 94 | CPDF_Matrix page2device; |
| 95 | pPageView->GetCurrentMatrix(page2device); |
| 96 | CPDF_Matrix device2page; |
| 97 | device2page.SetReverse(page2device); |
| 98 | FX_FLOAT left, top, right,bottom; |
| 99 | device2page.Transform((FX_FLOAT)rect.left, (FX_FLOAT)rect.top, left, top); |
| 100 | device2page.Transform((FX_FLOAT)rect.right, (FX_FLOAT)rect.bottom, right, bottom); |
| 101 | // m_pEnv->FFI_DeviceToPage(pPage, rect.left, rect.top, (double*)&left, (double*)&top); |
| 102 | // m_pEnv->FFI_DeviceToPage(pPage, rect.right, rect.bottom, (double*)&right, (double*)&bottom); |
| 103 | CPDF_Rect rcPDF(left, bottom, right, top); |
| 104 | rcPDF.Normalize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 105 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 106 | m_pEnv->FFI_Invalidate(pPage, rcPDF.left, rcPDF.top, rcPDF.right, rcPDF.bottom); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 107 | } |
| 108 | void CFX_SystemHandler::OutputSelectedRect(void* pFormFiller, CPDF_Rect& rect) |
| 109 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 110 | CFFL_FormFiller* pFFL = (CFFL_FormFiller*)pFormFiller; |
| 111 | if(pFFL) |
| 112 | { |
| 113 | CPDF_Point leftbottom = CPDF_Point(rect.left, rect.bottom); |
| 114 | CPDF_Point righttop = CPDF_Point(rect.right, rect.top); |
| 115 | CPDF_Point ptA = pFFL->PWLtoFFL(leftbottom); |
| 116 | CPDF_Point ptB = pFFL->PWLtoFFL(righttop); |
| 117 | CPDFSDK_Annot* pAnnot = pFFL->GetSDKAnnot(); |
| 118 | ASSERT(pAnnot); |
| 119 | CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage(); |
| 120 | ASSERT(pPage); |
| 121 | m_pEnv->FFI_OutputSelectedRect(pPage, ptA.x, ptB.y, ptB.x, ptA.y); |
| 122 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | FX_BOOL CFX_SystemHandler::IsSelectionImplemented() |
| 126 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 127 | if(m_pEnv) |
| 128 | { |
| 129 | FPDF_FORMFILLINFO* pInfo = m_pEnv->GetFormFillInfo(); |
| 130 | if(pInfo && pInfo->FFI_OutputSelectedRect) |
| 131 | return TRUE; |
| 132 | } |
| 133 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Tom Sepez | bfa9a82 | 2015-06-09 13:24:12 -0700 | [diff] [blame] | 136 | CFX_ByteString CFX_SystemHandler::GetNativeTrueTypeFont(int32_t nCharset) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 137 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 138 | return ""; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 141 | FX_BOOL CFX_SystemHandler::FindNativeTrueTypeFont(int32_t nCharset, CFX_ByteString sFontFaceName) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 142 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 143 | CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); |
| 144 | // FXFT_Face nFace = pFontMgr->FindSubstFont(sFontFaceName,TRUE,0,0,0,0,NULL); |
| 145 | // FXFT_Face nFace = pFontMgr->m_pBuiltinMapper->FindSubstFont(sFontFaceName,TRUE,0,0,0,0,NULL); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 146 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 147 | if(pFontMgr) |
| 148 | { |
| 149 | CFX_FontMapper* pFontMapper = pFontMgr->m_pBuiltinMapper; |
| 150 | if(pFontMapper) |
| 151 | { |
| 152 | int nSize = pFontMapper->m_InstalledTTFonts.GetSize(); |
| 153 | if(nSize ==0) |
| 154 | { |
| 155 | pFontMapper->LoadInstalledFonts(); |
| 156 | nSize = pFontMapper->m_InstalledTTFonts.GetSize(); |
| 157 | } |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 158 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 159 | for(int i=0; i<nSize; i++) |
| 160 | { |
| 161 | if(pFontMapper->m_InstalledTTFonts[i].Compare(sFontFaceName)) |
| 162 | return TRUE; |
| 163 | } |
| 164 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 165 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 166 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 167 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 168 | return FALSE; |
| 169 | // pFontMgr->m_FaceMap.Lookup(sFontFaceName,pFont); |
| 170 | // return (pFont!=NULL); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | static int CharSet2CP(int charset) |
| 174 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 175 | if(charset == 128) |
| 176 | return 932; |
| 177 | else if(charset == 134) |
| 178 | return 936; |
| 179 | else if(charset == 129) |
| 180 | return 949; |
| 181 | else if(charset == 136) |
| 182 | return 950; |
| 183 | return 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 184 | } |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 185 | CPDF_Font* CFX_SystemHandler::AddNativeTrueTypeFontToPDF(CPDF_Document* pDoc, CFX_ByteString sFontFaceName, |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 186 | uint8_t nCharset) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 187 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 188 | if(pDoc) |
| 189 | { |
| 190 | CFX_Font* pFXFont = new CFX_Font(); |
| 191 | pFXFont->LoadSubst(sFontFaceName,TRUE,0,0,0,CharSet2CP(nCharset),FALSE); |
| 192 | CPDF_Font* pFont = pDoc->AddFont(pFXFont,nCharset,FALSE); |
| 193 | delete pFXFont; |
| 194 | return pFont; |
| 195 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 196 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 197 | return NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | |
Tom Sepez | bfa9a82 | 2015-06-09 13:24:12 -0700 | [diff] [blame] | 201 | int32_t CFX_SystemHandler::SetTimer(int32_t uElapse, TimerCallback lpTimerFunc) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 202 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 203 | return m_pEnv->FFI_SetTimer(uElapse, lpTimerFunc); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 204 | } |
Tom Sepez | bfa9a82 | 2015-06-09 13:24:12 -0700 | [diff] [blame] | 205 | void CFX_SystemHandler::KillTimer(int32_t nID) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 206 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 207 | m_pEnv->FFI_KillTimer(nID); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | FX_SYSTEMTIME CFX_SystemHandler::GetLocalTime() |
| 211 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 212 | return m_pEnv->FFI_GetLocalTime(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 215 | CPDFDoc_Environment::CPDFDoc_Environment(CPDFXFA_Document* pDoc, FPDF_FORMFILLINFO* pFFinfo) : |
| 216 | m_pAnnotHandlerMgr(NULL), |
| 217 | m_pActionHandler(NULL), |
| 218 | m_pJSRuntime(NULL), |
| 219 | m_pInfo(pFFinfo), |
| 220 | m_pSDKDoc(NULL), |
| 221 | m_pXFADoc(pDoc), |
| 222 | m_pIFormFiller(NULL) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 223 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 224 | m_pSysHandler = new CFX_SystemHandler(this); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | CPDFDoc_Environment::~CPDFDoc_Environment() |
| 228 | { |
Tom Sepez | bdeeb8a | 2015-05-27 12:25:00 -0700 | [diff] [blame] | 229 | delete m_pIFormFiller; |
| 230 | m_pIFormFiller = NULL; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 231 | |
Tom Sepez | bdeeb8a | 2015-05-27 12:25:00 -0700 | [diff] [blame] | 232 | CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); |
| 233 | if (m_pJSRuntime && pProvider->GetRuntimeFactory()) |
| 234 | pProvider->GetRuntimeFactory()->DeleteJSRuntime(m_pJSRuntime); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 235 | |
Tom Sepez | bdeeb8a | 2015-05-27 12:25:00 -0700 | [diff] [blame] | 236 | if (pProvider->m_pEnvList.GetSize() == 0) |
| 237 | { |
| 238 | pProvider->ReleaseRuntime(); |
| 239 | pProvider->InitRuntime(TRUE); |
| 240 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 241 | |
Tom Sepez | bdeeb8a | 2015-05-27 12:25:00 -0700 | [diff] [blame] | 242 | delete m_pSysHandler; |
| 243 | m_pSysHandler = NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 244 | |
Tom Sepez | bdeeb8a | 2015-05-27 12:25:00 -0700 | [diff] [blame] | 245 | delete m_pAnnotHandlerMgr; |
| 246 | m_pAnnotHandlerMgr = NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 247 | |
Tom Sepez | bdeeb8a | 2015-05-27 12:25:00 -0700 | [diff] [blame] | 248 | delete m_pActionHandler; |
| 249 | m_pActionHandler = NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 252 | int CPDFDoc_Environment::JS_appAlert(const FX_WCHAR* Msg, const FX_WCHAR* Title, FX_UINT Type, FX_UINT Icon) |
| 253 | { |
| 254 | if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert) |
| 255 | { |
| 256 | CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode(); |
| 257 | CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode(); |
| 258 | FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength()); |
| 259 | FPDF_WIDESTRING pTitle = (FPDF_WIDESTRING)bsTitle.GetBuffer(bsTitle.GetLength()); |
| 260 | int ret = m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, pMsg, pTitle, Type, Icon); |
| 261 | bsMsg.ReleaseBuffer(); |
| 262 | bsTitle.ReleaseBuffer(); |
| 263 | return ret; |
| 264 | } |
| 265 | return -1; |
| 266 | } |
| 267 | |
| 268 | int CPDFDoc_Environment::JS_appResponse(const FX_WCHAR* Question, const FX_WCHAR* Title, const FX_WCHAR* Default, |
| 269 | const FX_WCHAR* cLabel, FPDF_BOOL bPassword, void* response, int length) |
| 270 | { |
| 271 | if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_response) |
| 272 | { |
| 273 | CFX_ByteString bsQuestion = CFX_WideString(Question).UTF16LE_Encode(); |
| 274 | CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode(); |
| 275 | CFX_ByteString bsDefault = CFX_WideString(Default).UTF16LE_Encode(); |
| 276 | CFX_ByteString bsLabel = CFX_WideString(cLabel).UTF16LE_Encode(); |
| 277 | FPDF_WIDESTRING pQuestion = (FPDF_WIDESTRING)bsQuestion.GetBuffer(bsQuestion.GetLength()); |
| 278 | FPDF_WIDESTRING pTitle = (FPDF_WIDESTRING)bsTitle.GetBuffer(bsTitle.GetLength()); |
| 279 | FPDF_WIDESTRING pDefault = (FPDF_WIDESTRING)bsDefault.GetBuffer(bsDefault.GetLength()); |
| 280 | FPDF_WIDESTRING pLabel = (FPDF_WIDESTRING)bsLabel.GetBuffer(bsLabel.GetLength()); |
| 281 | int ret = m_pInfo->m_pJsPlatform->app_response(m_pInfo->m_pJsPlatform, pQuestion, pTitle, |
| 282 | pDefault, pLabel, bPassword, response, length); |
| 283 | bsQuestion.ReleaseBuffer(); |
| 284 | bsTitle.ReleaseBuffer(); |
| 285 | bsDefault.ReleaseBuffer(); |
| 286 | bsLabel.ReleaseBuffer(); |
| 287 | return ret; |
| 288 | } |
| 289 | return -1; |
| 290 | } |
| 291 | |
| 292 | CFX_WideString CPDFDoc_Environment::JS_fieldBrowse() |
| 293 | { |
| 294 | if (!m_pInfo || |
| 295 | !m_pInfo->m_pJsPlatform || |
| 296 | !m_pInfo->m_pJsPlatform->Field_browse) { |
| 297 | return L""; |
| 298 | } |
| 299 | |
| 300 | const int nRequiredLen = m_pInfo->m_pJsPlatform->Field_browse( |
| 301 | m_pInfo->m_pJsPlatform, nullptr, 0); |
| 302 | if (nRequiredLen <= 0) |
| 303 | return L""; |
| 304 | |
| 305 | nonstd::unique_ptr<char[]> pBuff(new char[nRequiredLen]); |
| 306 | memset(pBuff.get(), 0, nRequiredLen); |
| 307 | const int nActualLen = m_pInfo->m_pJsPlatform->Field_browse( |
| 308 | m_pInfo->m_pJsPlatform, pBuff.get(), nRequiredLen); |
| 309 | if (nActualLen <= 0 || nActualLen > nRequiredLen) |
| 310 | return L""; |
| 311 | |
| 312 | CFX_ByteString bsRet = CFX_ByteString(pBuff.get(), nActualLen); |
| 313 | CFX_WideString wsRet = CFX_WideString::FromLocal(bsRet); |
| 314 | return wsRet; |
| 315 | } |
| 316 | |
| 317 | CFX_WideString CPDFDoc_Environment::JS_docGetFilePath() |
| 318 | { |
| 319 | if (!m_pInfo || |
| 320 | !m_pInfo->m_pJsPlatform || |
| 321 | !m_pInfo->m_pJsPlatform->Doc_getFilePath) { |
| 322 | return L""; |
| 323 | } |
| 324 | |
| 325 | const int nRequiredLen = m_pInfo->m_pJsPlatform->Doc_getFilePath( |
| 326 | m_pInfo->m_pJsPlatform, nullptr, 0); |
| 327 | if (nRequiredLen <= 0) |
| 328 | return L""; |
| 329 | |
| 330 | nonstd::unique_ptr<char[]> pBuff(new char[nRequiredLen]); |
| 331 | memset(pBuff.get(), 0, nRequiredLen); |
| 332 | const int nActualLen = m_pInfo->m_pJsPlatform->Doc_getFilePath( |
| 333 | m_pInfo->m_pJsPlatform, pBuff.get(), nRequiredLen); |
| 334 | if (nActualLen <= 0 || nActualLen > nRequiredLen) |
| 335 | return L""; |
| 336 | |
| 337 | CFX_ByteString bsRet = CFX_ByteString(pBuff.get(), nActualLen); |
| 338 | CFX_WideString wsRet = CFX_WideString::FromLocal(bsRet); |
| 339 | return wsRet; |
| 340 | } |
| 341 | |
| 342 | void CPDFDoc_Environment::JS_docSubmitForm(void* formData, int length, const FX_WCHAR* URL) |
| 343 | { |
| 344 | if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_submitForm) |
| 345 | { |
| 346 | CFX_ByteString bsDestination = CFX_WideString(URL).UTF16LE_Encode(); |
| 347 | FPDF_WIDESTRING pDestination = (FPDF_WIDESTRING)bsDestination.GetBuffer(bsDestination.GetLength()); |
| 348 | m_pInfo->m_pJsPlatform->Doc_submitForm(m_pInfo->m_pJsPlatform, formData, length, pDestination); |
| 349 | bsDestination.ReleaseBuffer(); |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | void CPDFDoc_Environment::JS_docmailForm(void* mailData, int length, FPDF_BOOL bUI, |
| 354 | const FX_WCHAR* To, const FX_WCHAR* Subject, |
| 355 | const FX_WCHAR* CC, const FX_WCHAR* BCC, |
| 356 | const FX_WCHAR* Msg) |
| 357 | { |
| 358 | if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_mail) |
| 359 | { |
| 360 | CFX_ByteString bsTo = CFX_WideString(To).UTF16LE_Encode(); |
| 361 | CFX_ByteString bsCC = CFX_WideString(Subject).UTF16LE_Encode(); |
| 362 | CFX_ByteString bsBcc = CFX_WideString(BCC).UTF16LE_Encode(); |
| 363 | CFX_ByteString bsSubject = CFX_WideString(Subject).UTF16LE_Encode(); |
| 364 | CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode(); |
| 365 | FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(bsTo.GetLength()); |
| 366 | FPDF_WIDESTRING pCC = (FPDF_WIDESTRING)bsCC.GetBuffer(bsCC.GetLength()); |
| 367 | FPDF_WIDESTRING pBcc = (FPDF_WIDESTRING)bsBcc.GetBuffer(bsBcc.GetLength()); |
| 368 | FPDF_WIDESTRING pSubject = (FPDF_WIDESTRING)bsSubject.GetBuffer(bsSubject.GetLength()); |
| 369 | FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength()); |
| 370 | m_pInfo->m_pJsPlatform->Doc_mail(m_pInfo->m_pJsPlatform, mailData, length, bUI, pTo, pSubject, |
| 371 | pCC, pBcc, pMsg); |
| 372 | bsTo.ReleaseBuffer(); |
| 373 | bsCC.ReleaseBuffer(); |
| 374 | bsBcc.ReleaseBuffer(); |
| 375 | bsSubject.ReleaseBuffer(); |
| 376 | bsMsg.ReleaseBuffer(); |
| 377 | } |
| 378 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 379 | |
| 380 | IFXJS_Runtime* CPDFDoc_Environment::GetJSRuntime() |
| 381 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 382 | if (!IsJSInitiated()) |
| 383 | return NULL; |
| 384 | if (!m_pJSRuntime) |
| 385 | m_pJSRuntime = CPDFXFA_App::GetInstance()->GetRuntimeFactory()->NewJSRuntime(this); |
| 386 | return m_pJSRuntime; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | CPDFSDK_AnnotHandlerMgr* CPDFDoc_Environment::GetAnnotHandlerMgr() |
| 390 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 391 | if (!m_pAnnotHandlerMgr) |
| 392 | m_pAnnotHandlerMgr = new CPDFSDK_AnnotHandlerMgr(this); |
| 393 | return m_pAnnotHandlerMgr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | CPDFSDK_ActionHandler* CPDFDoc_Environment::GetActionHander() |
| 397 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 398 | if (!m_pActionHandler) |
| 399 | m_pActionHandler = new CPDFSDK_ActionHandler(this); |
| 400 | return m_pActionHandler; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | CFFL_IFormFiller* CPDFDoc_Environment::GetIFormFiller() |
| 404 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 405 | if (!m_pIFormFiller) |
| 406 | m_pIFormFiller = new CFFL_IFormFiller(this); |
| 407 | return m_pIFormFiller; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 408 | } |
| 409 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 410 | CPDFSDK_Document::CPDFSDK_Document(CPDFXFA_Document* pDoc,CPDFDoc_Environment* pEnv) : |
| 411 | m_pDoc(pDoc), |
| 412 | m_pInterForm(nullptr), |
| 413 | m_pFocusAnnot(nullptr), |
| 414 | m_pEnv(pEnv), |
| 415 | m_pOccontent(nullptr), |
| 416 | m_bChangeMask(FALSE) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 417 | { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | CPDFSDK_Document::~CPDFSDK_Document() |
| 421 | { |
Lei Zhang | 606346f | 2015-06-19 18:11:07 -0700 | [diff] [blame] | 422 | for (auto& it : m_pageMap) |
| 423 | delete it.second; |
| 424 | m_pageMap.clear(); |
Tom Sepez | 2c28619 | 2015-06-18 12:47:11 -0700 | [diff] [blame] | 425 | |
| 426 | delete m_pInterForm; |
| 427 | m_pInterForm = nullptr; |
| 428 | |
| 429 | delete m_pOccontent; |
| 430 | m_pOccontent = nullptr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 431 | } |
| 432 | |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 433 | CPDFSDK_PageView* CPDFSDK_Document::GetPageView(CPDFXFA_Page* pPDFXFAPage, FX_BOOL ReNew) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 434 | { |
Lei Zhang | 606346f | 2015-06-19 18:11:07 -0700 | [diff] [blame] | 435 | auto it = m_pageMap.find(pPDFXFAPage); |
| 436 | if (it != m_pageMap.end()) |
| 437 | return it->second; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 438 | |
Lei Zhang | 606346f | 2015-06-19 18:11:07 -0700 | [diff] [blame] | 439 | if (!ReNew) |
| 440 | return nullptr; |
| 441 | |
| 442 | CPDFSDK_PageView* pPageView = new CPDFSDK_PageView(this, pPDFXFAPage); |
| 443 | m_pageMap[pPDFXFAPage] = pPageView; |
| 444 | // Delay to load all the annotations, to avoid endless loop. |
| 445 | pPageView->LoadFXAnnots(); |
| 446 | return pPageView; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | CPDFSDK_PageView* CPDFSDK_Document::GetCurrentView() |
| 450 | { |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 451 | CPDFXFA_Page* pPage = (CPDFXFA_Page *)m_pEnv->FFI_GetCurrentPage(m_pDoc); |
| 452 | return pPage ? GetPageView(pPage, TRUE) : nullptr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex) |
| 456 | { |
Lei Zhang | 606346f | 2015-06-19 18:11:07 -0700 | [diff] [blame] | 457 | CPDFXFA_Page* pTempPage = |
| 458 | (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc, nIndex); |
| 459 | if (!pTempPage) |
| 460 | return nullptr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 461 | |
Lei Zhang | 606346f | 2015-06-19 18:11:07 -0700 | [diff] [blame] | 462 | auto it = m_pageMap.find(pTempPage); |
| 463 | return it->second; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | void CPDFSDK_Document:: ProcJavascriptFun() |
| 467 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 468 | CPDFXFA_Document* pPDFDoc = GetDocument(); |
| 469 | CPDF_DocJSActions docJS(pPDFDoc->GetPDFDoc()); |
| 470 | int iCount = docJS.CountJSActions(); |
| 471 | if (iCount < 1) return; |
| 472 | for (int i = 0; i < iCount; i ++) |
| 473 | { |
| 474 | CFX_ByteString csJSName; |
| 475 | CPDF_Action jsAction = docJS.GetJSAction(i, csJSName); |
| 476 | if(m_pEnv->GetActionHander()) |
| 477 | m_pEnv->GetActionHander()->DoAction_JavaScript(jsAction,CFX_WideString::FromLocal(csJSName),this); |
| 478 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | FX_BOOL CPDFSDK_Document::ProcOpenAction() |
| 482 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 483 | if(!m_pDoc) |
| 484 | return FALSE; |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 485 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 486 | CPDF_Dictionary* pRoot = m_pDoc->GetPDFDoc()->GetRoot(); |
| 487 | if (!pRoot) |
| 488 | return FALSE; |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 489 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 490 | CPDF_Object* pOpenAction = pRoot->GetDict("OpenAction"); |
| 491 | if(!pOpenAction) |
| 492 | pOpenAction = pRoot->GetArray("OpenAction"); |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 493 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 494 | if(!pOpenAction) |
| 495 | return FALSE; |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 496 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 497 | if(pOpenAction->GetType()==PDFOBJ_ARRAY) |
| 498 | return TRUE; |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 499 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 500 | if(pOpenAction->GetType()==PDFOBJ_DICTIONARY) |
| 501 | { |
| 502 | CPDF_Dictionary * pDict=(CPDF_Dictionary*)pOpenAction; |
| 503 | CPDF_Action action(pDict); |
| 504 | if(m_pEnv->GetActionHander()) |
| 505 | m_pEnv->GetActionHander()->DoAction_DocOpen(action, this); |
| 506 | return TRUE; |
| 507 | } |
| 508 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 509 | } |
| 510 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 511 | CPDF_OCContext* CPDFSDK_Document::GetOCContext() |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 512 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 513 | if(!m_pOccontent) |
| 514 | m_pOccontent = new CPDF_OCContext(m_pDoc->GetPDFDoc()); |
| 515 | return m_pOccontent; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 516 | } |
| 517 | |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 518 | void CPDFSDK_Document::ReMovePageView(CPDFXFA_Page* pPDFXFAPage) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 519 | { |
Lei Zhang | 606346f | 2015-06-19 18:11:07 -0700 | [diff] [blame] | 520 | auto it = m_pageMap.find(pPDFXFAPage); |
| 521 | if (it == m_pageMap.end()) |
| 522 | return; |
| 523 | |
| 524 | CPDFSDK_PageView* pPageView = it->second; |
| 525 | if (pPageView->IsLocked()) |
| 526 | return; |
| 527 | |
| 528 | delete pPageView; |
| 529 | m_pageMap.erase(it); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 532 | CPDFXFA_Page * CPDFSDK_Document::GetPage(int nIndex) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 533 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 534 | CPDFXFA_Page * pTempPage = (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex); |
| 535 | if(!pTempPage) |
| 536 | return NULL; |
| 537 | return pTempPage; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm() |
| 541 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 542 | if(!m_pInterForm) |
| 543 | m_pInterForm = new CPDFSDK_InterForm(this); |
| 544 | return m_pInterForm; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | void CPDFSDK_Document::UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot) |
| 548 | { |
Lei Zhang | 606346f | 2015-06-19 18:11:07 -0700 | [diff] [blame] | 549 | for (const auto& it : m_pageMap) { |
| 550 | CPDFSDK_PageView* pPageView = it.second; |
| 551 | if (pPageView != pSender) { |
| 552 | pPageView->UpdateView(pAnnot); |
| 553 | } |
| 554 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | CPDFSDK_Annot* CPDFSDK_Document::GetFocusAnnot() |
| 558 | { |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 559 | return m_pFocusAnnot; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot* pAnnot,FX_UINT nFlag) |
| 563 | { |
| 564 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 565 | if(m_pFocusAnnot==pAnnot) return TRUE; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 566 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 567 | CPDFSDK_Annot* pLastFocusAnnot = m_pFocusAnnot; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 568 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 569 | if(m_pFocusAnnot) |
| 570 | { |
| 571 | if(!KillFocusAnnot(nFlag) ) return FALSE; |
| 572 | } |
| 573 | CPDFSDK_PageView* pPageView = NULL; |
| 574 | if (pAnnot) |
| 575 | pPageView = pAnnot->GetPageView(); |
| 576 | if(pAnnot && pPageView->IsValid()) |
| 577 | { |
| 578 | CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 579 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 580 | if(pAnnotHandler&&!m_pFocusAnnot) |
| 581 | { |
| 582 | if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot,pLastFocusAnnot)) |
| 583 | return FALSE; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 584 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 585 | if (!pAnnotHandler->Annot_OnSetFocus(pAnnot,nFlag)) |
| 586 | return FALSE; |
| 587 | if(!m_pFocusAnnot) |
| 588 | { |
| 589 | m_pFocusAnnot=pAnnot; |
| 590 | return TRUE; |
| 591 | } |
| 592 | } |
| 593 | } |
| 594 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | FX_BOOL CPDFSDK_Document::KillFocusAnnot(FX_UINT nFlag) |
| 598 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 599 | if(m_pFocusAnnot) |
| 600 | { |
| 601 | CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr(); |
| 602 | if(pAnnotHandler) |
| 603 | { |
| 604 | CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot; |
| 605 | m_pFocusAnnot = NULL; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 606 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 607 | if (!pAnnotHandler->Annot_OnChangeFocus(NULL, pFocusAnnot)) |
| 608 | return FALSE; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 609 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 610 | if(pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag)) |
| 611 | { |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 612 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 613 | if(pFocusAnnot->GetType() == FX_BSTRC("Widget")) |
| 614 | { |
| 615 | CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot; |
| 616 | int nFieldType = pWidget->GetFieldType(); |
| 617 | if(FIELDTYPE_TEXTFIELD == nFieldType || FIELDTYPE_COMBOBOX == nFieldType) |
| 618 | m_pEnv->FFI_OnSetFieldInputFocus(NULL, NULL, 0, FALSE); |
| 619 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 620 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 621 | if(!m_pFocusAnnot) |
| 622 | return TRUE; |
| 623 | } |
| 624 | else |
| 625 | { |
| 626 | m_pFocusAnnot = pFocusAnnot; |
| 627 | } |
| 628 | } |
| 629 | } |
| 630 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 631 | } |
| 632 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 633 | FX_BOOL CPDFSDK_Document::DeletePages(int nStart, int nCount) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 634 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 635 | if ( nStart < 0 || nStart >= GetPageCount() || nCount <= 0 ) |
| 636 | { |
| 637 | return FALSE; |
| 638 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 639 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 640 | CPDFXFA_Page * pTempPage = NULL; |
| 641 | for ( int i = nCount-1; i >= 0; i-- ) |
| 642 | { |
| 643 | pTempPage = GetPage(nStart+i); |
| 644 | if ( pTempPage != NULL ) |
| 645 | { |
| 646 | ReMovePageView(pTempPage); |
| 647 | } |
| 648 | } |
| 649 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | void CPDFSDK_Document::OnCloseDocument() |
| 653 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 654 | KillFocusAnnot(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | FX_BOOL CPDFSDK_Document::GetPermissions(int nFlag) |
| 658 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 659 | FX_DWORD dwPermissions = m_pDoc->GetPDFDoc()->GetUserPermissions(); |
| 660 | return dwPermissions&nFlag; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | IFXJS_Runtime * CPDFSDK_Document::GetJsRuntime() |
| 664 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 665 | ASSERT(m_pEnv!=NULL); |
| 666 | return m_pEnv->GetJSRuntime(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 667 | } |
| 668 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 669 | CFX_WideString CPDFSDK_Document::GetPath() |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 670 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 671 | ASSERT(m_pEnv != NULL); |
| 672 | return m_pEnv->JS_docGetFilePath(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 676 | CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,CPDFXFA_Page* page):m_page(page),m_pSDKDoc(pSDKDoc) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 677 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 678 | CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm(); |
| 679 | if(pInterForm) |
| 680 | { |
| 681 | CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); |
| 682 | if (page->GetPDFPage()) |
| 683 | pPDFInterForm->FixPageFields(page->GetPDFPage()); |
| 684 | } |
| 685 | m_fxAnnotArray.RemoveAll(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 686 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 687 | m_bEnterWidget = FALSE; |
| 688 | m_bExitWidget = FALSE; |
| 689 | m_bOnWidget = FALSE; |
| 690 | m_CaptureWidget = NULL; |
| 691 | m_bValid = FALSE; |
| 692 | m_bLocked = FALSE; |
| 693 | m_pAnnotList = NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | CPDFSDK_PageView::~CPDFSDK_PageView() |
| 697 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 698 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 699 | int nAnnotCount = m_fxAnnotArray.GetSize(); |
| 700 | for (int i=0; i<nAnnotCount; i++) |
| 701 | { |
| 702 | CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i); |
| 703 | //if there is a focused annot on the page, we should kill the focus first. |
| 704 | if(pAnnot == m_pSDKDoc->GetFocusAnnot()) |
| 705 | KillFocusAnnot(); |
| 706 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 707 | ASSERT(pAnnotHandlerMgr); |
| 708 | pAnnotHandlerMgr->ReleaseAnnot(pAnnot); |
| 709 | } |
| 710 | m_fxAnnotArray.RemoveAll(); |
Lei Zhang | 6d8b1c2 | 2015-06-19 17:26:17 -0700 | [diff] [blame] | 711 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 712 | delete m_pAnnotList; |
| 713 | m_pAnnotList = NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 714 | } |
| 715 | |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 716 | void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,CPDF_RenderOptions* pOptions, FX_RECT* pClip) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 717 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 718 | m_curMatrix = *pUser2Device; |
| 719 | // m_pAnnotList->DisplayAnnots(m_page, pDevice, pUser2Device, FALSE, pOptions); |
| 720 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 721 | CPDFXFA_Page* pPage = GetPDFXFAPage(); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 722 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 723 | if (pPage == NULL) return; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 724 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 725 | if (pPage->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA) { |
| 726 | CFX_Graphics gs; |
| 727 | gs.Create(pDevice); |
| 728 | if (pClip) { |
| 729 | CFX_RectF rectClip; |
| 730 | rectClip.Set(static_cast<FX_FLOAT>(pClip->left), |
| 731 | static_cast<FX_FLOAT>(pClip->top), |
| 732 | static_cast<FX_FLOAT>(pClip->Width()), |
| 733 | static_cast<FX_FLOAT>(pClip->Height())); |
| 734 | gs.SetClipRect(rectClip); |
| 735 | } |
| 736 | IXFA_RenderContext* pRenderContext = XFA_RenderContext_Create(); |
| 737 | if (!pRenderContext) |
| 738 | return; |
| 739 | CXFA_RenderOptions renderOptions; |
| 740 | renderOptions.m_bHighlight = TRUE; |
| 741 | pRenderContext->StartRender(pPage->GetXFAPageView(), &gs, *pUser2Device, renderOptions); |
| 742 | pRenderContext->DoRender(); |
| 743 | pRenderContext->StopRender(); |
| 744 | pRenderContext->Release(); |
| 745 | return; |
| 746 | } |
| 747 | // for pdf/static xfa. |
| 748 | CPDFSDK_AnnotIterator annotIterator(this, TRUE); |
| 749 | CPDFSDK_Annot * pSDKAnnot=NULL; |
| 750 | int index=-1; |
| 751 | pSDKAnnot = annotIterator.Next(index); |
| 752 | while(pSDKAnnot) |
| 753 | { |
| 754 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 755 | ASSERT(pAnnotHandlerMgr); |
| 756 | pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, 0); |
| 757 | pSDKAnnot = annotIterator.Next(index); |
| 758 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 759 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 760 | CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY) |
| 761 | { |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 762 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 763 | int nCount = m_pAnnotList->Count(); |
| 764 | for(int i = 0 ; i<nCount; i++) |
| 765 | { |
| 766 | CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i); |
| 767 | CFX_FloatRect annotRect; |
| 768 | pAnnot->GetRect(annotRect); |
| 769 | if(annotRect.Contains(pageX, pageY)) |
| 770 | return pAnnot; |
| 771 | } |
| 772 | return NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY) |
| 776 | { |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 777 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 778 | int nCount = m_pAnnotList->Count(); |
| 779 | for(int i = 0 ; i<nCount; i++) |
| 780 | { |
| 781 | CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i); |
| 782 | if(pAnnot->GetSubType() == "Widget") |
| 783 | { |
| 784 | CFX_FloatRect annotRect; |
| 785 | pAnnot->GetRect(annotRect); |
| 786 | if(annotRect.Contains(pageX, pageY)) |
| 787 | return pAnnot; |
| 788 | } |
| 789 | } |
| 790 | return NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | CPDFSDK_Annot* CPDFSDK_PageView::GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY) |
| 794 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 795 | CPDFSDK_AnnotIterator annotIterator(this, FALSE); |
| 796 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 797 | CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr(); |
| 798 | CPDFSDK_Annot* pSDKAnnot = NULL; |
| 799 | int index = -1; |
| 800 | pSDKAnnot = annotIterator.Next(index); |
| 801 | while(pSDKAnnot) |
| 802 | { |
| 803 | CPDF_Rect rc = pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot); |
| 804 | if(rc.Contains(pageX, pageY)) |
| 805 | return pSDKAnnot; |
| 806 | pSDKAnnot = annotIterator.Next(index); |
| 807 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 808 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 809 | return NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY) |
| 813 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 814 | CPDFSDK_AnnotIterator annotIterator(this, FALSE); |
| 815 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 816 | CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr(); |
| 817 | CPDFSDK_Annot* pSDKAnnot = NULL; |
| 818 | int index = -1; |
| 819 | pSDKAnnot = annotIterator.Next(index); |
| 820 | while(pSDKAnnot) |
| 821 | { |
| 822 | if(pSDKAnnot->GetType() == "Widget" || pSDKAnnot->GetType() == FSDK_XFAWIDGET_TYPENAME) |
| 823 | { |
| 824 | pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot); |
| 825 | CPDF_Point point(pageX, pageY); |
| 826 | if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point)) |
| 827 | return pSDKAnnot; |
| 828 | } |
| 829 | pSDKAnnot = annotIterator.Next(index); |
| 830 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 831 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 832 | return NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | |
| 836 | FX_BOOL CPDFSDK_PageView::Annot_HasAppearance(CPDF_Annot* pAnnot) |
| 837 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 838 | CPDF_Dictionary* pAnnotDic = pAnnot->GetAnnotDict(); |
| 839 | if(pAnnotDic) |
| 840 | return pAnnotDic->KeyExist("AS"); |
| 841 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 842 | } |
| 843 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 844 | CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Annot * pPDFAnnot) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 845 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 846 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 847 | ASSERT(pEnv); |
| 848 | CPDFSDK_AnnotHandlerMgr * pAnnotHandler= pEnv->GetAnnotHandlerMgr(); |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 849 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 850 | CPDFSDK_Annot* pSDKAnnot =NULL; |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 851 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 852 | if(pAnnotHandler) |
| 853 | { |
| 854 | pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this); |
| 855 | } |
| 856 | if(!pSDKAnnot) |
| 857 | return NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 858 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 859 | m_fxAnnotArray.Add(pSDKAnnot); |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 860 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 861 | if(pAnnotHandler) |
| 862 | { |
| 863 | pAnnotHandler->Annot_OnCreate(pSDKAnnot); |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 864 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 865 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 866 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 867 | return pSDKAnnot; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 868 | } |
| 869 | |
Tom Sepez | eed467d | 2015-06-02 10:35:27 -0700 | [diff] [blame] | 870 | CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(IXFA_Widget* pPDFAnnot) |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 871 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 872 | if (!pPDFAnnot) return NULL; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 873 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 874 | CPDFSDK_Annot* pSDKAnnot = GetAnnotByXFAWidget(pPDFAnnot); |
| 875 | if (pSDKAnnot) |
| 876 | return pSDKAnnot; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 877 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 878 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 879 | ASSERT(pEnv); |
| 880 | CPDFSDK_AnnotHandlerMgr * pAnnotHandler= pEnv->GetAnnotHandlerMgr(); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 881 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 882 | pSDKAnnot =NULL; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 883 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 884 | if(pAnnotHandler) |
| 885 | { |
| 886 | pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this); |
| 887 | } |
| 888 | if(!pSDKAnnot) |
| 889 | return NULL; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 890 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 891 | m_fxAnnotArray.Add(pSDKAnnot); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 892 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 893 | return pSDKAnnot; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 894 | } |
| 895 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 896 | CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary * pDict) |
| 897 | { |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 898 | return pDict ? AddAnnot(pDict->GetString("Subtype"), pDict) : nullptr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 899 | } |
| 900 | |
Tom Sepez | d7e5cc7 | 2015-06-10 14:33:37 -0700 | [diff] [blame] | 901 | CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(const FX_CHAR* lpSubType,CPDF_Dictionary * pDict) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 902 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 903 | return NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot) |
| 907 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 908 | if (!pAnnot) |
| 909 | return FALSE; |
| 910 | CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage(); |
| 911 | if (!pPage || (pPage->GetDocument()->GetDocType() != DOCTYPE_STATIC_XFA && pPage->GetDocument()->GetDocType() != DOCTYPE_DYNIMIC_XFA)) |
| 912 | return FALSE; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 913 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 914 | int index = m_fxAnnotArray.Find(pAnnot); |
| 915 | m_fxAnnotArray.RemoveAt(index); |
| 916 | if (m_CaptureWidget == pAnnot) |
| 917 | m_CaptureWidget = NULL; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 918 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 919 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | CPDF_Document* CPDFSDK_PageView::GetPDFDocument() |
| 923 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 924 | if(m_page) |
| 925 | { |
| 926 | return m_page->GetDocument()->GetPDFDoc(); |
| 927 | } |
| 928 | return NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 929 | } |
| 930 | |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 931 | CPDF_Page* CPDFSDK_PageView::GetPDFPage() |
| 932 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 933 | if (m_page) |
| 934 | { |
| 935 | return m_page->GetPDFPage(); |
| 936 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 937 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 938 | return NULL; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 939 | } |
| 940 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 941 | int CPDFSDK_PageView::CountAnnots() |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 942 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 943 | return m_fxAnnotArray.GetSize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 944 | } |
| 945 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 946 | CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(int nIndex) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 947 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 948 | int nCount = m_fxAnnotArray.GetSize(); |
| 949 | if ( nIndex < 0 || nIndex >= nCount ) |
| 950 | { |
| 951 | return NULL; |
| 952 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 953 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 954 | return (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(nIndex); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary * pDict) |
| 958 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 959 | int nCount = m_fxAnnotArray.GetSize(); |
| 960 | for(int i=0; i<nCount; i++) |
| 961 | { |
| 962 | CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i); |
| 963 | if (pDict == pAnnot->GetPDFAnnot()->GetAnnotDict()) |
| 964 | return pAnnot; |
| 965 | } |
| 966 | return NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 967 | } |
Tom Sepez | eed467d | 2015-06-02 10:35:27 -0700 | [diff] [blame] | 968 | CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(IXFA_Widget* hWidget) |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 969 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 970 | if (hWidget == NULL) |
| 971 | return NULL; |
| 972 | int annotCount = m_fxAnnotArray.GetSize(); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 973 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 974 | for(int i = 0; i < annotCount; i++) |
| 975 | { |
| 976 | CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i); |
| 977 | if(pAnnot->GetXFAWidget() == hWidget) |
| 978 | return pAnnot; |
| 979 | } |
| 980 | return NULL; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 981 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 982 | |
| 983 | FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point & point, FX_UINT nFlag) |
| 984 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 985 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 986 | ASSERT(pEnv); |
| 987 | CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); |
| 988 | if(!pFXAnnot) |
| 989 | { |
| 990 | KillFocusAnnot(nFlag); |
| 991 | } |
| 992 | else |
| 993 | { |
| 994 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 995 | ASSERT(pAnnotHandlerMgr); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 996 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 997 | FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnLButtonDown(this, pFXAnnot, nFlag,point); |
| 998 | if(bRet) |
| 999 | { |
| 1000 | SetFocusAnnot(pFXAnnot); |
| 1001 | } |
| 1002 | return bRet; |
| 1003 | } |
| 1004 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1005 | } |
| 1006 | |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1007 | FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CPDF_Point & point, FX_UINT nFlag) |
| 1008 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1009 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 1010 | ASSERT(pEnv); |
| 1011 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 1012 | ASSERT(pAnnotHandlerMgr); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1013 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1014 | CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1015 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1016 | if (pFXAnnot == NULL) |
| 1017 | return FALSE; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1018 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1019 | FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnRButtonDown(this, pFXAnnot, nFlag,point); |
| 1020 | if (bRet) |
| 1021 | { |
| 1022 | SetFocusAnnot(pFXAnnot); |
| 1023 | } |
| 1024 | return TRUE; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CPDF_Point & point, FX_UINT nFlag) |
| 1028 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1029 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 1030 | ASSERT(pEnv); |
| 1031 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 1032 | ASSERT(pAnnotHandlerMgr); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1033 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1034 | CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1035 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1036 | if (pFXAnnot == NULL) |
| 1037 | return FALSE; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1038 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1039 | FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnRButtonUp(this, pFXAnnot, nFlag,point); |
| 1040 | if (bRet) |
| 1041 | { |
| 1042 | SetFocusAnnot(pFXAnnot); |
| 1043 | } |
| 1044 | return TRUE; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1045 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1046 | |
| 1047 | FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CPDF_Point & point, FX_UINT nFlag) |
| 1048 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1049 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 1050 | ASSERT(pEnv); |
| 1051 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 1052 | ASSERT(pAnnotHandlerMgr); |
| 1053 | CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y); |
| 1054 | CPDFSDK_Annot* pFocusAnnot = GetFocusAnnot(); |
| 1055 | FX_BOOL bRet = FALSE; |
| 1056 | if(pFocusAnnot && pFocusAnnot != pFXAnnot) |
| 1057 | { |
| 1058 | //Last focus Annot gets a chance to handle the event. |
| 1059 | bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFocusAnnot, nFlag,point); |
| 1060 | } |
| 1061 | if(pFXAnnot && !bRet) |
| 1062 | { |
| 1063 | bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFXAnnot, nFlag,point); |
| 1064 | return bRet; |
| 1065 | } |
| 1066 | return bRet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | FX_BOOL CPDFSDK_PageView::OnMouseMove(const CPDF_Point & point, int nFlag) |
| 1070 | { |
| 1071 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1072 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 1073 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 1074 | ASSERT(pAnnotHandlerMgr); |
| 1075 | if(CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y)) |
| 1076 | { |
| 1077 | if(m_CaptureWidget && m_CaptureWidget != pFXAnnot) |
| 1078 | { |
| 1079 | m_bExitWidget = TRUE; |
| 1080 | m_bEnterWidget = FALSE; |
| 1081 | pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag); |
| 1082 | } |
| 1083 | m_CaptureWidget = (CPDFSDK_Widget*)pFXAnnot; |
| 1084 | m_bOnWidget = TRUE; |
| 1085 | if(!m_bEnterWidget) |
| 1086 | { |
| 1087 | m_bEnterWidget = TRUE; |
| 1088 | m_bExitWidget = FALSE; |
| 1089 | pAnnotHandlerMgr->Annot_OnMouseEnter(this, pFXAnnot,nFlag); |
| 1090 | } |
| 1091 | pAnnotHandlerMgr->Annot_OnMouseMove(this, pFXAnnot, nFlag, point); |
| 1092 | return TRUE; |
| 1093 | } |
| 1094 | else |
| 1095 | { |
| 1096 | if(m_bOnWidget) |
| 1097 | { |
| 1098 | m_bOnWidget = FALSE; |
| 1099 | m_bExitWidget = TRUE; |
| 1100 | m_bEnterWidget = FALSE; |
| 1101 | if(m_CaptureWidget) |
| 1102 | { |
| 1103 | pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag); |
| 1104 | m_CaptureWidget = NULL; |
| 1105 | } |
| 1106 | } |
| 1107 | return FALSE; |
| 1108 | } |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 1109 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1110 | return FALSE;; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1111 | } |
| 1112 | |
| 1113 | FX_BOOL CPDFSDK_PageView::OnMouseWheel(double deltaX, double deltaY,const CPDF_Point& point, int nFlag) |
| 1114 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1115 | if(CPDFSDK_Annot* pAnnot = GetFXWidgetAtPoint(point.x, point.y)) |
| 1116 | { |
| 1117 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 1118 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 1119 | ASSERT(pAnnotHandlerMgr); |
| 1120 | return pAnnotHandlerMgr->Annot_OnMouseWheel(this, pAnnot, nFlag, (int)deltaY, point); |
| 1121 | } |
| 1122 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1123 | |
| 1124 | } |
| 1125 | |
| 1126 | FX_BOOL CPDFSDK_PageView::OnChar(int nChar, FX_UINT nFlag) |
| 1127 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1128 | if(CPDFSDK_Annot* pAnnot = GetFocusAnnot()) |
| 1129 | { |
| 1130 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 1131 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 1132 | ASSERT(pAnnotHandlerMgr); |
| 1133 | return pAnnotHandlerMgr->Annot_OnChar(pAnnot, nChar, nFlag); |
| 1134 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1135 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1136 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | FX_BOOL CPDFSDK_PageView::OnKeyDown(int nKeyCode, int nFlag) |
| 1140 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1141 | if(CPDFSDK_Annot* pAnnot = GetFocusAnnot()) |
| 1142 | { |
| 1143 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 1144 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 1145 | ASSERT(pAnnotHandlerMgr); |
| 1146 | return pAnnotHandlerMgr->Annot_OnKeyDown(pAnnot, nKeyCode, nFlag); |
| 1147 | } |
| 1148 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | FX_BOOL CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag) |
| 1152 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1153 | // if(CPDFSDK_Annot* pAnnot = GetFocusAnnot()) |
| 1154 | // { |
| 1155 | // CFFL_IFormFiller* pIFormFiller = g_pFormFillApp->GetIFormFiller(); |
| 1156 | // return pIFormFiller->OnKeyUp(pAnnot, nKeyCode, nFlag); |
| 1157 | // } |
| 1158 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | extern void CheckUnSupportAnnot(CPDF_Document * pDoc, CPDF_Annot* pPDFAnnot); |
| 1162 | |
| 1163 | void CPDFSDK_PageView::LoadFXAnnots() |
| 1164 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1165 | ASSERT(m_page != NULL); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1166 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1167 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 1168 | ASSERT(pEnv != NULL); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1169 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1170 | CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 1171 | ASSERT(pAnnotHandlerMgr != NULL); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1172 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1173 | SetLock(TRUE); |
| 1174 | m_page->AddRef(); |
| 1175 | if (m_pSDKDoc->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA) |
| 1176 | { |
| 1177 | IXFA_PageView* pageView = NULL; |
| 1178 | pageView = m_page->GetXFAPageView(); |
| 1179 | ASSERT(pageView != NULL); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1180 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1181 | IXFA_WidgetIterator* pWidgetHander = pageView->CreateWidgetIterator(XFA_TRAVERSEWAY_Form, XFA_WIDGETFILTER_Visible|XFA_WIDGETFILTER_Viewable|XFA_WIDGETFILTER_AllType); |
| 1182 | if (!pWidgetHander) |
| 1183 | { |
| 1184 | m_page->Release(); |
| 1185 | SetLock(FALSE); |
| 1186 | return; |
| 1187 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1188 | |
Tom Sepez | eed467d | 2015-06-02 10:35:27 -0700 | [diff] [blame] | 1189 | IXFA_Widget* pXFAAnnot = pWidgetHander->MoveToNext(); |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1190 | while (pXFAAnnot) { |
| 1191 | CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pXFAAnnot, this); |
| 1192 | if(!pAnnot) { |
| 1193 | pXFAAnnot = pWidgetHander->MoveToNext(); |
| 1194 | continue; |
| 1195 | } |
| 1196 | m_fxAnnotArray.Add(pAnnot); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 1197 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1198 | pAnnotHandlerMgr->Annot_OnLoad(pAnnot); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1199 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1200 | pXFAAnnot = pWidgetHander->MoveToNext(); |
Bo Xu | facd015 | 2014-09-24 10:49:52 -0700 | [diff] [blame] | 1201 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1202 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1203 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1204 | pWidgetHander->Release(); |
| 1205 | } |
| 1206 | else |
| 1207 | { |
| 1208 | CPDF_Page* pPage = m_page->GetPDFPage(); |
| 1209 | ASSERT(pPage != NULL); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1210 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1211 | FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled(); |
| 1212 | //Disable the default AP construction. |
| 1213 | CPDF_InterForm::EnableUpdateAP(FALSE); |
| 1214 | m_pAnnotList = new CPDF_AnnotList(pPage); |
| 1215 | CPDF_InterForm::EnableUpdateAP(enableAPUpdate); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1216 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1217 | int nCount = m_pAnnotList->Count(); |
| 1218 | for(int i=0; i<nCount; i++) |
| 1219 | { |
| 1220 | CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i); |
| 1221 | CPDF_Document * pDoc = GetPDFDocument(); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1222 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1223 | CheckUnSupportAnnot(pDoc, pPDFAnnot); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1224 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1225 | CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this); |
| 1226 | if(!pAnnot) |
| 1227 | continue; |
| 1228 | m_fxAnnotArray.Add(pAnnot); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1229 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1230 | pAnnotHandlerMgr->Annot_OnLoad(pAnnot); |
| 1231 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1232 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1233 | } |
| 1234 | m_page->Release(); |
| 1235 | SetLock(FALSE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1236 | } |
| 1237 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1238 | void CPDFSDK_PageView::UpdateRects(CFX_RectArray& rects) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1239 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1240 | for(int i=0; i<rects.GetSize(); i++) |
| 1241 | { |
| 1242 | CPDF_Rect rc = rects.GetAt(i); |
| 1243 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 1244 | pEnv->FFI_Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom); |
| 1245 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot) |
| 1249 | { |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 1250 | CPDF_Rect rcWindow = pAnnot->GetRect(); |
| 1251 | CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 1252 | pEnv->FFI_Invalidate( |
| 1253 | m_page, rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1254 | } |
| 1255 | |
| 1256 | int CPDFSDK_PageView::GetPageIndex() |
| 1257 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1258 | if(m_page) |
| 1259 | { |
| 1260 | CPDF_Dictionary* pDic = m_page->GetPDFPage()->m_pFormDict; |
| 1261 | CPDFXFA_Document* pDoc = m_pSDKDoc->GetDocument(); |
| 1262 | if(pDoc && pDic) |
| 1263 | { |
| 1264 | return pDoc->GetPDFDoc()->GetPageIndex(pDic->GetObjNum()); |
| 1265 | } |
| 1266 | } |
| 1267 | return -1; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1268 | } |
| 1269 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1270 | FX_BOOL CPDFSDK_PageView::IsValidAnnot(void* p) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1271 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1272 | if (p == NULL) return FALSE; |
| 1273 | int iCount = m_pAnnotList->Count(); |
| 1274 | for (int i = 0; i < iCount; i++) |
| 1275 | { |
| 1276 | if (m_pAnnotList->GetAt(i) == p) |
| 1277 | return TRUE; |
| 1278 | } |
| 1279 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | |
| 1283 | CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() |
| 1284 | { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1285 | CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot(); |
| 1286 | if(!pFocusAnnot) |
| 1287 | return NULL; |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 1288 | |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1289 | for(int i=0; i<m_fxAnnotArray.GetSize(); i++) |
| 1290 | { |
| 1291 | CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i); |
| 1292 | if(pAnnot == pFocusAnnot) |
| 1293 | return pAnnot; |
| 1294 | } |
| 1295 | return NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1296 | } |