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