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 _XFA_DOCUMENT_H 8 #define _XFA_DOCUMENT_H 9 10 class CXFA_Document; 11 class CXFA_LayoutItem; 12 class CXFA_LayoutProcessor; 13 class CXFA_Node; 14 class IXFA_DocLayout; 15 class IXFA_DocParser; 16 class IXFA_LayoutPage; 17 class IXFA_Notify; 18 class IXFA_ObjFactory; 19 class IXFA_PageContent; 20 class IXFA_ScriptContext; 21 22 enum XFA_VERSION { 23 XFA_VERSION_UNKNOWN = 0, 24 XFA_VERSION_200 = 200, 25 XFA_VERSION_202 = 202, 26 XFA_VERSION_204 = 204, 27 XFA_VERSION_205 = 205, 28 XFA_VERSION_206 = 206, 29 XFA_VERSION_207 = 207, 30 XFA_VERSION_208 = 208, 31 XFA_VERSION_300 = 300, 32 XFA_VERSION_301 = 301, 33 XFA_VERSION_303 = 303, 34 XFA_VERSION_306 = 306, 35 XFA_VERSION_DEFAULT = XFA_VERSION_303, 36 XFA_VERSION_MIN = 200, 37 XFA_VERSION_MAX = 400, 38 }; 39 40 #define XFA_LAYOUTSTATUS_Visible 0x0001 41 #define XFA_LAYOUTSTATUS_Viewable 0x0010 42 #define XFA_LAYOUTSTATUS_Printable 0x0020 43 enum XFA_NODEEVENT { 44 XFA_NODEEVENT_Ready, 45 XFA_NODEEVENT_ValueChanging, 46 XFA_NODEEVENT_ValueChanged, 47 XFA_NODEEVENT_ChildAdded, 48 XFA_NODEEVENT_ChildRemoved, 49 }; 50 enum XFA_PAGEEVENT { 51 XFA_PAGEEVENT_PageAdded, 52 XFA_PAGEEVENT_PageRemoved, 53 }; 54 enum XFA_LAYOUTEVENT { 55 XFA_LAYOUTEVENT_ItemAdded, 56 XFA_LAYOUTEVENT_ItemRemoving, 57 XFA_LAYOUTEVENT_RectChanged, 58 XFA_LAYOUTEVENT_StatusChanged, 59 }; 60 enum XFA_LAYOUTRESULT { 61 XFA_LAYOUTRESULT_Continue, 62 XFA_LAYOUTRESULT_Done, 63 XFA_LAYOUTRESULT_NextContent, 64 }; 65 #define XFA_LAYOUTNOTIFY_StrictHeight 0x0001 66 #define XFA_LAYOUTNOTIFY_NoParentBreak 0x0002 67 class IXFA_Notify { 68 public: ~IXFA_Notify()69 virtual ~IXFA_Notify() {} 70 virtual void OnPageEvent(IXFA_LayoutPage* pSender, 71 XFA_PAGEEVENT eEvent, 72 void* pParam = NULL) = 0; 73 74 virtual void OnNodeEvent(CXFA_Node* pSender, 75 XFA_NODEEVENT eEvent, 76 void* pParam = NULL, 77 void* pParam2 = NULL, 78 void* pParam3 = NULL, 79 void* pParam4 = NULL) = 0; 80 virtual void OnWidgetDataEvent(CXFA_WidgetData* pSender, 81 FX_DWORD dwEvent, 82 void* pParam = NULL, 83 void* pAdditional = NULL, 84 void* pAdditional2 = NULL) = 0; 85 86 virtual CXFA_LayoutItem* OnCreateLayoutItem(CXFA_Node* pNode) = 0; 87 virtual void OnLayoutEvent(IXFA_DocLayout* pLayout, 88 CXFA_LayoutItem* pSender, 89 XFA_LAYOUTEVENT eEvent, 90 void* pParam = NULL, 91 void* pParam2 = NULL) = 0; 92 virtual void StartFieldDrawLayout(CXFA_Node* pItem, 93 FX_FLOAT& fCalcWidth, 94 FX_FLOAT& fCalcHeight) = 0; 95 virtual FX_BOOL FindSplitPos(CXFA_Node* pItem, 96 int32_t iBlockIndex, 97 FX_FLOAT& fCalcHeightPos) = 0; 98 virtual FX_BOOL RunScript(CXFA_Node* pScript, CXFA_Node* pFormItem) = 0; 99 virtual int32_t ExecEventByDeepFirst(CXFA_Node* pFormNode, 100 XFA_EVENTTYPE eEventType, 101 FX_BOOL bIsFormReady = FALSE, 102 FX_BOOL bRecursive = TRUE, 103 CXFA_WidgetAcc* pExclude = NULL) = 0; 104 virtual void AddCalcValidate(CXFA_Node* pNode) = 0; 105 virtual IXFA_Doc* GetHDOC() = 0; 106 virtual IXFA_DocProvider* GetDocProvider() = 0; 107 virtual IXFA_AppProvider* GetAppProvider() = 0; 108 virtual IXFA_WidgetHandler* GetWidgetHandler() = 0; 109 virtual IXFA_Widget* GetHWidget(CXFA_LayoutItem* pLayoutItem) = 0; 110 virtual void OpenDropDownList(IXFA_Widget* hWidget) = 0; 111 virtual CFX_WideString GetCurrentDateTime() = 0; 112 virtual void ResetData(CXFA_WidgetData* pWidgetData = NULL) = 0; 113 virtual int32_t GetLayoutStatus() = 0; 114 virtual void RunNodeInitialize(CXFA_Node* pNode) = 0; 115 virtual void RunSubformIndexChange(CXFA_Node* pSubformNode) = 0; 116 virtual CXFA_Node* GetFocusWidgetNode() = 0; 117 virtual void SetFocusWidgetNode(CXFA_Node* pNode) = 0; 118 }; 119 class IXFA_ObjFactory { 120 public: ~IXFA_ObjFactory()121 virtual ~IXFA_ObjFactory() {} 122 virtual CXFA_Node* CreateNode(FX_DWORD dwPacket, XFA_ELEMENT eElement) = 0; 123 virtual CXFA_Node* CreateNode(XFA_LPCPACKETINFO pPacket, 124 XFA_ELEMENT eElement) = 0; 125 }; 126 #define XFA_DOCFLAG_StrictScoping 0x0001 127 #define XFA_DOCFLAG_HasInteractive 0x0002 128 #define XFA_DOCFLAG_Interactive 0x0004 129 #define XFA_DOCFLAG_Scripting 0x0008 130 class CScript_DataWindow; 131 class CScript_EventPseudoModel; 132 class CScript_HostPseudoModel; 133 class CScript_LogPseudoModel; 134 class CScript_LayoutPseudoModel; 135 class CScript_SignaturePseudoModel; 136 class CXFA_Document : public IXFA_ObjFactory { 137 public: 138 CXFA_Document(IXFA_DocParser* pParser); 139 ~CXFA_Document(); GetRoot()140 CXFA_Node* GetRoot() const { return m_pRootNode; } GetParser()141 IXFA_DocParser* GetParser() const { return m_pParser; } 142 IXFA_Notify* GetNotify() const; 143 void SetRoot(CXFA_Node* pNewRoot); 144 CXFA_Object* GetXFANode(const CFX_WideStringC& wsNodeName); 145 CXFA_Object* GetXFANode(FX_DWORD wsNodeNameHash); 146 void AddPurgeNode(CXFA_Node* pNode); 147 FX_BOOL RemovePurgeNode(CXFA_Node* pNode); 148 void PurgeNodes(); HasFlag(FX_DWORD dwFlag)149 FX_BOOL HasFlag(FX_DWORD dwFlag) { return (m_dwDocFlags & dwFlag) == dwFlag; } 150 void SetFlag(FX_DWORD dwFlag, FX_BOOL bOn = TRUE); 151 FX_BOOL IsInteractive(); GetCurVersionMode()152 XFA_VERSION GetCurVersionMode() { return m_eCurVersionMode; } 153 XFA_VERSION RecognizeXFAVersionNumber(CFX_WideString& wsTemplateNS); 154 CXFA_LocaleMgr* GetLocalMgr(); 155 virtual CXFA_Node* CreateNode(FX_DWORD dwPacket, XFA_ELEMENT eElement); 156 virtual CXFA_Node* CreateNode(XFA_LPCPACKETINFO pPacket, 157 XFA_ELEMENT eElement); 158 void DoProtoMerge(); 159 CXFA_Node* GetNodeByID(CXFA_Node* pRoot, const CFX_WideStringC& wsID); 160 void DoDataMerge(); 161 void DoDataRemerge(FX_BOOL bDoDataMerge); 162 CXFA_Node* DataMerge_CopyContainer(CXFA_Node* pTemplateNode, 163 CXFA_Node* pFormNode, 164 CXFA_Node* pDataScope, 165 FX_BOOL bOneInstance = FALSE, 166 FX_BOOL bDataMerge = TRUE, 167 FX_BOOL bUpLevel = TRUE); 168 void DataMerge_UpdateBindingRelations(CXFA_Node* pFormUpdateRoot); 169 CXFA_Node* GetNotBindNode(CXFA_ObjArray& arrayNodes); 170 CXFA_LayoutProcessor* GetLayoutProcessor(); 171 IXFA_DocLayout* GetDocLayout(); 172 IXFA_ScriptContext* InitScriptContext(FXJSE_HRUNTIME hRuntime); 173 IXFA_ScriptContext* GetScriptContext(); 174 void ClearLayoutData(); 175 176 CFX_MapPtrTemplate<FX_DWORD, CXFA_Node*> m_rgGlobalBinding; 177 CXFA_NodeArray m_pPendingPageSet; 178 179 protected: 180 IXFA_DocParser* m_pParser; 181 IXFA_ScriptContext* m_pScriptContext; 182 CXFA_LayoutProcessor* m_pLayoutProcessor; 183 CXFA_Node* m_pRootNode; 184 CXFA_LocaleMgr* m_pLocalMgr; 185 CScript_DataWindow* m_pScriptDataWindow; 186 CScript_EventPseudoModel* m_pScriptEvent; 187 CScript_HostPseudoModel* m_pScriptHost; 188 CScript_LogPseudoModel* m_pScriptLog; 189 CScript_LayoutPseudoModel* m_pScriptLayout; 190 CScript_SignaturePseudoModel* m_pScriptSignature; 191 CXFA_NodeSet m_rgPurgeNodes; 192 XFA_VERSION m_eCurVersionMode; 193 FX_DWORD m_dwDocFlags; 194 friend class CXFA_SimpleParser; 195 }; 196 #endif 197