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_FXFA_CXFA_FFDOCVIEW_H_ 8 #define XFA_FXFA_CXFA_FFDOCVIEW_H_ 9 10 #include <deque> 11 #include <memory> 12 #include <vector> 13 14 #include "core/fxcrt/observed_ptr.h" 15 #include "core/fxcrt/unowned_ptr.h" 16 #include "xfa/fxfa/cxfa_eventparam.h" 17 #include "xfa/fxfa/cxfa_ffdoc.h" 18 #include "xfa/fxfa/cxfa_ffwidget.h" 19 #include "xfa/fxfa/fxfa.h" 20 21 class CXFA_BindItems; 22 class CXFA_FFDoc; 23 class CXFA_FFWidgetHandler; 24 class CXFA_Node; 25 class CXFA_ReadyNodeIterator; 26 class CXFA_Subform; 27 class CXFA_ViewLayoutItem; 28 29 extern const XFA_AttributeValue gs_EventActivity[]; 30 enum XFA_DOCVIEW_LAYOUTSTATUS { 31 XFA_DOCVIEW_LAYOUTSTATUS_None, 32 XFA_DOCVIEW_LAYOUTSTATUS_Start, 33 XFA_DOCVIEW_LAYOUTSTATUS_FormInitialize, 34 XFA_DOCVIEW_LAYOUTSTATUS_FormInitCalculate, 35 XFA_DOCVIEW_LAYOUTSTATUS_FormInitValidate, 36 XFA_DOCVIEW_LAYOUTSTATUS_FormFormReady, 37 XFA_DOCVIEW_LAYOUTSTATUS_Doing, 38 XFA_DOCVIEW_LAYOUTSTATUS_PagesetInitialize, 39 XFA_DOCVIEW_LAYOUTSTATUS_PagesetInitCalculate, 40 XFA_DOCVIEW_LAYOUTSTATUS_PagesetInitValidate, 41 XFA_DOCVIEW_LAYOUTSTATUS_PagesetFormReady, 42 XFA_DOCVIEW_LAYOUTSTATUS_LayoutReady, 43 XFA_DOCVIEW_LAYOUTSTATUS_DocReady, 44 XFA_DOCVIEW_LAYOUTSTATUS_End 45 }; 46 47 class CXFA_FFDocView { 48 public: 49 explicit CXFA_FFDocView(CXFA_FFDoc* pDoc); 50 ~CXFA_FFDocView(); 51 GetDoc()52 CXFA_FFDoc* GetDoc() const { return m_pDoc.Get(); } 53 int32_t StartLayout(); 54 int32_t DoLayout(); 55 void StopLayout(); GetLayoutStatus()56 int32_t GetLayoutStatus() const { return m_iStatus; } 57 58 void UpdateDocView(); 59 void UpdateUIDisplay(CXFA_Node* pNode, CXFA_FFWidget* pExcept); 60 61 int32_t CountPageViews() const; 62 CXFA_FFPageView* GetPageView(int32_t nIndex) const; 63 64 void ResetNode(CXFA_Node* pNode); 65 CXFA_FFWidgetHandler* GetWidgetHandler(); 66 std::unique_ptr<CXFA_ReadyNodeIterator> CreateReadyNodeIterator(); GetFocusWidget()67 CXFA_FFWidget* GetFocusWidget() const { return m_pFocusWidget.Get(); } 68 bool SetFocus(CXFA_FFWidget* pNewFocus); 69 CXFA_FFWidget* GetWidgetForNode(CXFA_Node* node); 70 CXFA_FFWidget* GetWidgetByName(const WideString& wsName, 71 CXFA_FFWidget* pRefWidget); 72 CXFA_LayoutProcessor* GetXFALayout() const; 73 void OnPageEvent(CXFA_ViewLayoutItem* pSender, uint32_t dwEvent); LockUpdate()74 void LockUpdate() { m_iLock++; } UnlockUpdate()75 void UnlockUpdate() { m_iLock--; } 76 void InvalidateRect(CXFA_FFPageView* pPageView, 77 const CFX_RectF& rtInvalidate); 78 void RunDocClose(); 79 80 void ProcessValueChanged(CXFA_Node* node); 81 void SetChangeMark(); 82 83 void AddValidateNode(CXFA_Node* node); 84 void AddCalculateNodeNotify(CXFA_Node* pNodeChange); 85 void AddCalculateNode(CXFA_Node* node); 86 87 bool RunLayout(); 88 void AddNewFormNode(CXFA_Node* pNode); 89 void AddIndexChangedSubform(CXFA_Node* pNode); GetFocusNode()90 CXFA_Node* GetFocusNode() const { return m_pFocusNode.Get(); } 91 void SetFocusNode(CXFA_Node* pNode); 92 void DeleteLayoutItem(CXFA_FFWidget* pWidget); 93 XFA_EventError ExecEventActivityByDeepFirst(CXFA_Node* pFormNode, 94 XFA_EVENTTYPE eEventType, 95 bool bIsFormReady, 96 bool bRecursive); 97 AddBindItem(CXFA_BindItems * item)98 void AddBindItem(CXFA_BindItems* item) { m_BindItems.push_back(item); } 99 100 bool m_bLayoutEvent = false; 101 bool m_bInLayoutStatus = false; 102 std::vector<WideString> m_arrNullTestMsg; 103 ResetLayoutProcessor()104 void ResetLayoutProcessor() { m_pXFADocLayout.Release(); } 105 106 private: 107 bool RunEventLayoutReady(); 108 void RunBindItems(); 109 void InitCalculate(CXFA_Node* pNode); 110 void InitLayout(CXFA_Node* pNode); 111 size_t RunCalculateRecursive(size_t index); 112 void ShowNullTestMsg(); 113 bool ResetSingleNodeData(CXFA_Node* pNode); 114 CXFA_Subform* GetRootSubform(); 115 IsUpdateLocked()116 bool IsUpdateLocked() const { return m_iLock > 0; } 117 bool InitValidate(CXFA_Node* pNode); 118 bool RunValidate(); 119 XFA_EventError RunCalculateWidgets(); 120 void RunSubformIndexChange(); 121 122 UnownedPtr<CXFA_FFDoc> const m_pDoc; 123 std::unique_ptr<CXFA_FFWidgetHandler> m_pWidgetHandler; 124 UnownedPtr<CXFA_LayoutProcessor> m_pXFADocLayout; 125 UnownedPtr<CXFA_Node> m_pFocusNode; 126 ObservedPtr<CXFA_FFWidget> m_pFocusWidget; 127 std::deque<CXFA_Node*> m_ValidateNodes; 128 std::vector<CXFA_Node*> m_CalculateNodes; 129 std::deque<CXFA_BindItems*> m_BindItems; 130 std::deque<CXFA_Node*> m_NewAddedNodes; 131 std::deque<CXFA_Node*> m_IndexChangedSubforms; 132 XFA_DOCVIEW_LAYOUTSTATUS m_iStatus = XFA_DOCVIEW_LAYOUTSTATUS_None; 133 int32_t m_iLock = 0; 134 }; 135 136 #endif // XFA_FXFA_CXFA_FFDOCVIEW_H_ 137