OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #ifndef FPDFSDK_INCLUDE_FSDK_MGR_H_ | 7 #ifndef FPDFSDK_INCLUDE_FSDK_MGR_H_ |
8 #define FPDFSDK_INCLUDE_FSDK_MGR_H_ | 8 #define FPDFSDK_INCLUDE_FSDK_MGR_H_ |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 | 11 |
12 #include "../../core/include/fpdftext/fpdf_text.h" | 12 #include "../../core/include/fpdftext/fpdf_text.h" |
13 #include "../../public/fpdf_formfill.h" | 13 #include "../../public/fpdf_formfill.h" |
14 #include "../../public/fpdf_fwlevent.h" // cross platform keycode and events def
ine. | 14 #include "../../public/fpdf_fwlevent.h" // cross platform keycode and events de
fine. |
15 #include "fsdk_common.h" | 15 #include "fsdk_common.h" |
16 #include "fsdk_define.h" | 16 #include "fsdk_define.h" |
17 #include "fx_systemhandler.h" | 17 #include "fx_systemhandler.h" |
18 #include "fsdk_baseannot.h" | 18 #include "fsdk_baseannot.h" |
19 #include "fsdk_baseform.h" | 19 #include "fsdk_baseform.h" |
20 #include "fsdk_annothandler.h" | 20 #include "fsdk_annothandler.h" |
21 #include "fsdk_actionhandler.h" | 21 #include "fsdk_actionhandler.h" |
22 #include "javascript/IJavaScript.h" | 22 #include "javascript/IJavaScript.h" |
23 | 23 |
24 class CFFL_IFormFiller; | 24 class CFFL_IFormFiller; |
25 class CJS_RuntimeFactory; | 25 class CJS_RuntimeFactory; |
26 class CPDFSDK_ActionHandler; | 26 class CPDFSDK_ActionHandler; |
27 class CPDFSDK_Annot; | 27 class CPDFSDK_Annot; |
28 class CPDFSDK_Document; | 28 class CPDFSDK_Document; |
29 class CPDFSDK_InterForm; | 29 class CPDFSDK_InterForm; |
30 class CPDFSDK_PageView; | 30 class CPDFSDK_PageView; |
31 class CPDFSDK_Widget; | 31 class CPDFSDK_Widget; |
32 class IFX_SystemHandler; | 32 class IFX_SystemHandler; |
33 | 33 |
34 class CPDFDoc_Environment final | 34 class CPDFDoc_Environment final { |
35 { | 35 public: |
36 public: | 36 CPDFDoc_Environment(CPDF_Document* pDoc, FPDF_FORMFILLINFO* pFFinfo); |
37 CPDFDoc_Environment(CPDF_Document* pDoc, FPDF_FORMFILLINFO* pFFinfo); | 37 ~CPDFDoc_Environment(); |
38 ~CPDFDoc_Environment(); | 38 |
39 | 39 void FFI_Invalidate(FPDF_PAGE page, |
40 void FFI_Invalidate(FPDF_PAGE page, double left, double top, double right, d
ouble bottom) | 40 double left, |
41 { | 41 double top, |
42 if (m_pInfo && m_pInfo->FFI_Invalidate) | 42 double right, |
43 m_pInfo->FFI_Invalidate(m_pInfo, page, left, top, right, bottom); | 43 double bottom) { |
| 44 if (m_pInfo && m_pInfo->FFI_Invalidate) |
| 45 m_pInfo->FFI_Invalidate(m_pInfo, page, left, top, right, bottom); |
| 46 } |
| 47 |
| 48 void FFI_OutputSelectedRect(FPDF_PAGE page, |
| 49 double left, |
| 50 double top, |
| 51 double right, |
| 52 double bottom) { |
| 53 if (m_pInfo && m_pInfo->FFI_OutputSelectedRect) |
| 54 m_pInfo->FFI_OutputSelectedRect(m_pInfo, page, left, top, right, bottom); |
| 55 } |
| 56 |
| 57 void FFI_SetCursor(int nCursorType) { |
| 58 if (m_pInfo && m_pInfo->FFI_SetCursor) |
| 59 m_pInfo->FFI_SetCursor(m_pInfo, nCursorType); |
| 60 } |
| 61 |
| 62 int FFI_SetTimer(int uElapse, TimerCallback lpTimerFunc) { |
| 63 if (m_pInfo && m_pInfo->FFI_SetTimer) |
| 64 return m_pInfo->FFI_SetTimer(m_pInfo, uElapse, lpTimerFunc); |
| 65 return -1; |
| 66 } |
| 67 |
| 68 void FFI_KillTimer(int nTimerID) { |
| 69 if (m_pInfo && m_pInfo->FFI_KillTimer) |
| 70 m_pInfo->FFI_KillTimer(m_pInfo, nTimerID); |
| 71 } |
| 72 |
| 73 FX_SYSTEMTIME FFI_GetLocalTime() const { |
| 74 FX_SYSTEMTIME fxtime; |
| 75 if (m_pInfo && m_pInfo->FFI_GetLocalTime) { |
| 76 FPDF_SYSTEMTIME systime = m_pInfo->FFI_GetLocalTime(m_pInfo); |
| 77 fxtime.wDay = systime.wDay; |
| 78 fxtime.wDayOfWeek = systime.wDayOfWeek; |
| 79 fxtime.wHour = systime.wHour; |
| 80 fxtime.wMilliseconds = systime.wMilliseconds; |
| 81 fxtime.wMinute = systime.wMinute; |
| 82 fxtime.wMonth = systime.wMonth; |
| 83 fxtime.wSecond = systime.wSecond; |
| 84 fxtime.wYear = systime.wYear; |
44 } | 85 } |
45 | 86 return fxtime; |
46 void FFI_OutputSelectedRect(FPDF_PAGE page, double left, double top, double
right, double bottom) | 87 } |
47 { | 88 |
48 if (m_pInfo && m_pInfo->FFI_OutputSelectedRect) | 89 void FFI_OnChange() { |
49 m_pInfo->FFI_OutputSelectedRect(m_pInfo, page, left, top, right, bot
tom); | 90 if (m_pInfo && m_pInfo->FFI_OnChange) |
| 91 m_pInfo->FFI_OnChange(m_pInfo); |
| 92 } |
| 93 |
| 94 FX_BOOL FFI_IsSHIFTKeyDown(FX_DWORD nFlag) const { |
| 95 return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0; |
| 96 } |
| 97 |
| 98 FX_BOOL FFI_IsCTRLKeyDown(FX_DWORD nFlag) const { |
| 99 return (nFlag & FWL_EVENTFLAG_ControlKey) != 0; |
| 100 } |
| 101 |
| 102 FX_BOOL FFI_IsALTKeyDown(FX_DWORD nFlag) const { |
| 103 return (nFlag & FWL_EVENTFLAG_AltKey) != 0; |
| 104 } |
| 105 |
| 106 FX_BOOL FFI_IsINSERTKeyDown(FX_DWORD nFlag) const { return FALSE; } |
| 107 |
| 108 int JS_appAlert(const FX_WCHAR* Msg, |
| 109 const FX_WCHAR* Title, |
| 110 FX_UINT Type, |
| 111 FX_UINT Icon); |
| 112 int JS_appResponse(const FX_WCHAR* Question, |
| 113 const FX_WCHAR* Title, |
| 114 const FX_WCHAR* Default, |
| 115 const FX_WCHAR* cLabel, |
| 116 FPDF_BOOL bPassword, |
| 117 void* response, |
| 118 int length); |
| 119 |
| 120 void JS_appBeep(int nType) { |
| 121 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_beep) |
| 122 m_pInfo->m_pJsPlatform->app_beep(m_pInfo->m_pJsPlatform, nType); |
| 123 } |
| 124 |
| 125 CFX_WideString JS_fieldBrowse(); |
| 126 CFX_WideString JS_docGetFilePath(); |
| 127 |
| 128 void JS_docSubmitForm(void* formData, int length, const FX_WCHAR* URL); |
| 129 void JS_docmailForm(void* mailData, |
| 130 int length, |
| 131 FPDF_BOOL bUI, |
| 132 const FX_WCHAR* To, |
| 133 const FX_WCHAR* Subject, |
| 134 const FX_WCHAR* CC, |
| 135 const FX_WCHAR* BCC, |
| 136 const FX_WCHAR* Msg); |
| 137 |
| 138 void JS_docprint(FPDF_BOOL bUI, |
| 139 int nStart, |
| 140 int nEnd, |
| 141 FPDF_BOOL bSilent, |
| 142 FPDF_BOOL bShrinkToFit, |
| 143 FPDF_BOOL bPrintAsImage, |
| 144 FPDF_BOOL bReverse, |
| 145 FPDF_BOOL bAnnotations) { |
| 146 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_print) |
| 147 m_pInfo->m_pJsPlatform->Doc_print(m_pInfo->m_pJsPlatform, bUI, nStart, |
| 148 nEnd, bSilent, bShrinkToFit, |
| 149 bPrintAsImage, bReverse, bAnnotations); |
| 150 } |
| 151 |
| 152 void JS_docgotoPage(int nPageNum) { |
| 153 if (m_pInfo && m_pInfo->m_pJsPlatform && |
| 154 m_pInfo->m_pJsPlatform->Doc_gotoPage) |
| 155 m_pInfo->m_pJsPlatform->Doc_gotoPage(m_pInfo->m_pJsPlatform, nPageNum); |
| 156 } |
| 157 |
| 158 FPDF_PAGE FFI_GetPage(FPDF_DOCUMENT document, int nPageIndex) { |
| 159 if (m_pInfo && m_pInfo->FFI_GetPage) |
| 160 return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex); |
| 161 return NULL; |
| 162 } |
| 163 |
| 164 FPDF_PAGE FFI_GetCurrentPage(FPDF_DOCUMENT document) { |
| 165 if (m_pInfo && m_pInfo->FFI_GetCurrentPage) |
| 166 return m_pInfo->FFI_GetCurrentPage(m_pInfo, document); |
| 167 return NULL; |
| 168 } |
| 169 |
| 170 int FFI_GetRotation(FPDF_PAGE page) { |
| 171 if (m_pInfo && m_pInfo->FFI_GetRotation) |
| 172 return m_pInfo->FFI_GetRotation(m_pInfo, page); |
| 173 return 0; |
| 174 } |
| 175 |
| 176 void FFI_ExecuteNamedAction(const FX_CHAR* namedAction) { |
| 177 if (m_pInfo && m_pInfo->FFI_ExecuteNamedAction) |
| 178 m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction); |
| 179 } |
| 180 |
| 181 void FFI_OnSetFieldInputFocus(void* field, |
| 182 FPDF_WIDESTRING focusText, |
| 183 FPDF_DWORD nTextLen, |
| 184 FX_BOOL bFocus) { |
| 185 if (m_pInfo && m_pInfo->FFI_SetTextFieldFocus) |
| 186 m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus); |
| 187 } |
| 188 |
| 189 void FFI_DoURIAction(const FX_CHAR* bsURI) { |
| 190 if (m_pInfo && m_pInfo->FFI_DoURIAction) |
| 191 m_pInfo->FFI_DoURIAction(m_pInfo, bsURI); |
| 192 } |
| 193 |
| 194 void FFI_DoGoToAction(int nPageIndex, |
| 195 int zoomMode, |
| 196 float* fPosArray, |
| 197 int sizeOfArray) { |
| 198 if (m_pInfo && m_pInfo->FFI_DoGoToAction) |
| 199 m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray, |
| 200 sizeOfArray); |
| 201 } |
| 202 |
| 203 FX_BOOL IsJSInitiated() const { return m_pInfo && m_pInfo->m_pJsPlatform; } |
| 204 void SetSDKDocument(CPDFSDK_Document* pFXDoc) { m_pSDKDoc = pFXDoc; } |
| 205 CPDFSDK_Document* GetSDKDocument() const { return m_pSDKDoc; } |
| 206 CPDF_Document* GetPDFDocument() const { return m_pPDFDoc; } |
| 207 CFX_ByteString GetAppName() const { return ""; } |
| 208 IFX_SystemHandler* GetSysHandler() const { return m_pSysHandler; } |
| 209 FPDF_FORMFILLINFO* GetFormFillInfo() const { return m_pInfo; } |
| 210 CJS_RuntimeFactory* GetRuntimeFactory() const { return m_pJSRuntimeFactory; } |
| 211 |
| 212 CFFL_IFormFiller* GetIFormFiller(); // Creates if not present. |
| 213 CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr(); // Creates if not present. |
| 214 IFXJS_Runtime* GetJSRuntime(); // Creates if not present. |
| 215 CPDFSDK_ActionHandler* GetActionHander(); // Creates if not present. |
| 216 |
| 217 private: |
| 218 CPDFSDK_AnnotHandlerMgr* m_pAnnotHandlerMgr; |
| 219 CPDFSDK_ActionHandler* m_pActionHandler; |
| 220 IFXJS_Runtime* m_pJSRuntime; |
| 221 FPDF_FORMFILLINFO* const m_pInfo; |
| 222 CPDFSDK_Document* m_pSDKDoc; |
| 223 CPDF_Document* const m_pPDFDoc; |
| 224 CFFL_IFormFiller* m_pIFormFiller; |
| 225 IFX_SystemHandler* m_pSysHandler; |
| 226 CJS_RuntimeFactory* m_pJSRuntimeFactory; |
| 227 }; |
| 228 |
| 229 class CPDFSDK_Document { |
| 230 public: |
| 231 CPDFSDK_Document(CPDF_Document* pDoc, CPDFDoc_Environment* pEnv); |
| 232 ~CPDFSDK_Document(); |
| 233 |
| 234 CPDFSDK_InterForm* GetInterForm(); |
| 235 CPDF_Document* GetDocument() { return m_pDoc; } |
| 236 |
| 237 CPDFSDK_PageView* GetPageView(CPDF_Page* pPDFPage, FX_BOOL ReNew = TRUE); |
| 238 CPDFSDK_PageView* GetPageView(int nIndex); |
| 239 CPDFSDK_PageView* GetCurrentView(); |
| 240 void ReMovePageView(CPDF_Page* pPDFPage); |
| 241 void UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot); |
| 242 |
| 243 CPDFSDK_Annot* GetFocusAnnot(); |
| 244 |
| 245 IFXJS_Runtime* GetJsRuntime(); |
| 246 |
| 247 FX_BOOL SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag = 0); |
| 248 FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0); |
| 249 |
| 250 FX_BOOL ExtractPages(const CFX_WordArray& arrExtraPages, |
| 251 CPDF_Document* pDstDoc); |
| 252 FX_BOOL InsertPages(int nInsertAt, |
| 253 const CPDF_Document* pSrcDoc, |
| 254 const CFX_WordArray& arrSrcPages); |
| 255 FX_BOOL ReplacePages(int nPage, |
| 256 const CPDF_Document* pSrcDoc, |
| 257 const CFX_WordArray& arrSrcPages); |
| 258 |
| 259 void OnCloseDocument(); |
| 260 |
| 261 int GetPageCount() { return m_pDoc->GetPageCount(); } |
| 262 FX_BOOL GetPermissions(int nFlag); |
| 263 FX_BOOL GetChangeMark() { return m_bChangeMask; } |
| 264 void SetChangeMark() { m_bChangeMask = TRUE; } |
| 265 void ClearChangeMark() { m_bChangeMask = FALSE; } |
| 266 CFX_WideString GetPath(); |
| 267 CPDF_Page* GetPage(int nIndex); |
| 268 CPDFDoc_Environment* GetEnv() { return m_pEnv; } |
| 269 void ProcJavascriptFun(); |
| 270 FX_BOOL ProcOpenAction(); |
| 271 CPDF_OCContext* GetOCContext(); |
| 272 |
| 273 private: |
| 274 std::map<CPDF_Page*, CPDFSDK_PageView*> m_pageMap; |
| 275 CPDF_Document* m_pDoc; |
| 276 CPDFSDK_InterForm* m_pInterForm; |
| 277 CPDFSDK_Annot* m_pFocusAnnot; |
| 278 CPDFDoc_Environment* m_pEnv; |
| 279 CPDF_OCContext* m_pOccontent; |
| 280 FX_BOOL m_bChangeMask; |
| 281 }; |
| 282 class CPDFSDK_PageView final { |
| 283 public: |
| 284 CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, CPDF_Page* page); |
| 285 ~CPDFSDK_PageView(); |
| 286 void PageView_OnDraw(CFX_RenderDevice* pDevice, |
| 287 CPDF_Matrix* pUser2Device, |
| 288 CPDF_RenderOptions* pOptions); |
| 289 CPDF_Annot* GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); |
| 290 CPDFSDK_Annot* GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); |
| 291 CPDF_Annot* GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); |
| 292 CPDFSDK_Annot* GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY); |
| 293 CPDFSDK_Annot* GetFocusAnnot(); |
| 294 void SetFocusAnnot(CPDFSDK_Annot* pSDKAnnot, FX_UINT nFlag = 0) { |
| 295 m_pSDKDoc->SetFocusAnnot(pSDKAnnot, nFlag); |
| 296 } |
| 297 FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0) { |
| 298 return m_pSDKDoc->KillFocusAnnot(nFlag); |
| 299 } |
| 300 FX_BOOL Annot_HasAppearance(CPDF_Annot* pAnnot); |
| 301 |
| 302 CPDFSDK_Annot* AddAnnot(CPDF_Dictionary* pDict); |
| 303 CPDFSDK_Annot* AddAnnot(const FX_CHAR* lpSubType, CPDF_Dictionary* pDict); |
| 304 CPDFSDK_Annot* AddAnnot(CPDF_Annot* pPDFAnnot); |
| 305 FX_BOOL DeleteAnnot(CPDFSDK_Annot* pAnnot); |
| 306 int CountAnnots(); |
| 307 CPDFSDK_Annot* GetAnnot(int nIndex); |
| 308 CPDFSDK_Annot* GetAnnotByDict(CPDF_Dictionary* pDict); |
| 309 CPDF_Page* GetPDFPage() { return m_page; } |
| 310 CPDF_Document* GetPDFDocument(); |
| 311 CPDFSDK_Document* GetSDKDocument() { return m_pSDKDoc; } |
| 312 FX_BOOL OnLButtonDown(const CPDF_Point& point, FX_UINT nFlag); |
| 313 FX_BOOL OnLButtonUp(const CPDF_Point& point, FX_UINT nFlag); |
| 314 FX_BOOL OnChar(int nChar, FX_UINT nFlag); |
| 315 FX_BOOL OnKeyDown(int nKeyCode, int nFlag); |
| 316 FX_BOOL OnKeyUp(int nKeyCode, int nFlag); |
| 317 |
| 318 FX_BOOL OnMouseMove(const CPDF_Point& point, int nFlag); |
| 319 FX_BOOL OnMouseWheel(double deltaX, |
| 320 double deltaY, |
| 321 const CPDF_Point& point, |
| 322 int nFlag); |
| 323 FX_BOOL IsValidAnnot(void* p); |
| 324 void GetCurrentMatrix(CPDF_Matrix& matrix) { matrix = m_curMatrix; } |
| 325 void UpdateRects(CFX_RectArray& rects); |
| 326 void UpdateView(CPDFSDK_Annot* pAnnot); |
| 327 CFX_PtrArray* GetAnnotList() { return &m_fxAnnotArray; } |
| 328 |
| 329 int GetPageIndex(); |
| 330 void LoadFXAnnots(); |
| 331 |
| 332 void SetValid(FX_BOOL bValid) { m_bValid = bValid; } |
| 333 FX_BOOL IsValid() { return m_bValid; } |
| 334 void SetLock(FX_BOOL bLocked) { m_bLocked = bLocked; } |
| 335 FX_BOOL IsLocked() { return m_bLocked; } |
| 336 void TakeOverPage() { m_bTakeOverPage = TRUE; } |
| 337 |
| 338 private: |
| 339 void PageView_OnHighlightFormFields(CFX_RenderDevice* pDevice, |
| 340 CPDFSDK_Widget* pWidget); |
| 341 CPDF_Matrix m_curMatrix; |
| 342 CPDF_Page* m_page; |
| 343 CPDF_AnnotList* m_pAnnotList; |
| 344 // CPDFSDK_Annot* m_pFocusAnnot; |
| 345 CFX_PtrArray m_fxAnnotArray; |
| 346 CPDFSDK_Document* m_pSDKDoc; |
| 347 CPDFSDK_Widget* m_CaptureWidget; |
| 348 FX_BOOL m_bEnterWidget; |
| 349 FX_BOOL m_bExitWidget; |
| 350 FX_BOOL m_bOnWidget; |
| 351 FX_BOOL m_bValid; |
| 352 FX_BOOL m_bLocked; |
| 353 FX_BOOL m_bTakeOverPage; |
| 354 }; |
| 355 |
| 356 template <class TYPE> |
| 357 class CGW_ArrayTemplate : public CFX_ArrayTemplate<TYPE> { |
| 358 public: |
| 359 CGW_ArrayTemplate() {} |
| 360 virtual ~CGW_ArrayTemplate() {} |
| 361 |
| 362 typedef int (*LP_COMPARE)(TYPE p1, TYPE p2); |
| 363 |
| 364 void Sort(LP_COMPARE pCompare, FX_BOOL bAscent = TRUE) { |
| 365 int nSize = this->GetSize(); |
| 366 QuickSort(0, nSize - 1, bAscent, pCompare); |
| 367 } |
| 368 |
| 369 private: |
| 370 void QuickSort(FX_UINT nStartPos, |
| 371 FX_UINT nStopPos, |
| 372 FX_BOOL bAscend, |
| 373 LP_COMPARE pCompare) { |
| 374 if (nStartPos >= nStopPos) |
| 375 return; |
| 376 |
| 377 if ((nStopPos - nStartPos) == 1) { |
| 378 TYPE Value1 = this->GetAt(nStartPos); |
| 379 TYPE Value2 = this->GetAt(nStopPos); |
| 380 |
| 381 int iGreate = (*pCompare)(Value1, Value2); |
| 382 if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0)) { |
| 383 this->SetAt(nStartPos, Value2); |
| 384 this->SetAt(nStopPos, Value1); |
| 385 } |
| 386 return; |
50 } | 387 } |
51 | 388 |
52 void FFI_SetCursor(int nCursorType) | 389 FX_UINT m = nStartPos + (nStopPos - nStartPos) / 2; |
53 { | 390 FX_UINT i = nStartPos; |
54 if (m_pInfo && m_pInfo->FFI_SetCursor) | 391 |
55 m_pInfo->FFI_SetCursor(m_pInfo, nCursorType); | 392 TYPE Value = this->GetAt(m); |
| 393 |
| 394 while (i < m) { |
| 395 TYPE temp = this->GetAt(i); |
| 396 |
| 397 int iGreate = (*pCompare)(temp, Value); |
| 398 if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0)) { |
| 399 this->InsertAt(m + 1, temp); |
| 400 this->RemoveAt(i); |
| 401 m--; |
| 402 } else { |
| 403 i++; |
| 404 } |
56 } | 405 } |
57 | 406 |
58 int FFI_SetTimer(int uElapse, TimerCallback lpTimerFunc) | 407 FX_UINT j = nStopPos; |
59 { | 408 |
60 if (m_pInfo && m_pInfo->FFI_SetTimer) | 409 while (j > m) { |
61 return m_pInfo->FFI_SetTimer(m_pInfo, uElapse, lpTimerFunc); | 410 TYPE temp = this->GetAt(j); |
62 return -1; | 411 |
| 412 int iGreate = (*pCompare)(temp, Value); |
| 413 if ((bAscend && iGreate < 0) || (!bAscend && iGreate > 0)) { |
| 414 this->RemoveAt(j); |
| 415 this->InsertAt(m, temp); |
| 416 m++; |
| 417 } else { |
| 418 j--; |
| 419 } |
63 } | 420 } |
64 | 421 |
65 void FFI_KillTimer(int nTimerID) | 422 if (nStartPos < m) |
66 { | 423 QuickSort(nStartPos, m, bAscend, pCompare); |
67 if (m_pInfo && m_pInfo->FFI_KillTimer) | 424 if (nStopPos > m) |
68 m_pInfo->FFI_KillTimer(m_pInfo, nTimerID); | 425 QuickSort(m, nStopPos, bAscend, pCompare); |
69 } | 426 } |
70 | |
71 FX_SYSTEMTIME FFI_GetLocalTime() const | |
72 { | |
73 FX_SYSTEMTIME fxtime; | |
74 if (m_pInfo && m_pInfo->FFI_GetLocalTime) | |
75 { | |
76 FPDF_SYSTEMTIME systime = m_pInfo->FFI_GetLocalTime(m_pInfo); | |
77 fxtime.wDay = systime.wDay; | |
78 fxtime.wDayOfWeek = systime.wDayOfWeek; | |
79 fxtime.wHour = systime.wHour; | |
80 fxtime.wMilliseconds = systime.wMilliseconds; | |
81 fxtime.wMinute = systime.wMinute; | |
82 fxtime.wMonth = systime.wMonth; | |
83 fxtime.wSecond = systime.wSecond; | |
84 fxtime.wYear = systime.wYear; | |
85 } | |
86 return fxtime; | |
87 } | |
88 | |
89 void FFI_OnChange() | |
90 { | |
91 if (m_pInfo && m_pInfo->FFI_OnChange) | |
92 m_pInfo->FFI_OnChange(m_pInfo); | |
93 } | |
94 | |
95 FX_BOOL FFI_IsSHIFTKeyDown(FX_DWORD nFlag) const | |
96 { | |
97 return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0; | |
98 } | |
99 | |
100 FX_BOOL FFI_IsCTRLKeyDown(FX_DWORD nFlag) const | |
101 { | |
102 return (nFlag & FWL_EVENTFLAG_ControlKey) != 0; | |
103 } | |
104 | |
105 FX_BOOL FFI_IsALTKeyDown(FX_DWORD nFlag) const | |
106 { | |
107 return (nFlag & FWL_EVENTFLAG_AltKey) != 0; | |
108 } | |
109 | |
110 FX_BOOL FFI_IsINSERTKeyDown(FX_DWORD nFlag) const | |
111 { | |
112 return FALSE; | |
113 } | |
114 | |
115 int JS_appAlert(const FX_WCHAR* Msg, const FX_WCHAR* Title, FX_UINT Type, FX
_UINT Icon); | |
116 int JS_appResponse(const FX_WCHAR* Question, const FX_WCHAR* Title, const FX
_WCHAR* Default, | |
117 const FX_WCHAR* cLabel, FPDF_BOOL bPassword, void* respon
se, int length); | |
118 | |
119 void JS_appBeep(int nType) | |
120 { | |
121 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_bee
p) | |
122 m_pInfo->m_pJsPlatform->app_beep(m_pInfo->m_pJsPlatform, nType); | |
123 } | |
124 | |
125 CFX_WideString JS_fieldBrowse(); | |
126 CFX_WideString JS_docGetFilePath(); | |
127 | |
128 void JS_docSubmitForm(void* formData, int length, const FX_WCHAR* URL); | |
129 void JS_docmailForm(void* mailData, int length, FPDF_BOOL bUI, | |
130 const FX_WCHAR* To, const FX_WCHAR* Subject, | |
131 const FX_WCHAR* CC, const FX_WCHAR* BCC, | |
132 const FX_WCHAR* Msg); | |
133 | |
134 void JS_docprint(FPDF_BOOL bUI, int nStart, int nEnd, FPDF_BOOL bSilent, | |
135 FPDF_BOOL bShrinkToFit, FPDF_BOOL bPrintAsImage, | |
136 FPDF_BOOL bReverse ,FPDF_BOOL bAnnotations) | |
137 { | |
138 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_pri
nt) | |
139 m_pInfo->m_pJsPlatform->Doc_print( | |
140 m_pInfo->m_pJsPlatform, bUI, nStart, nEnd, bSilent, bShrinkToFit
, | |
141 bPrintAsImage, bReverse, bAnnotations); | |
142 } | |
143 | |
144 void JS_docgotoPage(int nPageNum) | |
145 { | |
146 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_got
oPage) | |
147 m_pInfo->m_pJsPlatform->Doc_gotoPage(m_pInfo->m_pJsPlatform, nPageNu
m); | |
148 } | |
149 | |
150 FPDF_PAGE FFI_GetPage(FPDF_DOCUMENT document, int nPageIndex) | |
151 { | |
152 if (m_pInfo && m_pInfo->FFI_GetPage) | |
153 return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex); | |
154 return NULL; | |
155 } | |
156 | |
157 FPDF_PAGE FFI_GetCurrentPage(FPDF_DOCUMENT document) | |
158 { | |
159 if (m_pInfo && m_pInfo->FFI_GetCurrentPage) | |
160 return m_pInfo->FFI_GetCurrentPage(m_pInfo, document); | |
161 return NULL; | |
162 } | |
163 | |
164 int FFI_GetRotation(FPDF_PAGE page) | |
165 { | |
166 if (m_pInfo && m_pInfo->FFI_GetRotation) | |
167 return m_pInfo->FFI_GetRotation(m_pInfo, page); | |
168 return 0; | |
169 } | |
170 | |
171 void FFI_ExecuteNamedAction(const FX_CHAR* namedAction) | |
172 { | |
173 if (m_pInfo && m_pInfo->FFI_ExecuteNamedAction) | |
174 m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction); | |
175 } | |
176 | |
177 void FFI_OnSetFieldInputFocus(void* field,FPDF_WIDESTRING focusText, FPDF_DW
ORD nTextLen, FX_BOOL bFocus) | |
178 { | |
179 if (m_pInfo && m_pInfo->FFI_SetTextFieldFocus) | |
180 m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus)
; | |
181 } | |
182 | |
183 void FFI_DoURIAction(const FX_CHAR* bsURI) | |
184 { | |
185 if (m_pInfo && m_pInfo->FFI_DoURIAction) | |
186 m_pInfo->FFI_DoURIAction(m_pInfo, bsURI); | |
187 } | |
188 | |
189 void FFI_DoGoToAction(int nPageIndex, int zoomMode, float* fPosArray, int si
zeOfArray) | |
190 { | |
191 if (m_pInfo && m_pInfo->FFI_DoGoToAction) | |
192 m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray,
sizeOfArray); | |
193 } | |
194 | |
195 FX_BOOL IsJSInitiated() const { return m_pInfo && m_pInfo->m_pJsPlatform; } | |
196 void SetSDKDocument(CPDFSDK_Document* pFXDoc) { m_pSDKDoc = pFXDoc; } | |
197 CPDFSDK_Document* GetSDKDocument() const { return m_pSDKDoc; } | |
198 CPDF_Document* GetPDFDocument() const { return m_pPDFDoc; } | |
199 CFX_ByteString GetAppName() const { return ""; } | |
200 IFX_SystemHandler* GetSysHandler() const { return m_pSysHandler; } | |
201 FPDF_FORMFILLINFO* GetFormFillInfo() const { return m_pInfo;} | |
202 CJS_RuntimeFactory* GetRuntimeFactory() const { return m_pJSRuntimeFactory;
} | |
203 | |
204 CFFL_IFormFiller* GetIFormFiller(); // Creates if not present. | |
205 CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr(); // Creates if not present. | |
206 IFXJS_Runtime* GetJSRuntime(); // Creates if not present. | |
207 CPDFSDK_ActionHandler* GetActionHander(); // Creates if not present. | |
208 | |
209 private: | |
210 CPDFSDK_AnnotHandlerMgr* m_pAnnotHandlerMgr; | |
211 CPDFSDK_ActionHandler* m_pActionHandler; | |
212 IFXJS_Runtime* m_pJSRuntime; | |
213 FPDF_FORMFILLINFO* const m_pInfo; | |
214 CPDFSDK_Document* m_pSDKDoc; | |
215 CPDF_Document* const m_pPDFDoc; | |
216 CFFL_IFormFiller* m_pIFormFiller; | |
217 IFX_SystemHandler* m_pSysHandler; | |
218 CJS_RuntimeFactory* m_pJSRuntimeFactory; | |
219 }; | 427 }; |
220 | 428 |
221 class CPDFSDK_Document | |
222 { | |
223 public: | |
224 CPDFSDK_Document(CPDF_Document* pDoc, CPDFDoc_Environment* pEnv); | |
225 ~CPDFSDK_Document(); | |
226 | |
227 CPDFSDK_InterForm* GetInterForm() ; | |
228 CPDF_Document* GetDocument() {return m_pDoc;} | |
229 | |
230 CPDFSDK_PageView* GetPageView(CPDF_Page* pPDFPage, FX_BOOL ReNew = TRU
E); | |
231 CPDFSDK_PageView* GetPageView(int nIndex); | |
232 CPDFSDK_PageView* GetCurrentView(); | |
233 void ReMovePageView(CPDF_Page* pPDFPage); | |
234 void UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_An
not* pAnnot); | |
235 | |
236 CPDFSDK_Annot* GetFocusAnnot(); | |
237 | |
238 IFXJS_Runtime * GetJsRuntime(); | |
239 | |
240 FX_BOOL SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag =
0); | |
241 FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0); | |
242 | |
243 FX_BOOL ExtractPages(const CFX_WordArray &arrExtraPages, CPD
F_Document* pDstDoc); | |
244 FX_BOOL InsertPages(int nInsertAt, const CPDF_Document* pSrc
Doc, const CFX_WordArray &arrSrcPages); | |
245 FX_BOOL ReplacePages(int nPage, const CPDF_Document* pSrcDoc
, const CFX_WordArray &arrSrcPages); | |
246 | |
247 void OnCloseDocument(); | |
248 | |
249 int GetPageCount() {return m_pDoc->GetPageCount();} | |
250 FX_BOOL GetPermissions(int nFlag); | |
251 FX_BOOL GetChangeMark() {return m_bChangeMask;} | |
252 void SetChangeMark() {m_bChangeMask = TRUE;} | |
253 void ClearChangeMark() {m_bChangeMask= FALSE;} | |
254 CFX_WideString GetPath() ; | |
255 CPDF_Page* GetPage(int nIndex); | |
256 CPDFDoc_Environment * GetEnv() {return m_pEnv; } | |
257 void ProcJavascriptFun(); | |
258 FX_BOOL ProcOpenAction(); | |
259 CPDF_OCContext* GetOCContext(); | |
260 private: | |
261 std::map<CPDF_Page*, CPDFSDK_PageView*> m_pageMap; | |
262 CPDF_Document* m_pDoc; | |
263 CPDFSDK_InterForm* m_pInterForm; | |
264 CPDFSDK_Annot* m_pFocusAnnot; | |
265 CPDFDoc_Environment* m_pEnv; | |
266 CPDF_OCContext* m_pOccontent; | |
267 FX_BOOL m_bChangeMask; | |
268 }; | |
269 class CPDFSDK_PageView final | |
270 { | |
271 public: | |
272 CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,CPDF_Page* page); | |
273 ~CPDFSDK_PageView(); | |
274 void PageView_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,CP
DF_RenderOptions* pOptions) ; | |
275 CPDF_Annot* GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT
pageY); | |
276 CPDFSDK_Annot* GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT p
ageY); | |
277 CPDF_Annot* GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT
pageY); | |
278 CPDFSDK_Annot* GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT
pageY); | |
279 CPDFSDK_Annot* GetFocusAnnot() ; | |
280 void SetFocusAnnot(CPDFSDK_Annot* pSDKAnnot,FX_UI
NT nFlag = 0) {m_pSDKDoc->SetFocusAnnot(pSDKAnnot, nFlag);} | |
281 FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0) {return m_
pSDKDoc->KillFocusAnnot(nFlag);} | |
282 FX_BOOL Annot_HasAppearance(CPDF_Annot* pAnnot); | |
283 | |
284 CPDFSDK_Annot* AddAnnot(CPDF_Dictionary * pDict); | |
285 CPDFSDK_Annot* AddAnnot(const FX_CHAR* lpSubType,CPDF_Dicti
onary * pDict); | |
286 CPDFSDK_Annot* AddAnnot(CPDF_Annot * pPDFAnnot); | |
287 FX_BOOL DeleteAnnot(CPDFSDK_Annot* pAnnot); | |
288 int CountAnnots(); | |
289 CPDFSDK_Annot* GetAnnot(int nIndex); | |
290 CPDFSDK_Annot* GetAnnotByDict(CPDF_Dictionary * pDict); | |
291 CPDF_Page* GetPDFPage(){return m_page;} | |
292 CPDF_Document* GetPDFDocument(); | |
293 CPDFSDK_Document* GetSDKDocument() {return m_pSDKDoc;} | |
294 FX_BOOL OnLButtonDown(const CPDF_Point & point, FX_UINT nFla
g); | |
295 FX_BOOL OnLButtonUp(const CPDF_Point & point, FX_UINT nFlag)
; | |
296 FX_BOOL OnChar(int nChar, FX_UINT nFlag); | |
297 FX_BOOL OnKeyDown(int nKeyCode, int nFlag); | |
298 FX_BOOL OnKeyUp(int nKeyCode, int nFlag); | |
299 | |
300 FX_BOOL OnMouseMove(const CPDF_Point & point, int nFlag); | |
301 FX_BOOL OnMouseWheel(double deltaX, double deltaY,const CPDF
_Point& point, int nFlag); | |
302 FX_BOOL IsValidAnnot(void* p); | |
303 void GetCurrentMatrix(CPDF_Matrix& matrix) {matrix = m_cu
rMatrix;} | |
304 void UpdateRects(CFX_RectArray& rects); | |
305 void UpdateView(CPDFSDK_Annot* pAnnot); | |
306 CFX_PtrArray* GetAnnotList(){ return &m_fxAnnotArray; } | |
307 | |
308 int GetPageIndex(); | |
309 void LoadFXAnnots(); | |
310 | |
311 void SetValid(FX_BOOL bValid) {m_bValid = bValid;} | |
312 FX_BOOL IsValid() {return m_bValid;} | |
313 void SetLock(FX_BOOL bLocked) {m_bLocked= bLocked;} | |
314 FX_BOOL IsLocked() {return m_bLocked;} | |
315 void TakeOverPage() {m_bTakeOverPage = TRUE;} | |
316 private: | |
317 void PageView_OnHighlightFormFields(CFX_RenderDevice* pDevice, CPDFSDK_Widge
t* pWidget); | |
318 CPDF_Matrix m_curMatrix; | |
319 CPDF_Page* m_page; | |
320 CPDF_AnnotList* m_pAnnotList; | |
321 //CPDFSDK_Annot* m_pFocusAnnot; | |
322 CFX_PtrArray m_fxAnnotArray; | |
323 CPDFSDK_Document* m_pSDKDoc; | |
324 CPDFSDK_Widget* m_CaptureWidget; | |
325 FX_BOOL m_bEnterWidget; | |
326 FX_BOOL m_bExitWidget; | |
327 FX_BOOL m_bOnWidget; | |
328 FX_BOOL m_bValid; | |
329 FX_BOOL m_bLocked; | |
330 FX_BOOL m_bTakeOverPage; | |
331 }; | |
332 | |
333 | |
334 template<class TYPE> | |
335 class CGW_ArrayTemplate : public CFX_ArrayTemplate<TYPE> | |
336 { | |
337 public: | |
338 CGW_ArrayTemplate(){} | |
339 virtual ~CGW_ArrayTemplate(){} | |
340 | |
341 typedef int (*LP_COMPARE)(TYPE p1, TYPE p2); | |
342 | |
343 void Sort(LP_COMPARE pCompare, FX_BOOL bAscent = TRUE) | |
344 { | |
345 int nSize = this->GetSize(); | |
346 QuickSort(0, nSize -1, bAscent, pCompare); | |
347 } | |
348 | |
349 private: | |
350 void QuickSort(FX_UINT nStartPos, FX_UINT nStopPos, FX_BOOL bAscend, LP_COMP
ARE pCompare) | |
351 { | |
352 if (nStartPos >= nStopPos) return; | |
353 | |
354 if ((nStopPos - nStartPos) == 1) | |
355 { | |
356 TYPE Value1 = this->GetAt(nStartPos); | |
357 TYPE Value2 = this->GetAt(nStopPos); | |
358 | |
359 int iGreate = (*pCompare)(Value1, Value2); | |
360 if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0)) | |
361 { | |
362 this->SetAt(nStartPos, Value2); | |
363 this->SetAt(nStopPos, Value1); | |
364 } | |
365 return; | |
366 } | |
367 | |
368 FX_UINT m = nStartPos + (nStopPos - nStartPos) / 2; | |
369 FX_UINT i = nStartPos; | |
370 | |
371 TYPE Value = this->GetAt(m); | |
372 | |
373 while (i < m) | |
374 { | |
375 TYPE temp = this->GetAt(i); | |
376 | |
377 int iGreate = (*pCompare)(temp, Value); | |
378 if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0)) | |
379 { | |
380 this->InsertAt(m+1, temp); | |
381 this->RemoveAt(i); | |
382 m--; | |
383 } | |
384 else | |
385 { | |
386 i++; | |
387 } | |
388 } | |
389 | |
390 FX_UINT j = nStopPos; | |
391 | |
392 while (j > m) | |
393 { | |
394 TYPE temp = this->GetAt(j); | |
395 | |
396 int iGreate = (*pCompare)(temp, Value); | |
397 if ((bAscend && iGreate < 0) || (!bAscend && iGreate > 0)) | |
398 { | |
399 this->RemoveAt(j); | |
400 this->InsertAt(m, temp); | |
401 m++; | |
402 } | |
403 else | |
404 { | |
405 j--; | |
406 } | |
407 } | |
408 | |
409 if (nStartPos < m) QuickSort(nStartPos, m, bAscend, pCompare); | |
410 if (nStopPos > m) QuickSort(m, nStopPos, bAscend, pCompare); | |
411 } | |
412 }; | |
413 | |
414 #endif // FPDFSDK_INCLUDE_FSDK_MGR_H_ | 429 #endif // FPDFSDK_INCLUDE_FSDK_MGR_H_ |
OLD | NEW |