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 | |
Dan Sinclair | efcae5d | 2017-03-29 14:47:46 -0400 | [diff] [blame] | 7 | #include "xfa/fxfa/parser/cxfa_node.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 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 | |
Dan Sinclair | b929ab0 | 2017-03-29 15:18:16 -0400 | [diff] [blame] | 15 | #include "core/fxcrt/cfx_decimal.h" |
Dan Sinclair | 3b71d26 | 2017-04-19 08:58:54 -0400 | [diff] [blame] | 16 | #include "core/fxcrt/fx_codepage.h" |
Dan Sinclair | cfb1944 | 2017-04-20 13:13:04 -0400 | [diff] [blame^] | 17 | #include "core/fxcrt/fx_extension.h" |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 18 | #include "core/fxcrt/xml/cfx_xmlelement.h" |
| 19 | #include "core/fxcrt/xml/cfx_xmlnode.h" |
| 20 | #include "core/fxcrt/xml/cfx_xmltext.h" |
dsinclair | 4355468 | 2016-09-29 17:29:48 -0700 | [diff] [blame] | 21 | #include "fxjs/cfxjse_value.h" |
tsepez | a9caab9 | 2016-12-14 05:57:10 -0800 | [diff] [blame] | 22 | #include "third_party/base/ptr_util.h" |
tsepez | aadedf9 | 2016-05-12 10:08:06 -0700 | [diff] [blame] | 23 | #include "third_party/base/stl_util.h" |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 24 | #include "xfa/fxfa/app/xfa_ffnotify.h" |
dsinclair | 5b49309 | 2016-09-29 20:20:24 -0700 | [diff] [blame] | 25 | #include "xfa/fxfa/cxfa_eventparam.h" |
Dan Sinclair | efcae5d | 2017-03-29 14:47:46 -0400 | [diff] [blame] | 26 | #include "xfa/fxfa/cxfa_ffwidget.h" |
| 27 | #include "xfa/fxfa/parser/cxfa_arraynodelist.h" |
| 28 | #include "xfa/fxfa/parser/cxfa_attachnodelist.h" |
dsinclair | 1628024 | 2016-07-21 12:03:47 -0700 | [diff] [blame] | 29 | #include "xfa/fxfa/parser/cxfa_document.h" |
dsinclair | 0b851ff | 2016-07-21 12:03:01 -0700 | [diff] [blame] | 30 | #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 31 | #include "xfa/fxfa/parser/cxfa_measurement.h" |
dsinclair | 44d054c | 2016-04-06 10:23:46 -0700 | [diff] [blame] | 32 | #include "xfa/fxfa/parser/cxfa_occur.h" |
dsinclair | 31f8740 | 2016-07-20 06:34:45 -0700 | [diff] [blame] | 33 | #include "xfa/fxfa/parser/cxfa_scriptcontext.h" |
dsinclair | 34f86b0 | 2016-07-11 08:42:33 -0700 | [diff] [blame] | 34 | #include "xfa/fxfa/parser/cxfa_simple_parser.h" |
Dan Sinclair | efcae5d | 2017-03-29 14:47:46 -0400 | [diff] [blame] | 35 | #include "xfa/fxfa/parser/cxfa_traversestrategy_xfacontainernode.h" |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 36 | #include "xfa/fxfa/parser/xfa_basic_data.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 37 | |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 38 | namespace { |
| 39 | |
| 40 | void XFA_DeleteWideString(void* pData) { |
| 41 | delete static_cast<CFX_WideString*>(pData); |
| 42 | } |
| 43 | |
| 44 | void XFA_CopyWideString(void*& pData) { |
| 45 | if (pData) { |
| 46 | CFX_WideString* pNewData = new CFX_WideString(*(CFX_WideString*)pData); |
| 47 | pData = pNewData; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | XFA_MAPDATABLOCKCALLBACKINFO deleteWideStringCallBack = {XFA_DeleteWideString, |
| 52 | XFA_CopyWideString}; |
| 53 | |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 54 | void XFA_DataNodeDeleteBindItem(void* pData) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 55 | delete static_cast<std::vector<CXFA_Node*>*>(pData); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | XFA_MAPDATABLOCKCALLBACKINFO deleteBindItemCallBack = { |
| 59 | XFA_DataNodeDeleteBindItem, nullptr}; |
| 60 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 61 | int32_t GetCount(CXFA_Node* pInstMgrNode) { |
| 62 | ASSERT(pInstMgrNode); |
| 63 | int32_t iCount = 0; |
| 64 | uint32_t dwNameHash = 0; |
| 65 | for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 66 | pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 67 | XFA_Element eCurType = pNode->GetElementType(); |
| 68 | if (eCurType == XFA_Element::InstanceManager) |
| 69 | break; |
| 70 | if ((eCurType != XFA_Element::Subform) && |
| 71 | (eCurType != XFA_Element::SubformSet)) { |
| 72 | continue; |
| 73 | } |
| 74 | if (iCount == 0) { |
| 75 | CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name); |
| 76 | CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name); |
| 77 | if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' || |
| 78 | wsInstName.Mid(1) != wsName) { |
| 79 | return iCount; |
| 80 | } |
| 81 | dwNameHash = pNode->GetNameHash(); |
| 82 | } |
| 83 | if (dwNameHash != pNode->GetNameHash()) |
| 84 | break; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 85 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 86 | iCount++; |
| 87 | } |
| 88 | return iCount; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 89 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 90 | |
Tom Sepez | 7cdc660 | 2017-03-28 09:56:48 -0700 | [diff] [blame] | 91 | std::vector<CXFA_Node*> NodesSortedByDocumentIdx( |
| 92 | const std::unordered_set<CXFA_Node*>& rgNodeSet) { |
| 93 | if (rgNodeSet.empty()) |
| 94 | return std::vector<CXFA_Node*>(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 95 | |
Tom Sepez | 7cdc660 | 2017-03-28 09:56:48 -0700 | [diff] [blame] | 96 | std::vector<CXFA_Node*> rgNodeArray; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 97 | CXFA_Node* pCommonParent = |
| 98 | (*rgNodeSet.begin())->GetNodeItem(XFA_NODEITEM_Parent); |
| 99 | for (CXFA_Node* pNode = pCommonParent->GetNodeItem(XFA_NODEITEM_FirstChild); |
Tom Sepez | 7cdc660 | 2017-03-28 09:56:48 -0700 | [diff] [blame] | 100 | pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 101 | if (pdfium::ContainsValue(rgNodeSet, pNode)) |
| 102 | rgNodeArray.push_back(pNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 103 | } |
Tom Sepez | 7cdc660 | 2017-03-28 09:56:48 -0700 | [diff] [blame] | 104 | return rgNodeArray; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 105 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 106 | |
Tom Sepez | d4db58f | 2017-03-02 14:57:59 -0800 | [diff] [blame] | 107 | using CXFA_NodeSetPair = |
| 108 | std::pair<std::unordered_set<CXFA_Node*>, std::unordered_set<CXFA_Node*>>; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 109 | using CXFA_NodeSetPairMap = |
| 110 | std::map<uint32_t, std::unique_ptr<CXFA_NodeSetPair>>; |
| 111 | using CXFA_NodeSetPairMapMap = |
| 112 | std::map<CXFA_Node*, std::unique_ptr<CXFA_NodeSetPairMap>>; |
| 113 | |
| 114 | CXFA_NodeSetPair* NodeSetPairForNode(CXFA_Node* pNode, |
| 115 | CXFA_NodeSetPairMapMap* pMap) { |
| 116 | CXFA_Node* pParentNode = pNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 117 | uint32_t dwNameHash = pNode->GetNameHash(); |
| 118 | if (!pParentNode || !dwNameHash) |
| 119 | return nullptr; |
| 120 | |
| 121 | if (!(*pMap)[pParentNode]) |
tsepez | a9caab9 | 2016-12-14 05:57:10 -0800 | [diff] [blame] | 122 | (*pMap)[pParentNode] = pdfium::MakeUnique<CXFA_NodeSetPairMap>(); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 123 | |
| 124 | CXFA_NodeSetPairMap* pNodeSetPairMap = (*pMap)[pParentNode].get(); |
| 125 | if (!(*pNodeSetPairMap)[dwNameHash]) |
tsepez | a9caab9 | 2016-12-14 05:57:10 -0800 | [diff] [blame] | 126 | (*pNodeSetPairMap)[dwNameHash] = pdfium::MakeUnique<CXFA_NodeSetPair>(); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 127 | |
| 128 | return (*pNodeSetPairMap)[dwNameHash].get(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 129 | } |
| 130 | |
Tom Sepez | d4db58f | 2017-03-02 14:57:59 -0800 | [diff] [blame] | 131 | void ReorderDataNodes(const std::unordered_set<CXFA_Node*>& sSet1, |
| 132 | const std::unordered_set<CXFA_Node*>& sSet2, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 133 | bool bInsertBefore) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 134 | CXFA_NodeSetPairMapMap rgMap; |
| 135 | for (CXFA_Node* pNode : sSet1) { |
| 136 | CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap); |
| 137 | if (pNodeSetPair) |
| 138 | pNodeSetPair->first.insert(pNode); |
| 139 | } |
| 140 | for (CXFA_Node* pNode : sSet2) { |
| 141 | CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap); |
| 142 | if (pNodeSetPair) { |
| 143 | if (pdfium::ContainsValue(pNodeSetPair->first, pNode)) |
| 144 | pNodeSetPair->first.erase(pNode); |
| 145 | else |
| 146 | pNodeSetPair->second.insert(pNode); |
| 147 | } |
| 148 | } |
| 149 | for (const auto& iter1 : rgMap) { |
| 150 | CXFA_NodeSetPairMap* pNodeSetPairMap = iter1.second.get(); |
| 151 | if (!pNodeSetPairMap) |
| 152 | continue; |
| 153 | |
| 154 | for (const auto& iter2 : *pNodeSetPairMap) { |
| 155 | CXFA_NodeSetPair* pNodeSetPair = iter2.second.get(); |
| 156 | if (!pNodeSetPair) |
| 157 | continue; |
| 158 | if (!pNodeSetPair->first.empty() && !pNodeSetPair->second.empty()) { |
Tom Sepez | 7cdc660 | 2017-03-28 09:56:48 -0700 | [diff] [blame] | 159 | std::vector<CXFA_Node*> rgNodeArray1 = |
| 160 | NodesSortedByDocumentIdx(pNodeSetPair->first); |
| 161 | std::vector<CXFA_Node*> rgNodeArray2 = |
| 162 | NodesSortedByDocumentIdx(pNodeSetPair->second); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 163 | CXFA_Node* pParentNode = nullptr; |
| 164 | CXFA_Node* pBeforeNode = nullptr; |
| 165 | if (bInsertBefore) { |
Tom Sepez | 7cdc660 | 2017-03-28 09:56:48 -0700 | [diff] [blame] | 166 | pBeforeNode = rgNodeArray2.front(); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 167 | pParentNode = pBeforeNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 168 | } else { |
Tom Sepez | 7cdc660 | 2017-03-28 09:56:48 -0700 | [diff] [blame] | 169 | CXFA_Node* pLastNode = rgNodeArray2.back(); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 170 | pParentNode = pLastNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 171 | pBeforeNode = pLastNode->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 172 | } |
Tom Sepez | 7cdc660 | 2017-03-28 09:56:48 -0700 | [diff] [blame] | 173 | for (auto* pCurNode : rgNodeArray1) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 174 | pParentNode->RemoveChild(pCurNode); |
| 175 | pParentNode->InsertChild(pCurNode, pBeforeNode); |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | pNodeSetPairMap->clear(); |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | CXFA_Node* GetItem(CXFA_Node* pInstMgrNode, int32_t iIndex) { |
| 184 | ASSERT(pInstMgrNode); |
| 185 | int32_t iCount = 0; |
| 186 | uint32_t dwNameHash = 0; |
| 187 | for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 188 | pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 189 | XFA_Element eCurType = pNode->GetElementType(); |
| 190 | if (eCurType == XFA_Element::InstanceManager) |
| 191 | break; |
| 192 | if ((eCurType != XFA_Element::Subform) && |
| 193 | (eCurType != XFA_Element::SubformSet)) { |
| 194 | continue; |
| 195 | } |
| 196 | if (iCount == 0) { |
| 197 | CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name); |
| 198 | CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name); |
| 199 | if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' || |
| 200 | wsInstName.Mid(1) != wsName) { |
| 201 | return nullptr; |
| 202 | } |
| 203 | dwNameHash = pNode->GetNameHash(); |
| 204 | } |
| 205 | if (dwNameHash != pNode->GetNameHash()) |
| 206 | break; |
| 207 | |
| 208 | iCount++; |
| 209 | if (iCount > iIndex) |
| 210 | return pNode; |
| 211 | } |
| 212 | return nullptr; |
| 213 | } |
| 214 | |
| 215 | void InsertItem(CXFA_Node* pInstMgrNode, |
| 216 | CXFA_Node* pNewInstance, |
| 217 | int32_t iPos, |
| 218 | int32_t iCount = -1, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 219 | bool bMoveDataBindingNodes = true) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 220 | if (iCount < 0) |
| 221 | iCount = GetCount(pInstMgrNode); |
| 222 | if (iPos < 0) |
| 223 | iPos = iCount; |
| 224 | if (iPos == iCount) { |
| 225 | CXFA_Node* pNextSibling = |
| 226 | iCount > 0 |
| 227 | ? GetItem(pInstMgrNode, iCount - 1) |
| 228 | ->GetNodeItem(XFA_NODEITEM_NextSibling) |
| 229 | : pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 230 | pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent) |
| 231 | ->InsertChild(pNewInstance, pNextSibling); |
| 232 | if (bMoveDataBindingNodes) { |
Tom Sepez | d4db58f | 2017-03-02 14:57:59 -0800 | [diff] [blame] | 233 | std::unordered_set<CXFA_Node*> sNew; |
| 234 | std::unordered_set<CXFA_Node*> sAfter; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 235 | CXFA_NodeIteratorTemplate<CXFA_Node, |
| 236 | CXFA_TraverseStrategy_XFAContainerNode> |
| 237 | sIteratorNew(pNewInstance); |
| 238 | for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode; |
| 239 | pNode = sIteratorNew.MoveToNext()) { |
| 240 | CXFA_Node* pDataNode = pNode->GetBindData(); |
| 241 | if (!pDataNode) |
| 242 | continue; |
| 243 | |
| 244 | sNew.insert(pDataNode); |
| 245 | } |
| 246 | CXFA_NodeIteratorTemplate<CXFA_Node, |
| 247 | CXFA_TraverseStrategy_XFAContainerNode> |
| 248 | sIteratorAfter(pNextSibling); |
| 249 | for (CXFA_Node* pNode = sIteratorAfter.GetCurrent(); pNode; |
| 250 | pNode = sIteratorAfter.MoveToNext()) { |
| 251 | CXFA_Node* pDataNode = pNode->GetBindData(); |
| 252 | if (!pDataNode) |
| 253 | continue; |
| 254 | |
| 255 | sAfter.insert(pDataNode); |
| 256 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 257 | ReorderDataNodes(sNew, sAfter, false); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 258 | } |
| 259 | } else { |
| 260 | CXFA_Node* pBeforeInstance = GetItem(pInstMgrNode, iPos); |
| 261 | pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent) |
| 262 | ->InsertChild(pNewInstance, pBeforeInstance); |
| 263 | if (bMoveDataBindingNodes) { |
Tom Sepez | d4db58f | 2017-03-02 14:57:59 -0800 | [diff] [blame] | 264 | std::unordered_set<CXFA_Node*> sNew; |
| 265 | std::unordered_set<CXFA_Node*> sBefore; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 266 | CXFA_NodeIteratorTemplate<CXFA_Node, |
| 267 | CXFA_TraverseStrategy_XFAContainerNode> |
| 268 | sIteratorNew(pNewInstance); |
| 269 | for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode; |
| 270 | pNode = sIteratorNew.MoveToNext()) { |
| 271 | CXFA_Node* pDataNode = pNode->GetBindData(); |
| 272 | if (!pDataNode) |
| 273 | continue; |
| 274 | |
| 275 | sNew.insert(pDataNode); |
| 276 | } |
| 277 | CXFA_NodeIteratorTemplate<CXFA_Node, |
| 278 | CXFA_TraverseStrategy_XFAContainerNode> |
| 279 | sIteratorBefore(pBeforeInstance); |
| 280 | for (CXFA_Node* pNode = sIteratorBefore.GetCurrent(); pNode; |
| 281 | pNode = sIteratorBefore.MoveToNext()) { |
| 282 | CXFA_Node* pDataNode = pNode->GetBindData(); |
| 283 | if (!pDataNode) |
| 284 | continue; |
| 285 | |
| 286 | sBefore.insert(pDataNode); |
| 287 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 288 | ReorderDataNodes(sNew, sBefore, true); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 289 | } |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | void RemoveItem(CXFA_Node* pInstMgrNode, |
| 294 | CXFA_Node* pRemoveInstance, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 295 | bool bRemoveDataBinding = true) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 296 | pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)->RemoveChild(pRemoveInstance); |
| 297 | if (!bRemoveDataBinding) |
| 298 | return; |
| 299 | |
| 300 | CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFAContainerNode> |
| 301 | sIterator(pRemoveInstance); |
| 302 | for (CXFA_Node* pFormNode = sIterator.GetCurrent(); pFormNode; |
| 303 | pFormNode = sIterator.MoveToNext()) { |
| 304 | CXFA_Node* pDataNode = pFormNode->GetBindData(); |
| 305 | if (!pDataNode) |
| 306 | continue; |
| 307 | |
| 308 | if (pDataNode->RemoveBindItem(pFormNode) == 0) { |
| 309 | if (CXFA_Node* pDataParent = |
| 310 | pDataNode->GetNodeItem(XFA_NODEITEM_Parent)) { |
| 311 | pDataParent->RemoveChild(pDataNode); |
| 312 | } |
| 313 | } |
| 314 | pFormNode->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr); |
| 315 | } |
| 316 | } |
| 317 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 318 | CXFA_Node* CreateInstance(CXFA_Node* pInstMgrNode, bool bDataMerge) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 319 | CXFA_Document* pDocument = pInstMgrNode->GetDocument(); |
| 320 | CXFA_Node* pTemplateNode = pInstMgrNode->GetTemplateNode(); |
| 321 | CXFA_Node* pFormParent = pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 322 | CXFA_Node* pDataScope = nullptr; |
| 323 | for (CXFA_Node* pRootBoundNode = pFormParent; |
| 324 | pRootBoundNode && pRootBoundNode->IsContainerNode(); |
| 325 | pRootBoundNode = pRootBoundNode->GetNodeItem(XFA_NODEITEM_Parent)) { |
| 326 | pDataScope = pRootBoundNode->GetBindData(); |
| 327 | if (pDataScope) |
| 328 | break; |
| 329 | } |
| 330 | if (!pDataScope) { |
| 331 | pDataScope = ToNode(pDocument->GetXFAObject(XFA_HASHCODE_Record)); |
| 332 | ASSERT(pDataScope); |
| 333 | } |
| 334 | CXFA_Node* pInstance = pDocument->DataMerge_CopyContainer( |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 335 | pTemplateNode, pFormParent, pDataScope, true, bDataMerge, true); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 336 | if (pInstance) { |
| 337 | pDocument->DataMerge_UpdateBindingRelations(pInstance); |
| 338 | pFormParent->RemoveChild(pInstance); |
| 339 | } |
| 340 | return pInstance; |
| 341 | } |
| 342 | |
| 343 | struct XFA_ExecEventParaInfo { |
| 344 | public: |
| 345 | uint32_t m_uHash; |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 346 | const wchar_t* m_lpcEventName; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 347 | XFA_EVENTTYPE m_eventType; |
| 348 | uint32_t m_validFlags; |
| 349 | }; |
| 350 | static const XFA_ExecEventParaInfo gs_eventParaInfos[] = { |
| 351 | {0x02a6c55a, L"postSubmit", XFA_EVENT_PostSubmit, 0}, |
| 352 | {0x0ab466bb, L"preSubmit", XFA_EVENT_PreSubmit, 0}, |
| 353 | {0x109d7ce7, L"mouseEnter", XFA_EVENT_MouseEnter, 5}, |
| 354 | {0x17fad373, L"postPrint", XFA_EVENT_PostPrint, 0}, |
| 355 | {0x1bfc72d9, L"preOpen", XFA_EVENT_PreOpen, 7}, |
| 356 | {0x2196a452, L"initialize", XFA_EVENT_Initialize, 1}, |
| 357 | {0x27410f03, L"mouseExit", XFA_EVENT_MouseExit, 5}, |
| 358 | {0x33c43dec, L"docClose", XFA_EVENT_DocClose, 0}, |
| 359 | {0x361fa1b6, L"preSave", XFA_EVENT_PreSave, 0}, |
| 360 | {0x36f1c6d8, L"preSign", XFA_EVENT_PreSign, 6}, |
| 361 | {0x4731d6ba, L"exit", XFA_EVENT_Exit, 2}, |
| 362 | {0x56bf456b, L"docReady", XFA_EVENT_DocReady, 0}, |
| 363 | {0x7233018a, L"validate", XFA_EVENT_Validate, 1}, |
| 364 | {0x8808385e, L"indexChange", XFA_EVENT_IndexChange, 3}, |
| 365 | {0x891f4606, L"change", XFA_EVENT_Change, 4}, |
| 366 | {0x9528a7b4, L"prePrint", XFA_EVENT_PrePrint, 0}, |
| 367 | {0x9f693b21, L"mouseDown", XFA_EVENT_MouseDown, 5}, |
| 368 | {0xcdce56b3, L"full", XFA_EVENT_Full, 4}, |
| 369 | {0xd576d08e, L"mouseUp", XFA_EVENT_MouseUp, 5}, |
| 370 | {0xd95657a6, L"click", XFA_EVENT_Click, 4}, |
| 371 | {0xdbfbe02e, L"calculate", XFA_EVENT_Calculate, 1}, |
| 372 | {0xe25fa7b8, L"postOpen", XFA_EVENT_PostOpen, 7}, |
| 373 | {0xe28dce7e, L"enter", XFA_EVENT_Enter, 2}, |
| 374 | {0xfc82d695, L"postSave", XFA_EVENT_PostSave, 0}, |
| 375 | {0xfd54fbb7, L"postSign", XFA_EVENT_PostSign, 6}, |
| 376 | }; |
| 377 | |
| 378 | const XFA_ExecEventParaInfo* GetEventParaInfoByName( |
| 379 | const CFX_WideStringC& wsEventName) { |
| 380 | uint32_t uHash = FX_HashCode_GetW(wsEventName, false); |
| 381 | int32_t iStart = 0; |
| 382 | int32_t iEnd = (sizeof(gs_eventParaInfos) / sizeof(gs_eventParaInfos[0])) - 1; |
| 383 | do { |
| 384 | int32_t iMid = (iStart + iEnd) / 2; |
| 385 | const XFA_ExecEventParaInfo* eventParaInfo = &gs_eventParaInfos[iMid]; |
| 386 | if (uHash == eventParaInfo->m_uHash) |
| 387 | return eventParaInfo; |
| 388 | if (uHash < eventParaInfo->m_uHash) |
| 389 | iEnd = iMid - 1; |
| 390 | else |
| 391 | iStart = iMid + 1; |
| 392 | } while (iStart <= iEnd); |
| 393 | return nullptr; |
| 394 | } |
| 395 | |
| 396 | void StrToRGB(const CFX_WideString& strRGB, |
| 397 | int32_t& r, |
| 398 | int32_t& g, |
| 399 | int32_t& b) { |
| 400 | r = 0; |
| 401 | g = 0; |
| 402 | b = 0; |
| 403 | |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 404 | wchar_t zero = '0'; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 405 | int32_t iIndex = 0; |
| 406 | int32_t iLen = strRGB.GetLength(); |
| 407 | for (int32_t i = 0; i < iLen; ++i) { |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 408 | wchar_t ch = strRGB.GetAt(i); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 409 | if (ch == L',') |
| 410 | ++iIndex; |
| 411 | if (iIndex > 2) |
| 412 | break; |
| 413 | |
| 414 | int32_t iValue = ch - zero; |
| 415 | if (iValue >= 0 && iValue <= 9) { |
| 416 | switch (iIndex) { |
| 417 | case 0: |
| 418 | r = r * 10 + iValue; |
| 419 | break; |
| 420 | case 1: |
| 421 | g = g * 10 + iValue; |
| 422 | break; |
| 423 | default: |
| 424 | b = b * 10 + iValue; |
| 425 | break; |
| 426 | } |
| 427 | } |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | enum XFA_KEYTYPE { |
| 432 | XFA_KEYTYPE_Custom, |
| 433 | XFA_KEYTYPE_Element, |
| 434 | }; |
| 435 | |
| 436 | void* GetMapKey_Custom(const CFX_WideStringC& wsKey) { |
| 437 | uint32_t dwKey = FX_HashCode_GetW(wsKey, false); |
| 438 | return (void*)(uintptr_t)((dwKey << 1) | XFA_KEYTYPE_Custom); |
| 439 | } |
| 440 | |
| 441 | void* GetMapKey_Element(XFA_Element eType, XFA_ATTRIBUTE eAttribute) { |
| 442 | return (void*)(uintptr_t)((static_cast<int32_t>(eType) << 16) | |
| 443 | (eAttribute << 8) | XFA_KEYTYPE_Element); |
| 444 | } |
| 445 | |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 446 | const XFA_ATTRIBUTEINFO* GetAttributeOfElement(XFA_Element eElement, |
| 447 | XFA_ATTRIBUTE eAttribute, |
| 448 | uint32_t dwPacket) { |
| 449 | int32_t iCount = 0; |
| 450 | const uint8_t* pAttr = XFA_GetElementAttributes(eElement, iCount); |
| 451 | if (!pAttr || iCount < 1) |
| 452 | return nullptr; |
| 453 | |
| 454 | if (!std::binary_search(pAttr, pAttr + iCount, eAttribute)) |
| 455 | return nullptr; |
| 456 | |
| 457 | const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttribute); |
| 458 | ASSERT(pInfo); |
| 459 | if (dwPacket == XFA_XDPPACKET_UNKNOWN) |
| 460 | return pInfo; |
| 461 | return (dwPacket & pInfo->dwPackets) ? pInfo : nullptr; |
| 462 | } |
| 463 | |
| 464 | const XFA_ATTRIBUTEENUMINFO* GetAttributeEnumByID(XFA_ATTRIBUTEENUM eName) { |
| 465 | return g_XFAEnumData + eName; |
| 466 | } |
| 467 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 468 | } // namespace |
| 469 | |
| 470 | static void XFA_DefaultFreeData(void* pData) {} |
| 471 | |
| 472 | static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADefaultFreeData = { |
| 473 | XFA_DefaultFreeData, nullptr}; |
| 474 | |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 475 | XFA_MAPMODULEDATA::XFA_MAPMODULEDATA() {} |
| 476 | |
| 477 | XFA_MAPMODULEDATA::~XFA_MAPMODULEDATA() {} |
| 478 | |
dsinclair | b977847 | 2016-06-23 13:34:10 -0700 | [diff] [blame] | 479 | CXFA_Node::CXFA_Node(CXFA_Document* pDoc, |
| 480 | uint16_t ePacket, |
| 481 | XFA_ObjectType oType, |
dsinclair | c1df5d4 | 2016-07-18 06:36:51 -0700 | [diff] [blame] | 482 | XFA_Element eType, |
| 483 | const CFX_WideStringC& elementName) |
| 484 | : CXFA_Object(pDoc, oType, eType, elementName), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 485 | m_pNext(nullptr), |
| 486 | m_pChild(nullptr), |
| 487 | m_pLastChild(nullptr), |
| 488 | m_pParent(nullptr), |
| 489 | m_pXMLNode(nullptr), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 490 | m_ePacket(ePacket), |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 491 | m_uNodeFlags(XFA_NodeFlag_None), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 492 | m_dwNameHash(0), |
| 493 | m_pAuxNode(nullptr), |
| 494 | m_pMapModuleData(nullptr) { |
| 495 | ASSERT(m_pDocument); |
| 496 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 497 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 498 | CXFA_Node::~CXFA_Node() { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 499 | ASSERT(!m_pParent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 500 | RemoveMapModuleKey(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 501 | CXFA_Node* pNode = m_pChild; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 502 | while (pNode) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 503 | CXFA_Node* pNext = pNode->m_pNext; |
| 504 | pNode->m_pParent = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 505 | delete pNode; |
| 506 | pNode = pNext; |
| 507 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 508 | if (m_pXMLNode && IsOwnXMLNode()) |
tsepez | c757d9a | 2017-01-23 11:01:42 -0800 | [diff] [blame] | 509 | delete m_pXMLNode; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 510 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 511 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 512 | CXFA_Node* CXFA_Node::Clone(bool bRecursive) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 513 | CXFA_Node* pClone = m_pDocument->CreateNode(m_ePacket, m_elementType); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 514 | if (!pClone) |
| 515 | return nullptr; |
| 516 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 517 | MergeAllData(pClone); |
| 518 | pClone->UpdateNameHash(); |
| 519 | if (IsNeedSavingXMLNode()) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 520 | std::unique_ptr<CFX_XMLNode> pCloneXML; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 521 | if (IsAttributeInXML()) { |
| 522 | CFX_WideString wsName; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 523 | GetAttribute(XFA_ATTRIBUTE_Name, wsName, false); |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 524 | auto pCloneXMLElement = pdfium::MakeUnique<CFX_XMLElement>(wsName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 525 | CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value); |
| 526 | if (!wsValue.IsEmpty()) { |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 527 | pCloneXMLElement->SetTextData(CFX_WideString(wsValue)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 528 | } |
Dan Sinclair | 93bfc26 | 2017-04-04 15:10:00 -0400 | [diff] [blame] | 529 | pCloneXML.reset(pCloneXMLElement.release()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 530 | pClone->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown); |
| 531 | } else { |
Dan Sinclair | 93bfc26 | 2017-04-04 15:10:00 -0400 | [diff] [blame] | 532 | pCloneXML = m_pXMLNode->Clone(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 533 | } |
Dan Sinclair | 93bfc26 | 2017-04-04 15:10:00 -0400 | [diff] [blame] | 534 | pClone->SetXMLMappingNode(pCloneXML.release()); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 535 | pClone->SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 536 | } |
| 537 | if (bRecursive) { |
| 538 | for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild; |
| 539 | pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 540 | pClone->InsertChild(pChild->Clone(bRecursive)); |
| 541 | } |
| 542 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 543 | pClone->SetFlag(XFA_NodeFlag_Initialized, true); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 544 | pClone->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 545 | return pClone; |
| 546 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 547 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 548 | CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem) const { |
| 549 | switch (eItem) { |
| 550 | case XFA_NODEITEM_NextSibling: |
| 551 | return m_pNext; |
| 552 | case XFA_NODEITEM_FirstChild: |
| 553 | return m_pChild; |
| 554 | case XFA_NODEITEM_Parent: |
| 555 | return m_pParent; |
| 556 | case XFA_NODEITEM_PrevSibling: |
| 557 | if (m_pParent) { |
| 558 | CXFA_Node* pSibling = m_pParent->m_pChild; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 559 | CXFA_Node* pPrev = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 560 | while (pSibling && pSibling != this) { |
| 561 | pPrev = pSibling; |
| 562 | pSibling = pSibling->m_pNext; |
| 563 | } |
| 564 | return pPrev; |
| 565 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 566 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 567 | default: |
| 568 | break; |
| 569 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 570 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 571 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 572 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 573 | CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem, |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 574 | XFA_ObjectType eType) const { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 575 | CXFA_Node* pNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 576 | switch (eItem) { |
| 577 | case XFA_NODEITEM_NextSibling: |
| 578 | pNode = m_pNext; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 579 | while (pNode && pNode->GetObjectType() != eType) |
| 580 | pNode = pNode->m_pNext; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 581 | break; |
| 582 | case XFA_NODEITEM_FirstChild: |
| 583 | pNode = m_pChild; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 584 | while (pNode && pNode->GetObjectType() != eType) |
| 585 | pNode = pNode->m_pNext; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 586 | break; |
| 587 | case XFA_NODEITEM_Parent: |
| 588 | pNode = m_pParent; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 589 | while (pNode && pNode->GetObjectType() != eType) |
| 590 | pNode = pNode->m_pParent; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 591 | break; |
| 592 | case XFA_NODEITEM_PrevSibling: |
| 593 | if (m_pParent) { |
| 594 | CXFA_Node* pSibling = m_pParent->m_pChild; |
| 595 | while (pSibling && pSibling != this) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 596 | if (eType == pSibling->GetObjectType()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 597 | pNode = pSibling; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 598 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 599 | pSibling = pSibling->m_pNext; |
| 600 | } |
| 601 | } |
| 602 | break; |
| 603 | default: |
| 604 | break; |
| 605 | } |
| 606 | return pNode; |
| 607 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 608 | |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 609 | std::vector<CXFA_Node*> CXFA_Node::GetNodeList(uint32_t dwTypeFilter, |
| 610 | XFA_Element eTypeFilter) { |
| 611 | std::vector<CXFA_Node*> nodes; |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 612 | if (eTypeFilter != XFA_Element::Unknown) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 613 | for (CXFA_Node* pChild = m_pChild; pChild; pChild = pChild->m_pNext) { |
| 614 | if (pChild->GetElementType() == eTypeFilter) |
| 615 | nodes.push_back(pChild); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 616 | } |
| 617 | } else if (dwTypeFilter == |
| 618 | (XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties)) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 619 | for (CXFA_Node* pChild = m_pChild; pChild; pChild = pChild->m_pNext) |
| 620 | nodes.push_back(pChild); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 621 | } else if (dwTypeFilter != 0) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 622 | bool bFilterChildren = !!(dwTypeFilter & XFA_NODEFILTER_Children); |
| 623 | bool bFilterProperties = !!(dwTypeFilter & XFA_NODEFILTER_Properties); |
| 624 | bool bFilterOneOfProperties = |
| 625 | !!(dwTypeFilter & XFA_NODEFILTER_OneOfProperty); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 626 | CXFA_Node* pChild = m_pChild; |
| 627 | while (pChild) { |
| 628 | const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement( |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 629 | GetElementType(), pChild->GetElementType(), XFA_XDPPACKET_UNKNOWN); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 630 | if (pProperty) { |
| 631 | if (bFilterProperties) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 632 | nodes.push_back(pChild); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 633 | } else if (bFilterOneOfProperties && |
| 634 | (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 635 | nodes.push_back(pChild); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 636 | } else if (bFilterChildren && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 637 | (pChild->GetElementType() == XFA_Element::Variables || |
| 638 | pChild->GetElementType() == XFA_Element::PageSet)) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 639 | nodes.push_back(pChild); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 640 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 641 | } else if (bFilterChildren) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 642 | nodes.push_back(pChild); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 643 | } |
| 644 | pChild = pChild->m_pNext; |
| 645 | } |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 646 | if (bFilterOneOfProperties && nodes.empty()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 647 | int32_t iProperties = 0; |
| 648 | const XFA_PROPERTY* pProperty = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 649 | XFA_GetElementProperties(GetElementType(), iProperties); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 650 | if (!pProperty || iProperties < 1) |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 651 | return nodes; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 652 | for (int32_t i = 0; i < iProperties; i++) { |
| 653 | if (pProperty[i].uFlags & XFA_PROPERTYFLAG_DefaultOneOf) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 654 | const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(GetPacketID()); |
| 655 | CXFA_Node* pNewNode = |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 656 | m_pDocument->CreateNode(pPacket, pProperty[i].eName); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 657 | if (!pNewNode) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 658 | break; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 659 | InsertChild(pNewNode, nullptr); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 660 | pNewNode->SetFlag(XFA_NodeFlag_Initialized, true); |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 661 | nodes.push_back(pNewNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 662 | break; |
| 663 | } |
| 664 | } |
| 665 | } |
| 666 | } |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 667 | return nodes; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 668 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 669 | |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 670 | CXFA_Node* CXFA_Node::CreateSamePacketNode(XFA_Element eType, |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 671 | uint32_t dwFlags) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 672 | CXFA_Node* pNode = m_pDocument->CreateNode(m_ePacket, eType); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 673 | pNode->SetFlag(dwFlags, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 674 | return pNode; |
| 675 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 676 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 677 | CXFA_Node* CXFA_Node::CloneTemplateToForm(bool bRecursive) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 678 | ASSERT(m_ePacket == XFA_XDPPACKET_Template); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 679 | CXFA_Node* pClone = |
| 680 | m_pDocument->CreateNode(XFA_XDPPACKET_Form, m_elementType); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 681 | if (!pClone) |
| 682 | return nullptr; |
| 683 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 684 | pClone->SetTemplateNode(this); |
| 685 | pClone->UpdateNameHash(); |
| 686 | pClone->SetXMLMappingNode(GetXMLMappingNode()); |
| 687 | if (bRecursive) { |
| 688 | for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild; |
| 689 | pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 690 | pClone->InsertChild(pChild->CloneTemplateToForm(bRecursive)); |
| 691 | } |
| 692 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 693 | pClone->SetFlag(XFA_NodeFlag_Initialized, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 694 | return pClone; |
| 695 | } |
| 696 | |
| 697 | CXFA_Node* CXFA_Node::GetTemplateNode() const { |
| 698 | return m_pAuxNode; |
| 699 | } |
| 700 | |
| 701 | void CXFA_Node::SetTemplateNode(CXFA_Node* pTemplateNode) { |
| 702 | m_pAuxNode = pTemplateNode; |
| 703 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 704 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 705 | CXFA_Node* CXFA_Node::GetBindData() { |
| 706 | ASSERT(GetPacketID() == XFA_XDPPACKET_Form); |
| 707 | return static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); |
| 708 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 709 | |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 710 | std::vector<CXFA_Node*> CXFA_Node::GetBindItems() { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 711 | if (BindsFormItems()) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 712 | void* pBinding = nullptr; |
| 713 | TryObject(XFA_ATTRIBUTE_BindingNode, pBinding); |
| 714 | return *static_cast<std::vector<CXFA_Node*>*>(pBinding); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 715 | } |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 716 | std::vector<CXFA_Node*> result; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 717 | CXFA_Node* pFormNode = |
| 718 | static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 719 | if (pFormNode) |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 720 | result.push_back(pFormNode); |
| 721 | return result; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 722 | } |
| 723 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 724 | int32_t CXFA_Node::AddBindItem(CXFA_Node* pFormNode) { |
| 725 | ASSERT(pFormNode); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 726 | if (BindsFormItems()) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 727 | void* pBinding = nullptr; |
| 728 | TryObject(XFA_ATTRIBUTE_BindingNode, pBinding); |
| 729 | auto* pItems = static_cast<std::vector<CXFA_Node*>*>(pBinding); |
| 730 | if (!pdfium::ContainsValue(*pItems, pFormNode)) |
| 731 | pItems->push_back(pFormNode); |
| 732 | return pdfium::CollectionSize<int32_t>(*pItems); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 733 | } |
| 734 | CXFA_Node* pOldFormItem = |
| 735 | static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); |
| 736 | if (!pOldFormItem) { |
| 737 | SetObject(XFA_ATTRIBUTE_BindingNode, pFormNode); |
| 738 | return 1; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 739 | } |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 740 | if (pOldFormItem == pFormNode) |
| 741 | return 1; |
| 742 | |
| 743 | std::vector<CXFA_Node*>* pItems = new std::vector<CXFA_Node*>; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 744 | SetObject(XFA_ATTRIBUTE_BindingNode, pItems, &deleteBindItemCallBack); |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 745 | pItems->push_back(pOldFormItem); |
| 746 | pItems->push_back(pFormNode); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 747 | m_uNodeFlags |= XFA_NodeFlag_BindFormItems; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 748 | return 2; |
| 749 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 750 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 751 | int32_t CXFA_Node::RemoveBindItem(CXFA_Node* pFormNode) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 752 | if (BindsFormItems()) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 753 | void* pBinding = nullptr; |
| 754 | TryObject(XFA_ATTRIBUTE_BindingNode, pBinding); |
| 755 | auto* pItems = static_cast<std::vector<CXFA_Node*>*>(pBinding); |
| 756 | auto iter = std::find(pItems->begin(), pItems->end(), pFormNode); |
| 757 | if (iter != pItems->end()) { |
| 758 | *iter = pItems->back(); |
| 759 | pItems->pop_back(); |
| 760 | if (pItems->size() == 1) { |
| 761 | SetObject(XFA_ATTRIBUTE_BindingNode, |
| 762 | (*pItems)[0]); // Invalidates pItems. |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 763 | m_uNodeFlags &= ~XFA_NodeFlag_BindFormItems; |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 764 | return 1; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 765 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 766 | } |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 767 | return pdfium::CollectionSize<int32_t>(*pItems); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 768 | } |
| 769 | CXFA_Node* pOldFormItem = |
| 770 | static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 771 | if (pOldFormItem != pFormNode) |
| 772 | return pOldFormItem ? 1 : 0; |
| 773 | |
| 774 | SetObject(XFA_ATTRIBUTE_BindingNode, nullptr); |
| 775 | return 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 776 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 777 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 778 | bool CXFA_Node::HasBindItem() { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 779 | return GetPacketID() == XFA_XDPPACKET_Datasets && |
| 780 | GetObject(XFA_ATTRIBUTE_BindingNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 781 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 782 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 783 | CXFA_WidgetData* CXFA_Node::GetWidgetData() { |
| 784 | return (CXFA_WidgetData*)GetObject(XFA_ATTRIBUTE_WidgetData); |
| 785 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 786 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 787 | CXFA_WidgetData* CXFA_Node::GetContainerWidgetData() { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 788 | if (GetPacketID() != XFA_XDPPACKET_Form) |
| 789 | return nullptr; |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 790 | XFA_Element eType = GetElementType(); |
| 791 | if (eType == XFA_Element::ExclGroup) |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 792 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 793 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 794 | if (pParentNode && pParentNode->GetElementType() == XFA_Element::ExclGroup) |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 795 | return nullptr; |
| 796 | |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 797 | if (eType == XFA_Element::Field) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 798 | CXFA_WidgetData* pFieldWidgetData = GetWidgetData(); |
| 799 | if (pFieldWidgetData && |
| 800 | pFieldWidgetData->GetChoiceListOpen() == |
| 801 | XFA_ATTRIBUTEENUM_MultiSelect) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 802 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 803 | } else { |
| 804 | CFX_WideString wsPicture; |
| 805 | if (pFieldWidgetData) { |
| 806 | pFieldWidgetData->GetPictureContent(wsPicture, |
| 807 | XFA_VALUEPICTURE_DataBind); |
| 808 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 809 | if (!wsPicture.IsEmpty()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 810 | return pFieldWidgetData; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 811 | CXFA_Node* pDataNode = GetBindData(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 812 | if (!pDataNode) |
| 813 | return nullptr; |
| 814 | pFieldWidgetData = nullptr; |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 815 | for (CXFA_Node* pFormNode : pDataNode->GetBindItems()) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 816 | if (!pFormNode || pFormNode->HasRemovedChildren()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 817 | continue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 818 | pFieldWidgetData = pFormNode->GetWidgetData(); |
| 819 | if (pFieldWidgetData) { |
| 820 | pFieldWidgetData->GetPictureContent(wsPicture, |
| 821 | XFA_VALUEPICTURE_DataBind); |
| 822 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 823 | if (!wsPicture.IsEmpty()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 824 | break; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 825 | pFieldWidgetData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 826 | } |
| 827 | return pFieldWidgetData; |
| 828 | } |
| 829 | } |
| 830 | CXFA_Node* pGrandNode = |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 831 | pParentNode ? pParentNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 832 | CXFA_Node* pValueNode = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 833 | (pParentNode && pParentNode->GetElementType() == XFA_Element::Value) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 834 | ? pParentNode |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 835 | : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 836 | if (!pValueNode) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 837 | pValueNode = |
| 838 | (pGrandNode && pGrandNode->GetElementType() == XFA_Element::Value) |
| 839 | ? pGrandNode |
| 840 | : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 841 | } |
| 842 | CXFA_Node* pParentOfValueNode = |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 843 | pValueNode ? pValueNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 844 | return pParentOfValueNode ? pParentOfValueNode->GetContainerWidgetData() |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 845 | : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 846 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 847 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 848 | bool CXFA_Node::GetLocaleName(CFX_WideString& wsLocaleName) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 849 | CXFA_Node* pForm = GetDocument()->GetXFAObject(XFA_HASHCODE_Form)->AsNode(); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 850 | CXFA_Node* pTopSubform = pForm->GetFirstChildByClass(XFA_Element::Subform); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 851 | ASSERT(pTopSubform); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 852 | CXFA_Node* pLocaleNode = this; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 853 | bool bLocale = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 854 | do { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 855 | bLocale = pLocaleNode->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 856 | if (!bLocale) { |
| 857 | pLocaleNode = pLocaleNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 858 | } |
| 859 | } while (pLocaleNode && pLocaleNode != pTopSubform && !bLocale); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 860 | if (bLocale) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 861 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 862 | CXFA_Node* pConfig = ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Config)); |
| 863 | wsLocaleName = GetDocument()->GetLocalMgr()->GetConfigLocaleName(pConfig); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 864 | if (!wsLocaleName.IsEmpty()) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 865 | return true; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 866 | if (pTopSubform && |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 867 | pTopSubform->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false)) { |
| 868 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 869 | } |
| 870 | IFX_Locale* pLocale = GetDocument()->GetLocalMgr()->GetDefLocale(); |
| 871 | if (pLocale) { |
| 872 | wsLocaleName = pLocale->GetName(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 873 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 874 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 875 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 876 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 877 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 878 | XFA_ATTRIBUTEENUM CXFA_Node::GetIntact() { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 879 | CXFA_Node* pKeep = GetFirstChildByClass(XFA_Element::Keep); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 880 | XFA_ATTRIBUTEENUM eLayoutType = GetEnum(XFA_ATTRIBUTE_Layout); |
| 881 | if (pKeep) { |
| 882 | XFA_ATTRIBUTEENUM eIntact; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 883 | if (pKeep->TryEnum(XFA_ATTRIBUTE_Intact, eIntact, false)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 884 | if (eIntact == XFA_ATTRIBUTEENUM_None && |
| 885 | eLayoutType == XFA_ATTRIBUTEENUM_Row && |
| 886 | m_pDocument->GetCurVersionMode() < XFA_VERSION_208) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 887 | CXFA_Node* pPreviewRow = GetNodeItem(XFA_NODEITEM_PrevSibling, |
| 888 | XFA_ObjectType::ContainerNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 889 | if (pPreviewRow && |
| 890 | pPreviewRow->GetEnum(XFA_ATTRIBUTE_Layout) == |
| 891 | XFA_ATTRIBUTEENUM_Row) { |
| 892 | XFA_ATTRIBUTEENUM eValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 893 | if (pKeep->TryEnum(XFA_ATTRIBUTE_Previous, eValue, false) && |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 894 | (eValue == XFA_ATTRIBUTEENUM_ContentArea || |
| 895 | eValue == XFA_ATTRIBUTEENUM_PageArea)) { |
| 896 | return XFA_ATTRIBUTEENUM_ContentArea; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 897 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 898 | CXFA_Node* pNode = |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 899 | pPreviewRow->GetFirstChildByClass(XFA_Element::Keep); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 900 | if (pNode && pNode->TryEnum(XFA_ATTRIBUTE_Next, eValue, false) && |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 901 | (eValue == XFA_ATTRIBUTEENUM_ContentArea || |
| 902 | eValue == XFA_ATTRIBUTEENUM_PageArea)) { |
| 903 | return XFA_ATTRIBUTEENUM_ContentArea; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 904 | } |
| 905 | } |
| 906 | } |
| 907 | return eIntact; |
| 908 | } |
| 909 | } |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 910 | switch (GetElementType()) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 911 | case XFA_Element::Subform: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 912 | switch (eLayoutType) { |
| 913 | case XFA_ATTRIBUTEENUM_Position: |
| 914 | case XFA_ATTRIBUTEENUM_Row: |
| 915 | return XFA_ATTRIBUTEENUM_ContentArea; |
| 916 | case XFA_ATTRIBUTEENUM_Tb: |
| 917 | case XFA_ATTRIBUTEENUM_Table: |
| 918 | case XFA_ATTRIBUTEENUM_Lr_tb: |
| 919 | case XFA_ATTRIBUTEENUM_Rl_tb: |
| 920 | return XFA_ATTRIBUTEENUM_None; |
| 921 | default: |
| 922 | break; |
| 923 | } |
| 924 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 925 | case XFA_Element::Field: { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 926 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 927 | if (!pParentNode || |
| 928 | pParentNode->GetElementType() == XFA_Element::PageArea) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 929 | return XFA_ATTRIBUTEENUM_ContentArea; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 930 | if (pParentNode->GetIntact() == XFA_ATTRIBUTEENUM_None) { |
| 931 | XFA_ATTRIBUTEENUM eParLayout = |
| 932 | pParentNode->GetEnum(XFA_ATTRIBUTE_Layout); |
| 933 | if (eParLayout == XFA_ATTRIBUTEENUM_Position || |
| 934 | eParLayout == XFA_ATTRIBUTEENUM_Row || |
| 935 | eParLayout == XFA_ATTRIBUTEENUM_Table) { |
| 936 | return XFA_ATTRIBUTEENUM_None; |
| 937 | } |
| 938 | XFA_VERSION version = m_pDocument->GetCurVersionMode(); |
| 939 | if (eParLayout == XFA_ATTRIBUTEENUM_Tb && version < XFA_VERSION_208) { |
| 940 | CXFA_Measurement measureH; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 941 | if (TryMeasure(XFA_ATTRIBUTE_H, measureH, false)) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 942 | return XFA_ATTRIBUTEENUM_ContentArea; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 943 | } |
| 944 | return XFA_ATTRIBUTEENUM_None; |
| 945 | } |
| 946 | return XFA_ATTRIBUTEENUM_ContentArea; |
| 947 | } |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 948 | case XFA_Element::Draw: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 949 | return XFA_ATTRIBUTEENUM_ContentArea; |
| 950 | default: |
| 951 | break; |
| 952 | } |
| 953 | return XFA_ATTRIBUTEENUM_None; |
| 954 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 955 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 956 | CXFA_Node* CXFA_Node::GetDataDescriptionNode() { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 957 | if (m_ePacket == XFA_XDPPACKET_Datasets) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 958 | return m_pAuxNode; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 959 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 960 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 961 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 962 | void CXFA_Node::SetDataDescriptionNode(CXFA_Node* pDataDescriptionNode) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 963 | ASSERT(m_ePacket == XFA_XDPPACKET_Datasets); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 964 | m_pAuxNode = pDataDescriptionNode; |
| 965 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 966 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 967 | void CXFA_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments) { |
| 968 | int32_t iLength = pArguments->GetLength(); |
| 969 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 970 | ThrowParamCountMismatchException(L"resolveNode"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 971 | return; |
| 972 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 973 | CFX_WideString wsExpression = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 974 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 975 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 976 | if (!pScriptContext) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 977 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 978 | CXFA_Node* refNode = this; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 979 | if (refNode->GetElementType() == XFA_Element::Xfa) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 980 | refNode = ToNode(pScriptContext->GetThisObject()); |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 981 | uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 982 | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | |
| 983 | XFA_RESOLVENODE_Siblings; |
| 984 | XFA_RESOLVENODE_RS resoveNodeRS; |
tsepez | fc58ad1 | 2016-04-05 12:22:15 -0700 | [diff] [blame] | 985 | int32_t iRet = pScriptContext->ResolveObjects( |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 986 | refNode, wsExpression.AsStringC(), resoveNodeRS, dwFlag); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 987 | if (iRet < 1) { |
| 988 | pArguments->GetReturnValue()->SetNull(); |
| 989 | return; |
| 990 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 991 | if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 992 | CXFA_Object* pObject = resoveNodeRS.objects.front(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 993 | pArguments->GetReturnValue()->Assign( |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 994 | pScriptContext->GetJSValueFromMap(pObject)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 995 | } else { |
| 996 | const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = |
| 997 | resoveNodeRS.pScriptAttribute; |
| 998 | if (lpAttributeInfo && lpAttributeInfo->eValueType == XFA_SCRIPT_Object) { |
Dan Sinclair | fdf7d40 | 2017-04-18 15:25:58 -0400 | [diff] [blame] | 999 | auto pValue = |
| 1000 | pdfium::MakeUnique<CFXJSE_Value>(pScriptContext->GetRuntime()); |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 1001 | (resoveNodeRS.objects.front()->*(lpAttributeInfo->lpfnCallback))( |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1002 | pValue.get(), false, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1003 | pArguments->GetReturnValue()->Assign(pValue.get()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1004 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1005 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1006 | } |
| 1007 | } |
| 1008 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1009 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1010 | void CXFA_Node::Script_TreeClass_ResolveNodes(CFXJSE_Arguments* pArguments) { |
| 1011 | int32_t iLength = pArguments->GetLength(); |
| 1012 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1013 | ThrowParamCountMismatchException(L"resolveNodes"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1014 | return; |
| 1015 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1016 | CFX_WideString wsExpression = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1017 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1018 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1019 | if (!pValue) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1020 | return; |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1021 | uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1022 | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | |
| 1023 | XFA_RESOLVENODE_Siblings; |
| 1024 | CXFA_Node* refNode = this; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1025 | if (refNode->GetElementType() == XFA_Element::Xfa) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1026 | refNode = ToNode(m_pDocument->GetScriptContext()->GetThisObject()); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1027 | Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag, refNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1028 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1029 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1030 | void CXFA_Node::Script_Som_ResolveNodeList(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1031 | CFX_WideString wsExpression, |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1032 | uint32_t dwFlag, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1033 | CXFA_Node* refNode) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 1034 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1035 | if (!pScriptContext) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1036 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1037 | XFA_RESOLVENODE_RS resoveNodeRS; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1038 | if (!refNode) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1039 | refNode = this; |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1040 | pScriptContext->ResolveObjects(refNode, wsExpression.AsStringC(), |
tsepez | fc58ad1 | 2016-04-05 12:22:15 -0700 | [diff] [blame] | 1041 | resoveNodeRS, dwFlag); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1042 | CXFA_ArrayNodeList* pNodeList = new CXFA_ArrayNodeList(m_pDocument); |
| 1043 | if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 1044 | for (CXFA_Object* pObject : resoveNodeRS.objects) { |
| 1045 | if (pObject->IsNode()) |
| 1046 | pNodeList->Append(pObject->AsNode()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1047 | } |
| 1048 | } else { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1049 | CXFA_ValueArray valueArray(pScriptContext->GetRuntime()); |
Tom Sepez | 369fe1f | 2017-03-27 16:03:43 -0700 | [diff] [blame] | 1050 | if (resoveNodeRS.GetAttributeResult(&valueArray) > 0) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 1051 | for (CXFA_Object* pObject : valueArray.GetAttributeObject()) { |
| 1052 | if (pObject->IsNode()) |
| 1053 | pNodeList->Append(pObject->AsNode()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1054 | } |
| 1055 | } |
| 1056 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1057 | pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1058 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1059 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1060 | void CXFA_Node::Script_TreeClass_All(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1061 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1062 | XFA_ATTRIBUTE eAttribute) { |
| 1063 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1064 | ThrowInvalidPropertyException(); |
| 1065 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1066 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1067 | |
| 1068 | uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL; |
| 1069 | CFX_WideString wsName; |
| 1070 | GetAttribute(XFA_ATTRIBUTE_Name, wsName); |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 1071 | CFX_WideString wsExpression = wsName + L"[*]"; |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1072 | Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1073 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1074 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1075 | void CXFA_Node::Script_TreeClass_Nodes(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1076 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1077 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 1078 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1079 | if (!pScriptContext) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1080 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1081 | if (bSetting) { |
Dan Sinclair | c8fd331 | 2017-01-02 17:17:02 -0500 | [diff] [blame] | 1082 | CFX_WideString wsMessage = L"Unable to set "; |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 1083 | FXJSE_ThrowMessage(wsMessage.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1084 | } else { |
| 1085 | CXFA_AttachNodeList* pNodeList = new CXFA_AttachNodeList(m_pDocument, this); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1086 | pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1087 | } |
| 1088 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1089 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1090 | void CXFA_Node::Script_TreeClass_ClassAll(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1091 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1092 | XFA_ATTRIBUTE eAttribute) { |
| 1093 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1094 | ThrowInvalidPropertyException(); |
| 1095 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1096 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1097 | uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL; |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 1098 | CFX_WideString wsExpression = L"#" + GetClassName() + L"[*]"; |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1099 | Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1100 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1101 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1102 | void CXFA_Node::Script_TreeClass_Parent(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1103 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1104 | XFA_ATTRIBUTE eAttribute) { |
| 1105 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1106 | ThrowInvalidPropertyException(); |
| 1107 | return; |
| 1108 | } |
| 1109 | CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent); |
| 1110 | if (pParent) { |
| 1111 | pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pParent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1112 | } else { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1113 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1114 | } |
| 1115 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1116 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1117 | void CXFA_Node::Script_TreeClass_Index(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1118 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1119 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1120 | if (bSetting) { |
| 1121 | ThrowInvalidPropertyException(); |
| 1122 | return; |
| 1123 | } |
| 1124 | pValue->SetInteger(GetNodeSameNameIndex()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1125 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1126 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1127 | void CXFA_Node::Script_TreeClass_ClassIndex(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1128 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1129 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1130 | if (bSetting) { |
| 1131 | ThrowInvalidPropertyException(); |
| 1132 | return; |
| 1133 | } |
| 1134 | pValue->SetInteger(GetNodeSameClassIndex()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1135 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1136 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1137 | void CXFA_Node::Script_TreeClass_SomExpression(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1138 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1139 | XFA_ATTRIBUTE eAttribute) { |
| 1140 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1141 | ThrowInvalidPropertyException(); |
| 1142 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1143 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1144 | CFX_WideString wsSOMExpression; |
| 1145 | GetSOMExpression(wsSOMExpression); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 1146 | pValue->SetString(wsSOMExpression.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1147 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1148 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1149 | void CXFA_Node::Script_NodeClass_ApplyXSL(CFXJSE_Arguments* pArguments) { |
| 1150 | int32_t iLength = pArguments->GetLength(); |
| 1151 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1152 | ThrowParamCountMismatchException(L"applyXSL"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1153 | return; |
| 1154 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1155 | CFX_WideString wsExpression = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1156 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1157 | // TODO(weili): check whether we need to implement this, pdfium:501. |
| 1158 | // For now, just put the variables here to avoid unused variable warning. |
| 1159 | (void)wsExpression; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1160 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1161 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1162 | void CXFA_Node::Script_NodeClass_AssignNode(CFXJSE_Arguments* pArguments) { |
| 1163 | int32_t iLength = pArguments->GetLength(); |
| 1164 | if (iLength < 1 || iLength > 3) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1165 | ThrowParamCountMismatchException(L"assignNode"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1166 | return; |
| 1167 | } |
| 1168 | CFX_WideString wsExpression; |
| 1169 | CFX_WideString wsValue; |
| 1170 | int32_t iAction = 0; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1171 | wsExpression = |
| 1172 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1173 | if (iLength >= 2) { |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1174 | wsValue = |
| 1175 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1176 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1177 | if (iLength >= 3) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1178 | iAction = pArguments->GetInt32(2); |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1179 | // TODO(weili): check whether we need to implement this, pdfium:501. |
| 1180 | // For now, just put the variables here to avoid unused variable warning. |
| 1181 | (void)wsExpression; |
| 1182 | (void)wsValue; |
| 1183 | (void)iAction; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1184 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1185 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1186 | void CXFA_Node::Script_NodeClass_Clone(CFXJSE_Arguments* pArguments) { |
| 1187 | int32_t iLength = pArguments->GetLength(); |
| 1188 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1189 | ThrowParamCountMismatchException(L"clone"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1190 | return; |
| 1191 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1192 | bool bClone = !!pArguments->GetInt32(0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1193 | CXFA_Node* pCloneNode = Clone(bClone); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1194 | pArguments->GetReturnValue()->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1195 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pCloneNode)); |
| 1196 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1197 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1198 | void CXFA_Node::Script_NodeClass_GetAttribute(CFXJSE_Arguments* pArguments) { |
| 1199 | int32_t iLength = pArguments->GetLength(); |
| 1200 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1201 | ThrowParamCountMismatchException(L"getAttribute"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1202 | return; |
| 1203 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1204 | CFX_WideString wsExpression = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1205 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1206 | CFX_WideString wsValue; |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1207 | GetAttribute(wsExpression.AsStringC(), wsValue); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1208 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1209 | if (pValue) |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 1210 | pValue->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1211 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1212 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1213 | void CXFA_Node::Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments) { |
| 1214 | int32_t iLength = pArguments->GetLength(); |
| 1215 | if (iLength < 1 || iLength > 2) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1216 | ThrowParamCountMismatchException(L"getElement"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1217 | return; |
| 1218 | } |
| 1219 | CFX_WideString wsExpression; |
| 1220 | int32_t iValue = 0; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1221 | wsExpression = |
| 1222 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
| 1223 | if (iLength >= 2) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1224 | iValue = pArguments->GetInt32(1); |
dsinclair | 6e12478 | 2016-06-23 12:14:55 -0700 | [diff] [blame] | 1225 | CXFA_Node* pNode = |
| 1226 | GetProperty(iValue, XFA_GetElementTypeForName(wsExpression.AsStringC())); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1227 | pArguments->GetReturnValue()->Assign( |
| 1228 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1229 | } |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1230 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1231 | void CXFA_Node::Script_NodeClass_IsPropertySpecified( |
| 1232 | CFXJSE_Arguments* pArguments) { |
| 1233 | int32_t iLength = pArguments->GetLength(); |
| 1234 | if (iLength < 1 || iLength > 3) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1235 | ThrowParamCountMismatchException(L"isPropertySpecified"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1236 | return; |
| 1237 | } |
| 1238 | CFX_WideString wsExpression; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1239 | bool bParent = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1240 | int32_t iIndex = 0; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1241 | wsExpression = |
| 1242 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1243 | if (iLength >= 2) |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1244 | bParent = !!pArguments->GetInt32(1); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1245 | if (iLength >= 3) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1246 | iIndex = pArguments->GetInt32(2); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1247 | bool bHas = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1248 | const XFA_ATTRIBUTEINFO* pAttributeInfo = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1249 | XFA_GetAttributeByName(wsExpression.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1250 | CFX_WideString wsValue; |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1251 | if (pAttributeInfo) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1252 | bHas = HasAttribute(pAttributeInfo->eName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1253 | if (!bHas) { |
dsinclair | 6e12478 | 2016-06-23 12:14:55 -0700 | [diff] [blame] | 1254 | XFA_Element eType = XFA_GetElementTypeForName(wsExpression.AsStringC()); |
| 1255 | bHas = !!GetProperty(iIndex, eType); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1256 | if (!bHas && bParent && m_pParent) { |
| 1257 | // Also check on the parent. |
| 1258 | bHas = m_pParent->HasAttribute(pAttributeInfo->eName); |
| 1259 | if (!bHas) |
dsinclair | 6e12478 | 2016-06-23 12:14:55 -0700 | [diff] [blame] | 1260 | bHas = !!m_pParent->GetProperty(iIndex, eType); |
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 | } |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1263 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
| 1264 | if (pValue) |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1265 | pValue->SetBoolean(bHas); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1266 | } |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1267 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1268 | void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) { |
| 1269 | int32_t iLength = pArguments->GetLength(); |
| 1270 | if (iLength < 1 || iLength > 3) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1271 | ThrowParamCountMismatchException(L"loadXML"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1272 | return; |
| 1273 | } |
Dan Sinclair | fdf7d40 | 2017-04-18 15:25:58 -0400 | [diff] [blame] | 1274 | |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1275 | bool bIgnoreRoot = true; |
| 1276 | bool bOverwrite = 0; |
Dan Sinclair | fdf7d40 | 2017-04-18 15:25:58 -0400 | [diff] [blame] | 1277 | CFX_ByteString wsExpression = pArguments->GetUTF8String(0); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1278 | if (wsExpression.IsEmpty()) |
Tom Sepez | d3743ea | 2016-05-16 15:56:53 -0700 | [diff] [blame] | 1279 | return; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1280 | if (iLength >= 2) |
| 1281 | bIgnoreRoot = !!pArguments->GetInt32(1); |
| 1282 | if (iLength >= 3) |
| 1283 | bOverwrite = !!pArguments->GetInt32(2); |
Dan Sinclair | fdf7d40 | 2017-04-18 15:25:58 -0400 | [diff] [blame] | 1284 | auto pParser = pdfium::MakeUnique<CXFA_SimpleParser>(m_pDocument, false); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1285 | if (!pParser) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1286 | return; |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 1287 | CFX_XMLNode* pXMLNode = pParser->ParseXMLData(wsExpression, nullptr); |
Dan Sinclair | fdf7d40 | 2017-04-18 15:25:58 -0400 | [diff] [blame] | 1288 | if (!pXMLNode) |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1289 | return; |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1290 | if (bIgnoreRoot && |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 1291 | (pXMLNode->GetType() != FX_XMLNODE_Element || |
| 1292 | XFA_RecognizeRichText(static_cast<CFX_XMLElement*>(pXMLNode)))) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1293 | bIgnoreRoot = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1294 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1295 | CXFA_Node* pFakeRoot = Clone(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1296 | CFX_WideStringC wsContentType = GetCData(XFA_ATTRIBUTE_ContentType); |
| 1297 | if (!wsContentType.IsEmpty()) { |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 1298 | pFakeRoot->SetCData(XFA_ATTRIBUTE_ContentType, |
| 1299 | CFX_WideString(wsContentType)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1300 | } |
Dan Sinclair | 93bfc26 | 2017-04-04 15:10:00 -0400 | [diff] [blame] | 1301 | |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 1302 | std::unique_ptr<CFX_XMLNode> pFakeXMLRoot(pFakeRoot->GetXMLMappingNode()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1303 | if (!pFakeXMLRoot) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 1304 | CFX_XMLNode* pThisXMLRoot = GetXMLMappingNode(); |
Dan Sinclair | 93bfc26 | 2017-04-04 15:10:00 -0400 | [diff] [blame] | 1305 | pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone() : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1306 | } |
Dan Sinclair | 93bfc26 | 2017-04-04 15:10:00 -0400 | [diff] [blame] | 1307 | if (!pFakeXMLRoot) { |
| 1308 | pFakeXMLRoot = |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 1309 | pdfium::MakeUnique<CFX_XMLElement>(CFX_WideString(GetClassName())); |
Dan Sinclair | 93bfc26 | 2017-04-04 15:10:00 -0400 | [diff] [blame] | 1310 | } |
dsinclair | 017052a | 2016-06-28 07:43:51 -0700 | [diff] [blame] | 1311 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1312 | if (bIgnoreRoot) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 1313 | CFX_XMLNode* pXMLChild = pXMLNode->GetNodeItem(CFX_XMLNode::FirstChild); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1314 | while (pXMLChild) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 1315 | CFX_XMLNode* pXMLSibling = |
| 1316 | pXMLChild->GetNodeItem(CFX_XMLNode::NextSibling); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1317 | pXMLNode->RemoveChildNode(pXMLChild); |
| 1318 | pFakeXMLRoot->InsertChildNode(pXMLChild); |
| 1319 | pXMLChild = pXMLSibling; |
| 1320 | } |
| 1321 | } else { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 1322 | CFX_XMLNode* pXMLParent = pXMLNode->GetNodeItem(CFX_XMLNode::Parent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1323 | if (pXMLParent) { |
| 1324 | pXMLParent->RemoveChildNode(pXMLNode); |
| 1325 | } |
| 1326 | pFakeXMLRoot->InsertChildNode(pXMLNode); |
| 1327 | } |
Dan Sinclair | 93bfc26 | 2017-04-04 15:10:00 -0400 | [diff] [blame] | 1328 | pParser->ConstructXFANode(pFakeRoot, pFakeXMLRoot.get()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1329 | pFakeRoot = pParser->GetRootNode(); |
Dan Sinclair | 93bfc26 | 2017-04-04 15:10:00 -0400 | [diff] [blame] | 1330 | if (!pFakeRoot) |
| 1331 | return; |
| 1332 | |
| 1333 | if (bOverwrite) { |
| 1334 | CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1335 | CXFA_Node* pNewChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1336 | int32_t index = 0; |
| 1337 | while (pNewChild) { |
| 1338 | CXFA_Node* pItem = pNewChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1339 | pFakeRoot->RemoveChild(pNewChild); |
| 1340 | InsertChild(index++, pNewChild); |
| 1341 | pNewChild->SetFlag(XFA_NodeFlag_Initialized, true); |
| 1342 | pNewChild = pItem; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1343 | } |
Dan Sinclair | 93bfc26 | 2017-04-04 15:10:00 -0400 | [diff] [blame] | 1344 | while (pChild) { |
| 1345 | CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1346 | RemoveChild(pChild); |
| 1347 | pFakeRoot->InsertChild(pChild); |
| 1348 | pChild = pItem; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1349 | } |
Dan Sinclair | 93bfc26 | 2017-04-04 15:10:00 -0400 | [diff] [blame] | 1350 | if (GetPacketID() == XFA_XDPPACKET_Form && |
| 1351 | GetElementType() == XFA_Element::ExData) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 1352 | CFX_XMLNode* pTempXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 93bfc26 | 2017-04-04 15:10:00 -0400 | [diff] [blame] | 1353 | SetXMLMappingNode(pFakeXMLRoot.release()); |
| 1354 | SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 1355 | if (pTempXMLNode && !pTempXMLNode->GetNodeItem(CFX_XMLNode::Parent)) |
Dan Sinclair | 93bfc26 | 2017-04-04 15:10:00 -0400 | [diff] [blame] | 1356 | pFakeXMLRoot.reset(pTempXMLNode); |
| 1357 | else |
| 1358 | pFakeXMLRoot = nullptr; |
| 1359 | } |
| 1360 | MoveBufferMapData(pFakeRoot, this, XFA_CalcData, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1361 | } else { |
Dan Sinclair | 93bfc26 | 2017-04-04 15:10:00 -0400 | [diff] [blame] | 1362 | CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1363 | while (pChild) { |
| 1364 | CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1365 | pFakeRoot->RemoveChild(pChild); |
| 1366 | InsertChild(pChild); |
| 1367 | pChild->SetFlag(XFA_NodeFlag_Initialized, true); |
| 1368 | pChild = pItem; |
| 1369 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1370 | } |
Dan Sinclair | 93bfc26 | 2017-04-04 15:10:00 -0400 | [diff] [blame] | 1371 | if (pFakeXMLRoot) { |
| 1372 | pFakeRoot->SetXMLMappingNode(pFakeXMLRoot.release()); |
| 1373 | pFakeRoot->SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
| 1374 | } |
| 1375 | pFakeRoot->SetFlag(XFA_NodeFlag_HasRemovedChildren, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1376 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1377 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1378 | void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1379 | // TODO(weili): Check whether we need to implement this, pdfium:501. |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1380 | } |
| 1381 | |
| 1382 | void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) { |
| 1383 | int32_t iLength = pArguments->GetLength(); |
| 1384 | if (iLength < 0 || iLength > 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1385 | ThrowParamCountMismatchException(L"saveXML"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1386 | return; |
| 1387 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1388 | bool bPrettyMode = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1389 | if (iLength == 1) { |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1390 | if (pArguments->GetUTF8String(0) != "pretty") { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1391 | ThrowArgumentMismatchException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1392 | return; |
| 1393 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1394 | bPrettyMode = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1395 | } |
Dan Sinclair | 5ae8792 | 2017-04-18 11:54:04 -0400 | [diff] [blame] | 1396 | CFX_WideString bsXMLHeader = L"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1397 | if (GetPacketID() == XFA_XDPPACKET_Form || |
| 1398 | GetPacketID() == XFA_XDPPACKET_Datasets) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 1399 | CFX_XMLNode* pElement = nullptr; |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1400 | if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 1401 | pElement = GetXMLMappingNode(); |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 1402 | if (!pElement || pElement->GetType() != FX_XMLNODE_Element) { |
Dan Sinclair | 5ae8792 | 2017-04-18 11:54:04 -0400 | [diff] [blame] | 1403 | pArguments->GetReturnValue()->SetString( |
| 1404 | bsXMLHeader.UTF8Encode().AsStringC()); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1405 | return; |
| 1406 | } |
| 1407 | XFA_DataExporter_DealWithDataGroupNode(this); |
| 1408 | } |
tsepez | 833619b | 2016-12-07 09:21:17 -0800 | [diff] [blame] | 1409 | CFX_RetainPtr<IFX_MemoryStream> pMemoryStream = |
| 1410 | IFX_MemoryStream::Create(true); |
Dan Sinclair | 3b71d26 | 2017-04-19 08:58:54 -0400 | [diff] [blame] | 1411 | auto pStream = |
| 1412 | pdfium::MakeRetain<CFX_SeekableStreamProxy>(pMemoryStream, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1413 | pStream->SetCodePage(FX_CODEPAGE_UTF8); |
Dan Sinclair | 5ae8792 | 2017-04-18 11:54:04 -0400 | [diff] [blame] | 1414 | pStream->WriteString(bsXMLHeader.AsStringC()); |
| 1415 | |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1416 | if (GetPacketID() == XFA_XDPPACKET_Form) |
tsepez | 7cda31a | 2016-12-07 12:10:20 -0800 | [diff] [blame] | 1417 | XFA_DataExporter_RegenerateFormFile(this, pStream, nullptr, true); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1418 | else |
tsepez | 7cda31a | 2016-12-07 12:10:20 -0800 | [diff] [blame] | 1419 | pElement->SaveXMLNode(pStream); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1420 | // TODO(weili): Check whether we need to save pretty print XML, pdfium:501. |
| 1421 | // For now, just put it here to avoid unused variable warning. |
| 1422 | (void)bPrettyMode; |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1423 | pArguments->GetReturnValue()->SetString( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1424 | CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize())); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1425 | return; |
| 1426 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1427 | pArguments->GetReturnValue()->SetString(""); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) { |
| 1431 | int32_t iLength = pArguments->GetLength(); |
| 1432 | if (iLength != 2) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1433 | ThrowParamCountMismatchException(L"setAttribute"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1434 | return; |
| 1435 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1436 | CFX_WideString wsAttributeValue = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1437 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1438 | CFX_WideString wsAttribute = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1439 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC()); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1440 | SetAttribute(wsAttribute.AsStringC(), wsAttributeValue.AsStringC(), true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1441 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1442 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1443 | void CXFA_Node::Script_NodeClass_SetElement(CFXJSE_Arguments* pArguments) { |
| 1444 | int32_t iLength = pArguments->GetLength(); |
| 1445 | if (iLength != 1 && iLength != 2) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1446 | ThrowParamCountMismatchException(L"setElement"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1447 | return; |
| 1448 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1449 | CXFA_Node* pNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1450 | CFX_WideString wsName; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1451 | pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); |
| 1452 | if (iLength == 2) |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1453 | wsName = CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC()); |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1454 | // TODO(weili): check whether we need to implement this, pdfium:501. |
| 1455 | // For now, just put the variables here to avoid unused variable warning. |
| 1456 | (void)pNode; |
| 1457 | (void)wsName; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1458 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1459 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1460 | void CXFA_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1461 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1462 | XFA_ATTRIBUTE eAttribute) { |
| 1463 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1464 | ThrowInvalidPropertyException(); |
| 1465 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1466 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1467 | |
| 1468 | CFX_WideString wsNameSpace; |
| 1469 | TryNamespace(wsNameSpace); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 1470 | pValue->SetString(wsNameSpace.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1471 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1472 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1473 | void CXFA_Node::Script_NodeClass_Model(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1474 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1475 | XFA_ATTRIBUTE eAttribute) { |
| 1476 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1477 | ThrowInvalidPropertyException(); |
| 1478 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1479 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1480 | pValue->Assign( |
| 1481 | m_pDocument->GetScriptContext()->GetJSValueFromMap(GetModelNode())); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1482 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1483 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1484 | void CXFA_Node::Script_NodeClass_IsContainer(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1485 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1486 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1487 | if (bSetting) { |
| 1488 | ThrowInvalidPropertyException(); |
| 1489 | return; |
| 1490 | } |
| 1491 | pValue->SetBoolean(IsContainerNode()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1492 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1493 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1494 | void CXFA_Node::Script_NodeClass_IsNull(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1495 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1496 | XFA_ATTRIBUTE eAttribute) { |
| 1497 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1498 | ThrowInvalidPropertyException(); |
| 1499 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1500 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1501 | if (GetElementType() == XFA_Element::Subform) { |
| 1502 | pValue->SetBoolean(false); |
| 1503 | return; |
| 1504 | } |
| 1505 | CFX_WideString strValue; |
| 1506 | pValue->SetBoolean(!TryContent(strValue) || strValue.IsEmpty()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1507 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1508 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1509 | void CXFA_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1510 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1511 | XFA_ATTRIBUTE eAttribute) { |
| 1512 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1513 | ThrowInvalidPropertyException(); |
| 1514 | return; |
| 1515 | } |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 1516 | std::vector<CXFA_Node*> properties = |
| 1517 | GetNodeList(XFA_NODEFILTER_OneOfProperty); |
| 1518 | if (!properties.empty()) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1519 | pValue->Assign( |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 1520 | m_pDocument->GetScriptContext()->GetJSValueFromMap(properties.front())); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1521 | } |
| 1522 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1523 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1524 | void CXFA_Node::Script_ContainerClass_GetDelta(CFXJSE_Arguments* pArguments) {} |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1525 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1526 | void CXFA_Node::Script_ContainerClass_GetDeltas(CFXJSE_Arguments* pArguments) { |
| 1527 | CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1528 | pArguments->GetReturnValue()->SetObject( |
| 1529 | pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1530 | } |
| 1531 | void CXFA_Node::Script_ModelClass_ClearErrorList(CFXJSE_Arguments* pArguments) { |
| 1532 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1533 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1534 | void CXFA_Node::Script_ModelClass_CreateNode(CFXJSE_Arguments* pArguments) { |
| 1535 | Script_Template_CreateNode(pArguments); |
| 1536 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1537 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1538 | void CXFA_Node::Script_ModelClass_IsCompatibleNS(CFXJSE_Arguments* pArguments) { |
| 1539 | int32_t iLength = pArguments->GetLength(); |
| 1540 | if (iLength < 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1541 | ThrowParamCountMismatchException(L"isCompatibleNS"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1542 | return; |
| 1543 | } |
| 1544 | CFX_WideString wsNameSpace; |
| 1545 | if (iLength >= 1) { |
| 1546 | CFX_ByteString bsNameSpace = pArguments->GetUTF8String(0); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1547 | wsNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1548 | } |
| 1549 | CFX_WideString wsNodeNameSpace; |
| 1550 | TryNamespace(wsNodeNameSpace); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1551 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1552 | if (pValue) |
| 1553 | pValue->SetBoolean(wsNodeNameSpace == wsNameSpace); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1554 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1555 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1556 | void CXFA_Node::Script_ModelClass_Context(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1557 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1558 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1559 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1560 | void CXFA_Node::Script_ModelClass_AliasNode(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1561 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1562 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1563 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1564 | void CXFA_Node::Script_Attribute_Integer(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1565 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1566 | XFA_ATTRIBUTE eAttribute) { |
| 1567 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1568 | SetInteger(eAttribute, pValue->ToInteger(), true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1569 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1570 | pValue->SetInteger(GetInteger(eAttribute)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1571 | } |
| 1572 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1573 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1574 | void CXFA_Node::Script_Attribute_IntegerRead(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1575 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1576 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1577 | if (bSetting) { |
| 1578 | ThrowInvalidPropertyException(); |
| 1579 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1580 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1581 | pValue->SetInteger(GetInteger(eAttribute)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1582 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1583 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1584 | void CXFA_Node::Script_Attribute_BOOL(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1585 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1586 | XFA_ATTRIBUTE eAttribute) { |
| 1587 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1588 | SetBoolean(eAttribute, pValue->ToBoolean(), true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1589 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1590 | pValue->SetString(GetBoolean(eAttribute) ? "1" : "0"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1591 | } |
| 1592 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1593 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1594 | void CXFA_Node::Script_Attribute_BOOLRead(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1595 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1596 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1597 | if (bSetting) { |
| 1598 | ThrowInvalidPropertyException(); |
| 1599 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1600 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1601 | pValue->SetString(GetBoolean(eAttribute) ? "1" : "0"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1602 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1603 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1604 | void CXFA_Node::Script_Attribute_SendAttributeChangeMessage( |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1605 | XFA_ATTRIBUTE eAttribute, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1606 | bool bScriptModify) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1607 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1608 | if (!pLayoutPro) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1609 | return; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1610 | |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 1611 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1612 | if (!pNotify) |
| 1613 | return; |
| 1614 | |
| 1615 | uint32_t dwPacket = GetPacketID(); |
| 1616 | if (!(dwPacket & XFA_XDPPACKET_Form)) { |
| 1617 | pNotify->OnValueChanged(this, eAttribute, this, this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1618 | return; |
| 1619 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1620 | |
| 1621 | bool bNeedFindContainer = false; |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1622 | switch (GetElementType()) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1623 | case XFA_Element::Caption: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1624 | bNeedFindContainer = true; |
| 1625 | pNotify->OnValueChanged(this, eAttribute, this, |
| 1626 | GetNodeItem(XFA_NODEITEM_Parent)); |
| 1627 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1628 | case XFA_Element::Font: |
| 1629 | case XFA_Element::Para: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1630 | bNeedFindContainer = true; |
| 1631 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1632 | if (pParentNode->GetElementType() == XFA_Element::Caption) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1633 | pNotify->OnValueChanged(this, eAttribute, pParentNode, |
| 1634 | pParentNode->GetNodeItem(XFA_NODEITEM_Parent)); |
| 1635 | } else { |
| 1636 | pNotify->OnValueChanged(this, eAttribute, this, pParentNode); |
| 1637 | } |
| 1638 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1639 | case XFA_Element::Margin: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1640 | bNeedFindContainer = true; |
| 1641 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1642 | XFA_Element eParentType = pParentNode->GetElementType(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1643 | if (pParentNode->IsContainerNode()) { |
| 1644 | pNotify->OnValueChanged(this, eAttribute, this, pParentNode); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1645 | } else if (eParentType == XFA_Element::Caption) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1646 | pNotify->OnValueChanged(this, eAttribute, pParentNode, |
| 1647 | pParentNode->GetNodeItem(XFA_NODEITEM_Parent)); |
| 1648 | } else { |
| 1649 | CXFA_Node* pNode = pParentNode->GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1650 | if (pNode && pNode->GetElementType() == XFA_Element::Ui) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1651 | pNotify->OnValueChanged(this, eAttribute, pNode, |
| 1652 | pNode->GetNodeItem(XFA_NODEITEM_Parent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1653 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1654 | } |
| 1655 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1656 | case XFA_Element::Comb: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1657 | CXFA_Node* pEditNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1658 | XFA_Element eUIType = pEditNode->GetElementType(); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1659 | if (pEditNode && (eUIType == XFA_Element::DateTimeEdit || |
| 1660 | eUIType == XFA_Element::NumericEdit || |
| 1661 | eUIType == XFA_Element::TextEdit)) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1662 | CXFA_Node* pUINode = pEditNode->GetNodeItem(XFA_NODEITEM_Parent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1663 | if (pUINode) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1664 | pNotify->OnValueChanged(this, eAttribute, pUINode, |
| 1665 | pUINode->GetNodeItem(XFA_NODEITEM_Parent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1666 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1667 | } |
| 1668 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1669 | case XFA_Element::Button: |
| 1670 | case XFA_Element::Barcode: |
| 1671 | case XFA_Element::ChoiceList: |
| 1672 | case XFA_Element::DateTimeEdit: |
| 1673 | case XFA_Element::NumericEdit: |
| 1674 | case XFA_Element::PasswordEdit: |
| 1675 | case XFA_Element::TextEdit: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1676 | CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent); |
| 1677 | if (pUINode) { |
| 1678 | pNotify->OnValueChanged(this, eAttribute, pUINode, |
| 1679 | pUINode->GetNodeItem(XFA_NODEITEM_Parent)); |
| 1680 | } |
| 1681 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1682 | case XFA_Element::CheckButton: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1683 | bNeedFindContainer = true; |
| 1684 | CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent); |
| 1685 | if (pUINode) { |
| 1686 | pNotify->OnValueChanged(this, eAttribute, pUINode, |
| 1687 | pUINode->GetNodeItem(XFA_NODEITEM_Parent)); |
| 1688 | } |
| 1689 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1690 | case XFA_Element::Keep: |
| 1691 | case XFA_Element::Bookend: |
| 1692 | case XFA_Element::Break: |
| 1693 | case XFA_Element::BreakAfter: |
| 1694 | case XFA_Element::BreakBefore: |
| 1695 | case XFA_Element::Overflow: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1696 | bNeedFindContainer = true; |
| 1697 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1698 | case XFA_Element::Area: |
| 1699 | case XFA_Element::Draw: |
| 1700 | case XFA_Element::ExclGroup: |
| 1701 | case XFA_Element::Field: |
| 1702 | case XFA_Element::Subform: |
| 1703 | case XFA_Element::SubformSet: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1704 | pLayoutPro->AddChangedContainer(this); |
| 1705 | pNotify->OnValueChanged(this, eAttribute, this, this); |
| 1706 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1707 | case XFA_Element::Sharptext: |
| 1708 | case XFA_Element::Sharpxml: |
| 1709 | case XFA_Element::SharpxHTML: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1710 | CXFA_Node* pTextNode = GetNodeItem(XFA_NODEITEM_Parent); |
| 1711 | if (!pTextNode) { |
| 1712 | return; |
| 1713 | } |
| 1714 | CXFA_Node* pValueNode = pTextNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 1715 | if (!pValueNode) { |
| 1716 | return; |
| 1717 | } |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1718 | XFA_Element eType = pValueNode->GetElementType(); |
| 1719 | if (eType == XFA_Element::Value) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1720 | bNeedFindContainer = true; |
| 1721 | CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 1722 | if (pNode && pNode->IsContainerNode()) { |
| 1723 | if (bScriptModify) { |
| 1724 | pValueNode = pNode; |
| 1725 | } |
| 1726 | pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode); |
| 1727 | } else { |
| 1728 | pNotify->OnValueChanged(this, eAttribute, pNode, |
| 1729 | pNode->GetNodeItem(XFA_NODEITEM_Parent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1730 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1731 | } else { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1732 | if (eType == XFA_Element::Items) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1733 | CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 1734 | if (pNode && pNode->IsContainerNode()) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1735 | pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1736 | } |
| 1737 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1738 | } |
| 1739 | } break; |
| 1740 | default: |
| 1741 | break; |
| 1742 | } |
| 1743 | if (bNeedFindContainer) { |
| 1744 | CXFA_Node* pParent = this; |
| 1745 | while (pParent) { |
| 1746 | if (pParent->IsContainerNode()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1747 | break; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1748 | |
| 1749 | pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1750 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1751 | if (pParent) { |
| 1752 | pLayoutPro->AddChangedContainer(pParent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1753 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1754 | } |
| 1755 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1756 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1757 | void CXFA_Node::Script_Attribute_String(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1758 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1759 | XFA_ATTRIBUTE eAttribute) { |
| 1760 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1761 | CFX_WideString wsValue = pValue->ToWideString(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1762 | SetAttribute(eAttribute, wsValue.AsStringC(), true); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1763 | if (eAttribute == XFA_ATTRIBUTE_Use && |
| 1764 | GetElementType() == XFA_Element::Desc) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1765 | CXFA_Node* pTemplateNode = |
| 1766 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template)); |
| 1767 | CXFA_Node* pProtoRoot = |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1768 | pTemplateNode->GetFirstChildByClass(XFA_Element::Subform) |
| 1769 | ->GetFirstChildByClass(XFA_Element::Proto); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1770 | |
| 1771 | CFX_WideString wsID; |
| 1772 | CFX_WideString wsSOM; |
| 1773 | if (!wsValue.IsEmpty()) { |
| 1774 | if (wsValue[0] == '#') { |
| 1775 | wsID = CFX_WideString(wsValue.c_str() + 1, wsValue.GetLength() - 1); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1776 | } else { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1777 | wsSOM = wsValue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1778 | } |
| 1779 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1780 | CXFA_Node* pProtoNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1781 | if (!wsSOM.IsEmpty()) { |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1782 | uint32_t dwFlag = XFA_RESOLVENODE_Children | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1783 | XFA_RESOLVENODE_Attributes | |
| 1784 | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | |
| 1785 | XFA_RESOLVENODE_Siblings; |
| 1786 | XFA_RESOLVENODE_RS resoveNodeRS; |
| 1787 | int32_t iRet = m_pDocument->GetScriptContext()->ResolveObjects( |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1788 | pProtoRoot, wsSOM.AsStringC(), resoveNodeRS, dwFlag); |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 1789 | if (iRet > 0 && resoveNodeRS.objects.front()->IsNode()) { |
| 1790 | pProtoNode = resoveNodeRS.objects.front()->AsNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1791 | } |
| 1792 | } else if (!wsID.IsEmpty()) { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1793 | pProtoNode = m_pDocument->GetNodeByID(pProtoRoot, wsID.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1794 | } |
| 1795 | if (pProtoNode) { |
| 1796 | CXFA_Node* pHeadChild = GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1797 | while (pHeadChild) { |
| 1798 | CXFA_Node* pSibling = |
| 1799 | pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1800 | RemoveChild(pHeadChild); |
| 1801 | pHeadChild = pSibling; |
| 1802 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1803 | CXFA_Node* pProtoForm = pProtoNode->CloneTemplateToForm(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1804 | pHeadChild = pProtoForm->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1805 | while (pHeadChild) { |
| 1806 | CXFA_Node* pSibling = |
| 1807 | pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1808 | pProtoForm->RemoveChild(pHeadChild); |
| 1809 | InsertChild(pHeadChild); |
| 1810 | pHeadChild = pSibling; |
| 1811 | } |
| 1812 | m_pDocument->RemovePurgeNode(pProtoForm); |
| 1813 | delete pProtoForm; |
| 1814 | } |
| 1815 | } |
| 1816 | } else { |
| 1817 | CFX_WideString wsValue; |
| 1818 | GetAttribute(eAttribute, wsValue); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 1819 | pValue->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1820 | } |
| 1821 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1822 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1823 | void CXFA_Node::Script_Attribute_StringRead(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1824 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1825 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1826 | if (bSetting) { |
| 1827 | ThrowInvalidPropertyException(); |
| 1828 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1829 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1830 | |
| 1831 | CFX_WideString wsValue; |
| 1832 | GetAttribute(eAttribute, wsValue); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 1833 | pValue->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1834 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1835 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1836 | void CXFA_Node::Script_WsdlConnection_Execute(CFXJSE_Arguments* pArguments) { |
| 1837 | int32_t argc = pArguments->GetLength(); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1838 | if (argc != 0 && argc != 1) { |
| 1839 | ThrowParamCountMismatchException(L"execute"); |
| 1840 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1841 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1842 | pArguments->GetReturnValue()->SetBoolean(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1843 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1844 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1845 | void CXFA_Node::Script_Delta_Restore(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1846 | if (pArguments->GetLength() != 0) |
| 1847 | ThrowParamCountMismatchException(L"restore"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1848 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1849 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1850 | void CXFA_Node::Script_Delta_CurrentValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1851 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1852 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1853 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1854 | void CXFA_Node::Script_Delta_SavedValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1855 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1856 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1857 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1858 | void CXFA_Node::Script_Delta_Target(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1859 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1860 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1861 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1862 | void CXFA_Node::Script_Som_Message(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1863 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1864 | XFA_SOM_MESSAGETYPE iMessageType) { |
| 1865 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 1866 | if (!pWidgetData) { |
| 1867 | return; |
| 1868 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1869 | bool bNew = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1870 | CXFA_Validate validate = pWidgetData->GetValidate(); |
| 1871 | if (!validate) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1872 | validate = pWidgetData->GetValidate(true); |
| 1873 | bNew = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1874 | } |
| 1875 | if (bSetting) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1876 | switch (iMessageType) { |
| 1877 | case XFA_SOM_ValidationMessage: |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1878 | validate.SetScriptMessageText(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1879 | break; |
| 1880 | case XFA_SOM_FormatMessage: |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1881 | validate.SetFormatMessageText(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1882 | break; |
| 1883 | case XFA_SOM_MandatoryMessage: |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1884 | validate.SetNullMessageText(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1885 | break; |
| 1886 | default: |
| 1887 | break; |
| 1888 | } |
| 1889 | if (!bNew) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 1890 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1891 | if (!pNotify) { |
| 1892 | return; |
| 1893 | } |
| 1894 | pNotify->AddCalcValidate(this); |
| 1895 | } |
| 1896 | } else { |
| 1897 | CFX_WideString wsMessage; |
| 1898 | switch (iMessageType) { |
| 1899 | case XFA_SOM_ValidationMessage: |
| 1900 | validate.GetScriptMessageText(wsMessage); |
| 1901 | break; |
| 1902 | case XFA_SOM_FormatMessage: |
| 1903 | validate.GetFormatMessageText(wsMessage); |
| 1904 | break; |
| 1905 | case XFA_SOM_MandatoryMessage: |
| 1906 | validate.GetNullMessageText(wsMessage); |
| 1907 | break; |
| 1908 | default: |
| 1909 | break; |
| 1910 | } |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 1911 | pValue->SetString(wsMessage.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1912 | } |
| 1913 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1914 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1915 | void CXFA_Node::Script_Som_ValidationMessage(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1916 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1917 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1918 | Script_Som_Message(pValue, bSetting, XFA_SOM_ValidationMessage); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1919 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1920 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1921 | void CXFA_Node::Script_Field_Length(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1922 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1923 | XFA_ATTRIBUTE eAttribute) { |
| 1924 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1925 | ThrowInvalidPropertyException(); |
| 1926 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1927 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1928 | |
| 1929 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 1930 | if (!pWidgetData) { |
| 1931 | pValue->SetInteger(0); |
| 1932 | return; |
| 1933 | } |
| 1934 | pValue->SetInteger(pWidgetData->CountChoiceListItems(true)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1935 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1936 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1937 | void CXFA_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1938 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1939 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1940 | XFA_Element eType = GetElementType(); |
| 1941 | if (eType == XFA_Element::Field) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1942 | Script_Field_DefaultValue(pValue, bSetting, eAttribute); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1943 | return; |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1944 | } |
| 1945 | if (eType == XFA_Element::Draw) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1946 | Script_Draw_DefaultValue(pValue, bSetting, eAttribute); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1947 | return; |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1948 | } |
| 1949 | if (eType == XFA_Element::Boolean) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1950 | Script_Boolean_Value(pValue, bSetting, eAttribute); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1951 | return; |
| 1952 | } |
| 1953 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1954 | CFX_WideString wsNewValue; |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 1955 | if (!(pValue && (pValue->IsNull() || pValue->IsUndefined()))) |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1956 | wsNewValue = pValue->ToWideString(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1957 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1958 | CFX_WideString wsFormatValue(wsNewValue); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1959 | CXFA_WidgetData* pContainerWidgetData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1960 | if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1961 | CFX_WideString wsPicture; |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 1962 | for (CXFA_Node* pFormNode : GetBindItems()) { |
| 1963 | if (!pFormNode || pFormNode->HasRemovedChildren()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1964 | continue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1965 | pContainerWidgetData = pFormNode->GetContainerWidgetData(); |
| 1966 | if (pContainerWidgetData) { |
| 1967 | pContainerWidgetData->GetPictureContent(wsPicture, |
| 1968 | XFA_VALUEPICTURE_DataBind); |
| 1969 | } |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 1970 | if (!wsPicture.IsEmpty()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1971 | break; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1972 | pContainerWidgetData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1973 | } |
| 1974 | } else if (GetPacketID() == XFA_XDPPACKET_Form) { |
| 1975 | pContainerWidgetData = GetContainerWidgetData(); |
| 1976 | } |
| 1977 | if (pContainerWidgetData) { |
tsepez | 6f167c3 | 2016-04-14 15:46:27 -0700 | [diff] [blame] | 1978 | pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1979 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1980 | SetScriptContent(wsNewValue, wsFormatValue, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1981 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1982 | CFX_WideString content = GetScriptContent(true); |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1983 | if (content.IsEmpty() && eType != XFA_Element::Text && |
| 1984 | eType != XFA_Element::SubmitUrl) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1985 | pValue->SetNull(); |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1986 | } else if (eType == XFA_Element::Integer) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1987 | pValue->SetInteger(FXSYS_wtoi(content.c_str())); |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1988 | } else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1989 | CFX_Decimal decimal(content.AsStringC()); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1990 | pValue->SetFloat((float)(double)decimal); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1991 | } else { |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 1992 | pValue->SetString(content.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1993 | } |
| 1994 | } |
| 1995 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1996 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1997 | void CXFA_Node::Script_Som_DefaultValue_Read(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1998 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1999 | XFA_ATTRIBUTE eAttribute) { |
| 2000 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2001 | ThrowInvalidPropertyException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2002 | return; |
| 2003 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2004 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2005 | CFX_WideString content = GetScriptContent(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2006 | if (content.IsEmpty()) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2007 | pValue->SetNull(); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2008 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2009 | } |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2010 | pValue->SetString(content.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2011 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2012 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2013 | void CXFA_Node::Script_Boolean_Value(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2014 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2015 | XFA_ATTRIBUTE eAttribute) { |
| 2016 | if (bSetting) { |
| 2017 | CFX_ByteString newValue; |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 2018 | if (!(pValue && (pValue->IsNull() || pValue->IsUndefined()))) |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2019 | newValue = pValue->ToString(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2020 | |
tsepez | b4c9f3f | 2016-04-13 15:41:21 -0700 | [diff] [blame] | 2021 | int32_t iValue = FXSYS_atoi(newValue.c_str()); |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 2022 | CFX_WideString wsNewValue(iValue == 0 ? L"0" : L"1"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2023 | CFX_WideString wsFormatValue(wsNewValue); |
| 2024 | CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData(); |
| 2025 | if (pContainerWidgetData) { |
tsepez | 6f167c3 | 2016-04-14 15:46:27 -0700 | [diff] [blame] | 2026 | pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2027 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2028 | SetScriptContent(wsNewValue, wsFormatValue, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2029 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2030 | CFX_WideString wsValue = GetScriptContent(true); |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 2031 | pValue->SetBoolean(wsValue == L"1"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2032 | } |
| 2033 | } |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2034 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2035 | void CXFA_Node::Script_Som_BorderColor(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2036 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2037 | XFA_ATTRIBUTE eAttribute) { |
| 2038 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2039 | if (!pWidgetData) { |
| 2040 | return; |
| 2041 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2042 | CXFA_Border border = pWidgetData->GetBorder(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2043 | int32_t iSize = border.CountEdges(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2044 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2045 | int32_t r = 0; |
| 2046 | int32_t g = 0; |
| 2047 | int32_t b = 0; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2048 | StrToRGB(pValue->ToWideString(), r, g, b); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2049 | FX_ARGB rgb = ArgbEncode(100, r, g, b); |
| 2050 | for (int32_t i = 0; i < iSize; ++i) { |
| 2051 | CXFA_Edge edge = border.GetEdge(i); |
| 2052 | edge.SetColor(rgb); |
| 2053 | } |
| 2054 | } else { |
| 2055 | CXFA_Edge edge = border.GetEdge(0); |
| 2056 | FX_ARGB color = edge.GetColor(); |
| 2057 | int32_t a, r, g, b; |
| 2058 | ArgbDecode(color, a, r, g, b); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2059 | CFX_WideString strColor; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2060 | strColor.Format(L"%d,%d,%d", r, g, b); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2061 | pValue->SetString(strColor.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2062 | } |
| 2063 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2064 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2065 | void CXFA_Node::Script_Som_BorderWidth(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2066 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2067 | XFA_ATTRIBUTE eAttribute) { |
| 2068 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2069 | if (!pWidgetData) { |
| 2070 | return; |
| 2071 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2072 | CXFA_Border border = pWidgetData->GetBorder(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2073 | int32_t iSize = border.CountEdges(); |
| 2074 | CFX_WideString wsThickness; |
| 2075 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2076 | wsThickness = pValue->ToWideString(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2077 | for (int32_t i = 0; i < iSize; ++i) { |
| 2078 | CXFA_Edge edge = border.GetEdge(i); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2079 | CXFA_Measurement thickness(wsThickness.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2080 | edge.SetMSThickness(thickness); |
| 2081 | } |
| 2082 | } else { |
| 2083 | CXFA_Edge edge = border.GetEdge(0); |
| 2084 | CXFA_Measurement thickness = edge.GetMSThickness(); |
| 2085 | thickness.ToString(wsThickness); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2086 | pValue->SetString(wsThickness.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2087 | } |
| 2088 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2089 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2090 | void CXFA_Node::Script_Som_FillColor(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2091 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2092 | XFA_ATTRIBUTE eAttribute) { |
| 2093 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2094 | if (!pWidgetData) { |
| 2095 | return; |
| 2096 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2097 | CXFA_Border border = pWidgetData->GetBorder(true); |
| 2098 | CXFA_Fill borderfill = border.GetFill(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2099 | CXFA_Node* pNode = borderfill.GetNode(); |
| 2100 | if (!pNode) { |
| 2101 | return; |
| 2102 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2103 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2104 | int32_t r; |
| 2105 | int32_t g; |
| 2106 | int32_t b; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2107 | StrToRGB(pValue->ToWideString(), r, g, b); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2108 | FX_ARGB color = ArgbEncode(0xff, r, g, b); |
| 2109 | borderfill.SetColor(color); |
| 2110 | } else { |
| 2111 | FX_ARGB color = borderfill.GetColor(); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2112 | int32_t a; |
| 2113 | int32_t r; |
| 2114 | int32_t g; |
| 2115 | int32_t b; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2116 | ArgbDecode(color, a, r, g, b); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2117 | CFX_WideString wsColor; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2118 | wsColor.Format(L"%d,%d,%d", r, g, b); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2119 | pValue->SetString(wsColor.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2120 | } |
| 2121 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2122 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2123 | void CXFA_Node::Script_Som_DataNode(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2124 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2125 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2126 | if (bSetting) { |
| 2127 | ThrowInvalidPropertyException(); |
| 2128 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2129 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2130 | |
| 2131 | CXFA_Node* pDataNode = GetBindData(); |
| 2132 | if (!pDataNode) { |
| 2133 | pValue->SetNull(); |
| 2134 | return; |
| 2135 | } |
| 2136 | |
| 2137 | pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pDataNode)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2138 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2139 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2140 | void CXFA_Node::Script_Draw_DefaultValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2141 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2142 | XFA_ATTRIBUTE eAttribute) { |
| 2143 | if (bSetting) { |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 2144 | if (pValue && pValue->IsString()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2145 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 2146 | ASSERT(pWidgetData); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 2147 | XFA_Element uiType = pWidgetData->GetUIType(); |
| 2148 | if (uiType == XFA_Element::Text) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2149 | CFX_WideString wsNewValue = pValue->ToWideString(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2150 | CFX_WideString wsFormatValue(wsNewValue); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2151 | SetScriptContent(wsNewValue, wsFormatValue, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2152 | } |
| 2153 | } |
| 2154 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2155 | CFX_WideString content = GetScriptContent(true); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2156 | if (content.IsEmpty()) |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2157 | pValue->SetNull(); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2158 | else |
| 2159 | pValue->SetString(content.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2160 | } |
| 2161 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2162 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2163 | void CXFA_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2164 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2165 | XFA_ATTRIBUTE eAttribute) { |
| 2166 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2167 | if (!pWidgetData) { |
| 2168 | return; |
| 2169 | } |
| 2170 | if (bSetting) { |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 2171 | if (pValue && pValue->IsNull()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2172 | pWidgetData->m_bPreNull = pWidgetData->m_bIsNull; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2173 | pWidgetData->m_bIsNull = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2174 | } else { |
| 2175 | pWidgetData->m_bPreNull = pWidgetData->m_bIsNull; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2176 | pWidgetData->m_bIsNull = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2177 | } |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2178 | CFX_WideString wsNewText; |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 2179 | if (!(pValue && (pValue->IsNull() || pValue->IsUndefined()))) |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2180 | wsNewText = pValue->ToWideString(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2181 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2182 | CXFA_Node* pUIChild = pWidgetData->GetUIChild(); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2183 | if (pUIChild->GetElementType() == XFA_Element::NumericEdit) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2184 | int32_t iLeadDigits = 0; |
| 2185 | int32_t iFracDigits = 0; |
| 2186 | pWidgetData->GetLeadDigits(iLeadDigits); |
| 2187 | pWidgetData->GetFracDigits(iFracDigits); |
dsinclair | 44d054c | 2016-04-06 10:23:46 -0700 | [diff] [blame] | 2188 | wsNewText = |
| 2189 | pWidgetData->NumericLimit(wsNewText, iLeadDigits, iFracDigits); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2190 | } |
| 2191 | CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData(); |
| 2192 | CFX_WideString wsFormatText(wsNewText); |
| 2193 | if (pContainerWidgetData) { |
tsepez | 6f167c3 | 2016-04-14 15:46:27 -0700 | [diff] [blame] | 2194 | pContainerWidgetData->GetFormatDataValue(wsNewText, wsFormatText); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2195 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2196 | SetScriptContent(wsNewText, wsFormatText, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2197 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2198 | CFX_WideString content = GetScriptContent(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2199 | if (content.IsEmpty()) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2200 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2201 | } else { |
| 2202 | CXFA_Node* pUIChild = pWidgetData->GetUIChild(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2203 | CXFA_Value defVal = pWidgetData->GetFormValue(); |
| 2204 | CXFA_Node* pNode = defVal.GetNode()->GetNodeItem(XFA_NODEITEM_FirstChild); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2205 | if (pNode && pNode->GetElementType() == XFA_Element::Decimal) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 2206 | if (pUIChild->GetElementType() == XFA_Element::NumericEdit && |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2207 | (pNode->GetInteger(XFA_ATTRIBUTE_FracDigits) == -1)) { |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2208 | pValue->SetString(content.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2209 | } else { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2210 | CFX_Decimal decimal(content.AsStringC()); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 2211 | pValue->SetFloat((float)(double)decimal); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2212 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2213 | } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2214 | pValue->SetInteger(FXSYS_wtoi(content.c_str())); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2215 | } else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2216 | pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? false : true); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2217 | } else if (pNode && pNode->GetElementType() == XFA_Element::Float) { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2218 | CFX_Decimal decimal(content.AsStringC()); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 2219 | pValue->SetFloat((float)(double)decimal); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2220 | } else { |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2221 | pValue->SetString(content.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2222 | } |
| 2223 | } |
| 2224 | } |
| 2225 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2226 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2227 | void CXFA_Node::Script_Field_EditValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2228 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2229 | XFA_ATTRIBUTE eAttribute) { |
| 2230 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2231 | if (!pWidgetData) { |
| 2232 | return; |
| 2233 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2234 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2235 | pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Edit); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2236 | } else { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2237 | CFX_WideString wsValue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2238 | pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Edit); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2239 | pValue->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2240 | } |
| 2241 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2242 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2243 | void CXFA_Node::Script_Som_FontColor(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2244 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2245 | XFA_ATTRIBUTE eAttribute) { |
| 2246 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2247 | if (!pWidgetData) { |
| 2248 | return; |
| 2249 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2250 | CXFA_Font font = pWidgetData->GetFont(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2251 | CXFA_Node* pNode = font.GetNode(); |
| 2252 | if (!pNode) { |
| 2253 | return; |
| 2254 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2255 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2256 | int32_t r; |
| 2257 | int32_t g; |
| 2258 | int32_t b; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2259 | StrToRGB(pValue->ToWideString(), r, g, b); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2260 | FX_ARGB color = ArgbEncode(0xff, r, g, b); |
| 2261 | font.SetColor(color); |
| 2262 | } else { |
| 2263 | FX_ARGB color = font.GetColor(); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2264 | int32_t a; |
| 2265 | int32_t r; |
| 2266 | int32_t g; |
| 2267 | int32_t b; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2268 | ArgbDecode(color, a, r, g, b); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2269 | CFX_WideString wsColor; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2270 | wsColor.Format(L"%d,%d,%d", r, g, b); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2271 | pValue->SetString(wsColor.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2272 | } |
| 2273 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2274 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2275 | void CXFA_Node::Script_Field_FormatMessage(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2276 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2277 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2278 | Script_Som_Message(pValue, bSetting, XFA_SOM_FormatMessage); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2279 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2280 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2281 | void CXFA_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2282 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2283 | XFA_ATTRIBUTE eAttribute) { |
| 2284 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2285 | if (!pWidgetData) { |
| 2286 | return; |
| 2287 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2288 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2289 | pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Display); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2290 | } else { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2291 | CFX_WideString wsValue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2292 | pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Display); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2293 | pValue->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2294 | } |
| 2295 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2296 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2297 | void CXFA_Node::Script_Som_Mandatory(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2298 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2299 | XFA_ATTRIBUTE eAttribute) { |
| 2300 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2301 | if (!pWidgetData) { |
| 2302 | return; |
| 2303 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2304 | CXFA_Validate validate = pWidgetData->GetValidate(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2305 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2306 | validate.SetNullTest(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2307 | } else { |
| 2308 | int32_t iValue = validate.GetNullTest(); |
| 2309 | const XFA_ATTRIBUTEENUMINFO* pInfo = |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 2310 | GetAttributeEnumByID((XFA_ATTRIBUTEENUM)iValue); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2311 | CFX_WideString wsValue; |
| 2312 | if (pInfo) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2313 | wsValue = pInfo->pName; |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2314 | pValue->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2315 | } |
| 2316 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2317 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2318 | void CXFA_Node::Script_Som_MandatoryMessage(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2319 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2320 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2321 | Script_Som_Message(pValue, bSetting, XFA_SOM_MandatoryMessage); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2322 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2323 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2324 | void CXFA_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2325 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2326 | XFA_ATTRIBUTE eAttribute) { |
| 2327 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2328 | ThrowInvalidPropertyException(); |
| 2329 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2330 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2331 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2332 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2333 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2334 | void CXFA_Node::Script_Field_SelectedIndex(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2335 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2336 | XFA_ATTRIBUTE eAttribute) { |
| 2337 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2338 | if (!pWidgetData) { |
| 2339 | return; |
| 2340 | } |
| 2341 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2342 | int32_t iIndex = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2343 | if (iIndex == -1) { |
| 2344 | pWidgetData->ClearAllSelections(); |
| 2345 | return; |
| 2346 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2347 | pWidgetData->SetItemState(iIndex, true, true, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2348 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2349 | pValue->SetInteger(pWidgetData->GetSelectedItem()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2350 | } |
| 2351 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2352 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2353 | void CXFA_Node::Script_Field_ClearItems(CFXJSE_Arguments* pArguments) { |
| 2354 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2355 | if (!pWidgetData) { |
| 2356 | return; |
| 2357 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2358 | pWidgetData->DeleteItem(-1, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2359 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2360 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2361 | void CXFA_Node::Script_Field_ExecEvent(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2362 | if (pArguments->GetLength() != 1) { |
| 2363 | ThrowParamCountMismatchException(L"execEvent"); |
| 2364 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2365 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2366 | |
| 2367 | CFX_ByteString eventString = pArguments->GetUTF8String(0); |
| 2368 | int32_t iRet = execSingleEventByName( |
| 2369 | CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(), |
| 2370 | XFA_Element::Field); |
| 2371 | if (eventString != "validate") |
| 2372 | return; |
| 2373 | |
| 2374 | pArguments->GetReturnValue()->SetBoolean( |
| 2375 | (iRet == XFA_EVENTERROR_Error) ? false : true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2376 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2377 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2378 | void CXFA_Node::Script_Field_ExecInitialize(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2379 | if (pArguments->GetLength() != 0) { |
| 2380 | ThrowParamCountMismatchException(L"execInitialize"); |
| 2381 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2382 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2383 | |
| 2384 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2385 | if (!pNotify) |
| 2386 | return; |
| 2387 | |
| 2388 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize, false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2389 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2390 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2391 | void CXFA_Node::Script_Field_DeleteItem(CFXJSE_Arguments* pArguments) { |
| 2392 | int32_t iLength = pArguments->GetLength(); |
| 2393 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2394 | ThrowParamCountMismatchException(L"deleteItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2395 | return; |
| 2396 | } |
| 2397 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2398 | if (!pWidgetData) { |
| 2399 | return; |
| 2400 | } |
| 2401 | int32_t iIndex = pArguments->GetInt32(0); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2402 | bool bValue = pWidgetData->DeleteItem(iIndex, true, true); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2403 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2404 | if (pValue) |
| 2405 | pValue->SetBoolean(bValue); |
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_GetSaveItem(CFXJSE_Arguments* pArguments) { |
| 2409 | int32_t iLength = pArguments->GetLength(); |
| 2410 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2411 | ThrowParamCountMismatchException(L"getSaveItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2412 | return; |
| 2413 | } |
| 2414 | int32_t iIndex = pArguments->GetInt32(0); |
| 2415 | if (iIndex < 0) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2416 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2417 | return; |
| 2418 | } |
| 2419 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2420 | if (!pWidgetData) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2421 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2422 | return; |
| 2423 | } |
| 2424 | CFX_WideString wsValue; |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2425 | if (!pWidgetData->GetChoiceListItem(wsValue, iIndex, true)) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2426 | pArguments->GetReturnValue()->SetNull(); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2427 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2428 | } |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2429 | pArguments->GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2430 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2431 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2432 | void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments) { |
| 2433 | int32_t iLength = pArguments->GetLength(); |
| 2434 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2435 | ThrowParamCountMismatchException(L"boundItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2436 | return; |
| 2437 | } |
| 2438 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2439 | if (!pWidgetData) { |
| 2440 | return; |
| 2441 | } |
| 2442 | CFX_ByteString bsValue = pArguments->GetUTF8String(0); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2443 | CFX_WideString wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2444 | CFX_WideString wsBoundValue; |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2445 | pWidgetData->GetItemValue(wsValue.AsStringC(), wsBoundValue); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2446 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2447 | if (pValue) |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2448 | pValue->SetString(wsBoundValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2449 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2450 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2451 | void CXFA_Node::Script_Field_GetItemState(CFXJSE_Arguments* pArguments) { |
| 2452 | int32_t iLength = pArguments->GetLength(); |
| 2453 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2454 | ThrowParamCountMismatchException(L"getItemState"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2455 | return; |
| 2456 | } |
| 2457 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2458 | if (!pWidgetData) { |
| 2459 | return; |
| 2460 | } |
| 2461 | int32_t iIndex = pArguments->GetInt32(0); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2462 | bool bValue = pWidgetData->GetItemState(iIndex); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2463 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2464 | if (pValue) |
| 2465 | pValue->SetBoolean(bValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2466 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2467 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2468 | void CXFA_Node::Script_Field_ExecCalculate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2469 | if (pArguments->GetLength() != 0) { |
| 2470 | ThrowParamCountMismatchException(L"execCalculate"); |
| 2471 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2472 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2473 | |
| 2474 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2475 | if (!pNotify) |
| 2476 | return; |
| 2477 | |
| 2478 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate, false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2479 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2480 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2481 | void CXFA_Node::Script_Field_SetItems(CFXJSE_Arguments* pArguments) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2482 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2483 | void CXFA_Node::Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments) { |
| 2484 | int32_t iLength = pArguments->GetLength(); |
| 2485 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2486 | ThrowParamCountMismatchException(L"getDisplayItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2487 | return; |
| 2488 | } |
| 2489 | int32_t iIndex = pArguments->GetInt32(0); |
| 2490 | if (iIndex < 0) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2491 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2492 | return; |
| 2493 | } |
| 2494 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2495 | if (!pWidgetData) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2496 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2497 | return; |
| 2498 | } |
| 2499 | CFX_WideString wsValue; |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2500 | if (!pWidgetData->GetChoiceListItem(wsValue, iIndex, false)) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2501 | pArguments->GetReturnValue()->SetNull(); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2502 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2503 | } |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2504 | pArguments->GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2505 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2506 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2507 | void CXFA_Node::Script_Field_SetItemState(CFXJSE_Arguments* pArguments) { |
| 2508 | int32_t iLength = pArguments->GetLength(); |
| 2509 | if (iLength != 2) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2510 | ThrowParamCountMismatchException(L"setItemState"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2511 | return; |
| 2512 | } |
| 2513 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2514 | if (!pWidgetData) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2515 | return; |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2516 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2517 | int32_t iIndex = pArguments->GetInt32(0); |
| 2518 | if (pArguments->GetInt32(1) != 0) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2519 | pWidgetData->SetItemState(iIndex, true, true, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2520 | } else { |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2521 | if (pWidgetData->GetItemState(iIndex)) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2522 | pWidgetData->SetItemState(iIndex, false, true, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2523 | } |
| 2524 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2525 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2526 | void CXFA_Node::Script_Field_AddItem(CFXJSE_Arguments* pArguments) { |
| 2527 | int32_t iLength = pArguments->GetLength(); |
| 2528 | if (iLength < 1 || iLength > 2) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2529 | ThrowParamCountMismatchException(L"addItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2530 | return; |
| 2531 | } |
| 2532 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2533 | if (!pWidgetData) { |
| 2534 | return; |
| 2535 | } |
| 2536 | CFX_WideString wsLabel; |
| 2537 | CFX_WideString wsValue; |
| 2538 | if (iLength >= 1) { |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 2539 | CFX_ByteString bsLabel = pArguments->GetUTF8String(0); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2540 | wsLabel = CFX_WideString::FromUTF8(bsLabel.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2541 | } |
| 2542 | if (iLength >= 2) { |
| 2543 | CFX_ByteString bsValue = pArguments->GetUTF8String(1); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2544 | wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2545 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2546 | pWidgetData->InsertItem(wsLabel, wsValue, -1, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2547 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2548 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2549 | void CXFA_Node::Script_Field_ExecValidate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2550 | if (pArguments->GetLength() != 0) { |
| 2551 | ThrowParamCountMismatchException(L"execValidate"); |
| 2552 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2553 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2554 | |
| 2555 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2556 | if (!pNotify) { |
| 2557 | pArguments->GetReturnValue()->SetBoolean(false); |
| 2558 | return; |
| 2559 | } |
| 2560 | |
| 2561 | int32_t iRet = |
| 2562 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate, false, false); |
| 2563 | pArguments->GetReturnValue()->SetBoolean( |
| 2564 | (iRet == XFA_EVENTERROR_Error) ? false : true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2565 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2566 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2567 | void CXFA_Node::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2568 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2569 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2570 | if (bSetting) |
| 2571 | ThrowInvalidPropertyException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2572 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2573 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2574 | void CXFA_Node::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2575 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2576 | XFA_ATTRIBUTE eAttribute) { |
| 2577 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2578 | if (!pWidgetData) { |
| 2579 | return; |
| 2580 | } |
| 2581 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2582 | pWidgetData->SetSelectedMemberByValue(pValue->ToWideString().AsStringC(), |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2583 | true, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2584 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2585 | CFX_WideString wsValue = GetScriptContent(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2586 | XFA_VERSION curVersion = GetDocument()->GetCurVersionMode(); |
| 2587 | if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2588 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2589 | } else { |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2590 | pValue->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2591 | } |
| 2592 | } |
| 2593 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2594 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2595 | void CXFA_Node::Script_ExclGroup_Transient(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2596 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2597 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2598 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2599 | void CXFA_Node::Script_ExclGroup_ExecEvent(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2600 | if (pArguments->GetLength() != 1) { |
| 2601 | ThrowParamCountMismatchException(L"execEvent"); |
| 2602 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2603 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2604 | |
| 2605 | CFX_ByteString eventString = pArguments->GetUTF8String(0); |
| 2606 | execSingleEventByName( |
| 2607 | CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(), |
| 2608 | XFA_Element::ExclGroup); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2609 | } |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2610 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2611 | void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments) { |
| 2612 | int32_t argc = pArguments->GetLength(); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2613 | if (argc < 0 || argc > 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2614 | ThrowParamCountMismatchException(L"selectedMember"); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2615 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2616 | } |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2617 | |
| 2618 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2619 | if (!pWidgetData) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2620 | pArguments->GetReturnValue()->SetNull(); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2621 | return; |
| 2622 | } |
| 2623 | |
| 2624 | CXFA_Node* pReturnNode = nullptr; |
| 2625 | if (argc == 0) { |
| 2626 | pReturnNode = pWidgetData->GetSelectedMember(); |
| 2627 | } else { |
| 2628 | CFX_ByteString szName; |
| 2629 | szName = pArguments->GetUTF8String(0); |
| 2630 | pReturnNode = pWidgetData->SetSelectedMember( |
| 2631 | CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC(), true); |
| 2632 | } |
| 2633 | if (!pReturnNode) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2634 | pArguments->GetReturnValue()->SetNull(); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2635 | return; |
| 2636 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2637 | pArguments->GetReturnValue()->Assign( |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2638 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pReturnNode)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2639 | } |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2640 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2641 | void CXFA_Node::Script_ExclGroup_ExecInitialize(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2642 | if (pArguments->GetLength() != 0) { |
| 2643 | ThrowParamCountMismatchException(L"execInitialize"); |
| 2644 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2645 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2646 | |
| 2647 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2648 | if (!pNotify) |
| 2649 | return; |
| 2650 | |
| 2651 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2652 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2653 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2654 | void CXFA_Node::Script_ExclGroup_ExecCalculate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2655 | if (pArguments->GetLength() != 0) { |
| 2656 | ThrowParamCountMismatchException(L"execCalculate"); |
| 2657 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2658 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2659 | |
| 2660 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2661 | if (!pNotify) |
| 2662 | return; |
| 2663 | |
| 2664 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2665 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2666 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2667 | void CXFA_Node::Script_ExclGroup_ExecValidate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2668 | if (pArguments->GetLength() != 0) { |
| 2669 | ThrowParamCountMismatchException(L"execValidate"); |
| 2670 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2671 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2672 | |
| 2673 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2674 | if (!pNotify) { |
| 2675 | pArguments->GetReturnValue()->SetBoolean(false); |
| 2676 | return; |
| 2677 | } |
| 2678 | |
| 2679 | int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); |
| 2680 | pArguments->GetReturnValue()->SetBoolean( |
| 2681 | (iRet == XFA_EVENTERROR_Error) ? false : true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2682 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2683 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2684 | void CXFA_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2685 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2686 | XFA_ATTRIBUTE eAttribute) { |
| 2687 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2688 | int32_t iTo = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2689 | int32_t iFrom = Subform_and_SubformSet_InstanceIndex(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 2690 | CXFA_Node* pManagerNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2691 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; |
| 2692 | pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2693 | if (pNode->GetElementType() == XFA_Element::InstanceManager) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2694 | pManagerNode = pNode; |
| 2695 | break; |
| 2696 | } |
| 2697 | } |
| 2698 | if (pManagerNode) { |
| 2699 | pManagerNode->InstanceManager_MoveInstance(iTo, iFrom); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2700 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2701 | if (!pNotify) { |
| 2702 | return; |
| 2703 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2704 | CXFA_Node* pToInstance = GetItem(pManagerNode, iTo); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2705 | if (pToInstance && |
| 2706 | pToInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2707 | pNotify->RunSubformIndexChange(pToInstance); |
| 2708 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2709 | CXFA_Node* pFromInstance = GetItem(pManagerNode, iFrom); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 2710 | if (pFromInstance && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2711 | pFromInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2712 | pNotify->RunSubformIndexChange(pFromInstance); |
| 2713 | } |
| 2714 | } |
| 2715 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2716 | pValue->SetInteger(Subform_and_SubformSet_InstanceIndex()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2717 | } |
| 2718 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2719 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2720 | void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2721 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2722 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2723 | if (bSetting) { |
| 2724 | ThrowInvalidPropertyException(); |
| 2725 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2726 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2727 | |
| 2728 | CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name); |
| 2729 | CXFA_Node* pInstanceMgr = nullptr; |
| 2730 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; |
| 2731 | pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { |
| 2732 | if (pNode->GetElementType() == XFA_Element::InstanceManager) { |
| 2733 | CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name); |
| 2734 | if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' && |
| 2735 | wsInstMgrName.Mid(1) == wsName) { |
| 2736 | pInstanceMgr = pNode; |
| 2737 | } |
| 2738 | break; |
| 2739 | } |
| 2740 | } |
| 2741 | if (!pInstanceMgr) { |
| 2742 | pValue->SetNull(); |
| 2743 | return; |
| 2744 | } |
| 2745 | |
| 2746 | pValue->Assign( |
| 2747 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pInstanceMgr)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2748 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2749 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2750 | void CXFA_Node::Script_Subform_Locale(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2751 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2752 | XFA_ATTRIBUTE eAttribute) { |
| 2753 | if (bSetting) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2754 | SetCData(XFA_ATTRIBUTE_Locale, pValue->ToWideString(), true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2755 | } else { |
| 2756 | CFX_WideString wsLocaleName; |
| 2757 | GetLocaleName(wsLocaleName); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2758 | pValue->SetString(wsLocaleName.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2759 | } |
| 2760 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2761 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2762 | void CXFA_Node::Script_Subform_ExecEvent(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2763 | if (pArguments->GetLength() != 1) { |
| 2764 | ThrowParamCountMismatchException(L"execEvent"); |
| 2765 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2766 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2767 | |
| 2768 | CFX_ByteString eventString = pArguments->GetUTF8String(0); |
| 2769 | execSingleEventByName( |
| 2770 | CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(), |
| 2771 | XFA_Element::Subform); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2772 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2773 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2774 | void CXFA_Node::Script_Subform_ExecInitialize(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2775 | if (pArguments->GetLength() != 0) { |
| 2776 | ThrowParamCountMismatchException(L"execInitialize"); |
| 2777 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2778 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2779 | |
| 2780 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2781 | if (!pNotify) |
| 2782 | return; |
| 2783 | |
| 2784 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2785 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2786 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2787 | void CXFA_Node::Script_Subform_ExecCalculate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2788 | if (pArguments->GetLength() != 0) { |
| 2789 | ThrowParamCountMismatchException(L"execCalculate"); |
| 2790 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2791 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2792 | |
| 2793 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2794 | if (!pNotify) |
| 2795 | return; |
| 2796 | |
| 2797 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2798 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2799 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2800 | void CXFA_Node::Script_Subform_ExecValidate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2801 | if (pArguments->GetLength() != 0) { |
| 2802 | ThrowParamCountMismatchException(L"execValidate"); |
| 2803 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2804 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2805 | |
| 2806 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2807 | if (!pNotify) { |
| 2808 | pArguments->GetReturnValue()->SetBoolean(false); |
| 2809 | return; |
| 2810 | } |
| 2811 | |
| 2812 | int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); |
| 2813 | pArguments->GetReturnValue()->SetBoolean( |
| 2814 | (iRet == XFA_EVENTERROR_Error) ? false : true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2815 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2816 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2817 | void CXFA_Node::Script_Subform_GetInvalidObjects(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2818 | if (pArguments->GetLength() != 0) |
| 2819 | ThrowParamCountMismatchException(L"getInvalidObjects"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2820 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2821 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2822 | int32_t CXFA_Node::Subform_and_SubformSet_InstanceIndex() { |
| 2823 | int32_t index = 0; |
| 2824 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; |
| 2825 | pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2826 | if ((pNode->GetElementType() == XFA_Element::Subform) || |
| 2827 | (pNode->GetElementType() == XFA_Element::SubformSet)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2828 | index++; |
| 2829 | } else { |
| 2830 | break; |
| 2831 | } |
| 2832 | } |
| 2833 | return index; |
| 2834 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2835 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2836 | void CXFA_Node::Script_Template_FormNodes(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2837 | if (pArguments->GetLength() != 1) { |
| 2838 | ThrowParamCountMismatchException(L"formNodes"); |
| 2839 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2840 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2841 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2842 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2843 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2844 | void CXFA_Node::Script_Template_Remerge(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2845 | if (pArguments->GetLength() != 0) { |
| 2846 | ThrowParamCountMismatchException(L"remerge"); |
| 2847 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2848 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2849 | m_pDocument->DoDataRemerge(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2850 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2851 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2852 | void CXFA_Node::Script_Template_ExecInitialize(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2853 | if (pArguments->GetLength() != 0) { |
| 2854 | ThrowParamCountMismatchException(L"execInitialize"); |
| 2855 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2856 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2857 | |
| 2858 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2859 | if (!pWidgetData) { |
| 2860 | pArguments->GetReturnValue()->SetBoolean(false); |
| 2861 | return; |
| 2862 | } |
| 2863 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2864 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2865 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2866 | void CXFA_Node::Script_Template_CreateNode(CFXJSE_Arguments* pArguments) { |
| 2867 | int32_t argc = pArguments->GetLength(); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2868 | if (argc <= 0 || argc >= 4) { |
| 2869 | ThrowParamCountMismatchException(L"createNode"); |
| 2870 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2871 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2872 | |
| 2873 | CFX_WideString strName; |
| 2874 | CFX_WideString strNameSpace; |
| 2875 | CFX_ByteString bsTagName = pArguments->GetUTF8String(0); |
| 2876 | CFX_WideString strTagName = CFX_WideString::FromUTF8(bsTagName.AsStringC()); |
| 2877 | if (argc > 1) { |
| 2878 | CFX_ByteString bsName = pArguments->GetUTF8String(1); |
| 2879 | strName = CFX_WideString::FromUTF8(bsName.AsStringC()); |
| 2880 | if (argc == 3) { |
| 2881 | CFX_ByteString bsNameSpace = pArguments->GetUTF8String(2); |
| 2882 | strNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC()); |
| 2883 | } |
| 2884 | } |
| 2885 | |
| 2886 | XFA_Element eType = XFA_GetElementTypeForName(strTagName.AsStringC()); |
| 2887 | CXFA_Node* pNewNode = CreateSamePacketNode(eType); |
| 2888 | if (!pNewNode) { |
| 2889 | pArguments->GetReturnValue()->SetNull(); |
| 2890 | return; |
| 2891 | } |
| 2892 | |
| 2893 | if (strName.IsEmpty()) { |
| 2894 | pArguments->GetReturnValue()->Assign( |
| 2895 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode)); |
| 2896 | return; |
| 2897 | } |
| 2898 | |
| 2899 | if (!GetAttributeOfElement(eType, XFA_ATTRIBUTE_Name, |
| 2900 | XFA_XDPPACKET_UNKNOWN)) { |
| 2901 | ThrowMissingPropertyException(strTagName, L"name"); |
| 2902 | return; |
| 2903 | } |
| 2904 | |
| 2905 | pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, strName.AsStringC(), true); |
| 2906 | if (pNewNode->GetPacketID() == XFA_XDPPACKET_Datasets) |
| 2907 | pNewNode->CreateXMLMappingNode(); |
| 2908 | |
| 2909 | pArguments->GetReturnValue()->Assign( |
| 2910 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode)); |
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_Recalculate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2914 | if (pArguments->GetLength() != 1) { |
| 2915 | ThrowParamCountMismatchException(L"recalculate"); |
| 2916 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2917 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2918 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2919 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2920 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2921 | void CXFA_Node::Script_Template_ExecCalculate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2922 | if (pArguments->GetLength() != 0) { |
| 2923 | ThrowParamCountMismatchException(L"execCalculate"); |
| 2924 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2925 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2926 | |
| 2927 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2928 | if (!pWidgetData) { |
| 2929 | pArguments->GetReturnValue()->SetBoolean(false); |
| 2930 | return; |
| 2931 | } |
| 2932 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2933 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2934 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2935 | void CXFA_Node::Script_Template_ExecValidate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2936 | if (pArguments->GetLength() != 0) { |
| 2937 | ThrowParamCountMismatchException(L"execValidate"); |
| 2938 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2939 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2940 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2941 | if (!pWidgetData) { |
| 2942 | pArguments->GetReturnValue()->SetBoolean(false); |
| 2943 | return; |
| 2944 | } |
| 2945 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2946 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2947 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2948 | void CXFA_Node::Script_Manifest_Evaluate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2949 | if (pArguments->GetLength() != 0) { |
| 2950 | ThrowParamCountMismatchException(L"evaluate"); |
| 2951 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2952 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2953 | |
| 2954 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2955 | if (!pWidgetData) { |
| 2956 | pArguments->GetReturnValue()->SetBoolean(false); |
| 2957 | return; |
| 2958 | } |
| 2959 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2960 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2961 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2962 | void CXFA_Node::Script_InstanceManager_Max(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2963 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2964 | XFA_ATTRIBUTE eAttribute) { |
| 2965 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2966 | ThrowInvalidPropertyException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2967 | return; |
| 2968 | } |
| 2969 | CXFA_Occur nodeOccur(GetOccurNode()); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2970 | pValue->SetInteger(nodeOccur.GetMax()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2971 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2972 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2973 | void CXFA_Node::Script_InstanceManager_Min(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2974 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2975 | XFA_ATTRIBUTE eAttribute) { |
| 2976 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2977 | ThrowInvalidPropertyException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2978 | return; |
| 2979 | } |
| 2980 | CXFA_Occur nodeOccur(GetOccurNode()); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2981 | pValue->SetInteger(nodeOccur.GetMin()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2982 | } |
tsepez | aadedf9 | 2016-05-12 10:08:06 -0700 | [diff] [blame] | 2983 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2984 | void CXFA_Node::Script_InstanceManager_Count(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2985 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2986 | XFA_ATTRIBUTE eAttribute) { |
| 2987 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2988 | int32_t iDesired = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2989 | InstanceManager_SetInstances(iDesired); |
| 2990 | } else { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2991 | pValue->SetInteger(GetCount(this)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2992 | } |
| 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_InstanceManager_MoveInstance( |
| 2996 | CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2997 | if (pArguments->GetLength() != 2) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2998 | pArguments->GetReturnValue()->SetUndefined(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2999 | return; |
| 3000 | } |
| 3001 | int32_t iFrom = pArguments->GetInt32(0); |
| 3002 | int32_t iTo = pArguments->GetInt32(1); |
| 3003 | InstanceManager_MoveInstance(iTo, iFrom); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3004 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3005 | if (!pNotify) { |
| 3006 | return; |
| 3007 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3008 | CXFA_Node* pToInstance = GetItem(this, iTo); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3009 | if (pToInstance && pToInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3010 | pNotify->RunSubformIndexChange(pToInstance); |
| 3011 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3012 | CXFA_Node* pFromInstance = GetItem(this, iFrom); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3013 | if (pFromInstance && |
| 3014 | pFromInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3015 | pNotify->RunSubformIndexChange(pFromInstance); |
| 3016 | } |
| 3017 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3018 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3019 | void CXFA_Node::Script_InstanceManager_RemoveInstance( |
| 3020 | CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3021 | if (pArguments->GetLength() != 1) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3022 | pArguments->GetReturnValue()->SetUndefined(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3023 | return; |
| 3024 | } |
| 3025 | int32_t iIndex = pArguments->GetInt32(0); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3026 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3027 | if (iIndex < 0 || iIndex >= iCount) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3028 | ThrowIndexOutOfBoundsException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3029 | return; |
| 3030 | } |
| 3031 | CXFA_Occur nodeOccur(GetOccurNode()); |
| 3032 | int32_t iMin = nodeOccur.GetMin(); |
| 3033 | if (iCount - 1 < iMin) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3034 | ThrowTooManyOccurancesException(L"min"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3035 | return; |
| 3036 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3037 | CXFA_Node* pRemoveInstance = GetItem(this, iIndex); |
| 3038 | RemoveItem(this, pRemoveInstance); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3039 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3040 | if (pNotify) { |
| 3041 | for (int32_t i = iIndex; i < iCount - 1; i++) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3042 | CXFA_Node* pSubformInstance = GetItem(this, i); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3043 | if (pSubformInstance && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3044 | pSubformInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3045 | pNotify->RunSubformIndexChange(pSubformInstance); |
| 3046 | } |
| 3047 | } |
| 3048 | } |
| 3049 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3050 | if (!pLayoutPro) { |
| 3051 | return; |
| 3052 | } |
| 3053 | pLayoutPro->AddChangedContainer( |
| 3054 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3055 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3056 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3057 | void CXFA_Node::Script_InstanceManager_SetInstances( |
| 3058 | CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3059 | if (pArguments->GetLength() != 1) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3060 | pArguments->GetReturnValue()->SetUndefined(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3061 | return; |
| 3062 | } |
| 3063 | int32_t iDesired = pArguments->GetInt32(0); |
| 3064 | InstanceManager_SetInstances(iDesired); |
| 3065 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3066 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3067 | void CXFA_Node::Script_InstanceManager_AddInstance( |
| 3068 | CFXJSE_Arguments* pArguments) { |
| 3069 | int32_t argc = pArguments->GetLength(); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3070 | if (argc != 0 && argc != 1) { |
| 3071 | ThrowParamCountMismatchException(L"addInstance"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3072 | return; |
| 3073 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3074 | bool fFlags = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3075 | if (argc == 1) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3076 | fFlags = pArguments->GetInt32(0) == 0 ? false : true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3077 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3078 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3079 | CXFA_Occur nodeOccur(GetOccurNode()); |
| 3080 | int32_t iMax = nodeOccur.GetMax(); |
| 3081 | if (iMax >= 0 && iCount >= iMax) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3082 | ThrowTooManyOccurancesException(L"max"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3083 | return; |
| 3084 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3085 | CXFA_Node* pNewInstance = CreateInstance(this, fFlags); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3086 | InsertItem(this, pNewInstance, iCount, iCount, false); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3087 | pArguments->GetReturnValue()->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3088 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance)); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3089 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3090 | if (!pNotify) { |
| 3091 | return; |
| 3092 | } |
| 3093 | pNotify->RunNodeInitialize(pNewInstance); |
| 3094 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3095 | if (!pLayoutPro) { |
| 3096 | return; |
| 3097 | } |
| 3098 | pLayoutPro->AddChangedContainer( |
| 3099 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3100 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3101 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3102 | void CXFA_Node::Script_InstanceManager_InsertInstance( |
| 3103 | CFXJSE_Arguments* pArguments) { |
| 3104 | int32_t argc = pArguments->GetLength(); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3105 | if (argc != 1 && argc != 2) { |
| 3106 | ThrowParamCountMismatchException(L"insertInstance"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3107 | return; |
| 3108 | } |
| 3109 | int32_t iIndex = pArguments->GetInt32(0); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3110 | bool bBind = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3111 | if (argc == 2) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3112 | bBind = pArguments->GetInt32(1) == 0 ? false : true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3113 | } |
| 3114 | CXFA_Occur nodeOccur(GetOccurNode()); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3115 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3116 | if (iIndex < 0 || iIndex > iCount) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3117 | ThrowIndexOutOfBoundsException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3118 | return; |
| 3119 | } |
| 3120 | int32_t iMax = nodeOccur.GetMax(); |
| 3121 | if (iMax >= 0 && iCount >= iMax) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3122 | ThrowTooManyOccurancesException(L"max"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3123 | return; |
| 3124 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3125 | CXFA_Node* pNewInstance = CreateInstance(this, bBind); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3126 | InsertItem(this, pNewInstance, iIndex, iCount, true); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3127 | pArguments->GetReturnValue()->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3128 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance)); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3129 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3130 | if (!pNotify) { |
| 3131 | return; |
| 3132 | } |
| 3133 | pNotify->RunNodeInitialize(pNewInstance); |
| 3134 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3135 | if (!pLayoutPro) { |
| 3136 | return; |
| 3137 | } |
| 3138 | pLayoutPro->AddChangedContainer( |
| 3139 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3140 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3141 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3142 | int32_t CXFA_Node::InstanceManager_SetInstances(int32_t iDesired) { |
| 3143 | CXFA_Occur nodeOccur(GetOccurNode()); |
| 3144 | int32_t iMax = nodeOccur.GetMax(); |
| 3145 | int32_t iMin = nodeOccur.GetMin(); |
| 3146 | if (iDesired < iMin) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3147 | ThrowTooManyOccurancesException(L"min"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3148 | return 1; |
| 3149 | } |
| 3150 | if ((iMax >= 0) && (iDesired > iMax)) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3151 | ThrowTooManyOccurancesException(L"max"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3152 | return 2; |
| 3153 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3154 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3155 | if (iDesired == iCount) { |
| 3156 | return 0; |
| 3157 | } |
| 3158 | if (iDesired < iCount) { |
| 3159 | CFX_WideStringC wsInstManagerName = GetCData(XFA_ATTRIBUTE_Name); |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3160 | CFX_WideString wsInstanceName = |
| 3161 | CFX_WideString(wsInstManagerName.IsEmpty() ? wsInstManagerName |
| 3162 | : wsInstManagerName.Mid(1)); |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 3163 | uint32_t dInstanceNameHash = |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 3164 | FX_HashCode_GetW(wsInstanceName.AsStringC(), false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3165 | CXFA_Node* pPrevSibling = |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3166 | (iDesired == 0) ? this : GetItem(this, iDesired - 1); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3167 | while (iCount > iDesired) { |
| 3168 | CXFA_Node* pRemoveInstance = |
| 3169 | pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3170 | if (pRemoveInstance->GetElementType() != XFA_Element::Subform && |
| 3171 | pRemoveInstance->GetElementType() != XFA_Element::SubformSet) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3172 | continue; |
| 3173 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3174 | if (pRemoveInstance->GetElementType() == XFA_Element::InstanceManager) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3175 | ASSERT(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3176 | break; |
| 3177 | } |
| 3178 | if (pRemoveInstance->GetNameHash() == dInstanceNameHash) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3179 | RemoveItem(this, pRemoveInstance); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3180 | iCount--; |
| 3181 | } |
| 3182 | } |
| 3183 | } else if (iDesired > iCount) { |
| 3184 | while (iCount < iDesired) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3185 | CXFA_Node* pNewInstance = CreateInstance(this, true); |
| 3186 | InsertItem(this, pNewInstance, iCount, iCount, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3187 | iCount++; |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3188 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3189 | if (!pNotify) { |
| 3190 | return 0; |
| 3191 | } |
| 3192 | pNotify->RunNodeInitialize(pNewInstance); |
| 3193 | } |
| 3194 | } |
| 3195 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3196 | if (pLayoutPro) { |
| 3197 | pLayoutPro->AddChangedContainer( |
| 3198 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3199 | } |
| 3200 | return 0; |
| 3201 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3202 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3203 | int32_t CXFA_Node::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3204 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3205 | if (iFrom > iCount || iTo > iCount - 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3206 | ThrowIndexOutOfBoundsException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3207 | return 1; |
| 3208 | } |
| 3209 | if (iFrom < 0 || iTo < 0 || iFrom == iTo) { |
| 3210 | return 0; |
| 3211 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3212 | CXFA_Node* pMoveInstance = GetItem(this, iFrom); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3213 | RemoveItem(this, pMoveInstance, false); |
| 3214 | InsertItem(this, pMoveInstance, iTo, iCount - 1, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3215 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3216 | if (pLayoutPro) { |
| 3217 | pLayoutPro->AddChangedContainer( |
| 3218 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3219 | } |
| 3220 | return 0; |
| 3221 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3222 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3223 | void CXFA_Node::Script_Occur_Max(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3224 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3225 | XFA_ATTRIBUTE eAttribute) { |
| 3226 | CXFA_Occur occur(this); |
| 3227 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3228 | int32_t iMax = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3229 | occur.SetMax(iMax); |
| 3230 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3231 | pValue->SetInteger(occur.GetMax()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3232 | } |
| 3233 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3234 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3235 | void CXFA_Node::Script_Occur_Min(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3236 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3237 | XFA_ATTRIBUTE eAttribute) { |
| 3238 | CXFA_Occur occur(this); |
| 3239 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3240 | int32_t iMin = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3241 | occur.SetMin(iMin); |
| 3242 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3243 | pValue->SetInteger(occur.GetMin()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3244 | } |
| 3245 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3246 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3247 | void CXFA_Node::Script_Desc_Metadata(CFXJSE_Arguments* pArguments) { |
| 3248 | int32_t argc = pArguments->GetLength(); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3249 | if (argc != 0 && argc != 1) { |
| 3250 | ThrowParamCountMismatchException(L"metadata"); |
| 3251 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3252 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3253 | pArguments->GetReturnValue()->SetString(""); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3254 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3255 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3256 | void CXFA_Node::Script_Form_FormNodes(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3257 | if (pArguments->GetLength() != 1) { |
| 3258 | ThrowParamCountMismatchException(L"formNodes"); |
| 3259 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3260 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3261 | |
| 3262 | CXFA_Node* pDataNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); |
| 3263 | if (!pDataNode) { |
| 3264 | ThrowArgumentMismatchException(); |
| 3265 | return; |
| 3266 | } |
| 3267 | |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 3268 | std::vector<CXFA_Node*> formItems; |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3269 | CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument); |
| 3270 | pFormNodes->SetArrayNodeList(formItems); |
| 3271 | pArguments->GetReturnValue()->SetObject( |
| 3272 | pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3273 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3274 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3275 | void CXFA_Node::Script_Form_Remerge(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3276 | if (pArguments->GetLength() != 0) { |
| 3277 | ThrowParamCountMismatchException(L"remerge"); |
| 3278 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3279 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3280 | |
| 3281 | m_pDocument->DoDataRemerge(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3282 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3283 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3284 | void CXFA_Node::Script_Form_ExecInitialize(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3285 | if (pArguments->GetLength() != 0) { |
| 3286 | ThrowParamCountMismatchException(L"execInitialize"); |
| 3287 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3288 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3289 | |
| 3290 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 3291 | if (!pNotify) |
| 3292 | return; |
| 3293 | |
| 3294 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3295 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3296 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3297 | void CXFA_Node::Script_Form_Recalculate(CFXJSE_Arguments* pArguments) { |
| 3298 | CXFA_EventParam* pEventParam = |
| 3299 | m_pDocument->GetScriptContext()->GetEventParam(); |
| 3300 | if (pEventParam->m_eType == XFA_EVENT_Calculate || |
| 3301 | pEventParam->m_eType == XFA_EVENT_InitCalculate) { |
| 3302 | return; |
| 3303 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3304 | if (pArguments->GetLength() != 1) { |
| 3305 | ThrowParamCountMismatchException(L"recalculate"); |
| 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_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 3310 | if (!pNotify) |
| 3311 | return; |
| 3312 | if (pArguments->GetInt32(0) != 0) |
| 3313 | return; |
| 3314 | |
| 3315 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); |
| 3316 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); |
| 3317 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Ready, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3318 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3319 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3320 | void CXFA_Node::Script_Form_ExecCalculate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3321 | if (pArguments->GetLength() != 0) { |
| 3322 | ThrowParamCountMismatchException(L"execCalculate"); |
| 3323 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3324 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3325 | |
| 3326 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 3327 | if (!pNotify) |
| 3328 | return; |
| 3329 | |
| 3330 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3331 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3332 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3333 | void CXFA_Node::Script_Form_ExecValidate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3334 | if (pArguments->GetLength() != 0) { |
| 3335 | ThrowParamCountMismatchException(L"execValidate"); |
| 3336 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3337 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3338 | |
| 3339 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 3340 | if (!pNotify) { |
| 3341 | pArguments->GetReturnValue()->SetBoolean(false); |
| 3342 | return; |
| 3343 | } |
| 3344 | |
| 3345 | int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); |
| 3346 | pArguments->GetReturnValue()->SetBoolean( |
| 3347 | (iRet == XFA_EVENTERROR_Error) ? false : true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3348 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3349 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3350 | void CXFA_Node::Script_Form_Checksum(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3351 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3352 | XFA_ATTRIBUTE eAttribute) { |
| 3353 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 3354 | SetAttribute(XFA_ATTRIBUTE_Checksum, pValue->ToWideString().AsStringC()); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3355 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3356 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3357 | CFX_WideString wsChecksum; |
| 3358 | GetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum, false); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 3359 | pValue->SetString(wsChecksum.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3360 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3361 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3362 | void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3363 | if (pArguments->GetLength() != 1) { |
| 3364 | ThrowParamCountMismatchException(L"getAttribute"); |
| 3365 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3366 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3367 | CFX_ByteString bsAttributeName = pArguments->GetUTF8String(0); |
| 3368 | CFX_WideString wsAttributeValue; |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3369 | CFX_XMLNode* pXMLNode = GetXMLMappingNode(); |
| 3370 | if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) { |
| 3371 | wsAttributeValue = static_cast<CFX_XMLElement*>(pXMLNode)->GetString( |
Dan Sinclair | 5fa4e98 | 2017-04-05 11:48:21 -0400 | [diff] [blame] | 3372 | CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str()); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3373 | } |
| 3374 | pArguments->GetReturnValue()->SetString( |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 3375 | wsAttributeValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3376 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3377 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3378 | void CXFA_Node::Script_Packet_SetAttribute(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3379 | if (pArguments->GetLength() != 2) { |
| 3380 | ThrowParamCountMismatchException(L"setAttribute"); |
| 3381 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3382 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3383 | CFX_ByteString bsValue = pArguments->GetUTF8String(0); |
| 3384 | CFX_ByteString bsName = pArguments->GetUTF8String(1); |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3385 | CFX_XMLNode* pXMLNode = GetXMLMappingNode(); |
| 3386 | if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) { |
| 3387 | static_cast<CFX_XMLElement*>(pXMLNode)->SetString( |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3388 | CFX_WideString::FromUTF8(bsName.AsStringC()), |
| 3389 | CFX_WideString::FromUTF8(bsValue.AsStringC())); |
| 3390 | } |
| 3391 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3392 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3393 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3394 | void CXFA_Node::Script_Packet_RemoveAttribute(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3395 | if (pArguments->GetLength() != 1) { |
| 3396 | ThrowParamCountMismatchException(L"removeAttribute"); |
| 3397 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3398 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3399 | |
| 3400 | CFX_ByteString bsName = pArguments->GetUTF8String(0); |
| 3401 | CFX_WideString wsName = CFX_WideString::FromUTF8(bsName.AsStringC()); |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3402 | CFX_XMLNode* pXMLNode = GetXMLMappingNode(); |
| 3403 | if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) { |
| 3404 | CFX_XMLElement* pXMLElement = static_cast<CFX_XMLElement*>(pXMLNode); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3405 | if (pXMLElement->HasAttribute(wsName.c_str())) { |
| 3406 | pXMLElement->RemoveAttribute(wsName.c_str()); |
| 3407 | } |
| 3408 | } |
| 3409 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3410 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3411 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3412 | void CXFA_Node::Script_Packet_Content(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3413 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3414 | XFA_ATTRIBUTE eAttribute) { |
| 3415 | if (bSetting) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3416 | CFX_XMLNode* pXMLNode = GetXMLMappingNode(); |
| 3417 | if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) { |
| 3418 | CFX_XMLElement* pXMLElement = static_cast<CFX_XMLElement*>(pXMLNode); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 3419 | pXMLElement->SetTextData(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3420 | } |
| 3421 | } else { |
| 3422 | CFX_WideString wsTextData; |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3423 | CFX_XMLNode* pXMLNode = GetXMLMappingNode(); |
| 3424 | if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) { |
| 3425 | CFX_XMLElement* pXMLElement = static_cast<CFX_XMLElement*>(pXMLNode); |
Dan Sinclair | 5fa4e98 | 2017-04-05 11:48:21 -0400 | [diff] [blame] | 3426 | wsTextData = pXMLElement->GetTextData(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3427 | } |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 3428 | pValue->SetString(wsTextData.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3429 | } |
| 3430 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3431 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3432 | void CXFA_Node::Script_Source_Next(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3433 | if (pArguments->GetLength() != 0) |
| 3434 | ThrowParamCountMismatchException(L"next"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3435 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3436 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3437 | void CXFA_Node::Script_Source_CancelBatch(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3438 | if (pArguments->GetLength() != 0) |
| 3439 | ThrowParamCountMismatchException(L"cancelBatch"); |
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_Source_First(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3443 | if (pArguments->GetLength() != 0) |
| 3444 | ThrowParamCountMismatchException(L"first"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3445 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3446 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3447 | void CXFA_Node::Script_Source_UpdateBatch(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3448 | if (pArguments->GetLength() != 0) |
| 3449 | ThrowParamCountMismatchException(L"updateBatch"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3450 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3451 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3452 | void CXFA_Node::Script_Source_Previous(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3453 | if (pArguments->GetLength() != 0) |
| 3454 | ThrowParamCountMismatchException(L"previous"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3455 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3456 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3457 | void CXFA_Node::Script_Source_IsBOF(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3458 | if (pArguments->GetLength() != 0) |
| 3459 | ThrowParamCountMismatchException(L"isBOF"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3460 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3461 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3462 | void CXFA_Node::Script_Source_IsEOF(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3463 | if (pArguments->GetLength() != 0) |
| 3464 | ThrowParamCountMismatchException(L"isEOF"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3465 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3466 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3467 | void CXFA_Node::Script_Source_Cancel(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3468 | if (pArguments->GetLength() != 0) |
| 3469 | ThrowParamCountMismatchException(L"cancel"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3470 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3471 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3472 | void CXFA_Node::Script_Source_Update(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3473 | if (pArguments->GetLength() != 0) |
| 3474 | ThrowParamCountMismatchException(L"update"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3475 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3476 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3477 | void CXFA_Node::Script_Source_Open(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3478 | if (pArguments->GetLength() != 0) |
| 3479 | ThrowParamCountMismatchException(L"open"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3480 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3481 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3482 | void CXFA_Node::Script_Source_Delete(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3483 | if (pArguments->GetLength() != 0) |
| 3484 | ThrowParamCountMismatchException(L"delete"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3485 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3486 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3487 | void CXFA_Node::Script_Source_AddNew(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3488 | if (pArguments->GetLength() != 0) |
| 3489 | ThrowParamCountMismatchException(L"addNew"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3490 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3491 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3492 | void CXFA_Node::Script_Source_Requery(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3493 | if (pArguments->GetLength() != 0) |
| 3494 | ThrowParamCountMismatchException(L"requery"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3495 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3496 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3497 | void CXFA_Node::Script_Source_Resync(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3498 | if (pArguments->GetLength() != 0) |
| 3499 | ThrowParamCountMismatchException(L"resync"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3500 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3501 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3502 | void CXFA_Node::Script_Source_Close(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3503 | if (pArguments->GetLength() != 0) |
| 3504 | ThrowParamCountMismatchException(L"close"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3505 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3506 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3507 | void CXFA_Node::Script_Source_Last(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3508 | if (pArguments->GetLength() != 0) |
| 3509 | ThrowParamCountMismatchException(L"last"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3510 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3511 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3512 | void CXFA_Node::Script_Source_HasDataChanged(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3513 | if (pArguments->GetLength() != 0) |
| 3514 | ThrowParamCountMismatchException(L"hasDataChanged"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3515 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3516 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3517 | void CXFA_Node::Script_Source_Db(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3518 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3519 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3520 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3521 | void CXFA_Node::Script_Xfa_This(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3522 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3523 | XFA_ATTRIBUTE eAttribute) { |
| 3524 | if (!bSetting) { |
| 3525 | CXFA_Object* pThis = m_pDocument->GetScriptContext()->GetThisObject(); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 3526 | ASSERT(pThis); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3527 | pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pThis)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3528 | } |
| 3529 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3530 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3531 | void CXFA_Node::Script_Handler_Version(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3532 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3533 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3534 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3535 | void CXFA_Node::Script_SubmitFormat_Mode(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3536 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3537 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3538 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3539 | void CXFA_Node::Script_Extras_Type(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3540 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3541 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3542 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3543 | void CXFA_Node::Script_Script_Stateless(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3544 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3545 | XFA_ATTRIBUTE eAttribute) { |
| 3546 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3547 | ThrowInvalidPropertyException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3548 | return; |
| 3549 | } |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 3550 | pValue->SetString(FX_UTF8Encode(CFX_WideStringC(L"0", 1)).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3551 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3552 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3553 | void CXFA_Node::Script_Encrypt_Format(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3554 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3555 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3556 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3557 | bool CXFA_Node::HasAttribute(XFA_ATTRIBUTE eAttr, bool bCanInherit) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3558 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3559 | return HasMapModuleKey(pKey, bCanInherit); |
| 3560 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3561 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3562 | bool CXFA_Node::SetAttribute(XFA_ATTRIBUTE eAttr, |
| 3563 | const CFX_WideStringC& wsValue, |
| 3564 | bool bNotify) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3565 | const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3566 | if (!pAttr) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3567 | return false; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3568 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3569 | XFA_ATTRIBUTETYPE eType = pAttr->eType; |
| 3570 | if (eType == XFA_ATTRIBUTETYPE_NOTSURE) { |
| 3571 | const XFA_NOTSUREATTRIBUTE* pNotsure = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3572 | XFA_GetNotsureAttribute(GetElementType(), pAttr->eName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3573 | eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata; |
| 3574 | } |
| 3575 | switch (eType) { |
| 3576 | case XFA_ATTRIBUTETYPE_Enum: { |
| 3577 | const XFA_ATTRIBUTEENUMINFO* pEnum = XFA_GetAttributeEnumByName(wsValue); |
| 3578 | return SetEnum(pAttr->eName, |
| 3579 | pEnum ? pEnum->eName |
| 3580 | : (XFA_ATTRIBUTEENUM)(intptr_t)(pAttr->pDefValue), |
| 3581 | bNotify); |
| 3582 | } break; |
| 3583 | case XFA_ATTRIBUTETYPE_Cdata: |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3584 | return SetCData(pAttr->eName, CFX_WideString(wsValue), bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3585 | case XFA_ATTRIBUTETYPE_Boolean: |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 3586 | return SetBoolean(pAttr->eName, wsValue != L"0", bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3587 | case XFA_ATTRIBUTETYPE_Integer: |
dsinclair | e0347a6 | 2016-08-11 11:24:11 -0700 | [diff] [blame] | 3588 | return SetInteger(pAttr->eName, |
| 3589 | FXSYS_round(FXSYS_wcstof(wsValue.c_str(), |
| 3590 | wsValue.GetLength(), nullptr)), |
| 3591 | bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3592 | case XFA_ATTRIBUTETYPE_Measure: |
| 3593 | return SetMeasure(pAttr->eName, CXFA_Measurement(wsValue), bNotify); |
| 3594 | default: |
| 3595 | break; |
| 3596 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3597 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3598 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3599 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3600 | bool CXFA_Node::GetAttribute(XFA_ATTRIBUTE eAttr, |
| 3601 | CFX_WideString& wsValue, |
| 3602 | bool bUseDefault) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3603 | const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3604 | if (!pAttr) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3605 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3606 | } |
| 3607 | XFA_ATTRIBUTETYPE eType = pAttr->eType; |
| 3608 | if (eType == XFA_ATTRIBUTETYPE_NOTSURE) { |
| 3609 | const XFA_NOTSUREATTRIBUTE* pNotsure = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3610 | XFA_GetNotsureAttribute(GetElementType(), pAttr->eName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3611 | eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata; |
| 3612 | } |
| 3613 | switch (eType) { |
| 3614 | case XFA_ATTRIBUTETYPE_Enum: { |
| 3615 | XFA_ATTRIBUTEENUM eValue; |
| 3616 | if (!TryEnum(pAttr->eName, eValue, bUseDefault)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3617 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3618 | } |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 3619 | wsValue = GetAttributeEnumByID(eValue)->pName; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3620 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3621 | } break; |
| 3622 | case XFA_ATTRIBUTETYPE_Cdata: { |
| 3623 | CFX_WideStringC wsValueC; |
| 3624 | if (!TryCData(pAttr->eName, wsValueC, bUseDefault)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3625 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3626 | } |
| 3627 | wsValue = wsValueC; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3628 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3629 | } break; |
| 3630 | case XFA_ATTRIBUTETYPE_Boolean: { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3631 | bool bValue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3632 | if (!TryBoolean(pAttr->eName, bValue, bUseDefault)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3633 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3634 | } |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 3635 | wsValue = bValue ? L"1" : L"0"; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3636 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3637 | } break; |
| 3638 | case XFA_ATTRIBUTETYPE_Integer: { |
| 3639 | int32_t iValue; |
| 3640 | if (!TryInteger(pAttr->eName, iValue, bUseDefault)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3641 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3642 | } |
| 3643 | wsValue.Format(L"%d", iValue); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3644 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3645 | } break; |
| 3646 | case XFA_ATTRIBUTETYPE_Measure: { |
| 3647 | CXFA_Measurement mValue; |
| 3648 | if (!TryMeasure(pAttr->eName, mValue, bUseDefault)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3649 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3650 | } |
| 3651 | mValue.ToString(wsValue); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3652 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3653 | } break; |
| 3654 | default: |
| 3655 | break; |
| 3656 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3657 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3658 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3659 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3660 | bool CXFA_Node::SetAttribute(const CFX_WideStringC& wsAttr, |
| 3661 | const CFX_WideStringC& wsValue, |
| 3662 | bool bNotify) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3663 | const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsValue); |
| 3664 | if (pAttributeInfo) { |
| 3665 | return SetAttribute(pAttributeInfo->eName, wsValue, bNotify); |
| 3666 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3667 | void* pKey = GetMapKey_Custom(wsAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3668 | SetMapModuleString(pKey, wsValue); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3669 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3670 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3671 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3672 | bool CXFA_Node::GetAttribute(const CFX_WideStringC& wsAttr, |
| 3673 | CFX_WideString& wsValue, |
| 3674 | bool bUseDefault) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3675 | const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsAttr); |
| 3676 | if (pAttributeInfo) { |
| 3677 | return GetAttribute(pAttributeInfo->eName, wsValue, bUseDefault); |
| 3678 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3679 | void* pKey = GetMapKey_Custom(wsAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3680 | CFX_WideStringC wsValueC; |
| 3681 | if (GetMapModuleString(pKey, wsValueC)) { |
| 3682 | wsValue = wsValueC; |
| 3683 | } |
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 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3686 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3687 | bool CXFA_Node::RemoveAttribute(const CFX_WideStringC& wsAttr) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3688 | void* pKey = GetMapKey_Custom(wsAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3689 | RemoveMapModuleKey(pKey); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3690 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3691 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3692 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3693 | bool CXFA_Node::TryBoolean(XFA_ATTRIBUTE eAttr, |
| 3694 | bool& bValue, |
| 3695 | bool bUseDefault) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3696 | void* pValue = nullptr; |
| 3697 | if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Boolean, bUseDefault, pValue)) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3698 | return false; |
tsepez | 478ed62 | 2016-10-27 14:32:33 -0700 | [diff] [blame] | 3699 | bValue = !!pValue; |
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 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3702 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3703 | bool CXFA_Node::TryInteger(XFA_ATTRIBUTE eAttr, |
| 3704 | int32_t& iValue, |
| 3705 | bool bUseDefault) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3706 | void* pValue = nullptr; |
| 3707 | if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Integer, bUseDefault, pValue)) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3708 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3709 | iValue = (int32_t)(uintptr_t)pValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3710 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3711 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3712 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3713 | bool CXFA_Node::TryEnum(XFA_ATTRIBUTE eAttr, |
| 3714 | XFA_ATTRIBUTEENUM& eValue, |
| 3715 | bool bUseDefault) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3716 | void* pValue = nullptr; |
| 3717 | if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Enum, bUseDefault, pValue)) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3718 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3719 | eValue = (XFA_ATTRIBUTEENUM)(uintptr_t)pValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3720 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3721 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3722 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3723 | bool CXFA_Node::SetMeasure(XFA_ATTRIBUTE eAttr, |
| 3724 | CXFA_Measurement mValue, |
| 3725 | bool bNotify) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3726 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3727 | OnChanging(eAttr, bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3728 | SetMapModuleBuffer(pKey, &mValue, sizeof(CXFA_Measurement)); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3729 | OnChanged(eAttr, bNotify, false); |
| 3730 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3731 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3732 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3733 | bool CXFA_Node::TryMeasure(XFA_ATTRIBUTE eAttr, |
| 3734 | CXFA_Measurement& mValue, |
| 3735 | bool bUseDefault) const { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3736 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3737 | void* pValue; |
| 3738 | int32_t iBytes; |
| 3739 | if (GetMapModuleBuffer(pKey, pValue, iBytes) && iBytes == sizeof(mValue)) { |
Dan Sinclair | 1c5d0b4 | 2017-04-03 15:05:11 -0400 | [diff] [blame] | 3740 | memcpy(&mValue, pValue, sizeof(mValue)); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3741 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3742 | } |
| 3743 | if (bUseDefault && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3744 | XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3745 | XFA_ATTRIBUTETYPE_Measure, m_ePacket)) { |
Dan Sinclair | 1c5d0b4 | 2017-04-03 15:05:11 -0400 | [diff] [blame] | 3746 | memcpy(&mValue, pValue, sizeof(mValue)); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3747 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3748 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3749 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3750 | } |
| 3751 | |
| 3752 | CXFA_Measurement CXFA_Node::GetMeasure(XFA_ATTRIBUTE eAttr) const { |
| 3753 | CXFA_Measurement mValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3754 | return TryMeasure(eAttr, mValue, true) ? mValue : CXFA_Measurement(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3755 | } |
| 3756 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3757 | bool CXFA_Node::SetCData(XFA_ATTRIBUTE eAttr, |
| 3758 | const CFX_WideString& wsValue, |
| 3759 | bool bNotify, |
| 3760 | bool bScriptModify) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3761 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3762 | OnChanging(eAttr, bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3763 | if (eAttr == XFA_ATTRIBUTE_Value) { |
| 3764 | CFX_WideString* pClone = new CFX_WideString(wsValue); |
| 3765 | SetUserData(pKey, pClone, &deleteWideStringCallBack); |
| 3766 | } else { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 3767 | SetMapModuleString(pKey, wsValue.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3768 | if (eAttr == XFA_ATTRIBUTE_Name) |
| 3769 | UpdateNameHash(); |
| 3770 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3771 | OnChanged(eAttr, bNotify, bScriptModify); |
| 3772 | |
| 3773 | if (!IsNeedSavingXMLNode() || eAttr == XFA_ATTRIBUTE_QualifiedName || |
| 3774 | eAttr == XFA_ATTRIBUTE_BindingNode) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3775 | return true; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3776 | } |
| 3777 | |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3778 | if (eAttr == XFA_ATTRIBUTE_Name && |
| 3779 | (m_elementType == XFA_Element::DataValue || |
| 3780 | m_elementType == XFA_Element::DataGroup)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3781 | return true; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3782 | } |
| 3783 | |
| 3784 | if (eAttr == XFA_ATTRIBUTE_Value) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3785 | FX_XMLNODETYPE eXMLType = m_pXMLNode->GetType(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3786 | switch (eXMLType) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3787 | case FX_XMLNODE_Element: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3788 | if (IsAttributeInXML()) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3789 | static_cast<CFX_XMLElement*>(m_pXMLNode) |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3790 | ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)), |
| 3791 | wsValue); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3792 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3793 | bool bDeleteChildren = true; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3794 | if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 3795 | for (CXFA_Node* pChildDataNode = |
| 3796 | GetNodeItem(XFA_NODEITEM_FirstChild); |
| 3797 | pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem( |
| 3798 | XFA_NODEITEM_NextSibling)) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 3799 | if (!pChildDataNode->GetBindItems().empty()) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3800 | bDeleteChildren = false; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3801 | break; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3802 | } |
| 3803 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3804 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3805 | if (bDeleteChildren) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3806 | static_cast<CFX_XMLElement*>(m_pXMLNode)->DeleteChildren(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3807 | } |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3808 | static_cast<CFX_XMLElement*>(m_pXMLNode)->SetTextData(wsValue); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3809 | } |
| 3810 | break; |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3811 | case FX_XMLNODE_Text: |
| 3812 | static_cast<CFX_XMLText*>(m_pXMLNode)->SetText(wsValue); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3813 | break; |
| 3814 | default: |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 3815 | ASSERT(0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3816 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3817 | return true; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3818 | } |
| 3819 | |
| 3820 | const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr); |
| 3821 | if (pInfo) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3822 | ASSERT(m_pXMLNode->GetType() == FX_XMLNODE_Element); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3823 | CFX_WideString wsAttrName = pInfo->pName; |
| 3824 | if (pInfo->eName == XFA_ATTRIBUTE_ContentType) { |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 3825 | wsAttrName = L"xfa:" + wsAttrName; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3826 | } |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3827 | static_cast<CFX_XMLElement*>(m_pXMLNode)->SetString(wsAttrName, wsValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3828 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3829 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3830 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3831 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3832 | bool CXFA_Node::SetAttributeValue(const CFX_WideString& wsValue, |
| 3833 | const CFX_WideString& wsXMLValue, |
| 3834 | bool bNotify, |
| 3835 | bool bScriptModify) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3836 | void* pKey = GetMapKey_Element(GetElementType(), XFA_ATTRIBUTE_Value); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3837 | OnChanging(XFA_ATTRIBUTE_Value, bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3838 | CFX_WideString* pClone = new CFX_WideString(wsValue); |
| 3839 | SetUserData(pKey, pClone, &deleteWideStringCallBack); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3840 | OnChanged(XFA_ATTRIBUTE_Value, bNotify, bScriptModify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3841 | if (IsNeedSavingXMLNode()) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3842 | FX_XMLNODETYPE eXMLType = m_pXMLNode->GetType(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3843 | switch (eXMLType) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3844 | case FX_XMLNODE_Element: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3845 | if (IsAttributeInXML()) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3846 | static_cast<CFX_XMLElement*>(m_pXMLNode) |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3847 | ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)), |
| 3848 | wsXMLValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3849 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3850 | bool bDeleteChildren = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3851 | if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 3852 | for (CXFA_Node* pChildDataNode = |
| 3853 | GetNodeItem(XFA_NODEITEM_FirstChild); |
| 3854 | pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem( |
| 3855 | XFA_NODEITEM_NextSibling)) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 3856 | if (!pChildDataNode->GetBindItems().empty()) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3857 | bDeleteChildren = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3858 | break; |
| 3859 | } |
| 3860 | } |
| 3861 | } |
| 3862 | if (bDeleteChildren) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3863 | static_cast<CFX_XMLElement*>(m_pXMLNode)->DeleteChildren(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3864 | } |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3865 | static_cast<CFX_XMLElement*>(m_pXMLNode)->SetTextData(wsXMLValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3866 | } |
| 3867 | break; |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3868 | case FX_XMLNODE_Text: |
| 3869 | static_cast<CFX_XMLText*>(m_pXMLNode)->SetText(wsXMLValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3870 | break; |
| 3871 | default: |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 3872 | ASSERT(0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3873 | } |
| 3874 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3875 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3876 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3877 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3878 | bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr, |
| 3879 | CFX_WideString& wsValue, |
| 3880 | bool bUseDefault, |
| 3881 | bool bProto) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3882 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3883 | if (eAttr == XFA_ATTRIBUTE_Value) { |
| 3884 | CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto); |
| 3885 | if (pStr) { |
| 3886 | wsValue = *pStr; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3887 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3888 | } |
| 3889 | } else { |
| 3890 | CFX_WideStringC wsValueC; |
| 3891 | if (GetMapModuleString(pKey, wsValueC)) { |
| 3892 | wsValue = wsValueC; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3893 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3894 | } |
| 3895 | } |
| 3896 | if (!bUseDefault) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3897 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3898 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3899 | void* pValue = nullptr; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3900 | if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3901 | XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) { |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 3902 | wsValue = (const wchar_t*)pValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3903 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3904 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3905 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3906 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3907 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3908 | bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr, |
| 3909 | CFX_WideStringC& wsValue, |
| 3910 | bool bUseDefault, |
| 3911 | bool bProto) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3912 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3913 | if (eAttr == XFA_ATTRIBUTE_Value) { |
| 3914 | CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto); |
| 3915 | if (pStr) { |
tsepez | 4d31d0c | 2016-04-19 14:11:59 -0700 | [diff] [blame] | 3916 | wsValue = pStr->AsStringC(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3917 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3918 | } |
| 3919 | } else { |
| 3920 | if (GetMapModuleString(pKey, wsValue)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3921 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3922 | } |
| 3923 | } |
| 3924 | if (!bUseDefault) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3925 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3926 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3927 | void* pValue = nullptr; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3928 | if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3929 | XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) { |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 3930 | wsValue = (CFX_WideStringC)(const wchar_t*)pValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3931 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3932 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3933 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3934 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3935 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3936 | bool CXFA_Node::SetObject(XFA_ATTRIBUTE eAttr, |
| 3937 | void* pData, |
| 3938 | XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3939 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3940 | return SetUserData(pKey, pData, pCallbackInfo); |
| 3941 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3942 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3943 | bool CXFA_Node::TryObject(XFA_ATTRIBUTE eAttr, void*& pData) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3944 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3945 | pData = GetUserData(pKey); |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 3946 | return !!pData; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3947 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3948 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3949 | bool CXFA_Node::SetValue(XFA_ATTRIBUTE eAttr, |
| 3950 | XFA_ATTRIBUTETYPE eType, |
| 3951 | void* pValue, |
| 3952 | bool bNotify) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3953 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3954 | OnChanging(eAttr, bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3955 | SetMapModuleValue(pKey, pValue); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3956 | OnChanged(eAttr, bNotify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3957 | if (IsNeedSavingXMLNode()) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3958 | ASSERT(m_pXMLNode->GetType() == FX_XMLNODE_Element); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3959 | const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr); |
| 3960 | if (pInfo) { |
| 3961 | switch (eType) { |
| 3962 | case XFA_ATTRIBUTETYPE_Enum: |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3963 | static_cast<CFX_XMLElement*>(m_pXMLNode) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3964 | ->SetString( |
| 3965 | pInfo->pName, |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 3966 | GetAttributeEnumByID((XFA_ATTRIBUTEENUM)(uintptr_t)pValue) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3967 | ->pName); |
| 3968 | break; |
| 3969 | case XFA_ATTRIBUTETYPE_Boolean: |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3970 | static_cast<CFX_XMLElement*>(m_pXMLNode) |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3971 | ->SetString(pInfo->pName, pValue ? L"1" : L"0"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3972 | break; |
Dan Sinclair | 5fa4e98 | 2017-04-05 11:48:21 -0400 | [diff] [blame] | 3973 | case XFA_ATTRIBUTETYPE_Integer: { |
| 3974 | CFX_WideString wsValue; |
| 3975 | wsValue.Format( |
| 3976 | L"%d", static_cast<int32_t>(reinterpret_cast<uintptr_t>(pValue))); |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3977 | static_cast<CFX_XMLElement*>(m_pXMLNode) |
Dan Sinclair | 5fa4e98 | 2017-04-05 11:48:21 -0400 | [diff] [blame] | 3978 | ->SetString(pInfo->pName, wsValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3979 | break; |
Dan Sinclair | 5fa4e98 | 2017-04-05 11:48:21 -0400 | [diff] [blame] | 3980 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3981 | default: |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 3982 | ASSERT(0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3983 | } |
| 3984 | } |
| 3985 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3986 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3987 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3988 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3989 | bool CXFA_Node::GetValue(XFA_ATTRIBUTE eAttr, |
| 3990 | XFA_ATTRIBUTETYPE eType, |
| 3991 | bool bUseDefault, |
| 3992 | void*& pValue) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3993 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3994 | if (GetMapModuleValue(pKey, pValue)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3995 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3996 | } |
| 3997 | if (!bUseDefault) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3998 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3999 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4000 | return XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, eType, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4001 | m_ePacket); |
| 4002 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4003 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4004 | bool CXFA_Node::SetUserData(void* pKey, |
| 4005 | void* pData, |
| 4006 | XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4007 | SetMapModuleBuffer(pKey, &pData, sizeof(void*), |
| 4008 | pCallbackInfo ? pCallbackInfo : &gs_XFADefaultFreeData); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4009 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4010 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4011 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4012 | bool CXFA_Node::TryUserData(void* pKey, void*& pData, bool bProtoAlso) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4013 | int32_t iBytes = 0; |
| 4014 | if (!GetMapModuleBuffer(pKey, pData, iBytes, bProtoAlso)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4015 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4016 | } |
Dan Sinclair | 1c5d0b4 | 2017-04-03 15:05:11 -0400 | [diff] [blame] | 4017 | return iBytes == sizeof(void*) && memcpy(&pData, pData, iBytes); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4018 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4019 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4020 | bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent, |
| 4021 | const CFX_WideString& wsXMLValue, |
| 4022 | bool bNotify, |
| 4023 | bool bScriptModify, |
| 4024 | bool bSyncData) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4025 | CXFA_Node* pNode = nullptr; |
| 4026 | CXFA_Node* pBindNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4027 | switch (GetObjectType()) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4028 | case XFA_ObjectType::ContainerNode: { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4029 | if (XFA_FieldIsMultiListBox(this)) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4030 | CXFA_Node* pValue = GetProperty(0, XFA_Element::Value); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4031 | CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4032 | ASSERT(pChildValue); |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 4033 | pChildValue->SetCData(XFA_ATTRIBUTE_ContentType, L"text/xml"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4034 | pChildValue->SetScriptContent(wsContent, wsContent, bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4035 | bScriptModify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4036 | CXFA_Node* pBind = GetBindData(); |
| 4037 | if (bSyncData && pBind) { |
tsepez | 51709be | 2016-12-08 10:55:57 -0800 | [diff] [blame] | 4038 | std::vector<CFX_WideString> wsSaveTextArray; |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 4039 | size_t iSize = 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4040 | if (!wsContent.IsEmpty()) { |
| 4041 | int32_t iStart = 0; |
| 4042 | int32_t iLength = wsContent.GetLength(); |
| 4043 | int32_t iEnd = wsContent.Find(L'\n', iStart); |
| 4044 | iEnd = (iEnd == -1) ? iLength : iEnd; |
| 4045 | while (iEnd >= iStart) { |
tsepez | 51709be | 2016-12-08 10:55:57 -0800 | [diff] [blame] | 4046 | wsSaveTextArray.push_back(wsContent.Mid(iStart, iEnd - iStart)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4047 | iStart = iEnd + 1; |
| 4048 | if (iStart >= iLength) { |
| 4049 | break; |
| 4050 | } |
| 4051 | iEnd = wsContent.Find(L'\n', iStart); |
| 4052 | if (iEnd < 0) { |
tsepez | 51709be | 2016-12-08 10:55:57 -0800 | [diff] [blame] | 4053 | wsSaveTextArray.push_back( |
| 4054 | wsContent.Mid(iStart, iLength - iStart)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4055 | } |
| 4056 | } |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 4057 | iSize = wsSaveTextArray.size(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4058 | } |
| 4059 | if (iSize == 0) { |
| 4060 | while (CXFA_Node* pChildNode = |
| 4061 | pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) { |
| 4062 | pBind->RemoveChild(pChildNode); |
| 4063 | } |
| 4064 | } else { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 4065 | std::vector<CXFA_Node*> valueNodes = pBind->GetNodeList( |
| 4066 | XFA_NODEFILTER_Children, XFA_Element::DataValue); |
| 4067 | size_t iDatas = valueNodes.size(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4068 | if (iDatas < iSize) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 4069 | size_t iAddNodes = iSize - iDatas; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4070 | CXFA_Node* pValueNodes = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4071 | while (iAddNodes-- > 0) { |
| 4072 | pValueNodes = |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4073 | pBind->CreateSamePacketNode(XFA_Element::DataValue); |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 4074 | pValueNodes->SetCData(XFA_ATTRIBUTE_Name, L"value"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4075 | pValueNodes->CreateXMLMappingNode(); |
| 4076 | pBind->InsertChild(pValueNodes); |
| 4077 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4078 | pValueNodes = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4079 | } else if (iDatas > iSize) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 4080 | size_t iDelNodes = iDatas - iSize; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4081 | while (iDelNodes-- > 0) { |
| 4082 | pBind->RemoveChild(pBind->GetNodeItem(XFA_NODEITEM_FirstChild)); |
| 4083 | } |
| 4084 | } |
| 4085 | int32_t i = 0; |
| 4086 | for (CXFA_Node* pValueNode = |
| 4087 | pBind->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 4088 | pValueNode; pValueNode = pValueNode->GetNodeItem( |
| 4089 | XFA_NODEITEM_NextSibling)) { |
| 4090 | pValueNode->SetAttributeValue(wsSaveTextArray[i], |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4091 | wsSaveTextArray[i], false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4092 | i++; |
| 4093 | } |
| 4094 | } |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 4095 | for (CXFA_Node* pArrayNode : pBind->GetBindItems()) { |
| 4096 | if (pArrayNode != this) { |
| 4097 | pArrayNode->SetScriptContent(wsContent, wsContent, bNotify, |
| 4098 | bScriptModify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4099 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4100 | } |
| 4101 | } |
| 4102 | break; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4103 | } else if (GetElementType() == XFA_Element::ExclGroup) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4104 | pNode = this; |
| 4105 | } else { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4106 | CXFA_Node* pValue = GetProperty(0, XFA_Element::Value); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4107 | CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4108 | ASSERT(pChildValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4109 | pChildValue->SetScriptContent(wsContent, wsContent, bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4110 | bScriptModify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4111 | } |
| 4112 | pBindNode = GetBindData(); |
| 4113 | if (pBindNode && bSyncData) { |
| 4114 | pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4115 | bScriptModify, false); |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 4116 | for (CXFA_Node* pArrayNode : pBindNode->GetBindItems()) { |
| 4117 | if (pArrayNode != this) { |
| 4118 | pArrayNode->SetScriptContent(wsContent, wsContent, bNotify, true, |
| 4119 | false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4120 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4121 | } |
| 4122 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4123 | pBindNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4124 | break; |
| 4125 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4126 | case XFA_ObjectType::ContentNode: { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4127 | CFX_WideString wsContentType; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4128 | if (GetElementType() == XFA_Element::ExData) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4129 | GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false); |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 4130 | if (wsContentType == L"text/html") { |
| 4131 | wsContentType = L""; |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 4132 | SetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4133 | } |
| 4134 | } |
| 4135 | CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild); |
| 4136 | if (!pContentRawDataNode) { |
tsepez | 9f2970c | 2016-04-01 10:23:04 -0700 | [diff] [blame] | 4137 | pContentRawDataNode = CreateSamePacketNode( |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 4138 | (wsContentType == L"text/xml") ? XFA_Element::Sharpxml |
| 4139 | : XFA_Element::Sharptext); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4140 | InsertChild(pContentRawDataNode); |
| 4141 | } |
| 4142 | return pContentRawDataNode->SetScriptContent( |
| 4143 | wsContent, wsXMLValue, bNotify, bScriptModify, bSyncData); |
| 4144 | } break; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4145 | case XFA_ObjectType::NodeC: |
| 4146 | case XFA_ObjectType::TextNode: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4147 | pNode = this; |
| 4148 | break; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4149 | case XFA_ObjectType::NodeV: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4150 | pNode = this; |
| 4151 | if (bSyncData && GetPacketID() == XFA_XDPPACKET_Form) { |
| 4152 | CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent); |
| 4153 | if (pParent) { |
| 4154 | pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent); |
| 4155 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4156 | if (pParent && pParent->GetElementType() == XFA_Element::Value) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4157 | pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent); |
| 4158 | if (pParent && pParent->IsContainerNode()) { |
| 4159 | pBindNode = pParent->GetBindData(); |
| 4160 | if (pBindNode) { |
| 4161 | pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4162 | bScriptModify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4163 | } |
| 4164 | } |
| 4165 | } |
| 4166 | } |
| 4167 | break; |
| 4168 | default: |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4169 | if (GetElementType() == XFA_Element::DataValue) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4170 | pNode = this; |
| 4171 | pBindNode = this; |
| 4172 | } |
| 4173 | break; |
| 4174 | } |
| 4175 | if (pNode) { |
| 4176 | SetAttributeValue(wsContent, wsXMLValue, bNotify, bScriptModify); |
| 4177 | if (pBindNode && bSyncData) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 4178 | for (CXFA_Node* pArrayNode : pBindNode->GetBindItems()) { |
| 4179 | pArrayNode->SetScriptContent(wsContent, wsContent, bNotify, |
| 4180 | bScriptModify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4181 | } |
| 4182 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4183 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4184 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4185 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4186 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4187 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4188 | bool CXFA_Node::SetContent(const CFX_WideString& wsContent, |
| 4189 | const CFX_WideString& wsXMLValue, |
| 4190 | bool bNotify, |
| 4191 | bool bScriptModify, |
| 4192 | bool bSyncData) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4193 | return SetScriptContent(wsContent, wsXMLValue, bNotify, bScriptModify, |
| 4194 | bSyncData); |
| 4195 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4196 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4197 | CFX_WideString CXFA_Node::GetScriptContent(bool bScriptModify) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4198 | CFX_WideString wsContent; |
| 4199 | return TryContent(wsContent, bScriptModify) ? wsContent : CFX_WideString(); |
| 4200 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4201 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4202 | CFX_WideString CXFA_Node::GetContent() { |
| 4203 | return GetScriptContent(); |
| 4204 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4205 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4206 | bool CXFA_Node::TryContent(CFX_WideString& wsContent, |
| 4207 | bool bScriptModify, |
| 4208 | bool bProto) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4209 | CXFA_Node* pNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4210 | switch (GetObjectType()) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4211 | case XFA_ObjectType::ContainerNode: |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4212 | if (GetElementType() == XFA_Element::ExclGroup) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4213 | pNode = this; |
| 4214 | } else { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4215 | CXFA_Node* pValue = GetChild(0, XFA_Element::Value); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4216 | if (!pValue) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4217 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4218 | } |
| 4219 | CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 4220 | if (pChildValue && XFA_FieldIsMultiListBox(this)) { |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 4221 | pChildValue->SetAttribute(XFA_ATTRIBUTE_ContentType, L"text/xml"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4222 | } |
| 4223 | return pChildValue |
| 4224 | ? pChildValue->TryContent(wsContent, bScriptModify, bProto) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4225 | : false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4226 | } |
| 4227 | break; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4228 | case XFA_ObjectType::ContentNode: { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4229 | CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild); |
| 4230 | if (!pContentRawDataNode) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4231 | XFA_Element element = XFA_Element::Sharptext; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4232 | if (GetElementType() == XFA_Element::ExData) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4233 | CFX_WideString wsContentType; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4234 | GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false); |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 4235 | if (wsContentType == L"text/html") { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4236 | element = XFA_Element::SharpxHTML; |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 4237 | } else if (wsContentType == L"text/xml") { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4238 | element = XFA_Element::Sharpxml; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4239 | } |
| 4240 | } |
| 4241 | pContentRawDataNode = CreateSamePacketNode(element); |
| 4242 | InsertChild(pContentRawDataNode); |
| 4243 | } |
| 4244 | return pContentRawDataNode->TryContent(wsContent, bScriptModify, bProto); |
| 4245 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4246 | case XFA_ObjectType::NodeC: |
| 4247 | case XFA_ObjectType::NodeV: |
| 4248 | case XFA_ObjectType::TextNode: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4249 | pNode = this; |
| 4250 | default: |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4251 | if (GetElementType() == XFA_Element::DataValue) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4252 | pNode = this; |
| 4253 | } |
| 4254 | break; |
| 4255 | } |
| 4256 | if (pNode) { |
| 4257 | if (bScriptModify) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 4258 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4259 | if (pScriptContext) { |
| 4260 | m_pDocument->GetScriptContext()->AddNodesOfRunScript(this); |
| 4261 | } |
| 4262 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4263 | return TryCData(XFA_ATTRIBUTE_Value, wsContent, false, bProto); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4264 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4265 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4266 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4267 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4268 | CXFA_Node* CXFA_Node::GetModelNode() { |
| 4269 | switch (GetPacketID()) { |
| 4270 | case XFA_XDPPACKET_XDP: |
| 4271 | return m_pDocument->GetRoot(); |
| 4272 | case XFA_XDPPACKET_Config: |
| 4273 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config)); |
| 4274 | case XFA_XDPPACKET_Template: |
| 4275 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template)); |
| 4276 | case XFA_XDPPACKET_Form: |
| 4277 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)); |
| 4278 | case XFA_XDPPACKET_Datasets: |
| 4279 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets)); |
| 4280 | case XFA_XDPPACKET_LocaleSet: |
| 4281 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_LocaleSet)); |
| 4282 | case XFA_XDPPACKET_ConnectionSet: |
| 4283 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_ConnectionSet)); |
| 4284 | case XFA_XDPPACKET_SourceSet: |
| 4285 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_SourceSet)); |
| 4286 | case XFA_XDPPACKET_Xdc: |
| 4287 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Xdc)); |
| 4288 | default: |
| 4289 | return this; |
| 4290 | } |
| 4291 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4292 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4293 | bool CXFA_Node::TryNamespace(CFX_WideString& wsNamespace) { |
tsepez | 774bdde | 2016-04-14 09:49:44 -0700 | [diff] [blame] | 4294 | wsNamespace.clear(); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4295 | if (IsModelNode() || GetElementType() == XFA_Element::Packet) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 4296 | CFX_XMLNode* pXMLNode = GetXMLMappingNode(); |
| 4297 | if (!pXMLNode || pXMLNode->GetType() != FX_XMLNODE_Element) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4298 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4299 | } |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 4300 | wsNamespace = static_cast<CFX_XMLElement*>(pXMLNode)->GetNamespaceURI(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4301 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4302 | } else if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 4303 | CFX_XMLNode* pXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4304 | if (!pXMLNode) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4305 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4306 | } |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 4307 | if (pXMLNode->GetType() != FX_XMLNODE_Element) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4308 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4309 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4310 | if (GetElementType() == XFA_Element::DataValue && |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4311 | GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData) { |
| 4312 | return XFA_FDEExtension_ResolveNamespaceQualifier( |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 4313 | static_cast<CFX_XMLElement*>(pXMLNode), |
Dan Sinclair | 5fa4e98 | 2017-04-05 11:48:21 -0400 | [diff] [blame] | 4314 | GetCData(XFA_ATTRIBUTE_QualifiedName), &wsNamespace); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4315 | } |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 4316 | wsNamespace = static_cast<CFX_XMLElement*>(pXMLNode)->GetNamespaceURI(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4317 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4318 | } else { |
| 4319 | CXFA_Node* pModelNode = GetModelNode(); |
| 4320 | return pModelNode->TryNamespace(wsNamespace); |
| 4321 | } |
| 4322 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4323 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4324 | CXFA_Node* CXFA_Node::GetProperty(int32_t index, |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4325 | XFA_Element eProperty, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4326 | bool bCreateProperty) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4327 | XFA_Element eType = GetElementType(); |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 4328 | uint32_t dwPacket = GetPacketID(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4329 | const XFA_PROPERTY* pProperty = |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4330 | XFA_GetPropertyOfElement(eType, eProperty, dwPacket); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4331 | if (!pProperty || index >= pProperty->uOccur) |
| 4332 | return nullptr; |
| 4333 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4334 | CXFA_Node* pNode = m_pChild; |
| 4335 | int32_t iCount = 0; |
| 4336 | for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4337 | if (pNode->GetElementType() == eProperty) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4338 | iCount++; |
| 4339 | if (iCount > index) { |
| 4340 | return pNode; |
| 4341 | } |
| 4342 | } |
| 4343 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4344 | if (!bCreateProperty) |
| 4345 | return nullptr; |
| 4346 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4347 | if (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf) { |
| 4348 | pNode = m_pChild; |
| 4349 | for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 4350 | const XFA_PROPERTY* pExistProperty = |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4351 | XFA_GetPropertyOfElement(eType, pNode->GetElementType(), dwPacket); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4352 | if (pExistProperty && (pExistProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) |
| 4353 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4354 | } |
| 4355 | } |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4356 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4357 | const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(dwPacket); |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 4358 | CXFA_Node* pNewNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4359 | for (; iCount <= index; iCount++) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4360 | pNewNode = m_pDocument->CreateNode(pPacket, eProperty); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4361 | if (!pNewNode) |
| 4362 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4363 | InsertChild(pNewNode, nullptr); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4364 | pNewNode->SetFlag(XFA_NodeFlag_Initialized, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4365 | } |
| 4366 | return pNewNode; |
| 4367 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4368 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4369 | int32_t CXFA_Node::CountChildren(XFA_Element eType, bool bOnlyChild) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4370 | CXFA_Node* pNode = m_pChild; |
| 4371 | int32_t iCount = 0; |
| 4372 | for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4373 | if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4374 | if (bOnlyChild) { |
| 4375 | const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement( |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4376 | GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4377 | if (pProperty) { |
| 4378 | continue; |
| 4379 | } |
| 4380 | } |
| 4381 | iCount++; |
| 4382 | } |
| 4383 | } |
| 4384 | return iCount; |
| 4385 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4386 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4387 | CXFA_Node* CXFA_Node::GetChild(int32_t index, |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4388 | XFA_Element eType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4389 | bool bOnlyChild) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4390 | ASSERT(index > -1); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4391 | CXFA_Node* pNode = m_pChild; |
| 4392 | int32_t iCount = 0; |
| 4393 | for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4394 | if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4395 | if (bOnlyChild) { |
| 4396 | const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement( |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4397 | GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4398 | if (pProperty) { |
| 4399 | continue; |
| 4400 | } |
| 4401 | } |
| 4402 | iCount++; |
| 4403 | if (iCount > index) { |
| 4404 | return pNode; |
| 4405 | } |
| 4406 | } |
| 4407 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4408 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4409 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4410 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4411 | int32_t CXFA_Node::InsertChild(int32_t index, CXFA_Node* pNode) { |
| 4412 | ASSERT(!pNode->m_pNext); |
| 4413 | pNode->m_pParent = this; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4414 | bool ret = m_pDocument->RemovePurgeNode(pNode); |
Wei Li | 5fe7ae7 | 2016-05-04 21:13:15 -0700 | [diff] [blame] | 4415 | ASSERT(ret); |
Wei Li | 439bb9e | 2016-05-05 00:35:26 -0700 | [diff] [blame] | 4416 | (void)ret; // Avoid unused variable warning. |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4417 | |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4418 | if (!m_pChild || index == 0) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4419 | if (index > 0) { |
| 4420 | return -1; |
| 4421 | } |
| 4422 | pNode->m_pNext = m_pChild; |
| 4423 | m_pChild = pNode; |
| 4424 | index = 0; |
| 4425 | } else if (index < 0) { |
| 4426 | m_pLastChild->m_pNext = pNode; |
| 4427 | } else { |
| 4428 | CXFA_Node* pPrev = m_pChild; |
| 4429 | int32_t iCount = 0; |
| 4430 | while (++iCount != index && pPrev->m_pNext) { |
| 4431 | pPrev = pPrev->m_pNext; |
| 4432 | } |
| 4433 | if (index > 0 && index != iCount) { |
| 4434 | return -1; |
| 4435 | } |
| 4436 | pNode->m_pNext = pPrev->m_pNext; |
| 4437 | pPrev->m_pNext = pNode; |
| 4438 | index = iCount; |
| 4439 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4440 | if (!pNode->m_pNext) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4441 | m_pLastChild = pNode; |
| 4442 | } |
| 4443 | ASSERT(m_pLastChild); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4444 | ASSERT(!m_pLastChild->m_pNext); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4445 | pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4446 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4447 | if (pNotify) |
| 4448 | pNotify->OnChildAdded(this); |
| 4449 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4450 | if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 4451 | ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFX_XMLNode::Parent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4452 | m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, index); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4453 | pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4454 | } |
| 4455 | return index; |
| 4456 | } |
weili | 6e1ae86 | 2016-05-04 18:25:27 -0700 | [diff] [blame] | 4457 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4458 | bool CXFA_Node::InsertChild(CXFA_Node* pNode, CXFA_Node* pBeforeNode) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4459 | if (!pNode || pNode->m_pParent || |
| 4460 | (pBeforeNode && pBeforeNode->m_pParent != this)) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4461 | ASSERT(false); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4462 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4463 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4464 | bool ret = m_pDocument->RemovePurgeNode(pNode); |
Wei Li | 5fe7ae7 | 2016-05-04 21:13:15 -0700 | [diff] [blame] | 4465 | ASSERT(ret); |
Wei Li | 439bb9e | 2016-05-05 00:35:26 -0700 | [diff] [blame] | 4466 | (void)ret; // Avoid unused variable warning. |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4467 | |
| 4468 | int32_t nIndex = -1; |
| 4469 | pNode->m_pParent = this; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4470 | if (!m_pChild || pBeforeNode == m_pChild) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4471 | pNode->m_pNext = m_pChild; |
| 4472 | m_pChild = pNode; |
| 4473 | nIndex = 0; |
| 4474 | } else if (!pBeforeNode) { |
| 4475 | pNode->m_pNext = m_pLastChild->m_pNext; |
| 4476 | m_pLastChild->m_pNext = pNode; |
| 4477 | } else { |
| 4478 | nIndex = 1; |
| 4479 | CXFA_Node* pPrev = m_pChild; |
| 4480 | while (pPrev->m_pNext != pBeforeNode) { |
| 4481 | pPrev = pPrev->m_pNext; |
| 4482 | nIndex++; |
| 4483 | } |
| 4484 | pNode->m_pNext = pPrev->m_pNext; |
| 4485 | pPrev->m_pNext = pNode; |
| 4486 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4487 | if (!pNode->m_pNext) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4488 | m_pLastChild = pNode; |
| 4489 | } |
| 4490 | ASSERT(m_pLastChild); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4491 | ASSERT(!m_pLastChild->m_pNext); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4492 | pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4493 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4494 | if (pNotify) |
| 4495 | pNotify->OnChildAdded(this); |
| 4496 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4497 | if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 4498 | ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFX_XMLNode::Parent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4499 | m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, nIndex); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4500 | pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4501 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4502 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4503 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4504 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4505 | CXFA_Node* CXFA_Node::Deprecated_GetPrevSibling() { |
| 4506 | if (!m_pParent) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4507 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4508 | } |
| 4509 | for (CXFA_Node* pSibling = m_pParent->m_pChild; pSibling; |
| 4510 | pSibling = pSibling->m_pNext) { |
| 4511 | if (pSibling->m_pNext == this) { |
| 4512 | return pSibling; |
| 4513 | } |
| 4514 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4515 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4516 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4517 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4518 | bool CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4519 | if (!pNode || pNode->m_pParent != this) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4520 | ASSERT(false); |
| 4521 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4522 | } |
| 4523 | if (m_pChild == pNode) { |
| 4524 | m_pChild = pNode->m_pNext; |
| 4525 | if (m_pLastChild == pNode) { |
| 4526 | m_pLastChild = pNode->m_pNext; |
| 4527 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4528 | pNode->m_pNext = nullptr; |
| 4529 | pNode->m_pParent = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4530 | } else { |
| 4531 | CXFA_Node* pPrev = pNode->Deprecated_GetPrevSibling(); |
| 4532 | pPrev->m_pNext = pNode->m_pNext; |
| 4533 | if (m_pLastChild == pNode) { |
| 4534 | m_pLastChild = pNode->m_pNext ? pNode->m_pNext : pPrev; |
| 4535 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4536 | pNode->m_pNext = nullptr; |
| 4537 | pNode->m_pParent = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4538 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4539 | ASSERT(!m_pLastChild || !m_pLastChild->m_pNext); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4540 | OnRemoved(bNotify); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4541 | pNode->SetFlag(XFA_NodeFlag_HasRemovedChildren, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4542 | m_pDocument->AddPurgeNode(pNode); |
| 4543 | if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) { |
| 4544 | if (pNode->IsAttributeInXML()) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4545 | ASSERT(pNode->m_pXMLNode == m_pXMLNode && |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 4546 | m_pXMLNode->GetType() == FX_XMLNODE_Element); |
| 4547 | if (pNode->m_pXMLNode->GetType() == FX_XMLNODE_Element) { |
| 4548 | CFX_XMLElement* pXMLElement = |
| 4549 | static_cast<CFX_XMLElement*>(pNode->m_pXMLNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4550 | CFX_WideStringC wsAttributeName = |
| 4551 | pNode->GetCData(XFA_ATTRIBUTE_QualifiedName); |
tsepez | 660956f | 2016-04-06 06:27:29 -0700 | [diff] [blame] | 4552 | pXMLElement->RemoveAttribute(wsAttributeName.c_str()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4553 | } |
| 4554 | CFX_WideString wsName; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4555 | pNode->GetAttribute(XFA_ATTRIBUTE_Name, wsName, false); |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 4556 | CFX_XMLElement* pNewXMLElement = new CFX_XMLElement(wsName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4557 | CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value); |
| 4558 | if (!wsValue.IsEmpty()) { |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 4559 | pNewXMLElement->SetTextData(CFX_WideString(wsValue)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4560 | } |
| 4561 | pNode->m_pXMLNode = pNewXMLElement; |
| 4562 | pNode->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown); |
| 4563 | } else { |
| 4564 | m_pXMLNode->RemoveChildNode(pNode->m_pXMLNode); |
| 4565 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4566 | pNode->SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4567 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4568 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4569 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4570 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4571 | CXFA_Node* CXFA_Node::GetFirstChildByName(const CFX_WideStringC& wsName) const { |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 4572 | return GetFirstChildByName(FX_HashCode_GetW(wsName, false)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4573 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4574 | |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 4575 | CXFA_Node* CXFA_Node::GetFirstChildByName(uint32_t dwNameHash) const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4576 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode; |
| 4577 | pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 4578 | if (pNode->GetNameHash() == dwNameHash) { |
| 4579 | return pNode; |
| 4580 | } |
| 4581 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4582 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4583 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4584 | |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4585 | CXFA_Node* CXFA_Node::GetFirstChildByClass(XFA_Element eType) const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4586 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode; |
| 4587 | pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4588 | if (pNode->GetElementType() == eType) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4589 | return pNode; |
| 4590 | } |
| 4591 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4592 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4593 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4594 | |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 4595 | CXFA_Node* CXFA_Node::GetNextSameNameSibling(uint32_t dwNameHash) const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4596 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode; |
| 4597 | pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 4598 | if (pNode->GetNameHash() == dwNameHash) { |
| 4599 | return pNode; |
| 4600 | } |
| 4601 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4602 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4603 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4604 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4605 | CXFA_Node* CXFA_Node::GetNextSameNameSibling( |
| 4606 | const CFX_WideStringC& wsNodeName) const { |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 4607 | return GetNextSameNameSibling(FX_HashCode_GetW(wsNodeName, false)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4608 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4609 | |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4610 | CXFA_Node* CXFA_Node::GetNextSameClassSibling(XFA_Element eType) const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4611 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode; |
| 4612 | pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4613 | if (pNode->GetElementType() == eType) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4614 | return pNode; |
| 4615 | } |
| 4616 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4617 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4618 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4619 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4620 | int32_t CXFA_Node::GetNodeSameNameIndex() const { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 4621 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4622 | if (!pScriptContext) { |
| 4623 | return -1; |
| 4624 | } |
| 4625 | return pScriptContext->GetIndexByName(const_cast<CXFA_Node*>(this)); |
| 4626 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4627 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4628 | int32_t CXFA_Node::GetNodeSameClassIndex() const { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 4629 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4630 | if (!pScriptContext) { |
| 4631 | return -1; |
| 4632 | } |
| 4633 | return pScriptContext->GetIndexByClassName(const_cast<CXFA_Node*>(this)); |
| 4634 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4635 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4636 | void CXFA_Node::GetSOMExpression(CFX_WideString& wsSOMExpression) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 4637 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4638 | if (!pScriptContext) { |
| 4639 | return; |
| 4640 | } |
| 4641 | pScriptContext->GetSomExpression(this, wsSOMExpression); |
| 4642 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4643 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4644 | CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4645 | CXFA_Node* pInstanceMgr = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4646 | if (m_ePacket == XFA_XDPPACKET_Form) { |
| 4647 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4648 | if (!pParentNode || pParentNode->GetElementType() == XFA_Element::Area) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4649 | return pInstanceMgr; |
| 4650 | } |
| 4651 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; |
| 4652 | pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4653 | XFA_Element eType = pNode->GetElementType(); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4654 | if ((eType == XFA_Element::Subform || eType == XFA_Element::SubformSet) && |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4655 | pNode->m_dwNameHash != m_dwNameHash) { |
| 4656 | break; |
| 4657 | } |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4658 | if (eType == XFA_Element::InstanceManager) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4659 | CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name); |
| 4660 | CFX_WideStringC wsInstName = pNode->GetCData(XFA_ATTRIBUTE_Name); |
| 4661 | if (wsInstName.GetLength() > 0 && wsInstName.GetAt(0) == '_' && |
| 4662 | wsInstName.Mid(1) == wsName) { |
| 4663 | pInstanceMgr = pNode; |
| 4664 | } |
| 4665 | break; |
| 4666 | } |
| 4667 | } |
| 4668 | } |
| 4669 | return pInstanceMgr; |
| 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 | CXFA_Node* CXFA_Node::GetOccurNode() { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4673 | return GetFirstChildByClass(XFA_Element::Occur); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4674 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4675 | |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4676 | bool CXFA_Node::HasFlag(XFA_NodeFlag dwFlag) const { |
| 4677 | if (m_uNodeFlags & dwFlag) |
| 4678 | return true; |
| 4679 | if (dwFlag == XFA_NodeFlag_HasRemovedChildren) |
| 4680 | return m_pParent && m_pParent->HasFlag(dwFlag); |
| 4681 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4682 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4683 | |
| 4684 | void CXFA_Node::SetFlag(uint32_t dwFlag, bool bNotify) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4685 | if (dwFlag == XFA_NodeFlag_Initialized && bNotify && !IsInitialized()) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4686 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4687 | if (pNotify) { |
| 4688 | pNotify->OnNodeReady(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4689 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4690 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4691 | m_uNodeFlags |= dwFlag; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4692 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4693 | |
| 4694 | void CXFA_Node::ClearFlag(uint32_t dwFlag) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4695 | m_uNodeFlags &= ~dwFlag; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4696 | } |
| 4697 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4698 | bool CXFA_Node::IsAttributeInXML() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4699 | return GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData; |
| 4700 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4701 | |
| 4702 | void CXFA_Node::OnRemoved(bool bNotify) { |
| 4703 | if (!bNotify) |
| 4704 | return; |
| 4705 | |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4706 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4707 | if (pNotify) |
| 4708 | pNotify->OnChildRemoved(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4709 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4710 | |
| 4711 | void CXFA_Node::OnChanging(XFA_ATTRIBUTE eAttr, bool bNotify) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4712 | if (bNotify && IsInitialized()) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4713 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4714 | if (pNotify) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4715 | pNotify->OnValueChanging(this, eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4716 | } |
| 4717 | } |
| 4718 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4719 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4720 | void CXFA_Node::OnChanged(XFA_ATTRIBUTE eAttr, |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4721 | bool bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4722 | bool bScriptModify) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4723 | if (bNotify && IsInitialized()) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4724 | Script_Attribute_SendAttributeChangeMessage(eAttr, bScriptModify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4725 | } |
| 4726 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4727 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4728 | int32_t CXFA_Node::execSingleEventByName(const CFX_WideStringC& wsEventName, |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4729 | XFA_Element eType) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4730 | int32_t iRet = XFA_EVENTERROR_NotExist; |
| 4731 | const XFA_ExecEventParaInfo* eventParaInfo = |
| 4732 | GetEventParaInfoByName(wsEventName); |
| 4733 | if (eventParaInfo) { |
| 4734 | uint32_t validFlags = eventParaInfo->m_validFlags; |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4735 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4736 | if (!pNotify) { |
| 4737 | return iRet; |
| 4738 | } |
| 4739 | if (validFlags == 1) { |
| 4740 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType); |
| 4741 | } else if (validFlags == 2) { |
| 4742 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4743 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4744 | } else if (validFlags == 3) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4745 | if (eType == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4746 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4747 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4748 | } |
| 4749 | } else if (validFlags == 4) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4750 | if (eType == XFA_Element::ExclGroup || eType == XFA_Element::Field) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4751 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4752 | if (pParentNode && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4753 | pParentNode->GetElementType() == XFA_Element::ExclGroup) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4754 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4755 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4756 | } |
| 4757 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4758 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4759 | } |
| 4760 | } else if (validFlags == 5) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4761 | if (eType == XFA_Element::Field) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4762 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4763 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4764 | } |
| 4765 | } else if (validFlags == 6) { |
| 4766 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 4767 | if (pWidgetData) { |
| 4768 | CXFA_Node* pUINode = pWidgetData->GetUIChild(); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4769 | if (pUINode->m_elementType == XFA_Element::Signature) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4770 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4771 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4772 | } |
| 4773 | } |
| 4774 | } else if (validFlags == 7) { |
| 4775 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 4776 | if (pWidgetData) { |
| 4777 | CXFA_Node* pUINode = pWidgetData->GetUIChild(); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4778 | if ((pUINode->m_elementType == XFA_Element::ChoiceList) && |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4779 | (!pWidgetData->IsListBox())) { |
| 4780 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4781 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4782 | } |
| 4783 | } |
| 4784 | } |
| 4785 | } |
| 4786 | return iRet; |
| 4787 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4788 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4789 | void CXFA_Node::UpdateNameHash() { |
| 4790 | const XFA_NOTSUREATTRIBUTE* pNotsure = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4791 | XFA_GetNotsureAttribute(GetElementType(), XFA_ATTRIBUTE_Name); |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 4792 | CFX_WideStringC wsName; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4793 | if (!pNotsure || pNotsure->eType == XFA_ATTRIBUTETYPE_Cdata) { |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 4794 | wsName = GetCData(XFA_ATTRIBUTE_Name); |
| 4795 | m_dwNameHash = FX_HashCode_GetW(wsName, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4796 | } else if (pNotsure->eType == XFA_ATTRIBUTETYPE_Enum) { |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 4797 | wsName = GetAttributeEnumByID(GetEnum(XFA_ATTRIBUTE_Name))->pName; |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 4798 | m_dwNameHash = FX_HashCode_GetW(wsName, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4799 | } |
| 4800 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4801 | |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 4802 | CFX_XMLNode* CXFA_Node::CreateXMLMappingNode() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4803 | if (!m_pXMLNode) { |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 4804 | CFX_WideString wsTag(GetCData(XFA_ATTRIBUTE_Name)); |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 4805 | m_pXMLNode = new CFX_XMLElement(wsTag); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4806 | SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4807 | } |
| 4808 | return m_pXMLNode; |
| 4809 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4810 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4811 | bool CXFA_Node::IsNeedSavingXMLNode() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4812 | return m_pXMLNode && (GetPacketID() == XFA_XDPPACKET_Datasets || |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4813 | GetElementType() == XFA_Element::Xfa); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4814 | } |
| 4815 | |
| 4816 | XFA_MAPMODULEDATA* CXFA_Node::CreateMapModuleData() { |
| 4817 | if (!m_pMapModuleData) |
| 4818 | m_pMapModuleData = new XFA_MAPMODULEDATA; |
| 4819 | return m_pMapModuleData; |
| 4820 | } |
| 4821 | |
| 4822 | XFA_MAPMODULEDATA* CXFA_Node::GetMapModuleData() const { |
| 4823 | return m_pMapModuleData; |
| 4824 | } |
| 4825 | |
| 4826 | void CXFA_Node::SetMapModuleValue(void* pKey, void* pValue) { |
| 4827 | XFA_MAPMODULEDATA* pModule = CreateMapModuleData(); |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4828 | pModule->m_ValueMap[pKey] = pValue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4829 | } |
| 4830 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4831 | bool CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) { |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4832 | for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4833 | XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData(); |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4834 | if (pModule) { |
| 4835 | auto it = pModule->m_ValueMap.find(pKey); |
| 4836 | if (it != pModule->m_ValueMap.end()) { |
| 4837 | pValue = it->second; |
| 4838 | return true; |
| 4839 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4840 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4841 | if (pNode->GetPacketID() == XFA_XDPPACKET_Datasets) |
| 4842 | break; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4843 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4844 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4845 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4846 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4847 | void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) { |
tsepez | 660956f | 2016-04-06 06:27:29 -0700 | [diff] [blame] | 4848 | SetMapModuleBuffer(pKey, (void*)wsValue.c_str(), |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 4849 | wsValue.GetLength() * sizeof(wchar_t)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4850 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4851 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4852 | bool CXFA_Node::GetMapModuleString(void* pKey, CFX_WideStringC& wsValue) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4853 | void* pValue; |
| 4854 | int32_t iBytes; |
| 4855 | if (!GetMapModuleBuffer(pKey, pValue, iBytes)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4856 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4857 | } |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 4858 | wsValue = CFX_WideStringC((const wchar_t*)pValue, iBytes / sizeof(wchar_t)); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4859 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4860 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4861 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4862 | void CXFA_Node::SetMapModuleBuffer( |
| 4863 | void* pKey, |
| 4864 | void* pValue, |
| 4865 | int32_t iBytes, |
| 4866 | XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) { |
| 4867 | XFA_MAPMODULEDATA* pModule = CreateMapModuleData(); |
| 4868 | XFA_MAPDATABLOCK*& pBuffer = pModule->m_BufferMap[pKey]; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4869 | if (!pBuffer) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4870 | pBuffer = |
| 4871 | (XFA_MAPDATABLOCK*)FX_Alloc(uint8_t, sizeof(XFA_MAPDATABLOCK) + iBytes); |
| 4872 | } else if (pBuffer->iBytes != iBytes) { |
| 4873 | if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { |
| 4874 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
| 4875 | } |
| 4876 | pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(uint8_t, pBuffer, |
| 4877 | sizeof(XFA_MAPDATABLOCK) + iBytes); |
| 4878 | } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { |
| 4879 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
| 4880 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4881 | if (!pBuffer) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4882 | return; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4883 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4884 | pBuffer->pCallbackInfo = pCallbackInfo; |
| 4885 | pBuffer->iBytes = iBytes; |
Dan Sinclair | 1c5d0b4 | 2017-04-03 15:05:11 -0400 | [diff] [blame] | 4886 | memcpy(pBuffer->GetData(), pValue, iBytes); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4887 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4888 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4889 | bool CXFA_Node::GetMapModuleBuffer(void* pKey, |
| 4890 | void*& pValue, |
| 4891 | int32_t& iBytes, |
| 4892 | bool bProtoAlso) const { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4893 | XFA_MAPDATABLOCK* pBuffer = nullptr; |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4894 | for (const CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4895 | XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData(); |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4896 | if (pModule) { |
| 4897 | auto it = pModule->m_BufferMap.find(pKey); |
| 4898 | if (it != pModule->m_BufferMap.end()) { |
| 4899 | pBuffer = it->second; |
| 4900 | break; |
| 4901 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4902 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4903 | if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets) |
| 4904 | break; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4905 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4906 | if (!pBuffer) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4907 | return false; |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4908 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4909 | pValue = pBuffer->GetData(); |
| 4910 | iBytes = pBuffer->iBytes; |
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 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4914 | bool CXFA_Node::HasMapModuleKey(void* pKey, bool bProtoAlso) { |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4915 | for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4916 | XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData(); |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4917 | if (pModule) { |
| 4918 | auto it1 = pModule->m_ValueMap.find(pKey); |
| 4919 | if (it1 != pModule->m_ValueMap.end()) |
| 4920 | return true; |
| 4921 | |
| 4922 | auto it2 = pModule->m_BufferMap.find(pKey); |
| 4923 | if (it2 != pModule->m_BufferMap.end()) |
| 4924 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4925 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4926 | if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets) |
| 4927 | break; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4928 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4929 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4930 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4931 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4932 | void CXFA_Node::RemoveMapModuleKey(void* pKey) { |
| 4933 | XFA_MAPMODULEDATA* pModule = GetMapModuleData(); |
| 4934 | if (!pModule) |
| 4935 | return; |
| 4936 | |
| 4937 | if (pKey) { |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4938 | auto it = pModule->m_BufferMap.find(pKey); |
| 4939 | if (it != pModule->m_BufferMap.end()) { |
| 4940 | XFA_MAPDATABLOCK* pBuffer = it->second; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4941 | if (pBuffer) { |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4942 | if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4943 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4944 | FX_Free(pBuffer); |
| 4945 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4946 | pModule->m_BufferMap.erase(it); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4947 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4948 | pModule->m_ValueMap.erase(pKey); |
| 4949 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4950 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4951 | |
| 4952 | for (auto& pair : pModule->m_BufferMap) { |
| 4953 | XFA_MAPDATABLOCK* pBuffer = pair.second; |
| 4954 | if (pBuffer) { |
| 4955 | if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) |
| 4956 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
| 4957 | FX_Free(pBuffer); |
| 4958 | } |
| 4959 | } |
| 4960 | pModule->m_BufferMap.clear(); |
| 4961 | pModule->m_ValueMap.clear(); |
| 4962 | delete pModule; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4963 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4964 | |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4965 | void CXFA_Node::MergeAllData(void* pDstModule) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4966 | XFA_MAPMODULEDATA* pDstModuleData = |
| 4967 | static_cast<CXFA_Node*>(pDstModule)->CreateMapModuleData(); |
| 4968 | XFA_MAPMODULEDATA* pSrcModuleData = GetMapModuleData(); |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4969 | if (!pSrcModuleData) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4970 | return; |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4971 | |
| 4972 | for (const auto& pair : pSrcModuleData->m_ValueMap) |
| 4973 | pDstModuleData->m_ValueMap[pair.first] = pair.second; |
| 4974 | |
| 4975 | for (const auto& pair : pSrcModuleData->m_BufferMap) { |
| 4976 | XFA_MAPDATABLOCK* pSrcBuffer = pair.second; |
| 4977 | XFA_MAPDATABLOCK*& pDstBuffer = pDstModuleData->m_BufferMap[pair.first]; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4978 | if (pSrcBuffer->pCallbackInfo && pSrcBuffer->pCallbackInfo->pFree && |
| 4979 | !pSrcBuffer->pCallbackInfo->pCopy) { |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4980 | if (pDstBuffer) { |
| 4981 | pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData()); |
| 4982 | pDstModuleData->m_BufferMap.erase(pair.first); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4983 | } |
| 4984 | continue; |
| 4985 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4986 | if (!pDstBuffer) { |
| 4987 | pDstBuffer = (XFA_MAPDATABLOCK*)FX_Alloc( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4988 | uint8_t, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes); |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4989 | } else if (pDstBuffer->iBytes != pSrcBuffer->iBytes) { |
| 4990 | if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) { |
| 4991 | pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4992 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4993 | pDstBuffer = (XFA_MAPDATABLOCK*)FX_Realloc( |
| 4994 | uint8_t, pDstBuffer, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes); |
| 4995 | } else if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) { |
| 4996 | pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4997 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4998 | if (!pDstBuffer) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4999 | continue; |
| 5000 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 5001 | pDstBuffer->pCallbackInfo = pSrcBuffer->pCallbackInfo; |
| 5002 | pDstBuffer->iBytes = pSrcBuffer->iBytes; |
Dan Sinclair | 1c5d0b4 | 2017-04-03 15:05:11 -0400 | [diff] [blame] | 5003 | memcpy(pDstBuffer->GetData(), pSrcBuffer->GetData(), pSrcBuffer->iBytes); |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 5004 | if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pCopy) { |
| 5005 | pDstBuffer->pCallbackInfo->pCopy(*(void**)pDstBuffer->GetData()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5006 | } |
| 5007 | } |
| 5008 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 5009 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5010 | void CXFA_Node::MoveBufferMapData(CXFA_Node* pDstModule, void* pKey) { |
| 5011 | if (!pDstModule) { |
| 5012 | return; |
| 5013 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5014 | bool bNeedMove = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5015 | if (!pKey) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5016 | bNeedMove = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5017 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 5018 | if (pDstModule->GetElementType() != GetElementType()) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5019 | bNeedMove = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5020 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5021 | XFA_MAPMODULEDATA* pSrcModuleData = nullptr; |
| 5022 | XFA_MAPMODULEDATA* pDstModuleData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5023 | if (bNeedMove) { |
| 5024 | pSrcModuleData = GetMapModuleData(); |
| 5025 | if (!pSrcModuleData) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5026 | bNeedMove = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5027 | } |
| 5028 | pDstModuleData = pDstModule->CreateMapModuleData(); |
| 5029 | } |
| 5030 | if (bNeedMove) { |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 5031 | auto it = pSrcModuleData->m_BufferMap.find(pKey); |
| 5032 | if (it != pSrcModuleData->m_BufferMap.end()) { |
| 5033 | XFA_MAPDATABLOCK* pBufferBlockData = it->second; |
| 5034 | if (pBufferBlockData) { |
| 5035 | pSrcModuleData->m_BufferMap.erase(pKey); |
| 5036 | pDstModuleData->m_BufferMap[pKey] = pBufferBlockData; |
| 5037 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5038 | } |
| 5039 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 5040 | if (pDstModule->IsNodeV()) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5041 | CFX_WideString wsValue = pDstModule->GetScriptContent(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5042 | CFX_WideString wsFormatValue(wsValue); |
| 5043 | CXFA_WidgetData* pWidgetData = pDstModule->GetContainerWidgetData(); |
| 5044 | if (pWidgetData) { |
tsepez | 6f167c3 | 2016-04-14 15:46:27 -0700 | [diff] [blame] | 5045 | pWidgetData->GetFormatDataValue(wsValue, wsFormatValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5046 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5047 | pDstModule->SetScriptContent(wsValue, wsFormatValue, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5048 | } |
| 5049 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 5050 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5051 | void CXFA_Node::MoveBufferMapData(CXFA_Node* pSrcModule, |
| 5052 | CXFA_Node* pDstModule, |
| 5053 | void* pKey, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5054 | bool bRecursive) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5055 | if (!pSrcModule || !pDstModule || !pKey) { |
| 5056 | return; |
| 5057 | } |
| 5058 | if (bRecursive) { |
| 5059 | CXFA_Node* pSrcChild = pSrcModule->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 5060 | CXFA_Node* pDstChild = pDstModule->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 5061 | for (; pSrcChild && pDstChild; |
| 5062 | pSrcChild = pSrcChild->GetNodeItem(XFA_NODEITEM_NextSibling), |
| 5063 | pDstChild = pDstChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5064 | MoveBufferMapData(pSrcChild, pDstChild, pKey, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5065 | } |
| 5066 | } |
| 5067 | pSrcModule->MoveBufferMapData(pDstModule, pKey); |
| 5068 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 5069 | |
| 5070 | void CXFA_Node::ThrowMissingPropertyException( |
| 5071 | const CFX_WideString& obj, |
| 5072 | const CFX_WideString& prop) const { |
| 5073 | ThrowException(L"'%s' doesn't have property '%s'.", obj.c_str(), |
| 5074 | prop.c_str()); |
| 5075 | } |
| 5076 | |
| 5077 | void CXFA_Node::ThrowTooManyOccurancesException( |
| 5078 | const CFX_WideString& obj) const { |
| 5079 | ThrowException( |
| 5080 | L"The element [%s] has violated its allowable number of occurrences.", |
| 5081 | obj.c_str()); |
| 5082 | } |