OLD | NEW |
| (Empty) |
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_SRC_FXFA_PARSER_XFA_UTILS_H_ | |
8 #define XFA_SRC_FXFA_PARSER_XFA_UTILS_H_ | |
9 | |
10 #include "xfa/include/fxfa/fxfa_basic.h" | |
11 #include "xfa/src/fde/xml/fde_xml.h" | |
12 | |
13 class CXFA_LocaleValue; | |
14 | |
15 FX_BOOL XFA_FDEExtension_ResolveNamespaceQualifier( | |
16 IFDE_XMLElement* pNode, | |
17 const CFX_WideStringC& wsQualifier, | |
18 CFX_WideString& wsNamespaceURI); | |
19 template <class NodeType, class TraverseStrategy> | |
20 class CXFA_NodeIteratorTemplate { | |
21 public: | |
22 CXFA_NodeIteratorTemplate(NodeType* pRootNode = NULL) : m_pRoot(pRootNode) { | |
23 if (pRootNode) { | |
24 m_NodeStack.Push(pRootNode); | |
25 } | |
26 } | |
27 FX_BOOL Init(NodeType* pRootNode) { | |
28 if (!pRootNode) { | |
29 return FALSE; | |
30 } | |
31 m_pRoot = pRootNode; | |
32 m_NodeStack.RemoveAll(); | |
33 m_NodeStack.Push(pRootNode); | |
34 return TRUE; | |
35 } | |
36 void Clear() { m_NodeStack.RemoveAll(); } | |
37 void Reset() { | |
38 Clear(); | |
39 if (m_pRoot) { | |
40 m_NodeStack.Push(m_pRoot); | |
41 } | |
42 } | |
43 FX_BOOL SetCurrent(NodeType* pCurNode) { | |
44 m_NodeStack.RemoveAll(); | |
45 if (pCurNode) { | |
46 CFX_StackTemplate<NodeType*> revStack; | |
47 NodeType* pNode; | |
48 for (pNode = pCurNode; pNode && pNode != m_pRoot; | |
49 pNode = TraverseStrategy::GetParent(pNode)) { | |
50 revStack.Push(pNode); | |
51 } | |
52 if (!pNode) { | |
53 return FALSE; | |
54 } | |
55 revStack.Push(m_pRoot); | |
56 while (revStack.GetSize()) { | |
57 m_NodeStack.Push(*revStack.GetTopElement()); | |
58 revStack.Pop(); | |
59 } | |
60 } | |
61 return TRUE; | |
62 } | |
63 NodeType* GetCurrent() const { | |
64 return m_NodeStack.GetSize() ? *m_NodeStack.GetTopElement() : NULL; | |
65 } | |
66 NodeType* GetRoot() const { return m_pRoot; } | |
67 NodeType* MoveToPrev() { | |
68 int32_t nStackLength = m_NodeStack.GetSize(); | |
69 if (nStackLength == 1) { | |
70 return NULL; | |
71 } else if (nStackLength > 1) { | |
72 NodeType* pCurItem = *m_NodeStack.GetTopElement(); | |
73 m_NodeStack.Pop(); | |
74 NodeType* pParentItem = *m_NodeStack.GetTopElement(); | |
75 NodeType* pParentFirstChildItem = | |
76 TraverseStrategy::GetFirstChild(pParentItem); | |
77 if (pCurItem == pParentFirstChildItem) { | |
78 return pParentItem; | |
79 } | |
80 NodeType *pPrevItem = pParentFirstChildItem, *pPrevItemNext = NULL; | |
81 for (; pPrevItem; pPrevItem = pPrevItemNext) { | |
82 pPrevItemNext = TraverseStrategy::GetNextSibling(pPrevItem); | |
83 if (!pPrevItemNext || pPrevItemNext == pCurItem) { | |
84 break; | |
85 } | |
86 } | |
87 m_NodeStack.Push(pPrevItem); | |
88 } else { | |
89 m_NodeStack.RemoveAll(); | |
90 if (m_pRoot) { | |
91 m_NodeStack.Push(m_pRoot); | |
92 } | |
93 } | |
94 if (m_NodeStack.GetSize() > 0) { | |
95 NodeType* pChildItem = *m_NodeStack.GetTopElement(); | |
96 while ((pChildItem = TraverseStrategy::GetFirstChild(pChildItem)) != | |
97 NULL) { | |
98 while (NodeType* pNextItem = | |
99 TraverseStrategy::GetNextSibling(pChildItem)) { | |
100 pChildItem = pNextItem; | |
101 } | |
102 m_NodeStack.Push(pChildItem); | |
103 } | |
104 return *m_NodeStack.GetTopElement(); | |
105 } | |
106 return NULL; | |
107 } | |
108 NodeType* MoveToNext() { | |
109 NodeType** ppNode = NULL; | |
110 NodeType* pCurrent = GetCurrent(); | |
111 while (m_NodeStack.GetSize() > 0) { | |
112 while ((ppNode = m_NodeStack.GetTopElement())) { | |
113 if (pCurrent != *ppNode) { | |
114 return *ppNode; | |
115 } | |
116 NodeType* pChild = TraverseStrategy::GetFirstChild(*ppNode); | |
117 if (pChild == NULL) { | |
118 break; | |
119 } | |
120 m_NodeStack.Push(pChild); | |
121 } | |
122 while ((ppNode = m_NodeStack.GetTopElement())) { | |
123 NodeType* pNext = TraverseStrategy::GetNextSibling(*ppNode); | |
124 m_NodeStack.Pop(); | |
125 if (m_NodeStack.GetSize() == 0) { | |
126 break; | |
127 } | |
128 if (pNext) { | |
129 m_NodeStack.Push(pNext); | |
130 break; | |
131 } | |
132 } | |
133 } | |
134 return NULL; | |
135 } | |
136 NodeType* SkipChildrenAndMoveToNext() { | |
137 NodeType** ppNode = NULL; | |
138 while ((ppNode = m_NodeStack.GetTopElement())) { | |
139 NodeType* pNext = TraverseStrategy::GetNextSibling(*ppNode); | |
140 m_NodeStack.Pop(); | |
141 if (m_NodeStack.GetSize() == 0) { | |
142 break; | |
143 } | |
144 if (pNext) { | |
145 m_NodeStack.Push(pNext); | |
146 break; | |
147 } | |
148 } | |
149 return GetCurrent(); | |
150 } | |
151 | |
152 protected: | |
153 NodeType* m_pRoot; | |
154 CFX_StackTemplate<NodeType*> m_NodeStack; | |
155 }; | |
156 template <class KeyType> | |
157 class CXFA_PtrSetTemplate : private CFX_MapPtrToPtr { | |
158 public: | |
159 CXFA_PtrSetTemplate() : CFX_MapPtrToPtr(10) {} | |
160 | |
161 int GetCount() const { return CFX_MapPtrToPtr::GetCount(); } | |
162 | |
163 FX_BOOL IsEmpty() const { return CFX_MapPtrToPtr::IsEmpty(); } | |
164 | |
165 FX_BOOL Lookup(KeyType key) const { | |
166 void* pValue = NULL; | |
167 return CFX_MapPtrToPtr::Lookup((void*)key, pValue); | |
168 } | |
169 | |
170 FX_BOOL operator[](KeyType key) { return Lookup(key); } | |
171 | |
172 void Add(KeyType key) { CFX_MapPtrToPtr::SetAt((void*)key, (void*)key); } | |
173 | |
174 FX_BOOL RemoveKey(KeyType key) { | |
175 return CFX_MapPtrToPtr::RemoveKey((void*)key); | |
176 } | |
177 | |
178 void RemoveAll() { CFX_MapPtrToPtr::RemoveAll(); } | |
179 | |
180 FX_POSITION GetStartPosition() const { | |
181 return CFX_MapPtrToPtr::GetStartPosition(); | |
182 } | |
183 | |
184 void GetNextAssoc(FX_POSITION& rNextPosition, KeyType& rKey) const { | |
185 void* pKey = NULL; | |
186 void* pValue = NULL; | |
187 CFX_MapPtrToPtr::GetNextAssoc(rNextPosition, pKey, pValue); | |
188 rKey = (KeyType)(uintptr_t)pKey; | |
189 } | |
190 }; | |
191 class CXFA_Node; | |
192 class CXFA_WidgetData; | |
193 | |
194 CXFA_Node* XFA_CreateUIChild(CXFA_Node* pNode, XFA_ELEMENT& eWidgetType); | |
195 CXFA_LocaleValue XFA_GetLocaleValue(CXFA_WidgetData* pWidgetData); | |
196 CFX_WideString XFA_NumericLimit(const CFX_WideString& wsValue, | |
197 int32_t iLead, | |
198 int32_t iTread); | |
199 FX_DOUBLE XFA_WideStringToDouble(const CFX_WideString& wsStringVal); | |
200 FX_DOUBLE XFA_ByteStringToDouble(const CFX_ByteStringC& szStringVal); | |
201 int32_t XFA_MapRotation(int32_t nRotation); | |
202 | |
203 FX_BOOL XFA_RecognizeRichText(IFDE_XMLElement* pRichTextXMLNode); | |
204 void XFA_GetPlainTextFromRichText(IFDE_XMLNode* pXMLNode, | |
205 CFX_WideString& wsPlainText); | |
206 FX_BOOL XFA_FieldIsMultiListBox(CXFA_Node* pFieldNode); | |
207 IFX_Stream* XFA_CreateWideTextRead(const CFX_WideString& wsBuffer); | |
208 FX_BOOL XFA_IsLayoutElement(XFA_ELEMENT eElement, | |
209 FX_BOOL bLayoutContainer = FALSE); | |
210 FX_BOOL XFA_IsTakingupSpace(XFA_ATTRIBUTEENUM ePresence); | |
211 FX_BOOL XFA_IsFlowingLayout(XFA_ATTRIBUTEENUM eLayout); | |
212 FX_BOOL XFA_IsHorizontalFlow(XFA_ATTRIBUTEENUM eLayout); | |
213 void XFA_DataExporter_DealWithDataGroupNode(CXFA_Node* pDataNode); | |
214 void XFA_DataExporter_RegenerateFormFile(CXFA_Node* pNode, | |
215 IFX_Stream* pStream, | |
216 const FX_CHAR* pChecksum = NULL, | |
217 FX_BOOL bSaveXML = FALSE); | |
218 | |
219 #endif // XFA_SRC_FXFA_PARSER_XFA_UTILS_H_ | |
OLD | NEW |