blob: f67a880a36fb40ac8f448e21838ec0607029406f [file] [log] [blame]
Lei Zhang94293682016-01-27 18:27:56 -08001// Copyright 2014 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
dsinclair4d29e782016-10-04 14:02:47 -07007#ifndef FPDFSDK_FPDFXFA_CPDFXFA_DOCUMENT_H_
8#define FPDFSDK_FPDFXFA_CPDFXFA_DOCUMENT_H_
Lei Zhang94293682016-01-27 18:27:56 -08009
dsinclaira440bb32016-09-14 07:01:54 -070010#include <memory>
11
dsinclairbec76922016-09-29 16:52:30 -070012#include "fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h"
dsinclair5b493092016-09-29 20:20:24 -070013#include "xfa/fxfa/xfa_ffdoc.h"
weili625ad662016-06-15 11:21:33 -070014
dsinclair79db6092016-09-14 07:27:21 -070015class CPDFSDK_Document;
16class CPDFSDK_Environment;
Lei Zhang94293682016-01-27 18:27:56 -080017class CPDFXFA_App;
Lei Zhang94293682016-01-27 18:27:56 -080018class CPDFXFA_Page;
dsinclairdf4bc592016-03-31 20:34:43 -070019class CXFA_FFDocHandler;
dsinclair79db6092016-09-14 07:27:21 -070020class IJS_Runtime;
21class IJS_Context;
Lei Zhang94293682016-01-27 18:27:56 -080022
dsinclaira440bb32016-09-14 07:01:54 -070023enum LoadStatus {
24 FXFA_LOADSTATUS_PRELOAD = 0,
25 FXFA_LOADSTATUS_LOADING,
26 FXFA_LOADSTATUS_LOADED,
27 FXFA_LOADSTATUS_CLOSING,
28 FXFA_LOADSTATUS_CLOSED
29};
30
31class CPDFXFA_Document {
Lei Zhang94293682016-01-27 18:27:56 -080032 public:
dsinclaircedaa552016-08-24 11:12:19 -070033 CPDFXFA_Document(std::unique_ptr<CPDF_Document> pPDFDoc,
34 CPDFXFA_App* pProvider);
dsinclaira440bb32016-09-14 07:01:54 -070035 ~CPDFXFA_Document();
Lei Zhang94293682016-01-27 18:27:56 -080036
37 FX_BOOL LoadXFADoc();
dsinclaircedaa552016-08-24 11:12:19 -070038 CPDF_Document* GetPDFDoc() { return m_pPDFDoc.get(); }
weili2d5b0202016-08-03 11:06:49 -070039 CXFA_FFDoc* GetXFADoc() { return m_pXFADoc.get(); }
dsinclairdf4bc592016-03-31 20:34:43 -070040 CXFA_FFDocView* GetXFADocView() { return m_pXFADocView; }
dsinclair9f206f02016-09-20 12:17:42 -070041 int GetDocType() const { return m_iDocType; }
Tom Sepez744da702016-03-15 12:43:09 -070042
dsinclaira939bfe2016-09-22 13:18:45 -070043 CPDFSDK_Document* GetSDKDoc() const { return m_pSDKDoc.get(); }
44 void SetSDKDoc(std::unique_ptr<CPDFSDK_Document> pSDKDoc);
45
Tom Sepez744da702016-03-15 12:43:09 -070046 void DeletePage(int page_index);
dsinclair9f206f02016-09-20 12:17:42 -070047 int GetPageCount() const;
Lei Zhang94293682016-01-27 18:27:56 -080048
dsinclair9f206f02016-09-20 12:17:42 -070049 CPDFXFA_Page* GetXFAPage(int page_index);
50 CPDFXFA_Page* GetXFAPage(CXFA_FFPageView* pPage) const;
51
52 void RemovePage(CPDFXFA_Page* page);
Lei Zhang94293682016-01-27 18:27:56 -080053
dsinclair89f8fa82016-09-14 06:11:08 -070054 void ClearChangeMark();
Lei Zhang94293682016-01-27 18:27:56 -080055
dsinclaira440bb32016-09-14 07:01:54 -070056 protected:
57 friend class CPDFXFA_DocEnvironment;
dsinclair221caf62016-04-04 12:08:40 -070058
dsinclaira440bb32016-09-14 07:01:54 -070059 int GetOriginalPageCount() const { return m_nPageCount; }
60 void SetOriginalPageCount(int count) {
61 m_nPageCount = count;
62 m_XFAPageList.SetSize(count);
63 }
64
65 LoadStatus GetLoadStatus() const { return m_nLoadStatus; }
66
67 CFX_ArrayTemplate<CPDFXFA_Page*>* GetXFAPageList() { return &m_XFAPageList; }
68
69 private:
dsinclairdf4bc592016-03-31 20:34:43 -070070 void CloseXFADoc(CXFA_FFDocHandler* pDoc) {
Lei Zhang94293682016-01-27 18:27:56 -080071 if (pDoc) {
dsinclair221caf62016-04-04 12:08:40 -070072 m_pXFADoc->CloseDoc();
weili2d5b0202016-08-03 11:06:49 -070073 m_pXFADoc.reset();
dsinclair221caf62016-04-04 12:08:40 -070074 m_pXFADocView = nullptr;
Lei Zhang94293682016-01-27 18:27:56 -080075 }
76 }
77
78 int m_iDocType;
dsinclaircedaa552016-08-24 11:12:19 -070079
dsinclaircedaa552016-08-24 11:12:19 -070080 std::unique_ptr<CPDF_Document> m_pPDFDoc;
dsinclaira440bb32016-09-14 07:01:54 -070081 // |m_pSDKDoc| must be destroyed before |m_pPDFDoc| since it needs to access
82 // it to kill focused annotations.
weili2d5b0202016-08-03 11:06:49 -070083 std::unique_ptr<CPDFSDK_Document> m_pSDKDoc;
84 std::unique_ptr<CXFA_FFDoc> m_pXFADoc;
85 CXFA_FFDocView* m_pXFADocView; // not owned.
86 CPDFXFA_App* const m_pApp;
Lei Zhang94293682016-01-27 18:27:56 -080087 CFX_ArrayTemplate<CPDFXFA_Page*> m_XFAPageList;
jinming_wanga1cef702016-03-18 16:35:40 +080088 LoadStatus m_nLoadStatus;
89 int m_nPageCount;
dsinclaira440bb32016-09-14 07:01:54 -070090
91 // Must be destroy before |m_pSDKDoc|.
92 CPDFXFA_DocEnvironment m_DocEnv;
Lei Zhang94293682016-01-27 18:27:56 -080093};
94
dsinclair4d29e782016-10-04 14:02:47 -070095#endif // FPDFSDK_FPDFXFA_CPDFXFA_DOCUMENT_H_