blob: d7e4e3d8a8c26158e9b9ac1493537f75d0940856 [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
7#ifndef _FPDFSDK_MGR_H
8#define _FPDFSDK_MGR_H
9
10#include "fsdk_common.h"
11#include "fsdk_define.h"
12#include "fx_systemhandler.h"
13#include "fsdk_baseannot.h"
14#include "fsdk_baseform.h"
15#include "fpdfformfill.h"
16#include "fsdk_annothandler.h"
17#include "fsdk_actionhandler.h"
18
19//cross platform keycode and events define.
20#include "fpdf_fwlevent.h"
21
22
23class CPDFSDK_Document;
24class CPDFSDK_PageView;
25class CPDFSDK_Annot;
26class CFFL_IFormFiller;
27class CPDFSDK_Widget;
28class IFX_SystemHandler;
29class CPDFSDK_ActionHandler;
30class CJS_RuntimeFactory;
31
32#include "javascript/IJavaScript.h"
33
Nico Weber5eb9f7b2014-07-18 09:14:35 -070034class CPDFDoc_Environment FX_FINAL
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070035{
36public:
37 CPDFDoc_Environment(CPDF_Document * pDoc);
38 ~CPDFDoc_Environment();
39
40 int RegAppHandle(FPDF_FORMFILLINFO* pFFinfo);//{ m_pInfo = pFFinfo; return TRUE;}
41
Nico Weber5eb9f7b2014-07-18 09:14:35 -070042 void FFI_Invalidate(FPDF_PAGE page, double left, double top, double right, double bottom)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070043 {
44 if (m_pInfo && m_pInfo->FFI_Invalidate)
45 {
46 m_pInfo->FFI_Invalidate(m_pInfo, page, left, top, right, bottom);
47 }
48 }
Nico Weber5eb9f7b2014-07-18 09:14:35 -070049 void FFI_OutputSelectedRect(FPDF_PAGE page, double left, double top, double right, double bottom)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070050 {
51 if (m_pInfo && m_pInfo->FFI_OutputSelectedRect)
52 {
53 m_pInfo->FFI_OutputSelectedRect(m_pInfo, page, left, top, right, bottom);
54 }
55 }
56
Nico Weber5eb9f7b2014-07-18 09:14:35 -070057 void FFI_SetCursor(int nCursorType)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070058 {
59 if (m_pInfo && m_pInfo->FFI_SetCursor)
60 {
61 m_pInfo->FFI_SetCursor(m_pInfo, nCursorType);
62 }
63 }
64
Nico Weber5eb9f7b2014-07-18 09:14:35 -070065 int FFI_SetTimer(int uElapse, TimerCallback lpTimerFunc)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070066 {
67 if (m_pInfo && m_pInfo->FFI_SetTimer)
68 {
69 return m_pInfo->FFI_SetTimer(m_pInfo, uElapse, lpTimerFunc);
70 }
71 return -1;
72 }
73
Nico Weber5eb9f7b2014-07-18 09:14:35 -070074 void FFI_KillTimer(int nTimerID)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070075 {
76 if (m_pInfo && m_pInfo->FFI_KillTimer)
77 {
78 m_pInfo->FFI_KillTimer(m_pInfo, nTimerID);
79 }
80 }
81 FX_SYSTEMTIME FFI_GetLocalTime()
82 {
83 FX_SYSTEMTIME fxtime;
84 if(m_pInfo && m_pInfo->FFI_GetLocalTime)
85 {
86 FPDF_SYSTEMTIME systime = m_pInfo->FFI_GetLocalTime(m_pInfo);
87 fxtime.wDay = systime.wDay;
88 fxtime.wDayOfWeek = systime.wDayOfWeek;
89 fxtime.wHour = systime.wHour;
90 fxtime.wMilliseconds = systime.wMilliseconds;
91 fxtime.wMinute = systime.wMinute;
92 fxtime.wMonth = systime.wMonth;
93 fxtime.wSecond = systime.wSecond;
94 fxtime.wYear = systime.wYear;
95 }
96 return fxtime;
97 }
98
Nico Weber5eb9f7b2014-07-18 09:14:35 -070099 void FFI_OnChange()
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700100 {
101 if(m_pInfo && m_pInfo->FFI_OnChange)
102 {
103 m_pInfo->FFI_OnChange(m_pInfo);
104 }
105 }
106
Nico Weber5eb9f7b2014-07-18 09:14:35 -0700107 FX_BOOL FFI_IsSHIFTKeyDown(FX_DWORD nFlag)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700108 {
109
110 return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0;
111 }
Nico Weber5eb9f7b2014-07-18 09:14:35 -0700112 FX_BOOL FFI_IsCTRLKeyDown(FX_DWORD nFlag)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700113 {
114
115 return (nFlag & FWL_EVENTFLAG_ControlKey) != 0;
116 }
Nico Weber5eb9f7b2014-07-18 09:14:35 -0700117 FX_BOOL FFI_IsALTKeyDown(FX_DWORD nFlag)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700118 {
119
120 return (nFlag & FWL_EVENTFLAG_AltKey) != 0;
121 }
Nico Weber5eb9f7b2014-07-18 09:14:35 -0700122 FX_BOOL FFI_IsINSERTKeyDown(FX_DWORD nFlag)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700123 {
124 return FALSE;
125 }
126
Nico Weber5eb9f7b2014-07-18 09:14:35 -0700127 int JS_appAlert(FX_LPCWSTR Msg, FX_LPCWSTR Title, FX_UINT Type, FX_UINT Icon)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700128 {
129 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert)
130 {
131 CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode();
132 CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode();
133 FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength());
134 FPDF_WIDESTRING pTitle = (FPDF_WIDESTRING)bsTitle.GetBuffer(bsTitle.GetLength());
135 int ret = m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, pMsg, pTitle, Type, Icon);
136 bsMsg.ReleaseBuffer();
137 bsTitle.ReleaseBuffer();
138 return ret;
139 }
140 return -1;
141 }
142
Nico Weber5eb9f7b2014-07-18 09:14:35 -0700143 int JS_appResponse(FX_LPCWSTR Question, FX_LPCWSTR Title, FX_LPCWSTR Default, FX_LPCWSTR cLabel, FPDF_BOOL bPassword, void* response, int length)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700144 {
145 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_response)
146 {
147 CFX_ByteString bsQuestion = CFX_WideString(Question).UTF16LE_Encode();
148 CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode();
149 CFX_ByteString bsDefault = CFX_WideString(Default).UTF16LE_Encode();
150 CFX_ByteString bsLabel = CFX_WideString(cLabel).UTF16LE_Encode();
151 FPDF_WIDESTRING pQuestion = (FPDF_WIDESTRING)bsQuestion.GetBuffer(bsQuestion.GetLength());
152 FPDF_WIDESTRING pTitle = (FPDF_WIDESTRING)bsTitle.GetBuffer(bsTitle.GetLength());
153 FPDF_WIDESTRING pDefault = (FPDF_WIDESTRING)bsDefault.GetBuffer(bsDefault.GetLength());
154 FPDF_WIDESTRING pLabel = (FPDF_WIDESTRING)bsLabel.GetBuffer(bsLabel.GetLength());
155 int ret = m_pInfo->m_pJsPlatform->app_response(m_pInfo->m_pJsPlatform, pQuestion, pTitle,
156 pDefault, pLabel, bPassword, response, length);
157 bsQuestion.ReleaseBuffer();
158 bsTitle.ReleaseBuffer();
159 bsDefault.ReleaseBuffer();
160 bsLabel.ReleaseBuffer();
161 return ret;
162 }
163 return -1;
164 }
165
Nico Weber5eb9f7b2014-07-18 09:14:35 -0700166 void JS_appBeep(int nType)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700167 {
168 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_beep)
169 {
170 m_pInfo->m_pJsPlatform->app_beep(m_pInfo->m_pJsPlatform, nType);
171 }
172 }
173
Nico Weber5eb9f7b2014-07-18 09:14:35 -0700174 CFX_WideString JS_fieldBrowse()
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700175 {
176 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Field_browse)
177 {
178 int nLen = m_pInfo->m_pJsPlatform->Field_browse(m_pInfo->m_pJsPlatform, NULL, 0);
179 if(nLen <= 0)
180 return L"";
181 char* pbuff = new char[nLen];
182 if(pbuff)
183 memset(pbuff, 0, nLen);
184 else
185 return L"";
186 nLen = m_pInfo->m_pJsPlatform->Field_browse(m_pInfo->m_pJsPlatform, pbuff, nLen);
187 CFX_ByteString bsRet = CFX_ByteString(pbuff, nLen);
188 CFX_WideString wsRet = CFX_WideString::FromLocal(bsRet);
189 delete[] pbuff;
190 return wsRet;
191 }
192 return L"";
193 }
194
195 CFX_WideString JS_docGetFilePath()
196 {
197 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_getFilePath)
198 {
199 int nLen = m_pInfo->m_pJsPlatform->Doc_getFilePath(m_pInfo->m_pJsPlatform, NULL, 0);
200 if(nLen <= 0)
201 return L"";
202 char* pbuff = new char[nLen];
203 if(pbuff)
204 memset(pbuff, 0, nLen);
205 else
206 return L"";
207 nLen = m_pInfo->m_pJsPlatform->Doc_getFilePath(m_pInfo->m_pJsPlatform, pbuff, nLen);
208 CFX_ByteString bsRet = CFX_ByteString(pbuff, nLen);
209 CFX_WideString wsRet = CFX_WideString::FromLocal(bsRet);
210 delete[] pbuff;
211 return wsRet;
212 }
213 return L"";
214 }
215
216 void JS_docSubmitForm(void* formData, int length, FX_LPCWSTR URL)
217 {
218 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_submitForm)
219 {
220 CFX_ByteString bsDestination = CFX_WideString(URL).UTF16LE_Encode();
221 FPDF_WIDESTRING pDestination = (FPDF_WIDESTRING)bsDestination.GetBuffer(bsDestination.GetLength());
222 m_pInfo->m_pJsPlatform->Doc_submitForm(m_pInfo->m_pJsPlatform, formData, length, pDestination);
223 bsDestination.ReleaseBuffer();
224 }
225 }
226
227 void JS_docmailForm(void* mailData, int length, FPDF_BOOL bUI,FX_LPCWSTR To, FX_LPCWSTR Subject, FX_LPCWSTR CC, FX_LPCWSTR BCC, FX_LPCWSTR Msg)
228 {
229 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_mail)
230 {
231 CFX_ByteString bsTo = CFX_WideString(To).UTF16LE_Encode();
232 CFX_ByteString bsCC = CFX_WideString(Subject).UTF16LE_Encode();
233 CFX_ByteString bsBcc = CFX_WideString(BCC).UTF16LE_Encode();
234 CFX_ByteString bsSubject = CFX_WideString(Subject).UTF16LE_Encode();
235 CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode();
236 FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(bsTo.GetLength());
237 FPDF_WIDESTRING pCC = (FPDF_WIDESTRING)bsCC.GetBuffer(bsCC.GetLength());
238 FPDF_WIDESTRING pBcc = (FPDF_WIDESTRING)bsBcc.GetBuffer(bsBcc.GetLength());
239 FPDF_WIDESTRING pSubject = (FPDF_WIDESTRING)bsSubject.GetBuffer(bsSubject.GetLength());
240 FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength());
241 m_pInfo->m_pJsPlatform->Doc_mail(m_pInfo->m_pJsPlatform, mailData, length, bUI, pTo, pSubject,
242 pCC, pBcc, pMsg);
243 bsTo.ReleaseBuffer();
244 bsCC.ReleaseBuffer();
245 bsBcc.ReleaseBuffer();
246 bsSubject.ReleaseBuffer();
247 bsMsg.ReleaseBuffer();
248 }
249 }
250 CFX_WideString JS_appbrowseForDoc(FPDF_BOOL bSave, FX_LPCWSTR cFilenameInit)
251 {
252 //to do....
253 return L"";
254// if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_browseForDoc)
255// {
256// CFX_ByteString bsFilenameInit = CFX_WideString(cFilenameInit).UTF16LE_Encode();
257// FPDF_WIDESTRING pFileNameInit = (FPDF_WIDESTRING)bsFilenameInit.GetBuffer(bsFilenameInit.GetLength());
258//
259// m_pInfo->m_pJsPlatform->app_browseForDoc(m_pInfo->m_pJsPlatform, pFileNameInit);
260// bsFilenameInit.ReleaseBuffer();
261// }
262 }
263
264 void JS_docprint(FPDF_BOOL bUI , int nStart, int nEnd, FPDF_BOOL bSilent ,FPDF_BOOL bShrinkToFit,FPDF_BOOL bPrintAsImage ,FPDF_BOOL bReverse ,FPDF_BOOL bAnnotations)
265 {
266 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_print)
267 {
268 m_pInfo->m_pJsPlatform->Doc_print(m_pInfo->m_pJsPlatform, bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage, bReverse, bAnnotations);
269 }
270 }
271 void JS_docgotoPage(int nPageNum)
272 {
273 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_gotoPage)
274 {
275 m_pInfo->m_pJsPlatform->Doc_gotoPage(m_pInfo->m_pJsPlatform, nPageNum);
276 }
277 }
278
Nico Weber5eb9f7b2014-07-18 09:14:35 -0700279 FPDF_PAGE FFI_GetPage(FPDF_DOCUMENT document,int nPageIndex)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700280 {
281 if(m_pInfo && m_pInfo->FFI_GetPage)
282 {
283 return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex);
284 }
285 return NULL;
286 }
287
Nico Weber5eb9f7b2014-07-18 09:14:35 -0700288 FPDF_PAGE FFI_GetCurrentPage(FPDF_DOCUMENT document)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700289 {
290 if(m_pInfo && m_pInfo->FFI_GetCurrentPage)
291 {
292 return m_pInfo->FFI_GetCurrentPage(m_pInfo, document);
293 }
294 return NULL;
295 }
296
297 int FFI_GetRotation(FPDF_PAGE page)
298 {
299 if(m_pInfo && m_pInfo->FFI_GetRotation)
300 {
301 return m_pInfo->FFI_GetRotation(m_pInfo, page);
302 }
303 return 0;
304 }
305 void FFI_ExecuteNamedAction(FX_LPCSTR namedAction)
306 {
307 if(m_pInfo && m_pInfo->FFI_ExecuteNamedAction)
308 {
309 m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction);
310 }
311 }
312 void FFI_OnSetFieldInputFocus(void* field,FPDF_WIDESTRING focusText, FPDF_DWORD nTextLen, FX_BOOL bFocus)
313 {
314 if(m_pInfo && m_pInfo->FFI_SetTextFieldFocus)
315 {
316 m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus);
317 }
318 }
319
320 void FFI_DoURIAction(FX_LPCSTR bsURI)
321 {
322 if(m_pInfo && m_pInfo->FFI_DoURIAction)
323 {
324 m_pInfo->FFI_DoURIAction(m_pInfo, bsURI);
325 }
326 }
327
328 void FFI_DoGoToAction(int nPageIndex, int zoomMode, float* fPosArray, int sizeOfArray)
329 {
330 if(m_pInfo && m_pInfo->FFI_DoGoToAction)
331 {
332 m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray, sizeOfArray);
333 }
334 }
335
336public:
337 FX_BOOL IsJSInitiated();
338
339public:
340 void SetCurrentDoc(CPDFSDK_Document* pFXDoc) {m_pSDKDoc = pFXDoc;}
341 CPDFSDK_Document* GetCurrentDoc();
342 CPDF_Document* GetPDFDocument() {return m_pPDFDoc;}
343// CPDFSDK_Document* GetDocument(int nIndex);
344// int CountDocuments() {return m_docMap.GetCount();}
345
346 CPDFSDK_Document* OpenDocument(CFX_WideString &fileName);
347 CPDFSDK_Document* OpenMemPDFDoc(CPDF_Document* pNewDoc, CFX_WideString &fileName);
348 FX_BOOL OpenURL(CFX_WideString &filePath);
349
350
351 CFX_ByteString GetAppName() {return "";}
352
353 CFFL_IFormFiller* GetIFormFiller();
354 IFX_SystemHandler* GetSysHandler() {return m_pSysHandler;}
355
356public:
357 CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr();
358 IFXJS_Runtime* GetJSRuntime();
359 CPDFSDK_ActionHandler* GetActionHander();
360private:
361 CPDFSDK_AnnotHandlerMgr* m_pAnnotHandlerMgr;
362 CPDFSDK_ActionHandler* m_pActionHandler;
363 IFXJS_Runtime* m_pJSRuntime;
364public:
365 FPDF_FORMFILLINFO* GetFormFillInfo() {return m_pInfo;}
366private:
367 FPDF_FORMFILLINFO* m_pInfo;
368// CFX_MapPtrTemplate<CPDF_Document*, CPDFSDK_Document*> m_docMap;
369 CPDFSDK_Document* m_pSDKDoc;
370 CPDF_Document* m_pPDFDoc;
371
372 CFFL_IFormFiller* m_pIFormFiller;
373 IFX_SystemHandler* m_pSysHandler;
374
375public:
376 CJS_RuntimeFactory* m_pJSRuntimeFactory;
377};
378
379
380
381// class CFX_App
382// {
383// public:
384// CFX_App():m_pCurDoc(NULL) {}
385// void SetAt(CPDF_Document* pPDFDoc, CPDFSDK_Document* pFXDoc);
386// CPDFSDK_Document* GetAt(CPDF_Document* pPDFDoc);
387// public:
388// void SetCurrentDocument(CPDFSDK_Document* pFXDoc) {m_pCurDoc = pFXDoc;}
389// CPDFSDK_Document* GetCurrentDocument() {return m_pCurDoc;}
390// private:
391// CFX_MapPtrTemplate<CPDF_Document*, CPDFSDK_Document*> m_docArray;
392// CPDFSDK_Document* m_pCurDoc;
393// };
394class CPDFSDK_InterForm;
395class CPDFSDK_Document
396{
397public:
398 CPDFSDK_Document(CPDF_Document* pDoc, CPDFDoc_Environment* pEnv);
399 ~CPDFSDK_Document();
400public:
401 CPDFSDK_InterForm* GetInterForm() ;
402 CPDF_Document* GetDocument() {return m_pDoc;}
403
404public:
405 void InitPageView();
406 void AddPageView(CPDF_Page* pPDFPage, CPDFSDK_PageView* pPageView);
407 CPDFSDK_PageView* GetPageView(CPDF_Page* pPDFPage, FX_BOOL ReNew = TRUE);
408 CPDFSDK_PageView* GetPageView(int nIndex);
409 CPDFSDK_PageView* GetCurrentView();
410 void ReMovePageView(CPDF_Page* pPDFPage);
411 void UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot);
412
413 CPDFSDK_Annot* GetFocusAnnot();//{return NULL;}
414
415 IFXJS_Runtime * GetJsRuntime();
416
417 FX_BOOL SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag = 0);//{return FALSE;}
418 FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0);
419
420 FX_BOOL ExtractPages(const CFX_WordArray &arrExtraPages, CPDF_Document* pDstDoc);
421 FX_BOOL InsertPages(int nInsertAt, const CPDF_Document* pSrcDoc, const CFX_WordArray &arrSrcPages);
422 FX_BOOL DeletePages(int nStart, int nCount);
423 FX_BOOL ReplacePages(int nPage, const CPDF_Document* pSrcDoc, const CFX_WordArray &arrSrcPages);
424
425 void OnCloseDocument();
426
427 int GetPageCount() {return m_pDoc->GetPageCount();}
428 FX_BOOL GetPermissions(int nFlag);
429 FX_BOOL GetChangeMark() {return m_bChangeMask;}
430 void SetChangeMark() {m_bChangeMask = TRUE;}
431 void ClearChangeMark() {m_bChangeMask= FALSE;}
432// FX_BOOL GetChangeMark(){return FALSE;}//IsAnnotModified()||IsFormModified() || IsWidgetModified()|| m_nChangeMark>0 ;}
433// void ClearChangeMark(){}
434 CFX_WideString GetPath() ;
435 CPDF_Page* GetPage(int nIndex);
436 CPDFDoc_Environment * GetEnv() {return m_pEnv; }
437 void ProcJavascriptFun();
438 FX_BOOL ProcOpenAction();
439 CPDF_OCContext* GetOCContext();
440private:
441 //CFX_ArrayTemplate<CPDFSDK_PageView*> m_pageArray;
442 CFX_MapPtrTemplate<CPDF_Page*, CPDFSDK_PageView*> m_pageMap;
443 CPDF_Document* m_pDoc;
444
445 CPDFSDK_InterForm* m_pInterForm;
446 CPDFSDK_Annot* m_pFocusAnnot;
447 CPDFDoc_Environment * m_pEnv;
448 CPDF_OCContext * m_pOccontent;
449 FX_BOOL m_bChangeMask;
450};
451
Nico Weber5eb9f7b2014-07-18 09:14:35 -0700452class CPDFSDK_PageView FX_FINAL
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700453{
454public:
455 CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,CPDF_Page* page);
456 ~CPDFSDK_PageView();
457public:
Nico Weber5eb9f7b2014-07-18 09:14:35 -0700458 void PageView_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,CPDF_RenderOptions* pOptions) ;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700459public:
460 CPDF_Annot* GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
461 CPDFSDK_Annot* GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
462 CPDF_Annot* GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
463 CPDFSDK_Annot* GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
464 CPDFSDK_Annot* GetFocusAnnot() ;
465 void SetFocusAnnot(CPDFSDK_Annot* pSDKAnnot,FX_UINT nFlag = 0) {m_pSDKDoc->SetFocusAnnot(pSDKAnnot, nFlag);}
466 FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0) {return m_pSDKDoc->KillFocusAnnot(nFlag);}
467 FX_BOOL Annot_HasAppearance(CPDF_Annot* pAnnot);
468
469 CPDFSDK_Annot* AddAnnot(CPDF_Dictionary * pDict);
470 CPDFSDK_Annot* AddAnnot(FX_LPCSTR lpSubType,CPDF_Dictionary * pDict);
471 CPDFSDK_Annot* AddAnnot(CPDF_Annot * pPDFAnnot);
472 FX_BOOL DeleteAnnot(CPDFSDK_Annot* pAnnot);
473
474 int CountAnnots();
475 CPDFSDK_Annot* GetAnnot(int nIndex);
476 CPDFSDK_Annot* GetAnnotByDict(CPDF_Dictionary * pDict);
477 CPDF_Page* GetPDFPage(){return m_page;}
478 CPDF_Document* GetPDFDocument();
479 CPDFSDK_Document* GetSDKDocument() {return m_pSDKDoc;}
480public:
Nico Weber5eb9f7b2014-07-18 09:14:35 -0700481 FX_BOOL OnLButtonDown(const CPDF_Point & point, FX_UINT nFlag);
482 FX_BOOL OnLButtonUp(const CPDF_Point & point, FX_UINT nFlag);
483 FX_BOOL OnChar(int nChar, FX_UINT nFlag);
484 FX_BOOL OnKeyDown(int nKeyCode, int nFlag);
485 FX_BOOL OnKeyUp(int nKeyCode, int nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700486
Nico Weber5eb9f7b2014-07-18 09:14:35 -0700487 FX_BOOL OnMouseMove(const CPDF_Point & point, int nFlag);
488 FX_BOOL OnMouseWheel(double deltaX, double deltaY,const CPDF_Point& point, int nFlag);
489 FX_BOOL IsValidAnnot(FX_LPVOID p);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700490public:
Nico Weber5eb9f7b2014-07-18 09:14:35 -0700491 void GetCurrentMatrix(CPDF_Matrix& matrix) {matrix = m_curMatrix;}
492 void UpdateRects(CFX_RectArray& rects);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700493 void UpdateView(CPDFSDK_Annot* pAnnot);
494 CFX_PtrArray* GetAnnotList(){ return &m_fxAnnotArray; }
495
496public:
Nico Weber5eb9f7b2014-07-18 09:14:35 -0700497 int GetPageIndex();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700498 void LoadFXAnnots();
499private:
500 CPDF_Matrix m_curMatrix;
501
502private:
503 void PageView_OnHighlightFormFields(CFX_RenderDevice* pDevice, CPDFSDK_Widget* pWidget);
504
505private:
506 CPDF_Page* m_page;
507 CPDF_AnnotList* m_pAnnotList;
508
509 //CPDFSDK_Annot* m_pFocusAnnot;
510 CFX_PtrArray m_fxAnnotArray;
511
512 CPDFSDK_Document* m_pSDKDoc;
513private:
514 CPDFSDK_Widget* m_CaptureWidget;
515 FX_BOOL m_bEnterWidget;
516 FX_BOOL m_bExitWidget;
517 FX_BOOL m_bOnWidget;
518public:
519 void SetValid(FX_BOOL bValid) {m_bValid = bValid;}
520 FX_BOOL IsValid() {return m_bValid;}
521private:
522 FX_BOOL m_bValid;
523};
524
525
526template<class TYPE>
527class CGW_ArrayTemplate : public CFX_ArrayTemplate<TYPE>
528{
529public:
530 CGW_ArrayTemplate(){}
531 virtual ~CGW_ArrayTemplate(){}
532
533 typedef int (*LP_COMPARE)(TYPE p1, TYPE p2);
534
535 void Sort(LP_COMPARE pCompare, FX_BOOL bAscent = TRUE)
536 {
537 int nSize = this->GetSize();
538 QuickSort(0, nSize -1, bAscent, pCompare);
539 }
540
541private:
542 void QuickSort(FX_UINT nStartPos, FX_UINT nStopPos, FX_BOOL bAscend, LP_COMPARE pCompare)
543 {
544 if (nStartPos >= nStopPos) return;
545
546 if ((nStopPos - nStartPos) == 1)
547 {
548 TYPE Value1 = this->GetAt(nStartPos);
549 TYPE Value2 = this->GetAt(nStopPos);
550
551 int iGreate = (*pCompare)(Value1, Value2);
552 if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0))
553 {
554 this->SetAt(nStartPos, Value2);
555 this->SetAt(nStopPos, Value1);
556 }
557 return;
558 }
559
Bo Xu9a52eb02014-06-24 11:37:49 -0700560 FX_UINT m = nStartPos + (nStopPos - nStartPos) / 2;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700561 FX_UINT i = nStartPos;
562
563 TYPE Value = this->GetAt(m);
564
565 while (i < m)
566 {
567 TYPE temp = this->GetAt(i);
568
569 int iGreate = (*pCompare)(temp, Value);
570 if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0))
571 {
572 this->InsertAt(m+1, temp);
573 this->RemoveAt(i);
574 m--;
575 }
576 else
577 {
578 i++;
579 }
580 }
581
582 FX_UINT j = nStopPos;
583
584 while (j > m)
585 {
586 TYPE temp = this->GetAt(j);
587
588 int iGreate = (*pCompare)(temp, Value);
589 if ((bAscend && iGreate < 0) || (!bAscend && iGreate > 0))
590 {
591 this->RemoveAt(j);
592 this->InsertAt(m, temp);
593 m++;
594 }
595 else
596 {
597 j--;
598 }
599 }
600
601 if (nStartPos < m) QuickSort(nStartPos, m, bAscend, pCompare);
602 if (nStopPos > m) QuickSort(m, nStopPos, bAscend, pCompare);
603 }
604};
605
606
607#endif //_FPDFSDK_MGR_H
608