blob: 46c0ff7e02fd4b346742cb2f3ce40c1e21de0529 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// Copyright 2014 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Lei Zhang60f507b2015-06-13 00:41:00 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Tom Sepez1ed8a212015-05-11 15:25:39 -07007#include "../../public/fpdf_ext.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07008#include "../include/fsdk_define.h"
Bo Xufdc00a72014-10-28 23:03:33 -07009#include "../include/fpdfxfa/fpdfxfa_doc.h"
10#include "../include/fpdfxfa/fpdfxfa_page.h"
11#include "../include/fpdfxfa/fpdfxfa_util.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070012#include "../include/fsdk_mgr.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070013#include "../include/formfiller/FFL_FormFiller.h"
14#include "../include/javascript/IJavaScript.h"
Bo Xufdc00a72014-10-28 23:03:33 -070015#include "../include/fpdfxfa/fpdfxfa_app.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070016
17#if _FX_OS_ == _FX_ANDROID_
18#include "time.h"
19#else
20#include <ctime>
21#endif
22
23//extern CPDFDoc_Environment* g_pFormFillApp;
24class CFX_SystemHandler:public IFX_SystemHandler
25{
26public:
27 CFX_SystemHandler(CPDFDoc_Environment* pEnv):m_pEnv(pEnv),m_nCharSet(-1) {}
28public:
29 virtual void InvalidateRect(FX_HWND hWnd, FX_RECT rect) ;
30 virtual void OutputSelectedRect(void* pFormFiller, CPDF_Rect& rect);
31
32 virtual FX_BOOL IsSelectionImplemented();
33
34 virtual CFX_WideString GetClipboardText(FX_HWND hWnd){return L"";}
35 virtual FX_BOOL SetClipboardText(FX_HWND hWnd, CFX_WideString string) {return FALSE;}
Lei Zhang60f507b2015-06-13 00:41:00 -070036
Tom Sepezbfa9a822015-06-09 13:24:12 -070037 virtual void ClientToScreen(FX_HWND hWnd, int32_t& x, int32_t& y) {}
38 virtual void ScreenToClient(FX_HWND hWnd, int32_t& x, int32_t& y) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070039
40 /*cursor style
Lei Zhang60f507b2015-06-13 00:41:00 -070041 FXCT_ARROW
42 FXCT_NESW
43 FXCT_NWSE
44 FXCT_VBEAM
45 FXCT_HBEAM
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070046 FXCT_HAND
47 */
Tom Sepezbfa9a822015-06-09 13:24:12 -070048 virtual void SetCursor(int32_t nCursorType);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070049
50 virtual FX_HMENU CreatePopupMenu() {return NULL;}
Tom Sepezbfa9a822015-06-09 13:24:12 -070051 virtual FX_BOOL AppendMenuItem(FX_HMENU hMenu, int32_t nIDNewItem, CFX_WideString string) {return FALSE;}
52 virtual FX_BOOL EnableMenuItem(FX_HMENU hMenu, int32_t nIDItem, FX_BOOL bEnabled) {return FALSE;}
53 virtual int32_t TrackPopupMenu(FX_HMENU hMenu, int32_t x, int32_t y, FX_HWND hParent) {return -1;}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070054 virtual void DestroyMenu(FX_HMENU hMenu) {}
55
Tom Sepezbfa9a822015-06-09 13:24:12 -070056 virtual CFX_ByteString GetNativeTrueTypeFont(int32_t nCharset);
57 virtual FX_BOOL FindNativeTrueTypeFont(int32_t nCharset, CFX_ByteString sFontFaceName);
58 virtual CPDF_Font* AddNativeTrueTypeFontToPDF(CPDF_Document* pDoc, CFX_ByteString sFontFaceName, uint8_t nCharset);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070059
Tom Sepezbfa9a822015-06-09 13:24:12 -070060 virtual int32_t SetTimer(int32_t uElapse, TimerCallback lpTimerFunc) ;
61 virtual void KillTimer(int32_t nID) ;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070062
63
64 virtual FX_BOOL IsSHIFTKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsSHIFTKeyDown(nFlag);}
65 virtual FX_BOOL IsCTRLKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsCTRLKeyDown(nFlag);}
66 virtual FX_BOOL IsALTKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsALTKeyDown(nFlag);}
67 virtual FX_BOOL IsINSERTKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsINSERTKeyDown(nFlag);}
68
69 virtual FX_SYSTEMTIME GetLocalTime();
70
Tom Sepezbfa9a822015-06-09 13:24:12 -070071 virtual int32_t GetCharSet() {return m_nCharSet;}
72 virtual void SetCharSet(int32_t nCharSet) {m_nCharSet = nCharSet;}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070073private:
74 CPDFDoc_Environment* m_pEnv;
75 int m_nCharSet;
76};
77
Tom Sepezbfa9a822015-06-09 13:24:12 -070078void CFX_SystemHandler::SetCursor(int32_t nCursorType)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070079{
80
81 m_pEnv->FFI_SetCursor(nCursorType);
82}
83
84void CFX_SystemHandler::InvalidateRect(FX_HWND hWnd, FX_RECT rect)
85{
86 //g_pFormFillApp->FFI_Invalidate();
87 CPDFSDK_Annot* pSDKAnnot = (CPDFSDK_Annot*)hWnd;
Bo Xufdc00a72014-10-28 23:03:33 -070088 CPDFXFA_Page* pPage = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070089 CPDFSDK_PageView* pPageView = NULL;
90 pPageView = pSDKAnnot->GetPageView();
Bo Xufdc00a72014-10-28 23:03:33 -070091 pPage = pSDKAnnot->GetPDFXFAPage();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070092 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}
108void CFX_SystemHandler::OutputSelectedRect(void* pFormFiller, CPDF_Rect& rect)
109{
110 CFFL_FormFiller* pFFL = (CFFL_FormFiller*)pFormFiller;
111 if(pFFL)
112 {
113 CPDF_Point leftbottom = CPDF_Point(rect.left, rect.bottom);
114 CPDF_Point righttop = CPDF_Point(rect.right, rect.top);
115 CPDF_Point ptA = pFFL->PWLtoFFL(leftbottom);
Lei Zhang60f507b2015-06-13 00:41:00 -0700116 CPDF_Point ptB = pFFL->PWLtoFFL(righttop);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700117
118
119 CPDFSDK_Annot* pAnnot = pFFL->GetSDKAnnot();
120 ASSERT(pAnnot);
Bo Xufdc00a72014-10-28 23:03:33 -0700121 CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700122 ASSERT(pPage);
123 m_pEnv->FFI_OutputSelectedRect(pPage, ptA.x, ptB.y, ptB.x, ptA.y);
124 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700125
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700126}
127
128FX_BOOL CFX_SystemHandler::IsSelectionImplemented()
129{
130 if(m_pEnv)
131 {
132 FPDF_FORMFILLINFO* pInfo = m_pEnv->GetFormFillInfo();
133 if(pInfo && pInfo->FFI_OutputSelectedRect)
134 return TRUE;
135 }
136 return FALSE;
137}
138
Tom Sepezbfa9a822015-06-09 13:24:12 -0700139CFX_ByteString CFX_SystemHandler::GetNativeTrueTypeFont(int32_t nCharset)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700140{
141 return "";
142}
143
Lei Zhang60f507b2015-06-13 00:41:00 -0700144FX_BOOL CFX_SystemHandler::FindNativeTrueTypeFont(int32_t nCharset, CFX_ByteString sFontFaceName)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700145{
146 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr();
147// FXFT_Face nFace = pFontMgr->FindSubstFont(sFontFaceName,TRUE,0,0,0,0,NULL);
148// FXFT_Face nFace = pFontMgr->m_pBuiltinMapper->FindSubstFont(sFontFaceName,TRUE,0,0,0,0,NULL);
149
150 if(pFontMgr)
151 {
152 CFX_FontMapper* pFontMapper = pFontMgr->m_pBuiltinMapper;
153 if(pFontMapper)
Lei Zhang60f507b2015-06-13 00:41:00 -0700154 {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700155 int nSize = pFontMapper->m_InstalledTTFonts.GetSize();
156 if(nSize ==0)
157 {
158 pFontMapper->LoadInstalledFonts();
159 nSize = pFontMapper->m_InstalledTTFonts.GetSize();
160 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700161
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700162 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
176static int CharSet2CP(int charset)
177{
178 if(charset == 128)
179 return 932;
180 else if(charset == 134)
181 return 936;
182 else if(charset == 129)
183 return 949;
184 else if(charset == 136)
185 return 950;
186 return 0;
187}
Lei Zhang60f507b2015-06-13 00:41:00 -0700188CPDF_Font* CFX_SystemHandler::AddNativeTrueTypeFontToPDF(CPDF_Document* pDoc, CFX_ByteString sFontFaceName,
189 uint8_t nCharset)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700190{
191 if(pDoc)
192 {
193 CFX_Font* pFXFont = new CFX_Font();
194 pFXFont->LoadSubst(sFontFaceName,TRUE,0,0,0,CharSet2CP(nCharset),FALSE);
195 CPDF_Font* pFont = pDoc->AddFont(pFXFont,nCharset,FALSE);
196 delete pFXFont;
197 return pFont;
198 }
199
200 return NULL;
201}
202
203
Tom Sepezbfa9a822015-06-09 13:24:12 -0700204int32_t CFX_SystemHandler::SetTimer(int32_t uElapse, TimerCallback lpTimerFunc)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700205{
206 return m_pEnv->FFI_SetTimer(uElapse, lpTimerFunc);
207}
Tom Sepezbfa9a822015-06-09 13:24:12 -0700208void CFX_SystemHandler::KillTimer(int32_t nID)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700209{
210 m_pEnv->FFI_KillTimer(nID);
211}
212
213FX_SYSTEMTIME CFX_SystemHandler::GetLocalTime()
214{
215 return m_pEnv->FFI_GetLocalTime();
216}
217
Bo Xufdc00a72014-10-28 23:03:33 -0700218CPDFDoc_Environment::CPDFDoc_Environment(CPDFXFA_Document* pDoc) :
Nico Weber09363c82014-07-31 10:07:04 -0700219 m_pAnnotHandlerMgr(NULL),
220 m_pActionHandler(NULL),
221 m_pJSRuntime(NULL),
222 m_pInfo(NULL),
223 m_pSDKDoc(NULL),
Bo Xufdc00a72014-10-28 23:03:33 -0700224 m_pDoc(pDoc),
Nico Weber09363c82014-07-31 10:07:04 -0700225 m_pIFormFiller(NULL)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700226{
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700227 m_pSysHandler = NULL;
228 m_pSysHandler = new CFX_SystemHandler(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700229}
230
231CPDFDoc_Environment::~CPDFDoc_Environment()
232{
233
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700234 delete m_pIFormFiller;
235 m_pIFormFiller = NULL;
Bo Xufdc00a72014-10-28 23:03:33 -0700236
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700237 CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance();
238 if (m_pJSRuntime && pProvider->GetRuntimeFactory())
239 pProvider->GetRuntimeFactory()->DeleteJSRuntime(m_pJSRuntime);
Bo Xufdc00a72014-10-28 23:03:33 -0700240
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700241 if (pProvider->m_pEnvList.GetSize() == 0)
242 {
243 pProvider->ReleaseRuntime();
244 pProvider->InitRuntime(TRUE);
245 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700246
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700247 delete m_pSysHandler;
248 m_pSysHandler = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700249
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700250 delete m_pAnnotHandlerMgr;
251 m_pAnnotHandlerMgr = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700252
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700253 delete m_pActionHandler;
254 m_pActionHandler = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700255}
256
257
258IFXJS_Runtime* CPDFDoc_Environment::GetJSRuntime()
259{
260 if(!IsJSInitiated())
261 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700262 if(!m_pJSRuntime)
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700263 m_pJSRuntime = CPDFXFA_App::GetInstance()->GetRuntimeFactory()->NewJSRuntime(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700264 return m_pJSRuntime;
265}
266
267CPDFSDK_AnnotHandlerMgr* CPDFDoc_Environment::GetAnnotHandlerMgr()
268{
269 if(!m_pAnnotHandlerMgr)
270 m_pAnnotHandlerMgr = new CPDFSDK_AnnotHandlerMgr(this);
271 return m_pAnnotHandlerMgr;
272}
273
274CPDFSDK_ActionHandler* CPDFDoc_Environment::GetActionHander()
275{
276 if(!m_pActionHandler)
277 m_pActionHandler = new CPDFSDK_ActionHandler(this);
278 return m_pActionHandler;
279}
280
281int CPDFDoc_Environment::RegAppHandle(FPDF_FORMFILLINFO* pFFinfo)
282{
Lei Zhang60f507b2015-06-13 00:41:00 -0700283 m_pInfo = pFFinfo;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700284 return TRUE;
285}
286
287CPDFSDK_Document* CPDFDoc_Environment::GetCurrentDoc()
288{
289 return m_pSDKDoc;
290}
291
292CFFL_IFormFiller* CPDFDoc_Environment::GetIFormFiller()
293{
294 if(!m_pIFormFiller)
295 m_pIFormFiller = new CFFL_IFormFiller(this);
296 return m_pIFormFiller;
297}
298
299FX_BOOL CPDFDoc_Environment::IsJSInitiated()
300{
301 if(m_pInfo)
302 {
303 if(m_pInfo->m_pJsPlatform)
304 return TRUE;
305 else
306 return FALSE;
307 }
308 return FALSE;
309}
310
Bo Xufdc00a72014-10-28 23:03:33 -0700311CPDFSDK_Document::CPDFSDK_Document(CPDFXFA_Document* pDoc,CPDFDoc_Environment* pEnv):m_pDoc(pDoc),
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700312 m_pInterForm(NULL),m_pEnv(pEnv),m_pOccontent(NULL),m_bChangeMask(FALSE)
313{
314 m_pFocusAnnot = NULL;
315}
316
317CPDFSDK_Document::~CPDFSDK_Document()
318{
unknown636ad3b2014-10-29 19:37:24 +0800319 FX_POSITION pos = m_pageMap.GetStartPosition();
320 while(pos)
321 {
322 CPDFXFA_Page* pPage = NULL;
323 CPDFSDK_PageView* pPageView = NULL;
324 m_pageMap.GetNextAssoc(pos, pPage, pPageView);
325 delete pPageView;
326 }
Bo Xufdc00a72014-10-28 23:03:33 -0700327 m_pageMap.RemoveAll();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700328 if(m_pInterForm)
329 {
330 m_pInterForm->Destroy();
331 m_pInterForm = NULL;
332 }
333 if(m_pOccontent)
334 {
335 delete m_pOccontent;
336 m_pOccontent = NULL;
337 }
338}
339
340void CPDFSDK_Document::InitPageView()
341{
342 int nCount = m_pDoc->GetPageCount();
343 for(int i=0; i<nCount; i++)
344 {
345 // To do
346// CPDF_Dictionary* pDic = m_pDoc->GetPage(i);
347// m_pageMap.SetAt(pDic, pPageView);
348 }
349}
350
Bo Xufdc00a72014-10-28 23:03:33 -0700351void CPDFSDK_Document::AddPageView(CPDFXFA_Page* pPDFXFAPage, CPDFSDK_PageView* pPageView)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700352{
Bo Xufdc00a72014-10-28 23:03:33 -0700353 m_pageMap.SetAt(pPDFXFAPage, pPageView);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700354}
355
Bo Xufdc00a72014-10-28 23:03:33 -0700356CPDFSDK_PageView* CPDFSDK_Document::GetPageView(CPDFXFA_Page* pPDFXFAPage, FX_BOOL ReNew)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700357{
Bo Xufdc00a72014-10-28 23:03:33 -0700358 CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFXFAPage);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700359 if(pPageView != NULL)
360 return pPageView;
361 if(ReNew)
362 {
Bo Xufdc00a72014-10-28 23:03:33 -0700363 pPageView = new CPDFSDK_PageView(this,pPDFXFAPage);
364 m_pageMap.SetAt(pPDFXFAPage, pPageView);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700365 //Delay to load all the annotations, to avoid endless loop.
366 pPageView->LoadFXAnnots();
367 }
368 return pPageView;
369
370}
371
372CPDFSDK_PageView* CPDFSDK_Document::GetCurrentView()
373{
Lei Zhang60f507b2015-06-13 00:41:00 -0700374 CPDFXFA_Page* pPage = (CPDFXFA_Page *)m_pEnv->FFI_GetCurrentPage(m_pDoc);
375 return pPage ? GetPageView(pPage, TRUE) : nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700376}
377
378CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex)
379{
380 CPDFSDK_PageView * pTempPageView = NULL;
Bo Xufdc00a72014-10-28 23:03:33 -0700381 CPDFXFA_Page * pTempPage = (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700382 if(!pTempPage)
383 return NULL;
384
385 m_pageMap.Lookup(pTempPage, pTempPageView);
Lei Zhang60f507b2015-06-13 00:41:00 -0700386
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700387 ASSERT(pTempPageView != NULL);
Lei Zhang60f507b2015-06-13 00:41:00 -0700388
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700389 return pTempPageView;
390}
391
392void CPDFSDK_Document:: ProcJavascriptFun()
393{
Lei Zhang60f507b2015-06-13 00:41:00 -0700394 CPDFXFA_Document* pPDFDoc = GetDocument();
Bo Xufdc00a72014-10-28 23:03:33 -0700395 CPDF_DocJSActions docJS(pPDFDoc->GetPDFDoc());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700396 int iCount = docJS.CountJSActions();
397 if (iCount < 1) return;
398 for (int i = 0; i < iCount; i ++)
399 {
400 CFX_ByteString csJSName;
401 CPDF_Action jsAction = docJS.GetJSAction(i, csJSName);
402 if(m_pEnv->GetActionHander())
403 m_pEnv->GetActionHander()->DoAction_JavaScript(jsAction,CFX_WideString::FromLocal(csJSName),this);
404 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700405
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700406}
407
408FX_BOOL CPDFSDK_Document::ProcOpenAction()
409{
Tom Sepez7b5bc262015-03-05 16:44:22 -0800410 if(!m_pDoc)
411 return FALSE;
412
413 CPDF_Dictionary* pRoot = m_pDoc->GetPDFDoc()->GetRoot();
414 if (!pRoot)
415 return FALSE;
416
417 CPDF_Object* pOpenAction = pRoot->GetDict("OpenAction");
418 if(!pOpenAction)
419 pOpenAction = pRoot->GetArray("OpenAction");
420
421 if(!pOpenAction)
422 return FALSE;
423
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700424 if(pOpenAction->GetType()==PDFOBJ_ARRAY)
Tom Sepez7b5bc262015-03-05 16:44:22 -0800425 return TRUE;
426
427 if(pOpenAction->GetType()==PDFOBJ_DICTIONARY)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700428 {
Tom Sepez7b5bc262015-03-05 16:44:22 -0800429 CPDF_Dictionary * pDict=(CPDF_Dictionary*)pOpenAction;
430 CPDF_Action action(pDict);
431 if(m_pEnv->GetActionHander())
432 m_pEnv->GetActionHander()->DoAction_DocOpen(action, this);
433 return TRUE;
434 }
435 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700436}
437
438CPDF_OCContext* CPDFSDK_Document::GetOCContext()
439{
440 if(!m_pOccontent)
Bo Xufdc00a72014-10-28 23:03:33 -0700441 m_pOccontent = new CPDF_OCContext(m_pDoc->GetPDFDoc());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700442 return m_pOccontent;
443}
444
Bo Xufdc00a72014-10-28 23:03:33 -0700445void CPDFSDK_Document::ReMovePageView(CPDFXFA_Page* pPDFXFAPage)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700446{
Bo Xufdc00a72014-10-28 23:03:33 -0700447 CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFXFAPage);
unknown636ad3b2014-10-29 19:37:24 +0800448 if(pPageView && !pPageView->IsLocked())
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700449 {
450 delete pPageView;
Bo Xufdc00a72014-10-28 23:03:33 -0700451 m_pageMap.RemoveKey(pPDFXFAPage);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700452 }
453}
454
Bo Xufdc00a72014-10-28 23:03:33 -0700455CPDFXFA_Page * CPDFSDK_Document::GetPage(int nIndex)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700456{
Bo Xufdc00a72014-10-28 23:03:33 -0700457 CPDFXFA_Page * pTempPage = (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700458 if(!pTempPage)
459 return NULL;
460 return pTempPage;
461}
462
463CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm()
464{
465 if(!m_pInterForm)
466 m_pInterForm = new CPDFSDK_InterForm(this);
467 return m_pInterForm;
468}
469
470void CPDFSDK_Document::UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot)
471{
Lei Zhang60f507b2015-06-13 00:41:00 -0700472
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700473 FX_POSITION pos = m_pageMap.GetStartPosition();
Bo Xufdc00a72014-10-28 23:03:33 -0700474 CPDFXFA_Page * pPage = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700475 CPDFSDK_PageView * pPageView = NULL;
476 while(pos)
477 {
478 m_pageMap.GetNextAssoc(pos, pPage, pPageView);
479
480 if(pPageView != pSender)
481 {
482 pPageView->UpdateView(pAnnot);
483 }
484 }
485}
486
487CPDFSDK_Annot* CPDFSDK_Document::GetFocusAnnot()
488{
Lei Zhang60f507b2015-06-13 00:41:00 -0700489 return m_pFocusAnnot;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700490}
491
492FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot* pAnnot,FX_UINT nFlag)
493{
494
495 if(m_pFocusAnnot==pAnnot) return TRUE;
496
Bo Xufdc00a72014-10-28 23:03:33 -0700497 CPDFSDK_Annot* pLastFocusAnnot = m_pFocusAnnot;
498
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700499 if(m_pFocusAnnot)
500 {
Lei Zhang60f507b2015-06-13 00:41:00 -0700501 if(!KillFocusAnnot(nFlag) ) return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700502 }
Bo Xufdc00a72014-10-28 23:03:33 -0700503 CPDFSDK_PageView* pPageView = NULL;
504 if (pAnnot)
505 pPageView = pAnnot->GetPageView();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700506 if(pAnnot && pPageView->IsValid())
507 {
508 CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr();
509
510 if(pAnnotHandler&&!m_pFocusAnnot)
511 {
Bo Xufdc00a72014-10-28 23:03:33 -0700512 if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot,pLastFocusAnnot))
513 return FALSE;
514
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700515 if (!pAnnotHandler->Annot_OnSetFocus(pAnnot,nFlag))
516 return FALSE;
517 if(!m_pFocusAnnot)
518 {
Lei Zhang60f507b2015-06-13 00:41:00 -0700519 m_pFocusAnnot=pAnnot;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700520 return TRUE;
521 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700522 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700523 }
524 return FALSE;
525}
526
527FX_BOOL CPDFSDK_Document::KillFocusAnnot(FX_UINT nFlag)
528{
529 if(m_pFocusAnnot)
530 {
531 CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr();
532 if(pAnnotHandler)
533 {
534 CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot;
535 m_pFocusAnnot = NULL;
Bo Xufdc00a72014-10-28 23:03:33 -0700536
537 if (!pAnnotHandler->Annot_OnChangeFocus(NULL, pFocusAnnot))
538 return FALSE;
539
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700540 if(pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag))
541 {
Lei Zhang60f507b2015-06-13 00:41:00 -0700542
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700543 if(pFocusAnnot->GetType() == FX_BSTRC("Widget"))
544 {
545 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot;
546 int nFieldType = pWidget->GetFieldType();
547 if(FIELDTYPE_TEXTFIELD == nFieldType || FIELDTYPE_COMBOBOX == nFieldType)
548 m_pEnv->FFI_OnSetFieldInputFocus(NULL, NULL, 0, FALSE);
549 }
550
551 if(!m_pFocusAnnot)
552 return TRUE;
553 }
554 else
555 {
556 m_pFocusAnnot = pFocusAnnot;
557 }
558 }
559 }
560 return FALSE;
561}
562
563FX_BOOL CPDFSDK_Document::DeletePages(int nStart, int nCount)
564{
565 if ( nStart < 0 || nStart >= GetPageCount() || nCount <= 0 )
566 {
567 return FALSE;
568 }
569
Bo Xufdc00a72014-10-28 23:03:33 -0700570 CPDFXFA_Page * pTempPage = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700571 for ( int i = nCount-1; i >= 0; i-- )
572 {
573 pTempPage = GetPage(nStart+i);
574 if ( pTempPage != NULL )
575 {
576 ReMovePageView(pTempPage);
577 }
578 }
579 return TRUE;
580}
581
582void CPDFSDK_Document::OnCloseDocument()
583{
584 KillFocusAnnot();
585}
586
587FX_BOOL CPDFSDK_Document::GetPermissions(int nFlag)
588{
Bo Xufdc00a72014-10-28 23:03:33 -0700589 FX_DWORD dwPermissions = m_pDoc->GetPDFDoc()->GetUserPermissions();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700590 return dwPermissions&nFlag;
591}
592
593IFXJS_Runtime * CPDFSDK_Document::GetJsRuntime()
594{
595 ASSERT(m_pEnv!=NULL);
596 return m_pEnv->GetJSRuntime();
597}
598
Lei Zhang60f507b2015-06-13 00:41:00 -0700599CFX_WideString CPDFSDK_Document::GetPath()
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700600{
601 ASSERT(m_pEnv != NULL);
602 return m_pEnv->JS_docGetFilePath();
603}
604
605
Bo Xufdc00a72014-10-28 23:03:33 -0700606CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,CPDFXFA_Page* page):m_page(page),m_pSDKDoc(pSDKDoc)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700607{
608 CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm();
609 if(pInterForm)
610 {
611 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
Bo Xufdc00a72014-10-28 23:03:33 -0700612 if (page->GetPDFPage())
613 pPDFInterForm->FixPageFields(page->GetPDFPage());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700614 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700615 m_fxAnnotArray.RemoveAll();
616
617 m_bEnterWidget = FALSE;
618 m_bExitWidget = FALSE;
619 m_bOnWidget = FALSE;
620 m_CaptureWidget = NULL;
621 m_bValid = FALSE;
unknown636ad3b2014-10-29 19:37:24 +0800622 m_bLocked = FALSE;
Bo Xufdc00a72014-10-28 23:03:33 -0700623 m_pAnnotList = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700624}
625
626CPDFSDK_PageView::~CPDFSDK_PageView()
627{
Lei Zhang60f507b2015-06-13 00:41:00 -0700628 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700629 int nAnnotCount = m_fxAnnotArray.GetSize();
630 for (int i=0; i<nAnnotCount; i++)
631 {
632 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
633 //if there is a focused annot on the page, we should kill the focus first.
634 if(pAnnot == m_pSDKDoc->GetFocusAnnot())
635 KillFocusAnnot();
636 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
637 ASSERT(pAnnotHandlerMgr);
638 pAnnotHandlerMgr->ReleaseAnnot(pAnnot);
639 }
640 m_fxAnnotArray.RemoveAll();
641 if(m_pAnnotList)
642 {
643 delete m_pAnnotList;
644 m_pAnnotList = NULL;
645 }
646}
647
Bo Xufdc00a72014-10-28 23:03:33 -0700648void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,CPDF_RenderOptions* pOptions, FX_RECT* pClip)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700649{
650 m_curMatrix = *pUser2Device;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700651 // m_pAnnotList->DisplayAnnots(m_page, pDevice, pUser2Device, FALSE, pOptions);
652 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
Bo Xufdc00a72014-10-28 23:03:33 -0700653 CPDFXFA_Page* pPage = GetPDFXFAPage();
654
655 if (pPage == NULL) return;
656
657 if (pPage->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA) {
658 CFX_Graphics gs;
659 gs.Create(pDevice);
660 if (pClip) {
661 CFX_RectF rectClip;
Bruce Dawson3f49aa32015-01-08 11:47:49 -0800662 rectClip.Set(static_cast<FX_FLOAT>(pClip->left),
663 static_cast<FX_FLOAT>(pClip->top),
664 static_cast<FX_FLOAT>(pClip->Width()),
665 static_cast<FX_FLOAT>(pClip->Height()));
Bo Xufdc00a72014-10-28 23:03:33 -0700666 gs.SetClipRect(rectClip);
667 }
668 IXFA_RenderContext* pRenderContext = XFA_RenderContext_Create();
669 if (!pRenderContext)
670 return;
671 CXFA_RenderOptions renderOptions;
672 renderOptions.m_bHighlight = TRUE;
673 pRenderContext->StartRender(pPage->GetXFAPageView(), &gs, *pUser2Device, renderOptions);
674 pRenderContext->DoRender();
675 pRenderContext->StopRender();
676 pRenderContext->Release();
677 return;
678 }
679 // for pdf/static xfa.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700680 CPDFSDK_AnnotIterator annotIterator(this, TRUE);
681 CPDFSDK_Annot * pSDKAnnot=NULL;
682 int index=-1;
Bo Xufdc00a72014-10-28 23:03:33 -0700683 pSDKAnnot = annotIterator.Next(index);
684 while(pSDKAnnot)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700685 {
686 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
687 ASSERT(pAnnotHandlerMgr);
688 pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, 0);
Bo Xufdc00a72014-10-28 23:03:33 -0700689 pSDKAnnot = annotIterator.Next(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700690 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700691}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700692CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
693{
Lei Zhang60f507b2015-06-13 00:41:00 -0700694
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700695 int nCount = m_pAnnotList->Count();
696 for(int i = 0 ; i<nCount; i++)
697 {
698 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);
699 CFX_FloatRect annotRect;
700 pAnnot->GetRect(annotRect);
701 if(annotRect.Contains(pageX, pageY))
702 return pAnnot;
703 }
704 return NULL;
705}
706
707CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
708{
Lei Zhang60f507b2015-06-13 00:41:00 -0700709
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700710 int nCount = m_pAnnotList->Count();
711 for(int i = 0 ; i<nCount; i++)
712 {
713 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);
714 if(pAnnot->GetSubType() == "Widget")
715 {
716 CFX_FloatRect annotRect;
717 pAnnot->GetRect(annotRect);
718 if(annotRect.Contains(pageX, pageY))
719 return pAnnot;
720 }
721 }
722 return NULL;
723}
724
725CPDFSDK_Annot* CPDFSDK_PageView::GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
726{
727
728 CPDFSDK_AnnotIterator annotIterator(this, FALSE);
729 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
730 CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr();
731 CPDFSDK_Annot* pSDKAnnot = NULL;
732 int index = -1;
Bo Xufdc00a72014-10-28 23:03:33 -0700733 pSDKAnnot = annotIterator.Next(index);
734 while(pSDKAnnot)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700735 {
736 CPDF_Rect rc = pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
737 if(rc.Contains(pageX, pageY))
738 return pSDKAnnot;
Bo Xufdc00a72014-10-28 23:03:33 -0700739 pSDKAnnot = annotIterator.Next(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700740 }
741
742 return NULL;
743}
744
745CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
746{
747
748 CPDFSDK_AnnotIterator annotIterator(this, FALSE);
749 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
750 CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr();
751 CPDFSDK_Annot* pSDKAnnot = NULL;
752 int index = -1;
Bo Xufdc00a72014-10-28 23:03:33 -0700753 pSDKAnnot = annotIterator.Next(index);
754 while(pSDKAnnot)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700755 {
Bo Xufdc00a72014-10-28 23:03:33 -0700756 if(pSDKAnnot->GetType() == "Widget" || pSDKAnnot->GetType() == FSDK_XFAWIDGET_TYPENAME)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700757 {
758 pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
759 CPDF_Point point(pageX, pageY);
760 if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point))
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700761 return pSDKAnnot;
762 }
Bo Xufdc00a72014-10-28 23:03:33 -0700763 pSDKAnnot = annotIterator.Next(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700764 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700765
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700766 return NULL;
767}
768
769
770FX_BOOL CPDFSDK_PageView::Annot_HasAppearance(CPDF_Annot* pAnnot)
771{
Lei Zhang64adf192015-06-05 15:50:32 -0700772 CPDF_Dictionary* pAnnotDic = pAnnot->GetAnnotDict();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700773 if(pAnnotDic)
774 return pAnnotDic->KeyExist("AS");
775 return FALSE;
776}
777
778CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Annot * pPDFAnnot)
779{
780 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
781 ASSERT(pEnv);
Lei Zhang60f507b2015-06-13 00:41:00 -0700782 CPDFSDK_AnnotHandlerMgr * pAnnotHandler= pEnv->GetAnnotHandlerMgr();
783
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700784 CPDFSDK_Annot* pSDKAnnot =NULL;
Lei Zhang60f507b2015-06-13 00:41:00 -0700785
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700786 if(pAnnotHandler)
787 {
788 pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this);
789 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700790 if(!pSDKAnnot)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700791 return NULL;
792
Lei Zhang60f507b2015-06-13 00:41:00 -0700793 m_fxAnnotArray.Add(pSDKAnnot);
794
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700795 if(pAnnotHandler)
Lei Zhang60f507b2015-06-13 00:41:00 -0700796 {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700797 pAnnotHandler->Annot_OnCreate(pSDKAnnot);
Lei Zhang60f507b2015-06-13 00:41:00 -0700798
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700799 }
800
801 return pSDKAnnot;
802}
803
Tom Sepezeed467d2015-06-02 10:35:27 -0700804CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(IXFA_Widget* pPDFAnnot)
Bo Xufdc00a72014-10-28 23:03:33 -0700805{
806 if (!pPDFAnnot) return NULL;
807
808 CPDFSDK_Annot* pSDKAnnot = GetAnnotByXFAWidget(pPDFAnnot);
809 if (pSDKAnnot)
810 return pSDKAnnot;
811
812 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
813 ASSERT(pEnv);
814 CPDFSDK_AnnotHandlerMgr * pAnnotHandler= pEnv->GetAnnotHandlerMgr();
815
816 pSDKAnnot =NULL;
817
818 if(pAnnotHandler)
819 {
820 pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this);
821 }
822 if(!pSDKAnnot)
823 return NULL;
824
825 m_fxAnnotArray.Add(pSDKAnnot);
826
827 return pSDKAnnot;
828}
829
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700830CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary * pDict)
831{
Lei Zhang60f507b2015-06-13 00:41:00 -0700832 return pDict ? AddAnnot(pDict->GetString("Subtype"), pDict) : nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700833}
834
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700835CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(const FX_CHAR* lpSubType,CPDF_Dictionary * pDict)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700836{
837 return NULL;
838}
839
840FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot)
841{
Bo Xufdc00a72014-10-28 23:03:33 -0700842 if (!pAnnot)
843 return FALSE;
844 CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage();
845 if (!pPage || (pPage->GetDocument()->GetDocType() != DOCTYPE_STATIC_XFA && pPage->GetDocument()->GetDocType() != DOCTYPE_DYNIMIC_XFA))
846 return FALSE;
847
848 int index = m_fxAnnotArray.Find(pAnnot);
849 m_fxAnnotArray.RemoveAt(index);
850 if (m_CaptureWidget == pAnnot)
851 m_CaptureWidget = NULL;
852
853 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700854}
855
856CPDF_Document* CPDFSDK_PageView::GetPDFDocument()
857{
858 if(m_page)
859 {
Bo Xufdc00a72014-10-28 23:03:33 -0700860 return m_page->GetDocument()->GetPDFDoc();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700861 }
862 return NULL;
863}
864
Bo Xufdc00a72014-10-28 23:03:33 -0700865CPDF_Page* CPDFSDK_PageView::GetPDFPage()
866{
867 if (m_page)
868 {
869 return m_page->GetPDFPage();
870 }
871
872 return NULL;
873}
874
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700875int CPDFSDK_PageView::CountAnnots()
876{
Bo Xufdc00a72014-10-28 23:03:33 -0700877 return m_fxAnnotArray.GetSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700878}
879
880CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(int nIndex)
881{
882 int nCount = m_fxAnnotArray.GetSize();
883 if ( nIndex < 0 || nIndex >= nCount )
884 {
885 return NULL;
886 }
887
888 return (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(nIndex);
889}
890
891CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary * pDict)
892{
893 int nCount = m_fxAnnotArray.GetSize();
894 for(int i=0; i<nCount; i++)
895 {
896 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
Lei Zhang64adf192015-06-05 15:50:32 -0700897 if (pDict == pAnnot->GetPDFAnnot()->GetAnnotDict())
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700898 return pAnnot;
899 }
900 return NULL;
901}
Tom Sepezeed467d2015-06-02 10:35:27 -0700902CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(IXFA_Widget* hWidget)
Bo Xufdc00a72014-10-28 23:03:33 -0700903{
904 if (hWidget == NULL)
905 return NULL;
906 int annotCount = m_fxAnnotArray.GetSize();
907
908 for(int i = 0; i < annotCount; i++)
909 {
910 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
911 if(pAnnot->GetXFAWidget() == hWidget)
912 return pAnnot;
913 }
914 return NULL;
915}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700916
917FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point & point, FX_UINT nFlag)
918{
919 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
920 ASSERT(pEnv);
921 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
922 if(!pFXAnnot)
923 {
924 KillFocusAnnot(nFlag);
925 }
926 else
927 {
928 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
929 ASSERT(pAnnotHandlerMgr);
930
931 FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnLButtonDown(this, pFXAnnot, nFlag,point);
932 if(bRet)
933 {
934 SetFocusAnnot(pFXAnnot);
935 }
936 return bRet;
937 }
938 return FALSE;
939}
940
Bo Xufdc00a72014-10-28 23:03:33 -0700941FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CPDF_Point & point, FX_UINT nFlag)
942{
943 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
944 ASSERT(pEnv);
945 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
946 ASSERT(pAnnotHandlerMgr);
947
948 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
949
950 if (pFXAnnot == NULL)
951 return FALSE;
952
953 FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnRButtonDown(this, pFXAnnot, nFlag,point);
954 if (bRet)
955 {
956 SetFocusAnnot(pFXAnnot);
957 }
958 return TRUE;
959}
960
961FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CPDF_Point & point, FX_UINT nFlag)
962{
963 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
964 ASSERT(pEnv);
965 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
966 ASSERT(pAnnotHandlerMgr);
967
968 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
969
970 if (pFXAnnot == NULL)
971 return FALSE;
972
973 FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnRButtonUp(this, pFXAnnot, nFlag,point);
974 if (bRet)
975 {
976 SetFocusAnnot(pFXAnnot);
977 }
978 return TRUE;
979}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700980
981FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CPDF_Point & point, FX_UINT nFlag)
982{
983 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
984 ASSERT(pEnv);
985 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
986 ASSERT(pAnnotHandlerMgr);
987 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
988 CPDFSDK_Annot* pFocusAnnot = GetFocusAnnot();
989 FX_BOOL bRet = FALSE;
990 if(pFocusAnnot && pFocusAnnot != pFXAnnot)
991 {
992 //Last focus Annot gets a chance to handle the event.
993 bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFocusAnnot, nFlag,point);
994 }
995 if(pFXAnnot && !bRet)
996 {
997 bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFXAnnot, nFlag,point);
998 return bRet;
999 }
1000 return bRet;
1001}
1002
1003FX_BOOL CPDFSDK_PageView::OnMouseMove(const CPDF_Point & point, int nFlag)
1004{
1005
1006 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1007 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1008 ASSERT(pAnnotHandlerMgr);
1009 if(CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y))
1010 {
1011 if(m_CaptureWidget && m_CaptureWidget != pFXAnnot)
1012 {
1013 m_bExitWidget = TRUE;
1014 m_bEnterWidget = FALSE;
1015 pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag);
1016 }
1017 m_CaptureWidget = (CPDFSDK_Widget*)pFXAnnot;
1018 m_bOnWidget = TRUE;
1019 if(!m_bEnterWidget)
1020 {
1021 m_bEnterWidget = TRUE;
1022 m_bExitWidget = FALSE;
1023 pAnnotHandlerMgr->Annot_OnMouseEnter(this, pFXAnnot,nFlag);
1024 }
1025 pAnnotHandlerMgr->Annot_OnMouseMove(this, pFXAnnot, nFlag, point);
1026 return TRUE;
1027 }
1028 else
1029 {
1030 if(m_bOnWidget)
Lei Zhang60f507b2015-06-13 00:41:00 -07001031 {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001032 m_bOnWidget = FALSE;
1033 m_bExitWidget = TRUE;
1034 m_bEnterWidget = FALSE;
1035 if(m_CaptureWidget)
1036 {
1037 pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag);
1038 m_CaptureWidget = NULL;
1039 }
1040 }
1041 return FALSE;
1042 }
Lei Zhang60f507b2015-06-13 00:41:00 -07001043
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001044 return FALSE;;
1045}
1046
1047FX_BOOL CPDFSDK_PageView::OnMouseWheel(double deltaX, double deltaY,const CPDF_Point& point, int nFlag)
1048{
1049 if(CPDFSDK_Annot* pAnnot = GetFXWidgetAtPoint(point.x, point.y))
1050 {
1051 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1052 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1053 ASSERT(pAnnotHandlerMgr);
1054 return pAnnotHandlerMgr->Annot_OnMouseWheel(this, pAnnot, nFlag, (int)deltaY, point);
1055 }
1056 return FALSE;
1057
1058}
1059
1060FX_BOOL CPDFSDK_PageView::OnChar(int nChar, FX_UINT nFlag)
1061{
1062 if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
1063 {
1064 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1065 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1066 ASSERT(pAnnotHandlerMgr);
1067 return pAnnotHandlerMgr->Annot_OnChar(pAnnot, nChar, nFlag);
1068 }
1069
1070 return FALSE;
1071}
1072
1073FX_BOOL CPDFSDK_PageView::OnKeyDown(int nKeyCode, int nFlag)
1074{
1075 if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
1076 {
1077 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1078 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1079 ASSERT(pAnnotHandlerMgr);
1080 return pAnnotHandlerMgr->Annot_OnKeyDown(pAnnot, nKeyCode, nFlag);
1081 }
1082 return FALSE;
1083}
1084
1085FX_BOOL CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag)
1086{
1087// if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
1088// {
1089// CFFL_IFormFiller* pIFormFiller = g_pFormFillApp->GetIFormFiller();
1090// return pIFormFiller->OnKeyUp(pAnnot, nKeyCode, nFlag);
1091// }
1092 return FALSE;
1093}
1094
1095extern void CheckUnSupportAnnot(CPDF_Document * pDoc, CPDF_Annot* pPDFAnnot);
1096
1097void CPDFSDK_PageView::LoadFXAnnots()
1098{
Bo Xufdc00a72014-10-28 23:03:33 -07001099 ASSERT(m_page != NULL);
1100
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001101 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
Bo Xufdc00a72014-10-28 23:03:33 -07001102 ASSERT(pEnv != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001103
Bo Xufdc00a72014-10-28 23:03:33 -07001104 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1105 ASSERT(pAnnotHandlerMgr != NULL);
1106
unknown636ad3b2014-10-29 19:37:24 +08001107 SetLock(TRUE);
1108 m_page->AddRef();
Bo Xufdc00a72014-10-28 23:03:33 -07001109 if (m_pSDKDoc->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001110 {
Bo Xufdc00a72014-10-28 23:03:33 -07001111 IXFA_PageView* pageView = NULL;
1112 pageView = m_page->GetXFAPageView();
1113 ASSERT(pageView != NULL);
1114
Bo Xufdc00a72014-10-28 23:03:33 -07001115 IXFA_WidgetIterator* pWidgetHander = pageView->CreateWidgetIterator(XFA_TRAVERSEWAY_Form, XFA_WIDGETFILTER_Visible|XFA_WIDGETFILTER_Viewable|XFA_WIDGETFILTER_AllType);
1116 if (!pWidgetHander)
unknown636ad3b2014-10-29 19:37:24 +08001117 {
1118 m_page->Release();
1119 SetLock(FALSE);
Bo Xufdc00a72014-10-28 23:03:33 -07001120 return;
unknown636ad3b2014-10-29 19:37:24 +08001121 }
Bo Xufdc00a72014-10-28 23:03:33 -07001122
Tom Sepezeed467d2015-06-02 10:35:27 -07001123 IXFA_Widget* pXFAAnnot = pWidgetHander->MoveToNext();
Bo Xufdc00a72014-10-28 23:03:33 -07001124 while (pXFAAnnot) {
1125 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pXFAAnnot, this);
1126 if(!pAnnot) {
1127 pXFAAnnot = pWidgetHander->MoveToNext();
1128 continue;
1129 }
1130 m_fxAnnotArray.Add(pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001131
Bo Xufdc00a72014-10-28 23:03:33 -07001132 pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001133
Bo Xufdc00a72014-10-28 23:03:33 -07001134 pXFAAnnot = pWidgetHander->MoveToNext();
Bo Xufacd0152014-09-24 10:49:52 -07001135
Bo Xufdc00a72014-10-28 23:03:33 -07001136 }
1137
1138 pWidgetHander->Release();
1139 }
1140 else
1141 {
1142 CPDF_Page* pPage = m_page->GetPDFPage();
1143 ASSERT(pPage != NULL);
1144
1145 FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled();
1146 //Disable the default AP construction.
1147 CPDF_InterForm::EnableUpdateAP(FALSE);
1148 m_pAnnotList = new CPDF_AnnotList(pPage);
1149 CPDF_InterForm::EnableUpdateAP(enableAPUpdate);
1150
1151 int nCount = m_pAnnotList->Count();
1152 for(int i=0; i<nCount; i++)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001153 {
Bo Xufdc00a72014-10-28 23:03:33 -07001154 CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i);
Lei Zhang60f507b2015-06-13 00:41:00 -07001155 CPDF_Document * pDoc = GetPDFDocument();
Bo Xufdc00a72014-10-28 23:03:33 -07001156
1157 CheckUnSupportAnnot(pDoc, pPDFAnnot);
1158
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001159 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this);
1160 if(!pAnnot)
1161 continue;
1162 m_fxAnnotArray.Add(pAnnot);
1163
1164 pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
1165 }
1166
1167 }
unknown636ad3b2014-10-29 19:37:24 +08001168 m_page->Release();
1169 SetLock(FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001170}
1171
1172void CPDFSDK_PageView::UpdateRects(CFX_RectArray& rects)
1173{
1174 for(int i=0; i<rects.GetSize(); i++)
1175 {
1176 CPDF_Rect rc = rects.GetAt(i);
1177 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1178 pEnv->FFI_Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom);
1179 }
1180}
1181
1182void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot)
1183{
Lei Zhang60f507b2015-06-13 00:41:00 -07001184 CPDF_Rect rcWindow = pAnnot->GetRect();
1185 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1186 pEnv->FFI_Invalidate(
1187 m_page, rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001188}
1189
1190int CPDFSDK_PageView::GetPageIndex()
1191{
1192 if(m_page)
1193 {
Bo Xufdc00a72014-10-28 23:03:33 -07001194 CPDF_Dictionary* pDic = m_page->GetPDFPage()->m_pFormDict;
1195 CPDFXFA_Document* pDoc = m_pSDKDoc->GetDocument();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001196 if(pDoc && pDic)
1197 {
Bo Xufdc00a72014-10-28 23:03:33 -07001198 return pDoc->GetPDFDoc()->GetPageIndex(pDic->GetObjNum());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001199 }
1200 }
1201 return -1;
1202}
1203
Tom Sepezd7e5cc72015-06-10 14:33:37 -07001204FX_BOOL CPDFSDK_PageView::IsValidAnnot(void* p)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001205{
1206 if (p == NULL) return FALSE;
1207 int iCount = m_pAnnotList->Count();
1208 for (int i = 0; i < iCount; i++)
1209 {
1210 if (m_pAnnotList->GetAt(i) == p)
1211 return TRUE;
1212 }
1213 return FALSE;
1214}
1215
1216
1217CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot()
1218{
1219 CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot();
1220 if(!pFocusAnnot)
1221 return NULL;
Lei Zhang60f507b2015-06-13 00:41:00 -07001222
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001223 for(int i=0; i<m_fxAnnotArray.GetSize(); i++)
1224 {
1225 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
1226 if(pAnnot == pFocusAnnot)
1227 return pAnnot;
1228 }
1229 return NULL;
1230}
1231