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> |
Tom Sepez | d4db58f | 2017-03-02 14:57:59 -0800 | [diff] [blame^] | 11 | #include <unordered_set> |
Dan Sinclair | 85c8e7f | 2016-11-21 13:50:32 -0500 | [diff] [blame] | 12 | #include <utility> |
tsepez | 51709be | 2016-12-08 10:55:57 -0800 | [diff] [blame] | 13 | #include <vector> |
tsepez | aadedf9 | 2016-05-12 10:08:06 -0700 | [diff] [blame] | 14 | |
dsinclair | a52ab74 | 2016-09-29 13:59:29 -0700 | [diff] [blame] | 15 | #include "core/fxcrt/fx_ext.h" |
dsinclair | 4355468 | 2016-09-29 17:29:48 -0700 | [diff] [blame] | 16 | #include "fxjs/cfxjse_value.h" |
tsepez | a9caab9 | 2016-12-14 05:57:10 -0800 | [diff] [blame] | 17 | #include "third_party/base/ptr_util.h" |
tsepez | aadedf9 | 2016-05-12 10:08:06 -0700 | [diff] [blame] | 18 | #include "third_party/base/stl_util.h" |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 19 | #include "xfa/fde/xml/fde_xml_imp.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 20 | #include "xfa/fgas/crt/fgas_codepage.h" |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 21 | #include "xfa/fxfa/app/xfa_ffnotify.h" |
dsinclair | 5b49309 | 2016-09-29 20:20:24 -0700 | [diff] [blame] | 22 | #include "xfa/fxfa/cxfa_eventparam.h" |
dsinclair | 1628024 | 2016-07-21 12:03:47 -0700 | [diff] [blame] | 23 | #include "xfa/fxfa/parser/cxfa_document.h" |
dsinclair | 0b851ff | 2016-07-21 12:03:01 -0700 | [diff] [blame] | 24 | #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 25 | #include "xfa/fxfa/parser/cxfa_measurement.h" |
dsinclair | 44d054c | 2016-04-06 10:23:46 -0700 | [diff] [blame] | 26 | #include "xfa/fxfa/parser/cxfa_occur.h" |
dsinclair | 31f8740 | 2016-07-20 06:34:45 -0700 | [diff] [blame] | 27 | #include "xfa/fxfa/parser/cxfa_scriptcontext.h" |
dsinclair | 34f86b0 | 2016-07-11 08:42:33 -0700 | [diff] [blame] | 28 | #include "xfa/fxfa/parser/cxfa_simple_parser.h" |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 29 | #include "xfa/fxfa/parser/xfa_basic_data.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 30 | |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 31 | namespace { |
| 32 | |
| 33 | void XFA_DeleteWideString(void* pData) { |
| 34 | delete static_cast<CFX_WideString*>(pData); |
| 35 | } |
| 36 | |
| 37 | void XFA_CopyWideString(void*& pData) { |
| 38 | if (pData) { |
| 39 | CFX_WideString* pNewData = new CFX_WideString(*(CFX_WideString*)pData); |
| 40 | pData = pNewData; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | XFA_MAPDATABLOCKCALLBACKINFO deleteWideStringCallBack = {XFA_DeleteWideString, |
| 45 | XFA_CopyWideString}; |
| 46 | |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 47 | void XFA_DataNodeDeleteBindItem(void* pData) { |
| 48 | delete static_cast<CXFA_NodeArray*>(pData); |
| 49 | } |
| 50 | |
| 51 | XFA_MAPDATABLOCKCALLBACKINFO deleteBindItemCallBack = { |
| 52 | XFA_DataNodeDeleteBindItem, nullptr}; |
| 53 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 54 | int32_t GetCount(CXFA_Node* pInstMgrNode) { |
| 55 | ASSERT(pInstMgrNode); |
| 56 | int32_t iCount = 0; |
| 57 | uint32_t dwNameHash = 0; |
| 58 | for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 59 | pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 60 | XFA_Element eCurType = pNode->GetElementType(); |
| 61 | if (eCurType == XFA_Element::InstanceManager) |
| 62 | break; |
| 63 | if ((eCurType != XFA_Element::Subform) && |
| 64 | (eCurType != XFA_Element::SubformSet)) { |
| 65 | continue; |
| 66 | } |
| 67 | if (iCount == 0) { |
| 68 | CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name); |
| 69 | CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name); |
| 70 | if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' || |
| 71 | wsInstName.Mid(1) != wsName) { |
| 72 | return iCount; |
| 73 | } |
| 74 | dwNameHash = pNode->GetNameHash(); |
| 75 | } |
| 76 | if (dwNameHash != pNode->GetNameHash()) |
| 77 | break; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 78 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 79 | iCount++; |
| 80 | } |
| 81 | return iCount; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 82 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 83 | |
Tom Sepez | d4db58f | 2017-03-02 14:57:59 -0800 | [diff] [blame^] | 84 | void SortNodeArrayByDocumentIdx(const std::unordered_set<CXFA_Node*>& rgNodeSet, |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 85 | CXFA_NodeArray& rgNodeArray, |
| 86 | CFX_ArrayTemplate<int32_t>& rgIdxArray) { |
| 87 | int32_t iCount = pdfium::CollectionSize<int32_t>(rgNodeSet); |
| 88 | rgNodeArray.SetSize(iCount); |
| 89 | rgIdxArray.SetSize(iCount); |
| 90 | if (iCount == 0) |
| 91 | return; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 92 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 93 | int32_t iIndex = -1; |
| 94 | int32_t iTotalIndex = -1; |
| 95 | CXFA_Node* pCommonParent = |
| 96 | (*rgNodeSet.begin())->GetNodeItem(XFA_NODEITEM_Parent); |
| 97 | for (CXFA_Node* pNode = pCommonParent->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 98 | pNode && iIndex < iCount; |
| 99 | pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 100 | iTotalIndex++; |
| 101 | if (pdfium::ContainsValue(rgNodeSet, pNode)) { |
| 102 | iIndex++; |
| 103 | rgNodeArray[iIndex] = pNode; |
| 104 | rgIdxArray[iIndex] = iTotalIndex; |
| 105 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 106 | } |
| 107 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 108 | |
Tom Sepez | d4db58f | 2017-03-02 14:57:59 -0800 | [diff] [blame^] | 109 | using CXFA_NodeSetPair = |
| 110 | std::pair<std::unordered_set<CXFA_Node*>, std::unordered_set<CXFA_Node*>>; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 111 | using CXFA_NodeSetPairMap = |
| 112 | std::map<uint32_t, std::unique_ptr<CXFA_NodeSetPair>>; |
| 113 | using CXFA_NodeSetPairMapMap = |
| 114 | std::map<CXFA_Node*, std::unique_ptr<CXFA_NodeSetPairMap>>; |
| 115 | |
| 116 | CXFA_NodeSetPair* NodeSetPairForNode(CXFA_Node* pNode, |
| 117 | CXFA_NodeSetPairMapMap* pMap) { |
| 118 | CXFA_Node* pParentNode = pNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 119 | uint32_t dwNameHash = pNode->GetNameHash(); |
| 120 | if (!pParentNode || !dwNameHash) |
| 121 | return nullptr; |
| 122 | |
| 123 | if (!(*pMap)[pParentNode]) |
tsepez | a9caab9 | 2016-12-14 05:57:10 -0800 | [diff] [blame] | 124 | (*pMap)[pParentNode] = pdfium::MakeUnique<CXFA_NodeSetPairMap>(); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 125 | |
| 126 | CXFA_NodeSetPairMap* pNodeSetPairMap = (*pMap)[pParentNode].get(); |
| 127 | if (!(*pNodeSetPairMap)[dwNameHash]) |
tsepez | a9caab9 | 2016-12-14 05:57:10 -0800 | [diff] [blame] | 128 | (*pNodeSetPairMap)[dwNameHash] = pdfium::MakeUnique<CXFA_NodeSetPair>(); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 129 | |
| 130 | return (*pNodeSetPairMap)[dwNameHash].get(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 131 | } |
| 132 | |
Tom Sepez | d4db58f | 2017-03-02 14:57:59 -0800 | [diff] [blame^] | 133 | void ReorderDataNodes(const std::unordered_set<CXFA_Node*>& sSet1, |
| 134 | const std::unordered_set<CXFA_Node*>& sSet2, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 135 | bool bInsertBefore) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 136 | CXFA_NodeSetPairMapMap rgMap; |
| 137 | for (CXFA_Node* pNode : sSet1) { |
| 138 | CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap); |
| 139 | if (pNodeSetPair) |
| 140 | pNodeSetPair->first.insert(pNode); |
| 141 | } |
| 142 | for (CXFA_Node* pNode : sSet2) { |
| 143 | CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap); |
| 144 | if (pNodeSetPair) { |
| 145 | if (pdfium::ContainsValue(pNodeSetPair->first, pNode)) |
| 146 | pNodeSetPair->first.erase(pNode); |
| 147 | else |
| 148 | pNodeSetPair->second.insert(pNode); |
| 149 | } |
| 150 | } |
| 151 | for (const auto& iter1 : rgMap) { |
| 152 | CXFA_NodeSetPairMap* pNodeSetPairMap = iter1.second.get(); |
| 153 | if (!pNodeSetPairMap) |
| 154 | continue; |
| 155 | |
| 156 | for (const auto& iter2 : *pNodeSetPairMap) { |
| 157 | CXFA_NodeSetPair* pNodeSetPair = iter2.second.get(); |
| 158 | if (!pNodeSetPair) |
| 159 | continue; |
| 160 | if (!pNodeSetPair->first.empty() && !pNodeSetPair->second.empty()) { |
| 161 | CXFA_NodeArray rgNodeArray1; |
| 162 | CXFA_NodeArray rgNodeArray2; |
| 163 | CFX_ArrayTemplate<int32_t> rgIdxArray1; |
| 164 | CFX_ArrayTemplate<int32_t> rgIdxArray2; |
| 165 | SortNodeArrayByDocumentIdx(pNodeSetPair->first, rgNodeArray1, |
| 166 | rgIdxArray1); |
| 167 | SortNodeArrayByDocumentIdx(pNodeSetPair->second, rgNodeArray2, |
| 168 | rgIdxArray2); |
| 169 | CXFA_Node* pParentNode = nullptr; |
| 170 | CXFA_Node* pBeforeNode = nullptr; |
| 171 | if (bInsertBefore) { |
| 172 | pBeforeNode = rgNodeArray2[0]; |
| 173 | pParentNode = pBeforeNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 174 | } else { |
| 175 | CXFA_Node* pLastNode = rgNodeArray2[rgIdxArray2.GetSize() - 1]; |
| 176 | pParentNode = pLastNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 177 | pBeforeNode = pLastNode->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 178 | } |
| 179 | for (int32_t iIdx = 0; iIdx < rgIdxArray1.GetSize(); iIdx++) { |
| 180 | CXFA_Node* pCurNode = rgNodeArray1[iIdx]; |
| 181 | pParentNode->RemoveChild(pCurNode); |
| 182 | pParentNode->InsertChild(pCurNode, pBeforeNode); |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | pNodeSetPairMap->clear(); |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | CXFA_Node* GetItem(CXFA_Node* pInstMgrNode, int32_t iIndex) { |
| 191 | ASSERT(pInstMgrNode); |
| 192 | int32_t iCount = 0; |
| 193 | uint32_t dwNameHash = 0; |
| 194 | for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 195 | pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 196 | XFA_Element eCurType = pNode->GetElementType(); |
| 197 | if (eCurType == XFA_Element::InstanceManager) |
| 198 | break; |
| 199 | if ((eCurType != XFA_Element::Subform) && |
| 200 | (eCurType != XFA_Element::SubformSet)) { |
| 201 | continue; |
| 202 | } |
| 203 | if (iCount == 0) { |
| 204 | CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name); |
| 205 | CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name); |
| 206 | if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' || |
| 207 | wsInstName.Mid(1) != wsName) { |
| 208 | return nullptr; |
| 209 | } |
| 210 | dwNameHash = pNode->GetNameHash(); |
| 211 | } |
| 212 | if (dwNameHash != pNode->GetNameHash()) |
| 213 | break; |
| 214 | |
| 215 | iCount++; |
| 216 | if (iCount > iIndex) |
| 217 | return pNode; |
| 218 | } |
| 219 | return nullptr; |
| 220 | } |
| 221 | |
| 222 | void InsertItem(CXFA_Node* pInstMgrNode, |
| 223 | CXFA_Node* pNewInstance, |
| 224 | int32_t iPos, |
| 225 | int32_t iCount = -1, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 226 | bool bMoveDataBindingNodes = true) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 227 | if (iCount < 0) |
| 228 | iCount = GetCount(pInstMgrNode); |
| 229 | if (iPos < 0) |
| 230 | iPos = iCount; |
| 231 | if (iPos == iCount) { |
| 232 | CXFA_Node* pNextSibling = |
| 233 | iCount > 0 |
| 234 | ? GetItem(pInstMgrNode, iCount - 1) |
| 235 | ->GetNodeItem(XFA_NODEITEM_NextSibling) |
| 236 | : pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 237 | pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent) |
| 238 | ->InsertChild(pNewInstance, pNextSibling); |
| 239 | if (bMoveDataBindingNodes) { |
Tom Sepez | d4db58f | 2017-03-02 14:57:59 -0800 | [diff] [blame^] | 240 | std::unordered_set<CXFA_Node*> sNew; |
| 241 | std::unordered_set<CXFA_Node*> sAfter; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 242 | CXFA_NodeIteratorTemplate<CXFA_Node, |
| 243 | CXFA_TraverseStrategy_XFAContainerNode> |
| 244 | sIteratorNew(pNewInstance); |
| 245 | for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode; |
| 246 | pNode = sIteratorNew.MoveToNext()) { |
| 247 | CXFA_Node* pDataNode = pNode->GetBindData(); |
| 248 | if (!pDataNode) |
| 249 | continue; |
| 250 | |
| 251 | sNew.insert(pDataNode); |
| 252 | } |
| 253 | CXFA_NodeIteratorTemplate<CXFA_Node, |
| 254 | CXFA_TraverseStrategy_XFAContainerNode> |
| 255 | sIteratorAfter(pNextSibling); |
| 256 | for (CXFA_Node* pNode = sIteratorAfter.GetCurrent(); pNode; |
| 257 | pNode = sIteratorAfter.MoveToNext()) { |
| 258 | CXFA_Node* pDataNode = pNode->GetBindData(); |
| 259 | if (!pDataNode) |
| 260 | continue; |
| 261 | |
| 262 | sAfter.insert(pDataNode); |
| 263 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 264 | ReorderDataNodes(sNew, sAfter, false); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 265 | } |
| 266 | } else { |
| 267 | CXFA_Node* pBeforeInstance = GetItem(pInstMgrNode, iPos); |
| 268 | pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent) |
| 269 | ->InsertChild(pNewInstance, pBeforeInstance); |
| 270 | if (bMoveDataBindingNodes) { |
Tom Sepez | d4db58f | 2017-03-02 14:57:59 -0800 | [diff] [blame^] | 271 | std::unordered_set<CXFA_Node*> sNew; |
| 272 | std::unordered_set<CXFA_Node*> sBefore; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 273 | CXFA_NodeIteratorTemplate<CXFA_Node, |
| 274 | CXFA_TraverseStrategy_XFAContainerNode> |
| 275 | sIteratorNew(pNewInstance); |
| 276 | for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode; |
| 277 | pNode = sIteratorNew.MoveToNext()) { |
| 278 | CXFA_Node* pDataNode = pNode->GetBindData(); |
| 279 | if (!pDataNode) |
| 280 | continue; |
| 281 | |
| 282 | sNew.insert(pDataNode); |
| 283 | } |
| 284 | CXFA_NodeIteratorTemplate<CXFA_Node, |
| 285 | CXFA_TraverseStrategy_XFAContainerNode> |
| 286 | sIteratorBefore(pBeforeInstance); |
| 287 | for (CXFA_Node* pNode = sIteratorBefore.GetCurrent(); pNode; |
| 288 | pNode = sIteratorBefore.MoveToNext()) { |
| 289 | CXFA_Node* pDataNode = pNode->GetBindData(); |
| 290 | if (!pDataNode) |
| 291 | continue; |
| 292 | |
| 293 | sBefore.insert(pDataNode); |
| 294 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 295 | ReorderDataNodes(sNew, sBefore, true); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | void RemoveItem(CXFA_Node* pInstMgrNode, |
| 301 | CXFA_Node* pRemoveInstance, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 302 | bool bRemoveDataBinding = true) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 303 | pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)->RemoveChild(pRemoveInstance); |
| 304 | if (!bRemoveDataBinding) |
| 305 | return; |
| 306 | |
| 307 | CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFAContainerNode> |
| 308 | sIterator(pRemoveInstance); |
| 309 | for (CXFA_Node* pFormNode = sIterator.GetCurrent(); pFormNode; |
| 310 | pFormNode = sIterator.MoveToNext()) { |
| 311 | CXFA_Node* pDataNode = pFormNode->GetBindData(); |
| 312 | if (!pDataNode) |
| 313 | continue; |
| 314 | |
| 315 | if (pDataNode->RemoveBindItem(pFormNode) == 0) { |
| 316 | if (CXFA_Node* pDataParent = |
| 317 | pDataNode->GetNodeItem(XFA_NODEITEM_Parent)) { |
| 318 | pDataParent->RemoveChild(pDataNode); |
| 319 | } |
| 320 | } |
| 321 | pFormNode->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr); |
| 322 | } |
| 323 | } |
| 324 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 325 | CXFA_Node* CreateInstance(CXFA_Node* pInstMgrNode, bool bDataMerge) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 326 | CXFA_Document* pDocument = pInstMgrNode->GetDocument(); |
| 327 | CXFA_Node* pTemplateNode = pInstMgrNode->GetTemplateNode(); |
| 328 | CXFA_Node* pFormParent = pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 329 | CXFA_Node* pDataScope = nullptr; |
| 330 | for (CXFA_Node* pRootBoundNode = pFormParent; |
| 331 | pRootBoundNode && pRootBoundNode->IsContainerNode(); |
| 332 | pRootBoundNode = pRootBoundNode->GetNodeItem(XFA_NODEITEM_Parent)) { |
| 333 | pDataScope = pRootBoundNode->GetBindData(); |
| 334 | if (pDataScope) |
| 335 | break; |
| 336 | } |
| 337 | if (!pDataScope) { |
| 338 | pDataScope = ToNode(pDocument->GetXFAObject(XFA_HASHCODE_Record)); |
| 339 | ASSERT(pDataScope); |
| 340 | } |
| 341 | CXFA_Node* pInstance = pDocument->DataMerge_CopyContainer( |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 342 | pTemplateNode, pFormParent, pDataScope, true, bDataMerge, true); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 343 | if (pInstance) { |
| 344 | pDocument->DataMerge_UpdateBindingRelations(pInstance); |
| 345 | pFormParent->RemoveChild(pInstance); |
| 346 | } |
| 347 | return pInstance; |
| 348 | } |
| 349 | |
| 350 | struct XFA_ExecEventParaInfo { |
| 351 | public: |
| 352 | uint32_t m_uHash; |
| 353 | const FX_WCHAR* m_lpcEventName; |
| 354 | XFA_EVENTTYPE m_eventType; |
| 355 | uint32_t m_validFlags; |
| 356 | }; |
| 357 | static const XFA_ExecEventParaInfo gs_eventParaInfos[] = { |
| 358 | {0x02a6c55a, L"postSubmit", XFA_EVENT_PostSubmit, 0}, |
| 359 | {0x0ab466bb, L"preSubmit", XFA_EVENT_PreSubmit, 0}, |
| 360 | {0x109d7ce7, L"mouseEnter", XFA_EVENT_MouseEnter, 5}, |
| 361 | {0x17fad373, L"postPrint", XFA_EVENT_PostPrint, 0}, |
| 362 | {0x1bfc72d9, L"preOpen", XFA_EVENT_PreOpen, 7}, |
| 363 | {0x2196a452, L"initialize", XFA_EVENT_Initialize, 1}, |
| 364 | {0x27410f03, L"mouseExit", XFA_EVENT_MouseExit, 5}, |
| 365 | {0x33c43dec, L"docClose", XFA_EVENT_DocClose, 0}, |
| 366 | {0x361fa1b6, L"preSave", XFA_EVENT_PreSave, 0}, |
| 367 | {0x36f1c6d8, L"preSign", XFA_EVENT_PreSign, 6}, |
| 368 | {0x4731d6ba, L"exit", XFA_EVENT_Exit, 2}, |
| 369 | {0x56bf456b, L"docReady", XFA_EVENT_DocReady, 0}, |
| 370 | {0x7233018a, L"validate", XFA_EVENT_Validate, 1}, |
| 371 | {0x8808385e, L"indexChange", XFA_EVENT_IndexChange, 3}, |
| 372 | {0x891f4606, L"change", XFA_EVENT_Change, 4}, |
| 373 | {0x9528a7b4, L"prePrint", XFA_EVENT_PrePrint, 0}, |
| 374 | {0x9f693b21, L"mouseDown", XFA_EVENT_MouseDown, 5}, |
| 375 | {0xcdce56b3, L"full", XFA_EVENT_Full, 4}, |
| 376 | {0xd576d08e, L"mouseUp", XFA_EVENT_MouseUp, 5}, |
| 377 | {0xd95657a6, L"click", XFA_EVENT_Click, 4}, |
| 378 | {0xdbfbe02e, L"calculate", XFA_EVENT_Calculate, 1}, |
| 379 | {0xe25fa7b8, L"postOpen", XFA_EVENT_PostOpen, 7}, |
| 380 | {0xe28dce7e, L"enter", XFA_EVENT_Enter, 2}, |
| 381 | {0xfc82d695, L"postSave", XFA_EVENT_PostSave, 0}, |
| 382 | {0xfd54fbb7, L"postSign", XFA_EVENT_PostSign, 6}, |
| 383 | }; |
| 384 | |
| 385 | const XFA_ExecEventParaInfo* GetEventParaInfoByName( |
| 386 | const CFX_WideStringC& wsEventName) { |
| 387 | uint32_t uHash = FX_HashCode_GetW(wsEventName, false); |
| 388 | int32_t iStart = 0; |
| 389 | int32_t iEnd = (sizeof(gs_eventParaInfos) / sizeof(gs_eventParaInfos[0])) - 1; |
| 390 | do { |
| 391 | int32_t iMid = (iStart + iEnd) / 2; |
| 392 | const XFA_ExecEventParaInfo* eventParaInfo = &gs_eventParaInfos[iMid]; |
| 393 | if (uHash == eventParaInfo->m_uHash) |
| 394 | return eventParaInfo; |
| 395 | if (uHash < eventParaInfo->m_uHash) |
| 396 | iEnd = iMid - 1; |
| 397 | else |
| 398 | iStart = iMid + 1; |
| 399 | } while (iStart <= iEnd); |
| 400 | return nullptr; |
| 401 | } |
| 402 | |
| 403 | void StrToRGB(const CFX_WideString& strRGB, |
| 404 | int32_t& r, |
| 405 | int32_t& g, |
| 406 | int32_t& b) { |
| 407 | r = 0; |
| 408 | g = 0; |
| 409 | b = 0; |
| 410 | |
| 411 | FX_WCHAR zero = '0'; |
| 412 | int32_t iIndex = 0; |
| 413 | int32_t iLen = strRGB.GetLength(); |
| 414 | for (int32_t i = 0; i < iLen; ++i) { |
| 415 | FX_WCHAR ch = strRGB.GetAt(i); |
| 416 | if (ch == L',') |
| 417 | ++iIndex; |
| 418 | if (iIndex > 2) |
| 419 | break; |
| 420 | |
| 421 | int32_t iValue = ch - zero; |
| 422 | if (iValue >= 0 && iValue <= 9) { |
| 423 | switch (iIndex) { |
| 424 | case 0: |
| 425 | r = r * 10 + iValue; |
| 426 | break; |
| 427 | case 1: |
| 428 | g = g * 10 + iValue; |
| 429 | break; |
| 430 | default: |
| 431 | b = b * 10 + iValue; |
| 432 | break; |
| 433 | } |
| 434 | } |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | enum XFA_KEYTYPE { |
| 439 | XFA_KEYTYPE_Custom, |
| 440 | XFA_KEYTYPE_Element, |
| 441 | }; |
| 442 | |
| 443 | void* GetMapKey_Custom(const CFX_WideStringC& wsKey) { |
| 444 | uint32_t dwKey = FX_HashCode_GetW(wsKey, false); |
| 445 | return (void*)(uintptr_t)((dwKey << 1) | XFA_KEYTYPE_Custom); |
| 446 | } |
| 447 | |
| 448 | void* GetMapKey_Element(XFA_Element eType, XFA_ATTRIBUTE eAttribute) { |
| 449 | return (void*)(uintptr_t)((static_cast<int32_t>(eType) << 16) | |
| 450 | (eAttribute << 8) | XFA_KEYTYPE_Element); |
| 451 | } |
| 452 | |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 453 | const XFA_ATTRIBUTEINFO* GetAttributeOfElement(XFA_Element eElement, |
| 454 | XFA_ATTRIBUTE eAttribute, |
| 455 | uint32_t dwPacket) { |
| 456 | int32_t iCount = 0; |
| 457 | const uint8_t* pAttr = XFA_GetElementAttributes(eElement, iCount); |
| 458 | if (!pAttr || iCount < 1) |
| 459 | return nullptr; |
| 460 | |
| 461 | if (!std::binary_search(pAttr, pAttr + iCount, eAttribute)) |
| 462 | return nullptr; |
| 463 | |
| 464 | const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttribute); |
| 465 | ASSERT(pInfo); |
| 466 | if (dwPacket == XFA_XDPPACKET_UNKNOWN) |
| 467 | return pInfo; |
| 468 | return (dwPacket & pInfo->dwPackets) ? pInfo : nullptr; |
| 469 | } |
| 470 | |
| 471 | const XFA_ATTRIBUTEENUMINFO* GetAttributeEnumByID(XFA_ATTRIBUTEENUM eName) { |
| 472 | return g_XFAEnumData + eName; |
| 473 | } |
| 474 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 475 | } // namespace |
| 476 | |
| 477 | static void XFA_DefaultFreeData(void* pData) {} |
| 478 | |
| 479 | static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADefaultFreeData = { |
| 480 | XFA_DefaultFreeData, nullptr}; |
| 481 | |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 482 | XFA_MAPMODULEDATA::XFA_MAPMODULEDATA() {} |
| 483 | |
| 484 | XFA_MAPMODULEDATA::~XFA_MAPMODULEDATA() {} |
| 485 | |
dsinclair | b977847 | 2016-06-23 13:34:10 -0700 | [diff] [blame] | 486 | CXFA_Node::CXFA_Node(CXFA_Document* pDoc, |
| 487 | uint16_t ePacket, |
| 488 | XFA_ObjectType oType, |
dsinclair | c1df5d4 | 2016-07-18 06:36:51 -0700 | [diff] [blame] | 489 | XFA_Element eType, |
| 490 | const CFX_WideStringC& elementName) |
| 491 | : CXFA_Object(pDoc, oType, eType, elementName), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 492 | m_pNext(nullptr), |
| 493 | m_pChild(nullptr), |
| 494 | m_pLastChild(nullptr), |
| 495 | m_pParent(nullptr), |
| 496 | m_pXMLNode(nullptr), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 497 | m_ePacket(ePacket), |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 498 | m_uNodeFlags(XFA_NodeFlag_None), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 499 | m_dwNameHash(0), |
| 500 | m_pAuxNode(nullptr), |
| 501 | m_pMapModuleData(nullptr) { |
| 502 | ASSERT(m_pDocument); |
| 503 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 504 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 505 | CXFA_Node::~CXFA_Node() { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 506 | ASSERT(!m_pParent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 507 | RemoveMapModuleKey(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 508 | CXFA_Node* pNode = m_pChild; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 509 | while (pNode) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 510 | CXFA_Node* pNext = pNode->m_pNext; |
| 511 | pNode->m_pParent = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 512 | delete pNode; |
| 513 | pNode = pNext; |
| 514 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 515 | if (m_pXMLNode && IsOwnXMLNode()) |
tsepez | c757d9a | 2017-01-23 11:01:42 -0800 | [diff] [blame] | 516 | delete m_pXMLNode; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 517 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 518 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 519 | CXFA_Node* CXFA_Node::Clone(bool bRecursive) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 520 | CXFA_Node* pClone = m_pDocument->CreateNode(m_ePacket, m_elementType); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 521 | if (!pClone) |
| 522 | return nullptr; |
| 523 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 524 | MergeAllData(pClone); |
| 525 | pClone->UpdateNameHash(); |
| 526 | if (IsNeedSavingXMLNode()) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 527 | CFDE_XMLNode* pCloneXML = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 528 | if (IsAttributeInXML()) { |
| 529 | CFX_WideString wsName; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 530 | GetAttribute(XFA_ATTRIBUTE_Name, wsName, false); |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 531 | CFDE_XMLElement* pCloneXMLElement = new CFDE_XMLElement(wsName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 532 | CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value); |
| 533 | if (!wsValue.IsEmpty()) { |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 534 | pCloneXMLElement->SetTextData(CFX_WideString(wsValue)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 535 | } |
| 536 | pCloneXML = pCloneXMLElement; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 537 | pCloneXMLElement = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 538 | pClone->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown); |
| 539 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 540 | pCloneXML = m_pXMLNode->Clone(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 541 | } |
| 542 | pClone->SetXMLMappingNode(pCloneXML); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 543 | pClone->SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 544 | } |
| 545 | if (bRecursive) { |
| 546 | for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild; |
| 547 | pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 548 | pClone->InsertChild(pChild->Clone(bRecursive)); |
| 549 | } |
| 550 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 551 | pClone->SetFlag(XFA_NodeFlag_Initialized, true); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 552 | pClone->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 553 | return pClone; |
| 554 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 555 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 556 | CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem) const { |
| 557 | switch (eItem) { |
| 558 | case XFA_NODEITEM_NextSibling: |
| 559 | return m_pNext; |
| 560 | case XFA_NODEITEM_FirstChild: |
| 561 | return m_pChild; |
| 562 | case XFA_NODEITEM_Parent: |
| 563 | return m_pParent; |
| 564 | case XFA_NODEITEM_PrevSibling: |
| 565 | if (m_pParent) { |
| 566 | CXFA_Node* pSibling = m_pParent->m_pChild; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 567 | CXFA_Node* pPrev = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 568 | while (pSibling && pSibling != this) { |
| 569 | pPrev = pSibling; |
| 570 | pSibling = pSibling->m_pNext; |
| 571 | } |
| 572 | return pPrev; |
| 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 | default: |
| 576 | break; |
| 577 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 578 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 579 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 580 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 581 | CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem, |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 582 | XFA_ObjectType eType) const { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 583 | CXFA_Node* pNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 584 | switch (eItem) { |
| 585 | case XFA_NODEITEM_NextSibling: |
| 586 | pNode = m_pNext; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 587 | while (pNode && pNode->GetObjectType() != eType) |
| 588 | pNode = pNode->m_pNext; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 589 | break; |
| 590 | case XFA_NODEITEM_FirstChild: |
| 591 | pNode = m_pChild; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 592 | while (pNode && pNode->GetObjectType() != eType) |
| 593 | pNode = pNode->m_pNext; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 594 | break; |
| 595 | case XFA_NODEITEM_Parent: |
| 596 | pNode = m_pParent; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 597 | while (pNode && pNode->GetObjectType() != eType) |
| 598 | pNode = pNode->m_pParent; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 599 | break; |
| 600 | case XFA_NODEITEM_PrevSibling: |
| 601 | if (m_pParent) { |
| 602 | CXFA_Node* pSibling = m_pParent->m_pChild; |
| 603 | while (pSibling && pSibling != this) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 604 | if (eType == pSibling->GetObjectType()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 605 | pNode = pSibling; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 606 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 607 | pSibling = pSibling->m_pNext; |
| 608 | } |
| 609 | } |
| 610 | break; |
| 611 | default: |
| 612 | break; |
| 613 | } |
| 614 | return pNode; |
| 615 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 616 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 617 | int32_t CXFA_Node::GetNodeList(CXFA_NodeArray& nodes, |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 618 | uint32_t dwTypeFilter, |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 619 | XFA_Element eTypeFilter, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 620 | int32_t iLevel) { |
| 621 | if (--iLevel < 0) { |
| 622 | return nodes.GetSize(); |
| 623 | } |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 624 | if (eTypeFilter != XFA_Element::Unknown) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 625 | CXFA_Node* pChild = m_pChild; |
| 626 | while (pChild) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 627 | if (pChild->GetElementType() == eTypeFilter) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 628 | nodes.Add(pChild); |
| 629 | if (iLevel > 0) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 630 | GetNodeList(nodes, dwTypeFilter, eTypeFilter, iLevel); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 631 | } |
| 632 | } |
| 633 | pChild = pChild->m_pNext; |
| 634 | } |
| 635 | } else if (dwTypeFilter == |
| 636 | (XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties)) { |
| 637 | CXFA_Node* pChild = m_pChild; |
| 638 | while (pChild) { |
| 639 | nodes.Add(pChild); |
| 640 | if (iLevel > 0) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 641 | GetNodeList(nodes, dwTypeFilter, eTypeFilter, iLevel); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 642 | } |
| 643 | pChild = pChild->m_pNext; |
| 644 | } |
| 645 | } else if (dwTypeFilter != 0) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 646 | bool bFilterChildren = !!(dwTypeFilter & XFA_NODEFILTER_Children); |
| 647 | bool bFilterProperties = !!(dwTypeFilter & XFA_NODEFILTER_Properties); |
| 648 | bool bFilterOneOfProperties = |
| 649 | !!(dwTypeFilter & XFA_NODEFILTER_OneOfProperty); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 650 | CXFA_Node* pChild = m_pChild; |
| 651 | while (pChild) { |
| 652 | const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement( |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 653 | GetElementType(), pChild->GetElementType(), XFA_XDPPACKET_UNKNOWN); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 654 | if (pProperty) { |
| 655 | if (bFilterProperties) { |
| 656 | nodes.Add(pChild); |
| 657 | } else if (bFilterOneOfProperties && |
| 658 | (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) { |
| 659 | nodes.Add(pChild); |
| 660 | } else if (bFilterChildren && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 661 | (pChild->GetElementType() == XFA_Element::Variables || |
| 662 | pChild->GetElementType() == XFA_Element::PageSet)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 663 | nodes.Add(pChild); |
| 664 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 665 | } else if (bFilterChildren) { |
| 666 | nodes.Add(pChild); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 667 | } |
| 668 | pChild = pChild->m_pNext; |
| 669 | } |
| 670 | if (bFilterOneOfProperties && nodes.GetSize() < 1) { |
| 671 | int32_t iProperties = 0; |
| 672 | const XFA_PROPERTY* pProperty = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 673 | XFA_GetElementProperties(GetElementType(), iProperties); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 674 | if (!pProperty || iProperties < 1) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 675 | return 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 676 | for (int32_t i = 0; i < iProperties; i++) { |
| 677 | if (pProperty[i].uFlags & XFA_PROPERTYFLAG_DefaultOneOf) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 678 | const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(GetPacketID()); |
| 679 | CXFA_Node* pNewNode = |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 680 | m_pDocument->CreateNode(pPacket, pProperty[i].eName); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 681 | if (!pNewNode) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 682 | break; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 683 | InsertChild(pNewNode, nullptr); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 684 | pNewNode->SetFlag(XFA_NodeFlag_Initialized, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 685 | nodes.Add(pNewNode); |
| 686 | break; |
| 687 | } |
| 688 | } |
| 689 | } |
| 690 | } |
| 691 | return nodes.GetSize(); |
| 692 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 693 | |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 694 | CXFA_Node* CXFA_Node::CreateSamePacketNode(XFA_Element eType, |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 695 | uint32_t dwFlags) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 696 | CXFA_Node* pNode = m_pDocument->CreateNode(m_ePacket, eType); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 697 | pNode->SetFlag(dwFlags, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 698 | return pNode; |
| 699 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 700 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 701 | CXFA_Node* CXFA_Node::CloneTemplateToForm(bool bRecursive) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 702 | ASSERT(m_ePacket == XFA_XDPPACKET_Template); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 703 | CXFA_Node* pClone = |
| 704 | m_pDocument->CreateNode(XFA_XDPPACKET_Form, m_elementType); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 705 | if (!pClone) |
| 706 | return nullptr; |
| 707 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 708 | pClone->SetTemplateNode(this); |
| 709 | pClone->UpdateNameHash(); |
| 710 | pClone->SetXMLMappingNode(GetXMLMappingNode()); |
| 711 | if (bRecursive) { |
| 712 | for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild; |
| 713 | pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 714 | pClone->InsertChild(pChild->CloneTemplateToForm(bRecursive)); |
| 715 | } |
| 716 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 717 | pClone->SetFlag(XFA_NodeFlag_Initialized, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 718 | return pClone; |
| 719 | } |
| 720 | |
| 721 | CXFA_Node* CXFA_Node::GetTemplateNode() const { |
| 722 | return m_pAuxNode; |
| 723 | } |
| 724 | |
| 725 | void CXFA_Node::SetTemplateNode(CXFA_Node* pTemplateNode) { |
| 726 | m_pAuxNode = pTemplateNode; |
| 727 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 728 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 729 | CXFA_Node* CXFA_Node::GetBindData() { |
| 730 | ASSERT(GetPacketID() == XFA_XDPPACKET_Form); |
| 731 | return static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); |
| 732 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 733 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 734 | int32_t CXFA_Node::GetBindItems(CXFA_NodeArray& formItems) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 735 | if (BindsFormItems()) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 736 | CXFA_NodeArray* pItems = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 737 | TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems); |
| 738 | formItems.Copy(*pItems); |
| 739 | return formItems.GetSize(); |
| 740 | } |
| 741 | CXFA_Node* pFormNode = |
| 742 | static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 743 | if (pFormNode) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 744 | formItems.Add(pFormNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 745 | return formItems.GetSize(); |
| 746 | } |
| 747 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 748 | int32_t CXFA_Node::AddBindItem(CXFA_Node* pFormNode) { |
| 749 | ASSERT(pFormNode); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 750 | if (BindsFormItems()) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 751 | CXFA_NodeArray* pItems = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 752 | TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems); |
| 753 | ASSERT(pItems); |
| 754 | if (pItems->Find(pFormNode) < 0) { |
| 755 | pItems->Add(pFormNode); |
| 756 | } |
| 757 | return pItems->GetSize(); |
| 758 | } |
| 759 | CXFA_Node* pOldFormItem = |
| 760 | static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); |
| 761 | if (!pOldFormItem) { |
| 762 | SetObject(XFA_ATTRIBUTE_BindingNode, pFormNode); |
| 763 | return 1; |
| 764 | } else if (pOldFormItem == pFormNode) { |
| 765 | return 1; |
| 766 | } |
| 767 | CXFA_NodeArray* pItems = new CXFA_NodeArray; |
| 768 | SetObject(XFA_ATTRIBUTE_BindingNode, pItems, &deleteBindItemCallBack); |
| 769 | pItems->Add(pOldFormItem); |
| 770 | pItems->Add(pFormNode); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 771 | m_uNodeFlags |= XFA_NodeFlag_BindFormItems; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 772 | return 2; |
| 773 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 774 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 775 | int32_t CXFA_Node::RemoveBindItem(CXFA_Node* pFormNode) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 776 | if (BindsFormItems()) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 777 | CXFA_NodeArray* pItems = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 778 | TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems); |
| 779 | ASSERT(pItems); |
| 780 | int32_t iIndex = pItems->Find(pFormNode); |
| 781 | int32_t iCount = pItems->GetSize(); |
| 782 | if (iIndex >= 0) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 783 | if (iIndex != iCount - 1) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 784 | pItems->SetAt(iIndex, pItems->GetAt(iCount - 1)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 785 | pItems->RemoveAt(iCount - 1); |
| 786 | if (iCount == 2) { |
| 787 | CXFA_Node* pLastFormNode = pItems->GetAt(0); |
| 788 | SetObject(XFA_ATTRIBUTE_BindingNode, pLastFormNode); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 789 | m_uNodeFlags &= ~XFA_NodeFlag_BindFormItems; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 790 | } |
| 791 | iCount--; |
| 792 | } |
| 793 | return iCount; |
| 794 | } |
| 795 | CXFA_Node* pOldFormItem = |
| 796 | static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); |
| 797 | if (pOldFormItem == pFormNode) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 798 | SetObject(XFA_ATTRIBUTE_BindingNode, nullptr); |
| 799 | pOldFormItem = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 800 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 801 | return pOldFormItem ? 1 : 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 802 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 803 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 804 | bool CXFA_Node::HasBindItem() { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 805 | return GetPacketID() == XFA_XDPPACKET_Datasets && |
| 806 | GetObject(XFA_ATTRIBUTE_BindingNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 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::GetWidgetData() { |
| 810 | return (CXFA_WidgetData*)GetObject(XFA_ATTRIBUTE_WidgetData); |
| 811 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 812 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 813 | CXFA_WidgetData* CXFA_Node::GetContainerWidgetData() { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 814 | if (GetPacketID() != XFA_XDPPACKET_Form) |
| 815 | return nullptr; |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 816 | XFA_Element eType = GetElementType(); |
| 817 | if (eType == XFA_Element::ExclGroup) |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 818 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 819 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 820 | if (pParentNode && pParentNode->GetElementType() == XFA_Element::ExclGroup) |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 821 | return nullptr; |
| 822 | |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 823 | if (eType == XFA_Element::Field) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 824 | CXFA_WidgetData* pFieldWidgetData = GetWidgetData(); |
| 825 | if (pFieldWidgetData && |
| 826 | pFieldWidgetData->GetChoiceListOpen() == |
| 827 | XFA_ATTRIBUTEENUM_MultiSelect) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 828 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 829 | } else { |
| 830 | CFX_WideString wsPicture; |
| 831 | if (pFieldWidgetData) { |
| 832 | pFieldWidgetData->GetPictureContent(wsPicture, |
| 833 | XFA_VALUEPICTURE_DataBind); |
| 834 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 835 | if (!wsPicture.IsEmpty()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 836 | return pFieldWidgetData; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 837 | CXFA_Node* pDataNode = GetBindData(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 838 | if (!pDataNode) |
| 839 | return nullptr; |
| 840 | pFieldWidgetData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 841 | CXFA_NodeArray formNodes; |
| 842 | pDataNode->GetBindItems(formNodes); |
| 843 | for (int32_t i = 0; i < formNodes.GetSize(); i++) { |
| 844 | CXFA_Node* pFormNode = formNodes.GetAt(i); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 845 | if (!pFormNode || pFormNode->HasRemovedChildren()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 846 | continue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 847 | pFieldWidgetData = pFormNode->GetWidgetData(); |
| 848 | if (pFieldWidgetData) { |
| 849 | pFieldWidgetData->GetPictureContent(wsPicture, |
| 850 | XFA_VALUEPICTURE_DataBind); |
| 851 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 852 | if (!wsPicture.IsEmpty()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 853 | break; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 854 | pFieldWidgetData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 855 | } |
| 856 | return pFieldWidgetData; |
| 857 | } |
| 858 | } |
| 859 | CXFA_Node* pGrandNode = |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 860 | pParentNode ? pParentNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 861 | CXFA_Node* pValueNode = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 862 | (pParentNode && pParentNode->GetElementType() == XFA_Element::Value) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 863 | ? pParentNode |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 864 | : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 865 | if (!pValueNode) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 866 | pValueNode = |
| 867 | (pGrandNode && pGrandNode->GetElementType() == XFA_Element::Value) |
| 868 | ? pGrandNode |
| 869 | : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 870 | } |
| 871 | CXFA_Node* pParentOfValueNode = |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 872 | pValueNode ? pValueNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 873 | return pParentOfValueNode ? pParentOfValueNode->GetContainerWidgetData() |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 874 | : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 875 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 876 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 877 | bool CXFA_Node::GetLocaleName(CFX_WideString& wsLocaleName) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 878 | CXFA_Node* pForm = GetDocument()->GetXFAObject(XFA_HASHCODE_Form)->AsNode(); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 879 | CXFA_Node* pTopSubform = pForm->GetFirstChildByClass(XFA_Element::Subform); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 880 | ASSERT(pTopSubform); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 881 | CXFA_Node* pLocaleNode = this; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 882 | bool bLocale = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 883 | do { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 884 | bLocale = pLocaleNode->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 885 | if (!bLocale) { |
| 886 | pLocaleNode = pLocaleNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 887 | } |
| 888 | } while (pLocaleNode && pLocaleNode != pTopSubform && !bLocale); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 889 | if (bLocale) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 890 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 891 | CXFA_Node* pConfig = ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Config)); |
| 892 | wsLocaleName = GetDocument()->GetLocalMgr()->GetConfigLocaleName(pConfig); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 893 | if (!wsLocaleName.IsEmpty()) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 894 | return true; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 895 | if (pTopSubform && |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 896 | pTopSubform->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false)) { |
| 897 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 898 | } |
| 899 | IFX_Locale* pLocale = GetDocument()->GetLocalMgr()->GetDefLocale(); |
| 900 | if (pLocale) { |
| 901 | wsLocaleName = pLocale->GetName(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 902 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 903 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 904 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 905 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 906 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 907 | XFA_ATTRIBUTEENUM CXFA_Node::GetIntact() { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 908 | CXFA_Node* pKeep = GetFirstChildByClass(XFA_Element::Keep); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 909 | XFA_ATTRIBUTEENUM eLayoutType = GetEnum(XFA_ATTRIBUTE_Layout); |
| 910 | if (pKeep) { |
| 911 | XFA_ATTRIBUTEENUM eIntact; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 912 | if (pKeep->TryEnum(XFA_ATTRIBUTE_Intact, eIntact, false)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 913 | if (eIntact == XFA_ATTRIBUTEENUM_None && |
| 914 | eLayoutType == XFA_ATTRIBUTEENUM_Row && |
| 915 | m_pDocument->GetCurVersionMode() < XFA_VERSION_208) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 916 | CXFA_Node* pPreviewRow = GetNodeItem(XFA_NODEITEM_PrevSibling, |
| 917 | XFA_ObjectType::ContainerNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 918 | if (pPreviewRow && |
| 919 | pPreviewRow->GetEnum(XFA_ATTRIBUTE_Layout) == |
| 920 | XFA_ATTRIBUTEENUM_Row) { |
| 921 | XFA_ATTRIBUTEENUM eValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 922 | if (pKeep->TryEnum(XFA_ATTRIBUTE_Previous, eValue, false) && |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 923 | (eValue == XFA_ATTRIBUTEENUM_ContentArea || |
| 924 | eValue == XFA_ATTRIBUTEENUM_PageArea)) { |
| 925 | return XFA_ATTRIBUTEENUM_ContentArea; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 926 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 927 | CXFA_Node* pNode = |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 928 | pPreviewRow->GetFirstChildByClass(XFA_Element::Keep); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 929 | if (pNode && pNode->TryEnum(XFA_ATTRIBUTE_Next, eValue, false) && |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 930 | (eValue == XFA_ATTRIBUTEENUM_ContentArea || |
| 931 | eValue == XFA_ATTRIBUTEENUM_PageArea)) { |
| 932 | return XFA_ATTRIBUTEENUM_ContentArea; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 933 | } |
| 934 | } |
| 935 | } |
| 936 | return eIntact; |
| 937 | } |
| 938 | } |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 939 | switch (GetElementType()) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 940 | case XFA_Element::Subform: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 941 | switch (eLayoutType) { |
| 942 | case XFA_ATTRIBUTEENUM_Position: |
| 943 | case XFA_ATTRIBUTEENUM_Row: |
| 944 | return XFA_ATTRIBUTEENUM_ContentArea; |
| 945 | case XFA_ATTRIBUTEENUM_Tb: |
| 946 | case XFA_ATTRIBUTEENUM_Table: |
| 947 | case XFA_ATTRIBUTEENUM_Lr_tb: |
| 948 | case XFA_ATTRIBUTEENUM_Rl_tb: |
| 949 | return XFA_ATTRIBUTEENUM_None; |
| 950 | default: |
| 951 | break; |
| 952 | } |
| 953 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 954 | case XFA_Element::Field: { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 955 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 956 | if (!pParentNode || |
| 957 | pParentNode->GetElementType() == XFA_Element::PageArea) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 958 | return XFA_ATTRIBUTEENUM_ContentArea; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 959 | if (pParentNode->GetIntact() == XFA_ATTRIBUTEENUM_None) { |
| 960 | XFA_ATTRIBUTEENUM eParLayout = |
| 961 | pParentNode->GetEnum(XFA_ATTRIBUTE_Layout); |
| 962 | if (eParLayout == XFA_ATTRIBUTEENUM_Position || |
| 963 | eParLayout == XFA_ATTRIBUTEENUM_Row || |
| 964 | eParLayout == XFA_ATTRIBUTEENUM_Table) { |
| 965 | return XFA_ATTRIBUTEENUM_None; |
| 966 | } |
| 967 | XFA_VERSION version = m_pDocument->GetCurVersionMode(); |
| 968 | if (eParLayout == XFA_ATTRIBUTEENUM_Tb && version < XFA_VERSION_208) { |
| 969 | CXFA_Measurement measureH; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 970 | if (TryMeasure(XFA_ATTRIBUTE_H, measureH, false)) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 971 | return XFA_ATTRIBUTEENUM_ContentArea; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 972 | } |
| 973 | return XFA_ATTRIBUTEENUM_None; |
| 974 | } |
| 975 | return XFA_ATTRIBUTEENUM_ContentArea; |
| 976 | } |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 977 | case XFA_Element::Draw: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 978 | return XFA_ATTRIBUTEENUM_ContentArea; |
| 979 | default: |
| 980 | break; |
| 981 | } |
| 982 | return XFA_ATTRIBUTEENUM_None; |
| 983 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 984 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 985 | CXFA_Node* CXFA_Node::GetDataDescriptionNode() { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 986 | if (m_ePacket == XFA_XDPPACKET_Datasets) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 987 | return m_pAuxNode; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 988 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 989 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 990 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 991 | void CXFA_Node::SetDataDescriptionNode(CXFA_Node* pDataDescriptionNode) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 992 | ASSERT(m_ePacket == XFA_XDPPACKET_Datasets); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 993 | m_pAuxNode = pDataDescriptionNode; |
| 994 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 995 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 996 | void CXFA_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments) { |
| 997 | int32_t iLength = pArguments->GetLength(); |
| 998 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 999 | ThrowParamCountMismatchException(L"resolveNode"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1000 | return; |
| 1001 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1002 | CFX_WideString wsExpression = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1003 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 1004 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1005 | if (!pScriptContext) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1006 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1007 | CXFA_Node* refNode = this; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1008 | if (refNode->GetElementType() == XFA_Element::Xfa) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1009 | refNode = ToNode(pScriptContext->GetThisObject()); |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1010 | uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1011 | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | |
| 1012 | XFA_RESOLVENODE_Siblings; |
| 1013 | XFA_RESOLVENODE_RS resoveNodeRS; |
tsepez | fc58ad1 | 2016-04-05 12:22:15 -0700 | [diff] [blame] | 1014 | int32_t iRet = pScriptContext->ResolveObjects( |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1015 | refNode, wsExpression.AsStringC(), resoveNodeRS, dwFlag); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1016 | if (iRet < 1) { |
| 1017 | pArguments->GetReturnValue()->SetNull(); |
| 1018 | return; |
| 1019 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1020 | if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { |
| 1021 | CXFA_Object* pNode = resoveNodeRS.nodes[0]; |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1022 | pArguments->GetReturnValue()->Assign( |
| 1023 | pScriptContext->GetJSValueFromMap(pNode)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1024 | } else { |
| 1025 | const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = |
| 1026 | resoveNodeRS.pScriptAttribute; |
| 1027 | if (lpAttributeInfo && lpAttributeInfo->eValueType == XFA_SCRIPT_Object) { |
dsinclair | 86fad99 | 2016-05-31 11:34:04 -0700 | [diff] [blame] | 1028 | std::unique_ptr<CFXJSE_Value> pValue( |
| 1029 | new CFXJSE_Value(pScriptContext->GetRuntime())); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1030 | (resoveNodeRS.nodes[0]->*(lpAttributeInfo->lpfnCallback))( |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1031 | pValue.get(), false, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1032 | pArguments->GetReturnValue()->Assign(pValue.get()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1033 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1034 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1035 | } |
| 1036 | } |
| 1037 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1038 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1039 | void CXFA_Node::Script_TreeClass_ResolveNodes(CFXJSE_Arguments* pArguments) { |
| 1040 | int32_t iLength = pArguments->GetLength(); |
| 1041 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1042 | ThrowParamCountMismatchException(L"resolveNodes"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1043 | return; |
| 1044 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1045 | CFX_WideString wsExpression = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1046 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1047 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1048 | if (!pValue) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1049 | return; |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1050 | uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1051 | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | |
| 1052 | XFA_RESOLVENODE_Siblings; |
| 1053 | CXFA_Node* refNode = this; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1054 | if (refNode->GetElementType() == XFA_Element::Xfa) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1055 | refNode = ToNode(m_pDocument->GetScriptContext()->GetThisObject()); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1056 | Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag, refNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1057 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1058 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1059 | void CXFA_Node::Script_Som_ResolveNodeList(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1060 | CFX_WideString wsExpression, |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1061 | uint32_t dwFlag, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1062 | CXFA_Node* refNode) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 1063 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1064 | if (!pScriptContext) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1065 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1066 | XFA_RESOLVENODE_RS resoveNodeRS; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1067 | if (!refNode) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1068 | refNode = this; |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1069 | pScriptContext->ResolveObjects(refNode, wsExpression.AsStringC(), |
tsepez | fc58ad1 | 2016-04-05 12:22:15 -0700 | [diff] [blame] | 1070 | resoveNodeRS, dwFlag); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1071 | CXFA_ArrayNodeList* pNodeList = new CXFA_ArrayNodeList(m_pDocument); |
| 1072 | if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { |
| 1073 | for (int32_t i = 0; i < resoveNodeRS.nodes.GetSize(); i++) { |
| 1074 | if (resoveNodeRS.nodes[i]->IsNode()) |
| 1075 | pNodeList->Append(resoveNodeRS.nodes[i]->AsNode()); |
| 1076 | } |
| 1077 | } else { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1078 | CXFA_ValueArray valueArray(pScriptContext->GetRuntime()); |
| 1079 | if (resoveNodeRS.GetAttributeResult(valueArray) > 0) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1080 | CXFA_ObjArray objectArray; |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1081 | valueArray.GetAttributeObject(objectArray); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1082 | for (int32_t i = 0; i < objectArray.GetSize(); i++) { |
| 1083 | if (objectArray[i]->IsNode()) |
| 1084 | pNodeList->Append(objectArray[i]->AsNode()); |
| 1085 | } |
| 1086 | } |
| 1087 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1088 | pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1089 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1090 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1091 | void CXFA_Node::Script_TreeClass_All(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1092 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1093 | XFA_ATTRIBUTE eAttribute) { |
| 1094 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1095 | ThrowInvalidPropertyException(); |
| 1096 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1097 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1098 | |
| 1099 | uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL; |
| 1100 | CFX_WideString wsName; |
| 1101 | GetAttribute(XFA_ATTRIBUTE_Name, wsName); |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 1102 | CFX_WideString wsExpression = wsName + L"[*]"; |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1103 | Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1104 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1105 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1106 | void CXFA_Node::Script_TreeClass_Nodes(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1107 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1108 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 1109 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1110 | if (!pScriptContext) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1111 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1112 | if (bSetting) { |
Dan Sinclair | c8fd331 | 2017-01-02 17:17:02 -0500 | [diff] [blame] | 1113 | CFX_WideString wsMessage = L"Unable to set "; |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 1114 | FXJSE_ThrowMessage(wsMessage.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1115 | } else { |
| 1116 | CXFA_AttachNodeList* pNodeList = new CXFA_AttachNodeList(m_pDocument, this); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1117 | pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1118 | } |
| 1119 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1120 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1121 | void CXFA_Node::Script_TreeClass_ClassAll(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1122 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1123 | XFA_ATTRIBUTE eAttribute) { |
| 1124 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1125 | ThrowInvalidPropertyException(); |
| 1126 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1127 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1128 | uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL; |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 1129 | CFX_WideString wsExpression = L"#" + GetClassName() + L"[*]"; |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1130 | Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 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) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1137 | ThrowInvalidPropertyException(); |
| 1138 | return; |
| 1139 | } |
| 1140 | CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent); |
| 1141 | if (pParent) { |
| 1142 | pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pParent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1143 | } else { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1144 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1145 | } |
| 1146 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1147 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1148 | void CXFA_Node::Script_TreeClass_Index(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1149 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1150 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1151 | if (bSetting) { |
| 1152 | ThrowInvalidPropertyException(); |
| 1153 | return; |
| 1154 | } |
| 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) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1161 | if (bSetting) { |
| 1162 | ThrowInvalidPropertyException(); |
| 1163 | return; |
| 1164 | } |
| 1165 | pValue->SetInteger(GetNodeSameClassIndex()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1166 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1167 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1168 | void CXFA_Node::Script_TreeClass_SomExpression(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1169 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1170 | XFA_ATTRIBUTE eAttribute) { |
| 1171 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1172 | ThrowInvalidPropertyException(); |
| 1173 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1174 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1175 | CFX_WideString wsSOMExpression; |
| 1176 | GetSOMExpression(wsSOMExpression); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 1177 | pValue->SetString(wsSOMExpression.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1178 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1179 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1180 | void CXFA_Node::Script_NodeClass_ApplyXSL(CFXJSE_Arguments* pArguments) { |
| 1181 | int32_t iLength = pArguments->GetLength(); |
| 1182 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1183 | ThrowParamCountMismatchException(L"applyXSL"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1184 | return; |
| 1185 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1186 | CFX_WideString wsExpression = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1187 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1188 | // TODO(weili): check whether we need to implement this, pdfium:501. |
| 1189 | // For now, just put the variables here to avoid unused variable warning. |
| 1190 | (void)wsExpression; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1191 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1192 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1193 | void CXFA_Node::Script_NodeClass_AssignNode(CFXJSE_Arguments* pArguments) { |
| 1194 | int32_t iLength = pArguments->GetLength(); |
| 1195 | if (iLength < 1 || iLength > 3) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1196 | ThrowParamCountMismatchException(L"assignNode"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1197 | return; |
| 1198 | } |
| 1199 | CFX_WideString wsExpression; |
| 1200 | CFX_WideString wsValue; |
| 1201 | int32_t iAction = 0; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1202 | wsExpression = |
| 1203 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1204 | if (iLength >= 2) { |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1205 | wsValue = |
| 1206 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1207 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1208 | if (iLength >= 3) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1209 | iAction = pArguments->GetInt32(2); |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1210 | // TODO(weili): check whether we need to implement this, pdfium:501. |
| 1211 | // For now, just put the variables here to avoid unused variable warning. |
| 1212 | (void)wsExpression; |
| 1213 | (void)wsValue; |
| 1214 | (void)iAction; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1215 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1216 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1217 | void CXFA_Node::Script_NodeClass_Clone(CFXJSE_Arguments* pArguments) { |
| 1218 | int32_t iLength = pArguments->GetLength(); |
| 1219 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1220 | ThrowParamCountMismatchException(L"clone"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1221 | return; |
| 1222 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1223 | bool bClone = !!pArguments->GetInt32(0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1224 | CXFA_Node* pCloneNode = Clone(bClone); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1225 | pArguments->GetReturnValue()->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1226 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pCloneNode)); |
| 1227 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1228 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1229 | void CXFA_Node::Script_NodeClass_GetAttribute(CFXJSE_Arguments* pArguments) { |
| 1230 | int32_t iLength = pArguments->GetLength(); |
| 1231 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1232 | ThrowParamCountMismatchException(L"getAttribute"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1233 | return; |
| 1234 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1235 | CFX_WideString wsExpression = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1236 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1237 | CFX_WideString wsValue; |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1238 | GetAttribute(wsExpression.AsStringC(), wsValue); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1239 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1240 | if (pValue) |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 1241 | pValue->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1242 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1243 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1244 | void CXFA_Node::Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments) { |
| 1245 | int32_t iLength = pArguments->GetLength(); |
| 1246 | if (iLength < 1 || iLength > 2) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1247 | ThrowParamCountMismatchException(L"getElement"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1248 | return; |
| 1249 | } |
| 1250 | CFX_WideString wsExpression; |
| 1251 | int32_t iValue = 0; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1252 | wsExpression = |
| 1253 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
| 1254 | if (iLength >= 2) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1255 | iValue = pArguments->GetInt32(1); |
dsinclair | 6e12478 | 2016-06-23 12:14:55 -0700 | [diff] [blame] | 1256 | CXFA_Node* pNode = |
| 1257 | GetProperty(iValue, XFA_GetElementTypeForName(wsExpression.AsStringC())); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1258 | pArguments->GetReturnValue()->Assign( |
| 1259 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1260 | } |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1261 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1262 | void CXFA_Node::Script_NodeClass_IsPropertySpecified( |
| 1263 | CFXJSE_Arguments* pArguments) { |
| 1264 | int32_t iLength = pArguments->GetLength(); |
| 1265 | if (iLength < 1 || iLength > 3) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1266 | ThrowParamCountMismatchException(L"isPropertySpecified"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1267 | return; |
| 1268 | } |
| 1269 | CFX_WideString wsExpression; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1270 | bool bParent = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1271 | int32_t iIndex = 0; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1272 | wsExpression = |
| 1273 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1274 | if (iLength >= 2) |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1275 | bParent = !!pArguments->GetInt32(1); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1276 | if (iLength >= 3) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1277 | iIndex = pArguments->GetInt32(2); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1278 | bool bHas = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1279 | const XFA_ATTRIBUTEINFO* pAttributeInfo = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1280 | XFA_GetAttributeByName(wsExpression.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1281 | CFX_WideString wsValue; |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1282 | if (pAttributeInfo) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1283 | bHas = HasAttribute(pAttributeInfo->eName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1284 | if (!bHas) { |
dsinclair | 6e12478 | 2016-06-23 12:14:55 -0700 | [diff] [blame] | 1285 | XFA_Element eType = XFA_GetElementTypeForName(wsExpression.AsStringC()); |
| 1286 | bHas = !!GetProperty(iIndex, eType); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1287 | if (!bHas && bParent && m_pParent) { |
| 1288 | // Also check on the parent. |
| 1289 | bHas = m_pParent->HasAttribute(pAttributeInfo->eName); |
| 1290 | if (!bHas) |
dsinclair | 6e12478 | 2016-06-23 12:14:55 -0700 | [diff] [blame] | 1291 | bHas = !!m_pParent->GetProperty(iIndex, eType); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1292 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1293 | } |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1294 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
| 1295 | if (pValue) |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1296 | pValue->SetBoolean(bHas); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1297 | } |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1298 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1299 | void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) { |
| 1300 | int32_t iLength = pArguments->GetLength(); |
| 1301 | if (iLength < 1 || iLength > 3) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1302 | ThrowParamCountMismatchException(L"loadXML"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1303 | return; |
| 1304 | } |
| 1305 | CFX_WideString wsExpression; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1306 | bool bIgnoreRoot = true; |
| 1307 | bool bOverwrite = 0; |
| 1308 | wsExpression = |
| 1309 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
| 1310 | if (wsExpression.IsEmpty()) |
Tom Sepez | d3743ea | 2016-05-16 15:56:53 -0700 | [diff] [blame] | 1311 | return; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1312 | if (iLength >= 2) |
| 1313 | bIgnoreRoot = !!pArguments->GetInt32(1); |
| 1314 | if (iLength >= 3) |
| 1315 | bOverwrite = !!pArguments->GetInt32(2); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 1316 | std::unique_ptr<CXFA_SimpleParser> pParser( |
| 1317 | new CXFA_SimpleParser(m_pDocument, false)); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1318 | if (!pParser) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1319 | return; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1320 | CFDE_XMLNode* pXMLNode = nullptr; |
| 1321 | int32_t iParserStatus = |
| 1322 | pParser->ParseXMLData(wsExpression, pXMLNode, nullptr); |
| 1323 | if (iParserStatus != XFA_PARSESTATUS_Done || !pXMLNode) |
| 1324 | return; |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1325 | if (bIgnoreRoot && |
| 1326 | (pXMLNode->GetType() != FDE_XMLNODE_Element || |
| 1327 | XFA_RecognizeRichText(static_cast<CFDE_XMLElement*>(pXMLNode)))) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1328 | bIgnoreRoot = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1329 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1330 | CXFA_Node* pFakeRoot = Clone(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1331 | CFX_WideStringC wsContentType = GetCData(XFA_ATTRIBUTE_ContentType); |
| 1332 | if (!wsContentType.IsEmpty()) { |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 1333 | pFakeRoot->SetCData(XFA_ATTRIBUTE_ContentType, |
| 1334 | CFX_WideString(wsContentType)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1335 | } |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1336 | CFDE_XMLNode* pFakeXMLRoot = pFakeRoot->GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1337 | if (!pFakeXMLRoot) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1338 | CFDE_XMLNode* pThisXMLRoot = GetXMLMappingNode(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1339 | pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone(false) : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1340 | } |
dsinclair | 017052a | 2016-06-28 07:43:51 -0700 | [diff] [blame] | 1341 | if (!pFakeXMLRoot) |
| 1342 | pFakeXMLRoot = new CFDE_XMLElement(CFX_WideString(GetClassName())); |
| 1343 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1344 | if (bIgnoreRoot) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1345 | CFDE_XMLNode* pXMLChild = pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1346 | while (pXMLChild) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1347 | CFDE_XMLNode* pXMLSibling = |
| 1348 | pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1349 | pXMLNode->RemoveChildNode(pXMLChild); |
| 1350 | pFakeXMLRoot->InsertChildNode(pXMLChild); |
| 1351 | pXMLChild = pXMLSibling; |
| 1352 | } |
| 1353 | } else { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1354 | CFDE_XMLNode* pXMLParent = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1355 | if (pXMLParent) { |
| 1356 | pXMLParent->RemoveChildNode(pXMLNode); |
| 1357 | } |
| 1358 | pFakeXMLRoot->InsertChildNode(pXMLNode); |
| 1359 | } |
| 1360 | pParser->ConstructXFANode(pFakeRoot, pFakeXMLRoot); |
| 1361 | pFakeRoot = pParser->GetRootNode(); |
| 1362 | if (pFakeRoot) { |
| 1363 | if (bOverwrite) { |
| 1364 | CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1365 | CXFA_Node* pNewChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1366 | int32_t index = 0; |
| 1367 | while (pNewChild) { |
| 1368 | CXFA_Node* pItem = pNewChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1369 | pFakeRoot->RemoveChild(pNewChild); |
| 1370 | InsertChild(index++, pNewChild); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 1371 | pNewChild->SetFlag(XFA_NodeFlag_Initialized, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1372 | pNewChild = pItem; |
| 1373 | } |
| 1374 | while (pChild) { |
| 1375 | CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1376 | RemoveChild(pChild); |
| 1377 | pFakeRoot->InsertChild(pChild); |
| 1378 | pChild = pItem; |
| 1379 | } |
| 1380 | if (GetPacketID() == XFA_XDPPACKET_Form && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1381 | GetElementType() == XFA_Element::ExData) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1382 | CFDE_XMLNode* pTempXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1383 | SetXMLMappingNode(pFakeXMLRoot); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 1384 | SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1385 | if (pTempXMLNode && !pTempXMLNode->GetNodeItem(CFDE_XMLNode::Parent)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1386 | pFakeXMLRoot = pTempXMLNode; |
| 1387 | } else { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1388 | pFakeXMLRoot = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1389 | } |
| 1390 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1391 | MoveBufferMapData(pFakeRoot, this, XFA_CalcData, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1392 | } else { |
| 1393 | CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1394 | while (pChild) { |
| 1395 | CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1396 | pFakeRoot->RemoveChild(pChild); |
| 1397 | InsertChild(pChild); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 1398 | pChild->SetFlag(XFA_NodeFlag_Initialized, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1399 | pChild = pItem; |
| 1400 | } |
| 1401 | } |
| 1402 | if (pFakeXMLRoot) { |
| 1403 | pFakeRoot->SetXMLMappingNode(pFakeXMLRoot); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 1404 | pFakeRoot->SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1405 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 1406 | pFakeRoot->SetFlag(XFA_NodeFlag_HasRemovedChildren, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1407 | } else { |
tsepez | c757d9a | 2017-01-23 11:01:42 -0800 | [diff] [blame] | 1408 | delete pFakeXMLRoot; |
| 1409 | pFakeXMLRoot = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1410 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1411 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1412 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1413 | void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1414 | // TODO(weili): Check whether we need to implement this, pdfium:501. |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) { |
| 1418 | int32_t iLength = pArguments->GetLength(); |
| 1419 | if (iLength < 0 || iLength > 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1420 | ThrowParamCountMismatchException(L"saveXML"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1421 | return; |
| 1422 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1423 | bool bPrettyMode = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1424 | if (iLength == 1) { |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1425 | if (pArguments->GetUTF8String(0) != "pretty") { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1426 | ThrowArgumentMismatchException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1427 | return; |
| 1428 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1429 | bPrettyMode = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1430 | } |
| 1431 | CFX_ByteStringC bsXMLHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1432 | if (GetPacketID() == XFA_XDPPACKET_Form || |
| 1433 | GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 1434 | CFDE_XMLNode* pElement = nullptr; |
| 1435 | if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 1436 | pElement = GetXMLMappingNode(); |
| 1437 | if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1438 | pArguments->GetReturnValue()->SetString(bsXMLHeader); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1439 | return; |
| 1440 | } |
| 1441 | XFA_DataExporter_DealWithDataGroupNode(this); |
| 1442 | } |
tsepez | 833619b | 2016-12-07 09:21:17 -0800 | [diff] [blame] | 1443 | CFX_RetainPtr<IFX_MemoryStream> pMemoryStream = |
| 1444 | IFX_MemoryStream::Create(true); |
| 1445 | |
| 1446 | // Note: ambiguious below without static_cast. |
tsepez | 7cda31a | 2016-12-07 12:10:20 -0800 | [diff] [blame] | 1447 | CFX_RetainPtr<IFGAS_Stream> pStream = IFGAS_Stream::CreateStream( |
| 1448 | CFX_RetainPtr<IFX_SeekableWriteStream>(pMemoryStream), |
| 1449 | FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append); |
tsepez | 833619b | 2016-12-07 09:21:17 -0800 | [diff] [blame] | 1450 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1451 | if (!pStream) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1452 | pArguments->GetReturnValue()->SetString(bsXMLHeader); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1453 | return; |
| 1454 | } |
| 1455 | pStream->SetCodePage(FX_CODEPAGE_UTF8); |
dsinclair | 179bebb | 2016-04-05 11:02:18 -0700 | [diff] [blame] | 1456 | pStream->WriteData(bsXMLHeader.raw_str(), bsXMLHeader.GetLength()); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1457 | if (GetPacketID() == XFA_XDPPACKET_Form) |
tsepez | 7cda31a | 2016-12-07 12:10:20 -0800 | [diff] [blame] | 1458 | XFA_DataExporter_RegenerateFormFile(this, pStream, nullptr, true); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1459 | else |
tsepez | 7cda31a | 2016-12-07 12:10:20 -0800 | [diff] [blame] | 1460 | pElement->SaveXMLNode(pStream); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1461 | // TODO(weili): Check whether we need to save pretty print XML, pdfium:501. |
| 1462 | // For now, just put it here to avoid unused variable warning. |
| 1463 | (void)bPrettyMode; |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1464 | pArguments->GetReturnValue()->SetString( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1465 | CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize())); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1466 | return; |
| 1467 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1468 | pArguments->GetReturnValue()->SetString(""); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1469 | } |
| 1470 | |
| 1471 | void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) { |
| 1472 | int32_t iLength = pArguments->GetLength(); |
| 1473 | if (iLength != 2) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1474 | ThrowParamCountMismatchException(L"setAttribute"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1475 | return; |
| 1476 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1477 | CFX_WideString wsAttributeValue = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1478 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1479 | CFX_WideString wsAttribute = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1480 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC()); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1481 | SetAttribute(wsAttribute.AsStringC(), wsAttributeValue.AsStringC(), true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1482 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1483 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1484 | void CXFA_Node::Script_NodeClass_SetElement(CFXJSE_Arguments* pArguments) { |
| 1485 | int32_t iLength = pArguments->GetLength(); |
| 1486 | if (iLength != 1 && iLength != 2) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1487 | ThrowParamCountMismatchException(L"setElement"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1488 | return; |
| 1489 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1490 | CXFA_Node* pNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1491 | CFX_WideString wsName; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1492 | pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); |
| 1493 | if (iLength == 2) |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1494 | wsName = CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC()); |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1495 | // TODO(weili): check whether we need to implement this, pdfium:501. |
| 1496 | // For now, just put the variables here to avoid unused variable warning. |
| 1497 | (void)pNode; |
| 1498 | (void)wsName; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1499 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1500 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1501 | void CXFA_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1502 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1503 | XFA_ATTRIBUTE eAttribute) { |
| 1504 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1505 | ThrowInvalidPropertyException(); |
| 1506 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1507 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1508 | |
| 1509 | CFX_WideString wsNameSpace; |
| 1510 | TryNamespace(wsNameSpace); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 1511 | pValue->SetString(wsNameSpace.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1512 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1513 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1514 | void CXFA_Node::Script_NodeClass_Model(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1515 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1516 | XFA_ATTRIBUTE eAttribute) { |
| 1517 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1518 | ThrowInvalidPropertyException(); |
| 1519 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1520 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1521 | pValue->Assign( |
| 1522 | m_pDocument->GetScriptContext()->GetJSValueFromMap(GetModelNode())); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1523 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1524 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1525 | void CXFA_Node::Script_NodeClass_IsContainer(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1526 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1527 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1528 | if (bSetting) { |
| 1529 | ThrowInvalidPropertyException(); |
| 1530 | return; |
| 1531 | } |
| 1532 | pValue->SetBoolean(IsContainerNode()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1533 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1534 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1535 | void CXFA_Node::Script_NodeClass_IsNull(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1536 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1537 | XFA_ATTRIBUTE eAttribute) { |
| 1538 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1539 | ThrowInvalidPropertyException(); |
| 1540 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1541 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1542 | if (GetElementType() == XFA_Element::Subform) { |
| 1543 | pValue->SetBoolean(false); |
| 1544 | return; |
| 1545 | } |
| 1546 | CFX_WideString strValue; |
| 1547 | pValue->SetBoolean(!TryContent(strValue) || strValue.IsEmpty()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1548 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1549 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1550 | void CXFA_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1551 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1552 | XFA_ATTRIBUTE eAttribute) { |
| 1553 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1554 | ThrowInvalidPropertyException(); |
| 1555 | return; |
| 1556 | } |
| 1557 | |
| 1558 | CXFA_NodeArray properts; |
| 1559 | int32_t iSize = GetNodeList(properts, XFA_NODEFILTER_OneOfProperty); |
| 1560 | if (iSize > 0) { |
| 1561 | pValue->Assign( |
| 1562 | m_pDocument->GetScriptContext()->GetJSValueFromMap(properts[0])); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 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) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1583 | ThrowParamCountMismatchException(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) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1619 | if (bSetting) { |
| 1620 | ThrowInvalidPropertyException(); |
| 1621 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1622 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1623 | pValue->SetInteger(GetInteger(eAttribute)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 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) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1639 | if (bSetting) { |
| 1640 | ThrowInvalidPropertyException(); |
| 1641 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1642 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1643 | pValue->SetString(GetBoolean(eAttribute) ? "1" : "0"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 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); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 1861 | pValue->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1862 | } |
| 1863 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1864 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1865 | void CXFA_Node::Script_Attribute_StringRead(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1866 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1867 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1868 | if (bSetting) { |
| 1869 | ThrowInvalidPropertyException(); |
| 1870 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1871 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1872 | |
| 1873 | CFX_WideString wsValue; |
| 1874 | GetAttribute(eAttribute, wsValue); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 1875 | pValue->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1876 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1877 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1878 | void CXFA_Node::Script_WsdlConnection_Execute(CFXJSE_Arguments* pArguments) { |
| 1879 | int32_t argc = pArguments->GetLength(); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1880 | if (argc != 0 && argc != 1) { |
| 1881 | ThrowParamCountMismatchException(L"execute"); |
| 1882 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1883 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1884 | pArguments->GetReturnValue()->SetBoolean(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1885 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1886 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1887 | void CXFA_Node::Script_Delta_Restore(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1888 | if (pArguments->GetLength() != 0) |
| 1889 | ThrowParamCountMismatchException(L"restore"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1890 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1891 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1892 | void CXFA_Node::Script_Delta_CurrentValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1893 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1894 | XFA_ATTRIBUTE eAttribute) {} |
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_SavedValue(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_Target(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_Som_Message(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_SOM_MESSAGETYPE iMessageType) { |
| 1907 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 1908 | if (!pWidgetData) { |
| 1909 | return; |
| 1910 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1911 | bool bNew = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1912 | CXFA_Validate validate = pWidgetData->GetValidate(); |
| 1913 | if (!validate) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1914 | validate = pWidgetData->GetValidate(true); |
| 1915 | bNew = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1916 | } |
| 1917 | if (bSetting) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1918 | switch (iMessageType) { |
| 1919 | case XFA_SOM_ValidationMessage: |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1920 | validate.SetScriptMessageText(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1921 | break; |
| 1922 | case XFA_SOM_FormatMessage: |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1923 | validate.SetFormatMessageText(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1924 | break; |
| 1925 | case XFA_SOM_MandatoryMessage: |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1926 | validate.SetNullMessageText(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1927 | break; |
| 1928 | default: |
| 1929 | break; |
| 1930 | } |
| 1931 | if (!bNew) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 1932 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1933 | if (!pNotify) { |
| 1934 | return; |
| 1935 | } |
| 1936 | pNotify->AddCalcValidate(this); |
| 1937 | } |
| 1938 | } else { |
| 1939 | CFX_WideString wsMessage; |
| 1940 | switch (iMessageType) { |
| 1941 | case XFA_SOM_ValidationMessage: |
| 1942 | validate.GetScriptMessageText(wsMessage); |
| 1943 | break; |
| 1944 | case XFA_SOM_FormatMessage: |
| 1945 | validate.GetFormatMessageText(wsMessage); |
| 1946 | break; |
| 1947 | case XFA_SOM_MandatoryMessage: |
| 1948 | validate.GetNullMessageText(wsMessage); |
| 1949 | break; |
| 1950 | default: |
| 1951 | break; |
| 1952 | } |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 1953 | pValue->SetString(wsMessage.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1954 | } |
| 1955 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1956 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1957 | void CXFA_Node::Script_Som_ValidationMessage(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1958 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1959 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1960 | Script_Som_Message(pValue, bSetting, XFA_SOM_ValidationMessage); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1961 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1962 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1963 | void CXFA_Node::Script_Field_Length(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1964 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1965 | XFA_ATTRIBUTE eAttribute) { |
| 1966 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1967 | ThrowInvalidPropertyException(); |
| 1968 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1969 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1970 | |
| 1971 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 1972 | if (!pWidgetData) { |
| 1973 | pValue->SetInteger(0); |
| 1974 | return; |
| 1975 | } |
| 1976 | pValue->SetInteger(pWidgetData->CountChoiceListItems(true)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1977 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1978 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1979 | void CXFA_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1980 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1981 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1982 | XFA_Element eType = GetElementType(); |
| 1983 | if (eType == XFA_Element::Field) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1984 | Script_Field_DefaultValue(pValue, bSetting, eAttribute); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1985 | return; |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1986 | } |
| 1987 | if (eType == XFA_Element::Draw) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1988 | Script_Draw_DefaultValue(pValue, bSetting, eAttribute); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1989 | return; |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1990 | } |
| 1991 | if (eType == XFA_Element::Boolean) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1992 | Script_Boolean_Value(pValue, bSetting, eAttribute); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1993 | return; |
| 1994 | } |
| 1995 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1996 | CFX_WideString wsNewValue; |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 1997 | if (!(pValue && (pValue->IsNull() || pValue->IsUndefined()))) |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1998 | wsNewValue = pValue->ToWideString(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1999 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2000 | CFX_WideString wsFormatValue(wsNewValue); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 2001 | CXFA_WidgetData* pContainerWidgetData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2002 | if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 2003 | CXFA_NodeArray formNodes; |
| 2004 | GetBindItems(formNodes); |
| 2005 | CFX_WideString wsPicture; |
| 2006 | for (int32_t i = 0; i < formNodes.GetSize(); i++) { |
| 2007 | CXFA_Node* pFormNode = formNodes.GetAt(i); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 2008 | if (!pFormNode || pFormNode->HasRemovedChildren()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2009 | continue; |
| 2010 | } |
| 2011 | pContainerWidgetData = pFormNode->GetContainerWidgetData(); |
| 2012 | if (pContainerWidgetData) { |
| 2013 | pContainerWidgetData->GetPictureContent(wsPicture, |
| 2014 | XFA_VALUEPICTURE_DataBind); |
| 2015 | } |
| 2016 | if (!wsPicture.IsEmpty()) { |
| 2017 | break; |
| 2018 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 2019 | pContainerWidgetData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2020 | } |
| 2021 | } else if (GetPacketID() == XFA_XDPPACKET_Form) { |
| 2022 | pContainerWidgetData = GetContainerWidgetData(); |
| 2023 | } |
| 2024 | if (pContainerWidgetData) { |
tsepez | 6f167c3 | 2016-04-14 15:46:27 -0700 | [diff] [blame] | 2025 | pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2026 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2027 | SetScriptContent(wsNewValue, wsFormatValue, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2028 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2029 | CFX_WideString content = GetScriptContent(true); |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 2030 | if (content.IsEmpty() && eType != XFA_Element::Text && |
| 2031 | eType != XFA_Element::SubmitUrl) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2032 | pValue->SetNull(); |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 2033 | } else if (eType == XFA_Element::Integer) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2034 | pValue->SetInteger(FXSYS_wtoi(content.c_str())); |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 2035 | } else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2036 | CFX_Decimal decimal(content.AsStringC()); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2037 | pValue->SetFloat((FX_FLOAT)(double)decimal); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2038 | } else { |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2039 | pValue->SetString(content.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2040 | } |
| 2041 | } |
| 2042 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2043 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2044 | void CXFA_Node::Script_Som_DefaultValue_Read(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2045 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2046 | XFA_ATTRIBUTE eAttribute) { |
| 2047 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2048 | ThrowInvalidPropertyException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2049 | return; |
| 2050 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2051 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2052 | CFX_WideString content = GetScriptContent(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2053 | if (content.IsEmpty()) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2054 | pValue->SetNull(); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2055 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2056 | } |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2057 | pValue->SetString(content.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2058 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2059 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2060 | void CXFA_Node::Script_Boolean_Value(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2061 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2062 | XFA_ATTRIBUTE eAttribute) { |
| 2063 | if (bSetting) { |
| 2064 | CFX_ByteString newValue; |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 2065 | if (!(pValue && (pValue->IsNull() || pValue->IsUndefined()))) |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2066 | newValue = pValue->ToString(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2067 | |
tsepez | b4c9f3f | 2016-04-13 15:41:21 -0700 | [diff] [blame] | 2068 | int32_t iValue = FXSYS_atoi(newValue.c_str()); |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 2069 | CFX_WideString wsNewValue(iValue == 0 ? L"0" : L"1"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2070 | CFX_WideString wsFormatValue(wsNewValue); |
| 2071 | CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData(); |
| 2072 | if (pContainerWidgetData) { |
tsepez | 6f167c3 | 2016-04-14 15:46:27 -0700 | [diff] [blame] | 2073 | pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2074 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2075 | SetScriptContent(wsNewValue, wsFormatValue, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2076 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2077 | CFX_WideString wsValue = GetScriptContent(true); |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 2078 | pValue->SetBoolean(wsValue == L"1"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2079 | } |
| 2080 | } |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2081 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2082 | void CXFA_Node::Script_Som_BorderColor(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2083 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2084 | XFA_ATTRIBUTE eAttribute) { |
| 2085 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2086 | if (!pWidgetData) { |
| 2087 | return; |
| 2088 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2089 | CXFA_Border border = pWidgetData->GetBorder(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2090 | int32_t iSize = border.CountEdges(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2091 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2092 | int32_t r = 0; |
| 2093 | int32_t g = 0; |
| 2094 | int32_t b = 0; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2095 | StrToRGB(pValue->ToWideString(), r, g, b); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2096 | FX_ARGB rgb = ArgbEncode(100, r, g, b); |
| 2097 | for (int32_t i = 0; i < iSize; ++i) { |
| 2098 | CXFA_Edge edge = border.GetEdge(i); |
| 2099 | edge.SetColor(rgb); |
| 2100 | } |
| 2101 | } else { |
| 2102 | CXFA_Edge edge = border.GetEdge(0); |
| 2103 | FX_ARGB color = edge.GetColor(); |
| 2104 | int32_t a, r, g, b; |
| 2105 | ArgbDecode(color, a, r, g, b); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2106 | CFX_WideString strColor; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2107 | strColor.Format(L"%d,%d,%d", r, g, b); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2108 | pValue->SetString(strColor.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2109 | } |
| 2110 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2111 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2112 | void CXFA_Node::Script_Som_BorderWidth(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2113 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2114 | XFA_ATTRIBUTE eAttribute) { |
| 2115 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2116 | if (!pWidgetData) { |
| 2117 | return; |
| 2118 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2119 | CXFA_Border border = pWidgetData->GetBorder(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2120 | int32_t iSize = border.CountEdges(); |
| 2121 | CFX_WideString wsThickness; |
| 2122 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2123 | wsThickness = pValue->ToWideString(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2124 | for (int32_t i = 0; i < iSize; ++i) { |
| 2125 | CXFA_Edge edge = border.GetEdge(i); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2126 | CXFA_Measurement thickness(wsThickness.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2127 | edge.SetMSThickness(thickness); |
| 2128 | } |
| 2129 | } else { |
| 2130 | CXFA_Edge edge = border.GetEdge(0); |
| 2131 | CXFA_Measurement thickness = edge.GetMSThickness(); |
| 2132 | thickness.ToString(wsThickness); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2133 | pValue->SetString(wsThickness.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2134 | } |
| 2135 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2136 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2137 | void CXFA_Node::Script_Som_FillColor(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2138 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2139 | XFA_ATTRIBUTE eAttribute) { |
| 2140 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2141 | if (!pWidgetData) { |
| 2142 | return; |
| 2143 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2144 | CXFA_Border border = pWidgetData->GetBorder(true); |
| 2145 | CXFA_Fill borderfill = border.GetFill(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2146 | CXFA_Node* pNode = borderfill.GetNode(); |
| 2147 | if (!pNode) { |
| 2148 | return; |
| 2149 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2150 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2151 | int32_t r; |
| 2152 | int32_t g; |
| 2153 | int32_t b; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2154 | StrToRGB(pValue->ToWideString(), r, g, b); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2155 | FX_ARGB color = ArgbEncode(0xff, r, g, b); |
| 2156 | borderfill.SetColor(color); |
| 2157 | } else { |
| 2158 | FX_ARGB color = borderfill.GetColor(); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2159 | int32_t a; |
| 2160 | int32_t r; |
| 2161 | int32_t g; |
| 2162 | int32_t b; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2163 | ArgbDecode(color, a, r, g, b); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2164 | CFX_WideString wsColor; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2165 | wsColor.Format(L"%d,%d,%d", r, g, b); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2166 | pValue->SetString(wsColor.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2167 | } |
| 2168 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2169 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2170 | void CXFA_Node::Script_Som_DataNode(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2171 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2172 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2173 | if (bSetting) { |
| 2174 | ThrowInvalidPropertyException(); |
| 2175 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2176 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2177 | |
| 2178 | CXFA_Node* pDataNode = GetBindData(); |
| 2179 | if (!pDataNode) { |
| 2180 | pValue->SetNull(); |
| 2181 | return; |
| 2182 | } |
| 2183 | |
| 2184 | pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pDataNode)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2185 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2186 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2187 | void CXFA_Node::Script_Draw_DefaultValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2188 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2189 | XFA_ATTRIBUTE eAttribute) { |
| 2190 | if (bSetting) { |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 2191 | if (pValue && pValue->IsString()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2192 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 2193 | ASSERT(pWidgetData); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 2194 | XFA_Element uiType = pWidgetData->GetUIType(); |
| 2195 | if (uiType == XFA_Element::Text) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2196 | CFX_WideString wsNewValue = pValue->ToWideString(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2197 | CFX_WideString wsFormatValue(wsNewValue); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2198 | SetScriptContent(wsNewValue, wsFormatValue, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2199 | } |
| 2200 | } |
| 2201 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2202 | CFX_WideString content = GetScriptContent(true); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2203 | if (content.IsEmpty()) |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2204 | pValue->SetNull(); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2205 | else |
| 2206 | pValue->SetString(content.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2207 | } |
| 2208 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2209 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2210 | void CXFA_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2211 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2212 | XFA_ATTRIBUTE eAttribute) { |
| 2213 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2214 | if (!pWidgetData) { |
| 2215 | return; |
| 2216 | } |
| 2217 | if (bSetting) { |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 2218 | if (pValue && pValue->IsNull()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2219 | pWidgetData->m_bPreNull = pWidgetData->m_bIsNull; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2220 | pWidgetData->m_bIsNull = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2221 | } else { |
| 2222 | pWidgetData->m_bPreNull = pWidgetData->m_bIsNull; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2223 | pWidgetData->m_bIsNull = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2224 | } |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2225 | CFX_WideString wsNewText; |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 2226 | if (!(pValue && (pValue->IsNull() || pValue->IsUndefined()))) |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2227 | wsNewText = pValue->ToWideString(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2228 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2229 | CXFA_Node* pUIChild = pWidgetData->GetUIChild(); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2230 | if (pUIChild->GetElementType() == XFA_Element::NumericEdit) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2231 | int32_t iLeadDigits = 0; |
| 2232 | int32_t iFracDigits = 0; |
| 2233 | pWidgetData->GetLeadDigits(iLeadDigits); |
| 2234 | pWidgetData->GetFracDigits(iFracDigits); |
dsinclair | 44d054c | 2016-04-06 10:23:46 -0700 | [diff] [blame] | 2235 | wsNewText = |
| 2236 | pWidgetData->NumericLimit(wsNewText, iLeadDigits, iFracDigits); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2237 | } |
| 2238 | CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData(); |
| 2239 | CFX_WideString wsFormatText(wsNewText); |
| 2240 | if (pContainerWidgetData) { |
tsepez | 6f167c3 | 2016-04-14 15:46:27 -0700 | [diff] [blame] | 2241 | pContainerWidgetData->GetFormatDataValue(wsNewText, wsFormatText); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2242 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2243 | SetScriptContent(wsNewText, wsFormatText, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2244 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2245 | CFX_WideString content = GetScriptContent(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2246 | if (content.IsEmpty()) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2247 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2248 | } else { |
| 2249 | CXFA_Node* pUIChild = pWidgetData->GetUIChild(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2250 | CXFA_Value defVal = pWidgetData->GetFormValue(); |
| 2251 | CXFA_Node* pNode = defVal.GetNode()->GetNodeItem(XFA_NODEITEM_FirstChild); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2252 | if (pNode && pNode->GetElementType() == XFA_Element::Decimal) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 2253 | if (pUIChild->GetElementType() == XFA_Element::NumericEdit && |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2254 | (pNode->GetInteger(XFA_ATTRIBUTE_FracDigits) == -1)) { |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2255 | pValue->SetString(content.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2256 | } else { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2257 | CFX_Decimal decimal(content.AsStringC()); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2258 | pValue->SetFloat((FX_FLOAT)(double)decimal); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2259 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2260 | } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2261 | pValue->SetInteger(FXSYS_wtoi(content.c_str())); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2262 | } else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2263 | pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? false : true); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2264 | } else if (pNode && pNode->GetElementType() == XFA_Element::Float) { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2265 | CFX_Decimal decimal(content.AsStringC()); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2266 | pValue->SetFloat((FX_FLOAT)(double)decimal); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2267 | } else { |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2268 | pValue->SetString(content.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2269 | } |
| 2270 | } |
| 2271 | } |
| 2272 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2273 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2274 | void CXFA_Node::Script_Field_EditValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2275 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2276 | XFA_ATTRIBUTE eAttribute) { |
| 2277 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2278 | if (!pWidgetData) { |
| 2279 | return; |
| 2280 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2281 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2282 | pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Edit); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2283 | } else { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2284 | CFX_WideString wsValue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2285 | pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Edit); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2286 | pValue->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2287 | } |
| 2288 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2289 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2290 | void CXFA_Node::Script_Som_FontColor(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2291 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2292 | XFA_ATTRIBUTE eAttribute) { |
| 2293 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2294 | if (!pWidgetData) { |
| 2295 | return; |
| 2296 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2297 | CXFA_Font font = pWidgetData->GetFont(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2298 | CXFA_Node* pNode = font.GetNode(); |
| 2299 | if (!pNode) { |
| 2300 | return; |
| 2301 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2302 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2303 | int32_t r; |
| 2304 | int32_t g; |
| 2305 | int32_t b; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2306 | StrToRGB(pValue->ToWideString(), r, g, b); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2307 | FX_ARGB color = ArgbEncode(0xff, r, g, b); |
| 2308 | font.SetColor(color); |
| 2309 | } else { |
| 2310 | FX_ARGB color = font.GetColor(); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2311 | int32_t a; |
| 2312 | int32_t r; |
| 2313 | int32_t g; |
| 2314 | int32_t b; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2315 | ArgbDecode(color, a, r, g, b); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2316 | CFX_WideString wsColor; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2317 | wsColor.Format(L"%d,%d,%d", r, g, b); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2318 | pValue->SetString(wsColor.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2319 | } |
| 2320 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2321 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2322 | void CXFA_Node::Script_Field_FormatMessage(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2323 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2324 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2325 | Script_Som_Message(pValue, bSetting, XFA_SOM_FormatMessage); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2326 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2327 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2328 | void CXFA_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2329 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2330 | XFA_ATTRIBUTE eAttribute) { |
| 2331 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2332 | if (!pWidgetData) { |
| 2333 | return; |
| 2334 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2335 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2336 | pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Display); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2337 | } else { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2338 | CFX_WideString wsValue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2339 | pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Display); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2340 | pValue->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2341 | } |
| 2342 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2343 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2344 | void CXFA_Node::Script_Som_Mandatory(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2345 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2346 | XFA_ATTRIBUTE eAttribute) { |
| 2347 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2348 | if (!pWidgetData) { |
| 2349 | return; |
| 2350 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2351 | CXFA_Validate validate = pWidgetData->GetValidate(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2352 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2353 | validate.SetNullTest(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2354 | } else { |
| 2355 | int32_t iValue = validate.GetNullTest(); |
| 2356 | const XFA_ATTRIBUTEENUMINFO* pInfo = |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 2357 | GetAttributeEnumByID((XFA_ATTRIBUTEENUM)iValue); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2358 | CFX_WideString wsValue; |
| 2359 | if (pInfo) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2360 | wsValue = pInfo->pName; |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2361 | pValue->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2362 | } |
| 2363 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2364 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2365 | void CXFA_Node::Script_Som_MandatoryMessage(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2366 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2367 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2368 | Script_Som_Message(pValue, bSetting, XFA_SOM_MandatoryMessage); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2369 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2370 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2371 | void CXFA_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2372 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2373 | XFA_ATTRIBUTE eAttribute) { |
| 2374 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2375 | ThrowInvalidPropertyException(); |
| 2376 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2377 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2378 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2379 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2380 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2381 | void CXFA_Node::Script_Field_SelectedIndex(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2382 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2383 | XFA_ATTRIBUTE eAttribute) { |
| 2384 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2385 | if (!pWidgetData) { |
| 2386 | return; |
| 2387 | } |
| 2388 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2389 | int32_t iIndex = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2390 | if (iIndex == -1) { |
| 2391 | pWidgetData->ClearAllSelections(); |
| 2392 | return; |
| 2393 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2394 | pWidgetData->SetItemState(iIndex, true, true, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2395 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2396 | pValue->SetInteger(pWidgetData->GetSelectedItem()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2397 | } |
| 2398 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2399 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2400 | void CXFA_Node::Script_Field_ClearItems(CFXJSE_Arguments* pArguments) { |
| 2401 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2402 | if (!pWidgetData) { |
| 2403 | return; |
| 2404 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2405 | pWidgetData->DeleteItem(-1, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2406 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2407 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2408 | void CXFA_Node::Script_Field_ExecEvent(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2409 | if (pArguments->GetLength() != 1) { |
| 2410 | ThrowParamCountMismatchException(L"execEvent"); |
| 2411 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2412 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2413 | |
| 2414 | CFX_ByteString eventString = pArguments->GetUTF8String(0); |
| 2415 | int32_t iRet = execSingleEventByName( |
| 2416 | CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(), |
| 2417 | XFA_Element::Field); |
| 2418 | if (eventString != "validate") |
| 2419 | return; |
| 2420 | |
| 2421 | pArguments->GetReturnValue()->SetBoolean( |
| 2422 | (iRet == XFA_EVENTERROR_Error) ? false : true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2423 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2424 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2425 | void CXFA_Node::Script_Field_ExecInitialize(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2426 | if (pArguments->GetLength() != 0) { |
| 2427 | ThrowParamCountMismatchException(L"execInitialize"); |
| 2428 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2429 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2430 | |
| 2431 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2432 | if (!pNotify) |
| 2433 | return; |
| 2434 | |
| 2435 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize, false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2436 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2437 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2438 | void CXFA_Node::Script_Field_DeleteItem(CFXJSE_Arguments* pArguments) { |
| 2439 | int32_t iLength = pArguments->GetLength(); |
| 2440 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2441 | ThrowParamCountMismatchException(L"deleteItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2442 | return; |
| 2443 | } |
| 2444 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2445 | if (!pWidgetData) { |
| 2446 | return; |
| 2447 | } |
| 2448 | int32_t iIndex = pArguments->GetInt32(0); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2449 | bool bValue = pWidgetData->DeleteItem(iIndex, true, true); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2450 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2451 | if (pValue) |
| 2452 | pValue->SetBoolean(bValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2453 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2454 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2455 | void CXFA_Node::Script_Field_GetSaveItem(CFXJSE_Arguments* pArguments) { |
| 2456 | int32_t iLength = pArguments->GetLength(); |
| 2457 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2458 | ThrowParamCountMismatchException(L"getSaveItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2459 | return; |
| 2460 | } |
| 2461 | int32_t iIndex = pArguments->GetInt32(0); |
| 2462 | if (iIndex < 0) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2463 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2464 | return; |
| 2465 | } |
| 2466 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2467 | if (!pWidgetData) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2468 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2469 | return; |
| 2470 | } |
| 2471 | CFX_WideString wsValue; |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2472 | if (!pWidgetData->GetChoiceListItem(wsValue, iIndex, true)) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2473 | pArguments->GetReturnValue()->SetNull(); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2474 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2475 | } |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2476 | pArguments->GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2477 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2478 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2479 | void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments) { |
| 2480 | int32_t iLength = pArguments->GetLength(); |
| 2481 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2482 | ThrowParamCountMismatchException(L"boundItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2483 | return; |
| 2484 | } |
| 2485 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2486 | if (!pWidgetData) { |
| 2487 | return; |
| 2488 | } |
| 2489 | CFX_ByteString bsValue = pArguments->GetUTF8String(0); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2490 | CFX_WideString wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2491 | CFX_WideString wsBoundValue; |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2492 | pWidgetData->GetItemValue(wsValue.AsStringC(), wsBoundValue); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2493 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2494 | if (pValue) |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2495 | pValue->SetString(wsBoundValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2496 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2497 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2498 | void CXFA_Node::Script_Field_GetItemState(CFXJSE_Arguments* pArguments) { |
| 2499 | int32_t iLength = pArguments->GetLength(); |
| 2500 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2501 | ThrowParamCountMismatchException(L"getItemState"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2502 | return; |
| 2503 | } |
| 2504 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2505 | if (!pWidgetData) { |
| 2506 | return; |
| 2507 | } |
| 2508 | int32_t iIndex = pArguments->GetInt32(0); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2509 | bool bValue = pWidgetData->GetItemState(iIndex); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2510 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2511 | if (pValue) |
| 2512 | pValue->SetBoolean(bValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2513 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2514 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2515 | void CXFA_Node::Script_Field_ExecCalculate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2516 | if (pArguments->GetLength() != 0) { |
| 2517 | ThrowParamCountMismatchException(L"execCalculate"); |
| 2518 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2519 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2520 | |
| 2521 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2522 | if (!pNotify) |
| 2523 | return; |
| 2524 | |
| 2525 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate, false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2526 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2527 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2528 | void CXFA_Node::Script_Field_SetItems(CFXJSE_Arguments* pArguments) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2529 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2530 | void CXFA_Node::Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments) { |
| 2531 | int32_t iLength = pArguments->GetLength(); |
| 2532 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2533 | ThrowParamCountMismatchException(L"getDisplayItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2534 | return; |
| 2535 | } |
| 2536 | int32_t iIndex = pArguments->GetInt32(0); |
| 2537 | if (iIndex < 0) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2538 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2539 | return; |
| 2540 | } |
| 2541 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2542 | if (!pWidgetData) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2543 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2544 | return; |
| 2545 | } |
| 2546 | CFX_WideString wsValue; |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2547 | if (!pWidgetData->GetChoiceListItem(wsValue, iIndex, false)) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2548 | pArguments->GetReturnValue()->SetNull(); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2549 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2550 | } |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2551 | pArguments->GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2552 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2553 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2554 | void CXFA_Node::Script_Field_SetItemState(CFXJSE_Arguments* pArguments) { |
| 2555 | int32_t iLength = pArguments->GetLength(); |
| 2556 | if (iLength != 2) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2557 | ThrowParamCountMismatchException(L"setItemState"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2558 | return; |
| 2559 | } |
| 2560 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2561 | if (!pWidgetData) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2562 | return; |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2563 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2564 | int32_t iIndex = pArguments->GetInt32(0); |
| 2565 | if (pArguments->GetInt32(1) != 0) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2566 | pWidgetData->SetItemState(iIndex, true, true, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2567 | } else { |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2568 | if (pWidgetData->GetItemState(iIndex)) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2569 | pWidgetData->SetItemState(iIndex, false, true, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2570 | } |
| 2571 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2572 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2573 | void CXFA_Node::Script_Field_AddItem(CFXJSE_Arguments* pArguments) { |
| 2574 | int32_t iLength = pArguments->GetLength(); |
| 2575 | if (iLength < 1 || iLength > 2) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2576 | ThrowParamCountMismatchException(L"addItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2577 | return; |
| 2578 | } |
| 2579 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2580 | if (!pWidgetData) { |
| 2581 | return; |
| 2582 | } |
| 2583 | CFX_WideString wsLabel; |
| 2584 | CFX_WideString wsValue; |
| 2585 | if (iLength >= 1) { |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 2586 | CFX_ByteString bsLabel = pArguments->GetUTF8String(0); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2587 | wsLabel = CFX_WideString::FromUTF8(bsLabel.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2588 | } |
| 2589 | if (iLength >= 2) { |
| 2590 | CFX_ByteString bsValue = pArguments->GetUTF8String(1); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2591 | wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2592 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2593 | pWidgetData->InsertItem(wsLabel, wsValue, -1, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2594 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2595 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2596 | void CXFA_Node::Script_Field_ExecValidate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2597 | if (pArguments->GetLength() != 0) { |
| 2598 | ThrowParamCountMismatchException(L"execValidate"); |
| 2599 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2600 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2601 | |
| 2602 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2603 | if (!pNotify) { |
| 2604 | pArguments->GetReturnValue()->SetBoolean(false); |
| 2605 | return; |
| 2606 | } |
| 2607 | |
| 2608 | int32_t iRet = |
| 2609 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate, false, false); |
| 2610 | pArguments->GetReturnValue()->SetBoolean( |
| 2611 | (iRet == XFA_EVENTERROR_Error) ? false : true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2612 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2613 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2614 | void CXFA_Node::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2615 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2616 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2617 | if (bSetting) |
| 2618 | ThrowInvalidPropertyException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2619 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2620 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2621 | void CXFA_Node::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2622 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2623 | XFA_ATTRIBUTE eAttribute) { |
| 2624 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2625 | if (!pWidgetData) { |
| 2626 | return; |
| 2627 | } |
| 2628 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2629 | pWidgetData->SetSelectedMemberByValue(pValue->ToWideString().AsStringC(), |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2630 | true, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2631 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2632 | CFX_WideString wsValue = GetScriptContent(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2633 | XFA_VERSION curVersion = GetDocument()->GetCurVersionMode(); |
| 2634 | if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2635 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2636 | } else { |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2637 | pValue->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2638 | } |
| 2639 | } |
| 2640 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2641 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2642 | void CXFA_Node::Script_ExclGroup_Transient(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2643 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2644 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2645 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2646 | void CXFA_Node::Script_ExclGroup_ExecEvent(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2647 | if (pArguments->GetLength() != 1) { |
| 2648 | ThrowParamCountMismatchException(L"execEvent"); |
| 2649 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2650 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2651 | |
| 2652 | CFX_ByteString eventString = pArguments->GetUTF8String(0); |
| 2653 | execSingleEventByName( |
| 2654 | CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(), |
| 2655 | XFA_Element::ExclGroup); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2656 | } |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2657 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2658 | void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments) { |
| 2659 | int32_t argc = pArguments->GetLength(); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2660 | if (argc < 0 || argc > 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2661 | ThrowParamCountMismatchException(L"selectedMember"); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2662 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2663 | } |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2664 | |
| 2665 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2666 | if (!pWidgetData) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2667 | pArguments->GetReturnValue()->SetNull(); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2668 | return; |
| 2669 | } |
| 2670 | |
| 2671 | CXFA_Node* pReturnNode = nullptr; |
| 2672 | if (argc == 0) { |
| 2673 | pReturnNode = pWidgetData->GetSelectedMember(); |
| 2674 | } else { |
| 2675 | CFX_ByteString szName; |
| 2676 | szName = pArguments->GetUTF8String(0); |
| 2677 | pReturnNode = pWidgetData->SetSelectedMember( |
| 2678 | CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC(), true); |
| 2679 | } |
| 2680 | if (!pReturnNode) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2681 | pArguments->GetReturnValue()->SetNull(); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2682 | return; |
| 2683 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2684 | pArguments->GetReturnValue()->Assign( |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2685 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pReturnNode)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2686 | } |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2687 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2688 | void CXFA_Node::Script_ExclGroup_ExecInitialize(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2689 | if (pArguments->GetLength() != 0) { |
| 2690 | ThrowParamCountMismatchException(L"execInitialize"); |
| 2691 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2692 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2693 | |
| 2694 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2695 | if (!pNotify) |
| 2696 | return; |
| 2697 | |
| 2698 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2699 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2700 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2701 | void CXFA_Node::Script_ExclGroup_ExecCalculate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2702 | if (pArguments->GetLength() != 0) { |
| 2703 | ThrowParamCountMismatchException(L"execCalculate"); |
| 2704 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2705 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2706 | |
| 2707 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2708 | if (!pNotify) |
| 2709 | return; |
| 2710 | |
| 2711 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2712 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2713 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2714 | void CXFA_Node::Script_ExclGroup_ExecValidate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2715 | if (pArguments->GetLength() != 0) { |
| 2716 | ThrowParamCountMismatchException(L"execValidate"); |
| 2717 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2718 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2719 | |
| 2720 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2721 | if (!pNotify) { |
| 2722 | pArguments->GetReturnValue()->SetBoolean(false); |
| 2723 | return; |
| 2724 | } |
| 2725 | |
| 2726 | int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); |
| 2727 | pArguments->GetReturnValue()->SetBoolean( |
| 2728 | (iRet == XFA_EVENTERROR_Error) ? false : true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2729 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2730 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2731 | void CXFA_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2732 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2733 | XFA_ATTRIBUTE eAttribute) { |
| 2734 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2735 | int32_t iTo = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2736 | int32_t iFrom = Subform_and_SubformSet_InstanceIndex(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 2737 | CXFA_Node* pManagerNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2738 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; |
| 2739 | pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2740 | if (pNode->GetElementType() == XFA_Element::InstanceManager) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2741 | pManagerNode = pNode; |
| 2742 | break; |
| 2743 | } |
| 2744 | } |
| 2745 | if (pManagerNode) { |
| 2746 | pManagerNode->InstanceManager_MoveInstance(iTo, iFrom); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2747 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2748 | if (!pNotify) { |
| 2749 | return; |
| 2750 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2751 | CXFA_Node* pToInstance = GetItem(pManagerNode, iTo); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2752 | if (pToInstance && |
| 2753 | pToInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2754 | pNotify->RunSubformIndexChange(pToInstance); |
| 2755 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2756 | CXFA_Node* pFromInstance = GetItem(pManagerNode, iFrom); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 2757 | if (pFromInstance && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2758 | pFromInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2759 | pNotify->RunSubformIndexChange(pFromInstance); |
| 2760 | } |
| 2761 | } |
| 2762 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2763 | pValue->SetInteger(Subform_and_SubformSet_InstanceIndex()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2764 | } |
| 2765 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2766 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2767 | void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2768 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2769 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2770 | if (bSetting) { |
| 2771 | ThrowInvalidPropertyException(); |
| 2772 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2773 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2774 | |
| 2775 | CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name); |
| 2776 | CXFA_Node* pInstanceMgr = nullptr; |
| 2777 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; |
| 2778 | pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { |
| 2779 | if (pNode->GetElementType() == XFA_Element::InstanceManager) { |
| 2780 | CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name); |
| 2781 | if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' && |
| 2782 | wsInstMgrName.Mid(1) == wsName) { |
| 2783 | pInstanceMgr = pNode; |
| 2784 | } |
| 2785 | break; |
| 2786 | } |
| 2787 | } |
| 2788 | if (!pInstanceMgr) { |
| 2789 | pValue->SetNull(); |
| 2790 | return; |
| 2791 | } |
| 2792 | |
| 2793 | pValue->Assign( |
| 2794 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pInstanceMgr)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2795 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2796 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2797 | void CXFA_Node::Script_Subform_Locale(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2798 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2799 | XFA_ATTRIBUTE eAttribute) { |
| 2800 | if (bSetting) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2801 | SetCData(XFA_ATTRIBUTE_Locale, pValue->ToWideString(), true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2802 | } else { |
| 2803 | CFX_WideString wsLocaleName; |
| 2804 | GetLocaleName(wsLocaleName); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2805 | pValue->SetString(wsLocaleName.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2806 | } |
| 2807 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2808 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2809 | void CXFA_Node::Script_Subform_ExecEvent(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2810 | if (pArguments->GetLength() != 1) { |
| 2811 | ThrowParamCountMismatchException(L"execEvent"); |
| 2812 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2813 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2814 | |
| 2815 | CFX_ByteString eventString = pArguments->GetUTF8String(0); |
| 2816 | execSingleEventByName( |
| 2817 | CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(), |
| 2818 | XFA_Element::Subform); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2819 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2820 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2821 | void CXFA_Node::Script_Subform_ExecInitialize(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2822 | if (pArguments->GetLength() != 0) { |
| 2823 | ThrowParamCountMismatchException(L"execInitialize"); |
| 2824 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2825 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2826 | |
| 2827 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2828 | if (!pNotify) |
| 2829 | return; |
| 2830 | |
| 2831 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2832 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2833 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2834 | void CXFA_Node::Script_Subform_ExecCalculate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2835 | if (pArguments->GetLength() != 0) { |
| 2836 | ThrowParamCountMismatchException(L"execCalculate"); |
| 2837 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2838 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2839 | |
| 2840 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2841 | if (!pNotify) |
| 2842 | return; |
| 2843 | |
| 2844 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2845 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2846 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2847 | void CXFA_Node::Script_Subform_ExecValidate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2848 | if (pArguments->GetLength() != 0) { |
| 2849 | ThrowParamCountMismatchException(L"execValidate"); |
| 2850 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2851 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2852 | |
| 2853 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2854 | if (!pNotify) { |
| 2855 | pArguments->GetReturnValue()->SetBoolean(false); |
| 2856 | return; |
| 2857 | } |
| 2858 | |
| 2859 | int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); |
| 2860 | pArguments->GetReturnValue()->SetBoolean( |
| 2861 | (iRet == XFA_EVENTERROR_Error) ? false : true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2862 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2863 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2864 | void CXFA_Node::Script_Subform_GetInvalidObjects(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2865 | if (pArguments->GetLength() != 0) |
| 2866 | ThrowParamCountMismatchException(L"getInvalidObjects"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2867 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2868 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2869 | int32_t CXFA_Node::Subform_and_SubformSet_InstanceIndex() { |
| 2870 | int32_t index = 0; |
| 2871 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; |
| 2872 | pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2873 | if ((pNode->GetElementType() == XFA_Element::Subform) || |
| 2874 | (pNode->GetElementType() == XFA_Element::SubformSet)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2875 | index++; |
| 2876 | } else { |
| 2877 | break; |
| 2878 | } |
| 2879 | } |
| 2880 | return index; |
| 2881 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2882 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2883 | void CXFA_Node::Script_Template_FormNodes(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2884 | if (pArguments->GetLength() != 1) { |
| 2885 | ThrowParamCountMismatchException(L"formNodes"); |
| 2886 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2887 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2888 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2889 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2890 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2891 | void CXFA_Node::Script_Template_Remerge(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2892 | if (pArguments->GetLength() != 0) { |
| 2893 | ThrowParamCountMismatchException(L"remerge"); |
| 2894 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2895 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2896 | m_pDocument->DoDataRemerge(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2897 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2898 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2899 | void CXFA_Node::Script_Template_ExecInitialize(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2900 | if (pArguments->GetLength() != 0) { |
| 2901 | ThrowParamCountMismatchException(L"execInitialize"); |
| 2902 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2903 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2904 | |
| 2905 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2906 | if (!pWidgetData) { |
| 2907 | pArguments->GetReturnValue()->SetBoolean(false); |
| 2908 | return; |
| 2909 | } |
| 2910 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 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_CreateNode(CFXJSE_Arguments* pArguments) { |
| 2914 | int32_t argc = pArguments->GetLength(); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2915 | if (argc <= 0 || argc >= 4) { |
| 2916 | ThrowParamCountMismatchException(L"createNode"); |
| 2917 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2918 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2919 | |
| 2920 | CFX_WideString strName; |
| 2921 | CFX_WideString strNameSpace; |
| 2922 | CFX_ByteString bsTagName = pArguments->GetUTF8String(0); |
| 2923 | CFX_WideString strTagName = CFX_WideString::FromUTF8(bsTagName.AsStringC()); |
| 2924 | if (argc > 1) { |
| 2925 | CFX_ByteString bsName = pArguments->GetUTF8String(1); |
| 2926 | strName = CFX_WideString::FromUTF8(bsName.AsStringC()); |
| 2927 | if (argc == 3) { |
| 2928 | CFX_ByteString bsNameSpace = pArguments->GetUTF8String(2); |
| 2929 | strNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC()); |
| 2930 | } |
| 2931 | } |
| 2932 | |
| 2933 | XFA_Element eType = XFA_GetElementTypeForName(strTagName.AsStringC()); |
| 2934 | CXFA_Node* pNewNode = CreateSamePacketNode(eType); |
| 2935 | if (!pNewNode) { |
| 2936 | pArguments->GetReturnValue()->SetNull(); |
| 2937 | return; |
| 2938 | } |
| 2939 | |
| 2940 | if (strName.IsEmpty()) { |
| 2941 | pArguments->GetReturnValue()->Assign( |
| 2942 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode)); |
| 2943 | return; |
| 2944 | } |
| 2945 | |
| 2946 | if (!GetAttributeOfElement(eType, XFA_ATTRIBUTE_Name, |
| 2947 | XFA_XDPPACKET_UNKNOWN)) { |
| 2948 | ThrowMissingPropertyException(strTagName, L"name"); |
| 2949 | return; |
| 2950 | } |
| 2951 | |
| 2952 | pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, strName.AsStringC(), true); |
| 2953 | if (pNewNode->GetPacketID() == XFA_XDPPACKET_Datasets) |
| 2954 | pNewNode->CreateXMLMappingNode(); |
| 2955 | |
| 2956 | pArguments->GetReturnValue()->Assign( |
| 2957 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2958 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2959 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2960 | void CXFA_Node::Script_Template_Recalculate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2961 | if (pArguments->GetLength() != 1) { |
| 2962 | ThrowParamCountMismatchException(L"recalculate"); |
| 2963 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2964 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2965 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2966 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2967 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2968 | void CXFA_Node::Script_Template_ExecCalculate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2969 | if (pArguments->GetLength() != 0) { |
| 2970 | ThrowParamCountMismatchException(L"execCalculate"); |
| 2971 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2972 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2973 | |
| 2974 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2975 | if (!pWidgetData) { |
| 2976 | pArguments->GetReturnValue()->SetBoolean(false); |
| 2977 | return; |
| 2978 | } |
| 2979 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2980 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2981 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2982 | void CXFA_Node::Script_Template_ExecValidate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2983 | if (pArguments->GetLength() != 0) { |
| 2984 | ThrowParamCountMismatchException(L"execValidate"); |
| 2985 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2986 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2987 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2988 | if (!pWidgetData) { |
| 2989 | pArguments->GetReturnValue()->SetBoolean(false); |
| 2990 | return; |
| 2991 | } |
| 2992 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2993 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2994 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2995 | void CXFA_Node::Script_Manifest_Evaluate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2996 | if (pArguments->GetLength() != 0) { |
| 2997 | ThrowParamCountMismatchException(L"evaluate"); |
| 2998 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2999 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3000 | |
| 3001 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 3002 | if (!pWidgetData) { |
| 3003 | pArguments->GetReturnValue()->SetBoolean(false); |
| 3004 | return; |
| 3005 | } |
| 3006 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3007 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3008 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3009 | void CXFA_Node::Script_InstanceManager_Max(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3010 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3011 | XFA_ATTRIBUTE eAttribute) { |
| 3012 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3013 | ThrowInvalidPropertyException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3014 | return; |
| 3015 | } |
| 3016 | CXFA_Occur nodeOccur(GetOccurNode()); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3017 | pValue->SetInteger(nodeOccur.GetMax()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3018 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3019 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3020 | void CXFA_Node::Script_InstanceManager_Min(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3021 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3022 | XFA_ATTRIBUTE eAttribute) { |
| 3023 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3024 | ThrowInvalidPropertyException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3025 | return; |
| 3026 | } |
| 3027 | CXFA_Occur nodeOccur(GetOccurNode()); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3028 | pValue->SetInteger(nodeOccur.GetMin()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3029 | } |
tsepez | aadedf9 | 2016-05-12 10:08:06 -0700 | [diff] [blame] | 3030 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3031 | void CXFA_Node::Script_InstanceManager_Count(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3032 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3033 | XFA_ATTRIBUTE eAttribute) { |
| 3034 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3035 | int32_t iDesired = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3036 | InstanceManager_SetInstances(iDesired); |
| 3037 | } else { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3038 | pValue->SetInteger(GetCount(this)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3039 | } |
| 3040 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3041 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3042 | void CXFA_Node::Script_InstanceManager_MoveInstance( |
| 3043 | CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3044 | if (pArguments->GetLength() != 2) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3045 | pArguments->GetReturnValue()->SetUndefined(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3046 | return; |
| 3047 | } |
| 3048 | int32_t iFrom = pArguments->GetInt32(0); |
| 3049 | int32_t iTo = pArguments->GetInt32(1); |
| 3050 | InstanceManager_MoveInstance(iTo, iFrom); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3051 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3052 | if (!pNotify) { |
| 3053 | return; |
| 3054 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3055 | CXFA_Node* pToInstance = GetItem(this, iTo); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3056 | if (pToInstance && pToInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3057 | pNotify->RunSubformIndexChange(pToInstance); |
| 3058 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3059 | CXFA_Node* pFromInstance = GetItem(this, iFrom); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3060 | if (pFromInstance && |
| 3061 | pFromInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3062 | pNotify->RunSubformIndexChange(pFromInstance); |
| 3063 | } |
| 3064 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3065 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3066 | void CXFA_Node::Script_InstanceManager_RemoveInstance( |
| 3067 | CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3068 | if (pArguments->GetLength() != 1) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3069 | pArguments->GetReturnValue()->SetUndefined(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3070 | return; |
| 3071 | } |
| 3072 | int32_t iIndex = pArguments->GetInt32(0); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3073 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3074 | if (iIndex < 0 || iIndex >= iCount) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3075 | ThrowIndexOutOfBoundsException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3076 | return; |
| 3077 | } |
| 3078 | CXFA_Occur nodeOccur(GetOccurNode()); |
| 3079 | int32_t iMin = nodeOccur.GetMin(); |
| 3080 | if (iCount - 1 < iMin) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3081 | ThrowTooManyOccurancesException(L"min"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3082 | return; |
| 3083 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3084 | CXFA_Node* pRemoveInstance = GetItem(this, iIndex); |
| 3085 | RemoveItem(this, pRemoveInstance); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3086 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3087 | if (pNotify) { |
| 3088 | for (int32_t i = iIndex; i < iCount - 1; i++) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3089 | CXFA_Node* pSubformInstance = GetItem(this, i); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3090 | if (pSubformInstance && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3091 | pSubformInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3092 | pNotify->RunSubformIndexChange(pSubformInstance); |
| 3093 | } |
| 3094 | } |
| 3095 | } |
| 3096 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3097 | if (!pLayoutPro) { |
| 3098 | return; |
| 3099 | } |
| 3100 | pLayoutPro->AddChangedContainer( |
| 3101 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3102 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3103 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3104 | void CXFA_Node::Script_InstanceManager_SetInstances( |
| 3105 | CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3106 | if (pArguments->GetLength() != 1) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3107 | pArguments->GetReturnValue()->SetUndefined(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3108 | return; |
| 3109 | } |
| 3110 | int32_t iDesired = pArguments->GetInt32(0); |
| 3111 | InstanceManager_SetInstances(iDesired); |
| 3112 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3113 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3114 | void CXFA_Node::Script_InstanceManager_AddInstance( |
| 3115 | CFXJSE_Arguments* pArguments) { |
| 3116 | int32_t argc = pArguments->GetLength(); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3117 | if (argc != 0 && argc != 1) { |
| 3118 | ThrowParamCountMismatchException(L"addInstance"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3119 | return; |
| 3120 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3121 | bool fFlags = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3122 | if (argc == 1) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3123 | fFlags = pArguments->GetInt32(0) == 0 ? false : true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3124 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3125 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3126 | CXFA_Occur nodeOccur(GetOccurNode()); |
| 3127 | int32_t iMax = nodeOccur.GetMax(); |
| 3128 | if (iMax >= 0 && iCount >= iMax) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3129 | ThrowTooManyOccurancesException(L"max"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3130 | return; |
| 3131 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3132 | CXFA_Node* pNewInstance = CreateInstance(this, fFlags); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3133 | InsertItem(this, pNewInstance, iCount, iCount, false); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3134 | pArguments->GetReturnValue()->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3135 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance)); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3136 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3137 | if (!pNotify) { |
| 3138 | return; |
| 3139 | } |
| 3140 | pNotify->RunNodeInitialize(pNewInstance); |
| 3141 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3142 | if (!pLayoutPro) { |
| 3143 | return; |
| 3144 | } |
| 3145 | pLayoutPro->AddChangedContainer( |
| 3146 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3147 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3148 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3149 | void CXFA_Node::Script_InstanceManager_InsertInstance( |
| 3150 | CFXJSE_Arguments* pArguments) { |
| 3151 | int32_t argc = pArguments->GetLength(); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3152 | if (argc != 1 && argc != 2) { |
| 3153 | ThrowParamCountMismatchException(L"insertInstance"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3154 | return; |
| 3155 | } |
| 3156 | int32_t iIndex = pArguments->GetInt32(0); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3157 | bool bBind = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3158 | if (argc == 2) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3159 | bBind = pArguments->GetInt32(1) == 0 ? false : true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3160 | } |
| 3161 | CXFA_Occur nodeOccur(GetOccurNode()); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3162 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3163 | if (iIndex < 0 || iIndex > iCount) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3164 | ThrowIndexOutOfBoundsException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3165 | return; |
| 3166 | } |
| 3167 | int32_t iMax = nodeOccur.GetMax(); |
| 3168 | if (iMax >= 0 && iCount >= iMax) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3169 | ThrowTooManyOccurancesException(L"max"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3170 | return; |
| 3171 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3172 | CXFA_Node* pNewInstance = CreateInstance(this, bBind); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3173 | InsertItem(this, pNewInstance, iIndex, iCount, true); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3174 | pArguments->GetReturnValue()->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3175 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance)); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3176 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3177 | if (!pNotify) { |
| 3178 | return; |
| 3179 | } |
| 3180 | pNotify->RunNodeInitialize(pNewInstance); |
| 3181 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3182 | if (!pLayoutPro) { |
| 3183 | return; |
| 3184 | } |
| 3185 | pLayoutPro->AddChangedContainer( |
| 3186 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3187 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3188 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3189 | int32_t CXFA_Node::InstanceManager_SetInstances(int32_t iDesired) { |
| 3190 | CXFA_Occur nodeOccur(GetOccurNode()); |
| 3191 | int32_t iMax = nodeOccur.GetMax(); |
| 3192 | int32_t iMin = nodeOccur.GetMin(); |
| 3193 | if (iDesired < iMin) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3194 | ThrowTooManyOccurancesException(L"min"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3195 | return 1; |
| 3196 | } |
| 3197 | if ((iMax >= 0) && (iDesired > iMax)) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3198 | ThrowTooManyOccurancesException(L"max"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3199 | return 2; |
| 3200 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3201 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3202 | if (iDesired == iCount) { |
| 3203 | return 0; |
| 3204 | } |
| 3205 | if (iDesired < iCount) { |
| 3206 | CFX_WideStringC wsInstManagerName = GetCData(XFA_ATTRIBUTE_Name); |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3207 | CFX_WideString wsInstanceName = |
| 3208 | CFX_WideString(wsInstManagerName.IsEmpty() ? wsInstManagerName |
| 3209 | : wsInstManagerName.Mid(1)); |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 3210 | uint32_t dInstanceNameHash = |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 3211 | FX_HashCode_GetW(wsInstanceName.AsStringC(), false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3212 | CXFA_Node* pPrevSibling = |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3213 | (iDesired == 0) ? this : GetItem(this, iDesired - 1); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3214 | while (iCount > iDesired) { |
| 3215 | CXFA_Node* pRemoveInstance = |
| 3216 | pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3217 | if (pRemoveInstance->GetElementType() != XFA_Element::Subform && |
| 3218 | pRemoveInstance->GetElementType() != XFA_Element::SubformSet) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3219 | continue; |
| 3220 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3221 | if (pRemoveInstance->GetElementType() == XFA_Element::InstanceManager) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3222 | ASSERT(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3223 | break; |
| 3224 | } |
| 3225 | if (pRemoveInstance->GetNameHash() == dInstanceNameHash) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3226 | RemoveItem(this, pRemoveInstance); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3227 | iCount--; |
| 3228 | } |
| 3229 | } |
| 3230 | } else if (iDesired > iCount) { |
| 3231 | while (iCount < iDesired) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3232 | CXFA_Node* pNewInstance = CreateInstance(this, true); |
| 3233 | InsertItem(this, pNewInstance, iCount, iCount, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3234 | iCount++; |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3235 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3236 | if (!pNotify) { |
| 3237 | return 0; |
| 3238 | } |
| 3239 | pNotify->RunNodeInitialize(pNewInstance); |
| 3240 | } |
| 3241 | } |
| 3242 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3243 | if (pLayoutPro) { |
| 3244 | pLayoutPro->AddChangedContainer( |
| 3245 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3246 | } |
| 3247 | return 0; |
| 3248 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3249 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3250 | int32_t CXFA_Node::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3251 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3252 | if (iFrom > iCount || iTo > iCount - 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3253 | ThrowIndexOutOfBoundsException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3254 | return 1; |
| 3255 | } |
| 3256 | if (iFrom < 0 || iTo < 0 || iFrom == iTo) { |
| 3257 | return 0; |
| 3258 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3259 | CXFA_Node* pMoveInstance = GetItem(this, iFrom); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3260 | RemoveItem(this, pMoveInstance, false); |
| 3261 | InsertItem(this, pMoveInstance, iTo, iCount - 1, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3262 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3263 | if (pLayoutPro) { |
| 3264 | pLayoutPro->AddChangedContainer( |
| 3265 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3266 | } |
| 3267 | return 0; |
| 3268 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3269 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3270 | void CXFA_Node::Script_Occur_Max(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3271 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3272 | XFA_ATTRIBUTE eAttribute) { |
| 3273 | CXFA_Occur occur(this); |
| 3274 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3275 | int32_t iMax = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3276 | occur.SetMax(iMax); |
| 3277 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3278 | pValue->SetInteger(occur.GetMax()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3279 | } |
| 3280 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3281 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3282 | void CXFA_Node::Script_Occur_Min(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3283 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3284 | XFA_ATTRIBUTE eAttribute) { |
| 3285 | CXFA_Occur occur(this); |
| 3286 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3287 | int32_t iMin = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3288 | occur.SetMin(iMin); |
| 3289 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3290 | pValue->SetInteger(occur.GetMin()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3291 | } |
| 3292 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3293 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3294 | void CXFA_Node::Script_Desc_Metadata(CFXJSE_Arguments* pArguments) { |
| 3295 | int32_t argc = pArguments->GetLength(); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3296 | if (argc != 0 && argc != 1) { |
| 3297 | ThrowParamCountMismatchException(L"metadata"); |
| 3298 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3299 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3300 | pArguments->GetReturnValue()->SetString(""); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3301 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3302 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3303 | void CXFA_Node::Script_Form_FormNodes(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3304 | if (pArguments->GetLength() != 1) { |
| 3305 | ThrowParamCountMismatchException(L"formNodes"); |
| 3306 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3307 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3308 | |
| 3309 | CXFA_Node* pDataNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); |
| 3310 | if (!pDataNode) { |
| 3311 | ThrowArgumentMismatchException(); |
| 3312 | return; |
| 3313 | } |
| 3314 | |
| 3315 | CXFA_NodeArray formItems; |
| 3316 | CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument); |
| 3317 | pFormNodes->SetArrayNodeList(formItems); |
| 3318 | pArguments->GetReturnValue()->SetObject( |
| 3319 | pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3320 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3321 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3322 | void CXFA_Node::Script_Form_Remerge(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3323 | if (pArguments->GetLength() != 0) { |
| 3324 | ThrowParamCountMismatchException(L"remerge"); |
| 3325 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3326 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3327 | |
| 3328 | m_pDocument->DoDataRemerge(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3329 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3330 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3331 | void CXFA_Node::Script_Form_ExecInitialize(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3332 | if (pArguments->GetLength() != 0) { |
| 3333 | ThrowParamCountMismatchException(L"execInitialize"); |
| 3334 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3335 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3336 | |
| 3337 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 3338 | if (!pNotify) |
| 3339 | return; |
| 3340 | |
| 3341 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3342 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3343 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3344 | void CXFA_Node::Script_Form_Recalculate(CFXJSE_Arguments* pArguments) { |
| 3345 | CXFA_EventParam* pEventParam = |
| 3346 | m_pDocument->GetScriptContext()->GetEventParam(); |
| 3347 | if (pEventParam->m_eType == XFA_EVENT_Calculate || |
| 3348 | pEventParam->m_eType == XFA_EVENT_InitCalculate) { |
| 3349 | return; |
| 3350 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3351 | if (pArguments->GetLength() != 1) { |
| 3352 | ThrowParamCountMismatchException(L"recalculate"); |
| 3353 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3354 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3355 | |
| 3356 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 3357 | if (!pNotify) |
| 3358 | return; |
| 3359 | if (pArguments->GetInt32(0) != 0) |
| 3360 | return; |
| 3361 | |
| 3362 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); |
| 3363 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); |
| 3364 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Ready, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3365 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3366 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3367 | void CXFA_Node::Script_Form_ExecCalculate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3368 | if (pArguments->GetLength() != 0) { |
| 3369 | ThrowParamCountMismatchException(L"execCalculate"); |
| 3370 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3371 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3372 | |
| 3373 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 3374 | if (!pNotify) |
| 3375 | return; |
| 3376 | |
| 3377 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3378 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3379 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3380 | void CXFA_Node::Script_Form_ExecValidate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3381 | if (pArguments->GetLength() != 0) { |
| 3382 | ThrowParamCountMismatchException(L"execValidate"); |
| 3383 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3384 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3385 | |
| 3386 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 3387 | if (!pNotify) { |
| 3388 | pArguments->GetReturnValue()->SetBoolean(false); |
| 3389 | return; |
| 3390 | } |
| 3391 | |
| 3392 | int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); |
| 3393 | pArguments->GetReturnValue()->SetBoolean( |
| 3394 | (iRet == XFA_EVENTERROR_Error) ? false : true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3395 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3396 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3397 | void CXFA_Node::Script_Form_Checksum(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3398 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3399 | XFA_ATTRIBUTE eAttribute) { |
| 3400 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 3401 | SetAttribute(XFA_ATTRIBUTE_Checksum, pValue->ToWideString().AsStringC()); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3402 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3403 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3404 | CFX_WideString wsChecksum; |
| 3405 | GetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum, false); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 3406 | pValue->SetString(wsChecksum.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3407 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3408 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3409 | void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3410 | if (pArguments->GetLength() != 1) { |
| 3411 | ThrowParamCountMismatchException(L"getAttribute"); |
| 3412 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3413 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3414 | CFX_ByteString bsAttributeName = pArguments->GetUTF8String(0); |
| 3415 | CFX_WideString wsAttributeValue; |
| 3416 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
| 3417 | if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { |
| 3418 | static_cast<CFDE_XMLElement*>(pXMLNode)->GetString( |
| 3419 | CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str(), |
| 3420 | wsAttributeValue); |
| 3421 | } |
| 3422 | pArguments->GetReturnValue()->SetString( |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 3423 | wsAttributeValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3424 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3425 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3426 | void CXFA_Node::Script_Packet_SetAttribute(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3427 | if (pArguments->GetLength() != 2) { |
| 3428 | ThrowParamCountMismatchException(L"setAttribute"); |
| 3429 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3430 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3431 | CFX_ByteString bsValue = pArguments->GetUTF8String(0); |
| 3432 | CFX_ByteString bsName = pArguments->GetUTF8String(1); |
| 3433 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
| 3434 | if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { |
| 3435 | static_cast<CFDE_XMLElement*>(pXMLNode)->SetString( |
| 3436 | CFX_WideString::FromUTF8(bsName.AsStringC()), |
| 3437 | CFX_WideString::FromUTF8(bsValue.AsStringC())); |
| 3438 | } |
| 3439 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3440 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3441 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3442 | void CXFA_Node::Script_Packet_RemoveAttribute(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3443 | if (pArguments->GetLength() != 1) { |
| 3444 | ThrowParamCountMismatchException(L"removeAttribute"); |
| 3445 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3446 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3447 | |
| 3448 | CFX_ByteString bsName = pArguments->GetUTF8String(0); |
| 3449 | CFX_WideString wsName = CFX_WideString::FromUTF8(bsName.AsStringC()); |
| 3450 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
| 3451 | if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { |
| 3452 | CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); |
| 3453 | if (pXMLElement->HasAttribute(wsName.c_str())) { |
| 3454 | pXMLElement->RemoveAttribute(wsName.c_str()); |
| 3455 | } |
| 3456 | } |
| 3457 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3458 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3459 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3460 | void CXFA_Node::Script_Packet_Content(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3461 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3462 | XFA_ATTRIBUTE eAttribute) { |
| 3463 | if (bSetting) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3464 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3465 | if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3466 | CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 3467 | pXMLElement->SetTextData(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3468 | } |
| 3469 | } else { |
| 3470 | CFX_WideString wsTextData; |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3471 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3472 | if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3473 | CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3474 | pXMLElement->GetTextData(wsTextData); |
| 3475 | } |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 3476 | pValue->SetString(wsTextData.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3477 | } |
| 3478 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3479 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3480 | void CXFA_Node::Script_Source_Next(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3481 | if (pArguments->GetLength() != 0) |
| 3482 | ThrowParamCountMismatchException(L"next"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3483 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3484 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3485 | void CXFA_Node::Script_Source_CancelBatch(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3486 | if (pArguments->GetLength() != 0) |
| 3487 | ThrowParamCountMismatchException(L"cancelBatch"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3488 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3489 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3490 | void CXFA_Node::Script_Source_First(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3491 | if (pArguments->GetLength() != 0) |
| 3492 | ThrowParamCountMismatchException(L"first"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3493 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3494 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3495 | void CXFA_Node::Script_Source_UpdateBatch(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3496 | if (pArguments->GetLength() != 0) |
| 3497 | ThrowParamCountMismatchException(L"updateBatch"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 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_Previous(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3501 | if (pArguments->GetLength() != 0) |
| 3502 | ThrowParamCountMismatchException(L"previous"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3503 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3504 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3505 | void CXFA_Node::Script_Source_IsBOF(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3506 | if (pArguments->GetLength() != 0) |
| 3507 | ThrowParamCountMismatchException(L"isBOF"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3508 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3509 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3510 | void CXFA_Node::Script_Source_IsEOF(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3511 | if (pArguments->GetLength() != 0) |
| 3512 | ThrowParamCountMismatchException(L"isEOF"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3513 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3514 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3515 | void CXFA_Node::Script_Source_Cancel(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3516 | if (pArguments->GetLength() != 0) |
| 3517 | ThrowParamCountMismatchException(L"cancel"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3518 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3519 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3520 | void CXFA_Node::Script_Source_Update(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3521 | if (pArguments->GetLength() != 0) |
| 3522 | ThrowParamCountMismatchException(L"update"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3523 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3524 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3525 | void CXFA_Node::Script_Source_Open(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3526 | if (pArguments->GetLength() != 0) |
| 3527 | ThrowParamCountMismatchException(L"open"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3528 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3529 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3530 | void CXFA_Node::Script_Source_Delete(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3531 | if (pArguments->GetLength() != 0) |
| 3532 | ThrowParamCountMismatchException(L"delete"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3533 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3534 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3535 | void CXFA_Node::Script_Source_AddNew(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3536 | if (pArguments->GetLength() != 0) |
| 3537 | ThrowParamCountMismatchException(L"addNew"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 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_Requery(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3541 | if (pArguments->GetLength() != 0) |
| 3542 | ThrowParamCountMismatchException(L"requery"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3543 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3544 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3545 | void CXFA_Node::Script_Source_Resync(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3546 | if (pArguments->GetLength() != 0) |
| 3547 | ThrowParamCountMismatchException(L"resync"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3548 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3549 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3550 | void CXFA_Node::Script_Source_Close(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3551 | if (pArguments->GetLength() != 0) |
| 3552 | ThrowParamCountMismatchException(L"close"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3553 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3554 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3555 | void CXFA_Node::Script_Source_Last(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3556 | if (pArguments->GetLength() != 0) |
| 3557 | ThrowParamCountMismatchException(L"last"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3558 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3559 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3560 | void CXFA_Node::Script_Source_HasDataChanged(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3561 | if (pArguments->GetLength() != 0) |
| 3562 | ThrowParamCountMismatchException(L"hasDataChanged"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3563 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3564 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3565 | void CXFA_Node::Script_Source_Db(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3566 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3567 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3568 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3569 | void CXFA_Node::Script_Xfa_This(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3570 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3571 | XFA_ATTRIBUTE eAttribute) { |
| 3572 | if (!bSetting) { |
| 3573 | CXFA_Object* pThis = m_pDocument->GetScriptContext()->GetThisObject(); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 3574 | ASSERT(pThis); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3575 | pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pThis)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3576 | } |
| 3577 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3578 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3579 | void CXFA_Node::Script_Handler_Version(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3580 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3581 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3582 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3583 | void CXFA_Node::Script_SubmitFormat_Mode(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3584 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3585 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3586 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3587 | void CXFA_Node::Script_Extras_Type(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3588 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3589 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3590 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3591 | void CXFA_Node::Script_Script_Stateless(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3592 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3593 | XFA_ATTRIBUTE eAttribute) { |
| 3594 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3595 | ThrowInvalidPropertyException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3596 | return; |
| 3597 | } |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 3598 | pValue->SetString(FX_UTF8Encode(CFX_WideStringC(L"0", 1)).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3599 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3600 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3601 | void CXFA_Node::Script_Encrypt_Format(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3602 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3603 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3604 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3605 | bool CXFA_Node::HasAttribute(XFA_ATTRIBUTE eAttr, bool bCanInherit) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3606 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3607 | return HasMapModuleKey(pKey, bCanInherit); |
| 3608 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3609 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3610 | bool CXFA_Node::SetAttribute(XFA_ATTRIBUTE eAttr, |
| 3611 | const CFX_WideStringC& wsValue, |
| 3612 | bool bNotify) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3613 | const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3614 | if (!pAttr) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3615 | return false; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3616 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3617 | XFA_ATTRIBUTETYPE eType = pAttr->eType; |
| 3618 | if (eType == XFA_ATTRIBUTETYPE_NOTSURE) { |
| 3619 | const XFA_NOTSUREATTRIBUTE* pNotsure = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3620 | XFA_GetNotsureAttribute(GetElementType(), pAttr->eName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3621 | eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata; |
| 3622 | } |
| 3623 | switch (eType) { |
| 3624 | case XFA_ATTRIBUTETYPE_Enum: { |
| 3625 | const XFA_ATTRIBUTEENUMINFO* pEnum = XFA_GetAttributeEnumByName(wsValue); |
| 3626 | return SetEnum(pAttr->eName, |
| 3627 | pEnum ? pEnum->eName |
| 3628 | : (XFA_ATTRIBUTEENUM)(intptr_t)(pAttr->pDefValue), |
| 3629 | bNotify); |
| 3630 | } break; |
| 3631 | case XFA_ATTRIBUTETYPE_Cdata: |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3632 | return SetCData(pAttr->eName, CFX_WideString(wsValue), bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3633 | case XFA_ATTRIBUTETYPE_Boolean: |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 3634 | return SetBoolean(pAttr->eName, wsValue != L"0", bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3635 | case XFA_ATTRIBUTETYPE_Integer: |
dsinclair | e0347a6 | 2016-08-11 11:24:11 -0700 | [diff] [blame] | 3636 | return SetInteger(pAttr->eName, |
| 3637 | FXSYS_round(FXSYS_wcstof(wsValue.c_str(), |
| 3638 | wsValue.GetLength(), nullptr)), |
| 3639 | bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3640 | case XFA_ATTRIBUTETYPE_Measure: |
| 3641 | return SetMeasure(pAttr->eName, CXFA_Measurement(wsValue), bNotify); |
| 3642 | default: |
| 3643 | break; |
| 3644 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3645 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3646 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3647 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3648 | bool CXFA_Node::GetAttribute(XFA_ATTRIBUTE eAttr, |
| 3649 | CFX_WideString& wsValue, |
| 3650 | bool bUseDefault) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3651 | const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3652 | if (!pAttr) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3653 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3654 | } |
| 3655 | XFA_ATTRIBUTETYPE eType = pAttr->eType; |
| 3656 | if (eType == XFA_ATTRIBUTETYPE_NOTSURE) { |
| 3657 | const XFA_NOTSUREATTRIBUTE* pNotsure = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3658 | XFA_GetNotsureAttribute(GetElementType(), pAttr->eName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3659 | eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata; |
| 3660 | } |
| 3661 | switch (eType) { |
| 3662 | case XFA_ATTRIBUTETYPE_Enum: { |
| 3663 | XFA_ATTRIBUTEENUM eValue; |
| 3664 | if (!TryEnum(pAttr->eName, eValue, bUseDefault)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3665 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3666 | } |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 3667 | wsValue = GetAttributeEnumByID(eValue)->pName; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3668 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3669 | } break; |
| 3670 | case XFA_ATTRIBUTETYPE_Cdata: { |
| 3671 | CFX_WideStringC wsValueC; |
| 3672 | if (!TryCData(pAttr->eName, wsValueC, bUseDefault)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3673 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3674 | } |
| 3675 | wsValue = wsValueC; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3676 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3677 | } break; |
| 3678 | case XFA_ATTRIBUTETYPE_Boolean: { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3679 | bool bValue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3680 | if (!TryBoolean(pAttr->eName, bValue, bUseDefault)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3681 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3682 | } |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 3683 | wsValue = bValue ? L"1" : L"0"; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3684 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3685 | } break; |
| 3686 | case XFA_ATTRIBUTETYPE_Integer: { |
| 3687 | int32_t iValue; |
| 3688 | if (!TryInteger(pAttr->eName, iValue, bUseDefault)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3689 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3690 | } |
| 3691 | wsValue.Format(L"%d", iValue); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3692 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3693 | } break; |
| 3694 | case XFA_ATTRIBUTETYPE_Measure: { |
| 3695 | CXFA_Measurement mValue; |
| 3696 | if (!TryMeasure(pAttr->eName, mValue, bUseDefault)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3697 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3698 | } |
| 3699 | mValue.ToString(wsValue); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3700 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3701 | } break; |
| 3702 | default: |
| 3703 | break; |
| 3704 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3705 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3706 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3707 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3708 | bool CXFA_Node::SetAttribute(const CFX_WideStringC& wsAttr, |
| 3709 | const CFX_WideStringC& wsValue, |
| 3710 | bool bNotify) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3711 | const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsValue); |
| 3712 | if (pAttributeInfo) { |
| 3713 | return SetAttribute(pAttributeInfo->eName, wsValue, bNotify); |
| 3714 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3715 | void* pKey = GetMapKey_Custom(wsAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3716 | SetMapModuleString(pKey, wsValue); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3717 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3718 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3719 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3720 | bool CXFA_Node::GetAttribute(const CFX_WideStringC& wsAttr, |
| 3721 | CFX_WideString& wsValue, |
| 3722 | bool bUseDefault) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3723 | const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsAttr); |
| 3724 | if (pAttributeInfo) { |
| 3725 | return GetAttribute(pAttributeInfo->eName, wsValue, bUseDefault); |
| 3726 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3727 | void* pKey = GetMapKey_Custom(wsAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3728 | CFX_WideStringC wsValueC; |
| 3729 | if (GetMapModuleString(pKey, wsValueC)) { |
| 3730 | wsValue = wsValueC; |
| 3731 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3732 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3733 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3734 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3735 | bool CXFA_Node::RemoveAttribute(const CFX_WideStringC& wsAttr) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3736 | void* pKey = GetMapKey_Custom(wsAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3737 | RemoveMapModuleKey(pKey); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3738 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3739 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3740 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3741 | bool CXFA_Node::TryBoolean(XFA_ATTRIBUTE eAttr, |
| 3742 | bool& bValue, |
| 3743 | bool bUseDefault) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3744 | void* pValue = nullptr; |
| 3745 | if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Boolean, bUseDefault, pValue)) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3746 | return false; |
tsepez | 478ed62 | 2016-10-27 14:32:33 -0700 | [diff] [blame] | 3747 | bValue = !!pValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3748 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3749 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3750 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3751 | bool CXFA_Node::TryInteger(XFA_ATTRIBUTE eAttr, |
| 3752 | int32_t& iValue, |
| 3753 | bool bUseDefault) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3754 | void* pValue = nullptr; |
| 3755 | if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Integer, bUseDefault, pValue)) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3756 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3757 | iValue = (int32_t)(uintptr_t)pValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3758 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3759 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3760 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3761 | bool CXFA_Node::TryEnum(XFA_ATTRIBUTE eAttr, |
| 3762 | XFA_ATTRIBUTEENUM& eValue, |
| 3763 | bool bUseDefault) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3764 | void* pValue = nullptr; |
| 3765 | if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Enum, bUseDefault, pValue)) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3766 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3767 | eValue = (XFA_ATTRIBUTEENUM)(uintptr_t)pValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3768 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3769 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3770 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3771 | bool CXFA_Node::SetMeasure(XFA_ATTRIBUTE eAttr, |
| 3772 | CXFA_Measurement mValue, |
| 3773 | bool bNotify) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3774 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3775 | OnChanging(eAttr, bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3776 | SetMapModuleBuffer(pKey, &mValue, sizeof(CXFA_Measurement)); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3777 | OnChanged(eAttr, bNotify, false); |
| 3778 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3779 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3780 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3781 | bool CXFA_Node::TryMeasure(XFA_ATTRIBUTE eAttr, |
| 3782 | CXFA_Measurement& mValue, |
| 3783 | bool bUseDefault) const { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3784 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3785 | void* pValue; |
| 3786 | int32_t iBytes; |
| 3787 | if (GetMapModuleBuffer(pKey, pValue, iBytes) && iBytes == sizeof(mValue)) { |
| 3788 | FXSYS_memcpy(&mValue, pValue, sizeof(mValue)); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3789 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3790 | } |
| 3791 | if (bUseDefault && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3792 | XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3793 | XFA_ATTRIBUTETYPE_Measure, m_ePacket)) { |
| 3794 | FXSYS_memcpy(&mValue, pValue, sizeof(mValue)); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3795 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3796 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3797 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3798 | } |
| 3799 | |
| 3800 | CXFA_Measurement CXFA_Node::GetMeasure(XFA_ATTRIBUTE eAttr) const { |
| 3801 | CXFA_Measurement mValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3802 | return TryMeasure(eAttr, mValue, true) ? mValue : CXFA_Measurement(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3803 | } |
| 3804 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3805 | bool CXFA_Node::SetCData(XFA_ATTRIBUTE eAttr, |
| 3806 | const CFX_WideString& wsValue, |
| 3807 | bool bNotify, |
| 3808 | bool bScriptModify) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3809 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3810 | OnChanging(eAttr, bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3811 | if (eAttr == XFA_ATTRIBUTE_Value) { |
| 3812 | CFX_WideString* pClone = new CFX_WideString(wsValue); |
| 3813 | SetUserData(pKey, pClone, &deleteWideStringCallBack); |
| 3814 | } else { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 3815 | SetMapModuleString(pKey, wsValue.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3816 | if (eAttr == XFA_ATTRIBUTE_Name) |
| 3817 | UpdateNameHash(); |
| 3818 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3819 | OnChanged(eAttr, bNotify, bScriptModify); |
| 3820 | |
| 3821 | if (!IsNeedSavingXMLNode() || eAttr == XFA_ATTRIBUTE_QualifiedName || |
| 3822 | eAttr == XFA_ATTRIBUTE_BindingNode) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3823 | return true; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3824 | } |
| 3825 | |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3826 | if (eAttr == XFA_ATTRIBUTE_Name && |
| 3827 | (m_elementType == XFA_Element::DataValue || |
| 3828 | m_elementType == XFA_Element::DataGroup)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3829 | return true; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3830 | } |
| 3831 | |
| 3832 | if (eAttr == XFA_ATTRIBUTE_Value) { |
| 3833 | FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType(); |
| 3834 | switch (eXMLType) { |
| 3835 | case FDE_XMLNODE_Element: |
| 3836 | if (IsAttributeInXML()) { |
| 3837 | static_cast<CFDE_XMLElement*>(m_pXMLNode) |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3838 | ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)), |
| 3839 | wsValue); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3840 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3841 | bool bDeleteChildren = true; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3842 | if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 3843 | for (CXFA_Node* pChildDataNode = |
| 3844 | GetNodeItem(XFA_NODEITEM_FirstChild); |
| 3845 | pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem( |
| 3846 | XFA_NODEITEM_NextSibling)) { |
| 3847 | CXFA_NodeArray formNodes; |
| 3848 | if (pChildDataNode->GetBindItems(formNodes) > 0) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3849 | bDeleteChildren = false; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3850 | break; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3851 | } |
| 3852 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3853 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3854 | if (bDeleteChildren) { |
| 3855 | static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren(); |
| 3856 | } |
| 3857 | static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsValue); |
| 3858 | } |
| 3859 | break; |
| 3860 | case FDE_XMLNODE_Text: |
| 3861 | static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsValue); |
| 3862 | break; |
| 3863 | default: |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 3864 | ASSERT(0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3865 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3866 | return true; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3867 | } |
| 3868 | |
| 3869 | const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr); |
| 3870 | if (pInfo) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 3871 | ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3872 | CFX_WideString wsAttrName = pInfo->pName; |
| 3873 | if (pInfo->eName == XFA_ATTRIBUTE_ContentType) { |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 3874 | wsAttrName = L"xfa:" + wsAttrName; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3875 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3876 | static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetString(wsAttrName, wsValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3877 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3878 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3879 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3880 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3881 | bool CXFA_Node::SetAttributeValue(const CFX_WideString& wsValue, |
| 3882 | const CFX_WideString& wsXMLValue, |
| 3883 | bool bNotify, |
| 3884 | bool bScriptModify) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3885 | void* pKey = GetMapKey_Element(GetElementType(), XFA_ATTRIBUTE_Value); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3886 | OnChanging(XFA_ATTRIBUTE_Value, bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3887 | CFX_WideString* pClone = new CFX_WideString(wsValue); |
| 3888 | SetUserData(pKey, pClone, &deleteWideStringCallBack); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3889 | OnChanged(XFA_ATTRIBUTE_Value, bNotify, bScriptModify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3890 | if (IsNeedSavingXMLNode()) { |
| 3891 | FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType(); |
| 3892 | switch (eXMLType) { |
| 3893 | case FDE_XMLNODE_Element: |
| 3894 | if (IsAttributeInXML()) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3895 | static_cast<CFDE_XMLElement*>(m_pXMLNode) |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3896 | ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)), |
| 3897 | wsXMLValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3898 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3899 | bool bDeleteChildren = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3900 | if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 3901 | for (CXFA_Node* pChildDataNode = |
| 3902 | GetNodeItem(XFA_NODEITEM_FirstChild); |
| 3903 | pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem( |
| 3904 | XFA_NODEITEM_NextSibling)) { |
| 3905 | CXFA_NodeArray formNodes; |
| 3906 | if (pChildDataNode->GetBindItems(formNodes) > 0) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3907 | bDeleteChildren = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3908 | break; |
| 3909 | } |
| 3910 | } |
| 3911 | } |
| 3912 | if (bDeleteChildren) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3913 | static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3914 | } |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3915 | static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsXMLValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3916 | } |
| 3917 | break; |
| 3918 | case FDE_XMLNODE_Text: |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3919 | static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsXMLValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3920 | break; |
| 3921 | default: |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 3922 | ASSERT(0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3923 | } |
| 3924 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3925 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3926 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3927 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3928 | bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr, |
| 3929 | CFX_WideString& wsValue, |
| 3930 | bool bUseDefault, |
| 3931 | bool bProto) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3932 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3933 | if (eAttr == XFA_ATTRIBUTE_Value) { |
| 3934 | CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto); |
| 3935 | if (pStr) { |
| 3936 | wsValue = *pStr; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3937 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3938 | } |
| 3939 | } else { |
| 3940 | CFX_WideStringC wsValueC; |
| 3941 | if (GetMapModuleString(pKey, wsValueC)) { |
| 3942 | wsValue = wsValueC; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3943 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3944 | } |
| 3945 | } |
| 3946 | if (!bUseDefault) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3947 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3948 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3949 | void* pValue = nullptr; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3950 | if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3951 | XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) { |
| 3952 | wsValue = (const FX_WCHAR*)pValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3953 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3954 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3955 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3956 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3957 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3958 | bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr, |
| 3959 | CFX_WideStringC& wsValue, |
| 3960 | bool bUseDefault, |
| 3961 | bool bProto) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3962 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3963 | if (eAttr == XFA_ATTRIBUTE_Value) { |
| 3964 | CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto); |
| 3965 | if (pStr) { |
tsepez | 4d31d0c | 2016-04-19 14:11:59 -0700 | [diff] [blame] | 3966 | wsValue = pStr->AsStringC(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3967 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3968 | } |
| 3969 | } else { |
| 3970 | if (GetMapModuleString(pKey, wsValue)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3971 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3972 | } |
| 3973 | } |
| 3974 | if (!bUseDefault) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3975 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3976 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3977 | void* pValue = nullptr; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3978 | if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3979 | XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) { |
| 3980 | wsValue = (CFX_WideStringC)(const FX_WCHAR*)pValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3981 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3982 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3983 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3984 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3985 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3986 | bool CXFA_Node::SetObject(XFA_ATTRIBUTE eAttr, |
| 3987 | void* pData, |
| 3988 | XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3989 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3990 | return SetUserData(pKey, pData, pCallbackInfo); |
| 3991 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3992 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3993 | bool CXFA_Node::TryObject(XFA_ATTRIBUTE eAttr, void*& pData) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3994 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3995 | pData = GetUserData(pKey); |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 3996 | return !!pData; |
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::SetValue(XFA_ATTRIBUTE eAttr, |
| 4000 | XFA_ATTRIBUTETYPE eType, |
| 4001 | void* pValue, |
| 4002 | bool bNotify) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4003 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4004 | OnChanging(eAttr, bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4005 | SetMapModuleValue(pKey, pValue); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4006 | OnChanged(eAttr, bNotify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4007 | if (IsNeedSavingXMLNode()) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4008 | ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4009 | const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr); |
| 4010 | if (pInfo) { |
| 4011 | switch (eType) { |
| 4012 | case XFA_ATTRIBUTETYPE_Enum: |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4013 | static_cast<CFDE_XMLElement*>(m_pXMLNode) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4014 | ->SetString( |
| 4015 | pInfo->pName, |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 4016 | GetAttributeEnumByID((XFA_ATTRIBUTEENUM)(uintptr_t)pValue) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4017 | ->pName); |
| 4018 | break; |
| 4019 | case XFA_ATTRIBUTETYPE_Boolean: |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4020 | static_cast<CFDE_XMLElement*>(m_pXMLNode) |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 4021 | ->SetString(pInfo->pName, pValue ? L"1" : L"0"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4022 | break; |
| 4023 | case XFA_ATTRIBUTETYPE_Integer: |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4024 | static_cast<CFDE_XMLElement*>(m_pXMLNode) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4025 | ->SetInteger(pInfo->pName, (int32_t)(uintptr_t)pValue); |
| 4026 | break; |
| 4027 | default: |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4028 | ASSERT(0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4029 | } |
| 4030 | } |
| 4031 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4032 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4033 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4034 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4035 | bool CXFA_Node::GetValue(XFA_ATTRIBUTE eAttr, |
| 4036 | XFA_ATTRIBUTETYPE eType, |
| 4037 | bool bUseDefault, |
| 4038 | void*& pValue) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4039 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4040 | if (GetMapModuleValue(pKey, pValue)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4041 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4042 | } |
| 4043 | if (!bUseDefault) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4044 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4045 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4046 | return XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, eType, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4047 | m_ePacket); |
| 4048 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4049 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4050 | bool CXFA_Node::SetUserData(void* pKey, |
| 4051 | void* pData, |
| 4052 | XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4053 | SetMapModuleBuffer(pKey, &pData, sizeof(void*), |
| 4054 | pCallbackInfo ? pCallbackInfo : &gs_XFADefaultFreeData); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4055 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4056 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4057 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4058 | bool CXFA_Node::TryUserData(void* pKey, void*& pData, bool bProtoAlso) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4059 | int32_t iBytes = 0; |
| 4060 | if (!GetMapModuleBuffer(pKey, pData, iBytes, bProtoAlso)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4061 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4062 | } |
| 4063 | return iBytes == sizeof(void*) && FXSYS_memcpy(&pData, pData, iBytes); |
| 4064 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4065 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4066 | bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent, |
| 4067 | const CFX_WideString& wsXMLValue, |
| 4068 | bool bNotify, |
| 4069 | bool bScriptModify, |
| 4070 | bool bSyncData) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4071 | CXFA_Node* pNode = nullptr; |
| 4072 | CXFA_Node* pBindNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4073 | switch (GetObjectType()) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4074 | case XFA_ObjectType::ContainerNode: { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4075 | if (XFA_FieldIsMultiListBox(this)) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4076 | CXFA_Node* pValue = GetProperty(0, XFA_Element::Value); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4077 | CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4078 | ASSERT(pChildValue); |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 4079 | pChildValue->SetCData(XFA_ATTRIBUTE_ContentType, L"text/xml"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4080 | pChildValue->SetScriptContent(wsContent, wsContent, bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4081 | bScriptModify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4082 | CXFA_Node* pBind = GetBindData(); |
| 4083 | if (bSyncData && pBind) { |
tsepez | 51709be | 2016-12-08 10:55:57 -0800 | [diff] [blame] | 4084 | std::vector<CFX_WideString> wsSaveTextArray; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4085 | int32_t iSize = 0; |
| 4086 | if (!wsContent.IsEmpty()) { |
| 4087 | int32_t iStart = 0; |
| 4088 | int32_t iLength = wsContent.GetLength(); |
| 4089 | int32_t iEnd = wsContent.Find(L'\n', iStart); |
| 4090 | iEnd = (iEnd == -1) ? iLength : iEnd; |
| 4091 | while (iEnd >= iStart) { |
tsepez | 51709be | 2016-12-08 10:55:57 -0800 | [diff] [blame] | 4092 | wsSaveTextArray.push_back(wsContent.Mid(iStart, iEnd - iStart)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4093 | iStart = iEnd + 1; |
| 4094 | if (iStart >= iLength) { |
| 4095 | break; |
| 4096 | } |
| 4097 | iEnd = wsContent.Find(L'\n', iStart); |
| 4098 | if (iEnd < 0) { |
tsepez | 51709be | 2016-12-08 10:55:57 -0800 | [diff] [blame] | 4099 | wsSaveTextArray.push_back( |
| 4100 | wsContent.Mid(iStart, iLength - iStart)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4101 | } |
| 4102 | } |
tsepez | 51709be | 2016-12-08 10:55:57 -0800 | [diff] [blame] | 4103 | iSize = pdfium::CollectionSize<int32_t>(wsSaveTextArray); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4104 | } |
| 4105 | if (iSize == 0) { |
| 4106 | while (CXFA_Node* pChildNode = |
| 4107 | pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) { |
| 4108 | pBind->RemoveChild(pChildNode); |
| 4109 | } |
| 4110 | } else { |
| 4111 | CXFA_NodeArray valueNodes; |
| 4112 | int32_t iDatas = pBind->GetNodeList( |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4113 | valueNodes, XFA_NODEFILTER_Children, XFA_Element::DataValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4114 | if (iDatas < iSize) { |
| 4115 | int32_t iAddNodes = iSize - iDatas; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4116 | CXFA_Node* pValueNodes = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4117 | while (iAddNodes-- > 0) { |
| 4118 | pValueNodes = |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4119 | pBind->CreateSamePacketNode(XFA_Element::DataValue); |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 4120 | pValueNodes->SetCData(XFA_ATTRIBUTE_Name, L"value"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4121 | pValueNodes->CreateXMLMappingNode(); |
| 4122 | pBind->InsertChild(pValueNodes); |
| 4123 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4124 | pValueNodes = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4125 | } else if (iDatas > iSize) { |
| 4126 | int32_t iDelNodes = iDatas - iSize; |
| 4127 | while (iDelNodes-- > 0) { |
| 4128 | pBind->RemoveChild(pBind->GetNodeItem(XFA_NODEITEM_FirstChild)); |
| 4129 | } |
| 4130 | } |
| 4131 | int32_t i = 0; |
| 4132 | for (CXFA_Node* pValueNode = |
| 4133 | pBind->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 4134 | pValueNode; pValueNode = pValueNode->GetNodeItem( |
| 4135 | XFA_NODEITEM_NextSibling)) { |
| 4136 | pValueNode->SetAttributeValue(wsSaveTextArray[i], |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4137 | wsSaveTextArray[i], false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4138 | i++; |
| 4139 | } |
| 4140 | } |
| 4141 | CXFA_NodeArray nodeArray; |
| 4142 | pBind->GetBindItems(nodeArray); |
| 4143 | for (int32_t i = 0; i < nodeArray.GetSize(); i++) { |
weili | db444d2 | 2016-06-02 15:48:15 -0700 | [diff] [blame] | 4144 | if (nodeArray[i] != this) { |
| 4145 | nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4146 | bScriptModify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4147 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4148 | } |
| 4149 | } |
| 4150 | break; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4151 | } else if (GetElementType() == XFA_Element::ExclGroup) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4152 | pNode = this; |
| 4153 | } else { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4154 | CXFA_Node* pValue = GetProperty(0, XFA_Element::Value); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4155 | CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4156 | ASSERT(pChildValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4157 | pChildValue->SetScriptContent(wsContent, wsContent, bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4158 | bScriptModify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4159 | } |
| 4160 | pBindNode = GetBindData(); |
| 4161 | if (pBindNode && bSyncData) { |
| 4162 | pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4163 | bScriptModify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4164 | CXFA_NodeArray nodeArray; |
| 4165 | pBindNode->GetBindItems(nodeArray); |
| 4166 | for (int32_t i = 0; i < nodeArray.GetSize(); i++) { |
weili | db444d2 | 2016-06-02 15:48:15 -0700 | [diff] [blame] | 4167 | if (nodeArray[i] != this) { |
| 4168 | nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify, true, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4169 | false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4170 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4171 | } |
| 4172 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4173 | pBindNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4174 | break; |
| 4175 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4176 | case XFA_ObjectType::ContentNode: { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4177 | CFX_WideString wsContentType; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4178 | if (GetElementType() == XFA_Element::ExData) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4179 | GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false); |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 4180 | if (wsContentType == L"text/html") { |
| 4181 | wsContentType = L""; |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 4182 | SetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4183 | } |
| 4184 | } |
| 4185 | CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild); |
| 4186 | if (!pContentRawDataNode) { |
tsepez | 9f2970c | 2016-04-01 10:23:04 -0700 | [diff] [blame] | 4187 | pContentRawDataNode = CreateSamePacketNode( |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 4188 | (wsContentType == L"text/xml") ? XFA_Element::Sharpxml |
| 4189 | : XFA_Element::Sharptext); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4190 | InsertChild(pContentRawDataNode); |
| 4191 | } |
| 4192 | return pContentRawDataNode->SetScriptContent( |
| 4193 | wsContent, wsXMLValue, bNotify, bScriptModify, bSyncData); |
| 4194 | } break; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4195 | case XFA_ObjectType::NodeC: |
| 4196 | case XFA_ObjectType::TextNode: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4197 | pNode = this; |
| 4198 | break; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4199 | case XFA_ObjectType::NodeV: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4200 | pNode = this; |
| 4201 | if (bSyncData && GetPacketID() == XFA_XDPPACKET_Form) { |
| 4202 | CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent); |
| 4203 | if (pParent) { |
| 4204 | pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent); |
| 4205 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4206 | if (pParent && pParent->GetElementType() == XFA_Element::Value) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4207 | pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent); |
| 4208 | if (pParent && pParent->IsContainerNode()) { |
| 4209 | pBindNode = pParent->GetBindData(); |
| 4210 | if (pBindNode) { |
| 4211 | pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4212 | bScriptModify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4213 | } |
| 4214 | } |
| 4215 | } |
| 4216 | } |
| 4217 | break; |
| 4218 | default: |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4219 | if (GetElementType() == XFA_Element::DataValue) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4220 | pNode = this; |
| 4221 | pBindNode = this; |
| 4222 | } |
| 4223 | break; |
| 4224 | } |
| 4225 | if (pNode) { |
| 4226 | SetAttributeValue(wsContent, wsXMLValue, bNotify, bScriptModify); |
| 4227 | if (pBindNode && bSyncData) { |
| 4228 | CXFA_NodeArray nodeArray; |
| 4229 | pBindNode->GetBindItems(nodeArray); |
| 4230 | for (int32_t i = 0; i < nodeArray.GetSize(); i++) { |
weili | db444d2 | 2016-06-02 15:48:15 -0700 | [diff] [blame] | 4231 | nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4232 | bScriptModify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4233 | } |
| 4234 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4235 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4236 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4237 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4238 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4239 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4240 | bool CXFA_Node::SetContent(const CFX_WideString& wsContent, |
| 4241 | const CFX_WideString& wsXMLValue, |
| 4242 | bool bNotify, |
| 4243 | bool bScriptModify, |
| 4244 | bool bSyncData) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4245 | return SetScriptContent(wsContent, wsXMLValue, bNotify, bScriptModify, |
| 4246 | bSyncData); |
| 4247 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4248 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4249 | CFX_WideString CXFA_Node::GetScriptContent(bool bScriptModify) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4250 | CFX_WideString wsContent; |
| 4251 | return TryContent(wsContent, bScriptModify) ? wsContent : CFX_WideString(); |
| 4252 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4253 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4254 | CFX_WideString CXFA_Node::GetContent() { |
| 4255 | return GetScriptContent(); |
| 4256 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4257 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4258 | bool CXFA_Node::TryContent(CFX_WideString& wsContent, |
| 4259 | bool bScriptModify, |
| 4260 | bool bProto) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4261 | CXFA_Node* pNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4262 | switch (GetObjectType()) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4263 | case XFA_ObjectType::ContainerNode: |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4264 | if (GetElementType() == XFA_Element::ExclGroup) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4265 | pNode = this; |
| 4266 | } else { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4267 | CXFA_Node* pValue = GetChild(0, XFA_Element::Value); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4268 | if (!pValue) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4269 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4270 | } |
| 4271 | CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 4272 | if (pChildValue && XFA_FieldIsMultiListBox(this)) { |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 4273 | pChildValue->SetAttribute(XFA_ATTRIBUTE_ContentType, L"text/xml"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4274 | } |
| 4275 | return pChildValue |
| 4276 | ? pChildValue->TryContent(wsContent, bScriptModify, bProto) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4277 | : false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4278 | } |
| 4279 | break; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4280 | case XFA_ObjectType::ContentNode: { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4281 | CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild); |
| 4282 | if (!pContentRawDataNode) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4283 | XFA_Element element = XFA_Element::Sharptext; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4284 | if (GetElementType() == XFA_Element::ExData) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4285 | CFX_WideString wsContentType; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4286 | GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false); |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 4287 | if (wsContentType == L"text/html") { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4288 | element = XFA_Element::SharpxHTML; |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 4289 | } else if (wsContentType == L"text/xml") { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4290 | element = XFA_Element::Sharpxml; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4291 | } |
| 4292 | } |
| 4293 | pContentRawDataNode = CreateSamePacketNode(element); |
| 4294 | InsertChild(pContentRawDataNode); |
| 4295 | } |
| 4296 | return pContentRawDataNode->TryContent(wsContent, bScriptModify, bProto); |
| 4297 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4298 | case XFA_ObjectType::NodeC: |
| 4299 | case XFA_ObjectType::NodeV: |
| 4300 | case XFA_ObjectType::TextNode: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4301 | pNode = this; |
| 4302 | default: |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4303 | if (GetElementType() == XFA_Element::DataValue) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4304 | pNode = this; |
| 4305 | } |
| 4306 | break; |
| 4307 | } |
| 4308 | if (pNode) { |
| 4309 | if (bScriptModify) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 4310 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4311 | if (pScriptContext) { |
| 4312 | m_pDocument->GetScriptContext()->AddNodesOfRunScript(this); |
| 4313 | } |
| 4314 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4315 | return TryCData(XFA_ATTRIBUTE_Value, wsContent, false, bProto); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4316 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4317 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4318 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4319 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4320 | CXFA_Node* CXFA_Node::GetModelNode() { |
| 4321 | switch (GetPacketID()) { |
| 4322 | case XFA_XDPPACKET_XDP: |
| 4323 | return m_pDocument->GetRoot(); |
| 4324 | case XFA_XDPPACKET_Config: |
| 4325 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config)); |
| 4326 | case XFA_XDPPACKET_Template: |
| 4327 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template)); |
| 4328 | case XFA_XDPPACKET_Form: |
| 4329 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)); |
| 4330 | case XFA_XDPPACKET_Datasets: |
| 4331 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets)); |
| 4332 | case XFA_XDPPACKET_LocaleSet: |
| 4333 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_LocaleSet)); |
| 4334 | case XFA_XDPPACKET_ConnectionSet: |
| 4335 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_ConnectionSet)); |
| 4336 | case XFA_XDPPACKET_SourceSet: |
| 4337 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_SourceSet)); |
| 4338 | case XFA_XDPPACKET_Xdc: |
| 4339 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Xdc)); |
| 4340 | default: |
| 4341 | return this; |
| 4342 | } |
| 4343 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4344 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4345 | bool CXFA_Node::TryNamespace(CFX_WideString& wsNamespace) { |
tsepez | 774bdde | 2016-04-14 09:49:44 -0700 | [diff] [blame] | 4346 | wsNamespace.clear(); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4347 | if (IsModelNode() || GetElementType() == XFA_Element::Packet) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4348 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4349 | if (!pXMLNode || pXMLNode->GetType() != FDE_XMLNODE_Element) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4350 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4351 | } |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4352 | static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4353 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4354 | } else if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4355 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4356 | if (!pXMLNode) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4357 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4358 | } |
| 4359 | if (pXMLNode->GetType() != FDE_XMLNODE_Element) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4360 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4361 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4362 | if (GetElementType() == XFA_Element::DataValue && |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4363 | GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData) { |
| 4364 | return XFA_FDEExtension_ResolveNamespaceQualifier( |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4365 | static_cast<CFDE_XMLElement*>(pXMLNode), |
| 4366 | GetCData(XFA_ATTRIBUTE_QualifiedName), wsNamespace); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4367 | } |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4368 | static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4369 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4370 | } else { |
| 4371 | CXFA_Node* pModelNode = GetModelNode(); |
| 4372 | return pModelNode->TryNamespace(wsNamespace); |
| 4373 | } |
| 4374 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4375 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4376 | CXFA_Node* CXFA_Node::GetProperty(int32_t index, |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4377 | XFA_Element eProperty, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4378 | bool bCreateProperty) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4379 | XFA_Element eType = GetElementType(); |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 4380 | uint32_t dwPacket = GetPacketID(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4381 | const XFA_PROPERTY* pProperty = |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4382 | XFA_GetPropertyOfElement(eType, eProperty, dwPacket); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4383 | if (!pProperty || index >= pProperty->uOccur) |
| 4384 | return nullptr; |
| 4385 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4386 | CXFA_Node* pNode = m_pChild; |
| 4387 | int32_t iCount = 0; |
| 4388 | for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4389 | if (pNode->GetElementType() == eProperty) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4390 | iCount++; |
| 4391 | if (iCount > index) { |
| 4392 | return pNode; |
| 4393 | } |
| 4394 | } |
| 4395 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4396 | if (!bCreateProperty) |
| 4397 | return nullptr; |
| 4398 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4399 | if (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf) { |
| 4400 | pNode = m_pChild; |
| 4401 | for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 4402 | const XFA_PROPERTY* pExistProperty = |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4403 | XFA_GetPropertyOfElement(eType, pNode->GetElementType(), dwPacket); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4404 | if (pExistProperty && (pExistProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) |
| 4405 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4406 | } |
| 4407 | } |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4408 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4409 | const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(dwPacket); |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 4410 | CXFA_Node* pNewNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4411 | for (; iCount <= index; iCount++) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4412 | pNewNode = m_pDocument->CreateNode(pPacket, eProperty); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4413 | if (!pNewNode) |
| 4414 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4415 | InsertChild(pNewNode, nullptr); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4416 | pNewNode->SetFlag(XFA_NodeFlag_Initialized, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4417 | } |
| 4418 | return pNewNode; |
| 4419 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4420 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4421 | int32_t CXFA_Node::CountChildren(XFA_Element eType, bool bOnlyChild) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4422 | CXFA_Node* pNode = m_pChild; |
| 4423 | int32_t iCount = 0; |
| 4424 | for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4425 | if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4426 | if (bOnlyChild) { |
| 4427 | const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement( |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4428 | GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4429 | if (pProperty) { |
| 4430 | continue; |
| 4431 | } |
| 4432 | } |
| 4433 | iCount++; |
| 4434 | } |
| 4435 | } |
| 4436 | return iCount; |
| 4437 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4438 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4439 | CXFA_Node* CXFA_Node::GetChild(int32_t index, |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4440 | XFA_Element eType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4441 | bool bOnlyChild) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4442 | ASSERT(index > -1); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4443 | CXFA_Node* pNode = m_pChild; |
| 4444 | int32_t iCount = 0; |
| 4445 | for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4446 | if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4447 | if (bOnlyChild) { |
| 4448 | const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement( |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4449 | GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4450 | if (pProperty) { |
| 4451 | continue; |
| 4452 | } |
| 4453 | } |
| 4454 | iCount++; |
| 4455 | if (iCount > index) { |
| 4456 | return pNode; |
| 4457 | } |
| 4458 | } |
| 4459 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4460 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4461 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4462 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4463 | int32_t CXFA_Node::InsertChild(int32_t index, CXFA_Node* pNode) { |
| 4464 | ASSERT(!pNode->m_pNext); |
| 4465 | pNode->m_pParent = this; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4466 | bool ret = m_pDocument->RemovePurgeNode(pNode); |
Wei Li | 5fe7ae7 | 2016-05-04 21:13:15 -0700 | [diff] [blame] | 4467 | ASSERT(ret); |
Wei Li | 439bb9e | 2016-05-05 00:35:26 -0700 | [diff] [blame] | 4468 | (void)ret; // Avoid unused variable warning. |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4469 | |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4470 | if (!m_pChild || index == 0) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4471 | if (index > 0) { |
| 4472 | return -1; |
| 4473 | } |
| 4474 | pNode->m_pNext = m_pChild; |
| 4475 | m_pChild = pNode; |
| 4476 | index = 0; |
| 4477 | } else if (index < 0) { |
| 4478 | m_pLastChild->m_pNext = pNode; |
| 4479 | } else { |
| 4480 | CXFA_Node* pPrev = m_pChild; |
| 4481 | int32_t iCount = 0; |
| 4482 | while (++iCount != index && pPrev->m_pNext) { |
| 4483 | pPrev = pPrev->m_pNext; |
| 4484 | } |
| 4485 | if (index > 0 && index != iCount) { |
| 4486 | return -1; |
| 4487 | } |
| 4488 | pNode->m_pNext = pPrev->m_pNext; |
| 4489 | pPrev->m_pNext = pNode; |
| 4490 | index = iCount; |
| 4491 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4492 | if (!pNode->m_pNext) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4493 | m_pLastChild = pNode; |
| 4494 | } |
| 4495 | ASSERT(m_pLastChild); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4496 | ASSERT(!m_pLastChild->m_pNext); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4497 | pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4498 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4499 | if (pNotify) |
| 4500 | pNotify->OnChildAdded(this); |
| 4501 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4502 | if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4503 | ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4504 | m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, index); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4505 | pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4506 | } |
| 4507 | return index; |
| 4508 | } |
weili | 6e1ae86 | 2016-05-04 18:25:27 -0700 | [diff] [blame] | 4509 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4510 | bool CXFA_Node::InsertChild(CXFA_Node* pNode, CXFA_Node* pBeforeNode) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4511 | if (!pNode || pNode->m_pParent || |
| 4512 | (pBeforeNode && pBeforeNode->m_pParent != this)) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4513 | ASSERT(false); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4514 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4515 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4516 | bool ret = m_pDocument->RemovePurgeNode(pNode); |
Wei Li | 5fe7ae7 | 2016-05-04 21:13:15 -0700 | [diff] [blame] | 4517 | ASSERT(ret); |
Wei Li | 439bb9e | 2016-05-05 00:35:26 -0700 | [diff] [blame] | 4518 | (void)ret; // Avoid unused variable warning. |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4519 | |
| 4520 | int32_t nIndex = -1; |
| 4521 | pNode->m_pParent = this; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4522 | if (!m_pChild || pBeforeNode == m_pChild) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4523 | pNode->m_pNext = m_pChild; |
| 4524 | m_pChild = pNode; |
| 4525 | nIndex = 0; |
| 4526 | } else if (!pBeforeNode) { |
| 4527 | pNode->m_pNext = m_pLastChild->m_pNext; |
| 4528 | m_pLastChild->m_pNext = pNode; |
| 4529 | } else { |
| 4530 | nIndex = 1; |
| 4531 | CXFA_Node* pPrev = m_pChild; |
| 4532 | while (pPrev->m_pNext != pBeforeNode) { |
| 4533 | pPrev = pPrev->m_pNext; |
| 4534 | nIndex++; |
| 4535 | } |
| 4536 | pNode->m_pNext = pPrev->m_pNext; |
| 4537 | pPrev->m_pNext = pNode; |
| 4538 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4539 | if (!pNode->m_pNext) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4540 | m_pLastChild = pNode; |
| 4541 | } |
| 4542 | ASSERT(m_pLastChild); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4543 | ASSERT(!m_pLastChild->m_pNext); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4544 | pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4545 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4546 | if (pNotify) |
| 4547 | pNotify->OnChildAdded(this); |
| 4548 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4549 | if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4550 | ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4551 | m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, nIndex); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4552 | pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4553 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4554 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4555 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4556 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4557 | CXFA_Node* CXFA_Node::Deprecated_GetPrevSibling() { |
| 4558 | if (!m_pParent) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4559 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4560 | } |
| 4561 | for (CXFA_Node* pSibling = m_pParent->m_pChild; pSibling; |
| 4562 | pSibling = pSibling->m_pNext) { |
| 4563 | if (pSibling->m_pNext == this) { |
| 4564 | return pSibling; |
| 4565 | } |
| 4566 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4567 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4568 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4569 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4570 | bool CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4571 | if (!pNode || pNode->m_pParent != this) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4572 | ASSERT(false); |
| 4573 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4574 | } |
| 4575 | if (m_pChild == pNode) { |
| 4576 | m_pChild = pNode->m_pNext; |
| 4577 | if (m_pLastChild == pNode) { |
| 4578 | m_pLastChild = pNode->m_pNext; |
| 4579 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4580 | pNode->m_pNext = nullptr; |
| 4581 | pNode->m_pParent = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4582 | } else { |
| 4583 | CXFA_Node* pPrev = pNode->Deprecated_GetPrevSibling(); |
| 4584 | pPrev->m_pNext = pNode->m_pNext; |
| 4585 | if (m_pLastChild == pNode) { |
| 4586 | m_pLastChild = pNode->m_pNext ? pNode->m_pNext : pPrev; |
| 4587 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4588 | pNode->m_pNext = nullptr; |
| 4589 | pNode->m_pParent = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4590 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4591 | ASSERT(!m_pLastChild || !m_pLastChild->m_pNext); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4592 | OnRemoved(bNotify); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4593 | pNode->SetFlag(XFA_NodeFlag_HasRemovedChildren, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4594 | m_pDocument->AddPurgeNode(pNode); |
| 4595 | if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) { |
| 4596 | if (pNode->IsAttributeInXML()) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4597 | ASSERT(pNode->m_pXMLNode == m_pXMLNode && |
| 4598 | m_pXMLNode->GetType() == FDE_XMLNODE_Element); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4599 | if (pNode->m_pXMLNode->GetType() == FDE_XMLNODE_Element) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4600 | CFDE_XMLElement* pXMLElement = |
| 4601 | static_cast<CFDE_XMLElement*>(pNode->m_pXMLNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4602 | CFX_WideStringC wsAttributeName = |
| 4603 | pNode->GetCData(XFA_ATTRIBUTE_QualifiedName); |
tsepez | 660956f | 2016-04-06 06:27:29 -0700 | [diff] [blame] | 4604 | pXMLElement->RemoveAttribute(wsAttributeName.c_str()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4605 | } |
| 4606 | CFX_WideString wsName; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4607 | pNode->GetAttribute(XFA_ATTRIBUTE_Name, wsName, false); |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4608 | CFDE_XMLElement* pNewXMLElement = new CFDE_XMLElement(wsName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4609 | CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value); |
| 4610 | if (!wsValue.IsEmpty()) { |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 4611 | pNewXMLElement->SetTextData(CFX_WideString(wsValue)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4612 | } |
| 4613 | pNode->m_pXMLNode = pNewXMLElement; |
| 4614 | pNode->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown); |
| 4615 | } else { |
| 4616 | m_pXMLNode->RemoveChildNode(pNode->m_pXMLNode); |
| 4617 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4618 | pNode->SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4619 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4620 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4621 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4622 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4623 | CXFA_Node* CXFA_Node::GetFirstChildByName(const CFX_WideStringC& wsName) const { |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 4624 | return GetFirstChildByName(FX_HashCode_GetW(wsName, false)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4625 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4626 | |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 4627 | CXFA_Node* CXFA_Node::GetFirstChildByName(uint32_t dwNameHash) const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4628 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode; |
| 4629 | pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 4630 | if (pNode->GetNameHash() == dwNameHash) { |
| 4631 | return pNode; |
| 4632 | } |
| 4633 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4634 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4635 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4636 | |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4637 | CXFA_Node* CXFA_Node::GetFirstChildByClass(XFA_Element eType) const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4638 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode; |
| 4639 | pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4640 | if (pNode->GetElementType() == eType) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4641 | return pNode; |
| 4642 | } |
| 4643 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4644 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4645 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4646 | |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 4647 | CXFA_Node* CXFA_Node::GetNextSameNameSibling(uint32_t dwNameHash) const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4648 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode; |
| 4649 | pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 4650 | if (pNode->GetNameHash() == dwNameHash) { |
| 4651 | return pNode; |
| 4652 | } |
| 4653 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4654 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4655 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4656 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4657 | CXFA_Node* CXFA_Node::GetNextSameNameSibling( |
| 4658 | const CFX_WideStringC& wsNodeName) const { |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 4659 | return GetNextSameNameSibling(FX_HashCode_GetW(wsNodeName, false)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4660 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4661 | |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4662 | CXFA_Node* CXFA_Node::GetNextSameClassSibling(XFA_Element eType) const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4663 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode; |
| 4664 | pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4665 | if (pNode->GetElementType() == eType) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4666 | return pNode; |
| 4667 | } |
| 4668 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4669 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4670 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4671 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4672 | int32_t CXFA_Node::GetNodeSameNameIndex() const { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 4673 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4674 | if (!pScriptContext) { |
| 4675 | return -1; |
| 4676 | } |
| 4677 | return pScriptContext->GetIndexByName(const_cast<CXFA_Node*>(this)); |
| 4678 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4679 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4680 | int32_t CXFA_Node::GetNodeSameClassIndex() const { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 4681 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4682 | if (!pScriptContext) { |
| 4683 | return -1; |
| 4684 | } |
| 4685 | return pScriptContext->GetIndexByClassName(const_cast<CXFA_Node*>(this)); |
| 4686 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4687 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4688 | void CXFA_Node::GetSOMExpression(CFX_WideString& wsSOMExpression) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 4689 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4690 | if (!pScriptContext) { |
| 4691 | return; |
| 4692 | } |
| 4693 | pScriptContext->GetSomExpression(this, wsSOMExpression); |
| 4694 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4695 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4696 | CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4697 | CXFA_Node* pInstanceMgr = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4698 | if (m_ePacket == XFA_XDPPACKET_Form) { |
| 4699 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4700 | if (!pParentNode || pParentNode->GetElementType() == XFA_Element::Area) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4701 | return pInstanceMgr; |
| 4702 | } |
| 4703 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; |
| 4704 | pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4705 | XFA_Element eType = pNode->GetElementType(); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4706 | if ((eType == XFA_Element::Subform || eType == XFA_Element::SubformSet) && |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4707 | pNode->m_dwNameHash != m_dwNameHash) { |
| 4708 | break; |
| 4709 | } |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4710 | if (eType == XFA_Element::InstanceManager) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4711 | CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name); |
| 4712 | CFX_WideStringC wsInstName = pNode->GetCData(XFA_ATTRIBUTE_Name); |
| 4713 | if (wsInstName.GetLength() > 0 && wsInstName.GetAt(0) == '_' && |
| 4714 | wsInstName.Mid(1) == wsName) { |
| 4715 | pInstanceMgr = pNode; |
| 4716 | } |
| 4717 | break; |
| 4718 | } |
| 4719 | } |
| 4720 | } |
| 4721 | return pInstanceMgr; |
| 4722 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4723 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4724 | CXFA_Node* CXFA_Node::GetOccurNode() { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4725 | return GetFirstChildByClass(XFA_Element::Occur); |
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 | |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4728 | bool CXFA_Node::HasFlag(XFA_NodeFlag dwFlag) const { |
| 4729 | if (m_uNodeFlags & dwFlag) |
| 4730 | return true; |
| 4731 | if (dwFlag == XFA_NodeFlag_HasRemovedChildren) |
| 4732 | return m_pParent && m_pParent->HasFlag(dwFlag); |
| 4733 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4734 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4735 | |
| 4736 | void CXFA_Node::SetFlag(uint32_t dwFlag, bool bNotify) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4737 | if (dwFlag == XFA_NodeFlag_Initialized && bNotify && !IsInitialized()) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4738 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4739 | if (pNotify) { |
| 4740 | pNotify->OnNodeReady(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4741 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4742 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4743 | m_uNodeFlags |= dwFlag; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4744 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4745 | |
| 4746 | void CXFA_Node::ClearFlag(uint32_t dwFlag) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4747 | m_uNodeFlags &= ~dwFlag; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4748 | } |
| 4749 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4750 | bool CXFA_Node::IsAttributeInXML() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4751 | return GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData; |
| 4752 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4753 | |
| 4754 | void CXFA_Node::OnRemoved(bool bNotify) { |
| 4755 | if (!bNotify) |
| 4756 | return; |
| 4757 | |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4758 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4759 | if (pNotify) |
| 4760 | pNotify->OnChildRemoved(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4761 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4762 | |
| 4763 | void CXFA_Node::OnChanging(XFA_ATTRIBUTE eAttr, bool bNotify) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4764 | if (bNotify && IsInitialized()) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4765 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4766 | if (pNotify) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4767 | pNotify->OnValueChanging(this, eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4768 | } |
| 4769 | } |
| 4770 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4771 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4772 | void CXFA_Node::OnChanged(XFA_ATTRIBUTE eAttr, |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4773 | bool bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4774 | bool bScriptModify) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4775 | if (bNotify && IsInitialized()) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4776 | Script_Attribute_SendAttributeChangeMessage(eAttr, bScriptModify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4777 | } |
| 4778 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4779 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4780 | int32_t CXFA_Node::execSingleEventByName(const CFX_WideStringC& wsEventName, |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4781 | XFA_Element eType) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4782 | int32_t iRet = XFA_EVENTERROR_NotExist; |
| 4783 | const XFA_ExecEventParaInfo* eventParaInfo = |
| 4784 | GetEventParaInfoByName(wsEventName); |
| 4785 | if (eventParaInfo) { |
| 4786 | uint32_t validFlags = eventParaInfo->m_validFlags; |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4787 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4788 | if (!pNotify) { |
| 4789 | return iRet; |
| 4790 | } |
| 4791 | if (validFlags == 1) { |
| 4792 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType); |
| 4793 | } else if (validFlags == 2) { |
| 4794 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4795 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4796 | } else if (validFlags == 3) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4797 | if (eType == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4798 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4799 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4800 | } |
| 4801 | } else if (validFlags == 4) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4802 | if (eType == XFA_Element::ExclGroup || eType == XFA_Element::Field) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4803 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4804 | if (pParentNode && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4805 | pParentNode->GetElementType() == XFA_Element::ExclGroup) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4806 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4807 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4808 | } |
| 4809 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4810 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4811 | } |
| 4812 | } else if (validFlags == 5) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4813 | if (eType == XFA_Element::Field) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4814 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4815 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4816 | } |
| 4817 | } else if (validFlags == 6) { |
| 4818 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 4819 | if (pWidgetData) { |
| 4820 | CXFA_Node* pUINode = pWidgetData->GetUIChild(); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4821 | if (pUINode->m_elementType == XFA_Element::Signature) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4822 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4823 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4824 | } |
| 4825 | } |
| 4826 | } else if (validFlags == 7) { |
| 4827 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 4828 | if (pWidgetData) { |
| 4829 | CXFA_Node* pUINode = pWidgetData->GetUIChild(); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4830 | if ((pUINode->m_elementType == XFA_Element::ChoiceList) && |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4831 | (!pWidgetData->IsListBox())) { |
| 4832 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4833 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4834 | } |
| 4835 | } |
| 4836 | } |
| 4837 | } |
| 4838 | return iRet; |
| 4839 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4840 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4841 | void CXFA_Node::UpdateNameHash() { |
| 4842 | const XFA_NOTSUREATTRIBUTE* pNotsure = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4843 | XFA_GetNotsureAttribute(GetElementType(), XFA_ATTRIBUTE_Name); |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 4844 | CFX_WideStringC wsName; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4845 | if (!pNotsure || pNotsure->eType == XFA_ATTRIBUTETYPE_Cdata) { |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 4846 | wsName = GetCData(XFA_ATTRIBUTE_Name); |
| 4847 | m_dwNameHash = FX_HashCode_GetW(wsName, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4848 | } else if (pNotsure->eType == XFA_ATTRIBUTETYPE_Enum) { |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 4849 | wsName = GetAttributeEnumByID(GetEnum(XFA_ATTRIBUTE_Name))->pName; |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 4850 | m_dwNameHash = FX_HashCode_GetW(wsName, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4851 | } |
| 4852 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4853 | |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4854 | CFDE_XMLNode* CXFA_Node::CreateXMLMappingNode() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4855 | if (!m_pXMLNode) { |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 4856 | CFX_WideString wsTag(GetCData(XFA_ATTRIBUTE_Name)); |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4857 | m_pXMLNode = new CFDE_XMLElement(wsTag); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4858 | SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4859 | } |
| 4860 | return m_pXMLNode; |
| 4861 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4862 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4863 | bool CXFA_Node::IsNeedSavingXMLNode() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4864 | return m_pXMLNode && (GetPacketID() == XFA_XDPPACKET_Datasets || |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4865 | GetElementType() == XFA_Element::Xfa); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4866 | } |
| 4867 | |
| 4868 | XFA_MAPMODULEDATA* CXFA_Node::CreateMapModuleData() { |
| 4869 | if (!m_pMapModuleData) |
| 4870 | m_pMapModuleData = new XFA_MAPMODULEDATA; |
| 4871 | return m_pMapModuleData; |
| 4872 | } |
| 4873 | |
| 4874 | XFA_MAPMODULEDATA* CXFA_Node::GetMapModuleData() const { |
| 4875 | return m_pMapModuleData; |
| 4876 | } |
| 4877 | |
| 4878 | void CXFA_Node::SetMapModuleValue(void* pKey, void* pValue) { |
| 4879 | XFA_MAPMODULEDATA* pModule = CreateMapModuleData(); |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4880 | pModule->m_ValueMap[pKey] = pValue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4881 | } |
| 4882 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4883 | bool CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) { |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4884 | for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4885 | XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData(); |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4886 | if (pModule) { |
| 4887 | auto it = pModule->m_ValueMap.find(pKey); |
| 4888 | if (it != pModule->m_ValueMap.end()) { |
| 4889 | pValue = it->second; |
| 4890 | return true; |
| 4891 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4892 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4893 | if (pNode->GetPacketID() == XFA_XDPPACKET_Datasets) |
| 4894 | break; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4895 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4896 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4897 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4898 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4899 | void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) { |
tsepez | 660956f | 2016-04-06 06:27:29 -0700 | [diff] [blame] | 4900 | SetMapModuleBuffer(pKey, (void*)wsValue.c_str(), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4901 | wsValue.GetLength() * sizeof(FX_WCHAR)); |
| 4902 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4903 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4904 | bool CXFA_Node::GetMapModuleString(void* pKey, CFX_WideStringC& wsValue) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4905 | void* pValue; |
| 4906 | int32_t iBytes; |
| 4907 | if (!GetMapModuleBuffer(pKey, pValue, iBytes)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4908 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4909 | } |
| 4910 | wsValue = CFX_WideStringC((const FX_WCHAR*)pValue, iBytes / sizeof(FX_WCHAR)); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4911 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4912 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4913 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4914 | void CXFA_Node::SetMapModuleBuffer( |
| 4915 | void* pKey, |
| 4916 | void* pValue, |
| 4917 | int32_t iBytes, |
| 4918 | XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) { |
| 4919 | XFA_MAPMODULEDATA* pModule = CreateMapModuleData(); |
| 4920 | XFA_MAPDATABLOCK*& pBuffer = pModule->m_BufferMap[pKey]; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4921 | if (!pBuffer) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4922 | pBuffer = |
| 4923 | (XFA_MAPDATABLOCK*)FX_Alloc(uint8_t, sizeof(XFA_MAPDATABLOCK) + iBytes); |
| 4924 | } else if (pBuffer->iBytes != iBytes) { |
| 4925 | if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { |
| 4926 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
| 4927 | } |
| 4928 | pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(uint8_t, pBuffer, |
| 4929 | sizeof(XFA_MAPDATABLOCK) + iBytes); |
| 4930 | } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { |
| 4931 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
| 4932 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4933 | if (!pBuffer) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4934 | return; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4935 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4936 | pBuffer->pCallbackInfo = pCallbackInfo; |
| 4937 | pBuffer->iBytes = iBytes; |
| 4938 | FXSYS_memcpy(pBuffer->GetData(), pValue, iBytes); |
| 4939 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4940 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4941 | bool CXFA_Node::GetMapModuleBuffer(void* pKey, |
| 4942 | void*& pValue, |
| 4943 | int32_t& iBytes, |
| 4944 | bool bProtoAlso) const { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4945 | XFA_MAPDATABLOCK* pBuffer = nullptr; |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4946 | for (const CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4947 | XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData(); |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4948 | if (pModule) { |
| 4949 | auto it = pModule->m_BufferMap.find(pKey); |
| 4950 | if (it != pModule->m_BufferMap.end()) { |
| 4951 | pBuffer = it->second; |
| 4952 | break; |
| 4953 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4954 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4955 | if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets) |
| 4956 | break; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4957 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4958 | if (!pBuffer) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4959 | return false; |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4960 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4961 | pValue = pBuffer->GetData(); |
| 4962 | iBytes = pBuffer->iBytes; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4963 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4964 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4965 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4966 | bool CXFA_Node::HasMapModuleKey(void* pKey, bool bProtoAlso) { |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4967 | for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4968 | XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData(); |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4969 | if (pModule) { |
| 4970 | auto it1 = pModule->m_ValueMap.find(pKey); |
| 4971 | if (it1 != pModule->m_ValueMap.end()) |
| 4972 | return true; |
| 4973 | |
| 4974 | auto it2 = pModule->m_BufferMap.find(pKey); |
| 4975 | if (it2 != pModule->m_BufferMap.end()) |
| 4976 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4977 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4978 | if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets) |
| 4979 | break; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4980 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4981 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4982 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4983 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4984 | void CXFA_Node::RemoveMapModuleKey(void* pKey) { |
| 4985 | XFA_MAPMODULEDATA* pModule = GetMapModuleData(); |
| 4986 | if (!pModule) |
| 4987 | return; |
| 4988 | |
| 4989 | if (pKey) { |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4990 | auto it = pModule->m_BufferMap.find(pKey); |
| 4991 | if (it != pModule->m_BufferMap.end()) { |
| 4992 | XFA_MAPDATABLOCK* pBuffer = it->second; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4993 | if (pBuffer) { |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4994 | if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4995 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4996 | FX_Free(pBuffer); |
| 4997 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4998 | pModule->m_BufferMap.erase(it); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4999 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 5000 | pModule->m_ValueMap.erase(pKey); |
| 5001 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5002 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 5003 | |
| 5004 | for (auto& pair : pModule->m_BufferMap) { |
| 5005 | XFA_MAPDATABLOCK* pBuffer = pair.second; |
| 5006 | if (pBuffer) { |
| 5007 | if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) |
| 5008 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
| 5009 | FX_Free(pBuffer); |
| 5010 | } |
| 5011 | } |
| 5012 | pModule->m_BufferMap.clear(); |
| 5013 | pModule->m_ValueMap.clear(); |
| 5014 | delete pModule; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5015 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 5016 | |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 5017 | void CXFA_Node::MergeAllData(void* pDstModule) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5018 | XFA_MAPMODULEDATA* pDstModuleData = |
| 5019 | static_cast<CXFA_Node*>(pDstModule)->CreateMapModuleData(); |
| 5020 | XFA_MAPMODULEDATA* pSrcModuleData = GetMapModuleData(); |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 5021 | if (!pSrcModuleData) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5022 | return; |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 5023 | |
| 5024 | for (const auto& pair : pSrcModuleData->m_ValueMap) |
| 5025 | pDstModuleData->m_ValueMap[pair.first] = pair.second; |
| 5026 | |
| 5027 | for (const auto& pair : pSrcModuleData->m_BufferMap) { |
| 5028 | XFA_MAPDATABLOCK* pSrcBuffer = pair.second; |
| 5029 | XFA_MAPDATABLOCK*& pDstBuffer = pDstModuleData->m_BufferMap[pair.first]; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5030 | if (pSrcBuffer->pCallbackInfo && pSrcBuffer->pCallbackInfo->pFree && |
| 5031 | !pSrcBuffer->pCallbackInfo->pCopy) { |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 5032 | if (pDstBuffer) { |
| 5033 | pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData()); |
| 5034 | pDstModuleData->m_BufferMap.erase(pair.first); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5035 | } |
| 5036 | continue; |
| 5037 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 5038 | if (!pDstBuffer) { |
| 5039 | pDstBuffer = (XFA_MAPDATABLOCK*)FX_Alloc( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5040 | uint8_t, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes); |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 5041 | } else if (pDstBuffer->iBytes != pSrcBuffer->iBytes) { |
| 5042 | if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) { |
| 5043 | pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5044 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 5045 | pDstBuffer = (XFA_MAPDATABLOCK*)FX_Realloc( |
| 5046 | uint8_t, pDstBuffer, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes); |
| 5047 | } else if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) { |
| 5048 | pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5049 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 5050 | if (!pDstBuffer) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5051 | continue; |
| 5052 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 5053 | pDstBuffer->pCallbackInfo = pSrcBuffer->pCallbackInfo; |
| 5054 | pDstBuffer->iBytes = pSrcBuffer->iBytes; |
| 5055 | FXSYS_memcpy(pDstBuffer->GetData(), pSrcBuffer->GetData(), |
| 5056 | pSrcBuffer->iBytes); |
| 5057 | if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pCopy) { |
| 5058 | pDstBuffer->pCallbackInfo->pCopy(*(void**)pDstBuffer->GetData()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5059 | } |
| 5060 | } |
| 5061 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 5062 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5063 | void CXFA_Node::MoveBufferMapData(CXFA_Node* pDstModule, void* pKey) { |
| 5064 | if (!pDstModule) { |
| 5065 | return; |
| 5066 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5067 | bool bNeedMove = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5068 | if (!pKey) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5069 | bNeedMove = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5070 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 5071 | if (pDstModule->GetElementType() != GetElementType()) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5072 | bNeedMove = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5073 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5074 | XFA_MAPMODULEDATA* pSrcModuleData = nullptr; |
| 5075 | XFA_MAPMODULEDATA* pDstModuleData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5076 | if (bNeedMove) { |
| 5077 | pSrcModuleData = GetMapModuleData(); |
| 5078 | if (!pSrcModuleData) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5079 | bNeedMove = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5080 | } |
| 5081 | pDstModuleData = pDstModule->CreateMapModuleData(); |
| 5082 | } |
| 5083 | if (bNeedMove) { |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 5084 | auto it = pSrcModuleData->m_BufferMap.find(pKey); |
| 5085 | if (it != pSrcModuleData->m_BufferMap.end()) { |
| 5086 | XFA_MAPDATABLOCK* pBufferBlockData = it->second; |
| 5087 | if (pBufferBlockData) { |
| 5088 | pSrcModuleData->m_BufferMap.erase(pKey); |
| 5089 | pDstModuleData->m_BufferMap[pKey] = pBufferBlockData; |
| 5090 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5091 | } |
| 5092 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 5093 | if (pDstModule->IsNodeV()) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5094 | CFX_WideString wsValue = pDstModule->GetScriptContent(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5095 | CFX_WideString wsFormatValue(wsValue); |
| 5096 | CXFA_WidgetData* pWidgetData = pDstModule->GetContainerWidgetData(); |
| 5097 | if (pWidgetData) { |
tsepez | 6f167c3 | 2016-04-14 15:46:27 -0700 | [diff] [blame] | 5098 | pWidgetData->GetFormatDataValue(wsValue, wsFormatValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5099 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5100 | pDstModule->SetScriptContent(wsValue, wsFormatValue, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5101 | } |
| 5102 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 5103 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5104 | void CXFA_Node::MoveBufferMapData(CXFA_Node* pSrcModule, |
| 5105 | CXFA_Node* pDstModule, |
| 5106 | void* pKey, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5107 | bool bRecursive) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5108 | if (!pSrcModule || !pDstModule || !pKey) { |
| 5109 | return; |
| 5110 | } |
| 5111 | if (bRecursive) { |
| 5112 | CXFA_Node* pSrcChild = pSrcModule->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 5113 | CXFA_Node* pDstChild = pDstModule->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 5114 | for (; pSrcChild && pDstChild; |
| 5115 | pSrcChild = pSrcChild->GetNodeItem(XFA_NODEITEM_NextSibling), |
| 5116 | pDstChild = pDstChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5117 | MoveBufferMapData(pSrcChild, pDstChild, pKey, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5118 | } |
| 5119 | } |
| 5120 | pSrcModule->MoveBufferMapData(pDstModule, pKey); |
| 5121 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 5122 | |
| 5123 | void CXFA_Node::ThrowMissingPropertyException( |
| 5124 | const CFX_WideString& obj, |
| 5125 | const CFX_WideString& prop) const { |
| 5126 | ThrowException(L"'%s' doesn't have property '%s'.", obj.c_str(), |
| 5127 | prop.c_str()); |
| 5128 | } |
| 5129 | |
| 5130 | void CXFA_Node::ThrowTooManyOccurancesException( |
| 5131 | const CFX_WideString& obj) const { |
| 5132 | ThrowException( |
| 5133 | L"The element [%s] has violated its allowable number of occurrences.", |
| 5134 | obj.c_str()); |
| 5135 | } |