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" |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 20 | #include "xfa/fde/xml/fde_xml_imp.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 21 | #include "xfa/fgas/crt/fgas_codepage.h" |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 22 | #include "xfa/fxfa/app/xfa_ffnotify.h" |
dsinclair | 5b49309 | 2016-09-29 20:20:24 -0700 | [diff] [blame] | 23 | #include "xfa/fxfa/cxfa_eventparam.h" |
Dan Sinclair | efcae5d | 2017-03-29 14:47:46 -0400 | [diff] [blame] | 24 | #include "xfa/fxfa/cxfa_ffwidget.h" |
| 25 | #include "xfa/fxfa/parser/cxfa_arraynodelist.h" |
| 26 | #include "xfa/fxfa/parser/cxfa_attachnodelist.h" |
dsinclair | 1628024 | 2016-07-21 12:03:47 -0700 | [diff] [blame] | 27 | #include "xfa/fxfa/parser/cxfa_document.h" |
dsinclair | 0b851ff | 2016-07-21 12:03:01 -0700 | [diff] [blame] | 28 | #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 29 | #include "xfa/fxfa/parser/cxfa_measurement.h" |
dsinclair | 44d054c | 2016-04-06 10:23:46 -0700 | [diff] [blame] | 30 | #include "xfa/fxfa/parser/cxfa_occur.h" |
dsinclair | 31f8740 | 2016-07-20 06:34:45 -0700 | [diff] [blame] | 31 | #include "xfa/fxfa/parser/cxfa_scriptcontext.h" |
dsinclair | 34f86b0 | 2016-07-11 08:42:33 -0700 | [diff] [blame] | 32 | #include "xfa/fxfa/parser/cxfa_simple_parser.h" |
Dan Sinclair | efcae5d | 2017-03-29 14:47:46 -0400 | [diff] [blame] | 33 | #include "xfa/fxfa/parser/cxfa_traversestrategy_xfacontainernode.h" |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 34 | #include "xfa/fxfa/parser/xfa_basic_data.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 35 | |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 36 | namespace { |
| 37 | |
| 38 | void XFA_DeleteWideString(void* pData) { |
| 39 | delete static_cast<CFX_WideString*>(pData); |
| 40 | } |
| 41 | |
| 42 | void XFA_CopyWideString(void*& pData) { |
| 43 | if (pData) { |
| 44 | CFX_WideString* pNewData = new CFX_WideString(*(CFX_WideString*)pData); |
| 45 | pData = pNewData; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | XFA_MAPDATABLOCKCALLBACKINFO deleteWideStringCallBack = {XFA_DeleteWideString, |
| 50 | XFA_CopyWideString}; |
| 51 | |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 52 | void XFA_DataNodeDeleteBindItem(void* pData) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 53 | delete static_cast<std::vector<CXFA_Node*>*>(pData); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | XFA_MAPDATABLOCKCALLBACKINFO deleteBindItemCallBack = { |
| 57 | XFA_DataNodeDeleteBindItem, nullptr}; |
| 58 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 59 | int32_t GetCount(CXFA_Node* pInstMgrNode) { |
| 60 | ASSERT(pInstMgrNode); |
| 61 | int32_t iCount = 0; |
| 62 | uint32_t dwNameHash = 0; |
| 63 | for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 64 | pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 65 | XFA_Element eCurType = pNode->GetElementType(); |
| 66 | if (eCurType == XFA_Element::InstanceManager) |
| 67 | break; |
| 68 | if ((eCurType != XFA_Element::Subform) && |
| 69 | (eCurType != XFA_Element::SubformSet)) { |
| 70 | continue; |
| 71 | } |
| 72 | if (iCount == 0) { |
| 73 | CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name); |
| 74 | CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name); |
| 75 | if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' || |
| 76 | wsInstName.Mid(1) != wsName) { |
| 77 | return iCount; |
| 78 | } |
| 79 | dwNameHash = pNode->GetNameHash(); |
| 80 | } |
| 81 | if (dwNameHash != pNode->GetNameHash()) |
| 82 | break; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 83 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 84 | iCount++; |
| 85 | } |
| 86 | return iCount; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 87 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 88 | |
Tom Sepez | 7cdc660 | 2017-03-28 09:56:48 -0700 | [diff] [blame] | 89 | std::vector<CXFA_Node*> NodesSortedByDocumentIdx( |
| 90 | const std::unordered_set<CXFA_Node*>& rgNodeSet) { |
| 91 | if (rgNodeSet.empty()) |
| 92 | return std::vector<CXFA_Node*>(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 93 | |
Tom Sepez | 7cdc660 | 2017-03-28 09:56:48 -0700 | [diff] [blame] | 94 | std::vector<CXFA_Node*> rgNodeArray; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 95 | CXFA_Node* pCommonParent = |
| 96 | (*rgNodeSet.begin())->GetNodeItem(XFA_NODEITEM_Parent); |
| 97 | for (CXFA_Node* pNode = pCommonParent->GetNodeItem(XFA_NODEITEM_FirstChild); |
Tom Sepez | 7cdc660 | 2017-03-28 09:56:48 -0700 | [diff] [blame] | 98 | pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 99 | if (pdfium::ContainsValue(rgNodeSet, pNode)) |
| 100 | rgNodeArray.push_back(pNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 101 | } |
Tom Sepez | 7cdc660 | 2017-03-28 09:56:48 -0700 | [diff] [blame] | 102 | return rgNodeArray; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 103 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 104 | |
Tom Sepez | d4db58f | 2017-03-02 14:57:59 -0800 | [diff] [blame] | 105 | using CXFA_NodeSetPair = |
| 106 | std::pair<std::unordered_set<CXFA_Node*>, std::unordered_set<CXFA_Node*>>; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 107 | using CXFA_NodeSetPairMap = |
| 108 | std::map<uint32_t, std::unique_ptr<CXFA_NodeSetPair>>; |
| 109 | using CXFA_NodeSetPairMapMap = |
| 110 | std::map<CXFA_Node*, std::unique_ptr<CXFA_NodeSetPairMap>>; |
| 111 | |
| 112 | CXFA_NodeSetPair* NodeSetPairForNode(CXFA_Node* pNode, |
| 113 | CXFA_NodeSetPairMapMap* pMap) { |
| 114 | CXFA_Node* pParentNode = pNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 115 | uint32_t dwNameHash = pNode->GetNameHash(); |
| 116 | if (!pParentNode || !dwNameHash) |
| 117 | return nullptr; |
| 118 | |
| 119 | if (!(*pMap)[pParentNode]) |
tsepez | a9caab9 | 2016-12-14 05:57:10 -0800 | [diff] [blame] | 120 | (*pMap)[pParentNode] = pdfium::MakeUnique<CXFA_NodeSetPairMap>(); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 121 | |
| 122 | CXFA_NodeSetPairMap* pNodeSetPairMap = (*pMap)[pParentNode].get(); |
| 123 | if (!(*pNodeSetPairMap)[dwNameHash]) |
tsepez | a9caab9 | 2016-12-14 05:57:10 -0800 | [diff] [blame] | 124 | (*pNodeSetPairMap)[dwNameHash] = pdfium::MakeUnique<CXFA_NodeSetPair>(); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 125 | |
| 126 | return (*pNodeSetPairMap)[dwNameHash].get(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 127 | } |
| 128 | |
Tom Sepez | d4db58f | 2017-03-02 14:57:59 -0800 | [diff] [blame] | 129 | void ReorderDataNodes(const std::unordered_set<CXFA_Node*>& sSet1, |
| 130 | const std::unordered_set<CXFA_Node*>& sSet2, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 131 | bool bInsertBefore) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 132 | CXFA_NodeSetPairMapMap rgMap; |
| 133 | for (CXFA_Node* pNode : sSet1) { |
| 134 | CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap); |
| 135 | if (pNodeSetPair) |
| 136 | pNodeSetPair->first.insert(pNode); |
| 137 | } |
| 138 | for (CXFA_Node* pNode : sSet2) { |
| 139 | CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap); |
| 140 | if (pNodeSetPair) { |
| 141 | if (pdfium::ContainsValue(pNodeSetPair->first, pNode)) |
| 142 | pNodeSetPair->first.erase(pNode); |
| 143 | else |
| 144 | pNodeSetPair->second.insert(pNode); |
| 145 | } |
| 146 | } |
| 147 | for (const auto& iter1 : rgMap) { |
| 148 | CXFA_NodeSetPairMap* pNodeSetPairMap = iter1.second.get(); |
| 149 | if (!pNodeSetPairMap) |
| 150 | continue; |
| 151 | |
| 152 | for (const auto& iter2 : *pNodeSetPairMap) { |
| 153 | CXFA_NodeSetPair* pNodeSetPair = iter2.second.get(); |
| 154 | if (!pNodeSetPair) |
| 155 | continue; |
| 156 | if (!pNodeSetPair->first.empty() && !pNodeSetPair->second.empty()) { |
Tom Sepez | 7cdc660 | 2017-03-28 09:56:48 -0700 | [diff] [blame] | 157 | std::vector<CXFA_Node*> rgNodeArray1 = |
| 158 | NodesSortedByDocumentIdx(pNodeSetPair->first); |
| 159 | std::vector<CXFA_Node*> rgNodeArray2 = |
| 160 | NodesSortedByDocumentIdx(pNodeSetPair->second); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 161 | CXFA_Node* pParentNode = nullptr; |
| 162 | CXFA_Node* pBeforeNode = nullptr; |
| 163 | if (bInsertBefore) { |
Tom Sepez | 7cdc660 | 2017-03-28 09:56:48 -0700 | [diff] [blame] | 164 | pBeforeNode = rgNodeArray2.front(); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 165 | pParentNode = pBeforeNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 166 | } else { |
Tom Sepez | 7cdc660 | 2017-03-28 09:56:48 -0700 | [diff] [blame] | 167 | CXFA_Node* pLastNode = rgNodeArray2.back(); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 168 | pParentNode = pLastNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 169 | pBeforeNode = pLastNode->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 170 | } |
Tom Sepez | 7cdc660 | 2017-03-28 09:56:48 -0700 | [diff] [blame] | 171 | for (auto* pCurNode : rgNodeArray1) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 172 | pParentNode->RemoveChild(pCurNode); |
| 173 | pParentNode->InsertChild(pCurNode, pBeforeNode); |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | pNodeSetPairMap->clear(); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | CXFA_Node* GetItem(CXFA_Node* pInstMgrNode, int32_t iIndex) { |
| 182 | ASSERT(pInstMgrNode); |
| 183 | int32_t iCount = 0; |
| 184 | uint32_t dwNameHash = 0; |
| 185 | for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 186 | pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 187 | XFA_Element eCurType = pNode->GetElementType(); |
| 188 | if (eCurType == XFA_Element::InstanceManager) |
| 189 | break; |
| 190 | if ((eCurType != XFA_Element::Subform) && |
| 191 | (eCurType != XFA_Element::SubformSet)) { |
| 192 | continue; |
| 193 | } |
| 194 | if (iCount == 0) { |
| 195 | CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name); |
| 196 | CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name); |
| 197 | if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' || |
| 198 | wsInstName.Mid(1) != wsName) { |
| 199 | return nullptr; |
| 200 | } |
| 201 | dwNameHash = pNode->GetNameHash(); |
| 202 | } |
| 203 | if (dwNameHash != pNode->GetNameHash()) |
| 204 | break; |
| 205 | |
| 206 | iCount++; |
| 207 | if (iCount > iIndex) |
| 208 | return pNode; |
| 209 | } |
| 210 | return nullptr; |
| 211 | } |
| 212 | |
| 213 | void InsertItem(CXFA_Node* pInstMgrNode, |
| 214 | CXFA_Node* pNewInstance, |
| 215 | int32_t iPos, |
| 216 | int32_t iCount = -1, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 217 | bool bMoveDataBindingNodes = true) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 218 | if (iCount < 0) |
| 219 | iCount = GetCount(pInstMgrNode); |
| 220 | if (iPos < 0) |
| 221 | iPos = iCount; |
| 222 | if (iPos == iCount) { |
| 223 | CXFA_Node* pNextSibling = |
| 224 | iCount > 0 |
| 225 | ? GetItem(pInstMgrNode, iCount - 1) |
| 226 | ->GetNodeItem(XFA_NODEITEM_NextSibling) |
| 227 | : pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 228 | pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent) |
| 229 | ->InsertChild(pNewInstance, pNextSibling); |
| 230 | if (bMoveDataBindingNodes) { |
Tom Sepez | d4db58f | 2017-03-02 14:57:59 -0800 | [diff] [blame] | 231 | std::unordered_set<CXFA_Node*> sNew; |
| 232 | std::unordered_set<CXFA_Node*> sAfter; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 233 | CXFA_NodeIteratorTemplate<CXFA_Node, |
| 234 | CXFA_TraverseStrategy_XFAContainerNode> |
| 235 | sIteratorNew(pNewInstance); |
| 236 | for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode; |
| 237 | pNode = sIteratorNew.MoveToNext()) { |
| 238 | CXFA_Node* pDataNode = pNode->GetBindData(); |
| 239 | if (!pDataNode) |
| 240 | continue; |
| 241 | |
| 242 | sNew.insert(pDataNode); |
| 243 | } |
| 244 | CXFA_NodeIteratorTemplate<CXFA_Node, |
| 245 | CXFA_TraverseStrategy_XFAContainerNode> |
| 246 | sIteratorAfter(pNextSibling); |
| 247 | for (CXFA_Node* pNode = sIteratorAfter.GetCurrent(); pNode; |
| 248 | pNode = sIteratorAfter.MoveToNext()) { |
| 249 | CXFA_Node* pDataNode = pNode->GetBindData(); |
| 250 | if (!pDataNode) |
| 251 | continue; |
| 252 | |
| 253 | sAfter.insert(pDataNode); |
| 254 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 255 | ReorderDataNodes(sNew, sAfter, false); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 256 | } |
| 257 | } else { |
| 258 | CXFA_Node* pBeforeInstance = GetItem(pInstMgrNode, iPos); |
| 259 | pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent) |
| 260 | ->InsertChild(pNewInstance, pBeforeInstance); |
| 261 | if (bMoveDataBindingNodes) { |
Tom Sepez | d4db58f | 2017-03-02 14:57:59 -0800 | [diff] [blame] | 262 | std::unordered_set<CXFA_Node*> sNew; |
| 263 | std::unordered_set<CXFA_Node*> sBefore; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 264 | CXFA_NodeIteratorTemplate<CXFA_Node, |
| 265 | CXFA_TraverseStrategy_XFAContainerNode> |
| 266 | sIteratorNew(pNewInstance); |
| 267 | for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode; |
| 268 | pNode = sIteratorNew.MoveToNext()) { |
| 269 | CXFA_Node* pDataNode = pNode->GetBindData(); |
| 270 | if (!pDataNode) |
| 271 | continue; |
| 272 | |
| 273 | sNew.insert(pDataNode); |
| 274 | } |
| 275 | CXFA_NodeIteratorTemplate<CXFA_Node, |
| 276 | CXFA_TraverseStrategy_XFAContainerNode> |
| 277 | sIteratorBefore(pBeforeInstance); |
| 278 | for (CXFA_Node* pNode = sIteratorBefore.GetCurrent(); pNode; |
| 279 | pNode = sIteratorBefore.MoveToNext()) { |
| 280 | CXFA_Node* pDataNode = pNode->GetBindData(); |
| 281 | if (!pDataNode) |
| 282 | continue; |
| 283 | |
| 284 | sBefore.insert(pDataNode); |
| 285 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 286 | ReorderDataNodes(sNew, sBefore, true); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | void RemoveItem(CXFA_Node* pInstMgrNode, |
| 292 | CXFA_Node* pRemoveInstance, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 293 | bool bRemoveDataBinding = true) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 294 | pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)->RemoveChild(pRemoveInstance); |
| 295 | if (!bRemoveDataBinding) |
| 296 | return; |
| 297 | |
| 298 | CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFAContainerNode> |
| 299 | sIterator(pRemoveInstance); |
| 300 | for (CXFA_Node* pFormNode = sIterator.GetCurrent(); pFormNode; |
| 301 | pFormNode = sIterator.MoveToNext()) { |
| 302 | CXFA_Node* pDataNode = pFormNode->GetBindData(); |
| 303 | if (!pDataNode) |
| 304 | continue; |
| 305 | |
| 306 | if (pDataNode->RemoveBindItem(pFormNode) == 0) { |
| 307 | if (CXFA_Node* pDataParent = |
| 308 | pDataNode->GetNodeItem(XFA_NODEITEM_Parent)) { |
| 309 | pDataParent->RemoveChild(pDataNode); |
| 310 | } |
| 311 | } |
| 312 | pFormNode->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr); |
| 313 | } |
| 314 | } |
| 315 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 316 | CXFA_Node* CreateInstance(CXFA_Node* pInstMgrNode, bool bDataMerge) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 317 | CXFA_Document* pDocument = pInstMgrNode->GetDocument(); |
| 318 | CXFA_Node* pTemplateNode = pInstMgrNode->GetTemplateNode(); |
| 319 | CXFA_Node* pFormParent = pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 320 | CXFA_Node* pDataScope = nullptr; |
| 321 | for (CXFA_Node* pRootBoundNode = pFormParent; |
| 322 | pRootBoundNode && pRootBoundNode->IsContainerNode(); |
| 323 | pRootBoundNode = pRootBoundNode->GetNodeItem(XFA_NODEITEM_Parent)) { |
| 324 | pDataScope = pRootBoundNode->GetBindData(); |
| 325 | if (pDataScope) |
| 326 | break; |
| 327 | } |
| 328 | if (!pDataScope) { |
| 329 | pDataScope = ToNode(pDocument->GetXFAObject(XFA_HASHCODE_Record)); |
| 330 | ASSERT(pDataScope); |
| 331 | } |
| 332 | CXFA_Node* pInstance = pDocument->DataMerge_CopyContainer( |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 333 | pTemplateNode, pFormParent, pDataScope, true, bDataMerge, true); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 334 | if (pInstance) { |
| 335 | pDocument->DataMerge_UpdateBindingRelations(pInstance); |
| 336 | pFormParent->RemoveChild(pInstance); |
| 337 | } |
| 338 | return pInstance; |
| 339 | } |
| 340 | |
| 341 | struct XFA_ExecEventParaInfo { |
| 342 | public: |
| 343 | uint32_t m_uHash; |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 344 | const wchar_t* m_lpcEventName; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 345 | XFA_EVENTTYPE m_eventType; |
| 346 | uint32_t m_validFlags; |
| 347 | }; |
| 348 | static const XFA_ExecEventParaInfo gs_eventParaInfos[] = { |
| 349 | {0x02a6c55a, L"postSubmit", XFA_EVENT_PostSubmit, 0}, |
| 350 | {0x0ab466bb, L"preSubmit", XFA_EVENT_PreSubmit, 0}, |
| 351 | {0x109d7ce7, L"mouseEnter", XFA_EVENT_MouseEnter, 5}, |
| 352 | {0x17fad373, L"postPrint", XFA_EVENT_PostPrint, 0}, |
| 353 | {0x1bfc72d9, L"preOpen", XFA_EVENT_PreOpen, 7}, |
| 354 | {0x2196a452, L"initialize", XFA_EVENT_Initialize, 1}, |
| 355 | {0x27410f03, L"mouseExit", XFA_EVENT_MouseExit, 5}, |
| 356 | {0x33c43dec, L"docClose", XFA_EVENT_DocClose, 0}, |
| 357 | {0x361fa1b6, L"preSave", XFA_EVENT_PreSave, 0}, |
| 358 | {0x36f1c6d8, L"preSign", XFA_EVENT_PreSign, 6}, |
| 359 | {0x4731d6ba, L"exit", XFA_EVENT_Exit, 2}, |
| 360 | {0x56bf456b, L"docReady", XFA_EVENT_DocReady, 0}, |
| 361 | {0x7233018a, L"validate", XFA_EVENT_Validate, 1}, |
| 362 | {0x8808385e, L"indexChange", XFA_EVENT_IndexChange, 3}, |
| 363 | {0x891f4606, L"change", XFA_EVENT_Change, 4}, |
| 364 | {0x9528a7b4, L"prePrint", XFA_EVENT_PrePrint, 0}, |
| 365 | {0x9f693b21, L"mouseDown", XFA_EVENT_MouseDown, 5}, |
| 366 | {0xcdce56b3, L"full", XFA_EVENT_Full, 4}, |
| 367 | {0xd576d08e, L"mouseUp", XFA_EVENT_MouseUp, 5}, |
| 368 | {0xd95657a6, L"click", XFA_EVENT_Click, 4}, |
| 369 | {0xdbfbe02e, L"calculate", XFA_EVENT_Calculate, 1}, |
| 370 | {0xe25fa7b8, L"postOpen", XFA_EVENT_PostOpen, 7}, |
| 371 | {0xe28dce7e, L"enter", XFA_EVENT_Enter, 2}, |
| 372 | {0xfc82d695, L"postSave", XFA_EVENT_PostSave, 0}, |
| 373 | {0xfd54fbb7, L"postSign", XFA_EVENT_PostSign, 6}, |
| 374 | }; |
| 375 | |
| 376 | const XFA_ExecEventParaInfo* GetEventParaInfoByName( |
| 377 | const CFX_WideStringC& wsEventName) { |
| 378 | uint32_t uHash = FX_HashCode_GetW(wsEventName, false); |
| 379 | int32_t iStart = 0; |
| 380 | int32_t iEnd = (sizeof(gs_eventParaInfos) / sizeof(gs_eventParaInfos[0])) - 1; |
| 381 | do { |
| 382 | int32_t iMid = (iStart + iEnd) / 2; |
| 383 | const XFA_ExecEventParaInfo* eventParaInfo = &gs_eventParaInfos[iMid]; |
| 384 | if (uHash == eventParaInfo->m_uHash) |
| 385 | return eventParaInfo; |
| 386 | if (uHash < eventParaInfo->m_uHash) |
| 387 | iEnd = iMid - 1; |
| 388 | else |
| 389 | iStart = iMid + 1; |
| 390 | } while (iStart <= iEnd); |
| 391 | return nullptr; |
| 392 | } |
| 393 | |
| 394 | void StrToRGB(const CFX_WideString& strRGB, |
| 395 | int32_t& r, |
| 396 | int32_t& g, |
| 397 | int32_t& b) { |
| 398 | r = 0; |
| 399 | g = 0; |
| 400 | b = 0; |
| 401 | |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 402 | wchar_t zero = '0'; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 403 | int32_t iIndex = 0; |
| 404 | int32_t iLen = strRGB.GetLength(); |
| 405 | for (int32_t i = 0; i < iLen; ++i) { |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 406 | wchar_t ch = strRGB.GetAt(i); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 407 | if (ch == L',') |
| 408 | ++iIndex; |
| 409 | if (iIndex > 2) |
| 410 | break; |
| 411 | |
| 412 | int32_t iValue = ch - zero; |
| 413 | if (iValue >= 0 && iValue <= 9) { |
| 414 | switch (iIndex) { |
| 415 | case 0: |
| 416 | r = r * 10 + iValue; |
| 417 | break; |
| 418 | case 1: |
| 419 | g = g * 10 + iValue; |
| 420 | break; |
| 421 | default: |
| 422 | b = b * 10 + iValue; |
| 423 | break; |
| 424 | } |
| 425 | } |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | enum XFA_KEYTYPE { |
| 430 | XFA_KEYTYPE_Custom, |
| 431 | XFA_KEYTYPE_Element, |
| 432 | }; |
| 433 | |
| 434 | void* GetMapKey_Custom(const CFX_WideStringC& wsKey) { |
| 435 | uint32_t dwKey = FX_HashCode_GetW(wsKey, false); |
| 436 | return (void*)(uintptr_t)((dwKey << 1) | XFA_KEYTYPE_Custom); |
| 437 | } |
| 438 | |
| 439 | void* GetMapKey_Element(XFA_Element eType, XFA_ATTRIBUTE eAttribute) { |
| 440 | return (void*)(uintptr_t)((static_cast<int32_t>(eType) << 16) | |
| 441 | (eAttribute << 8) | XFA_KEYTYPE_Element); |
| 442 | } |
| 443 | |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 444 | const XFA_ATTRIBUTEINFO* GetAttributeOfElement(XFA_Element eElement, |
| 445 | XFA_ATTRIBUTE eAttribute, |
| 446 | uint32_t dwPacket) { |
| 447 | int32_t iCount = 0; |
| 448 | const uint8_t* pAttr = XFA_GetElementAttributes(eElement, iCount); |
| 449 | if (!pAttr || iCount < 1) |
| 450 | return nullptr; |
| 451 | |
| 452 | if (!std::binary_search(pAttr, pAttr + iCount, eAttribute)) |
| 453 | return nullptr; |
| 454 | |
| 455 | const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttribute); |
| 456 | ASSERT(pInfo); |
| 457 | if (dwPacket == XFA_XDPPACKET_UNKNOWN) |
| 458 | return pInfo; |
| 459 | return (dwPacket & pInfo->dwPackets) ? pInfo : nullptr; |
| 460 | } |
| 461 | |
| 462 | const XFA_ATTRIBUTEENUMINFO* GetAttributeEnumByID(XFA_ATTRIBUTEENUM eName) { |
| 463 | return g_XFAEnumData + eName; |
| 464 | } |
| 465 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 466 | } // namespace |
| 467 | |
| 468 | static void XFA_DefaultFreeData(void* pData) {} |
| 469 | |
| 470 | static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADefaultFreeData = { |
| 471 | XFA_DefaultFreeData, nullptr}; |
| 472 | |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 473 | XFA_MAPMODULEDATA::XFA_MAPMODULEDATA() {} |
| 474 | |
| 475 | XFA_MAPMODULEDATA::~XFA_MAPMODULEDATA() {} |
| 476 | |
dsinclair | b977847 | 2016-06-23 13:34:10 -0700 | [diff] [blame] | 477 | CXFA_Node::CXFA_Node(CXFA_Document* pDoc, |
| 478 | uint16_t ePacket, |
| 479 | XFA_ObjectType oType, |
dsinclair | c1df5d4 | 2016-07-18 06:36:51 -0700 | [diff] [blame] | 480 | XFA_Element eType, |
| 481 | const CFX_WideStringC& elementName) |
| 482 | : CXFA_Object(pDoc, oType, eType, elementName), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 483 | m_pNext(nullptr), |
| 484 | m_pChild(nullptr), |
| 485 | m_pLastChild(nullptr), |
| 486 | m_pParent(nullptr), |
| 487 | m_pXMLNode(nullptr), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 488 | m_ePacket(ePacket), |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 489 | m_uNodeFlags(XFA_NodeFlag_None), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 490 | m_dwNameHash(0), |
| 491 | m_pAuxNode(nullptr), |
| 492 | m_pMapModuleData(nullptr) { |
| 493 | ASSERT(m_pDocument); |
| 494 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 495 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 496 | CXFA_Node::~CXFA_Node() { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 497 | ASSERT(!m_pParent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 498 | RemoveMapModuleKey(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 499 | CXFA_Node* pNode = m_pChild; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 500 | while (pNode) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 501 | CXFA_Node* pNext = pNode->m_pNext; |
| 502 | pNode->m_pParent = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 503 | delete pNode; |
| 504 | pNode = pNext; |
| 505 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 506 | if (m_pXMLNode && IsOwnXMLNode()) |
tsepez | c757d9a | 2017-01-23 11:01:42 -0800 | [diff] [blame] | 507 | delete m_pXMLNode; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 508 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 509 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 510 | CXFA_Node* CXFA_Node::Clone(bool bRecursive) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 511 | CXFA_Node* pClone = m_pDocument->CreateNode(m_ePacket, m_elementType); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 512 | if (!pClone) |
| 513 | return nullptr; |
| 514 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 515 | MergeAllData(pClone); |
| 516 | pClone->UpdateNameHash(); |
| 517 | if (IsNeedSavingXMLNode()) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 518 | CFDE_XMLNode* pCloneXML = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 519 | if (IsAttributeInXML()) { |
| 520 | CFX_WideString wsName; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 521 | GetAttribute(XFA_ATTRIBUTE_Name, wsName, false); |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 522 | CFDE_XMLElement* pCloneXMLElement = new CFDE_XMLElement(wsName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 523 | CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value); |
| 524 | if (!wsValue.IsEmpty()) { |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 525 | pCloneXMLElement->SetTextData(CFX_WideString(wsValue)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 526 | } |
| 527 | pCloneXML = pCloneXMLElement; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 528 | pCloneXMLElement = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 529 | pClone->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown); |
| 530 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 531 | pCloneXML = m_pXMLNode->Clone(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 532 | } |
| 533 | pClone->SetXMLMappingNode(pCloneXML); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 534 | pClone->SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 535 | } |
| 536 | if (bRecursive) { |
| 537 | for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild; |
| 538 | pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 539 | pClone->InsertChild(pChild->Clone(bRecursive)); |
| 540 | } |
| 541 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 542 | pClone->SetFlag(XFA_NodeFlag_Initialized, true); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 543 | pClone->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 544 | return pClone; |
| 545 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 546 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 547 | CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem) const { |
| 548 | switch (eItem) { |
| 549 | case XFA_NODEITEM_NextSibling: |
| 550 | return m_pNext; |
| 551 | case XFA_NODEITEM_FirstChild: |
| 552 | return m_pChild; |
| 553 | case XFA_NODEITEM_Parent: |
| 554 | return m_pParent; |
| 555 | case XFA_NODEITEM_PrevSibling: |
| 556 | if (m_pParent) { |
| 557 | CXFA_Node* pSibling = m_pParent->m_pChild; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 558 | CXFA_Node* pPrev = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 559 | while (pSibling && pSibling != this) { |
| 560 | pPrev = pSibling; |
| 561 | pSibling = pSibling->m_pNext; |
| 562 | } |
| 563 | return pPrev; |
| 564 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 565 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 566 | default: |
| 567 | break; |
| 568 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 569 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 570 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 571 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 572 | CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem, |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 573 | XFA_ObjectType eType) const { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 574 | CXFA_Node* pNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 575 | switch (eItem) { |
| 576 | case XFA_NODEITEM_NextSibling: |
| 577 | pNode = m_pNext; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 578 | while (pNode && pNode->GetObjectType() != eType) |
| 579 | pNode = pNode->m_pNext; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 580 | break; |
| 581 | case XFA_NODEITEM_FirstChild: |
| 582 | pNode = m_pChild; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 583 | while (pNode && pNode->GetObjectType() != eType) |
| 584 | pNode = pNode->m_pNext; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 585 | break; |
| 586 | case XFA_NODEITEM_Parent: |
| 587 | pNode = m_pParent; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 588 | while (pNode && pNode->GetObjectType() != eType) |
| 589 | pNode = pNode->m_pParent; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 590 | break; |
| 591 | case XFA_NODEITEM_PrevSibling: |
| 592 | if (m_pParent) { |
| 593 | CXFA_Node* pSibling = m_pParent->m_pChild; |
| 594 | while (pSibling && pSibling != this) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 595 | if (eType == pSibling->GetObjectType()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 596 | pNode = pSibling; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 597 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 598 | pSibling = pSibling->m_pNext; |
| 599 | } |
| 600 | } |
| 601 | break; |
| 602 | default: |
| 603 | break; |
| 604 | } |
| 605 | return pNode; |
| 606 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 607 | |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 608 | std::vector<CXFA_Node*> CXFA_Node::GetNodeList(uint32_t dwTypeFilter, |
| 609 | XFA_Element eTypeFilter) { |
| 610 | std::vector<CXFA_Node*> nodes; |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 611 | if (eTypeFilter != XFA_Element::Unknown) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 612 | for (CXFA_Node* pChild = m_pChild; pChild; pChild = pChild->m_pNext) { |
| 613 | if (pChild->GetElementType() == eTypeFilter) |
| 614 | nodes.push_back(pChild); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 615 | } |
| 616 | } else if (dwTypeFilter == |
| 617 | (XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties)) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 618 | for (CXFA_Node* pChild = m_pChild; pChild; pChild = pChild->m_pNext) |
| 619 | nodes.push_back(pChild); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 620 | } else if (dwTypeFilter != 0) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 621 | bool bFilterChildren = !!(dwTypeFilter & XFA_NODEFILTER_Children); |
| 622 | bool bFilterProperties = !!(dwTypeFilter & XFA_NODEFILTER_Properties); |
| 623 | bool bFilterOneOfProperties = |
| 624 | !!(dwTypeFilter & XFA_NODEFILTER_OneOfProperty); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 625 | CXFA_Node* pChild = m_pChild; |
| 626 | while (pChild) { |
| 627 | const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement( |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 628 | GetElementType(), pChild->GetElementType(), XFA_XDPPACKET_UNKNOWN); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 629 | if (pProperty) { |
| 630 | if (bFilterProperties) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 631 | nodes.push_back(pChild); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 632 | } else if (bFilterOneOfProperties && |
| 633 | (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 634 | nodes.push_back(pChild); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 635 | } else if (bFilterChildren && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 636 | (pChild->GetElementType() == XFA_Element::Variables || |
| 637 | pChild->GetElementType() == XFA_Element::PageSet)) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 638 | nodes.push_back(pChild); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 639 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 640 | } else if (bFilterChildren) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 641 | nodes.push_back(pChild); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 642 | } |
| 643 | pChild = pChild->m_pNext; |
| 644 | } |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 645 | if (bFilterOneOfProperties && nodes.empty()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 646 | int32_t iProperties = 0; |
| 647 | const XFA_PROPERTY* pProperty = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 648 | XFA_GetElementProperties(GetElementType(), iProperties); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 649 | if (!pProperty || iProperties < 1) |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 650 | return nodes; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 651 | for (int32_t i = 0; i < iProperties; i++) { |
| 652 | if (pProperty[i].uFlags & XFA_PROPERTYFLAG_DefaultOneOf) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 653 | const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(GetPacketID()); |
| 654 | CXFA_Node* pNewNode = |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 655 | m_pDocument->CreateNode(pPacket, pProperty[i].eName); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 656 | if (!pNewNode) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 657 | break; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 658 | InsertChild(pNewNode, nullptr); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 659 | pNewNode->SetFlag(XFA_NodeFlag_Initialized, true); |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 660 | nodes.push_back(pNewNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 661 | break; |
| 662 | } |
| 663 | } |
| 664 | } |
| 665 | } |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 666 | return nodes; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 667 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 668 | |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 669 | CXFA_Node* CXFA_Node::CreateSamePacketNode(XFA_Element eType, |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 670 | uint32_t dwFlags) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 671 | CXFA_Node* pNode = m_pDocument->CreateNode(m_ePacket, eType); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 672 | pNode->SetFlag(dwFlags, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 673 | return pNode; |
| 674 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 675 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 676 | CXFA_Node* CXFA_Node::CloneTemplateToForm(bool bRecursive) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 677 | ASSERT(m_ePacket == XFA_XDPPACKET_Template); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 678 | CXFA_Node* pClone = |
| 679 | m_pDocument->CreateNode(XFA_XDPPACKET_Form, m_elementType); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 680 | if (!pClone) |
| 681 | return nullptr; |
| 682 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 683 | pClone->SetTemplateNode(this); |
| 684 | pClone->UpdateNameHash(); |
| 685 | pClone->SetXMLMappingNode(GetXMLMappingNode()); |
| 686 | if (bRecursive) { |
| 687 | for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild; |
| 688 | pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 689 | pClone->InsertChild(pChild->CloneTemplateToForm(bRecursive)); |
| 690 | } |
| 691 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 692 | pClone->SetFlag(XFA_NodeFlag_Initialized, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 693 | return pClone; |
| 694 | } |
| 695 | |
| 696 | CXFA_Node* CXFA_Node::GetTemplateNode() const { |
| 697 | return m_pAuxNode; |
| 698 | } |
| 699 | |
| 700 | void CXFA_Node::SetTemplateNode(CXFA_Node* pTemplateNode) { |
| 701 | m_pAuxNode = pTemplateNode; |
| 702 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 703 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 704 | CXFA_Node* CXFA_Node::GetBindData() { |
| 705 | ASSERT(GetPacketID() == XFA_XDPPACKET_Form); |
| 706 | return static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); |
| 707 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 708 | |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 709 | std::vector<CXFA_Node*> CXFA_Node::GetBindItems() { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 710 | if (BindsFormItems()) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 711 | void* pBinding = nullptr; |
| 712 | TryObject(XFA_ATTRIBUTE_BindingNode, pBinding); |
| 713 | return *static_cast<std::vector<CXFA_Node*>*>(pBinding); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 714 | } |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 715 | std::vector<CXFA_Node*> result; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 716 | CXFA_Node* pFormNode = |
| 717 | static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 718 | if (pFormNode) |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 719 | result.push_back(pFormNode); |
| 720 | return result; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 721 | } |
| 722 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 723 | int32_t CXFA_Node::AddBindItem(CXFA_Node* pFormNode) { |
| 724 | ASSERT(pFormNode); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 725 | if (BindsFormItems()) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 726 | void* pBinding = nullptr; |
| 727 | TryObject(XFA_ATTRIBUTE_BindingNode, pBinding); |
| 728 | auto* pItems = static_cast<std::vector<CXFA_Node*>*>(pBinding); |
| 729 | if (!pdfium::ContainsValue(*pItems, pFormNode)) |
| 730 | pItems->push_back(pFormNode); |
| 731 | return pdfium::CollectionSize<int32_t>(*pItems); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 732 | } |
| 733 | CXFA_Node* pOldFormItem = |
| 734 | static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); |
| 735 | if (!pOldFormItem) { |
| 736 | SetObject(XFA_ATTRIBUTE_BindingNode, pFormNode); |
| 737 | return 1; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 738 | } |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 739 | if (pOldFormItem == pFormNode) |
| 740 | return 1; |
| 741 | |
| 742 | std::vector<CXFA_Node*>* pItems = new std::vector<CXFA_Node*>; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 743 | SetObject(XFA_ATTRIBUTE_BindingNode, pItems, &deleteBindItemCallBack); |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 744 | pItems->push_back(pOldFormItem); |
| 745 | pItems->push_back(pFormNode); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 746 | m_uNodeFlags |= XFA_NodeFlag_BindFormItems; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 747 | return 2; |
| 748 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 749 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 750 | int32_t CXFA_Node::RemoveBindItem(CXFA_Node* pFormNode) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 751 | if (BindsFormItems()) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 752 | void* pBinding = nullptr; |
| 753 | TryObject(XFA_ATTRIBUTE_BindingNode, pBinding); |
| 754 | auto* pItems = static_cast<std::vector<CXFA_Node*>*>(pBinding); |
| 755 | auto iter = std::find(pItems->begin(), pItems->end(), pFormNode); |
| 756 | if (iter != pItems->end()) { |
| 757 | *iter = pItems->back(); |
| 758 | pItems->pop_back(); |
| 759 | if (pItems->size() == 1) { |
| 760 | SetObject(XFA_ATTRIBUTE_BindingNode, |
| 761 | (*pItems)[0]); // Invalidates pItems. |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 762 | m_uNodeFlags &= ~XFA_NodeFlag_BindFormItems; |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 763 | return 1; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 764 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 765 | } |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 766 | return pdfium::CollectionSize<int32_t>(*pItems); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 767 | } |
| 768 | CXFA_Node* pOldFormItem = |
| 769 | static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 770 | if (pOldFormItem != pFormNode) |
| 771 | return pOldFormItem ? 1 : 0; |
| 772 | |
| 773 | SetObject(XFA_ATTRIBUTE_BindingNode, nullptr); |
| 774 | return 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 775 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 776 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 777 | bool CXFA_Node::HasBindItem() { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 778 | return GetPacketID() == XFA_XDPPACKET_Datasets && |
| 779 | GetObject(XFA_ATTRIBUTE_BindingNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 780 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 781 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 782 | CXFA_WidgetData* CXFA_Node::GetWidgetData() { |
| 783 | return (CXFA_WidgetData*)GetObject(XFA_ATTRIBUTE_WidgetData); |
| 784 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 785 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 786 | CXFA_WidgetData* CXFA_Node::GetContainerWidgetData() { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 787 | if (GetPacketID() != XFA_XDPPACKET_Form) |
| 788 | return nullptr; |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 789 | XFA_Element eType = GetElementType(); |
| 790 | if (eType == XFA_Element::ExclGroup) |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 791 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 792 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 793 | if (pParentNode && pParentNode->GetElementType() == XFA_Element::ExclGroup) |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 794 | return nullptr; |
| 795 | |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 796 | if (eType == XFA_Element::Field) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 797 | CXFA_WidgetData* pFieldWidgetData = GetWidgetData(); |
| 798 | if (pFieldWidgetData && |
| 799 | pFieldWidgetData->GetChoiceListOpen() == |
| 800 | XFA_ATTRIBUTEENUM_MultiSelect) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 801 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 802 | } else { |
| 803 | CFX_WideString wsPicture; |
| 804 | if (pFieldWidgetData) { |
| 805 | pFieldWidgetData->GetPictureContent(wsPicture, |
| 806 | XFA_VALUEPICTURE_DataBind); |
| 807 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 808 | if (!wsPicture.IsEmpty()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 809 | return pFieldWidgetData; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 810 | CXFA_Node* pDataNode = GetBindData(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 811 | if (!pDataNode) |
| 812 | return nullptr; |
| 813 | pFieldWidgetData = nullptr; |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 814 | for (CXFA_Node* pFormNode : pDataNode->GetBindItems()) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 815 | if (!pFormNode || pFormNode->HasRemovedChildren()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 816 | continue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 817 | pFieldWidgetData = pFormNode->GetWidgetData(); |
| 818 | if (pFieldWidgetData) { |
| 819 | pFieldWidgetData->GetPictureContent(wsPicture, |
| 820 | XFA_VALUEPICTURE_DataBind); |
| 821 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 822 | if (!wsPicture.IsEmpty()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 823 | break; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 824 | pFieldWidgetData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 825 | } |
| 826 | return pFieldWidgetData; |
| 827 | } |
| 828 | } |
| 829 | CXFA_Node* pGrandNode = |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 830 | pParentNode ? pParentNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 831 | CXFA_Node* pValueNode = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 832 | (pParentNode && pParentNode->GetElementType() == XFA_Element::Value) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 833 | ? pParentNode |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 834 | : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 835 | if (!pValueNode) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 836 | pValueNode = |
| 837 | (pGrandNode && pGrandNode->GetElementType() == XFA_Element::Value) |
| 838 | ? pGrandNode |
| 839 | : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 840 | } |
| 841 | CXFA_Node* pParentOfValueNode = |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 842 | pValueNode ? pValueNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 843 | return pParentOfValueNode ? pParentOfValueNode->GetContainerWidgetData() |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 844 | : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 845 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 846 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 847 | bool CXFA_Node::GetLocaleName(CFX_WideString& wsLocaleName) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 848 | CXFA_Node* pForm = GetDocument()->GetXFAObject(XFA_HASHCODE_Form)->AsNode(); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 849 | CXFA_Node* pTopSubform = pForm->GetFirstChildByClass(XFA_Element::Subform); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 850 | ASSERT(pTopSubform); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 851 | CXFA_Node* pLocaleNode = this; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 852 | bool bLocale = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 853 | do { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 854 | bLocale = pLocaleNode->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 855 | if (!bLocale) { |
| 856 | pLocaleNode = pLocaleNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 857 | } |
| 858 | } while (pLocaleNode && pLocaleNode != pTopSubform && !bLocale); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 859 | if (bLocale) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 860 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 861 | CXFA_Node* pConfig = ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Config)); |
| 862 | wsLocaleName = GetDocument()->GetLocalMgr()->GetConfigLocaleName(pConfig); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 863 | if (!wsLocaleName.IsEmpty()) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 864 | return true; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 865 | if (pTopSubform && |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 866 | pTopSubform->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, false)) { |
| 867 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 868 | } |
| 869 | IFX_Locale* pLocale = GetDocument()->GetLocalMgr()->GetDefLocale(); |
| 870 | if (pLocale) { |
| 871 | wsLocaleName = pLocale->GetName(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 872 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 873 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 874 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 875 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 876 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 877 | XFA_ATTRIBUTEENUM CXFA_Node::GetIntact() { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 878 | CXFA_Node* pKeep = GetFirstChildByClass(XFA_Element::Keep); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 879 | XFA_ATTRIBUTEENUM eLayoutType = GetEnum(XFA_ATTRIBUTE_Layout); |
| 880 | if (pKeep) { |
| 881 | XFA_ATTRIBUTEENUM eIntact; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 882 | if (pKeep->TryEnum(XFA_ATTRIBUTE_Intact, eIntact, false)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 883 | if (eIntact == XFA_ATTRIBUTEENUM_None && |
| 884 | eLayoutType == XFA_ATTRIBUTEENUM_Row && |
| 885 | m_pDocument->GetCurVersionMode() < XFA_VERSION_208) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 886 | CXFA_Node* pPreviewRow = GetNodeItem(XFA_NODEITEM_PrevSibling, |
| 887 | XFA_ObjectType::ContainerNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 888 | if (pPreviewRow && |
| 889 | pPreviewRow->GetEnum(XFA_ATTRIBUTE_Layout) == |
| 890 | XFA_ATTRIBUTEENUM_Row) { |
| 891 | XFA_ATTRIBUTEENUM eValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 892 | if (pKeep->TryEnum(XFA_ATTRIBUTE_Previous, eValue, false) && |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 893 | (eValue == XFA_ATTRIBUTEENUM_ContentArea || |
| 894 | eValue == XFA_ATTRIBUTEENUM_PageArea)) { |
| 895 | return XFA_ATTRIBUTEENUM_ContentArea; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 896 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 897 | CXFA_Node* pNode = |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 898 | pPreviewRow->GetFirstChildByClass(XFA_Element::Keep); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 899 | if (pNode && pNode->TryEnum(XFA_ATTRIBUTE_Next, eValue, false) && |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 900 | (eValue == XFA_ATTRIBUTEENUM_ContentArea || |
| 901 | eValue == XFA_ATTRIBUTEENUM_PageArea)) { |
| 902 | return XFA_ATTRIBUTEENUM_ContentArea; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 903 | } |
| 904 | } |
| 905 | } |
| 906 | return eIntact; |
| 907 | } |
| 908 | } |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 909 | switch (GetElementType()) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 910 | case XFA_Element::Subform: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 911 | switch (eLayoutType) { |
| 912 | case XFA_ATTRIBUTEENUM_Position: |
| 913 | case XFA_ATTRIBUTEENUM_Row: |
| 914 | return XFA_ATTRIBUTEENUM_ContentArea; |
| 915 | case XFA_ATTRIBUTEENUM_Tb: |
| 916 | case XFA_ATTRIBUTEENUM_Table: |
| 917 | case XFA_ATTRIBUTEENUM_Lr_tb: |
| 918 | case XFA_ATTRIBUTEENUM_Rl_tb: |
| 919 | return XFA_ATTRIBUTEENUM_None; |
| 920 | default: |
| 921 | break; |
| 922 | } |
| 923 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 924 | case XFA_Element::Field: { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 925 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 926 | if (!pParentNode || |
| 927 | pParentNode->GetElementType() == XFA_Element::PageArea) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 928 | return XFA_ATTRIBUTEENUM_ContentArea; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 929 | if (pParentNode->GetIntact() == XFA_ATTRIBUTEENUM_None) { |
| 930 | XFA_ATTRIBUTEENUM eParLayout = |
| 931 | pParentNode->GetEnum(XFA_ATTRIBUTE_Layout); |
| 932 | if (eParLayout == XFA_ATTRIBUTEENUM_Position || |
| 933 | eParLayout == XFA_ATTRIBUTEENUM_Row || |
| 934 | eParLayout == XFA_ATTRIBUTEENUM_Table) { |
| 935 | return XFA_ATTRIBUTEENUM_None; |
| 936 | } |
| 937 | XFA_VERSION version = m_pDocument->GetCurVersionMode(); |
| 938 | if (eParLayout == XFA_ATTRIBUTEENUM_Tb && version < XFA_VERSION_208) { |
| 939 | CXFA_Measurement measureH; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 940 | if (TryMeasure(XFA_ATTRIBUTE_H, measureH, false)) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 941 | return XFA_ATTRIBUTEENUM_ContentArea; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 942 | } |
| 943 | return XFA_ATTRIBUTEENUM_None; |
| 944 | } |
| 945 | return XFA_ATTRIBUTEENUM_ContentArea; |
| 946 | } |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 947 | case XFA_Element::Draw: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 948 | return XFA_ATTRIBUTEENUM_ContentArea; |
| 949 | default: |
| 950 | break; |
| 951 | } |
| 952 | return XFA_ATTRIBUTEENUM_None; |
| 953 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 954 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 955 | CXFA_Node* CXFA_Node::GetDataDescriptionNode() { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 956 | if (m_ePacket == XFA_XDPPACKET_Datasets) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 957 | return m_pAuxNode; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 958 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 959 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 960 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 961 | void CXFA_Node::SetDataDescriptionNode(CXFA_Node* pDataDescriptionNode) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 962 | ASSERT(m_ePacket == XFA_XDPPACKET_Datasets); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 963 | m_pAuxNode = pDataDescriptionNode; |
| 964 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 965 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 966 | void CXFA_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments) { |
| 967 | int32_t iLength = pArguments->GetLength(); |
| 968 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 969 | ThrowParamCountMismatchException(L"resolveNode"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 970 | return; |
| 971 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 972 | CFX_WideString wsExpression = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 973 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 974 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 975 | if (!pScriptContext) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 976 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 977 | CXFA_Node* refNode = this; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 978 | if (refNode->GetElementType() == XFA_Element::Xfa) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 979 | refNode = ToNode(pScriptContext->GetThisObject()); |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 980 | uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 981 | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | |
| 982 | XFA_RESOLVENODE_Siblings; |
| 983 | XFA_RESOLVENODE_RS resoveNodeRS; |
tsepez | fc58ad1 | 2016-04-05 12:22:15 -0700 | [diff] [blame] | 984 | int32_t iRet = pScriptContext->ResolveObjects( |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 985 | refNode, wsExpression.AsStringC(), resoveNodeRS, dwFlag); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 986 | if (iRet < 1) { |
| 987 | pArguments->GetReturnValue()->SetNull(); |
| 988 | return; |
| 989 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 990 | if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 991 | CXFA_Object* pObject = resoveNodeRS.objects.front(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 992 | pArguments->GetReturnValue()->Assign( |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 993 | pScriptContext->GetJSValueFromMap(pObject)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 994 | } else { |
| 995 | const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = |
| 996 | resoveNodeRS.pScriptAttribute; |
| 997 | if (lpAttributeInfo && lpAttributeInfo->eValueType == XFA_SCRIPT_Object) { |
dsinclair | 86fad99 | 2016-05-31 11:34:04 -0700 | [diff] [blame] | 998 | std::unique_ptr<CFXJSE_Value> pValue( |
| 999 | new CFXJSE_Value(pScriptContext->GetRuntime())); |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 1000 | (resoveNodeRS.objects.front()->*(lpAttributeInfo->lpfnCallback))( |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1001 | pValue.get(), false, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1002 | pArguments->GetReturnValue()->Assign(pValue.get()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1003 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1004 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1005 | } |
| 1006 | } |
| 1007 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1008 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1009 | void CXFA_Node::Script_TreeClass_ResolveNodes(CFXJSE_Arguments* pArguments) { |
| 1010 | int32_t iLength = pArguments->GetLength(); |
| 1011 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1012 | ThrowParamCountMismatchException(L"resolveNodes"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1013 | return; |
| 1014 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1015 | CFX_WideString wsExpression = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1016 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1017 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1018 | if (!pValue) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1019 | return; |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1020 | uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1021 | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | |
| 1022 | XFA_RESOLVENODE_Siblings; |
| 1023 | CXFA_Node* refNode = this; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1024 | if (refNode->GetElementType() == XFA_Element::Xfa) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1025 | refNode = ToNode(m_pDocument->GetScriptContext()->GetThisObject()); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1026 | Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag, refNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1027 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1028 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1029 | void CXFA_Node::Script_Som_ResolveNodeList(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1030 | CFX_WideString wsExpression, |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1031 | uint32_t dwFlag, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1032 | CXFA_Node* refNode) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 1033 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1034 | if (!pScriptContext) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1035 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1036 | XFA_RESOLVENODE_RS resoveNodeRS; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1037 | if (!refNode) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1038 | refNode = this; |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1039 | pScriptContext->ResolveObjects(refNode, wsExpression.AsStringC(), |
tsepez | fc58ad1 | 2016-04-05 12:22:15 -0700 | [diff] [blame] | 1040 | resoveNodeRS, dwFlag); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1041 | CXFA_ArrayNodeList* pNodeList = new CXFA_ArrayNodeList(m_pDocument); |
| 1042 | if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 1043 | for (CXFA_Object* pObject : resoveNodeRS.objects) { |
| 1044 | if (pObject->IsNode()) |
| 1045 | pNodeList->Append(pObject->AsNode()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1046 | } |
| 1047 | } else { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1048 | CXFA_ValueArray valueArray(pScriptContext->GetRuntime()); |
Tom Sepez | 369fe1f | 2017-03-27 16:03:43 -0700 | [diff] [blame] | 1049 | if (resoveNodeRS.GetAttributeResult(&valueArray) > 0) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 1050 | for (CXFA_Object* pObject : valueArray.GetAttributeObject()) { |
| 1051 | if (pObject->IsNode()) |
| 1052 | pNodeList->Append(pObject->AsNode()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1053 | } |
| 1054 | } |
| 1055 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1056 | pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1057 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1058 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1059 | void CXFA_Node::Script_TreeClass_All(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1060 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1061 | XFA_ATTRIBUTE eAttribute) { |
| 1062 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1063 | ThrowInvalidPropertyException(); |
| 1064 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1065 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1066 | |
| 1067 | uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL; |
| 1068 | CFX_WideString wsName; |
| 1069 | GetAttribute(XFA_ATTRIBUTE_Name, wsName); |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 1070 | CFX_WideString wsExpression = wsName + L"[*]"; |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1071 | Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1072 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1073 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1074 | void CXFA_Node::Script_TreeClass_Nodes(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1075 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1076 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 1077 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1078 | if (!pScriptContext) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1079 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1080 | if (bSetting) { |
Dan Sinclair | c8fd331 | 2017-01-02 17:17:02 -0500 | [diff] [blame] | 1081 | CFX_WideString wsMessage = L"Unable to set "; |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 1082 | FXJSE_ThrowMessage(wsMessage.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1083 | } else { |
| 1084 | CXFA_AttachNodeList* pNodeList = new CXFA_AttachNodeList(m_pDocument, this); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1085 | pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1086 | } |
| 1087 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1088 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1089 | void CXFA_Node::Script_TreeClass_ClassAll(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1090 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1091 | XFA_ATTRIBUTE eAttribute) { |
| 1092 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1093 | ThrowInvalidPropertyException(); |
| 1094 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1095 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1096 | uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL; |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 1097 | CFX_WideString wsExpression = L"#" + GetClassName() + L"[*]"; |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1098 | Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1099 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1100 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1101 | void CXFA_Node::Script_TreeClass_Parent(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1102 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1103 | XFA_ATTRIBUTE eAttribute) { |
| 1104 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1105 | ThrowInvalidPropertyException(); |
| 1106 | return; |
| 1107 | } |
| 1108 | CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent); |
| 1109 | if (pParent) { |
| 1110 | pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pParent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1111 | } else { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1112 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1113 | } |
| 1114 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1115 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1116 | void CXFA_Node::Script_TreeClass_Index(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1117 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1118 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1119 | if (bSetting) { |
| 1120 | ThrowInvalidPropertyException(); |
| 1121 | return; |
| 1122 | } |
| 1123 | pValue->SetInteger(GetNodeSameNameIndex()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1124 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1125 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1126 | void CXFA_Node::Script_TreeClass_ClassIndex(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1127 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1128 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1129 | if (bSetting) { |
| 1130 | ThrowInvalidPropertyException(); |
| 1131 | return; |
| 1132 | } |
| 1133 | pValue->SetInteger(GetNodeSameClassIndex()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1134 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1135 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1136 | void CXFA_Node::Script_TreeClass_SomExpression(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1137 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1138 | XFA_ATTRIBUTE eAttribute) { |
| 1139 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1140 | ThrowInvalidPropertyException(); |
| 1141 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1142 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1143 | CFX_WideString wsSOMExpression; |
| 1144 | GetSOMExpression(wsSOMExpression); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 1145 | pValue->SetString(wsSOMExpression.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1146 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1147 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1148 | void CXFA_Node::Script_NodeClass_ApplyXSL(CFXJSE_Arguments* pArguments) { |
| 1149 | int32_t iLength = pArguments->GetLength(); |
| 1150 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1151 | ThrowParamCountMismatchException(L"applyXSL"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1152 | return; |
| 1153 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1154 | CFX_WideString wsExpression = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1155 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1156 | // TODO(weili): check whether we need to implement this, pdfium:501. |
| 1157 | // For now, just put the variables here to avoid unused variable warning. |
| 1158 | (void)wsExpression; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1159 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1160 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1161 | void CXFA_Node::Script_NodeClass_AssignNode(CFXJSE_Arguments* pArguments) { |
| 1162 | int32_t iLength = pArguments->GetLength(); |
| 1163 | if (iLength < 1 || iLength > 3) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1164 | ThrowParamCountMismatchException(L"assignNode"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1165 | return; |
| 1166 | } |
| 1167 | CFX_WideString wsExpression; |
| 1168 | CFX_WideString wsValue; |
| 1169 | int32_t iAction = 0; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1170 | wsExpression = |
| 1171 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1172 | if (iLength >= 2) { |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1173 | wsValue = |
| 1174 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1175 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1176 | if (iLength >= 3) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1177 | iAction = pArguments->GetInt32(2); |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1178 | // TODO(weili): check whether we need to implement this, pdfium:501. |
| 1179 | // For now, just put the variables here to avoid unused variable warning. |
| 1180 | (void)wsExpression; |
| 1181 | (void)wsValue; |
| 1182 | (void)iAction; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1183 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1184 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1185 | void CXFA_Node::Script_NodeClass_Clone(CFXJSE_Arguments* pArguments) { |
| 1186 | int32_t iLength = pArguments->GetLength(); |
| 1187 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1188 | ThrowParamCountMismatchException(L"clone"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1189 | return; |
| 1190 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1191 | bool bClone = !!pArguments->GetInt32(0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1192 | CXFA_Node* pCloneNode = Clone(bClone); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1193 | pArguments->GetReturnValue()->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1194 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pCloneNode)); |
| 1195 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1196 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1197 | void CXFA_Node::Script_NodeClass_GetAttribute(CFXJSE_Arguments* pArguments) { |
| 1198 | int32_t iLength = pArguments->GetLength(); |
| 1199 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1200 | ThrowParamCountMismatchException(L"getAttribute"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1201 | return; |
| 1202 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1203 | CFX_WideString wsExpression = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1204 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1205 | CFX_WideString wsValue; |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1206 | GetAttribute(wsExpression.AsStringC(), wsValue); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1207 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1208 | if (pValue) |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 1209 | pValue->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1210 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1211 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1212 | void CXFA_Node::Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments) { |
| 1213 | int32_t iLength = pArguments->GetLength(); |
| 1214 | if (iLength < 1 || iLength > 2) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1215 | ThrowParamCountMismatchException(L"getElement"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1216 | return; |
| 1217 | } |
| 1218 | CFX_WideString wsExpression; |
| 1219 | int32_t iValue = 0; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1220 | wsExpression = |
| 1221 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
| 1222 | if (iLength >= 2) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1223 | iValue = pArguments->GetInt32(1); |
dsinclair | 6e12478 | 2016-06-23 12:14:55 -0700 | [diff] [blame] | 1224 | CXFA_Node* pNode = |
| 1225 | GetProperty(iValue, XFA_GetElementTypeForName(wsExpression.AsStringC())); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1226 | pArguments->GetReturnValue()->Assign( |
| 1227 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1228 | } |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1229 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1230 | void CXFA_Node::Script_NodeClass_IsPropertySpecified( |
| 1231 | CFXJSE_Arguments* pArguments) { |
| 1232 | int32_t iLength = pArguments->GetLength(); |
| 1233 | if (iLength < 1 || iLength > 3) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1234 | ThrowParamCountMismatchException(L"isPropertySpecified"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1235 | return; |
| 1236 | } |
| 1237 | CFX_WideString wsExpression; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1238 | bool bParent = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1239 | int32_t iIndex = 0; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1240 | wsExpression = |
| 1241 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1242 | if (iLength >= 2) |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1243 | bParent = !!pArguments->GetInt32(1); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1244 | if (iLength >= 3) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1245 | iIndex = pArguments->GetInt32(2); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1246 | bool bHas = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1247 | const XFA_ATTRIBUTEINFO* pAttributeInfo = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1248 | XFA_GetAttributeByName(wsExpression.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1249 | CFX_WideString wsValue; |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1250 | if (pAttributeInfo) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1251 | bHas = HasAttribute(pAttributeInfo->eName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1252 | if (!bHas) { |
dsinclair | 6e12478 | 2016-06-23 12:14:55 -0700 | [diff] [blame] | 1253 | XFA_Element eType = XFA_GetElementTypeForName(wsExpression.AsStringC()); |
| 1254 | bHas = !!GetProperty(iIndex, eType); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1255 | if (!bHas && bParent && m_pParent) { |
| 1256 | // Also check on the parent. |
| 1257 | bHas = m_pParent->HasAttribute(pAttributeInfo->eName); |
| 1258 | if (!bHas) |
dsinclair | 6e12478 | 2016-06-23 12:14:55 -0700 | [diff] [blame] | 1259 | bHas = !!m_pParent->GetProperty(iIndex, eType); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1260 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1261 | } |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1262 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
| 1263 | if (pValue) |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1264 | pValue->SetBoolean(bHas); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1265 | } |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1266 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1267 | void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) { |
| 1268 | int32_t iLength = pArguments->GetLength(); |
| 1269 | if (iLength < 1 || iLength > 3) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1270 | ThrowParamCountMismatchException(L"loadXML"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1271 | return; |
| 1272 | } |
| 1273 | CFX_WideString wsExpression; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1274 | bool bIgnoreRoot = true; |
| 1275 | bool bOverwrite = 0; |
| 1276 | wsExpression = |
| 1277 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
| 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); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 1284 | std::unique_ptr<CXFA_SimpleParser> pParser( |
| 1285 | new CXFA_SimpleParser(m_pDocument, false)); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1286 | if (!pParser) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1287 | return; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1288 | CFDE_XMLNode* pXMLNode = nullptr; |
| 1289 | int32_t iParserStatus = |
| 1290 | pParser->ParseXMLData(wsExpression, pXMLNode, nullptr); |
| 1291 | if (iParserStatus != XFA_PARSESTATUS_Done || !pXMLNode) |
| 1292 | return; |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1293 | if (bIgnoreRoot && |
| 1294 | (pXMLNode->GetType() != FDE_XMLNODE_Element || |
| 1295 | XFA_RecognizeRichText(static_cast<CFDE_XMLElement*>(pXMLNode)))) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1296 | bIgnoreRoot = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1297 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1298 | CXFA_Node* pFakeRoot = Clone(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1299 | CFX_WideStringC wsContentType = GetCData(XFA_ATTRIBUTE_ContentType); |
| 1300 | if (!wsContentType.IsEmpty()) { |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 1301 | pFakeRoot->SetCData(XFA_ATTRIBUTE_ContentType, |
| 1302 | CFX_WideString(wsContentType)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1303 | } |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1304 | CFDE_XMLNode* pFakeXMLRoot = pFakeRoot->GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1305 | if (!pFakeXMLRoot) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1306 | CFDE_XMLNode* pThisXMLRoot = GetXMLMappingNode(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1307 | pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone(false) : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1308 | } |
dsinclair | 017052a | 2016-06-28 07:43:51 -0700 | [diff] [blame] | 1309 | if (!pFakeXMLRoot) |
| 1310 | pFakeXMLRoot = new CFDE_XMLElement(CFX_WideString(GetClassName())); |
| 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 | } |
| 1328 | pParser->ConstructXFANode(pFakeRoot, pFakeXMLRoot); |
| 1329 | pFakeRoot = pParser->GetRootNode(); |
| 1330 | if (pFakeRoot) { |
| 1331 | if (bOverwrite) { |
| 1332 | CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1333 | CXFA_Node* pNewChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1334 | int32_t index = 0; |
| 1335 | while (pNewChild) { |
| 1336 | CXFA_Node* pItem = pNewChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1337 | pFakeRoot->RemoveChild(pNewChild); |
| 1338 | InsertChild(index++, pNewChild); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 1339 | pNewChild->SetFlag(XFA_NodeFlag_Initialized, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1340 | pNewChild = pItem; |
| 1341 | } |
| 1342 | while (pChild) { |
| 1343 | CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1344 | RemoveChild(pChild); |
| 1345 | pFakeRoot->InsertChild(pChild); |
| 1346 | pChild = pItem; |
| 1347 | } |
| 1348 | if (GetPacketID() == XFA_XDPPACKET_Form && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1349 | GetElementType() == XFA_Element::ExData) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1350 | CFDE_XMLNode* pTempXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1351 | SetXMLMappingNode(pFakeXMLRoot); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 1352 | SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1353 | if (pTempXMLNode && !pTempXMLNode->GetNodeItem(CFDE_XMLNode::Parent)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1354 | pFakeXMLRoot = pTempXMLNode; |
| 1355 | } else { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1356 | pFakeXMLRoot = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1357 | } |
| 1358 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1359 | MoveBufferMapData(pFakeRoot, this, XFA_CalcData, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1360 | } else { |
| 1361 | CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1362 | while (pChild) { |
| 1363 | CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1364 | pFakeRoot->RemoveChild(pChild); |
| 1365 | InsertChild(pChild); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 1366 | pChild->SetFlag(XFA_NodeFlag_Initialized, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1367 | pChild = pItem; |
| 1368 | } |
| 1369 | } |
| 1370 | if (pFakeXMLRoot) { |
| 1371 | pFakeRoot->SetXMLMappingNode(pFakeXMLRoot); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 1372 | pFakeRoot->SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1373 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 1374 | pFakeRoot->SetFlag(XFA_NodeFlag_HasRemovedChildren, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1375 | } else { |
tsepez | c757d9a | 2017-01-23 11:01:42 -0800 | [diff] [blame] | 1376 | delete pFakeXMLRoot; |
| 1377 | pFakeXMLRoot = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1378 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1379 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1380 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1381 | void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1382 | // TODO(weili): Check whether we need to implement this, pdfium:501. |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1383 | } |
| 1384 | |
| 1385 | void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) { |
| 1386 | int32_t iLength = pArguments->GetLength(); |
| 1387 | if (iLength < 0 || iLength > 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1388 | ThrowParamCountMismatchException(L"saveXML"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1389 | return; |
| 1390 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1391 | bool bPrettyMode = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1392 | if (iLength == 1) { |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1393 | if (pArguments->GetUTF8String(0) != "pretty") { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1394 | ThrowArgumentMismatchException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1395 | return; |
| 1396 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1397 | bPrettyMode = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1398 | } |
| 1399 | CFX_ByteStringC bsXMLHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1400 | if (GetPacketID() == XFA_XDPPACKET_Form || |
| 1401 | GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 1402 | CFDE_XMLNode* pElement = nullptr; |
| 1403 | if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 1404 | pElement = GetXMLMappingNode(); |
| 1405 | if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1406 | pArguments->GetReturnValue()->SetString(bsXMLHeader); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1407 | return; |
| 1408 | } |
| 1409 | XFA_DataExporter_DealWithDataGroupNode(this); |
| 1410 | } |
tsepez | 833619b | 2016-12-07 09:21:17 -0800 | [diff] [blame] | 1411 | CFX_RetainPtr<IFX_MemoryStream> pMemoryStream = |
| 1412 | IFX_MemoryStream::Create(true); |
| 1413 | |
| 1414 | // Note: ambiguious below without static_cast. |
tsepez | 7cda31a | 2016-12-07 12:10:20 -0800 | [diff] [blame] | 1415 | CFX_RetainPtr<IFGAS_Stream> pStream = IFGAS_Stream::CreateStream( |
| 1416 | CFX_RetainPtr<IFX_SeekableWriteStream>(pMemoryStream), |
| 1417 | FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | FX_STREAMACCESS_Append); |
tsepez | 833619b | 2016-12-07 09:21:17 -0800 | [diff] [blame] | 1418 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1419 | if (!pStream) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1420 | pArguments->GetReturnValue()->SetString(bsXMLHeader); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1421 | return; |
| 1422 | } |
| 1423 | pStream->SetCodePage(FX_CODEPAGE_UTF8); |
dsinclair | 179bebb | 2016-04-05 11:02:18 -0700 | [diff] [blame] | 1424 | pStream->WriteData(bsXMLHeader.raw_str(), bsXMLHeader.GetLength()); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1425 | if (GetPacketID() == XFA_XDPPACKET_Form) |
tsepez | 7cda31a | 2016-12-07 12:10:20 -0800 | [diff] [blame] | 1426 | XFA_DataExporter_RegenerateFormFile(this, pStream, nullptr, true); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1427 | else |
tsepez | 7cda31a | 2016-12-07 12:10:20 -0800 | [diff] [blame] | 1428 | pElement->SaveXMLNode(pStream); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1429 | // TODO(weili): Check whether we need to save pretty print XML, pdfium:501. |
| 1430 | // For now, just put it here to avoid unused variable warning. |
| 1431 | (void)bPrettyMode; |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1432 | pArguments->GetReturnValue()->SetString( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1433 | CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize())); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1434 | return; |
| 1435 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1436 | pArguments->GetReturnValue()->SetString(""); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1437 | } |
| 1438 | |
| 1439 | void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) { |
| 1440 | int32_t iLength = pArguments->GetLength(); |
| 1441 | if (iLength != 2) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1442 | ThrowParamCountMismatchException(L"setAttribute"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1443 | return; |
| 1444 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1445 | CFX_WideString wsAttributeValue = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1446 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1447 | CFX_WideString wsAttribute = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1448 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC()); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1449 | SetAttribute(wsAttribute.AsStringC(), wsAttributeValue.AsStringC(), true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1450 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1451 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1452 | void CXFA_Node::Script_NodeClass_SetElement(CFXJSE_Arguments* pArguments) { |
| 1453 | int32_t iLength = pArguments->GetLength(); |
| 1454 | if (iLength != 1 && iLength != 2) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1455 | ThrowParamCountMismatchException(L"setElement"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1456 | return; |
| 1457 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1458 | CXFA_Node* pNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1459 | CFX_WideString wsName; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1460 | pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); |
| 1461 | if (iLength == 2) |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1462 | wsName = CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC()); |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1463 | // TODO(weili): check whether we need to implement this, pdfium:501. |
| 1464 | // For now, just put the variables here to avoid unused variable warning. |
| 1465 | (void)pNode; |
| 1466 | (void)wsName; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1467 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1468 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1469 | void CXFA_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1470 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1471 | XFA_ATTRIBUTE eAttribute) { |
| 1472 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1473 | ThrowInvalidPropertyException(); |
| 1474 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1475 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1476 | |
| 1477 | CFX_WideString wsNameSpace; |
| 1478 | TryNamespace(wsNameSpace); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 1479 | pValue->SetString(wsNameSpace.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1480 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1481 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1482 | void CXFA_Node::Script_NodeClass_Model(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1483 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1484 | XFA_ATTRIBUTE eAttribute) { |
| 1485 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1486 | ThrowInvalidPropertyException(); |
| 1487 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1488 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1489 | pValue->Assign( |
| 1490 | m_pDocument->GetScriptContext()->GetJSValueFromMap(GetModelNode())); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1491 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1492 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1493 | void CXFA_Node::Script_NodeClass_IsContainer(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1494 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1495 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1496 | if (bSetting) { |
| 1497 | ThrowInvalidPropertyException(); |
| 1498 | return; |
| 1499 | } |
| 1500 | pValue->SetBoolean(IsContainerNode()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1501 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1502 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1503 | void CXFA_Node::Script_NodeClass_IsNull(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1504 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1505 | XFA_ATTRIBUTE eAttribute) { |
| 1506 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1507 | ThrowInvalidPropertyException(); |
| 1508 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1509 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1510 | if (GetElementType() == XFA_Element::Subform) { |
| 1511 | pValue->SetBoolean(false); |
| 1512 | return; |
| 1513 | } |
| 1514 | CFX_WideString strValue; |
| 1515 | pValue->SetBoolean(!TryContent(strValue) || strValue.IsEmpty()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1516 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1517 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1518 | void CXFA_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1519 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1520 | XFA_ATTRIBUTE eAttribute) { |
| 1521 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1522 | ThrowInvalidPropertyException(); |
| 1523 | return; |
| 1524 | } |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 1525 | std::vector<CXFA_Node*> properties = |
| 1526 | GetNodeList(XFA_NODEFILTER_OneOfProperty); |
| 1527 | if (!properties.empty()) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1528 | pValue->Assign( |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 1529 | m_pDocument->GetScriptContext()->GetJSValueFromMap(properties.front())); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1530 | } |
| 1531 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1532 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1533 | void CXFA_Node::Script_ContainerClass_GetDelta(CFXJSE_Arguments* pArguments) {} |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1534 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1535 | void CXFA_Node::Script_ContainerClass_GetDeltas(CFXJSE_Arguments* pArguments) { |
| 1536 | CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1537 | pArguments->GetReturnValue()->SetObject( |
| 1538 | pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1539 | } |
| 1540 | void CXFA_Node::Script_ModelClass_ClearErrorList(CFXJSE_Arguments* pArguments) { |
| 1541 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1542 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1543 | void CXFA_Node::Script_ModelClass_CreateNode(CFXJSE_Arguments* pArguments) { |
| 1544 | Script_Template_CreateNode(pArguments); |
| 1545 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1546 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1547 | void CXFA_Node::Script_ModelClass_IsCompatibleNS(CFXJSE_Arguments* pArguments) { |
| 1548 | int32_t iLength = pArguments->GetLength(); |
| 1549 | if (iLength < 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1550 | ThrowParamCountMismatchException(L"isCompatibleNS"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1551 | return; |
| 1552 | } |
| 1553 | CFX_WideString wsNameSpace; |
| 1554 | if (iLength >= 1) { |
| 1555 | CFX_ByteString bsNameSpace = pArguments->GetUTF8String(0); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1556 | wsNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1557 | } |
| 1558 | CFX_WideString wsNodeNameSpace; |
| 1559 | TryNamespace(wsNodeNameSpace); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1560 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1561 | if (pValue) |
| 1562 | pValue->SetBoolean(wsNodeNameSpace == wsNameSpace); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1563 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1564 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1565 | void CXFA_Node::Script_ModelClass_Context(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1566 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1567 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1568 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1569 | void CXFA_Node::Script_ModelClass_AliasNode(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1570 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1571 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1572 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1573 | void CXFA_Node::Script_Attribute_Integer(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1574 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1575 | XFA_ATTRIBUTE eAttribute) { |
| 1576 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1577 | SetInteger(eAttribute, pValue->ToInteger(), true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1578 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1579 | pValue->SetInteger(GetInteger(eAttribute)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1580 | } |
| 1581 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1582 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1583 | void CXFA_Node::Script_Attribute_IntegerRead(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1584 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1585 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1586 | if (bSetting) { |
| 1587 | ThrowInvalidPropertyException(); |
| 1588 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1589 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1590 | pValue->SetInteger(GetInteger(eAttribute)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1591 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1592 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1593 | void CXFA_Node::Script_Attribute_BOOL(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1594 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1595 | XFA_ATTRIBUTE eAttribute) { |
| 1596 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1597 | SetBoolean(eAttribute, pValue->ToBoolean(), true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1598 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1599 | pValue->SetString(GetBoolean(eAttribute) ? "1" : "0"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1600 | } |
| 1601 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1602 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1603 | void CXFA_Node::Script_Attribute_BOOLRead(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1604 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1605 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1606 | if (bSetting) { |
| 1607 | ThrowInvalidPropertyException(); |
| 1608 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1609 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1610 | pValue->SetString(GetBoolean(eAttribute) ? "1" : "0"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1611 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1612 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1613 | void CXFA_Node::Script_Attribute_SendAttributeChangeMessage( |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1614 | XFA_ATTRIBUTE eAttribute, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1615 | bool bScriptModify) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1616 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1617 | if (!pLayoutPro) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1618 | return; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1619 | |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 1620 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1621 | if (!pNotify) |
| 1622 | return; |
| 1623 | |
| 1624 | uint32_t dwPacket = GetPacketID(); |
| 1625 | if (!(dwPacket & XFA_XDPPACKET_Form)) { |
| 1626 | pNotify->OnValueChanged(this, eAttribute, this, this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1627 | return; |
| 1628 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1629 | |
| 1630 | bool bNeedFindContainer = false; |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1631 | switch (GetElementType()) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1632 | case XFA_Element::Caption: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1633 | bNeedFindContainer = true; |
| 1634 | pNotify->OnValueChanged(this, eAttribute, this, |
| 1635 | GetNodeItem(XFA_NODEITEM_Parent)); |
| 1636 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1637 | case XFA_Element::Font: |
| 1638 | case XFA_Element::Para: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1639 | bNeedFindContainer = true; |
| 1640 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1641 | if (pParentNode->GetElementType() == XFA_Element::Caption) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1642 | pNotify->OnValueChanged(this, eAttribute, pParentNode, |
| 1643 | pParentNode->GetNodeItem(XFA_NODEITEM_Parent)); |
| 1644 | } else { |
| 1645 | pNotify->OnValueChanged(this, eAttribute, this, pParentNode); |
| 1646 | } |
| 1647 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1648 | case XFA_Element::Margin: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1649 | bNeedFindContainer = true; |
| 1650 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1651 | XFA_Element eParentType = pParentNode->GetElementType(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1652 | if (pParentNode->IsContainerNode()) { |
| 1653 | pNotify->OnValueChanged(this, eAttribute, this, pParentNode); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1654 | } else if (eParentType == XFA_Element::Caption) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1655 | pNotify->OnValueChanged(this, eAttribute, pParentNode, |
| 1656 | pParentNode->GetNodeItem(XFA_NODEITEM_Parent)); |
| 1657 | } else { |
| 1658 | CXFA_Node* pNode = pParentNode->GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1659 | if (pNode && pNode->GetElementType() == XFA_Element::Ui) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1660 | pNotify->OnValueChanged(this, eAttribute, pNode, |
| 1661 | pNode->GetNodeItem(XFA_NODEITEM_Parent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1662 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1663 | } |
| 1664 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1665 | case XFA_Element::Comb: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1666 | CXFA_Node* pEditNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1667 | XFA_Element eUIType = pEditNode->GetElementType(); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1668 | if (pEditNode && (eUIType == XFA_Element::DateTimeEdit || |
| 1669 | eUIType == XFA_Element::NumericEdit || |
| 1670 | eUIType == XFA_Element::TextEdit)) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1671 | CXFA_Node* pUINode = pEditNode->GetNodeItem(XFA_NODEITEM_Parent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1672 | if (pUINode) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1673 | pNotify->OnValueChanged(this, eAttribute, pUINode, |
| 1674 | pUINode->GetNodeItem(XFA_NODEITEM_Parent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1675 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1676 | } |
| 1677 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1678 | case XFA_Element::Button: |
| 1679 | case XFA_Element::Barcode: |
| 1680 | case XFA_Element::ChoiceList: |
| 1681 | case XFA_Element::DateTimeEdit: |
| 1682 | case XFA_Element::NumericEdit: |
| 1683 | case XFA_Element::PasswordEdit: |
| 1684 | case XFA_Element::TextEdit: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1685 | CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent); |
| 1686 | if (pUINode) { |
| 1687 | pNotify->OnValueChanged(this, eAttribute, pUINode, |
| 1688 | pUINode->GetNodeItem(XFA_NODEITEM_Parent)); |
| 1689 | } |
| 1690 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1691 | case XFA_Element::CheckButton: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1692 | bNeedFindContainer = true; |
| 1693 | CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent); |
| 1694 | if (pUINode) { |
| 1695 | pNotify->OnValueChanged(this, eAttribute, pUINode, |
| 1696 | pUINode->GetNodeItem(XFA_NODEITEM_Parent)); |
| 1697 | } |
| 1698 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1699 | case XFA_Element::Keep: |
| 1700 | case XFA_Element::Bookend: |
| 1701 | case XFA_Element::Break: |
| 1702 | case XFA_Element::BreakAfter: |
| 1703 | case XFA_Element::BreakBefore: |
| 1704 | case XFA_Element::Overflow: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1705 | bNeedFindContainer = true; |
| 1706 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1707 | case XFA_Element::Area: |
| 1708 | case XFA_Element::Draw: |
| 1709 | case XFA_Element::ExclGroup: |
| 1710 | case XFA_Element::Field: |
| 1711 | case XFA_Element::Subform: |
| 1712 | case XFA_Element::SubformSet: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1713 | pLayoutPro->AddChangedContainer(this); |
| 1714 | pNotify->OnValueChanged(this, eAttribute, this, this); |
| 1715 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1716 | case XFA_Element::Sharptext: |
| 1717 | case XFA_Element::Sharpxml: |
| 1718 | case XFA_Element::SharpxHTML: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1719 | CXFA_Node* pTextNode = GetNodeItem(XFA_NODEITEM_Parent); |
| 1720 | if (!pTextNode) { |
| 1721 | return; |
| 1722 | } |
| 1723 | CXFA_Node* pValueNode = pTextNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 1724 | if (!pValueNode) { |
| 1725 | return; |
| 1726 | } |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1727 | XFA_Element eType = pValueNode->GetElementType(); |
| 1728 | if (eType == XFA_Element::Value) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1729 | bNeedFindContainer = true; |
| 1730 | CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 1731 | if (pNode && pNode->IsContainerNode()) { |
| 1732 | if (bScriptModify) { |
| 1733 | pValueNode = pNode; |
| 1734 | } |
| 1735 | pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode); |
| 1736 | } else { |
| 1737 | pNotify->OnValueChanged(this, eAttribute, pNode, |
| 1738 | pNode->GetNodeItem(XFA_NODEITEM_Parent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1739 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1740 | } else { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1741 | if (eType == XFA_Element::Items) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1742 | CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 1743 | if (pNode && pNode->IsContainerNode()) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1744 | pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1745 | } |
| 1746 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1747 | } |
| 1748 | } break; |
| 1749 | default: |
| 1750 | break; |
| 1751 | } |
| 1752 | if (bNeedFindContainer) { |
| 1753 | CXFA_Node* pParent = this; |
| 1754 | while (pParent) { |
| 1755 | if (pParent->IsContainerNode()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1756 | break; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1757 | |
| 1758 | pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1759 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1760 | if (pParent) { |
| 1761 | pLayoutPro->AddChangedContainer(pParent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1762 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1763 | } |
| 1764 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1765 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1766 | void CXFA_Node::Script_Attribute_String(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1767 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1768 | XFA_ATTRIBUTE eAttribute) { |
| 1769 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1770 | CFX_WideString wsValue = pValue->ToWideString(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1771 | SetAttribute(eAttribute, wsValue.AsStringC(), true); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1772 | if (eAttribute == XFA_ATTRIBUTE_Use && |
| 1773 | GetElementType() == XFA_Element::Desc) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1774 | CXFA_Node* pTemplateNode = |
| 1775 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template)); |
| 1776 | CXFA_Node* pProtoRoot = |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1777 | pTemplateNode->GetFirstChildByClass(XFA_Element::Subform) |
| 1778 | ->GetFirstChildByClass(XFA_Element::Proto); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1779 | |
| 1780 | CFX_WideString wsID; |
| 1781 | CFX_WideString wsSOM; |
| 1782 | if (!wsValue.IsEmpty()) { |
| 1783 | if (wsValue[0] == '#') { |
| 1784 | wsID = CFX_WideString(wsValue.c_str() + 1, wsValue.GetLength() - 1); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1785 | } else { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1786 | wsSOM = wsValue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1787 | } |
| 1788 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1789 | CXFA_Node* pProtoNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1790 | if (!wsSOM.IsEmpty()) { |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1791 | uint32_t dwFlag = XFA_RESOLVENODE_Children | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1792 | XFA_RESOLVENODE_Attributes | |
| 1793 | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | |
| 1794 | XFA_RESOLVENODE_Siblings; |
| 1795 | XFA_RESOLVENODE_RS resoveNodeRS; |
| 1796 | int32_t iRet = m_pDocument->GetScriptContext()->ResolveObjects( |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1797 | pProtoRoot, wsSOM.AsStringC(), resoveNodeRS, dwFlag); |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 1798 | if (iRet > 0 && resoveNodeRS.objects.front()->IsNode()) { |
| 1799 | pProtoNode = resoveNodeRS.objects.front()->AsNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1800 | } |
| 1801 | } else if (!wsID.IsEmpty()) { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1802 | pProtoNode = m_pDocument->GetNodeByID(pProtoRoot, wsID.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1803 | } |
| 1804 | if (pProtoNode) { |
| 1805 | CXFA_Node* pHeadChild = GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1806 | while (pHeadChild) { |
| 1807 | CXFA_Node* pSibling = |
| 1808 | pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1809 | RemoveChild(pHeadChild); |
| 1810 | pHeadChild = pSibling; |
| 1811 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1812 | CXFA_Node* pProtoForm = pProtoNode->CloneTemplateToForm(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1813 | pHeadChild = pProtoForm->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1814 | while (pHeadChild) { |
| 1815 | CXFA_Node* pSibling = |
| 1816 | pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1817 | pProtoForm->RemoveChild(pHeadChild); |
| 1818 | InsertChild(pHeadChild); |
| 1819 | pHeadChild = pSibling; |
| 1820 | } |
| 1821 | m_pDocument->RemovePurgeNode(pProtoForm); |
| 1822 | delete pProtoForm; |
| 1823 | } |
| 1824 | } |
| 1825 | } else { |
| 1826 | CFX_WideString wsValue; |
| 1827 | GetAttribute(eAttribute, wsValue); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 1828 | pValue->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1829 | } |
| 1830 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1831 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1832 | void CXFA_Node::Script_Attribute_StringRead(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1833 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1834 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1835 | if (bSetting) { |
| 1836 | ThrowInvalidPropertyException(); |
| 1837 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1838 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1839 | |
| 1840 | CFX_WideString wsValue; |
| 1841 | GetAttribute(eAttribute, wsValue); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 1842 | pValue->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1843 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1844 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1845 | void CXFA_Node::Script_WsdlConnection_Execute(CFXJSE_Arguments* pArguments) { |
| 1846 | int32_t argc = pArguments->GetLength(); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1847 | if (argc != 0 && argc != 1) { |
| 1848 | ThrowParamCountMismatchException(L"execute"); |
| 1849 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1850 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1851 | pArguments->GetReturnValue()->SetBoolean(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1852 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1853 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1854 | void CXFA_Node::Script_Delta_Restore(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1855 | if (pArguments->GetLength() != 0) |
| 1856 | ThrowParamCountMismatchException(L"restore"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1857 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1858 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1859 | void CXFA_Node::Script_Delta_CurrentValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1860 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1861 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1862 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1863 | void CXFA_Node::Script_Delta_SavedValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1864 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1865 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1866 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1867 | void CXFA_Node::Script_Delta_Target(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1868 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1869 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1870 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1871 | void CXFA_Node::Script_Som_Message(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1872 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1873 | XFA_SOM_MESSAGETYPE iMessageType) { |
| 1874 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 1875 | if (!pWidgetData) { |
| 1876 | return; |
| 1877 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1878 | bool bNew = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1879 | CXFA_Validate validate = pWidgetData->GetValidate(); |
| 1880 | if (!validate) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1881 | validate = pWidgetData->GetValidate(true); |
| 1882 | bNew = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1883 | } |
| 1884 | if (bSetting) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1885 | switch (iMessageType) { |
| 1886 | case XFA_SOM_ValidationMessage: |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1887 | validate.SetScriptMessageText(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1888 | break; |
| 1889 | case XFA_SOM_FormatMessage: |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1890 | validate.SetFormatMessageText(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1891 | break; |
| 1892 | case XFA_SOM_MandatoryMessage: |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1893 | validate.SetNullMessageText(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1894 | break; |
| 1895 | default: |
| 1896 | break; |
| 1897 | } |
| 1898 | if (!bNew) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 1899 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1900 | if (!pNotify) { |
| 1901 | return; |
| 1902 | } |
| 1903 | pNotify->AddCalcValidate(this); |
| 1904 | } |
| 1905 | } else { |
| 1906 | CFX_WideString wsMessage; |
| 1907 | switch (iMessageType) { |
| 1908 | case XFA_SOM_ValidationMessage: |
| 1909 | validate.GetScriptMessageText(wsMessage); |
| 1910 | break; |
| 1911 | case XFA_SOM_FormatMessage: |
| 1912 | validate.GetFormatMessageText(wsMessage); |
| 1913 | break; |
| 1914 | case XFA_SOM_MandatoryMessage: |
| 1915 | validate.GetNullMessageText(wsMessage); |
| 1916 | break; |
| 1917 | default: |
| 1918 | break; |
| 1919 | } |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 1920 | pValue->SetString(wsMessage.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1921 | } |
| 1922 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1923 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1924 | void CXFA_Node::Script_Som_ValidationMessage(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1925 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1926 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1927 | Script_Som_Message(pValue, bSetting, XFA_SOM_ValidationMessage); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1928 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1929 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1930 | void CXFA_Node::Script_Field_Length(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1931 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1932 | XFA_ATTRIBUTE eAttribute) { |
| 1933 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1934 | ThrowInvalidPropertyException(); |
| 1935 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1936 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 1937 | |
| 1938 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 1939 | if (!pWidgetData) { |
| 1940 | pValue->SetInteger(0); |
| 1941 | return; |
| 1942 | } |
| 1943 | pValue->SetInteger(pWidgetData->CountChoiceListItems(true)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1944 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1945 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1946 | void CXFA_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1947 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1948 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1949 | XFA_Element eType = GetElementType(); |
| 1950 | if (eType == XFA_Element::Field) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1951 | Script_Field_DefaultValue(pValue, bSetting, eAttribute); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1952 | return; |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1953 | } |
| 1954 | if (eType == XFA_Element::Draw) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1955 | Script_Draw_DefaultValue(pValue, bSetting, eAttribute); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1956 | return; |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1957 | } |
| 1958 | if (eType == XFA_Element::Boolean) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1959 | Script_Boolean_Value(pValue, bSetting, eAttribute); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1960 | return; |
| 1961 | } |
| 1962 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1963 | CFX_WideString wsNewValue; |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 1964 | if (!(pValue && (pValue->IsNull() || pValue->IsUndefined()))) |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1965 | wsNewValue = pValue->ToWideString(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1966 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1967 | CFX_WideString wsFormatValue(wsNewValue); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1968 | CXFA_WidgetData* pContainerWidgetData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1969 | if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1970 | CFX_WideString wsPicture; |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 1971 | for (CXFA_Node* pFormNode : GetBindItems()) { |
| 1972 | if (!pFormNode || pFormNode->HasRemovedChildren()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1973 | continue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1974 | pContainerWidgetData = pFormNode->GetContainerWidgetData(); |
| 1975 | if (pContainerWidgetData) { |
| 1976 | pContainerWidgetData->GetPictureContent(wsPicture, |
| 1977 | XFA_VALUEPICTURE_DataBind); |
| 1978 | } |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 1979 | if (!wsPicture.IsEmpty()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1980 | break; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1981 | pContainerWidgetData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1982 | } |
| 1983 | } else if (GetPacketID() == XFA_XDPPACKET_Form) { |
| 1984 | pContainerWidgetData = GetContainerWidgetData(); |
| 1985 | } |
| 1986 | if (pContainerWidgetData) { |
tsepez | 6f167c3 | 2016-04-14 15:46:27 -0700 | [diff] [blame] | 1987 | pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1988 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1989 | SetScriptContent(wsNewValue, wsFormatValue, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1990 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 1991 | CFX_WideString content = GetScriptContent(true); |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1992 | if (content.IsEmpty() && eType != XFA_Element::Text && |
| 1993 | eType != XFA_Element::SubmitUrl) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1994 | pValue->SetNull(); |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1995 | } else if (eType == XFA_Element::Integer) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1996 | pValue->SetInteger(FXSYS_wtoi(content.c_str())); |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1997 | } else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1998 | CFX_Decimal decimal(content.AsStringC()); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1999 | pValue->SetFloat((float)(double)decimal); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2000 | } else { |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2001 | pValue->SetString(content.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2002 | } |
| 2003 | } |
| 2004 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2005 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2006 | void CXFA_Node::Script_Som_DefaultValue_Read(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2007 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2008 | XFA_ATTRIBUTE eAttribute) { |
| 2009 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2010 | ThrowInvalidPropertyException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2011 | return; |
| 2012 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2013 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2014 | CFX_WideString content = GetScriptContent(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2015 | if (content.IsEmpty()) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2016 | pValue->SetNull(); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2017 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2018 | } |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2019 | pValue->SetString(content.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2020 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2021 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2022 | void CXFA_Node::Script_Boolean_Value(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2023 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2024 | XFA_ATTRIBUTE eAttribute) { |
| 2025 | if (bSetting) { |
| 2026 | CFX_ByteString newValue; |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 2027 | if (!(pValue && (pValue->IsNull() || pValue->IsUndefined()))) |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2028 | newValue = pValue->ToString(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2029 | |
tsepez | b4c9f3f | 2016-04-13 15:41:21 -0700 | [diff] [blame] | 2030 | int32_t iValue = FXSYS_atoi(newValue.c_str()); |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 2031 | CFX_WideString wsNewValue(iValue == 0 ? L"0" : L"1"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2032 | CFX_WideString wsFormatValue(wsNewValue); |
| 2033 | CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData(); |
| 2034 | if (pContainerWidgetData) { |
tsepez | 6f167c3 | 2016-04-14 15:46:27 -0700 | [diff] [blame] | 2035 | pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2036 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2037 | SetScriptContent(wsNewValue, wsFormatValue, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2038 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2039 | CFX_WideString wsValue = GetScriptContent(true); |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 2040 | pValue->SetBoolean(wsValue == L"1"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2041 | } |
| 2042 | } |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2043 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2044 | void CXFA_Node::Script_Som_BorderColor(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2045 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2046 | XFA_ATTRIBUTE eAttribute) { |
| 2047 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2048 | if (!pWidgetData) { |
| 2049 | return; |
| 2050 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2051 | CXFA_Border border = pWidgetData->GetBorder(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2052 | int32_t iSize = border.CountEdges(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2053 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2054 | int32_t r = 0; |
| 2055 | int32_t g = 0; |
| 2056 | int32_t b = 0; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2057 | StrToRGB(pValue->ToWideString(), r, g, b); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2058 | FX_ARGB rgb = ArgbEncode(100, r, g, b); |
| 2059 | for (int32_t i = 0; i < iSize; ++i) { |
| 2060 | CXFA_Edge edge = border.GetEdge(i); |
| 2061 | edge.SetColor(rgb); |
| 2062 | } |
| 2063 | } else { |
| 2064 | CXFA_Edge edge = border.GetEdge(0); |
| 2065 | FX_ARGB color = edge.GetColor(); |
| 2066 | int32_t a, r, g, b; |
| 2067 | ArgbDecode(color, a, r, g, b); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2068 | CFX_WideString strColor; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2069 | strColor.Format(L"%d,%d,%d", r, g, b); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2070 | pValue->SetString(strColor.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2071 | } |
| 2072 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2073 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2074 | void CXFA_Node::Script_Som_BorderWidth(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2075 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2076 | XFA_ATTRIBUTE eAttribute) { |
| 2077 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2078 | if (!pWidgetData) { |
| 2079 | return; |
| 2080 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2081 | CXFA_Border border = pWidgetData->GetBorder(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2082 | int32_t iSize = border.CountEdges(); |
| 2083 | CFX_WideString wsThickness; |
| 2084 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2085 | wsThickness = pValue->ToWideString(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2086 | for (int32_t i = 0; i < iSize; ++i) { |
| 2087 | CXFA_Edge edge = border.GetEdge(i); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2088 | CXFA_Measurement thickness(wsThickness.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2089 | edge.SetMSThickness(thickness); |
| 2090 | } |
| 2091 | } else { |
| 2092 | CXFA_Edge edge = border.GetEdge(0); |
| 2093 | CXFA_Measurement thickness = edge.GetMSThickness(); |
| 2094 | thickness.ToString(wsThickness); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2095 | pValue->SetString(wsThickness.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2096 | } |
| 2097 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2098 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2099 | void CXFA_Node::Script_Som_FillColor(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2100 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2101 | XFA_ATTRIBUTE eAttribute) { |
| 2102 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2103 | if (!pWidgetData) { |
| 2104 | return; |
| 2105 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2106 | CXFA_Border border = pWidgetData->GetBorder(true); |
| 2107 | CXFA_Fill borderfill = border.GetFill(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2108 | CXFA_Node* pNode = borderfill.GetNode(); |
| 2109 | if (!pNode) { |
| 2110 | return; |
| 2111 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2112 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2113 | int32_t r; |
| 2114 | int32_t g; |
| 2115 | int32_t b; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2116 | StrToRGB(pValue->ToWideString(), r, g, b); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2117 | FX_ARGB color = ArgbEncode(0xff, r, g, b); |
| 2118 | borderfill.SetColor(color); |
| 2119 | } else { |
| 2120 | FX_ARGB color = borderfill.GetColor(); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2121 | int32_t a; |
| 2122 | int32_t r; |
| 2123 | int32_t g; |
| 2124 | int32_t b; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2125 | ArgbDecode(color, a, r, g, b); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2126 | CFX_WideString wsColor; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2127 | wsColor.Format(L"%d,%d,%d", r, g, b); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2128 | pValue->SetString(wsColor.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2129 | } |
| 2130 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2131 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2132 | void CXFA_Node::Script_Som_DataNode(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2133 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2134 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2135 | if (bSetting) { |
| 2136 | ThrowInvalidPropertyException(); |
| 2137 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2138 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2139 | |
| 2140 | CXFA_Node* pDataNode = GetBindData(); |
| 2141 | if (!pDataNode) { |
| 2142 | pValue->SetNull(); |
| 2143 | return; |
| 2144 | } |
| 2145 | |
| 2146 | pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pDataNode)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2147 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2148 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2149 | void CXFA_Node::Script_Draw_DefaultValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2150 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2151 | XFA_ATTRIBUTE eAttribute) { |
| 2152 | if (bSetting) { |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 2153 | if (pValue && pValue->IsString()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2154 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 2155 | ASSERT(pWidgetData); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 2156 | XFA_Element uiType = pWidgetData->GetUIType(); |
| 2157 | if (uiType == XFA_Element::Text) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2158 | CFX_WideString wsNewValue = pValue->ToWideString(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2159 | CFX_WideString wsFormatValue(wsNewValue); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2160 | SetScriptContent(wsNewValue, wsFormatValue, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2161 | } |
| 2162 | } |
| 2163 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2164 | CFX_WideString content = GetScriptContent(true); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2165 | if (content.IsEmpty()) |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2166 | pValue->SetNull(); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2167 | else |
| 2168 | pValue->SetString(content.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2169 | } |
| 2170 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2171 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2172 | void CXFA_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2173 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2174 | XFA_ATTRIBUTE eAttribute) { |
| 2175 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2176 | if (!pWidgetData) { |
| 2177 | return; |
| 2178 | } |
| 2179 | if (bSetting) { |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 2180 | if (pValue && pValue->IsNull()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2181 | pWidgetData->m_bPreNull = pWidgetData->m_bIsNull; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2182 | pWidgetData->m_bIsNull = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2183 | } else { |
| 2184 | pWidgetData->m_bPreNull = pWidgetData->m_bIsNull; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2185 | pWidgetData->m_bIsNull = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2186 | } |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2187 | CFX_WideString wsNewText; |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 2188 | if (!(pValue && (pValue->IsNull() || pValue->IsUndefined()))) |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2189 | wsNewText = pValue->ToWideString(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2190 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2191 | CXFA_Node* pUIChild = pWidgetData->GetUIChild(); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2192 | if (pUIChild->GetElementType() == XFA_Element::NumericEdit) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2193 | int32_t iLeadDigits = 0; |
| 2194 | int32_t iFracDigits = 0; |
| 2195 | pWidgetData->GetLeadDigits(iLeadDigits); |
| 2196 | pWidgetData->GetFracDigits(iFracDigits); |
dsinclair | 44d054c | 2016-04-06 10:23:46 -0700 | [diff] [blame] | 2197 | wsNewText = |
| 2198 | pWidgetData->NumericLimit(wsNewText, iLeadDigits, iFracDigits); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2199 | } |
| 2200 | CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData(); |
| 2201 | CFX_WideString wsFormatText(wsNewText); |
| 2202 | if (pContainerWidgetData) { |
tsepez | 6f167c3 | 2016-04-14 15:46:27 -0700 | [diff] [blame] | 2203 | pContainerWidgetData->GetFormatDataValue(wsNewText, wsFormatText); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2204 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2205 | SetScriptContent(wsNewText, wsFormatText, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2206 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2207 | CFX_WideString content = GetScriptContent(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2208 | if (content.IsEmpty()) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2209 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2210 | } else { |
| 2211 | CXFA_Node* pUIChild = pWidgetData->GetUIChild(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2212 | CXFA_Value defVal = pWidgetData->GetFormValue(); |
| 2213 | CXFA_Node* pNode = defVal.GetNode()->GetNodeItem(XFA_NODEITEM_FirstChild); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2214 | if (pNode && pNode->GetElementType() == XFA_Element::Decimal) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 2215 | if (pUIChild->GetElementType() == XFA_Element::NumericEdit && |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2216 | (pNode->GetInteger(XFA_ATTRIBUTE_FracDigits) == -1)) { |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2217 | pValue->SetString(content.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2218 | } else { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2219 | CFX_Decimal decimal(content.AsStringC()); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 2220 | pValue->SetFloat((float)(double)decimal); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2221 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2222 | } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2223 | pValue->SetInteger(FXSYS_wtoi(content.c_str())); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2224 | } else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2225 | pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? false : true); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2226 | } else if (pNode && pNode->GetElementType() == XFA_Element::Float) { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2227 | CFX_Decimal decimal(content.AsStringC()); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 2228 | pValue->SetFloat((float)(double)decimal); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2229 | } else { |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2230 | pValue->SetString(content.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2231 | } |
| 2232 | } |
| 2233 | } |
| 2234 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2235 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2236 | void CXFA_Node::Script_Field_EditValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2237 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2238 | XFA_ATTRIBUTE eAttribute) { |
| 2239 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2240 | if (!pWidgetData) { |
| 2241 | return; |
| 2242 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2243 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2244 | pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Edit); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2245 | } else { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2246 | CFX_WideString wsValue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2247 | pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Edit); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2248 | pValue->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2249 | } |
| 2250 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2251 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2252 | void CXFA_Node::Script_Som_FontColor(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2253 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2254 | XFA_ATTRIBUTE eAttribute) { |
| 2255 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2256 | if (!pWidgetData) { |
| 2257 | return; |
| 2258 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2259 | CXFA_Font font = pWidgetData->GetFont(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2260 | CXFA_Node* pNode = font.GetNode(); |
| 2261 | if (!pNode) { |
| 2262 | return; |
| 2263 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2264 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2265 | int32_t r; |
| 2266 | int32_t g; |
| 2267 | int32_t b; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2268 | StrToRGB(pValue->ToWideString(), r, g, b); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2269 | FX_ARGB color = ArgbEncode(0xff, r, g, b); |
| 2270 | font.SetColor(color); |
| 2271 | } else { |
| 2272 | FX_ARGB color = font.GetColor(); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2273 | int32_t a; |
| 2274 | int32_t r; |
| 2275 | int32_t g; |
| 2276 | int32_t b; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2277 | ArgbDecode(color, a, r, g, b); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2278 | CFX_WideString wsColor; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2279 | wsColor.Format(L"%d,%d,%d", r, g, b); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2280 | pValue->SetString(wsColor.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2281 | } |
| 2282 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2283 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2284 | void CXFA_Node::Script_Field_FormatMessage(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2285 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2286 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2287 | Script_Som_Message(pValue, bSetting, XFA_SOM_FormatMessage); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2288 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2289 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2290 | void CXFA_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2291 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2292 | XFA_ATTRIBUTE eAttribute) { |
| 2293 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2294 | if (!pWidgetData) { |
| 2295 | return; |
| 2296 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2297 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2298 | pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Display); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2299 | } else { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2300 | CFX_WideString wsValue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2301 | pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Display); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2302 | pValue->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2303 | } |
| 2304 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2305 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2306 | void CXFA_Node::Script_Som_Mandatory(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2307 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2308 | XFA_ATTRIBUTE eAttribute) { |
| 2309 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2310 | if (!pWidgetData) { |
| 2311 | return; |
| 2312 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2313 | CXFA_Validate validate = pWidgetData->GetValidate(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2314 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2315 | validate.SetNullTest(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2316 | } else { |
| 2317 | int32_t iValue = validate.GetNullTest(); |
| 2318 | const XFA_ATTRIBUTEENUMINFO* pInfo = |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 2319 | GetAttributeEnumByID((XFA_ATTRIBUTEENUM)iValue); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2320 | CFX_WideString wsValue; |
| 2321 | if (pInfo) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2322 | wsValue = pInfo->pName; |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2323 | pValue->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2324 | } |
| 2325 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2326 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2327 | void CXFA_Node::Script_Som_MandatoryMessage(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2328 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2329 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2330 | Script_Som_Message(pValue, bSetting, XFA_SOM_MandatoryMessage); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2331 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2332 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2333 | void CXFA_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2334 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2335 | XFA_ATTRIBUTE eAttribute) { |
| 2336 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2337 | ThrowInvalidPropertyException(); |
| 2338 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2339 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2340 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2341 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2342 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2343 | void CXFA_Node::Script_Field_SelectedIndex(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2344 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2345 | XFA_ATTRIBUTE eAttribute) { |
| 2346 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2347 | if (!pWidgetData) { |
| 2348 | return; |
| 2349 | } |
| 2350 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2351 | int32_t iIndex = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2352 | if (iIndex == -1) { |
| 2353 | pWidgetData->ClearAllSelections(); |
| 2354 | return; |
| 2355 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2356 | pWidgetData->SetItemState(iIndex, true, true, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2357 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2358 | pValue->SetInteger(pWidgetData->GetSelectedItem()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2359 | } |
| 2360 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2361 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2362 | void CXFA_Node::Script_Field_ClearItems(CFXJSE_Arguments* pArguments) { |
| 2363 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2364 | if (!pWidgetData) { |
| 2365 | return; |
| 2366 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2367 | pWidgetData->DeleteItem(-1, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2368 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2369 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2370 | void CXFA_Node::Script_Field_ExecEvent(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2371 | if (pArguments->GetLength() != 1) { |
| 2372 | ThrowParamCountMismatchException(L"execEvent"); |
| 2373 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2374 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2375 | |
| 2376 | CFX_ByteString eventString = pArguments->GetUTF8String(0); |
| 2377 | int32_t iRet = execSingleEventByName( |
| 2378 | CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(), |
| 2379 | XFA_Element::Field); |
| 2380 | if (eventString != "validate") |
| 2381 | return; |
| 2382 | |
| 2383 | pArguments->GetReturnValue()->SetBoolean( |
| 2384 | (iRet == XFA_EVENTERROR_Error) ? false : true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2385 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2386 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2387 | void CXFA_Node::Script_Field_ExecInitialize(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2388 | if (pArguments->GetLength() != 0) { |
| 2389 | ThrowParamCountMismatchException(L"execInitialize"); |
| 2390 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2391 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2392 | |
| 2393 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2394 | if (!pNotify) |
| 2395 | return; |
| 2396 | |
| 2397 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize, false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2398 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2399 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2400 | void CXFA_Node::Script_Field_DeleteItem(CFXJSE_Arguments* pArguments) { |
| 2401 | int32_t iLength = pArguments->GetLength(); |
| 2402 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2403 | ThrowParamCountMismatchException(L"deleteItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2404 | return; |
| 2405 | } |
| 2406 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2407 | if (!pWidgetData) { |
| 2408 | return; |
| 2409 | } |
| 2410 | int32_t iIndex = pArguments->GetInt32(0); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2411 | bool bValue = pWidgetData->DeleteItem(iIndex, true, true); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2412 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2413 | if (pValue) |
| 2414 | pValue->SetBoolean(bValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2415 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2416 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2417 | void CXFA_Node::Script_Field_GetSaveItem(CFXJSE_Arguments* pArguments) { |
| 2418 | int32_t iLength = pArguments->GetLength(); |
| 2419 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2420 | ThrowParamCountMismatchException(L"getSaveItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2421 | return; |
| 2422 | } |
| 2423 | int32_t iIndex = pArguments->GetInt32(0); |
| 2424 | if (iIndex < 0) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2425 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2426 | return; |
| 2427 | } |
| 2428 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2429 | if (!pWidgetData) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2430 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2431 | return; |
| 2432 | } |
| 2433 | CFX_WideString wsValue; |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2434 | if (!pWidgetData->GetChoiceListItem(wsValue, iIndex, true)) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2435 | pArguments->GetReturnValue()->SetNull(); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2436 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2437 | } |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2438 | pArguments->GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2439 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2440 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2441 | void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments) { |
| 2442 | int32_t iLength = pArguments->GetLength(); |
| 2443 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2444 | ThrowParamCountMismatchException(L"boundItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2445 | return; |
| 2446 | } |
| 2447 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2448 | if (!pWidgetData) { |
| 2449 | return; |
| 2450 | } |
| 2451 | CFX_ByteString bsValue = pArguments->GetUTF8String(0); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2452 | CFX_WideString wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2453 | CFX_WideString wsBoundValue; |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2454 | pWidgetData->GetItemValue(wsValue.AsStringC(), wsBoundValue); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2455 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2456 | if (pValue) |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2457 | pValue->SetString(wsBoundValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2458 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2459 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2460 | void CXFA_Node::Script_Field_GetItemState(CFXJSE_Arguments* pArguments) { |
| 2461 | int32_t iLength = pArguments->GetLength(); |
| 2462 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2463 | ThrowParamCountMismatchException(L"getItemState"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2464 | return; |
| 2465 | } |
| 2466 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2467 | if (!pWidgetData) { |
| 2468 | return; |
| 2469 | } |
| 2470 | int32_t iIndex = pArguments->GetInt32(0); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2471 | bool bValue = pWidgetData->GetItemState(iIndex); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2472 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2473 | if (pValue) |
| 2474 | pValue->SetBoolean(bValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2475 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2476 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2477 | void CXFA_Node::Script_Field_ExecCalculate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2478 | if (pArguments->GetLength() != 0) { |
| 2479 | ThrowParamCountMismatchException(L"execCalculate"); |
| 2480 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2481 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2482 | |
| 2483 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2484 | if (!pNotify) |
| 2485 | return; |
| 2486 | |
| 2487 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate, false, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2488 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2489 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2490 | void CXFA_Node::Script_Field_SetItems(CFXJSE_Arguments* pArguments) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2491 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2492 | void CXFA_Node::Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments) { |
| 2493 | int32_t iLength = pArguments->GetLength(); |
| 2494 | if (iLength != 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2495 | ThrowParamCountMismatchException(L"getDisplayItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2496 | return; |
| 2497 | } |
| 2498 | int32_t iIndex = pArguments->GetInt32(0); |
| 2499 | if (iIndex < 0) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2500 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2501 | return; |
| 2502 | } |
| 2503 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2504 | if (!pWidgetData) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2505 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2506 | return; |
| 2507 | } |
| 2508 | CFX_WideString wsValue; |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2509 | if (!pWidgetData->GetChoiceListItem(wsValue, iIndex, false)) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2510 | pArguments->GetReturnValue()->SetNull(); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2511 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2512 | } |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2513 | pArguments->GetReturnValue()->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2514 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2515 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2516 | void CXFA_Node::Script_Field_SetItemState(CFXJSE_Arguments* pArguments) { |
| 2517 | int32_t iLength = pArguments->GetLength(); |
| 2518 | if (iLength != 2) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2519 | ThrowParamCountMismatchException(L"setItemState"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2520 | return; |
| 2521 | } |
| 2522 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2523 | if (!pWidgetData) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2524 | return; |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2525 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2526 | int32_t iIndex = pArguments->GetInt32(0); |
| 2527 | if (pArguments->GetInt32(1) != 0) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2528 | pWidgetData->SetItemState(iIndex, true, true, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2529 | } else { |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2530 | if (pWidgetData->GetItemState(iIndex)) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2531 | pWidgetData->SetItemState(iIndex, false, true, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2532 | } |
| 2533 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2534 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2535 | void CXFA_Node::Script_Field_AddItem(CFXJSE_Arguments* pArguments) { |
| 2536 | int32_t iLength = pArguments->GetLength(); |
| 2537 | if (iLength < 1 || iLength > 2) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2538 | ThrowParamCountMismatchException(L"addItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2539 | return; |
| 2540 | } |
| 2541 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2542 | if (!pWidgetData) { |
| 2543 | return; |
| 2544 | } |
| 2545 | CFX_WideString wsLabel; |
| 2546 | CFX_WideString wsValue; |
| 2547 | if (iLength >= 1) { |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 2548 | CFX_ByteString bsLabel = pArguments->GetUTF8String(0); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2549 | wsLabel = CFX_WideString::FromUTF8(bsLabel.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2550 | } |
| 2551 | if (iLength >= 2) { |
| 2552 | CFX_ByteString bsValue = pArguments->GetUTF8String(1); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2553 | wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2554 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2555 | pWidgetData->InsertItem(wsLabel, wsValue, -1, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2556 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2557 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2558 | void CXFA_Node::Script_Field_ExecValidate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2559 | if (pArguments->GetLength() != 0) { |
| 2560 | ThrowParamCountMismatchException(L"execValidate"); |
| 2561 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2562 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2563 | |
| 2564 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2565 | if (!pNotify) { |
| 2566 | pArguments->GetReturnValue()->SetBoolean(false); |
| 2567 | return; |
| 2568 | } |
| 2569 | |
| 2570 | int32_t iRet = |
| 2571 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate, false, false); |
| 2572 | pArguments->GetReturnValue()->SetBoolean( |
| 2573 | (iRet == XFA_EVENTERROR_Error) ? false : true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2574 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2575 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2576 | void CXFA_Node::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2577 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2578 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2579 | if (bSetting) |
| 2580 | ThrowInvalidPropertyException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2581 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2582 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2583 | void CXFA_Node::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2584 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2585 | XFA_ATTRIBUTE eAttribute) { |
| 2586 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2587 | if (!pWidgetData) { |
| 2588 | return; |
| 2589 | } |
| 2590 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2591 | pWidgetData->SetSelectedMemberByValue(pValue->ToWideString().AsStringC(), |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2592 | true, true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2593 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2594 | CFX_WideString wsValue = GetScriptContent(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2595 | XFA_VERSION curVersion = GetDocument()->GetCurVersionMode(); |
| 2596 | if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2597 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2598 | } else { |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2599 | pValue->SetString(wsValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2600 | } |
| 2601 | } |
| 2602 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2603 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2604 | void CXFA_Node::Script_ExclGroup_Transient(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2605 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2606 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2607 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2608 | void CXFA_Node::Script_ExclGroup_ExecEvent(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2609 | if (pArguments->GetLength() != 1) { |
| 2610 | ThrowParamCountMismatchException(L"execEvent"); |
| 2611 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2612 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2613 | |
| 2614 | CFX_ByteString eventString = pArguments->GetUTF8String(0); |
| 2615 | execSingleEventByName( |
| 2616 | CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(), |
| 2617 | XFA_Element::ExclGroup); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2618 | } |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2619 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2620 | void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments) { |
| 2621 | int32_t argc = pArguments->GetLength(); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2622 | if (argc < 0 || argc > 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2623 | ThrowParamCountMismatchException(L"selectedMember"); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2624 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2625 | } |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2626 | |
| 2627 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2628 | if (!pWidgetData) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2629 | pArguments->GetReturnValue()->SetNull(); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2630 | return; |
| 2631 | } |
| 2632 | |
| 2633 | CXFA_Node* pReturnNode = nullptr; |
| 2634 | if (argc == 0) { |
| 2635 | pReturnNode = pWidgetData->GetSelectedMember(); |
| 2636 | } else { |
| 2637 | CFX_ByteString szName; |
| 2638 | szName = pArguments->GetUTF8String(0); |
| 2639 | pReturnNode = pWidgetData->SetSelectedMember( |
| 2640 | CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC(), true); |
| 2641 | } |
| 2642 | if (!pReturnNode) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2643 | pArguments->GetReturnValue()->SetNull(); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2644 | return; |
| 2645 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2646 | pArguments->GetReturnValue()->Assign( |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2647 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pReturnNode)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2648 | } |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2649 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2650 | void CXFA_Node::Script_ExclGroup_ExecInitialize(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2651 | if (pArguments->GetLength() != 0) { |
| 2652 | ThrowParamCountMismatchException(L"execInitialize"); |
| 2653 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2654 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2655 | |
| 2656 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2657 | if (!pNotify) |
| 2658 | return; |
| 2659 | |
| 2660 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2661 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2662 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2663 | void CXFA_Node::Script_ExclGroup_ExecCalculate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2664 | if (pArguments->GetLength() != 0) { |
| 2665 | ThrowParamCountMismatchException(L"execCalculate"); |
| 2666 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2667 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2668 | |
| 2669 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2670 | if (!pNotify) |
| 2671 | return; |
| 2672 | |
| 2673 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2674 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2675 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2676 | void CXFA_Node::Script_ExclGroup_ExecValidate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2677 | if (pArguments->GetLength() != 0) { |
| 2678 | ThrowParamCountMismatchException(L"execValidate"); |
| 2679 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2680 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2681 | |
| 2682 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2683 | if (!pNotify) { |
| 2684 | pArguments->GetReturnValue()->SetBoolean(false); |
| 2685 | return; |
| 2686 | } |
| 2687 | |
| 2688 | int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); |
| 2689 | pArguments->GetReturnValue()->SetBoolean( |
| 2690 | (iRet == XFA_EVENTERROR_Error) ? false : true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2691 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2692 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2693 | void CXFA_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2694 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2695 | XFA_ATTRIBUTE eAttribute) { |
| 2696 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2697 | int32_t iTo = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2698 | int32_t iFrom = Subform_and_SubformSet_InstanceIndex(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 2699 | CXFA_Node* pManagerNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2700 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; |
| 2701 | pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2702 | if (pNode->GetElementType() == XFA_Element::InstanceManager) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2703 | pManagerNode = pNode; |
| 2704 | break; |
| 2705 | } |
| 2706 | } |
| 2707 | if (pManagerNode) { |
| 2708 | pManagerNode->InstanceManager_MoveInstance(iTo, iFrom); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2709 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2710 | if (!pNotify) { |
| 2711 | return; |
| 2712 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2713 | CXFA_Node* pToInstance = GetItem(pManagerNode, iTo); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2714 | if (pToInstance && |
| 2715 | pToInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2716 | pNotify->RunSubformIndexChange(pToInstance); |
| 2717 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2718 | CXFA_Node* pFromInstance = GetItem(pManagerNode, iFrom); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 2719 | if (pFromInstance && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2720 | pFromInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2721 | pNotify->RunSubformIndexChange(pFromInstance); |
| 2722 | } |
| 2723 | } |
| 2724 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2725 | pValue->SetInteger(Subform_and_SubformSet_InstanceIndex()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2726 | } |
| 2727 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2728 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2729 | void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2730 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2731 | XFA_ATTRIBUTE eAttribute) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2732 | if (bSetting) { |
| 2733 | ThrowInvalidPropertyException(); |
| 2734 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2735 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2736 | |
| 2737 | CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name); |
| 2738 | CXFA_Node* pInstanceMgr = nullptr; |
| 2739 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; |
| 2740 | pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { |
| 2741 | if (pNode->GetElementType() == XFA_Element::InstanceManager) { |
| 2742 | CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name); |
| 2743 | if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' && |
| 2744 | wsInstMgrName.Mid(1) == wsName) { |
| 2745 | pInstanceMgr = pNode; |
| 2746 | } |
| 2747 | break; |
| 2748 | } |
| 2749 | } |
| 2750 | if (!pInstanceMgr) { |
| 2751 | pValue->SetNull(); |
| 2752 | return; |
| 2753 | } |
| 2754 | |
| 2755 | pValue->Assign( |
| 2756 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pInstanceMgr)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2757 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2758 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2759 | void CXFA_Node::Script_Subform_Locale(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2760 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2761 | XFA_ATTRIBUTE eAttribute) { |
| 2762 | if (bSetting) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2763 | SetCData(XFA_ATTRIBUTE_Locale, pValue->ToWideString(), true, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2764 | } else { |
| 2765 | CFX_WideString wsLocaleName; |
| 2766 | GetLocaleName(wsLocaleName); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 2767 | pValue->SetString(wsLocaleName.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2768 | } |
| 2769 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2770 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2771 | void CXFA_Node::Script_Subform_ExecEvent(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2772 | if (pArguments->GetLength() != 1) { |
| 2773 | ThrowParamCountMismatchException(L"execEvent"); |
| 2774 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2775 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2776 | |
| 2777 | CFX_ByteString eventString = pArguments->GetUTF8String(0); |
| 2778 | execSingleEventByName( |
| 2779 | CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(), |
| 2780 | XFA_Element::Subform); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2781 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2782 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2783 | void CXFA_Node::Script_Subform_ExecInitialize(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2784 | if (pArguments->GetLength() != 0) { |
| 2785 | ThrowParamCountMismatchException(L"execInitialize"); |
| 2786 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2787 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2788 | |
| 2789 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2790 | if (!pNotify) |
| 2791 | return; |
| 2792 | |
| 2793 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2794 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2795 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2796 | void CXFA_Node::Script_Subform_ExecCalculate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2797 | if (pArguments->GetLength() != 0) { |
| 2798 | ThrowParamCountMismatchException(L"execCalculate"); |
| 2799 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2800 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2801 | |
| 2802 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2803 | if (!pNotify) |
| 2804 | return; |
| 2805 | |
| 2806 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2807 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2808 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2809 | void CXFA_Node::Script_Subform_ExecValidate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2810 | if (pArguments->GetLength() != 0) { |
| 2811 | ThrowParamCountMismatchException(L"execValidate"); |
| 2812 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2813 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2814 | |
| 2815 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 2816 | if (!pNotify) { |
| 2817 | pArguments->GetReturnValue()->SetBoolean(false); |
| 2818 | return; |
| 2819 | } |
| 2820 | |
| 2821 | int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); |
| 2822 | pArguments->GetReturnValue()->SetBoolean( |
| 2823 | (iRet == XFA_EVENTERROR_Error) ? false : true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2824 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2825 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2826 | void CXFA_Node::Script_Subform_GetInvalidObjects(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2827 | if (pArguments->GetLength() != 0) |
| 2828 | ThrowParamCountMismatchException(L"getInvalidObjects"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2829 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2830 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2831 | int32_t CXFA_Node::Subform_and_SubformSet_InstanceIndex() { |
| 2832 | int32_t index = 0; |
| 2833 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; |
| 2834 | pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2835 | if ((pNode->GetElementType() == XFA_Element::Subform) || |
| 2836 | (pNode->GetElementType() == XFA_Element::SubformSet)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2837 | index++; |
| 2838 | } else { |
| 2839 | break; |
| 2840 | } |
| 2841 | } |
| 2842 | return index; |
| 2843 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2844 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2845 | void CXFA_Node::Script_Template_FormNodes(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2846 | if (pArguments->GetLength() != 1) { |
| 2847 | ThrowParamCountMismatchException(L"formNodes"); |
| 2848 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2849 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2850 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2851 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2852 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2853 | void CXFA_Node::Script_Template_Remerge(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2854 | if (pArguments->GetLength() != 0) { |
| 2855 | ThrowParamCountMismatchException(L"remerge"); |
| 2856 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2857 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2858 | m_pDocument->DoDataRemerge(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2859 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2860 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2861 | void CXFA_Node::Script_Template_ExecInitialize(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2862 | if (pArguments->GetLength() != 0) { |
| 2863 | ThrowParamCountMismatchException(L"execInitialize"); |
| 2864 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2865 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2866 | |
| 2867 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2868 | if (!pWidgetData) { |
| 2869 | pArguments->GetReturnValue()->SetBoolean(false); |
| 2870 | return; |
| 2871 | } |
| 2872 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2873 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2874 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2875 | void CXFA_Node::Script_Template_CreateNode(CFXJSE_Arguments* pArguments) { |
| 2876 | int32_t argc = pArguments->GetLength(); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2877 | if (argc <= 0 || argc >= 4) { |
| 2878 | ThrowParamCountMismatchException(L"createNode"); |
| 2879 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2880 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2881 | |
| 2882 | CFX_WideString strName; |
| 2883 | CFX_WideString strNameSpace; |
| 2884 | CFX_ByteString bsTagName = pArguments->GetUTF8String(0); |
| 2885 | CFX_WideString strTagName = CFX_WideString::FromUTF8(bsTagName.AsStringC()); |
| 2886 | if (argc > 1) { |
| 2887 | CFX_ByteString bsName = pArguments->GetUTF8String(1); |
| 2888 | strName = CFX_WideString::FromUTF8(bsName.AsStringC()); |
| 2889 | if (argc == 3) { |
| 2890 | CFX_ByteString bsNameSpace = pArguments->GetUTF8String(2); |
| 2891 | strNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC()); |
| 2892 | } |
| 2893 | } |
| 2894 | |
| 2895 | XFA_Element eType = XFA_GetElementTypeForName(strTagName.AsStringC()); |
| 2896 | CXFA_Node* pNewNode = CreateSamePacketNode(eType); |
| 2897 | if (!pNewNode) { |
| 2898 | pArguments->GetReturnValue()->SetNull(); |
| 2899 | return; |
| 2900 | } |
| 2901 | |
| 2902 | if (strName.IsEmpty()) { |
| 2903 | pArguments->GetReturnValue()->Assign( |
| 2904 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode)); |
| 2905 | return; |
| 2906 | } |
| 2907 | |
| 2908 | if (!GetAttributeOfElement(eType, XFA_ATTRIBUTE_Name, |
| 2909 | XFA_XDPPACKET_UNKNOWN)) { |
| 2910 | ThrowMissingPropertyException(strTagName, L"name"); |
| 2911 | return; |
| 2912 | } |
| 2913 | |
| 2914 | pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, strName.AsStringC(), true); |
| 2915 | if (pNewNode->GetPacketID() == XFA_XDPPACKET_Datasets) |
| 2916 | pNewNode->CreateXMLMappingNode(); |
| 2917 | |
| 2918 | pArguments->GetReturnValue()->Assign( |
| 2919 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2920 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2921 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2922 | void CXFA_Node::Script_Template_Recalculate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2923 | if (pArguments->GetLength() != 1) { |
| 2924 | ThrowParamCountMismatchException(L"recalculate"); |
| 2925 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2926 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2927 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2928 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2929 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2930 | void CXFA_Node::Script_Template_ExecCalculate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2931 | if (pArguments->GetLength() != 0) { |
| 2932 | ThrowParamCountMismatchException(L"execCalculate"); |
| 2933 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2934 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2935 | |
| 2936 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2937 | if (!pWidgetData) { |
| 2938 | pArguments->GetReturnValue()->SetBoolean(false); |
| 2939 | return; |
| 2940 | } |
| 2941 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2942 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2943 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2944 | void CXFA_Node::Script_Template_ExecValidate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2945 | if (pArguments->GetLength() != 0) { |
| 2946 | ThrowParamCountMismatchException(L"execValidate"); |
| 2947 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2948 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2949 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2950 | if (!pWidgetData) { |
| 2951 | pArguments->GetReturnValue()->SetBoolean(false); |
| 2952 | return; |
| 2953 | } |
| 2954 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2955 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2956 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2957 | void CXFA_Node::Script_Manifest_Evaluate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2958 | if (pArguments->GetLength() != 0) { |
| 2959 | ThrowParamCountMismatchException(L"evaluate"); |
| 2960 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2961 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2962 | |
| 2963 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2964 | if (!pWidgetData) { |
| 2965 | pArguments->GetReturnValue()->SetBoolean(false); |
| 2966 | return; |
| 2967 | } |
| 2968 | pArguments->GetReturnValue()->SetBoolean(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2969 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2970 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2971 | void CXFA_Node::Script_InstanceManager_Max(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2972 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2973 | XFA_ATTRIBUTE eAttribute) { |
| 2974 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2975 | ThrowInvalidPropertyException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2976 | return; |
| 2977 | } |
| 2978 | CXFA_Occur nodeOccur(GetOccurNode()); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2979 | pValue->SetInteger(nodeOccur.GetMax()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2980 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2981 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2982 | void CXFA_Node::Script_InstanceManager_Min(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2983 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2984 | XFA_ATTRIBUTE eAttribute) { |
| 2985 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 2986 | ThrowInvalidPropertyException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2987 | return; |
| 2988 | } |
| 2989 | CXFA_Occur nodeOccur(GetOccurNode()); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2990 | pValue->SetInteger(nodeOccur.GetMin()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2991 | } |
tsepez | aadedf9 | 2016-05-12 10:08:06 -0700 | [diff] [blame] | 2992 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2993 | void CXFA_Node::Script_InstanceManager_Count(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 2994 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2995 | XFA_ATTRIBUTE eAttribute) { |
| 2996 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2997 | int32_t iDesired = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2998 | InstanceManager_SetInstances(iDesired); |
| 2999 | } else { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3000 | pValue->SetInteger(GetCount(this)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3001 | } |
| 3002 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3003 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3004 | void CXFA_Node::Script_InstanceManager_MoveInstance( |
| 3005 | CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3006 | if (pArguments->GetLength() != 2) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3007 | pArguments->GetReturnValue()->SetUndefined(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3008 | return; |
| 3009 | } |
| 3010 | int32_t iFrom = pArguments->GetInt32(0); |
| 3011 | int32_t iTo = pArguments->GetInt32(1); |
| 3012 | InstanceManager_MoveInstance(iTo, iFrom); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3013 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3014 | if (!pNotify) { |
| 3015 | return; |
| 3016 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3017 | CXFA_Node* pToInstance = GetItem(this, iTo); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3018 | if (pToInstance && pToInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3019 | pNotify->RunSubformIndexChange(pToInstance); |
| 3020 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3021 | CXFA_Node* pFromInstance = GetItem(this, iFrom); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3022 | if (pFromInstance && |
| 3023 | pFromInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3024 | pNotify->RunSubformIndexChange(pFromInstance); |
| 3025 | } |
| 3026 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3027 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3028 | void CXFA_Node::Script_InstanceManager_RemoveInstance( |
| 3029 | CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3030 | if (pArguments->GetLength() != 1) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3031 | pArguments->GetReturnValue()->SetUndefined(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3032 | return; |
| 3033 | } |
| 3034 | int32_t iIndex = pArguments->GetInt32(0); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3035 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3036 | if (iIndex < 0 || iIndex >= iCount) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3037 | ThrowIndexOutOfBoundsException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3038 | return; |
| 3039 | } |
| 3040 | CXFA_Occur nodeOccur(GetOccurNode()); |
| 3041 | int32_t iMin = nodeOccur.GetMin(); |
| 3042 | if (iCount - 1 < iMin) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3043 | ThrowTooManyOccurancesException(L"min"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3044 | return; |
| 3045 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3046 | CXFA_Node* pRemoveInstance = GetItem(this, iIndex); |
| 3047 | RemoveItem(this, pRemoveInstance); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3048 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3049 | if (pNotify) { |
| 3050 | for (int32_t i = iIndex; i < iCount - 1; i++) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3051 | CXFA_Node* pSubformInstance = GetItem(this, i); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3052 | if (pSubformInstance && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3053 | pSubformInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3054 | pNotify->RunSubformIndexChange(pSubformInstance); |
| 3055 | } |
| 3056 | } |
| 3057 | } |
| 3058 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3059 | if (!pLayoutPro) { |
| 3060 | return; |
| 3061 | } |
| 3062 | pLayoutPro->AddChangedContainer( |
| 3063 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3064 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3065 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3066 | void CXFA_Node::Script_InstanceManager_SetInstances( |
| 3067 | CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3068 | if (pArguments->GetLength() != 1) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3069 | pArguments->GetReturnValue()->SetUndefined(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3070 | return; |
| 3071 | } |
| 3072 | int32_t iDesired = pArguments->GetInt32(0); |
| 3073 | InstanceManager_SetInstances(iDesired); |
| 3074 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3075 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3076 | void CXFA_Node::Script_InstanceManager_AddInstance( |
| 3077 | CFXJSE_Arguments* pArguments) { |
| 3078 | int32_t argc = pArguments->GetLength(); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3079 | if (argc != 0 && argc != 1) { |
| 3080 | ThrowParamCountMismatchException(L"addInstance"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3081 | return; |
| 3082 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3083 | bool fFlags = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3084 | if (argc == 1) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3085 | fFlags = pArguments->GetInt32(0) == 0 ? false : true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3086 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3087 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3088 | CXFA_Occur nodeOccur(GetOccurNode()); |
| 3089 | int32_t iMax = nodeOccur.GetMax(); |
| 3090 | if (iMax >= 0 && iCount >= iMax) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3091 | ThrowTooManyOccurancesException(L"max"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3092 | return; |
| 3093 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3094 | CXFA_Node* pNewInstance = CreateInstance(this, fFlags); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3095 | InsertItem(this, pNewInstance, iCount, iCount, false); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3096 | pArguments->GetReturnValue()->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3097 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance)); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3098 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3099 | if (!pNotify) { |
| 3100 | return; |
| 3101 | } |
| 3102 | pNotify->RunNodeInitialize(pNewInstance); |
| 3103 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3104 | if (!pLayoutPro) { |
| 3105 | return; |
| 3106 | } |
| 3107 | pLayoutPro->AddChangedContainer( |
| 3108 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3109 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3110 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3111 | void CXFA_Node::Script_InstanceManager_InsertInstance( |
| 3112 | CFXJSE_Arguments* pArguments) { |
| 3113 | int32_t argc = pArguments->GetLength(); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3114 | if (argc != 1 && argc != 2) { |
| 3115 | ThrowParamCountMismatchException(L"insertInstance"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3116 | return; |
| 3117 | } |
| 3118 | int32_t iIndex = pArguments->GetInt32(0); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3119 | bool bBind = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3120 | if (argc == 2) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3121 | bBind = pArguments->GetInt32(1) == 0 ? false : true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3122 | } |
| 3123 | CXFA_Occur nodeOccur(GetOccurNode()); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3124 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3125 | if (iIndex < 0 || iIndex > iCount) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3126 | ThrowIndexOutOfBoundsException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3127 | return; |
| 3128 | } |
| 3129 | int32_t iMax = nodeOccur.GetMax(); |
| 3130 | if (iMax >= 0 && iCount >= iMax) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3131 | ThrowTooManyOccurancesException(L"max"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3132 | return; |
| 3133 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3134 | CXFA_Node* pNewInstance = CreateInstance(this, bBind); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3135 | InsertItem(this, pNewInstance, iIndex, iCount, true); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3136 | pArguments->GetReturnValue()->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3137 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance)); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3138 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3139 | if (!pNotify) { |
| 3140 | return; |
| 3141 | } |
| 3142 | pNotify->RunNodeInitialize(pNewInstance); |
| 3143 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3144 | if (!pLayoutPro) { |
| 3145 | return; |
| 3146 | } |
| 3147 | pLayoutPro->AddChangedContainer( |
| 3148 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3149 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3150 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3151 | int32_t CXFA_Node::InstanceManager_SetInstances(int32_t iDesired) { |
| 3152 | CXFA_Occur nodeOccur(GetOccurNode()); |
| 3153 | int32_t iMax = nodeOccur.GetMax(); |
| 3154 | int32_t iMin = nodeOccur.GetMin(); |
| 3155 | if (iDesired < iMin) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3156 | ThrowTooManyOccurancesException(L"min"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3157 | return 1; |
| 3158 | } |
| 3159 | if ((iMax >= 0) && (iDesired > iMax)) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3160 | ThrowTooManyOccurancesException(L"max"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3161 | return 2; |
| 3162 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3163 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3164 | if (iDesired == iCount) { |
| 3165 | return 0; |
| 3166 | } |
| 3167 | if (iDesired < iCount) { |
| 3168 | CFX_WideStringC wsInstManagerName = GetCData(XFA_ATTRIBUTE_Name); |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3169 | CFX_WideString wsInstanceName = |
| 3170 | CFX_WideString(wsInstManagerName.IsEmpty() ? wsInstManagerName |
| 3171 | : wsInstManagerName.Mid(1)); |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 3172 | uint32_t dInstanceNameHash = |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 3173 | FX_HashCode_GetW(wsInstanceName.AsStringC(), false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3174 | CXFA_Node* pPrevSibling = |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3175 | (iDesired == 0) ? this : GetItem(this, iDesired - 1); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3176 | while (iCount > iDesired) { |
| 3177 | CXFA_Node* pRemoveInstance = |
| 3178 | pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3179 | if (pRemoveInstance->GetElementType() != XFA_Element::Subform && |
| 3180 | pRemoveInstance->GetElementType() != XFA_Element::SubformSet) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3181 | continue; |
| 3182 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3183 | if (pRemoveInstance->GetElementType() == XFA_Element::InstanceManager) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3184 | ASSERT(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3185 | break; |
| 3186 | } |
| 3187 | if (pRemoveInstance->GetNameHash() == dInstanceNameHash) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3188 | RemoveItem(this, pRemoveInstance); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3189 | iCount--; |
| 3190 | } |
| 3191 | } |
| 3192 | } else if (iDesired > iCount) { |
| 3193 | while (iCount < iDesired) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3194 | CXFA_Node* pNewInstance = CreateInstance(this, true); |
| 3195 | InsertItem(this, pNewInstance, iCount, iCount, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3196 | iCount++; |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3197 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3198 | if (!pNotify) { |
| 3199 | return 0; |
| 3200 | } |
| 3201 | pNotify->RunNodeInitialize(pNewInstance); |
| 3202 | } |
| 3203 | } |
| 3204 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3205 | if (pLayoutPro) { |
| 3206 | pLayoutPro->AddChangedContainer( |
| 3207 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3208 | } |
| 3209 | return 0; |
| 3210 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3211 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3212 | int32_t CXFA_Node::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3213 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3214 | if (iFrom > iCount || iTo > iCount - 1) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3215 | ThrowIndexOutOfBoundsException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3216 | return 1; |
| 3217 | } |
| 3218 | if (iFrom < 0 || iTo < 0 || iFrom == iTo) { |
| 3219 | return 0; |
| 3220 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3221 | CXFA_Node* pMoveInstance = GetItem(this, iFrom); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3222 | RemoveItem(this, pMoveInstance, false); |
| 3223 | InsertItem(this, pMoveInstance, iTo, iCount - 1, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3224 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3225 | if (pLayoutPro) { |
| 3226 | pLayoutPro->AddChangedContainer( |
| 3227 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3228 | } |
| 3229 | return 0; |
| 3230 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3231 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3232 | void CXFA_Node::Script_Occur_Max(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3233 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3234 | XFA_ATTRIBUTE eAttribute) { |
| 3235 | CXFA_Occur occur(this); |
| 3236 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3237 | int32_t iMax = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3238 | occur.SetMax(iMax); |
| 3239 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3240 | pValue->SetInteger(occur.GetMax()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3241 | } |
| 3242 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3243 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3244 | void CXFA_Node::Script_Occur_Min(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3245 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3246 | XFA_ATTRIBUTE eAttribute) { |
| 3247 | CXFA_Occur occur(this); |
| 3248 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3249 | int32_t iMin = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3250 | occur.SetMin(iMin); |
| 3251 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3252 | pValue->SetInteger(occur.GetMin()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3253 | } |
| 3254 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3255 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3256 | void CXFA_Node::Script_Desc_Metadata(CFXJSE_Arguments* pArguments) { |
| 3257 | int32_t argc = pArguments->GetLength(); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3258 | if (argc != 0 && argc != 1) { |
| 3259 | ThrowParamCountMismatchException(L"metadata"); |
| 3260 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3261 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3262 | pArguments->GetReturnValue()->SetString(""); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3263 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3264 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3265 | void CXFA_Node::Script_Form_FormNodes(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3266 | if (pArguments->GetLength() != 1) { |
| 3267 | ThrowParamCountMismatchException(L"formNodes"); |
| 3268 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3269 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3270 | |
| 3271 | CXFA_Node* pDataNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); |
| 3272 | if (!pDataNode) { |
| 3273 | ThrowArgumentMismatchException(); |
| 3274 | return; |
| 3275 | } |
| 3276 | |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 3277 | std::vector<CXFA_Node*> formItems; |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3278 | CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument); |
| 3279 | pFormNodes->SetArrayNodeList(formItems); |
| 3280 | pArguments->GetReturnValue()->SetObject( |
| 3281 | pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3282 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3283 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3284 | void CXFA_Node::Script_Form_Remerge(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3285 | if (pArguments->GetLength() != 0) { |
| 3286 | ThrowParamCountMismatchException(L"remerge"); |
| 3287 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3288 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3289 | |
| 3290 | m_pDocument->DoDataRemerge(true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3291 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3292 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3293 | void CXFA_Node::Script_Form_ExecInitialize(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3294 | if (pArguments->GetLength() != 0) { |
| 3295 | ThrowParamCountMismatchException(L"execInitialize"); |
| 3296 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3297 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3298 | |
| 3299 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 3300 | if (!pNotify) |
| 3301 | return; |
| 3302 | |
| 3303 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3304 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3305 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3306 | void CXFA_Node::Script_Form_Recalculate(CFXJSE_Arguments* pArguments) { |
| 3307 | CXFA_EventParam* pEventParam = |
| 3308 | m_pDocument->GetScriptContext()->GetEventParam(); |
| 3309 | if (pEventParam->m_eType == XFA_EVENT_Calculate || |
| 3310 | pEventParam->m_eType == XFA_EVENT_InitCalculate) { |
| 3311 | return; |
| 3312 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3313 | if (pArguments->GetLength() != 1) { |
| 3314 | ThrowParamCountMismatchException(L"recalculate"); |
| 3315 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3316 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3317 | |
| 3318 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 3319 | if (!pNotify) |
| 3320 | return; |
| 3321 | if (pArguments->GetInt32(0) != 0) |
| 3322 | return; |
| 3323 | |
| 3324 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); |
| 3325 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); |
| 3326 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Ready, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3327 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3328 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3329 | void CXFA_Node::Script_Form_ExecCalculate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3330 | if (pArguments->GetLength() != 0) { |
| 3331 | ThrowParamCountMismatchException(L"execCalculate"); |
| 3332 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3333 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3334 | |
| 3335 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 3336 | if (!pNotify) |
| 3337 | return; |
| 3338 | |
| 3339 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3340 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3341 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3342 | void CXFA_Node::Script_Form_ExecValidate(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3343 | if (pArguments->GetLength() != 0) { |
| 3344 | ThrowParamCountMismatchException(L"execValidate"); |
| 3345 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3346 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3347 | |
| 3348 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
| 3349 | if (!pNotify) { |
| 3350 | pArguments->GetReturnValue()->SetBoolean(false); |
| 3351 | return; |
| 3352 | } |
| 3353 | |
| 3354 | int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); |
| 3355 | pArguments->GetReturnValue()->SetBoolean( |
| 3356 | (iRet == XFA_EVENTERROR_Error) ? false : true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3357 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3358 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3359 | void CXFA_Node::Script_Form_Checksum(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3360 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3361 | XFA_ATTRIBUTE eAttribute) { |
| 3362 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 3363 | SetAttribute(XFA_ATTRIBUTE_Checksum, pValue->ToWideString().AsStringC()); |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3364 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3365 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3366 | CFX_WideString wsChecksum; |
| 3367 | GetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum, false); |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 3368 | pValue->SetString(wsChecksum.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3369 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3370 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3371 | void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3372 | if (pArguments->GetLength() != 1) { |
| 3373 | ThrowParamCountMismatchException(L"getAttribute"); |
| 3374 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3375 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3376 | CFX_ByteString bsAttributeName = pArguments->GetUTF8String(0); |
| 3377 | CFX_WideString wsAttributeValue; |
| 3378 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
| 3379 | if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { |
| 3380 | static_cast<CFDE_XMLElement*>(pXMLNode)->GetString( |
| 3381 | CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str(), |
| 3382 | wsAttributeValue); |
| 3383 | } |
| 3384 | pArguments->GetReturnValue()->SetString( |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 3385 | wsAttributeValue.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3386 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3387 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3388 | void CXFA_Node::Script_Packet_SetAttribute(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3389 | if (pArguments->GetLength() != 2) { |
| 3390 | ThrowParamCountMismatchException(L"setAttribute"); |
| 3391 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3392 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3393 | CFX_ByteString bsValue = pArguments->GetUTF8String(0); |
| 3394 | CFX_ByteString bsName = pArguments->GetUTF8String(1); |
| 3395 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
| 3396 | if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { |
| 3397 | static_cast<CFDE_XMLElement*>(pXMLNode)->SetString( |
| 3398 | CFX_WideString::FromUTF8(bsName.AsStringC()), |
| 3399 | CFX_WideString::FromUTF8(bsValue.AsStringC())); |
| 3400 | } |
| 3401 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3402 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3403 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3404 | void CXFA_Node::Script_Packet_RemoveAttribute(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3405 | if (pArguments->GetLength() != 1) { |
| 3406 | ThrowParamCountMismatchException(L"removeAttribute"); |
| 3407 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3408 | } |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3409 | |
| 3410 | CFX_ByteString bsName = pArguments->GetUTF8String(0); |
| 3411 | CFX_WideString wsName = CFX_WideString::FromUTF8(bsName.AsStringC()); |
| 3412 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
| 3413 | if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { |
| 3414 | CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); |
| 3415 | if (pXMLElement->HasAttribute(wsName.c_str())) { |
| 3416 | pXMLElement->RemoveAttribute(wsName.c_str()); |
| 3417 | } |
| 3418 | } |
| 3419 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3420 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3421 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3422 | void CXFA_Node::Script_Packet_Content(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3423 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3424 | XFA_ATTRIBUTE eAttribute) { |
| 3425 | if (bSetting) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3426 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3427 | if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3428 | CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 3429 | pXMLElement->SetTextData(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3430 | } |
| 3431 | } else { |
| 3432 | CFX_WideString wsTextData; |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3433 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3434 | if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3435 | CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3436 | pXMLElement->GetTextData(wsTextData); |
| 3437 | } |
Tom Sepez | f0b6554 | 2017-02-13 10:26:01 -0800 | [diff] [blame] | 3438 | pValue->SetString(wsTextData.UTF8Encode().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3439 | } |
| 3440 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3441 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3442 | void CXFA_Node::Script_Source_Next(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3443 | if (pArguments->GetLength() != 0) |
| 3444 | ThrowParamCountMismatchException(L"next"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3445 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3446 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3447 | void CXFA_Node::Script_Source_CancelBatch(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3448 | if (pArguments->GetLength() != 0) |
| 3449 | ThrowParamCountMismatchException(L"cancelBatch"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3450 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3451 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3452 | void CXFA_Node::Script_Source_First(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3453 | if (pArguments->GetLength() != 0) |
| 3454 | ThrowParamCountMismatchException(L"first"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3455 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3456 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3457 | void CXFA_Node::Script_Source_UpdateBatch(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3458 | if (pArguments->GetLength() != 0) |
| 3459 | ThrowParamCountMismatchException(L"updateBatch"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3460 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3461 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3462 | void CXFA_Node::Script_Source_Previous(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3463 | if (pArguments->GetLength() != 0) |
| 3464 | ThrowParamCountMismatchException(L"previous"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3465 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3466 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3467 | void CXFA_Node::Script_Source_IsBOF(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3468 | if (pArguments->GetLength() != 0) |
| 3469 | ThrowParamCountMismatchException(L"isBOF"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3470 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3471 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3472 | void CXFA_Node::Script_Source_IsEOF(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3473 | if (pArguments->GetLength() != 0) |
| 3474 | ThrowParamCountMismatchException(L"isEOF"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3475 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3476 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3477 | void CXFA_Node::Script_Source_Cancel(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3478 | if (pArguments->GetLength() != 0) |
| 3479 | ThrowParamCountMismatchException(L"cancel"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3480 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3481 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3482 | void CXFA_Node::Script_Source_Update(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3483 | if (pArguments->GetLength() != 0) |
| 3484 | ThrowParamCountMismatchException(L"update"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3485 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3486 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3487 | void CXFA_Node::Script_Source_Open(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3488 | if (pArguments->GetLength() != 0) |
| 3489 | ThrowParamCountMismatchException(L"open"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3490 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3491 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3492 | void CXFA_Node::Script_Source_Delete(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3493 | if (pArguments->GetLength() != 0) |
| 3494 | ThrowParamCountMismatchException(L"delete"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3495 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3496 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3497 | void CXFA_Node::Script_Source_AddNew(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3498 | if (pArguments->GetLength() != 0) |
| 3499 | ThrowParamCountMismatchException(L"addNew"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3500 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3501 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3502 | void CXFA_Node::Script_Source_Requery(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3503 | if (pArguments->GetLength() != 0) |
| 3504 | ThrowParamCountMismatchException(L"requery"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3505 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3506 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3507 | void CXFA_Node::Script_Source_Resync(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3508 | if (pArguments->GetLength() != 0) |
| 3509 | ThrowParamCountMismatchException(L"resync"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3510 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3511 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3512 | void CXFA_Node::Script_Source_Close(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3513 | if (pArguments->GetLength() != 0) |
| 3514 | ThrowParamCountMismatchException(L"close"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3515 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3516 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3517 | void CXFA_Node::Script_Source_Last(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3518 | if (pArguments->GetLength() != 0) |
| 3519 | ThrowParamCountMismatchException(L"last"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3520 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3521 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3522 | void CXFA_Node::Script_Source_HasDataChanged(CFXJSE_Arguments* pArguments) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3523 | if (pArguments->GetLength() != 0) |
| 3524 | ThrowParamCountMismatchException(L"hasDataChanged"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3525 | } |
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_Source_Db(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) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3530 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3531 | void CXFA_Node::Script_Xfa_This(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3532 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3533 | XFA_ATTRIBUTE eAttribute) { |
| 3534 | if (!bSetting) { |
| 3535 | CXFA_Object* pThis = m_pDocument->GetScriptContext()->GetThisObject(); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 3536 | ASSERT(pThis); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3537 | pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pThis)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3538 | } |
| 3539 | } |
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_Handler_Version(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_SubmitFormat_Mode(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_Extras_Type(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) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3552 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3553 | void CXFA_Node::Script_Script_Stateless(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3554 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3555 | XFA_ATTRIBUTE eAttribute) { |
| 3556 | if (bSetting) { |
Dan Sinclair | 3cdcfeb | 2017-01-03 15:45:10 -0500 | [diff] [blame] | 3557 | ThrowInvalidPropertyException(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3558 | return; |
| 3559 | } |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 3560 | pValue->SetString(FX_UTF8Encode(CFX_WideStringC(L"0", 1)).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3561 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3562 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3563 | void CXFA_Node::Script_Encrypt_Format(CFXJSE_Value* pValue, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3564 | bool bSetting, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3565 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3566 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3567 | bool CXFA_Node::HasAttribute(XFA_ATTRIBUTE eAttr, bool bCanInherit) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3568 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3569 | return HasMapModuleKey(pKey, bCanInherit); |
| 3570 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3571 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3572 | bool CXFA_Node::SetAttribute(XFA_ATTRIBUTE eAttr, |
| 3573 | const CFX_WideStringC& wsValue, |
| 3574 | bool bNotify) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3575 | const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3576 | if (!pAttr) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3577 | return false; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3578 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3579 | XFA_ATTRIBUTETYPE eType = pAttr->eType; |
| 3580 | if (eType == XFA_ATTRIBUTETYPE_NOTSURE) { |
| 3581 | const XFA_NOTSUREATTRIBUTE* pNotsure = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3582 | XFA_GetNotsureAttribute(GetElementType(), pAttr->eName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3583 | eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata; |
| 3584 | } |
| 3585 | switch (eType) { |
| 3586 | case XFA_ATTRIBUTETYPE_Enum: { |
| 3587 | const XFA_ATTRIBUTEENUMINFO* pEnum = XFA_GetAttributeEnumByName(wsValue); |
| 3588 | return SetEnum(pAttr->eName, |
| 3589 | pEnum ? pEnum->eName |
| 3590 | : (XFA_ATTRIBUTEENUM)(intptr_t)(pAttr->pDefValue), |
| 3591 | bNotify); |
| 3592 | } break; |
| 3593 | case XFA_ATTRIBUTETYPE_Cdata: |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3594 | return SetCData(pAttr->eName, CFX_WideString(wsValue), bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3595 | case XFA_ATTRIBUTETYPE_Boolean: |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 3596 | return SetBoolean(pAttr->eName, wsValue != L"0", bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3597 | case XFA_ATTRIBUTETYPE_Integer: |
dsinclair | e0347a6 | 2016-08-11 11:24:11 -0700 | [diff] [blame] | 3598 | return SetInteger(pAttr->eName, |
| 3599 | FXSYS_round(FXSYS_wcstof(wsValue.c_str(), |
| 3600 | wsValue.GetLength(), nullptr)), |
| 3601 | bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3602 | case XFA_ATTRIBUTETYPE_Measure: |
| 3603 | return SetMeasure(pAttr->eName, CXFA_Measurement(wsValue), bNotify); |
| 3604 | default: |
| 3605 | break; |
| 3606 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3607 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3608 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3609 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3610 | bool CXFA_Node::GetAttribute(XFA_ATTRIBUTE eAttr, |
| 3611 | CFX_WideString& wsValue, |
| 3612 | bool bUseDefault) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3613 | const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3614 | if (!pAttr) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3615 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3616 | } |
| 3617 | XFA_ATTRIBUTETYPE eType = pAttr->eType; |
| 3618 | if (eType == XFA_ATTRIBUTETYPE_NOTSURE) { |
| 3619 | const XFA_NOTSUREATTRIBUTE* pNotsure = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3620 | XFA_GetNotsureAttribute(GetElementType(), pAttr->eName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3621 | eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata; |
| 3622 | } |
| 3623 | switch (eType) { |
| 3624 | case XFA_ATTRIBUTETYPE_Enum: { |
| 3625 | XFA_ATTRIBUTEENUM eValue; |
| 3626 | if (!TryEnum(pAttr->eName, eValue, bUseDefault)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3627 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3628 | } |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 3629 | wsValue = GetAttributeEnumByID(eValue)->pName; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3630 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3631 | } break; |
| 3632 | case XFA_ATTRIBUTETYPE_Cdata: { |
| 3633 | CFX_WideStringC wsValueC; |
| 3634 | if (!TryCData(pAttr->eName, wsValueC, bUseDefault)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3635 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3636 | } |
| 3637 | wsValue = wsValueC; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3638 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3639 | } break; |
| 3640 | case XFA_ATTRIBUTETYPE_Boolean: { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3641 | bool bValue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3642 | if (!TryBoolean(pAttr->eName, bValue, bUseDefault)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3643 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3644 | } |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 3645 | wsValue = bValue ? L"1" : L"0"; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3646 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3647 | } break; |
| 3648 | case XFA_ATTRIBUTETYPE_Integer: { |
| 3649 | int32_t iValue; |
| 3650 | if (!TryInteger(pAttr->eName, iValue, bUseDefault)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3651 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3652 | } |
| 3653 | wsValue.Format(L"%d", iValue); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3654 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3655 | } break; |
| 3656 | case XFA_ATTRIBUTETYPE_Measure: { |
| 3657 | CXFA_Measurement mValue; |
| 3658 | if (!TryMeasure(pAttr->eName, mValue, bUseDefault)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3659 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3660 | } |
| 3661 | mValue.ToString(wsValue); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3662 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3663 | } break; |
| 3664 | default: |
| 3665 | break; |
| 3666 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3667 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3668 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3669 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3670 | bool CXFA_Node::SetAttribute(const CFX_WideStringC& wsAttr, |
| 3671 | const CFX_WideStringC& wsValue, |
| 3672 | bool bNotify) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3673 | const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsValue); |
| 3674 | if (pAttributeInfo) { |
| 3675 | return SetAttribute(pAttributeInfo->eName, wsValue, bNotify); |
| 3676 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3677 | void* pKey = GetMapKey_Custom(wsAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3678 | SetMapModuleString(pKey, wsValue); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3679 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3680 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3681 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3682 | bool CXFA_Node::GetAttribute(const CFX_WideStringC& wsAttr, |
| 3683 | CFX_WideString& wsValue, |
| 3684 | bool bUseDefault) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3685 | const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsAttr); |
| 3686 | if (pAttributeInfo) { |
| 3687 | return GetAttribute(pAttributeInfo->eName, wsValue, bUseDefault); |
| 3688 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3689 | void* pKey = GetMapKey_Custom(wsAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3690 | CFX_WideStringC wsValueC; |
| 3691 | if (GetMapModuleString(pKey, wsValueC)) { |
| 3692 | wsValue = wsValueC; |
| 3693 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3694 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3695 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3696 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3697 | bool CXFA_Node::RemoveAttribute(const CFX_WideStringC& wsAttr) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3698 | void* pKey = GetMapKey_Custom(wsAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3699 | RemoveMapModuleKey(pKey); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3700 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3701 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3702 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3703 | bool CXFA_Node::TryBoolean(XFA_ATTRIBUTE eAttr, |
| 3704 | bool& bValue, |
| 3705 | bool bUseDefault) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3706 | void* pValue = nullptr; |
| 3707 | if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Boolean, bUseDefault, pValue)) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3708 | return false; |
tsepez | 478ed62 | 2016-10-27 14:32:33 -0700 | [diff] [blame] | 3709 | bValue = !!pValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3710 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3711 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3712 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3713 | bool CXFA_Node::TryInteger(XFA_ATTRIBUTE eAttr, |
| 3714 | int32_t& iValue, |
| 3715 | bool bUseDefault) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3716 | void* pValue = nullptr; |
| 3717 | if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Integer, bUseDefault, pValue)) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3718 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3719 | iValue = (int32_t)(uintptr_t)pValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3720 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3721 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3722 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3723 | bool CXFA_Node::TryEnum(XFA_ATTRIBUTE eAttr, |
| 3724 | XFA_ATTRIBUTEENUM& eValue, |
| 3725 | bool bUseDefault) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3726 | void* pValue = nullptr; |
| 3727 | if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Enum, bUseDefault, pValue)) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3728 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3729 | eValue = (XFA_ATTRIBUTEENUM)(uintptr_t)pValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3730 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3731 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3732 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3733 | bool CXFA_Node::SetMeasure(XFA_ATTRIBUTE eAttr, |
| 3734 | CXFA_Measurement mValue, |
| 3735 | bool bNotify) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3736 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3737 | OnChanging(eAttr, bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3738 | SetMapModuleBuffer(pKey, &mValue, sizeof(CXFA_Measurement)); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3739 | OnChanged(eAttr, bNotify, false); |
| 3740 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3741 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3742 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3743 | bool CXFA_Node::TryMeasure(XFA_ATTRIBUTE eAttr, |
| 3744 | CXFA_Measurement& mValue, |
| 3745 | bool bUseDefault) const { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3746 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3747 | void* pValue; |
| 3748 | int32_t iBytes; |
| 3749 | if (GetMapModuleBuffer(pKey, pValue, iBytes) && iBytes == sizeof(mValue)) { |
Dan Sinclair | 1c5d0b4 | 2017-04-03 15:05:11 -0400 | [diff] [blame] | 3750 | memcpy(&mValue, pValue, sizeof(mValue)); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3751 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3752 | } |
| 3753 | if (bUseDefault && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3754 | XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3755 | XFA_ATTRIBUTETYPE_Measure, m_ePacket)) { |
Dan Sinclair | 1c5d0b4 | 2017-04-03 15:05:11 -0400 | [diff] [blame] | 3756 | memcpy(&mValue, pValue, sizeof(mValue)); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3757 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3758 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3759 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3760 | } |
| 3761 | |
| 3762 | CXFA_Measurement CXFA_Node::GetMeasure(XFA_ATTRIBUTE eAttr) const { |
| 3763 | CXFA_Measurement mValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3764 | return TryMeasure(eAttr, mValue, true) ? mValue : CXFA_Measurement(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3765 | } |
| 3766 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3767 | bool CXFA_Node::SetCData(XFA_ATTRIBUTE eAttr, |
| 3768 | const CFX_WideString& wsValue, |
| 3769 | bool bNotify, |
| 3770 | bool bScriptModify) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3771 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3772 | OnChanging(eAttr, bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3773 | if (eAttr == XFA_ATTRIBUTE_Value) { |
| 3774 | CFX_WideString* pClone = new CFX_WideString(wsValue); |
| 3775 | SetUserData(pKey, pClone, &deleteWideStringCallBack); |
| 3776 | } else { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 3777 | SetMapModuleString(pKey, wsValue.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3778 | if (eAttr == XFA_ATTRIBUTE_Name) |
| 3779 | UpdateNameHash(); |
| 3780 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3781 | OnChanged(eAttr, bNotify, bScriptModify); |
| 3782 | |
| 3783 | if (!IsNeedSavingXMLNode() || eAttr == XFA_ATTRIBUTE_QualifiedName || |
| 3784 | eAttr == XFA_ATTRIBUTE_BindingNode) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3785 | return true; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3786 | } |
| 3787 | |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3788 | if (eAttr == XFA_ATTRIBUTE_Name && |
| 3789 | (m_elementType == XFA_Element::DataValue || |
| 3790 | m_elementType == XFA_Element::DataGroup)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3791 | return true; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3792 | } |
| 3793 | |
| 3794 | if (eAttr == XFA_ATTRIBUTE_Value) { |
| 3795 | FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType(); |
| 3796 | switch (eXMLType) { |
| 3797 | case FDE_XMLNODE_Element: |
| 3798 | if (IsAttributeInXML()) { |
| 3799 | static_cast<CFDE_XMLElement*>(m_pXMLNode) |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3800 | ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)), |
| 3801 | wsValue); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3802 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3803 | bool bDeleteChildren = true; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3804 | if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 3805 | for (CXFA_Node* pChildDataNode = |
| 3806 | GetNodeItem(XFA_NODEITEM_FirstChild); |
| 3807 | pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem( |
| 3808 | XFA_NODEITEM_NextSibling)) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 3809 | if (!pChildDataNode->GetBindItems().empty()) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3810 | bDeleteChildren = false; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3811 | break; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3812 | } |
| 3813 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3814 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3815 | if (bDeleteChildren) { |
| 3816 | static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren(); |
| 3817 | } |
| 3818 | static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsValue); |
| 3819 | } |
| 3820 | break; |
| 3821 | case FDE_XMLNODE_Text: |
| 3822 | static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsValue); |
| 3823 | break; |
| 3824 | default: |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 3825 | ASSERT(0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3826 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3827 | return true; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3828 | } |
| 3829 | |
| 3830 | const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr); |
| 3831 | if (pInfo) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 3832 | ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3833 | CFX_WideString wsAttrName = pInfo->pName; |
| 3834 | if (pInfo->eName == XFA_ATTRIBUTE_ContentType) { |
dan sinclair | 65c7c23 | 2017-02-02 14:05:30 -0800 | [diff] [blame] | 3835 | wsAttrName = L"xfa:" + wsAttrName; |
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 | static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetString(wsAttrName, wsValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3838 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3839 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3840 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3841 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3842 | bool CXFA_Node::SetAttributeValue(const CFX_WideString& wsValue, |
| 3843 | const CFX_WideString& wsXMLValue, |
| 3844 | bool bNotify, |
| 3845 | bool bScriptModify) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3846 | void* pKey = GetMapKey_Element(GetElementType(), XFA_ATTRIBUTE_Value); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3847 | OnChanging(XFA_ATTRIBUTE_Value, bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3848 | CFX_WideString* pClone = new CFX_WideString(wsValue); |
| 3849 | SetUserData(pKey, pClone, &deleteWideStringCallBack); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3850 | OnChanged(XFA_ATTRIBUTE_Value, bNotify, bScriptModify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3851 | if (IsNeedSavingXMLNode()) { |
| 3852 | FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType(); |
| 3853 | switch (eXMLType) { |
| 3854 | case FDE_XMLNODE_Element: |
| 3855 | if (IsAttributeInXML()) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3856 | static_cast<CFDE_XMLElement*>(m_pXMLNode) |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3857 | ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)), |
| 3858 | wsXMLValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3859 | } else { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3860 | bool bDeleteChildren = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3861 | if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 3862 | for (CXFA_Node* pChildDataNode = |
| 3863 | GetNodeItem(XFA_NODEITEM_FirstChild); |
| 3864 | pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem( |
| 3865 | XFA_NODEITEM_NextSibling)) { |
Tom Sepez | f8a9439 | 2017-03-14 12:13:22 -0700 | [diff] [blame] | 3866 | if (!pChildDataNode->GetBindItems().empty()) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3867 | bDeleteChildren = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3868 | break; |
| 3869 | } |
| 3870 | } |
| 3871 | } |
| 3872 | if (bDeleteChildren) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3873 | static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3874 | } |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3875 | static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsXMLValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3876 | } |
| 3877 | break; |
| 3878 | case FDE_XMLNODE_Text: |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3879 | static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsXMLValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3880 | break; |
| 3881 | default: |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 3882 | ASSERT(0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3883 | } |
| 3884 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3885 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3886 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3887 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3888 | bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr, |
| 3889 | CFX_WideString& wsValue, |
| 3890 | bool bUseDefault, |
| 3891 | bool bProto) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3892 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3893 | if (eAttr == XFA_ATTRIBUTE_Value) { |
| 3894 | CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto); |
| 3895 | if (pStr) { |
| 3896 | wsValue = *pStr; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3897 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3898 | } |
| 3899 | } else { |
| 3900 | CFX_WideStringC wsValueC; |
| 3901 | if (GetMapModuleString(pKey, wsValueC)) { |
| 3902 | wsValue = wsValueC; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3903 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3904 | } |
| 3905 | } |
| 3906 | if (!bUseDefault) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3907 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3908 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3909 | void* pValue = nullptr; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3910 | if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3911 | XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) { |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 3912 | wsValue = (const wchar_t*)pValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3913 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3914 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3915 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3916 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3917 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3918 | bool CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr, |
| 3919 | CFX_WideStringC& wsValue, |
| 3920 | bool bUseDefault, |
| 3921 | bool bProto) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3922 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3923 | if (eAttr == XFA_ATTRIBUTE_Value) { |
| 3924 | CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto); |
| 3925 | if (pStr) { |
tsepez | 4d31d0c | 2016-04-19 14:11:59 -0700 | [diff] [blame] | 3926 | wsValue = pStr->AsStringC(); |
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 | } else { |
| 3930 | if (GetMapModuleString(pKey, wsValue)) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3931 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3932 | } |
| 3933 | } |
| 3934 | if (!bUseDefault) { |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3935 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3936 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3937 | void* pValue = nullptr; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3938 | if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3939 | XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) { |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 3940 | wsValue = (CFX_WideStringC)(const wchar_t*)pValue; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3941 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3942 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3943 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3944 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3945 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3946 | bool CXFA_Node::SetObject(XFA_ATTRIBUTE eAttr, |
| 3947 | void* pData, |
| 3948 | XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3949 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3950 | return SetUserData(pKey, pData, pCallbackInfo); |
| 3951 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3952 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3953 | bool CXFA_Node::TryObject(XFA_ATTRIBUTE eAttr, void*& pData) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3954 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3955 | pData = GetUserData(pKey); |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 3956 | return !!pData; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3957 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3958 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3959 | bool CXFA_Node::SetValue(XFA_ATTRIBUTE eAttr, |
| 3960 | XFA_ATTRIBUTETYPE eType, |
| 3961 | void* pValue, |
| 3962 | bool bNotify) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3963 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3964 | OnChanging(eAttr, bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3965 | SetMapModuleValue(pKey, pValue); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 3966 | OnChanged(eAttr, bNotify, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3967 | if (IsNeedSavingXMLNode()) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 3968 | ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3969 | const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr); |
| 3970 | if (pInfo) { |
| 3971 | switch (eType) { |
| 3972 | case XFA_ATTRIBUTETYPE_Enum: |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3973 | static_cast<CFDE_XMLElement*>(m_pXMLNode) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3974 | ->SetString( |
| 3975 | pInfo->pName, |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 3976 | GetAttributeEnumByID((XFA_ATTRIBUTEENUM)(uintptr_t)pValue) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3977 | ->pName); |
| 3978 | break; |
| 3979 | case XFA_ATTRIBUTETYPE_Boolean: |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3980 | static_cast<CFDE_XMLElement*>(m_pXMLNode) |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3981 | ->SetString(pInfo->pName, pValue ? L"1" : L"0"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3982 | break; |
| 3983 | case XFA_ATTRIBUTETYPE_Integer: |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3984 | static_cast<CFDE_XMLElement*>(m_pXMLNode) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3985 | ->SetInteger(pInfo->pName, (int32_t)(uintptr_t)pValue); |
| 3986 | break; |
| 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 | } |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4306 | static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace); |
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), |
| 4320 | GetCData(XFA_ATTRIBUTE_QualifiedName), wsNamespace); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4321 | } |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4322 | static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace); |
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 | } |