blob: dc454ee160e192fe93022bd915b2ff0a483bde92 [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.
4
5// 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;}
36
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
41 FXCT_ARROW
42 FXCT_NESW
43 FXCT_NWSE
44 FXCT_VBEAM
45 FXCT_HBEAM
46 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);
116 CPDF_Point ptB = pFFL->PWLtoFFL(righttop);
117
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 }
125
126}
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
Tom Sepezbfa9a822015-06-09 13:24:12 -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)
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
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}
188CPDF_Font* CFX_SystemHandler::AddNativeTrueTypeFontToPDF(CPDF_Document* pDoc, CFX_ByteString sFontFaceName,
Tom Sepezbfa9a822015-06-09 13:24:12 -0700189 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{
283 m_pInfo = pFFinfo;
284 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{
Bo Xufdc00a72014-10-28 23:03:33 -0700374 CPDFXFA_Page * pPage = (CPDFXFA_Page *)m_pEnv->FFI_GetCurrentPage(m_pDoc);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700375 if(pPage)
376 return this->GetPageView(pPage, TRUE);
377 return NULL;
378}
379
380CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex)
381{
382 CPDFSDK_PageView * pTempPageView = NULL;
Bo Xufdc00a72014-10-28 23:03:33 -0700383 CPDFXFA_Page * pTempPage = (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700384 if(!pTempPage)
385 return NULL;
386
387 m_pageMap.Lookup(pTempPage, pTempPageView);
388
389 ASSERT(pTempPageView != NULL);
390
391 return pTempPageView;
392}
393
394void CPDFSDK_Document:: ProcJavascriptFun()
395{
Bo Xufdc00a72014-10-28 23:03:33 -0700396 CPDFXFA_Document* pPDFDoc = this->GetDocument();
397 CPDF_DocJSActions docJS(pPDFDoc->GetPDFDoc());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700398 int iCount = docJS.CountJSActions();
399 if (iCount < 1) return;
400 for (int i = 0; i < iCount; i ++)
401 {
402 CFX_ByteString csJSName;
403 CPDF_Action jsAction = docJS.GetJSAction(i, csJSName);
404 if(m_pEnv->GetActionHander())
405 m_pEnv->GetActionHander()->DoAction_JavaScript(jsAction,CFX_WideString::FromLocal(csJSName),this);
406 }
407
408}
409
410FX_BOOL CPDFSDK_Document::ProcOpenAction()
411{
Tom Sepez7b5bc262015-03-05 16:44:22 -0800412 if(!m_pDoc)
413 return FALSE;
414
415 CPDF_Dictionary* pRoot = m_pDoc->GetPDFDoc()->GetRoot();
416 if (!pRoot)
417 return FALSE;
418
419 CPDF_Object* pOpenAction = pRoot->GetDict("OpenAction");
420 if(!pOpenAction)
421 pOpenAction = pRoot->GetArray("OpenAction");
422
423 if(!pOpenAction)
424 return FALSE;
425
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700426 if(pOpenAction->GetType()==PDFOBJ_ARRAY)
Tom Sepez7b5bc262015-03-05 16:44:22 -0800427 return TRUE;
428
429 if(pOpenAction->GetType()==PDFOBJ_DICTIONARY)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700430 {
Tom Sepez7b5bc262015-03-05 16:44:22 -0800431 CPDF_Dictionary * pDict=(CPDF_Dictionary*)pOpenAction;
432 CPDF_Action action(pDict);
433 if(m_pEnv->GetActionHander())
434 m_pEnv->GetActionHander()->DoAction_DocOpen(action, this);
435 return TRUE;
436 }
437 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700438}
439
440CPDF_OCContext* CPDFSDK_Document::GetOCContext()
441{
442 if(!m_pOccontent)
Bo Xufdc00a72014-10-28 23:03:33 -0700443 m_pOccontent = new CPDF_OCContext(m_pDoc->GetPDFDoc());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700444 return m_pOccontent;
445}
446
Bo Xufdc00a72014-10-28 23:03:33 -0700447void CPDFSDK_Document::ReMovePageView(CPDFXFA_Page* pPDFXFAPage)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700448{
Bo Xufdc00a72014-10-28 23:03:33 -0700449 CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFXFAPage);
unknown636ad3b2014-10-29 19:37:24 +0800450 if(pPageView && !pPageView->IsLocked())
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700451 {
452 delete pPageView;
Bo Xufdc00a72014-10-28 23:03:33 -0700453 m_pageMap.RemoveKey(pPDFXFAPage);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700454 }
455}
456
Bo Xufdc00a72014-10-28 23:03:33 -0700457CPDFXFA_Page * CPDFSDK_Document::GetPage(int nIndex)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700458{
Bo Xufdc00a72014-10-28 23:03:33 -0700459 CPDFXFA_Page * pTempPage = (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700460 if(!pTempPage)
461 return NULL;
462 return pTempPage;
463}
464
465CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm()
466{
467 if(!m_pInterForm)
468 m_pInterForm = new CPDFSDK_InterForm(this);
469 return m_pInterForm;
470}
471
472void CPDFSDK_Document::UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot)
473{
474
475 FX_POSITION pos = m_pageMap.GetStartPosition();
Bo Xufdc00a72014-10-28 23:03:33 -0700476 CPDFXFA_Page * pPage = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700477 CPDFSDK_PageView * pPageView = NULL;
478 while(pos)
479 {
480 m_pageMap.GetNextAssoc(pos, pPage, pPageView);
481
482 if(pPageView != pSender)
483 {
484 pPageView->UpdateView(pAnnot);
485 }
486 }
487}
488
489CPDFSDK_Annot* CPDFSDK_Document::GetFocusAnnot()
490{
491 return this->m_pFocusAnnot;
492}
493
494FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot* pAnnot,FX_UINT nFlag)
495{
496
497 if(m_pFocusAnnot==pAnnot) return TRUE;
498
Bo Xufdc00a72014-10-28 23:03:33 -0700499 CPDFSDK_Annot* pLastFocusAnnot = m_pFocusAnnot;
500
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700501 if(m_pFocusAnnot)
502 {
503 if(!this->KillFocusAnnot(nFlag) ) return FALSE;
504 }
Bo Xufdc00a72014-10-28 23:03:33 -0700505 CPDFSDK_PageView* pPageView = NULL;
506 if (pAnnot)
507 pPageView = pAnnot->GetPageView();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700508 if(pAnnot && pPageView->IsValid())
509 {
510 CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr();
511
512 if(pAnnotHandler&&!m_pFocusAnnot)
513 {
Bo Xufdc00a72014-10-28 23:03:33 -0700514 if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot,pLastFocusAnnot))
515 return FALSE;
516
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700517 if (!pAnnotHandler->Annot_OnSetFocus(pAnnot,nFlag))
518 return FALSE;
519 if(!m_pFocusAnnot)
520 {
521 this->m_pFocusAnnot=pAnnot;
522 return TRUE;
523 }
524 }
525 }
526 return FALSE;
527}
528
529FX_BOOL CPDFSDK_Document::KillFocusAnnot(FX_UINT nFlag)
530{
531 if(m_pFocusAnnot)
532 {
533 CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr();
534 if(pAnnotHandler)
535 {
536 CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot;
537 m_pFocusAnnot = NULL;
Bo Xufdc00a72014-10-28 23:03:33 -0700538
539 if (!pAnnotHandler->Annot_OnChangeFocus(NULL, pFocusAnnot))
540 return FALSE;
541
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700542 if(pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag))
543 {
544
545 if(pFocusAnnot->GetType() == FX_BSTRC("Widget"))
546 {
547 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot;
548 int nFieldType = pWidget->GetFieldType();
549 if(FIELDTYPE_TEXTFIELD == nFieldType || FIELDTYPE_COMBOBOX == nFieldType)
550 m_pEnv->FFI_OnSetFieldInputFocus(NULL, NULL, 0, FALSE);
551 }
552
553 if(!m_pFocusAnnot)
554 return TRUE;
555 }
556 else
557 {
558 m_pFocusAnnot = pFocusAnnot;
559 }
560 }
561 }
562 return FALSE;
563}
564
565FX_BOOL CPDFSDK_Document::DeletePages(int nStart, int nCount)
566{
567 if ( nStart < 0 || nStart >= GetPageCount() || nCount <= 0 )
568 {
569 return FALSE;
570 }
571
Bo Xufdc00a72014-10-28 23:03:33 -0700572 CPDFXFA_Page * pTempPage = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700573 for ( int i = nCount-1; i >= 0; i-- )
574 {
575 pTempPage = GetPage(nStart+i);
576 if ( pTempPage != NULL )
577 {
578 ReMovePageView(pTempPage);
579 }
580 }
581 return TRUE;
582}
583
584void CPDFSDK_Document::OnCloseDocument()
585{
586 KillFocusAnnot();
587}
588
589FX_BOOL CPDFSDK_Document::GetPermissions(int nFlag)
590{
Bo Xufdc00a72014-10-28 23:03:33 -0700591 FX_DWORD dwPermissions = m_pDoc->GetPDFDoc()->GetUserPermissions();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700592 return dwPermissions&nFlag;
593}
594
595IFXJS_Runtime * CPDFSDK_Document::GetJsRuntime()
596{
597 ASSERT(m_pEnv!=NULL);
598 return m_pEnv->GetJSRuntime();
599}
600
601CFX_WideString CPDFSDK_Document::GetPath()
602{
603 ASSERT(m_pEnv != NULL);
604 return m_pEnv->JS_docGetFilePath();
605}
606
607
Bo Xufdc00a72014-10-28 23:03:33 -0700608CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,CPDFXFA_Page* page):m_page(page),m_pSDKDoc(pSDKDoc)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700609{
610 CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm();
611 if(pInterForm)
612 {
613 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
Bo Xufdc00a72014-10-28 23:03:33 -0700614 if (page->GetPDFPage())
615 pPDFInterForm->FixPageFields(page->GetPDFPage());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700616 }
Bo Xufdc00a72014-10-28 23:03:33 -0700617
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700618 m_fxAnnotArray.RemoveAll();
619
620 m_bEnterWidget = FALSE;
621 m_bExitWidget = FALSE;
622 m_bOnWidget = FALSE;
623 m_CaptureWidget = NULL;
624 m_bValid = FALSE;
unknown636ad3b2014-10-29 19:37:24 +0800625 m_bLocked = FALSE;
Bo Xufdc00a72014-10-28 23:03:33 -0700626 m_pAnnotList = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700627}
628
629CPDFSDK_PageView::~CPDFSDK_PageView()
630{
631 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
632 int nAnnotCount = m_fxAnnotArray.GetSize();
633 for (int i=0; i<nAnnotCount; i++)
634 {
635 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
636 //if there is a focused annot on the page, we should kill the focus first.
637 if(pAnnot == m_pSDKDoc->GetFocusAnnot())
638 KillFocusAnnot();
639 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
640 ASSERT(pAnnotHandlerMgr);
641 pAnnotHandlerMgr->ReleaseAnnot(pAnnot);
642 }
643 m_fxAnnotArray.RemoveAll();
644 if(m_pAnnotList)
645 {
646 delete m_pAnnotList;
647 m_pAnnotList = NULL;
648 }
649}
650
Bo Xufdc00a72014-10-28 23:03:33 -0700651void 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 -0700652{
653 m_curMatrix = *pUser2Device;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700654 // m_pAnnotList->DisplayAnnots(m_page, pDevice, pUser2Device, FALSE, pOptions);
655 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
Bo Xufdc00a72014-10-28 23:03:33 -0700656 CPDFXFA_Page* pPage = GetPDFXFAPage();
657
658 if (pPage == NULL) return;
659
660 if (pPage->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA) {
661 CFX_Graphics gs;
662 gs.Create(pDevice);
663 if (pClip) {
664 CFX_RectF rectClip;
Bruce Dawson3f49aa32015-01-08 11:47:49 -0800665 rectClip.Set(static_cast<FX_FLOAT>(pClip->left),
666 static_cast<FX_FLOAT>(pClip->top),
667 static_cast<FX_FLOAT>(pClip->Width()),
668 static_cast<FX_FLOAT>(pClip->Height()));
Bo Xufdc00a72014-10-28 23:03:33 -0700669 gs.SetClipRect(rectClip);
670 }
671 IXFA_RenderContext* pRenderContext = XFA_RenderContext_Create();
672 if (!pRenderContext)
673 return;
674 CXFA_RenderOptions renderOptions;
675 renderOptions.m_bHighlight = TRUE;
676 pRenderContext->StartRender(pPage->GetXFAPageView(), &gs, *pUser2Device, renderOptions);
677 pRenderContext->DoRender();
678 pRenderContext->StopRender();
679 pRenderContext->Release();
680 return;
681 }
682 // for pdf/static xfa.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700683 CPDFSDK_AnnotIterator annotIterator(this, TRUE);
684 CPDFSDK_Annot * pSDKAnnot=NULL;
685 int index=-1;
Bo Xufdc00a72014-10-28 23:03:33 -0700686 pSDKAnnot = annotIterator.Next(index);
687 while(pSDKAnnot)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700688 {
689 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
690 ASSERT(pAnnotHandlerMgr);
691 pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, 0);
Bo Xufdc00a72014-10-28 23:03:33 -0700692 pSDKAnnot = annotIterator.Next(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700693 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700694}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700695CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
696{
697
698 int nCount = m_pAnnotList->Count();
699 for(int i = 0 ; i<nCount; i++)
700 {
701 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);
702 CFX_FloatRect annotRect;
703 pAnnot->GetRect(annotRect);
704 if(annotRect.Contains(pageX, pageY))
705 return pAnnot;
706 }
707 return NULL;
708}
709
710CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
711{
712
713 int nCount = m_pAnnotList->Count();
714 for(int i = 0 ; i<nCount; i++)
715 {
716 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);
717 if(pAnnot->GetSubType() == "Widget")
718 {
719 CFX_FloatRect annotRect;
720 pAnnot->GetRect(annotRect);
721 if(annotRect.Contains(pageX, pageY))
722 return pAnnot;
723 }
724 }
725 return NULL;
726}
727
728CPDFSDK_Annot* CPDFSDK_PageView::GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
729{
730
731 CPDFSDK_AnnotIterator annotIterator(this, FALSE);
732 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
733 CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr();
734 CPDFSDK_Annot* pSDKAnnot = NULL;
735 int index = -1;
Bo Xufdc00a72014-10-28 23:03:33 -0700736 pSDKAnnot = annotIterator.Next(index);
737 while(pSDKAnnot)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700738 {
739 CPDF_Rect rc = pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
740 if(rc.Contains(pageX, pageY))
741 return pSDKAnnot;
Bo Xufdc00a72014-10-28 23:03:33 -0700742 pSDKAnnot = annotIterator.Next(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700743 }
744
745 return NULL;
746}
747
748CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
749{
750
751 CPDFSDK_AnnotIterator annotIterator(this, FALSE);
752 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
753 CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr();
754 CPDFSDK_Annot* pSDKAnnot = NULL;
755 int index = -1;
Bo Xufdc00a72014-10-28 23:03:33 -0700756 pSDKAnnot = annotIterator.Next(index);
757 while(pSDKAnnot)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700758 {
Bo Xufdc00a72014-10-28 23:03:33 -0700759 if(pSDKAnnot->GetType() == "Widget" || pSDKAnnot->GetType() == FSDK_XFAWIDGET_TYPENAME)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700760 {
761 pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
762 CPDF_Point point(pageX, pageY);
763 if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point))
764// if(rc.Contains(pageX, pageY))
765 return pSDKAnnot;
766 }
Bo Xufdc00a72014-10-28 23:03:33 -0700767 pSDKAnnot = annotIterator.Next(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700768 }
769
770 return NULL;
771}
772
773
774FX_BOOL CPDFSDK_PageView::Annot_HasAppearance(CPDF_Annot* pAnnot)
775{
Lei Zhang64adf192015-06-05 15:50:32 -0700776 CPDF_Dictionary* pAnnotDic = pAnnot->GetAnnotDict();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700777 if(pAnnotDic)
778 return pAnnotDic->KeyExist("AS");
779 return FALSE;
780}
781
782CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Annot * pPDFAnnot)
783{
784 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
785 ASSERT(pEnv);
786 CPDFSDK_AnnotHandlerMgr * pAnnotHandler= pEnv->GetAnnotHandlerMgr();
787
788 CPDFSDK_Annot* pSDKAnnot =NULL;
789
790 if(pAnnotHandler)
791 {
792 pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this);
793 }
794 if(!pSDKAnnot)
795 return NULL;
796
797 m_fxAnnotArray.Add(pSDKAnnot);
798
799 if(pAnnotHandler)
800 {
801 pAnnotHandler->Annot_OnCreate(pSDKAnnot);
802
803 }
804
805 return pSDKAnnot;
806}
807
Tom Sepezeed467d2015-06-02 10:35:27 -0700808CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(IXFA_Widget* pPDFAnnot)
Bo Xufdc00a72014-10-28 23:03:33 -0700809{
810 if (!pPDFAnnot) return NULL;
811
812 CPDFSDK_Annot* pSDKAnnot = GetAnnotByXFAWidget(pPDFAnnot);
813 if (pSDKAnnot)
814 return pSDKAnnot;
815
816 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
817 ASSERT(pEnv);
818 CPDFSDK_AnnotHandlerMgr * pAnnotHandler= pEnv->GetAnnotHandlerMgr();
819
820 pSDKAnnot =NULL;
821
822 if(pAnnotHandler)
823 {
824 pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this);
825 }
826 if(!pSDKAnnot)
827 return NULL;
828
829 m_fxAnnotArray.Add(pSDKAnnot);
830
831 return pSDKAnnot;
832}
833
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700834CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary * pDict)
835{
836 if(pDict)
837 return this->AddAnnot(pDict->GetString("Subtype"),pDict);
838 return NULL;
839}
840
841CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(FX_LPCSTR lpSubType,CPDF_Dictionary * pDict)
842{
843 return NULL;
844}
845
846FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot)
847{
Bo Xufdc00a72014-10-28 23:03:33 -0700848 if (!pAnnot)
849 return FALSE;
850 CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage();
851 if (!pPage || (pPage->GetDocument()->GetDocType() != DOCTYPE_STATIC_XFA && pPage->GetDocument()->GetDocType() != DOCTYPE_DYNIMIC_XFA))
852 return FALSE;
853
854 int index = m_fxAnnotArray.Find(pAnnot);
855 m_fxAnnotArray.RemoveAt(index);
856 if (m_CaptureWidget == pAnnot)
857 m_CaptureWidget = NULL;
858
859 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700860}
861
862CPDF_Document* CPDFSDK_PageView::GetPDFDocument()
863{
864 if(m_page)
865 {
Bo Xufdc00a72014-10-28 23:03:33 -0700866 return m_page->GetDocument()->GetPDFDoc();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700867 }
868 return NULL;
869}
870
Bo Xufdc00a72014-10-28 23:03:33 -0700871CPDF_Page* CPDFSDK_PageView::GetPDFPage()
872{
873 if (m_page)
874 {
875 return m_page->GetPDFPage();
876 }
877
878 return NULL;
879}
880
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700881int CPDFSDK_PageView::CountAnnots()
882{
Bo Xufdc00a72014-10-28 23:03:33 -0700883 return m_fxAnnotArray.GetSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700884}
885
886CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(int nIndex)
887{
888 int nCount = m_fxAnnotArray.GetSize();
889 if ( nIndex < 0 || nIndex >= nCount )
890 {
891 return NULL;
892 }
893
894 return (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(nIndex);
895}
896
897CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary * pDict)
898{
899 int nCount = m_fxAnnotArray.GetSize();
900 for(int i=0; i<nCount; i++)
901 {
902 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
Lei Zhang64adf192015-06-05 15:50:32 -0700903 if (pDict == pAnnot->GetPDFAnnot()->GetAnnotDict())
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700904 return pAnnot;
905 }
906 return NULL;
907}
Tom Sepezeed467d2015-06-02 10:35:27 -0700908CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(IXFA_Widget* hWidget)
Bo Xufdc00a72014-10-28 23:03:33 -0700909{
910 if (hWidget == NULL)
911 return NULL;
912 int annotCount = m_fxAnnotArray.GetSize();
913
914 for(int i = 0; i < annotCount; i++)
915 {
916 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
917 if(pAnnot->GetXFAWidget() == hWidget)
918 return pAnnot;
919 }
920 return NULL;
921}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700922
923FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point & point, FX_UINT nFlag)
924{
925 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
926 ASSERT(pEnv);
927 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
928 if(!pFXAnnot)
929 {
930 KillFocusAnnot(nFlag);
931 }
932 else
933 {
934 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
935 ASSERT(pAnnotHandlerMgr);
936
937 FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnLButtonDown(this, pFXAnnot, nFlag,point);
938 if(bRet)
939 {
940 SetFocusAnnot(pFXAnnot);
941 }
942 return bRet;
943 }
944 return FALSE;
945}
946
Bo Xufdc00a72014-10-28 23:03:33 -0700947FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CPDF_Point & point, FX_UINT nFlag)
948{
949 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
950 ASSERT(pEnv);
951 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
952 ASSERT(pAnnotHandlerMgr);
953
954 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
955
956 if (pFXAnnot == NULL)
957 return FALSE;
958
959 FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnRButtonDown(this, pFXAnnot, nFlag,point);
960 if (bRet)
961 {
962 SetFocusAnnot(pFXAnnot);
963 }
964 return TRUE;
965}
966
967FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CPDF_Point & point, FX_UINT nFlag)
968{
969 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
970 ASSERT(pEnv);
971 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
972 ASSERT(pAnnotHandlerMgr);
973
974 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
975
976 if (pFXAnnot == NULL)
977 return FALSE;
978
979 FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnRButtonUp(this, pFXAnnot, nFlag,point);
980 if (bRet)
981 {
982 SetFocusAnnot(pFXAnnot);
983 }
984 return TRUE;
985}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700986
987FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CPDF_Point & point, FX_UINT nFlag)
988{
989 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
990 ASSERT(pEnv);
991 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
992 ASSERT(pAnnotHandlerMgr);
993 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
994 CPDFSDK_Annot* pFocusAnnot = GetFocusAnnot();
995 FX_BOOL bRet = FALSE;
996 if(pFocusAnnot && pFocusAnnot != pFXAnnot)
997 {
998 //Last focus Annot gets a chance to handle the event.
999 bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFocusAnnot, nFlag,point);
1000 }
1001 if(pFXAnnot && !bRet)
1002 {
1003 bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFXAnnot, nFlag,point);
1004 return bRet;
1005 }
1006 return bRet;
1007}
1008
1009FX_BOOL CPDFSDK_PageView::OnMouseMove(const CPDF_Point & point, int nFlag)
1010{
1011
1012 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1013 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1014 ASSERT(pAnnotHandlerMgr);
1015 if(CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y))
1016 {
1017 if(m_CaptureWidget && m_CaptureWidget != pFXAnnot)
1018 {
1019 m_bExitWidget = TRUE;
1020 m_bEnterWidget = FALSE;
1021 pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag);
1022 }
1023 m_CaptureWidget = (CPDFSDK_Widget*)pFXAnnot;
1024 m_bOnWidget = TRUE;
1025 if(!m_bEnterWidget)
1026 {
1027 m_bEnterWidget = TRUE;
1028 m_bExitWidget = FALSE;
1029 pAnnotHandlerMgr->Annot_OnMouseEnter(this, pFXAnnot,nFlag);
1030 }
1031 pAnnotHandlerMgr->Annot_OnMouseMove(this, pFXAnnot, nFlag, point);
1032 return TRUE;
1033 }
1034 else
1035 {
1036 if(m_bOnWidget)
1037 {
1038 m_bOnWidget = FALSE;
1039 m_bExitWidget = TRUE;
1040 m_bEnterWidget = FALSE;
1041 if(m_CaptureWidget)
1042 {
1043 pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag);
1044 m_CaptureWidget = NULL;
1045 }
1046 }
1047 return FALSE;
1048 }
1049
1050 return FALSE;;
1051}
1052
1053FX_BOOL CPDFSDK_PageView::OnMouseWheel(double deltaX, double deltaY,const CPDF_Point& point, int nFlag)
1054{
1055 if(CPDFSDK_Annot* pAnnot = GetFXWidgetAtPoint(point.x, point.y))
1056 {
1057 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1058 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1059 ASSERT(pAnnotHandlerMgr);
1060 return pAnnotHandlerMgr->Annot_OnMouseWheel(this, pAnnot, nFlag, (int)deltaY, point);
1061 }
1062 return FALSE;
1063
1064}
1065
1066FX_BOOL CPDFSDK_PageView::OnChar(int nChar, FX_UINT nFlag)
1067{
1068 if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
1069 {
1070 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1071 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1072 ASSERT(pAnnotHandlerMgr);
1073 return pAnnotHandlerMgr->Annot_OnChar(pAnnot, nChar, nFlag);
1074 }
1075
1076 return FALSE;
1077}
1078
1079FX_BOOL CPDFSDK_PageView::OnKeyDown(int nKeyCode, int nFlag)
1080{
1081 if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
1082 {
1083 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1084 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1085 ASSERT(pAnnotHandlerMgr);
1086 return pAnnotHandlerMgr->Annot_OnKeyDown(pAnnot, nKeyCode, nFlag);
1087 }
1088 return FALSE;
1089}
1090
1091FX_BOOL CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag)
1092{
1093// if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
1094// {
1095// CFFL_IFormFiller* pIFormFiller = g_pFormFillApp->GetIFormFiller();
1096// return pIFormFiller->OnKeyUp(pAnnot, nKeyCode, nFlag);
1097// }
1098 return FALSE;
1099}
1100
1101extern void CheckUnSupportAnnot(CPDF_Document * pDoc, CPDF_Annot* pPDFAnnot);
1102
1103void CPDFSDK_PageView::LoadFXAnnots()
1104{
Bo Xufdc00a72014-10-28 23:03:33 -07001105 ASSERT(m_page != NULL);
1106
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001107 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
Bo Xufdc00a72014-10-28 23:03:33 -07001108 ASSERT(pEnv != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001109
Bo Xufdc00a72014-10-28 23:03:33 -07001110 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1111 ASSERT(pAnnotHandlerMgr != NULL);
1112
unknown636ad3b2014-10-29 19:37:24 +08001113 SetLock(TRUE);
1114 m_page->AddRef();
Bo Xufdc00a72014-10-28 23:03:33 -07001115 if (m_pSDKDoc->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001116 {
Bo Xufdc00a72014-10-28 23:03:33 -07001117 IXFA_PageView* pageView = NULL;
1118 pageView = m_page->GetXFAPageView();
1119 ASSERT(pageView != NULL);
1120
Bo Xufdc00a72014-10-28 23:03:33 -07001121 IXFA_WidgetIterator* pWidgetHander = pageView->CreateWidgetIterator(XFA_TRAVERSEWAY_Form, XFA_WIDGETFILTER_Visible|XFA_WIDGETFILTER_Viewable|XFA_WIDGETFILTER_AllType);
1122 if (!pWidgetHander)
unknown636ad3b2014-10-29 19:37:24 +08001123 {
1124 m_page->Release();
1125 SetLock(FALSE);
Bo Xufdc00a72014-10-28 23:03:33 -07001126 return;
unknown636ad3b2014-10-29 19:37:24 +08001127 }
Bo Xufdc00a72014-10-28 23:03:33 -07001128
Tom Sepezeed467d2015-06-02 10:35:27 -07001129 IXFA_Widget* pXFAAnnot = pWidgetHander->MoveToNext();
Bo Xufdc00a72014-10-28 23:03:33 -07001130 while (pXFAAnnot) {
1131 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pXFAAnnot, this);
1132 if(!pAnnot) {
1133 pXFAAnnot = pWidgetHander->MoveToNext();
1134 continue;
1135 }
1136 m_fxAnnotArray.Add(pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001137
Bo Xufdc00a72014-10-28 23:03:33 -07001138 pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001139
Bo Xufdc00a72014-10-28 23:03:33 -07001140 pXFAAnnot = pWidgetHander->MoveToNext();
Bo Xufacd0152014-09-24 10:49:52 -07001141
Bo Xufdc00a72014-10-28 23:03:33 -07001142 }
1143
1144 pWidgetHander->Release();
1145 }
1146 else
1147 {
1148 CPDF_Page* pPage = m_page->GetPDFPage();
1149 ASSERT(pPage != NULL);
1150
1151 FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled();
1152 //Disable the default AP construction.
1153 CPDF_InterForm::EnableUpdateAP(FALSE);
1154 m_pAnnotList = new CPDF_AnnotList(pPage);
1155 CPDF_InterForm::EnableUpdateAP(enableAPUpdate);
1156
1157 int nCount = m_pAnnotList->Count();
1158 for(int i=0; i<nCount; i++)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001159 {
Bo Xufdc00a72014-10-28 23:03:33 -07001160 CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i);
1161 CPDF_Document * pDoc = this->GetPDFDocument();
1162
1163 CheckUnSupportAnnot(pDoc, pPDFAnnot);
1164
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001165 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this);
1166 if(!pAnnot)
1167 continue;
1168 m_fxAnnotArray.Add(pAnnot);
1169
1170 pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
1171 }
1172
1173 }
unknown636ad3b2014-10-29 19:37:24 +08001174 m_page->Release();
1175 SetLock(FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001176}
1177
1178void CPDFSDK_PageView::UpdateRects(CFX_RectArray& rects)
1179{
1180 for(int i=0; i<rects.GetSize(); i++)
1181 {
1182 CPDF_Rect rc = rects.GetAt(i);
1183 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1184 pEnv->FFI_Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom);
1185 }
1186}
1187
1188void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot)
1189{
1190 CPDF_Rect rcWindow;
1191
1192 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1193// CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr();
1194
1195 rcWindow = pAnnot->GetRect();//pAnnotHandler->Annot_OnGetViewBBox(this,pAnnot);
1196 pEnv->FFI_Invalidate(m_page, rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom);
1197
1198}
1199
1200int CPDFSDK_PageView::GetPageIndex()
1201{
1202 if(m_page)
1203 {
Bo Xufdc00a72014-10-28 23:03:33 -07001204 CPDF_Dictionary* pDic = m_page->GetPDFPage()->m_pFormDict;
1205 CPDFXFA_Document* pDoc = m_pSDKDoc->GetDocument();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001206 if(pDoc && pDic)
1207 {
Bo Xufdc00a72014-10-28 23:03:33 -07001208 return pDoc->GetPDFDoc()->GetPageIndex(pDic->GetObjNum());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001209 }
1210 }
1211 return -1;
1212}
1213
1214FX_BOOL CPDFSDK_PageView::IsValidAnnot(FX_LPVOID p)
1215{
1216 if (p == NULL) return FALSE;
1217 int iCount = m_pAnnotList->Count();
1218 for (int i = 0; i < iCount; i++)
1219 {
1220 if (m_pAnnotList->GetAt(i) == p)
1221 return TRUE;
1222 }
1223 return FALSE;
1224}
1225
1226
1227CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot()
1228{
1229 CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot();
1230 if(!pFocusAnnot)
1231 return NULL;
1232
1233 for(int i=0; i<m_fxAnnotArray.GetSize(); i++)
1234 {
1235 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
1236 if(pAnnot == pFocusAnnot)
1237 return pAnnot;
1238 }
1239 return NULL;
1240}
1241