blob: 29da5030a04b070b3ab20ad9e99e7ee3033b5301 [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.
Tom Sepezc6ab1722015-02-05 15:27:25 -08004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Tom Sepez19922bb2015-05-28 13:23:12 -07007#ifndef FPDFSDK_INCLUDE_FSDK_MGR_H_
8#define FPDFSDK_INCLUDE_FSDK_MGR_H_
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07009
Lei Zhang606346f2015-06-19 18:11:07 -070010#include <map>
11
Lei Zhange5b0bd12015-06-19 17:15:41 -070012#include "../../core/include/fpdftext/fpdf_text.h"
Tom Sepez1ed8a212015-05-11 15:25:39 -070013#include "../../public/fpdf_formfill.h"
14#include "../../public/fpdf_fwlevent.h" // cross platform keycode and events define.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070015#include "fsdk_common.h"
16#include "fsdk_define.h"
17#include "fx_systemhandler.h"
Bo Xufdc00a72014-10-28 23:03:33 -070018#include "fpdfxfa/fpdfxfa_doc.h"
19#include "fpdfxfa/fpdfxfa_page.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070020#include "fsdk_baseannot.h"
21#include "fsdk_baseform.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070022#include "fsdk_annothandler.h"
23#include "fsdk_actionhandler.h"
Lei Zhange5b0bd12015-06-19 17:15:41 -070024#include "javascript/IJavaScript.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070025
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070026class CPDFSDK_Document;
27class CPDFSDK_PageView;
28class CPDFSDK_Annot;
29class CFFL_IFormFiller;
30class CPDFSDK_Widget;
31class IFX_SystemHandler;
32class CPDFSDK_ActionHandler;
33class CJS_RuntimeFactory;
34
Tom Sepezb1161362015-06-09 11:29:12 -070035class CPDFDoc_Environment final
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070036{
37public:
Bo Xufdc00a72014-10-28 23:03:33 -070038 CPDFDoc_Environment(CPDFXFA_Document * pDoc);
Lei Zhang568aff52015-06-19 14:58:28 -070039 virtual ~CPDFDoc_Environment();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070040
Tom Sepez2f3dfef2015-03-02 15:35:26 -080041 int RegAppHandle(FPDF_FORMFILLINFO* pFFinfo);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070042
Bo Xufdc00a72014-10-28 23:03:33 -070043 virtual void Release()
44 {
45 if (m_pInfo && m_pInfo->Release)
46 m_pInfo->Release(m_pInfo);
47 delete this;
48 }
Nico Weber5eb9f7b2014-07-18 09:14:35 -070049 void FFI_Invalidate(FPDF_PAGE page, double left, double top, double right, double bottom)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070050 {
Tom Sepezc6ab1722015-02-05 15:27:25 -080051 if (m_pInfo && m_pInfo->FFI_Invalidate)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070052 {
53 m_pInfo->FFI_Invalidate(m_pInfo, page, left, top, right, bottom);
54 }
55 }
Nico Weber5eb9f7b2014-07-18 09:14:35 -070056 void FFI_OutputSelectedRect(FPDF_PAGE page, double left, double top, double right, double bottom)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070057 {
Tom Sepezc6ab1722015-02-05 15:27:25 -080058 if (m_pInfo && m_pInfo->FFI_OutputSelectedRect)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070059 {
60 m_pInfo->FFI_OutputSelectedRect(m_pInfo, page, left, top, right, bottom);
61 }
62 }
63
Nico Weber5eb9f7b2014-07-18 09:14:35 -070064 void FFI_SetCursor(int nCursorType)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070065 {
Tom Sepezc6ab1722015-02-05 15:27:25 -080066 if (m_pInfo && m_pInfo->FFI_SetCursor)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070067 {
68 m_pInfo->FFI_SetCursor(m_pInfo, nCursorType);
69 }
70 }
71
Nico Weber5eb9f7b2014-07-18 09:14:35 -070072 int FFI_SetTimer(int uElapse, TimerCallback lpTimerFunc)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070073 {
Tom Sepezc6ab1722015-02-05 15:27:25 -080074 if (m_pInfo && m_pInfo->FFI_SetTimer)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070075 {
76 return m_pInfo->FFI_SetTimer(m_pInfo, uElapse, lpTimerFunc);
77 }
78 return -1;
79 }
Tom Sepezc6ab1722015-02-05 15:27:25 -080080
Nico Weber5eb9f7b2014-07-18 09:14:35 -070081 void FFI_KillTimer(int nTimerID)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070082 {
Tom Sepezc6ab1722015-02-05 15:27:25 -080083 if (m_pInfo && m_pInfo->FFI_KillTimer)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070084 {
85 m_pInfo->FFI_KillTimer(m_pInfo, nTimerID);
86 }
87 }
88 FX_SYSTEMTIME FFI_GetLocalTime()
89 {
90 FX_SYSTEMTIME fxtime;
91 if(m_pInfo && m_pInfo->FFI_GetLocalTime)
92 {
93 FPDF_SYSTEMTIME systime = m_pInfo->FFI_GetLocalTime(m_pInfo);
94 fxtime.wDay = systime.wDay;
95 fxtime.wDayOfWeek = systime.wDayOfWeek;
96 fxtime.wHour = systime.wHour;
97 fxtime.wMilliseconds = systime.wMilliseconds;
98 fxtime.wMinute = systime.wMinute;
99 fxtime.wMonth = systime.wMonth;
100 fxtime.wSecond = systime.wSecond;
101 fxtime.wYear = systime.wYear;
102 }
103 return fxtime;
104 }
105
Nico Weber5eb9f7b2014-07-18 09:14:35 -0700106 void FFI_OnChange()
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700107 {
108 if(m_pInfo && m_pInfo->FFI_OnChange)
109 {
110 m_pInfo->FFI_OnChange(m_pInfo);
111 }
112 }
113
Nico Weber5eb9f7b2014-07-18 09:14:35 -0700114 FX_BOOL FFI_IsSHIFTKeyDown(FX_DWORD nFlag)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700115 {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800116
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700117 return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0;
118 }
Nico Weber5eb9f7b2014-07-18 09:14:35 -0700119 FX_BOOL FFI_IsCTRLKeyDown(FX_DWORD nFlag)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700120 {
121
122 return (nFlag & FWL_EVENTFLAG_ControlKey) != 0;
123 }
Nico Weber5eb9f7b2014-07-18 09:14:35 -0700124 FX_BOOL FFI_IsALTKeyDown(FX_DWORD nFlag)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700125 {
126
127 return (nFlag & FWL_EVENTFLAG_AltKey) != 0;
128 }
Nico Weber5eb9f7b2014-07-18 09:14:35 -0700129 FX_BOOL FFI_IsINSERTKeyDown(FX_DWORD nFlag)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700130 {
131 return FALSE;
132 }
133
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700134 int JS_appAlert(const FX_WCHAR* Msg, const FX_WCHAR* Title, FX_UINT Type, FX_UINT Icon)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700135 {
136 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert)
137 {
138 CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode();
139 CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode();
140 FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength());
141 FPDF_WIDESTRING pTitle = (FPDF_WIDESTRING)bsTitle.GetBuffer(bsTitle.GetLength());
142 int ret = m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, pMsg, pTitle, Type, Icon);
143 bsMsg.ReleaseBuffer();
144 bsTitle.ReleaseBuffer();
145 return ret;
146 }
147 return -1;
148 }
149
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700150 int JS_appResponse(const FX_WCHAR* Question, const FX_WCHAR* Title, const FX_WCHAR* Default, const FX_WCHAR* cLabel, FPDF_BOOL bPassword, void* response, int length)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700151 {
152 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_response)
153 {
154 CFX_ByteString bsQuestion = CFX_WideString(Question).UTF16LE_Encode();
155 CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode();
156 CFX_ByteString bsDefault = CFX_WideString(Default).UTF16LE_Encode();
157 CFX_ByteString bsLabel = CFX_WideString(cLabel).UTF16LE_Encode();
158 FPDF_WIDESTRING pQuestion = (FPDF_WIDESTRING)bsQuestion.GetBuffer(bsQuestion.GetLength());
159 FPDF_WIDESTRING pTitle = (FPDF_WIDESTRING)bsTitle.GetBuffer(bsTitle.GetLength());
160 FPDF_WIDESTRING pDefault = (FPDF_WIDESTRING)bsDefault.GetBuffer(bsDefault.GetLength());
161 FPDF_WIDESTRING pLabel = (FPDF_WIDESTRING)bsLabel.GetBuffer(bsLabel.GetLength());
Tom Sepezc6ab1722015-02-05 15:27:25 -0800162 int ret = m_pInfo->m_pJsPlatform->app_response(m_pInfo->m_pJsPlatform, pQuestion, pTitle,
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700163 pDefault, pLabel, bPassword, response, length);
164 bsQuestion.ReleaseBuffer();
165 bsTitle.ReleaseBuffer();
166 bsDefault.ReleaseBuffer();
167 bsLabel.ReleaseBuffer();
168 return ret;
169 }
170 return -1;
171 }
172
Nico Weber5eb9f7b2014-07-18 09:14:35 -0700173 void JS_appBeep(int nType)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700174 {
175 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_beep)
176 {
177 m_pInfo->m_pJsPlatform->app_beep(m_pInfo->m_pJsPlatform, nType);
178 }
179 }
180
Nico Weber5eb9f7b2014-07-18 09:14:35 -0700181 CFX_WideString JS_fieldBrowse()
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700182 {
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700183 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Field_browse)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700184 {
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700185 int nRequiredLen = m_pInfo->m_pJsPlatform->Field_browse(m_pInfo->m_pJsPlatform, NULL, 0);
186 if (nRequiredLen <= 0)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700187 return L"";
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700188
189 char* pbuff = new char[nRequiredLen];
190 if (!pbuff)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700191 return L"";
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700192
193 memset(pbuff, 0, nRequiredLen);
194 int nActualLen = m_pInfo->m_pJsPlatform->Field_browse(m_pInfo->m_pJsPlatform, pbuff, nRequiredLen);
195 if (nActualLen <= 0 || nActualLen > nRequiredLen)
196 {
197 delete[] pbuff;
198 return L"";
199 }
200 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700201 CFX_WideString wsRet = CFX_WideString::FromLocal(bsRet);
202 delete[] pbuff;
203 return wsRet;
204 }
205 return L"";
206 }
207
208 CFX_WideString JS_docGetFilePath()
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700209 {
210 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_getFilePath)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700211 {
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700212 int nRequiredLen = m_pInfo->m_pJsPlatform->Doc_getFilePath(m_pInfo->m_pJsPlatform, NULL, 0);
213 if (nRequiredLen <= 0)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700214 return L"";
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700215
216 char* pbuff = new char[nRequiredLen];
217 if (!pbuff)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700218 return L"";
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700219
220 memset(pbuff, 0, nRequiredLen);
221 int nActualLen = m_pInfo->m_pJsPlatform->Doc_getFilePath(m_pInfo->m_pJsPlatform, pbuff, nRequiredLen);
222 if (nActualLen <= 0 || nActualLen > nRequiredLen)
223 {
224 delete[] pbuff;
225 return L"";
226 }
227 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700228 CFX_WideString wsRet = CFX_WideString::FromLocal(bsRet);
229 delete[] pbuff;
230 return wsRet;
231 }
232 return L"";
233 }
234
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700235 void JS_docSubmitForm(void* formData, int length, const FX_WCHAR* URL)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700236 {
237 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_submitForm)
238 {
239 CFX_ByteString bsDestination = CFX_WideString(URL).UTF16LE_Encode();
240 FPDF_WIDESTRING pDestination = (FPDF_WIDESTRING)bsDestination.GetBuffer(bsDestination.GetLength());
241 m_pInfo->m_pJsPlatform->Doc_submitForm(m_pInfo->m_pJsPlatform, formData, length, pDestination);
242 bsDestination.ReleaseBuffer();
243 }
244 }
245
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700246 void JS_docmailForm(void* mailData, int length, FPDF_BOOL bUI,const FX_WCHAR* To, const FX_WCHAR* Subject, const FX_WCHAR* CC, const FX_WCHAR* BCC, const FX_WCHAR* Msg)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700247 {
248 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_mail)
249 {
250 CFX_ByteString bsTo = CFX_WideString(To).UTF16LE_Encode();
251 CFX_ByteString bsCC = CFX_WideString(Subject).UTF16LE_Encode();
252 CFX_ByteString bsBcc = CFX_WideString(BCC).UTF16LE_Encode();
253 CFX_ByteString bsSubject = CFX_WideString(Subject).UTF16LE_Encode();
254 CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode();
255 FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(bsTo.GetLength());
256 FPDF_WIDESTRING pCC = (FPDF_WIDESTRING)bsCC.GetBuffer(bsCC.GetLength());
257 FPDF_WIDESTRING pBcc = (FPDF_WIDESTRING)bsBcc.GetBuffer(bsBcc.GetLength());
258 FPDF_WIDESTRING pSubject = (FPDF_WIDESTRING)bsSubject.GetBuffer(bsSubject.GetLength());
259 FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength());
260 m_pInfo->m_pJsPlatform->Doc_mail(m_pInfo->m_pJsPlatform, mailData, length, bUI, pTo, pSubject,
261 pCC, pBcc, pMsg);
262 bsTo.ReleaseBuffer();
263 bsCC.ReleaseBuffer();
264 bsBcc.ReleaseBuffer();
265 bsSubject.ReleaseBuffer();
266 bsMsg.ReleaseBuffer();
267 }
268 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700269
270 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)
271 {
272 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_print)
273 {
274 m_pInfo->m_pJsPlatform->Doc_print(m_pInfo->m_pJsPlatform, bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage, bReverse, bAnnotations);
275 }
276 }
277 void JS_docgotoPage(int nPageNum)
278 {
279 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_gotoPage)
280 {
281 m_pInfo->m_pJsPlatform->Doc_gotoPage(m_pInfo->m_pJsPlatform, nPageNum);
282 }
283 }
284
Nico Weber5eb9f7b2014-07-18 09:14:35 -0700285 FPDF_PAGE FFI_GetPage(FPDF_DOCUMENT document,int nPageIndex)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700286 {
287 if(m_pInfo && m_pInfo->FFI_GetPage)
288 {
289 return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex);
290 }
291 return NULL;
292 }
293
Nico Weber5eb9f7b2014-07-18 09:14:35 -0700294 FPDF_PAGE FFI_GetCurrentPage(FPDF_DOCUMENT document)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700295 {
296 if(m_pInfo && m_pInfo->FFI_GetCurrentPage)
297 {
298 return m_pInfo->FFI_GetCurrentPage(m_pInfo, document);
299 }
300 return NULL;
301 }
302
303 int FFI_GetRotation(FPDF_PAGE page)
304 {
305 if(m_pInfo && m_pInfo->FFI_GetRotation)
306 {
307 return m_pInfo->FFI_GetRotation(m_pInfo, page);
308 }
309 return 0;
310 }
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700311 void FFI_ExecuteNamedAction(const FX_CHAR* namedAction)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700312 {
313 if(m_pInfo && m_pInfo->FFI_ExecuteNamedAction)
314 {
315 m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction);
316 }
317 }
318 void FFI_OnSetFieldInputFocus(void* field,FPDF_WIDESTRING focusText, FPDF_DWORD nTextLen, FX_BOOL bFocus)
319 {
320 if(m_pInfo && m_pInfo->FFI_SetTextFieldFocus)
321 {
322 m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus);
323 }
324 }
325
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700326 void FFI_DoURIAction(const FX_CHAR* bsURI)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700327 {
328 if(m_pInfo && m_pInfo->FFI_DoURIAction)
329 {
330 m_pInfo->FFI_DoURIAction(m_pInfo, bsURI);
331 }
332 }
333
334 void FFI_DoGoToAction(int nPageIndex, int zoomMode, float* fPosArray, int sizeOfArray)
335 {
336 if(m_pInfo && m_pInfo->FFI_DoGoToAction)
337 {
338 m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray, sizeOfArray);
339 }
340 }
341
Bo Xufdc00a72014-10-28 23:03:33 -0700342 void FFI_DisplayCaret(FPDF_PAGE page, FPDF_BOOL bVisible, double left, double top, double right, double bottom)
343 {
344 if (m_pInfo && m_pInfo->FFI_DisplayCaret)
345 {
346 m_pInfo->FFI_DisplayCaret(m_pInfo, page, bVisible, left, top, right, bottom);
347 }
348 }
349 int FFI_GetCurrentPageIndex(FPDF_DOCUMENT document)
350 {
351 if (m_pInfo && m_pInfo->FFI_GetCurrentPageIndex)
352 {
353 m_pInfo->FFI_GetCurrentPageIndex(m_pInfo, document);
354 }
355 return -1;
356 }
357 int FFI_SetCurrentPage(FPDF_DOCUMENT document, int iCurPage)
358 {
359 if (m_pInfo && m_pInfo->FFI_SetCurrentPage)
360 {
361 m_pInfo->FFI_SetCurrentPage(m_pInfo, document, iCurPage);
362 }
363 return -1;
364 }
365
366 CFX_WideString FFI_GetAppName()
367 {
368 return CFX_WideString(L"Acrobat");
369
370 //if (m_pInfo && m_pInfo->FFI_GetAppName)
371 //{
372 // int nLen = m_pInfo->FFI_GetAppName(m_pInfo, NULL, 0);
373 // if(nLen <= 0)
374 // return L"";
375 // char* pbuff = new char[nLen];
376 // if(pbuff)
377 // memset(pbuff, 0, nLen);
Tom Sepezc6ab1722015-02-05 15:27:25 -0800378 // else
Bo Xufdc00a72014-10-28 23:03:33 -0700379 // return L"";
380 // nLen = m_pInfo->FFI_GetAppName(m_pInfo, pbuff, nLen);
381 // CFX_ByteString bsRet = CFX_ByteString(pbuff, nLen);
382 // CFX_WideString wsRet = CFX_WideString::FromLocal(bsRet);
383 // delete[] pbuff;
384 // return wsRet;
385 //}
386
387 //return L"";
388 }
389
390 CFX_WideString FFI_GetPlatform()
391 {
392 if (m_pInfo && m_pInfo->FFI_GetPlatform)
393 {
394 int nRequiredLen = m_pInfo->FFI_GetPlatform(m_pInfo, NULL, 0);
395 if (nRequiredLen <= 0)
396 return L"";
397
398 char* pbuff = new char[nRequiredLen];
399 if (!pbuff)
400 return L"";
401
402 memset(pbuff, 0, nRequiredLen);
403 int nActualLen = m_pInfo->FFI_GetPlatform(m_pInfo, pbuff, nRequiredLen);
404 if (nActualLen <= 0 || nActualLen > nRequiredLen)
405 {
406 delete[] pbuff;
407 return L"";
408 }
409 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
410 CFX_WideString wsRet = CFX_WideString::FromUTF16LE((unsigned short*)bsRet.GetBuffer(bsRet.GetLength()), bsRet.GetLength()/sizeof(unsigned short));
411 delete[] pbuff;
412 return wsRet;
413 }
414 return L"";
415 }
416
Tom Sepezca3ac5e2015-06-10 17:38:11 -0700417 void FFI_GotoURL(FPDF_DOCUMENT document, const CFX_WideStringC& wsURL, FX_BOOL bAppend)
Bo Xufdc00a72014-10-28 23:03:33 -0700418 {
419 if (m_pInfo && m_pInfo->FFI_GotoURL)
420 {
421 CFX_ByteString bsTo = CFX_WideString(wsURL).UTF16LE_Encode();
422 FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(wsURL.GetLength());
423 m_pInfo->FFI_GotoURL(m_pInfo, document, pTo);
424 bsTo.ReleaseBuffer();
425 }
426 }
427 void FFI_GetURL(FPDF_DOCUMENT document, CFX_WideString& wsURL)
428 {
429 wsURL = CFX_WideString();
430 return;
431 //if (m_pInfo && m_pInfo->FFI_GetURL)
432 //{
433 // FPDF_WIDESTRING url = m_pInfo->FFI_GetURL(m_pInfo, document);
434 // CFX_WideString tmp;
435 // tmp.FromUTF16LE(url);
436 // wsURL = tmp;
437 //}
438 }
439
440 void FFI_AddDoRecord(FPDF_DOCUMENT document, FPDF_WIDGET hWidget)
441 {
442 //if (m_pInfo && m_pInfo->FFI_AddDoRecord)
443 //{
444 // m_pInfo->FFI_AddDoRecord(m_pInfo, document, hWidget);
445 //}
446 }
447 void FFI_PageEvent(FPDF_PAGE page, FPDF_DWORD flag)
448 {
449 //if (m_pInfo && m_pInfo->FFI_PageEvent)
450 //{
451 // m_pInfo->FFI_PageEvent(m_pInfo, page, flag);
452 //}
453 }
454
455 void FFI_GetPageViewRect(FPDF_PAGE page, FS_RECTF& dstRect)
456 {
457 if (m_pInfo && m_pInfo->FFI_GetPageViewRect)
458 {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800459 double left;
Bo Xufdc00a72014-10-28 23:03:33 -0700460 double top;
461 double right;
462 double bottom;
463 m_pInfo->FFI_GetPageViewRect(m_pInfo, page, &left, &top, &right, &bottom);
464
Bruce Dawson3f49aa32015-01-08 11:47:49 -0800465 dstRect.left = static_cast<float>(left);
466 dstRect.top = static_cast<float>(top < bottom ? bottom : top);
467 dstRect.bottom = static_cast<float>(top < bottom ? top : bottom);
468 dstRect.right = static_cast<float>(right);
Bo Xufdc00a72014-10-28 23:03:33 -0700469 }
470 }
471
472
473 FX_BOOL FFI_PopupMenu(FPDF_PAGE page, FPDF_WIDGET hWidget, int menuFlag, CFX_PointF ptPopup, const CFX_PointF* pRectExclude)
474 {
475 if (m_pInfo && m_pInfo->FFI_PopupMenu)
476 {
477 return m_pInfo->FFI_PopupMenu(m_pInfo, page, hWidget, menuFlag, ptPopup.x, ptPopup.y);
478 }
479 return FALSE;
480 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800481
Bo Xufdc00a72014-10-28 23:03:33 -0700482 void FFI_Alert(FPDF_WIDESTRING Msg, FPDF_WIDESTRING Title, int Type, int Icon)
483 {
484 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert)
485 {
486 m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, Msg, Title, Type, Icon);
487 }
488 }
489 void FFI_EmailTo(FPDF_FILEHANDLER* fileHandler, FPDF_WIDESTRING pTo, FPDF_WIDESTRING pSubject, FPDF_WIDESTRING pCC, FPDF_WIDESTRING pBcc, FPDF_WIDESTRING pMsg)
490 {
491 if(m_pInfo && m_pInfo->FFI_EmailTo)
492 {
493 m_pInfo->FFI_EmailTo(m_pInfo, fileHandler, pTo, pSubject, pCC, pBcc, pMsg);
494 }
495 }
496 void FFI_UploadTo(FPDF_FILEHANDLER* fileHandler, int fileFlag, FPDF_WIDESTRING uploadTo)
497 {
498 if(m_pInfo && m_pInfo->FFI_UploadTo)
499 {
500 m_pInfo->FFI_UploadTo(m_pInfo, fileHandler, fileFlag, uploadTo);
501 }
502 }
503 FPDF_FILEHANDLER* FFI_OpenFile(int fileType, FPDF_WIDESTRING wsURL, const char* mode)
504 {
505 if(m_pInfo && m_pInfo->FFI_OpenFile)
506 {
507 return m_pInfo->FFI_OpenFile(m_pInfo, fileType, wsURL, mode);
508 }
509 return NULL;
510 }
511 CFX_WideString FFI_GetFilePath(FPDF_FILEHANDLER* pFileHandler)
512 {
513#if 0
514 if (m_pInfo && m_pInfo->FFI_GetFilePath)
515 {
516 int nRequiredLen = m_pInfo->FFI_GetFilePath(m_pInfo, pFileHandler, NULL, 0);
517 if (nRequiredLen <= 0)
518 return L"";
519
520 char* pbuff = new char[nRequiredLen];
521 if (!pbuff)
522 return L"";
523
524 memset(pbuff, 0, nRequiredLen);
525 int nActualLen = m_pInfo->FFI_GetFilePath(m_pInfo, pFileHandler, pbuff, nRequiredLen);
526 if (nActualLen <= 0 || nActualLen > nRequiredLen)
527 {
528 delete[] pbuff;
529 return L"";
530 }
531 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
532 CFX_WideString wsRet = CFX_WideString::FromUTF16LE((unsigned short*)bsRet.GetBuffer(bsRet.GetLength()), bsRet.GetLength()/sizeof(unsigned short));
533 delete[] pbuff;
534 return wsRet;
535 }
536 return L"";
537#else
538 return L"";
539#endif
540 }
541 int FFI_GetDocumentCount()
542 {
543 //if (m_pInfo && m_pInfo->FFI_GetDocumentCount)
544 //{
545 //return m_pInfo->FFI_GetDocumentCount(m_pInfo);
546 //}
547 return 0;
548 }
549
550 int FFI_GetCurDocument()
551 {
552 //if (m_pInfo && m_pInfo->FFI_GetCurDocumentIndex)
553 //{
554 // return m_pInfo->FFI_GetCurDocumentIndex(m_pInfo);
555 //}
556 return 0;
557 }
558
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700559 IFX_FileRead* FFI_DownloadFromURL(const FX_WCHAR* url)
Bo Xufdc00a72014-10-28 23:03:33 -0700560 {
561 if (m_pInfo && m_pInfo->FFI_DownloadFromURL)
562 {
563 CFX_ByteString bstrURL = CFX_WideString(url).UTF16LE_Encode();
564 FPDF_WIDESTRING wsURL = (FPDF_WIDESTRING)bstrURL.GetBuffer(bstrURL.GetLength());
565
566 FPDF_LPFILEHANDLER fileHandler = m_pInfo->FFI_DownloadFromURL(m_pInfo, wsURL);
567
568 CFPDF_FileStream* fileStream = FX_NEW CFPDF_FileStream(fileHandler);
569 return fileStream;
570 }
571 return NULL;
572 }
573
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700574 CFX_WideString FFI_PostRequestURL(const FX_WCHAR* wsURL, const FX_WCHAR* wsData, const FX_WCHAR* wsContentType, const FX_WCHAR* wsEncode, const FX_WCHAR* wsHeader)
Bo Xufdc00a72014-10-28 23:03:33 -0700575 {
576 if (m_pInfo && m_pInfo->FFI_PostRequestURL)
577 {
578 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
579 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
580
581 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
582 FPDF_WIDESTRING data = (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
583
584 CFX_ByteString bsContentType = CFX_WideString(wsContentType).UTF16LE_Encode();
585 FPDF_WIDESTRING contentType = (FPDF_WIDESTRING)bsContentType.GetBuffer(bsContentType.GetLength());
586
587 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
588 FPDF_WIDESTRING encode = (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
589
590 CFX_ByteString bsHeader = CFX_WideString(wsHeader).UTF16LE_Encode();
591 FPDF_WIDESTRING header = (FPDF_WIDESTRING)bsHeader.GetBuffer(bsHeader.GetLength());
592
593 FPDF_BSTR respone;
594 FPDF_BStr_Init(&respone);
595 FPDF_BOOL bRet = m_pInfo->FFI_PostRequestURL(m_pInfo, URL, data, contentType, encode, header, &respone);
596
597 CFX_WideString wsRet = CFX_WideString::FromUTF16LE((unsigned short*)respone.str, respone.len/sizeof(unsigned short));
598 FPDF_BStr_Clear(&respone);
599
600 return wsRet;
601 }
602 return L"";
603 }
604
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700605 FPDF_BOOL FFI_PutRequestURL(const FX_WCHAR* wsURL, const FX_WCHAR* wsData, const FX_WCHAR* wsEncode)
Bo Xufdc00a72014-10-28 23:03:33 -0700606 {
607 if (m_pInfo && m_pInfo->FFI_PutRequestURL)
608 {
609 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
610 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
611
612 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
613 FPDF_WIDESTRING data = (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
614
615 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
616 FPDF_WIDESTRING encode = (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
617
618 return m_pInfo->FFI_PutRequestURL(m_pInfo, URL, data, encode);
619 }
620 return FALSE;
621 }
622
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700623 FPDF_BOOL FFI_ShowFileDialog(const FX_WCHAR* wsTitle, const FX_WCHAR* wsFilter, CFX_WideStringArray &wsPathArr, FX_BOOL bOpen)
Bo Xufdc00a72014-10-28 23:03:33 -0700624 {
625 /*CFX_ByteString bsTitle = CFX_WideString(wsTitle).UTF16LE_Encode();
626 FPDF_WIDESTRING title = (FPDF_WIDESTRING)bsTitle.GetBuffer(bsTitle.GetLength());
627
628 CFX_ByteString bsFilter = CFX_WideString(wsFilter).UTF16LE_Encode();
629 FPDF_WIDESTRING filter = (FPDF_WIDESTRING)bsFilter.GetBuffer(bsFilter.GetLength());
630
631 CFX_ByteStringArray* strPathArr = FX_NEW CFX_ByteStringArray();
632 if (m_pInfo && m_pInfo->FFI_ShowFileDialog)
633 {
634 FPDF_BOOL bRet = m_pInfo->FFI_ShowFileDialog(m_pInfo, title, filter, bOpen, (FPDF_STRINGHANDLE)strPathArr);
Tom Sepezc6ab1722015-02-05 15:27:25 -0800635 if (bRet)
Bo Xufdc00a72014-10-28 23:03:33 -0700636 {
637 int count = strPathArr->GetSize();
638 for (int i=0; i<count; i++)
639 {
640 CFX_ByteString bsPath = *strPathArr->GetDataPtr(i);
641 CFX_WideString wsPath = CFX_WideString::FromUTF16LE((unsigned short*)bsPath.GetBuffer(bsPath.GetLength()), bsPath.GetLength()/sizeof(unsigned short));
642 if (!wsPath.IsEmpty())
643 wsPathArr.Add(wsPath);
644 wsPath = L"";
645 }
646 return TRUE;
647 }
648
649 return FALSE;
650 }
651 */
652
653 return FALSE;
654 }
655 CFX_WideString FFI_GetLanguage()
656 {
657 if (m_pInfo && m_pInfo->FFI_GetLanguage)
658 {
659 int nRequiredLen = m_pInfo->FFI_GetLanguage(m_pInfo, NULL, 0);
660 if (nRequiredLen <= 0)
661 return L"";
662
663 char* pbuff = new char[nRequiredLen];
664 if (!pbuff)
665 return L"";
666
667 memset(pbuff, 0, nRequiredLen);
668 int nActualLen = m_pInfo->FFI_GetLanguage(m_pInfo, pbuff, nRequiredLen);
669 if (nActualLen <= 0 || nActualLen > nRequiredLen)
670 {
671 delete[] pbuff;
672 return L"";
673 }
674 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
675 CFX_WideString wsRet = CFX_WideString::FromUTF16LE((unsigned short*)bsRet.GetBuffer(bsRet.GetLength()), bsRet.GetLength()/sizeof(unsigned short));
676 delete[] pbuff;
677 return wsRet;
678 }
679 return L"";
680 }
681
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700682 FX_BOOL IsJSInitiated();
683
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700684 void SetCurrentDoc(CPDFSDK_Document* pFXDoc) {m_pSDKDoc = pFXDoc;}
685 CPDFSDK_Document* GetCurrentDoc();
Bo Xufdc00a72014-10-28 23:03:33 -0700686 CPDFXFA_Document* GetPDFXFADocument() {return m_pDoc;}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700687
688 CFX_ByteString GetAppName() {return "";}
689
690 CFFL_IFormFiller* GetIFormFiller();
691 IFX_SystemHandler* GetSysHandler() {return m_pSysHandler;}
692
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700693 CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr();
694 IFXJS_Runtime* GetJSRuntime();
695 CPDFSDK_ActionHandler* GetActionHander();
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800696 FPDF_FORMFILLINFO* GetFormFillInfo() {return m_pInfo;}
697
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700698private:
699 CPDFSDK_AnnotHandlerMgr* m_pAnnotHandlerMgr;
700 CPDFSDK_ActionHandler* m_pActionHandler;
701 IFXJS_Runtime* m_pJSRuntime;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700702 FPDF_FORMFILLINFO* m_pInfo;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700703 CPDFSDK_Document* m_pSDKDoc;
Bo Xufdc00a72014-10-28 23:03:33 -0700704 CPDFXFA_Document* m_pDoc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700705
706 CFFL_IFormFiller* m_pIFormFiller;
707 IFX_SystemHandler* m_pSysHandler;
708
709public:
Bo Xufdc00a72014-10-28 23:03:33 -0700710 //CJS_RuntimeFactory* m_pJSRuntimeFactory;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700711};
712
713
714
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700715class CPDFSDK_InterForm;
716class CPDFSDK_Document
717{
718public:
Bo Xufdc00a72014-10-28 23:03:33 -0700719 CPDFSDK_Document(CPDFXFA_Document* pDoc, CPDFDoc_Environment* pEnv);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700720 ~CPDFSDK_Document();
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800721
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700722 CPDFSDK_InterForm* GetInterForm() ;
Bo Xufdc00a72014-10-28 23:03:33 -0700723 CPDFXFA_Document* GetDocument() {return m_pDoc;}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700724
Lei Zhang606346f2015-06-19 18:11:07 -0700725 int GetPageViewCount() const { return m_pageMap.size(); }
Bo Xufdc00a72014-10-28 23:03:33 -0700726 CPDFSDK_PageView* GetPageView(CPDFXFA_Page* pPDFXFAPage, FX_BOOL ReNew = TRUE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700727 CPDFSDK_PageView* GetPageView(int nIndex);
728 CPDFSDK_PageView* GetCurrentView();
Bo Xufdc00a72014-10-28 23:03:33 -0700729 void ReMovePageView(CPDFXFA_Page* pPDFPage);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700730 void UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot);
731
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800732 CPDFSDK_Annot* GetFocusAnnot();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700733
734 IFXJS_Runtime * GetJsRuntime();
Tom Sepezc6ab1722015-02-05 15:27:25 -0800735
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800736 FX_BOOL SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag = 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700737 FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0);
738
739 FX_BOOL ExtractPages(const CFX_WordArray &arrExtraPages, CPDF_Document* pDstDoc);
740 FX_BOOL InsertPages(int nInsertAt, const CPDF_Document* pSrcDoc, const CFX_WordArray &arrSrcPages);
741 FX_BOOL DeletePages(int nStart, int nCount);
742 FX_BOOL ReplacePages(int nPage, const CPDF_Document* pSrcDoc, const CFX_WordArray &arrSrcPages);
743
744 void OnCloseDocument();
745
746 int GetPageCount() {return m_pDoc->GetPageCount();}
747 FX_BOOL GetPermissions(int nFlag);
748 FX_BOOL GetChangeMark() {return m_bChangeMask;}
749 void SetChangeMark() {m_bChangeMask = TRUE;}
750 void ClearChangeMark() {m_bChangeMask= FALSE;}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700751 CFX_WideString GetPath() ;
Bo Xufdc00a72014-10-28 23:03:33 -0700752 CPDFXFA_Page* GetPage(int nIndex);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700753 CPDFDoc_Environment * GetEnv() {return m_pEnv; }
754 void ProcJavascriptFun();
755 FX_BOOL ProcOpenAction();
756 CPDF_OCContext* GetOCContext();
757private:
Lei Zhang606346f2015-06-19 18:11:07 -0700758 std::map<CPDFXFA_Page*, CPDFSDK_PageView*> m_pageMap;
759 CPDFXFA_Document* m_pDoc;
760 CPDFSDK_InterForm* m_pInterForm;
761 CPDFSDK_Annot* m_pFocusAnnot;
762 CPDFDoc_Environment* m_pEnv;
763 CPDF_OCContext* m_pOccontent;
764 FX_BOOL m_bChangeMask;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700765};
Tom Sepezb1161362015-06-09 11:29:12 -0700766class CPDFSDK_PageView final
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700767{
768public:
Bo Xufdc00a72014-10-28 23:03:33 -0700769 CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,CPDFXFA_Page* page);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700770 ~CPDFSDK_PageView();
Bo Xufdc00a72014-10-28 23:03:33 -0700771 void PageView_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,CPDF_RenderOptions* pOptions, FX_RECT* pClip = NULL) ;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700772 CPDF_Annot* GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
773 CPDFSDK_Annot* GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
774 CPDF_Annot* GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
775 CPDFSDK_Annot* GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
776 CPDFSDK_Annot* GetFocusAnnot() ;
777 void SetFocusAnnot(CPDFSDK_Annot* pSDKAnnot,FX_UINT nFlag = 0) {m_pSDKDoc->SetFocusAnnot(pSDKAnnot, nFlag);}
778 FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0) {return m_pSDKDoc->KillFocusAnnot(nFlag);}
779 FX_BOOL Annot_HasAppearance(CPDF_Annot* pAnnot);
780
781 CPDFSDK_Annot* AddAnnot(CPDF_Dictionary * pDict);
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700782 CPDFSDK_Annot* AddAnnot(const FX_CHAR* lpSubType,CPDF_Dictionary * pDict);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700783 CPDFSDK_Annot* AddAnnot(CPDF_Annot * pPDFAnnot);
Tom Sepezeed467d2015-06-02 10:35:27 -0700784 CPDFSDK_Annot* AddAnnot(IXFA_Widget* pPDFAnnot);
Tom Sepezc6ab1722015-02-05 15:27:25 -0800785 FX_BOOL DeleteAnnot(CPDFSDK_Annot* pAnnot);
786
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700787 int CountAnnots();
788 CPDFSDK_Annot* GetAnnot(int nIndex);
789 CPDFSDK_Annot* GetAnnotByDict(CPDF_Dictionary * pDict);
Tom Sepezeed467d2015-06-02 10:35:27 -0700790 CPDFSDK_Annot* GetAnnotByXFAWidget(IXFA_Widget* hWidget);
Bo Xufdc00a72014-10-28 23:03:33 -0700791 CPDFXFA_Page* GetPDFXFAPage(){return m_page;}
792 CPDF_Page* GetPDFPage();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700793 CPDF_Document* GetPDFDocument();
Tom Sepezc6ab1722015-02-05 15:27:25 -0800794 CPDFSDK_Document* GetSDKDocument() {return m_pSDKDoc;}
Nico Weber5eb9f7b2014-07-18 09:14:35 -0700795 FX_BOOL OnLButtonDown(const CPDF_Point & point, FX_UINT nFlag);
796 FX_BOOL OnLButtonUp(const CPDF_Point & point, FX_UINT nFlag);
Bo Xufdc00a72014-10-28 23:03:33 -0700797 FX_BOOL OnRButtonDown(const CPDF_Point & point, FX_UINT nFlag);
798 FX_BOOL OnRButtonUp(const CPDF_Point & point, FX_UINT nFlag);
Nico Weber5eb9f7b2014-07-18 09:14:35 -0700799 FX_BOOL OnChar(int nChar, FX_UINT nFlag);
800 FX_BOOL OnKeyDown(int nKeyCode, int nFlag);
801 FX_BOOL OnKeyUp(int nKeyCode, int nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700802
Nico Weber5eb9f7b2014-07-18 09:14:35 -0700803 FX_BOOL OnMouseMove(const CPDF_Point & point, int nFlag);
804 FX_BOOL OnMouseWheel(double deltaX, double deltaY,const CPDF_Point& point, int nFlag);
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700805 FX_BOOL IsValidAnnot(void* p);
Nico Weber5eb9f7b2014-07-18 09:14:35 -0700806 void GetCurrentMatrix(CPDF_Matrix& matrix) {matrix = m_curMatrix;}
807 void UpdateRects(CFX_RectArray& rects);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700808 void UpdateView(CPDFSDK_Annot* pAnnot);
809 CFX_PtrArray* GetAnnotList(){ return &m_fxAnnotArray; }
810
Nico Weber5eb9f7b2014-07-18 09:14:35 -0700811 int GetPageIndex();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700812 void LoadFXAnnots();
Bo Xufdc00a72014-10-28 23:03:33 -0700813 void SetValid(FX_BOOL bValid) {m_bValid = bValid;}
814 FX_BOOL IsValid() {return m_bValid;}
815 void SetLock(FX_BOOL bLocked) {m_bLocked= bLocked;}
816 FX_BOOL IsLocked() {return m_bLocked;}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700817private:
818 void PageView_OnHighlightFormFields(CFX_RenderDevice* pDevice, CPDFSDK_Widget* pWidget);
Bo Xufdc00a72014-10-28 23:03:33 -0700819 CPDF_Matrix m_curMatrix;
820 CPDFXFA_Page* m_page;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700821 CPDF_AnnotList* m_pAnnotList;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700822 //CPDFSDK_Annot* m_pFocusAnnot;
823 CFX_PtrArray m_fxAnnotArray;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700824 CPDFSDK_Document* m_pSDKDoc;
Bo Xufdc00a72014-10-28 23:03:33 -0700825 CPDFSDK_Annot* m_CaptureWidget;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700826 FX_BOOL m_bEnterWidget;
827 FX_BOOL m_bExitWidget;
828 FX_BOOL m_bOnWidget;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700829 FX_BOOL m_bValid;
Bo Xufdc00a72014-10-28 23:03:33 -0700830 FX_BOOL m_bLocked;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700831};
832
833
834template<class TYPE>
835class CGW_ArrayTemplate : public CFX_ArrayTemplate<TYPE>
836{
Tom Sepezc6ab1722015-02-05 15:27:25 -0800837public:
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700838 CGW_ArrayTemplate(){}
839 virtual ~CGW_ArrayTemplate(){}
Tom Sepezc6ab1722015-02-05 15:27:25 -0800840
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700841 typedef int (*LP_COMPARE)(TYPE p1, TYPE p2);
Tom Sepezc6ab1722015-02-05 15:27:25 -0800842
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700843 void Sort(LP_COMPARE pCompare, FX_BOOL bAscent = TRUE)
844 {
845 int nSize = this->GetSize();
846 QuickSort(0, nSize -1, bAscent, pCompare);
847 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800848
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700849private:
850 void QuickSort(FX_UINT nStartPos, FX_UINT nStopPos, FX_BOOL bAscend, LP_COMPARE pCompare)
851 {
852 if (nStartPos >= nStopPos) return;
Tom Sepezc6ab1722015-02-05 15:27:25 -0800853
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700854 if ((nStopPos - nStartPos) == 1)
855 {
856 TYPE Value1 = this->GetAt(nStartPos);
857 TYPE Value2 = this->GetAt(nStopPos);
Tom Sepezc6ab1722015-02-05 15:27:25 -0800858
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700859 int iGreate = (*pCompare)(Value1, Value2);
860 if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0))
861 {
862 this->SetAt(nStartPos, Value2);
863 this->SetAt(nStopPos, Value1);
864 }
865 return;
866 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800867
Bo Xu9a52eb02014-06-24 11:37:49 -0700868 FX_UINT m = nStartPos + (nStopPos - nStartPos) / 2;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700869 FX_UINT i = nStartPos;
Tom Sepezc6ab1722015-02-05 15:27:25 -0800870
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700871 TYPE Value = this->GetAt(m);
Tom Sepezc6ab1722015-02-05 15:27:25 -0800872
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700873 while (i < m)
874 {
875 TYPE temp = this->GetAt(i);
Tom Sepezc6ab1722015-02-05 15:27:25 -0800876
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700877 int iGreate = (*pCompare)(temp, Value);
878 if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0))
879 {
880 this->InsertAt(m+1, temp);
881 this->RemoveAt(i);
882 m--;
883 }
884 else
885 {
886 i++;
887 }
888 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800889
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700890 FX_UINT j = nStopPos;
Tom Sepezc6ab1722015-02-05 15:27:25 -0800891
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700892 while (j > m)
893 {
894 TYPE temp = this->GetAt(j);
Tom Sepezc6ab1722015-02-05 15:27:25 -0800895
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700896 int iGreate = (*pCompare)(temp, Value);
897 if ((bAscend && iGreate < 0) || (!bAscend && iGreate > 0))
898 {
899 this->RemoveAt(j);
900 this->InsertAt(m, temp);
901 m++;
902 }
903 else
904 {
905 j--;
906 }
907 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800908
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700909 if (nStartPos < m) QuickSort(nStartPos, m, bAscend, pCompare);
910 if (nStopPos > m) QuickSort(m, nStopPos, bAscend, pCompare);
911 }
912};
913
Tom Sepez19922bb2015-05-28 13:23:12 -0700914#endif // FPDFSDK_INCLUDE_FSDK_MGR_H_