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