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 | e47e0c9 | 2017-04-26 10:55:54 -0700 | [diff] [blame^] | 11 | #include <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 | 283a043 | 2017-04-20 14:11:21 -0400 | [diff] [blame] | 16 | #include "core/fxcrt/cfx_memorystream.h" |
Dan Sinclair | 3b71d26 | 2017-04-19 08:58:54 -0400 | [diff] [blame] | 17 | #include "core/fxcrt/fx_codepage.h" |
Dan Sinclair | cfb1944 | 2017-04-20 13:13:04 -0400 | [diff] [blame] | 18 | #include "core/fxcrt/fx_extension.h" |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 19 | #include "core/fxcrt/xml/cfx_xmlelement.h" |
| 20 | #include "core/fxcrt/xml/cfx_xmlnode.h" |
| 21 | #include "core/fxcrt/xml/cfx_xmltext.h" |
dsinclair | 4355468 | 2016-09-29 17:29:48 -0700 | [diff] [blame] | 22 | #include "fxjs/cfxjse_value.h" |
tsepez | a9caab9 | 2016-12-14 05:57:10 -0800 | [diff] [blame] | 23 | #include "third_party/base/ptr_util.h" |
tsepez | aadedf9 | 2016-05-12 10:08:06 -0700 | [diff] [blame] | 24 | #include "third_party/base/stl_util.h" |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 25 | #include "xfa/fxfa/app/xfa_ffnotify.h" |
dsinclair | 5b49309 | 2016-09-29 20:20:24 -0700 | [diff] [blame] | 26 | #include "xfa/fxfa/cxfa_eventparam.h" |
Dan Sinclair | efcae5d | 2017-03-29 14:47:46 -0400 | [diff] [blame] | 27 | #include "xfa/fxfa/cxfa_ffwidget.h" |
| 28 | #include "xfa/fxfa/parser/cxfa_arraynodelist.h" |
| 29 | #include "xfa/fxfa/parser/cxfa_attachnodelist.h" |
dsinclair | 1628024 | 2016-07-21 12:03:47 -0700 | [diff] [blame] | 30 | #include "xfa/fxfa/parser/cxfa_document.h" |
dsinclair | 0b851ff | 2016-07-21 12:03:01 -0700 | [diff] [blame] | 31 | #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 32 | #include "xfa/fxfa/parser/cxfa_measurement.h" |
dsinclair | 44d054c | 2016-04-06 10:23:46 -0700 | [diff] [blame] | 33 | #include "xfa/fxfa/parser/cxfa_occur.h" |
dsinclair | 31f8740 | 2016-07-20 06:34:45 -0700 | [diff] [blame] | 34 | #include "xfa/fxfa/parser/cxfa_scriptcontext.h" |
dsinclair | 34f86b0 | 2016-07-11 08:42:33 -0700 | [diff] [blame] | 35 | #include "xfa/fxfa/parser/cxfa_simple_parser.h" |
Dan Sinclair | efcae5d | 2017-03-29 14:47:46 -0400 | [diff] [blame] | 36 | #include "xfa/fxfa/parser/cxfa_traversestrategy_xfacontainernode.h" |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 37 | #include "xfa/fxfa/parser/xfa_basic_data.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 38 | |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 39 | namespace { |
| 40 | |
| 41 | void XFA_DeleteWideString(void* pData) { |
| 42 | delete static_cast<CFX_WideString*>(pData); |
| 43 | } |
| 44 | |
| 45 | void XFA_CopyWideString(void*& pData) { |
| 46 | if (pData) { |
| 47 | CFX_WideString* pNewData = new CFX_WideString(*(CFX_WideString*)pData); |
| 48 | pData = pNewData; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | XFA_MAPDATABLOCKCALLBACKINFO deleteWideStringCallBack = {XFA_DeleteWideString, |
| 53 | XFA_CopyWideString}; |
| 54 | |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 55 | void XFA_DataNodeDeleteBindItem(void* pData) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 56 | delete static_cast<std::vector<CXFA_Node*>*>(pData); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | XFA_MAPDATABLOCKCALLBACKINFO deleteBindItemCallBack = { |
| 60 | XFA_DataNodeDeleteBindItem, nullptr}; |
| 61 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 62 | int32_t GetCount(CXFA_Node* pInstMgrNode) { |
| 63 | ASSERT(pInstMgrNode); |
| 64 | int32_t iCount = 0; |
| 65 | uint32_t dwNameHash = 0; |
| 66 | for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 67 | pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 68 | XFA_Element eCurType = pNode->GetElementType(); |
| 69 | if (eCurType == XFA_Element::InstanceManager) |
| 70 | break; |
| 71 | if ((eCurType != XFA_Element::Subform) && |
| 72 | (eCurType != XFA_Element::SubformSet)) { |
| 73 | continue; |
| 74 | } |
| 75 | if (iCount == 0) { |
| 76 | CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name); |
| 77 | CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name); |
| 78 | if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' || |
| 79 | wsInstName.Mid(1) != wsName) { |
| 80 | return iCount; |
| 81 | } |
| 82 | dwNameHash = pNode->GetNameHash(); |
| 83 | } |
| 84 | if (dwNameHash != pNode->GetNameHash()) |
| 85 | break; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 86 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 87 | iCount++; |
| 88 | } |
| 89 | return iCount; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 90 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 91 | |
Tom Sepez | 7cdc660 | 2017-03-28 09:56:48 -0700 | [diff] [blame] | 92 | std::vector<CXFA_Node*> NodesSortedByDocumentIdx( |
Tom Sepez | e47e0c9 | 2017-04-26 10:55:54 -0700 | [diff] [blame^] | 93 | const std::set<CXFA_Node*>& rgNodeSet) { |
Tom Sepez | 7cdc660 | 2017-03-28 09:56:48 -0700 | [diff] [blame] | 94 | if (rgNodeSet.empty()) |
| 95 | return std::vector<CXFA_Node*>(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 96 | |
Tom Sepez | 7cdc660 | 2017-03-28 09:56:48 -0700 | [diff] [blame] | 97 | std::vector<CXFA_Node*> rgNodeArray; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 98 | CXFA_Node* pCommonParent = |
| 99 | (*rgNodeSet.begin())->GetNodeItem(XFA_NODEITEM_Parent); |
| 100 | for (CXFA_Node* pNode = pCommonParent->GetNodeItem(XFA_NODEITEM_FirstChild); |
Tom Sepez | 7cdc660 | 2017-03-28 09:56:48 -0700 | [diff] [blame] | 101 | pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 102 | if (pdfium::ContainsValue(rgNodeSet, pNode)) |
| 103 | rgNodeArray.push_back(pNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 104 | } |
Tom Sepez | 7cdc660 | 2017-03-28 09:56:48 -0700 | [diff] [blame] | 105 | return rgNodeArray; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 106 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 107 | |
Tom Sepez | e47e0c9 | 2017-04-26 10:55:54 -0700 | [diff] [blame^] | 108 | using CXFA_NodeSetPair = std::pair<std::set<CXFA_Node*>, std::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 | e47e0c9 | 2017-04-26 10:55:54 -0700 | [diff] [blame^] | 131 | void ReorderDataNodes(const std::set<CXFA_Node*>& sSet1, |
| 132 | const std::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 | e47e0c9 | 2017-04-26 10:55:54 -0700 | [diff] [blame^] | 233 | std::set<CXFA_Node*> sNew; |
| 234 | std::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 | e47e0c9 | 2017-04-26 10:55:54 -0700 | [diff] [blame^] | 264 | std::set<CXFA_Node*> sNew; |
| 265 | std::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 | } |
Dan Sinclair | 283a043 | 2017-04-20 14:11:21 -0400 | [diff] [blame] | 1409 | auto pMemoryStream = pdfium::MakeRetain<CFX_MemoryStream>(true); |
Dan Sinclair | 3b71d26 | 2017-04-19 08:58:54 -0400 | [diff] [blame] | 1410 | auto pStream = |
| 1411 | pdfium::MakeRetain<CFX_SeekableStreamProxy>(pMemoryStream, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1412 | pStream->SetCodePage(FX_CODEPAGE_UTF8); |
Dan Sinclair | 5ae8792 | 2017-04-18 11:54:04 -0400 | [diff] [blame] | 1413 | pStream->WriteString(bsXMLHeader.AsStringC()); |
| 1414 | |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1415 | if (GetPacketID() == XFA_XDPPACKET_Form) |
tsepez | 7cda31a | 2016-12-07 12:10:20 -0800 | [diff] [blame] | 1416 | XFA_DataExporter_RegenerateFormFile(this, pStream, nullptr, true); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1417 | else |
tsepez | 7cda31a | 2016-12-07 12:10:20 -0800 | [diff] [blame] | 1418 | pElement->SaveXMLNode(pStream); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1419 | // TODO(weili): Check whether we need to save pretty print XML, pdfium:501. |
| 1420 | // For now, just put it here to avoid unused variable warning. |
| 1421 | (void)bPrettyMode; |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1422 | pArguments->GetReturnValue()->SetString( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1423 | CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize())); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1424 | return; |
| 1425 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1426 | pArguments->GetReturnValue()->SetString(""); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1427 | } |
| 1428 | |
| 1429 | void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) { |
| 1430 | int32_t iLength = pArguments->GetLength(); |
| 1431 | if (iLength != 2) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1432 | ThrowParamCountMismatchException(L"setAttribute"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1433 | return; |
| 1434 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1435 | CFX_WideString wsAttributeValue = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1436 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1437 | CFX_WideString wsAttribute = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1438 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC()); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1439 | SetAttribute(wsAttribute.AsStringC(), wsAttributeValue.AsStringC(), true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1440 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1441 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1442 | void CXFA_Node::Script_NodeClass_SetElement(CFXJSE_Arguments* pArguments) { |
| 1443 | int32_t iLength = pArguments->GetLength(); |
| 1444 | if (iLength != 1 && iLength != 2) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1445 | ThrowParamCountMismatchException(L"setElement"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1446 | return; |
| 1447 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1448 | CXFA_Node* pNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1449 | CFX_WideString wsName; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1450 | pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); |
| 1451 | if (iLength == 2) |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1452 | wsName = CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC()); |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1453 | // TODO(weili): check whether we need to implement this, pdfium:501. |
| 1454 | // For now, just put the variables here to avoid unused variable warning. |
| 1455 | (void)pNode; |
| 1456 | (void)wsName; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1457 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1458 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1459 | void CXFA_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1460 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1461 | XFA_ATTRIBUTE eAttribute) { |
| 1462 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1463 | ThrowInvalidPropertyException(); |
| 1464 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1465 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1466 | |
| 1467 | CFX_WideString wsNameSpace; |
| 1468 | TryNamespace(wsNameSpace); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 1469 | pValue->SetString(wsNameSpace.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1470 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1471 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1472 | void CXFA_Node::Script_NodeClass_Model(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1473 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1474 | XFA_ATTRIBUTE eAttribute) { |
| 1475 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1476 | ThrowInvalidPropertyException(); |
| 1477 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1478 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1479 | pValue->Assign( |
| 1480 | m_pDocument->GetScriptContext()->GetJSValueFromMap(GetModelNode())); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1481 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1482 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1483 | void CXFA_Node::Script_NodeClass_IsContainer(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1484 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1485 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1486 | if (bSetting) { |
| 1487 | ThrowInvalidPropertyException(); |
| 1488 | return; |
| 1489 | } |
| 1490 | pValue->SetBoolean(IsContainerNode()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1491 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1492 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1493 | void CXFA_Node::Script_NodeClass_IsNull(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1494 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1495 | XFA_ATTRIBUTE eAttribute) { |
| 1496 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1497 | ThrowInvalidPropertyException(); |
| 1498 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1499 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1500 | if (GetElementType() == XFA_Element::Subform) { |
| 1501 | pValue->SetBoolean(false); |
| 1502 | return; |
| 1503 | } |
| 1504 | CFX_WideString strValue; |
| 1505 | pValue->SetBoolean(!TryContent(strValue) || strValue.IsEmpty()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1506 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1507 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1508 | void CXFA_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1509 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1510 | XFA_ATTRIBUTE eAttribute) { |
| 1511 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1512 | ThrowInvalidPropertyException(); |
| 1513 | return; |
| 1514 | } |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 1515 | std::vector<CXFA_Node*> properties = |
| 1516 | GetNodeList(XFA_NODEFILTER_OneOfProperty); |
| 1517 | if (!properties.empty()) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1518 | pValue->Assign( |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 1519 | m_pDocument->GetScriptContext()->GetJSValueFromMap(properties.front())); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1520 | } |
| 1521 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1522 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1523 | void CXFA_Node::Script_ContainerClass_GetDelta(CFXJSE_Arguments* pArguments) {} |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1524 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1525 | void CXFA_Node::Script_ContainerClass_GetDeltas(CFXJSE_Arguments* pArguments) { |
| 1526 | CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1527 | pArguments->GetReturnValue()->SetObject( |
| 1528 | pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1529 | } |
| 1530 | void CXFA_Node::Script_ModelClass_ClearErrorList(CFXJSE_Arguments* pArguments) { |
| 1531 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1532 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1533 | void CXFA_Node::Script_ModelClass_CreateNode(CFXJSE_Arguments* pArguments) { |
| 1534 | Script_Template_CreateNode(pArguments); |
| 1535 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1536 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1537 | void CXFA_Node::Script_ModelClass_IsCompatibleNS(CFXJSE_Arguments* pArguments) { |
| 1538 | int32_t iLength = pArguments->GetLength(); |
| 1539 | if (iLength < 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1540 | ThrowParamCountMismatchException(L"isCompatibleNS"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1541 | return; |
| 1542 | } |
| 1543 | CFX_WideString wsNameSpace; |
| 1544 | if (iLength >= 1) { |
| 1545 | CFX_ByteString bsNameSpace = pArguments->GetUTF8String(0); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1546 | wsNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1547 | } |
| 1548 | CFX_WideString wsNodeNameSpace; |
| 1549 | TryNamespace(wsNodeNameSpace); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1550 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1551 | if (pValue) |
| 1552 | pValue->SetBoolean(wsNodeNameSpace == wsNameSpace); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1553 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1554 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1555 | void CXFA_Node::Script_ModelClass_Context(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1556 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1557 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1558 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1559 | void CXFA_Node::Script_ModelClass_AliasNode(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1560 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1561 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1562 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1563 | void CXFA_Node::Script_Attribute_Integer(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1564 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1565 | XFA_ATTRIBUTE eAttribute) { |
| 1566 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1567 | SetInteger(eAttribute, pValue->ToInteger(), true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1568 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1569 | pValue->SetInteger(GetInteger(eAttribute)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1570 | } |
| 1571 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1572 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1573 | void CXFA_Node::Script_Attribute_IntegerRead(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1574 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1575 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1576 | if (bSetting) { |
| 1577 | ThrowInvalidPropertyException(); |
| 1578 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1579 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1580 | pValue->SetInteger(GetInteger(eAttribute)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1581 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1582 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1583 | void CXFA_Node::Script_Attribute_BOOL(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1584 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1585 | XFA_ATTRIBUTE eAttribute) { |
| 1586 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1587 | SetBoolean(eAttribute, pValue->ToBoolean(), true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1588 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1589 | pValue->SetString(GetBoolean(eAttribute) ? "1" : "0"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1590 | } |
| 1591 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1592 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1593 | void CXFA_Node::Script_Attribute_BOOLRead(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1594 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1595 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1596 | if (bSetting) { |
| 1597 | ThrowInvalidPropertyException(); |
| 1598 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1599 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1600 | pValue->SetString(GetBoolean(eAttribute) ? "1" : "0"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1601 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1602 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1603 | void CXFA_Node::Script_Attribute_SendAttributeChangeMessage( |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1604 | XFA_ATTRIBUTE eAttribute, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1605 | bool bScriptModify) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1606 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1607 | if (!pLayoutPro) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1608 | return; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1609 | |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 1610 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1611 | if (!pNotify) |
| 1612 | return; |
| 1613 | |
| 1614 | uint32_t dwPacket = GetPacketID(); |
| 1615 | if (!(dwPacket & XFA_XDPPACKET_Form)) { |
| 1616 | pNotify->OnValueChanged(this, eAttribute, this, this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1617 | return; |
| 1618 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1619 | |
| 1620 | bool bNeedFindContainer = false; |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1621 | switch (GetElementType()) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1622 | case XFA_Element::Caption: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1623 | bNeedFindContainer = true; |
| 1624 | pNotify->OnValueChanged(this, eAttribute, this, |
| 1625 | GetNodeItem(XFA_NODEITEM_Parent)); |
| 1626 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1627 | case XFA_Element::Font: |
| 1628 | case XFA_Element::Para: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1629 | bNeedFindContainer = true; |
| 1630 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1631 | if (pParentNode->GetElementType() == XFA_Element::Caption) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1632 | pNotify->OnValueChanged(this, eAttribute, pParentNode, |
| 1633 | pParentNode->GetNodeItem(XFA_NODEITEM_Parent)); |
| 1634 | } else { |
| 1635 | pNotify->OnValueChanged(this, eAttribute, this, pParentNode); |
| 1636 | } |
| 1637 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1638 | case XFA_Element::Margin: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1639 | bNeedFindContainer = true; |
| 1640 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1641 | XFA_Element eParentType = pParentNode->GetElementType(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1642 | if (pParentNode->IsContainerNode()) { |
| 1643 | pNotify->OnValueChanged(this, eAttribute, this, pParentNode); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1644 | } else if (eParentType == XFA_Element::Caption) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1645 | pNotify->OnValueChanged(this, eAttribute, pParentNode, |
| 1646 | pParentNode->GetNodeItem(XFA_NODEITEM_Parent)); |
| 1647 | } else { |
| 1648 | CXFA_Node* pNode = pParentNode->GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1649 | if (pNode && pNode->GetElementType() == XFA_Element::Ui) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1650 | pNotify->OnValueChanged(this, eAttribute, pNode, |
| 1651 | pNode->GetNodeItem(XFA_NODEITEM_Parent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1652 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1653 | } |
| 1654 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1655 | case XFA_Element::Comb: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1656 | CXFA_Node* pEditNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1657 | XFA_Element eUIType = pEditNode->GetElementType(); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1658 | if (pEditNode && (eUIType == XFA_Element::DateTimeEdit || |
| 1659 | eUIType == XFA_Element::NumericEdit || |
| 1660 | eUIType == XFA_Element::TextEdit)) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1661 | CXFA_Node* pUINode = pEditNode->GetNodeItem(XFA_NODEITEM_Parent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1662 | if (pUINode) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1663 | pNotify->OnValueChanged(this, eAttribute, pUINode, |
| 1664 | pUINode->GetNodeItem(XFA_NODEITEM_Parent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1665 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1666 | } |
| 1667 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1668 | case XFA_Element::Button: |
| 1669 | case XFA_Element::Barcode: |
| 1670 | case XFA_Element::ChoiceList: |
| 1671 | case XFA_Element::DateTimeEdit: |
| 1672 | case XFA_Element::NumericEdit: |
| 1673 | case XFA_Element::PasswordEdit: |
| 1674 | case XFA_Element::TextEdit: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1675 | CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent); |
| 1676 | if (pUINode) { |
| 1677 | pNotify->OnValueChanged(this, eAttribute, pUINode, |
| 1678 | pUINode->GetNodeItem(XFA_NODEITEM_Parent)); |
| 1679 | } |
| 1680 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1681 | case XFA_Element::CheckButton: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1682 | bNeedFindContainer = true; |
| 1683 | CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent); |
| 1684 | if (pUINode) { |
| 1685 | pNotify->OnValueChanged(this, eAttribute, pUINode, |
| 1686 | pUINode->GetNodeItem(XFA_NODEITEM_Parent)); |
| 1687 | } |
| 1688 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1689 | case XFA_Element::Keep: |
| 1690 | case XFA_Element::Bookend: |
| 1691 | case XFA_Element::Break: |
| 1692 | case XFA_Element::BreakAfter: |
| 1693 | case XFA_Element::BreakBefore: |
| 1694 | case XFA_Element::Overflow: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1695 | bNeedFindContainer = true; |
| 1696 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1697 | case XFA_Element::Area: |
| 1698 | case XFA_Element::Draw: |
| 1699 | case XFA_Element::ExclGroup: |
| 1700 | case XFA_Element::Field: |
| 1701 | case XFA_Element::Subform: |
| 1702 | case XFA_Element::SubformSet: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1703 | pLayoutPro->AddChangedContainer(this); |
| 1704 | pNotify->OnValueChanged(this, eAttribute, this, this); |
| 1705 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1706 | case XFA_Element::Sharptext: |
| 1707 | case XFA_Element::Sharpxml: |
| 1708 | case XFA_Element::SharpxHTML: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1709 | CXFA_Node* pTextNode = GetNodeItem(XFA_NODEITEM_Parent); |
| 1710 | if (!pTextNode) { |
| 1711 | return; |
| 1712 | } |
| 1713 | CXFA_Node* pValueNode = pTextNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 1714 | if (!pValueNode) { |
| 1715 | return; |
| 1716 | } |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1717 | XFA_Element eType = pValueNode->GetElementType(); |
| 1718 | if (eType == XFA_Element::Value) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1719 | bNeedFindContainer = true; |
| 1720 | CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 1721 | if (pNode && pNode->IsContainerNode()) { |
| 1722 | if (bScriptModify) { |
| 1723 | pValueNode = pNode; |
| 1724 | } |
| 1725 | pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode); |
| 1726 | } else { |
| 1727 | pNotify->OnValueChanged(this, eAttribute, pNode, |
| 1728 | pNode->GetNodeItem(XFA_NODEITEM_Parent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1729 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1730 | } else { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1731 | if (eType == XFA_Element::Items) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1732 | CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 1733 | if (pNode && pNode->IsContainerNode()) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1734 | pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1735 | } |
| 1736 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1737 | } |
| 1738 | } break; |
| 1739 | default: |
| 1740 | break; |
| 1741 | } |
| 1742 | if (bNeedFindContainer) { |
| 1743 | CXFA_Node* pParent = this; |
| 1744 | while (pParent) { |
| 1745 | if (pParent->IsContainerNode()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1746 | break; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1747 | |
| 1748 | pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1749 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1750 | if (pParent) { |
| 1751 | pLayoutPro->AddChangedContainer(pParent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1752 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1753 | } |
| 1754 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1755 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1756 | void CXFA_Node::Script_Attribute_String(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1757 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1758 | XFA_ATTRIBUTE eAttribute) { |
| 1759 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1760 | CFX_WideString wsValue = pValue->ToWideString(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1761 | SetAttribute(eAttribute, wsValue.AsStringC(), true); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1762 | if (eAttribute == XFA_ATTRIBUTE_Use && |
| 1763 | GetElementType() == XFA_Element::Desc) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1764 | CXFA_Node* pTemplateNode = |
| 1765 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template)); |
| 1766 | CXFA_Node* pProtoRoot = |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1767 | pTemplateNode->GetFirstChildByClass(XFA_Element::Subform) |
| 1768 | ->GetFirstChildByClass(XFA_Element::Proto); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1769 | |
| 1770 | CFX_WideString wsID; |
| 1771 | CFX_WideString wsSOM; |
| 1772 | if (!wsValue.IsEmpty()) { |
| 1773 | if (wsValue[0] == '#') { |
| 1774 | wsID = CFX_WideString(wsValue.c_str() + 1, wsValue.GetLength() - 1); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1775 | } else { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1776 | wsSOM = wsValue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1777 | } |
| 1778 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1779 | CXFA_Node* pProtoNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1780 | if (!wsSOM.IsEmpty()) { |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1781 | uint32_t dwFlag = XFA_RESOLVENODE_Children | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1782 | XFA_RESOLVENODE_Attributes | |
| 1783 | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | |
| 1784 | XFA_RESOLVENODE_Siblings; |
| 1785 | XFA_RESOLVENODE_RS resoveNodeRS; |
| 1786 | int32_t iRet = m_pDocument->GetScriptContext()->ResolveObjects( |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1787 | pProtoRoot, wsSOM.AsStringC(), resoveNodeRS, dwFlag); |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 1788 | if (iRet > 0 && resoveNodeRS.objects.front()->IsNode()) { |
| 1789 | pProtoNode = resoveNodeRS.objects.front()->AsNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1790 | } |
| 1791 | } else if (!wsID.IsEmpty()) { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1792 | pProtoNode = m_pDocument->GetNodeByID(pProtoRoot, wsID.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1793 | } |
| 1794 | if (pProtoNode) { |
| 1795 | CXFA_Node* pHeadChild = GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1796 | while (pHeadChild) { |
| 1797 | CXFA_Node* pSibling = |
| 1798 | pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1799 | RemoveChild(pHeadChild); |
| 1800 | pHeadChild = pSibling; |
| 1801 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1802 | CXFA_Node* pProtoForm = pProtoNode->CloneTemplateToForm(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1803 | pHeadChild = pProtoForm->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1804 | while (pHeadChild) { |
| 1805 | CXFA_Node* pSibling = |
| 1806 | pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1807 | pProtoForm->RemoveChild(pHeadChild); |
| 1808 | InsertChild(pHeadChild); |
| 1809 | pHeadChild = pSibling; |
| 1810 | } |
| 1811 | m_pDocument->RemovePurgeNode(pProtoForm); |
| 1812 | delete pProtoForm; |
| 1813 | } |
| 1814 | } |
| 1815 | } else { |
| 1816 | CFX_WideString wsValue; |
| 1817 | GetAttribute(eAttribute, wsValue); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 1818 | pValue->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1819 | } |
| 1820 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1821 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1822 | void CXFA_Node::Script_Attribute_StringRead(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1823 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1824 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1825 | if (bSetting) { |
| 1826 | ThrowInvalidPropertyException(); |
| 1827 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1828 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1829 | |
| 1830 | CFX_WideString wsValue; |
| 1831 | GetAttribute(eAttribute, wsValue); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 1832 | pValue->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1833 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1834 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1835 | void CXFA_Node::Script_WsdlConnection_Execute(CFXJSE_Arguments* pArguments) { |
| 1836 | int32_t argc = pArguments->GetLength(); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1837 | if (argc != 0 && argc != 1) { |
| 1838 | ThrowParamCountMismatchException(L"execute"); |
| 1839 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1840 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1841 | pArguments->GetReturnValue()->SetBoolean(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1842 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1843 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1844 | void CXFA_Node::Script_Delta_Restore(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1845 | if (pArguments->GetLength() != 0) |
| 1846 | ThrowParamCountMismatchException(L"restore"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1847 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1848 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1849 | void CXFA_Node::Script_Delta_CurrentValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1850 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1851 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1852 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1853 | void CXFA_Node::Script_Delta_SavedValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1854 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1855 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1856 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1857 | void CXFA_Node::Script_Delta_Target(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1858 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1859 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1860 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1861 | void CXFA_Node::Script_Som_Message(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1862 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1863 | XFA_SOM_MESSAGETYPE iMessageType) { |
| 1864 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 1865 | if (!pWidgetData) { |
| 1866 | return; |
| 1867 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1868 | bool bNew = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1869 | CXFA_Validate validate = pWidgetData->GetValidate(); |
| 1870 | if (!validate) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1871 | validate = pWidgetData->GetValidate(true); |
| 1872 | bNew = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1873 | } |
| 1874 | if (bSetting) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1875 | switch (iMessageType) { |
| 1876 | case XFA_SOM_ValidationMessage: |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1877 | validate.SetScriptMessageText(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1878 | break; |
| 1879 | case XFA_SOM_FormatMessage: |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1880 | validate.SetFormatMessageText(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1881 | break; |
| 1882 | case XFA_SOM_MandatoryMessage: |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1883 | validate.SetNullMessageText(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1884 | break; |
| 1885 | default: |
| 1886 | break; |
| 1887 | } |
| 1888 | if (!bNew) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 1889 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1890 | if (!pNotify) { |
| 1891 | return; |
| 1892 | } |
| 1893 | pNotify->AddCalcValidate(this); |
| 1894 | } |
| 1895 | } else { |
| 1896 | CFX_WideString wsMessage; |
| 1897 | switch (iMessageType) { |
| 1898 | case XFA_SOM_ValidationMessage: |
| 1899 | validate.GetScriptMessageText(wsMessage); |
| 1900 | break; |
| 1901 | case XFA_SOM_FormatMessage: |
| 1902 | validate.GetFormatMessageText(wsMessage); |
| 1903 | break; |
| 1904 | case XFA_SOM_MandatoryMessage: |
| 1905 | validate.GetNullMessageText(wsMessage); |
| 1906 | break; |
| 1907 | default: |
| 1908 | break; |
| 1909 | } |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 1910 | pValue->SetString(wsMessage.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1911 | } |
| 1912 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1913 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1914 | void CXFA_Node::Script_Som_ValidationMessage(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1915 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1916 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1917 | Script_Som_Message(pValue, bSetting, XFA_SOM_ValidationMessage); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1918 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1919 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1920 | void CXFA_Node::Script_Field_Length(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1921 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1922 | XFA_ATTRIBUTE eAttribute) { |
| 1923 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1924 | ThrowInvalidPropertyException(); |
| 1925 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1926 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1927 | |
| 1928 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 1929 | if (!pWidgetData) { |
| 1930 | pValue->SetInteger(0); |
| 1931 | return; |
| 1932 | } |
| 1933 | pValue->SetInteger(pWidgetData->CountChoiceListItems(true)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1934 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1935 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1936 | void CXFA_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1937 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1938 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1939 | XFA_Element eType = GetElementType(); |
| 1940 | if (eType == XFA_Element::Field) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1941 | Script_Field_DefaultValue(pValue, bSetting, eAttribute); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1942 | return; |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1943 | } |
| 1944 | if (eType == XFA_Element::Draw) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1945 | Script_Draw_DefaultValue(pValue, bSetting, eAttribute); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1946 | return; |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1947 | } |
| 1948 | if (eType == XFA_Element::Boolean) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1949 | Script_Boolean_Value(pValue, bSetting, eAttribute); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1950 | return; |
| 1951 | } |
| 1952 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1953 | CFX_WideString wsNewValue; |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 1954 | if (!(pValue && (pValue->IsNull() || pValue->IsUndefined()))) |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1955 | wsNewValue = pValue->ToWideString(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1956 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1957 | CFX_WideString wsFormatValue(wsNewValue); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1958 | CXFA_WidgetData* pContainerWidgetData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1959 | if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1960 | CFX_WideString wsPicture; |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 1961 | for (CXFA_Node* pFormNode : GetBindItems()) { |
| 1962 | if (!pFormNode || pFormNode->HasRemovedChildren()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1963 | continue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1964 | pContainerWidgetData = pFormNode->GetContainerWidgetData(); |
| 1965 | if (pContainerWidgetData) { |
| 1966 | pContainerWidgetData->GetPictureContent(wsPicture, |
| 1967 | XFA_VALUEPICTURE_DataBind); |
| 1968 | } |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 1969 | if (!wsPicture.IsEmpty()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1970 | break; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1971 | pContainerWidgetData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1972 | } |
| 1973 | } else if (GetPacketID() == XFA_XDPPACKET_Form) { |
| 1974 | pContainerWidgetData = GetContainerWidgetData(); |
| 1975 | } |
| 1976 | if (pContainerWidgetData) { |
tsepez | 6f167c3 | 2016-04-14 15:46:27 -0700 | [diff] [blame] | 1977 | pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1978 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1979 | SetScriptContent(wsNewValue, wsFormatValue, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1980 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1981 | CFX_WideString content = GetScriptContent(true); |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1982 | if (content.IsEmpty() && eType != XFA_Element::Text && |
| 1983 | eType != XFA_Element::SubmitUrl) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1984 | pValue->SetNull(); |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1985 | } else if (eType == XFA_Element::Integer) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1986 | pValue->SetInteger(FXSYS_wtoi(content.c_str())); |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1987 | } else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1988 | CFX_Decimal decimal(content.AsStringC()); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1989 | pValue->SetFloat((float)(double)decimal); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1990 | } else { |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 1991 | pValue->SetString(content.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1992 | } |
| 1993 | } |
| 1994 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1995 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1996 | void CXFA_Node::Script_Som_DefaultValue_Read(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1997 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1998 | XFA_ATTRIBUTE eAttribute) { |
| 1999 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2000 | ThrowInvalidPropertyException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2001 | return; |
| 2002 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2003 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2004 | CFX_WideString content = GetScriptContent(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2005 | if (content.IsEmpty()) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2006 | pValue->SetNull(); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2007 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2008 | } |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2009 | pValue->SetString(content.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2010 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2011 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2012 | void CXFA_Node::Script_Boolean_Value(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2013 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2014 | XFA_ATTRIBUTE eAttribute) { |
| 2015 | if (bSetting) { |
| 2016 | CFX_ByteString newValue; |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 2017 | if (!(pValue && (pValue->IsNull() || pValue->IsUndefined()))) |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2018 | newValue = pValue->ToString(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2019 | |
tsepez | b4c9f3f | 2016-04-13 15:41:21 -0700 | [diff] [blame] | 2020 | int32_t iValue = FXSYS_atoi(newValue.c_str()); |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 2021 | CFX_WideString wsNewValue(iValue == 0 ? L"0" : L"1"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2022 | CFX_WideString wsFormatValue(wsNewValue); |
| 2023 | CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData(); |
| 2024 | if (pContainerWidgetData) { |
tsepez | 6f167c3 | 2016-04-14 15:46:27 -0700 | [diff] [blame] | 2025 | pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2026 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2027 | SetScriptContent(wsNewValue, wsFormatValue, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2028 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2029 | CFX_WideString wsValue = GetScriptContent(true); |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 2030 | pValue->SetBoolean(wsValue == L"1"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2031 | } |
| 2032 | } |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2033 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2034 | void CXFA_Node::Script_Som_BorderColor(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2035 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2036 | XFA_ATTRIBUTE eAttribute) { |
| 2037 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2038 | if (!pWidgetData) { |
| 2039 | return; |
| 2040 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2041 | CXFA_Border border = pWidgetData->GetBorder(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2042 | int32_t iSize = border.CountEdges(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2043 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2044 | int32_t r = 0; |
| 2045 | int32_t g = 0; |
| 2046 | int32_t b = 0; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2047 | StrToRGB(pValue->ToWideString(), r, g, b); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2048 | FX_ARGB rgb = ArgbEncode(100, r, g, b); |
| 2049 | for (int32_t i = 0; i < iSize; ++i) { |
| 2050 | CXFA_Edge edge = border.GetEdge(i); |
| 2051 | edge.SetColor(rgb); |
| 2052 | } |
| 2053 | } else { |
| 2054 | CXFA_Edge edge = border.GetEdge(0); |
| 2055 | FX_ARGB color = edge.GetColor(); |
Nicolas Pena | ddfc3dc | 2017-04-20 15:29:25 -0400 | [diff] [blame] | 2056 | int32_t a; |
| 2057 | int32_t r; |
| 2058 | int32_t g; |
| 2059 | int32_t b; |
| 2060 | std::tie(a, r, g, b) = ArgbDecode(color); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2061 | CFX_WideString strColor; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2062 | strColor.Format(L"%d,%d,%d", r, g, b); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2063 | pValue->SetString(strColor.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2064 | } |
| 2065 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2066 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2067 | void CXFA_Node::Script_Som_BorderWidth(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2068 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2069 | XFA_ATTRIBUTE eAttribute) { |
| 2070 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2071 | if (!pWidgetData) { |
| 2072 | return; |
| 2073 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2074 | CXFA_Border border = pWidgetData->GetBorder(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2075 | int32_t iSize = border.CountEdges(); |
| 2076 | CFX_WideString wsThickness; |
| 2077 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2078 | wsThickness = pValue->ToWideString(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2079 | for (int32_t i = 0; i < iSize; ++i) { |
| 2080 | CXFA_Edge edge = border.GetEdge(i); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2081 | CXFA_Measurement thickness(wsThickness.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2082 | edge.SetMSThickness(thickness); |
| 2083 | } |
| 2084 | } else { |
| 2085 | CXFA_Edge edge = border.GetEdge(0); |
| 2086 | CXFA_Measurement thickness = edge.GetMSThickness(); |
| 2087 | thickness.ToString(wsThickness); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2088 | pValue->SetString(wsThickness.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2089 | } |
| 2090 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2091 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2092 | void CXFA_Node::Script_Som_FillColor(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2093 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2094 | XFA_ATTRIBUTE eAttribute) { |
| 2095 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2096 | if (!pWidgetData) { |
| 2097 | return; |
| 2098 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2099 | CXFA_Border border = pWidgetData->GetBorder(true); |
| 2100 | CXFA_Fill borderfill = border.GetFill(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2101 | CXFA_Node* pNode = borderfill.GetNode(); |
| 2102 | if (!pNode) { |
| 2103 | return; |
| 2104 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2105 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2106 | int32_t r; |
| 2107 | int32_t g; |
| 2108 | int32_t b; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2109 | StrToRGB(pValue->ToWideString(), r, g, b); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2110 | FX_ARGB color = ArgbEncode(0xff, r, g, b); |
| 2111 | borderfill.SetColor(color); |
| 2112 | } else { |
| 2113 | FX_ARGB color = borderfill.GetColor(); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2114 | int32_t a; |
| 2115 | int32_t r; |
| 2116 | int32_t g; |
| 2117 | int32_t b; |
Nicolas Pena | ddfc3dc | 2017-04-20 15:29:25 -0400 | [diff] [blame] | 2118 | std::tie(a, r, g, b) = ArgbDecode(color); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2119 | CFX_WideString wsColor; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2120 | wsColor.Format(L"%d,%d,%d", r, g, b); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2121 | pValue->SetString(wsColor.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2122 | } |
| 2123 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2124 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2125 | void CXFA_Node::Script_Som_DataNode(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2126 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2127 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2128 | if (bSetting) { |
| 2129 | ThrowInvalidPropertyException(); |
| 2130 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2131 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2132 | |
| 2133 | CXFA_Node* pDataNode = GetBindData(); |
| 2134 | if (!pDataNode) { |
| 2135 | pValue->SetNull(); |
| 2136 | return; |
| 2137 | } |
| 2138 | |
| 2139 | pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pDataNode)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2140 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2141 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2142 | void CXFA_Node::Script_Draw_DefaultValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2143 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2144 | XFA_ATTRIBUTE eAttribute) { |
| 2145 | if (bSetting) { |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 2146 | if (pValue && pValue->IsString()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2147 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 2148 | ASSERT(pWidgetData); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 2149 | XFA_Element uiType = pWidgetData->GetUIType(); |
| 2150 | if (uiType == XFA_Element::Text) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2151 | CFX_WideString wsNewValue = pValue->ToWideString(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2152 | CFX_WideString wsFormatValue(wsNewValue); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2153 | SetScriptContent(wsNewValue, wsFormatValue, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2154 | } |
| 2155 | } |
| 2156 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2157 | CFX_WideString content = GetScriptContent(true); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2158 | if (content.IsEmpty()) |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2159 | pValue->SetNull(); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2160 | else |
| 2161 | pValue->SetString(content.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2162 | } |
| 2163 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2164 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2165 | void CXFA_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2166 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2167 | XFA_ATTRIBUTE eAttribute) { |
| 2168 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2169 | if (!pWidgetData) { |
| 2170 | return; |
| 2171 | } |
| 2172 | if (bSetting) { |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 2173 | if (pValue && pValue->IsNull()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2174 | pWidgetData->m_bPreNull = pWidgetData->m_bIsNull; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2175 | pWidgetData->m_bIsNull = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2176 | } else { |
| 2177 | pWidgetData->m_bPreNull = pWidgetData->m_bIsNull; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2178 | pWidgetData->m_bIsNull = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2179 | } |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2180 | CFX_WideString wsNewText; |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 2181 | if (!(pValue && (pValue->IsNull() || pValue->IsUndefined()))) |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2182 | wsNewText = pValue->ToWideString(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2183 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2184 | CXFA_Node* pUIChild = pWidgetData->GetUIChild(); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2185 | if (pUIChild->GetElementType() == XFA_Element::NumericEdit) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2186 | int32_t iLeadDigits = 0; |
| 2187 | int32_t iFracDigits = 0; |
| 2188 | pWidgetData->GetLeadDigits(iLeadDigits); |
| 2189 | pWidgetData->GetFracDigits(iFracDigits); |
dsinclair | 44d054c | 2016-04-06 10:23:46 -0700 | [diff] [blame] | 2190 | wsNewText = |
| 2191 | pWidgetData->NumericLimit(wsNewText, iLeadDigits, iFracDigits); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2192 | } |
| 2193 | CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData(); |
| 2194 | CFX_WideString wsFormatText(wsNewText); |
| 2195 | if (pContainerWidgetData) { |
tsepez | 6f167c3 | 2016-04-14 15:46:27 -0700 | [diff] [blame] | 2196 | pContainerWidgetData->GetFormatDataValue(wsNewText, wsFormatText); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2197 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2198 | SetScriptContent(wsNewText, wsFormatText, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2199 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2200 | CFX_WideString content = GetScriptContent(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2201 | if (content.IsEmpty()) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2202 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2203 | } else { |
| 2204 | CXFA_Node* pUIChild = pWidgetData->GetUIChild(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2205 | CXFA_Value defVal = pWidgetData->GetFormValue(); |
| 2206 | CXFA_Node* pNode = defVal.GetNode()->GetNodeItem(XFA_NODEITEM_FirstChild); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2207 | if (pNode && pNode->GetElementType() == XFA_Element::Decimal) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 2208 | if (pUIChild->GetElementType() == XFA_Element::NumericEdit && |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2209 | (pNode->GetInteger(XFA_ATTRIBUTE_FracDigits) == -1)) { |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2210 | pValue->SetString(content.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2211 | } else { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2212 | CFX_Decimal decimal(content.AsStringC()); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 2213 | pValue->SetFloat((float)(double)decimal); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2214 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2215 | } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2216 | pValue->SetInteger(FXSYS_wtoi(content.c_str())); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2217 | } else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2218 | pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? false : true); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2219 | } else if (pNode && pNode->GetElementType() == XFA_Element::Float) { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2220 | CFX_Decimal decimal(content.AsStringC()); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 2221 | pValue->SetFloat((float)(double)decimal); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2222 | } else { |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2223 | pValue->SetString(content.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2224 | } |
| 2225 | } |
| 2226 | } |
| 2227 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2228 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2229 | void CXFA_Node::Script_Field_EditValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2230 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2231 | XFA_ATTRIBUTE eAttribute) { |
| 2232 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2233 | if (!pWidgetData) { |
| 2234 | return; |
| 2235 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2236 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2237 | pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Edit); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2238 | } else { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2239 | CFX_WideString wsValue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2240 | pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Edit); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2241 | pValue->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2242 | } |
| 2243 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2244 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2245 | void CXFA_Node::Script_Som_FontColor(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2246 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2247 | XFA_ATTRIBUTE eAttribute) { |
| 2248 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2249 | if (!pWidgetData) { |
| 2250 | return; |
| 2251 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2252 | CXFA_Font font = pWidgetData->GetFont(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2253 | CXFA_Node* pNode = font.GetNode(); |
| 2254 | if (!pNode) { |
| 2255 | return; |
| 2256 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2257 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2258 | int32_t r; |
| 2259 | int32_t g; |
| 2260 | int32_t b; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2261 | StrToRGB(pValue->ToWideString(), r, g, b); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2262 | FX_ARGB color = ArgbEncode(0xff, r, g, b); |
| 2263 | font.SetColor(color); |
| 2264 | } else { |
| 2265 | FX_ARGB color = font.GetColor(); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2266 | int32_t a; |
| 2267 | int32_t r; |
| 2268 | int32_t g; |
| 2269 | int32_t b; |
Nicolas Pena | ddfc3dc | 2017-04-20 15:29:25 -0400 | [diff] [blame] | 2270 | std::tie(a, r, g, b) = ArgbDecode(color); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2271 | CFX_WideString wsColor; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2272 | wsColor.Format(L"%d,%d,%d", r, g, b); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2273 | pValue->SetString(wsColor.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2274 | } |
| 2275 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2276 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2277 | void CXFA_Node::Script_Field_FormatMessage(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2278 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2279 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2280 | Script_Som_Message(pValue, bSetting, XFA_SOM_FormatMessage); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2281 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2282 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2283 | void CXFA_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2284 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2285 | XFA_ATTRIBUTE eAttribute) { |
| 2286 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2287 | if (!pWidgetData) { |
| 2288 | return; |
| 2289 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2290 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2291 | pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Display); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2292 | } else { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2293 | CFX_WideString wsValue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2294 | pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Display); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2295 | pValue->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2296 | } |
| 2297 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2298 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2299 | void CXFA_Node::Script_Som_Mandatory(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2300 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2301 | XFA_ATTRIBUTE eAttribute) { |
| 2302 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2303 | if (!pWidgetData) { |
| 2304 | return; |
| 2305 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2306 | CXFA_Validate validate = pWidgetData->GetValidate(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2307 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2308 | validate.SetNullTest(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2309 | } else { |
| 2310 | int32_t iValue = validate.GetNullTest(); |
| 2311 | const XFA_ATTRIBUTEENUMINFO* pInfo = |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 2312 | GetAttributeEnumByID((XFA_ATTRIBUTEENUM)iValue); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2313 | CFX_WideString wsValue; |
| 2314 | if (pInfo) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2315 | wsValue = pInfo->pName; |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2316 | pValue->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2317 | } |
| 2318 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2319 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2320 | void CXFA_Node::Script_Som_MandatoryMessage(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2321 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2322 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2323 | Script_Som_Message(pValue, bSetting, XFA_SOM_MandatoryMessage); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2324 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2325 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2326 | void CXFA_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2327 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2328 | XFA_ATTRIBUTE eAttribute) { |
| 2329 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2330 | ThrowInvalidPropertyException(); |
| 2331 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2332 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2333 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2334 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2335 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2336 | void CXFA_Node::Script_Field_SelectedIndex(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2337 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2338 | XFA_ATTRIBUTE eAttribute) { |
| 2339 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2340 | if (!pWidgetData) { |
| 2341 | return; |
| 2342 | } |
| 2343 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2344 | int32_t iIndex = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2345 | if (iIndex == -1) { |
| 2346 | pWidgetData->ClearAllSelections(); |
| 2347 | return; |
| 2348 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2349 | pWidgetData->SetItemState(iIndex, true, true, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2350 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2351 | pValue->SetInteger(pWidgetData->GetSelectedItem()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2352 | } |
| 2353 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2354 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2355 | void CXFA_Node::Script_Field_ClearItems(CFXJSE_Arguments* pArguments) { |
| 2356 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2357 | if (!pWidgetData) { |
| 2358 | return; |
| 2359 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2360 | pWidgetData->DeleteItem(-1, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2361 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2362 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2363 | void CXFA_Node::Script_Field_ExecEvent(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2364 | if (pArguments->GetLength() != 1) { |
| 2365 | ThrowParamCountMismatchException(L"execEvent"); |
| 2366 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2367 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2368 | |
| 2369 | CFX_ByteString eventString = pArguments->GetUTF8String(0); |
| 2370 | int32_t iRet = execSingleEventByName( |
| 2371 | CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(), |
| 2372 | XFA_Element::Field); |
| 2373 | if (eventString != "validate") |
| 2374 | return; |
| 2375 | |
| 2376 | pArguments->GetReturnValue()->SetBoolean( |
| 2377 | (iRet == XFA_EVENTERROR_Error) ? false : true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2378 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2379 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2380 | void CXFA_Node::Script_Field_ExecInitialize(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2381 | if (pArguments->GetLength() != 0) { |
| 2382 | ThrowParamCountMismatchException(L"execInitialize"); |
| 2383 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2384 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2385 | |
| 2386 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2387 | if (!pNotify) |
| 2388 | return; |
| 2389 | |
| 2390 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize, false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2391 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2392 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2393 | void CXFA_Node::Script_Field_DeleteItem(CFXJSE_Arguments* pArguments) { |
| 2394 | int32_t iLength = pArguments->GetLength(); |
| 2395 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2396 | ThrowParamCountMismatchException(L"deleteItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2397 | return; |
| 2398 | } |
| 2399 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2400 | if (!pWidgetData) { |
| 2401 | return; |
| 2402 | } |
| 2403 | int32_t iIndex = pArguments->GetInt32(0); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2404 | bool bValue = pWidgetData->DeleteItem(iIndex, true, true); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2405 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2406 | if (pValue) |
| 2407 | pValue->SetBoolean(bValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2408 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2409 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2410 | void CXFA_Node::Script_Field_GetSaveItem(CFXJSE_Arguments* pArguments) { |
| 2411 | int32_t iLength = pArguments->GetLength(); |
| 2412 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2413 | ThrowParamCountMismatchException(L"getSaveItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2414 | return; |
| 2415 | } |
| 2416 | int32_t iIndex = pArguments->GetInt32(0); |
| 2417 | if (iIndex < 0) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2418 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2419 | return; |
| 2420 | } |
| 2421 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2422 | if (!pWidgetData) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2423 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2424 | return; |
| 2425 | } |
| 2426 | CFX_WideString wsValue; |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2427 | if (!pWidgetData->GetChoiceListItem(wsValue, iIndex, true)) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2428 | pArguments->GetReturnValue()->SetNull(); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2429 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2430 | } |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2431 | pArguments->GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2432 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2433 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2434 | void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments) { |
| 2435 | int32_t iLength = pArguments->GetLength(); |
| 2436 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2437 | ThrowParamCountMismatchException(L"boundItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2438 | return; |
| 2439 | } |
| 2440 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2441 | if (!pWidgetData) { |
| 2442 | return; |
| 2443 | } |
| 2444 | CFX_ByteString bsValue = pArguments->GetUTF8String(0); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2445 | CFX_WideString wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2446 | CFX_WideString wsBoundValue; |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2447 | pWidgetData->GetItemValue(wsValue.AsStringC(), wsBoundValue); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2448 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2449 | if (pValue) |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2450 | pValue->SetString(wsBoundValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2451 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2452 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2453 | void CXFA_Node::Script_Field_GetItemState(CFXJSE_Arguments* pArguments) { |
| 2454 | int32_t iLength = pArguments->GetLength(); |
| 2455 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2456 | ThrowParamCountMismatchException(L"getItemState"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2457 | return; |
| 2458 | } |
| 2459 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2460 | if (!pWidgetData) { |
| 2461 | return; |
| 2462 | } |
| 2463 | int32_t iIndex = pArguments->GetInt32(0); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2464 | bool bValue = pWidgetData->GetItemState(iIndex); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2465 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2466 | if (pValue) |
| 2467 | pValue->SetBoolean(bValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2468 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2469 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2470 | void CXFA_Node::Script_Field_ExecCalculate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2471 | if (pArguments->GetLength() != 0) { |
| 2472 | ThrowParamCountMismatchException(L"execCalculate"); |
| 2473 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2474 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2475 | |
| 2476 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2477 | if (!pNotify) |
| 2478 | return; |
| 2479 | |
| 2480 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate, false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2481 | } |
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_SetItems(CFXJSE_Arguments* pArguments) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2484 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2485 | void CXFA_Node::Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments) { |
| 2486 | int32_t iLength = pArguments->GetLength(); |
| 2487 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2488 | ThrowParamCountMismatchException(L"getDisplayItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2489 | return; |
| 2490 | } |
| 2491 | int32_t iIndex = pArguments->GetInt32(0); |
| 2492 | if (iIndex < 0) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2493 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2494 | return; |
| 2495 | } |
| 2496 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2497 | if (!pWidgetData) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2498 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2499 | return; |
| 2500 | } |
| 2501 | CFX_WideString wsValue; |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2502 | if (!pWidgetData->GetChoiceListItem(wsValue, iIndex, false)) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2503 | pArguments->GetReturnValue()->SetNull(); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2504 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2505 | } |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2506 | pArguments->GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2507 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2508 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2509 | void CXFA_Node::Script_Field_SetItemState(CFXJSE_Arguments* pArguments) { |
| 2510 | int32_t iLength = pArguments->GetLength(); |
| 2511 | if (iLength != 2) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2512 | ThrowParamCountMismatchException(L"setItemState"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2513 | return; |
| 2514 | } |
| 2515 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2516 | if (!pWidgetData) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2517 | return; |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2518 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2519 | int32_t iIndex = pArguments->GetInt32(0); |
| 2520 | if (pArguments->GetInt32(1) != 0) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2521 | pWidgetData->SetItemState(iIndex, true, true, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2522 | } else { |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2523 | if (pWidgetData->GetItemState(iIndex)) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2524 | pWidgetData->SetItemState(iIndex, false, true, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2525 | } |
| 2526 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2527 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2528 | void CXFA_Node::Script_Field_AddItem(CFXJSE_Arguments* pArguments) { |
| 2529 | int32_t iLength = pArguments->GetLength(); |
| 2530 | if (iLength < 1 || iLength > 2) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2531 | ThrowParamCountMismatchException(L"addItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2532 | return; |
| 2533 | } |
| 2534 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2535 | if (!pWidgetData) { |
| 2536 | return; |
| 2537 | } |
| 2538 | CFX_WideString wsLabel; |
| 2539 | CFX_WideString wsValue; |
| 2540 | if (iLength >= 1) { |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 2541 | CFX_ByteString bsLabel = pArguments->GetUTF8String(0); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2542 | wsLabel = CFX_WideString::FromUTF8(bsLabel.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2543 | } |
| 2544 | if (iLength >= 2) { |
| 2545 | CFX_ByteString bsValue = pArguments->GetUTF8String(1); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2546 | wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2547 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2548 | pWidgetData->InsertItem(wsLabel, wsValue, -1, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2549 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2550 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2551 | void CXFA_Node::Script_Field_ExecValidate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2552 | if (pArguments->GetLength() != 0) { |
| 2553 | ThrowParamCountMismatchException(L"execValidate"); |
| 2554 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2555 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2556 | |
| 2557 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2558 | if (!pNotify) { |
| 2559 | pArguments->GetReturnValue()->SetBoolean(false); |
| 2560 | return; |
| 2561 | } |
| 2562 | |
| 2563 | int32_t iRet = |
| 2564 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate, false, false); |
| 2565 | pArguments->GetReturnValue()->SetBoolean( |
| 2566 | (iRet == XFA_EVENTERROR_Error) ? false : true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2567 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2568 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2569 | void CXFA_Node::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2570 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2571 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2572 | if (bSetting) |
| 2573 | ThrowInvalidPropertyException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2574 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2575 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2576 | void CXFA_Node::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2577 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2578 | XFA_ATTRIBUTE eAttribute) { |
| 2579 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2580 | if (!pWidgetData) { |
| 2581 | return; |
| 2582 | } |
| 2583 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2584 | pWidgetData->SetSelectedMemberByValue(pValue->ToWideString().AsStringC(), |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2585 | true, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2586 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2587 | CFX_WideString wsValue = GetScriptContent(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2588 | XFA_VERSION curVersion = GetDocument()->GetCurVersionMode(); |
| 2589 | if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2590 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2591 | } else { |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2592 | pValue->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2593 | } |
| 2594 | } |
| 2595 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2596 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2597 | void CXFA_Node::Script_ExclGroup_Transient(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2598 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2599 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2600 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2601 | void CXFA_Node::Script_ExclGroup_ExecEvent(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2602 | if (pArguments->GetLength() != 1) { |
| 2603 | ThrowParamCountMismatchException(L"execEvent"); |
| 2604 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2605 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2606 | |
| 2607 | CFX_ByteString eventString = pArguments->GetUTF8String(0); |
| 2608 | execSingleEventByName( |
| 2609 | CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(), |
| 2610 | XFA_Element::ExclGroup); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2611 | } |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2612 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2613 | void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments) { |
| 2614 | int32_t argc = pArguments->GetLength(); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2615 | if (argc < 0 || argc > 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2616 | ThrowParamCountMismatchException(L"selectedMember"); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2617 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2618 | } |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2619 | |
| 2620 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2621 | if (!pWidgetData) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2622 | pArguments->GetReturnValue()->SetNull(); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2623 | return; |
| 2624 | } |
| 2625 | |
| 2626 | CXFA_Node* pReturnNode = nullptr; |
| 2627 | if (argc == 0) { |
| 2628 | pReturnNode = pWidgetData->GetSelectedMember(); |
| 2629 | } else { |
| 2630 | CFX_ByteString szName; |
| 2631 | szName = pArguments->GetUTF8String(0); |
| 2632 | pReturnNode = pWidgetData->SetSelectedMember( |
| 2633 | CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC(), true); |
| 2634 | } |
| 2635 | if (!pReturnNode) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2636 | pArguments->GetReturnValue()->SetNull(); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2637 | return; |
| 2638 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2639 | pArguments->GetReturnValue()->Assign( |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2640 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pReturnNode)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2641 | } |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2642 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2643 | void CXFA_Node::Script_ExclGroup_ExecInitialize(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2644 | if (pArguments->GetLength() != 0) { |
| 2645 | ThrowParamCountMismatchException(L"execInitialize"); |
| 2646 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2647 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2648 | |
| 2649 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2650 | if (!pNotify) |
| 2651 | return; |
| 2652 | |
| 2653 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2654 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2655 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2656 | void CXFA_Node::Script_ExclGroup_ExecCalculate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2657 | if (pArguments->GetLength() != 0) { |
| 2658 | ThrowParamCountMismatchException(L"execCalculate"); |
| 2659 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2660 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2661 | |
| 2662 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2663 | if (!pNotify) |
| 2664 | return; |
| 2665 | |
| 2666 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2667 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2668 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2669 | void CXFA_Node::Script_ExclGroup_ExecValidate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2670 | if (pArguments->GetLength() != 0) { |
| 2671 | ThrowParamCountMismatchException(L"execValidate"); |
| 2672 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2673 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2674 | |
| 2675 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2676 | if (!pNotify) { |
| 2677 | pArguments->GetReturnValue()->SetBoolean(false); |
| 2678 | return; |
| 2679 | } |
| 2680 | |
| 2681 | int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); |
| 2682 | pArguments->GetReturnValue()->SetBoolean( |
| 2683 | (iRet == XFA_EVENTERROR_Error) ? false : true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2684 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2685 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2686 | void CXFA_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2687 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2688 | XFA_ATTRIBUTE eAttribute) { |
| 2689 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2690 | int32_t iTo = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2691 | int32_t iFrom = Subform_and_SubformSet_InstanceIndex(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 2692 | CXFA_Node* pManagerNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2693 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; |
| 2694 | pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2695 | if (pNode->GetElementType() == XFA_Element::InstanceManager) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2696 | pManagerNode = pNode; |
| 2697 | break; |
| 2698 | } |
| 2699 | } |
| 2700 | if (pManagerNode) { |
| 2701 | pManagerNode->InstanceManager_MoveInstance(iTo, iFrom); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2702 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2703 | if (!pNotify) { |
| 2704 | return; |
| 2705 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2706 | CXFA_Node* pToInstance = GetItem(pManagerNode, iTo); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2707 | if (pToInstance && |
| 2708 | pToInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2709 | pNotify->RunSubformIndexChange(pToInstance); |
| 2710 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2711 | CXFA_Node* pFromInstance = GetItem(pManagerNode, iFrom); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 2712 | if (pFromInstance && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2713 | pFromInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2714 | pNotify->RunSubformIndexChange(pFromInstance); |
| 2715 | } |
| 2716 | } |
| 2717 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2718 | pValue->SetInteger(Subform_and_SubformSet_InstanceIndex()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2719 | } |
| 2720 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2721 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2722 | void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2723 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2724 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2725 | if (bSetting) { |
| 2726 | ThrowInvalidPropertyException(); |
| 2727 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2728 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2729 | |
| 2730 | CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name); |
| 2731 | CXFA_Node* pInstanceMgr = nullptr; |
| 2732 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; |
| 2733 | pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { |
| 2734 | if (pNode->GetElementType() == XFA_Element::InstanceManager) { |
| 2735 | CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name); |
| 2736 | if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' && |
| 2737 | wsInstMgrName.Mid(1) == wsName) { |
| 2738 | pInstanceMgr = pNode; |
| 2739 | } |
| 2740 | break; |
| 2741 | } |
| 2742 | } |
| 2743 | if (!pInstanceMgr) { |
| 2744 | pValue->SetNull(); |
| 2745 | return; |
| 2746 | } |
| 2747 | |
| 2748 | pValue->Assign( |
| 2749 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pInstanceMgr)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2750 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2751 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2752 | void CXFA_Node::Script_Subform_Locale(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2753 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2754 | XFA_ATTRIBUTE eAttribute) { |
| 2755 | if (bSetting) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2756 | SetCData(XFA_ATTRIBUTE_Locale, pValue->ToWideString(), true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2757 | } else { |
| 2758 | CFX_WideString wsLocaleName; |
| 2759 | GetLocaleName(wsLocaleName); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2760 | pValue->SetString(wsLocaleName.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2761 | } |
| 2762 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2763 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2764 | void CXFA_Node::Script_Subform_ExecEvent(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2765 | if (pArguments->GetLength() != 1) { |
| 2766 | ThrowParamCountMismatchException(L"execEvent"); |
| 2767 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2768 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2769 | |
| 2770 | CFX_ByteString eventString = pArguments->GetUTF8String(0); |
| 2771 | execSingleEventByName( |
| 2772 | CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(), |
| 2773 | XFA_Element::Subform); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2774 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2775 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2776 | void CXFA_Node::Script_Subform_ExecInitialize(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2777 | if (pArguments->GetLength() != 0) { |
| 2778 | ThrowParamCountMismatchException(L"execInitialize"); |
| 2779 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2780 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2781 | |
| 2782 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2783 | if (!pNotify) |
| 2784 | return; |
| 2785 | |
| 2786 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2787 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2788 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2789 | void CXFA_Node::Script_Subform_ExecCalculate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2790 | if (pArguments->GetLength() != 0) { |
| 2791 | ThrowParamCountMismatchException(L"execCalculate"); |
| 2792 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2793 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2794 | |
| 2795 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2796 | if (!pNotify) |
| 2797 | return; |
| 2798 | |
| 2799 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2800 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2801 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2802 | void CXFA_Node::Script_Subform_ExecValidate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2803 | if (pArguments->GetLength() != 0) { |
| 2804 | ThrowParamCountMismatchException(L"execValidate"); |
| 2805 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2806 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2807 | |
| 2808 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2809 | if (!pNotify) { |
| 2810 | pArguments->GetReturnValue()->SetBoolean(false); |
| 2811 | return; |
| 2812 | } |
| 2813 | |
| 2814 | int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); |
| 2815 | pArguments->GetReturnValue()->SetBoolean( |
| 2816 | (iRet == XFA_EVENTERROR_Error) ? false : true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2817 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2818 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2819 | void CXFA_Node::Script_Subform_GetInvalidObjects(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2820 | if (pArguments->GetLength() != 0) |
| 2821 | ThrowParamCountMismatchException(L"getInvalidObjects"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2822 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2823 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2824 | int32_t CXFA_Node::Subform_and_SubformSet_InstanceIndex() { |
| 2825 | int32_t index = 0; |
| 2826 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; |
| 2827 | pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2828 | if ((pNode->GetElementType() == XFA_Element::Subform) || |
| 2829 | (pNode->GetElementType() == XFA_Element::SubformSet)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2830 | index++; |
| 2831 | } else { |
| 2832 | break; |
| 2833 | } |
| 2834 | } |
| 2835 | return index; |
| 2836 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2837 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2838 | void CXFA_Node::Script_Template_FormNodes(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2839 | if (pArguments->GetLength() != 1) { |
| 2840 | ThrowParamCountMismatchException(L"formNodes"); |
| 2841 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2842 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2843 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2844 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2845 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2846 | void CXFA_Node::Script_Template_Remerge(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2847 | if (pArguments->GetLength() != 0) { |
| 2848 | ThrowParamCountMismatchException(L"remerge"); |
| 2849 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2850 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2851 | m_pDocument->DoDataRemerge(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2852 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2853 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2854 | void CXFA_Node::Script_Template_ExecInitialize(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2855 | if (pArguments->GetLength() != 0) { |
| 2856 | ThrowParamCountMismatchException(L"execInitialize"); |
| 2857 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2858 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2859 | |
| 2860 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2861 | if (!pWidgetData) { |
| 2862 | pArguments->GetReturnValue()->SetBoolean(false); |
| 2863 | return; |
| 2864 | } |
| 2865 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2866 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2867 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2868 | void CXFA_Node::Script_Template_CreateNode(CFXJSE_Arguments* pArguments) { |
| 2869 | int32_t argc = pArguments->GetLength(); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2870 | if (argc <= 0 || argc >= 4) { |
| 2871 | ThrowParamCountMismatchException(L"createNode"); |
| 2872 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2873 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2874 | |
| 2875 | CFX_WideString strName; |
| 2876 | CFX_WideString strNameSpace; |
| 2877 | CFX_ByteString bsTagName = pArguments->GetUTF8String(0); |
| 2878 | CFX_WideString strTagName = CFX_WideString::FromUTF8(bsTagName.AsStringC()); |
| 2879 | if (argc > 1) { |
| 2880 | CFX_ByteString bsName = pArguments->GetUTF8String(1); |
| 2881 | strName = CFX_WideString::FromUTF8(bsName.AsStringC()); |
| 2882 | if (argc == 3) { |
| 2883 | CFX_ByteString bsNameSpace = pArguments->GetUTF8String(2); |
| 2884 | strNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC()); |
| 2885 | } |
| 2886 | } |
| 2887 | |
| 2888 | XFA_Element eType = XFA_GetElementTypeForName(strTagName.AsStringC()); |
| 2889 | CXFA_Node* pNewNode = CreateSamePacketNode(eType); |
| 2890 | if (!pNewNode) { |
| 2891 | pArguments->GetReturnValue()->SetNull(); |
| 2892 | return; |
| 2893 | } |
| 2894 | |
| 2895 | if (strName.IsEmpty()) { |
| 2896 | pArguments->GetReturnValue()->Assign( |
| 2897 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode)); |
| 2898 | return; |
| 2899 | } |
| 2900 | |
| 2901 | if (!GetAttributeOfElement(eType, XFA_ATTRIBUTE_Name, |
| 2902 | XFA_XDPPACKET_UNKNOWN)) { |
| 2903 | ThrowMissingPropertyException(strTagName, L"name"); |
| 2904 | return; |
| 2905 | } |
| 2906 | |
| 2907 | pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, strName.AsStringC(), true); |
| 2908 | if (pNewNode->GetPacketID() == XFA_XDPPACKET_Datasets) |
| 2909 | pNewNode->CreateXMLMappingNode(); |
| 2910 | |
| 2911 | pArguments->GetReturnValue()->Assign( |
| 2912 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2913 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2914 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2915 | void CXFA_Node::Script_Template_Recalculate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2916 | if (pArguments->GetLength() != 1) { |
| 2917 | ThrowParamCountMismatchException(L"recalculate"); |
| 2918 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2919 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2920 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2921 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2922 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2923 | void CXFA_Node::Script_Template_ExecCalculate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2924 | if (pArguments->GetLength() != 0) { |
| 2925 | ThrowParamCountMismatchException(L"execCalculate"); |
| 2926 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2927 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2928 | |
| 2929 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2930 | if (!pWidgetData) { |
| 2931 | pArguments->GetReturnValue()->SetBoolean(false); |
| 2932 | return; |
| 2933 | } |
| 2934 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2935 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2936 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2937 | void CXFA_Node::Script_Template_ExecValidate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2938 | if (pArguments->GetLength() != 0) { |
| 2939 | ThrowParamCountMismatchException(L"execValidate"); |
| 2940 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2941 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2942 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2943 | if (!pWidgetData) { |
| 2944 | pArguments->GetReturnValue()->SetBoolean(false); |
| 2945 | return; |
| 2946 | } |
| 2947 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2948 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2949 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2950 | void CXFA_Node::Script_Manifest_Evaluate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2951 | if (pArguments->GetLength() != 0) { |
| 2952 | ThrowParamCountMismatchException(L"evaluate"); |
| 2953 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2954 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2955 | |
| 2956 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2957 | if (!pWidgetData) { |
| 2958 | pArguments->GetReturnValue()->SetBoolean(false); |
| 2959 | return; |
| 2960 | } |
| 2961 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2962 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2963 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2964 | void CXFA_Node::Script_InstanceManager_Max(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2965 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2966 | XFA_ATTRIBUTE eAttribute) { |
| 2967 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2968 | ThrowInvalidPropertyException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2969 | return; |
| 2970 | } |
| 2971 | CXFA_Occur nodeOccur(GetOccurNode()); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2972 | pValue->SetInteger(nodeOccur.GetMax()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2973 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2974 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2975 | void CXFA_Node::Script_InstanceManager_Min(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2976 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2977 | XFA_ATTRIBUTE eAttribute) { |
| 2978 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2979 | ThrowInvalidPropertyException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2980 | return; |
| 2981 | } |
| 2982 | CXFA_Occur nodeOccur(GetOccurNode()); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2983 | pValue->SetInteger(nodeOccur.GetMin()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2984 | } |
tsepez | aadedf9 | 2016-05-12 10:08:06 -0700 | [diff] [blame] | 2985 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2986 | void CXFA_Node::Script_InstanceManager_Count(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2987 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2988 | XFA_ATTRIBUTE eAttribute) { |
| 2989 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2990 | int32_t iDesired = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2991 | InstanceManager_SetInstances(iDesired); |
| 2992 | } else { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2993 | pValue->SetInteger(GetCount(this)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2994 | } |
| 2995 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2996 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2997 | void CXFA_Node::Script_InstanceManager_MoveInstance( |
| 2998 | CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2999 | if (pArguments->GetLength() != 2) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3000 | pArguments->GetReturnValue()->SetUndefined(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3001 | return; |
| 3002 | } |
| 3003 | int32_t iFrom = pArguments->GetInt32(0); |
| 3004 | int32_t iTo = pArguments->GetInt32(1); |
| 3005 | InstanceManager_MoveInstance(iTo, iFrom); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3006 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3007 | if (!pNotify) { |
| 3008 | return; |
| 3009 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3010 | CXFA_Node* pToInstance = GetItem(this, iTo); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3011 | if (pToInstance && pToInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3012 | pNotify->RunSubformIndexChange(pToInstance); |
| 3013 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3014 | CXFA_Node* pFromInstance = GetItem(this, iFrom); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3015 | if (pFromInstance && |
| 3016 | pFromInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3017 | pNotify->RunSubformIndexChange(pFromInstance); |
| 3018 | } |
| 3019 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3020 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3021 | void CXFA_Node::Script_InstanceManager_RemoveInstance( |
| 3022 | CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3023 | if (pArguments->GetLength() != 1) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3024 | pArguments->GetReturnValue()->SetUndefined(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3025 | return; |
| 3026 | } |
| 3027 | int32_t iIndex = pArguments->GetInt32(0); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3028 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3029 | if (iIndex < 0 || iIndex >= iCount) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3030 | ThrowIndexOutOfBoundsException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3031 | return; |
| 3032 | } |
| 3033 | CXFA_Occur nodeOccur(GetOccurNode()); |
| 3034 | int32_t iMin = nodeOccur.GetMin(); |
| 3035 | if (iCount - 1 < iMin) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3036 | ThrowTooManyOccurancesException(L"min"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3037 | return; |
| 3038 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3039 | CXFA_Node* pRemoveInstance = GetItem(this, iIndex); |
| 3040 | RemoveItem(this, pRemoveInstance); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3041 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3042 | if (pNotify) { |
| 3043 | for (int32_t i = iIndex; i < iCount - 1; i++) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3044 | CXFA_Node* pSubformInstance = GetItem(this, i); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3045 | if (pSubformInstance && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3046 | pSubformInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3047 | pNotify->RunSubformIndexChange(pSubformInstance); |
| 3048 | } |
| 3049 | } |
| 3050 | } |
| 3051 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3052 | if (!pLayoutPro) { |
| 3053 | return; |
| 3054 | } |
| 3055 | pLayoutPro->AddChangedContainer( |
| 3056 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3057 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3058 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3059 | void CXFA_Node::Script_InstanceManager_SetInstances( |
| 3060 | CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3061 | if (pArguments->GetLength() != 1) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3062 | pArguments->GetReturnValue()->SetUndefined(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3063 | return; |
| 3064 | } |
| 3065 | int32_t iDesired = pArguments->GetInt32(0); |
| 3066 | InstanceManager_SetInstances(iDesired); |
| 3067 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3068 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3069 | void CXFA_Node::Script_InstanceManager_AddInstance( |
| 3070 | CFXJSE_Arguments* pArguments) { |
| 3071 | int32_t argc = pArguments->GetLength(); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3072 | if (argc != 0 && argc != 1) { |
| 3073 | ThrowParamCountMismatchException(L"addInstance"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3074 | return; |
| 3075 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3076 | bool fFlags = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3077 | if (argc == 1) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3078 | fFlags = pArguments->GetInt32(0) == 0 ? false : true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3079 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3080 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3081 | CXFA_Occur nodeOccur(GetOccurNode()); |
| 3082 | int32_t iMax = nodeOccur.GetMax(); |
| 3083 | if (iMax >= 0 && iCount >= iMax) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3084 | ThrowTooManyOccurancesException(L"max"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3085 | return; |
| 3086 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3087 | CXFA_Node* pNewInstance = CreateInstance(this, fFlags); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3088 | InsertItem(this, pNewInstance, iCount, iCount, false); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3089 | pArguments->GetReturnValue()->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3090 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance)); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3091 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3092 | if (!pNotify) { |
| 3093 | return; |
| 3094 | } |
| 3095 | pNotify->RunNodeInitialize(pNewInstance); |
| 3096 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3097 | if (!pLayoutPro) { |
| 3098 | return; |
| 3099 | } |
| 3100 | pLayoutPro->AddChangedContainer( |
| 3101 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3102 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3103 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3104 | void CXFA_Node::Script_InstanceManager_InsertInstance( |
| 3105 | CFXJSE_Arguments* pArguments) { |
| 3106 | int32_t argc = pArguments->GetLength(); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3107 | if (argc != 1 && argc != 2) { |
| 3108 | ThrowParamCountMismatchException(L"insertInstance"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3109 | return; |
| 3110 | } |
| 3111 | int32_t iIndex = pArguments->GetInt32(0); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3112 | bool bBind = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3113 | if (argc == 2) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3114 | bBind = pArguments->GetInt32(1) == 0 ? false : true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3115 | } |
| 3116 | CXFA_Occur nodeOccur(GetOccurNode()); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3117 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3118 | if (iIndex < 0 || iIndex > iCount) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3119 | ThrowIndexOutOfBoundsException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3120 | return; |
| 3121 | } |
| 3122 | int32_t iMax = nodeOccur.GetMax(); |
| 3123 | if (iMax >= 0 && iCount >= iMax) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3124 | ThrowTooManyOccurancesException(L"max"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3125 | return; |
| 3126 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3127 | CXFA_Node* pNewInstance = CreateInstance(this, bBind); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3128 | InsertItem(this, pNewInstance, iIndex, iCount, true); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3129 | pArguments->GetReturnValue()->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3130 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance)); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3131 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3132 | if (!pNotify) { |
| 3133 | return; |
| 3134 | } |
| 3135 | pNotify->RunNodeInitialize(pNewInstance); |
| 3136 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3137 | if (!pLayoutPro) { |
| 3138 | return; |
| 3139 | } |
| 3140 | pLayoutPro->AddChangedContainer( |
| 3141 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3142 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3143 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3144 | int32_t CXFA_Node::InstanceManager_SetInstances(int32_t iDesired) { |
| 3145 | CXFA_Occur nodeOccur(GetOccurNode()); |
| 3146 | int32_t iMax = nodeOccur.GetMax(); |
| 3147 | int32_t iMin = nodeOccur.GetMin(); |
| 3148 | if (iDesired < iMin) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3149 | ThrowTooManyOccurancesException(L"min"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3150 | return 1; |
| 3151 | } |
| 3152 | if ((iMax >= 0) && (iDesired > iMax)) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3153 | ThrowTooManyOccurancesException(L"max"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3154 | return 2; |
| 3155 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3156 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3157 | if (iDesired == iCount) { |
| 3158 | return 0; |
| 3159 | } |
| 3160 | if (iDesired < iCount) { |
| 3161 | CFX_WideStringC wsInstManagerName = GetCData(XFA_ATTRIBUTE_Name); |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3162 | CFX_WideString wsInstanceName = |
| 3163 | CFX_WideString(wsInstManagerName.IsEmpty() ? wsInstManagerName |
| 3164 | : wsInstManagerName.Mid(1)); |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 3165 | uint32_t dInstanceNameHash = |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 3166 | FX_HashCode_GetW(wsInstanceName.AsStringC(), false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3167 | CXFA_Node* pPrevSibling = |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3168 | (iDesired == 0) ? this : GetItem(this, iDesired - 1); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3169 | while (iCount > iDesired) { |
| 3170 | CXFA_Node* pRemoveInstance = |
| 3171 | pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3172 | if (pRemoveInstance->GetElementType() != XFA_Element::Subform && |
| 3173 | pRemoveInstance->GetElementType() != XFA_Element::SubformSet) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3174 | continue; |
| 3175 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3176 | if (pRemoveInstance->GetElementType() == XFA_Element::InstanceManager) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3177 | ASSERT(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3178 | break; |
| 3179 | } |
| 3180 | if (pRemoveInstance->GetNameHash() == dInstanceNameHash) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3181 | RemoveItem(this, pRemoveInstance); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3182 | iCount--; |
| 3183 | } |
| 3184 | } |
| 3185 | } else if (iDesired > iCount) { |
| 3186 | while (iCount < iDesired) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3187 | CXFA_Node* pNewInstance = CreateInstance(this, true); |
| 3188 | InsertItem(this, pNewInstance, iCount, iCount, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3189 | iCount++; |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3190 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3191 | if (!pNotify) { |
| 3192 | return 0; |
| 3193 | } |
| 3194 | pNotify->RunNodeInitialize(pNewInstance); |
| 3195 | } |
| 3196 | } |
| 3197 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3198 | if (pLayoutPro) { |
| 3199 | pLayoutPro->AddChangedContainer( |
| 3200 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3201 | } |
| 3202 | return 0; |
| 3203 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3204 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3205 | int32_t CXFA_Node::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3206 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3207 | if (iFrom > iCount || iTo > iCount - 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3208 | ThrowIndexOutOfBoundsException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3209 | return 1; |
| 3210 | } |
| 3211 | if (iFrom < 0 || iTo < 0 || iFrom == iTo) { |
| 3212 | return 0; |
| 3213 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3214 | CXFA_Node* pMoveInstance = GetItem(this, iFrom); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3215 | RemoveItem(this, pMoveInstance, false); |
| 3216 | InsertItem(this, pMoveInstance, iTo, iCount - 1, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3217 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3218 | if (pLayoutPro) { |
| 3219 | pLayoutPro->AddChangedContainer( |
| 3220 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3221 | } |
| 3222 | return 0; |
| 3223 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3224 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3225 | void CXFA_Node::Script_Occur_Max(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3226 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3227 | XFA_ATTRIBUTE eAttribute) { |
| 3228 | CXFA_Occur occur(this); |
| 3229 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3230 | int32_t iMax = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3231 | occur.SetMax(iMax); |
| 3232 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3233 | pValue->SetInteger(occur.GetMax()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3234 | } |
| 3235 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3236 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3237 | void CXFA_Node::Script_Occur_Min(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3238 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3239 | XFA_ATTRIBUTE eAttribute) { |
| 3240 | CXFA_Occur occur(this); |
| 3241 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3242 | int32_t iMin = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3243 | occur.SetMin(iMin); |
| 3244 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3245 | pValue->SetInteger(occur.GetMin()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3246 | } |
| 3247 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3248 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3249 | void CXFA_Node::Script_Desc_Metadata(CFXJSE_Arguments* pArguments) { |
| 3250 | int32_t argc = pArguments->GetLength(); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3251 | if (argc != 0 && argc != 1) { |
| 3252 | ThrowParamCountMismatchException(L"metadata"); |
| 3253 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3254 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3255 | pArguments->GetReturnValue()->SetString(""); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3256 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3257 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3258 | void CXFA_Node::Script_Form_FormNodes(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3259 | if (pArguments->GetLength() != 1) { |
| 3260 | ThrowParamCountMismatchException(L"formNodes"); |
| 3261 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3262 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3263 | |
| 3264 | CXFA_Node* pDataNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); |
| 3265 | if (!pDataNode) { |
| 3266 | ThrowArgumentMismatchException(); |
| 3267 | return; |
| 3268 | } |
| 3269 | |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 3270 | std::vector<CXFA_Node*> formItems; |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3271 | CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument); |
| 3272 | pFormNodes->SetArrayNodeList(formItems); |
| 3273 | pArguments->GetReturnValue()->SetObject( |
| 3274 | pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3275 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3276 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3277 | void CXFA_Node::Script_Form_Remerge(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3278 | if (pArguments->GetLength() != 0) { |
| 3279 | ThrowParamCountMismatchException(L"remerge"); |
| 3280 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3281 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3282 | |
| 3283 | m_pDocument->DoDataRemerge(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3284 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3285 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3286 | void CXFA_Node::Script_Form_ExecInitialize(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3287 | if (pArguments->GetLength() != 0) { |
| 3288 | ThrowParamCountMismatchException(L"execInitialize"); |
| 3289 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3290 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3291 | |
| 3292 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 3293 | if (!pNotify) |
| 3294 | return; |
| 3295 | |
| 3296 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3297 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3298 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3299 | void CXFA_Node::Script_Form_Recalculate(CFXJSE_Arguments* pArguments) { |
| 3300 | CXFA_EventParam* pEventParam = |
| 3301 | m_pDocument->GetScriptContext()->GetEventParam(); |
| 3302 | if (pEventParam->m_eType == XFA_EVENT_Calculate || |
| 3303 | pEventParam->m_eType == XFA_EVENT_InitCalculate) { |
| 3304 | return; |
| 3305 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3306 | if (pArguments->GetLength() != 1) { |
| 3307 | ThrowParamCountMismatchException(L"recalculate"); |
| 3308 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3309 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3310 | |
| 3311 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 3312 | if (!pNotify) |
| 3313 | return; |
| 3314 | if (pArguments->GetInt32(0) != 0) |
| 3315 | return; |
| 3316 | |
| 3317 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); |
| 3318 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); |
| 3319 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Ready, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3320 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3321 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3322 | void CXFA_Node::Script_Form_ExecCalculate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3323 | if (pArguments->GetLength() != 0) { |
| 3324 | ThrowParamCountMismatchException(L"execCalculate"); |
| 3325 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3326 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3327 | |
| 3328 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 3329 | if (!pNotify) |
| 3330 | return; |
| 3331 | |
| 3332 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3333 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3334 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3335 | void CXFA_Node::Script_Form_ExecValidate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3336 | if (pArguments->GetLength() != 0) { |
| 3337 | ThrowParamCountMismatchException(L"execValidate"); |
| 3338 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3339 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3340 | |
| 3341 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 3342 | if (!pNotify) { |
| 3343 | pArguments->GetReturnValue()->SetBoolean(false); |
| 3344 | return; |
| 3345 | } |
| 3346 | |
| 3347 | int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); |
| 3348 | pArguments->GetReturnValue()->SetBoolean( |
| 3349 | (iRet == XFA_EVENTERROR_Error) ? false : true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3350 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3351 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3352 | void CXFA_Node::Script_Form_Checksum(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3353 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3354 | XFA_ATTRIBUTE eAttribute) { |
| 3355 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 3356 | SetAttribute(XFA_ATTRIBUTE_Checksum, pValue->ToWideString().AsStringC()); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3357 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3358 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3359 | CFX_WideString wsChecksum; |
| 3360 | GetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum, false); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 3361 | pValue->SetString(wsChecksum.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3362 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3363 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3364 | void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3365 | if (pArguments->GetLength() != 1) { |
| 3366 | ThrowParamCountMismatchException(L"getAttribute"); |
| 3367 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3368 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3369 | CFX_ByteString bsAttributeName = pArguments->GetUTF8String(0); |
| 3370 | CFX_WideString wsAttributeValue; |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3371 | CFX_XMLNode* pXMLNode = GetXMLMappingNode(); |
| 3372 | if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) { |
| 3373 | wsAttributeValue = static_cast<CFX_XMLElement*>(pXMLNode)->GetString( |
Dan Sinclair | 5fa4e98 | 2017-04-05 11:48:21 -0400 | [diff] [blame] | 3374 | CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str()); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3375 | } |
| 3376 | pArguments->GetReturnValue()->SetString( |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 3377 | wsAttributeValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3378 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3379 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3380 | void CXFA_Node::Script_Packet_SetAttribute(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3381 | if (pArguments->GetLength() != 2) { |
| 3382 | ThrowParamCountMismatchException(L"setAttribute"); |
| 3383 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3384 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3385 | CFX_ByteString bsValue = pArguments->GetUTF8String(0); |
| 3386 | CFX_ByteString bsName = pArguments->GetUTF8String(1); |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3387 | CFX_XMLNode* pXMLNode = GetXMLMappingNode(); |
| 3388 | if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) { |
| 3389 | static_cast<CFX_XMLElement*>(pXMLNode)->SetString( |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3390 | CFX_WideString::FromUTF8(bsName.AsStringC()), |
| 3391 | CFX_WideString::FromUTF8(bsValue.AsStringC())); |
| 3392 | } |
| 3393 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3394 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3395 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3396 | void CXFA_Node::Script_Packet_RemoveAttribute(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3397 | if (pArguments->GetLength() != 1) { |
| 3398 | ThrowParamCountMismatchException(L"removeAttribute"); |
| 3399 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3400 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3401 | |
| 3402 | CFX_ByteString bsName = pArguments->GetUTF8String(0); |
| 3403 | CFX_WideString wsName = CFX_WideString::FromUTF8(bsName.AsStringC()); |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3404 | CFX_XMLNode* pXMLNode = GetXMLMappingNode(); |
| 3405 | if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) { |
| 3406 | CFX_XMLElement* pXMLElement = static_cast<CFX_XMLElement*>(pXMLNode); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3407 | if (pXMLElement->HasAttribute(wsName.c_str())) { |
| 3408 | pXMLElement->RemoveAttribute(wsName.c_str()); |
| 3409 | } |
| 3410 | } |
| 3411 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3412 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3413 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3414 | void CXFA_Node::Script_Packet_Content(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3415 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3416 | XFA_ATTRIBUTE eAttribute) { |
| 3417 | if (bSetting) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3418 | CFX_XMLNode* pXMLNode = GetXMLMappingNode(); |
| 3419 | if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) { |
| 3420 | CFX_XMLElement* pXMLElement = static_cast<CFX_XMLElement*>(pXMLNode); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 3421 | pXMLElement->SetTextData(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3422 | } |
| 3423 | } else { |
| 3424 | CFX_WideString wsTextData; |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3425 | CFX_XMLNode* pXMLNode = GetXMLMappingNode(); |
| 3426 | if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) { |
| 3427 | CFX_XMLElement* pXMLElement = static_cast<CFX_XMLElement*>(pXMLNode); |
Dan Sinclair | 5fa4e98 | 2017-04-05 11:48:21 -0400 | [diff] [blame] | 3428 | wsTextData = pXMLElement->GetTextData(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3429 | } |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 3430 | pValue->SetString(wsTextData.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3431 | } |
| 3432 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3433 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3434 | void CXFA_Node::Script_Source_Next(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3435 | if (pArguments->GetLength() != 0) |
| 3436 | ThrowParamCountMismatchException(L"next"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3437 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3438 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3439 | void CXFA_Node::Script_Source_CancelBatch(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3440 | if (pArguments->GetLength() != 0) |
| 3441 | ThrowParamCountMismatchException(L"cancelBatch"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3442 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3443 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3444 | void CXFA_Node::Script_Source_First(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3445 | if (pArguments->GetLength() != 0) |
| 3446 | ThrowParamCountMismatchException(L"first"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3447 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3448 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3449 | void CXFA_Node::Script_Source_UpdateBatch(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3450 | if (pArguments->GetLength() != 0) |
| 3451 | ThrowParamCountMismatchException(L"updateBatch"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3452 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3453 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3454 | void CXFA_Node::Script_Source_Previous(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3455 | if (pArguments->GetLength() != 0) |
| 3456 | ThrowParamCountMismatchException(L"previous"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3457 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3458 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3459 | void CXFA_Node::Script_Source_IsBOF(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3460 | if (pArguments->GetLength() != 0) |
| 3461 | ThrowParamCountMismatchException(L"isBOF"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3462 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3463 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3464 | void CXFA_Node::Script_Source_IsEOF(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3465 | if (pArguments->GetLength() != 0) |
| 3466 | ThrowParamCountMismatchException(L"isEOF"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3467 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3468 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3469 | void CXFA_Node::Script_Source_Cancel(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3470 | if (pArguments->GetLength() != 0) |
| 3471 | ThrowParamCountMismatchException(L"cancel"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3472 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3473 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3474 | void CXFA_Node::Script_Source_Update(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3475 | if (pArguments->GetLength() != 0) |
| 3476 | ThrowParamCountMismatchException(L"update"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3477 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3478 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3479 | void CXFA_Node::Script_Source_Open(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3480 | if (pArguments->GetLength() != 0) |
| 3481 | ThrowParamCountMismatchException(L"open"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3482 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3483 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3484 | void CXFA_Node::Script_Source_Delete(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3485 | if (pArguments->GetLength() != 0) |
| 3486 | ThrowParamCountMismatchException(L"delete"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3487 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3488 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3489 | void CXFA_Node::Script_Source_AddNew(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3490 | if (pArguments->GetLength() != 0) |
| 3491 | ThrowParamCountMismatchException(L"addNew"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3492 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3493 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3494 | void CXFA_Node::Script_Source_Requery(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3495 | if (pArguments->GetLength() != 0) |
| 3496 | ThrowParamCountMismatchException(L"requery"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3497 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3498 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3499 | void CXFA_Node::Script_Source_Resync(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3500 | if (pArguments->GetLength() != 0) |
| 3501 | ThrowParamCountMismatchException(L"resync"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3502 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3503 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3504 | void CXFA_Node::Script_Source_Close(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3505 | if (pArguments->GetLength() != 0) |
| 3506 | ThrowParamCountMismatchException(L"close"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3507 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3508 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3509 | void CXFA_Node::Script_Source_Last(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3510 | if (pArguments->GetLength() != 0) |
| 3511 | ThrowParamCountMismatchException(L"last"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3512 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3513 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3514 | void CXFA_Node::Script_Source_HasDataChanged(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3515 | if (pArguments->GetLength() != 0) |
| 3516 | ThrowParamCountMismatchException(L"hasDataChanged"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3517 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3518 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3519 | void CXFA_Node::Script_Source_Db(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3520 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3521 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3522 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3523 | void CXFA_Node::Script_Xfa_This(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3524 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3525 | XFA_ATTRIBUTE eAttribute) { |
| 3526 | if (!bSetting) { |
| 3527 | CXFA_Object* pThis = m_pDocument->GetScriptContext()->GetThisObject(); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 3528 | ASSERT(pThis); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3529 | pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pThis)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3530 | } |
| 3531 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3532 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3533 | void CXFA_Node::Script_Handler_Version(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3534 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3535 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3536 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3537 | void CXFA_Node::Script_SubmitFormat_Mode(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3538 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3539 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3540 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3541 | void CXFA_Node::Script_Extras_Type(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3542 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3543 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3544 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3545 | void CXFA_Node::Script_Script_Stateless(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3546 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3547 | XFA_ATTRIBUTE eAttribute) { |
| 3548 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3549 | ThrowInvalidPropertyException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3550 | return; |
| 3551 | } |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 3552 | pValue->SetString(FX_UTF8Encode(CFX_WideStringC(L"0", 1)).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3553 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3554 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3555 | void CXFA_Node::Script_Encrypt_Format(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3556 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3557 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3558 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3559 | bool CXFA_Node::HasAttribute(XFA_ATTRIBUTE eAttr, bool bCanInherit) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3560 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3561 | return HasMapModuleKey(pKey, bCanInherit); |
| 3562 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3563 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3564 | bool CXFA_Node::SetAttribute(XFA_ATTRIBUTE eAttr, |
| 3565 | const CFX_WideStringC& wsValue, |
| 3566 | bool bNotify) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3567 | const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3568 | if (!pAttr) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3569 | return false; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3570 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3571 | XFA_ATTRIBUTETYPE eType = pAttr->eType; |
| 3572 | if (eType == XFA_ATTRIBUTETYPE_NOTSURE) { |
| 3573 | const XFA_NOTSUREATTRIBUTE* pNotsure = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3574 | XFA_GetNotsureAttribute(GetElementType(), pAttr->eName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3575 | eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata; |
| 3576 | } |
| 3577 | switch (eType) { |
| 3578 | case XFA_ATTRIBUTETYPE_Enum: { |
| 3579 | const XFA_ATTRIBUTEENUMINFO* pEnum = XFA_GetAttributeEnumByName(wsValue); |
| 3580 | return SetEnum(pAttr->eName, |
| 3581 | pEnum ? pEnum->eName |
| 3582 | : (XFA_ATTRIBUTEENUM)(intptr_t)(pAttr->pDefValue), |
| 3583 | bNotify); |
| 3584 | } break; |
| 3585 | case XFA_ATTRIBUTETYPE_Cdata: |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3586 | return SetCData(pAttr->eName, CFX_WideString(wsValue), bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3587 | case XFA_ATTRIBUTETYPE_Boolean: |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 3588 | return SetBoolean(pAttr->eName, wsValue != L"0", bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3589 | case XFA_ATTRIBUTETYPE_Integer: |
dsinclair | e0347a6 | 2016-08-11 11:24:11 -0700 | [diff] [blame] | 3590 | return SetInteger(pAttr->eName, |
| 3591 | FXSYS_round(FXSYS_wcstof(wsValue.c_str(), |
| 3592 | wsValue.GetLength(), nullptr)), |
| 3593 | bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3594 | case XFA_ATTRIBUTETYPE_Measure: |
| 3595 | return SetMeasure(pAttr->eName, CXFA_Measurement(wsValue), bNotify); |
| 3596 | default: |
| 3597 | break; |
| 3598 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3599 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3600 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3601 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3602 | bool CXFA_Node::GetAttribute(XFA_ATTRIBUTE eAttr, |
| 3603 | CFX_WideString& wsValue, |
| 3604 | bool bUseDefault) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3605 | const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3606 | if (!pAttr) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3607 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3608 | } |
| 3609 | XFA_ATTRIBUTETYPE eType = pAttr->eType; |
| 3610 | if (eType == XFA_ATTRIBUTETYPE_NOTSURE) { |
| 3611 | const XFA_NOTSUREATTRIBUTE* pNotsure = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3612 | XFA_GetNotsureAttribute(GetElementType(), pAttr->eName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3613 | eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata; |
| 3614 | } |
| 3615 | switch (eType) { |
| 3616 | case XFA_ATTRIBUTETYPE_Enum: { |
| 3617 | XFA_ATTRIBUTEENUM eValue; |
| 3618 | if (!TryEnum(pAttr->eName, eValue, bUseDefault)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3619 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3620 | } |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 3621 | wsValue = GetAttributeEnumByID(eValue)->pName; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3622 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3623 | } break; |
| 3624 | case XFA_ATTRIBUTETYPE_Cdata: { |
| 3625 | CFX_WideStringC wsValueC; |
| 3626 | if (!TryCData(pAttr->eName, wsValueC, bUseDefault)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3627 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3628 | } |
| 3629 | wsValue = wsValueC; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3630 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3631 | } break; |
| 3632 | case XFA_ATTRIBUTETYPE_Boolean: { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3633 | bool bValue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3634 | if (!TryBoolean(pAttr->eName, bValue, bUseDefault)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3635 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3636 | } |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 3637 | wsValue = bValue ? L"1" : L"0"; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3638 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3639 | } break; |
| 3640 | case XFA_ATTRIBUTETYPE_Integer: { |
| 3641 | int32_t iValue; |
| 3642 | if (!TryInteger(pAttr->eName, iValue, bUseDefault)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3643 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3644 | } |
| 3645 | wsValue.Format(L"%d", iValue); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3646 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3647 | } break; |
| 3648 | case XFA_ATTRIBUTETYPE_Measure: { |
| 3649 | CXFA_Measurement mValue; |
| 3650 | if (!TryMeasure(pAttr->eName, mValue, bUseDefault)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3651 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3652 | } |
| 3653 | mValue.ToString(wsValue); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3654 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3655 | } break; |
| 3656 | default: |
| 3657 | break; |
| 3658 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3659 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3660 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3661 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3662 | bool CXFA_Node::SetAttribute(const CFX_WideStringC& wsAttr, |
| 3663 | const CFX_WideStringC& wsValue, |
| 3664 | bool bNotify) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3665 | const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsValue); |
| 3666 | if (pAttributeInfo) { |
| 3667 | return SetAttribute(pAttributeInfo->eName, wsValue, bNotify); |
| 3668 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3669 | void* pKey = GetMapKey_Custom(wsAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3670 | SetMapModuleString(pKey, wsValue); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3671 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3672 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3673 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3674 | bool CXFA_Node::GetAttribute(const CFX_WideStringC& wsAttr, |
| 3675 | CFX_WideString& wsValue, |
| 3676 | bool bUseDefault) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3677 | const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsAttr); |
| 3678 | if (pAttributeInfo) { |
| 3679 | return GetAttribute(pAttributeInfo->eName, wsValue, bUseDefault); |
| 3680 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3681 | void* pKey = GetMapKey_Custom(wsAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3682 | CFX_WideStringC wsValueC; |
| 3683 | if (GetMapModuleString(pKey, wsValueC)) { |
| 3684 | wsValue = wsValueC; |
| 3685 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3686 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3687 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3688 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3689 | bool CXFA_Node::RemoveAttribute(const CFX_WideStringC& wsAttr) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3690 | void* pKey = GetMapKey_Custom(wsAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3691 | RemoveMapModuleKey(pKey); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3692 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3693 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3694 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3695 | bool CXFA_Node::TryBoolean(XFA_ATTRIBUTE eAttr, |
| 3696 | bool& bValue, |
| 3697 | bool bUseDefault) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3698 | void* pValue = nullptr; |
| 3699 | if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Boolean, bUseDefault, pValue)) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3700 | return false; |
tsepez | 478ed62 | 2016-10-27 14:32:33 -0700 | [diff] [blame] | 3701 | bValue = !!pValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3702 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3703 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3704 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3705 | bool CXFA_Node::TryInteger(XFA_ATTRIBUTE eAttr, |
| 3706 | int32_t& iValue, |
| 3707 | bool bUseDefault) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3708 | void* pValue = nullptr; |
| 3709 | if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Integer, bUseDefault, pValue)) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3710 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3711 | iValue = (int32_t)(uintptr_t)pValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3712 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3713 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3714 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3715 | bool CXFA_Node::TryEnum(XFA_ATTRIBUTE eAttr, |
| 3716 | XFA_ATTRIBUTEENUM& eValue, |
| 3717 | bool bUseDefault) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3718 | void* pValue = nullptr; |
| 3719 | if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Enum, bUseDefault, pValue)) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3720 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3721 | eValue = (XFA_ATTRIBUTEENUM)(uintptr_t)pValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3722 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3723 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3724 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3725 | bool CXFA_Node::SetMeasure(XFA_ATTRIBUTE eAttr, |
| 3726 | CXFA_Measurement mValue, |
| 3727 | bool bNotify) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3728 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3729 | OnChanging(eAttr, bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3730 | SetMapModuleBuffer(pKey, &mValue, sizeof(CXFA_Measurement)); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3731 | OnChanged(eAttr, bNotify, false); |
| 3732 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3733 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3734 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3735 | bool CXFA_Node::TryMeasure(XFA_ATTRIBUTE eAttr, |
| 3736 | CXFA_Measurement& mValue, |
| 3737 | bool bUseDefault) const { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3738 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3739 | void* pValue; |
| 3740 | int32_t iBytes; |
| 3741 | if (GetMapModuleBuffer(pKey, pValue, iBytes) && iBytes == sizeof(mValue)) { |
Dan Sinclair | 1c5d0b4 | 2017-04-03 15:05:11 -0400 | [diff] [blame] | 3742 | memcpy(&mValue, pValue, sizeof(mValue)); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3743 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3744 | } |
| 3745 | if (bUseDefault && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3746 | XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3747 | XFA_ATTRIBUTETYPE_Measure, m_ePacket)) { |
Dan Sinclair | 1c5d0b4 | 2017-04-03 15:05:11 -0400 | [diff] [blame] | 3748 | memcpy(&mValue, pValue, sizeof(mValue)); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3749 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3750 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3751 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3752 | } |
| 3753 | |
| 3754 | CXFA_Measurement CXFA_Node::GetMeasure(XFA_ATTRIBUTE eAttr) const { |
| 3755 | CXFA_Measurement mValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3756 | return TryMeasure(eAttr, mValue, true) ? mValue : CXFA_Measurement(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3757 | } |
| 3758 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3759 | bool CXFA_Node::SetCData(XFA_ATTRIBUTE eAttr, |
| 3760 | const CFX_WideString& wsValue, |
| 3761 | bool bNotify, |
| 3762 | bool bScriptModify) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3763 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3764 | OnChanging(eAttr, bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3765 | if (eAttr == XFA_ATTRIBUTE_Value) { |
| 3766 | CFX_WideString* pClone = new CFX_WideString(wsValue); |
| 3767 | SetUserData(pKey, pClone, &deleteWideStringCallBack); |
| 3768 | } else { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 3769 | SetMapModuleString(pKey, wsValue.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3770 | if (eAttr == XFA_ATTRIBUTE_Name) |
| 3771 | UpdateNameHash(); |
| 3772 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3773 | OnChanged(eAttr, bNotify, bScriptModify); |
| 3774 | |
| 3775 | if (!IsNeedSavingXMLNode() || eAttr == XFA_ATTRIBUTE_QualifiedName || |
| 3776 | eAttr == XFA_ATTRIBUTE_BindingNode) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3777 | return true; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3778 | } |
| 3779 | |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3780 | if (eAttr == XFA_ATTRIBUTE_Name && |
| 3781 | (m_elementType == XFA_Element::DataValue || |
| 3782 | m_elementType == XFA_Element::DataGroup)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3783 | return true; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3784 | } |
| 3785 | |
| 3786 | if (eAttr == XFA_ATTRIBUTE_Value) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3787 | FX_XMLNODETYPE eXMLType = m_pXMLNode->GetType(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3788 | switch (eXMLType) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3789 | case FX_XMLNODE_Element: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3790 | if (IsAttributeInXML()) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3791 | static_cast<CFX_XMLElement*>(m_pXMLNode) |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3792 | ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)), |
| 3793 | wsValue); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3794 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3795 | bool bDeleteChildren = true; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3796 | if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 3797 | for (CXFA_Node* pChildDataNode = |
| 3798 | GetNodeItem(XFA_NODEITEM_FirstChild); |
| 3799 | pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem( |
| 3800 | XFA_NODEITEM_NextSibling)) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 3801 | if (!pChildDataNode->GetBindItems().empty()) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3802 | bDeleteChildren = false; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3803 | break; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3804 | } |
| 3805 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3806 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3807 | if (bDeleteChildren) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3808 | static_cast<CFX_XMLElement*>(m_pXMLNode)->DeleteChildren(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3809 | } |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3810 | static_cast<CFX_XMLElement*>(m_pXMLNode)->SetTextData(wsValue); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3811 | } |
| 3812 | break; |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3813 | case FX_XMLNODE_Text: |
| 3814 | static_cast<CFX_XMLText*>(m_pXMLNode)->SetText(wsValue); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3815 | break; |
| 3816 | default: |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 3817 | ASSERT(0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3818 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3819 | return true; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3820 | } |
| 3821 | |
| 3822 | const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr); |
| 3823 | if (pInfo) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3824 | ASSERT(m_pXMLNode->GetType() == FX_XMLNODE_Element); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3825 | CFX_WideString wsAttrName = pInfo->pName; |
| 3826 | if (pInfo->eName == XFA_ATTRIBUTE_ContentType) { |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 3827 | wsAttrName = L"xfa:" + wsAttrName; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3828 | } |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3829 | static_cast<CFX_XMLElement*>(m_pXMLNode)->SetString(wsAttrName, wsValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3830 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3831 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3832 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3833 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3834 | bool CXFA_Node::SetAttributeValue(const CFX_WideString& wsValue, |
| 3835 | const CFX_WideString& wsXMLValue, |
| 3836 | bool bNotify, |
| 3837 | bool bScriptModify) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3838 | void* pKey = GetMapKey_Element(GetElementType(), XFA_ATTRIBUTE_Value); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3839 | OnChanging(XFA_ATTRIBUTE_Value, bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3840 | CFX_WideString* pClone = new CFX_WideString(wsValue); |
| 3841 | SetUserData(pKey, pClone, &deleteWideStringCallBack); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3842 | OnChanged(XFA_ATTRIBUTE_Value, bNotify, bScriptModify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3843 | if (IsNeedSavingXMLNode()) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3844 | FX_XMLNODETYPE eXMLType = m_pXMLNode->GetType(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3845 | switch (eXMLType) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3846 | case FX_XMLNODE_Element: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3847 | if (IsAttributeInXML()) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3848 | static_cast<CFX_XMLElement*>(m_pXMLNode) |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3849 | ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)), |
| 3850 | wsXMLValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3851 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3852 | bool bDeleteChildren = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3853 | if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 3854 | for (CXFA_Node* pChildDataNode = |
| 3855 | GetNodeItem(XFA_NODEITEM_FirstChild); |
| 3856 | pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem( |
| 3857 | XFA_NODEITEM_NextSibling)) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 3858 | if (!pChildDataNode->GetBindItems().empty()) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3859 | bDeleteChildren = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3860 | break; |
| 3861 | } |
| 3862 | } |
| 3863 | } |
| 3864 | if (bDeleteChildren) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3865 | static_cast<CFX_XMLElement*>(m_pXMLNode)->DeleteChildren(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3866 | } |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3867 | static_cast<CFX_XMLElement*>(m_pXMLNode)->SetTextData(wsXMLValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3868 | } |
| 3869 | break; |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3870 | case FX_XMLNODE_Text: |
| 3871 | static_cast<CFX_XMLText*>(m_pXMLNode)->SetText(wsXMLValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3872 | break; |
| 3873 | default: |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 3874 | ASSERT(0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3875 | } |
| 3876 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3877 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3878 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3879 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3880 | bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr, |
| 3881 | CFX_WideString& wsValue, |
| 3882 | bool bUseDefault, |
| 3883 | bool bProto) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3884 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3885 | if (eAttr == XFA_ATTRIBUTE_Value) { |
| 3886 | CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto); |
| 3887 | if (pStr) { |
| 3888 | wsValue = *pStr; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3889 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3890 | } |
| 3891 | } else { |
| 3892 | CFX_WideStringC wsValueC; |
| 3893 | if (GetMapModuleString(pKey, wsValueC)) { |
| 3894 | wsValue = wsValueC; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3895 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3896 | } |
| 3897 | } |
| 3898 | if (!bUseDefault) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3899 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3900 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3901 | void* pValue = nullptr; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3902 | if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3903 | XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) { |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 3904 | wsValue = (const wchar_t*)pValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3905 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3906 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3907 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3908 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3909 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3910 | bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr, |
| 3911 | CFX_WideStringC& wsValue, |
| 3912 | bool bUseDefault, |
| 3913 | bool bProto) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3914 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3915 | if (eAttr == XFA_ATTRIBUTE_Value) { |
| 3916 | CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto); |
| 3917 | if (pStr) { |
tsepez | 4d31d0c | 2016-04-19 14:11:59 -0700 | [diff] [blame] | 3918 | wsValue = pStr->AsStringC(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3919 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3920 | } |
| 3921 | } else { |
| 3922 | if (GetMapModuleString(pKey, wsValue)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3923 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3924 | } |
| 3925 | } |
| 3926 | if (!bUseDefault) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3927 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3928 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3929 | void* pValue = nullptr; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3930 | if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3931 | XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) { |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 3932 | wsValue = (CFX_WideStringC)(const wchar_t*)pValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3933 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3934 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3935 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3936 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3937 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3938 | bool CXFA_Node::SetObject(XFA_ATTRIBUTE eAttr, |
| 3939 | void* pData, |
| 3940 | XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3941 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3942 | return SetUserData(pKey, pData, pCallbackInfo); |
| 3943 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3944 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3945 | bool CXFA_Node::TryObject(XFA_ATTRIBUTE eAttr, void*& pData) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3946 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3947 | pData = GetUserData(pKey); |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 3948 | return !!pData; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3949 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3950 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3951 | bool CXFA_Node::SetValue(XFA_ATTRIBUTE eAttr, |
| 3952 | XFA_ATTRIBUTETYPE eType, |
| 3953 | void* pValue, |
| 3954 | bool bNotify) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3955 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3956 | OnChanging(eAttr, bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3957 | SetMapModuleValue(pKey, pValue); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3958 | OnChanged(eAttr, bNotify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3959 | if (IsNeedSavingXMLNode()) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3960 | ASSERT(m_pXMLNode->GetType() == FX_XMLNODE_Element); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3961 | const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr); |
| 3962 | if (pInfo) { |
| 3963 | switch (eType) { |
| 3964 | case XFA_ATTRIBUTETYPE_Enum: |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3965 | static_cast<CFX_XMLElement*>(m_pXMLNode) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3966 | ->SetString( |
| 3967 | pInfo->pName, |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 3968 | GetAttributeEnumByID((XFA_ATTRIBUTEENUM)(uintptr_t)pValue) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3969 | ->pName); |
| 3970 | break; |
| 3971 | case XFA_ATTRIBUTETYPE_Boolean: |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3972 | static_cast<CFX_XMLElement*>(m_pXMLNode) |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3973 | ->SetString(pInfo->pName, pValue ? L"1" : L"0"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3974 | break; |
Dan Sinclair | 5fa4e98 | 2017-04-05 11:48:21 -0400 | [diff] [blame] | 3975 | case XFA_ATTRIBUTETYPE_Integer: { |
| 3976 | CFX_WideString wsValue; |
| 3977 | wsValue.Format( |
| 3978 | L"%d", static_cast<int32_t>(reinterpret_cast<uintptr_t>(pValue))); |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 3979 | static_cast<CFX_XMLElement*>(m_pXMLNode) |
Dan Sinclair | 5fa4e98 | 2017-04-05 11:48:21 -0400 | [diff] [blame] | 3980 | ->SetString(pInfo->pName, wsValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3981 | break; |
Dan Sinclair | 5fa4e98 | 2017-04-05 11:48:21 -0400 | [diff] [blame] | 3982 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3983 | default: |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 3984 | ASSERT(0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3985 | } |
| 3986 | } |
| 3987 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3988 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3989 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3990 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3991 | bool CXFA_Node::GetValue(XFA_ATTRIBUTE eAttr, |
| 3992 | XFA_ATTRIBUTETYPE eType, |
| 3993 | bool bUseDefault, |
| 3994 | void*& pValue) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3995 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3996 | if (GetMapModuleValue(pKey, pValue)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3997 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3998 | } |
| 3999 | if (!bUseDefault) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4000 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4001 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4002 | return XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, eType, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4003 | m_ePacket); |
| 4004 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4005 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4006 | bool CXFA_Node::SetUserData(void* pKey, |
| 4007 | void* pData, |
| 4008 | XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4009 | SetMapModuleBuffer(pKey, &pData, sizeof(void*), |
| 4010 | pCallbackInfo ? pCallbackInfo : &gs_XFADefaultFreeData); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4011 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4012 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4013 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4014 | bool CXFA_Node::TryUserData(void* pKey, void*& pData, bool bProtoAlso) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4015 | int32_t iBytes = 0; |
| 4016 | if (!GetMapModuleBuffer(pKey, pData, iBytes, bProtoAlso)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4017 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4018 | } |
Dan Sinclair | 1c5d0b4 | 2017-04-03 15:05:11 -0400 | [diff] [blame] | 4019 | return iBytes == sizeof(void*) && memcpy(&pData, pData, iBytes); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4020 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4021 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4022 | bool CXFA_Node::SetScriptContent(const CFX_WideString& wsContent, |
| 4023 | const CFX_WideString& wsXMLValue, |
| 4024 | bool bNotify, |
| 4025 | bool bScriptModify, |
| 4026 | bool bSyncData) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4027 | CXFA_Node* pNode = nullptr; |
| 4028 | CXFA_Node* pBindNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4029 | switch (GetObjectType()) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4030 | case XFA_ObjectType::ContainerNode: { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4031 | if (XFA_FieldIsMultiListBox(this)) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4032 | CXFA_Node* pValue = GetProperty(0, XFA_Element::Value); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4033 | CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4034 | ASSERT(pChildValue); |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 4035 | pChildValue->SetCData(XFA_ATTRIBUTE_ContentType, L"text/xml"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4036 | pChildValue->SetScriptContent(wsContent, wsContent, bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4037 | bScriptModify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4038 | CXFA_Node* pBind = GetBindData(); |
| 4039 | if (bSyncData && pBind) { |
tsepez | 51709be | 2016-12-08 10:55:57 -0800 | [diff] [blame] | 4040 | std::vector<CFX_WideString> wsSaveTextArray; |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 4041 | size_t iSize = 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4042 | if (!wsContent.IsEmpty()) { |
| 4043 | int32_t iStart = 0; |
| 4044 | int32_t iLength = wsContent.GetLength(); |
| 4045 | int32_t iEnd = wsContent.Find(L'\n', iStart); |
| 4046 | iEnd = (iEnd == -1) ? iLength : iEnd; |
| 4047 | while (iEnd >= iStart) { |
tsepez | 51709be | 2016-12-08 10:55:57 -0800 | [diff] [blame] | 4048 | wsSaveTextArray.push_back(wsContent.Mid(iStart, iEnd - iStart)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4049 | iStart = iEnd + 1; |
| 4050 | if (iStart >= iLength) { |
| 4051 | break; |
| 4052 | } |
| 4053 | iEnd = wsContent.Find(L'\n', iStart); |
| 4054 | if (iEnd < 0) { |
tsepez | 51709be | 2016-12-08 10:55:57 -0800 | [diff] [blame] | 4055 | wsSaveTextArray.push_back( |
| 4056 | wsContent.Mid(iStart, iLength - iStart)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4057 | } |
| 4058 | } |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 4059 | iSize = wsSaveTextArray.size(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4060 | } |
| 4061 | if (iSize == 0) { |
| 4062 | while (CXFA_Node* pChildNode = |
| 4063 | pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) { |
| 4064 | pBind->RemoveChild(pChildNode); |
| 4065 | } |
| 4066 | } else { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 4067 | std::vector<CXFA_Node*> valueNodes = pBind->GetNodeList( |
| 4068 | XFA_NODEFILTER_Children, XFA_Element::DataValue); |
| 4069 | size_t iDatas = valueNodes.size(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4070 | if (iDatas < iSize) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 4071 | size_t iAddNodes = iSize - iDatas; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4072 | CXFA_Node* pValueNodes = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4073 | while (iAddNodes-- > 0) { |
| 4074 | pValueNodes = |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4075 | pBind->CreateSamePacketNode(XFA_Element::DataValue); |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 4076 | pValueNodes->SetCData(XFA_ATTRIBUTE_Name, L"value"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4077 | pValueNodes->CreateXMLMappingNode(); |
| 4078 | pBind->InsertChild(pValueNodes); |
| 4079 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4080 | pValueNodes = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4081 | } else if (iDatas > iSize) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 4082 | size_t iDelNodes = iDatas - iSize; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4083 | while (iDelNodes-- > 0) { |
| 4084 | pBind->RemoveChild(pBind->GetNodeItem(XFA_NODEITEM_FirstChild)); |
| 4085 | } |
| 4086 | } |
| 4087 | int32_t i = 0; |
| 4088 | for (CXFA_Node* pValueNode = |
| 4089 | pBind->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 4090 | pValueNode; pValueNode = pValueNode->GetNodeItem( |
| 4091 | XFA_NODEITEM_NextSibling)) { |
| 4092 | pValueNode->SetAttributeValue(wsSaveTextArray[i], |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4093 | wsSaveTextArray[i], false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4094 | i++; |
| 4095 | } |
| 4096 | } |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 4097 | for (CXFA_Node* pArrayNode : pBind->GetBindItems()) { |
| 4098 | if (pArrayNode != this) { |
| 4099 | pArrayNode->SetScriptContent(wsContent, wsContent, bNotify, |
| 4100 | bScriptModify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4101 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4102 | } |
| 4103 | } |
| 4104 | break; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4105 | } else if (GetElementType() == XFA_Element::ExclGroup) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4106 | pNode = this; |
| 4107 | } else { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4108 | CXFA_Node* pValue = GetProperty(0, XFA_Element::Value); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4109 | CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4110 | ASSERT(pChildValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4111 | pChildValue->SetScriptContent(wsContent, wsContent, bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4112 | bScriptModify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4113 | } |
| 4114 | pBindNode = GetBindData(); |
| 4115 | if (pBindNode && bSyncData) { |
| 4116 | pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4117 | bScriptModify, false); |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 4118 | for (CXFA_Node* pArrayNode : pBindNode->GetBindItems()) { |
| 4119 | if (pArrayNode != this) { |
| 4120 | pArrayNode->SetScriptContent(wsContent, wsContent, bNotify, true, |
| 4121 | false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4122 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4123 | } |
| 4124 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4125 | pBindNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4126 | break; |
| 4127 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4128 | case XFA_ObjectType::ContentNode: { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4129 | CFX_WideString wsContentType; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4130 | if (GetElementType() == XFA_Element::ExData) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4131 | GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false); |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 4132 | if (wsContentType == L"text/html") { |
| 4133 | wsContentType = L""; |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 4134 | SetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4135 | } |
| 4136 | } |
| 4137 | CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild); |
| 4138 | if (!pContentRawDataNode) { |
tsepez | 9f2970c | 2016-04-01 10:23:04 -0700 | [diff] [blame] | 4139 | pContentRawDataNode = CreateSamePacketNode( |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 4140 | (wsContentType == L"text/xml") ? XFA_Element::Sharpxml |
| 4141 | : XFA_Element::Sharptext); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4142 | InsertChild(pContentRawDataNode); |
| 4143 | } |
| 4144 | return pContentRawDataNode->SetScriptContent( |
| 4145 | wsContent, wsXMLValue, bNotify, bScriptModify, bSyncData); |
| 4146 | } break; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4147 | case XFA_ObjectType::NodeC: |
| 4148 | case XFA_ObjectType::TextNode: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4149 | pNode = this; |
| 4150 | break; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4151 | case XFA_ObjectType::NodeV: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4152 | pNode = this; |
| 4153 | if (bSyncData && GetPacketID() == XFA_XDPPACKET_Form) { |
| 4154 | CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent); |
| 4155 | if (pParent) { |
| 4156 | pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent); |
| 4157 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4158 | if (pParent && pParent->GetElementType() == XFA_Element::Value) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4159 | pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent); |
| 4160 | if (pParent && pParent->IsContainerNode()) { |
| 4161 | pBindNode = pParent->GetBindData(); |
| 4162 | if (pBindNode) { |
| 4163 | pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4164 | bScriptModify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4165 | } |
| 4166 | } |
| 4167 | } |
| 4168 | } |
| 4169 | break; |
| 4170 | default: |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4171 | if (GetElementType() == XFA_Element::DataValue) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4172 | pNode = this; |
| 4173 | pBindNode = this; |
| 4174 | } |
| 4175 | break; |
| 4176 | } |
| 4177 | if (pNode) { |
| 4178 | SetAttributeValue(wsContent, wsXMLValue, bNotify, bScriptModify); |
| 4179 | if (pBindNode && bSyncData) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 4180 | for (CXFA_Node* pArrayNode : pBindNode->GetBindItems()) { |
| 4181 | pArrayNode->SetScriptContent(wsContent, wsContent, bNotify, |
| 4182 | bScriptModify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4183 | } |
| 4184 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4185 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4186 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4187 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4188 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4189 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4190 | bool CXFA_Node::SetContent(const CFX_WideString& wsContent, |
| 4191 | const CFX_WideString& wsXMLValue, |
| 4192 | bool bNotify, |
| 4193 | bool bScriptModify, |
| 4194 | bool bSyncData) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4195 | return SetScriptContent(wsContent, wsXMLValue, bNotify, bScriptModify, |
| 4196 | bSyncData); |
| 4197 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4198 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4199 | CFX_WideString CXFA_Node::GetScriptContent(bool bScriptModify) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4200 | CFX_WideString wsContent; |
| 4201 | return TryContent(wsContent, bScriptModify) ? wsContent : CFX_WideString(); |
| 4202 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4203 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4204 | CFX_WideString CXFA_Node::GetContent() { |
| 4205 | return GetScriptContent(); |
| 4206 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4207 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4208 | bool CXFA_Node::TryContent(CFX_WideString& wsContent, |
| 4209 | bool bScriptModify, |
| 4210 | bool bProto) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4211 | CXFA_Node* pNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4212 | switch (GetObjectType()) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4213 | case XFA_ObjectType::ContainerNode: |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4214 | if (GetElementType() == XFA_Element::ExclGroup) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4215 | pNode = this; |
| 4216 | } else { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4217 | CXFA_Node* pValue = GetChild(0, XFA_Element::Value); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4218 | if (!pValue) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4219 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4220 | } |
| 4221 | CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 4222 | if (pChildValue && XFA_FieldIsMultiListBox(this)) { |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 4223 | pChildValue->SetAttribute(XFA_ATTRIBUTE_ContentType, L"text/xml"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4224 | } |
| 4225 | return pChildValue |
| 4226 | ? pChildValue->TryContent(wsContent, bScriptModify, bProto) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4227 | : false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4228 | } |
| 4229 | break; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4230 | case XFA_ObjectType::ContentNode: { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4231 | CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild); |
| 4232 | if (!pContentRawDataNode) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4233 | XFA_Element element = XFA_Element::Sharptext; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4234 | if (GetElementType() == XFA_Element::ExData) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4235 | CFX_WideString wsContentType; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4236 | GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, false); |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 4237 | if (wsContentType == L"text/html") { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4238 | element = XFA_Element::SharpxHTML; |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 4239 | } else if (wsContentType == L"text/xml") { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4240 | element = XFA_Element::Sharpxml; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4241 | } |
| 4242 | } |
| 4243 | pContentRawDataNode = CreateSamePacketNode(element); |
| 4244 | InsertChild(pContentRawDataNode); |
| 4245 | } |
| 4246 | return pContentRawDataNode->TryContent(wsContent, bScriptModify, bProto); |
| 4247 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4248 | case XFA_ObjectType::NodeC: |
| 4249 | case XFA_ObjectType::NodeV: |
| 4250 | case XFA_ObjectType::TextNode: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4251 | pNode = this; |
| 4252 | default: |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4253 | if (GetElementType() == XFA_Element::DataValue) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4254 | pNode = this; |
| 4255 | } |
| 4256 | break; |
| 4257 | } |
| 4258 | if (pNode) { |
| 4259 | if (bScriptModify) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 4260 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4261 | if (pScriptContext) { |
| 4262 | m_pDocument->GetScriptContext()->AddNodesOfRunScript(this); |
| 4263 | } |
| 4264 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4265 | return TryCData(XFA_ATTRIBUTE_Value, wsContent, false, bProto); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4266 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4267 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4268 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4269 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4270 | CXFA_Node* CXFA_Node::GetModelNode() { |
| 4271 | switch (GetPacketID()) { |
| 4272 | case XFA_XDPPACKET_XDP: |
| 4273 | return m_pDocument->GetRoot(); |
| 4274 | case XFA_XDPPACKET_Config: |
| 4275 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config)); |
| 4276 | case XFA_XDPPACKET_Template: |
| 4277 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template)); |
| 4278 | case XFA_XDPPACKET_Form: |
| 4279 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)); |
| 4280 | case XFA_XDPPACKET_Datasets: |
| 4281 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets)); |
| 4282 | case XFA_XDPPACKET_LocaleSet: |
| 4283 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_LocaleSet)); |
| 4284 | case XFA_XDPPACKET_ConnectionSet: |
| 4285 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_ConnectionSet)); |
| 4286 | case XFA_XDPPACKET_SourceSet: |
| 4287 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_SourceSet)); |
| 4288 | case XFA_XDPPACKET_Xdc: |
| 4289 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Xdc)); |
| 4290 | default: |
| 4291 | return this; |
| 4292 | } |
| 4293 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4294 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4295 | bool CXFA_Node::TryNamespace(CFX_WideString& wsNamespace) { |
tsepez | 774bdde | 2016-04-14 09:49:44 -0700 | [diff] [blame] | 4296 | wsNamespace.clear(); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4297 | if (IsModelNode() || GetElementType() == XFA_Element::Packet) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 4298 | CFX_XMLNode* pXMLNode = GetXMLMappingNode(); |
| 4299 | if (!pXMLNode || pXMLNode->GetType() != FX_XMLNODE_Element) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4300 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4301 | } |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 4302 | wsNamespace = static_cast<CFX_XMLElement*>(pXMLNode)->GetNamespaceURI(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4303 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4304 | } else if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 4305 | CFX_XMLNode* pXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4306 | if (!pXMLNode) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4307 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4308 | } |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 4309 | if (pXMLNode->GetType() != FX_XMLNODE_Element) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4310 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4311 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4312 | if (GetElementType() == XFA_Element::DataValue && |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4313 | GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData) { |
| 4314 | return XFA_FDEExtension_ResolveNamespaceQualifier( |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 4315 | static_cast<CFX_XMLElement*>(pXMLNode), |
Dan Sinclair | 5fa4e98 | 2017-04-05 11:48:21 -0400 | [diff] [blame] | 4316 | GetCData(XFA_ATTRIBUTE_QualifiedName), &wsNamespace); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4317 | } |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 4318 | wsNamespace = static_cast<CFX_XMLElement*>(pXMLNode)->GetNamespaceURI(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4319 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4320 | } else { |
| 4321 | CXFA_Node* pModelNode = GetModelNode(); |
| 4322 | return pModelNode->TryNamespace(wsNamespace); |
| 4323 | } |
| 4324 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4325 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4326 | CXFA_Node* CXFA_Node::GetProperty(int32_t index, |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4327 | XFA_Element eProperty, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4328 | bool bCreateProperty) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4329 | XFA_Element eType = GetElementType(); |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 4330 | uint32_t dwPacket = GetPacketID(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4331 | const XFA_PROPERTY* pProperty = |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4332 | XFA_GetPropertyOfElement(eType, eProperty, dwPacket); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4333 | if (!pProperty || index >= pProperty->uOccur) |
| 4334 | return nullptr; |
| 4335 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4336 | CXFA_Node* pNode = m_pChild; |
| 4337 | int32_t iCount = 0; |
| 4338 | for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4339 | if (pNode->GetElementType() == eProperty) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4340 | iCount++; |
| 4341 | if (iCount > index) { |
| 4342 | return pNode; |
| 4343 | } |
| 4344 | } |
| 4345 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4346 | if (!bCreateProperty) |
| 4347 | return nullptr; |
| 4348 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4349 | if (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf) { |
| 4350 | pNode = m_pChild; |
| 4351 | for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 4352 | const XFA_PROPERTY* pExistProperty = |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4353 | XFA_GetPropertyOfElement(eType, pNode->GetElementType(), dwPacket); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4354 | if (pExistProperty && (pExistProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) |
| 4355 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4356 | } |
| 4357 | } |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4358 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4359 | const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(dwPacket); |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 4360 | CXFA_Node* pNewNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4361 | for (; iCount <= index; iCount++) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4362 | pNewNode = m_pDocument->CreateNode(pPacket, eProperty); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4363 | if (!pNewNode) |
| 4364 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4365 | InsertChild(pNewNode, nullptr); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4366 | pNewNode->SetFlag(XFA_NodeFlag_Initialized, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4367 | } |
| 4368 | return pNewNode; |
| 4369 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4370 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4371 | int32_t CXFA_Node::CountChildren(XFA_Element eType, bool bOnlyChild) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4372 | CXFA_Node* pNode = m_pChild; |
| 4373 | int32_t iCount = 0; |
| 4374 | for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4375 | if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4376 | if (bOnlyChild) { |
| 4377 | const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement( |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4378 | GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4379 | if (pProperty) { |
| 4380 | continue; |
| 4381 | } |
| 4382 | } |
| 4383 | iCount++; |
| 4384 | } |
| 4385 | } |
| 4386 | return iCount; |
| 4387 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4388 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4389 | CXFA_Node* CXFA_Node::GetChild(int32_t index, |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4390 | XFA_Element eType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4391 | bool bOnlyChild) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4392 | ASSERT(index > -1); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4393 | CXFA_Node* pNode = m_pChild; |
| 4394 | int32_t iCount = 0; |
| 4395 | for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4396 | if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4397 | if (bOnlyChild) { |
| 4398 | const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement( |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4399 | GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4400 | if (pProperty) { |
| 4401 | continue; |
| 4402 | } |
| 4403 | } |
| 4404 | iCount++; |
| 4405 | if (iCount > index) { |
| 4406 | return pNode; |
| 4407 | } |
| 4408 | } |
| 4409 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4410 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4411 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4412 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4413 | int32_t CXFA_Node::InsertChild(int32_t index, CXFA_Node* pNode) { |
| 4414 | ASSERT(!pNode->m_pNext); |
| 4415 | pNode->m_pParent = this; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4416 | bool ret = m_pDocument->RemovePurgeNode(pNode); |
Wei Li | 5fe7ae7 | 2016-05-04 21:13:15 -0700 | [diff] [blame] | 4417 | ASSERT(ret); |
Wei Li | 439bb9e | 2016-05-05 00:35:26 -0700 | [diff] [blame] | 4418 | (void)ret; // Avoid unused variable warning. |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4419 | |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4420 | if (!m_pChild || index == 0) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4421 | if (index > 0) { |
| 4422 | return -1; |
| 4423 | } |
| 4424 | pNode->m_pNext = m_pChild; |
| 4425 | m_pChild = pNode; |
| 4426 | index = 0; |
| 4427 | } else if (index < 0) { |
| 4428 | m_pLastChild->m_pNext = pNode; |
| 4429 | } else { |
| 4430 | CXFA_Node* pPrev = m_pChild; |
| 4431 | int32_t iCount = 0; |
| 4432 | while (++iCount != index && pPrev->m_pNext) { |
| 4433 | pPrev = pPrev->m_pNext; |
| 4434 | } |
| 4435 | if (index > 0 && index != iCount) { |
| 4436 | return -1; |
| 4437 | } |
| 4438 | pNode->m_pNext = pPrev->m_pNext; |
| 4439 | pPrev->m_pNext = pNode; |
| 4440 | index = iCount; |
| 4441 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4442 | if (!pNode->m_pNext) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4443 | m_pLastChild = pNode; |
| 4444 | } |
| 4445 | ASSERT(m_pLastChild); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4446 | ASSERT(!m_pLastChild->m_pNext); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4447 | pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4448 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4449 | if (pNotify) |
| 4450 | pNotify->OnChildAdded(this); |
| 4451 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4452 | if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 4453 | ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFX_XMLNode::Parent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4454 | m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, index); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4455 | pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4456 | } |
| 4457 | return index; |
| 4458 | } |
weili | 6e1ae86 | 2016-05-04 18:25:27 -0700 | [diff] [blame] | 4459 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4460 | bool CXFA_Node::InsertChild(CXFA_Node* pNode, CXFA_Node* pBeforeNode) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4461 | if (!pNode || pNode->m_pParent || |
| 4462 | (pBeforeNode && pBeforeNode->m_pParent != this)) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4463 | ASSERT(false); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4464 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4465 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4466 | bool ret = m_pDocument->RemovePurgeNode(pNode); |
Wei Li | 5fe7ae7 | 2016-05-04 21:13:15 -0700 | [diff] [blame] | 4467 | ASSERT(ret); |
Wei Li | 439bb9e | 2016-05-05 00:35:26 -0700 | [diff] [blame] | 4468 | (void)ret; // Avoid unused variable warning. |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4469 | |
| 4470 | int32_t nIndex = -1; |
| 4471 | pNode->m_pParent = this; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4472 | if (!m_pChild || pBeforeNode == m_pChild) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4473 | pNode->m_pNext = m_pChild; |
| 4474 | m_pChild = pNode; |
| 4475 | nIndex = 0; |
| 4476 | } else if (!pBeforeNode) { |
| 4477 | pNode->m_pNext = m_pLastChild->m_pNext; |
| 4478 | m_pLastChild->m_pNext = pNode; |
| 4479 | } else { |
| 4480 | nIndex = 1; |
| 4481 | CXFA_Node* pPrev = m_pChild; |
| 4482 | while (pPrev->m_pNext != pBeforeNode) { |
| 4483 | pPrev = pPrev->m_pNext; |
| 4484 | nIndex++; |
| 4485 | } |
| 4486 | pNode->m_pNext = pPrev->m_pNext; |
| 4487 | pPrev->m_pNext = pNode; |
| 4488 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4489 | if (!pNode->m_pNext) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4490 | m_pLastChild = pNode; |
| 4491 | } |
| 4492 | ASSERT(m_pLastChild); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4493 | ASSERT(!m_pLastChild->m_pNext); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4494 | pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4495 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4496 | if (pNotify) |
| 4497 | pNotify->OnChildAdded(this); |
| 4498 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4499 | if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) { |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 4500 | ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFX_XMLNode::Parent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4501 | m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, nIndex); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4502 | pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4503 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4504 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4505 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4506 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4507 | CXFA_Node* CXFA_Node::Deprecated_GetPrevSibling() { |
| 4508 | if (!m_pParent) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4509 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4510 | } |
| 4511 | for (CXFA_Node* pSibling = m_pParent->m_pChild; pSibling; |
| 4512 | pSibling = pSibling->m_pNext) { |
| 4513 | if (pSibling->m_pNext == this) { |
| 4514 | return pSibling; |
| 4515 | } |
| 4516 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4517 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4518 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4519 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4520 | bool CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4521 | if (!pNode || pNode->m_pParent != this) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4522 | ASSERT(false); |
| 4523 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4524 | } |
| 4525 | if (m_pChild == pNode) { |
| 4526 | m_pChild = pNode->m_pNext; |
| 4527 | if (m_pLastChild == pNode) { |
| 4528 | m_pLastChild = pNode->m_pNext; |
| 4529 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4530 | pNode->m_pNext = nullptr; |
| 4531 | pNode->m_pParent = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4532 | } else { |
| 4533 | CXFA_Node* pPrev = pNode->Deprecated_GetPrevSibling(); |
| 4534 | pPrev->m_pNext = pNode->m_pNext; |
| 4535 | if (m_pLastChild == pNode) { |
| 4536 | m_pLastChild = pNode->m_pNext ? pNode->m_pNext : pPrev; |
| 4537 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4538 | pNode->m_pNext = nullptr; |
| 4539 | pNode->m_pParent = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4540 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4541 | ASSERT(!m_pLastChild || !m_pLastChild->m_pNext); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4542 | OnRemoved(bNotify); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4543 | pNode->SetFlag(XFA_NodeFlag_HasRemovedChildren, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4544 | m_pDocument->AddPurgeNode(pNode); |
| 4545 | if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) { |
| 4546 | if (pNode->IsAttributeInXML()) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4547 | ASSERT(pNode->m_pXMLNode == m_pXMLNode && |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 4548 | m_pXMLNode->GetType() == FX_XMLNODE_Element); |
| 4549 | if (pNode->m_pXMLNode->GetType() == FX_XMLNODE_Element) { |
| 4550 | CFX_XMLElement* pXMLElement = |
| 4551 | static_cast<CFX_XMLElement*>(pNode->m_pXMLNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4552 | CFX_WideStringC wsAttributeName = |
| 4553 | pNode->GetCData(XFA_ATTRIBUTE_QualifiedName); |
tsepez | 660956f | 2016-04-06 06:27:29 -0700 | [diff] [blame] | 4554 | pXMLElement->RemoveAttribute(wsAttributeName.c_str()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4555 | } |
| 4556 | CFX_WideString wsName; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4557 | pNode->GetAttribute(XFA_ATTRIBUTE_Name, wsName, false); |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 4558 | CFX_XMLElement* pNewXMLElement = new CFX_XMLElement(wsName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4559 | CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value); |
| 4560 | if (!wsValue.IsEmpty()) { |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 4561 | pNewXMLElement->SetTextData(CFX_WideString(wsValue)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4562 | } |
| 4563 | pNode->m_pXMLNode = pNewXMLElement; |
| 4564 | pNode->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown); |
| 4565 | } else { |
| 4566 | m_pXMLNode->RemoveChildNode(pNode->m_pXMLNode); |
| 4567 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4568 | pNode->SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4569 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4570 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4571 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4572 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4573 | CXFA_Node* CXFA_Node::GetFirstChildByName(const CFX_WideStringC& wsName) const { |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 4574 | return GetFirstChildByName(FX_HashCode_GetW(wsName, false)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4575 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4576 | |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 4577 | CXFA_Node* CXFA_Node::GetFirstChildByName(uint32_t dwNameHash) const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4578 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode; |
| 4579 | pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 4580 | if (pNode->GetNameHash() == dwNameHash) { |
| 4581 | return pNode; |
| 4582 | } |
| 4583 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4584 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4585 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4586 | |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4587 | CXFA_Node* CXFA_Node::GetFirstChildByClass(XFA_Element eType) const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4588 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode; |
| 4589 | pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4590 | if (pNode->GetElementType() == eType) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4591 | return pNode; |
| 4592 | } |
| 4593 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4594 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4595 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4596 | |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 4597 | CXFA_Node* CXFA_Node::GetNextSameNameSibling(uint32_t dwNameHash) const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4598 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode; |
| 4599 | pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 4600 | if (pNode->GetNameHash() == dwNameHash) { |
| 4601 | return pNode; |
| 4602 | } |
| 4603 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4604 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4605 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4606 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4607 | CXFA_Node* CXFA_Node::GetNextSameNameSibling( |
| 4608 | const CFX_WideStringC& wsNodeName) const { |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 4609 | return GetNextSameNameSibling(FX_HashCode_GetW(wsNodeName, false)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4610 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4611 | |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4612 | CXFA_Node* CXFA_Node::GetNextSameClassSibling(XFA_Element eType) const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4613 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode; |
| 4614 | pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4615 | if (pNode->GetElementType() == eType) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4616 | return pNode; |
| 4617 | } |
| 4618 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4619 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4620 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4621 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4622 | int32_t CXFA_Node::GetNodeSameNameIndex() const { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 4623 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4624 | if (!pScriptContext) { |
| 4625 | return -1; |
| 4626 | } |
| 4627 | return pScriptContext->GetIndexByName(const_cast<CXFA_Node*>(this)); |
| 4628 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4629 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4630 | int32_t CXFA_Node::GetNodeSameClassIndex() const { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 4631 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4632 | if (!pScriptContext) { |
| 4633 | return -1; |
| 4634 | } |
| 4635 | return pScriptContext->GetIndexByClassName(const_cast<CXFA_Node*>(this)); |
| 4636 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4637 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4638 | void CXFA_Node::GetSOMExpression(CFX_WideString& wsSOMExpression) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 4639 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4640 | if (!pScriptContext) { |
| 4641 | return; |
| 4642 | } |
| 4643 | pScriptContext->GetSomExpression(this, wsSOMExpression); |
| 4644 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4645 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4646 | CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4647 | CXFA_Node* pInstanceMgr = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4648 | if (m_ePacket == XFA_XDPPACKET_Form) { |
| 4649 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4650 | if (!pParentNode || pParentNode->GetElementType() == XFA_Element::Area) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4651 | return pInstanceMgr; |
| 4652 | } |
| 4653 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; |
| 4654 | pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4655 | XFA_Element eType = pNode->GetElementType(); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4656 | if ((eType == XFA_Element::Subform || eType == XFA_Element::SubformSet) && |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4657 | pNode->m_dwNameHash != m_dwNameHash) { |
| 4658 | break; |
| 4659 | } |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4660 | if (eType == XFA_Element::InstanceManager) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4661 | CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name); |
| 4662 | CFX_WideStringC wsInstName = pNode->GetCData(XFA_ATTRIBUTE_Name); |
| 4663 | if (wsInstName.GetLength() > 0 && wsInstName.GetAt(0) == '_' && |
| 4664 | wsInstName.Mid(1) == wsName) { |
| 4665 | pInstanceMgr = pNode; |
| 4666 | } |
| 4667 | break; |
| 4668 | } |
| 4669 | } |
| 4670 | } |
| 4671 | return pInstanceMgr; |
| 4672 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4673 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4674 | CXFA_Node* CXFA_Node::GetOccurNode() { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4675 | return GetFirstChildByClass(XFA_Element::Occur); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4676 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4677 | |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4678 | bool CXFA_Node::HasFlag(XFA_NodeFlag dwFlag) const { |
| 4679 | if (m_uNodeFlags & dwFlag) |
| 4680 | return true; |
| 4681 | if (dwFlag == XFA_NodeFlag_HasRemovedChildren) |
| 4682 | return m_pParent && m_pParent->HasFlag(dwFlag); |
| 4683 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4684 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4685 | |
| 4686 | void CXFA_Node::SetFlag(uint32_t dwFlag, bool bNotify) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4687 | if (dwFlag == XFA_NodeFlag_Initialized && bNotify && !IsInitialized()) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4688 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4689 | if (pNotify) { |
| 4690 | pNotify->OnNodeReady(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4691 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4692 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4693 | m_uNodeFlags |= dwFlag; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4694 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4695 | |
| 4696 | void CXFA_Node::ClearFlag(uint32_t dwFlag) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4697 | m_uNodeFlags &= ~dwFlag; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4698 | } |
| 4699 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4700 | bool CXFA_Node::IsAttributeInXML() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4701 | return GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData; |
| 4702 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4703 | |
| 4704 | void CXFA_Node::OnRemoved(bool bNotify) { |
| 4705 | if (!bNotify) |
| 4706 | return; |
| 4707 | |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4708 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4709 | if (pNotify) |
| 4710 | pNotify->OnChildRemoved(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4711 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4712 | |
| 4713 | void CXFA_Node::OnChanging(XFA_ATTRIBUTE eAttr, bool bNotify) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4714 | if (bNotify && IsInitialized()) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4715 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4716 | if (pNotify) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4717 | pNotify->OnValueChanging(this, eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4718 | } |
| 4719 | } |
| 4720 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4721 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4722 | void CXFA_Node::OnChanged(XFA_ATTRIBUTE eAttr, |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4723 | bool bNotify, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4724 | bool bScriptModify) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4725 | if (bNotify && IsInitialized()) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4726 | Script_Attribute_SendAttributeChangeMessage(eAttr, bScriptModify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4727 | } |
| 4728 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4729 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4730 | int32_t CXFA_Node::execSingleEventByName(const CFX_WideStringC& wsEventName, |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4731 | XFA_Element eType) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4732 | int32_t iRet = XFA_EVENTERROR_NotExist; |
| 4733 | const XFA_ExecEventParaInfo* eventParaInfo = |
| 4734 | GetEventParaInfoByName(wsEventName); |
| 4735 | if (eventParaInfo) { |
| 4736 | uint32_t validFlags = eventParaInfo->m_validFlags; |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4737 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4738 | if (!pNotify) { |
| 4739 | return iRet; |
| 4740 | } |
| 4741 | if (validFlags == 1) { |
| 4742 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType); |
| 4743 | } else if (validFlags == 2) { |
| 4744 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4745 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4746 | } else if (validFlags == 3) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4747 | if (eType == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4748 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4749 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4750 | } |
| 4751 | } else if (validFlags == 4) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4752 | if (eType == XFA_Element::ExclGroup || eType == XFA_Element::Field) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4753 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4754 | if (pParentNode && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4755 | pParentNode->GetElementType() == XFA_Element::ExclGroup) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4756 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4757 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4758 | } |
| 4759 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4760 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4761 | } |
| 4762 | } else if (validFlags == 5) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4763 | if (eType == XFA_Element::Field) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4764 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4765 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4766 | } |
| 4767 | } else if (validFlags == 6) { |
| 4768 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 4769 | if (pWidgetData) { |
| 4770 | CXFA_Node* pUINode = pWidgetData->GetUIChild(); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4771 | if (pUINode->m_elementType == XFA_Element::Signature) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4772 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4773 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4774 | } |
| 4775 | } |
| 4776 | } else if (validFlags == 7) { |
| 4777 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 4778 | if (pWidgetData) { |
| 4779 | CXFA_Node* pUINode = pWidgetData->GetUIChild(); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4780 | if ((pUINode->m_elementType == XFA_Element::ChoiceList) && |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4781 | (!pWidgetData->IsListBox())) { |
| 4782 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4783 | false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4784 | } |
| 4785 | } |
| 4786 | } |
| 4787 | } |
| 4788 | return iRet; |
| 4789 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4790 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4791 | void CXFA_Node::UpdateNameHash() { |
| 4792 | const XFA_NOTSUREATTRIBUTE* pNotsure = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4793 | XFA_GetNotsureAttribute(GetElementType(), XFA_ATTRIBUTE_Name); |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 4794 | CFX_WideStringC wsName; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4795 | if (!pNotsure || pNotsure->eType == XFA_ATTRIBUTETYPE_Cdata) { |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 4796 | wsName = GetCData(XFA_ATTRIBUTE_Name); |
| 4797 | m_dwNameHash = FX_HashCode_GetW(wsName, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4798 | } else if (pNotsure->eType == XFA_ATTRIBUTETYPE_Enum) { |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 4799 | wsName = GetAttributeEnumByID(GetEnum(XFA_ATTRIBUTE_Name))->pName; |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 4800 | m_dwNameHash = FX_HashCode_GetW(wsName, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4801 | } |
| 4802 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4803 | |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 4804 | CFX_XMLNode* CXFA_Node::CreateXMLMappingNode() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4805 | if (!m_pXMLNode) { |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 4806 | CFX_WideString wsTag(GetCData(XFA_ATTRIBUTE_Name)); |
Dan Sinclair | 0d86ecb | 2017-04-19 09:19:57 -0400 | [diff] [blame] | 4807 | m_pXMLNode = new CFX_XMLElement(wsTag); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4808 | SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4809 | } |
| 4810 | return m_pXMLNode; |
| 4811 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4812 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4813 | bool CXFA_Node::IsNeedSavingXMLNode() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4814 | return m_pXMLNode && (GetPacketID() == XFA_XDPPACKET_Datasets || |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4815 | GetElementType() == XFA_Element::Xfa); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4816 | } |
| 4817 | |
| 4818 | XFA_MAPMODULEDATA* CXFA_Node::CreateMapModuleData() { |
| 4819 | if (!m_pMapModuleData) |
| 4820 | m_pMapModuleData = new XFA_MAPMODULEDATA; |
| 4821 | return m_pMapModuleData; |
| 4822 | } |
| 4823 | |
| 4824 | XFA_MAPMODULEDATA* CXFA_Node::GetMapModuleData() const { |
| 4825 | return m_pMapModuleData; |
| 4826 | } |
| 4827 | |
| 4828 | void CXFA_Node::SetMapModuleValue(void* pKey, void* pValue) { |
| 4829 | XFA_MAPMODULEDATA* pModule = CreateMapModuleData(); |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4830 | pModule->m_ValueMap[pKey] = pValue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4831 | } |
| 4832 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4833 | bool CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) { |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4834 | for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4835 | XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData(); |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4836 | if (pModule) { |
| 4837 | auto it = pModule->m_ValueMap.find(pKey); |
| 4838 | if (it != pModule->m_ValueMap.end()) { |
| 4839 | pValue = it->second; |
| 4840 | return true; |
| 4841 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4842 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4843 | if (pNode->GetPacketID() == XFA_XDPPACKET_Datasets) |
| 4844 | break; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4845 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4846 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4847 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4848 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4849 | void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) { |
tsepez | 660956f | 2016-04-06 06:27:29 -0700 | [diff] [blame] | 4850 | SetMapModuleBuffer(pKey, (void*)wsValue.c_str(), |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 4851 | wsValue.GetLength() * sizeof(wchar_t)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4852 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4853 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4854 | bool CXFA_Node::GetMapModuleString(void* pKey, CFX_WideStringC& wsValue) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4855 | void* pValue; |
| 4856 | int32_t iBytes; |
| 4857 | if (!GetMapModuleBuffer(pKey, pValue, iBytes)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4858 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4859 | } |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 4860 | wsValue = CFX_WideStringC((const wchar_t*)pValue, iBytes / sizeof(wchar_t)); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4861 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4862 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4863 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4864 | void CXFA_Node::SetMapModuleBuffer( |
| 4865 | void* pKey, |
| 4866 | void* pValue, |
| 4867 | int32_t iBytes, |
| 4868 | XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) { |
| 4869 | XFA_MAPMODULEDATA* pModule = CreateMapModuleData(); |
| 4870 | XFA_MAPDATABLOCK*& pBuffer = pModule->m_BufferMap[pKey]; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4871 | if (!pBuffer) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4872 | pBuffer = |
| 4873 | (XFA_MAPDATABLOCK*)FX_Alloc(uint8_t, sizeof(XFA_MAPDATABLOCK) + iBytes); |
| 4874 | } else if (pBuffer->iBytes != iBytes) { |
| 4875 | if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { |
| 4876 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
| 4877 | } |
| 4878 | pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(uint8_t, pBuffer, |
| 4879 | sizeof(XFA_MAPDATABLOCK) + iBytes); |
| 4880 | } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { |
| 4881 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
| 4882 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4883 | if (!pBuffer) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4884 | return; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4885 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4886 | pBuffer->pCallbackInfo = pCallbackInfo; |
| 4887 | pBuffer->iBytes = iBytes; |
Dan Sinclair | 1c5d0b4 | 2017-04-03 15:05:11 -0400 | [diff] [blame] | 4888 | memcpy(pBuffer->GetData(), pValue, iBytes); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4889 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4890 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4891 | bool CXFA_Node::GetMapModuleBuffer(void* pKey, |
| 4892 | void*& pValue, |
| 4893 | int32_t& iBytes, |
| 4894 | bool bProtoAlso) const { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4895 | XFA_MAPDATABLOCK* pBuffer = nullptr; |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4896 | for (const CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4897 | XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData(); |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4898 | if (pModule) { |
| 4899 | auto it = pModule->m_BufferMap.find(pKey); |
| 4900 | if (it != pModule->m_BufferMap.end()) { |
| 4901 | pBuffer = it->second; |
| 4902 | break; |
| 4903 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4904 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4905 | if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets) |
| 4906 | break; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4907 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4908 | if (!pBuffer) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4909 | return false; |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4910 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4911 | pValue = pBuffer->GetData(); |
| 4912 | iBytes = pBuffer->iBytes; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4913 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4914 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4915 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4916 | bool CXFA_Node::HasMapModuleKey(void* pKey, bool bProtoAlso) { |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4917 | for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4918 | XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData(); |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4919 | if (pModule) { |
| 4920 | auto it1 = pModule->m_ValueMap.find(pKey); |
| 4921 | if (it1 != pModule->m_ValueMap.end()) |
| 4922 | return true; |
| 4923 | |
| 4924 | auto it2 = pModule->m_BufferMap.find(pKey); |
| 4925 | if (it2 != pModule->m_BufferMap.end()) |
| 4926 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4927 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4928 | if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets) |
| 4929 | break; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4930 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 4931 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4932 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4933 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4934 | void CXFA_Node::RemoveMapModuleKey(void* pKey) { |
| 4935 | XFA_MAPMODULEDATA* pModule = GetMapModuleData(); |
| 4936 | if (!pModule) |
| 4937 | return; |
| 4938 | |
| 4939 | if (pKey) { |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4940 | auto it = pModule->m_BufferMap.find(pKey); |
| 4941 | if (it != pModule->m_BufferMap.end()) { |
| 4942 | XFA_MAPDATABLOCK* pBuffer = it->second; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4943 | if (pBuffer) { |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4944 | if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4945 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4946 | FX_Free(pBuffer); |
| 4947 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4948 | pModule->m_BufferMap.erase(it); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4949 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4950 | pModule->m_ValueMap.erase(pKey); |
| 4951 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4952 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4953 | |
| 4954 | for (auto& pair : pModule->m_BufferMap) { |
| 4955 | XFA_MAPDATABLOCK* pBuffer = pair.second; |
| 4956 | if (pBuffer) { |
| 4957 | if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) |
| 4958 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
| 4959 | FX_Free(pBuffer); |
| 4960 | } |
| 4961 | } |
| 4962 | pModule->m_BufferMap.clear(); |
| 4963 | pModule->m_ValueMap.clear(); |
| 4964 | delete pModule; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4965 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4966 | |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4967 | void CXFA_Node::MergeAllData(void* pDstModule) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4968 | XFA_MAPMODULEDATA* pDstModuleData = |
| 4969 | static_cast<CXFA_Node*>(pDstModule)->CreateMapModuleData(); |
| 4970 | XFA_MAPMODULEDATA* pSrcModuleData = GetMapModuleData(); |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4971 | if (!pSrcModuleData) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4972 | return; |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4973 | |
| 4974 | for (const auto& pair : pSrcModuleData->m_ValueMap) |
| 4975 | pDstModuleData->m_ValueMap[pair.first] = pair.second; |
| 4976 | |
| 4977 | for (const auto& pair : pSrcModuleData->m_BufferMap) { |
| 4978 | XFA_MAPDATABLOCK* pSrcBuffer = pair.second; |
| 4979 | XFA_MAPDATABLOCK*& pDstBuffer = pDstModuleData->m_BufferMap[pair.first]; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4980 | if (pSrcBuffer->pCallbackInfo && pSrcBuffer->pCallbackInfo->pFree && |
| 4981 | !pSrcBuffer->pCallbackInfo->pCopy) { |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4982 | if (pDstBuffer) { |
| 4983 | pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData()); |
| 4984 | pDstModuleData->m_BufferMap.erase(pair.first); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4985 | } |
| 4986 | continue; |
| 4987 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4988 | if (!pDstBuffer) { |
| 4989 | pDstBuffer = (XFA_MAPDATABLOCK*)FX_Alloc( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4990 | uint8_t, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes); |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4991 | } else if (pDstBuffer->iBytes != pSrcBuffer->iBytes) { |
| 4992 | if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) { |
| 4993 | pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4994 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 4995 | pDstBuffer = (XFA_MAPDATABLOCK*)FX_Realloc( |
| 4996 | uint8_t, pDstBuffer, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes); |
| 4997 | } else if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) { |
| 4998 | pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4999 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 5000 | if (!pDstBuffer) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5001 | continue; |
| 5002 | } |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 5003 | pDstBuffer->pCallbackInfo = pSrcBuffer->pCallbackInfo; |
| 5004 | pDstBuffer->iBytes = pSrcBuffer->iBytes; |
Dan Sinclair | 1c5d0b4 | 2017-04-03 15:05:11 -0400 | [diff] [blame] | 5005 | memcpy(pDstBuffer->GetData(), pSrcBuffer->GetData(), pSrcBuffer->iBytes); |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 5006 | if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pCopy) { |
| 5007 | pDstBuffer->pCallbackInfo->pCopy(*(void**)pDstBuffer->GetData()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5008 | } |
| 5009 | } |
| 5010 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 5011 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5012 | void CXFA_Node::MoveBufferMapData(CXFA_Node* pDstModule, void* pKey) { |
| 5013 | if (!pDstModule) { |
| 5014 | return; |
| 5015 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5016 | bool bNeedMove = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5017 | if (!pKey) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5018 | bNeedMove = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5019 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 5020 | if (pDstModule->GetElementType() != GetElementType()) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5021 | bNeedMove = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5022 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5023 | XFA_MAPMODULEDATA* pSrcModuleData = nullptr; |
| 5024 | XFA_MAPMODULEDATA* pDstModuleData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5025 | if (bNeedMove) { |
| 5026 | pSrcModuleData = GetMapModuleData(); |
| 5027 | if (!pSrcModuleData) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5028 | bNeedMove = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5029 | } |
| 5030 | pDstModuleData = pDstModule->CreateMapModuleData(); |
| 5031 | } |
| 5032 | if (bNeedMove) { |
tsepez | 6bb3b89 | 2017-01-05 12:18:41 -0800 | [diff] [blame] | 5033 | auto it = pSrcModuleData->m_BufferMap.find(pKey); |
| 5034 | if (it != pSrcModuleData->m_BufferMap.end()) { |
| 5035 | XFA_MAPDATABLOCK* pBufferBlockData = it->second; |
| 5036 | if (pBufferBlockData) { |
| 5037 | pSrcModuleData->m_BufferMap.erase(pKey); |
| 5038 | pDstModuleData->m_BufferMap[pKey] = pBufferBlockData; |
| 5039 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5040 | } |
| 5041 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 5042 | if (pDstModule->IsNodeV()) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5043 | CFX_WideString wsValue = pDstModule->GetScriptContent(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5044 | CFX_WideString wsFormatValue(wsValue); |
| 5045 | CXFA_WidgetData* pWidgetData = pDstModule->GetContainerWidgetData(); |
| 5046 | if (pWidgetData) { |
tsepez | 6f167c3 | 2016-04-14 15:46:27 -0700 | [diff] [blame] | 5047 | pWidgetData->GetFormatDataValue(wsValue, wsFormatValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5048 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5049 | pDstModule->SetScriptContent(wsValue, wsFormatValue, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5050 | } |
| 5051 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 5052 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5053 | void CXFA_Node::MoveBufferMapData(CXFA_Node* pSrcModule, |
| 5054 | CXFA_Node* pDstModule, |
| 5055 | void* pKey, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5056 | bool bRecursive) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5057 | if (!pSrcModule || !pDstModule || !pKey) { |
| 5058 | return; |
| 5059 | } |
| 5060 | if (bRecursive) { |
| 5061 | CXFA_Node* pSrcChild = pSrcModule->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 5062 | CXFA_Node* pDstChild = pDstModule->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 5063 | for (; pSrcChild && pDstChild; |
| 5064 | pSrcChild = pSrcChild->GetNodeItem(XFA_NODEITEM_NextSibling), |
| 5065 | pDstChild = pDstChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 5066 | MoveBufferMapData(pSrcChild, pDstChild, pKey, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5067 | } |
| 5068 | } |
| 5069 | pSrcModule->MoveBufferMapData(pDstModule, pKey); |
| 5070 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 5071 | |
| 5072 | void CXFA_Node::ThrowMissingPropertyException( |
| 5073 | const CFX_WideString& obj, |
| 5074 | const CFX_WideString& prop) const { |
| 5075 | ThrowException(L"'%s' doesn't have property '%s'.", obj.c_str(), |
| 5076 | prop.c_str()); |
| 5077 | } |
| 5078 | |
| 5079 | void CXFA_Node::ThrowTooManyOccurancesException( |
| 5080 | const CFX_WideString& obj) const { |
| 5081 | ThrowException( |
| 5082 | L"The element [%s] has violated its allowable number of occurrences.", |
| 5083 | obj.c_str()); |
| 5084 | } |