Home | History | Annotate | Download | only in fpdfxfa
      1 // 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 
      7 #ifndef FPDFXFA_DOC_H_
      8 #define FPDFXFA_DOC_H_
      9 
     10 #include "public/fpdfview.h"
     11 #include "xfa/include/fxfa/fxfa.h"
     12 
     13 class CPDFXFA_App;
     14 class CPDFXFA_Document;
     15 class CPDFXFA_Page;
     16 class CPDFSDK_Document;
     17 class CPDFDoc_Environment;
     18 class IJS_Runtime;
     19 class IJS_Context;
     20 class IXFA_DocHandler;
     21 
     22 class CPDFXFA_Document : public IXFA_DocProvider {
     23  public:
     24   CPDFXFA_Document(CPDF_Document* pPDFDoc, CPDFXFA_App* pProvider);
     25   ~CPDFXFA_Document();
     26 
     27   FX_BOOL LoadXFADoc();
     28   CPDFXFA_App* GetApp() { return m_pApp; }
     29   CPDF_Document* GetPDFDoc() { return m_pPDFDoc; }
     30   IXFA_Doc* GetXFADoc() { return m_pXFADoc; }
     31   IXFA_DocView* GetXFADocView() { return m_pXFADocView; }
     32 
     33   int GetPageCount();
     34   CPDFXFA_Page* GetPage(int page_index);
     35   CPDFXFA_Page* GetPage(IXFA_PageView* pPage);
     36   void RemovePage(CPDFXFA_Page* page);
     37   int GetDocType() { return m_iDocType; }
     38 
     39   CPDFSDK_Document* GetSDKDocument(CPDFDoc_Environment* pFormFillEnv);
     40 
     41   void FXRect2PDFRect(const CFX_RectF& fxRectF, CPDF_Rect& pdfRect);
     42 
     43   virtual void SetChangeMark(IXFA_Doc* hDoc);
     44   virtual FX_BOOL GetChangeMark(IXFA_Doc* hDoc);
     45   // used in dynamic xfa, dwFlags refer to XFA_INVALIDATE_XXX macros.
     46   virtual void InvalidateRect(IXFA_PageView* pPageView,
     47                               const CFX_RectF& rt,
     48                               FX_DWORD dwFlags = 0);
     49   // used in static xfa, dwFlags refer to XFA_INVALIDATE_XXX macros.
     50   virtual void InvalidateRect(IXFA_Widget* hWidget, FX_DWORD dwFlags = 0);
     51   // show or hide caret
     52   virtual void DisplayCaret(IXFA_Widget* hWidget,
     53                             FX_BOOL bVisible,
     54                             const CFX_RectF* pRtAnchor);
     55   // dwPos: (0:bottom 1:top)
     56   virtual FX_BOOL GetPopupPos(IXFA_Widget* hWidget,
     57                               FX_FLOAT fMinPopup,
     58                               FX_FLOAT fMaxPopup,
     59                               const CFX_RectF& rtAnchor,
     60                               CFX_RectF& rtPopup);
     61   virtual FX_BOOL PopupMenu(IXFA_Widget* hWidget,
     62                             CFX_PointF ptPopup,
     63                             const CFX_RectF* pRectExclude = NULL);
     64 
     65   // dwFlags XFA_PAGEVIEWEVENT_Added, XFA_PAGEVIEWEVENT_Removing
     66   virtual void PageViewEvent(IXFA_PageView* pPageView, FX_DWORD dwFlags);
     67   // dwEvent refer to XFA_WIDGETEVENT_XXX
     68   virtual void WidgetEvent(IXFA_Widget* hWidget,
     69                            CXFA_WidgetAcc* pWidgetData,
     70                            FX_DWORD dwEvent,
     71                            void* pParam = NULL,
     72                            void* pAdditional = NULL);
     73 
     74   // return true if render it.
     75   virtual FX_BOOL RenderCustomWidget(IXFA_Widget* hWidget,
     76                                      CFX_Graphics* pGS,
     77                                      CFX_Matrix* pMatrix,
     78                                      const CFX_RectF& rtUI) {
     79     return FALSE;
     80   }
     81 
     82   // host method
     83   virtual int32_t CountPages(IXFA_Doc* hDoc);
     84   virtual int32_t GetCurrentPage(IXFA_Doc* hDoc);
     85   virtual void SetCurrentPage(IXFA_Doc* hDoc, int32_t iCurPage);
     86   virtual FX_BOOL IsCalculationsEnabled(IXFA_Doc* hDoc);
     87   virtual void SetCalculationsEnabled(IXFA_Doc* hDoc, FX_BOOL bEnabled);
     88   virtual void GetTitle(IXFA_Doc* hDoc, CFX_WideString& wsTitle);
     89   virtual void SetTitle(IXFA_Doc* hDoc, const CFX_WideStringC& wsTitle);
     90   virtual void ExportData(IXFA_Doc* hDoc,
     91                           const CFX_WideStringC& wsFilePath,
     92                           FX_BOOL bXDP = TRUE);
     93   virtual void ImportData(IXFA_Doc* hDoc, const CFX_WideStringC& wsFilePath);
     94   virtual void GotoURL(IXFA_Doc* hDoc,
     95                        const CFX_WideStringC& bsURL,
     96                        FX_BOOL bAppend = TRUE);
     97   virtual FX_BOOL IsValidationsEnabled(IXFA_Doc* hDoc);
     98   virtual void SetValidationsEnabled(IXFA_Doc* hDoc, FX_BOOL bEnabled);
     99   virtual void SetFocusWidget(IXFA_Doc* hDoc, IXFA_Widget* hWidget);
    100   virtual void Print(IXFA_Doc* hDoc,
    101                      int32_t nStartPage,
    102                      int32_t nEndPage,
    103                      FX_DWORD dwOptions);
    104 
    105   // LayoutPseudo method
    106   virtual int32_t AbsPageCountInBatch(IXFA_Doc* hDoc) { return 0; }
    107   virtual int32_t AbsPageInBatch(IXFA_Doc* hDoc, IXFA_Widget* hWidget) {
    108     return 0;
    109   }
    110   virtual int32_t SheetCountInBatch(IXFA_Doc* hDoc) { return 0; }
    111   virtual int32_t SheetInBatch(IXFA_Doc* hDoc, IXFA_Widget* hWidget) {
    112     return 0;
    113   }
    114 
    115   // SignaturePseudoModel method
    116   // TODO:
    117   virtual int32_t Verify(
    118       IXFA_Doc* hDoc,
    119       CXFA_Node* pSigNode,
    120       FX_BOOL
    121           bUsed = TRUE /*, SecurityHandler* pHandler, SignatureInfo &info*/) {
    122     return 0;
    123   }
    124   virtual FX_BOOL Sign(
    125       IXFA_Doc* hDoc,
    126       CXFA_NodeList* pNodeList,
    127       const CFX_WideStringC& wsExpression,
    128       const CFX_WideStringC& wsXMLIdent,
    129       const CFX_WideStringC& wsValue = FX_WSTRC(L"open"),
    130       FX_BOOL
    131           bUsed = TRUE /*, SecurityHandler* pHandler = NULL, SignatureInfo &info*/) {
    132     return 0;
    133   }
    134   virtual CXFA_NodeList* Enumerate(IXFA_Doc* hDoc) { return 0; }
    135   virtual FX_BOOL Clear(IXFA_Doc* hDoc,
    136                         CXFA_Node* pSigNode,
    137                         FX_BOOL bCleared = TRUE) {
    138     return 0;
    139   }
    140 
    141   // Get document path
    142   virtual void GetURL(IXFA_Doc* hDoc, CFX_WideString& wsDocURL);
    143   virtual FX_ARGB GetHighlightColor(IXFA_Doc* hDoc);
    144   virtual void AddDoRecord(IXFA_Widget* hWidget);
    145   /**
    146    *Submit data to email, http, ftp.
    147    * @param[in] hDoc The document handler.
    148    * @param[in] eFormat Determines the format in which the data will be
    149    *submitted. XFA_ATTRIBUTEENUM_Xdp, XFA_ATTRIBUTEENUM_Xml...
    150    * @param[in] wsTarget The URL to which the data will be submitted.
    151    * @param[in] eEncoding The encoding of text content.
    152    * @param[in] pXDPContent Controls what subset of the data is submitted, used
    153    *only when the format property is xdp.
    154    * @param[in] bEmbedPDF, specifies whether PDF is embedded in the submitted
    155    *content or not.
    156    */
    157   virtual FX_BOOL SubmitData(IXFA_Doc* hDoc, CXFA_Submit submit);
    158 
    159   virtual FX_BOOL CheckWord(IXFA_Doc* hDoc, const CFX_ByteStringC& sWord) {
    160     return FALSE;
    161   }
    162   virtual FX_BOOL GetSuggestWords(IXFA_Doc* hDoc,
    163                                   const CFX_ByteStringC& sWord,
    164                                   CFX_ByteStringArray& sSuggest) {
    165     return FALSE;
    166   }
    167 
    168   // Get PDF javascript object, set the object to hValue.
    169   virtual FX_BOOL GetPDFScriptObject(IXFA_Doc* hDoc,
    170                                      const CFX_ByteStringC& utf8Name,
    171                                      FXJSE_HVALUE hValue);
    172 
    173   virtual FX_BOOL GetGlobalProperty(IXFA_Doc* hDoc,
    174                                     const CFX_ByteStringC& szPropName,
    175                                     FXJSE_HVALUE hValue);
    176   virtual FX_BOOL SetGlobalProperty(IXFA_Doc* hDoc,
    177                                     const CFX_ByteStringC& szPropName,
    178                                     FXJSE_HVALUE hValue);
    179   virtual CPDF_Document* OpenPDF(IXFA_Doc* hDoc,
    180                                  IFX_FileRead* pFile,
    181                                  FX_BOOL bTakeOverFile) {
    182     return NULL;
    183   }
    184 
    185   virtual IFX_FileRead* OpenLinkedFile(IXFA_Doc* hDoc,
    186                                        const CFX_WideString& wsLink);
    187 
    188   FX_BOOL _GetHValueByName(const CFX_ByteStringC& utf8Name,
    189                            FXJSE_HVALUE hValue,
    190                            IJS_Runtime* runTime);
    191   FX_BOOL _OnBeforeNotifySumbit();
    192   void _OnAfterNotifySumbit();
    193   FX_BOOL _NotifySubmit(FX_BOOL bPrevOrPost);
    194   FX_BOOL _SubmitData(IXFA_Doc* hDoc, CXFA_Submit submit);
    195   FX_BOOL _MailToInfo(CFX_WideString& csURL,
    196                       CFX_WideString& csToAddress,
    197                       CFX_WideString& csCCAddress,
    198                       CFX_WideString& csBCCAddress,
    199                       CFX_WideString& csSubject,
    200                       CFX_WideString& csMsg);
    201   FX_BOOL _ExportSubmitFile(FPDF_FILEHANDLER* ppFileHandler,
    202                             int fileType,
    203                             FPDF_DWORD encodeType,
    204                             FPDF_DWORD flag = 0x01111111);
    205   void _ToXFAContentFlags(CFX_WideString csSrcContent, FPDF_DWORD& flag);
    206   void _ClearChangeMark();
    207 
    208  private:
    209   void CloseXFADoc(IXFA_DocHandler* pDoc) {
    210     if (pDoc) {
    211       pDoc->CloseDoc(m_pXFADoc);
    212       pDoc->ReleaseDoc(m_pXFADoc);
    213       m_pXFADoc = NULL;
    214       m_pXFADocView = NULL;
    215     }
    216   }
    217 
    218   int m_iDocType;
    219   CPDF_Document* m_pPDFDoc;
    220   CPDFSDK_Document* m_pSDKDoc;
    221   IXFA_Doc* m_pXFADoc;
    222   IXFA_DocView* m_pXFADocView;
    223   CPDFXFA_App* m_pApp;
    224   IJS_Context* m_pJSContext;
    225   CFX_ArrayTemplate<CPDFXFA_Page*> m_XFAPageList;
    226 };
    227 
    228 #endif  // FPDFXFA_DOC_H_
    229