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_FPDFXFA_INCLUDE_FPDFXFA_DOC_H_ | 7 #ifndef FPDFSDK_FPDFXFA_INCLUDE_FPDFXFA_DOC_H_ |
8 #define FPDFSDK_FPDFXFA_INCLUDE_FPDFXFA_DOC_H_ | 8 #define FPDFSDK_FPDFXFA_INCLUDE_FPDFXFA_DOC_H_ |
9 | 9 |
| 10 #include <memory> |
| 11 |
| 12 #include "fpdfsdk/fpdfxfa/include/cpdfxfa_docenvironment.h" |
10 #include "xfa/fxfa/include/xfa_ffdoc.h" | 13 #include "xfa/fxfa/include/xfa_ffdoc.h" |
11 | 14 |
12 #include <memory> | |
13 #include <vector> | |
14 | |
15 #include "public/fpdfview.h" | |
16 #include "xfa/fxfa/include/fxfa.h" | |
17 #include "xfa/fxfa/include/xfa_ffdochandler.h" | |
18 | |
19 class CPDFXFA_App; | 15 class CPDFXFA_App; |
20 class CPDFXFA_Document; | |
21 class CPDFXFA_Page; | 16 class CPDFXFA_Page; |
22 class CPDFSDK_Document; | 17 class CPDFSDK_Document; |
23 class CPDFDoc_Environment; | 18 class CPDFDoc_Environment; |
24 class IJS_Runtime; | |
25 class IJS_Context; | |
26 class CXFA_FFDocHandler; | 19 class CXFA_FFDocHandler; |
27 | 20 |
28 class CPDFXFA_Document : public IXFA_DocProvider { | 21 enum LoadStatus { |
| 22 FXFA_LOADSTATUS_PRELOAD = 0, |
| 23 FXFA_LOADSTATUS_LOADING, |
| 24 FXFA_LOADSTATUS_LOADED, |
| 25 FXFA_LOADSTATUS_CLOSING, |
| 26 FXFA_LOADSTATUS_CLOSED |
| 27 }; |
| 28 |
| 29 class CPDFXFA_Document { |
29 public: | 30 public: |
30 CPDFXFA_Document(std::unique_ptr<CPDF_Document> pPDFDoc, | 31 CPDFXFA_Document(std::unique_ptr<CPDF_Document> pPDFDoc, |
31 CPDFXFA_App* pProvider); | 32 CPDFXFA_App* pProvider); |
32 ~CPDFXFA_Document() override; | 33 ~CPDFXFA_Document(); |
33 | 34 |
34 FX_BOOL LoadXFADoc(); | 35 FX_BOOL LoadXFADoc(); |
35 CPDF_Document* GetPDFDoc() { return m_pPDFDoc.get(); } | 36 CPDF_Document* GetPDFDoc() { return m_pPDFDoc.get(); } |
36 CXFA_FFDoc* GetXFADoc() { return m_pXFADoc.get(); } | 37 CXFA_FFDoc* GetXFADoc() { return m_pXFADoc.get(); } |
37 CXFA_FFDocView* GetXFADocView() { return m_pXFADocView; } | 38 CXFA_FFDocView* GetXFADocView() { return m_pXFADocView; } |
38 | 39 |
39 int GetPageCount(); | 40 int GetPageCount(); |
40 CPDFXFA_Page* GetPage(int page_index); | 41 CPDFXFA_Page* GetPage(int page_index); |
| 42 CPDFXFA_Page* GetPage(CXFA_FFPageView* pPage); |
41 | 43 |
42 void DeletePage(int page_index); | 44 void DeletePage(int page_index); |
43 void RemovePage(CPDFXFA_Page* page); | 45 void RemovePage(CPDFXFA_Page* page); |
44 int GetDocType() { return m_iDocType; } | 46 int GetDocType() { return m_iDocType; } |
45 | 47 |
46 CPDFSDK_Document* GetSDKDocument(CPDFDoc_Environment* pFormFillEnv); | 48 CPDFSDK_Document* GetSDKDocument(CPDFDoc_Environment* pFormFillEnv); |
47 | 49 |
48 // IXFA_DocProvider | |
49 void SetChangeMark(CXFA_FFDoc* hDoc) override; | |
50 // used in dynamic xfa, dwFlags refer to XFA_INVALIDATE_XXX macros. | |
51 void InvalidateRect(CXFA_FFPageView* pPageView, | |
52 const CFX_RectF& rt, | |
53 uint32_t dwFlags) override; | |
54 // show or hide caret | |
55 void DisplayCaret(CXFA_FFWidget* hWidget, | |
56 FX_BOOL bVisible, | |
57 const CFX_RectF* pRtAnchor) override; | |
58 // dwPos: (0:bottom 1:top) | |
59 FX_BOOL GetPopupPos(CXFA_FFWidget* hWidget, | |
60 FX_FLOAT fMinPopup, | |
61 FX_FLOAT fMaxPopup, | |
62 const CFX_RectF& rtAnchor, | |
63 CFX_RectF& rtPopup) override; | |
64 FX_BOOL PopupMenu(CXFA_FFWidget* hWidget, CFX_PointF ptPopup) override; | |
65 | |
66 // dwFlags XFA_PAGEVIEWEVENT_Added, XFA_PAGEVIEWEVENT_Removing | |
67 void PageViewEvent(CXFA_FFPageView* pPageView, uint32_t dwFlags) override; | |
68 void WidgetPostAdd(CXFA_FFWidget* hWidget, | |
69 CXFA_WidgetAcc* pWidgetData) override; | |
70 void WidgetPreRemove(CXFA_FFWidget* hWidget, | |
71 CXFA_WidgetAcc* pWidgetData) override; | |
72 | |
73 // Host method | |
74 int32_t CountPages(CXFA_FFDoc* hDoc) override; | |
75 int32_t GetCurrentPage(CXFA_FFDoc* hDoc) override; | |
76 void SetCurrentPage(CXFA_FFDoc* hDoc, int32_t iCurPage) override; | |
77 FX_BOOL IsCalculationsEnabled(CXFA_FFDoc* hDoc) override; | |
78 void SetCalculationsEnabled(CXFA_FFDoc* hDoc, FX_BOOL bEnabled) override; | |
79 void GetTitle(CXFA_FFDoc* hDoc, CFX_WideString& wsTitle) override; | |
80 void SetTitle(CXFA_FFDoc* hDoc, const CFX_WideString& wsTitle) override; | |
81 void ExportData(CXFA_FFDoc* hDoc, | |
82 const CFX_WideString& wsFilePath, | |
83 FX_BOOL bXDP) override; | |
84 void GotoURL(CXFA_FFDoc* hDoc, | |
85 const CFX_WideString& bsURL, | |
86 FX_BOOL bAppend) override; | |
87 FX_BOOL IsValidationsEnabled(CXFA_FFDoc* hDoc) override; | |
88 void SetValidationsEnabled(CXFA_FFDoc* hDoc, FX_BOOL bEnabled) override; | |
89 void SetFocusWidget(CXFA_FFDoc* hDoc, CXFA_FFWidget* hWidget) override; | |
90 void Print(CXFA_FFDoc* hDoc, | |
91 int32_t nStartPage, | |
92 int32_t nEndPage, | |
93 uint32_t dwOptions) override; | |
94 FX_ARGB GetHighlightColor(CXFA_FFDoc* hDoc) override; | |
95 | |
96 /** | |
97 *Submit data to email, http, ftp. | |
98 * @param[in] hDoc The document handler. | |
99 * @param[in] eFormat Determines the format in which the data will be | |
100 *submitted. XFA_ATTRIBUTEENUM_Xdp, XFA_ATTRIBUTEENUM_Xml... | |
101 * @param[in] wsTarget The URL to which the data will be submitted. | |
102 * @param[in] eEncoding The encoding of text content. | |
103 * @param[in] pXDPContent Controls what subset of the data is submitted, used | |
104 *only when the format property is xdp. | |
105 * @param[in] bEmbedPDF, specifies whether PDF is embedded in the submitted | |
106 *content or not. | |
107 */ | |
108 FX_BOOL SubmitData(CXFA_FFDoc* hDoc, CXFA_Submit submit) override; | |
109 | |
110 FX_BOOL GetGlobalProperty(CXFA_FFDoc* hDoc, | |
111 const CFX_ByteStringC& szPropName, | |
112 CFXJSE_Value* pValue) override; | |
113 FX_BOOL SetGlobalProperty(CXFA_FFDoc* hDoc, | |
114 const CFX_ByteStringC& szPropName, | |
115 CFXJSE_Value* pValue) override; | |
116 | |
117 IFX_FileRead* OpenLinkedFile(CXFA_FFDoc* hDoc, | |
118 const CFX_WideString& wsLink) override; | |
119 | |
120 void ClearChangeMark(); | 50 void ClearChangeMark(); |
121 | 51 |
| 52 protected: |
| 53 friend class CPDFXFA_DocEnvironment; |
| 54 |
| 55 CPDFSDK_Document* GetSDKDoc() { return m_pSDKDoc.get(); } |
| 56 int GetOriginalPageCount() const { return m_nPageCount; } |
| 57 void SetOriginalPageCount(int count) { |
| 58 m_nPageCount = count; |
| 59 m_XFAPageList.SetSize(count); |
| 60 } |
| 61 |
| 62 LoadStatus GetLoadStatus() const { return m_nLoadStatus; } |
| 63 |
| 64 CFX_ArrayTemplate<CPDFXFA_Page*>* GetXFAPageList() { return &m_XFAPageList; } |
| 65 |
122 private: | 66 private: |
123 enum LoadStatus { | |
124 FXFA_LOADSTATUS_PRELOAD = 0, | |
125 FXFA_LOADSTATUS_LOADING, | |
126 FXFA_LOADSTATUS_LOADED, | |
127 FXFA_LOADSTATUS_CLOSING, | |
128 FXFA_LOADSTATUS_CLOSED | |
129 }; | |
130 | |
131 void CloseXFADoc(CXFA_FFDocHandler* pDoc) { | 67 void CloseXFADoc(CXFA_FFDocHandler* pDoc) { |
132 if (pDoc) { | 68 if (pDoc) { |
133 m_pXFADoc->CloseDoc(); | 69 m_pXFADoc->CloseDoc(); |
134 m_pXFADoc.reset(); | 70 m_pXFADoc.reset(); |
135 m_pXFADocView = nullptr; | 71 m_pXFADocView = nullptr; |
136 } | 72 } |
137 } | 73 } |
138 | 74 |
139 CPDFXFA_Page* GetPage(CXFA_FFPageView* pPage); | |
140 FX_BOOL OnBeforeNotifySubmit(); | |
141 void OnAfterNotifySubmit(); | |
142 FX_BOOL NotifySubmit(FX_BOOL bPrevOrPost); | |
143 FX_BOOL SubmitDataInternal(CXFA_FFDoc* hDoc, CXFA_Submit submit); | |
144 FX_BOOL MailToInfo(CFX_WideString& csURL, | |
145 CFX_WideString& csToAddress, | |
146 CFX_WideString& csCCAddress, | |
147 CFX_WideString& csBCCAddress, | |
148 CFX_WideString& csSubject, | |
149 CFX_WideString& csMsg); | |
150 FX_BOOL ExportSubmitFile(FPDF_FILEHANDLER* ppFileHandler, | |
151 int fileType, | |
152 FPDF_DWORD encodeType, | |
153 FPDF_DWORD flag); | |
154 void ToXFAContentFlags(CFX_WideString csSrcContent, FPDF_DWORD& flag); | |
155 | |
156 int m_iDocType; | 75 int m_iDocType; |
157 | 76 |
158 // |m_pSDKDoc| has to be released before |m_pPDFDoc| since it needs to access | 77 std::unique_ptr<CPDF_Document> m_pPDFDoc; |
| 78 // |m_pSDKDoc| must be destroyed before |m_pPDFDoc| since it needs to access |
159 // it to kill focused annotations. | 79 // it to kill focused annotations. |
160 std::unique_ptr<CPDF_Document> m_pPDFDoc; | |
161 std::unique_ptr<CPDFSDK_Document> m_pSDKDoc; | 80 std::unique_ptr<CPDFSDK_Document> m_pSDKDoc; |
162 std::unique_ptr<CXFA_FFDoc> m_pXFADoc; | 81 std::unique_ptr<CXFA_FFDoc> m_pXFADoc; |
163 CXFA_FFDocView* m_pXFADocView; // not owned. | 82 CXFA_FFDocView* m_pXFADocView; // not owned. |
164 CPDFXFA_App* const m_pApp; | 83 CPDFXFA_App* const m_pApp; |
165 IJS_Context* m_pJSContext; | |
166 CFX_ArrayTemplate<CPDFXFA_Page*> m_XFAPageList; | 84 CFX_ArrayTemplate<CPDFXFA_Page*> m_XFAPageList; |
167 LoadStatus m_nLoadStatus; | 85 LoadStatus m_nLoadStatus; |
168 int m_nPageCount; | 86 int m_nPageCount; |
| 87 |
| 88 // Must be destroy before |m_pSDKDoc|. |
| 89 CPDFXFA_DocEnvironment m_DocEnv; |
169 }; | 90 }; |
170 | 91 |
171 #endif // FPDFSDK_FPDFXFA_INCLUDE_FPDFXFA_DOC_H_ | 92 #endif // FPDFSDK_FPDFXFA_INCLUDE_FPDFXFA_DOC_H_ |
OLD | NEW |