Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: xfa/fxfa/parser/xfa_object_imp.cpp

Issue 2018733002: Clean up part of CXFA_Node class (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "xfa/fxfa/parser/xfa_object.h" 7 #include "xfa/fxfa/parser/xfa_object.h"
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 10 matching lines...) Expand all
21 #include "xfa/fxfa/parser/xfa_document.h" 21 #include "xfa/fxfa/parser/xfa_document.h"
22 #include "xfa/fxfa/parser/xfa_document_layout_imp.h" 22 #include "xfa/fxfa/parser/xfa_document_layout_imp.h"
23 #include "xfa/fxfa/parser/xfa_localemgr.h" 23 #include "xfa/fxfa/parser/xfa_localemgr.h"
24 #include "xfa/fxfa/parser/xfa_parser.h" 24 #include "xfa/fxfa/parser/xfa_parser.h"
25 #include "xfa/fxfa/parser/xfa_parser_imp.h" 25 #include "xfa/fxfa/parser/xfa_parser_imp.h"
26 #include "xfa/fxfa/parser/xfa_script.h" 26 #include "xfa/fxfa/parser/xfa_script.h"
27 #include "xfa/fxfa/parser/xfa_script_imp.h" 27 #include "xfa/fxfa/parser/xfa_script_imp.h"
28 #include "xfa/fxfa/parser/xfa_utils.h" 28 #include "xfa/fxfa/parser/xfa_utils.h"
29 #include "xfa/fxjse/cfxjse_arguments.h" 29 #include "xfa/fxjse/cfxjse_arguments.h"
30 30
31 namespace {
32
33 void XFA_DeleteWideString(void* pData) {
34 delete static_cast<CFX_WideString*>(pData);
35 }
36
37 void XFA_CopyWideString(void*& pData) {
38 if (pData) {
39 CFX_WideString* pNewData = new CFX_WideString(*(CFX_WideString*)pData);
40 pData = pNewData;
41 }
42 }
43
44 XFA_MAPDATABLOCKCALLBACKINFO deleteWideStringCallBack = {XFA_DeleteWideString,
Tom Sepez 2016/05/26 23:55:04 nit: const FA_MAPDATABLOCKCALLBACKINFO
Wei Li 2016/05/27 00:51:45 Let's defer this change since it requires changing
45 XFA_CopyWideString};
46
47 XFA_OBJECTTYPE XFA_GetElementObjectType(XFA_ELEMENT eElement) {
48 return (XFA_OBJECTTYPE)XFA_GetElementByID(eElement)->eObjectType;
Tom Sepez 2016/05/26 23:55:04 nit: static cast.
Wei Li 2016/05/27 00:51:46 Done.
49 }
50
51 void XFA_DataNodeDeleteBindItem(void* pData) {
52 delete static_cast<CXFA_NodeArray*>(pData);
53 }
54
55 XFA_MAPDATABLOCKCALLBACKINFO deleteBindItemCallBack = {
Tom Sepez 2016/05/26 23:55:03 const XFA_MAPDATABLOCKCALLBACKINFO
Wei Li 2016/05/27 00:51:45 Let's defer this since it requires changing SetObj
56 XFA_DataNodeDeleteBindItem, nullptr};
57
58 } // namespace
59
31 CXFA_Object::CXFA_Object(CXFA_Document* pDocument, uint32_t uFlags) 60 CXFA_Object::CXFA_Object(CXFA_Document* pDocument, uint32_t uFlags)
32 : m_pDocument(pDocument), m_uFlags(uFlags) {} 61 : m_pDocument(pDocument), m_uFlags(uFlags) {}
62
33 void CXFA_Object::GetClassName(CFX_WideStringC& wsName) const { 63 void CXFA_Object::GetClassName(CFX_WideStringC& wsName) const {
34 wsName = XFA_GetElementByID(GetClassID())->pName; 64 wsName = XFA_GetElementByID(GetClassID())->pName;
35 } 65 }
66
36 uint32_t CXFA_Object::GetClassHashCode() const { 67 uint32_t CXFA_Object::GetClassHashCode() const {
37 return XFA_GetElementByID(GetClassID())->uHash; 68 return XFA_GetElementByID(GetClassID())->uHash;
38 } 69 }
70
39 XFA_ELEMENT CXFA_Object::GetClassID() const { 71 XFA_ELEMENT CXFA_Object::GetClassID() const {
40 if (IsNode()) { 72 if (IsNode())
41 return AsNode()->GetClassID(); 73 return AsNode()->GetClassID();
42 } 74 if (IsOrdinaryObject())
43 if (IsOrdinaryObject()) {
44 return AsOrdinaryObject()->GetClassID(); 75 return AsOrdinaryObject()->GetClassID();
45 } 76 if (IsNodeList())
46 if (IsNodeList()) {
47 return AsNodeList()->GetClassID(); 77 return AsNodeList()->GetClassID();
48 } 78 if (IsOrdinaryList())
49 if (IsOrdinaryList()) {
50 return XFA_ELEMENT_List; 79 return XFA_ELEMENT_List;
51 }
52 ASSERT(FALSE); 80 ASSERT(FALSE);
53 return (XFA_ELEMENT)0; 81 return (XFA_ELEMENT)0;
54 } 82 }
83
55 void CXFA_Object::Script_ObjectClass_ClassName(CFXJSE_Value* pValue, 84 void CXFA_Object::Script_ObjectClass_ClassName(CFXJSE_Value* pValue,
56 FX_BOOL bSetting, 85 FX_BOOL bSetting,
57 XFA_ATTRIBUTE eAttribute) { 86 XFA_ATTRIBUTE eAttribute) {
58 if (!bSetting) { 87 if (!bSetting) {
59 CFX_WideStringC className; 88 CFX_WideStringC className;
60 GetClassName(className); 89 GetClassName(className);
61 FXJSE_Value_SetUTF8String( 90 FXJSE_Value_SetUTF8String(
62 pValue, 91 pValue,
63 FX_UTF8Encode(className.c_str(), className.GetLength()).AsStringC()); 92 FX_UTF8Encode(className.c_str(), className.GetLength()).AsStringC());
64 } else { 93 } else {
65 ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET); 94 ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);
66 } 95 }
67 } 96 }
97
68 void CXFA_Object::ThrowScriptErrorMessage(int32_t iStringID, ...) { 98 void CXFA_Object::ThrowScriptErrorMessage(int32_t iStringID, ...) {
69 IXFA_AppProvider* pAppProvider = m_pDocument->GetNotify()->GetAppProvider(); 99 IXFA_AppProvider* pAppProvider = m_pDocument->GetNotify()->GetAppProvider();
70 ASSERT(pAppProvider); 100 ASSERT(pAppProvider);
71 CFX_WideString wsFormat; 101 CFX_WideString wsFormat;
72 pAppProvider->LoadString(iStringID, wsFormat); 102 pAppProvider->LoadString(iStringID, wsFormat);
73 CFX_WideString wsMessage; 103 CFX_WideString wsMessage;
74 va_list arg_ptr; 104 va_list arg_ptr;
75 va_start(arg_ptr, iStringID); 105 va_start(arg_ptr, iStringID);
76 wsMessage.FormatV(wsFormat.c_str(), arg_ptr); 106 wsMessage.FormatV(wsFormat.c_str(), arg_ptr);
77 va_end(arg_ptr); 107 va_end(arg_ptr);
78 FXJSE_ThrowMessage( 108 FXJSE_ThrowMessage(
79 "", FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC()); 109 "", FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC());
80 } 110 }
81 111
82 static void XFA_DeleteWideString(void* pData) {
83 delete static_cast<CFX_WideString*>(pData);
84 }
85
86 static void XFA_CopyWideString(void*& pData) {
87 if (pData) {
88 CFX_WideString* pNewData = new CFX_WideString(*(CFX_WideString*)pData);
89 pData = pNewData;
90 }
91 }
92 static XFA_MAPDATABLOCKCALLBACKINFO deleteWideStringCallBack = {
93 XFA_DeleteWideString, XFA_CopyWideString};
94 static XFA_OBJECTTYPE XFA_GetElementObjectType(XFA_ELEMENT eElement) {
95 return (XFA_OBJECTTYPE)XFA_GetElementByID(eElement)->eObjectType;
96 }
97 CXFA_Node::CXFA_Node(CXFA_Document* pDoc, 112 CXFA_Node::CXFA_Node(CXFA_Document* pDoc,
98 uint16_t ePacket, 113 uint16_t ePacket,
99 XFA_ELEMENT eElement) 114 XFA_ELEMENT eElement)
100 : CXFA_Object(pDoc, XFA_GetElementObjectType(eElement)), 115 : CXFA_Object(pDoc, XFA_GetElementObjectType(eElement)),
101 m_pNext(nullptr), 116 m_pNext(nullptr),
102 m_pChild(nullptr), 117 m_pChild(nullptr),
103 m_pLastChild(nullptr), 118 m_pLastChild(nullptr),
104 m_pParent(nullptr), 119 m_pParent(nullptr),
105 m_pXMLNode(nullptr), 120 m_pXMLNode(nullptr),
106 m_eNodeClass(eElement), 121 m_eNodeClass(eElement),
107 m_ePacket(ePacket), 122 m_ePacket(ePacket),
108 m_dwNameHash(0), 123 m_dwNameHash(0),
109 m_pAuxNode(nullptr), 124 m_pAuxNode(nullptr),
110 m_pMapModuleData(nullptr) { 125 m_pMapModuleData(nullptr) {
111 ASSERT(m_pDocument); 126 ASSERT(m_pDocument);
112 } 127 }
128
113 CXFA_Node::~CXFA_Node() { 129 CXFA_Node::~CXFA_Node() {
114 ASSERT(m_pParent == NULL); 130 ASSERT(!m_pParent);
115 RemoveMapModuleKey(); 131 RemoveMapModuleKey();
116 CXFA_Node *pNext, *pNode = m_pChild; 132 CXFA_Node* pNext;
Tom Sepez 2016/05/26 23:55:03 make pNode local to body of loop
Wei Li 2016/05/27 00:51:46 pNext? Done.
133 CXFA_Node* pNode = m_pChild;
117 while (pNode) { 134 while (pNode) {
118 pNext = pNode->m_pNext; 135 pNext = pNode->m_pNext;
119 pNode->m_pParent = NULL; 136 pNode->m_pParent = nullptr;
120 delete pNode; 137 delete pNode;
121 pNode = pNext; 138 pNode = pNext;
122 } 139 }
123 if (m_pXMLNode && HasFlag(XFA_NODEFLAG_OwnXMLNode)) { 140 if (m_pXMLNode && HasFlag(XFA_NODEFLAG_OwnXMLNode))
124 m_pXMLNode->Release(); 141 m_pXMLNode->Release();
125 }
126 } 142 }
143
127 CXFA_Node* CXFA_Node::Clone(FX_BOOL bRecursive) { 144 CXFA_Node* CXFA_Node::Clone(FX_BOOL bRecursive) {
128 CXFA_Document* pFactory = m_pDocument->GetParser()->GetFactory(); 145 CXFA_Document* pFactory = m_pDocument->GetParser()->GetFactory();
129 CXFA_Node* pClone = pFactory->CreateNode(m_ePacket, m_eNodeClass); 146 CXFA_Node* pClone = pFactory->CreateNode(m_ePacket, m_eNodeClass);
130 if (!pClone) { 147 if (!pClone)
131 return NULL; 148 return nullptr;
132 } 149
133 MergeAllData(pClone); 150 MergeAllData(pClone);
134 pClone->UpdateNameHash(); 151 pClone->UpdateNameHash();
135 if (IsNeedSavingXMLNode()) { 152 if (IsNeedSavingXMLNode()) {
136 CFDE_XMLNode* pCloneXML = NULL; 153 CFDE_XMLNode* pCloneXML = nullptr;
137 if (IsAttributeInXML()) { 154 if (IsAttributeInXML()) {
138 CFX_WideString wsName; 155 CFX_WideString wsName;
139 GetAttribute(XFA_ATTRIBUTE_Name, wsName, FALSE); 156 GetAttribute(XFA_ATTRIBUTE_Name, wsName, FALSE);
140 CFDE_XMLElement* pCloneXMLElement = new CFDE_XMLElement(wsName); 157 CFDE_XMLElement* pCloneXMLElement = new CFDE_XMLElement(wsName);
141 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value); 158 CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value);
142 if (!wsValue.IsEmpty()) { 159 if (!wsValue.IsEmpty()) {
143 pCloneXMLElement->SetTextData(CFX_WideString(wsValue)); 160 pCloneXMLElement->SetTextData(CFX_WideString(wsValue));
144 } 161 }
145 pCloneXML = pCloneXMLElement; 162 pCloneXML = pCloneXMLElement;
146 pCloneXMLElement = NULL; 163 pCloneXMLElement = nullptr;
147 pClone->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown); 164 pClone->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
148 } else { 165 } else {
149 pCloneXML = m_pXMLNode->Clone(FALSE); 166 pCloneXML = m_pXMLNode->Clone(FALSE);
150 } 167 }
151 pClone->SetXMLMappingNode(pCloneXML); 168 pClone->SetXMLMappingNode(pCloneXML);
152 pClone->SetFlag(XFA_NODEFLAG_OwnXMLNode, false); 169 pClone->SetFlag(XFA_NODEFLAG_OwnXMLNode, false);
153 } 170 }
154 if (bRecursive) { 171 if (bRecursive) {
155 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild; 172 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
156 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { 173 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
157 pClone->InsertChild(pChild->Clone(bRecursive)); 174 pClone->InsertChild(pChild->Clone(bRecursive));
158 } 175 }
159 } 176 }
160 pClone->SetFlag(XFA_NODEFLAG_Initialized, true); 177 pClone->SetFlag(XFA_NODEFLAG_Initialized, true);
161 pClone->SetObject(XFA_ATTRIBUTE_BindingNode, NULL); 178 pClone->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
162 return pClone; 179 return pClone;
163 } 180 }
181
164 CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem) const { 182 CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem) const {
165 switch (eItem) { 183 switch (eItem) {
166 case XFA_NODEITEM_NextSibling: 184 case XFA_NODEITEM_NextSibling:
167 return m_pNext; 185 return m_pNext;
168 case XFA_NODEITEM_FirstChild: 186 case XFA_NODEITEM_FirstChild:
169 return m_pChild; 187 return m_pChild;
170 case XFA_NODEITEM_Parent: 188 case XFA_NODEITEM_Parent:
171 return m_pParent; 189 return m_pParent;
172 case XFA_NODEITEM_PrevSibling: 190 case XFA_NODEITEM_PrevSibling:
173 if (m_pParent) { 191 if (m_pParent) {
174 CXFA_Node* pSibling = m_pParent->m_pChild; 192 CXFA_Node* pSibling = m_pParent->m_pChild;
175 CXFA_Node* pPrev = NULL; 193 CXFA_Node* pPrev = nullptr;
176 while (pSibling && pSibling != this) { 194 while (pSibling && pSibling != this) {
177 pPrev = pSibling; 195 pPrev = pSibling;
178 pSibling = pSibling->m_pNext; 196 pSibling = pSibling->m_pNext;
179 } 197 }
180 return pPrev; 198 return pPrev;
181 } 199 }
182 return NULL; 200 return nullptr;
183 default: 201 default:
184 break; 202 break;
185 } 203 }
186 return NULL; 204 return nullptr;
187 } 205 }
206
188 CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem, 207 CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem,
189 XFA_OBJECTTYPE eType) const { 208 XFA_OBJECTTYPE eType) const {
190 CXFA_Node* pNode = NULL; 209 CXFA_Node* pNode = nullptr;
191 switch (eItem) { 210 switch (eItem) {
192 case XFA_NODEITEM_NextSibling: 211 case XFA_NODEITEM_NextSibling:
193 pNode = m_pNext; 212 pNode = m_pNext;
194 if (eType != XFA_OBJECTTYPEMASK) { 213 if (eType != XFA_OBJECTTYPEMASK) {
195 while (pNode && pNode->GetObjectType() != eType) { 214 while (pNode && pNode->GetObjectType() != eType)
196 pNode = pNode->m_pNext; 215 pNode = pNode->m_pNext;
197 }
198 } 216 }
199 break; 217 break;
200 case XFA_NODEITEM_FirstChild: 218 case XFA_NODEITEM_FirstChild:
201 pNode = m_pChild; 219 pNode = m_pChild;
202 if (eType != XFA_OBJECTTYPEMASK) { 220 if (eType != XFA_OBJECTTYPEMASK) {
203 while (pNode && pNode->GetObjectType() != eType) { 221 while (pNode && pNode->GetObjectType() != eType)
204 pNode = pNode->m_pNext; 222 pNode = pNode->m_pNext;
205 }
206 } 223 }
207 break; 224 break;
208 case XFA_NODEITEM_Parent: 225 case XFA_NODEITEM_Parent:
209 pNode = m_pParent; 226 pNode = m_pParent;
210 if (eType != XFA_OBJECTTYPEMASK) { 227 if (eType != XFA_OBJECTTYPEMASK) {
211 while (pNode && pNode->GetObjectType() != eType) { 228 while (pNode && pNode->GetObjectType() != eType)
212 pNode = pNode->m_pParent; 229 pNode = pNode->m_pParent;
213 }
214 } 230 }
215 break; 231 break;
216 case XFA_NODEITEM_PrevSibling: 232 case XFA_NODEITEM_PrevSibling:
217 if (m_pParent) { 233 if (m_pParent) {
218 CXFA_Node* pSibling = m_pParent->m_pChild; 234 CXFA_Node* pSibling = m_pParent->m_pChild;
219 while (pSibling && pSibling != this) { 235 while (pSibling && pSibling != this) {
220 if (eType == XFA_OBJECTTYPEMASK || 236 if (eType == XFA_OBJECTTYPEMASK ||
221 eType == pSibling->GetObjectType()) { 237 eType == pSibling->GetObjectType()) {
222 pNode = pSibling; 238 pNode = pSibling;
223 } 239 }
224 pSibling = pSibling->m_pNext; 240 pSibling = pSibling->m_pNext;
225 } 241 }
226 } 242 }
227 break; 243 break;
228 default: 244 default:
229 break; 245 break;
230 } 246 }
231 return pNode; 247 return pNode;
232 } 248 }
249
233 int32_t CXFA_Node::GetNodeList(CXFA_NodeArray& nodes, 250 int32_t CXFA_Node::GetNodeList(CXFA_NodeArray& nodes,
234 uint32_t dwTypeFilter, 251 uint32_t dwTypeFilter,
235 XFA_ELEMENT eElementFilter, 252 XFA_ELEMENT eElementFilter,
236 int32_t iLevel) { 253 int32_t iLevel) {
237 if (--iLevel < 0) { 254 if (--iLevel < 0) {
238 return nodes.GetSize(); 255 return nodes.GetSize();
239 } 256 }
240 if (eElementFilter != XFA_ELEMENT_UNKNOWN) { 257 if (eElementFilter != XFA_ELEMENT_UNKNOWN) {
241 CXFA_Node* pChild = m_pChild; 258 CXFA_Node* pChild = m_pChild;
242 while (pChild) { 259 while (pChild) {
243 if (pChild->GetClassID() == eElementFilter) { 260 if (pChild->GetClassID() == eElementFilter) {
244 nodes.Add(pChild); 261 nodes.Add(pChild);
245 if (iLevel > 0) { 262 if (iLevel > 0) {
246 GetNodeList(nodes, dwTypeFilter, eElementFilter, iLevel); 263 GetNodeList(nodes, dwTypeFilter, eElementFilter, iLevel);
247 } 264 }
248 } 265 }
249 pChild = pChild->m_pNext; 266 pChild = pChild->m_pNext;
250 } 267 }
251 } else if (dwTypeFilter == 268 } else if (dwTypeFilter ==
252 (XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties)) { 269 (XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties)) {
253 CXFA_Node* pChild = m_pChild; 270 CXFA_Node* pChild = m_pChild;
254 while (pChild) { 271 while (pChild) {
255 nodes.Add(pChild); 272 nodes.Add(pChild);
256 if (iLevel > 0) { 273 if (iLevel > 0) {
257 GetNodeList(nodes, dwTypeFilter, eElementFilter, iLevel); 274 GetNodeList(nodes, dwTypeFilter, eElementFilter, iLevel);
258 } 275 }
259 pChild = pChild->m_pNext; 276 pChild = pChild->m_pNext;
260 } 277 }
261 } else if (dwTypeFilter != 0) { 278 } else if (dwTypeFilter != 0) {
262 FX_BOOL bFilterChildren = (dwTypeFilter & XFA_NODEFILTER_Children) != 0; 279 bool bFilterChildren = !!(dwTypeFilter & XFA_NODEFILTER_Children);
Tom Sepez 2016/05/26 23:55:04 nice.
263 FX_BOOL bFilterProperties = (dwTypeFilter & XFA_NODEFILTER_Properties) != 0; 280 bool bFilterProperties = !!(dwTypeFilter & XFA_NODEFILTER_Properties);
264 FX_BOOL bFilterOneOfProperties = 281 bool bFilterOneOfProperties =
265 (dwTypeFilter & XFA_NODEFILTER_OneOfProperty) != 0; 282 !!(dwTypeFilter & XFA_NODEFILTER_OneOfProperty);
266 CXFA_Node* pChild = m_pChild; 283 CXFA_Node* pChild = m_pChild;
267 while (pChild) { 284 while (pChild) {
268 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement( 285 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement(
269 GetClassID(), pChild->GetClassID(), XFA_XDPPACKET_UNKNOWN); 286 GetClassID(), pChild->GetClassID(), XFA_XDPPACKET_UNKNOWN);
270 if (pProperty) { 287 if (pProperty) {
271 if (bFilterProperties) { 288 if (bFilterProperties) {
272 nodes.Add(pChild); 289 nodes.Add(pChild);
273 } else if (bFilterOneOfProperties && 290 } else if (bFilterOneOfProperties &&
274 (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) { 291 (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) {
275 nodes.Add(pChild); 292 nodes.Add(pChild);
276 } else if (bFilterChildren && 293 } else if (bFilterChildren &&
277 (pChild->GetClassID() == XFA_ELEMENT_Variables || 294 (pChild->GetClassID() == XFA_ELEMENT_Variables ||
278 pChild->GetClassID() == XFA_ELEMENT_PageSet)) { 295 pChild->GetClassID() == XFA_ELEMENT_PageSet)) {
279 nodes.Add(pChild); 296 nodes.Add(pChild);
280 } 297 }
281 } else { 298 } else if (bFilterChildren) {
282 if (bFilterChildren) { 299 nodes.Add(pChild);
283 nodes.Add(pChild);
284 }
285 } 300 }
286 pChild = pChild->m_pNext; 301 pChild = pChild->m_pNext;
287 } 302 }
288 if (bFilterOneOfProperties && nodes.GetSize() < 1) { 303 if (bFilterOneOfProperties && nodes.GetSize() < 1) {
289 int32_t iProperties = 0; 304 int32_t iProperties = 0;
290 const XFA_PROPERTY* pProperty = 305 const XFA_PROPERTY* pProperty =
291 XFA_GetElementProperties(GetClassID(), iProperties); 306 XFA_GetElementProperties(GetClassID(), iProperties);
292 if (pProperty == NULL || iProperties < 1) { 307 if (!pProperty || iProperties < 1)
293 return 0; 308 return 0;
294 }
295 for (int32_t i = 0; i < iProperties; i++) { 309 for (int32_t i = 0; i < iProperties; i++) {
296 if (pProperty[i].uFlags & XFA_PROPERTYFLAG_DefaultOneOf) { 310 if (pProperty[i].uFlags & XFA_PROPERTYFLAG_DefaultOneOf) {
297 CXFA_Document* pFactory = m_pDocument->GetParser()->GetFactory(); 311 CXFA_Document* pFactory = m_pDocument->GetParser()->GetFactory();
298 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(GetPacketID()); 312 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(GetPacketID());
299 CXFA_Node* pNewNode = 313 CXFA_Node* pNewNode =
300 pFactory->CreateNode(pPacket, (XFA_ELEMENT)pProperty[i].eName); 314 pFactory->CreateNode(pPacket, (XFA_ELEMENT)pProperty[i].eName);
301 if (!pNewNode) { 315 if (!pNewNode)
302 break; 316 break;
303 } 317 InsertChild(pNewNode, nullptr);
304 InsertChild(pNewNode, NULL);
305 pNewNode->SetFlag(XFA_NODEFLAG_Initialized, true); 318 pNewNode->SetFlag(XFA_NODEFLAG_Initialized, true);
306 nodes.Add(pNewNode); 319 nodes.Add(pNewNode);
307 break; 320 break;
308 } 321 }
309 } 322 }
310 } 323 }
311 } 324 }
312 return nodes.GetSize(); 325 return nodes.GetSize();
313 } 326 }
327
314 CXFA_Node* CXFA_Node::CreateSamePacketNode(XFA_ELEMENT eElement, 328 CXFA_Node* CXFA_Node::CreateSamePacketNode(XFA_ELEMENT eElement,
315 uint32_t dwFlags) { 329 uint32_t dwFlags) {
316 CXFA_Document* pFactory = m_pDocument->GetParser()->GetFactory(); 330 CXFA_Document* pFactory = m_pDocument->GetParser()->GetFactory();
317 CXFA_Node* pNode = pFactory->CreateNode(m_ePacket, eElement); 331 CXFA_Node* pNode = pFactory->CreateNode(m_ePacket, eElement);
318 pNode->SetFlag(dwFlags, true); 332 pNode->SetFlag(dwFlags, true);
319 return pNode; 333 return pNode;
320 } 334 }
335
321 CXFA_Node* CXFA_Node::CloneTemplateToForm(FX_BOOL bRecursive) { 336 CXFA_Node* CXFA_Node::CloneTemplateToForm(FX_BOOL bRecursive) {
322 ASSERT(m_ePacket == XFA_XDPPACKET_Template); 337 ASSERT(m_ePacket == XFA_XDPPACKET_Template);
323 CXFA_Document* pFactory = m_pDocument->GetParser()->GetFactory(); 338 CXFA_Document* pFactory = m_pDocument->GetParser()->GetFactory();
324 CXFA_Node* pClone = pFactory->CreateNode(XFA_XDPPACKET_Form, m_eNodeClass); 339 CXFA_Node* pClone = pFactory->CreateNode(XFA_XDPPACKET_Form, m_eNodeClass);
325 if (!pClone) { 340 if (!pClone)
326 return NULL; 341 return nullptr;
327 } 342
328 pClone->SetTemplateNode(this); 343 pClone->SetTemplateNode(this);
329 pClone->UpdateNameHash(); 344 pClone->UpdateNameHash();
330 pClone->SetXMLMappingNode(GetXMLMappingNode()); 345 pClone->SetXMLMappingNode(GetXMLMappingNode());
331 if (bRecursive) { 346 if (bRecursive) {
332 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild; 347 for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild;
333 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { 348 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
334 pClone->InsertChild(pChild->CloneTemplateToForm(bRecursive)); 349 pClone->InsertChild(pChild->CloneTemplateToForm(bRecursive));
335 } 350 }
336 } 351 }
337 pClone->SetFlag(XFA_NODEFLAG_Initialized, true); 352 pClone->SetFlag(XFA_NODEFLAG_Initialized, true);
338 return pClone; 353 return pClone;
339 } 354 }
340 355
341 CXFA_Node* CXFA_Node::GetTemplateNode() const { 356 CXFA_Node* CXFA_Node::GetTemplateNode() const {
342 return m_pAuxNode; 357 return m_pAuxNode;
343 } 358 }
344 359
345 void CXFA_Node::SetTemplateNode(CXFA_Node* pTemplateNode) { 360 void CXFA_Node::SetTemplateNode(CXFA_Node* pTemplateNode) {
346 m_pAuxNode = pTemplateNode; 361 m_pAuxNode = pTemplateNode;
347 } 362 }
363
348 CXFA_Node* CXFA_Node::GetBindData() { 364 CXFA_Node* CXFA_Node::GetBindData() {
349 ASSERT(GetPacketID() == XFA_XDPPACKET_Form); 365 ASSERT(GetPacketID() == XFA_XDPPACKET_Form);
350 return static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); 366 return static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
351 } 367 }
368
352 int32_t CXFA_Node::GetBindItems(CXFA_NodeArray& formItems) { 369 int32_t CXFA_Node::GetBindItems(CXFA_NodeArray& formItems) {
353 if (m_uFlags & XFA_NODEFLAG_BindFormItems) { 370 if (m_uFlags & XFA_NODEFLAG_BindFormItems) {
354 CXFA_NodeArray* pItems = NULL; 371 CXFA_NodeArray* pItems = nullptr;
355 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems); 372 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
356 formItems.Copy(*pItems); 373 formItems.Copy(*pItems);
357 return formItems.GetSize(); 374 return formItems.GetSize();
358 } 375 }
359 CXFA_Node* pFormNode = 376 CXFA_Node* pFormNode =
360 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); 377 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
361 if (pFormNode) { 378 if (pFormNode)
362 formItems.Add(pFormNode); 379 formItems.Add(pFormNode);
363 }
364 return formItems.GetSize(); 380 return formItems.GetSize();
365 } 381 }
366 382
367 static void XFA_DataNodeDeleteBindItem(void* pData) {
368 delete static_cast<CXFA_NodeArray*>(pData);
369 }
370
371 static XFA_MAPDATABLOCKCALLBACKINFO deleteBindItemCallBack = {
372 XFA_DataNodeDeleteBindItem, NULL};
373 int32_t CXFA_Node::AddBindItem(CXFA_Node* pFormNode) { 383 int32_t CXFA_Node::AddBindItem(CXFA_Node* pFormNode) {
374 ASSERT(pFormNode); 384 ASSERT(pFormNode);
375 if (m_uFlags & XFA_NODEFLAG_BindFormItems) { 385 if (m_uFlags & XFA_NODEFLAG_BindFormItems) {
376 CXFA_NodeArray* pItems = NULL; 386 CXFA_NodeArray* pItems = nullptr;
377 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems); 387 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
378 ASSERT(pItems); 388 ASSERT(pItems);
379 if (pItems->Find(pFormNode) < 0) { 389 if (pItems->Find(pFormNode) < 0) {
380 pItems->Add(pFormNode); 390 pItems->Add(pFormNode);
381 } 391 }
382 return pItems->GetSize(); 392 return pItems->GetSize();
383 } 393 }
384 CXFA_Node* pOldFormItem = 394 CXFA_Node* pOldFormItem =
385 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); 395 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
386 if (!pOldFormItem) { 396 if (!pOldFormItem) {
387 SetObject(XFA_ATTRIBUTE_BindingNode, pFormNode); 397 SetObject(XFA_ATTRIBUTE_BindingNode, pFormNode);
388 return 1; 398 return 1;
389 } else if (pOldFormItem == pFormNode) { 399 } else if (pOldFormItem == pFormNode) {
390 return 1; 400 return 1;
391 } 401 }
392 CXFA_NodeArray* pItems = new CXFA_NodeArray; 402 CXFA_NodeArray* pItems = new CXFA_NodeArray;
393 SetObject(XFA_ATTRIBUTE_BindingNode, pItems, &deleteBindItemCallBack); 403 SetObject(XFA_ATTRIBUTE_BindingNode, pItems, &deleteBindItemCallBack);
394 pItems->Add(pOldFormItem); 404 pItems->Add(pOldFormItem);
395 pItems->Add(pFormNode); 405 pItems->Add(pFormNode);
396 m_uFlags |= XFA_NODEFLAG_BindFormItems; 406 m_uFlags |= XFA_NODEFLAG_BindFormItems;
397 return 2; 407 return 2;
398 } 408 }
409
399 int32_t CXFA_Node::RemoveBindItem(CXFA_Node* pFormNode) { 410 int32_t CXFA_Node::RemoveBindItem(CXFA_Node* pFormNode) {
400 if (m_uFlags & XFA_NODEFLAG_BindFormItems) { 411 if (m_uFlags & XFA_NODEFLAG_BindFormItems) {
401 CXFA_NodeArray* pItems = NULL; 412 CXFA_NodeArray* pItems = nullptr;
402 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems); 413 TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems);
403 ASSERT(pItems); 414 ASSERT(pItems);
404 int32_t iIndex = pItems->Find(pFormNode); 415 int32_t iIndex = pItems->Find(pFormNode);
405 int32_t iCount = pItems->GetSize(); 416 int32_t iCount = pItems->GetSize();
406 if (iIndex >= 0) { 417 if (iIndex >= 0) {
407 if (iIndex != iCount - 1) { 418 if (iIndex != iCount - 1)
408 pItems->SetAt(iIndex, pItems->GetAt(iCount - 1)); 419 pItems->SetAt(iIndex, pItems->GetAt(iCount - 1));
409 }
410 pItems->RemoveAt(iCount - 1); 420 pItems->RemoveAt(iCount - 1);
411 if (iCount == 2) { 421 if (iCount == 2) {
412 CXFA_Node* pLastFormNode = pItems->GetAt(0); 422 CXFA_Node* pLastFormNode = pItems->GetAt(0);
413 SetObject(XFA_ATTRIBUTE_BindingNode, pLastFormNode); 423 SetObject(XFA_ATTRIBUTE_BindingNode, pLastFormNode);
414 m_uFlags &= ~XFA_NODEFLAG_BindFormItems; 424 m_uFlags &= ~XFA_NODEFLAG_BindFormItems;
415 } 425 }
416 iCount--; 426 iCount--;
417 } 427 }
418 return iCount; 428 return iCount;
419 } 429 }
420 CXFA_Node* pOldFormItem = 430 CXFA_Node* pOldFormItem =
421 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); 431 static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode));
422 if (pOldFormItem == pFormNode) { 432 if (pOldFormItem == pFormNode) {
423 SetObject(XFA_ATTRIBUTE_BindingNode, NULL); 433 SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
424 pOldFormItem = NULL; 434 pOldFormItem = nullptr;
425 } 435 }
426 return pOldFormItem == NULL ? 0 : 1; 436 return pOldFormItem ? 1 : 0;
427 } 437 }
438
428 FX_BOOL CXFA_Node::HasBindItem() { 439 FX_BOOL CXFA_Node::HasBindItem() {
429 return (GetPacketID() == XFA_XDPPACKET_Datasets) && 440 return GetPacketID() == XFA_XDPPACKET_Datasets &&
430 GetObject(XFA_ATTRIBUTE_BindingNode) != NULL; 441 GetObject(XFA_ATTRIBUTE_BindingNode);
431 } 442 }
443
432 CXFA_WidgetData* CXFA_Node::GetWidgetData() { 444 CXFA_WidgetData* CXFA_Node::GetWidgetData() {
433 return (CXFA_WidgetData*)GetObject(XFA_ATTRIBUTE_WidgetData); 445 return (CXFA_WidgetData*)GetObject(XFA_ATTRIBUTE_WidgetData);
434 } 446 }
447
435 CXFA_WidgetData* CXFA_Node::GetContainerWidgetData() { 448 CXFA_WidgetData* CXFA_Node::GetContainerWidgetData() {
436 if (GetPacketID() != XFA_XDPPACKET_Form) { 449 if (GetPacketID() != XFA_XDPPACKET_Form)
437 return NULL; 450 return nullptr;
438 }
439 XFA_ELEMENT classID = GetClassID(); 451 XFA_ELEMENT classID = GetClassID();
440 if (classID == XFA_ELEMENT_ExclGroup) { 452 if (classID == XFA_ELEMENT_ExclGroup)
441 return NULL; 453 return nullptr;
442 }
443 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); 454 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
444 if (pParentNode && pParentNode->GetClassID() == XFA_ELEMENT_ExclGroup) { 455 if (pParentNode && pParentNode->GetClassID() == XFA_ELEMENT_ExclGroup)
445 return NULL; 456 return nullptr;
446 } 457
447 if (classID == XFA_ELEMENT_Field) { 458 if (classID == XFA_ELEMENT_Field) {
448 CXFA_WidgetData* pFieldWidgetData = GetWidgetData(); 459 CXFA_WidgetData* pFieldWidgetData = GetWidgetData();
449 if (pFieldWidgetData && 460 if (pFieldWidgetData &&
450 pFieldWidgetData->GetChoiceListOpen() == 461 pFieldWidgetData->GetChoiceListOpen() ==
451 XFA_ATTRIBUTEENUM_MultiSelect) { 462 XFA_ATTRIBUTEENUM_MultiSelect) {
452 return NULL; 463 return nullptr;
453 } else { 464 } else {
454 CFX_WideString wsPicture; 465 CFX_WideString wsPicture;
455 if (pFieldWidgetData) { 466 if (pFieldWidgetData) {
456 pFieldWidgetData->GetPictureContent(wsPicture, 467 pFieldWidgetData->GetPictureContent(wsPicture,
457 XFA_VALUEPICTURE_DataBind); 468 XFA_VALUEPICTURE_DataBind);
458 } 469 }
459 if (!wsPicture.IsEmpty()) { 470 if (!wsPicture.IsEmpty())
460 return pFieldWidgetData; 471 return pFieldWidgetData;
461 }
462 CXFA_Node* pDataNode = GetBindData(); 472 CXFA_Node* pDataNode = GetBindData();
463 if (!pDataNode) { 473 if (!pDataNode)
464 return NULL; 474 return nullptr;
465 } 475 pFieldWidgetData = nullptr;
466 pFieldWidgetData = NULL;
467 CXFA_NodeArray formNodes; 476 CXFA_NodeArray formNodes;
468 pDataNode->GetBindItems(formNodes); 477 pDataNode->GetBindItems(formNodes);
469 for (int32_t i = 0; i < formNodes.GetSize(); i++) { 478 for (int32_t i = 0; i < formNodes.GetSize(); i++) {
470 CXFA_Node* pFormNode = formNodes.GetAt(i); 479 CXFA_Node* pFormNode = formNodes.GetAt(i);
471 if (!pFormNode || pFormNode->HasFlag(XFA_NODEFLAG_HasRemoved)) { 480 if (!pFormNode || pFormNode->HasFlag(XFA_NODEFLAG_HasRemoved))
472 continue; 481 continue;
473 }
474 pFieldWidgetData = pFormNode->GetWidgetData(); 482 pFieldWidgetData = pFormNode->GetWidgetData();
475 if (pFieldWidgetData) { 483 if (pFieldWidgetData) {
476 pFieldWidgetData->GetPictureContent(wsPicture, 484 pFieldWidgetData->GetPictureContent(wsPicture,
477 XFA_VALUEPICTURE_DataBind); 485 XFA_VALUEPICTURE_DataBind);
478 } 486 }
479 if (!wsPicture.IsEmpty()) { 487 if (!wsPicture.IsEmpty())
480 break; 488 break;
481 } 489 pFieldWidgetData = nullptr;
482 pFieldWidgetData = NULL;
483 } 490 }
484 return pFieldWidgetData; 491 return pFieldWidgetData;
485 } 492 }
486 } 493 }
487 CXFA_Node* pGrandNode = 494 CXFA_Node* pGrandNode =
488 pParentNode ? pParentNode->GetNodeItem(XFA_NODEITEM_Parent) : NULL; 495 pParentNode ? pParentNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
489 CXFA_Node* pValueNode = 496 CXFA_Node* pValueNode =
490 (pParentNode && pParentNode->GetClassID() == XFA_ELEMENT_Value) 497 (pParentNode && pParentNode->GetClassID() == XFA_ELEMENT_Value)
491 ? pParentNode 498 ? pParentNode
492 : NULL; 499 : nullptr;
493 if (!pValueNode) { 500 if (!pValueNode) {
494 pValueNode = (pGrandNode && pGrandNode->GetClassID() == XFA_ELEMENT_Value) 501 pValueNode = (pGrandNode && pGrandNode->GetClassID() == XFA_ELEMENT_Value)
495 ? pGrandNode 502 ? pGrandNode
496 : NULL; 503 : nullptr;
497 } 504 }
498 CXFA_Node* pParentOfValueNode = 505 CXFA_Node* pParentOfValueNode =
499 pValueNode ? pValueNode->GetNodeItem(XFA_NODEITEM_Parent) : NULL; 506 pValueNode ? pValueNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr;
500 return pParentOfValueNode ? pParentOfValueNode->GetContainerWidgetData() 507 return pParentOfValueNode ? pParentOfValueNode->GetContainerWidgetData()
501 : NULL; 508 : nullptr;
502 } 509 }
510
503 FX_BOOL CXFA_Node::GetLocaleName(CFX_WideString& wsLocaleName) { 511 FX_BOOL CXFA_Node::GetLocaleName(CFX_WideString& wsLocaleName) {
504 CXFA_Node* pForm = GetDocument()->GetXFAObject(XFA_HASHCODE_Form)->AsNode(); 512 CXFA_Node* pForm = GetDocument()->GetXFAObject(XFA_HASHCODE_Form)->AsNode();
505 CXFA_Node* pTopSubform = pForm->GetFirstChildByClass(XFA_ELEMENT_Subform); 513 CXFA_Node* pTopSubform = pForm->GetFirstChildByClass(XFA_ELEMENT_Subform);
506 ASSERT(pTopSubform); 514 ASSERT(pTopSubform);
507 CXFA_Node* pLocaleNode = this; 515 CXFA_Node* pLocaleNode = this;
508 FX_BOOL bLocale = FALSE; 516 bool bLocale = false;
509 do { 517 do {
510 bLocale = pLocaleNode->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, FALSE); 518 bLocale = pLocaleNode->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, FALSE);
511 if (!bLocale) { 519 if (!bLocale) {
512 pLocaleNode = pLocaleNode->GetNodeItem(XFA_NODEITEM_Parent); 520 pLocaleNode = pLocaleNode->GetNodeItem(XFA_NODEITEM_Parent);
513 } 521 }
514 } while (pLocaleNode && pLocaleNode != pTopSubform && !bLocale); 522 } while (pLocaleNode && pLocaleNode != pTopSubform && !bLocale);
515 if (bLocale) { 523 if (bLocale)
516 return bLocale; 524 return TRUE;
517 }
518 CXFA_Node* pConfig = ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Config)); 525 CXFA_Node* pConfig = ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Config));
519 wsLocaleName = GetDocument()->GetLocalMgr()->GetConfigLocaleName(pConfig); 526 wsLocaleName = GetDocument()->GetLocalMgr()->GetConfigLocaleName(pConfig);
520 if (!wsLocaleName.IsEmpty()) { 527 if (!wsLocaleName.IsEmpty())
521 bLocale = TRUE; 528 return TRUE;
522 } 529 if (pTopSubform &&
523 if (bLocale) { 530 pTopSubform->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, FALSE)) {
524 return bLocale; 531 return TRUE;
525 }
526 if (pTopSubform) {
527 bLocale = pTopSubform->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, FALSE);
528 }
529 if (bLocale) {
530 return bLocale;
531 } 532 }
532 IFX_Locale* pLocale = GetDocument()->GetLocalMgr()->GetDefLocale(); 533 IFX_Locale* pLocale = GetDocument()->GetLocalMgr()->GetDefLocale();
533 if (pLocale) { 534 if (pLocale) {
534 wsLocaleName = pLocale->GetName(); 535 wsLocaleName = pLocale->GetName();
535 bLocale = TRUE; 536 return TRUE;
536 } 537 }
537 return bLocale; 538 return FALSE;
538 } 539 }
540
539 XFA_ATTRIBUTEENUM CXFA_Node::GetIntact() { 541 XFA_ATTRIBUTEENUM CXFA_Node::GetIntact() {
540 XFA_ELEMENT eElement = GetClassID(); 542 XFA_ELEMENT eElement = GetClassID();
541 CXFA_Node* pKeep = GetFirstChildByClass(XFA_ELEMENT_Keep); 543 CXFA_Node* pKeep = GetFirstChildByClass(XFA_ELEMENT_Keep);
542 XFA_ATTRIBUTEENUM eLayoutType = GetEnum(XFA_ATTRIBUTE_Layout); 544 XFA_ATTRIBUTEENUM eLayoutType = GetEnum(XFA_ATTRIBUTE_Layout);
543 if (pKeep) { 545 if (pKeep) {
544 XFA_ATTRIBUTEENUM eIntact; 546 XFA_ATTRIBUTEENUM eIntact;
545 if (pKeep->TryEnum(XFA_ATTRIBUTE_Intact, eIntact, FALSE)) { 547 if (pKeep->TryEnum(XFA_ATTRIBUTE_Intact, eIntact, FALSE)) {
546 if (eIntact == XFA_ATTRIBUTEENUM_None && 548 if (eIntact == XFA_ATTRIBUTEENUM_None &&
547 eLayoutType == XFA_ATTRIBUTEENUM_Row && 549 eLayoutType == XFA_ATTRIBUTEENUM_Row &&
548 m_pDocument->GetCurVersionMode() < XFA_VERSION_208) { 550 m_pDocument->GetCurVersionMode() < XFA_VERSION_208) {
549 CXFA_Node* pPreviewRow = 551 CXFA_Node* pPreviewRow =
550 GetNodeItem(XFA_NODEITEM_PrevSibling, XFA_OBJECTTYPE_ContainerNode); 552 GetNodeItem(XFA_NODEITEM_PrevSibling, XFA_OBJECTTYPE_ContainerNode);
551 if (pPreviewRow && 553 if (pPreviewRow &&
552 pPreviewRow->GetEnum(XFA_ATTRIBUTE_Layout) == 554 pPreviewRow->GetEnum(XFA_ATTRIBUTE_Layout) ==
553 XFA_ATTRIBUTEENUM_Row) { 555 XFA_ATTRIBUTEENUM_Row) {
554 XFA_ATTRIBUTEENUM eValue; 556 XFA_ATTRIBUTEENUM eValue;
555 if (pKeep->TryEnum(XFA_ATTRIBUTE_Previous, eValue, FALSE)) { 557 if (pKeep->TryEnum(XFA_ATTRIBUTE_Previous, eValue, FALSE) &&
556 if (eValue == XFA_ATTRIBUTEENUM_ContentArea || 558 (eValue == XFA_ATTRIBUTEENUM_ContentArea ||
557 eValue == XFA_ATTRIBUTEENUM_PageArea) { 559 eValue == XFA_ATTRIBUTEENUM_PageArea)) {
558 return XFA_ATTRIBUTEENUM_ContentArea; 560 return XFA_ATTRIBUTEENUM_ContentArea;
559 }
560 } 561 }
561 CXFA_Node* pKeep = 562 CXFA_Node* pKeep =
Tom Sepez 2016/05/26 23:55:03 this is a shadow of the variable on line 543. Let
Wei Li 2016/05/27 00:51:45 Done.
562 pPreviewRow->GetFirstChildByClass(XFA_ELEMENT_Keep); 563 pPreviewRow->GetFirstChildByClass(XFA_ELEMENT_Keep);
563 if (pKeep) { 564 if (pKeep && pKeep->TryEnum(XFA_ATTRIBUTE_Next, eValue, FALSE) &&
564 if (pKeep->TryEnum(XFA_ATTRIBUTE_Next, eValue, FALSE)) { 565 (eValue == XFA_ATTRIBUTEENUM_ContentArea ||
565 if (eValue == XFA_ATTRIBUTEENUM_ContentArea || 566 eValue == XFA_ATTRIBUTEENUM_PageArea)) {
566 eValue == XFA_ATTRIBUTEENUM_PageArea) { 567 return XFA_ATTRIBUTEENUM_ContentArea;
567 return XFA_ATTRIBUTEENUM_ContentArea;
568 }
569 }
570 } 568 }
571 } 569 }
572 } 570 }
573 return eIntact; 571 return eIntact;
574 } 572 }
575 } 573 }
576 switch (eElement) { 574 switch (eElement) {
577 case XFA_ELEMENT_Subform: 575 case XFA_ELEMENT_Subform:
578 switch (eLayoutType) { 576 switch (eLayoutType) {
579 case XFA_ATTRIBUTEENUM_Position: 577 case XFA_ATTRIBUTEENUM_Position:
580 case XFA_ATTRIBUTEENUM_Row: 578 case XFA_ATTRIBUTEENUM_Row:
581 return XFA_ATTRIBUTEENUM_ContentArea; 579 return XFA_ATTRIBUTEENUM_ContentArea;
582 case XFA_ATTRIBUTEENUM_Tb: 580 case XFA_ATTRIBUTEENUM_Tb:
583 case XFA_ATTRIBUTEENUM_Table: 581 case XFA_ATTRIBUTEENUM_Table:
584 case XFA_ATTRIBUTEENUM_Lr_tb: 582 case XFA_ATTRIBUTEENUM_Lr_tb:
585 case XFA_ATTRIBUTEENUM_Rl_tb: 583 case XFA_ATTRIBUTEENUM_Rl_tb:
586 return XFA_ATTRIBUTEENUM_None; 584 return XFA_ATTRIBUTEENUM_None;
587 default: 585 default:
588 break; 586 break;
589 } 587 }
590 break; 588 break;
591 case XFA_ELEMENT_Field: { 589 case XFA_ELEMENT_Field: {
592 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); 590 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
593 if (!pParentNode || pParentNode->GetClassID() == XFA_ELEMENT_PageArea) { 591 if (!pParentNode || pParentNode->GetClassID() == XFA_ELEMENT_PageArea)
594 return XFA_ATTRIBUTEENUM_ContentArea; 592 return XFA_ATTRIBUTEENUM_ContentArea;
595 }
596 if (pParentNode->GetIntact() == XFA_ATTRIBUTEENUM_None) { 593 if (pParentNode->GetIntact() == XFA_ATTRIBUTEENUM_None) {
597 XFA_ATTRIBUTEENUM eParLayout = 594 XFA_ATTRIBUTEENUM eParLayout =
598 pParentNode->GetEnum(XFA_ATTRIBUTE_Layout); 595 pParentNode->GetEnum(XFA_ATTRIBUTE_Layout);
599 if (eParLayout == XFA_ATTRIBUTEENUM_Position || 596 if (eParLayout == XFA_ATTRIBUTEENUM_Position ||
600 eParLayout == XFA_ATTRIBUTEENUM_Row || 597 eParLayout == XFA_ATTRIBUTEENUM_Row ||
601 eParLayout == XFA_ATTRIBUTEENUM_Table) { 598 eParLayout == XFA_ATTRIBUTEENUM_Table) {
602 return XFA_ATTRIBUTEENUM_None; 599 return XFA_ATTRIBUTEENUM_None;
603 } 600 }
604 XFA_VERSION version = m_pDocument->GetCurVersionMode(); 601 XFA_VERSION version = m_pDocument->GetCurVersionMode();
605 if (eParLayout == XFA_ATTRIBUTEENUM_Tb && version < XFA_VERSION_208) { 602 if (eParLayout == XFA_ATTRIBUTEENUM_Tb && version < XFA_VERSION_208) {
606 CXFA_Measurement measureH; 603 CXFA_Measurement measureH;
607 if (TryMeasure(XFA_ATTRIBUTE_H, measureH, FALSE)) { 604 if (TryMeasure(XFA_ATTRIBUTE_H, measureH, FALSE))
608 return XFA_ATTRIBUTEENUM_ContentArea; 605 return XFA_ATTRIBUTEENUM_ContentArea;
609 }
610 } 606 }
611 return XFA_ATTRIBUTEENUM_None; 607 return XFA_ATTRIBUTEENUM_None;
612 } 608 }
613 return XFA_ATTRIBUTEENUM_ContentArea; 609 return XFA_ATTRIBUTEENUM_ContentArea;
614 } 610 }
615 case XFA_ELEMENT_Draw: 611 case XFA_ELEMENT_Draw:
616 return XFA_ATTRIBUTEENUM_ContentArea; 612 return XFA_ATTRIBUTEENUM_ContentArea;
617 default: 613 default:
618 break; 614 break;
619 } 615 }
620 return XFA_ATTRIBUTEENUM_None; 616 return XFA_ATTRIBUTEENUM_None;
621 } 617 }
618
622 CXFA_Node* CXFA_Node::GetDataDescriptionNode() { 619 CXFA_Node* CXFA_Node::GetDataDescriptionNode() {
623 if (m_ePacket == XFA_XDPPACKET_Datasets) { 620 if (m_ePacket == XFA_XDPPACKET_Datasets)
624 return m_pAuxNode; 621 return m_pAuxNode;
625 } 622 return nullptr;
626 return NULL;
627 } 623 }
624
628 void CXFA_Node::SetDataDescriptionNode(CXFA_Node* pDataDescriptionNode) { 625 void CXFA_Node::SetDataDescriptionNode(CXFA_Node* pDataDescriptionNode) {
629 ASSERT(m_ePacket == XFA_XDPPACKET_Datasets); 626 ASSERT(m_ePacket == XFA_XDPPACKET_Datasets);
630 m_pAuxNode = pDataDescriptionNode; 627 m_pAuxNode = pDataDescriptionNode;
631 } 628 }
629
632 void CXFA_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments) { 630 void CXFA_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments) {
633 int32_t iLength = pArguments->GetLength(); 631 int32_t iLength = pArguments->GetLength();
634 if (iLength != 1) { 632 if (iLength != 1) {
635 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resolveNode"); 633 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resolveNode");
636 return; 634 return;
637 } 635 }
638 CFX_WideString wsExpression = 636 CFX_WideString wsExpression =
639 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); 637 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
640 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); 638 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
641 if (!pScriptContext) { 639 if (!pScriptContext)
642 return; 640 return;
643 }
644 CXFA_Node* refNode = this; 641 CXFA_Node* refNode = this;
645 if (refNode->GetClassID() == XFA_ELEMENT_Xfa) { 642 if (refNode->GetClassID() == XFA_ELEMENT_Xfa)
646 refNode = ToNode(pScriptContext->GetThisObject()); 643 refNode = ToNode(pScriptContext->GetThisObject());
647 }
648 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes | 644 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
649 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | 645 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
650 XFA_RESOLVENODE_Siblings; 646 XFA_RESOLVENODE_Siblings;
651 XFA_RESOLVENODE_RS resoveNodeRS; 647 XFA_RESOLVENODE_RS resoveNodeRS;
652 int32_t iRet = pScriptContext->ResolveObjects( 648 int32_t iRet = pScriptContext->ResolveObjects(
653 refNode, wsExpression.AsStringC(), resoveNodeRS, dwFlag); 649 refNode, wsExpression.AsStringC(), resoveNodeRS, dwFlag);
654 if (iRet < 1) { 650 if (iRet < 1)
655 return FXJSE_Value_SetNull(pArguments->GetReturnValue()); 651 return FXJSE_Value_SetNull(pArguments->GetReturnValue());
656 } 652
657 CFXJSE_Value* pValue = nullptr; 653 CFXJSE_Value* pValue = nullptr;
658 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { 654 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
659 CXFA_Object* pNode = resoveNodeRS.nodes[0]; 655 CXFA_Object* pNode = resoveNodeRS.nodes[0];
660 pValue = pScriptContext->GetJSValueFromMap(pNode); 656 pValue = pScriptContext->GetJSValueFromMap(pNode);
661 FXJSE_Value_Set(pArguments->GetReturnValue(), pValue); 657 FXJSE_Value_Set(pArguments->GetReturnValue(), pValue);
662 } else { 658 } else {
663 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = 659 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo =
664 resoveNodeRS.pScriptAttribute; 660 resoveNodeRS.pScriptAttribute;
665 if (lpAttributeInfo && lpAttributeInfo->eValueType == XFA_SCRIPT_Object) { 661 if (lpAttributeInfo && lpAttributeInfo->eValueType == XFA_SCRIPT_Object) {
666 pValue = FXJSE_Value_Create(pScriptContext->GetRuntime()); 662 pValue = FXJSE_Value_Create(pScriptContext->GetRuntime());
667 (resoveNodeRS.nodes[0]->*(lpAttributeInfo->lpfnCallback))( 663 (resoveNodeRS.nodes[0]->*(lpAttributeInfo->lpfnCallback))(
668 pValue, FALSE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); 664 pValue, FALSE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute);
669 FXJSE_Value_Set(pArguments->GetReturnValue(), pValue); 665 FXJSE_Value_Set(pArguments->GetReturnValue(), pValue);
670 FXJSE_Value_Release(pValue); 666 FXJSE_Value_Release(pValue);
671 } else { 667 } else {
672 FXJSE_Value_SetNull(pArguments->GetReturnValue()); 668 FXJSE_Value_SetNull(pArguments->GetReturnValue());
673 } 669 }
674 } 670 }
675 } 671 }
672
676 void CXFA_Node::Script_TreeClass_ResolveNodes(CFXJSE_Arguments* pArguments) { 673 void CXFA_Node::Script_TreeClass_ResolveNodes(CFXJSE_Arguments* pArguments) {
677 int32_t iLength = pArguments->GetLength(); 674 int32_t iLength = pArguments->GetLength();
678 if (iLength != 1) { 675 if (iLength != 1) {
679 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, 676 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
680 L"resolveNodes"); 677 L"resolveNodes");
681 return; 678 return;
682 } 679 }
683 CFX_WideString wsExpression = 680 CFX_WideString wsExpression =
684 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); 681 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
685 CFXJSE_Value* pValue = pArguments->GetReturnValue(); 682 CFXJSE_Value* pValue = pArguments->GetReturnValue();
686 if (!pValue) { 683 if (!pValue)
687 return; 684 return;
688 }
689 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes | 685 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
690 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | 686 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
691 XFA_RESOLVENODE_Siblings; 687 XFA_RESOLVENODE_Siblings;
692 CXFA_Node* refNode = this; 688 CXFA_Node* refNode = this;
693 if (refNode->GetClassID() == XFA_ELEMENT_Xfa) { 689 if (refNode->GetClassID() == XFA_ELEMENT_Xfa)
694 refNode = ToNode(m_pDocument->GetScriptContext()->GetThisObject()); 690 refNode = ToNode(m_pDocument->GetScriptContext()->GetThisObject());
695 }
696 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag, refNode); 691 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag, refNode);
697 } 692 }
693
698 void CXFA_Node::Script_Som_ResolveNodeList(CFXJSE_Value* pValue, 694 void CXFA_Node::Script_Som_ResolveNodeList(CFXJSE_Value* pValue,
699 CFX_WideString wsExpression, 695 CFX_WideString wsExpression,
700 uint32_t dwFlag, 696 uint32_t dwFlag,
701 CXFA_Node* refNode) { 697 CXFA_Node* refNode) {
702 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); 698 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
703 if (!pScriptContext) { 699 if (!pScriptContext)
704 return; 700 return;
705 }
706 XFA_RESOLVENODE_RS resoveNodeRS; 701 XFA_RESOLVENODE_RS resoveNodeRS;
707 if (refNode == NULL) { 702 if (!refNode)
708 refNode = this; 703 refNode = this;
709 }
710 pScriptContext->ResolveObjects(refNode, wsExpression.AsStringC(), 704 pScriptContext->ResolveObjects(refNode, wsExpression.AsStringC(),
711 resoveNodeRS, dwFlag); 705 resoveNodeRS, dwFlag);
712 CXFA_ArrayNodeList* pNodeList = new CXFA_ArrayNodeList(m_pDocument); 706 CXFA_ArrayNodeList* pNodeList = new CXFA_ArrayNodeList(m_pDocument);
713 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { 707 if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) {
714 for (int32_t i = 0; i < resoveNodeRS.nodes.GetSize(); i++) { 708 for (int32_t i = 0; i < resoveNodeRS.nodes.GetSize(); i++) {
715 if (resoveNodeRS.nodes[i]->IsNode()) 709 if (resoveNodeRS.nodes[i]->IsNode())
716 pNodeList->Append(resoveNodeRS.nodes[i]->AsNode()); 710 pNodeList->Append(resoveNodeRS.nodes[i]->AsNode());
717 } 711 }
718 } else { 712 } else {
719 CXFA_ValueArray valueArray(pScriptContext->GetRuntime()); 713 CXFA_ValueArray valueArray(pScriptContext->GetRuntime());
720 if (resoveNodeRS.GetAttributeResult(valueArray) > 0) { 714 if (resoveNodeRS.GetAttributeResult(valueArray) > 0) {
721 CXFA_ObjArray objectArray; 715 CXFA_ObjArray objectArray;
722 valueArray.GetAttributeObject(objectArray); 716 valueArray.GetAttributeObject(objectArray);
723 for (int32_t i = 0; i < objectArray.GetSize(); i++) { 717 for (int32_t i = 0; i < objectArray.GetSize(); i++) {
724 if (objectArray[i]->IsNode()) 718 if (objectArray[i]->IsNode())
725 pNodeList->Append(objectArray[i]->AsNode()); 719 pNodeList->Append(objectArray[i]->AsNode());
726 } 720 }
727 } 721 }
728 } 722 }
729 FXJSE_Value_SetObject(pValue, (CXFA_Object*)pNodeList, 723 FXJSE_Value_SetObject(pValue, (CXFA_Object*)pNodeList,
730 pScriptContext->GetJseNormalClass()); 724 pScriptContext->GetJseNormalClass());
731 } 725 }
726
732 void CXFA_Node::Script_TreeClass_All(CFXJSE_Value* pValue, 727 void CXFA_Node::Script_TreeClass_All(CFXJSE_Value* pValue,
733 FX_BOOL bSetting, 728 FX_BOOL bSetting,
734 XFA_ATTRIBUTE eAttribute) { 729 XFA_ATTRIBUTE eAttribute) {
735 if (bSetting) { 730 if (bSetting) {
736 ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET); 731 ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);
737 } else { 732 } else {
738 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL; 733 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
739 CFX_WideString wsName; 734 CFX_WideString wsName;
740 GetAttribute(XFA_ATTRIBUTE_Name, wsName); 735 GetAttribute(XFA_ATTRIBUTE_Name, wsName);
741 CFX_WideString wsExpression = wsName + FX_WSTRC(L"[*]"); 736 CFX_WideString wsExpression = wsName + FX_WSTRC(L"[*]");
742 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag); 737 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
743 } 738 }
744 } 739 }
740
745 void CXFA_Node::Script_TreeClass_Nodes(CFXJSE_Value* pValue, 741 void CXFA_Node::Script_TreeClass_Nodes(CFXJSE_Value* pValue,
746 FX_BOOL bSetting, 742 FX_BOOL bSetting,
747 XFA_ATTRIBUTE eAttribute) { 743 XFA_ATTRIBUTE eAttribute) {
748 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); 744 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
749 if (!pScriptContext) { 745 if (!pScriptContext)
750 return; 746 return;
751 }
752 if (bSetting) { 747 if (bSetting) {
753 IXFA_AppProvider* pAppProvider = m_pDocument->GetNotify()->GetAppProvider(); 748 IXFA_AppProvider* pAppProvider = m_pDocument->GetNotify()->GetAppProvider();
754 ASSERT(pAppProvider); 749 ASSERT(pAppProvider);
755 CFX_WideString wsMessage; 750 CFX_WideString wsMessage;
756 pAppProvider->LoadString(XFA_IDS_Unable_TO_SET, wsMessage); 751 pAppProvider->LoadString(XFA_IDS_Unable_TO_SET, wsMessage);
757 FXJSE_ThrowMessage( 752 FXJSE_ThrowMessage(
758 "", 753 "",
759 FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC()); 754 FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC());
760 } else { 755 } else {
761 CXFA_AttachNodeList* pNodeList = new CXFA_AttachNodeList(m_pDocument, this); 756 CXFA_AttachNodeList* pNodeList = new CXFA_AttachNodeList(m_pDocument, this);
762 FXJSE_Value_SetObject(pValue, (CXFA_Object*)pNodeList, 757 FXJSE_Value_SetObject(pValue, (CXFA_Object*)pNodeList,
763 pScriptContext->GetJseNormalClass()); 758 pScriptContext->GetJseNormalClass());
764 } 759 }
765 } 760 }
761
766 void CXFA_Node::Script_TreeClass_ClassAll(CFXJSE_Value* pValue, 762 void CXFA_Node::Script_TreeClass_ClassAll(CFXJSE_Value* pValue,
767 FX_BOOL bSetting, 763 FX_BOOL bSetting,
768 XFA_ATTRIBUTE eAttribute) { 764 XFA_ATTRIBUTE eAttribute) {
769 if (bSetting) { 765 if (bSetting) {
770 ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET); 766 ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);
771 } else { 767 } else {
772 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL; 768 uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL;
773 CFX_WideStringC wsName; 769 CFX_WideStringC wsName;
774 GetClassName(wsName); 770 GetClassName(wsName);
775 CFX_WideString wsExpression = FX_WSTRC(L"#") + wsName + FX_WSTRC(L"[*]"); 771 CFX_WideString wsExpression = FX_WSTRC(L"#") + wsName + FX_WSTRC(L"[*]");
776 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag); 772 Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag);
777 } 773 }
778 } 774 }
775
779 void CXFA_Node::Script_TreeClass_Parent(CFXJSE_Value* pValue, 776 void CXFA_Node::Script_TreeClass_Parent(CFXJSE_Value* pValue,
780 FX_BOOL bSetting, 777 FX_BOOL bSetting,
781 XFA_ATTRIBUTE eAttribute) { 778 XFA_ATTRIBUTE eAttribute) {
782 if (bSetting) { 779 if (bSetting) {
783 ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET); 780 ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);
784 } else { 781 } else {
785 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent); 782 CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent);
786 if (pParent) { 783 if (pParent) {
787 FXJSE_Value_Set( 784 FXJSE_Value_Set(
788 pValue, m_pDocument->GetScriptContext()->GetJSValueFromMap(pParent)); 785 pValue, m_pDocument->GetScriptContext()->GetJSValueFromMap(pParent));
789 } else { 786 } else {
790 FXJSE_Value_SetNull(pValue); 787 FXJSE_Value_SetNull(pValue);
791 } 788 }
792 } 789 }
793 } 790 }
791
794 void CXFA_Node::Script_TreeClass_Index(CFXJSE_Value* pValue, 792 void CXFA_Node::Script_TreeClass_Index(CFXJSE_Value* pValue,
795 FX_BOOL bSetting, 793 FX_BOOL bSetting,
796 XFA_ATTRIBUTE eAttribute) { 794 XFA_ATTRIBUTE eAttribute) {
797 if (bSetting) { 795 if (bSetting)
798 ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET); 796 ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);
799 } else { 797 else
800 FXJSE_Value_SetInteger(pValue, GetNodeSameNameIndex()); 798 FXJSE_Value_SetInteger(pValue, GetNodeSameNameIndex());
801 }
802 } 799 }
800
803 void CXFA_Node::Script_TreeClass_ClassIndex(CFXJSE_Value* pValue, 801 void CXFA_Node::Script_TreeClass_ClassIndex(CFXJSE_Value* pValue,
804 FX_BOOL bSetting, 802 FX_BOOL bSetting,
805 XFA_ATTRIBUTE eAttribute) { 803 XFA_ATTRIBUTE eAttribute) {
806 if (bSetting) { 804 if (bSetting)
807 ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET); 805 ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);
808 } else { 806 else
809 FXJSE_Value_SetInteger(pValue, GetNodeSameClassIndex()); 807 FXJSE_Value_SetInteger(pValue, GetNodeSameClassIndex());
810 }
811 } 808 }
809
812 void CXFA_Node::Script_TreeClass_SomExpression(CFXJSE_Value* pValue, 810 void CXFA_Node::Script_TreeClass_SomExpression(CFXJSE_Value* pValue,
813 FX_BOOL bSetting, 811 FX_BOOL bSetting,
814 XFA_ATTRIBUTE eAttribute) { 812 XFA_ATTRIBUTE eAttribute) {
815 if (bSetting) { 813 if (bSetting) {
816 ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET); 814 ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);
817 } else { 815 } else {
818 CFX_WideString wsSOMExpression; 816 CFX_WideString wsSOMExpression;
819 GetSOMExpression(wsSOMExpression); 817 GetSOMExpression(wsSOMExpression);
820 FXJSE_Value_SetUTF8String(pValue, 818 FXJSE_Value_SetUTF8String(pValue,
821 FX_UTF8Encode(wsSOMExpression).AsStringC()); 819 FX_UTF8Encode(wsSOMExpression).AsStringC());
822 } 820 }
823 } 821 }
822
824 void CXFA_Node::Script_NodeClass_ApplyXSL(CFXJSE_Arguments* pArguments) { 823 void CXFA_Node::Script_NodeClass_ApplyXSL(CFXJSE_Arguments* pArguments) {
825 int32_t iLength = pArguments->GetLength(); 824 int32_t iLength = pArguments->GetLength();
826 if (iLength != 1) { 825 if (iLength != 1) {
827 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"applyXSL"); 826 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"applyXSL");
828 return; 827 return;
829 } 828 }
830 CFX_WideString wsExpression = 829 CFX_WideString wsExpression =
831 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); 830 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
832 // TODO(weili): check whether we need to implement this, pdfium:501. 831 // TODO(weili): check whether we need to implement this, pdfium:501.
833 // For now, just put the variables here to avoid unused variable warning. 832 // For now, just put the variables here to avoid unused variable warning.
834 (void)wsExpression; 833 (void)wsExpression;
835 } 834 }
836 835
837 void CXFA_Node::Script_NodeClass_AssignNode(CFXJSE_Arguments* pArguments) { 836 void CXFA_Node::Script_NodeClass_AssignNode(CFXJSE_Arguments* pArguments) {
838 int32_t iLength = pArguments->GetLength(); 837 int32_t iLength = pArguments->GetLength();
839 if (iLength < 1 || iLength > 3) { 838 if (iLength < 1 || iLength > 3) {
840 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"assignNode"); 839 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"assignNode");
841 return; 840 return;
842 } 841 }
843 CFX_WideString wsExpression; 842 CFX_WideString wsExpression;
844 CFX_WideString wsValue; 843 CFX_WideString wsValue;
845 int32_t iAction = 0; 844 int32_t iAction = 0;
846 if (iLength >= 1) { 845 wsExpression =
847 wsExpression = 846 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
848 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
849 }
850 if (iLength >= 2) { 847 if (iLength >= 2) {
851 wsValue = 848 wsValue =
852 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC()); 849 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
853 } 850 }
854 if (iLength >= 3) 851 if (iLength >= 3)
855 iAction = pArguments->GetInt32(2); 852 iAction = pArguments->GetInt32(2);
856 // TODO(weili): check whether we need to implement this, pdfium:501. 853 // TODO(weili): check whether we need to implement this, pdfium:501.
857 // For now, just put the variables here to avoid unused variable warning. 854 // For now, just put the variables here to avoid unused variable warning.
858 (void)wsExpression; 855 (void)wsExpression;
859 (void)wsValue; 856 (void)wsValue;
860 (void)iAction; 857 (void)iAction;
861 } 858 }
862 859
863 void CXFA_Node::Script_NodeClass_Clone(CFXJSE_Arguments* pArguments) { 860 void CXFA_Node::Script_NodeClass_Clone(CFXJSE_Arguments* pArguments) {
864 int32_t iLength = pArguments->GetLength(); 861 int32_t iLength = pArguments->GetLength();
865 if (iLength != 1) { 862 if (iLength != 1) {
866 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"clone"); 863 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"clone");
867 return; 864 return;
868 } 865 }
869 FX_BOOL bClone = TRUE; 866 bool bClone = !!pArguments->GetInt32(0);
870 bClone = pArguments->GetInt32(0) == 0 ? FALSE : TRUE;
871 CXFA_Node* pCloneNode = Clone(bClone); 867 CXFA_Node* pCloneNode = Clone(bClone);
872 FXJSE_Value_Set( 868 FXJSE_Value_Set(
873 pArguments->GetReturnValue(), 869 pArguments->GetReturnValue(),
874 m_pDocument->GetScriptContext()->GetJSValueFromMap(pCloneNode)); 870 m_pDocument->GetScriptContext()->GetJSValueFromMap(pCloneNode));
875 } 871 }
872
876 void CXFA_Node::Script_NodeClass_GetAttribute(CFXJSE_Arguments* pArguments) { 873 void CXFA_Node::Script_NodeClass_GetAttribute(CFXJSE_Arguments* pArguments) {
877 int32_t iLength = pArguments->GetLength(); 874 int32_t iLength = pArguments->GetLength();
878 if (iLength != 1) { 875 if (iLength != 1) {
879 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, 876 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
880 L"getAttribute"); 877 L"getAttribute");
881 return; 878 return;
882 } 879 }
883 CFX_WideString wsExpression = 880 CFX_WideString wsExpression =
884 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); 881 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
885 CFX_WideString wsValue; 882 CFX_WideString wsValue;
886 GetAttribute(wsExpression.AsStringC(), wsValue); 883 GetAttribute(wsExpression.AsStringC(), wsValue);
887 CFXJSE_Value* pValue = pArguments->GetReturnValue(); 884 CFXJSE_Value* pValue = pArguments->GetReturnValue();
888 if (pValue) { 885 if (pValue)
889 FXJSE_Value_SetUTF8String(pValue, FX_UTF8Encode(wsValue).AsStringC()); 886 FXJSE_Value_SetUTF8String(pValue, FX_UTF8Encode(wsValue).AsStringC());
890 }
891 } 887 }
888
892 void CXFA_Node::Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments) { 889 void CXFA_Node::Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments) {
893 int32_t iLength = pArguments->GetLength(); 890 int32_t iLength = pArguments->GetLength();
894 if (iLength < 1 || iLength > 2) { 891 if (iLength < 1 || iLength > 2) {
895 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getElement"); 892 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getElement");
896 return; 893 return;
897 } 894 }
898 CFX_WideString wsExpression; 895 CFX_WideString wsExpression;
899 int32_t iValue = 0; 896 int32_t iValue = 0;
900 if (iLength >= 1) { 897 wsExpression =
901 CFX_ByteString bsExpression = pArguments->GetUTF8String(0); 898 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
902 wsExpression = CFX_WideString::FromUTF8(bsExpression.AsStringC()); 899 if (iLength >= 2)
903 }
904 if (iLength >= 2) {
905 iValue = pArguments->GetInt32(1); 900 iValue = pArguments->GetInt32(1);
906 }
907 const XFA_ELEMENTINFO* pElementInfo = 901 const XFA_ELEMENTINFO* pElementInfo =
908 XFA_GetElementByName(wsExpression.AsStringC()); 902 XFA_GetElementByName(wsExpression.AsStringC());
909 CXFA_Node* pNode = GetProperty(iValue, pElementInfo->eName); 903 CXFA_Node* pNode = GetProperty(iValue, pElementInfo->eName);
910 FXJSE_Value_Set(pArguments->GetReturnValue(), 904 FXJSE_Value_Set(pArguments->GetReturnValue(),
911 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode)); 905 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode));
912 } 906 }
913 907
914 void CXFA_Node::Script_NodeClass_IsPropertySpecified( 908 void CXFA_Node::Script_NodeClass_IsPropertySpecified(
915 CFXJSE_Arguments* pArguments) { 909 CFXJSE_Arguments* pArguments) {
916 int32_t iLength = pArguments->GetLength(); 910 int32_t iLength = pArguments->GetLength();
917 if (iLength < 1 || iLength > 3) { 911 if (iLength < 1 || iLength > 3) {
918 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, 912 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
919 L"isPropertySpecified"); 913 L"isPropertySpecified");
920 return; 914 return;
921 } 915 }
922 CFX_WideString wsExpression; 916 CFX_WideString wsExpression;
923 FX_BOOL bParent = TRUE; 917 bool bParent = true;
924 int32_t iIndex = 0; 918 int32_t iIndex = 0;
925 if (iLength >= 1) { 919 wsExpression =
926 wsExpression = 920 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
927 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
928 }
929 if (iLength >= 2) 921 if (iLength >= 2)
930 bParent = !!pArguments->GetInt32(1) ? TRUE : FALSE; 922 bParent = !!pArguments->GetInt32(1);
931 if (iLength >= 3) 923 if (iLength >= 3)
932 iIndex = pArguments->GetInt32(2); 924 iIndex = pArguments->GetInt32(2);
933 FX_BOOL bHas = FALSE; 925 bool bHas = false;
934 const XFA_ATTRIBUTEINFO* pAttributeInfo = 926 const XFA_ATTRIBUTEINFO* pAttributeInfo =
935 XFA_GetAttributeByName(wsExpression.AsStringC()); 927 XFA_GetAttributeByName(wsExpression.AsStringC());
936 CFX_WideString wsValue; 928 CFX_WideString wsValue;
937 if (pAttributeInfo) 929 if (pAttributeInfo)
938 bHas = HasAttribute(pAttributeInfo->eName); 930 bHas = HasAttribute(pAttributeInfo->eName);
939 if (!bHas) { 931 if (!bHas) {
940 const XFA_ELEMENTINFO* pElementInfo = 932 const XFA_ELEMENTINFO* pElementInfo =
941 XFA_GetElementByName(wsExpression.AsStringC()); 933 XFA_GetElementByName(wsExpression.AsStringC());
942 bHas = !!GetProperty(iIndex, pElementInfo->eName); 934 bHas = !!GetProperty(iIndex, pElementInfo->eName);
943 if (!bHas && bParent && m_pParent) { 935 if (!bHas && bParent && m_pParent) {
944 // Also check on the parent. 936 // Also check on the parent.
945 bHas = m_pParent->HasAttribute(pAttributeInfo->eName); 937 bHas = m_pParent->HasAttribute(pAttributeInfo->eName);
946 if (!bHas) 938 if (!bHas)
947 bHas = !!m_pParent->GetProperty(iIndex, pElementInfo->eName); 939 bHas = !!m_pParent->GetProperty(iIndex, pElementInfo->eName);
948 } 940 }
949 } 941 }
950 CFXJSE_Value* pValue = pArguments->GetReturnValue(); 942 CFXJSE_Value* pValue = pArguments->GetReturnValue();
951 if (pValue) 943 if (pValue)
952 FXJSE_Value_SetBoolean(pValue, bHas); 944 FXJSE_Value_SetBoolean(pValue, bHas);
953 } 945 }
954 946
955 void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) { 947 void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) {
956 int32_t iLength = pArguments->GetLength(); 948 int32_t iLength = pArguments->GetLength();
957 if (iLength < 1 || iLength > 3) { 949 if (iLength < 1 || iLength > 3) {
958 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"loadXML"); 950 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"loadXML");
959 return; 951 return;
960 } 952 }
961 CFX_WideString wsExpression; 953 CFX_WideString wsExpression;
962 FX_BOOL bIgnoreRoot = TRUE; 954 bool bIgnoreRoot = true;
963 FX_BOOL bOverwrite = 0; 955 bool bOverwrite = 0;
964 if (iLength >= 1) { 956 wsExpression =
965 CFX_ByteString bsExpression = pArguments->GetUTF8String(0); 957 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
966 wsExpression = CFX_WideString::FromUTF8(bsExpression.AsStringC()); 958 if (wsExpression.IsEmpty())
967 if (wsExpression.IsEmpty()) {
968 return;
969 }
970 }
971 if (iLength >= 2) {
972 bIgnoreRoot = pArguments->GetInt32(1) == 0 ? FALSE : TRUE;
973 }
974 if (iLength >= 3) {
975 bOverwrite = pArguments->GetInt32(2) == 0 ? FALSE : TRUE;
976 }
977 IXFA_Parser* pParser = IXFA_Parser::Create(m_pDocument);
978 if (!pParser) {
979 return; 959 return;
980 } 960 if (iLength >= 2)
981 CFDE_XMLNode* pXMLNode = NULL; 961 bIgnoreRoot = !!pArguments->GetInt32(1);
982 int32_t iParserStatus = pParser->ParseXMLData(wsExpression, pXMLNode, NULL); 962 if (iLength >= 3)
983 if (iParserStatus != XFA_PARSESTATUS_Done || !pXMLNode) { 963 bOverwrite = !!pArguments->GetInt32(2);
984 pParser->Release(); 964 std::unique_ptr<IXFA_Parser> pParser(IXFA_Parser::Create(m_pDocument));
Tom Sepez 2016/05/26 23:55:03 Did we get rid of the Release() in IXFA_Parser in
Wei Li 2016/05/27 00:51:45 thanks, added for the other two unique_ptrs as wel
985 pParser = NULL; 965 if (!pParser)
986 return; 966 return;
987 } 967 CFDE_XMLNode* pXMLNode = nullptr;
968 int32_t iParserStatus =
969 pParser->ParseXMLData(wsExpression, pXMLNode, nullptr);
970 if (iParserStatus != XFA_PARSESTATUS_Done || !pXMLNode)
971 return;
988 if (bIgnoreRoot && 972 if (bIgnoreRoot &&
989 (pXMLNode->GetType() != FDE_XMLNODE_Element || 973 (pXMLNode->GetType() != FDE_XMLNODE_Element ||
990 XFA_RecognizeRichText(static_cast<CFDE_XMLElement*>(pXMLNode)))) { 974 XFA_RecognizeRichText(static_cast<CFDE_XMLElement*>(pXMLNode)))) {
991 bIgnoreRoot = FALSE; 975 bIgnoreRoot = false;
992 } 976 }
993 CXFA_Node* pFakeRoot = Clone(FALSE); 977 CXFA_Node* pFakeRoot = Clone(FALSE);
994 CFX_WideStringC wsContentType = GetCData(XFA_ATTRIBUTE_ContentType); 978 CFX_WideStringC wsContentType = GetCData(XFA_ATTRIBUTE_ContentType);
995 if (!wsContentType.IsEmpty()) { 979 if (!wsContentType.IsEmpty()) {
996 pFakeRoot->SetCData(XFA_ATTRIBUTE_ContentType, 980 pFakeRoot->SetCData(XFA_ATTRIBUTE_ContentType,
997 CFX_WideString(wsContentType)); 981 CFX_WideString(wsContentType));
998 } 982 }
999 CFDE_XMLNode* pFakeXMLRoot = pFakeRoot->GetXMLMappingNode(); 983 CFDE_XMLNode* pFakeXMLRoot = pFakeRoot->GetXMLMappingNode();
1000 if (!pFakeXMLRoot) { 984 if (!pFakeXMLRoot) {
1001 CFDE_XMLNode* pThisXMLRoot = GetXMLMappingNode(); 985 CFDE_XMLNode* pThisXMLRoot = GetXMLMappingNode();
1002 pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone(FALSE) : NULL; 986 pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone(FALSE) : nullptr;
1003 } 987 }
1004 if (!pFakeXMLRoot) { 988 if (!pFakeXMLRoot) {
1005 CFX_WideStringC wsClassName; 989 CFX_WideStringC wsClassName;
1006 GetClassName(wsClassName); 990 GetClassName(wsClassName);
1007 pFakeXMLRoot = new CFDE_XMLElement(CFX_WideString(wsClassName)); 991 pFakeXMLRoot = new CFDE_XMLElement(CFX_WideString(wsClassName));
1008 } 992 }
1009 if (bIgnoreRoot) { 993 if (bIgnoreRoot) {
1010 CFDE_XMLNode* pXMLChild = pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); 994 CFDE_XMLNode* pXMLChild = pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild);
1011 while (pXMLChild) { 995 while (pXMLChild) {
1012 CFDE_XMLNode* pXMLSibling = 996 CFDE_XMLNode* pXMLSibling =
(...skipping 27 matching lines...) Expand all
1040 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); 1024 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1041 RemoveChild(pChild); 1025 RemoveChild(pChild);
1042 pFakeRoot->InsertChild(pChild); 1026 pFakeRoot->InsertChild(pChild);
1043 pChild = pItem; 1027 pChild = pItem;
1044 } 1028 }
1045 if (GetPacketID() == XFA_XDPPACKET_Form && 1029 if (GetPacketID() == XFA_XDPPACKET_Form &&
1046 GetClassID() == XFA_ELEMENT_ExData) { 1030 GetClassID() == XFA_ELEMENT_ExData) {
1047 CFDE_XMLNode* pTempXMLNode = GetXMLMappingNode(); 1031 CFDE_XMLNode* pTempXMLNode = GetXMLMappingNode();
1048 SetXMLMappingNode(pFakeXMLRoot); 1032 SetXMLMappingNode(pFakeXMLRoot);
1049 SetFlag(XFA_NODEFLAG_OwnXMLNode, false); 1033 SetFlag(XFA_NODEFLAG_OwnXMLNode, false);
1050 if (pTempXMLNode && 1034 if (pTempXMLNode && !pTempXMLNode->GetNodeItem(CFDE_XMLNode::Parent)) {
1051 pTempXMLNode->GetNodeItem(CFDE_XMLNode::Parent) == NULL) {
1052 pFakeXMLRoot = pTempXMLNode; 1035 pFakeXMLRoot = pTempXMLNode;
1053 } else { 1036 } else {
1054 pFakeXMLRoot = NULL; 1037 pFakeXMLRoot = nullptr;
1055 } 1038 }
1056 } 1039 }
1057 MoveBufferMapData(pFakeRoot, this, XFA_CalcData, TRUE); 1040 MoveBufferMapData(pFakeRoot, this, XFA_CalcData, TRUE);
1058 } else { 1041 } else {
1059 CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild); 1042 CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild);
1060 while (pChild) { 1043 while (pChild) {
1061 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); 1044 CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling);
1062 pFakeRoot->RemoveChild(pChild); 1045 pFakeRoot->RemoveChild(pChild);
1063 InsertChild(pChild); 1046 InsertChild(pChild);
1064 pChild->SetFlag(XFA_NODEFLAG_Initialized, true); 1047 pChild->SetFlag(XFA_NODEFLAG_Initialized, true);
1065 pChild = pItem; 1048 pChild = pItem;
1066 } 1049 }
1067 } 1050 }
1068 if (pFakeXMLRoot) { 1051 if (pFakeXMLRoot) {
1069 pFakeRoot->SetXMLMappingNode(pFakeXMLRoot); 1052 pFakeRoot->SetXMLMappingNode(pFakeXMLRoot);
1070 pFakeRoot->SetFlag(XFA_NODEFLAG_OwnXMLNode, false); 1053 pFakeRoot->SetFlag(XFA_NODEFLAG_OwnXMLNode, false);
1071 } 1054 }
1072 pFakeRoot->SetFlag(XFA_NODEFLAG_HasRemoved, false); 1055 pFakeRoot->SetFlag(XFA_NODEFLAG_HasRemoved, false);
1073 } else { 1056 } else {
1074 if (pFakeXMLRoot) { 1057 if (pFakeXMLRoot) {
1075 pFakeXMLRoot->Release(); 1058 pFakeXMLRoot->Release();
1076 pFakeXMLRoot = NULL; 1059 pFakeXMLRoot = nullptr;
1077 } 1060 }
1078 } 1061 }
1079 pParser->Release();
1080 pParser = NULL;
1081 } 1062 }
1063
1082 void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) { 1064 void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) {
1065 // TODO(weili): Check whether we need to implement this, pdfium:501.
1083 } 1066 }
1084 1067
1085 void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) { 1068 void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) {
1086 int32_t iLength = pArguments->GetLength(); 1069 int32_t iLength = pArguments->GetLength();
1087 if (iLength < 0 || iLength > 1) { 1070 if (iLength < 0 || iLength > 1) {
1088 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"saveXML"); 1071 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"saveXML");
1089 return; 1072 return;
1090 } 1073 }
1091 FX_BOOL bPrettyMode = FALSE; 1074 bool bPrettyMode = false;
1092 if (iLength == 1) { 1075 if (iLength == 1) {
1093 if (pArguments->GetUTF8String(0) != "pretty") { 1076 if (pArguments->GetUTF8String(0) != "pretty") {
1094 ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH); 1077 ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH);
1095 return; 1078 return;
1096 } 1079 }
1097 bPrettyMode = TRUE; 1080 bPrettyMode = true;
1098 } 1081 }
1099 CFX_ByteStringC bsXMLHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; 1082 CFX_ByteStringC bsXMLHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
1100 if (GetPacketID() == XFA_XDPPACKET_Form || 1083 if (GetPacketID() == XFA_XDPPACKET_Form ||
1101 GetPacketID() == XFA_XDPPACKET_Datasets) { 1084 GetPacketID() == XFA_XDPPACKET_Datasets) {
1102 CFDE_XMLNode* pElement = nullptr; 1085 CFDE_XMLNode* pElement = nullptr;
1103 if (GetPacketID() == XFA_XDPPACKET_Datasets) { 1086 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
1104 pElement = GetXMLMappingNode(); 1087 pElement = GetXMLMappingNode();
1105 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) { 1088 if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) {
1106 FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), bsXMLHeader); 1089 FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), bsXMLHeader);
1107 return; 1090 return;
1108 } 1091 }
1109 XFA_DataExporter_DealWithDataGroupNode(this); 1092 XFA_DataExporter_DealWithDataGroupNode(this);
1110 } 1093 }
1111 std::unique_ptr<IFX_MemoryStream> pMemoryStream( 1094 std::unique_ptr<IFX_MemoryStream> pMemoryStream(
1112 FX_CreateMemoryStream(TRUE)); 1095 FX_CreateMemoryStream(TRUE));
1113 std::unique_ptr<IFX_Stream> pStream(IFX_Stream::CreateStream( 1096 std::unique_ptr<IFX_Stream> pStream(IFX_Stream::CreateStream(
1114 (IFX_FileWrite*)pMemoryStream.get(), 1097 (IFX_FileWrite*)pMemoryStream.get(),
1115 FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append)); 1098 FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append));
1116 if (!pStream) { 1099 if (!pStream) {
1117 FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), bsXMLHeader); 1100 FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), bsXMLHeader);
1118 return; 1101 return;
1119 } 1102 }
1120 pStream->SetCodePage(FX_CODEPAGE_UTF8); 1103 pStream->SetCodePage(FX_CODEPAGE_UTF8);
1121 pStream->WriteData(bsXMLHeader.raw_str(), bsXMLHeader.GetLength()); 1104 pStream->WriteData(bsXMLHeader.raw_str(), bsXMLHeader.GetLength());
1122 if (GetPacketID() == XFA_XDPPACKET_Form) 1105 if (GetPacketID() == XFA_XDPPACKET_Form)
1123 XFA_DataExporter_RegenerateFormFile(this, pStream.get(), NULL, TRUE); 1106 XFA_DataExporter_RegenerateFormFile(this, pStream.get(), nullptr, TRUE);
1124 else 1107 else
1125 pElement->SaveXMLNode(pStream.get()); 1108 pElement->SaveXMLNode(pStream.get());
1126 // TODO(weili): Check whether we need to save pretty print XML, pdfium:501. 1109 // TODO(weili): Check whether we need to save pretty print XML, pdfium:501.
1127 // For now, just put it here to avoid unused variable warning. 1110 // For now, just put it here to avoid unused variable warning.
1128 (void)bPrettyMode; 1111 (void)bPrettyMode;
1129 FXJSE_Value_SetUTF8String( 1112 FXJSE_Value_SetUTF8String(
1130 pArguments->GetReturnValue(), 1113 pArguments->GetReturnValue(),
1131 CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize())); 1114 CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize()));
1132 return; 1115 return;
1133 } 1116 }
1134 FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), ""); 1117 FXJSE_Value_SetUTF8String(pArguments->GetReturnValue(), "");
1135 } 1118 }
1136 1119
1137 void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) { 1120 void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) {
1138 int32_t iLength = pArguments->GetLength(); 1121 int32_t iLength = pArguments->GetLength();
1139 if (iLength != 2) { 1122 if (iLength != 2) {
1140 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, 1123 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD,
1141 L"setAttribute"); 1124 L"setAttribute");
1142 return; 1125 return;
1143 } 1126 }
1144 CFX_WideString wsAttributeValue = 1127 CFX_WideString wsAttributeValue =
1145 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); 1128 CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC());
1146 CFX_WideString wsAttribute = 1129 CFX_WideString wsAttribute =
1147 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC()); 1130 CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
1148 SetAttribute(wsAttribute.AsStringC(), wsAttributeValue.AsStringC(), TRUE); 1131 SetAttribute(wsAttribute.AsStringC(), wsAttributeValue.AsStringC(), true);
1149 } 1132 }
1150 1133
1151 void CXFA_Node::Script_NodeClass_SetElement(CFXJSE_Arguments* pArguments) { 1134 void CXFA_Node::Script_NodeClass_SetElement(CFXJSE_Arguments* pArguments) {
1152 int32_t iLength = pArguments->GetLength(); 1135 int32_t iLength = pArguments->GetLength();
1153 if (iLength != 1 && iLength != 2) { 1136 if (iLength != 1 && iLength != 2) {
1154 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setElement"); 1137 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setElement");
1155 return; 1138 return;
1156 } 1139 }
1157 CXFA_Node* pNode = nullptr; 1140 CXFA_Node* pNode = nullptr;
1158 CFX_WideString wsName; 1141 CFX_WideString wsName;
1159 if (iLength >= 1) 1142 pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
1160 pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); 1143 if (iLength == 2)
1161 if (iLength >= 2) {
1162 wsName = CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC()); 1144 wsName = CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC());
1163 }
1164 // TODO(weili): check whether we need to implement this, pdfium:501. 1145 // TODO(weili): check whether we need to implement this, pdfium:501.
1165 // For now, just put the variables here to avoid unused variable warning. 1146 // For now, just put the variables here to avoid unused variable warning.
1166 (void)pNode; 1147 (void)pNode;
1167 (void)wsName; 1148 (void)wsName;
1168 } 1149 }
1169 1150
1170 void CXFA_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue, 1151 void CXFA_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue,
1171 FX_BOOL bSetting, 1152 FX_BOOL bSetting,
1172 XFA_ATTRIBUTE eAttribute) { 1153 XFA_ATTRIBUTE eAttribute) {
1173 if (bSetting) { 1154 if (bSetting) {
1174 ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET); 1155 ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);
1175 } else { 1156 } else {
1176 CFX_WideString wsNameSpace; 1157 CFX_WideString wsNameSpace;
1177 TryNamespace(wsNameSpace); 1158 TryNamespace(wsNameSpace);
1178 FXJSE_Value_SetUTF8String(pValue, FX_UTF8Encode(wsNameSpace).AsStringC()); 1159 FXJSE_Value_SetUTF8String(pValue, FX_UTF8Encode(wsNameSpace).AsStringC());
1179 } 1160 }
1180 } 1161 }
1162
1181 void CXFA_Node::Script_NodeClass_Model(CFXJSE_Value* pValue, 1163 void CXFA_Node::Script_NodeClass_Model(CFXJSE_Value* pValue,
1182 FX_BOOL bSetting, 1164 FX_BOOL bSetting,
1183 XFA_ATTRIBUTE eAttribute) { 1165 XFA_ATTRIBUTE eAttribute) {
1184 if (bSetting) { 1166 if (bSetting) {
1185 ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET); 1167 ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);
1186 } else { 1168 } else {
1187 FXJSE_Value_Set(pValue, m_pDocument->GetScriptContext()->GetJSValueFromMap( 1169 FXJSE_Value_Set(pValue, m_pDocument->GetScriptContext()->GetJSValueFromMap(
1188 GetModelNode())); 1170 GetModelNode()));
1189 } 1171 }
1190 } 1172 }
1173
1191 void CXFA_Node::Script_NodeClass_IsContainer(CFXJSE_Value* pValue, 1174 void CXFA_Node::Script_NodeClass_IsContainer(CFXJSE_Value* pValue,
1192 FX_BOOL bSetting, 1175 FX_BOOL bSetting,
1193 XFA_ATTRIBUTE eAttribute) { 1176 XFA_ATTRIBUTE eAttribute) {
1194 if (bSetting) { 1177 if (bSetting)
1195 ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET); 1178 ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);
1196 } else { 1179 else
1197 FXJSE_Value_SetBoolean(pValue, IsContainerNode()); 1180 FXJSE_Value_SetBoolean(pValue, IsContainerNode());
1198 }
1199 } 1181 }
1182
1200 void CXFA_Node::Script_NodeClass_IsNull(CFXJSE_Value* pValue, 1183 void CXFA_Node::Script_NodeClass_IsNull(CFXJSE_Value* pValue,
1201 FX_BOOL bSetting, 1184 FX_BOOL bSetting,
1202 XFA_ATTRIBUTE eAttribute) { 1185 XFA_ATTRIBUTE eAttribute) {
1203 if (bSetting) { 1186 if (bSetting) {
1204 ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET); 1187 ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);
1205 } else { 1188 } else {
1206 if (GetClassID() == XFA_ELEMENT_Subform) { 1189 if (GetClassID() == XFA_ELEMENT_Subform) {
1207 FXJSE_Value_SetBoolean(pValue, FALSE); 1190 FXJSE_Value_SetBoolean(pValue, FALSE);
1208 return; 1191 return;
1209 } 1192 }
1210 CFX_WideString strValue; 1193 CFX_WideString strValue;
1211 FXJSE_Value_SetBoolean(pValue, !TryContent(strValue) || strValue.IsEmpty()); 1194 FXJSE_Value_SetBoolean(pValue, !TryContent(strValue) || strValue.IsEmpty());
1212 } 1195 }
1213 } 1196 }
1197
1214 void CXFA_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue, 1198 void CXFA_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue,
1215 FX_BOOL bSetting, 1199 FX_BOOL bSetting,
1216 XFA_ATTRIBUTE eAttribute) { 1200 XFA_ATTRIBUTE eAttribute) {
1217 if (bSetting) { 1201 if (bSetting) {
1218 ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET); 1202 ThrowScriptErrorMessage(XFA_IDS_INVAlID_PROP_SET);
1219 } else { 1203 } else {
1220 CXFA_NodeArray properts; 1204 CXFA_NodeArray properts;
1221 int32_t iSize = GetNodeList(properts, XFA_NODEFILTER_OneOfProperty); 1205 int32_t iSize = GetNodeList(properts, XFA_NODEFILTER_OneOfProperty);
1222 if (iSize > 0) { 1206 if (iSize > 0) {
1223 FXJSE_Value_Set( 1207 FXJSE_Value_Set(
1224 pValue, 1208 pValue,
1225 m_pDocument->GetScriptContext()->GetJSValueFromMap(properts[0])); 1209 m_pDocument->GetScriptContext()->GetJSValueFromMap(properts[0]));
1226 } 1210 }
1227 } 1211 }
1228 } 1212 }
1213
1229 void CXFA_Node::Script_ContainerClass_GetDelta(CFXJSE_Arguments* pArguments) {} 1214 void CXFA_Node::Script_ContainerClass_GetDelta(CFXJSE_Arguments* pArguments) {}
1230 void CXFA_Node::Script_ContainerClass_GetDeltas(CFXJSE_Arguments* pArguments) { 1215 void CXFA_Node::Script_ContainerClass_GetDeltas(CFXJSE_Arguments* pArguments) {
1231 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument); 1216 CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument);
1232 FXJSE_Value_SetObject(pArguments->GetReturnValue(), (CXFA_Object*)pFormNodes, 1217 FXJSE_Value_SetObject(pArguments->GetReturnValue(), (CXFA_Object*)pFormNodes,
1233 m_pDocument->GetScriptContext()->GetJseNormalClass()); 1218 m_pDocument->GetScriptContext()->GetJseNormalClass());
1234 } 1219 }
1235 void CXFA_Node::Script_ModelClass_ClearErrorList(CFXJSE_Arguments* pArguments) { 1220 void CXFA_Node::Script_ModelClass_ClearErrorList(CFXJSE_Arguments* pArguments) {
1236 } 1221 }
1237 void CXFA_Node::Script_ModelClass_CreateNode(CFXJSE_Arguments* pArguments) { 1222 void CXFA_Node::Script_ModelClass_CreateNode(CFXJSE_Arguments* pArguments) {
1238 Script_Template_CreateNode(pArguments); 1223 Script_Template_CreateNode(pArguments);
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1468 CXFA_Node* pProtoRoot = 1453 CXFA_Node* pProtoRoot =
1469 pTemplateNode->GetFirstChildByClass(XFA_ELEMENT_Subform) 1454 pTemplateNode->GetFirstChildByClass(XFA_ELEMENT_Subform)
1470 ->GetFirstChildByClass(XFA_ELEMENT_Proto); 1455 ->GetFirstChildByClass(XFA_ELEMENT_Proto);
1471 if (!wsUseVal.IsEmpty()) { 1456 if (!wsUseVal.IsEmpty()) {
1472 if (wsUseVal[0] == '#') { 1457 if (wsUseVal[0] == '#') {
1473 wsID = CFX_WideString(wsUseVal.c_str() + 1, wsUseVal.GetLength() - 1); 1458 wsID = CFX_WideString(wsUseVal.c_str() + 1, wsUseVal.GetLength() - 1);
1474 } else { 1459 } else {
1475 wsSOM = wsUseVal; 1460 wsSOM = wsUseVal;
1476 } 1461 }
1477 } 1462 }
1478 CXFA_Node* pProtoNode = NULL; 1463 CXFA_Node* pProtoNode = nullptr;
1479 if (!wsSOM.IsEmpty()) { 1464 if (!wsSOM.IsEmpty()) {
1480 uint32_t dwFlag = XFA_RESOLVENODE_Children | 1465 uint32_t dwFlag = XFA_RESOLVENODE_Children |
1481 XFA_RESOLVENODE_Attributes | 1466 XFA_RESOLVENODE_Attributes |
1482 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | 1467 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent |
1483 XFA_RESOLVENODE_Siblings; 1468 XFA_RESOLVENODE_Siblings;
1484 XFA_RESOLVENODE_RS resoveNodeRS; 1469 XFA_RESOLVENODE_RS resoveNodeRS;
1485 int32_t iRet = m_pDocument->GetScriptContext()->ResolveObjects( 1470 int32_t iRet = m_pDocument->GetScriptContext()->ResolveObjects(
1486 pProtoRoot, wsSOM.AsStringC(), resoveNodeRS, dwFlag); 1471 pProtoRoot, wsSOM.AsStringC(), resoveNodeRS, dwFlag);
1487 if (iRet > 0 && resoveNodeRS.nodes[0]->IsNode()) { 1472 if (iRet > 0 && resoveNodeRS.nodes[0]->IsNode()) {
1488 pProtoNode = resoveNodeRS.nodes[0]->AsNode(); 1473 pProtoNode = resoveNodeRS.nodes[0]->AsNode();
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1646 Script_Boolean_Value(pValue, bSetting, eAttribute); 1631 Script_Boolean_Value(pValue, bSetting, eAttribute);
1647 return; 1632 return;
1648 } 1633 }
1649 if (bSetting) { 1634 if (bSetting) {
1650 CFX_ByteString newValue; 1635 CFX_ByteString newValue;
1651 if (!(FXJSE_Value_IsNull(pValue) || FXJSE_Value_IsUndefined(pValue))) { 1636 if (!(FXJSE_Value_IsNull(pValue) || FXJSE_Value_IsUndefined(pValue))) {
1652 FXJSE_Value_ToUTF8String(pValue, newValue); 1637 FXJSE_Value_ToUTF8String(pValue, newValue);
1653 } 1638 }
1654 CFX_WideString wsNewValue = CFX_WideString::FromUTF8(newValue.AsStringC()); 1639 CFX_WideString wsNewValue = CFX_WideString::FromUTF8(newValue.AsStringC());
1655 CFX_WideString wsFormatValue(wsNewValue); 1640 CFX_WideString wsFormatValue(wsNewValue);
1656 CXFA_WidgetData* pContainerWidgetData = NULL; 1641 CXFA_WidgetData* pContainerWidgetData = nullptr;
1657 if (GetPacketID() == XFA_XDPPACKET_Datasets) { 1642 if (GetPacketID() == XFA_XDPPACKET_Datasets) {
1658 CXFA_NodeArray formNodes; 1643 CXFA_NodeArray formNodes;
1659 GetBindItems(formNodes); 1644 GetBindItems(formNodes);
1660 CFX_WideString wsPicture; 1645 CFX_WideString wsPicture;
1661 for (int32_t i = 0; i < formNodes.GetSize(); i++) { 1646 for (int32_t i = 0; i < formNodes.GetSize(); i++) {
1662 CXFA_Node* pFormNode = formNodes.GetAt(i); 1647 CXFA_Node* pFormNode = formNodes.GetAt(i);
1663 if (!pFormNode || pFormNode->HasFlag(XFA_NODEFLAG_HasRemoved)) { 1648 if (!pFormNode || pFormNode->HasFlag(XFA_NODEFLAG_HasRemoved)) {
1664 continue; 1649 continue;
1665 } 1650 }
1666 pContainerWidgetData = pFormNode->GetContainerWidgetData(); 1651 pContainerWidgetData = pFormNode->GetContainerWidgetData();
1667 if (pContainerWidgetData) { 1652 if (pContainerWidgetData) {
1668 pContainerWidgetData->GetPictureContent(wsPicture, 1653 pContainerWidgetData->GetPictureContent(wsPicture,
1669 XFA_VALUEPICTURE_DataBind); 1654 XFA_VALUEPICTURE_DataBind);
1670 } 1655 }
1671 if (!wsPicture.IsEmpty()) { 1656 if (!wsPicture.IsEmpty()) {
1672 break; 1657 break;
1673 } 1658 }
1674 pContainerWidgetData = NULL; 1659 pContainerWidgetData = nullptr;
1675 } 1660 }
1676 } else if (GetPacketID() == XFA_XDPPACKET_Form) { 1661 } else if (GetPacketID() == XFA_XDPPACKET_Form) {
1677 pContainerWidgetData = GetContainerWidgetData(); 1662 pContainerWidgetData = GetContainerWidgetData();
1678 } 1663 }
1679 if (pContainerWidgetData) { 1664 if (pContainerWidgetData) {
1680 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue); 1665 pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue);
1681 } 1666 }
1682 SetScriptContent(wsNewValue, wsFormatValue, true, TRUE); 1667 SetScriptContent(wsNewValue, wsFormatValue, true, TRUE);
1683 } else { 1668 } else {
1684 CFX_WideString content = GetScriptContent(TRUE); 1669 CFX_WideString content = GetScriptContent(TRUE);
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
2407 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent"); 2392 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent");
2408 } 2393 }
2409 } 2394 }
2410 void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments) { 2395 void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments) {
2411 int32_t argc = pArguments->GetLength(); 2396 int32_t argc = pArguments->GetLength();
2412 if ((argc == 0) || (argc == 1)) { 2397 if ((argc == 0) || (argc == 1)) {
2413 CXFA_WidgetData* pWidgetData = GetWidgetData(); 2398 CXFA_WidgetData* pWidgetData = GetWidgetData();
2414 if (!pWidgetData) { 2399 if (!pWidgetData) {
2415 FXJSE_Value_SetNull(pArguments->GetReturnValue()); 2400 FXJSE_Value_SetNull(pArguments->GetReturnValue());
2416 } else { 2401 } else {
2417 CXFA_Node* pReturnNode = NULL; 2402 CXFA_Node* pReturnNode = nullptr;
2418 if (argc == 0) { 2403 if (argc == 0) {
2419 pReturnNode = pWidgetData->GetSelectedMember(); 2404 pReturnNode = pWidgetData->GetSelectedMember();
2420 } else { 2405 } else {
2421 CFX_ByteString szName; 2406 CFX_ByteString szName;
2422 szName = pArguments->GetUTF8String(0); 2407 szName = pArguments->GetUTF8String(0);
2423 pReturnNode = pWidgetData->SetSelectedMember( 2408 pReturnNode = pWidgetData->SetSelectedMember(
2424 CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC()); 2409 CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC());
2425 } 2410 }
2426 if (pReturnNode) { 2411 if (pReturnNode) {
2427 FXJSE_Value_Set( 2412 FXJSE_Value_Set(
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2491 } 2476 }
2492 if ((eCurType != XFA_ELEMENT_Subform) && 2477 if ((eCurType != XFA_ELEMENT_Subform) &&
2493 (eCurType != XFA_ELEMENT_SubformSet)) { 2478 (eCurType != XFA_ELEMENT_SubformSet)) {
2494 continue; 2479 continue;
2495 } 2480 }
2496 if (iCount == 0) { 2481 if (iCount == 0) {
2497 CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name); 2482 CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name);
2498 CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name); 2483 CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name);
2499 if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' || 2484 if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' ||
2500 wsInstName.Mid(1) != wsName) { 2485 wsInstName.Mid(1) != wsName) {
2501 return NULL; 2486 return nullptr;
2502 } 2487 }
2503 dwNameHash = pNode->GetNameHash(); 2488 dwNameHash = pNode->GetNameHash();
2504 } 2489 }
2505 if (dwNameHash != pNode->GetNameHash()) { 2490 if (dwNameHash != pNode->GetNameHash()) {
2506 break; 2491 break;
2507 } 2492 }
2508 iCount++; 2493 iCount++;
2509 if (iCount > iIndex) { 2494 if (iCount > iIndex) {
2510 return pNode; 2495 return pNode;
2511 } 2496 }
2512 } 2497 }
2513 return NULL; 2498 return nullptr;
2514 } 2499 }
2515 void CXFA_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue, 2500 void CXFA_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue,
2516 FX_BOOL bSetting, 2501 FX_BOOL bSetting,
2517 XFA_ATTRIBUTE eAttribute) { 2502 XFA_ATTRIBUTE eAttribute) {
2518 if (bSetting) { 2503 if (bSetting) {
2519 int32_t iTo = FXJSE_Value_ToInteger(pValue); 2504 int32_t iTo = FXJSE_Value_ToInteger(pValue);
2520 int32_t iFrom = Subform_and_SubformSet_InstanceIndex(); 2505 int32_t iFrom = Subform_and_SubformSet_InstanceIndex();
2521 CXFA_Node* pManagerNode = NULL; 2506 CXFA_Node* pManagerNode = nullptr;
2522 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; 2507 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2523 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { 2508 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
2524 if (pNode->GetClassID() == XFA_ELEMENT_InstanceManager) { 2509 if (pNode->GetClassID() == XFA_ELEMENT_InstanceManager) {
2525 pManagerNode = pNode; 2510 pManagerNode = pNode;
2526 break; 2511 break;
2527 } 2512 }
2528 } 2513 }
2529 if (pManagerNode) { 2514 if (pManagerNode) {
2530 pManagerNode->InstanceManager_MoveInstance(iTo, iFrom); 2515 pManagerNode->InstanceManager_MoveInstance(iTo, iFrom);
2531 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); 2516 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify();
(...skipping 13 matching lines...) Expand all
2545 } 2530 }
2546 } else { 2531 } else {
2547 FXJSE_Value_SetInteger(pValue, Subform_and_SubformSet_InstanceIndex()); 2532 FXJSE_Value_SetInteger(pValue, Subform_and_SubformSet_InstanceIndex());
2548 } 2533 }
2549 } 2534 }
2550 void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue, 2535 void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue,
2551 FX_BOOL bSetting, 2536 FX_BOOL bSetting,
2552 XFA_ATTRIBUTE eAttribute) { 2537 XFA_ATTRIBUTE eAttribute) {
2553 if (!bSetting) { 2538 if (!bSetting) {
2554 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name); 2539 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name);
2555 CXFA_Node* pInstanceMgr = NULL; 2540 CXFA_Node* pInstanceMgr = nullptr;
2556 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; 2541 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
2557 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { 2542 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
2558 if (pNode->GetClassID() == XFA_ELEMENT_InstanceManager) { 2543 if (pNode->GetClassID() == XFA_ELEMENT_InstanceManager) {
2559 CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name); 2544 CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name);
2560 if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' && 2545 if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' &&
2561 wsInstMgrName.Mid(1) == wsName) { 2546 wsInstMgrName.Mid(1) == wsName) {
2562 pInstanceMgr = pNode; 2547 pInstanceMgr = pNode;
2563 } 2548 }
2564 break; 2549 break;
2565 } 2550 }
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
3044 CXFA_Node* pDataNode = pFormNode->GetBindData(); 3029 CXFA_Node* pDataNode = pFormNode->GetBindData();
3045 if (!pDataNode) { 3030 if (!pDataNode) {
3046 continue; 3031 continue;
3047 } 3032 }
3048 if (pDataNode->RemoveBindItem(pFormNode) == 0) { 3033 if (pDataNode->RemoveBindItem(pFormNode) == 0) {
3049 if (CXFA_Node* pDataParent = 3034 if (CXFA_Node* pDataParent =
3050 pDataNode->GetNodeItem(XFA_NODEITEM_Parent)) { 3035 pDataNode->GetNodeItem(XFA_NODEITEM_Parent)) {
3051 pDataParent->RemoveChild(pDataNode); 3036 pDataParent->RemoveChild(pDataNode);
3052 } 3037 }
3053 } 3038 }
3054 pFormNode->SetObject(XFA_ATTRIBUTE_BindingNode, NULL); 3039 pFormNode->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr);
3055 } 3040 }
3056 } 3041 }
3057 static CXFA_Node* XFA_ScriptInstanceManager_CreateInstance( 3042 static CXFA_Node* XFA_ScriptInstanceManager_CreateInstance(
3058 CXFA_Node* pInstMgrNode, 3043 CXFA_Node* pInstMgrNode,
3059 FX_BOOL bDataMerge) { 3044 FX_BOOL bDataMerge) {
3060 CXFA_Document* pDocument = pInstMgrNode->GetDocument(); 3045 CXFA_Document* pDocument = pInstMgrNode->GetDocument();
3061 CXFA_Node* pTemplateNode = pInstMgrNode->GetTemplateNode(); 3046 CXFA_Node* pTemplateNode = pInstMgrNode->GetTemplateNode();
3062 CXFA_Node* pFormParent = pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent); 3047 CXFA_Node* pFormParent = pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent);
3063 CXFA_Node* pDataScope = NULL; 3048 CXFA_Node* pDataScope = nullptr;
3064 for (CXFA_Node* pRootBoundNode = pFormParent; 3049 for (CXFA_Node* pRootBoundNode = pFormParent;
3065 pRootBoundNode && 3050 pRootBoundNode &&
3066 pRootBoundNode->GetObjectType() == XFA_OBJECTTYPE_ContainerNode; 3051 pRootBoundNode->GetObjectType() == XFA_OBJECTTYPE_ContainerNode;
3067 pRootBoundNode = pRootBoundNode->GetNodeItem(XFA_NODEITEM_Parent)) { 3052 pRootBoundNode = pRootBoundNode->GetNodeItem(XFA_NODEITEM_Parent)) {
3068 pDataScope = pRootBoundNode->GetBindData(); 3053 pDataScope = pRootBoundNode->GetBindData();
3069 if (pDataScope) { 3054 if (pDataScope) {
3070 break; 3055 break;
3071 } 3056 }
3072 } 3057 }
3073 if (!pDataScope) { 3058 if (!pDataScope) {
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
3710 XFA_KEYTYPE_Element); 3695 XFA_KEYTYPE_Element);
3711 } 3696 }
3712 FX_BOOL CXFA_Node::HasAttribute(XFA_ATTRIBUTE eAttr, FX_BOOL bCanInherit) { 3697 FX_BOOL CXFA_Node::HasAttribute(XFA_ATTRIBUTE eAttr, FX_BOOL bCanInherit) {
3713 void* pKey = XFA_GetMapKey_Element(GetClassID(), eAttr); 3698 void* pKey = XFA_GetMapKey_Element(GetClassID(), eAttr);
3714 return HasMapModuleKey(pKey, bCanInherit); 3699 return HasMapModuleKey(pKey, bCanInherit);
3715 } 3700 }
3716 FX_BOOL CXFA_Node::SetAttribute(XFA_ATTRIBUTE eAttr, 3701 FX_BOOL CXFA_Node::SetAttribute(XFA_ATTRIBUTE eAttr,
3717 const CFX_WideStringC& wsValue, 3702 const CFX_WideStringC& wsValue,
3718 bool bNotify) { 3703 bool bNotify) {
3719 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr); 3704 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
3720 if (pAttr == NULL) { 3705 if (!pAttr)
3721 return FALSE; 3706 return FALSE;
3722 } 3707
3723 XFA_ATTRIBUTETYPE eType = pAttr->eType; 3708 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3724 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) { 3709 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3725 const XFA_NOTSUREATTRIBUTE* pNotsure = 3710 const XFA_NOTSUREATTRIBUTE* pNotsure =
3726 XFA_GetNotsureAttribute(GetClassID(), pAttr->eName); 3711 XFA_GetNotsureAttribute(GetClassID(), pAttr->eName);
3727 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata; 3712 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3728 } 3713 }
3729 switch (eType) { 3714 switch (eType) {
3730 case XFA_ATTRIBUTETYPE_Enum: { 3715 case XFA_ATTRIBUTETYPE_Enum: {
3731 const XFA_ATTRIBUTEENUMINFO* pEnum = XFA_GetAttributeEnumByName(wsValue); 3716 const XFA_ATTRIBUTEENUMINFO* pEnum = XFA_GetAttributeEnumByName(wsValue);
3732 return SetEnum(pAttr->eName, 3717 return SetEnum(pAttr->eName,
(...skipping 14 matching lines...) Expand all
3747 return SetMeasure(pAttr->eName, CXFA_Measurement(wsValue), bNotify); 3732 return SetMeasure(pAttr->eName, CXFA_Measurement(wsValue), bNotify);
3748 default: 3733 default:
3749 break; 3734 break;
3750 } 3735 }
3751 return FALSE; 3736 return FALSE;
3752 } 3737 }
3753 FX_BOOL CXFA_Node::GetAttribute(XFA_ATTRIBUTE eAttr, 3738 FX_BOOL CXFA_Node::GetAttribute(XFA_ATTRIBUTE eAttr,
3754 CFX_WideString& wsValue, 3739 CFX_WideString& wsValue,
3755 FX_BOOL bUseDefault) { 3740 FX_BOOL bUseDefault) {
3756 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr); 3741 const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr);
3757 if (pAttr == NULL) { 3742 if (!pAttr) {
3758 return FALSE; 3743 return FALSE;
3759 } 3744 }
3760 XFA_ATTRIBUTETYPE eType = pAttr->eType; 3745 XFA_ATTRIBUTETYPE eType = pAttr->eType;
3761 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) { 3746 if (eType == XFA_ATTRIBUTETYPE_NOTSURE) {
3762 const XFA_NOTSUREATTRIBUTE* pNotsure = 3747 const XFA_NOTSUREATTRIBUTE* pNotsure =
3763 XFA_GetNotsureAttribute(GetClassID(), pAttr->eName); 3748 XFA_GetNotsureAttribute(GetClassID(), pAttr->eName);
3764 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata; 3749 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata;
3765 } 3750 }
3766 switch (eType) { 3751 switch (eType) {
3767 case XFA_ATTRIBUTETYPE_Enum: { 3752 case XFA_ATTRIBUTETYPE_Enum: {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
3835 return TRUE; 3820 return TRUE;
3836 } 3821 }
3837 FX_BOOL CXFA_Node::RemoveAttribute(const CFX_WideStringC& wsAttr) { 3822 FX_BOOL CXFA_Node::RemoveAttribute(const CFX_WideStringC& wsAttr) {
3838 void* pKey = XFA_GetMapKey_Custom(wsAttr); 3823 void* pKey = XFA_GetMapKey_Custom(wsAttr);
3839 RemoveMapModuleKey(pKey); 3824 RemoveMapModuleKey(pKey);
3840 return TRUE; 3825 return TRUE;
3841 } 3826 }
3842 FX_BOOL CXFA_Node::TryBoolean(XFA_ATTRIBUTE eAttr, 3827 FX_BOOL CXFA_Node::TryBoolean(XFA_ATTRIBUTE eAttr,
3843 FX_BOOL& bValue, 3828 FX_BOOL& bValue,
3844 FX_BOOL bUseDefault) { 3829 FX_BOOL bUseDefault) {
3845 void* pValue = NULL; 3830 void* pValue = nullptr;
3846 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Boolean, bUseDefault, pValue)) { 3831 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Boolean, bUseDefault, pValue)) {
Tom Sepez 2016/05/26 23:55:03 nit: no {}
Wei Li 2016/05/27 00:51:46 Done.
3847 return FALSE; 3832 return FALSE;
3848 } 3833 }
3849 bValue = (FX_BOOL)(uintptr_t)pValue; 3834 bValue = (FX_BOOL)(uintptr_t)pValue;
3850 return TRUE; 3835 return TRUE;
3851 } 3836 }
3852 FX_BOOL CXFA_Node::TryInteger(XFA_ATTRIBUTE eAttr, 3837 FX_BOOL CXFA_Node::TryInteger(XFA_ATTRIBUTE eAttr,
3853 int32_t& iValue, 3838 int32_t& iValue,
3854 FX_BOOL bUseDefault) { 3839 FX_BOOL bUseDefault) {
3855 void* pValue = NULL; 3840 void* pValue = nullptr;
3856 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Integer, bUseDefault, pValue)) { 3841 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Integer, bUseDefault, pValue)) {
Tom Sepez 2016/05/26 23:55:04 ditto
Wei Li 2016/05/27 00:51:45 Done.
3857 return FALSE; 3842 return FALSE;
3858 } 3843 }
3859 iValue = (int32_t)(uintptr_t)pValue; 3844 iValue = (int32_t)(uintptr_t)pValue;
3860 return TRUE; 3845 return TRUE;
3861 } 3846 }
3862 FX_BOOL CXFA_Node::TryEnum(XFA_ATTRIBUTE eAttr, 3847 FX_BOOL CXFA_Node::TryEnum(XFA_ATTRIBUTE eAttr,
3863 XFA_ATTRIBUTEENUM& eValue, 3848 XFA_ATTRIBUTEENUM& eValue,
3864 FX_BOOL bUseDefault) { 3849 FX_BOOL bUseDefault) {
3865 void* pValue = NULL; 3850 void* pValue = nullptr;
3866 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Enum, bUseDefault, pValue)) { 3851 if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Enum, bUseDefault, pValue)) {
Tom Sepez 2016/05/26 23:55:04 ditto
Wei Li 2016/05/27 00:51:45 Done.
3867 return FALSE; 3852 return FALSE;
3868 } 3853 }
3869 eValue = (XFA_ATTRIBUTEENUM)(uintptr_t)pValue; 3854 eValue = (XFA_ATTRIBUTEENUM)(uintptr_t)pValue;
3870 return TRUE; 3855 return TRUE;
3871 } 3856 }
3872 3857
3873 FX_BOOL CXFA_Node::SetMeasure(XFA_ATTRIBUTE eAttr, 3858 FX_BOOL CXFA_Node::SetMeasure(XFA_ATTRIBUTE eAttr,
3874 CXFA_Measurement mValue, 3859 CXFA_Measurement mValue,
3875 bool bNotify) { 3860 bool bNotify) {
3876 void* pKey = XFA_GetMapKey_Element(GetClassID(), eAttr); 3861 void* pKey = XFA_GetMapKey_Element(GetClassID(), eAttr);
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
4039 } else { 4024 } else {
4040 CFX_WideStringC wsValueC; 4025 CFX_WideStringC wsValueC;
4041 if (GetMapModuleString(pKey, wsValueC)) { 4026 if (GetMapModuleString(pKey, wsValueC)) {
4042 wsValue = wsValueC; 4027 wsValue = wsValueC;
4043 return TRUE; 4028 return TRUE;
4044 } 4029 }
4045 } 4030 }
4046 if (!bUseDefault) { 4031 if (!bUseDefault) {
4047 return FALSE; 4032 return FALSE;
4048 } 4033 }
4049 void* pValue = NULL; 4034 void* pValue = nullptr;
4050 if (XFA_GetAttributeDefaultValue(pValue, GetClassID(), eAttr, 4035 if (XFA_GetAttributeDefaultValue(pValue, GetClassID(), eAttr,
4051 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) { 4036 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
4052 wsValue = (const FX_WCHAR*)pValue; 4037 wsValue = (const FX_WCHAR*)pValue;
4053 return TRUE; 4038 return TRUE;
4054 } 4039 }
4055 return FALSE; 4040 return FALSE;
4056 } 4041 }
4057 FX_BOOL CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr, 4042 FX_BOOL CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr,
4058 CFX_WideStringC& wsValue, 4043 CFX_WideStringC& wsValue,
4059 FX_BOOL bUseDefault, 4044 FX_BOOL bUseDefault,
4060 FX_BOOL bProto) { 4045 FX_BOOL bProto) {
4061 void* pKey = XFA_GetMapKey_Element(GetClassID(), eAttr); 4046 void* pKey = XFA_GetMapKey_Element(GetClassID(), eAttr);
4062 if (eAttr == XFA_ATTRIBUTE_Value) { 4047 if (eAttr == XFA_ATTRIBUTE_Value) {
4063 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto); 4048 CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto);
4064 if (pStr) { 4049 if (pStr) {
4065 wsValue = pStr->AsStringC(); 4050 wsValue = pStr->AsStringC();
4066 return TRUE; 4051 return TRUE;
4067 } 4052 }
4068 } else { 4053 } else {
4069 if (GetMapModuleString(pKey, wsValue)) { 4054 if (GetMapModuleString(pKey, wsValue)) {
4070 return TRUE; 4055 return TRUE;
4071 } 4056 }
4072 } 4057 }
4073 if (!bUseDefault) { 4058 if (!bUseDefault) {
4074 return FALSE; 4059 return FALSE;
4075 } 4060 }
4076 void* pValue = NULL; 4061 void* pValue = nullptr;
4077 if (XFA_GetAttributeDefaultValue(pValue, GetClassID(), eAttr, 4062 if (XFA_GetAttributeDefaultValue(pValue, GetClassID(), eAttr,
4078 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) { 4063 XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) {
4079 wsValue = (CFX_WideStringC)(const FX_WCHAR*)pValue; 4064 wsValue = (CFX_WideStringC)(const FX_WCHAR*)pValue;
4080 return TRUE; 4065 return TRUE;
4081 } 4066 }
4082 return FALSE; 4067 return FALSE;
4083 } 4068 }
4084 FX_BOOL CXFA_Node::SetObject(XFA_ATTRIBUTE eAttr, 4069 FX_BOOL CXFA_Node::SetObject(XFA_ATTRIBUTE eAttr,
4085 void* pData, 4070 void* pData,
4086 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) { 4071 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
4087 void* pKey = XFA_GetMapKey_Element(GetClassID(), eAttr); 4072 void* pKey = XFA_GetMapKey_Element(GetClassID(), eAttr);
4088 return SetUserData(pKey, pData, pCallbackInfo); 4073 return SetUserData(pKey, pData, pCallbackInfo);
4089 } 4074 }
4090 FX_BOOL CXFA_Node::TryObject(XFA_ATTRIBUTE eAttr, void*& pData) { 4075 FX_BOOL CXFA_Node::TryObject(XFA_ATTRIBUTE eAttr, void*& pData) {
4091 void* pKey = XFA_GetMapKey_Element(GetClassID(), eAttr); 4076 void* pKey = XFA_GetMapKey_Element(GetClassID(), eAttr);
4092 pData = GetUserData(pKey); 4077 pData = GetUserData(pKey);
4093 return pData != NULL; 4078 return pData != nullptr;
4094 } 4079 }
4095 FX_BOOL CXFA_Node::SetValue(XFA_ATTRIBUTE eAttr, 4080 FX_BOOL CXFA_Node::SetValue(XFA_ATTRIBUTE eAttr,
4096 XFA_ATTRIBUTETYPE eType, 4081 XFA_ATTRIBUTETYPE eType,
4097 void* pValue, 4082 void* pValue,
4098 bool bNotify) { 4083 bool bNotify) {
4099 void* pKey = XFA_GetMapKey_Element(GetClassID(), eAttr); 4084 void* pKey = XFA_GetMapKey_Element(GetClassID(), eAttr);
4100 OnChanging(eAttr, bNotify); 4085 OnChanging(eAttr, bNotify);
4101 SetMapModuleValue(pKey, pValue); 4086 SetMapModuleValue(pKey, pValue);
4102 OnChanged(eAttr, bNotify, FALSE); 4087 OnChanged(eAttr, bNotify, FALSE);
4103 if (IsNeedSavingXMLNode()) { 4088 if (IsNeedSavingXMLNode()) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
4136 return TRUE; 4121 return TRUE;
4137 } 4122 }
4138 if (!bUseDefault) { 4123 if (!bUseDefault) {
4139 return FALSE; 4124 return FALSE;
4140 } 4125 }
4141 return XFA_GetAttributeDefaultValue(pValue, GetClassID(), eAttr, eType, 4126 return XFA_GetAttributeDefaultValue(pValue, GetClassID(), eAttr, eType,
4142 m_ePacket); 4127 m_ePacket);
4143 } 4128 }
4144 static void XFA_DefaultFreeData(void* pData) {} 4129 static void XFA_DefaultFreeData(void* pData) {}
4145 static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADefaultFreeData = { 4130 static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADefaultFreeData = {
4146 XFA_DefaultFreeData, NULL}; 4131 XFA_DefaultFreeData, nullptr};
4147 FX_BOOL CXFA_Node::SetUserData(void* pKey, 4132 FX_BOOL CXFA_Node::SetUserData(void* pKey,
4148 void* pData, 4133 void* pData,
4149 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) { 4134 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
4150 SetMapModuleBuffer(pKey, &pData, sizeof(void*), 4135 SetMapModuleBuffer(pKey, &pData, sizeof(void*),
4151 pCallbackInfo ? pCallbackInfo : &gs_XFADefaultFreeData); 4136 pCallbackInfo ? pCallbackInfo : &gs_XFADefaultFreeData);
4152 return TRUE; 4137 return TRUE;
4153 } 4138 }
4154 FX_BOOL CXFA_Node::TryUserData(void* pKey, void*& pData, FX_BOOL bProtoAlso) { 4139 FX_BOOL CXFA_Node::TryUserData(void* pKey, void*& pData, FX_BOOL bProtoAlso) {
4155 int32_t iBytes = 0; 4140 int32_t iBytes = 0;
4156 if (!GetMapModuleBuffer(pKey, pData, iBytes, bProtoAlso)) { 4141 if (!GetMapModuleBuffer(pKey, pData, iBytes, bProtoAlso)) {
4157 return FALSE; 4142 return FALSE;
4158 } 4143 }
4159 return iBytes == sizeof(void*) && FXSYS_memcpy(&pData, pData, iBytes); 4144 return iBytes == sizeof(void*) && FXSYS_memcpy(&pData, pData, iBytes);
4160 } 4145 }
4161 FX_BOOL CXFA_Node::SetScriptContent(const CFX_WideString& wsContent, 4146 FX_BOOL CXFA_Node::SetScriptContent(const CFX_WideString& wsContent,
4162 const CFX_WideString& wsXMLValue, 4147 const CFX_WideString& wsXMLValue,
4163 bool bNotify, 4148 bool bNotify,
4164 FX_BOOL bScriptModify, 4149 FX_BOOL bScriptModify,
4165 FX_BOOL bSyncData) { 4150 FX_BOOL bSyncData) {
4166 CXFA_Node* pNode = NULL; 4151 CXFA_Node* pNode = nullptr;
4167 CXFA_Node* pBindNode = NULL; 4152 CXFA_Node* pBindNode = nullptr;
4168 switch (GetObjectType()) { 4153 switch (GetObjectType()) {
4169 case XFA_OBJECTTYPE_ContainerNode: { 4154 case XFA_OBJECTTYPE_ContainerNode: {
4170 if (XFA_FieldIsMultiListBox(this)) { 4155 if (XFA_FieldIsMultiListBox(this)) {
4171 CXFA_Node* pValue = GetProperty(0, XFA_ELEMENT_Value); 4156 CXFA_Node* pValue = GetProperty(0, XFA_ELEMENT_Value);
4172 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild); 4157 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
4173 ASSERT(pChildValue); 4158 ASSERT(pChildValue);
4174 pChildValue->SetCData(XFA_ATTRIBUTE_ContentType, L"text/xml"); 4159 pChildValue->SetCData(XFA_ATTRIBUTE_ContentType, L"text/xml");
4175 pChildValue->SetScriptContent(wsContent, wsContent, bNotify, 4160 pChildValue->SetScriptContent(wsContent, wsContent, bNotify,
4176 bScriptModify, FALSE); 4161 bScriptModify, FALSE);
4177 CXFA_Node* pBind = GetBindData(); 4162 CXFA_Node* pBind = GetBindData();
(...skipping 22 matching lines...) Expand all
4200 while (CXFA_Node* pChildNode = 4185 while (CXFA_Node* pChildNode =
4201 pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) { 4186 pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) {
4202 pBind->RemoveChild(pChildNode); 4187 pBind->RemoveChild(pChildNode);
4203 } 4188 }
4204 } else { 4189 } else {
4205 CXFA_NodeArray valueNodes; 4190 CXFA_NodeArray valueNodes;
4206 int32_t iDatas = pBind->GetNodeList( 4191 int32_t iDatas = pBind->GetNodeList(
4207 valueNodes, XFA_NODEFILTER_Children, XFA_ELEMENT_DataValue); 4192 valueNodes, XFA_NODEFILTER_Children, XFA_ELEMENT_DataValue);
4208 if (iDatas < iSize) { 4193 if (iDatas < iSize) {
4209 int32_t iAddNodes = iSize - iDatas; 4194 int32_t iAddNodes = iSize - iDatas;
4210 CXFA_Node* pValueNodes = NULL; 4195 CXFA_Node* pValueNodes = nullptr;
4211 while (iAddNodes-- > 0) { 4196 while (iAddNodes-- > 0) {
4212 pValueNodes = 4197 pValueNodes =
4213 pBind->CreateSamePacketNode(XFA_ELEMENT_DataValue); 4198 pBind->CreateSamePacketNode(XFA_ELEMENT_DataValue);
4214 pValueNodes->SetCData(XFA_ATTRIBUTE_Name, L"value"); 4199 pValueNodes->SetCData(XFA_ATTRIBUTE_Name, L"value");
4215 pValueNodes->CreateXMLMappingNode(); 4200 pValueNodes->CreateXMLMappingNode();
4216 pBind->InsertChild(pValueNodes); 4201 pBind->InsertChild(pValueNodes);
4217 } 4202 }
4218 pValueNodes = NULL; 4203 pValueNodes = nullptr;
4219 } else if (iDatas > iSize) { 4204 } else if (iDatas > iSize) {
4220 int32_t iDelNodes = iDatas - iSize; 4205 int32_t iDelNodes = iDatas - iSize;
4221 while (iDelNodes-- > 0) { 4206 while (iDelNodes-- > 0) {
4222 pBind->RemoveChild(pBind->GetNodeItem(XFA_NODEITEM_FirstChild)); 4207 pBind->RemoveChild(pBind->GetNodeItem(XFA_NODEITEM_FirstChild));
4223 } 4208 }
4224 } 4209 }
4225 int32_t i = 0; 4210 int32_t i = 0;
4226 for (CXFA_Node* pValueNode = 4211 for (CXFA_Node* pValueNode =
4227 pBind->GetNodeItem(XFA_NODEITEM_FirstChild); 4212 pBind->GetNodeItem(XFA_NODEITEM_FirstChild);
4228 pValueNode; pValueNode = pValueNode->GetNodeItem( 4213 pValueNode; pValueNode = pValueNode->GetNodeItem(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
4260 CXFA_NodeArray nodeArray; 4245 CXFA_NodeArray nodeArray;
4261 pBindNode->GetBindItems(nodeArray); 4246 pBindNode->GetBindItems(nodeArray);
4262 for (int32_t i = 0; i < nodeArray.GetSize(); i++) { 4247 for (int32_t i = 0; i < nodeArray.GetSize(); i++) {
4263 CXFA_Node* pNode = nodeArray[i]; 4248 CXFA_Node* pNode = nodeArray[i];
4264 if (pNode == this) { 4249 if (pNode == this) {
4265 continue; 4250 continue;
4266 } 4251 }
4267 pNode->SetScriptContent(wsContent, wsContent, bNotify, true, FALSE); 4252 pNode->SetScriptContent(wsContent, wsContent, bNotify, true, FALSE);
4268 } 4253 }
4269 } 4254 }
4270 pBindNode = NULL; 4255 pBindNode = nullptr;
4271 break; 4256 break;
4272 } 4257 }
4273 case XFA_OBJECTTYPE_ContentNode: { 4258 case XFA_OBJECTTYPE_ContentNode: {
4274 CFX_WideString wsContentType; 4259 CFX_WideString wsContentType;
4275 if (GetClassID() == XFA_ELEMENT_ExData) { 4260 if (GetClassID() == XFA_ELEMENT_ExData) {
4276 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, FALSE); 4261 GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, FALSE);
4277 if (wsContentType == FX_WSTRC(L"text/html")) { 4262 if (wsContentType == FX_WSTRC(L"text/html")) {
4278 wsContentType = FX_WSTRC(L""); 4263 wsContentType = FX_WSTRC(L"");
4279 SetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType.AsStringC()); 4264 SetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType.AsStringC());
4280 } 4265 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
4345 CFX_WideString CXFA_Node::GetScriptContent(FX_BOOL bScriptModify) { 4330 CFX_WideString CXFA_Node::GetScriptContent(FX_BOOL bScriptModify) {
4346 CFX_WideString wsContent; 4331 CFX_WideString wsContent;
4347 return TryContent(wsContent, bScriptModify) ? wsContent : CFX_WideString(); 4332 return TryContent(wsContent, bScriptModify) ? wsContent : CFX_WideString();
4348 } 4333 }
4349 CFX_WideString CXFA_Node::GetContent() { 4334 CFX_WideString CXFA_Node::GetContent() {
4350 return GetScriptContent(); 4335 return GetScriptContent();
4351 } 4336 }
4352 FX_BOOL CXFA_Node::TryContent(CFX_WideString& wsContent, 4337 FX_BOOL CXFA_Node::TryContent(CFX_WideString& wsContent,
4353 FX_BOOL bScriptModify, 4338 FX_BOOL bScriptModify,
4354 FX_BOOL bProto) { 4339 FX_BOOL bProto) {
4355 CXFA_Node* pNode = NULL; 4340 CXFA_Node* pNode = nullptr;
4356 switch (GetObjectType()) { 4341 switch (GetObjectType()) {
4357 case XFA_OBJECTTYPE_ContainerNode: 4342 case XFA_OBJECTTYPE_ContainerNode:
4358 if (GetClassID() == XFA_ELEMENT_ExclGroup) { 4343 if (GetClassID() == XFA_ELEMENT_ExclGroup) {
4359 pNode = this; 4344 pNode = this;
4360 } else { 4345 } else {
4361 CXFA_Node* pValue = GetChild(0, XFA_ELEMENT_Value); 4346 CXFA_Node* pValue = GetChild(0, XFA_ELEMENT_Value);
4362 if (!pValue) { 4347 if (!pValue) {
4363 return FALSE; 4348 return FALSE;
4364 } 4349 }
4365 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild); 4350 CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
4466 return pModelNode->TryNamespace(wsNamespace); 4451 return pModelNode->TryNamespace(wsNamespace);
4467 } 4452 }
4468 } 4453 }
4469 CXFA_Node* CXFA_Node::GetProperty(int32_t index, 4454 CXFA_Node* CXFA_Node::GetProperty(int32_t index,
4470 XFA_ELEMENT eProperty, 4455 XFA_ELEMENT eProperty,
4471 FX_BOOL bCreateProperty) { 4456 FX_BOOL bCreateProperty) {
4472 XFA_ELEMENT eElement = GetClassID(); 4457 XFA_ELEMENT eElement = GetClassID();
4473 uint32_t dwPacket = GetPacketID(); 4458 uint32_t dwPacket = GetPacketID();
4474 const XFA_PROPERTY* pProperty = 4459 const XFA_PROPERTY* pProperty =
4475 XFA_GetPropertyOfElement(eElement, eProperty, dwPacket); 4460 XFA_GetPropertyOfElement(eElement, eProperty, dwPacket);
4476 if (pProperty == NULL || index >= pProperty->uOccur) { 4461 if (!pProperty || index >= pProperty->uOccur)
4477 return NULL; 4462 return nullptr;
4478 } 4463
4479 CXFA_Node* pNode = m_pChild; 4464 CXFA_Node* pNode = m_pChild;
4480 int32_t iCount = 0; 4465 int32_t iCount = 0;
4481 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { 4466 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4482 if (pNode->GetClassID() == eProperty) { 4467 if (pNode->GetClassID() == eProperty) {
4483 iCount++; 4468 iCount++;
4484 if (iCount > index) { 4469 if (iCount > index) {
4485 return pNode; 4470 return pNode;
4486 } 4471 }
4487 } 4472 }
4488 } 4473 }
4489 if (!bCreateProperty) { 4474 if (!bCreateProperty)
4490 return NULL; 4475 return nullptr;
4491 } 4476
4492 if (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf) { 4477 if (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf) {
4493 pNode = m_pChild; 4478 pNode = m_pChild;
4494 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { 4479 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4495 const XFA_PROPERTY* pExistProperty = 4480 const XFA_PROPERTY* pExistProperty =
4496 XFA_GetPropertyOfElement(eElement, pNode->GetClassID(), dwPacket); 4481 XFA_GetPropertyOfElement(eElement, pNode->GetClassID(), dwPacket);
4497 if (pExistProperty && (pExistProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) { 4482 if (pExistProperty && (pExistProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) {
Tom Sepez 2016/05/26 23:55:03 nit: no {}
Wei Li 2016/05/27 00:51:45 Done.
4498 return NULL; 4483 return nullptr;
4499 } 4484 }
4500 } 4485 }
4501 } 4486 }
4502 CXFA_Document* pFactory = m_pDocument->GetParser()->GetFactory(); 4487 CXFA_Document* pFactory = m_pDocument->GetParser()->GetFactory();
4503 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(dwPacket); 4488 const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(dwPacket);
4504 CXFA_Node* pNewNode = nullptr; 4489 CXFA_Node* pNewNode = nullptr;
4505 for (; iCount <= index; iCount++) { 4490 for (; iCount <= index; iCount++) {
4506 pNewNode = pFactory->CreateNode(pPacket, eProperty); 4491 pNewNode = pFactory->CreateNode(pPacket, eProperty);
4507 if (!pNewNode) { 4492 if (!pNewNode) {
Tom Sepez 2016/05/26 23:55:03 nit: no {}
Wei Li 2016/05/27 00:51:45 Done.
4508 return NULL; 4493 return nullptr;
4509 } 4494 }
4510 InsertChild(pNewNode, nullptr); 4495 InsertChild(pNewNode, nullptr);
4511 pNewNode->SetFlag(XFA_NODEFLAG_Initialized, true); 4496 pNewNode->SetFlag(XFA_NODEFLAG_Initialized, true);
4512 } 4497 }
4513 return pNewNode; 4498 return pNewNode;
4514 } 4499 }
4515 int32_t CXFA_Node::CountChildren(XFA_ELEMENT eElement, FX_BOOL bOnlyChild) { 4500 int32_t CXFA_Node::CountChildren(XFA_ELEMENT eElement, FX_BOOL bOnlyChild) {
4516 CXFA_Node* pNode = m_pChild; 4501 CXFA_Node* pNode = m_pChild;
4517 int32_t iCount = 0; 4502 int32_t iCount = 0;
4518 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { 4503 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
(...skipping 24 matching lines...) Expand all
4543 if (pProperty) { 4528 if (pProperty) {
4544 continue; 4529 continue;
4545 } 4530 }
4546 } 4531 }
4547 iCount++; 4532 iCount++;
4548 if (iCount > index) { 4533 if (iCount > index) {
4549 return pNode; 4534 return pNode;
4550 } 4535 }
4551 } 4536 }
4552 } 4537 }
4553 return NULL; 4538 return nullptr;
4554 } 4539 }
4555 int32_t CXFA_Node::InsertChild(int32_t index, CXFA_Node* pNode) { 4540 int32_t CXFA_Node::InsertChild(int32_t index, CXFA_Node* pNode) {
4556 ASSERT(!pNode->m_pNext); 4541 ASSERT(!pNode->m_pNext);
4557 pNode->m_pParent = this; 4542 pNode->m_pParent = this;
4558 FX_BOOL ret = m_pDocument->RemovePurgeNode(pNode); 4543 FX_BOOL ret = m_pDocument->RemovePurgeNode(pNode);
4559 ASSERT(ret); 4544 ASSERT(ret);
4560 (void)ret; // Avoid unused variable warning. 4545 (void)ret; // Avoid unused variable warning.
4561 4546
4562 if (m_pChild == NULL || index == 0) { 4547 if (!m_pChild || index == 0) {
4563 if (index > 0) { 4548 if (index > 0) {
4564 return -1; 4549 return -1;
4565 } 4550 }
4566 pNode->m_pNext = m_pChild; 4551 pNode->m_pNext = m_pChild;
4567 m_pChild = pNode; 4552 m_pChild = pNode;
4568 index = 0; 4553 index = 0;
4569 } else if (index < 0) { 4554 } else if (index < 0) {
4570 m_pLastChild->m_pNext = pNode; 4555 m_pLastChild->m_pNext = pNode;
4571 } else { 4556 } else {
4572 CXFA_Node* pPrev = m_pChild; 4557 CXFA_Node* pPrev = m_pChild;
4573 int32_t iCount = 0; 4558 int32_t iCount = 0;
4574 while (++iCount != index && pPrev->m_pNext) { 4559 while (++iCount != index && pPrev->m_pNext) {
4575 pPrev = pPrev->m_pNext; 4560 pPrev = pPrev->m_pNext;
4576 } 4561 }
4577 if (index > 0 && index != iCount) { 4562 if (index > 0 && index != iCount) {
4578 return -1; 4563 return -1;
4579 } 4564 }
4580 pNode->m_pNext = pPrev->m_pNext; 4565 pNode->m_pNext = pPrev->m_pNext;
4581 pPrev->m_pNext = pNode; 4566 pPrev->m_pNext = pNode;
4582 index = iCount; 4567 index = iCount;
4583 } 4568 }
4584 if (pNode->m_pNext == NULL) { 4569 if (!pNode->m_pNext) {
4585 m_pLastChild = pNode; 4570 m_pLastChild = pNode;
4586 } 4571 }
4587 ASSERT(m_pLastChild); 4572 ASSERT(m_pLastChild);
4588 ASSERT(m_pLastChild->m_pNext == NULL); 4573 ASSERT(!m_pLastChild->m_pNext);
4589 pNode->ClearFlag(XFA_NODEFLAG_HasRemoved); 4574 pNode->ClearFlag(XFA_NODEFLAG_HasRemoved);
4590 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); 4575 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify();
4591 if (pNotify) 4576 if (pNotify)
4592 pNotify->OnChildAdded(this); 4577 pNotify->OnChildAdded(this);
4593 4578
4594 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) { 4579 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
4595 ASSERT(pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent) == NULL); 4580 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
4596 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, index); 4581 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, index);
4597 pNode->ClearFlag(XFA_NODEFLAG_OwnXMLNode); 4582 pNode->ClearFlag(XFA_NODEFLAG_OwnXMLNode);
4598 } 4583 }
4599 return index; 4584 return index;
4600 } 4585 }
4601 4586
4602 FX_BOOL CXFA_Node::InsertChild(CXFA_Node* pNode, CXFA_Node* pBeforeNode) { 4587 FX_BOOL CXFA_Node::InsertChild(CXFA_Node* pNode, CXFA_Node* pBeforeNode) {
4603 if (!pNode || pNode->m_pParent || 4588 if (!pNode || pNode->m_pParent ||
4604 (pBeforeNode && pBeforeNode->m_pParent != this)) { 4589 (pBeforeNode && pBeforeNode->m_pParent != this)) {
4605 ASSERT(false); 4590 ASSERT(false);
4606 return FALSE; 4591 return FALSE;
4607 } 4592 }
4608 FX_BOOL ret = m_pDocument->RemovePurgeNode(pNode); 4593 FX_BOOL ret = m_pDocument->RemovePurgeNode(pNode);
4609 ASSERT(ret); 4594 ASSERT(ret);
4610 (void)ret; // Avoid unused variable warning. 4595 (void)ret; // Avoid unused variable warning.
4611 4596
4612 int32_t nIndex = -1; 4597 int32_t nIndex = -1;
4613 pNode->m_pParent = this; 4598 pNode->m_pParent = this;
4614 if (m_pChild == NULL || pBeforeNode == m_pChild) { 4599 if (!m_pChild || pBeforeNode == m_pChild) {
4615 pNode->m_pNext = m_pChild; 4600 pNode->m_pNext = m_pChild;
4616 m_pChild = pNode; 4601 m_pChild = pNode;
4617 nIndex = 0; 4602 nIndex = 0;
4618 } else if (!pBeforeNode) { 4603 } else if (!pBeforeNode) {
4619 pNode->m_pNext = m_pLastChild->m_pNext; 4604 pNode->m_pNext = m_pLastChild->m_pNext;
4620 m_pLastChild->m_pNext = pNode; 4605 m_pLastChild->m_pNext = pNode;
4621 } else { 4606 } else {
4622 nIndex = 1; 4607 nIndex = 1;
4623 CXFA_Node* pPrev = m_pChild; 4608 CXFA_Node* pPrev = m_pChild;
4624 while (pPrev->m_pNext != pBeforeNode) { 4609 while (pPrev->m_pNext != pBeforeNode) {
4625 pPrev = pPrev->m_pNext; 4610 pPrev = pPrev->m_pNext;
4626 nIndex++; 4611 nIndex++;
4627 } 4612 }
4628 pNode->m_pNext = pPrev->m_pNext; 4613 pNode->m_pNext = pPrev->m_pNext;
4629 pPrev->m_pNext = pNode; 4614 pPrev->m_pNext = pNode;
4630 } 4615 }
4631 if (pNode->m_pNext == NULL) { 4616 if (!pNode->m_pNext) {
4632 m_pLastChild = pNode; 4617 m_pLastChild = pNode;
4633 } 4618 }
4634 ASSERT(m_pLastChild); 4619 ASSERT(m_pLastChild);
4635 ASSERT(m_pLastChild->m_pNext == NULL); 4620 ASSERT(!m_pLastChild->m_pNext);
4636 pNode->ClearFlag(XFA_NODEFLAG_HasRemoved); 4621 pNode->ClearFlag(XFA_NODEFLAG_HasRemoved);
4637 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify(); 4622 CXFA_FFNotify* pNotify = m_pDocument->GetParser()->GetNotify();
4638 if (pNotify) 4623 if (pNotify)
4639 pNotify->OnChildAdded(this); 4624 pNotify->OnChildAdded(this);
4640 4625
4641 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) { 4626 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
4642 ASSERT(pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent) == NULL); 4627 ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent));
4643 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, nIndex); 4628 m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, nIndex);
4644 pNode->ClearFlag(XFA_NODEFLAG_OwnXMLNode); 4629 pNode->ClearFlag(XFA_NODEFLAG_OwnXMLNode);
4645 } 4630 }
4646 return TRUE; 4631 return TRUE;
4647 } 4632 }
4648 CXFA_Node* CXFA_Node::Deprecated_GetPrevSibling() { 4633 CXFA_Node* CXFA_Node::Deprecated_GetPrevSibling() {
4649 if (!m_pParent) { 4634 if (!m_pParent) {
4650 return NULL; 4635 return nullptr;
4651 } 4636 }
4652 for (CXFA_Node* pSibling = m_pParent->m_pChild; pSibling; 4637 for (CXFA_Node* pSibling = m_pParent->m_pChild; pSibling;
4653 pSibling = pSibling->m_pNext) { 4638 pSibling = pSibling->m_pNext) {
4654 if (pSibling->m_pNext == this) { 4639 if (pSibling->m_pNext == this) {
4655 return pSibling; 4640 return pSibling;
4656 } 4641 }
4657 } 4642 }
4658 return NULL; 4643 return nullptr;
4659 } 4644 }
4660 FX_BOOL CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) { 4645 FX_BOOL CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) {
4661 if (pNode == NULL || pNode->m_pParent != this) { 4646 if (!pNode || pNode->m_pParent != this) {
4662 ASSERT(FALSE); 4647 ASSERT(FALSE);
4663 return FALSE; 4648 return FALSE;
4664 } 4649 }
4665 if (m_pChild == pNode) { 4650 if (m_pChild == pNode) {
4666 m_pChild = pNode->m_pNext; 4651 m_pChild = pNode->m_pNext;
4667 if (m_pLastChild == pNode) { 4652 if (m_pLastChild == pNode) {
4668 m_pLastChild = pNode->m_pNext; 4653 m_pLastChild = pNode->m_pNext;
4669 } 4654 }
4670 pNode->m_pNext = NULL; 4655 pNode->m_pNext = nullptr;
4671 pNode->m_pParent = NULL; 4656 pNode->m_pParent = nullptr;
4672 } else { 4657 } else {
4673 CXFA_Node* pPrev = pNode->Deprecated_GetPrevSibling(); 4658 CXFA_Node* pPrev = pNode->Deprecated_GetPrevSibling();
4674 pPrev->m_pNext = pNode->m_pNext; 4659 pPrev->m_pNext = pNode->m_pNext;
4675 if (m_pLastChild == pNode) { 4660 if (m_pLastChild == pNode) {
4676 m_pLastChild = pNode->m_pNext ? pNode->m_pNext : pPrev; 4661 m_pLastChild = pNode->m_pNext ? pNode->m_pNext : pPrev;
4677 } 4662 }
4678 pNode->m_pNext = NULL; 4663 pNode->m_pNext = nullptr;
4679 pNode->m_pParent = NULL; 4664 pNode->m_pParent = nullptr;
4680 } 4665 }
4681 ASSERT(m_pLastChild == NULL || m_pLastChild->m_pNext == NULL); 4666 ASSERT(!m_pLastChild || !m_pLastChild->m_pNext);
4682 OnRemoved(bNotify); 4667 OnRemoved(bNotify);
4683 pNode->SetFlag(XFA_NODEFLAG_HasRemoved, true); 4668 pNode->SetFlag(XFA_NODEFLAG_HasRemoved, true);
4684 m_pDocument->AddPurgeNode(pNode); 4669 m_pDocument->AddPurgeNode(pNode);
4685 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) { 4670 if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) {
4686 if (pNode->IsAttributeInXML()) { 4671 if (pNode->IsAttributeInXML()) {
4687 ASSERT(pNode->m_pXMLNode == m_pXMLNode && 4672 ASSERT(pNode->m_pXMLNode == m_pXMLNode &&
4688 m_pXMLNode->GetType() == FDE_XMLNODE_Element); 4673 m_pXMLNode->GetType() == FDE_XMLNODE_Element);
4689 if (pNode->m_pXMLNode->GetType() == FDE_XMLNODE_Element) { 4674 if (pNode->m_pXMLNode->GetType() == FDE_XMLNODE_Element) {
4690 CFDE_XMLElement* pXMLElement = 4675 CFDE_XMLElement* pXMLElement =
4691 static_cast<CFDE_XMLElement*>(pNode->m_pXMLNode); 4676 static_cast<CFDE_XMLElement*>(pNode->m_pXMLNode);
(...skipping 20 matching lines...) Expand all
4712 CXFA_Node* CXFA_Node::GetFirstChildByName(const CFX_WideStringC& wsName) const { 4697 CXFA_Node* CXFA_Node::GetFirstChildByName(const CFX_WideStringC& wsName) const {
4713 return GetFirstChildByName(FX_HashCode_GetW(wsName, false)); 4698 return GetFirstChildByName(FX_HashCode_GetW(wsName, false));
4714 } 4699 }
4715 CXFA_Node* CXFA_Node::GetFirstChildByName(uint32_t dwNameHash) const { 4700 CXFA_Node* CXFA_Node::GetFirstChildByName(uint32_t dwNameHash) const {
4716 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode; 4701 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4717 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { 4702 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4718 if (pNode->GetNameHash() == dwNameHash) { 4703 if (pNode->GetNameHash() == dwNameHash) {
4719 return pNode; 4704 return pNode;
4720 } 4705 }
4721 } 4706 }
4722 return NULL; 4707 return nullptr;
4723 } 4708 }
4724 CXFA_Node* CXFA_Node::GetFirstChildByClass(XFA_ELEMENT eElement) const { 4709 CXFA_Node* CXFA_Node::GetFirstChildByClass(XFA_ELEMENT eElement) const {
4725 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode; 4710 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4726 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { 4711 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4727 if (pNode->GetClassID() == eElement) { 4712 if (pNode->GetClassID() == eElement) {
4728 return pNode; 4713 return pNode;
4729 } 4714 }
4730 } 4715 }
4731 return NULL; 4716 return nullptr;
4732 } 4717 }
4733 CXFA_Node* CXFA_Node::GetNextSameNameSibling(uint32_t dwNameHash) const { 4718 CXFA_Node* CXFA_Node::GetNextSameNameSibling(uint32_t dwNameHash) const {
4734 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode; 4719 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4735 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { 4720 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4736 if (pNode->GetNameHash() == dwNameHash) { 4721 if (pNode->GetNameHash() == dwNameHash) {
4737 return pNode; 4722 return pNode;
4738 } 4723 }
4739 } 4724 }
4740 return NULL; 4725 return nullptr;
4741 } 4726 }
4742 CXFA_Node* CXFA_Node::GetNextSameNameSibling( 4727 CXFA_Node* CXFA_Node::GetNextSameNameSibling(
4743 const CFX_WideStringC& wsNodeName) const { 4728 const CFX_WideStringC& wsNodeName) const {
4744 return GetNextSameNameSibling(FX_HashCode_GetW(wsNodeName, false)); 4729 return GetNextSameNameSibling(FX_HashCode_GetW(wsNodeName, false));
4745 } 4730 }
4746 CXFA_Node* CXFA_Node::GetNextSameClassSibling(XFA_ELEMENT eElement) const { 4731 CXFA_Node* CXFA_Node::GetNextSameClassSibling(XFA_ELEMENT eElement) const {
4747 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode; 4732 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4748 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { 4733 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4749 if (pNode->GetClassID() == eElement) { 4734 if (pNode->GetClassID() == eElement) {
4750 return pNode; 4735 return pNode;
4751 } 4736 }
4752 } 4737 }
4753 return NULL; 4738 return nullptr;
4754 } 4739 }
4755 int32_t CXFA_Node::GetNodeSameNameIndex() const { 4740 int32_t CXFA_Node::GetNodeSameNameIndex() const {
4756 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); 4741 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
4757 if (!pScriptContext) { 4742 if (!pScriptContext) {
4758 return -1; 4743 return -1;
4759 } 4744 }
4760 return pScriptContext->GetIndexByName(const_cast<CXFA_Node*>(this)); 4745 return pScriptContext->GetIndexByName(const_cast<CXFA_Node*>(this));
4761 } 4746 }
4762 int32_t CXFA_Node::GetNodeSameClassIndex() const { 4747 int32_t CXFA_Node::GetNodeSameClassIndex() const {
4763 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); 4748 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
4764 if (!pScriptContext) { 4749 if (!pScriptContext) {
4765 return -1; 4750 return -1;
4766 } 4751 }
4767 return pScriptContext->GetIndexByClassName(const_cast<CXFA_Node*>(this)); 4752 return pScriptContext->GetIndexByClassName(const_cast<CXFA_Node*>(this));
4768 } 4753 }
4769 void CXFA_Node::GetSOMExpression(CFX_WideString& wsSOMExpression) { 4754 void CXFA_Node::GetSOMExpression(CFX_WideString& wsSOMExpression) {
4770 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); 4755 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext();
4771 if (!pScriptContext) { 4756 if (!pScriptContext) {
4772 return; 4757 return;
4773 } 4758 }
4774 pScriptContext->GetSomExpression(this, wsSOMExpression); 4759 pScriptContext->GetSomExpression(this, wsSOMExpression);
4775 } 4760 }
4776 CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() { 4761 CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() {
4777 CXFA_Node* pInstanceMgr = NULL; 4762 CXFA_Node* pInstanceMgr = nullptr;
4778 if (m_ePacket == XFA_XDPPACKET_Form) { 4763 if (m_ePacket == XFA_XDPPACKET_Form) {
4779 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); 4764 CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent);
4780 if (!pParentNode || pParentNode->GetClassID() == XFA_ELEMENT_Area) { 4765 if (!pParentNode || pParentNode->GetClassID() == XFA_ELEMENT_Area) {
4781 return pInstanceMgr; 4766 return pInstanceMgr;
4782 } 4767 }
4783 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; 4768 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode;
4784 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { 4769 pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) {
4785 XFA_ELEMENT eType = pNode->GetClassID(); 4770 XFA_ELEMENT eType = pNode->GetClassID();
4786 if ((eType == XFA_ELEMENT_Subform || eType == XFA_ELEMENT_SubformSet) && 4771 if ((eType == XFA_ELEMENT_Subform || eType == XFA_ELEMENT_SubformSet) &&
4787 pNode->m_dwNameHash != m_dwNameHash) { 4772 pNode->m_dwNameHash != m_dwNameHash) {
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
4963 4948
4964 FX_BOOL CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) { 4949 FX_BOOL CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) {
4965 CXFA_Node* pNode = this; 4950 CXFA_Node* pNode = this;
4966 while (pNode) { 4951 while (pNode) {
4967 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData(); 4952 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
4968 if (pModule && pModule->m_ValueMap.Lookup(pKey, pValue)) { 4953 if (pModule && pModule->m_ValueMap.Lookup(pKey, pValue)) {
4969 return TRUE; 4954 return TRUE;
4970 } 4955 }
4971 pNode = pNode->GetPacketID() != XFA_XDPPACKET_Datasets 4956 pNode = pNode->GetPacketID() != XFA_XDPPACKET_Datasets
4972 ? pNode->GetTemplateNode() 4957 ? pNode->GetTemplateNode()
4973 : NULL; 4958 : nullptr;
4974 } 4959 }
4975 return FALSE; 4960 return FALSE;
4976 } 4961 }
4977 void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) { 4962 void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) {
4978 SetMapModuleBuffer(pKey, (void*)wsValue.c_str(), 4963 SetMapModuleBuffer(pKey, (void*)wsValue.c_str(),
4979 wsValue.GetLength() * sizeof(FX_WCHAR)); 4964 wsValue.GetLength() * sizeof(FX_WCHAR));
4980 } 4965 }
4981 FX_BOOL CXFA_Node::GetMapModuleString(void* pKey, CFX_WideStringC& wsValue) { 4966 FX_BOOL CXFA_Node::GetMapModuleString(void* pKey, CFX_WideStringC& wsValue) {
4982 void* pValue; 4967 void* pValue;
4983 int32_t iBytes; 4968 int32_t iBytes;
4984 if (!GetMapModuleBuffer(pKey, pValue, iBytes)) { 4969 if (!GetMapModuleBuffer(pKey, pValue, iBytes)) {
4985 return FALSE; 4970 return FALSE;
4986 } 4971 }
4987 wsValue = CFX_WideStringC((const FX_WCHAR*)pValue, iBytes / sizeof(FX_WCHAR)); 4972 wsValue = CFX_WideStringC((const FX_WCHAR*)pValue, iBytes / sizeof(FX_WCHAR));
4988 return TRUE; 4973 return TRUE;
4989 } 4974 }
4990 void CXFA_Node::SetMapModuleBuffer( 4975 void CXFA_Node::SetMapModuleBuffer(
4991 void* pKey, 4976 void* pKey,
4992 void* pValue, 4977 void* pValue,
4993 int32_t iBytes, 4978 int32_t iBytes,
4994 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) { 4979 XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) {
4995 XFA_MAPMODULEDATA* pModule = CreateMapModuleData(); 4980 XFA_MAPMODULEDATA* pModule = CreateMapModuleData();
4996 XFA_MAPDATABLOCK*& pBuffer = pModule->m_BufferMap[pKey]; 4981 XFA_MAPDATABLOCK*& pBuffer = pModule->m_BufferMap[pKey];
4997 if (pBuffer == NULL) { 4982 if (!pBuffer) {
4998 pBuffer = 4983 pBuffer =
4999 (XFA_MAPDATABLOCK*)FX_Alloc(uint8_t, sizeof(XFA_MAPDATABLOCK) + iBytes); 4984 (XFA_MAPDATABLOCK*)FX_Alloc(uint8_t, sizeof(XFA_MAPDATABLOCK) + iBytes);
5000 } else if (pBuffer->iBytes != iBytes) { 4985 } else if (pBuffer->iBytes != iBytes) {
5001 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { 4986 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
5002 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); 4987 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5003 } 4988 }
5004 pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(uint8_t, pBuffer, 4989 pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(uint8_t, pBuffer,
5005 sizeof(XFA_MAPDATABLOCK) + iBytes); 4990 sizeof(XFA_MAPDATABLOCK) + iBytes);
5006 } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { 4991 } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
5007 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); 4992 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5008 } 4993 }
5009 if (pBuffer == NULL) { 4994 if (!pBuffer)
5010 return; 4995 return;
5011 } 4996
5012 pBuffer->pCallbackInfo = pCallbackInfo; 4997 pBuffer->pCallbackInfo = pCallbackInfo;
5013 pBuffer->iBytes = iBytes; 4998 pBuffer->iBytes = iBytes;
5014 FXSYS_memcpy(pBuffer->GetData(), pValue, iBytes); 4999 FXSYS_memcpy(pBuffer->GetData(), pValue, iBytes);
5015 } 5000 }
5016 FX_BOOL CXFA_Node::GetMapModuleBuffer(void* pKey, 5001 FX_BOOL CXFA_Node::GetMapModuleBuffer(void* pKey,
5017 void*& pValue, 5002 void*& pValue,
5018 int32_t& iBytes, 5003 int32_t& iBytes,
5019 FX_BOOL bProtoAlso) const { 5004 FX_BOOL bProtoAlso) const {
5020 XFA_MAPDATABLOCK* pBuffer = NULL; 5005 XFA_MAPDATABLOCK* pBuffer = nullptr;
5021 const CXFA_Node* pNode = this; 5006 const CXFA_Node* pNode = this;
5022 while (pNode) { 5007 while (pNode) {
5023 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData(); 5008 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
5024 if (pModule && pModule->m_BufferMap.Lookup(pKey, pBuffer)) { 5009 if (pModule && pModule->m_BufferMap.Lookup(pKey, pBuffer)) {
5025 break; 5010 break;
5026 } 5011 }
5027 pNode = (bProtoAlso && pNode->GetPacketID() != XFA_XDPPACKET_Datasets) 5012 pNode = (bProtoAlso && pNode->GetPacketID() != XFA_XDPPACKET_Datasets)
5028 ? pNode->GetTemplateNode() 5013 ? pNode->GetTemplateNode()
5029 : NULL; 5014 : nullptr;
5030 } 5015 }
5031 if (pBuffer == NULL) { 5016 if (!pBuffer) {
5032 return FALSE; 5017 return FALSE;
5033 } 5018 }
5034 pValue = pBuffer->GetData(); 5019 pValue = pBuffer->GetData();
5035 iBytes = pBuffer->iBytes; 5020 iBytes = pBuffer->iBytes;
5036 return TRUE; 5021 return TRUE;
5037 } 5022 }
5038 FX_BOOL CXFA_Node::HasMapModuleKey(void* pKey, FX_BOOL bProtoAlso) { 5023 FX_BOOL CXFA_Node::HasMapModuleKey(void* pKey, FX_BOOL bProtoAlso) {
5039 CXFA_Node* pNode = this; 5024 CXFA_Node* pNode = this;
5040 while (pNode) { 5025 while (pNode) {
5041 void* pVal; 5026 void* pVal;
5042 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData(); 5027 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData();
5043 if (pModule && 5028 if (pModule &&
5044 (pModule->m_ValueMap.Lookup(pKey, pVal) || 5029 (pModule->m_ValueMap.Lookup(pKey, pVal) ||
5045 pModule->m_BufferMap.Lookup(pKey, (XFA_MAPDATABLOCK*&)pVal))) { 5030 pModule->m_BufferMap.Lookup(pKey, (XFA_MAPDATABLOCK*&)pVal))) {
5046 return TRUE; 5031 return TRUE;
5047 } 5032 }
5048 pNode = (bProtoAlso && pNode->GetPacketID() != XFA_XDPPACKET_Datasets) 5033 pNode = (bProtoAlso && pNode->GetPacketID() != XFA_XDPPACKET_Datasets)
5049 ? pNode->GetTemplateNode() 5034 ? pNode->GetTemplateNode()
5050 : NULL; 5035 : nullptr;
5051 } 5036 }
5052 return FALSE; 5037 return FALSE;
5053 } 5038 }
5054 void CXFA_Node::RemoveMapModuleKey(void* pKey) { 5039 void CXFA_Node::RemoveMapModuleKey(void* pKey) {
5055 XFA_MAPMODULEDATA* pModule = GetMapModuleData(); 5040 XFA_MAPMODULEDATA* pModule = GetMapModuleData();
5056 if (!pModule) 5041 if (!pModule)
5057 return; 5042 return;
5058 5043
5059 if (pKey) { 5044 if (pKey) {
5060 XFA_MAPDATABLOCK* pBuffer = NULL; 5045 XFA_MAPDATABLOCK* pBuffer = nullptr;
5061 pModule->m_BufferMap.Lookup(pKey, pBuffer); 5046 pModule->m_BufferMap.Lookup(pKey, pBuffer);
5062 if (pBuffer) { 5047 if (pBuffer) {
5063 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { 5048 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
5064 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); 5049 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5065 } 5050 }
5066 FX_Free(pBuffer); 5051 FX_Free(pBuffer);
5067 } 5052 }
5068 pModule->m_BufferMap.RemoveKey(pKey); 5053 pModule->m_BufferMap.RemoveKey(pKey);
5069 pModule->m_ValueMap.RemoveKey(pKey); 5054 pModule->m_ValueMap.RemoveKey(pKey);
5070 } else { 5055 } else {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
5110 continue; 5095 continue;
5111 } 5096 }
5112 if (pSrcBuffer->pCallbackInfo && pSrcBuffer->pCallbackInfo->pFree && 5097 if (pSrcBuffer->pCallbackInfo && pSrcBuffer->pCallbackInfo->pFree &&
5113 !pSrcBuffer->pCallbackInfo->pCopy) { 5098 !pSrcBuffer->pCallbackInfo->pCopy) {
5114 if (pBuffer) { 5099 if (pBuffer) {
5115 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); 5100 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5116 pDstModuleData->m_BufferMap.RemoveKey(pKey); 5101 pDstModuleData->m_BufferMap.RemoveKey(pKey);
5117 } 5102 }
5118 continue; 5103 continue;
5119 } 5104 }
5120 if (pBuffer == NULL) { 5105 if (!pBuffer) {
5121 pBuffer = (XFA_MAPDATABLOCK*)FX_Alloc( 5106 pBuffer = (XFA_MAPDATABLOCK*)FX_Alloc(
5122 uint8_t, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes); 5107 uint8_t, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
5123 } else if (pBuffer->iBytes != pSrcBuffer->iBytes) { 5108 } else if (pBuffer->iBytes != pSrcBuffer->iBytes) {
5124 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { 5109 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
5125 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); 5110 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5126 } 5111 }
5127 pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc( 5112 pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(
5128 uint8_t, pBuffer, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes); 5113 uint8_t, pBuffer, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes);
5129 } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { 5114 } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) {
5130 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); 5115 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData());
5131 } 5116 }
5132 if (pBuffer == NULL) { 5117 if (!pBuffer) {
5133 continue; 5118 continue;
5134 } 5119 }
5135 pBuffer->pCallbackInfo = pSrcBuffer->pCallbackInfo; 5120 pBuffer->pCallbackInfo = pSrcBuffer->pCallbackInfo;
5136 pBuffer->iBytes = pSrcBuffer->iBytes; 5121 pBuffer->iBytes = pSrcBuffer->iBytes;
5137 FXSYS_memcpy(pBuffer->GetData(), pSrcBuffer->GetData(), pSrcBuffer->iBytes); 5122 FXSYS_memcpy(pBuffer->GetData(), pSrcBuffer->GetData(), pSrcBuffer->iBytes);
5138 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pCopy) { 5123 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pCopy) {
5139 pBuffer->pCallbackInfo->pCopy(*(void**)pBuffer->GetData()); 5124 pBuffer->pCallbackInfo->pCopy(*(void**)pBuffer->GetData());
5140 } 5125 }
5141 } 5126 }
5142 } 5127 }
5143 void CXFA_Node::MoveBufferMapData(CXFA_Node* pDstModule, void* pKey) { 5128 void CXFA_Node::MoveBufferMapData(CXFA_Node* pDstModule, void* pKey) {
5144 if (!pDstModule) { 5129 if (!pDstModule) {
5145 return; 5130 return;
5146 } 5131 }
5147 FX_BOOL bNeedMove = TRUE; 5132 FX_BOOL bNeedMove = TRUE;
5148 if (!pKey) { 5133 if (!pKey) {
5149 bNeedMove = FALSE; 5134 bNeedMove = FALSE;
5150 } 5135 }
5151 if (pDstModule->GetClassID() != GetClassID()) { 5136 if (pDstModule->GetClassID() != GetClassID()) {
5152 bNeedMove = FALSE; 5137 bNeedMove = FALSE;
5153 } 5138 }
5154 XFA_MAPMODULEDATA* pSrcModuleData = NULL; 5139 XFA_MAPMODULEDATA* pSrcModuleData = nullptr;
5155 XFA_MAPMODULEDATA* pDstModuleData = NULL; 5140 XFA_MAPMODULEDATA* pDstModuleData = nullptr;
5156 if (bNeedMove) { 5141 if (bNeedMove) {
5157 pSrcModuleData = GetMapModuleData(); 5142 pSrcModuleData = GetMapModuleData();
5158 if (!pSrcModuleData) { 5143 if (!pSrcModuleData) {
5159 bNeedMove = FALSE; 5144 bNeedMove = FALSE;
5160 } 5145 }
5161 pDstModuleData = pDstModule->CreateMapModuleData(); 5146 pDstModuleData = pDstModule->CreateMapModuleData();
5162 } 5147 }
5163 if (bNeedMove) { 5148 if (bNeedMove) {
5164 void* pBufferBlockData = pSrcModuleData->m_BufferMap.GetValueAt(pKey); 5149 void* pBufferBlockData = pSrcModuleData->m_BufferMap.GetValueAt(pKey);
5165 if (pBufferBlockData) { 5150 if (pBufferBlockData) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
5202 m_pDocument->GetScriptContext()->CacheList(this); 5187 m_pDocument->GetScriptContext()->CacheList(this);
5203 } 5188 }
5204 CXFA_Node* CXFA_NodeList::NamedItem(const CFX_WideStringC& wsName) { 5189 CXFA_Node* CXFA_NodeList::NamedItem(const CFX_WideStringC& wsName) {
5205 uint32_t dwHashCode = FX_HashCode_GetW(wsName, false); 5190 uint32_t dwHashCode = FX_HashCode_GetW(wsName, false);
5206 int32_t iCount = GetLength(); 5191 int32_t iCount = GetLength();
5207 for (int32_t i = 0; i < iCount; i++) { 5192 for (int32_t i = 0; i < iCount; i++) {
5208 CXFA_Node* ret = Item(i); 5193 CXFA_Node* ret = Item(i);
5209 if (dwHashCode == ret->GetNameHash()) 5194 if (dwHashCode == ret->GetNameHash())
5210 return ret; 5195 return ret;
5211 } 5196 }
5212 return NULL; 5197 return nullptr;
5213 } 5198 }
5214 void CXFA_NodeList::Script_ListClass_Append(CFXJSE_Arguments* pArguments) { 5199 void CXFA_NodeList::Script_ListClass_Append(CFXJSE_Arguments* pArguments) {
5215 int32_t argc = pArguments->GetLength(); 5200 int32_t argc = pArguments->GetLength();
5216 if (argc == 1) { 5201 if (argc == 1) {
5217 CXFA_Node* pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); 5202 CXFA_Node* pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
5218 if (pNode) { 5203 if (pNode) {
5219 Append(pNode); 5204 Append(pNode);
5220 } else { 5205 } else {
5221 ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH); 5206 ThrowScriptErrorMessage(XFA_IDS_ARGUMENT_MISMATCH);
5222 } 5207 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
5300 } 5285 }
5301 int32_t CXFA_ArrayNodeList::GetLength() { 5286 int32_t CXFA_ArrayNodeList::GetLength() {
5302 return m_array.GetSize(); 5287 return m_array.GetSize();
5303 } 5288 }
5304 FX_BOOL CXFA_ArrayNodeList::Append(CXFA_Node* pNode) { 5289 FX_BOOL CXFA_ArrayNodeList::Append(CXFA_Node* pNode) {
5305 m_array.Add(pNode); 5290 m_array.Add(pNode);
5306 return TRUE; 5291 return TRUE;
5307 } 5292 }
5308 FX_BOOL CXFA_ArrayNodeList::Insert(CXFA_Node* pNewNode, 5293 FX_BOOL CXFA_ArrayNodeList::Insert(CXFA_Node* pNewNode,
5309 CXFA_Node* pBeforeNode) { 5294 CXFA_Node* pBeforeNode) {
5310 if (pBeforeNode == NULL) { 5295 if (!pBeforeNode) {
5311 m_array.Add(pNewNode); 5296 m_array.Add(pNewNode);
5312 } else { 5297 } else {
5313 int32_t iSize = m_array.GetSize(); 5298 int32_t iSize = m_array.GetSize();
5314 for (int32_t i = 0; i < iSize; ++i) { 5299 for (int32_t i = 0; i < iSize; ++i) {
5315 if (m_array[i] == pBeforeNode) { 5300 if (m_array[i] == pBeforeNode) {
5316 m_array.InsertAt(i, pNewNode); 5301 m_array.InsertAt(i, pNewNode);
5317 break; 5302 break;
5318 } 5303 }
5319 } 5304 }
5320 } 5305 }
5321 return TRUE; 5306 return TRUE;
5322 } 5307 }
5323 FX_BOOL CXFA_ArrayNodeList::Remove(CXFA_Node* pNode) { 5308 FX_BOOL CXFA_ArrayNodeList::Remove(CXFA_Node* pNode) {
5324 int32_t iSize = m_array.GetSize(); 5309 int32_t iSize = m_array.GetSize();
5325 for (int32_t i = 0; i < iSize; ++i) { 5310 for (int32_t i = 0; i < iSize; ++i) {
5326 if (m_array[i] == pNode) { 5311 if (m_array[i] == pNode) {
5327 m_array.RemoveAt(i); 5312 m_array.RemoveAt(i);
5328 break; 5313 break;
5329 } 5314 }
5330 } 5315 }
5331 return TRUE; 5316 return TRUE;
5332 } 5317 }
5333 CXFA_Node* CXFA_ArrayNodeList::Item(int32_t iIndex) { 5318 CXFA_Node* CXFA_ArrayNodeList::Item(int32_t iIndex) {
5334 int32_t iSize = m_array.GetSize(); 5319 int32_t iSize = m_array.GetSize();
5335 if (iIndex >= 0 && iIndex < iSize) { 5320 if (iIndex >= 0 && iIndex < iSize) {
5336 return m_array[iIndex]; 5321 return m_array[iIndex];
5337 } 5322 }
5338 return NULL; 5323 return nullptr;
5339 } 5324 }
5340 CXFA_AttachNodeList::CXFA_AttachNodeList(CXFA_Document* pDocument, 5325 CXFA_AttachNodeList::CXFA_AttachNodeList(CXFA_Document* pDocument,
5341 CXFA_Node* pAttachNode) 5326 CXFA_Node* pAttachNode)
5342 : CXFA_NodeList(pDocument) { 5327 : CXFA_NodeList(pDocument) {
5343 m_pAttachNode = pAttachNode; 5328 m_pAttachNode = pAttachNode;
5344 } 5329 }
5345 int32_t CXFA_AttachNodeList::GetLength() { 5330 int32_t CXFA_AttachNodeList::GetLength() {
5346 return m_pAttachNode->CountChildren( 5331 return m_pAttachNode->CountChildren(
5347 XFA_ELEMENT_UNKNOWN, m_pAttachNode->GetClassID() == XFA_ELEMENT_Subform); 5332 XFA_ELEMENT_UNKNOWN, m_pAttachNode->GetClassID() == XFA_ELEMENT_Subform);
5348 } 5333 }
(...skipping 13 matching lines...) Expand all
5362 return m_pAttachNode->InsertChild(pNewNode, pBeforeNode); 5347 return m_pAttachNode->InsertChild(pNewNode, pBeforeNode);
5363 } 5348 }
5364 FX_BOOL CXFA_AttachNodeList::Remove(CXFA_Node* pNode) { 5349 FX_BOOL CXFA_AttachNodeList::Remove(CXFA_Node* pNode) {
5365 return m_pAttachNode->RemoveChild(pNode); 5350 return m_pAttachNode->RemoveChild(pNode);
5366 } 5351 }
5367 CXFA_Node* CXFA_AttachNodeList::Item(int32_t iIndex) { 5352 CXFA_Node* CXFA_AttachNodeList::Item(int32_t iIndex) {
5368 return m_pAttachNode->GetChild( 5353 return m_pAttachNode->GetChild(
5369 iIndex, XFA_ELEMENT_UNKNOWN, 5354 iIndex, XFA_ELEMENT_UNKNOWN,
5370 m_pAttachNode->GetClassID() == XFA_ELEMENT_Subform); 5355 m_pAttachNode->GetClassID() == XFA_ELEMENT_Subform);
5371 } 5356 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698