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