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