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