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