dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1 | // Copyright 2016 PDFium Authors. All rights reserved. |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
| 7 | #include "xfa/fxfa/parser/xfa_object.h" |
| 8 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 9 | #include <map> |
tsepez | aadedf9 | 2016-05-12 10:08:06 -0700 | [diff] [blame] | 10 | #include <memory> |
Dan Sinclair | 85c8e7f | 2016-11-21 13:50:32 -0500 | [diff] [blame] | 11 | #include <utility> |
tsepez | aadedf9 | 2016-05-12 10:08:06 -0700 | [diff] [blame] | 12 | |
dsinclair | a52ab74 | 2016-09-29 13:59:29 -0700 | [diff] [blame] | 13 | #include "core/fxcrt/fx_ext.h" |
dsinclair | 4355468 | 2016-09-29 17:29:48 -0700 | [diff] [blame] | 14 | #include "fxjs/cfxjse_value.h" |
tsepez | aadedf9 | 2016-05-12 10:08:06 -0700 | [diff] [blame] | 15 | #include "third_party/base/stl_util.h" |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 16 | #include "xfa/fde/xml/fde_xml_imp.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 17 | #include "xfa/fgas/crt/fgas_codepage.h" |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 18 | #include "xfa/fxfa/app/xfa_ffnotify.h" |
dsinclair | 5b49309 | 2016-09-29 20:20:24 -0700 | [diff] [blame] | 19 | #include "xfa/fxfa/cxfa_eventparam.h" |
dsinclair | 1628024 | 2016-07-21 12:03:47 -0700 | [diff] [blame] | 20 | #include "xfa/fxfa/parser/cxfa_document.h" |
dsinclair | 0b851ff | 2016-07-21 12:03:01 -0700 | [diff] [blame] | 21 | #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 22 | #include "xfa/fxfa/parser/cxfa_measurement.h" |
dsinclair | 44d054c | 2016-04-06 10:23:46 -0700 | [diff] [blame] | 23 | #include "xfa/fxfa/parser/cxfa_occur.h" |
dsinclair | 31f8740 | 2016-07-20 06:34:45 -0700 | [diff] [blame] | 24 | #include "xfa/fxfa/parser/cxfa_scriptcontext.h" |
dsinclair | 34f86b0 | 2016-07-11 08:42:33 -0700 | [diff] [blame] | 25 | #include "xfa/fxfa/parser/cxfa_simple_parser.h" |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 26 | #include "xfa/fxfa/parser/xfa_basic_data.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 27 | |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 28 | namespace { |
| 29 | |
| 30 | void XFA_DeleteWideString(void* pData) { |
| 31 | delete static_cast<CFX_WideString*>(pData); |
| 32 | } |
| 33 | |
| 34 | void XFA_CopyWideString(void*& pData) { |
| 35 | if (pData) { |
| 36 | CFX_WideString* pNewData = new CFX_WideString(*(CFX_WideString*)pData); |
| 37 | pData = pNewData; |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | XFA_MAPDATABLOCKCALLBACKINFO deleteWideStringCallBack = {XFA_DeleteWideString, |
| 42 | XFA_CopyWideString}; |
| 43 | |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 44 | void XFA_DataNodeDeleteBindItem(void* pData) { |
| 45 | delete static_cast<CXFA_NodeArray*>(pData); |
| 46 | } |
| 47 | |
| 48 | XFA_MAPDATABLOCKCALLBACKINFO deleteBindItemCallBack = { |
| 49 | XFA_DataNodeDeleteBindItem, nullptr}; |
| 50 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 51 | int32_t GetCount(CXFA_Node* pInstMgrNode) { |
| 52 | ASSERT(pInstMgrNode); |
| 53 | int32_t iCount = 0; |
| 54 | uint32_t dwNameHash = 0; |
| 55 | for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 56 | pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 57 | XFA_Element eCurType = pNode->GetElementType(); |
| 58 | if (eCurType == XFA_Element::InstanceManager) |
| 59 | break; |
| 60 | if ((eCurType != XFA_Element::Subform) && |
| 61 | (eCurType != XFA_Element::SubformSet)) { |
| 62 | continue; |
| 63 | } |
| 64 | if (iCount == 0) { |
| 65 | CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name); |
| 66 | CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name); |
| 67 | if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' || |
| 68 | wsInstName.Mid(1) != wsName) { |
| 69 | return iCount; |
| 70 | } |
| 71 | dwNameHash = pNode->GetNameHash(); |
| 72 | } |
| 73 | if (dwNameHash != pNode->GetNameHash()) |
| 74 | break; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 75 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 76 | iCount++; |
| 77 | } |
| 78 | return iCount; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 79 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 80 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 81 | void SortNodeArrayByDocumentIdx(const CXFA_NodeSet& rgNodeSet, |
| 82 | CXFA_NodeArray& rgNodeArray, |
| 83 | CFX_ArrayTemplate<int32_t>& rgIdxArray) { |
| 84 | int32_t iCount = pdfium::CollectionSize<int32_t>(rgNodeSet); |
| 85 | rgNodeArray.SetSize(iCount); |
| 86 | rgIdxArray.SetSize(iCount); |
| 87 | if (iCount == 0) |
| 88 | return; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 89 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 90 | int32_t iIndex = -1; |
| 91 | int32_t iTotalIndex = -1; |
| 92 | CXFA_Node* pCommonParent = |
| 93 | (*rgNodeSet.begin())->GetNodeItem(XFA_NODEITEM_Parent); |
| 94 | for (CXFA_Node* pNode = pCommonParent->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 95 | pNode && iIndex < iCount; |
| 96 | pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 97 | iTotalIndex++; |
| 98 | if (pdfium::ContainsValue(rgNodeSet, pNode)) { |
| 99 | iIndex++; |
| 100 | rgNodeArray[iIndex] = pNode; |
| 101 | rgIdxArray[iIndex] = iTotalIndex; |
| 102 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 103 | } |
| 104 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 105 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 106 | using CXFA_NodeSetPair = std::pair<CXFA_NodeSet, CXFA_NodeSet>; |
| 107 | using CXFA_NodeSetPairMap = |
| 108 | std::map<uint32_t, std::unique_ptr<CXFA_NodeSetPair>>; |
| 109 | using CXFA_NodeSetPairMapMap = |
| 110 | std::map<CXFA_Node*, std::unique_ptr<CXFA_NodeSetPairMap>>; |
| 111 | |
| 112 | CXFA_NodeSetPair* NodeSetPairForNode(CXFA_Node* pNode, |
| 113 | CXFA_NodeSetPairMapMap* pMap) { |
| 114 | CXFA_Node* pParentNode = pNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 115 | uint32_t dwNameHash = pNode->GetNameHash(); |
| 116 | if (!pParentNode || !dwNameHash) |
| 117 | return nullptr; |
| 118 | |
| 119 | if (!(*pMap)[pParentNode]) |
| 120 | (*pMap)[pParentNode].reset(new CXFA_NodeSetPairMap); |
| 121 | |
| 122 | CXFA_NodeSetPairMap* pNodeSetPairMap = (*pMap)[pParentNode].get(); |
| 123 | if (!(*pNodeSetPairMap)[dwNameHash]) |
| 124 | (*pNodeSetPairMap)[dwNameHash].reset(new CXFA_NodeSetPair); |
| 125 | |
| 126 | return (*pNodeSetPairMap)[dwNameHash].get(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 127 | } |
| 128 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 129 | void ReorderDataNodes(const CXFA_NodeSet& sSet1, |
| 130 | const CXFA_NodeSet& sSet2, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 131 | bool bInsertBefore) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 132 | CXFA_NodeSetPairMapMap rgMap; |
| 133 | for (CXFA_Node* pNode : sSet1) { |
| 134 | CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap); |
| 135 | if (pNodeSetPair) |
| 136 | pNodeSetPair->first.insert(pNode); |
| 137 | } |
| 138 | for (CXFA_Node* pNode : sSet2) { |
| 139 | CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap); |
| 140 | if (pNodeSetPair) { |
| 141 | if (pdfium::ContainsValue(pNodeSetPair->first, pNode)) |
| 142 | pNodeSetPair->first.erase(pNode); |
| 143 | else |
| 144 | pNodeSetPair->second.insert(pNode); |
| 145 | } |
| 146 | } |
| 147 | for (const auto& iter1 : rgMap) { |
| 148 | CXFA_NodeSetPairMap* pNodeSetPairMap = iter1.second.get(); |
| 149 | if (!pNodeSetPairMap) |
| 150 | continue; |
| 151 | |
| 152 | for (const auto& iter2 : *pNodeSetPairMap) { |
| 153 | CXFA_NodeSetPair* pNodeSetPair = iter2.second.get(); |
| 154 | if (!pNodeSetPair) |
| 155 | continue; |
| 156 | if (!pNodeSetPair->first.empty() && !pNodeSetPair->second.empty()) { |
| 157 | CXFA_NodeArray rgNodeArray1; |
| 158 | CXFA_NodeArray rgNodeArray2; |
| 159 | CFX_ArrayTemplate<int32_t> rgIdxArray1; |
| 160 | CFX_ArrayTemplate<int32_t> rgIdxArray2; |
| 161 | SortNodeArrayByDocumentIdx(pNodeSetPair->first, rgNodeArray1, |
| 162 | rgIdxArray1); |
| 163 | SortNodeArrayByDocumentIdx(pNodeSetPair->second, rgNodeArray2, |
| 164 | rgIdxArray2); |
| 165 | CXFA_Node* pParentNode = nullptr; |
| 166 | CXFA_Node* pBeforeNode = nullptr; |
| 167 | if (bInsertBefore) { |
| 168 | pBeforeNode = rgNodeArray2[0]; |
| 169 | pParentNode = pBeforeNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 170 | } else { |
| 171 | CXFA_Node* pLastNode = rgNodeArray2[rgIdxArray2.GetSize() - 1]; |
| 172 | pParentNode = pLastNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 173 | pBeforeNode = pLastNode->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 174 | } |
| 175 | for (int32_t iIdx = 0; iIdx < rgIdxArray1.GetSize(); iIdx++) { |
| 176 | CXFA_Node* pCurNode = rgNodeArray1[iIdx]; |
| 177 | pParentNode->RemoveChild(pCurNode); |
| 178 | pParentNode->InsertChild(pCurNode, pBeforeNode); |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | pNodeSetPairMap->clear(); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | CXFA_Node* GetItem(CXFA_Node* pInstMgrNode, int32_t iIndex) { |
| 187 | ASSERT(pInstMgrNode); |
| 188 | int32_t iCount = 0; |
| 189 | uint32_t dwNameHash = 0; |
| 190 | for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 191 | pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 192 | XFA_Element eCurType = pNode->GetElementType(); |
| 193 | if (eCurType == XFA_Element::InstanceManager) |
| 194 | break; |
| 195 | if ((eCurType != XFA_Element::Subform) && |
| 196 | (eCurType != XFA_Element::SubformSet)) { |
| 197 | continue; |
| 198 | } |
| 199 | if (iCount == 0) { |
| 200 | CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name); |
| 201 | CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name); |
| 202 | if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' || |
| 203 | wsInstName.Mid(1) != wsName) { |
| 204 | return nullptr; |
| 205 | } |
| 206 | dwNameHash = pNode->GetNameHash(); |
| 207 | } |
| 208 | if (dwNameHash != pNode->GetNameHash()) |
| 209 | break; |
| 210 | |
| 211 | iCount++; |
| 212 | if (iCount > iIndex) |
| 213 | return pNode; |
| 214 | } |
| 215 | return nullptr; |
| 216 | } |
| 217 | |
| 218 | void InsertItem(CXFA_Node* pInstMgrNode, |
| 219 | CXFA_Node* pNewInstance, |
| 220 | int32_t iPos, |
| 221 | int32_t iCount = -1, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 222 | bool bMoveDataBindingNodes = true) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 223 | if (iCount < 0) |
| 224 | iCount = GetCount(pInstMgrNode); |
| 225 | if (iPos < 0) |
| 226 | iPos = iCount; |
| 227 | if (iPos == iCount) { |
| 228 | CXFA_Node* pNextSibling = |
| 229 | iCount > 0 |
| 230 | ? GetItem(pInstMgrNode, iCount - 1) |
| 231 | ->GetNodeItem(XFA_NODEITEM_NextSibling) |
| 232 | : pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 233 | pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent) |
| 234 | ->InsertChild(pNewInstance, pNextSibling); |
| 235 | if (bMoveDataBindingNodes) { |
| 236 | CXFA_NodeSet sNew; |
| 237 | CXFA_NodeSet sAfter; |
| 238 | CXFA_NodeIteratorTemplate<CXFA_Node, |
| 239 | CXFA_TraverseStrategy_XFAContainerNode> |
| 240 | sIteratorNew(pNewInstance); |
| 241 | for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode; |
| 242 | pNode = sIteratorNew.MoveToNext()) { |
| 243 | CXFA_Node* pDataNode = pNode->GetBindData(); |
| 244 | if (!pDataNode) |
| 245 | continue; |
| 246 | |
| 247 | sNew.insert(pDataNode); |
| 248 | } |
| 249 | CXFA_NodeIteratorTemplate<CXFA_Node, |
| 250 | CXFA_TraverseStrategy_XFAContainerNode> |
| 251 | sIteratorAfter(pNextSibling); |
| 252 | for (CXFA_Node* pNode = sIteratorAfter.GetCurrent(); pNode; |
| 253 | pNode = sIteratorAfter.MoveToNext()) { |
| 254 | CXFA_Node* pDataNode = pNode->GetBindData(); |
| 255 | if (!pDataNode) |
| 256 | continue; |
| 257 | |
| 258 | sAfter.insert(pDataNode); |
| 259 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 260 | ReorderDataNodes(sNew, sAfter, false); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 261 | } |
| 262 | } else { |
| 263 | CXFA_Node* pBeforeInstance = GetItem(pInstMgrNode, iPos); |
| 264 | pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent) |
| 265 | ->InsertChild(pNewInstance, pBeforeInstance); |
| 266 | if (bMoveDataBindingNodes) { |
| 267 | CXFA_NodeSet sNew; |
| 268 | CXFA_NodeSet sBefore; |
| 269 | CXFA_NodeIteratorTemplate<CXFA_Node, |
| 270 | CXFA_TraverseStrategy_XFAContainerNode> |
| 271 | sIteratorNew(pNewInstance); |
| 272 | for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode; |
| 273 | pNode = sIteratorNew.MoveToNext()) { |
| 274 | CXFA_Node* pDataNode = pNode->GetBindData(); |
| 275 | if (!pDataNode) |
| 276 | continue; |
| 277 | |
| 278 | sNew.insert(pDataNode); |
| 279 | } |
| 280 | CXFA_NodeIteratorTemplate<CXFA_Node, |
| 281 | CXFA_TraverseStrategy_XFAContainerNode> |
| 282 | sIteratorBefore(pBeforeInstance); |
| 283 | for (CXFA_Node* pNode = sIteratorBefore.GetCurrent(); pNode; |
| 284 | pNode = sIteratorBefore.MoveToNext()) { |
| 285 | CXFA_Node* pDataNode = pNode->GetBindData(); |
| 286 | if (!pDataNode) |
| 287 | continue; |
| 288 | |
| 289 | sBefore.insert(pDataNode); |
| 290 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 291 | ReorderDataNodes(sNew, sBefore, true); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 292 | } |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | void RemoveItem(CXFA_Node* pInstMgrNode, |
| 297 | CXFA_Node* pRemoveInstance, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 298 | bool bRemoveDataBinding = true) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 299 | pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)->RemoveChild(pRemoveInstance); |
| 300 | if (!bRemoveDataBinding) |
| 301 | return; |
| 302 | |
| 303 | CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFAContainerNode> |
| 304 | sIterator(pRemoveInstance); |
| 305 | for (CXFA_Node* pFormNode = sIterator.GetCurrent(); pFormNode; |
| 306 | pFormNode = sIterator.MoveToNext()) { |
| 307 | CXFA_Node* pDataNode = pFormNode->GetBindData(); |
| 308 | if (!pDataNode) |
| 309 | continue; |
| 310 | |
| 311 | if (pDataNode->RemoveBindItem(pFormNode) == 0) { |
| 312 | if (CXFA_Node* pDataParent = |
| 313 | pDataNode->GetNodeItem(XFA_NODEITEM_Parent)) { |
| 314 | pDataParent->RemoveChild(pDataNode); |
| 315 | } |
| 316 | } |
| 317 | pFormNode->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr); |
| 318 | } |
| 319 | } |
| 320 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 321 | CXFA_Node* CreateInstance(CXFA_Node* pInstMgrNode, bool bDataMerge) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 322 | CXFA_Document* pDocument = pInstMgrNode->GetDocument(); |
| 323 | CXFA_Node* pTemplateNode = pInstMgrNode->GetTemplateNode(); |
| 324 | CXFA_Node* pFormParent = pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 325 | CXFA_Node* pDataScope = nullptr; |
| 326 | for (CXFA_Node* pRootBoundNode = pFormParent; |
| 327 | pRootBoundNode && pRootBoundNode->IsContainerNode(); |
| 328 | pRootBoundNode = pRootBoundNode->GetNodeItem(XFA_NODEITEM_Parent)) { |
| 329 | pDataScope = pRootBoundNode->GetBindData(); |
| 330 | if (pDataScope) |
| 331 | break; |
| 332 | } |
| 333 | if (!pDataScope) { |
| 334 | pDataScope = ToNode(pDocument->GetXFAObject(XFA_HASHCODE_Record)); |
| 335 | ASSERT(pDataScope); |
| 336 | } |
| 337 | CXFA_Node* pInstance = pDocument->DataMerge_CopyContainer( |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 338 | pTemplateNode, pFormParent, pDataScope, true, bDataMerge, true); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 339 | if (pInstance) { |
| 340 | pDocument->DataMerge_UpdateBindingRelations(pInstance); |
| 341 | pFormParent->RemoveChild(pInstance); |
| 342 | } |
| 343 | return pInstance; |
| 344 | } |
| 345 | |
| 346 | struct XFA_ExecEventParaInfo { |
| 347 | public: |
| 348 | uint32_t m_uHash; |
| 349 | const FX_WCHAR* m_lpcEventName; |
| 350 | XFA_EVENTTYPE m_eventType; |
| 351 | uint32_t m_validFlags; |
| 352 | }; |
| 353 | static const XFA_ExecEventParaInfo gs_eventParaInfos[] = { |
| 354 | {0x02a6c55a, L"postSubmit", XFA_EVENT_PostSubmit, 0}, |
| 355 | {0x0ab466bb, L"preSubmit", XFA_EVENT_PreSubmit, 0}, |
| 356 | {0x109d7ce7, L"mouseEnter", XFA_EVENT_MouseEnter, 5}, |
| 357 | {0x17fad373, L"postPrint", XFA_EVENT_PostPrint, 0}, |
| 358 | {0x1bfc72d9, L"preOpen", XFA_EVENT_PreOpen, 7}, |
| 359 | {0x2196a452, L"initialize", XFA_EVENT_Initialize, 1}, |
| 360 | {0x27410f03, L"mouseExit", XFA_EVENT_MouseExit, 5}, |
| 361 | {0x33c43dec, L"docClose", XFA_EVENT_DocClose, 0}, |
| 362 | {0x361fa1b6, L"preSave", XFA_EVENT_PreSave, 0}, |
| 363 | {0x36f1c6d8, L"preSign", XFA_EVENT_PreSign, 6}, |
| 364 | {0x4731d6ba, L"exit", XFA_EVENT_Exit, 2}, |
| 365 | {0x56bf456b, L"docReady", XFA_EVENT_DocReady, 0}, |
| 366 | {0x7233018a, L"validate", XFA_EVENT_Validate, 1}, |
| 367 | {0x8808385e, L"indexChange", XFA_EVENT_IndexChange, 3}, |
| 368 | {0x891f4606, L"change", XFA_EVENT_Change, 4}, |
| 369 | {0x9528a7b4, L"prePrint", XFA_EVENT_PrePrint, 0}, |
| 370 | {0x9f693b21, L"mouseDown", XFA_EVENT_MouseDown, 5}, |
| 371 | {0xcdce56b3, L"full", XFA_EVENT_Full, 4}, |
| 372 | {0xd576d08e, L"mouseUp", XFA_EVENT_MouseUp, 5}, |
| 373 | {0xd95657a6, L"click", XFA_EVENT_Click, 4}, |
| 374 | {0xdbfbe02e, L"calculate", XFA_EVENT_Calculate, 1}, |
| 375 | {0xe25fa7b8, L"postOpen", XFA_EVENT_PostOpen, 7}, |
| 376 | {0xe28dce7e, L"enter", XFA_EVENT_Enter, 2}, |
| 377 | {0xfc82d695, L"postSave", XFA_EVENT_PostSave, 0}, |
| 378 | {0xfd54fbb7, L"postSign", XFA_EVENT_PostSign, 6}, |
| 379 | }; |
| 380 | |
| 381 | const XFA_ExecEventParaInfo* GetEventParaInfoByName( |
| 382 | const CFX_WideStringC& wsEventName) { |
| 383 | uint32_t uHash = FX_HashCode_GetW(wsEventName, false); |
| 384 | int32_t iStart = 0; |
| 385 | int32_t iEnd = (sizeof(gs_eventParaInfos) / sizeof(gs_eventParaInfos[0])) - 1; |
| 386 | do { |
| 387 | int32_t iMid = (iStart + iEnd) / 2; |
| 388 | const XFA_ExecEventParaInfo* eventParaInfo = &gs_eventParaInfos[iMid]; |
| 389 | if (uHash == eventParaInfo->m_uHash) |
| 390 | return eventParaInfo; |
| 391 | if (uHash < eventParaInfo->m_uHash) |
| 392 | iEnd = iMid - 1; |
| 393 | else |
| 394 | iStart = iMid + 1; |
| 395 | } while (iStart <= iEnd); |
| 396 | return nullptr; |
| 397 | } |
| 398 | |
| 399 | void StrToRGB(const CFX_WideString& strRGB, |
| 400 | int32_t& r, |
| 401 | int32_t& g, |
| 402 | int32_t& b) { |
| 403 | r = 0; |
| 404 | g = 0; |
| 405 | b = 0; |
| 406 | |
| 407 | FX_WCHAR zero = '0'; |
| 408 | int32_t iIndex = 0; |
| 409 | int32_t iLen = strRGB.GetLength(); |
| 410 | for (int32_t i = 0; i < iLen; ++i) { |
| 411 | FX_WCHAR ch = strRGB.GetAt(i); |
| 412 | if (ch == L',') |
| 413 | ++iIndex; |
| 414 | if (iIndex > 2) |
| 415 | break; |
| 416 | |
| 417 | int32_t iValue = ch - zero; |
| 418 | if (iValue >= 0 && iValue <= 9) { |
| 419 | switch (iIndex) { |
| 420 | case 0: |
| 421 | r = r * 10 + iValue; |
| 422 | break; |
| 423 | case 1: |
| 424 | g = g * 10 + iValue; |
| 425 | break; |
| 426 | default: |
| 427 | b = b * 10 + iValue; |
| 428 | break; |
| 429 | } |
| 430 | } |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | enum XFA_KEYTYPE { |
| 435 | XFA_KEYTYPE_Custom, |
| 436 | XFA_KEYTYPE_Element, |
| 437 | }; |
| 438 | |
| 439 | void* GetMapKey_Custom(const CFX_WideStringC& wsKey) { |
| 440 | uint32_t dwKey = FX_HashCode_GetW(wsKey, false); |
| 441 | return (void*)(uintptr_t)((dwKey << 1) | XFA_KEYTYPE_Custom); |
| 442 | } |
| 443 | |
| 444 | void* GetMapKey_Element(XFA_Element eType, XFA_ATTRIBUTE eAttribute) { |
| 445 | return (void*)(uintptr_t)((static_cast<int32_t>(eType) << 16) | |
| 446 | (eAttribute << 8) | XFA_KEYTYPE_Element); |
| 447 | } |
| 448 | |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 449 | const XFA_ATTRIBUTEINFO* GetAttributeOfElement(XFA_Element eElement, |
| 450 | XFA_ATTRIBUTE eAttribute, |
| 451 | uint32_t dwPacket) { |
| 452 | int32_t iCount = 0; |
| 453 | const uint8_t* pAttr = XFA_GetElementAttributes(eElement, iCount); |
| 454 | if (!pAttr || iCount < 1) |
| 455 | return nullptr; |
| 456 | |
| 457 | if (!std::binary_search(pAttr, pAttr + iCount, eAttribute)) |
| 458 | return nullptr; |
| 459 | |
| 460 | const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttribute); |
| 461 | ASSERT(pInfo); |
| 462 | if (dwPacket == XFA_XDPPACKET_UNKNOWN) |
| 463 | return pInfo; |
| 464 | return (dwPacket & pInfo->dwPackets) ? pInfo : nullptr; |
| 465 | } |
| 466 | |
| 467 | const XFA_ATTRIBUTEENUMINFO* GetAttributeEnumByID(XFA_ATTRIBUTEENUM eName) { |
| 468 | return g_XFAEnumData + eName; |
| 469 | } |
| 470 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 471 | } // namespace |
| 472 | |
| 473 | static void XFA_DefaultFreeData(void* pData) {} |
| 474 | |
| 475 | static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADefaultFreeData = { |
| 476 | XFA_DefaultFreeData, nullptr}; |
| 477 | |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 478 | XFA_MAPMODULEDATA::XFA_MAPMODULEDATA() {} |
| 479 | |
| 480 | XFA_MAPMODULEDATA::~XFA_MAPMODULEDATA() {} |
| 481 | |
dsinclair | b977847 | 2016-06-23 13:34:10 -0700 | [diff] [blame] | 482 | CXFA_Node::CXFA_Node(CXFA_Document* pDoc, |
| 483 | uint16_t ePacket, |
| 484 | XFA_ObjectType oType, |
dsinclair | c1df5d4 | 2016-07-18 06:36:51 -0700 | [diff] [blame] | 485 | XFA_Element eType, |
| 486 | const CFX_WideStringC& elementName) |
| 487 | : CXFA_Object(pDoc, oType, eType, elementName), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 488 | m_pNext(nullptr), |
| 489 | m_pChild(nullptr), |
| 490 | m_pLastChild(nullptr), |
| 491 | m_pParent(nullptr), |
| 492 | m_pXMLNode(nullptr), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 493 | m_ePacket(ePacket), |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 494 | m_uNodeFlags(XFA_NodeFlag_None), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 495 | m_dwNameHash(0), |
| 496 | m_pAuxNode(nullptr), |
| 497 | m_pMapModuleData(nullptr) { |
| 498 | ASSERT(m_pDocument); |
| 499 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 500 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 501 | CXFA_Node::~CXFA_Node() { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 502 | ASSERT(!m_pParent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 503 | RemoveMapModuleKey(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 504 | CXFA_Node* pNode = m_pChild; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 505 | while (pNode) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 506 | CXFA_Node* pNext = pNode->m_pNext; |
| 507 | pNode->m_pParent = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 508 | delete pNode; |
| 509 | pNode = pNext; |
| 510 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 511 | if (m_pXMLNode && IsOwnXMLNode()) |
Tom Sepez | d3743ea | 2016-05-16 15:56:53 -0700 | [diff] [blame] | 512 | m_pXMLNode->Release(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 513 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 514 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 515 | CXFA_Node* CXFA_Node::Clone(bool bRecursive) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 516 | CXFA_Node* pClone = m_pDocument->CreateNode(m_ePacket, m_elementType); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 517 | if (!pClone) |
| 518 | return nullptr; |
| 519 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 520 | MergeAllData(pClone); |
| 521 | pClone->UpdateNameHash(); |
| 522 | if (IsNeedSavingXMLNode()) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 523 | CFDE_XMLNode* pCloneXML = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 524 | if (IsAttributeInXML()) { |
| 525 | CFX_WideString wsName; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 526 | GetAttribute(XFA_ATTRIBUTE_Name, wsName, false); |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 527 | CFDE_XMLElement* pCloneXMLElement = new CFDE_XMLElement(wsName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 528 | CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value); |
| 529 | if (!wsValue.IsEmpty()) { |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 530 | pCloneXMLElement->SetTextData(CFX_WideString(wsValue)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 531 | } |
| 532 | pCloneXML = pCloneXMLElement; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 533 | pCloneXMLElement = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 534 | pClone->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown); |
| 535 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 536 | pCloneXML = m_pXMLNode->Clone(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 537 | } |
| 538 | pClone->SetXMLMappingNode(pCloneXML); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 539 | pClone->SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 540 | } |
| 541 | if (bRecursive) { |
| 542 | for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild; |
| 543 | pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 544 | pClone->InsertChild(pChild->Clone(bRecursive)); |
| 545 | } |
| 546 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 547 | pClone->SetFlag(XFA_NodeFlag_Initialized, true); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 548 | pClone->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 549 | return pClone; |
| 550 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 551 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 552 | CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem) const { |
| 553 | switch (eItem) { |
| 554 | case XFA_NODEITEM_NextSibling: |
| 555 | return m_pNext; |
| 556 | case XFA_NODEITEM_FirstChild: |
| 557 | return m_pChild; |
| 558 | case XFA_NODEITEM_Parent: |
| 559 | return m_pParent; |
| 560 | case XFA_NODEITEM_PrevSibling: |
| 561 | if (m_pParent) { |
| 562 | CXFA_Node* pSibling = m_pParent->m_pChild; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 563 | CXFA_Node* pPrev = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 564 | while (pSibling && pSibling != this) { |
| 565 | pPrev = pSibling; |
| 566 | pSibling = pSibling->m_pNext; |
| 567 | } |
| 568 | return pPrev; |
| 569 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 570 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 571 | default: |
| 572 | break; |
| 573 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 574 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 575 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 576 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 577 | CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem, |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 578 | XFA_ObjectType eType) const { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 579 | CXFA_Node* pNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 580 | switch (eItem) { |
| 581 | case XFA_NODEITEM_NextSibling: |
| 582 | pNode = m_pNext; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 583 | while (pNode && pNode->GetObjectType() != eType) |
| 584 | pNode = pNode->m_pNext; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 585 | break; |
| 586 | case XFA_NODEITEM_FirstChild: |
| 587 | pNode = m_pChild; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 588 | while (pNode && pNode->GetObjectType() != eType) |
| 589 | pNode = pNode->m_pNext; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 590 | break; |
| 591 | case XFA_NODEITEM_Parent: |
| 592 | pNode = m_pParent; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 593 | while (pNode && pNode->GetObjectType() != eType) |
| 594 | pNode = pNode->m_pParent; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 595 | break; |
| 596 | case XFA_NODEITEM_PrevSibling: |
| 597 | if (m_pParent) { |
| 598 | CXFA_Node* pSibling = m_pParent->m_pChild; |
| 599 | while (pSibling && pSibling != this) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 600 | if (eType == pSibling->GetObjectType()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 601 | pNode = pSibling; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 602 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 603 | pSibling = pSibling->m_pNext; |
| 604 | } |
| 605 | } |
| 606 | break; |
| 607 | default: |
| 608 | break; |
| 609 | } |
| 610 | return pNode; |
| 611 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 612 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 613 | int32_t CXFA_Node::GetNodeList(CXFA_NodeArray& nodes, |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 614 | uint32_t dwTypeFilter, |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 615 | XFA_Element eTypeFilter, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 616 | int32_t iLevel) { |
| 617 | if (--iLevel < 0) { |
| 618 | return nodes.GetSize(); |
| 619 | } |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 620 | if (eTypeFilter != XFA_Element::Unknown) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 621 | CXFA_Node* pChild = m_pChild; |
| 622 | while (pChild) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 623 | if (pChild->GetElementType() == eTypeFilter) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 624 | nodes.Add(pChild); |
| 625 | if (iLevel > 0) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 626 | GetNodeList(nodes, dwTypeFilter, eTypeFilter, iLevel); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 627 | } |
| 628 | } |
| 629 | pChild = pChild->m_pNext; |
| 630 | } |
| 631 | } else if (dwTypeFilter == |
| 632 | (XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties)) { |
| 633 | CXFA_Node* pChild = m_pChild; |
| 634 | while (pChild) { |
| 635 | nodes.Add(pChild); |
| 636 | if (iLevel > 0) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 637 | GetNodeList(nodes, dwTypeFilter, eTypeFilter, iLevel); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 638 | } |
| 639 | pChild = pChild->m_pNext; |
| 640 | } |
| 641 | } else if (dwTypeFilter != 0) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 642 | bool bFilterChildren = !!(dwTypeFilter & XFA_NODEFILTER_Children); |
| 643 | bool bFilterProperties = !!(dwTypeFilter & XFA_NODEFILTER_Properties); |
| 644 | bool bFilterOneOfProperties = |
| 645 | !!(dwTypeFilter & XFA_NODEFILTER_OneOfProperty); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 646 | CXFA_Node* pChild = m_pChild; |
| 647 | while (pChild) { |
| 648 | const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement( |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 649 | GetElementType(), pChild->GetElementType(), XFA_XDPPACKET_UNKNOWN); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 650 | if (pProperty) { |
| 651 | if (bFilterProperties) { |
| 652 | nodes.Add(pChild); |
| 653 | } else if (bFilterOneOfProperties && |
| 654 | (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) { |
| 655 | nodes.Add(pChild); |
| 656 | } else if (bFilterChildren && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 657 | (pChild->GetElementType() == XFA_Element::Variables || |
| 658 | pChild->GetElementType() == XFA_Element::PageSet)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 659 | nodes.Add(pChild); |
| 660 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 661 | } else if (bFilterChildren) { |
| 662 | nodes.Add(pChild); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 663 | } |
| 664 | pChild = pChild->m_pNext; |
| 665 | } |
| 666 | if (bFilterOneOfProperties && nodes.GetSize() < 1) { |
| 667 | int32_t iProperties = 0; |
| 668 | const XFA_PROPERTY* pProperty = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 669 | XFA_GetElementProperties(GetElementType(), iProperties); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 670 | if (!pProperty || iProperties < 1) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 671 | return 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 672 | for (int32_t i = 0; i < iProperties; i++) { |
| 673 | if (pProperty[i].uFlags & XFA_PROPERTYFLAG_DefaultOneOf) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 674 | const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(GetPacketID()); |
| 675 | CXFA_Node* pNewNode = |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 676 | m_pDocument->CreateNode(pPacket, pProperty[i].eName); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 677 | if (!pNewNode) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 678 | break; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 679 | InsertChild(pNewNode, nullptr); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 680 | pNewNode->SetFlag(XFA_NodeFlag_Initialized, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 681 | nodes.Add(pNewNode); |
| 682 | break; |
| 683 | } |
| 684 | } |
| 685 | } |
| 686 | } |
| 687 | return nodes.GetSize(); |
| 688 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 689 | |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 690 | CXFA_Node* CXFA_Node::CreateSamePacketNode(XFA_Element eType, |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 691 | uint32_t dwFlags) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 692 | CXFA_Node* pNode = m_pDocument->CreateNode(m_ePacket, eType); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 693 | pNode->SetFlag(dwFlags, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 694 | return pNode; |
| 695 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 696 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 697 | CXFA_Node* CXFA_Node::CloneTemplateToForm(bool bRecursive) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 698 | ASSERT(m_ePacket == XFA_XDPPACKET_Template); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 699 | CXFA_Node* pClone = |
| 700 | m_pDocument->CreateNode(XFA_XDPPACKET_Form, m_elementType); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 701 | if (!pClone) |
| 702 | return nullptr; |
| 703 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 704 | pClone->SetTemplateNode(this); |
| 705 | pClone->UpdateNameHash(); |
| 706 | pClone->SetXMLMappingNode(GetXMLMappingNode()); |
| 707 | if (bRecursive) { |
| 708 | for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild; |
| 709 | pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 710 | pClone->InsertChild(pChild->CloneTemplateToForm(bRecursive)); |
| 711 | } |
| 712 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 713 | pClone->SetFlag(XFA_NodeFlag_Initialized, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 714 | return pClone; |
| 715 | } |
| 716 | |
| 717 | CXFA_Node* CXFA_Node::GetTemplateNode() const { |
| 718 | return m_pAuxNode; |
| 719 | } |
| 720 | |
| 721 | void CXFA_Node::SetTemplateNode(CXFA_Node* pTemplateNode) { |
| 722 | m_pAuxNode = pTemplateNode; |
| 723 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 724 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 725 | CXFA_Node* CXFA_Node::GetBindData() { |
| 726 | ASSERT(GetPacketID() == XFA_XDPPACKET_Form); |
| 727 | return static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); |
| 728 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 729 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 730 | int32_t CXFA_Node::GetBindItems(CXFA_NodeArray& formItems) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 731 | if (BindsFormItems()) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 732 | CXFA_NodeArray* pItems = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 733 | TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems); |
| 734 | formItems.Copy(*pItems); |
| 735 | return formItems.GetSize(); |
| 736 | } |
| 737 | CXFA_Node* pFormNode = |
| 738 | static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 739 | if (pFormNode) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 740 | formItems.Add(pFormNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 741 | return formItems.GetSize(); |
| 742 | } |
| 743 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 744 | int32_t CXFA_Node::AddBindItem(CXFA_Node* pFormNode) { |
| 745 | ASSERT(pFormNode); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 746 | if (BindsFormItems()) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 747 | CXFA_NodeArray* pItems = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 748 | TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems); |
| 749 | ASSERT(pItems); |
| 750 | if (pItems->Find(pFormNode) < 0) { |
| 751 | pItems->Add(pFormNode); |
| 752 | } |
| 753 | return pItems->GetSize(); |
| 754 | } |
| 755 | CXFA_Node* pOldFormItem = |
| 756 | static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); |
| 757 | if (!pOldFormItem) { |
| 758 | SetObject(XFA_ATTRIBUTE_BindingNode, pFormNode); |
| 759 | return 1; |
| 760 | } else if (pOldFormItem == pFormNode) { |
| 761 | return 1; |
| 762 | } |
| 763 | CXFA_NodeArray* pItems = new CXFA_NodeArray; |
| 764 | SetObject(XFA_ATTRIBUTE_BindingNode, pItems, &deleteBindItemCallBack); |
| 765 | pItems->Add(pOldFormItem); |
| 766 | pItems->Add(pFormNode); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 767 | m_uNodeFlags |= XFA_NodeFlag_BindFormItems; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 768 | return 2; |
| 769 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 770 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 771 | int32_t CXFA_Node::RemoveBindItem(CXFA_Node* pFormNode) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 772 | if (BindsFormItems()) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 773 | CXFA_NodeArray* pItems = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 774 | TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems); |
| 775 | ASSERT(pItems); |
| 776 | int32_t iIndex = pItems->Find(pFormNode); |
| 777 | int32_t iCount = pItems->GetSize(); |
| 778 | if (iIndex >= 0) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 779 | if (iIndex != iCount - 1) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 780 | pItems->SetAt(iIndex, pItems->GetAt(iCount - 1)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 781 | pItems->RemoveAt(iCount - 1); |
| 782 | if (iCount == 2) { |
| 783 | CXFA_Node* pLastFormNode = pItems->GetAt(0); |
| 784 | SetObject(XFA_ATTRIBUTE_BindingNode, pLastFormNode); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 785 | m_uNodeFlags &= ~XFA_NodeFlag_BindFormItems; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 786 | } |
| 787 | iCount--; |
| 788 | } |
| 789 | return iCount; |
| 790 | } |
| 791 | CXFA_Node* pOldFormItem = |
| 792 | static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); |
| 793 | if (pOldFormItem == pFormNode) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 794 | SetObject(XFA_ATTRIBUTE_BindingNode, nullptr); |
| 795 | pOldFormItem = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 796 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 797 | return pOldFormItem ? 1 : 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 798 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 799 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 800 | bool CXFA_Node::HasBindItem() { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 801 | return GetPacketID() == XFA_XDPPACKET_Datasets && |
| 802 | GetObject(XFA_ATTRIBUTE_BindingNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 803 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 804 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 805 | CXFA_WidgetData* CXFA_Node::GetWidgetData() { |
| 806 | return (CXFA_WidgetData*)GetObject(XFA_ATTRIBUTE_WidgetData); |
| 807 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 808 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 809 | CXFA_WidgetData* CXFA_Node::GetContainerWidgetData() { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 810 | if (GetPacketID() != XFA_XDPPACKET_Form) |
| 811 | return nullptr; |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 812 | XFA_Element eType = GetElementType(); |
| 813 | if (eType == XFA_Element::ExclGroup) |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 814 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 815 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 816 | if (pParentNode && pParentNode->GetElementType() == XFA_Element::ExclGroup) |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 817 | return nullptr; |
| 818 | |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 819 | if (eType == XFA_Element::Field) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 820 | CXFA_WidgetData* pFieldWidgetData = GetWidgetData(); |
| 821 | if (pFieldWidgetData && |
| 822 | pFieldWidgetData->GetChoiceListOpen() == |
| 823 | XFA_ATTRIBUTEENUM_MultiSelect) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 824 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 825 | } else { |
| 826 | CFX_WideString wsPicture; |
| 827 | if (pFieldWidgetData) { |
| 828 | pFieldWidgetData->GetPictureContent(wsPicture, |
| 829 | XFA_VALUEPICTURE_DataBind); |
| 830 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 831 | if (!wsPicture.IsEmpty()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 832 | return pFieldWidgetData; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 833 | CXFA_Node* pDataNode = GetBindData(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 834 | if (!pDataNode) |
| 835 | return nullptr; |
| 836 | pFieldWidgetData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 837 | CXFA_NodeArray formNodes; |
| 838 | pDataNode->GetBindItems(formNodes); |
| 839 | for (int32_t i = 0; i < formNodes.GetSize(); i++) { |
| 840 | CXFA_Node* pFormNode = formNodes.GetAt(i); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 841 | if (!pFormNode || pFormNode->HasRemovedChildren()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 842 | continue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 843 | pFieldWidgetData = pFormNode->GetWidgetData(); |
| 844 | if (pFieldWidgetData) { |
| 845 | pFieldWidgetData->GetPictureContent(wsPicture, |
| 846 | XFA_VALUEPICTURE_DataBind); |
| 847 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 848 | if (!wsPicture.IsEmpty()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 849 | break; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 850 | pFieldWidgetData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 851 | } |
| 852 | return pFieldWidgetData; |
| 853 | } |
| 854 | } |
| 855 | CXFA_Node* pGrandNode = |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 856 | pParentNode ? pParentNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 857 | CXFA_Node* pValueNode = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 858 | (pParentNode && pParentNode->GetElementType() == XFA_Element::Value) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 859 | ? pParentNode |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 860 | : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 861 | if (!pValueNode) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 862 | pValueNode = |
| 863 | (pGrandNode && pGrandNode->GetElementType() == XFA_Element::Value) |
| 864 | ? pGrandNode |
| 865 | : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 866 | } |
| 867 | CXFA_Node* pParentOfValueNode = |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 868 | pValueNode ? pValueNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 869 | return pParentOfValueNode ? pParentOfValueNode->GetContainerWidgetData() |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 870 | : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 871 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 872 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 873 | bool CXFA_Node::GetLocaleName(CFX_WideString& wsLocaleName) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 874 | CXFA_Node* pForm = GetDocument()->GetXFAObject(XFA_HASHCODE_Form)->AsNode(); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 875 | CXFA_Node* pTopSubform = pForm->GetFirstChildByClass(XFA_Element::Subform); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 876 | ASSERT(pTopSubform); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 877 | CXFA_Node* pLocaleNode = this; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 878 | bool bLocale = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 879 | do { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 880 | bLocale = pLocaleNode->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 881 | if (!bLocale) { |
| 882 | pLocaleNode = pLocaleNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 883 | } |
| 884 | } while (pLocaleNode && pLocaleNode != pTopSubform && !bLocale); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 885 | if (bLocale) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 886 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 887 | CXFA_Node* pConfig = ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Config)); |
| 888 | wsLocaleName = GetDocument()->GetLocalMgr()->GetConfigLocaleName(pConfig); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 889 | if (!wsLocaleName.IsEmpty()) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 890 | return true; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 891 | if (pTopSubform && |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 892 | pTopSubform->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false)) { |
| 893 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 894 | } |
| 895 | IFX_Locale* pLocale = GetDocument()->GetLocalMgr()->GetDefLocale(); |
| 896 | if (pLocale) { |
| 897 | wsLocaleName = pLocale->GetName(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 898 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 899 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 900 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 901 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 902 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 903 | XFA_ATTRIBUTEENUM CXFA_Node::GetIntact() { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 904 | CXFA_Node* pKeep = GetFirstChildByClass(XFA_Element::Keep); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 905 | XFA_ATTRIBUTEENUM eLayoutType = GetEnum(XFA_ATTRIBUTE_Layout); |
| 906 | if (pKeep) { |
| 907 | XFA_ATTRIBUTEENUM eIntact; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 908 | if (pKeep->TryEnum(XFA_ATTRIBUTE_Intact, eIntact, false)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 909 | if (eIntact == XFA_ATTRIBUTEENUM_None && |
| 910 | eLayoutType == XFA_ATTRIBUTEENUM_Row && |
| 911 | m_pDocument->GetCurVersionMode() < XFA_VERSION_208) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 912 | CXFA_Node* pPreviewRow = GetNodeItem(XFA_NODEITEM_PrevSibling, |
| 913 | XFA_ObjectType::ContainerNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 914 | if (pPreviewRow && |
| 915 | pPreviewRow->GetEnum(XFA_ATTRIBUTE_Layout) == |
| 916 | XFA_ATTRIBUTEENUM_Row) { |
| 917 | XFA_ATTRIBUTEENUM eValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 918 | if (pKeep->TryEnum(XFA_ATTRIBUTE_Previous, eValue, false) && |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 919 | (eValue == XFA_ATTRIBUTEENUM_ContentArea || |
| 920 | eValue == XFA_ATTRIBUTEENUM_PageArea)) { |
| 921 | return XFA_ATTRIBUTEENUM_ContentArea; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 922 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 923 | CXFA_Node* pNode = |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 924 | pPreviewRow->GetFirstChildByClass(XFA_Element::Keep); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 925 | if (pNode && pNode->TryEnum(XFA_ATTRIBUTE_Next, eValue, false) && |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 926 | (eValue == XFA_ATTRIBUTEENUM_ContentArea || |
| 927 | eValue == XFA_ATTRIBUTEENUM_PageArea)) { |
| 928 | return XFA_ATTRIBUTEENUM_ContentArea; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 929 | } |
| 930 | } |
| 931 | } |
| 932 | return eIntact; |
| 933 | } |
| 934 | } |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 935 | switch (GetElementType()) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 936 | case XFA_Element::Subform: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 937 | switch (eLayoutType) { |
| 938 | case XFA_ATTRIBUTEENUM_Position: |
| 939 | case XFA_ATTRIBUTEENUM_Row: |
| 940 | return XFA_ATTRIBUTEENUM_ContentArea; |
| 941 | case XFA_ATTRIBUTEENUM_Tb: |
| 942 | case XFA_ATTRIBUTEENUM_Table: |
| 943 | case XFA_ATTRIBUTEENUM_Lr_tb: |
| 944 | case XFA_ATTRIBUTEENUM_Rl_tb: |
| 945 | return XFA_ATTRIBUTEENUM_None; |
| 946 | default: |
| 947 | break; |
| 948 | } |
| 949 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 950 | case XFA_Element::Field: { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 951 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 952 | if (!pParentNode || |
| 953 | pParentNode->GetElementType() == XFA_Element::PageArea) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 954 | return XFA_ATTRIBUTEENUM_ContentArea; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 955 | if (pParentNode->GetIntact() == XFA_ATTRIBUTEENUM_None) { |
| 956 | XFA_ATTRIBUTEENUM eParLayout = |
| 957 | pParentNode->GetEnum(XFA_ATTRIBUTE_Layout); |
| 958 | if (eParLayout == XFA_ATTRIBUTEENUM_Position || |
| 959 | eParLayout == XFA_ATTRIBUTEENUM_Row || |
| 960 | eParLayout == XFA_ATTRIBUTEENUM_Table) { |
| 961 | return XFA_ATTRIBUTEENUM_None; |
| 962 | } |
| 963 | XFA_VERSION version = m_pDocument->GetCurVersionMode(); |
| 964 | if (eParLayout == XFA_ATTRIBUTEENUM_Tb && version < XFA_VERSION_208) { |
| 965 | CXFA_Measurement measureH; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 966 | if (TryMeasure(XFA_ATTRIBUTE_H, measureH, false)) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 967 | return XFA_ATTRIBUTEENUM_ContentArea; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 968 | } |
| 969 | return XFA_ATTRIBUTEENUM_None; |
| 970 | } |
| 971 | return XFA_ATTRIBUTEENUM_ContentArea; |
| 972 | } |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 973 | case XFA_Element::Draw: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 974 | return XFA_ATTRIBUTEENUM_ContentArea; |
| 975 | default: |
| 976 | break; |
| 977 | } |
| 978 | return XFA_ATTRIBUTEENUM_None; |
| 979 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 980 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 981 | CXFA_Node* CXFA_Node::GetDataDescriptionNode() { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 982 | if (m_ePacket == XFA_XDPPACKET_Datasets) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 983 | return m_pAuxNode; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 984 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 985 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 986 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 987 | void CXFA_Node::SetDataDescriptionNode(CXFA_Node* pDataDescriptionNode) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 988 | ASSERT(m_ePacket == XFA_XDPPACKET_Datasets); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 989 | m_pAuxNode = pDataDescriptionNode; |
| 990 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 991 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 992 | void CXFA_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments) { |
| 993 | int32_t iLength = pArguments->GetLength(); |
| 994 | if (iLength != 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 995 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resolveNode"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 996 | return; |
| 997 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 998 | CFX_WideString wsExpression = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 999 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 1000 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1001 | if (!pScriptContext) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1002 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1003 | CXFA_Node* refNode = this; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1004 | if (refNode->GetElementType() == XFA_Element::Xfa) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1005 | refNode = ToNode(pScriptContext->GetThisObject()); |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1006 | uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1007 | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | |
| 1008 | XFA_RESOLVENODE_Siblings; |
| 1009 | XFA_RESOLVENODE_RS resoveNodeRS; |
tsepez | fc58ad1 | 2016-04-05 12:22:15 -0700 | [diff] [blame] | 1010 | int32_t iRet = pScriptContext->ResolveObjects( |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1011 | refNode, wsExpression.AsStringC(), resoveNodeRS, dwFlag); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1012 | if (iRet < 1) { |
| 1013 | pArguments->GetReturnValue()->SetNull(); |
| 1014 | return; |
| 1015 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1016 | if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { |
| 1017 | CXFA_Object* pNode = resoveNodeRS.nodes[0]; |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1018 | pArguments->GetReturnValue()->Assign( |
| 1019 | pScriptContext->GetJSValueFromMap(pNode)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1020 | } else { |
| 1021 | const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = |
| 1022 | resoveNodeRS.pScriptAttribute; |
| 1023 | if (lpAttributeInfo && lpAttributeInfo->eValueType == XFA_SCRIPT_Object) { |
dsinclair | 86fad99 | 2016-05-31 11:34:04 -0700 | [diff] [blame] | 1024 | std::unique_ptr<CFXJSE_Value> pValue( |
| 1025 | new CFXJSE_Value(pScriptContext->GetRuntime())); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1026 | (resoveNodeRS.nodes[0]->*(lpAttributeInfo->lpfnCallback))( |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1027 | pValue.get(), false, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1028 | pArguments->GetReturnValue()->Assign(pValue.get()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1029 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1030 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1031 | } |
| 1032 | } |
| 1033 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1034 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1035 | void CXFA_Node::Script_TreeClass_ResolveNodes(CFXJSE_Arguments* pArguments) { |
| 1036 | int32_t iLength = pArguments->GetLength(); |
| 1037 | if (iLength != 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1038 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resolveNodes"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1039 | return; |
| 1040 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1041 | CFX_WideString wsExpression = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1042 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1043 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1044 | if (!pValue) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1045 | return; |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1046 | uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1047 | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | |
| 1048 | XFA_RESOLVENODE_Siblings; |
| 1049 | CXFA_Node* refNode = this; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1050 | if (refNode->GetElementType() == XFA_Element::Xfa) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1051 | refNode = ToNode(m_pDocument->GetScriptContext()->GetThisObject()); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1052 | Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag, refNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1053 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1054 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1055 | void CXFA_Node::Script_Som_ResolveNodeList(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1056 | CFX_WideString wsExpression, |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1057 | uint32_t dwFlag, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1058 | CXFA_Node* refNode) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 1059 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1060 | if (!pScriptContext) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1061 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1062 | XFA_RESOLVENODE_RS resoveNodeRS; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1063 | if (!refNode) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1064 | refNode = this; |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1065 | pScriptContext->ResolveObjects(refNode, wsExpression.AsStringC(), |
tsepez | fc58ad1 | 2016-04-05 12:22:15 -0700 | [diff] [blame] | 1066 | resoveNodeRS, dwFlag); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1067 | CXFA_ArrayNodeList* pNodeList = new CXFA_ArrayNodeList(m_pDocument); |
| 1068 | if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { |
| 1069 | for (int32_t i = 0; i < resoveNodeRS.nodes.GetSize(); i++) { |
| 1070 | if (resoveNodeRS.nodes[i]->IsNode()) |
| 1071 | pNodeList->Append(resoveNodeRS.nodes[i]->AsNode()); |
| 1072 | } |
| 1073 | } else { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1074 | CXFA_ValueArray valueArray(pScriptContext->GetRuntime()); |
| 1075 | if (resoveNodeRS.GetAttributeResult(valueArray) > 0) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1076 | CXFA_ObjArray objectArray; |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1077 | valueArray.GetAttributeObject(objectArray); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1078 | for (int32_t i = 0; i < objectArray.GetSize(); i++) { |
| 1079 | if (objectArray[i]->IsNode()) |
| 1080 | pNodeList->Append(objectArray[i]->AsNode()); |
| 1081 | } |
| 1082 | } |
| 1083 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1084 | pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1085 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1086 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1087 | void CXFA_Node::Script_TreeClass_All(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1088 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1089 | XFA_ATTRIBUTE eAttribute) { |
| 1090 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1091 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1092 | } else { |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1093 | uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1094 | CFX_WideString wsName; |
| 1095 | GetAttribute(XFA_ATTRIBUTE_Name, wsName); |
| 1096 | CFX_WideString wsExpression = wsName + FX_WSTRC(L"[*]"); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1097 | Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1098 | } |
| 1099 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1100 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1101 | void CXFA_Node::Script_TreeClass_Nodes(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1102 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1103 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 1104 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1105 | if (!pScriptContext) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1106 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1107 | if (bSetting) { |
| 1108 | IXFA_AppProvider* pAppProvider = m_pDocument->GetNotify()->GetAppProvider(); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 1109 | ASSERT(pAppProvider); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1110 | CFX_WideString wsMessage; |
| 1111 | pAppProvider->LoadString(XFA_IDS_Unable_TO_SET, wsMessage); |
tsepez | 28f97ff | 2016-04-04 16:41:35 -0700 | [diff] [blame] | 1112 | FXJSE_ThrowMessage( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 1113 | FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1114 | } else { |
| 1115 | CXFA_AttachNodeList* pNodeList = new CXFA_AttachNodeList(m_pDocument, this); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1116 | pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1117 | } |
| 1118 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1119 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1120 | void CXFA_Node::Script_TreeClass_ClassAll(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1121 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1122 | XFA_ATTRIBUTE eAttribute) { |
| 1123 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1124 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1125 | } else { |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1126 | uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL; |
dsinclair | 017052a | 2016-06-28 07:43:51 -0700 | [diff] [blame] | 1127 | CFX_WideString wsExpression = |
| 1128 | FX_WSTRC(L"#") + GetClassName() + FX_WSTRC(L"[*]"); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1129 | Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1130 | } |
| 1131 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1132 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1133 | void CXFA_Node::Script_TreeClass_Parent(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1134 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1135 | XFA_ATTRIBUTE eAttribute) { |
| 1136 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1137 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1138 | } else { |
| 1139 | CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent); |
| 1140 | if (pParent) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1141 | pValue->Assign( |
| 1142 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pParent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1143 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1144 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1145 | } |
| 1146 | } |
| 1147 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1148 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1149 | void CXFA_Node::Script_TreeClass_Index(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1150 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1151 | XFA_ATTRIBUTE eAttribute) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1152 | if (bSetting) |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1153 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1154 | else |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1155 | pValue->SetInteger(GetNodeSameNameIndex()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1156 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1157 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1158 | void CXFA_Node::Script_TreeClass_ClassIndex(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1159 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1160 | XFA_ATTRIBUTE eAttribute) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1161 | if (bSetting) |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1162 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1163 | else |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1164 | pValue->SetInteger(GetNodeSameClassIndex()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1165 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1166 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1167 | void CXFA_Node::Script_TreeClass_SomExpression(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1168 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1169 | XFA_ATTRIBUTE eAttribute) { |
| 1170 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1171 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1172 | } else { |
| 1173 | CFX_WideString wsSOMExpression; |
| 1174 | GetSOMExpression(wsSOMExpression); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1175 | pValue->SetString(FX_UTF8Encode(wsSOMExpression).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1176 | } |
| 1177 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1178 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1179 | void CXFA_Node::Script_NodeClass_ApplyXSL(CFXJSE_Arguments* pArguments) { |
| 1180 | int32_t iLength = pArguments->GetLength(); |
| 1181 | if (iLength != 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1182 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"applyXSL"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1183 | return; |
| 1184 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1185 | CFX_WideString wsExpression = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1186 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1187 | // TODO(weili): check whether we need to implement this, pdfium:501. |
| 1188 | // For now, just put the variables here to avoid unused variable warning. |
| 1189 | (void)wsExpression; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1190 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1191 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1192 | void CXFA_Node::Script_NodeClass_AssignNode(CFXJSE_Arguments* pArguments) { |
| 1193 | int32_t iLength = pArguments->GetLength(); |
| 1194 | if (iLength < 1 || iLength > 3) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1195 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"assignNode"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1196 | return; |
| 1197 | } |
| 1198 | CFX_WideString wsExpression; |
| 1199 | CFX_WideString wsValue; |
| 1200 | int32_t iAction = 0; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1201 | wsExpression = |
| 1202 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1203 | if (iLength >= 2) { |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1204 | wsValue = |
| 1205 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1206 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1207 | if (iLength >= 3) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1208 | iAction = pArguments->GetInt32(2); |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1209 | // TODO(weili): check whether we need to implement this, pdfium:501. |
| 1210 | // For now, just put the variables here to avoid unused variable warning. |
| 1211 | (void)wsExpression; |
| 1212 | (void)wsValue; |
| 1213 | (void)iAction; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1214 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1215 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1216 | void CXFA_Node::Script_NodeClass_Clone(CFXJSE_Arguments* pArguments) { |
| 1217 | int32_t iLength = pArguments->GetLength(); |
| 1218 | if (iLength != 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1219 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"clone"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1220 | return; |
| 1221 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1222 | bool bClone = !!pArguments->GetInt32(0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1223 | CXFA_Node* pCloneNode = Clone(bClone); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1224 | pArguments->GetReturnValue()->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1225 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pCloneNode)); |
| 1226 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1227 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1228 | void CXFA_Node::Script_NodeClass_GetAttribute(CFXJSE_Arguments* pArguments) { |
| 1229 | int32_t iLength = pArguments->GetLength(); |
| 1230 | if (iLength != 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1231 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getAttribute"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1232 | return; |
| 1233 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1234 | CFX_WideString wsExpression = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1235 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1236 | CFX_WideString wsValue; |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1237 | GetAttribute(wsExpression.AsStringC(), wsValue); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1238 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1239 | if (pValue) |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1240 | pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1241 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1242 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1243 | void CXFA_Node::Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments) { |
| 1244 | int32_t iLength = pArguments->GetLength(); |
| 1245 | if (iLength < 1 || iLength > 2) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1246 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getElement"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1247 | return; |
| 1248 | } |
| 1249 | CFX_WideString wsExpression; |
| 1250 | int32_t iValue = 0; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1251 | wsExpression = |
| 1252 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
| 1253 | if (iLength >= 2) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1254 | iValue = pArguments->GetInt32(1); |
dsinclair | 6e12478 | 2016-06-23 12:14:55 -0700 | [diff] [blame] | 1255 | CXFA_Node* pNode = |
| 1256 | GetProperty(iValue, XFA_GetElementTypeForName(wsExpression.AsStringC())); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1257 | pArguments->GetReturnValue()->Assign( |
| 1258 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1259 | } |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1260 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1261 | void CXFA_Node::Script_NodeClass_IsPropertySpecified( |
| 1262 | CFXJSE_Arguments* pArguments) { |
| 1263 | int32_t iLength = pArguments->GetLength(); |
| 1264 | if (iLength < 1 || iLength > 3) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1265 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isPropertySpecified"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1266 | return; |
| 1267 | } |
| 1268 | CFX_WideString wsExpression; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1269 | bool bParent = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1270 | int32_t iIndex = 0; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1271 | wsExpression = |
| 1272 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1273 | if (iLength >= 2) |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1274 | bParent = !!pArguments->GetInt32(1); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1275 | if (iLength >= 3) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1276 | iIndex = pArguments->GetInt32(2); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1277 | bool bHas = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1278 | const XFA_ATTRIBUTEINFO* pAttributeInfo = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1279 | XFA_GetAttributeByName(wsExpression.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1280 | CFX_WideString wsValue; |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1281 | if (pAttributeInfo) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1282 | bHas = HasAttribute(pAttributeInfo->eName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1283 | if (!bHas) { |
dsinclair | 6e12478 | 2016-06-23 12:14:55 -0700 | [diff] [blame] | 1284 | XFA_Element eType = XFA_GetElementTypeForName(wsExpression.AsStringC()); |
| 1285 | bHas = !!GetProperty(iIndex, eType); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1286 | if (!bHas && bParent && m_pParent) { |
| 1287 | // Also check on the parent. |
| 1288 | bHas = m_pParent->HasAttribute(pAttributeInfo->eName); |
| 1289 | if (!bHas) |
dsinclair | 6e12478 | 2016-06-23 12:14:55 -0700 | [diff] [blame] | 1290 | bHas = !!m_pParent->GetProperty(iIndex, eType); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1291 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1292 | } |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1293 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
| 1294 | if (pValue) |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1295 | pValue->SetBoolean(bHas); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1296 | } |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1297 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1298 | void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) { |
| 1299 | int32_t iLength = pArguments->GetLength(); |
| 1300 | if (iLength < 1 || iLength > 3) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1301 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"loadXML"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1302 | return; |
| 1303 | } |
| 1304 | CFX_WideString wsExpression; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1305 | bool bIgnoreRoot = true; |
| 1306 | bool bOverwrite = 0; |
| 1307 | wsExpression = |
| 1308 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
| 1309 | if (wsExpression.IsEmpty()) |
Tom Sepez | d3743ea | 2016-05-16 15:56:53 -0700 | [diff] [blame] | 1310 | return; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1311 | if (iLength >= 2) |
| 1312 | bIgnoreRoot = !!pArguments->GetInt32(1); |
| 1313 | if (iLength >= 3) |
| 1314 | bOverwrite = !!pArguments->GetInt32(2); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 1315 | std::unique_ptr<CXFA_SimpleParser> pParser( |
| 1316 | new CXFA_SimpleParser(m_pDocument, false)); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1317 | if (!pParser) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1318 | return; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1319 | CFDE_XMLNode* pXMLNode = nullptr; |
| 1320 | int32_t iParserStatus = |
| 1321 | pParser->ParseXMLData(wsExpression, pXMLNode, nullptr); |
| 1322 | if (iParserStatus != XFA_PARSESTATUS_Done || !pXMLNode) |
| 1323 | return; |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1324 | if (bIgnoreRoot && |
| 1325 | (pXMLNode->GetType() != FDE_XMLNODE_Element || |
| 1326 | XFA_RecognizeRichText(static_cast<CFDE_XMLElement*>(pXMLNode)))) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1327 | bIgnoreRoot = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1328 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1329 | CXFA_Node* pFakeRoot = Clone(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1330 | CFX_WideStringC wsContentType = GetCData(XFA_ATTRIBUTE_ContentType); |
| 1331 | if (!wsContentType.IsEmpty()) { |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 1332 | pFakeRoot->SetCData(XFA_ATTRIBUTE_ContentType, |
| 1333 | CFX_WideString(wsContentType)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1334 | } |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1335 | CFDE_XMLNode* pFakeXMLRoot = pFakeRoot->GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1336 | if (!pFakeXMLRoot) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1337 | CFDE_XMLNode* pThisXMLRoot = GetXMLMappingNode(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1338 | pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone(false) : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1339 | } |
dsinclair | 017052a | 2016-06-28 07:43:51 -0700 | [diff] [blame] | 1340 | if (!pFakeXMLRoot) |
| 1341 | pFakeXMLRoot = new CFDE_XMLElement(CFX_WideString(GetClassName())); |
| 1342 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1343 | if (bIgnoreRoot) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1344 | CFDE_XMLNode* pXMLChild = pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1345 | while (pXMLChild) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1346 | CFDE_XMLNode* pXMLSibling = |
| 1347 | pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1348 | pXMLNode->RemoveChildNode(pXMLChild); |
| 1349 | pFakeXMLRoot->InsertChildNode(pXMLChild); |
| 1350 | pXMLChild = pXMLSibling; |
| 1351 | } |
| 1352 | } else { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1353 | CFDE_XMLNode* pXMLParent = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1354 | if (pXMLParent) { |
| 1355 | pXMLParent->RemoveChildNode(pXMLNode); |
| 1356 | } |
| 1357 | pFakeXMLRoot->InsertChildNode(pXMLNode); |
| 1358 | } |
| 1359 | pParser->ConstructXFANode(pFakeRoot, pFakeXMLRoot); |
| 1360 | pFakeRoot = pParser->GetRootNode(); |
| 1361 | if (pFakeRoot) { |
| 1362 | if (bOverwrite) { |
| 1363 | CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1364 | CXFA_Node* pNewChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1365 | int32_t index = 0; |
| 1366 | while (pNewChild) { |
| 1367 | CXFA_Node* pItem = pNewChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1368 | pFakeRoot->RemoveChild(pNewChild); |
| 1369 | InsertChild(index++, pNewChild); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 1370 | pNewChild->SetFlag(XFA_NodeFlag_Initialized, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1371 | pNewChild = pItem; |
| 1372 | } |
| 1373 | while (pChild) { |
| 1374 | CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1375 | RemoveChild(pChild); |
| 1376 | pFakeRoot->InsertChild(pChild); |
| 1377 | pChild = pItem; |
| 1378 | } |
| 1379 | if (GetPacketID() == XFA_XDPPACKET_Form && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1380 | GetElementType() == XFA_Element::ExData) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1381 | CFDE_XMLNode* pTempXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1382 | SetXMLMappingNode(pFakeXMLRoot); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 1383 | SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1384 | if (pTempXMLNode && !pTempXMLNode->GetNodeItem(CFDE_XMLNode::Parent)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1385 | pFakeXMLRoot = pTempXMLNode; |
| 1386 | } else { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1387 | pFakeXMLRoot = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1388 | } |
| 1389 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1390 | MoveBufferMapData(pFakeRoot, this, XFA_CalcData, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1391 | } else { |
| 1392 | CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1393 | while (pChild) { |
| 1394 | CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1395 | pFakeRoot->RemoveChild(pChild); |
| 1396 | InsertChild(pChild); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 1397 | pChild->SetFlag(XFA_NodeFlag_Initialized, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1398 | pChild = pItem; |
| 1399 | } |
| 1400 | } |
| 1401 | if (pFakeXMLRoot) { |
| 1402 | pFakeRoot->SetXMLMappingNode(pFakeXMLRoot); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 1403 | pFakeRoot->SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1404 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 1405 | pFakeRoot->SetFlag(XFA_NodeFlag_HasRemovedChildren, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1406 | } else { |
Tom Sepez | d3743ea | 2016-05-16 15:56:53 -0700 | [diff] [blame] | 1407 | if (pFakeXMLRoot) { |
| 1408 | pFakeXMLRoot->Release(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1409 | pFakeXMLRoot = nullptr; |
Tom Sepez | d3743ea | 2016-05-16 15:56:53 -0700 | [diff] [blame] | 1410 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1411 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1412 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1413 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1414 | void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1415 | // TODO(weili): Check whether we need to implement this, pdfium:501. |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) { |
| 1419 | int32_t iLength = pArguments->GetLength(); |
| 1420 | if (iLength < 0 || iLength > 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1421 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"saveXML"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1422 | return; |
| 1423 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1424 | bool bPrettyMode = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1425 | if (iLength == 1) { |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1426 | if (pArguments->GetUTF8String(0) != "pretty") { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1427 | ThrowException(XFA_IDS_ARGUMENT_MISMATCH); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1428 | return; |
| 1429 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1430 | bPrettyMode = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1431 | } |
| 1432 | CFX_ByteStringC bsXMLHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1433 | if (GetPacketID() == XFA_XDPPACKET_Form || |
| 1434 | GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 1435 | CFDE_XMLNode* pElement = nullptr; |
| 1436 | if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 1437 | pElement = GetXMLMappingNode(); |
| 1438 | if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1439 | pArguments->GetReturnValue()->SetString(bsXMLHeader); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1440 | return; |
| 1441 | } |
| 1442 | XFA_DataExporter_DealWithDataGroupNode(this); |
| 1443 | } |
tsepez | 833619b | 2016-12-07 09:21:17 -0800 | [diff] [blame^] | 1444 | CFX_RetainPtr<IFX_MemoryStream> pMemoryStream = |
| 1445 | IFX_MemoryStream::Create(true); |
| 1446 | |
| 1447 | // Note: ambiguious below without static_cast. |
tsepez | 0527ec5 | 2016-12-02 10:53:30 -0800 | [diff] [blame] | 1448 | std::unique_ptr<IFGAS_Stream, ReleaseDeleter<IFGAS_Stream>> pStream( |
| 1449 | IFGAS_Stream::CreateStream( |
tsepez | 833619b | 2016-12-07 09:21:17 -0800 | [diff] [blame^] | 1450 | CFX_RetainPtr<IFX_SeekableWriteStream>(pMemoryStream), |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1451 | FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | |
| 1452 | FX_STREAMACCESS_Append)); |
tsepez | 833619b | 2016-12-07 09:21:17 -0800 | [diff] [blame^] | 1453 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1454 | if (!pStream) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1455 | pArguments->GetReturnValue()->SetString(bsXMLHeader); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1456 | return; |
| 1457 | } |
| 1458 | pStream->SetCodePage(FX_CODEPAGE_UTF8); |
dsinclair | 179bebb | 2016-04-05 11:02:18 -0700 | [diff] [blame] | 1459 | pStream->WriteData(bsXMLHeader.raw_str(), bsXMLHeader.GetLength()); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1460 | if (GetPacketID() == XFA_XDPPACKET_Form) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1461 | XFA_DataExporter_RegenerateFormFile(this, pStream.get(), nullptr, true); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1462 | else |
| 1463 | pElement->SaveXMLNode(pStream.get()); |
| 1464 | // TODO(weili): Check whether we need to save pretty print XML, pdfium:501. |
| 1465 | // For now, just put it here to avoid unused variable warning. |
| 1466 | (void)bPrettyMode; |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1467 | pArguments->GetReturnValue()->SetString( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1468 | CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize())); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1469 | return; |
| 1470 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1471 | pArguments->GetReturnValue()->SetString(""); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1472 | } |
| 1473 | |
| 1474 | void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) { |
| 1475 | int32_t iLength = pArguments->GetLength(); |
| 1476 | if (iLength != 2) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1477 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setAttribute"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1478 | return; |
| 1479 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1480 | CFX_WideString wsAttributeValue = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1481 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1482 | CFX_WideString wsAttribute = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1483 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC()); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1484 | SetAttribute(wsAttribute.AsStringC(), wsAttributeValue.AsStringC(), true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1485 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1486 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1487 | void CXFA_Node::Script_NodeClass_SetElement(CFXJSE_Arguments* pArguments) { |
| 1488 | int32_t iLength = pArguments->GetLength(); |
| 1489 | if (iLength != 1 && iLength != 2) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1490 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setElement"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1491 | return; |
| 1492 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1493 | CXFA_Node* pNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1494 | CFX_WideString wsName; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1495 | pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); |
| 1496 | if (iLength == 2) |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1497 | wsName = CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC()); |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1498 | // TODO(weili): check whether we need to implement this, pdfium:501. |
| 1499 | // For now, just put the variables here to avoid unused variable warning. |
| 1500 | (void)pNode; |
| 1501 | (void)wsName; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1502 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1503 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1504 | void CXFA_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1505 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1506 | XFA_ATTRIBUTE eAttribute) { |
| 1507 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1508 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1509 | } else { |
| 1510 | CFX_WideString wsNameSpace; |
| 1511 | TryNamespace(wsNameSpace); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1512 | pValue->SetString(FX_UTF8Encode(wsNameSpace).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1513 | } |
| 1514 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1515 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1516 | void CXFA_Node::Script_NodeClass_Model(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1517 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1518 | XFA_ATTRIBUTE eAttribute) { |
| 1519 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1520 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1521 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1522 | pValue->Assign( |
| 1523 | m_pDocument->GetScriptContext()->GetJSValueFromMap(GetModelNode())); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1524 | } |
| 1525 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1526 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1527 | void CXFA_Node::Script_NodeClass_IsContainer(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1528 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1529 | XFA_ATTRIBUTE eAttribute) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1530 | if (bSetting) |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1531 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1532 | else |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1533 | pValue->SetBoolean(IsContainerNode()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1534 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1535 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1536 | void CXFA_Node::Script_NodeClass_IsNull(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1537 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1538 | XFA_ATTRIBUTE eAttribute) { |
| 1539 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1540 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1541 | } else { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1542 | if (GetElementType() == XFA_Element::Subform) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1543 | pValue->SetBoolean(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1544 | return; |
| 1545 | } |
| 1546 | CFX_WideString strValue; |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1547 | pValue->SetBoolean(!TryContent(strValue) || strValue.IsEmpty()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1548 | } |
| 1549 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1550 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1551 | void CXFA_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1552 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1553 | XFA_ATTRIBUTE eAttribute) { |
| 1554 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1555 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1556 | } else { |
| 1557 | CXFA_NodeArray properts; |
| 1558 | int32_t iSize = GetNodeList(properts, XFA_NODEFILTER_OneOfProperty); |
| 1559 | if (iSize > 0) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1560 | pValue->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1561 | m_pDocument->GetScriptContext()->GetJSValueFromMap(properts[0])); |
| 1562 | } |
| 1563 | } |
| 1564 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1565 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1566 | void CXFA_Node::Script_ContainerClass_GetDelta(CFXJSE_Arguments* pArguments) {} |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1567 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1568 | void CXFA_Node::Script_ContainerClass_GetDeltas(CFXJSE_Arguments* pArguments) { |
| 1569 | CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1570 | pArguments->GetReturnValue()->SetObject( |
| 1571 | pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1572 | } |
| 1573 | void CXFA_Node::Script_ModelClass_ClearErrorList(CFXJSE_Arguments* pArguments) { |
| 1574 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1575 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1576 | void CXFA_Node::Script_ModelClass_CreateNode(CFXJSE_Arguments* pArguments) { |
| 1577 | Script_Template_CreateNode(pArguments); |
| 1578 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1579 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1580 | void CXFA_Node::Script_ModelClass_IsCompatibleNS(CFXJSE_Arguments* pArguments) { |
| 1581 | int32_t iLength = pArguments->GetLength(); |
| 1582 | if (iLength < 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1583 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isCompatibleNS"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1584 | return; |
| 1585 | } |
| 1586 | CFX_WideString wsNameSpace; |
| 1587 | if (iLength >= 1) { |
| 1588 | CFX_ByteString bsNameSpace = pArguments->GetUTF8String(0); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1589 | wsNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1590 | } |
| 1591 | CFX_WideString wsNodeNameSpace; |
| 1592 | TryNamespace(wsNodeNameSpace); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1593 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1594 | if (pValue) |
| 1595 | pValue->SetBoolean(wsNodeNameSpace == wsNameSpace); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1596 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1597 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1598 | void CXFA_Node::Script_ModelClass_Context(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1599 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1600 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1601 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1602 | void CXFA_Node::Script_ModelClass_AliasNode(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1603 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1604 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1605 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1606 | void CXFA_Node::Script_Attribute_Integer(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1607 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1608 | XFA_ATTRIBUTE eAttribute) { |
| 1609 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1610 | SetInteger(eAttribute, pValue->ToInteger(), true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1611 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1612 | pValue->SetInteger(GetInteger(eAttribute)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1613 | } |
| 1614 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1615 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1616 | void CXFA_Node::Script_Attribute_IntegerRead(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1617 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1618 | XFA_ATTRIBUTE eAttribute) { |
| 1619 | if (!bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1620 | pValue->SetInteger(GetInteger(eAttribute)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1621 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1622 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1623 | } |
| 1624 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1625 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1626 | void CXFA_Node::Script_Attribute_BOOL(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1627 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1628 | XFA_ATTRIBUTE eAttribute) { |
| 1629 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1630 | SetBoolean(eAttribute, pValue->ToBoolean(), true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1631 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1632 | pValue->SetString(GetBoolean(eAttribute) ? "1" : "0"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1633 | } |
| 1634 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1635 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1636 | void CXFA_Node::Script_Attribute_BOOLRead(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1637 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1638 | XFA_ATTRIBUTE eAttribute) { |
| 1639 | if (!bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1640 | pValue->SetString(GetBoolean(eAttribute) ? "1" : "0"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1641 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1642 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1643 | } |
| 1644 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1645 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1646 | void CXFA_Node::Script_Attribute_SendAttributeChangeMessage( |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1647 | XFA_ATTRIBUTE eAttribute, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1648 | bool bScriptModify) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1649 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1650 | if (!pLayoutPro) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1651 | return; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1652 | |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 1653 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1654 | if (!pNotify) |
| 1655 | return; |
| 1656 | |
| 1657 | uint32_t dwPacket = GetPacketID(); |
| 1658 | if (!(dwPacket & XFA_XDPPACKET_Form)) { |
| 1659 | pNotify->OnValueChanged(this, eAttribute, this, this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1660 | return; |
| 1661 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1662 | |
| 1663 | bool bNeedFindContainer = false; |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1664 | switch (GetElementType()) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1665 | case XFA_Element::Caption: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1666 | bNeedFindContainer = true; |
| 1667 | pNotify->OnValueChanged(this, eAttribute, this, |
| 1668 | GetNodeItem(XFA_NODEITEM_Parent)); |
| 1669 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1670 | case XFA_Element::Font: |
| 1671 | case XFA_Element::Para: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1672 | bNeedFindContainer = true; |
| 1673 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1674 | if (pParentNode->GetElementType() == XFA_Element::Caption) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1675 | pNotify->OnValueChanged(this, eAttribute, pParentNode, |
| 1676 | pParentNode->GetNodeItem(XFA_NODEITEM_Parent)); |
| 1677 | } else { |
| 1678 | pNotify->OnValueChanged(this, eAttribute, this, pParentNode); |
| 1679 | } |
| 1680 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1681 | case XFA_Element::Margin: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1682 | bNeedFindContainer = true; |
| 1683 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1684 | XFA_Element eParentType = pParentNode->GetElementType(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1685 | if (pParentNode->IsContainerNode()) { |
| 1686 | pNotify->OnValueChanged(this, eAttribute, this, pParentNode); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1687 | } else if (eParentType == XFA_Element::Caption) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1688 | pNotify->OnValueChanged(this, eAttribute, pParentNode, |
| 1689 | pParentNode->GetNodeItem(XFA_NODEITEM_Parent)); |
| 1690 | } else { |
| 1691 | CXFA_Node* pNode = pParentNode->GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1692 | if (pNode && pNode->GetElementType() == XFA_Element::Ui) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1693 | pNotify->OnValueChanged(this, eAttribute, pNode, |
| 1694 | pNode->GetNodeItem(XFA_NODEITEM_Parent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1695 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1696 | } |
| 1697 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1698 | case XFA_Element::Comb: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1699 | CXFA_Node* pEditNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1700 | XFA_Element eUIType = pEditNode->GetElementType(); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1701 | if (pEditNode && (eUIType == XFA_Element::DateTimeEdit || |
| 1702 | eUIType == XFA_Element::NumericEdit || |
| 1703 | eUIType == XFA_Element::TextEdit)) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1704 | CXFA_Node* pUINode = pEditNode->GetNodeItem(XFA_NODEITEM_Parent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1705 | if (pUINode) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1706 | pNotify->OnValueChanged(this, eAttribute, pUINode, |
| 1707 | pUINode->GetNodeItem(XFA_NODEITEM_Parent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1708 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1709 | } |
| 1710 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1711 | case XFA_Element::Button: |
| 1712 | case XFA_Element::Barcode: |
| 1713 | case XFA_Element::ChoiceList: |
| 1714 | case XFA_Element::DateTimeEdit: |
| 1715 | case XFA_Element::NumericEdit: |
| 1716 | case XFA_Element::PasswordEdit: |
| 1717 | case XFA_Element::TextEdit: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1718 | CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent); |
| 1719 | if (pUINode) { |
| 1720 | pNotify->OnValueChanged(this, eAttribute, pUINode, |
| 1721 | pUINode->GetNodeItem(XFA_NODEITEM_Parent)); |
| 1722 | } |
| 1723 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1724 | case XFA_Element::CheckButton: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1725 | bNeedFindContainer = true; |
| 1726 | CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent); |
| 1727 | if (pUINode) { |
| 1728 | pNotify->OnValueChanged(this, eAttribute, pUINode, |
| 1729 | pUINode->GetNodeItem(XFA_NODEITEM_Parent)); |
| 1730 | } |
| 1731 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1732 | case XFA_Element::Keep: |
| 1733 | case XFA_Element::Bookend: |
| 1734 | case XFA_Element::Break: |
| 1735 | case XFA_Element::BreakAfter: |
| 1736 | case XFA_Element::BreakBefore: |
| 1737 | case XFA_Element::Overflow: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1738 | bNeedFindContainer = true; |
| 1739 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1740 | case XFA_Element::Area: |
| 1741 | case XFA_Element::Draw: |
| 1742 | case XFA_Element::ExclGroup: |
| 1743 | case XFA_Element::Field: |
| 1744 | case XFA_Element::Subform: |
| 1745 | case XFA_Element::SubformSet: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1746 | pLayoutPro->AddChangedContainer(this); |
| 1747 | pNotify->OnValueChanged(this, eAttribute, this, this); |
| 1748 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1749 | case XFA_Element::Sharptext: |
| 1750 | case XFA_Element::Sharpxml: |
| 1751 | case XFA_Element::SharpxHTML: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1752 | CXFA_Node* pTextNode = GetNodeItem(XFA_NODEITEM_Parent); |
| 1753 | if (!pTextNode) { |
| 1754 | return; |
| 1755 | } |
| 1756 | CXFA_Node* pValueNode = pTextNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 1757 | if (!pValueNode) { |
| 1758 | return; |
| 1759 | } |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1760 | XFA_Element eType = pValueNode->GetElementType(); |
| 1761 | if (eType == XFA_Element::Value) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1762 | bNeedFindContainer = true; |
| 1763 | CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 1764 | if (pNode && pNode->IsContainerNode()) { |
| 1765 | if (bScriptModify) { |
| 1766 | pValueNode = pNode; |
| 1767 | } |
| 1768 | pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode); |
| 1769 | } else { |
| 1770 | pNotify->OnValueChanged(this, eAttribute, pNode, |
| 1771 | pNode->GetNodeItem(XFA_NODEITEM_Parent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1772 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1773 | } else { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1774 | if (eType == XFA_Element::Items) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1775 | CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 1776 | if (pNode && pNode->IsContainerNode()) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1777 | pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1778 | } |
| 1779 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1780 | } |
| 1781 | } break; |
| 1782 | default: |
| 1783 | break; |
| 1784 | } |
| 1785 | if (bNeedFindContainer) { |
| 1786 | CXFA_Node* pParent = this; |
| 1787 | while (pParent) { |
| 1788 | if (pParent->IsContainerNode()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1789 | break; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1790 | |
| 1791 | pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1792 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1793 | if (pParent) { |
| 1794 | pLayoutPro->AddChangedContainer(pParent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1795 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1796 | } |
| 1797 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1798 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1799 | void CXFA_Node::Script_Attribute_String(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1800 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1801 | XFA_ATTRIBUTE eAttribute) { |
| 1802 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1803 | CFX_WideString wsValue = pValue->ToWideString(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1804 | SetAttribute(eAttribute, wsValue.AsStringC(), true); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1805 | if (eAttribute == XFA_ATTRIBUTE_Use && |
| 1806 | GetElementType() == XFA_Element::Desc) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1807 | CXFA_Node* pTemplateNode = |
| 1808 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template)); |
| 1809 | CXFA_Node* pProtoRoot = |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1810 | pTemplateNode->GetFirstChildByClass(XFA_Element::Subform) |
| 1811 | ->GetFirstChildByClass(XFA_Element::Proto); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1812 | |
| 1813 | CFX_WideString wsID; |
| 1814 | CFX_WideString wsSOM; |
| 1815 | if (!wsValue.IsEmpty()) { |
| 1816 | if (wsValue[0] == '#') { |
| 1817 | wsID = CFX_WideString(wsValue.c_str() + 1, wsValue.GetLength() - 1); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1818 | } else { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1819 | wsSOM = wsValue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1820 | } |
| 1821 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1822 | CXFA_Node* pProtoNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1823 | if (!wsSOM.IsEmpty()) { |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1824 | uint32_t dwFlag = XFA_RESOLVENODE_Children | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1825 | XFA_RESOLVENODE_Attributes | |
| 1826 | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | |
| 1827 | XFA_RESOLVENODE_Siblings; |
| 1828 | XFA_RESOLVENODE_RS resoveNodeRS; |
| 1829 | int32_t iRet = m_pDocument->GetScriptContext()->ResolveObjects( |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1830 | pProtoRoot, wsSOM.AsStringC(), resoveNodeRS, dwFlag); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1831 | if (iRet > 0 && resoveNodeRS.nodes[0]->IsNode()) { |
| 1832 | pProtoNode = resoveNodeRS.nodes[0]->AsNode(); |
| 1833 | } |
| 1834 | } else if (!wsID.IsEmpty()) { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1835 | pProtoNode = m_pDocument->GetNodeByID(pProtoRoot, wsID.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1836 | } |
| 1837 | if (pProtoNode) { |
| 1838 | CXFA_Node* pHeadChild = GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1839 | while (pHeadChild) { |
| 1840 | CXFA_Node* pSibling = |
| 1841 | pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1842 | RemoveChild(pHeadChild); |
| 1843 | pHeadChild = pSibling; |
| 1844 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1845 | CXFA_Node* pProtoForm = pProtoNode->CloneTemplateToForm(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1846 | pHeadChild = pProtoForm->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1847 | while (pHeadChild) { |
| 1848 | CXFA_Node* pSibling = |
| 1849 | pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1850 | pProtoForm->RemoveChild(pHeadChild); |
| 1851 | InsertChild(pHeadChild); |
| 1852 | pHeadChild = pSibling; |
| 1853 | } |
| 1854 | m_pDocument->RemovePurgeNode(pProtoForm); |
| 1855 | delete pProtoForm; |
| 1856 | } |
| 1857 | } |
| 1858 | } else { |
| 1859 | CFX_WideString wsValue; |
| 1860 | GetAttribute(eAttribute, wsValue); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1861 | pValue->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 1862 | FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1863 | } |
| 1864 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1865 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1866 | void CXFA_Node::Script_Attribute_StringRead(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1867 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1868 | XFA_ATTRIBUTE eAttribute) { |
| 1869 | if (!bSetting) { |
| 1870 | CFX_WideString wsValue; |
| 1871 | GetAttribute(eAttribute, wsValue); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1872 | pValue->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 1873 | FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1874 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1875 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1876 | } |
| 1877 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1878 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1879 | void CXFA_Node::Script_WsdlConnection_Execute(CFXJSE_Arguments* pArguments) { |
| 1880 | int32_t argc = pArguments->GetLength(); |
| 1881 | if ((argc == 0) || (argc == 1)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1882 | pArguments->GetReturnValue()->SetBoolean(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1883 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1884 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execute"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1885 | } |
| 1886 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1887 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1888 | void CXFA_Node::Script_Delta_Restore(CFXJSE_Arguments* pArguments) { |
| 1889 | int32_t argc = pArguments->GetLength(); |
| 1890 | if (argc == 0) { |
| 1891 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1892 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"restore"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1893 | } |
| 1894 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1895 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1896 | void CXFA_Node::Script_Delta_CurrentValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1897 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1898 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1899 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1900 | void CXFA_Node::Script_Delta_SavedValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1901 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1902 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1903 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1904 | void CXFA_Node::Script_Delta_Target(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1905 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1906 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1907 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1908 | void CXFA_Node::Script_Som_Message(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1909 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1910 | XFA_SOM_MESSAGETYPE iMessageType) { |
| 1911 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 1912 | if (!pWidgetData) { |
| 1913 | return; |
| 1914 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1915 | bool bNew = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1916 | CXFA_Validate validate = pWidgetData->GetValidate(); |
| 1917 | if (!validate) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1918 | validate = pWidgetData->GetValidate(true); |
| 1919 | bNew = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1920 | } |
| 1921 | if (bSetting) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1922 | switch (iMessageType) { |
| 1923 | case XFA_SOM_ValidationMessage: |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1924 | validate.SetScriptMessageText(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1925 | break; |
| 1926 | case XFA_SOM_FormatMessage: |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1927 | validate.SetFormatMessageText(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1928 | break; |
| 1929 | case XFA_SOM_MandatoryMessage: |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1930 | validate.SetNullMessageText(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1931 | break; |
| 1932 | default: |
| 1933 | break; |
| 1934 | } |
| 1935 | if (!bNew) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 1936 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1937 | if (!pNotify) { |
| 1938 | return; |
| 1939 | } |
| 1940 | pNotify->AddCalcValidate(this); |
| 1941 | } |
| 1942 | } else { |
| 1943 | CFX_WideString wsMessage; |
| 1944 | switch (iMessageType) { |
| 1945 | case XFA_SOM_ValidationMessage: |
| 1946 | validate.GetScriptMessageText(wsMessage); |
| 1947 | break; |
| 1948 | case XFA_SOM_FormatMessage: |
| 1949 | validate.GetFormatMessageText(wsMessage); |
| 1950 | break; |
| 1951 | case XFA_SOM_MandatoryMessage: |
| 1952 | validate.GetNullMessageText(wsMessage); |
| 1953 | break; |
| 1954 | default: |
| 1955 | break; |
| 1956 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1957 | pValue->SetString(FX_UTF8Encode(wsMessage).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1958 | } |
| 1959 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1960 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1961 | void CXFA_Node::Script_Som_ValidationMessage(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1962 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1963 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1964 | Script_Som_Message(pValue, bSetting, XFA_SOM_ValidationMessage); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1965 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1966 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1967 | void CXFA_Node::Script_Field_Length(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1968 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1969 | XFA_ATTRIBUTE eAttribute) { |
| 1970 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1971 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1972 | } else { |
| 1973 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 1974 | if (!pWidgetData) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1975 | pValue->SetInteger(0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1976 | return; |
| 1977 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1978 | pValue->SetInteger(pWidgetData->CountChoiceListItems(true)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1979 | } |
| 1980 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1981 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1982 | void CXFA_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1983 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1984 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1985 | XFA_Element eType = GetElementType(); |
| 1986 | if (eType == XFA_Element::Field) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1987 | Script_Field_DefaultValue(pValue, bSetting, eAttribute); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1988 | return; |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1989 | } |
| 1990 | if (eType == XFA_Element::Draw) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1991 | Script_Draw_DefaultValue(pValue, bSetting, eAttribute); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1992 | return; |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1993 | } |
| 1994 | if (eType == XFA_Element::Boolean) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1995 | Script_Boolean_Value(pValue, bSetting, eAttribute); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1996 | return; |
| 1997 | } |
| 1998 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1999 | CFX_WideString wsNewValue; |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 2000 | if (!(pValue && (pValue->IsNull() || pValue->IsUndefined()))) |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2001 | wsNewValue = pValue->ToWideString(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2002 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2003 | CFX_WideString wsFormatValue(wsNewValue); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 2004 | CXFA_WidgetData* pContainerWidgetData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2005 | if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 2006 | CXFA_NodeArray formNodes; |
| 2007 | GetBindItems(formNodes); |
| 2008 | CFX_WideString wsPicture; |
| 2009 | for (int32_t i = 0; i < formNodes.GetSize(); i++) { |
| 2010 | CXFA_Node* pFormNode = formNodes.GetAt(i); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 2011 | if (!pFormNode || pFormNode->HasRemovedChildren()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2012 | continue; |
| 2013 | } |
| 2014 | pContainerWidgetData = pFormNode->GetContainerWidgetData(); |
| 2015 | if (pContainerWidgetData) { |
| 2016 | pContainerWidgetData->GetPictureContent(wsPicture, |
| 2017 | XFA_VALUEPICTURE_DataBind); |
| 2018 | } |
| 2019 | if (!wsPicture.IsEmpty()) { |
| 2020 | break; |
| 2021 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 2022 | pContainerWidgetData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2023 | } |
| 2024 | } else if (GetPacketID() == XFA_XDPPACKET_Form) { |
| 2025 | pContainerWidgetData = GetContainerWidgetData(); |
| 2026 | } |
| 2027 | if (pContainerWidgetData) { |
tsepez | 6f167c3 | 2016-04-14 15:46:27 -0700 | [diff] [blame] | 2028 | pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2029 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2030 | SetScriptContent(wsNewValue, wsFormatValue, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2031 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2032 | CFX_WideString content = GetScriptContent(true); |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 2033 | if (content.IsEmpty() && eType != XFA_Element::Text && |
| 2034 | eType != XFA_Element::SubmitUrl) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2035 | pValue->SetNull(); |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 2036 | } else if (eType == XFA_Element::Integer) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2037 | pValue->SetInteger(FXSYS_wtoi(content.c_str())); |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 2038 | } else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2039 | CFX_Decimal decimal(content.AsStringC()); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2040 | pValue->SetFloat((FX_FLOAT)(double)decimal); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2041 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2042 | pValue->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 2043 | FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2044 | } |
| 2045 | } |
| 2046 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2047 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2048 | void CXFA_Node::Script_Som_DefaultValue_Read(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2049 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2050 | XFA_ATTRIBUTE eAttribute) { |
| 2051 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2052 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2053 | return; |
| 2054 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2055 | CFX_WideString content = GetScriptContent(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2056 | if (content.IsEmpty()) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2057 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2058 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2059 | pValue->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 2060 | FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2061 | } |
| 2062 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2063 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2064 | void CXFA_Node::Script_Boolean_Value(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2065 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2066 | XFA_ATTRIBUTE eAttribute) { |
| 2067 | if (bSetting) { |
| 2068 | CFX_ByteString newValue; |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 2069 | if (!(pValue && (pValue->IsNull() || pValue->IsUndefined()))) |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2070 | newValue = pValue->ToString(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2071 | |
tsepez | b4c9f3f | 2016-04-13 15:41:21 -0700 | [diff] [blame] | 2072 | int32_t iValue = FXSYS_atoi(newValue.c_str()); |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 2073 | CFX_WideString wsNewValue(iValue == 0 ? L"0" : L"1"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2074 | CFX_WideString wsFormatValue(wsNewValue); |
| 2075 | CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData(); |
| 2076 | if (pContainerWidgetData) { |
tsepez | 6f167c3 | 2016-04-14 15:46:27 -0700 | [diff] [blame] | 2077 | pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2078 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2079 | SetScriptContent(wsNewValue, wsFormatValue, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2080 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2081 | CFX_WideString wsValue = GetScriptContent(true); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2082 | pValue->SetBoolean(wsValue == FX_WSTRC(L"1")); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2083 | } |
| 2084 | } |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2085 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2086 | void CXFA_Node::Script_Som_BorderColor(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2087 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2088 | XFA_ATTRIBUTE eAttribute) { |
| 2089 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2090 | if (!pWidgetData) { |
| 2091 | return; |
| 2092 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2093 | CXFA_Border border = pWidgetData->GetBorder(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2094 | int32_t iSize = border.CountEdges(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2095 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2096 | int32_t r = 0; |
| 2097 | int32_t g = 0; |
| 2098 | int32_t b = 0; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2099 | StrToRGB(pValue->ToWideString(), r, g, b); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2100 | FX_ARGB rgb = ArgbEncode(100, r, g, b); |
| 2101 | for (int32_t i = 0; i < iSize; ++i) { |
| 2102 | CXFA_Edge edge = border.GetEdge(i); |
| 2103 | edge.SetColor(rgb); |
| 2104 | } |
| 2105 | } else { |
| 2106 | CXFA_Edge edge = border.GetEdge(0); |
| 2107 | FX_ARGB color = edge.GetColor(); |
| 2108 | int32_t a, r, g, b; |
| 2109 | ArgbDecode(color, a, r, g, b); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2110 | CFX_WideString strColor; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2111 | strColor.Format(L"%d,%d,%d", r, g, b); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2112 | pValue->SetString(FX_UTF8Encode(strColor).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2113 | } |
| 2114 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2115 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2116 | void CXFA_Node::Script_Som_BorderWidth(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2117 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2118 | XFA_ATTRIBUTE eAttribute) { |
| 2119 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2120 | if (!pWidgetData) { |
| 2121 | return; |
| 2122 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2123 | CXFA_Border border = pWidgetData->GetBorder(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2124 | int32_t iSize = border.CountEdges(); |
| 2125 | CFX_WideString wsThickness; |
| 2126 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2127 | wsThickness = pValue->ToWideString(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2128 | for (int32_t i = 0; i < iSize; ++i) { |
| 2129 | CXFA_Edge edge = border.GetEdge(i); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2130 | CXFA_Measurement thickness(wsThickness.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2131 | edge.SetMSThickness(thickness); |
| 2132 | } |
| 2133 | } else { |
| 2134 | CXFA_Edge edge = border.GetEdge(0); |
| 2135 | CXFA_Measurement thickness = edge.GetMSThickness(); |
| 2136 | thickness.ToString(wsThickness); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2137 | pValue->SetString(FX_UTF8Encode(wsThickness).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2138 | } |
| 2139 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2140 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2141 | void CXFA_Node::Script_Som_FillColor(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2142 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2143 | XFA_ATTRIBUTE eAttribute) { |
| 2144 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2145 | if (!pWidgetData) { |
| 2146 | return; |
| 2147 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2148 | CXFA_Border border = pWidgetData->GetBorder(true); |
| 2149 | CXFA_Fill borderfill = border.GetFill(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2150 | CXFA_Node* pNode = borderfill.GetNode(); |
| 2151 | if (!pNode) { |
| 2152 | return; |
| 2153 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2154 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2155 | int32_t r; |
| 2156 | int32_t g; |
| 2157 | int32_t b; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2158 | StrToRGB(pValue->ToWideString(), r, g, b); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2159 | FX_ARGB color = ArgbEncode(0xff, r, g, b); |
| 2160 | borderfill.SetColor(color); |
| 2161 | } else { |
| 2162 | FX_ARGB color = borderfill.GetColor(); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2163 | int32_t a; |
| 2164 | int32_t r; |
| 2165 | int32_t g; |
| 2166 | int32_t b; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2167 | ArgbDecode(color, a, r, g, b); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2168 | CFX_WideString wsColor; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2169 | wsColor.Format(L"%d,%d,%d", r, g, b); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2170 | pValue->SetString(FX_UTF8Encode(wsColor).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2171 | } |
| 2172 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2173 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2174 | void CXFA_Node::Script_Som_DataNode(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2175 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2176 | XFA_ATTRIBUTE eAttribute) { |
| 2177 | if (!bSetting) { |
| 2178 | CXFA_Node* pDataNode = GetBindData(); |
| 2179 | if (pDataNode) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2180 | pValue->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2181 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pDataNode)); |
| 2182 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2183 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2184 | } |
| 2185 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2186 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2187 | } |
| 2188 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2189 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2190 | void CXFA_Node::Script_Draw_DefaultValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2191 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2192 | XFA_ATTRIBUTE eAttribute) { |
| 2193 | if (bSetting) { |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 2194 | if (pValue && pValue->IsString()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2195 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 2196 | ASSERT(pWidgetData); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 2197 | XFA_Element uiType = pWidgetData->GetUIType(); |
| 2198 | if (uiType == XFA_Element::Text) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2199 | CFX_WideString wsNewValue = pValue->ToWideString(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2200 | CFX_WideString wsFormatValue(wsNewValue); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2201 | SetScriptContent(wsNewValue, wsFormatValue, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2202 | } |
| 2203 | } |
| 2204 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2205 | CFX_WideString content = GetScriptContent(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2206 | if (content.IsEmpty()) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2207 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2208 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2209 | pValue->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 2210 | FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2211 | } |
| 2212 | } |
| 2213 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2214 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2215 | void CXFA_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2216 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2217 | XFA_ATTRIBUTE eAttribute) { |
| 2218 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2219 | if (!pWidgetData) { |
| 2220 | return; |
| 2221 | } |
| 2222 | if (bSetting) { |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 2223 | if (pValue && pValue->IsNull()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2224 | pWidgetData->m_bPreNull = pWidgetData->m_bIsNull; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2225 | pWidgetData->m_bIsNull = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2226 | } else { |
| 2227 | pWidgetData->m_bPreNull = pWidgetData->m_bIsNull; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2228 | pWidgetData->m_bIsNull = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2229 | } |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2230 | CFX_WideString wsNewText; |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 2231 | if (!(pValue && (pValue->IsNull() || pValue->IsUndefined()))) |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2232 | wsNewText = pValue->ToWideString(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2233 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2234 | CXFA_Node* pUIChild = pWidgetData->GetUIChild(); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2235 | if (pUIChild->GetElementType() == XFA_Element::NumericEdit) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2236 | int32_t iLeadDigits = 0; |
| 2237 | int32_t iFracDigits = 0; |
| 2238 | pWidgetData->GetLeadDigits(iLeadDigits); |
| 2239 | pWidgetData->GetFracDigits(iFracDigits); |
dsinclair | 44d054c | 2016-04-06 10:23:46 -0700 | [diff] [blame] | 2240 | wsNewText = |
| 2241 | pWidgetData->NumericLimit(wsNewText, iLeadDigits, iFracDigits); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2242 | } |
| 2243 | CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData(); |
| 2244 | CFX_WideString wsFormatText(wsNewText); |
| 2245 | if (pContainerWidgetData) { |
tsepez | 6f167c3 | 2016-04-14 15:46:27 -0700 | [diff] [blame] | 2246 | pContainerWidgetData->GetFormatDataValue(wsNewText, wsFormatText); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2247 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2248 | SetScriptContent(wsNewText, wsFormatText, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2249 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2250 | CFX_WideString content = GetScriptContent(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2251 | if (content.IsEmpty()) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2252 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2253 | } else { |
| 2254 | CXFA_Node* pUIChild = pWidgetData->GetUIChild(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2255 | CXFA_Value defVal = pWidgetData->GetFormValue(); |
| 2256 | CXFA_Node* pNode = defVal.GetNode()->GetNodeItem(XFA_NODEITEM_FirstChild); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2257 | if (pNode && pNode->GetElementType() == XFA_Element::Decimal) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 2258 | if (pUIChild->GetElementType() == XFA_Element::NumericEdit && |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2259 | (pNode->GetInteger(XFA_ATTRIBUTE_FracDigits) == -1)) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2260 | pValue->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 2261 | FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2262 | } else { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2263 | CFX_Decimal decimal(content.AsStringC()); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2264 | pValue->SetFloat((FX_FLOAT)(double)decimal); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2265 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2266 | } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2267 | pValue->SetInteger(FXSYS_wtoi(content.c_str())); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2268 | } else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2269 | pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? false : true); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2270 | } else if (pNode && pNode->GetElementType() == XFA_Element::Float) { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2271 | CFX_Decimal decimal(content.AsStringC()); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2272 | pValue->SetFloat((FX_FLOAT)(double)decimal); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2273 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2274 | pValue->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 2275 | FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2276 | } |
| 2277 | } |
| 2278 | } |
| 2279 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2280 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2281 | void CXFA_Node::Script_Field_EditValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2282 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2283 | XFA_ATTRIBUTE eAttribute) { |
| 2284 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2285 | if (!pWidgetData) { |
| 2286 | return; |
| 2287 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2288 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2289 | pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Edit); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2290 | } else { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2291 | CFX_WideString wsValue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2292 | pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Edit); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2293 | pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2294 | } |
| 2295 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2296 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2297 | void CXFA_Node::Script_Som_FontColor(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2298 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2299 | XFA_ATTRIBUTE eAttribute) { |
| 2300 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2301 | if (!pWidgetData) { |
| 2302 | return; |
| 2303 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2304 | CXFA_Font font = pWidgetData->GetFont(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2305 | CXFA_Node* pNode = font.GetNode(); |
| 2306 | if (!pNode) { |
| 2307 | return; |
| 2308 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2309 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2310 | int32_t r; |
| 2311 | int32_t g; |
| 2312 | int32_t b; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2313 | StrToRGB(pValue->ToWideString(), r, g, b); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2314 | FX_ARGB color = ArgbEncode(0xff, r, g, b); |
| 2315 | font.SetColor(color); |
| 2316 | } else { |
| 2317 | FX_ARGB color = font.GetColor(); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2318 | int32_t a; |
| 2319 | int32_t r; |
| 2320 | int32_t g; |
| 2321 | int32_t b; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2322 | ArgbDecode(color, a, r, g, b); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2323 | CFX_WideString wsColor; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2324 | wsColor.Format(L"%d,%d,%d", r, g, b); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2325 | pValue->SetString(FX_UTF8Encode(wsColor).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2326 | } |
| 2327 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2328 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2329 | void CXFA_Node::Script_Field_FormatMessage(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2330 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2331 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2332 | Script_Som_Message(pValue, bSetting, XFA_SOM_FormatMessage); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2333 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2334 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2335 | void CXFA_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2336 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2337 | XFA_ATTRIBUTE eAttribute) { |
| 2338 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2339 | if (!pWidgetData) { |
| 2340 | return; |
| 2341 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2342 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2343 | pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Display); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2344 | } else { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2345 | CFX_WideString wsValue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2346 | pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Display); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2347 | pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2348 | } |
| 2349 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2350 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2351 | void CXFA_Node::Script_Som_Mandatory(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2352 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2353 | XFA_ATTRIBUTE eAttribute) { |
| 2354 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2355 | if (!pWidgetData) { |
| 2356 | return; |
| 2357 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2358 | CXFA_Validate validate = pWidgetData->GetValidate(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2359 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2360 | validate.SetNullTest(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2361 | } else { |
| 2362 | int32_t iValue = validate.GetNullTest(); |
| 2363 | const XFA_ATTRIBUTEENUMINFO* pInfo = |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 2364 | GetAttributeEnumByID((XFA_ATTRIBUTEENUM)iValue); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2365 | CFX_WideString wsValue; |
| 2366 | if (pInfo) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2367 | wsValue = pInfo->pName; |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2368 | pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2369 | } |
| 2370 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2371 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2372 | void CXFA_Node::Script_Som_MandatoryMessage(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2373 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2374 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2375 | Script_Som_Message(pValue, bSetting, XFA_SOM_MandatoryMessage); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2376 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2377 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2378 | void CXFA_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2379 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2380 | XFA_ATTRIBUTE eAttribute) { |
| 2381 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2382 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2383 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2384 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2385 | } |
| 2386 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2387 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2388 | void CXFA_Node::Script_Field_SelectedIndex(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2389 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2390 | XFA_ATTRIBUTE eAttribute) { |
| 2391 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2392 | if (!pWidgetData) { |
| 2393 | return; |
| 2394 | } |
| 2395 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2396 | int32_t iIndex = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2397 | if (iIndex == -1) { |
| 2398 | pWidgetData->ClearAllSelections(); |
| 2399 | return; |
| 2400 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2401 | pWidgetData->SetItemState(iIndex, true, true, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2402 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2403 | pValue->SetInteger(pWidgetData->GetSelectedItem()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2404 | } |
| 2405 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2406 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2407 | void CXFA_Node::Script_Field_ClearItems(CFXJSE_Arguments* pArguments) { |
| 2408 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2409 | if (!pWidgetData) { |
| 2410 | return; |
| 2411 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2412 | pWidgetData->DeleteItem(-1, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2413 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2414 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2415 | void CXFA_Node::Script_Field_ExecEvent(CFXJSE_Arguments* pArguments) { |
| 2416 | int32_t argc = pArguments->GetLength(); |
| 2417 | if (argc == 1) { |
| 2418 | CFX_ByteString eventString = pArguments->GetUTF8String(0); |
| 2419 | int32_t iRet = execSingleEventByName( |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2420 | CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(), |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 2421 | XFA_Element::Field); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2422 | if (eventString == "validate") { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2423 | pArguments->GetReturnValue()->SetBoolean( |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2424 | (iRet == XFA_EVENTERROR_Error) ? false : true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2425 | } |
| 2426 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2427 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2428 | } |
| 2429 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2430 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2431 | void CXFA_Node::Script_Field_ExecInitialize(CFXJSE_Arguments* pArguments) { |
| 2432 | int32_t argc = pArguments->GetLength(); |
| 2433 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2434 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2435 | if (!pNotify) { |
| 2436 | return; |
| 2437 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2438 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize, false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2439 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2440 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2441 | } |
| 2442 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2443 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2444 | void CXFA_Node::Script_Field_DeleteItem(CFXJSE_Arguments* pArguments) { |
| 2445 | int32_t iLength = pArguments->GetLength(); |
| 2446 | if (iLength != 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2447 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"deleteItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2448 | return; |
| 2449 | } |
| 2450 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2451 | if (!pWidgetData) { |
| 2452 | return; |
| 2453 | } |
| 2454 | int32_t iIndex = pArguments->GetInt32(0); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2455 | bool bValue = pWidgetData->DeleteItem(iIndex, true, true); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2456 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2457 | if (pValue) |
| 2458 | pValue->SetBoolean(bValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2459 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2460 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2461 | void CXFA_Node::Script_Field_GetSaveItem(CFXJSE_Arguments* pArguments) { |
| 2462 | int32_t iLength = pArguments->GetLength(); |
| 2463 | if (iLength != 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2464 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getSaveItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2465 | return; |
| 2466 | } |
| 2467 | int32_t iIndex = pArguments->GetInt32(0); |
| 2468 | if (iIndex < 0) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2469 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2470 | return; |
| 2471 | } |
| 2472 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2473 | if (!pWidgetData) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2474 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2475 | return; |
| 2476 | } |
| 2477 | CFX_WideString wsValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2478 | bool bHasItem = pWidgetData->GetChoiceListItem(wsValue, iIndex, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2479 | if (bHasItem) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2480 | pArguments->GetReturnValue()->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 2481 | FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2482 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2483 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2484 | } |
| 2485 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2486 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2487 | void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments) { |
| 2488 | int32_t iLength = pArguments->GetLength(); |
| 2489 | if (iLength != 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2490 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"boundItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2491 | return; |
| 2492 | } |
| 2493 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2494 | if (!pWidgetData) { |
| 2495 | return; |
| 2496 | } |
| 2497 | CFX_ByteString bsValue = pArguments->GetUTF8String(0); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2498 | CFX_WideString wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2499 | CFX_WideString wsBoundValue; |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2500 | pWidgetData->GetItemValue(wsValue.AsStringC(), wsBoundValue); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2501 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2502 | if (pValue) |
| 2503 | pValue->SetString(FX_UTF8Encode(wsBoundValue).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2504 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2505 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2506 | void CXFA_Node::Script_Field_GetItemState(CFXJSE_Arguments* pArguments) { |
| 2507 | int32_t iLength = pArguments->GetLength(); |
| 2508 | if (iLength != 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2509 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getItemState"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2510 | return; |
| 2511 | } |
| 2512 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2513 | if (!pWidgetData) { |
| 2514 | return; |
| 2515 | } |
| 2516 | int32_t iIndex = pArguments->GetInt32(0); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2517 | bool bValue = pWidgetData->GetItemState(iIndex); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2518 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2519 | if (pValue) |
| 2520 | pValue->SetBoolean(bValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2521 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2522 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2523 | void CXFA_Node::Script_Field_ExecCalculate(CFXJSE_Arguments* pArguments) { |
| 2524 | int32_t argc = pArguments->GetLength(); |
| 2525 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2526 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2527 | if (!pNotify) { |
| 2528 | return; |
| 2529 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2530 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate, false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2531 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2532 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2533 | } |
| 2534 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2535 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2536 | void CXFA_Node::Script_Field_SetItems(CFXJSE_Arguments* pArguments) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2537 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2538 | void CXFA_Node::Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments) { |
| 2539 | int32_t iLength = pArguments->GetLength(); |
| 2540 | if (iLength != 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2541 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getDisplayItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2542 | return; |
| 2543 | } |
| 2544 | int32_t iIndex = pArguments->GetInt32(0); |
| 2545 | if (iIndex < 0) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2546 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2547 | return; |
| 2548 | } |
| 2549 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2550 | if (!pWidgetData) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2551 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2552 | return; |
| 2553 | } |
| 2554 | CFX_WideString wsValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2555 | bool bHasItem = pWidgetData->GetChoiceListItem(wsValue, iIndex, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2556 | if (bHasItem) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2557 | pArguments->GetReturnValue()->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 2558 | FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2559 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2560 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2561 | } |
| 2562 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2563 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2564 | void CXFA_Node::Script_Field_SetItemState(CFXJSE_Arguments* pArguments) { |
| 2565 | int32_t iLength = pArguments->GetLength(); |
| 2566 | if (iLength != 2) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2567 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setItemState"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2568 | return; |
| 2569 | } |
| 2570 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2571 | if (!pWidgetData) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2572 | return; |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2573 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2574 | int32_t iIndex = pArguments->GetInt32(0); |
| 2575 | if (pArguments->GetInt32(1) != 0) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2576 | pWidgetData->SetItemState(iIndex, true, true, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2577 | } else { |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2578 | if (pWidgetData->GetItemState(iIndex)) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2579 | pWidgetData->SetItemState(iIndex, false, true, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2580 | } |
| 2581 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2582 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2583 | void CXFA_Node::Script_Field_AddItem(CFXJSE_Arguments* pArguments) { |
| 2584 | int32_t iLength = pArguments->GetLength(); |
| 2585 | if (iLength < 1 || iLength > 2) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2586 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"addItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2587 | return; |
| 2588 | } |
| 2589 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2590 | if (!pWidgetData) { |
| 2591 | return; |
| 2592 | } |
| 2593 | CFX_WideString wsLabel; |
| 2594 | CFX_WideString wsValue; |
| 2595 | if (iLength >= 1) { |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 2596 | CFX_ByteString bsLabel = pArguments->GetUTF8String(0); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2597 | wsLabel = CFX_WideString::FromUTF8(bsLabel.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2598 | } |
| 2599 | if (iLength >= 2) { |
| 2600 | CFX_ByteString bsValue = pArguments->GetUTF8String(1); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2601 | wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2602 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2603 | pWidgetData->InsertItem(wsLabel, wsValue, -1, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2604 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2605 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2606 | void CXFA_Node::Script_Field_ExecValidate(CFXJSE_Arguments* pArguments) { |
| 2607 | int32_t argc = pArguments->GetLength(); |
| 2608 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2609 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2610 | if (!pNotify) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2611 | pArguments->GetReturnValue()->SetBoolean(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2612 | } else { |
| 2613 | int32_t iRet = |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2614 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate, false, false); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2615 | pArguments->GetReturnValue()->SetBoolean( |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2616 | (iRet == XFA_EVENTERROR_Error) ? false : true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2617 | } |
| 2618 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2619 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2620 | } |
| 2621 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2622 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2623 | void CXFA_Node::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2624 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2625 | XFA_ATTRIBUTE eAttribute) { |
| 2626 | if (!bSetting) { |
| 2627 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2628 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2629 | } |
| 2630 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2631 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2632 | void CXFA_Node::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2633 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2634 | XFA_ATTRIBUTE eAttribute) { |
| 2635 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2636 | if (!pWidgetData) { |
| 2637 | return; |
| 2638 | } |
| 2639 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2640 | pWidgetData->SetSelectedMemberByValue(pValue->ToWideString().AsStringC(), |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2641 | true, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2642 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2643 | CFX_WideString wsValue = GetScriptContent(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2644 | XFA_VERSION curVersion = GetDocument()->GetCurVersionMode(); |
| 2645 | if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2646 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2647 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2648 | pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2649 | } |
| 2650 | } |
| 2651 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2652 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2653 | void CXFA_Node::Script_ExclGroup_Transient(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2654 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2655 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2656 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2657 | void CXFA_Node::Script_ExclGroup_ExecEvent(CFXJSE_Arguments* pArguments) { |
| 2658 | int32_t argc = pArguments->GetLength(); |
| 2659 | if (argc == 1) { |
| 2660 | CFX_ByteString eventString = pArguments->GetUTF8String(0); |
| 2661 | execSingleEventByName( |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2662 | CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(), |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 2663 | XFA_Element::ExclGroup); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2664 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2665 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2666 | } |
| 2667 | } |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2668 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2669 | void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments) { |
| 2670 | int32_t argc = pArguments->GetLength(); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2671 | if (argc < 0 || argc > 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2672 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"selectedMember"); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2673 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2674 | } |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2675 | |
| 2676 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2677 | if (!pWidgetData) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2678 | pArguments->GetReturnValue()->SetNull(); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2679 | return; |
| 2680 | } |
| 2681 | |
| 2682 | CXFA_Node* pReturnNode = nullptr; |
| 2683 | if (argc == 0) { |
| 2684 | pReturnNode = pWidgetData->GetSelectedMember(); |
| 2685 | } else { |
| 2686 | CFX_ByteString szName; |
| 2687 | szName = pArguments->GetUTF8String(0); |
| 2688 | pReturnNode = pWidgetData->SetSelectedMember( |
| 2689 | CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC(), true); |
| 2690 | } |
| 2691 | if (!pReturnNode) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2692 | pArguments->GetReturnValue()->SetNull(); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2693 | return; |
| 2694 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2695 | pArguments->GetReturnValue()->Assign( |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2696 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pReturnNode)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2697 | } |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2698 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2699 | void CXFA_Node::Script_ExclGroup_ExecInitialize(CFXJSE_Arguments* pArguments) { |
| 2700 | int32_t argc = pArguments->GetLength(); |
| 2701 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2702 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2703 | if (!pNotify) { |
| 2704 | return; |
| 2705 | } |
| 2706 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize); |
| 2707 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2708 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2709 | } |
| 2710 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2711 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2712 | void CXFA_Node::Script_ExclGroup_ExecCalculate(CFXJSE_Arguments* pArguments) { |
| 2713 | int32_t argc = pArguments->GetLength(); |
| 2714 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2715 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2716 | if (!pNotify) { |
| 2717 | return; |
| 2718 | } |
| 2719 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); |
| 2720 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2721 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2722 | } |
| 2723 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2724 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2725 | void CXFA_Node::Script_ExclGroup_ExecValidate(CFXJSE_Arguments* pArguments) { |
| 2726 | int32_t argc = pArguments->GetLength(); |
| 2727 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2728 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2729 | if (!pNotify) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2730 | pArguments->GetReturnValue()->SetBoolean(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2731 | } else { |
| 2732 | int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2733 | pArguments->GetReturnValue()->SetBoolean( |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2734 | (iRet == XFA_EVENTERROR_Error) ? false : true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2735 | } |
| 2736 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2737 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2738 | } |
| 2739 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2740 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2741 | void CXFA_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2742 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2743 | XFA_ATTRIBUTE eAttribute) { |
| 2744 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2745 | int32_t iTo = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2746 | int32_t iFrom = Subform_and_SubformSet_InstanceIndex(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 2747 | CXFA_Node* pManagerNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2748 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; |
| 2749 | pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2750 | if (pNode->GetElementType() == XFA_Element::InstanceManager) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2751 | pManagerNode = pNode; |
| 2752 | break; |
| 2753 | } |
| 2754 | } |
| 2755 | if (pManagerNode) { |
| 2756 | pManagerNode->InstanceManager_MoveInstance(iTo, iFrom); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2757 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2758 | if (!pNotify) { |
| 2759 | return; |
| 2760 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2761 | CXFA_Node* pToInstance = GetItem(pManagerNode, iTo); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2762 | if (pToInstance && |
| 2763 | pToInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2764 | pNotify->RunSubformIndexChange(pToInstance); |
| 2765 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2766 | CXFA_Node* pFromInstance = GetItem(pManagerNode, iFrom); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 2767 | if (pFromInstance && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2768 | pFromInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2769 | pNotify->RunSubformIndexChange(pFromInstance); |
| 2770 | } |
| 2771 | } |
| 2772 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2773 | pValue->SetInteger(Subform_and_SubformSet_InstanceIndex()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2774 | } |
| 2775 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2776 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2777 | void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2778 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2779 | XFA_ATTRIBUTE eAttribute) { |
| 2780 | if (!bSetting) { |
| 2781 | CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 2782 | CXFA_Node* pInstanceMgr = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2783 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; |
| 2784 | pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2785 | if (pNode->GetElementType() == XFA_Element::InstanceManager) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2786 | CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name); |
| 2787 | if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' && |
| 2788 | wsInstMgrName.Mid(1) == wsName) { |
| 2789 | pInstanceMgr = pNode; |
| 2790 | } |
| 2791 | break; |
| 2792 | } |
| 2793 | } |
| 2794 | if (pInstanceMgr) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2795 | pValue->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2796 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pInstanceMgr)); |
| 2797 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2798 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2799 | } |
| 2800 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2801 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2802 | } |
| 2803 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2804 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2805 | void CXFA_Node::Script_Subform_Locale(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2806 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2807 | XFA_ATTRIBUTE eAttribute) { |
| 2808 | if (bSetting) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2809 | SetCData(XFA_ATTRIBUTE_Locale, pValue->ToWideString(), true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2810 | } else { |
| 2811 | CFX_WideString wsLocaleName; |
| 2812 | GetLocaleName(wsLocaleName); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2813 | pValue->SetString( |
| 2814 | FX_UTF8Encode(wsLocaleName.c_str(), wsLocaleName.GetLength()) |
| 2815 | .AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2816 | } |
| 2817 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2818 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2819 | void CXFA_Node::Script_Subform_ExecEvent(CFXJSE_Arguments* pArguments) { |
| 2820 | int32_t argc = pArguments->GetLength(); |
| 2821 | if (argc == 1) { |
| 2822 | CFX_ByteString eventString = pArguments->GetUTF8String(0); |
| 2823 | execSingleEventByName( |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2824 | CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(), |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 2825 | XFA_Element::Subform); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2826 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2827 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2828 | } |
| 2829 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2830 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2831 | void CXFA_Node::Script_Subform_ExecInitialize(CFXJSE_Arguments* pArguments) { |
| 2832 | int32_t argc = pArguments->GetLength(); |
| 2833 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2834 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2835 | if (!pNotify) { |
| 2836 | return; |
| 2837 | } |
| 2838 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize); |
| 2839 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2840 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2841 | } |
| 2842 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2843 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2844 | void CXFA_Node::Script_Subform_ExecCalculate(CFXJSE_Arguments* pArguments) { |
| 2845 | int32_t argc = pArguments->GetLength(); |
| 2846 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2847 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2848 | if (!pNotify) { |
| 2849 | return; |
| 2850 | } |
| 2851 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); |
| 2852 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2853 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2854 | } |
| 2855 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2856 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2857 | void CXFA_Node::Script_Subform_ExecValidate(CFXJSE_Arguments* pArguments) { |
| 2858 | int32_t argc = pArguments->GetLength(); |
| 2859 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2860 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2861 | if (!pNotify) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2862 | pArguments->GetReturnValue()->SetBoolean(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2863 | } else { |
| 2864 | int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2865 | pArguments->GetReturnValue()->SetBoolean( |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2866 | (iRet == XFA_EVENTERROR_Error) ? false : true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2867 | } |
| 2868 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2869 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2870 | } |
| 2871 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2872 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2873 | void CXFA_Node::Script_Subform_GetInvalidObjects(CFXJSE_Arguments* pArguments) { |
| 2874 | int32_t argc = pArguments->GetLength(); |
| 2875 | if (argc == 0) { |
| 2876 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2877 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getInvalidObjects"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2878 | } |
| 2879 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2880 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2881 | int32_t CXFA_Node::Subform_and_SubformSet_InstanceIndex() { |
| 2882 | int32_t index = 0; |
| 2883 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; |
| 2884 | pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2885 | if ((pNode->GetElementType() == XFA_Element::Subform) || |
| 2886 | (pNode->GetElementType() == XFA_Element::SubformSet)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2887 | index++; |
| 2888 | } else { |
| 2889 | break; |
| 2890 | } |
| 2891 | } |
| 2892 | return index; |
| 2893 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2894 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2895 | void CXFA_Node::Script_Template_FormNodes(CFXJSE_Arguments* pArguments) { |
| 2896 | int32_t argc = pArguments->GetLength(); |
| 2897 | if (argc == 1) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2898 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2899 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2900 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"formNodes"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2901 | } |
| 2902 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2903 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2904 | void CXFA_Node::Script_Template_Remerge(CFXJSE_Arguments* pArguments) { |
| 2905 | int32_t argc = pArguments->GetLength(); |
| 2906 | if (argc == 0) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2907 | m_pDocument->DoDataRemerge(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2908 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2909 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"remerge"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2910 | } |
| 2911 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2912 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2913 | void CXFA_Node::Script_Template_ExecInitialize(CFXJSE_Arguments* pArguments) { |
| 2914 | int32_t argc = pArguments->GetLength(); |
| 2915 | if (argc == 0) { |
| 2916 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2917 | if (!pWidgetData) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2918 | pArguments->GetReturnValue()->SetBoolean(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2919 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2920 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2921 | } |
| 2922 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2923 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2924 | } |
| 2925 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2926 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2927 | void CXFA_Node::Script_Template_CreateNode(CFXJSE_Arguments* pArguments) { |
| 2928 | int32_t argc = pArguments->GetLength(); |
| 2929 | if ((argc > 0) && (argc < 4)) { |
| 2930 | CFX_WideString strTagName; |
| 2931 | CFX_WideString strName; |
| 2932 | CFX_WideString strNameSpace; |
| 2933 | CFX_ByteString bsTagName = pArguments->GetUTF8String(0); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2934 | strTagName = CFX_WideString::FromUTF8(bsTagName.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2935 | if (argc > 1) { |
| 2936 | CFX_ByteString bsName = pArguments->GetUTF8String(1); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2937 | strName = CFX_WideString::FromUTF8(bsName.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2938 | if (argc == 3) { |
| 2939 | CFX_ByteString bsNameSpace = pArguments->GetUTF8String(2); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2940 | strNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2941 | } |
| 2942 | } |
dsinclair | 6e12478 | 2016-06-23 12:14:55 -0700 | [diff] [blame] | 2943 | XFA_Element eType = XFA_GetElementTypeForName(strTagName.AsStringC()); |
| 2944 | CXFA_Node* pNewNode = CreateSamePacketNode(eType); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2945 | if (!pNewNode) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2946 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2947 | } else { |
| 2948 | if (!strName.IsEmpty()) { |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 2949 | if (GetAttributeOfElement(eType, XFA_ATTRIBUTE_Name, |
| 2950 | XFA_XDPPACKET_UNKNOWN)) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 2951 | pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, strName.AsStringC(), true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2952 | if (pNewNode->GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 2953 | pNewNode->CreateXMLMappingNode(); |
| 2954 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2955 | pArguments->GetReturnValue()->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2956 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode)); |
| 2957 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2958 | ThrowException(XFA_IDS_NOT_HAVE_PROPERTY, strTagName.c_str(), |
| 2959 | L"name"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2960 | } |
| 2961 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2962 | pArguments->GetReturnValue()->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2963 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode)); |
| 2964 | } |
| 2965 | } |
| 2966 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2967 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"createNode"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2968 | } |
| 2969 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2970 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2971 | void CXFA_Node::Script_Template_Recalculate(CFXJSE_Arguments* pArguments) { |
| 2972 | if (pArguments->GetLength() == 1) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2973 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2974 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2975 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"recalculate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2976 | } |
| 2977 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2978 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2979 | void CXFA_Node::Script_Template_ExecCalculate(CFXJSE_Arguments* pArguments) { |
| 2980 | int32_t argc = pArguments->GetLength(); |
| 2981 | if (argc == 0) { |
| 2982 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2983 | if (!pWidgetData) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2984 | pArguments->GetReturnValue()->SetBoolean(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2985 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2986 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2987 | } |
| 2988 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2989 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2990 | } |
| 2991 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2992 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2993 | void CXFA_Node::Script_Template_ExecValidate(CFXJSE_Arguments* pArguments) { |
| 2994 | int32_t argc = pArguments->GetLength(); |
| 2995 | if (argc == 0) { |
| 2996 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2997 | if (!pWidgetData) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2998 | pArguments->GetReturnValue()->SetBoolean(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2999 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3000 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3001 | } |
| 3002 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3003 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3004 | } |
| 3005 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3006 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3007 | void CXFA_Node::Script_Manifest_Evaluate(CFXJSE_Arguments* pArguments) { |
| 3008 | int32_t argc = pArguments->GetLength(); |
| 3009 | if (argc == 0) { |
| 3010 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 3011 | if (!pWidgetData) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3012 | pArguments->GetReturnValue()->SetBoolean(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3013 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3014 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3015 | } |
| 3016 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3017 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"evaluate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3018 | } |
| 3019 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3020 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3021 | void CXFA_Node::Script_InstanceManager_Max(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3022 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3023 | XFA_ATTRIBUTE eAttribute) { |
| 3024 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3025 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3026 | return; |
| 3027 | } |
| 3028 | CXFA_Occur nodeOccur(GetOccurNode()); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3029 | pValue->SetInteger(nodeOccur.GetMax()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3030 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3031 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3032 | void CXFA_Node::Script_InstanceManager_Min(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3033 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3034 | XFA_ATTRIBUTE eAttribute) { |
| 3035 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3036 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3037 | return; |
| 3038 | } |
| 3039 | CXFA_Occur nodeOccur(GetOccurNode()); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3040 | pValue->SetInteger(nodeOccur.GetMin()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3041 | } |
tsepez | aadedf9 | 2016-05-12 10:08:06 -0700 | [diff] [blame] | 3042 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3043 | void CXFA_Node::Script_InstanceManager_Count(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3044 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3045 | XFA_ATTRIBUTE eAttribute) { |
| 3046 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3047 | int32_t iDesired = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3048 | InstanceManager_SetInstances(iDesired); |
| 3049 | } else { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3050 | pValue->SetInteger(GetCount(this)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3051 | } |
| 3052 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3053 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3054 | void CXFA_Node::Script_InstanceManager_MoveInstance( |
| 3055 | CFXJSE_Arguments* pArguments) { |
| 3056 | int32_t argc = pArguments->GetLength(); |
| 3057 | if (argc != 2) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3058 | pArguments->GetReturnValue()->SetUndefined(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3059 | return; |
| 3060 | } |
| 3061 | int32_t iFrom = pArguments->GetInt32(0); |
| 3062 | int32_t iTo = pArguments->GetInt32(1); |
| 3063 | InstanceManager_MoveInstance(iTo, iFrom); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3064 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3065 | if (!pNotify) { |
| 3066 | return; |
| 3067 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3068 | CXFA_Node* pToInstance = GetItem(this, iTo); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3069 | if (pToInstance && pToInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3070 | pNotify->RunSubformIndexChange(pToInstance); |
| 3071 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3072 | CXFA_Node* pFromInstance = GetItem(this, iFrom); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3073 | if (pFromInstance && |
| 3074 | pFromInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3075 | pNotify->RunSubformIndexChange(pFromInstance); |
| 3076 | } |
| 3077 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3078 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3079 | void CXFA_Node::Script_InstanceManager_RemoveInstance( |
| 3080 | CFXJSE_Arguments* pArguments) { |
| 3081 | int32_t argc = pArguments->GetLength(); |
| 3082 | if (argc != 1) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3083 | pArguments->GetReturnValue()->SetUndefined(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3084 | return; |
| 3085 | } |
| 3086 | int32_t iIndex = pArguments->GetInt32(0); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3087 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3088 | if (iIndex < 0 || iIndex >= iCount) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3089 | ThrowException(XFA_IDS_INDEX_OUT_OF_BOUNDS); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3090 | return; |
| 3091 | } |
| 3092 | CXFA_Occur nodeOccur(GetOccurNode()); |
| 3093 | int32_t iMin = nodeOccur.GetMin(); |
| 3094 | if (iCount - 1 < iMin) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3095 | ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"min"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3096 | return; |
| 3097 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3098 | CXFA_Node* pRemoveInstance = GetItem(this, iIndex); |
| 3099 | RemoveItem(this, pRemoveInstance); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3100 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3101 | if (pNotify) { |
| 3102 | for (int32_t i = iIndex; i < iCount - 1; i++) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3103 | CXFA_Node* pSubformInstance = GetItem(this, i); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3104 | if (pSubformInstance && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3105 | pSubformInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3106 | pNotify->RunSubformIndexChange(pSubformInstance); |
| 3107 | } |
| 3108 | } |
| 3109 | } |
| 3110 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3111 | if (!pLayoutPro) { |
| 3112 | return; |
| 3113 | } |
| 3114 | pLayoutPro->AddChangedContainer( |
| 3115 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3116 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3117 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3118 | void CXFA_Node::Script_InstanceManager_SetInstances( |
| 3119 | CFXJSE_Arguments* pArguments) { |
| 3120 | int32_t argc = pArguments->GetLength(); |
| 3121 | if (argc != 1) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3122 | pArguments->GetReturnValue()->SetUndefined(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3123 | return; |
| 3124 | } |
| 3125 | int32_t iDesired = pArguments->GetInt32(0); |
| 3126 | InstanceManager_SetInstances(iDesired); |
| 3127 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3128 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3129 | void CXFA_Node::Script_InstanceManager_AddInstance( |
| 3130 | CFXJSE_Arguments* pArguments) { |
| 3131 | int32_t argc = pArguments->GetLength(); |
| 3132 | if ((argc != 0) && (argc != 1)) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3133 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"addInstance"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3134 | return; |
| 3135 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3136 | bool fFlags = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3137 | if (argc == 1) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3138 | fFlags = pArguments->GetInt32(0) == 0 ? false : true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3139 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3140 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3141 | CXFA_Occur nodeOccur(GetOccurNode()); |
| 3142 | int32_t iMax = nodeOccur.GetMax(); |
| 3143 | if (iMax >= 0 && iCount >= iMax) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3144 | ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"max"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3145 | return; |
| 3146 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3147 | CXFA_Node* pNewInstance = CreateInstance(this, fFlags); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3148 | InsertItem(this, pNewInstance, iCount, iCount, false); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3149 | pArguments->GetReturnValue()->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3150 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance)); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3151 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3152 | if (!pNotify) { |
| 3153 | return; |
| 3154 | } |
| 3155 | pNotify->RunNodeInitialize(pNewInstance); |
| 3156 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3157 | if (!pLayoutPro) { |
| 3158 | return; |
| 3159 | } |
| 3160 | pLayoutPro->AddChangedContainer( |
| 3161 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3162 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3163 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3164 | void CXFA_Node::Script_InstanceManager_InsertInstance( |
| 3165 | CFXJSE_Arguments* pArguments) { |
| 3166 | int32_t argc = pArguments->GetLength(); |
| 3167 | if ((argc != 1) && (argc != 2)) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3168 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"insertInstance"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3169 | return; |
| 3170 | } |
| 3171 | int32_t iIndex = pArguments->GetInt32(0); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3172 | bool bBind = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3173 | if (argc == 2) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3174 | bBind = pArguments->GetInt32(1) == 0 ? false : true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3175 | } |
| 3176 | CXFA_Occur nodeOccur(GetOccurNode()); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3177 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3178 | if (iIndex < 0 || iIndex > iCount) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3179 | ThrowException(XFA_IDS_INDEX_OUT_OF_BOUNDS); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3180 | return; |
| 3181 | } |
| 3182 | int32_t iMax = nodeOccur.GetMax(); |
| 3183 | if (iMax >= 0 && iCount >= iMax) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3184 | ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"max"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3185 | return; |
| 3186 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3187 | CXFA_Node* pNewInstance = CreateInstance(this, bBind); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3188 | InsertItem(this, pNewInstance, iIndex, iCount, true); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3189 | pArguments->GetReturnValue()->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3190 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance)); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3191 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3192 | if (!pNotify) { |
| 3193 | return; |
| 3194 | } |
| 3195 | pNotify->RunNodeInitialize(pNewInstance); |
| 3196 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3197 | if (!pLayoutPro) { |
| 3198 | return; |
| 3199 | } |
| 3200 | pLayoutPro->AddChangedContainer( |
| 3201 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3202 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3203 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3204 | int32_t CXFA_Node::InstanceManager_SetInstances(int32_t iDesired) { |
| 3205 | CXFA_Occur nodeOccur(GetOccurNode()); |
| 3206 | int32_t iMax = nodeOccur.GetMax(); |
| 3207 | int32_t iMin = nodeOccur.GetMin(); |
| 3208 | if (iDesired < iMin) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3209 | ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"min"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3210 | return 1; |
| 3211 | } |
| 3212 | if ((iMax >= 0) && (iDesired > iMax)) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3213 | ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"max"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3214 | return 2; |
| 3215 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3216 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3217 | if (iDesired == iCount) { |
| 3218 | return 0; |
| 3219 | } |
| 3220 | if (iDesired < iCount) { |
| 3221 | CFX_WideStringC wsInstManagerName = GetCData(XFA_ATTRIBUTE_Name); |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3222 | CFX_WideString wsInstanceName = |
| 3223 | CFX_WideString(wsInstManagerName.IsEmpty() ? wsInstManagerName |
| 3224 | : wsInstManagerName.Mid(1)); |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 3225 | uint32_t dInstanceNameHash = |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 3226 | FX_HashCode_GetW(wsInstanceName.AsStringC(), false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3227 | CXFA_Node* pPrevSibling = |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3228 | (iDesired == 0) ? this : GetItem(this, iDesired - 1); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3229 | while (iCount > iDesired) { |
| 3230 | CXFA_Node* pRemoveInstance = |
| 3231 | pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3232 | if (pRemoveInstance->GetElementType() != XFA_Element::Subform && |
| 3233 | pRemoveInstance->GetElementType() != XFA_Element::SubformSet) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3234 | continue; |
| 3235 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3236 | if (pRemoveInstance->GetElementType() == XFA_Element::InstanceManager) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3237 | ASSERT(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3238 | break; |
| 3239 | } |
| 3240 | if (pRemoveInstance->GetNameHash() == dInstanceNameHash) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3241 | RemoveItem(this, pRemoveInstance); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3242 | iCount--; |
| 3243 | } |
| 3244 | } |
| 3245 | } else if (iDesired > iCount) { |
| 3246 | while (iCount < iDesired) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3247 | CXFA_Node* pNewInstance = CreateInstance(this, true); |
| 3248 | InsertItem(this, pNewInstance, iCount, iCount, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3249 | iCount++; |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3250 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3251 | if (!pNotify) { |
| 3252 | return 0; |
| 3253 | } |
| 3254 | pNotify->RunNodeInitialize(pNewInstance); |
| 3255 | } |
| 3256 | } |
| 3257 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3258 | if (pLayoutPro) { |
| 3259 | pLayoutPro->AddChangedContainer( |
| 3260 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3261 | } |
| 3262 | return 0; |
| 3263 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3264 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3265 | int32_t CXFA_Node::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3266 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3267 | if (iFrom > iCount || iTo > iCount - 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3268 | ThrowException(XFA_IDS_INDEX_OUT_OF_BOUNDS); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3269 | return 1; |
| 3270 | } |
| 3271 | if (iFrom < 0 || iTo < 0 || iFrom == iTo) { |
| 3272 | return 0; |
| 3273 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3274 | CXFA_Node* pMoveInstance = GetItem(this, iFrom); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3275 | RemoveItem(this, pMoveInstance, false); |
| 3276 | InsertItem(this, pMoveInstance, iTo, iCount - 1, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3277 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3278 | if (pLayoutPro) { |
| 3279 | pLayoutPro->AddChangedContainer( |
| 3280 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3281 | } |
| 3282 | return 0; |
| 3283 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3284 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3285 | void CXFA_Node::Script_Occur_Max(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3286 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3287 | XFA_ATTRIBUTE eAttribute) { |
| 3288 | CXFA_Occur occur(this); |
| 3289 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3290 | int32_t iMax = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3291 | occur.SetMax(iMax); |
| 3292 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3293 | pValue->SetInteger(occur.GetMax()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3294 | } |
| 3295 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3296 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3297 | void CXFA_Node::Script_Occur_Min(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3298 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3299 | XFA_ATTRIBUTE eAttribute) { |
| 3300 | CXFA_Occur occur(this); |
| 3301 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3302 | int32_t iMin = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3303 | occur.SetMin(iMin); |
| 3304 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3305 | pValue->SetInteger(occur.GetMin()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3306 | } |
| 3307 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3308 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3309 | void CXFA_Node::Script_Desc_Metadata(CFXJSE_Arguments* pArguments) { |
| 3310 | int32_t argc = pArguments->GetLength(); |
| 3311 | if ((argc == 0) || (argc == 1)) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3312 | pArguments->GetReturnValue()->SetString(""); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3313 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3314 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"metadata"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3315 | } |
| 3316 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3317 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3318 | void CXFA_Node::Script_Form_FormNodes(CFXJSE_Arguments* pArguments) { |
| 3319 | int32_t argc = pArguments->GetLength(); |
| 3320 | if (argc == 1) { |
| 3321 | CXFA_Node* pDataNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); |
| 3322 | if (pDataNode) { |
| 3323 | CXFA_NodeArray formItems; |
| 3324 | CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument); |
| 3325 | pFormNodes->SetArrayNodeList(formItems); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3326 | pArguments->GetReturnValue()->SetObject( |
| 3327 | pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3328 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3329 | ThrowException(XFA_IDS_ARGUMENT_MISMATCH); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3330 | } |
| 3331 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3332 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"formNodes"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3333 | } |
| 3334 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3335 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3336 | void CXFA_Node::Script_Form_Remerge(CFXJSE_Arguments* pArguments) { |
| 3337 | int32_t argc = pArguments->GetLength(); |
| 3338 | if (argc == 0) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3339 | m_pDocument->DoDataRemerge(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3340 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3341 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"remerge"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3342 | } |
| 3343 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3344 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3345 | void CXFA_Node::Script_Form_ExecInitialize(CFXJSE_Arguments* pArguments) { |
| 3346 | int32_t argc = pArguments->GetLength(); |
| 3347 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3348 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3349 | if (!pNotify) { |
| 3350 | return; |
| 3351 | } |
| 3352 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize); |
| 3353 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3354 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3355 | } |
| 3356 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3357 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3358 | void CXFA_Node::Script_Form_Recalculate(CFXJSE_Arguments* pArguments) { |
| 3359 | CXFA_EventParam* pEventParam = |
| 3360 | m_pDocument->GetScriptContext()->GetEventParam(); |
| 3361 | if (pEventParam->m_eType == XFA_EVENT_Calculate || |
| 3362 | pEventParam->m_eType == XFA_EVENT_InitCalculate) { |
| 3363 | return; |
| 3364 | } |
| 3365 | int32_t argc = pArguments->GetLength(); |
| 3366 | if (argc == 1) { |
| 3367 | const bool bScriptFlags = pArguments->GetInt32(0) != 0; |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3368 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3369 | if (!pNotify) { |
| 3370 | return; |
| 3371 | } |
| 3372 | if (bScriptFlags) { |
| 3373 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); |
| 3374 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3375 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Ready, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3376 | } else { |
| 3377 | } |
| 3378 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3379 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"recalculate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3380 | } |
| 3381 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3382 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3383 | void CXFA_Node::Script_Form_ExecCalculate(CFXJSE_Arguments* pArguments) { |
| 3384 | int32_t argc = pArguments->GetLength(); |
| 3385 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3386 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3387 | if (!pNotify) { |
| 3388 | return; |
| 3389 | } |
| 3390 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); |
| 3391 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3392 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3393 | } |
| 3394 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3395 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3396 | void CXFA_Node::Script_Form_ExecValidate(CFXJSE_Arguments* pArguments) { |
| 3397 | int32_t argc = pArguments->GetLength(); |
| 3398 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3399 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3400 | if (!pNotify) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3401 | pArguments->GetReturnValue()->SetBoolean(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3402 | } else { |
| 3403 | int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3404 | pArguments->GetReturnValue()->SetBoolean( |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3405 | (iRet == XFA_EVENTERROR_Error) ? false : true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3406 | } |
| 3407 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3408 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3409 | } |
| 3410 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3411 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3412 | void CXFA_Node::Script_Form_Checksum(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3413 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3414 | XFA_ATTRIBUTE eAttribute) { |
| 3415 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 3416 | SetAttribute(XFA_ATTRIBUTE_Checksum, pValue->ToWideString().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3417 | } else { |
| 3418 | CFX_WideString wsChecksum; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3419 | GetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum, false); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3420 | pValue->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 3421 | FX_UTF8Encode(wsChecksum.c_str(), wsChecksum.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3422 | } |
| 3423 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3424 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3425 | void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) { |
| 3426 | int32_t argc = pArguments->GetLength(); |
| 3427 | if (argc == 1) { |
| 3428 | CFX_ByteString bsAttributeName = pArguments->GetUTF8String(0); |
| 3429 | CFX_WideString wsAttributeValue; |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3430 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3431 | if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 3432 | static_cast<CFDE_XMLElement*>(pXMLNode)->GetString( |
| 3433 | CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str(), |
| 3434 | wsAttributeValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3435 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3436 | pArguments->GetReturnValue()->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 3437 | FX_UTF8Encode(wsAttributeValue.c_str(), wsAttributeValue.GetLength()) |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 3438 | .AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3439 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3440 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getAttribute"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3441 | } |
| 3442 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3443 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3444 | void CXFA_Node::Script_Packet_SetAttribute(CFXJSE_Arguments* pArguments) { |
| 3445 | int32_t argc = pArguments->GetLength(); |
| 3446 | if (argc == 2) { |
| 3447 | CFX_ByteString bsValue = pArguments->GetUTF8String(0); |
| 3448 | CFX_ByteString bsName = pArguments->GetUTF8String(1); |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3449 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3450 | if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3451 | static_cast<CFDE_XMLElement*>(pXMLNode)->SetString( |
| 3452 | CFX_WideString::FromUTF8(bsName.AsStringC()), |
| 3453 | CFX_WideString::FromUTF8(bsValue.AsStringC())); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3454 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3455 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3456 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3457 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setAttribute"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3458 | } |
| 3459 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3460 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3461 | void CXFA_Node::Script_Packet_RemoveAttribute(CFXJSE_Arguments* pArguments) { |
| 3462 | int32_t argc = pArguments->GetLength(); |
| 3463 | if (argc == 1) { |
| 3464 | CFX_ByteString bsName = pArguments->GetUTF8String(0); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 3465 | CFX_WideString wsName = CFX_WideString::FromUTF8(bsName.AsStringC()); |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3466 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3467 | if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3468 | CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 3469 | if (pXMLElement->HasAttribute(wsName.c_str())) { |
| 3470 | pXMLElement->RemoveAttribute(wsName.c_str()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3471 | } |
| 3472 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3473 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3474 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3475 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"removeAttribute"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3476 | } |
| 3477 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3478 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3479 | void CXFA_Node::Script_Packet_Content(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3480 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3481 | XFA_ATTRIBUTE eAttribute) { |
| 3482 | if (bSetting) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3483 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3484 | if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3485 | CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 3486 | pXMLElement->SetTextData(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3487 | } |
| 3488 | } else { |
| 3489 | CFX_WideString wsTextData; |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3490 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3491 | if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3492 | CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3493 | pXMLElement->GetTextData(wsTextData); |
| 3494 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3495 | pValue->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 3496 | FX_UTF8Encode(wsTextData.c_str(), wsTextData.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3497 | } |
| 3498 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3499 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3500 | void CXFA_Node::Script_Source_Next(CFXJSE_Arguments* pArguments) { |
| 3501 | int32_t argc = pArguments->GetLength(); |
| 3502 | if (argc == 0) { |
| 3503 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3504 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"next"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3505 | } |
| 3506 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3507 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3508 | void CXFA_Node::Script_Source_CancelBatch(CFXJSE_Arguments* pArguments) { |
| 3509 | int32_t argc = pArguments->GetLength(); |
| 3510 | if (argc == 0) { |
| 3511 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3512 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"cancelBatch"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3513 | } |
| 3514 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3515 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3516 | void CXFA_Node::Script_Source_First(CFXJSE_Arguments* pArguments) { |
| 3517 | int32_t argc = pArguments->GetLength(); |
| 3518 | if (argc == 0) { |
| 3519 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3520 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"first"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3521 | } |
| 3522 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3523 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3524 | void CXFA_Node::Script_Source_UpdateBatch(CFXJSE_Arguments* pArguments) { |
| 3525 | int32_t argc = pArguments->GetLength(); |
| 3526 | if (argc == 0) { |
| 3527 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3528 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"updateBatch"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3529 | } |
| 3530 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3531 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3532 | void CXFA_Node::Script_Source_Previous(CFXJSE_Arguments* pArguments) { |
| 3533 | int32_t argc = pArguments->GetLength(); |
| 3534 | if (argc == 0) { |
| 3535 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3536 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"previous"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3537 | } |
| 3538 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3539 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3540 | void CXFA_Node::Script_Source_IsBOF(CFXJSE_Arguments* pArguments) { |
| 3541 | int32_t argc = pArguments->GetLength(); |
| 3542 | if (argc == 0) { |
| 3543 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3544 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isBOF"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3545 | } |
| 3546 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3547 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3548 | void CXFA_Node::Script_Source_IsEOF(CFXJSE_Arguments* pArguments) { |
| 3549 | int32_t argc = pArguments->GetLength(); |
| 3550 | if (argc == 0) { |
| 3551 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3552 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isEOF"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3553 | } |
| 3554 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3555 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3556 | void CXFA_Node::Script_Source_Cancel(CFXJSE_Arguments* pArguments) { |
| 3557 | int32_t argc = pArguments->GetLength(); |
| 3558 | if (argc == 0) { |
| 3559 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3560 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"cancel"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3561 | } |
| 3562 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3563 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3564 | void CXFA_Node::Script_Source_Update(CFXJSE_Arguments* pArguments) { |
| 3565 | int32_t argc = pArguments->GetLength(); |
| 3566 | if (argc == 0) { |
| 3567 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3568 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"update"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3569 | } |
| 3570 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3571 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3572 | void CXFA_Node::Script_Source_Open(CFXJSE_Arguments* pArguments) { |
| 3573 | int32_t argc = pArguments->GetLength(); |
| 3574 | if (argc == 0) { |
| 3575 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3576 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"open"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3577 | } |
| 3578 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3579 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3580 | void CXFA_Node::Script_Source_Delete(CFXJSE_Arguments* pArguments) { |
| 3581 | int32_t argc = pArguments->GetLength(); |
| 3582 | if (argc == 0) { |
| 3583 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3584 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"delete"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3585 | } |
| 3586 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3587 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3588 | void CXFA_Node::Script_Source_AddNew(CFXJSE_Arguments* pArguments) { |
| 3589 | int32_t argc = pArguments->GetLength(); |
| 3590 | if (argc == 0) { |
| 3591 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3592 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"addNew"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3593 | } |
| 3594 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3595 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3596 | void CXFA_Node::Script_Source_Requery(CFXJSE_Arguments* pArguments) { |
| 3597 | int32_t argc = pArguments->GetLength(); |
| 3598 | if (argc == 0) { |
| 3599 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3600 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"requery"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3601 | } |
| 3602 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3603 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3604 | void CXFA_Node::Script_Source_Resync(CFXJSE_Arguments* pArguments) { |
| 3605 | int32_t argc = pArguments->GetLength(); |
| 3606 | if (argc == 0) { |
| 3607 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3608 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resync"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3609 | } |
| 3610 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3611 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3612 | void CXFA_Node::Script_Source_Close(CFXJSE_Arguments* pArguments) { |
| 3613 | int32_t argc = pArguments->GetLength(); |
| 3614 | if (argc == 0) { |
| 3615 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3616 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"close"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3617 | } |
| 3618 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3619 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3620 | void CXFA_Node::Script_Source_Last(CFXJSE_Arguments* pArguments) { |
| 3621 | int32_t argc = pArguments->GetLength(); |
| 3622 | if (argc == 0) { |
| 3623 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3624 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"last"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3625 | } |
| 3626 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3627 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3628 | void CXFA_Node::Script_Source_HasDataChanged(CFXJSE_Arguments* pArguments) { |
| 3629 | int32_t argc = pArguments->GetLength(); |
| 3630 | if (argc == 0) { |
| 3631 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3632 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"hasDataChanged"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3633 | } |
| 3634 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3635 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3636 | void CXFA_Node::Script_Source_Db(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3637 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3638 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3639 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3640 | void CXFA_Node::Script_Xfa_This(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3641 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3642 | XFA_ATTRIBUTE eAttribute) { |
| 3643 | if (!bSetting) { |
| 3644 | CXFA_Object* pThis = m_pDocument->GetScriptContext()->GetThisObject(); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 3645 | ASSERT(pThis); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3646 | pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pThis)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3647 | } |
| 3648 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3649 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3650 | void CXFA_Node::Script_Handler_Version(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3651 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3652 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3653 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3654 | void CXFA_Node::Script_SubmitFormat_Mode(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3655 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3656 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3657 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3658 | void CXFA_Node::Script_Extras_Type(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3659 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3660 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3661 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3662 | void CXFA_Node::Script_Script_Stateless(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3663 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3664 | XFA_ATTRIBUTE eAttribute) { |
| 3665 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3666 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3667 | return; |
| 3668 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3669 | pValue->SetString(FX_UTF8Encode(FX_WSTRC(L"0")).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3670 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3671 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3672 | void CXFA_Node::Script_Encrypt_Format(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3673 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3674 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3675 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3676 | bool CXFA_Node::HasAttribute(XFA_ATTRIBUTE eAttr, bool bCanInherit) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3677 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3678 | return HasMapModuleKey(pKey, bCanInherit); |
| 3679 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3680 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3681 | bool CXFA_Node::SetAttribute(XFA_ATTRIBUTE eAttr, |
| 3682 | const CFX_WideStringC& wsValue, |
| 3683 | bool bNotify) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3684 | const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3685 | if (!pAttr) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3686 | return false; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3687 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3688 | XFA_ATTRIBUTETYPE eType = pAttr->eType; |
| 3689 | if (eType == XFA_ATTRIBUTETYPE_NOTSURE) { |
| 3690 | const XFA_NOTSUREATTRIBUTE* pNotsure = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3691 | XFA_GetNotsureAttribute(GetElementType(), pAttr->eName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3692 | eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata; |
| 3693 | } |
| 3694 | switch (eType) { |
| 3695 | case XFA_ATTRIBUTETYPE_Enum: { |
| 3696 | const XFA_ATTRIBUTEENUMINFO* pEnum = XFA_GetAttributeEnumByName(wsValue); |
| 3697 | return SetEnum(pAttr->eName, |
| 3698 | pEnum ? pEnum->eName |
| 3699 | : (XFA_ATTRIBUTEENUM)(intptr_t)(pAttr->pDefValue), |
| 3700 | bNotify); |
| 3701 | } break; |
| 3702 | case XFA_ATTRIBUTETYPE_Cdata: |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3703 | return SetCData(pAttr->eName, CFX_WideString(wsValue), bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3704 | case XFA_ATTRIBUTETYPE_Boolean: |
| 3705 | return SetBoolean(pAttr->eName, wsValue != FX_WSTRC(L"0"), bNotify); |
| 3706 | case XFA_ATTRIBUTETYPE_Integer: |
dsinclair | e0347a6 | 2016-08-11 11:24:11 -0700 | [diff] [blame] | 3707 | return SetInteger(pAttr->eName, |
| 3708 | FXSYS_round(FXSYS_wcstof(wsValue.c_str(), |
| 3709 | wsValue.GetLength(), nullptr)), |
| 3710 | bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3711 | case XFA_ATTRIBUTETYPE_Measure: |
| 3712 | return SetMeasure(pAttr->eName, CXFA_Measurement(wsValue), bNotify); |
| 3713 | default: |
| 3714 | break; |
| 3715 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3716 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3717 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3718 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3719 | bool CXFA_Node::GetAttribute(XFA_ATTRIBUTE eAttr, |
| 3720 | CFX_WideString& wsValue, |
| 3721 | bool bUseDefault) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3722 | const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3723 | if (!pAttr) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3724 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3725 | } |
| 3726 | XFA_ATTRIBUTETYPE eType = pAttr->eType; |
| 3727 | if (eType == XFA_ATTRIBUTETYPE_NOTSURE) { |
| 3728 | const XFA_NOTSUREATTRIBUTE* pNotsure = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3729 | XFA_GetNotsureAttribute(GetElementType(), pAttr->eName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3730 | eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata; |
| 3731 | } |
| 3732 | switch (eType) { |
| 3733 | case XFA_ATTRIBUTETYPE_Enum: { |
| 3734 | XFA_ATTRIBUTEENUM eValue; |
| 3735 | if (!TryEnum(pAttr->eName, eValue, bUseDefault)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3736 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3737 | } |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 3738 | wsValue = GetAttributeEnumByID(eValue)->pName; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3739 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3740 | } break; |
| 3741 | case XFA_ATTRIBUTETYPE_Cdata: { |
| 3742 | CFX_WideStringC wsValueC; |
| 3743 | if (!TryCData(pAttr->eName, wsValueC, bUseDefault)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3744 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3745 | } |
| 3746 | wsValue = wsValueC; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3747 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3748 | } break; |
| 3749 | case XFA_ATTRIBUTETYPE_Boolean: { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3750 | bool bValue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3751 | if (!TryBoolean(pAttr->eName, bValue, bUseDefault)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3752 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3753 | } |
| 3754 | wsValue = bValue ? FX_WSTRC(L"1") : FX_WSTRC(L"0"); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3755 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3756 | } break; |
| 3757 | case XFA_ATTRIBUTETYPE_Integer: { |
| 3758 | int32_t iValue; |
| 3759 | if (!TryInteger(pAttr->eName, iValue, bUseDefault)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3760 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3761 | } |
| 3762 | wsValue.Format(L"%d", iValue); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3763 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3764 | } break; |
| 3765 | case XFA_ATTRIBUTETYPE_Measure: { |
| 3766 | CXFA_Measurement mValue; |
| 3767 | if (!TryMeasure(pAttr->eName, mValue, bUseDefault)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3768 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3769 | } |
| 3770 | mValue.ToString(wsValue); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3771 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3772 | } break; |
| 3773 | default: |
| 3774 | break; |
| 3775 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3776 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3777 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3778 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3779 | bool CXFA_Node::SetAttribute(const CFX_WideStringC& wsAttr, |
| 3780 | const CFX_WideStringC& wsValue, |
| 3781 | bool bNotify) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3782 | const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsValue); |
| 3783 | if (pAttributeInfo) { |
| 3784 | return SetAttribute(pAttributeInfo->eName, wsValue, bNotify); |
| 3785 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3786 | void* pKey = GetMapKey_Custom(wsAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3787 | SetMapModuleString(pKey, wsValue); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3788 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3789 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3790 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3791 | bool CXFA_Node::GetAttribute(const CFX_WideStringC& wsAttr, |
| 3792 | CFX_WideString& wsValue, |
| 3793 | bool bUseDefault) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3794 | const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsAttr); |
| 3795 | if (pAttributeInfo) { |
| 3796 | return GetAttribute(pAttributeInfo->eName, wsValue, bUseDefault); |
| 3797 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3798 | void* pKey = GetMapKey_Custom(wsAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3799 | CFX_WideStringC wsValueC; |
| 3800 | if (GetMapModuleString(pKey, wsValueC)) { |
| 3801 | wsValue = wsValueC; |
| 3802 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3803 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3804 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3805 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3806 | bool CXFA_Node::RemoveAttribute(const CFX_WideStringC& wsAttr) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3807 | void* pKey = GetMapKey_Custom(wsAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3808 | RemoveMapModuleKey(pKey); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3809 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3810 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3811 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3812 | bool CXFA_Node::TryBoolean(XFA_ATTRIBUTE eAttr, |
| 3813 | bool& bValue, |
| 3814 | bool bUseDefault) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3815 | void* pValue = nullptr; |
| 3816 | if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Boolean, bUseDefault, pValue)) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3817 | return false; |
tsepez | 478ed62 | 2016-10-27 14:32:33 -0700 | [diff] [blame] | 3818 | bValue = !!pValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3819 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3820 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3821 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3822 | bool CXFA_Node::TryInteger(XFA_ATTRIBUTE eAttr, |
| 3823 | int32_t& iValue, |
| 3824 | bool bUseDefault) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3825 | void* pValue = nullptr; |
| 3826 | if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Integer, bUseDefault, pValue)) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3827 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3828 | iValue = (int32_t)(uintptr_t)pValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3829 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3830 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3831 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3832 | bool CXFA_Node::TryEnum(XFA_ATTRIBUTE eAttr, |
| 3833 | XFA_ATTRIBUTEENUM& eValue, |
| 3834 | bool bUseDefault) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3835 | void* pValue = nullptr; |
| 3836 | if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Enum, bUseDefault, pValue)) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3837 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3838 | eValue = (XFA_ATTRIBUTEENUM)(uintptr_t)pValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3839 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3840 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3841 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3842 | bool CXFA_Node::SetMeasure(XFA_ATTRIBUTE eAttr, |
| 3843 | CXFA_Measurement mValue, |
| 3844 | bool bNotify) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3845 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3846 | OnChanging(eAttr, bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3847 | SetMapModuleBuffer(pKey, &mValue, sizeof(CXFA_Measurement)); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3848 | OnChanged(eAttr, bNotify, false); |
| 3849 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3850 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3851 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3852 | bool CXFA_Node::TryMeasure(XFA_ATTRIBUTE eAttr, |
| 3853 | CXFA_Measurement& mValue, |
| 3854 | bool bUseDefault) const { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3855 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3856 | void* pValue; |
| 3857 | int32_t iBytes; |
| 3858 | if (GetMapModuleBuffer(pKey, pValue, iBytes) && iBytes == sizeof(mValue)) { |
| 3859 | FXSYS_memcpy(&mValue, pValue, sizeof(mValue)); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3860 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3861 | } |
| 3862 | if (bUseDefault && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3863 | XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3864 | XFA_ATTRIBUTETYPE_Measure, m_ePacket)) { |
| 3865 | FXSYS_memcpy(&mValue, pValue, sizeof(mValue)); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3866 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3867 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3868 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3869 | } |
| 3870 | |
| 3871 | CXFA_Measurement CXFA_Node::GetMeasure(XFA_ATTRIBUTE eAttr) const { |
| 3872 | CXFA_Measurement mValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3873 | return TryMeasure(eAttr, mValue, true) ? mValue : CXFA_Measurement(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3874 | } |
| 3875 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3876 | bool CXFA_Node::SetCData(XFA_ATTRIBUTE eAttr, |
| 3877 | const CFX_WideString& wsValue, |
| 3878 | bool bNotify, |
| 3879 | bool bScriptModify) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3880 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3881 | OnChanging(eAttr, bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3882 | if (eAttr == XFA_ATTRIBUTE_Value) { |
| 3883 | CFX_WideString* pClone = new CFX_WideString(wsValue); |
| 3884 | SetUserData(pKey, pClone, &deleteWideStringCallBack); |
| 3885 | } else { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 3886 | SetMapModuleString(pKey, wsValue.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3887 | if (eAttr == XFA_ATTRIBUTE_Name) |
| 3888 | UpdateNameHash(); |
| 3889 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3890 | OnChanged(eAttr, bNotify, bScriptModify); |
| 3891 | |
| 3892 | if (!IsNeedSavingXMLNode() || eAttr == XFA_ATTRIBUTE_QualifiedName || |
| 3893 | eAttr == XFA_ATTRIBUTE_BindingNode) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3894 | return true; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3895 | } |
| 3896 | |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3897 | if (eAttr == XFA_ATTRIBUTE_Name && |
| 3898 | (m_elementType == XFA_Element::DataValue || |
| 3899 | m_elementType == XFA_Element::DataGroup)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3900 | return true; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3901 | } |
| 3902 | |
| 3903 | if (eAttr == XFA_ATTRIBUTE_Value) { |
| 3904 | FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType(); |
| 3905 | switch (eXMLType) { |
| 3906 | case FDE_XMLNODE_Element: |
| 3907 | if (IsAttributeInXML()) { |
| 3908 | static_cast<CFDE_XMLElement*>(m_pXMLNode) |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3909 | ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)), |
| 3910 | wsValue); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3911 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3912 | bool bDeleteChildren = true; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3913 | if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 3914 | for (CXFA_Node* pChildDataNode = |
| 3915 | GetNodeItem(XFA_NODEITEM_FirstChild); |
| 3916 | pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem( |
| 3917 | XFA_NODEITEM_NextSibling)) { |
| 3918 | CXFA_NodeArray formNodes; |
| 3919 | if (pChildDataNode->GetBindItems(formNodes) > 0) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3920 | bDeleteChildren = false; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3921 | break; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3922 | } |
| 3923 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3924 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3925 | if (bDeleteChildren) { |
| 3926 | static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren(); |
| 3927 | } |
| 3928 | static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsValue); |
| 3929 | } |
| 3930 | break; |
| 3931 | case FDE_XMLNODE_Text: |
| 3932 | static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsValue); |
| 3933 | break; |
| 3934 | default: |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 3935 | ASSERT(0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3936 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3937 | return true; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3938 | } |
| 3939 | |
| 3940 | const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr); |
| 3941 | if (pInfo) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 3942 | ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3943 | CFX_WideString wsAttrName = pInfo->pName; |
| 3944 | if (pInfo->eName == XFA_ATTRIBUTE_ContentType) { |
| 3945 | wsAttrName = FX_WSTRC(L"xfa:") + wsAttrName; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3946 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3947 | static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetString(wsAttrName, wsValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3948 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3949 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3950 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3951 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3952 | bool CXFA_Node::SetAttributeValue(const CFX_WideString& wsValue, |
| 3953 | const CFX_WideString& wsXMLValue, |
| 3954 | bool bNotify, |
| 3955 | bool bScriptModify) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3956 | void* pKey = GetMapKey_Element(GetElementType(), XFA_ATTRIBUTE_Value); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3957 | OnChanging(XFA_ATTRIBUTE_Value, bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3958 | CFX_WideString* pClone = new CFX_WideString(wsValue); |
| 3959 | SetUserData(pKey, pClone, &deleteWideStringCallBack); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3960 | OnChanged(XFA_ATTRIBUTE_Value, bNotify, bScriptModify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3961 | if (IsNeedSavingXMLNode()) { |
| 3962 | FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType(); |
| 3963 | switch (eXMLType) { |
| 3964 | case FDE_XMLNODE_Element: |
| 3965 | if (IsAttributeInXML()) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3966 | static_cast<CFDE_XMLElement*>(m_pXMLNode) |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3967 | ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)), |
| 3968 | wsXMLValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3969 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3970 | bool bDeleteChildren = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3971 | if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 3972 | for (CXFA_Node* pChildDataNode = |
| 3973 | GetNodeItem(XFA_NODEITEM_FirstChild); |
| 3974 | pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem( |
| 3975 | XFA_NODEITEM_NextSibling)) { |
| 3976 | CXFA_NodeArray formNodes; |
| 3977 | if (pChildDataNode->GetBindItems(formNodes) > 0) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3978 | bDeleteChildren = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3979 | break; |
| 3980 | } |
| 3981 | } |
| 3982 | } |
| 3983 | if (bDeleteChildren) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3984 | static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3985 | } |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3986 | static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsXMLValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3987 | } |
| 3988 | break; |
| 3989 | case FDE_XMLNODE_Text: |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3990 | static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsXMLValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3991 | break; |
| 3992 | default: |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 3993 | ASSERT(0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3994 | } |
| 3995 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3996 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3997 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3998 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3999 | bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr, |
| 4000 | CFX_WideString& wsValue, |
| 4001 | bool bUseDefault, |
| 4002 | bool bProto) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4003 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4004 | if (eAttr == XFA_ATTRIBUTE_Value) { |
| 4005 | CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto); |
| 4006 | if (pStr) { |
| 4007 | wsValue = *pStr; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4008 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4009 | } |
| 4010 | } else { |
| 4011 | CFX_WideStringC wsValueC; |
| 4012 | if (GetMapModuleString(pKey, wsValueC)) { |
| 4013 | wsValue = wsValueC; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4014 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4015 | } |
| 4016 | } |
| 4017 | if (!bUseDefault) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4018 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4019 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4020 | void* pValue = nullptr; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4021 | if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4022 | XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) { |
| 4023 | wsValue = (const FX_WCHAR*)pValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4024 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4025 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4026 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4027 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4028 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4029 | bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr, |
| 4030 | CFX_WideStringC& wsValue, |
| 4031 | bool bUseDefault, |
| 4032 | bool bProto) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4033 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4034 | if (eAttr == XFA_ATTRIBUTE_Value) { |
| 4035 | CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto); |
| 4036 | if (pStr) { |
tsepez | 4d31d0c | 2016-04-19 14:11:59 -0700 | [diff] [blame] | 4037 | wsValue = pStr->AsStringC(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4038 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4039 | } |
| 4040 | } else { |
| 4041 | if (GetMapModuleString(pKey, wsValue)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4042 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4043 | } |
| 4044 | } |
| 4045 | if (!bUseDefault) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4046 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4047 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4048 | void* pValue = nullptr; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4049 | if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4050 | XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) { |
| 4051 | wsValue = (CFX_WideStringC)(const FX_WCHAR*)pValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4052 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4053 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4054 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4055 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4056 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4057 | bool CXFA_Node::SetObject(XFA_ATTRIBUTE eAttr, |
| 4058 | void* pData, |
| 4059 | XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4060 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4061 | return SetUserData(pKey, pData, pCallbackInfo); |
| 4062 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4063 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4064 | bool CXFA_Node::TryObject(XFA_ATTRIBUTE eAttr, void*& pData) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4065 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4066 | pData = GetUserData(pKey); |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 4067 | return !!pData; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4068 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4069 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4070 | bool CXFA_Node::SetValue(XFA_ATTRIBUTE eAttr, |
| 4071 | XFA_ATTRIBUTETYPE eType, |
| 4072 | void* pValue, |
| 4073 | bool bNotify) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4074 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4075 | OnChanging(eAttr, bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4076 | SetMapModuleValue(pKey, pValue); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4077 | OnChanged(eAttr, bNotify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4078 | if (IsNeedSavingXMLNode()) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4079 | ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4080 | const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr); |
| 4081 | if (pInfo) { |
| 4082 | switch (eType) { |
| 4083 | case XFA_ATTRIBUTETYPE_Enum: |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4084 | static_cast<CFDE_XMLElement*>(m_pXMLNode) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4085 | ->SetString( |
| 4086 | pInfo->pName, |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 4087 | GetAttributeEnumByID((XFA_ATTRIBUTEENUM)(uintptr_t)pValue) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4088 | ->pName); |
| 4089 | break; |
| 4090 | case XFA_ATTRIBUTETYPE_Boolean: |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4091 | static_cast<CFDE_XMLElement*>(m_pXMLNode) |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 4092 | ->SetString(pInfo->pName, pValue ? L"1" : L"0"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4093 | break; |
| 4094 | case XFA_ATTRIBUTETYPE_Integer: |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4095 | static_cast<CFDE_XMLElement*>(m_pXMLNode) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4096 | ->SetInteger(pInfo->pName, (int32_t)(uintptr_t)pValue); |
| 4097 | break; |
| 4098 | default: |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4099 | ASSERT(0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4100 | } |
| 4101 | } |
| 4102 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4103 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4104 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4105 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4106 | bool CXFA_Node::GetValue(XFA_ATTRIBUTE eAttr, |
| 4107 | XFA_ATTRIBUTETYPE eType, |
| 4108 | bool bUseDefault, |
| 4109 | void*& pValue) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4110 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4111 | if (GetMapModuleValue(pKey, pValue)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4112 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4113 | } |
| 4114 | if (!bUseDefault) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4115 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4116 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4117 | return XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, eType, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4118 | m_ePacket); |
| 4119 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4120 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4121 | bool CXFA_Node::SetUserData(void* pKey, |
| 4122 | void* pData, |
| 4123 | XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4124 | SetMapModuleBuffer(pKey, &pData, sizeof(void*), |
| 4125 | pCallbackInfo ? pCallbackInfo : &gs_XFADefaultFreeData); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4126 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4127 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4128 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4129 | bool CXFA_Node::TryUserData(void* pKey, void*& pData, bool bProtoAlso) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4130 | int32_t iBytes = 0; |
| 4131 | if (!GetMapModuleBuffer(pKey, pData, iBytes, bProtoAlso)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4132 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4133 | } |
| 4134 | return iBytes == sizeof(void*) && FXSYS_memcpy(&pData, pData, iBytes); |
| 4135 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4136 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4137 | bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent, |
| 4138 | const CFX_WideString& wsXMLValue, |
| 4139 | bool bNotify, |
| 4140 | bool bScriptModify, |
| 4141 | bool bSyncData) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4142 | CXFA_Node* pNode = nullptr; |
| 4143 | CXFA_Node* pBindNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4144 | switch (GetObjectType()) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4145 | case XFA_ObjectType::ContainerNode: { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4146 | if (XFA_FieldIsMultiListBox(this)) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4147 | CXFA_Node* pValue = GetProperty(0, XFA_Element::Value); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4148 | CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4149 | ASSERT(pChildValue); |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 4150 | pChildValue->SetCData(XFA_ATTRIBUTE_ContentType, L"text/xml"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4151 | pChildValue->SetScriptContent(wsContent, wsContent, bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4152 | bScriptModify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4153 | CXFA_Node* pBind = GetBindData(); |
| 4154 | if (bSyncData && pBind) { |
| 4155 | CFX_WideStringArray wsSaveTextArray; |
| 4156 | int32_t iSize = 0; |
| 4157 | if (!wsContent.IsEmpty()) { |
| 4158 | int32_t iStart = 0; |
| 4159 | int32_t iLength = wsContent.GetLength(); |
| 4160 | int32_t iEnd = wsContent.Find(L'\n', iStart); |
| 4161 | iEnd = (iEnd == -1) ? iLength : iEnd; |
| 4162 | while (iEnd >= iStart) { |
| 4163 | wsSaveTextArray.Add(wsContent.Mid(iStart, iEnd - iStart)); |
| 4164 | iStart = iEnd + 1; |
| 4165 | if (iStart >= iLength) { |
| 4166 | break; |
| 4167 | } |
| 4168 | iEnd = wsContent.Find(L'\n', iStart); |
| 4169 | if (iEnd < 0) { |
| 4170 | wsSaveTextArray.Add(wsContent.Mid(iStart, iLength - iStart)); |
| 4171 | } |
| 4172 | } |
| 4173 | iSize = wsSaveTextArray.GetSize(); |
| 4174 | } |
| 4175 | if (iSize == 0) { |
| 4176 | while (CXFA_Node* pChildNode = |
| 4177 | pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) { |
| 4178 | pBind->RemoveChild(pChildNode); |
| 4179 | } |
| 4180 | } else { |
| 4181 | CXFA_NodeArray valueNodes; |
| 4182 | int32_t iDatas = pBind->GetNodeList( |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4183 | valueNodes, XFA_NODEFILTER_Children, XFA_Element::DataValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4184 | if (iDatas < iSize) { |
| 4185 | int32_t iAddNodes = iSize - iDatas; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4186 | CXFA_Node* pValueNodes = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4187 | while (iAddNodes-- > 0) { |
| 4188 | pValueNodes = |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4189 | pBind->CreateSamePacketNode(XFA_Element::DataValue); |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 4190 | pValueNodes->SetCData(XFA_ATTRIBUTE_Name, L"value"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4191 | pValueNodes->CreateXMLMappingNode(); |
| 4192 | pBind->InsertChild(pValueNodes); |
| 4193 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4194 | pValueNodes = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4195 | } else if (iDatas > iSize) { |
| 4196 | int32_t iDelNodes = iDatas - iSize; |
| 4197 | while (iDelNodes-- > 0) { |
| 4198 | pBind->RemoveChild(pBind->GetNodeItem(XFA_NODEITEM_FirstChild)); |
| 4199 | } |
| 4200 | } |
| 4201 | int32_t i = 0; |
| 4202 | for (CXFA_Node* pValueNode = |
| 4203 | pBind->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 4204 | pValueNode; pValueNode = pValueNode->GetNodeItem( |
| 4205 | XFA_NODEITEM_NextSibling)) { |
| 4206 | pValueNode->SetAttributeValue(wsSaveTextArray[i], |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4207 | wsSaveTextArray[i], false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4208 | i++; |
| 4209 | } |
| 4210 | } |
| 4211 | CXFA_NodeArray nodeArray; |
| 4212 | pBind->GetBindItems(nodeArray); |
| 4213 | for (int32_t i = 0; i < nodeArray.GetSize(); i++) { |
weili | db444d2 | 2016-06-02 15:48:15 -0700 | [diff] [blame] | 4214 | if (nodeArray[i] != this) { |
| 4215 | nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4216 | bScriptModify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4217 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4218 | } |
| 4219 | } |
| 4220 | break; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4221 | } else if (GetElementType() == XFA_Element::ExclGroup) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4222 | pNode = this; |
| 4223 | } else { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4224 | CXFA_Node* pValue = GetProperty(0, XFA_Element::Value); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4225 | CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4226 | ASSERT(pChildValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4227 | pChildValue->SetScriptContent(wsContent, wsContent, bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4228 | bScriptModify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4229 | } |
| 4230 | pBindNode = GetBindData(); |
| 4231 | if (pBindNode && bSyncData) { |
| 4232 | pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4233 | bScriptModify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4234 | CXFA_NodeArray nodeArray; |
| 4235 | pBindNode->GetBindItems(nodeArray); |
| 4236 | for (int32_t i = 0; i < nodeArray.GetSize(); i++) { |
weili | db444d2 | 2016-06-02 15:48:15 -0700 | [diff] [blame] | 4237 | if (nodeArray[i] != this) { |
| 4238 | nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify, true, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4239 | false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4240 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4241 | } |
| 4242 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4243 | pBindNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4244 | break; |
| 4245 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4246 | case XFA_ObjectType::ContentNode: { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4247 | CFX_WideString wsContentType; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4248 | if (GetElementType() == XFA_Element::ExData) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4249 | GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false); |
tsepez | 9f2970c | 2016-04-01 10:23:04 -0700 | [diff] [blame] | 4250 | if (wsContentType == FX_WSTRC(L"text/html")) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4251 | wsContentType = FX_WSTRC(L""); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 4252 | SetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4253 | } |
| 4254 | } |
| 4255 | CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild); |
| 4256 | if (!pContentRawDataNode) { |
tsepez | 9f2970c | 2016-04-01 10:23:04 -0700 | [diff] [blame] | 4257 | pContentRawDataNode = CreateSamePacketNode( |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4258 | (wsContentType == FX_WSTRC(L"text/xml")) ? XFA_Element::Sharpxml |
| 4259 | : XFA_Element::Sharptext); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4260 | InsertChild(pContentRawDataNode); |
| 4261 | } |
| 4262 | return pContentRawDataNode->SetScriptContent( |
| 4263 | wsContent, wsXMLValue, bNotify, bScriptModify, bSyncData); |
| 4264 | } break; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4265 | case XFA_ObjectType::NodeC: |
| 4266 | case XFA_ObjectType::TextNode: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4267 | pNode = this; |
| 4268 | break; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4269 | case XFA_ObjectType::NodeV: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4270 | pNode = this; |
| 4271 | if (bSyncData && GetPacketID() == XFA_XDPPACKET_Form) { |
| 4272 | CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent); |
| 4273 | if (pParent) { |
| 4274 | pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent); |
| 4275 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4276 | if (pParent && pParent->GetElementType() == XFA_Element::Value) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4277 | pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent); |
| 4278 | if (pParent && pParent->IsContainerNode()) { |
| 4279 | pBindNode = pParent->GetBindData(); |
| 4280 | if (pBindNode) { |
| 4281 | pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4282 | bScriptModify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4283 | } |
| 4284 | } |
| 4285 | } |
| 4286 | } |
| 4287 | break; |
| 4288 | default: |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4289 | if (GetElementType() == XFA_Element::DataValue) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4290 | pNode = this; |
| 4291 | pBindNode = this; |
| 4292 | } |
| 4293 | break; |
| 4294 | } |
| 4295 | if (pNode) { |
| 4296 | SetAttributeValue(wsContent, wsXMLValue, bNotify, bScriptModify); |
| 4297 | if (pBindNode && bSyncData) { |
| 4298 | CXFA_NodeArray nodeArray; |
| 4299 | pBindNode->GetBindItems(nodeArray); |
| 4300 | for (int32_t i = 0; i < nodeArray.GetSize(); i++) { |
weili | db444d2 | 2016-06-02 15:48:15 -0700 | [diff] [blame] | 4301 | nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4302 | bScriptModify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4303 | } |
| 4304 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4305 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4306 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4307 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4308 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4309 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4310 | bool CXFA_Node::SetContent(const CFX_WideString& wsContent, |
| 4311 | const CFX_WideString& wsXMLValue, |
| 4312 | bool bNotify, |
| 4313 | bool bScriptModify, |
| 4314 | bool bSyncData) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4315 | return SetScriptContent(wsContent, wsXMLValue, bNotify, bScriptModify, |
| 4316 | bSyncData); |
| 4317 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4318 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4319 | CFX_WideString CXFA_Node::GetScriptContent(bool bScriptModify) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4320 | CFX_WideString wsContent; |
| 4321 | return TryContent(wsContent, bScriptModify) ? wsContent : CFX_WideString(); |
| 4322 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4323 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4324 | CFX_WideString CXFA_Node::GetContent() { |
| 4325 | return GetScriptContent(); |
| 4326 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4327 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4328 | bool CXFA_Node::TryContent(CFX_WideString& wsContent, |
| 4329 | bool bScriptModify, |
| 4330 | bool bProto) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4331 | CXFA_Node* pNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4332 | switch (GetObjectType()) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4333 | case XFA_ObjectType::ContainerNode: |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4334 | if (GetElementType() == XFA_Element::ExclGroup) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4335 | pNode = this; |
| 4336 | } else { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4337 | CXFA_Node* pValue = GetChild(0, XFA_Element::Value); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4338 | if (!pValue) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4339 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4340 | } |
| 4341 | CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 4342 | if (pChildValue && XFA_FieldIsMultiListBox(this)) { |
| 4343 | pChildValue->SetAttribute(XFA_ATTRIBUTE_ContentType, |
| 4344 | FX_WSTRC(L"text/xml")); |
| 4345 | } |
| 4346 | return pChildValue |
| 4347 | ? pChildValue->TryContent(wsContent, bScriptModify, bProto) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4348 | : false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4349 | } |
| 4350 | break; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4351 | case XFA_ObjectType::ContentNode: { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4352 | CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild); |
| 4353 | if (!pContentRawDataNode) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4354 | XFA_Element element = XFA_Element::Sharptext; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4355 | if (GetElementType() == XFA_Element::ExData) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4356 | CFX_WideString wsContentType; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4357 | GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false); |
tsepez | 9f2970c | 2016-04-01 10:23:04 -0700 | [diff] [blame] | 4358 | if (wsContentType == FX_WSTRC(L"text/html")) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4359 | element = XFA_Element::SharpxHTML; |
tsepez | 9f2970c | 2016-04-01 10:23:04 -0700 | [diff] [blame] | 4360 | } else if (wsContentType == FX_WSTRC(L"text/xml")) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4361 | element = XFA_Element::Sharpxml; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4362 | } |
| 4363 | } |
| 4364 | pContentRawDataNode = CreateSamePacketNode(element); |
| 4365 | InsertChild(pContentRawDataNode); |
| 4366 | } |
| 4367 | return pContentRawDataNode->TryContent(wsContent, bScriptModify, bProto); |
| 4368 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4369 | case XFA_ObjectType::NodeC: |
| 4370 | case XFA_ObjectType::NodeV: |
| 4371 | case XFA_ObjectType::TextNode: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4372 | pNode = this; |
| 4373 | default: |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4374 | if (GetElementType() == XFA_Element::DataValue) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4375 | pNode = this; |
| 4376 | } |
| 4377 | break; |
| 4378 | } |
| 4379 | if (pNode) { |
| 4380 | if (bScriptModify) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 4381 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4382 | if (pScriptContext) { |
| 4383 | m_pDocument->GetScriptContext()->AddNodesOfRunScript(this); |
| 4384 | } |
| 4385 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4386 | return TryCData(XFA_ATTRIBUTE_Value, wsContent, false, bProto); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4387 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4388 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4389 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4390 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4391 | CXFA_Node* CXFA_Node::GetModelNode() { |
| 4392 | switch (GetPacketID()) { |
| 4393 | case XFA_XDPPACKET_XDP: |
| 4394 | return m_pDocument->GetRoot(); |
| 4395 | case XFA_XDPPACKET_Config: |
| 4396 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config)); |
| 4397 | case XFA_XDPPACKET_Template: |
| 4398 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template)); |
| 4399 | case XFA_XDPPACKET_Form: |
| 4400 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)); |
| 4401 | case XFA_XDPPACKET_Datasets: |
| 4402 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets)); |
| 4403 | case XFA_XDPPACKET_LocaleSet: |
| 4404 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_LocaleSet)); |
| 4405 | case XFA_XDPPACKET_ConnectionSet: |
| 4406 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_ConnectionSet)); |
| 4407 | case XFA_XDPPACKET_SourceSet: |
| 4408 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_SourceSet)); |
| 4409 | case XFA_XDPPACKET_Xdc: |
| 4410 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Xdc)); |
| 4411 | default: |
| 4412 | return this; |
| 4413 | } |
| 4414 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4415 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4416 | bool CXFA_Node::TryNamespace(CFX_WideString& wsNamespace) { |
tsepez | 774bdde | 2016-04-14 09:49:44 -0700 | [diff] [blame] | 4417 | wsNamespace.clear(); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4418 | if (IsModelNode() || GetElementType() == XFA_Element::Packet) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4419 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4420 | if (!pXMLNode || pXMLNode->GetType() != FDE_XMLNODE_Element) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4421 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4422 | } |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4423 | static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4424 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4425 | } else if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4426 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4427 | if (!pXMLNode) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4428 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4429 | } |
| 4430 | if (pXMLNode->GetType() != FDE_XMLNODE_Element) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4431 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4432 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4433 | if (GetElementType() == XFA_Element::DataValue && |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4434 | GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData) { |
| 4435 | return XFA_FDEExtension_ResolveNamespaceQualifier( |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4436 | static_cast<CFDE_XMLElement*>(pXMLNode), |
| 4437 | GetCData(XFA_ATTRIBUTE_QualifiedName), wsNamespace); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4438 | } |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4439 | static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4440 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4441 | } else { |
| 4442 | CXFA_Node* pModelNode = GetModelNode(); |
| 4443 | return pModelNode->TryNamespace(wsNamespace); |
| 4444 | } |
| 4445 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4446 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4447 | CXFA_Node* CXFA_Node::GetProperty(int32_t index, |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4448 | XFA_Element eProperty, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4449 | bool bCreateProperty) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4450 | XFA_Element eType = GetElementType(); |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 4451 | uint32_t dwPacket = GetPacketID(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4452 | const XFA_PROPERTY* pProperty = |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4453 | XFA_GetPropertyOfElement(eType, eProperty, dwPacket); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4454 | if (!pProperty || index >= pProperty->uOccur) |
| 4455 | return nullptr; |
| 4456 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4457 | CXFA_Node* pNode = m_pChild; |
| 4458 | int32_t iCount = 0; |
| 4459 | for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4460 | if (pNode->GetElementType() == eProperty) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4461 | iCount++; |
| 4462 | if (iCount > index) { |
| 4463 | return pNode; |
| 4464 | } |
| 4465 | } |
| 4466 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4467 | if (!bCreateProperty) |
| 4468 | return nullptr; |
| 4469 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4470 | if (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf) { |
| 4471 | pNode = m_pChild; |
| 4472 | for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 4473 | const XFA_PROPERTY* pExistProperty = |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4474 | XFA_GetPropertyOfElement(eType, pNode->GetElementType(), dwPacket); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4475 | if (pExistProperty && (pExistProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) |
| 4476 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4477 | } |
| 4478 | } |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4479 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4480 | const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(dwPacket); |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 4481 | CXFA_Node* pNewNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4482 | for (; iCount <= index; iCount++) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4483 | pNewNode = m_pDocument->CreateNode(pPacket, eProperty); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4484 | if (!pNewNode) |
| 4485 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4486 | InsertChild(pNewNode, nullptr); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4487 | pNewNode->SetFlag(XFA_NodeFlag_Initialized, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4488 | } |
| 4489 | return pNewNode; |
| 4490 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4491 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4492 | int32_t CXFA_Node::CountChildren(XFA_Element eType, bool bOnlyChild) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4493 | CXFA_Node* pNode = m_pChild; |
| 4494 | int32_t iCount = 0; |
| 4495 | for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4496 | if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4497 | if (bOnlyChild) { |
| 4498 | const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement( |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4499 | GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4500 | if (pProperty) { |
| 4501 | continue; |
| 4502 | } |
| 4503 | } |
| 4504 | iCount++; |
| 4505 | } |
| 4506 | } |
| 4507 | return iCount; |
| 4508 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4509 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4510 | CXFA_Node* CXFA_Node::GetChild(int32_t index, |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4511 | XFA_Element eType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4512 | bool bOnlyChild) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4513 | ASSERT(index > -1); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4514 | CXFA_Node* pNode = m_pChild; |
| 4515 | int32_t iCount = 0; |
| 4516 | for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4517 | if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4518 | if (bOnlyChild) { |
| 4519 | const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement( |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4520 | GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4521 | if (pProperty) { |
| 4522 | continue; |
| 4523 | } |
| 4524 | } |
| 4525 | iCount++; |
| 4526 | if (iCount > index) { |
| 4527 | return pNode; |
| 4528 | } |
| 4529 | } |
| 4530 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4531 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4532 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4533 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4534 | int32_t CXFA_Node::InsertChild(int32_t index, CXFA_Node* pNode) { |
| 4535 | ASSERT(!pNode->m_pNext); |
| 4536 | pNode->m_pParent = this; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4537 | bool ret = m_pDocument->RemovePurgeNode(pNode); |
Wei Li | 5fe7ae7 | 2016-05-04 21:13:15 -0700 | [diff] [blame] | 4538 | ASSERT(ret); |
Wei Li | 439bb9e | 2016-05-05 00:35:26 -0700 | [diff] [blame] | 4539 | (void)ret; // Avoid unused variable warning. |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4540 | |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4541 | if (!m_pChild || index == 0) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4542 | if (index > 0) { |
| 4543 | return -1; |
| 4544 | } |
| 4545 | pNode->m_pNext = m_pChild; |
| 4546 | m_pChild = pNode; |
| 4547 | index = 0; |
| 4548 | } else if (index < 0) { |
| 4549 | m_pLastChild->m_pNext = pNode; |
| 4550 | } else { |
| 4551 | CXFA_Node* pPrev = m_pChild; |
| 4552 | int32_t iCount = 0; |
| 4553 | while (++iCount != index && pPrev->m_pNext) { |
| 4554 | pPrev = pPrev->m_pNext; |
| 4555 | } |
| 4556 | if (index > 0 && index != iCount) { |
| 4557 | return -1; |
| 4558 | } |
| 4559 | pNode->m_pNext = pPrev->m_pNext; |
| 4560 | pPrev->m_pNext = pNode; |
| 4561 | index = iCount; |
| 4562 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4563 | if (!pNode->m_pNext) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4564 | m_pLastChild = pNode; |
| 4565 | } |
| 4566 | ASSERT(m_pLastChild); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4567 | ASSERT(!m_pLastChild->m_pNext); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4568 | pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4569 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4570 | if (pNotify) |
| 4571 | pNotify->OnChildAdded(this); |
| 4572 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4573 | if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4574 | ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4575 | m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, index); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4576 | pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4577 | } |
| 4578 | return index; |
| 4579 | } |
weili | 6e1ae86 | 2016-05-04 18:25:27 -0700 | [diff] [blame] | 4580 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4581 | bool CXFA_Node::InsertChild(CXFA_Node* pNode, CXFA_Node* pBeforeNode) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4582 | if (!pNode || pNode->m_pParent || |
| 4583 | (pBeforeNode && pBeforeNode->m_pParent != this)) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4584 | ASSERT(false); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4585 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4586 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4587 | bool ret = m_pDocument->RemovePurgeNode(pNode); |
Wei Li | 5fe7ae7 | 2016-05-04 21:13:15 -0700 | [diff] [blame] | 4588 | ASSERT(ret); |
Wei Li | 439bb9e | 2016-05-05 00:35:26 -0700 | [diff] [blame] | 4589 | (void)ret; // Avoid unused variable warning. |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4590 | |
| 4591 | int32_t nIndex = -1; |
| 4592 | pNode->m_pParent = this; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4593 | if (!m_pChild || pBeforeNode == m_pChild) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4594 | pNode->m_pNext = m_pChild; |
| 4595 | m_pChild = pNode; |
| 4596 | nIndex = 0; |
| 4597 | } else if (!pBeforeNode) { |
| 4598 | pNode->m_pNext = m_pLastChild->m_pNext; |
| 4599 | m_pLastChild->m_pNext = pNode; |
| 4600 | } else { |
| 4601 | nIndex = 1; |
| 4602 | CXFA_Node* pPrev = m_pChild; |
| 4603 | while (pPrev->m_pNext != pBeforeNode) { |
| 4604 | pPrev = pPrev->m_pNext; |
| 4605 | nIndex++; |
| 4606 | } |
| 4607 | pNode->m_pNext = pPrev->m_pNext; |
| 4608 | pPrev->m_pNext = pNode; |
| 4609 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4610 | if (!pNode->m_pNext) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4611 | m_pLastChild = pNode; |
| 4612 | } |
| 4613 | ASSERT(m_pLastChild); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4614 | ASSERT(!m_pLastChild->m_pNext); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4615 | pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4616 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4617 | if (pNotify) |
| 4618 | pNotify->OnChildAdded(this); |
| 4619 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4620 | if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4621 | ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4622 | m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, nIndex); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4623 | pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4624 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4625 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4626 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4627 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4628 | CXFA_Node* CXFA_Node::Deprecated_GetPrevSibling() { |
| 4629 | if (!m_pParent) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4630 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4631 | } |
| 4632 | for (CXFA_Node* pSibling = m_pParent->m_pChild; pSibling; |
| 4633 | pSibling = pSibling->m_pNext) { |
| 4634 | if (pSibling->m_pNext == this) { |
| 4635 | return pSibling; |
| 4636 | } |
| 4637 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4638 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4639 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4640 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4641 | bool CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4642 | if (!pNode || pNode->m_pParent != this) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4643 | ASSERT(false); |
| 4644 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4645 | } |
| 4646 | if (m_pChild == pNode) { |
| 4647 | m_pChild = pNode->m_pNext; |
| 4648 | if (m_pLastChild == pNode) { |
| 4649 | m_pLastChild = pNode->m_pNext; |
| 4650 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4651 | pNode->m_pNext = nullptr; |
| 4652 | pNode->m_pParent = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4653 | } else { |
| 4654 | CXFA_Node* pPrev = pNode->Deprecated_GetPrevSibling(); |
| 4655 | pPrev->m_pNext = pNode->m_pNext; |
| 4656 | if (m_pLastChild == pNode) { |
| 4657 | m_pLastChild = pNode->m_pNext ? pNode->m_pNext : pPrev; |
| 4658 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4659 | pNode->m_pNext = nullptr; |
| 4660 | pNode->m_pParent = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4661 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4662 | ASSERT(!m_pLastChild || !m_pLastChild->m_pNext); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4663 | OnRemoved(bNotify); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4664 | pNode->SetFlag(XFA_NodeFlag_HasRemovedChildren, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4665 | m_pDocument->AddPurgeNode(pNode); |
| 4666 | if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) { |
| 4667 | if (pNode->IsAttributeInXML()) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4668 | ASSERT(pNode->m_pXMLNode == m_pXMLNode && |
| 4669 | m_pXMLNode->GetType() == FDE_XMLNODE_Element); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4670 | if (pNode->m_pXMLNode->GetType() == FDE_XMLNODE_Element) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4671 | CFDE_XMLElement* pXMLElement = |
| 4672 | static_cast<CFDE_XMLElement*>(pNode->m_pXMLNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4673 | CFX_WideStringC wsAttributeName = |
| 4674 | pNode->GetCData(XFA_ATTRIBUTE_QualifiedName); |
tsepez | 660956f | 2016-04-06 06:27:29 -0700 | [diff] [blame] | 4675 | pXMLElement->RemoveAttribute(wsAttributeName.c_str()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4676 | } |
| 4677 | CFX_WideString wsName; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4678 | pNode->GetAttribute(XFA_ATTRIBUTE_Name, wsName, false); |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4679 | CFDE_XMLElement* pNewXMLElement = new CFDE_XMLElement(wsName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4680 | CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value); |
| 4681 | if (!wsValue.IsEmpty()) { |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 4682 | pNewXMLElement->SetTextData(CFX_WideString(wsValue)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4683 | } |
| 4684 | pNode->m_pXMLNode = pNewXMLElement; |
| 4685 | pNode->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown); |
| 4686 | } else { |
| 4687 | m_pXMLNode->RemoveChildNode(pNode->m_pXMLNode); |
| 4688 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4689 | pNode->SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4690 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4691 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4692 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4693 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4694 | CXFA_Node* CXFA_Node::GetFirstChildByName(const CFX_WideStringC& wsName) const { |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 4695 | return GetFirstChildByName(FX_HashCode_GetW(wsName, false)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4696 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4697 | |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 4698 | CXFA_Node* CXFA_Node::GetFirstChildByName(uint32_t dwNameHash) const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4699 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode; |
| 4700 | pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 4701 | if (pNode->GetNameHash() == dwNameHash) { |
| 4702 | return pNode; |
| 4703 | } |
| 4704 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4705 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4706 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4707 | |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4708 | CXFA_Node* CXFA_Node::GetFirstChildByClass(XFA_Element eType) const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4709 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode; |
| 4710 | pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4711 | if (pNode->GetElementType() == eType) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4712 | return pNode; |
| 4713 | } |
| 4714 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4715 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4716 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4717 | |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 4718 | CXFA_Node* CXFA_Node::GetNextSameNameSibling(uint32_t dwNameHash) const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4719 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode; |
| 4720 | pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 4721 | if (pNode->GetNameHash() == dwNameHash) { |
| 4722 | return pNode; |
| 4723 | } |
| 4724 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4725 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4726 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4727 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4728 | CXFA_Node* CXFA_Node::GetNextSameNameSibling( |
| 4729 | const CFX_WideStringC& wsNodeName) const { |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 4730 | return GetNextSameNameSibling(FX_HashCode_GetW(wsNodeName, false)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4731 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4732 | |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4733 | CXFA_Node* CXFA_Node::GetNextSameClassSibling(XFA_Element eType) const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4734 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode; |
| 4735 | pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4736 | if (pNode->GetElementType() == eType) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4737 | return pNode; |
| 4738 | } |
| 4739 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4740 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4741 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4742 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4743 | int32_t CXFA_Node::GetNodeSameNameIndex() const { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 4744 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4745 | if (!pScriptContext) { |
| 4746 | return -1; |
| 4747 | } |
| 4748 | return pScriptContext->GetIndexByName(const_cast<CXFA_Node*>(this)); |
| 4749 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4750 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4751 | int32_t CXFA_Node::GetNodeSameClassIndex() const { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 4752 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4753 | if (!pScriptContext) { |
| 4754 | return -1; |
| 4755 | } |
| 4756 | return pScriptContext->GetIndexByClassName(const_cast<CXFA_Node*>(this)); |
| 4757 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4758 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4759 | void CXFA_Node::GetSOMExpression(CFX_WideString& wsSOMExpression) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 4760 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4761 | if (!pScriptContext) { |
| 4762 | return; |
| 4763 | } |
| 4764 | pScriptContext->GetSomExpression(this, wsSOMExpression); |
| 4765 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4766 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4767 | CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4768 | CXFA_Node* pInstanceMgr = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4769 | if (m_ePacket == XFA_XDPPACKET_Form) { |
| 4770 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4771 | if (!pParentNode || pParentNode->GetElementType() == XFA_Element::Area) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4772 | return pInstanceMgr; |
| 4773 | } |
| 4774 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; |
| 4775 | pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4776 | XFA_Element eType = pNode->GetElementType(); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4777 | if ((eType == XFA_Element::Subform || eType == XFA_Element::SubformSet) && |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4778 | pNode->m_dwNameHash != m_dwNameHash) { |
| 4779 | break; |
| 4780 | } |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4781 | if (eType == XFA_Element::InstanceManager) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4782 | CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name); |
| 4783 | CFX_WideStringC wsInstName = pNode->GetCData(XFA_ATTRIBUTE_Name); |
| 4784 | if (wsInstName.GetLength() > 0 && wsInstName.GetAt(0) == '_' && |
| 4785 | wsInstName.Mid(1) == wsName) { |
| 4786 | pInstanceMgr = pNode; |
| 4787 | } |
| 4788 | break; |
| 4789 | } |
| 4790 | } |
| 4791 | } |
| 4792 | return pInstanceMgr; |
| 4793 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4794 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4795 | CXFA_Node* CXFA_Node::GetOccurNode() { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4796 | return GetFirstChildByClass(XFA_Element::Occur); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4797 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4798 | |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4799 | bool CXFA_Node::HasFlag(XFA_NodeFlag dwFlag) const { |
| 4800 | if (m_uNodeFlags & dwFlag) |
| 4801 | return true; |
| 4802 | if (dwFlag == XFA_NodeFlag_HasRemovedChildren) |
| 4803 | return m_pParent && m_pParent->HasFlag(dwFlag); |
| 4804 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4805 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4806 | |
| 4807 | void CXFA_Node::SetFlag(uint32_t dwFlag, bool bNotify) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4808 | if (dwFlag == XFA_NodeFlag_Initialized && bNotify && !IsInitialized()) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4809 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4810 | if (pNotify) { |
| 4811 | pNotify->OnNodeReady(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4812 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4813 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4814 | m_uNodeFlags |= dwFlag; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4815 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4816 | |
| 4817 | void CXFA_Node::ClearFlag(uint32_t dwFlag) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4818 | m_uNodeFlags &= ~dwFlag; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4819 | } |
| 4820 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4821 | bool CXFA_Node::IsAttributeInXML() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4822 | return GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData; |
| 4823 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4824 | |
| 4825 | void CXFA_Node::OnRemoved(bool bNotify) { |
| 4826 | if (!bNotify) |
| 4827 | return; |
| 4828 | |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4829 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4830 | if (pNotify) |
| 4831 | pNotify->OnChildRemoved(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4832 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4833 | |
| 4834 | void CXFA_Node::OnChanging(XFA_ATTRIBUTE eAttr, bool bNotify) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4835 | if (bNotify && IsInitialized()) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4836 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4837 | if (pNotify) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4838 | pNotify->OnValueChanging(this, eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4839 | } |
| 4840 | } |
| 4841 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4842 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4843 | void CXFA_Node::OnChanged(XFA_ATTRIBUTE eAttr, |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4844 | bool bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4845 | bool bScriptModify) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4846 | if (bNotify && IsInitialized()) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4847 | Script_Attribute_SendAttributeChangeMessage(eAttr, bScriptModify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4848 | } |
| 4849 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4850 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4851 | int32_t CXFA_Node::execSingleEventByName(const CFX_WideStringC& wsEventName, |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4852 | XFA_Element eType) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4853 | int32_t iRet = XFA_EVENTERROR_NotExist; |
| 4854 | const XFA_ExecEventParaInfo* eventParaInfo = |
| 4855 | GetEventParaInfoByName(wsEventName); |
| 4856 | if (eventParaInfo) { |
| 4857 | uint32_t validFlags = eventParaInfo->m_validFlags; |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4858 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4859 | if (!pNotify) { |
| 4860 | return iRet; |
| 4861 | } |
| 4862 | if (validFlags == 1) { |
| 4863 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType); |
| 4864 | } else if (validFlags == 2) { |
| 4865 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4866 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4867 | } else if (validFlags == 3) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4868 | if (eType == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4869 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4870 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4871 | } |
| 4872 | } else if (validFlags == 4) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4873 | if (eType == XFA_Element::ExclGroup || eType == XFA_Element::Field) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4874 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4875 | if (pParentNode && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4876 | pParentNode->GetElementType() == XFA_Element::ExclGroup) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4877 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4878 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4879 | } |
| 4880 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4881 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4882 | } |
| 4883 | } else if (validFlags == 5) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4884 | if (eType == XFA_Element::Field) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4885 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4886 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4887 | } |
| 4888 | } else if (validFlags == 6) { |
| 4889 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 4890 | if (pWidgetData) { |
| 4891 | CXFA_Node* pUINode = pWidgetData->GetUIChild(); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4892 | if (pUINode->m_elementType == XFA_Element::Signature) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4893 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4894 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4895 | } |
| 4896 | } |
| 4897 | } else if (validFlags == 7) { |
| 4898 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 4899 | if (pWidgetData) { |
| 4900 | CXFA_Node* pUINode = pWidgetData->GetUIChild(); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4901 | if ((pUINode->m_elementType == XFA_Element::ChoiceList) && |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4902 | (!pWidgetData->IsListBox())) { |
| 4903 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4904 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4905 | } |
| 4906 | } |
| 4907 | } |
| 4908 | } |
| 4909 | return iRet; |
| 4910 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4911 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4912 | void CXFA_Node::UpdateNameHash() { |
| 4913 | const XFA_NOTSUREATTRIBUTE* pNotsure = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4914 | XFA_GetNotsureAttribute(GetElementType(), XFA_ATTRIBUTE_Name); |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 4915 | CFX_WideStringC wsName; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4916 | if (!pNotsure || pNotsure->eType == XFA_ATTRIBUTETYPE_Cdata) { |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 4917 | wsName = GetCData(XFA_ATTRIBUTE_Name); |
| 4918 | m_dwNameHash = FX_HashCode_GetW(wsName, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4919 | } else if (pNotsure->eType == XFA_ATTRIBUTETYPE_Enum) { |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 4920 | wsName = GetAttributeEnumByID(GetEnum(XFA_ATTRIBUTE_Name))->pName; |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 4921 | m_dwNameHash = FX_HashCode_GetW(wsName, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4922 | } |
| 4923 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4924 | |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4925 | CFDE_XMLNode* CXFA_Node::CreateXMLMappingNode() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4926 | if (!m_pXMLNode) { |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 4927 | CFX_WideString wsTag(GetCData(XFA_ATTRIBUTE_Name)); |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4928 | m_pXMLNode = new CFDE_XMLElement(wsTag); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4929 | SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4930 | } |
| 4931 | return m_pXMLNode; |
| 4932 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4933 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4934 | bool CXFA_Node::IsNeedSavingXMLNode() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4935 | return m_pXMLNode && (GetPacketID() == XFA_XDPPACKET_Datasets || |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4936 | GetElementType() == XFA_Element::Xfa); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4937 | } |
| 4938 | |
| 4939 | XFA_MAPMODULEDATA* CXFA_Node::CreateMapModuleData() { |
| 4940 | if (!m_pMapModuleData) |
| 4941 | m_pMapModuleData = new XFA_MAPMODULEDATA; |
| 4942 | return m_pMapModuleData; |
| 4943 | } |
| 4944 | |
| 4945 | XFA_MAPMODULEDATA* CXFA_Node::GetMapModuleData() const { |
| 4946 | return m_pMapModuleData; |
| 4947 | } |
| 4948 | |
| 4949 | void CXFA_Node::SetMapModuleValue(void* pKey, void* pValue) { |
| 4950 | XFA_MAPMODULEDATA* pModule = CreateMapModuleData(); |
| 4951 | pModule->m_ValueMap.SetAt(pKey, pValue); |
| 4952 | } |
| 4953 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4954 | bool CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4955 | CXFA_Node* pNode = this; |
| 4956 | while (pNode) { |
| 4957 | XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData(); |
| 4958 | if (pModule && pModule->m_ValueMap.Lookup(pKey, pValue)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4959 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4960 | } |
| 4961 | pNode = pNode->GetPacketID() != XFA_XDPPACKET_Datasets |
| 4962 | ? pNode->GetTemplateNode() |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4963 | : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4964 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4965 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4966 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4967 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4968 | void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) { |
tsepez | 660956f | 2016-04-06 06:27:29 -0700 | [diff] [blame] | 4969 | SetMapModuleBuffer(pKey, (void*)wsValue.c_str(), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4970 | wsValue.GetLength() * sizeof(FX_WCHAR)); |
| 4971 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4972 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4973 | bool CXFA_Node::GetMapModuleString(void* pKey, CFX_WideStringC& wsValue) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4974 | void* pValue; |
| 4975 | int32_t iBytes; |
| 4976 | if (!GetMapModuleBuffer(pKey, pValue, iBytes)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4977 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4978 | } |
| 4979 | wsValue = CFX_WideStringC((const FX_WCHAR*)pValue, iBytes / sizeof(FX_WCHAR)); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4980 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4981 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4982 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4983 | void CXFA_Node::SetMapModuleBuffer( |
| 4984 | void* pKey, |
| 4985 | void* pValue, |
| 4986 | int32_t iBytes, |
| 4987 | XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) { |
| 4988 | XFA_MAPMODULEDATA* pModule = CreateMapModuleData(); |
| 4989 | XFA_MAPDATABLOCK*& pBuffer = pModule->m_BufferMap[pKey]; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4990 | if (!pBuffer) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4991 | pBuffer = |
| 4992 | (XFA_MAPDATABLOCK*)FX_Alloc(uint8_t, sizeof(XFA_MAPDATABLOCK) + iBytes); |
| 4993 | } else if (pBuffer->iBytes != iBytes) { |
| 4994 | if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { |
| 4995 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
| 4996 | } |
| 4997 | pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(uint8_t, pBuffer, |
| 4998 | sizeof(XFA_MAPDATABLOCK) + iBytes); |
| 4999 | } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { |
| 5000 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
| 5001 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5002 | if (!pBuffer) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5003 | return; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5004 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5005 | pBuffer->pCallbackInfo = pCallbackInfo; |
| 5006 | pBuffer->iBytes = iBytes; |
| 5007 | FXSYS_memcpy(pBuffer->GetData(), pValue, iBytes); |
| 5008 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 5009 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5010 | bool CXFA_Node::GetMapModuleBuffer(void* pKey, |
| 5011 | void*& pValue, |
| 5012 | int32_t& iBytes, |
| 5013 | bool bProtoAlso) const { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5014 | XFA_MAPDATABLOCK* pBuffer = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5015 | const CXFA_Node* pNode = this; |
| 5016 | while (pNode) { |
| 5017 | XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData(); |
| 5018 | if (pModule && pModule->m_BufferMap.Lookup(pKey, pBuffer)) { |
| 5019 | break; |
| 5020 | } |
| 5021 | pNode = (bProtoAlso && pNode->GetPacketID() != XFA_XDPPACKET_Datasets) |
| 5022 | ? pNode->GetTemplateNode() |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5023 | : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5024 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5025 | if (!pBuffer) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5026 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5027 | } |
| 5028 | pValue = pBuffer->GetData(); |
| 5029 | iBytes = pBuffer->iBytes; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5030 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5031 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 5032 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5033 | bool CXFA_Node::HasMapModuleKey(void* pKey, bool bProtoAlso) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5034 | CXFA_Node* pNode = this; |
| 5035 | while (pNode) { |
| 5036 | void* pVal; |
| 5037 | XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData(); |
| 5038 | if (pModule && |
| 5039 | (pModule->m_ValueMap.Lookup(pKey, pVal) || |
| 5040 | pModule->m_BufferMap.Lookup(pKey, (XFA_MAPDATABLOCK*&)pVal))) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5041 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5042 | } |
| 5043 | pNode = (bProtoAlso && pNode->GetPacketID() != XFA_XDPPACKET_Datasets) |
| 5044 | ? pNode->GetTemplateNode() |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5045 | : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5046 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5047 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5048 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 5049 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5050 | void CXFA_Node::RemoveMapModuleKey(void* pKey) { |
| 5051 | XFA_MAPMODULEDATA* pModule = GetMapModuleData(); |
| 5052 | if (!pModule) |
| 5053 | return; |
| 5054 | |
| 5055 | if (pKey) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5056 | XFA_MAPDATABLOCK* pBuffer = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5057 | pModule->m_BufferMap.Lookup(pKey, pBuffer); |
| 5058 | if (pBuffer) { |
| 5059 | if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { |
| 5060 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
| 5061 | } |
| 5062 | FX_Free(pBuffer); |
| 5063 | } |
| 5064 | pModule->m_BufferMap.RemoveKey(pKey); |
| 5065 | pModule->m_ValueMap.RemoveKey(pKey); |
| 5066 | } else { |
| 5067 | XFA_MAPDATABLOCK* pBuffer; |
| 5068 | FX_POSITION posBuffer = pModule->m_BufferMap.GetStartPosition(); |
| 5069 | while (posBuffer) { |
| 5070 | pModule->m_BufferMap.GetNextAssoc(posBuffer, pKey, pBuffer); |
| 5071 | if (pBuffer) { |
| 5072 | if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { |
| 5073 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
| 5074 | } |
| 5075 | FX_Free(pBuffer); |
| 5076 | } |
| 5077 | } |
| 5078 | pModule->m_BufferMap.RemoveAll(); |
| 5079 | pModule->m_ValueMap.RemoveAll(); |
| 5080 | delete pModule; |
| 5081 | } |
| 5082 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 5083 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5084 | void CXFA_Node::MergeAllData(void* pDstModule, bool bUseSrcAttr) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5085 | XFA_MAPMODULEDATA* pDstModuleData = |
| 5086 | static_cast<CXFA_Node*>(pDstModule)->CreateMapModuleData(); |
| 5087 | XFA_MAPMODULEDATA* pSrcModuleData = GetMapModuleData(); |
| 5088 | if (!pSrcModuleData) { |
| 5089 | return; |
| 5090 | } |
| 5091 | FX_POSITION psValue = pSrcModuleData->m_ValueMap.GetStartPosition(); |
| 5092 | while (psValue) { |
| 5093 | void* pKey; |
| 5094 | void* pValue; |
| 5095 | pSrcModuleData->m_ValueMap.GetNextAssoc(psValue, pKey, pValue); |
| 5096 | if (bUseSrcAttr || !pDstModuleData->m_ValueMap.GetValueAt(pKey)) { |
| 5097 | pDstModuleData->m_ValueMap.SetAt(pKey, pValue); |
| 5098 | } |
| 5099 | } |
| 5100 | FX_POSITION psBuffer = pSrcModuleData->m_BufferMap.GetStartPosition(); |
| 5101 | while (psBuffer) { |
| 5102 | void* pKey; |
| 5103 | XFA_MAPDATABLOCK* pSrcBuffer; |
| 5104 | pSrcModuleData->m_BufferMap.GetNextAssoc(psBuffer, pKey, pSrcBuffer); |
| 5105 | XFA_MAPDATABLOCK*& pBuffer = pDstModuleData->m_BufferMap[pKey]; |
| 5106 | if (pBuffer && !bUseSrcAttr) { |
| 5107 | continue; |
| 5108 | } |
| 5109 | if (pSrcBuffer->pCallbackInfo && pSrcBuffer->pCallbackInfo->pFree && |
| 5110 | !pSrcBuffer->pCallbackInfo->pCopy) { |
| 5111 | if (pBuffer) { |
| 5112 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
| 5113 | pDstModuleData->m_BufferMap.RemoveKey(pKey); |
| 5114 | } |
| 5115 | continue; |
| 5116 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5117 | if (!pBuffer) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5118 | pBuffer = (XFA_MAPDATABLOCK*)FX_Alloc( |
| 5119 | uint8_t, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes); |
| 5120 | } else if (pBuffer->iBytes != pSrcBuffer->iBytes) { |
| 5121 | if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { |
| 5122 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
| 5123 | } |
| 5124 | pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc( |
| 5125 | uint8_t, pBuffer, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes); |
| 5126 | } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { |
| 5127 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
| 5128 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5129 | if (!pBuffer) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5130 | continue; |
| 5131 | } |
| 5132 | pBuffer->pCallbackInfo = pSrcBuffer->pCallbackInfo; |
| 5133 | pBuffer->iBytes = pSrcBuffer->iBytes; |
| 5134 | FXSYS_memcpy(pBuffer->GetData(), pSrcBuffer->GetData(), pSrcBuffer->iBytes); |
| 5135 | if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pCopy) { |
| 5136 | pBuffer->pCallbackInfo->pCopy(*(void**)pBuffer->GetData()); |
| 5137 | } |
| 5138 | } |
| 5139 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 5140 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5141 | void CXFA_Node::MoveBufferMapData(CXFA_Node* pDstModule, void* pKey) { |
| 5142 | if (!pDstModule) { |
| 5143 | return; |
| 5144 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5145 | bool bNeedMove = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5146 | if (!pKey) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5147 | bNeedMove = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5148 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 5149 | if (pDstModule->GetElementType() != GetElementType()) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5150 | bNeedMove = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5151 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5152 | XFA_MAPMODULEDATA* pSrcModuleData = nullptr; |
| 5153 | XFA_MAPMODULEDATA* pDstModuleData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5154 | if (bNeedMove) { |
| 5155 | pSrcModuleData = GetMapModuleData(); |
| 5156 | if (!pSrcModuleData) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5157 | bNeedMove = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5158 | } |
| 5159 | pDstModuleData = pDstModule->CreateMapModuleData(); |
| 5160 | } |
| 5161 | if (bNeedMove) { |
| 5162 | void* pBufferBlockData = pSrcModuleData->m_BufferMap.GetValueAt(pKey); |
| 5163 | if (pBufferBlockData) { |
| 5164 | pSrcModuleData->m_BufferMap.RemoveKey(pKey); |
| 5165 | pDstModuleData->m_BufferMap.RemoveKey(pKey); |
| 5166 | pDstModuleData->m_BufferMap.SetAt(pKey, |
| 5167 | (XFA_MAPDATABLOCK*)pBufferBlockData); |
| 5168 | } |
| 5169 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 5170 | if (pDstModule->IsNodeV()) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5171 | CFX_WideString wsValue = pDstModule->GetScriptContent(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5172 | CFX_WideString wsFormatValue(wsValue); |
| 5173 | CXFA_WidgetData* pWidgetData = pDstModule->GetContainerWidgetData(); |
| 5174 | if (pWidgetData) { |
tsepez | 6f167c3 | 2016-04-14 15:46:27 -0700 | [diff] [blame] | 5175 | pWidgetData->GetFormatDataValue(wsValue, wsFormatValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5176 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5177 | pDstModule->SetScriptContent(wsValue, wsFormatValue, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5178 | } |
| 5179 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 5180 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5181 | void CXFA_Node::MoveBufferMapData(CXFA_Node* pSrcModule, |
| 5182 | CXFA_Node* pDstModule, |
| 5183 | void* pKey, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5184 | bool bRecursive) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5185 | if (!pSrcModule || !pDstModule || !pKey) { |
| 5186 | return; |
| 5187 | } |
| 5188 | if (bRecursive) { |
| 5189 | CXFA_Node* pSrcChild = pSrcModule->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 5190 | CXFA_Node* pDstChild = pDstModule->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 5191 | for (; pSrcChild && pDstChild; |
| 5192 | pSrcChild = pSrcChild->GetNodeItem(XFA_NODEITEM_NextSibling), |
| 5193 | pDstChild = pDstChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5194 | MoveBufferMapData(pSrcChild, pDstChild, pKey, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5195 | } |
| 5196 | } |
| 5197 | pSrcModule->MoveBufferMapData(pDstModule, pKey); |
| 5198 | } |