dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1 | // Copyright 2016 PDFium Authors. All rights reserved. |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
| 7 | #include "xfa/fxfa/parser/xfa_object.h" |
| 8 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 9 | #include <map> |
tsepez | aadedf9 | 2016-05-12 10:08:06 -0700 | [diff] [blame] | 10 | #include <memory> |
| 11 | |
dsinclair | a52ab74 | 2016-09-29 13:59:29 -0700 | [diff] [blame] | 12 | #include "core/fxcrt/fx_ext.h" |
dsinclair | 4355468 | 2016-09-29 17:29:48 -0700 | [diff] [blame^] | 13 | #include "fxjs/cfxjse_value.h" |
tsepez | aadedf9 | 2016-05-12 10:08:06 -0700 | [diff] [blame] | 14 | #include "third_party/base/stl_util.h" |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 15 | #include "xfa/fde/xml/fde_xml_imp.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 16 | #include "xfa/fgas/crt/fgas_codepage.h" |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 17 | #include "xfa/fxfa/app/xfa_ffnotify.h" |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 18 | #include "xfa/fxfa/include/cxfa_eventparam.h" |
dsinclair | 1628024 | 2016-07-21 12:03:47 -0700 | [diff] [blame] | 19 | #include "xfa/fxfa/parser/cxfa_document.h" |
dsinclair | 0b851ff | 2016-07-21 12:03:01 -0700 | [diff] [blame] | 20 | #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 21 | #include "xfa/fxfa/parser/cxfa_measurement.h" |
dsinclair | 44d054c | 2016-04-06 10:23:46 -0700 | [diff] [blame] | 22 | #include "xfa/fxfa/parser/cxfa_occur.h" |
dsinclair | 31f8740 | 2016-07-20 06:34:45 -0700 | [diff] [blame] | 23 | #include "xfa/fxfa/parser/cxfa_scriptcontext.h" |
dsinclair | 34f86b0 | 2016-07-11 08:42:33 -0700 | [diff] [blame] | 24 | #include "xfa/fxfa/parser/cxfa_simple_parser.h" |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 25 | #include "xfa/fxfa/parser/xfa_basic_data.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 26 | |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 27 | namespace { |
| 28 | |
| 29 | void XFA_DeleteWideString(void* pData) { |
| 30 | delete static_cast<CFX_WideString*>(pData); |
| 31 | } |
| 32 | |
| 33 | void XFA_CopyWideString(void*& pData) { |
| 34 | if (pData) { |
| 35 | CFX_WideString* pNewData = new CFX_WideString(*(CFX_WideString*)pData); |
| 36 | pData = pNewData; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | XFA_MAPDATABLOCKCALLBACKINFO deleteWideStringCallBack = {XFA_DeleteWideString, |
| 41 | XFA_CopyWideString}; |
| 42 | |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 43 | void XFA_DataNodeDeleteBindItem(void* pData) { |
| 44 | delete static_cast<CXFA_NodeArray*>(pData); |
| 45 | } |
| 46 | |
| 47 | XFA_MAPDATABLOCKCALLBACKINFO deleteBindItemCallBack = { |
| 48 | XFA_DataNodeDeleteBindItem, nullptr}; |
| 49 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 50 | int32_t GetCount(CXFA_Node* pInstMgrNode) { |
| 51 | ASSERT(pInstMgrNode); |
| 52 | int32_t iCount = 0; |
| 53 | uint32_t dwNameHash = 0; |
| 54 | for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 55 | pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 56 | XFA_Element eCurType = pNode->GetElementType(); |
| 57 | if (eCurType == XFA_Element::InstanceManager) |
| 58 | break; |
| 59 | if ((eCurType != XFA_Element::Subform) && |
| 60 | (eCurType != XFA_Element::SubformSet)) { |
| 61 | continue; |
| 62 | } |
| 63 | if (iCount == 0) { |
| 64 | CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name); |
| 65 | CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name); |
| 66 | if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' || |
| 67 | wsInstName.Mid(1) != wsName) { |
| 68 | return iCount; |
| 69 | } |
| 70 | dwNameHash = pNode->GetNameHash(); |
| 71 | } |
| 72 | if (dwNameHash != pNode->GetNameHash()) |
| 73 | break; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 74 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 75 | iCount++; |
| 76 | } |
| 77 | return iCount; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 78 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 79 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 80 | void SortNodeArrayByDocumentIdx(const CXFA_NodeSet& rgNodeSet, |
| 81 | CXFA_NodeArray& rgNodeArray, |
| 82 | CFX_ArrayTemplate<int32_t>& rgIdxArray) { |
| 83 | int32_t iCount = pdfium::CollectionSize<int32_t>(rgNodeSet); |
| 84 | rgNodeArray.SetSize(iCount); |
| 85 | rgIdxArray.SetSize(iCount); |
| 86 | if (iCount == 0) |
| 87 | return; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 88 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 89 | int32_t iIndex = -1; |
| 90 | int32_t iTotalIndex = -1; |
| 91 | CXFA_Node* pCommonParent = |
| 92 | (*rgNodeSet.begin())->GetNodeItem(XFA_NODEITEM_Parent); |
| 93 | for (CXFA_Node* pNode = pCommonParent->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 94 | pNode && iIndex < iCount; |
| 95 | pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 96 | iTotalIndex++; |
| 97 | if (pdfium::ContainsValue(rgNodeSet, pNode)) { |
| 98 | iIndex++; |
| 99 | rgNodeArray[iIndex] = pNode; |
| 100 | rgIdxArray[iIndex] = iTotalIndex; |
| 101 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 102 | } |
| 103 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 104 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 105 | using CXFA_NodeSetPair = std::pair<CXFA_NodeSet, CXFA_NodeSet>; |
| 106 | using CXFA_NodeSetPairMap = |
| 107 | std::map<uint32_t, std::unique_ptr<CXFA_NodeSetPair>>; |
| 108 | using CXFA_NodeSetPairMapMap = |
| 109 | std::map<CXFA_Node*, std::unique_ptr<CXFA_NodeSetPairMap>>; |
| 110 | |
| 111 | CXFA_NodeSetPair* NodeSetPairForNode(CXFA_Node* pNode, |
| 112 | CXFA_NodeSetPairMapMap* pMap) { |
| 113 | CXFA_Node* pParentNode = pNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 114 | uint32_t dwNameHash = pNode->GetNameHash(); |
| 115 | if (!pParentNode || !dwNameHash) |
| 116 | return nullptr; |
| 117 | |
| 118 | if (!(*pMap)[pParentNode]) |
| 119 | (*pMap)[pParentNode].reset(new CXFA_NodeSetPairMap); |
| 120 | |
| 121 | CXFA_NodeSetPairMap* pNodeSetPairMap = (*pMap)[pParentNode].get(); |
| 122 | if (!(*pNodeSetPairMap)[dwNameHash]) |
| 123 | (*pNodeSetPairMap)[dwNameHash].reset(new CXFA_NodeSetPair); |
| 124 | |
| 125 | return (*pNodeSetPairMap)[dwNameHash].get(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 126 | } |
| 127 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 128 | void ReorderDataNodes(const CXFA_NodeSet& sSet1, |
| 129 | const CXFA_NodeSet& sSet2, |
| 130 | FX_BOOL bInsertBefore) { |
| 131 | CXFA_NodeSetPairMapMap rgMap; |
| 132 | for (CXFA_Node* pNode : sSet1) { |
| 133 | CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap); |
| 134 | if (pNodeSetPair) |
| 135 | pNodeSetPair->first.insert(pNode); |
| 136 | } |
| 137 | for (CXFA_Node* pNode : sSet2) { |
| 138 | CXFA_NodeSetPair* pNodeSetPair = NodeSetPairForNode(pNode, &rgMap); |
| 139 | if (pNodeSetPair) { |
| 140 | if (pdfium::ContainsValue(pNodeSetPair->first, pNode)) |
| 141 | pNodeSetPair->first.erase(pNode); |
| 142 | else |
| 143 | pNodeSetPair->second.insert(pNode); |
| 144 | } |
| 145 | } |
| 146 | for (const auto& iter1 : rgMap) { |
| 147 | CXFA_NodeSetPairMap* pNodeSetPairMap = iter1.second.get(); |
| 148 | if (!pNodeSetPairMap) |
| 149 | continue; |
| 150 | |
| 151 | for (const auto& iter2 : *pNodeSetPairMap) { |
| 152 | CXFA_NodeSetPair* pNodeSetPair = iter2.second.get(); |
| 153 | if (!pNodeSetPair) |
| 154 | continue; |
| 155 | if (!pNodeSetPair->first.empty() && !pNodeSetPair->second.empty()) { |
| 156 | CXFA_NodeArray rgNodeArray1; |
| 157 | CXFA_NodeArray rgNodeArray2; |
| 158 | CFX_ArrayTemplate<int32_t> rgIdxArray1; |
| 159 | CFX_ArrayTemplate<int32_t> rgIdxArray2; |
| 160 | SortNodeArrayByDocumentIdx(pNodeSetPair->first, rgNodeArray1, |
| 161 | rgIdxArray1); |
| 162 | SortNodeArrayByDocumentIdx(pNodeSetPair->second, rgNodeArray2, |
| 163 | rgIdxArray2); |
| 164 | CXFA_Node* pParentNode = nullptr; |
| 165 | CXFA_Node* pBeforeNode = nullptr; |
| 166 | if (bInsertBefore) { |
| 167 | pBeforeNode = rgNodeArray2[0]; |
| 168 | pParentNode = pBeforeNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 169 | } else { |
| 170 | CXFA_Node* pLastNode = rgNodeArray2[rgIdxArray2.GetSize() - 1]; |
| 171 | pParentNode = pLastNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 172 | pBeforeNode = pLastNode->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 173 | } |
| 174 | for (int32_t iIdx = 0; iIdx < rgIdxArray1.GetSize(); iIdx++) { |
| 175 | CXFA_Node* pCurNode = rgNodeArray1[iIdx]; |
| 176 | pParentNode->RemoveChild(pCurNode); |
| 177 | pParentNode->InsertChild(pCurNode, pBeforeNode); |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | pNodeSetPairMap->clear(); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | CXFA_Node* GetItem(CXFA_Node* pInstMgrNode, int32_t iIndex) { |
| 186 | ASSERT(pInstMgrNode); |
| 187 | int32_t iCount = 0; |
| 188 | uint32_t dwNameHash = 0; |
| 189 | for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 190 | pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 191 | XFA_Element eCurType = pNode->GetElementType(); |
| 192 | if (eCurType == XFA_Element::InstanceManager) |
| 193 | break; |
| 194 | if ((eCurType != XFA_Element::Subform) && |
| 195 | (eCurType != XFA_Element::SubformSet)) { |
| 196 | continue; |
| 197 | } |
| 198 | if (iCount == 0) { |
| 199 | CFX_WideStringC wsName = pNode->GetCData(XFA_ATTRIBUTE_Name); |
| 200 | CFX_WideStringC wsInstName = pInstMgrNode->GetCData(XFA_ATTRIBUTE_Name); |
| 201 | if (wsInstName.GetLength() < 1 || wsInstName.GetAt(0) != '_' || |
| 202 | wsInstName.Mid(1) != wsName) { |
| 203 | return nullptr; |
| 204 | } |
| 205 | dwNameHash = pNode->GetNameHash(); |
| 206 | } |
| 207 | if (dwNameHash != pNode->GetNameHash()) |
| 208 | break; |
| 209 | |
| 210 | iCount++; |
| 211 | if (iCount > iIndex) |
| 212 | return pNode; |
| 213 | } |
| 214 | return nullptr; |
| 215 | } |
| 216 | |
| 217 | void InsertItem(CXFA_Node* pInstMgrNode, |
| 218 | CXFA_Node* pNewInstance, |
| 219 | int32_t iPos, |
| 220 | int32_t iCount = -1, |
| 221 | FX_BOOL bMoveDataBindingNodes = TRUE) { |
| 222 | if (iCount < 0) |
| 223 | iCount = GetCount(pInstMgrNode); |
| 224 | if (iPos < 0) |
| 225 | iPos = iCount; |
| 226 | if (iPos == iCount) { |
| 227 | CXFA_Node* pNextSibling = |
| 228 | iCount > 0 |
| 229 | ? GetItem(pInstMgrNode, iCount - 1) |
| 230 | ->GetNodeItem(XFA_NODEITEM_NextSibling) |
| 231 | : pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 232 | pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent) |
| 233 | ->InsertChild(pNewInstance, pNextSibling); |
| 234 | if (bMoveDataBindingNodes) { |
| 235 | CXFA_NodeSet sNew; |
| 236 | CXFA_NodeSet sAfter; |
| 237 | CXFA_NodeIteratorTemplate<CXFA_Node, |
| 238 | CXFA_TraverseStrategy_XFAContainerNode> |
| 239 | sIteratorNew(pNewInstance); |
| 240 | for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode; |
| 241 | pNode = sIteratorNew.MoveToNext()) { |
| 242 | CXFA_Node* pDataNode = pNode->GetBindData(); |
| 243 | if (!pDataNode) |
| 244 | continue; |
| 245 | |
| 246 | sNew.insert(pDataNode); |
| 247 | } |
| 248 | CXFA_NodeIteratorTemplate<CXFA_Node, |
| 249 | CXFA_TraverseStrategy_XFAContainerNode> |
| 250 | sIteratorAfter(pNextSibling); |
| 251 | for (CXFA_Node* pNode = sIteratorAfter.GetCurrent(); pNode; |
| 252 | pNode = sIteratorAfter.MoveToNext()) { |
| 253 | CXFA_Node* pDataNode = pNode->GetBindData(); |
| 254 | if (!pDataNode) |
| 255 | continue; |
| 256 | |
| 257 | sAfter.insert(pDataNode); |
| 258 | } |
| 259 | ReorderDataNodes(sNew, sAfter, FALSE); |
| 260 | } |
| 261 | } else { |
| 262 | CXFA_Node* pBeforeInstance = GetItem(pInstMgrNode, iPos); |
| 263 | pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent) |
| 264 | ->InsertChild(pNewInstance, pBeforeInstance); |
| 265 | if (bMoveDataBindingNodes) { |
| 266 | CXFA_NodeSet sNew; |
| 267 | CXFA_NodeSet sBefore; |
| 268 | CXFA_NodeIteratorTemplate<CXFA_Node, |
| 269 | CXFA_TraverseStrategy_XFAContainerNode> |
| 270 | sIteratorNew(pNewInstance); |
| 271 | for (CXFA_Node* pNode = sIteratorNew.GetCurrent(); pNode; |
| 272 | pNode = sIteratorNew.MoveToNext()) { |
| 273 | CXFA_Node* pDataNode = pNode->GetBindData(); |
| 274 | if (!pDataNode) |
| 275 | continue; |
| 276 | |
| 277 | sNew.insert(pDataNode); |
| 278 | } |
| 279 | CXFA_NodeIteratorTemplate<CXFA_Node, |
| 280 | CXFA_TraverseStrategy_XFAContainerNode> |
| 281 | sIteratorBefore(pBeforeInstance); |
| 282 | for (CXFA_Node* pNode = sIteratorBefore.GetCurrent(); pNode; |
| 283 | pNode = sIteratorBefore.MoveToNext()) { |
| 284 | CXFA_Node* pDataNode = pNode->GetBindData(); |
| 285 | if (!pDataNode) |
| 286 | continue; |
| 287 | |
| 288 | sBefore.insert(pDataNode); |
| 289 | } |
| 290 | ReorderDataNodes(sNew, sBefore, TRUE); |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | void RemoveItem(CXFA_Node* pInstMgrNode, |
| 296 | CXFA_Node* pRemoveInstance, |
| 297 | FX_BOOL bRemoveDataBinding = TRUE) { |
| 298 | pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)->RemoveChild(pRemoveInstance); |
| 299 | if (!bRemoveDataBinding) |
| 300 | return; |
| 301 | |
| 302 | CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFAContainerNode> |
| 303 | sIterator(pRemoveInstance); |
| 304 | for (CXFA_Node* pFormNode = sIterator.GetCurrent(); pFormNode; |
| 305 | pFormNode = sIterator.MoveToNext()) { |
| 306 | CXFA_Node* pDataNode = pFormNode->GetBindData(); |
| 307 | if (!pDataNode) |
| 308 | continue; |
| 309 | |
| 310 | if (pDataNode->RemoveBindItem(pFormNode) == 0) { |
| 311 | if (CXFA_Node* pDataParent = |
| 312 | pDataNode->GetNodeItem(XFA_NODEITEM_Parent)) { |
| 313 | pDataParent->RemoveChild(pDataNode); |
| 314 | } |
| 315 | } |
| 316 | pFormNode->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | CXFA_Node* CreateInstance(CXFA_Node* pInstMgrNode, FX_BOOL bDataMerge) { |
| 321 | CXFA_Document* pDocument = pInstMgrNode->GetDocument(); |
| 322 | CXFA_Node* pTemplateNode = pInstMgrNode->GetTemplateNode(); |
| 323 | CXFA_Node* pFormParent = pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 324 | CXFA_Node* pDataScope = nullptr; |
| 325 | for (CXFA_Node* pRootBoundNode = pFormParent; |
| 326 | pRootBoundNode && pRootBoundNode->IsContainerNode(); |
| 327 | pRootBoundNode = pRootBoundNode->GetNodeItem(XFA_NODEITEM_Parent)) { |
| 328 | pDataScope = pRootBoundNode->GetBindData(); |
| 329 | if (pDataScope) |
| 330 | break; |
| 331 | } |
| 332 | if (!pDataScope) { |
| 333 | pDataScope = ToNode(pDocument->GetXFAObject(XFA_HASHCODE_Record)); |
| 334 | ASSERT(pDataScope); |
| 335 | } |
| 336 | CXFA_Node* pInstance = pDocument->DataMerge_CopyContainer( |
| 337 | pTemplateNode, pFormParent, pDataScope, TRUE, bDataMerge, TRUE); |
| 338 | if (pInstance) { |
| 339 | pDocument->DataMerge_UpdateBindingRelations(pInstance); |
| 340 | pFormParent->RemoveChild(pInstance); |
| 341 | } |
| 342 | return pInstance; |
| 343 | } |
| 344 | |
| 345 | struct XFA_ExecEventParaInfo { |
| 346 | public: |
| 347 | uint32_t m_uHash; |
| 348 | const FX_WCHAR* m_lpcEventName; |
| 349 | XFA_EVENTTYPE m_eventType; |
| 350 | uint32_t m_validFlags; |
| 351 | }; |
| 352 | static const XFA_ExecEventParaInfo gs_eventParaInfos[] = { |
| 353 | {0x02a6c55a, L"postSubmit", XFA_EVENT_PostSubmit, 0}, |
| 354 | {0x0ab466bb, L"preSubmit", XFA_EVENT_PreSubmit, 0}, |
| 355 | {0x109d7ce7, L"mouseEnter", XFA_EVENT_MouseEnter, 5}, |
| 356 | {0x17fad373, L"postPrint", XFA_EVENT_PostPrint, 0}, |
| 357 | {0x1bfc72d9, L"preOpen", XFA_EVENT_PreOpen, 7}, |
| 358 | {0x2196a452, L"initialize", XFA_EVENT_Initialize, 1}, |
| 359 | {0x27410f03, L"mouseExit", XFA_EVENT_MouseExit, 5}, |
| 360 | {0x33c43dec, L"docClose", XFA_EVENT_DocClose, 0}, |
| 361 | {0x361fa1b6, L"preSave", XFA_EVENT_PreSave, 0}, |
| 362 | {0x36f1c6d8, L"preSign", XFA_EVENT_PreSign, 6}, |
| 363 | {0x4731d6ba, L"exit", XFA_EVENT_Exit, 2}, |
| 364 | {0x56bf456b, L"docReady", XFA_EVENT_DocReady, 0}, |
| 365 | {0x7233018a, L"validate", XFA_EVENT_Validate, 1}, |
| 366 | {0x8808385e, L"indexChange", XFA_EVENT_IndexChange, 3}, |
| 367 | {0x891f4606, L"change", XFA_EVENT_Change, 4}, |
| 368 | {0x9528a7b4, L"prePrint", XFA_EVENT_PrePrint, 0}, |
| 369 | {0x9f693b21, L"mouseDown", XFA_EVENT_MouseDown, 5}, |
| 370 | {0xcdce56b3, L"full", XFA_EVENT_Full, 4}, |
| 371 | {0xd576d08e, L"mouseUp", XFA_EVENT_MouseUp, 5}, |
| 372 | {0xd95657a6, L"click", XFA_EVENT_Click, 4}, |
| 373 | {0xdbfbe02e, L"calculate", XFA_EVENT_Calculate, 1}, |
| 374 | {0xe25fa7b8, L"postOpen", XFA_EVENT_PostOpen, 7}, |
| 375 | {0xe28dce7e, L"enter", XFA_EVENT_Enter, 2}, |
| 376 | {0xfc82d695, L"postSave", XFA_EVENT_PostSave, 0}, |
| 377 | {0xfd54fbb7, L"postSign", XFA_EVENT_PostSign, 6}, |
| 378 | }; |
| 379 | |
| 380 | const XFA_ExecEventParaInfo* GetEventParaInfoByName( |
| 381 | const CFX_WideStringC& wsEventName) { |
| 382 | uint32_t uHash = FX_HashCode_GetW(wsEventName, false); |
| 383 | int32_t iStart = 0; |
| 384 | int32_t iEnd = (sizeof(gs_eventParaInfos) / sizeof(gs_eventParaInfos[0])) - 1; |
| 385 | do { |
| 386 | int32_t iMid = (iStart + iEnd) / 2; |
| 387 | const XFA_ExecEventParaInfo* eventParaInfo = &gs_eventParaInfos[iMid]; |
| 388 | if (uHash == eventParaInfo->m_uHash) |
| 389 | return eventParaInfo; |
| 390 | if (uHash < eventParaInfo->m_uHash) |
| 391 | iEnd = iMid - 1; |
| 392 | else |
| 393 | iStart = iMid + 1; |
| 394 | } while (iStart <= iEnd); |
| 395 | return nullptr; |
| 396 | } |
| 397 | |
| 398 | void StrToRGB(const CFX_WideString& strRGB, |
| 399 | int32_t& r, |
| 400 | int32_t& g, |
| 401 | int32_t& b) { |
| 402 | r = 0; |
| 403 | g = 0; |
| 404 | b = 0; |
| 405 | |
| 406 | FX_WCHAR zero = '0'; |
| 407 | int32_t iIndex = 0; |
| 408 | int32_t iLen = strRGB.GetLength(); |
| 409 | for (int32_t i = 0; i < iLen; ++i) { |
| 410 | FX_WCHAR ch = strRGB.GetAt(i); |
| 411 | if (ch == L',') |
| 412 | ++iIndex; |
| 413 | if (iIndex > 2) |
| 414 | break; |
| 415 | |
| 416 | int32_t iValue = ch - zero; |
| 417 | if (iValue >= 0 && iValue <= 9) { |
| 418 | switch (iIndex) { |
| 419 | case 0: |
| 420 | r = r * 10 + iValue; |
| 421 | break; |
| 422 | case 1: |
| 423 | g = g * 10 + iValue; |
| 424 | break; |
| 425 | default: |
| 426 | b = b * 10 + iValue; |
| 427 | break; |
| 428 | } |
| 429 | } |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | enum XFA_KEYTYPE { |
| 434 | XFA_KEYTYPE_Custom, |
| 435 | XFA_KEYTYPE_Element, |
| 436 | }; |
| 437 | |
| 438 | void* GetMapKey_Custom(const CFX_WideStringC& wsKey) { |
| 439 | uint32_t dwKey = FX_HashCode_GetW(wsKey, false); |
| 440 | return (void*)(uintptr_t)((dwKey << 1) | XFA_KEYTYPE_Custom); |
| 441 | } |
| 442 | |
| 443 | void* GetMapKey_Element(XFA_Element eType, XFA_ATTRIBUTE eAttribute) { |
| 444 | return (void*)(uintptr_t)((static_cast<int32_t>(eType) << 16) | |
| 445 | (eAttribute << 8) | XFA_KEYTYPE_Element); |
| 446 | } |
| 447 | |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 448 | const XFA_ATTRIBUTEINFO* GetAttributeOfElement(XFA_Element eElement, |
| 449 | XFA_ATTRIBUTE eAttribute, |
| 450 | uint32_t dwPacket) { |
| 451 | int32_t iCount = 0; |
| 452 | const uint8_t* pAttr = XFA_GetElementAttributes(eElement, iCount); |
| 453 | if (!pAttr || iCount < 1) |
| 454 | return nullptr; |
| 455 | |
| 456 | if (!std::binary_search(pAttr, pAttr + iCount, eAttribute)) |
| 457 | return nullptr; |
| 458 | |
| 459 | const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttribute); |
| 460 | ASSERT(pInfo); |
| 461 | if (dwPacket == XFA_XDPPACKET_UNKNOWN) |
| 462 | return pInfo; |
| 463 | return (dwPacket & pInfo->dwPackets) ? pInfo : nullptr; |
| 464 | } |
| 465 | |
| 466 | const XFA_ATTRIBUTEENUMINFO* GetAttributeEnumByID(XFA_ATTRIBUTEENUM eName) { |
| 467 | return g_XFAEnumData + eName; |
| 468 | } |
| 469 | |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 470 | } // namespace |
| 471 | |
| 472 | static void XFA_DefaultFreeData(void* pData) {} |
| 473 | |
| 474 | static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADefaultFreeData = { |
| 475 | XFA_DefaultFreeData, nullptr}; |
| 476 | |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 477 | XFA_MAPMODULEDATA::XFA_MAPMODULEDATA() {} |
| 478 | |
| 479 | XFA_MAPMODULEDATA::~XFA_MAPMODULEDATA() {} |
| 480 | |
dsinclair | b977847 | 2016-06-23 13:34:10 -0700 | [diff] [blame] | 481 | CXFA_Node::CXFA_Node(CXFA_Document* pDoc, |
| 482 | uint16_t ePacket, |
| 483 | XFA_ObjectType oType, |
dsinclair | c1df5d4 | 2016-07-18 06:36:51 -0700 | [diff] [blame] | 484 | XFA_Element eType, |
| 485 | const CFX_WideStringC& elementName) |
| 486 | : CXFA_Object(pDoc, oType, eType, elementName), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 487 | m_pNext(nullptr), |
| 488 | m_pChild(nullptr), |
| 489 | m_pLastChild(nullptr), |
| 490 | m_pParent(nullptr), |
| 491 | m_pXMLNode(nullptr), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 492 | m_ePacket(ePacket), |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 493 | m_uNodeFlags(XFA_NodeFlag_None), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 494 | m_dwNameHash(0), |
| 495 | m_pAuxNode(nullptr), |
| 496 | m_pMapModuleData(nullptr) { |
| 497 | ASSERT(m_pDocument); |
| 498 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 499 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 500 | CXFA_Node::~CXFA_Node() { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 501 | ASSERT(!m_pParent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 502 | RemoveMapModuleKey(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 503 | CXFA_Node* pNode = m_pChild; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 504 | while (pNode) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 505 | CXFA_Node* pNext = pNode->m_pNext; |
| 506 | pNode->m_pParent = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 507 | delete pNode; |
| 508 | pNode = pNext; |
| 509 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 510 | if (m_pXMLNode && IsOwnXMLNode()) |
Tom Sepez | d3743ea | 2016-05-16 15:56:53 -0700 | [diff] [blame] | 511 | m_pXMLNode->Release(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 512 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 513 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 514 | CXFA_Node* CXFA_Node::Clone(FX_BOOL bRecursive) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 515 | CXFA_Node* pClone = m_pDocument->CreateNode(m_ePacket, m_elementType); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 516 | if (!pClone) |
| 517 | return nullptr; |
| 518 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 519 | MergeAllData(pClone); |
| 520 | pClone->UpdateNameHash(); |
| 521 | if (IsNeedSavingXMLNode()) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 522 | CFDE_XMLNode* pCloneXML = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 523 | if (IsAttributeInXML()) { |
| 524 | CFX_WideString wsName; |
| 525 | GetAttribute(XFA_ATTRIBUTE_Name, wsName, FALSE); |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 526 | CFDE_XMLElement* pCloneXMLElement = new CFDE_XMLElement(wsName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 527 | CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value); |
| 528 | if (!wsValue.IsEmpty()) { |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 529 | pCloneXMLElement->SetTextData(CFX_WideString(wsValue)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 530 | } |
| 531 | pCloneXML = pCloneXMLElement; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 532 | pCloneXMLElement = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 533 | pClone->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown); |
| 534 | } else { |
| 535 | pCloneXML = m_pXMLNode->Clone(FALSE); |
| 536 | } |
| 537 | pClone->SetXMLMappingNode(pCloneXML); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 538 | pClone->SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 539 | } |
| 540 | if (bRecursive) { |
| 541 | for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild; |
| 542 | pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 543 | pClone->InsertChild(pChild->Clone(bRecursive)); |
| 544 | } |
| 545 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 546 | pClone->SetFlag(XFA_NodeFlag_Initialized, true); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 547 | pClone->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 548 | return pClone; |
| 549 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 550 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 551 | CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem) const { |
| 552 | switch (eItem) { |
| 553 | case XFA_NODEITEM_NextSibling: |
| 554 | return m_pNext; |
| 555 | case XFA_NODEITEM_FirstChild: |
| 556 | return m_pChild; |
| 557 | case XFA_NODEITEM_Parent: |
| 558 | return m_pParent; |
| 559 | case XFA_NODEITEM_PrevSibling: |
| 560 | if (m_pParent) { |
| 561 | CXFA_Node* pSibling = m_pParent->m_pChild; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 562 | CXFA_Node* pPrev = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 563 | while (pSibling && pSibling != this) { |
| 564 | pPrev = pSibling; |
| 565 | pSibling = pSibling->m_pNext; |
| 566 | } |
| 567 | return pPrev; |
| 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 | default: |
| 571 | break; |
| 572 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 573 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 574 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 575 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 576 | CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem, |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 577 | XFA_ObjectType eType) const { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 578 | CXFA_Node* pNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 579 | switch (eItem) { |
| 580 | case XFA_NODEITEM_NextSibling: |
| 581 | pNode = m_pNext; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 582 | while (pNode && pNode->GetObjectType() != eType) |
| 583 | pNode = pNode->m_pNext; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 584 | break; |
| 585 | case XFA_NODEITEM_FirstChild: |
| 586 | pNode = m_pChild; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 587 | while (pNode && pNode->GetObjectType() != eType) |
| 588 | pNode = pNode->m_pNext; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 589 | break; |
| 590 | case XFA_NODEITEM_Parent: |
| 591 | pNode = m_pParent; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 592 | while (pNode && pNode->GetObjectType() != eType) |
| 593 | pNode = pNode->m_pParent; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 594 | break; |
| 595 | case XFA_NODEITEM_PrevSibling: |
| 596 | if (m_pParent) { |
| 597 | CXFA_Node* pSibling = m_pParent->m_pChild; |
| 598 | while (pSibling && pSibling != this) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 599 | if (eType == pSibling->GetObjectType()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 600 | pNode = pSibling; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 601 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 602 | pSibling = pSibling->m_pNext; |
| 603 | } |
| 604 | } |
| 605 | break; |
| 606 | default: |
| 607 | break; |
| 608 | } |
| 609 | return pNode; |
| 610 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 611 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 612 | int32_t CXFA_Node::GetNodeList(CXFA_NodeArray& nodes, |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 613 | uint32_t dwTypeFilter, |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 614 | XFA_Element eTypeFilter, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 615 | int32_t iLevel) { |
| 616 | if (--iLevel < 0) { |
| 617 | return nodes.GetSize(); |
| 618 | } |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 619 | if (eTypeFilter != XFA_Element::Unknown) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 620 | CXFA_Node* pChild = m_pChild; |
| 621 | while (pChild) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 622 | if (pChild->GetElementType() == eTypeFilter) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 623 | nodes.Add(pChild); |
| 624 | if (iLevel > 0) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 625 | GetNodeList(nodes, dwTypeFilter, eTypeFilter, iLevel); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 626 | } |
| 627 | } |
| 628 | pChild = pChild->m_pNext; |
| 629 | } |
| 630 | } else if (dwTypeFilter == |
| 631 | (XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties)) { |
| 632 | CXFA_Node* pChild = m_pChild; |
| 633 | while (pChild) { |
| 634 | nodes.Add(pChild); |
| 635 | if (iLevel > 0) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 636 | GetNodeList(nodes, dwTypeFilter, eTypeFilter, iLevel); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 637 | } |
| 638 | pChild = pChild->m_pNext; |
| 639 | } |
| 640 | } else if (dwTypeFilter != 0) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 641 | bool bFilterChildren = !!(dwTypeFilter & XFA_NODEFILTER_Children); |
| 642 | bool bFilterProperties = !!(dwTypeFilter & XFA_NODEFILTER_Properties); |
| 643 | bool bFilterOneOfProperties = |
| 644 | !!(dwTypeFilter & XFA_NODEFILTER_OneOfProperty); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 645 | CXFA_Node* pChild = m_pChild; |
| 646 | while (pChild) { |
| 647 | const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement( |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 648 | GetElementType(), pChild->GetElementType(), XFA_XDPPACKET_UNKNOWN); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 649 | if (pProperty) { |
| 650 | if (bFilterProperties) { |
| 651 | nodes.Add(pChild); |
| 652 | } else if (bFilterOneOfProperties && |
| 653 | (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) { |
| 654 | nodes.Add(pChild); |
| 655 | } else if (bFilterChildren && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 656 | (pChild->GetElementType() == XFA_Element::Variables || |
| 657 | pChild->GetElementType() == XFA_Element::PageSet)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 658 | nodes.Add(pChild); |
| 659 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 660 | } else if (bFilterChildren) { |
| 661 | nodes.Add(pChild); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 662 | } |
| 663 | pChild = pChild->m_pNext; |
| 664 | } |
| 665 | if (bFilterOneOfProperties && nodes.GetSize() < 1) { |
| 666 | int32_t iProperties = 0; |
| 667 | const XFA_PROPERTY* pProperty = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 668 | XFA_GetElementProperties(GetElementType(), iProperties); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 669 | if (!pProperty || iProperties < 1) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 670 | return 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 671 | for (int32_t i = 0; i < iProperties; i++) { |
| 672 | if (pProperty[i].uFlags & XFA_PROPERTYFLAG_DefaultOneOf) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 673 | const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(GetPacketID()); |
| 674 | CXFA_Node* pNewNode = |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 675 | m_pDocument->CreateNode(pPacket, pProperty[i].eName); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 676 | if (!pNewNode) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 677 | break; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 678 | InsertChild(pNewNode, nullptr); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 679 | pNewNode->SetFlag(XFA_NodeFlag_Initialized, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 680 | nodes.Add(pNewNode); |
| 681 | break; |
| 682 | } |
| 683 | } |
| 684 | } |
| 685 | } |
| 686 | return nodes.GetSize(); |
| 687 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 688 | |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 689 | CXFA_Node* CXFA_Node::CreateSamePacketNode(XFA_Element eType, |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 690 | uint32_t dwFlags) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 691 | CXFA_Node* pNode = m_pDocument->CreateNode(m_ePacket, eType); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 692 | pNode->SetFlag(dwFlags, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 693 | return pNode; |
| 694 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 695 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 696 | CXFA_Node* CXFA_Node::CloneTemplateToForm(FX_BOOL bRecursive) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 697 | ASSERT(m_ePacket == XFA_XDPPACKET_Template); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 698 | CXFA_Node* pClone = |
| 699 | m_pDocument->CreateNode(XFA_XDPPACKET_Form, m_elementType); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 700 | if (!pClone) |
| 701 | return nullptr; |
| 702 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 703 | pClone->SetTemplateNode(this); |
| 704 | pClone->UpdateNameHash(); |
| 705 | pClone->SetXMLMappingNode(GetXMLMappingNode()); |
| 706 | if (bRecursive) { |
| 707 | for (CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); pChild; |
| 708 | pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 709 | pClone->InsertChild(pChild->CloneTemplateToForm(bRecursive)); |
| 710 | } |
| 711 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 712 | pClone->SetFlag(XFA_NodeFlag_Initialized, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 713 | return pClone; |
| 714 | } |
| 715 | |
| 716 | CXFA_Node* CXFA_Node::GetTemplateNode() const { |
| 717 | return m_pAuxNode; |
| 718 | } |
| 719 | |
| 720 | void CXFA_Node::SetTemplateNode(CXFA_Node* pTemplateNode) { |
| 721 | m_pAuxNode = pTemplateNode; |
| 722 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 723 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 724 | CXFA_Node* CXFA_Node::GetBindData() { |
| 725 | ASSERT(GetPacketID() == XFA_XDPPACKET_Form); |
| 726 | return static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); |
| 727 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 728 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 729 | int32_t CXFA_Node::GetBindItems(CXFA_NodeArray& formItems) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 730 | if (BindsFormItems()) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 731 | CXFA_NodeArray* pItems = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 732 | TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems); |
| 733 | formItems.Copy(*pItems); |
| 734 | return formItems.GetSize(); |
| 735 | } |
| 736 | CXFA_Node* pFormNode = |
| 737 | static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 738 | if (pFormNode) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 739 | formItems.Add(pFormNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 740 | return formItems.GetSize(); |
| 741 | } |
| 742 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 743 | int32_t CXFA_Node::AddBindItem(CXFA_Node* pFormNode) { |
| 744 | ASSERT(pFormNode); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 745 | if (BindsFormItems()) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 746 | CXFA_NodeArray* pItems = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 747 | TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems); |
| 748 | ASSERT(pItems); |
| 749 | if (pItems->Find(pFormNode) < 0) { |
| 750 | pItems->Add(pFormNode); |
| 751 | } |
| 752 | return pItems->GetSize(); |
| 753 | } |
| 754 | CXFA_Node* pOldFormItem = |
| 755 | static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); |
| 756 | if (!pOldFormItem) { |
| 757 | SetObject(XFA_ATTRIBUTE_BindingNode, pFormNode); |
| 758 | return 1; |
| 759 | } else if (pOldFormItem == pFormNode) { |
| 760 | return 1; |
| 761 | } |
| 762 | CXFA_NodeArray* pItems = new CXFA_NodeArray; |
| 763 | SetObject(XFA_ATTRIBUTE_BindingNode, pItems, &deleteBindItemCallBack); |
| 764 | pItems->Add(pOldFormItem); |
| 765 | pItems->Add(pFormNode); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 766 | m_uNodeFlags |= XFA_NodeFlag_BindFormItems; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 767 | return 2; |
| 768 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 769 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 770 | int32_t CXFA_Node::RemoveBindItem(CXFA_Node* pFormNode) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 771 | if (BindsFormItems()) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 772 | CXFA_NodeArray* pItems = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 773 | TryObject(XFA_ATTRIBUTE_BindingNode, (void*&)pItems); |
| 774 | ASSERT(pItems); |
| 775 | int32_t iIndex = pItems->Find(pFormNode); |
| 776 | int32_t iCount = pItems->GetSize(); |
| 777 | if (iIndex >= 0) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 778 | if (iIndex != iCount - 1) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 779 | pItems->SetAt(iIndex, pItems->GetAt(iCount - 1)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 780 | pItems->RemoveAt(iCount - 1); |
| 781 | if (iCount == 2) { |
| 782 | CXFA_Node* pLastFormNode = pItems->GetAt(0); |
| 783 | SetObject(XFA_ATTRIBUTE_BindingNode, pLastFormNode); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 784 | m_uNodeFlags &= ~XFA_NodeFlag_BindFormItems; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 785 | } |
| 786 | iCount--; |
| 787 | } |
| 788 | return iCount; |
| 789 | } |
| 790 | CXFA_Node* pOldFormItem = |
| 791 | static_cast<CXFA_Node*>(GetObject(XFA_ATTRIBUTE_BindingNode)); |
| 792 | if (pOldFormItem == pFormNode) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 793 | SetObject(XFA_ATTRIBUTE_BindingNode, nullptr); |
| 794 | pOldFormItem = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 795 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 796 | return pOldFormItem ? 1 : 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 797 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 798 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 799 | FX_BOOL CXFA_Node::HasBindItem() { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 800 | return GetPacketID() == XFA_XDPPACKET_Datasets && |
| 801 | GetObject(XFA_ATTRIBUTE_BindingNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 802 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 803 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 804 | CXFA_WidgetData* CXFA_Node::GetWidgetData() { |
| 805 | return (CXFA_WidgetData*)GetObject(XFA_ATTRIBUTE_WidgetData); |
| 806 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 807 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 808 | CXFA_WidgetData* CXFA_Node::GetContainerWidgetData() { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 809 | if (GetPacketID() != XFA_XDPPACKET_Form) |
| 810 | return nullptr; |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 811 | XFA_Element eType = GetElementType(); |
| 812 | if (eType == XFA_Element::ExclGroup) |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 813 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 814 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 815 | if (pParentNode && pParentNode->GetElementType() == XFA_Element::ExclGroup) |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 816 | return nullptr; |
| 817 | |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 818 | if (eType == XFA_Element::Field) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 819 | CXFA_WidgetData* pFieldWidgetData = GetWidgetData(); |
| 820 | if (pFieldWidgetData && |
| 821 | pFieldWidgetData->GetChoiceListOpen() == |
| 822 | XFA_ATTRIBUTEENUM_MultiSelect) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 823 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 824 | } else { |
| 825 | CFX_WideString wsPicture; |
| 826 | if (pFieldWidgetData) { |
| 827 | pFieldWidgetData->GetPictureContent(wsPicture, |
| 828 | XFA_VALUEPICTURE_DataBind); |
| 829 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 830 | if (!wsPicture.IsEmpty()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 831 | return pFieldWidgetData; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 832 | CXFA_Node* pDataNode = GetBindData(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 833 | if (!pDataNode) |
| 834 | return nullptr; |
| 835 | pFieldWidgetData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 836 | CXFA_NodeArray formNodes; |
| 837 | pDataNode->GetBindItems(formNodes); |
| 838 | for (int32_t i = 0; i < formNodes.GetSize(); i++) { |
| 839 | CXFA_Node* pFormNode = formNodes.GetAt(i); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 840 | if (!pFormNode || pFormNode->HasRemovedChildren()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 841 | continue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 842 | pFieldWidgetData = pFormNode->GetWidgetData(); |
| 843 | if (pFieldWidgetData) { |
| 844 | pFieldWidgetData->GetPictureContent(wsPicture, |
| 845 | XFA_VALUEPICTURE_DataBind); |
| 846 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 847 | if (!wsPicture.IsEmpty()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 848 | break; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 849 | pFieldWidgetData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 850 | } |
| 851 | return pFieldWidgetData; |
| 852 | } |
| 853 | } |
| 854 | CXFA_Node* pGrandNode = |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 855 | pParentNode ? pParentNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 856 | CXFA_Node* pValueNode = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 857 | (pParentNode && pParentNode->GetElementType() == XFA_Element::Value) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 858 | ? pParentNode |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 859 | : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 860 | if (!pValueNode) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 861 | pValueNode = |
| 862 | (pGrandNode && pGrandNode->GetElementType() == XFA_Element::Value) |
| 863 | ? pGrandNode |
| 864 | : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 865 | } |
| 866 | CXFA_Node* pParentOfValueNode = |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 867 | pValueNode ? pValueNode->GetNodeItem(XFA_NODEITEM_Parent) : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 868 | return pParentOfValueNode ? pParentOfValueNode->GetContainerWidgetData() |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 869 | : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 870 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 871 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 872 | FX_BOOL CXFA_Node::GetLocaleName(CFX_WideString& wsLocaleName) { |
| 873 | CXFA_Node* pForm = GetDocument()->GetXFAObject(XFA_HASHCODE_Form)->AsNode(); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 874 | CXFA_Node* pTopSubform = pForm->GetFirstChildByClass(XFA_Element::Subform); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 875 | ASSERT(pTopSubform); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 876 | CXFA_Node* pLocaleNode = this; |
| 877 | FX_BOOL bLocale = FALSE; |
| 878 | do { |
| 879 | bLocale = pLocaleNode->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, FALSE); |
| 880 | if (!bLocale) { |
| 881 | pLocaleNode = pLocaleNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 882 | } |
| 883 | } while (pLocaleNode && pLocaleNode != pTopSubform && !bLocale); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 884 | if (bLocale) |
| 885 | return TRUE; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 886 | CXFA_Node* pConfig = ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Config)); |
| 887 | wsLocaleName = GetDocument()->GetLocalMgr()->GetConfigLocaleName(pConfig); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 888 | if (!wsLocaleName.IsEmpty()) |
| 889 | return TRUE; |
| 890 | if (pTopSubform && |
| 891 | pTopSubform->TryCData(XFA_ATTRIBUTE_Locale, wsLocaleName, FALSE)) { |
| 892 | return TRUE; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 893 | } |
| 894 | IFX_Locale* pLocale = GetDocument()->GetLocalMgr()->GetDefLocale(); |
| 895 | if (pLocale) { |
| 896 | wsLocaleName = pLocale->GetName(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 897 | return TRUE; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 898 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 899 | return FALSE; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 900 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 901 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 902 | XFA_ATTRIBUTEENUM CXFA_Node::GetIntact() { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 903 | CXFA_Node* pKeep = GetFirstChildByClass(XFA_Element::Keep); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 904 | XFA_ATTRIBUTEENUM eLayoutType = GetEnum(XFA_ATTRIBUTE_Layout); |
| 905 | if (pKeep) { |
| 906 | XFA_ATTRIBUTEENUM eIntact; |
| 907 | if (pKeep->TryEnum(XFA_ATTRIBUTE_Intact, eIntact, FALSE)) { |
| 908 | if (eIntact == XFA_ATTRIBUTEENUM_None && |
| 909 | eLayoutType == XFA_ATTRIBUTEENUM_Row && |
| 910 | m_pDocument->GetCurVersionMode() < XFA_VERSION_208) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 911 | CXFA_Node* pPreviewRow = GetNodeItem(XFA_NODEITEM_PrevSibling, |
| 912 | XFA_ObjectType::ContainerNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 913 | if (pPreviewRow && |
| 914 | pPreviewRow->GetEnum(XFA_ATTRIBUTE_Layout) == |
| 915 | XFA_ATTRIBUTEENUM_Row) { |
| 916 | XFA_ATTRIBUTEENUM eValue; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 917 | if (pKeep->TryEnum(XFA_ATTRIBUTE_Previous, eValue, FALSE) && |
| 918 | (eValue == XFA_ATTRIBUTEENUM_ContentArea || |
| 919 | eValue == XFA_ATTRIBUTEENUM_PageArea)) { |
| 920 | return XFA_ATTRIBUTEENUM_ContentArea; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 921 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 922 | CXFA_Node* pNode = |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 923 | pPreviewRow->GetFirstChildByClass(XFA_Element::Keep); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 924 | if (pNode && pNode->TryEnum(XFA_ATTRIBUTE_Next, eValue, FALSE) && |
| 925 | (eValue == XFA_ATTRIBUTEENUM_ContentArea || |
| 926 | eValue == XFA_ATTRIBUTEENUM_PageArea)) { |
| 927 | return XFA_ATTRIBUTEENUM_ContentArea; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 928 | } |
| 929 | } |
| 930 | } |
| 931 | return eIntact; |
| 932 | } |
| 933 | } |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 934 | switch (GetElementType()) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 935 | case XFA_Element::Subform: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 936 | switch (eLayoutType) { |
| 937 | case XFA_ATTRIBUTEENUM_Position: |
| 938 | case XFA_ATTRIBUTEENUM_Row: |
| 939 | return XFA_ATTRIBUTEENUM_ContentArea; |
| 940 | case XFA_ATTRIBUTEENUM_Tb: |
| 941 | case XFA_ATTRIBUTEENUM_Table: |
| 942 | case XFA_ATTRIBUTEENUM_Lr_tb: |
| 943 | case XFA_ATTRIBUTEENUM_Rl_tb: |
| 944 | return XFA_ATTRIBUTEENUM_None; |
| 945 | default: |
| 946 | break; |
| 947 | } |
| 948 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 949 | case XFA_Element::Field: { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 950 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 951 | if (!pParentNode || |
| 952 | pParentNode->GetElementType() == XFA_Element::PageArea) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 953 | return XFA_ATTRIBUTEENUM_ContentArea; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 954 | if (pParentNode->GetIntact() == XFA_ATTRIBUTEENUM_None) { |
| 955 | XFA_ATTRIBUTEENUM eParLayout = |
| 956 | pParentNode->GetEnum(XFA_ATTRIBUTE_Layout); |
| 957 | if (eParLayout == XFA_ATTRIBUTEENUM_Position || |
| 958 | eParLayout == XFA_ATTRIBUTEENUM_Row || |
| 959 | eParLayout == XFA_ATTRIBUTEENUM_Table) { |
| 960 | return XFA_ATTRIBUTEENUM_None; |
| 961 | } |
| 962 | XFA_VERSION version = m_pDocument->GetCurVersionMode(); |
| 963 | if (eParLayout == XFA_ATTRIBUTEENUM_Tb && version < XFA_VERSION_208) { |
| 964 | CXFA_Measurement measureH; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 965 | if (TryMeasure(XFA_ATTRIBUTE_H, measureH, FALSE)) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 966 | return XFA_ATTRIBUTEENUM_ContentArea; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 967 | } |
| 968 | return XFA_ATTRIBUTEENUM_None; |
| 969 | } |
| 970 | return XFA_ATTRIBUTEENUM_ContentArea; |
| 971 | } |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 972 | case XFA_Element::Draw: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 973 | return XFA_ATTRIBUTEENUM_ContentArea; |
| 974 | default: |
| 975 | break; |
| 976 | } |
| 977 | return XFA_ATTRIBUTEENUM_None; |
| 978 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 979 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 980 | CXFA_Node* CXFA_Node::GetDataDescriptionNode() { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 981 | if (m_ePacket == XFA_XDPPACKET_Datasets) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 982 | return m_pAuxNode; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 983 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 984 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 985 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 986 | void CXFA_Node::SetDataDescriptionNode(CXFA_Node* pDataDescriptionNode) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 987 | ASSERT(m_ePacket == XFA_XDPPACKET_Datasets); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 988 | m_pAuxNode = pDataDescriptionNode; |
| 989 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 990 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 991 | void CXFA_Node::Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments) { |
| 992 | int32_t iLength = pArguments->GetLength(); |
| 993 | if (iLength != 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 994 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resolveNode"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 995 | return; |
| 996 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 997 | CFX_WideString wsExpression = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 998 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 999 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1000 | if (!pScriptContext) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1001 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1002 | CXFA_Node* refNode = this; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1003 | if (refNode->GetElementType() == XFA_Element::Xfa) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1004 | refNode = ToNode(pScriptContext->GetThisObject()); |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1005 | uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1006 | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | |
| 1007 | XFA_RESOLVENODE_Siblings; |
| 1008 | XFA_RESOLVENODE_RS resoveNodeRS; |
tsepez | fc58ad1 | 2016-04-05 12:22:15 -0700 | [diff] [blame] | 1009 | int32_t iRet = pScriptContext->ResolveObjects( |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1010 | refNode, wsExpression.AsStringC(), resoveNodeRS, dwFlag); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1011 | if (iRet < 1) { |
| 1012 | pArguments->GetReturnValue()->SetNull(); |
| 1013 | return; |
| 1014 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1015 | if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { |
| 1016 | CXFA_Object* pNode = resoveNodeRS.nodes[0]; |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1017 | pArguments->GetReturnValue()->Assign( |
| 1018 | pScriptContext->GetJSValueFromMap(pNode)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1019 | } else { |
| 1020 | const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = |
| 1021 | resoveNodeRS.pScriptAttribute; |
| 1022 | if (lpAttributeInfo && lpAttributeInfo->eValueType == XFA_SCRIPT_Object) { |
dsinclair | 86fad99 | 2016-05-31 11:34:04 -0700 | [diff] [blame] | 1023 | std::unique_ptr<CFXJSE_Value> pValue( |
| 1024 | new CFXJSE_Value(pScriptContext->GetRuntime())); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1025 | (resoveNodeRS.nodes[0]->*(lpAttributeInfo->lpfnCallback))( |
dsinclair | 86fad99 | 2016-05-31 11:34:04 -0700 | [diff] [blame] | 1026 | pValue.get(), FALSE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1027 | pArguments->GetReturnValue()->Assign(pValue.get()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1028 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1029 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1030 | } |
| 1031 | } |
| 1032 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1033 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1034 | void CXFA_Node::Script_TreeClass_ResolveNodes(CFXJSE_Arguments* pArguments) { |
| 1035 | int32_t iLength = pArguments->GetLength(); |
| 1036 | if (iLength != 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1037 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resolveNodes"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1038 | return; |
| 1039 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1040 | CFX_WideString wsExpression = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1041 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1042 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1043 | if (!pValue) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1044 | return; |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1045 | uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1046 | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | |
| 1047 | XFA_RESOLVENODE_Siblings; |
| 1048 | CXFA_Node* refNode = this; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1049 | if (refNode->GetElementType() == XFA_Element::Xfa) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1050 | refNode = ToNode(m_pDocument->GetScriptContext()->GetThisObject()); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1051 | Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag, refNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1052 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1053 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1054 | void CXFA_Node::Script_Som_ResolveNodeList(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1055 | CFX_WideString wsExpression, |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1056 | uint32_t dwFlag, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1057 | CXFA_Node* refNode) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 1058 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1059 | if (!pScriptContext) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1060 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1061 | XFA_RESOLVENODE_RS resoveNodeRS; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1062 | if (!refNode) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1063 | refNode = this; |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1064 | pScriptContext->ResolveObjects(refNode, wsExpression.AsStringC(), |
tsepez | fc58ad1 | 2016-04-05 12:22:15 -0700 | [diff] [blame] | 1065 | resoveNodeRS, dwFlag); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1066 | CXFA_ArrayNodeList* pNodeList = new CXFA_ArrayNodeList(m_pDocument); |
| 1067 | if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { |
| 1068 | for (int32_t i = 0; i < resoveNodeRS.nodes.GetSize(); i++) { |
| 1069 | if (resoveNodeRS.nodes[i]->IsNode()) |
| 1070 | pNodeList->Append(resoveNodeRS.nodes[i]->AsNode()); |
| 1071 | } |
| 1072 | } else { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1073 | CXFA_ValueArray valueArray(pScriptContext->GetRuntime()); |
| 1074 | if (resoveNodeRS.GetAttributeResult(valueArray) > 0) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1075 | CXFA_ObjArray objectArray; |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1076 | valueArray.GetAttributeObject(objectArray); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1077 | for (int32_t i = 0; i < objectArray.GetSize(); i++) { |
| 1078 | if (objectArray[i]->IsNode()) |
| 1079 | pNodeList->Append(objectArray[i]->AsNode()); |
| 1080 | } |
| 1081 | } |
| 1082 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1083 | pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1084 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1085 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1086 | void CXFA_Node::Script_TreeClass_All(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1087 | FX_BOOL bSetting, |
| 1088 | XFA_ATTRIBUTE eAttribute) { |
| 1089 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1090 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1091 | } else { |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1092 | uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1093 | CFX_WideString wsName; |
| 1094 | GetAttribute(XFA_ATTRIBUTE_Name, wsName); |
| 1095 | CFX_WideString wsExpression = wsName + FX_WSTRC(L"[*]"); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1096 | Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1097 | } |
| 1098 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1099 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1100 | void CXFA_Node::Script_TreeClass_Nodes(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1101 | FX_BOOL bSetting, |
| 1102 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 1103 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1104 | if (!pScriptContext) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1105 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1106 | if (bSetting) { |
| 1107 | IXFA_AppProvider* pAppProvider = m_pDocument->GetNotify()->GetAppProvider(); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 1108 | ASSERT(pAppProvider); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1109 | CFX_WideString wsMessage; |
| 1110 | pAppProvider->LoadString(XFA_IDS_Unable_TO_SET, wsMessage); |
tsepez | 28f97ff | 2016-04-04 16:41:35 -0700 | [diff] [blame] | 1111 | FXJSE_ThrowMessage( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 1112 | FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1113 | } else { |
| 1114 | CXFA_AttachNodeList* pNodeList = new CXFA_AttachNodeList(m_pDocument, this); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1115 | pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1116 | } |
| 1117 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1118 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1119 | void CXFA_Node::Script_TreeClass_ClassAll(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1120 | FX_BOOL bSetting, |
| 1121 | XFA_ATTRIBUTE eAttribute) { |
| 1122 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1123 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1124 | } else { |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1125 | uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL; |
dsinclair | 017052a | 2016-06-28 07:43:51 -0700 | [diff] [blame] | 1126 | CFX_WideString wsExpression = |
| 1127 | FX_WSTRC(L"#") + GetClassName() + FX_WSTRC(L"[*]"); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1128 | Script_Som_ResolveNodeList(pValue, wsExpression, dwFlag); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1129 | } |
| 1130 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1131 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1132 | void CXFA_Node::Script_TreeClass_Parent(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1133 | FX_BOOL bSetting, |
| 1134 | XFA_ATTRIBUTE eAttribute) { |
| 1135 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1136 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1137 | } else { |
| 1138 | CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent); |
| 1139 | if (pParent) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1140 | pValue->Assign( |
| 1141 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pParent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1142 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1143 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1144 | } |
| 1145 | } |
| 1146 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1147 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1148 | void CXFA_Node::Script_TreeClass_Index(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1149 | FX_BOOL bSetting, |
| 1150 | XFA_ATTRIBUTE eAttribute) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1151 | if (bSetting) |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1152 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1153 | else |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1154 | pValue->SetInteger(GetNodeSameNameIndex()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1155 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1156 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1157 | void CXFA_Node::Script_TreeClass_ClassIndex(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1158 | FX_BOOL bSetting, |
| 1159 | XFA_ATTRIBUTE eAttribute) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1160 | if (bSetting) |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1161 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1162 | else |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1163 | pValue->SetInteger(GetNodeSameClassIndex()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1164 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1165 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1166 | void CXFA_Node::Script_TreeClass_SomExpression(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1167 | FX_BOOL bSetting, |
| 1168 | XFA_ATTRIBUTE eAttribute) { |
| 1169 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1170 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1171 | } else { |
| 1172 | CFX_WideString wsSOMExpression; |
| 1173 | GetSOMExpression(wsSOMExpression); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1174 | pValue->SetString(FX_UTF8Encode(wsSOMExpression).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1175 | } |
| 1176 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1177 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1178 | void CXFA_Node::Script_NodeClass_ApplyXSL(CFXJSE_Arguments* pArguments) { |
| 1179 | int32_t iLength = pArguments->GetLength(); |
| 1180 | if (iLength != 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1181 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"applyXSL"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1182 | return; |
| 1183 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1184 | CFX_WideString wsExpression = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1185 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1186 | // TODO(weili): check whether we need to implement this, pdfium:501. |
| 1187 | // For now, just put the variables here to avoid unused variable warning. |
| 1188 | (void)wsExpression; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1189 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1190 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1191 | void CXFA_Node::Script_NodeClass_AssignNode(CFXJSE_Arguments* pArguments) { |
| 1192 | int32_t iLength = pArguments->GetLength(); |
| 1193 | if (iLength < 1 || iLength > 3) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1194 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"assignNode"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1195 | return; |
| 1196 | } |
| 1197 | CFX_WideString wsExpression; |
| 1198 | CFX_WideString wsValue; |
| 1199 | int32_t iAction = 0; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1200 | wsExpression = |
| 1201 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1202 | if (iLength >= 2) { |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1203 | wsValue = |
| 1204 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1205 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1206 | if (iLength >= 3) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1207 | iAction = pArguments->GetInt32(2); |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1208 | // TODO(weili): check whether we need to implement this, pdfium:501. |
| 1209 | // For now, just put the variables here to avoid unused variable warning. |
| 1210 | (void)wsExpression; |
| 1211 | (void)wsValue; |
| 1212 | (void)iAction; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1213 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1214 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1215 | void CXFA_Node::Script_NodeClass_Clone(CFXJSE_Arguments* pArguments) { |
| 1216 | int32_t iLength = pArguments->GetLength(); |
| 1217 | if (iLength != 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1218 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"clone"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1219 | return; |
| 1220 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1221 | bool bClone = !!pArguments->GetInt32(0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1222 | CXFA_Node* pCloneNode = Clone(bClone); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1223 | pArguments->GetReturnValue()->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1224 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pCloneNode)); |
| 1225 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1226 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1227 | void CXFA_Node::Script_NodeClass_GetAttribute(CFXJSE_Arguments* pArguments) { |
| 1228 | int32_t iLength = pArguments->GetLength(); |
| 1229 | if (iLength != 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1230 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getAttribute"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1231 | return; |
| 1232 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1233 | CFX_WideString wsExpression = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1234 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1235 | CFX_WideString wsValue; |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1236 | GetAttribute(wsExpression.AsStringC(), wsValue); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1237 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1238 | if (pValue) |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1239 | pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1240 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1241 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1242 | void CXFA_Node::Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments) { |
| 1243 | int32_t iLength = pArguments->GetLength(); |
| 1244 | if (iLength < 1 || iLength > 2) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1245 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getElement"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1246 | return; |
| 1247 | } |
| 1248 | CFX_WideString wsExpression; |
| 1249 | int32_t iValue = 0; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1250 | wsExpression = |
| 1251 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
| 1252 | if (iLength >= 2) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1253 | iValue = pArguments->GetInt32(1); |
dsinclair | 6e12478 | 2016-06-23 12:14:55 -0700 | [diff] [blame] | 1254 | CXFA_Node* pNode = |
| 1255 | GetProperty(iValue, XFA_GetElementTypeForName(wsExpression.AsStringC())); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1256 | pArguments->GetReturnValue()->Assign( |
| 1257 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1258 | } |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1259 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1260 | void CXFA_Node::Script_NodeClass_IsPropertySpecified( |
| 1261 | CFXJSE_Arguments* pArguments) { |
| 1262 | int32_t iLength = pArguments->GetLength(); |
| 1263 | if (iLength < 1 || iLength > 3) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1264 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isPropertySpecified"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1265 | return; |
| 1266 | } |
| 1267 | CFX_WideString wsExpression; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1268 | bool bParent = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1269 | int32_t iIndex = 0; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1270 | wsExpression = |
| 1271 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1272 | if (iLength >= 2) |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1273 | bParent = !!pArguments->GetInt32(1); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1274 | if (iLength >= 3) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1275 | iIndex = pArguments->GetInt32(2); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1276 | FX_BOOL bHas = FALSE; |
| 1277 | const XFA_ATTRIBUTEINFO* pAttributeInfo = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1278 | XFA_GetAttributeByName(wsExpression.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1279 | CFX_WideString wsValue; |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1280 | if (pAttributeInfo) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1281 | bHas = HasAttribute(pAttributeInfo->eName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1282 | if (!bHas) { |
dsinclair | 6e12478 | 2016-06-23 12:14:55 -0700 | [diff] [blame] | 1283 | XFA_Element eType = XFA_GetElementTypeForName(wsExpression.AsStringC()); |
| 1284 | bHas = !!GetProperty(iIndex, eType); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1285 | if (!bHas && bParent && m_pParent) { |
| 1286 | // Also check on the parent. |
| 1287 | bHas = m_pParent->HasAttribute(pAttributeInfo->eName); |
| 1288 | if (!bHas) |
dsinclair | 6e12478 | 2016-06-23 12:14:55 -0700 | [diff] [blame] | 1289 | bHas = !!m_pParent->GetProperty(iIndex, eType); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1290 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1291 | } |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1292 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
| 1293 | if (pValue) |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1294 | pValue->SetBoolean(bHas); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1295 | } |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1296 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1297 | void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) { |
| 1298 | int32_t iLength = pArguments->GetLength(); |
| 1299 | if (iLength < 1 || iLength > 3) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1300 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"loadXML"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1301 | return; |
| 1302 | } |
| 1303 | CFX_WideString wsExpression; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1304 | bool bIgnoreRoot = true; |
| 1305 | bool bOverwrite = 0; |
| 1306 | wsExpression = |
| 1307 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
| 1308 | if (wsExpression.IsEmpty()) |
Tom Sepez | d3743ea | 2016-05-16 15:56:53 -0700 | [diff] [blame] | 1309 | return; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1310 | if (iLength >= 2) |
| 1311 | bIgnoreRoot = !!pArguments->GetInt32(1); |
| 1312 | if (iLength >= 3) |
| 1313 | bOverwrite = !!pArguments->GetInt32(2); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 1314 | std::unique_ptr<CXFA_SimpleParser> pParser( |
| 1315 | new CXFA_SimpleParser(m_pDocument, false)); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1316 | if (!pParser) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1317 | return; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1318 | CFDE_XMLNode* pXMLNode = nullptr; |
| 1319 | int32_t iParserStatus = |
| 1320 | pParser->ParseXMLData(wsExpression, pXMLNode, nullptr); |
| 1321 | if (iParserStatus != XFA_PARSESTATUS_Done || !pXMLNode) |
| 1322 | return; |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1323 | if (bIgnoreRoot && |
| 1324 | (pXMLNode->GetType() != FDE_XMLNODE_Element || |
| 1325 | XFA_RecognizeRichText(static_cast<CFDE_XMLElement*>(pXMLNode)))) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1326 | bIgnoreRoot = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1327 | } |
| 1328 | CXFA_Node* pFakeRoot = Clone(FALSE); |
| 1329 | CFX_WideStringC wsContentType = GetCData(XFA_ATTRIBUTE_ContentType); |
| 1330 | if (!wsContentType.IsEmpty()) { |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 1331 | pFakeRoot->SetCData(XFA_ATTRIBUTE_ContentType, |
| 1332 | CFX_WideString(wsContentType)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1333 | } |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1334 | CFDE_XMLNode* pFakeXMLRoot = pFakeRoot->GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1335 | if (!pFakeXMLRoot) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1336 | CFDE_XMLNode* pThisXMLRoot = GetXMLMappingNode(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1337 | pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone(FALSE) : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1338 | } |
dsinclair | 017052a | 2016-06-28 07:43:51 -0700 | [diff] [blame] | 1339 | if (!pFakeXMLRoot) |
| 1340 | pFakeXMLRoot = new CFDE_XMLElement(CFX_WideString(GetClassName())); |
| 1341 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1342 | if (bIgnoreRoot) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1343 | CFDE_XMLNode* pXMLChild = pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1344 | while (pXMLChild) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1345 | CFDE_XMLNode* pXMLSibling = |
| 1346 | pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1347 | pXMLNode->RemoveChildNode(pXMLChild); |
| 1348 | pFakeXMLRoot->InsertChildNode(pXMLChild); |
| 1349 | pXMLChild = pXMLSibling; |
| 1350 | } |
| 1351 | } else { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1352 | CFDE_XMLNode* pXMLParent = pXMLNode->GetNodeItem(CFDE_XMLNode::Parent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1353 | if (pXMLParent) { |
| 1354 | pXMLParent->RemoveChildNode(pXMLNode); |
| 1355 | } |
| 1356 | pFakeXMLRoot->InsertChildNode(pXMLNode); |
| 1357 | } |
| 1358 | pParser->ConstructXFANode(pFakeRoot, pFakeXMLRoot); |
| 1359 | pFakeRoot = pParser->GetRootNode(); |
| 1360 | if (pFakeRoot) { |
| 1361 | if (bOverwrite) { |
| 1362 | CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1363 | CXFA_Node* pNewChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1364 | int32_t index = 0; |
| 1365 | while (pNewChild) { |
| 1366 | CXFA_Node* pItem = pNewChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1367 | pFakeRoot->RemoveChild(pNewChild); |
| 1368 | InsertChild(index++, pNewChild); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 1369 | pNewChild->SetFlag(XFA_NodeFlag_Initialized, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1370 | pNewChild = pItem; |
| 1371 | } |
| 1372 | while (pChild) { |
| 1373 | CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1374 | RemoveChild(pChild); |
| 1375 | pFakeRoot->InsertChild(pChild); |
| 1376 | pChild = pItem; |
| 1377 | } |
| 1378 | if (GetPacketID() == XFA_XDPPACKET_Form && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1379 | GetElementType() == XFA_Element::ExData) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1380 | CFDE_XMLNode* pTempXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1381 | SetXMLMappingNode(pFakeXMLRoot); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 1382 | SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1383 | if (pTempXMLNode && !pTempXMLNode->GetNodeItem(CFDE_XMLNode::Parent)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1384 | pFakeXMLRoot = pTempXMLNode; |
| 1385 | } else { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1386 | pFakeXMLRoot = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1387 | } |
| 1388 | } |
| 1389 | MoveBufferMapData(pFakeRoot, this, XFA_CalcData, TRUE); |
| 1390 | } else { |
| 1391 | CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1392 | while (pChild) { |
| 1393 | CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1394 | pFakeRoot->RemoveChild(pChild); |
| 1395 | InsertChild(pChild); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 1396 | pChild->SetFlag(XFA_NodeFlag_Initialized, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1397 | pChild = pItem; |
| 1398 | } |
| 1399 | } |
| 1400 | if (pFakeXMLRoot) { |
| 1401 | pFakeRoot->SetXMLMappingNode(pFakeXMLRoot); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 1402 | pFakeRoot->SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1403 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 1404 | pFakeRoot->SetFlag(XFA_NodeFlag_HasRemovedChildren, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1405 | } else { |
Tom Sepez | d3743ea | 2016-05-16 15:56:53 -0700 | [diff] [blame] | 1406 | if (pFakeXMLRoot) { |
| 1407 | pFakeXMLRoot->Release(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1408 | pFakeXMLRoot = nullptr; |
Tom Sepez | d3743ea | 2016-05-16 15:56:53 -0700 | [diff] [blame] | 1409 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1410 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1411 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1412 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1413 | void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1414 | // TODO(weili): Check whether we need to implement this, pdfium:501. |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) { |
| 1418 | int32_t iLength = pArguments->GetLength(); |
| 1419 | if (iLength < 0 || iLength > 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1420 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"saveXML"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1421 | return; |
| 1422 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1423 | bool bPrettyMode = false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1424 | if (iLength == 1) { |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1425 | if (pArguments->GetUTF8String(0) != "pretty") { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1426 | ThrowException(XFA_IDS_ARGUMENT_MISMATCH); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1427 | return; |
| 1428 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1429 | bPrettyMode = true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1430 | } |
| 1431 | CFX_ByteStringC bsXMLHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1432 | if (GetPacketID() == XFA_XDPPACKET_Form || |
| 1433 | GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 1434 | CFDE_XMLNode* pElement = nullptr; |
| 1435 | if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 1436 | pElement = GetXMLMappingNode(); |
| 1437 | if (!pElement || pElement->GetType() != FDE_XMLNODE_Element) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1438 | pArguments->GetReturnValue()->SetString(bsXMLHeader); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1439 | return; |
| 1440 | } |
| 1441 | XFA_DataExporter_DealWithDataGroupNode(this); |
| 1442 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1443 | std::unique_ptr<IFX_MemoryStream, ReleaseDeleter<IFX_MemoryStream>> |
| 1444 | pMemoryStream(FX_CreateMemoryStream(TRUE)); |
| 1445 | std::unique_ptr<IFX_Stream, ReleaseDeleter<IFX_Stream>> pStream( |
| 1446 | IFX_Stream::CreateStream( |
| 1447 | static_cast<IFX_FileWrite*>(pMemoryStream.get()), |
| 1448 | FX_STREAMACCESS_Text | FX_STREAMACCESS_Write | |
| 1449 | FX_STREAMACCESS_Append)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1450 | if (!pStream) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1451 | pArguments->GetReturnValue()->SetString(bsXMLHeader); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1452 | return; |
| 1453 | } |
| 1454 | pStream->SetCodePage(FX_CODEPAGE_UTF8); |
dsinclair | 179bebb | 2016-04-05 11:02:18 -0700 | [diff] [blame] | 1455 | pStream->WriteData(bsXMLHeader.raw_str(), bsXMLHeader.GetLength()); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1456 | if (GetPacketID() == XFA_XDPPACKET_Form) |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1457 | XFA_DataExporter_RegenerateFormFile(this, pStream.get(), nullptr, TRUE); |
weili | 65be4b1 | 2016-05-25 15:47:43 -0700 | [diff] [blame] | 1458 | else |
| 1459 | pElement->SaveXMLNode(pStream.get()); |
| 1460 | // TODO(weili): Check whether we need to save pretty print XML, pdfium:501. |
| 1461 | // For now, just put it here to avoid unused variable warning. |
| 1462 | (void)bPrettyMode; |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1463 | pArguments->GetReturnValue()->SetString( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1464 | CFX_ByteStringC(pMemoryStream->GetBuffer(), pMemoryStream->GetSize())); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1465 | return; |
| 1466 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1467 | pArguments->GetReturnValue()->SetString(""); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | void CXFA_Node::Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments) { |
| 1471 | int32_t iLength = pArguments->GetLength(); |
| 1472 | if (iLength != 2) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1473 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setAttribute"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1474 | return; |
| 1475 | } |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1476 | CFX_WideString wsAttributeValue = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1477 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringC()); |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 1478 | CFX_WideString wsAttribute = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1479 | CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC()); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1480 | SetAttribute(wsAttribute.AsStringC(), wsAttributeValue.AsStringC(), true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1481 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1482 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1483 | void CXFA_Node::Script_NodeClass_SetElement(CFXJSE_Arguments* pArguments) { |
| 1484 | int32_t iLength = pArguments->GetLength(); |
| 1485 | if (iLength != 1 && iLength != 2) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1486 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setElement"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1487 | return; |
| 1488 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1489 | CXFA_Node* pNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1490 | CFX_WideString wsName; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1491 | pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); |
| 1492 | if (iLength == 2) |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1493 | wsName = CFX_WideString::FromUTF8(pArguments->GetUTF8String(1).AsStringC()); |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1494 | // TODO(weili): check whether we need to implement this, pdfium:501. |
| 1495 | // For now, just put the variables here to avoid unused variable warning. |
| 1496 | (void)pNode; |
| 1497 | (void)wsName; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1498 | } |
weili | 60607c3 | 2016-05-26 11:53:12 -0700 | [diff] [blame] | 1499 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1500 | void CXFA_Node::Script_NodeClass_Ns(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1501 | FX_BOOL bSetting, |
| 1502 | XFA_ATTRIBUTE eAttribute) { |
| 1503 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1504 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1505 | } else { |
| 1506 | CFX_WideString wsNameSpace; |
| 1507 | TryNamespace(wsNameSpace); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1508 | pValue->SetString(FX_UTF8Encode(wsNameSpace).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1509 | } |
| 1510 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1511 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1512 | void CXFA_Node::Script_NodeClass_Model(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1513 | FX_BOOL bSetting, |
| 1514 | XFA_ATTRIBUTE eAttribute) { |
| 1515 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1516 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1517 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1518 | pValue->Assign( |
| 1519 | m_pDocument->GetScriptContext()->GetJSValueFromMap(GetModelNode())); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1520 | } |
| 1521 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1522 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1523 | void CXFA_Node::Script_NodeClass_IsContainer(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1524 | FX_BOOL bSetting, |
| 1525 | XFA_ATTRIBUTE eAttribute) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1526 | if (bSetting) |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1527 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1528 | else |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1529 | pValue->SetBoolean(IsContainerNode()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1530 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1531 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1532 | void CXFA_Node::Script_NodeClass_IsNull(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1533 | FX_BOOL bSetting, |
| 1534 | XFA_ATTRIBUTE eAttribute) { |
| 1535 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1536 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1537 | } else { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1538 | if (GetElementType() == XFA_Element::Subform) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1539 | pValue->SetBoolean(FALSE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1540 | return; |
| 1541 | } |
| 1542 | CFX_WideString strValue; |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1543 | pValue->SetBoolean(!TryContent(strValue) || strValue.IsEmpty()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1544 | } |
| 1545 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1546 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1547 | void CXFA_Node::Script_NodeClass_OneOfChild(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1548 | FX_BOOL bSetting, |
| 1549 | XFA_ATTRIBUTE eAttribute) { |
| 1550 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1551 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1552 | } else { |
| 1553 | CXFA_NodeArray properts; |
| 1554 | int32_t iSize = GetNodeList(properts, XFA_NODEFILTER_OneOfProperty); |
| 1555 | if (iSize > 0) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1556 | pValue->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1557 | m_pDocument->GetScriptContext()->GetJSValueFromMap(properts[0])); |
| 1558 | } |
| 1559 | } |
| 1560 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1561 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1562 | void CXFA_Node::Script_ContainerClass_GetDelta(CFXJSE_Arguments* pArguments) {} |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1563 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1564 | void CXFA_Node::Script_ContainerClass_GetDeltas(CFXJSE_Arguments* pArguments) { |
| 1565 | CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1566 | pArguments->GetReturnValue()->SetObject( |
| 1567 | pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1568 | } |
| 1569 | void CXFA_Node::Script_ModelClass_ClearErrorList(CFXJSE_Arguments* pArguments) { |
| 1570 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1571 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1572 | void CXFA_Node::Script_ModelClass_CreateNode(CFXJSE_Arguments* pArguments) { |
| 1573 | Script_Template_CreateNode(pArguments); |
| 1574 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1575 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1576 | void CXFA_Node::Script_ModelClass_IsCompatibleNS(CFXJSE_Arguments* pArguments) { |
| 1577 | int32_t iLength = pArguments->GetLength(); |
| 1578 | if (iLength < 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1579 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isCompatibleNS"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1580 | return; |
| 1581 | } |
| 1582 | CFX_WideString wsNameSpace; |
| 1583 | if (iLength >= 1) { |
| 1584 | CFX_ByteString bsNameSpace = pArguments->GetUTF8String(0); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1585 | wsNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1586 | } |
| 1587 | CFX_WideString wsNodeNameSpace; |
| 1588 | TryNamespace(wsNodeNameSpace); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1589 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1590 | if (pValue) |
| 1591 | pValue->SetBoolean(wsNodeNameSpace == wsNameSpace); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1592 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1593 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1594 | void CXFA_Node::Script_ModelClass_Context(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1595 | FX_BOOL bSetting, |
| 1596 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1597 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1598 | void CXFA_Node::Script_ModelClass_AliasNode(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1599 | FX_BOOL bSetting, |
| 1600 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1601 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1602 | void CXFA_Node::Script_Attribute_Integer(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1603 | FX_BOOL bSetting, |
| 1604 | XFA_ATTRIBUTE eAttribute) { |
| 1605 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1606 | SetInteger(eAttribute, pValue->ToInteger(), true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1607 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1608 | pValue->SetInteger(GetInteger(eAttribute)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1609 | } |
| 1610 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1611 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1612 | void CXFA_Node::Script_Attribute_IntegerRead(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1613 | FX_BOOL bSetting, |
| 1614 | XFA_ATTRIBUTE eAttribute) { |
| 1615 | if (!bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1616 | pValue->SetInteger(GetInteger(eAttribute)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1617 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1618 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1619 | } |
| 1620 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1621 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1622 | void CXFA_Node::Script_Attribute_BOOL(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1623 | FX_BOOL bSetting, |
| 1624 | XFA_ATTRIBUTE eAttribute) { |
| 1625 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1626 | SetBoolean(eAttribute, pValue->ToBoolean(), true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1627 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1628 | pValue->SetString(GetBoolean(eAttribute) ? "1" : "0"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1629 | } |
| 1630 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1631 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1632 | void CXFA_Node::Script_Attribute_BOOLRead(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1633 | FX_BOOL bSetting, |
| 1634 | XFA_ATTRIBUTE eAttribute) { |
| 1635 | if (!bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1636 | pValue->SetString(GetBoolean(eAttribute) ? "1" : "0"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1637 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1638 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1639 | } |
| 1640 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1641 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1642 | void CXFA_Node::Script_Attribute_SendAttributeChangeMessage( |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1643 | XFA_ATTRIBUTE eAttribute, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1644 | FX_BOOL bScriptModify) { |
| 1645 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1646 | if (!pLayoutPro) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1647 | return; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1648 | |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 1649 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1650 | if (!pNotify) |
| 1651 | return; |
| 1652 | |
| 1653 | uint32_t dwPacket = GetPacketID(); |
| 1654 | if (!(dwPacket & XFA_XDPPACKET_Form)) { |
| 1655 | pNotify->OnValueChanged(this, eAttribute, this, this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1656 | return; |
| 1657 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1658 | |
| 1659 | bool bNeedFindContainer = false; |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1660 | switch (GetElementType()) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1661 | case XFA_Element::Caption: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1662 | bNeedFindContainer = true; |
| 1663 | pNotify->OnValueChanged(this, eAttribute, this, |
| 1664 | GetNodeItem(XFA_NODEITEM_Parent)); |
| 1665 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1666 | case XFA_Element::Font: |
| 1667 | case XFA_Element::Para: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1668 | bNeedFindContainer = true; |
| 1669 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1670 | if (pParentNode->GetElementType() == XFA_Element::Caption) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1671 | pNotify->OnValueChanged(this, eAttribute, pParentNode, |
| 1672 | pParentNode->GetNodeItem(XFA_NODEITEM_Parent)); |
| 1673 | } else { |
| 1674 | pNotify->OnValueChanged(this, eAttribute, this, pParentNode); |
| 1675 | } |
| 1676 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1677 | case XFA_Element::Margin: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1678 | bNeedFindContainer = true; |
| 1679 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1680 | XFA_Element eParentType = pParentNode->GetElementType(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1681 | if (pParentNode->IsContainerNode()) { |
| 1682 | pNotify->OnValueChanged(this, eAttribute, this, pParentNode); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1683 | } else if (eParentType == XFA_Element::Caption) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1684 | pNotify->OnValueChanged(this, eAttribute, pParentNode, |
| 1685 | pParentNode->GetNodeItem(XFA_NODEITEM_Parent)); |
| 1686 | } else { |
| 1687 | CXFA_Node* pNode = pParentNode->GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1688 | if (pNode && pNode->GetElementType() == XFA_Element::Ui) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1689 | pNotify->OnValueChanged(this, eAttribute, pNode, |
| 1690 | pNode->GetNodeItem(XFA_NODEITEM_Parent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1691 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1692 | } |
| 1693 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1694 | case XFA_Element::Comb: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1695 | CXFA_Node* pEditNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1696 | XFA_Element eUIType = pEditNode->GetElementType(); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1697 | if (pEditNode && (eUIType == XFA_Element::DateTimeEdit || |
| 1698 | eUIType == XFA_Element::NumericEdit || |
| 1699 | eUIType == XFA_Element::TextEdit)) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1700 | CXFA_Node* pUINode = pEditNode->GetNodeItem(XFA_NODEITEM_Parent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1701 | if (pUINode) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1702 | pNotify->OnValueChanged(this, eAttribute, pUINode, |
| 1703 | pUINode->GetNodeItem(XFA_NODEITEM_Parent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1704 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1705 | } |
| 1706 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1707 | case XFA_Element::Button: |
| 1708 | case XFA_Element::Barcode: |
| 1709 | case XFA_Element::ChoiceList: |
| 1710 | case XFA_Element::DateTimeEdit: |
| 1711 | case XFA_Element::NumericEdit: |
| 1712 | case XFA_Element::PasswordEdit: |
| 1713 | case XFA_Element::TextEdit: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1714 | CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent); |
| 1715 | if (pUINode) { |
| 1716 | pNotify->OnValueChanged(this, eAttribute, pUINode, |
| 1717 | pUINode->GetNodeItem(XFA_NODEITEM_Parent)); |
| 1718 | } |
| 1719 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1720 | case XFA_Element::CheckButton: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1721 | bNeedFindContainer = true; |
| 1722 | CXFA_Node* pUINode = GetNodeItem(XFA_NODEITEM_Parent); |
| 1723 | if (pUINode) { |
| 1724 | pNotify->OnValueChanged(this, eAttribute, pUINode, |
| 1725 | pUINode->GetNodeItem(XFA_NODEITEM_Parent)); |
| 1726 | } |
| 1727 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1728 | case XFA_Element::Keep: |
| 1729 | case XFA_Element::Bookend: |
| 1730 | case XFA_Element::Break: |
| 1731 | case XFA_Element::BreakAfter: |
| 1732 | case XFA_Element::BreakBefore: |
| 1733 | case XFA_Element::Overflow: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1734 | bNeedFindContainer = true; |
| 1735 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1736 | case XFA_Element::Area: |
| 1737 | case XFA_Element::Draw: |
| 1738 | case XFA_Element::ExclGroup: |
| 1739 | case XFA_Element::Field: |
| 1740 | case XFA_Element::Subform: |
| 1741 | case XFA_Element::SubformSet: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1742 | pLayoutPro->AddChangedContainer(this); |
| 1743 | pNotify->OnValueChanged(this, eAttribute, this, this); |
| 1744 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1745 | case XFA_Element::Sharptext: |
| 1746 | case XFA_Element::Sharpxml: |
| 1747 | case XFA_Element::SharpxHTML: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1748 | CXFA_Node* pTextNode = GetNodeItem(XFA_NODEITEM_Parent); |
| 1749 | if (!pTextNode) { |
| 1750 | return; |
| 1751 | } |
| 1752 | CXFA_Node* pValueNode = pTextNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 1753 | if (!pValueNode) { |
| 1754 | return; |
| 1755 | } |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1756 | XFA_Element eType = pValueNode->GetElementType(); |
| 1757 | if (eType == XFA_Element::Value) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1758 | bNeedFindContainer = true; |
| 1759 | CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 1760 | if (pNode && pNode->IsContainerNode()) { |
| 1761 | if (bScriptModify) { |
| 1762 | pValueNode = pNode; |
| 1763 | } |
| 1764 | pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode); |
| 1765 | } else { |
| 1766 | pNotify->OnValueChanged(this, eAttribute, pNode, |
| 1767 | pNode->GetNodeItem(XFA_NODEITEM_Parent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1768 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1769 | } else { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1770 | if (eType == XFA_Element::Items) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1771 | CXFA_Node* pNode = pValueNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 1772 | if (pNode && pNode->IsContainerNode()) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1773 | pNotify->OnValueChanged(this, eAttribute, pValueNode, pNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1774 | } |
| 1775 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1776 | } |
| 1777 | } break; |
| 1778 | default: |
| 1779 | break; |
| 1780 | } |
| 1781 | if (bNeedFindContainer) { |
| 1782 | CXFA_Node* pParent = this; |
| 1783 | while (pParent) { |
| 1784 | if (pParent->IsContainerNode()) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1785 | break; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1786 | |
| 1787 | pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1788 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1789 | if (pParent) { |
| 1790 | pLayoutPro->AddChangedContainer(pParent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1791 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1792 | } |
| 1793 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1794 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1795 | void CXFA_Node::Script_Attribute_String(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1796 | FX_BOOL bSetting, |
| 1797 | XFA_ATTRIBUTE eAttribute) { |
| 1798 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1799 | CFX_WideString wsValue = pValue->ToWideString(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 1800 | SetAttribute(eAttribute, wsValue.AsStringC(), true); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 1801 | if (eAttribute == XFA_ATTRIBUTE_Use && |
| 1802 | GetElementType() == XFA_Element::Desc) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1803 | CXFA_Node* pTemplateNode = |
| 1804 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template)); |
| 1805 | CXFA_Node* pProtoRoot = |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 1806 | pTemplateNode->GetFirstChildByClass(XFA_Element::Subform) |
| 1807 | ->GetFirstChildByClass(XFA_Element::Proto); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1808 | |
| 1809 | CFX_WideString wsID; |
| 1810 | CFX_WideString wsSOM; |
| 1811 | if (!wsValue.IsEmpty()) { |
| 1812 | if (wsValue[0] == '#') { |
| 1813 | wsID = CFX_WideString(wsValue.c_str() + 1, wsValue.GetLength() - 1); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1814 | } else { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1815 | wsSOM = wsValue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1816 | } |
| 1817 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 1818 | CXFA_Node* pProtoNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1819 | if (!wsSOM.IsEmpty()) { |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1820 | uint32_t dwFlag = XFA_RESOLVENODE_Children | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1821 | XFA_RESOLVENODE_Attributes | |
| 1822 | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | |
| 1823 | XFA_RESOLVENODE_Siblings; |
| 1824 | XFA_RESOLVENODE_RS resoveNodeRS; |
| 1825 | int32_t iRet = m_pDocument->GetScriptContext()->ResolveObjects( |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1826 | pProtoRoot, wsSOM.AsStringC(), resoveNodeRS, dwFlag); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1827 | if (iRet > 0 && resoveNodeRS.nodes[0]->IsNode()) { |
| 1828 | pProtoNode = resoveNodeRS.nodes[0]->AsNode(); |
| 1829 | } |
| 1830 | } else if (!wsID.IsEmpty()) { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1831 | pProtoNode = m_pDocument->GetNodeByID(pProtoRoot, wsID.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1832 | } |
| 1833 | if (pProtoNode) { |
| 1834 | CXFA_Node* pHeadChild = GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1835 | while (pHeadChild) { |
| 1836 | CXFA_Node* pSibling = |
| 1837 | pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1838 | RemoveChild(pHeadChild); |
| 1839 | pHeadChild = pSibling; |
| 1840 | } |
| 1841 | CXFA_Node* pProtoForm = pProtoNode->CloneTemplateToForm(TRUE); |
| 1842 | pHeadChild = pProtoForm->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1843 | while (pHeadChild) { |
| 1844 | CXFA_Node* pSibling = |
| 1845 | pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1846 | pProtoForm->RemoveChild(pHeadChild); |
| 1847 | InsertChild(pHeadChild); |
| 1848 | pHeadChild = pSibling; |
| 1849 | } |
| 1850 | m_pDocument->RemovePurgeNode(pProtoForm); |
| 1851 | delete pProtoForm; |
| 1852 | } |
| 1853 | } |
| 1854 | } else { |
| 1855 | CFX_WideString wsValue; |
| 1856 | GetAttribute(eAttribute, wsValue); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1857 | pValue->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 1858 | FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1859 | } |
| 1860 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1861 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1862 | void CXFA_Node::Script_Attribute_StringRead(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1863 | FX_BOOL bSetting, |
| 1864 | XFA_ATTRIBUTE eAttribute) { |
| 1865 | if (!bSetting) { |
| 1866 | CFX_WideString wsValue; |
| 1867 | GetAttribute(eAttribute, wsValue); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1868 | pValue->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 1869 | FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1870 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1871 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1872 | } |
| 1873 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1874 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1875 | void CXFA_Node::Script_WsdlConnection_Execute(CFXJSE_Arguments* pArguments) { |
| 1876 | int32_t argc = pArguments->GetLength(); |
| 1877 | if ((argc == 0) || (argc == 1)) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1878 | pArguments->GetReturnValue()->SetBoolean(FALSE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1879 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1880 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execute"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1881 | } |
| 1882 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1883 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1884 | void CXFA_Node::Script_Delta_Restore(CFXJSE_Arguments* pArguments) { |
| 1885 | int32_t argc = pArguments->GetLength(); |
| 1886 | if (argc == 0) { |
| 1887 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1888 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"restore"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1889 | } |
| 1890 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1891 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1892 | void CXFA_Node::Script_Delta_CurrentValue(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1893 | FX_BOOL bSetting, |
| 1894 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1895 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1896 | void CXFA_Node::Script_Delta_SavedValue(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1897 | FX_BOOL bSetting, |
| 1898 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1899 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1900 | void CXFA_Node::Script_Delta_Target(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1901 | FX_BOOL bSetting, |
| 1902 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1903 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1904 | void CXFA_Node::Script_Som_Message(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1905 | FX_BOOL bSetting, |
| 1906 | XFA_SOM_MESSAGETYPE iMessageType) { |
| 1907 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 1908 | if (!pWidgetData) { |
| 1909 | return; |
| 1910 | } |
| 1911 | FX_BOOL bNew = FALSE; |
| 1912 | CXFA_Validate validate = pWidgetData->GetValidate(); |
| 1913 | if (!validate) { |
| 1914 | validate = pWidgetData->GetValidate(TRUE); |
| 1915 | bNew = TRUE; |
| 1916 | } |
| 1917 | if (bSetting) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1918 | switch (iMessageType) { |
| 1919 | case XFA_SOM_ValidationMessage: |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1920 | validate.SetScriptMessageText(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1921 | break; |
| 1922 | case XFA_SOM_FormatMessage: |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1923 | validate.SetFormatMessageText(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1924 | break; |
| 1925 | case XFA_SOM_MandatoryMessage: |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1926 | validate.SetNullMessageText(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1927 | break; |
| 1928 | default: |
| 1929 | break; |
| 1930 | } |
| 1931 | if (!bNew) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 1932 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1933 | if (!pNotify) { |
| 1934 | return; |
| 1935 | } |
| 1936 | pNotify->AddCalcValidate(this); |
| 1937 | } |
| 1938 | } else { |
| 1939 | CFX_WideString wsMessage; |
| 1940 | switch (iMessageType) { |
| 1941 | case XFA_SOM_ValidationMessage: |
| 1942 | validate.GetScriptMessageText(wsMessage); |
| 1943 | break; |
| 1944 | case XFA_SOM_FormatMessage: |
| 1945 | validate.GetFormatMessageText(wsMessage); |
| 1946 | break; |
| 1947 | case XFA_SOM_MandatoryMessage: |
| 1948 | validate.GetNullMessageText(wsMessage); |
| 1949 | break; |
| 1950 | default: |
| 1951 | break; |
| 1952 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1953 | pValue->SetString(FX_UTF8Encode(wsMessage).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1954 | } |
| 1955 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1956 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1957 | void CXFA_Node::Script_Som_ValidationMessage(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1958 | FX_BOOL bSetting, |
| 1959 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1960 | Script_Som_Message(pValue, bSetting, XFA_SOM_ValidationMessage); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1961 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1962 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1963 | void CXFA_Node::Script_Field_Length(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1964 | FX_BOOL bSetting, |
| 1965 | XFA_ATTRIBUTE eAttribute) { |
| 1966 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 1967 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1968 | } else { |
| 1969 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 1970 | if (!pWidgetData) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1971 | pValue->SetInteger(0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1972 | return; |
| 1973 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1974 | pValue->SetInteger(pWidgetData->CountChoiceListItems(TRUE)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1975 | } |
| 1976 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 1977 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1978 | void CXFA_Node::Script_Som_DefaultValue(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1979 | FX_BOOL bSetting, |
| 1980 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1981 | XFA_Element eType = GetElementType(); |
| 1982 | if (eType == XFA_Element::Field) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1983 | Script_Field_DefaultValue(pValue, bSetting, eAttribute); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1984 | return; |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1985 | } |
| 1986 | if (eType == XFA_Element::Draw) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1987 | Script_Draw_DefaultValue(pValue, bSetting, eAttribute); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1988 | return; |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 1989 | } |
| 1990 | if (eType == XFA_Element::Boolean) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 1991 | Script_Boolean_Value(pValue, bSetting, eAttribute); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1992 | return; |
| 1993 | } |
| 1994 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1995 | CFX_WideString wsNewValue; |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 1996 | if (!(pValue && (pValue->IsNull() || pValue->IsUndefined()))) |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 1997 | wsNewValue = pValue->ToWideString(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 1998 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1999 | CFX_WideString wsFormatValue(wsNewValue); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 2000 | CXFA_WidgetData* pContainerWidgetData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2001 | if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 2002 | CXFA_NodeArray formNodes; |
| 2003 | GetBindItems(formNodes); |
| 2004 | CFX_WideString wsPicture; |
| 2005 | for (int32_t i = 0; i < formNodes.GetSize(); i++) { |
| 2006 | CXFA_Node* pFormNode = formNodes.GetAt(i); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 2007 | if (!pFormNode || pFormNode->HasRemovedChildren()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2008 | continue; |
| 2009 | } |
| 2010 | pContainerWidgetData = pFormNode->GetContainerWidgetData(); |
| 2011 | if (pContainerWidgetData) { |
| 2012 | pContainerWidgetData->GetPictureContent(wsPicture, |
| 2013 | XFA_VALUEPICTURE_DataBind); |
| 2014 | } |
| 2015 | if (!wsPicture.IsEmpty()) { |
| 2016 | break; |
| 2017 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 2018 | pContainerWidgetData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2019 | } |
| 2020 | } else if (GetPacketID() == XFA_XDPPACKET_Form) { |
| 2021 | pContainerWidgetData = GetContainerWidgetData(); |
| 2022 | } |
| 2023 | if (pContainerWidgetData) { |
tsepez | 6f167c3 | 2016-04-14 15:46:27 -0700 | [diff] [blame] | 2024 | pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2025 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 2026 | SetScriptContent(wsNewValue, wsFormatValue, true, TRUE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2027 | } else { |
| 2028 | CFX_WideString content = GetScriptContent(TRUE); |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 2029 | if (content.IsEmpty() && eType != XFA_Element::Text && |
| 2030 | eType != XFA_Element::SubmitUrl) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2031 | pValue->SetNull(); |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 2032 | } else if (eType == XFA_Element::Integer) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2033 | pValue->SetInteger(FXSYS_wtoi(content.c_str())); |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 2034 | } else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2035 | CFX_Decimal decimal(content.AsStringC()); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2036 | pValue->SetFloat((FX_FLOAT)(double)decimal); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2037 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2038 | pValue->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 2039 | FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2040 | } |
| 2041 | } |
| 2042 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2043 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2044 | void CXFA_Node::Script_Som_DefaultValue_Read(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2045 | FX_BOOL bSetting, |
| 2046 | XFA_ATTRIBUTE eAttribute) { |
| 2047 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2048 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2049 | return; |
| 2050 | } |
| 2051 | CFX_WideString content = GetScriptContent(TRUE); |
| 2052 | if (content.IsEmpty()) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2053 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2054 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2055 | pValue->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 2056 | FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2057 | } |
| 2058 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2059 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2060 | void CXFA_Node::Script_Boolean_Value(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2061 | FX_BOOL bSetting, |
| 2062 | XFA_ATTRIBUTE eAttribute) { |
| 2063 | if (bSetting) { |
| 2064 | CFX_ByteString newValue; |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 2065 | if (!(pValue && (pValue->IsNull() || pValue->IsUndefined()))) |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2066 | newValue = pValue->ToString(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2067 | |
tsepez | b4c9f3f | 2016-04-13 15:41:21 -0700 | [diff] [blame] | 2068 | int32_t iValue = FXSYS_atoi(newValue.c_str()); |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 2069 | CFX_WideString wsNewValue(iValue == 0 ? L"0" : L"1"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2070 | CFX_WideString wsFormatValue(wsNewValue); |
| 2071 | CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData(); |
| 2072 | if (pContainerWidgetData) { |
tsepez | 6f167c3 | 2016-04-14 15:46:27 -0700 | [diff] [blame] | 2073 | pContainerWidgetData->GetFormatDataValue(wsNewValue, wsFormatValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2074 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 2075 | SetScriptContent(wsNewValue, wsFormatValue, true, TRUE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2076 | } else { |
| 2077 | CFX_WideString wsValue = GetScriptContent(TRUE); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2078 | pValue->SetBoolean(wsValue == FX_WSTRC(L"1")); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2079 | } |
| 2080 | } |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2081 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2082 | void CXFA_Node::Script_Som_BorderColor(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2083 | FX_BOOL bSetting, |
| 2084 | XFA_ATTRIBUTE eAttribute) { |
| 2085 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2086 | if (!pWidgetData) { |
| 2087 | return; |
| 2088 | } |
| 2089 | CXFA_Border border = pWidgetData->GetBorder(TRUE); |
| 2090 | int32_t iSize = border.CountEdges(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2091 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2092 | int32_t r = 0; |
| 2093 | int32_t g = 0; |
| 2094 | int32_t b = 0; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2095 | StrToRGB(pValue->ToWideString(), r, g, b); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2096 | FX_ARGB rgb = ArgbEncode(100, r, g, b); |
| 2097 | for (int32_t i = 0; i < iSize; ++i) { |
| 2098 | CXFA_Edge edge = border.GetEdge(i); |
| 2099 | edge.SetColor(rgb); |
| 2100 | } |
| 2101 | } else { |
| 2102 | CXFA_Edge edge = border.GetEdge(0); |
| 2103 | FX_ARGB color = edge.GetColor(); |
| 2104 | int32_t a, r, g, b; |
| 2105 | ArgbDecode(color, a, r, g, b); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2106 | CFX_WideString strColor; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2107 | strColor.Format(L"%d,%d,%d", r, g, b); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2108 | pValue->SetString(FX_UTF8Encode(strColor).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2109 | } |
| 2110 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2111 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2112 | void CXFA_Node::Script_Som_BorderWidth(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2113 | FX_BOOL bSetting, |
| 2114 | XFA_ATTRIBUTE eAttribute) { |
| 2115 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2116 | if (!pWidgetData) { |
| 2117 | return; |
| 2118 | } |
| 2119 | CXFA_Border border = pWidgetData->GetBorder(TRUE); |
| 2120 | int32_t iSize = border.CountEdges(); |
| 2121 | CFX_WideString wsThickness; |
| 2122 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2123 | wsThickness = pValue->ToWideString(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2124 | for (int32_t i = 0; i < iSize; ++i) { |
| 2125 | CXFA_Edge edge = border.GetEdge(i); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2126 | CXFA_Measurement thickness(wsThickness.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2127 | edge.SetMSThickness(thickness); |
| 2128 | } |
| 2129 | } else { |
| 2130 | CXFA_Edge edge = border.GetEdge(0); |
| 2131 | CXFA_Measurement thickness = edge.GetMSThickness(); |
| 2132 | thickness.ToString(wsThickness); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2133 | pValue->SetString(FX_UTF8Encode(wsThickness).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2134 | } |
| 2135 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2136 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2137 | void CXFA_Node::Script_Som_FillColor(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2138 | FX_BOOL bSetting, |
| 2139 | XFA_ATTRIBUTE eAttribute) { |
| 2140 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2141 | if (!pWidgetData) { |
| 2142 | return; |
| 2143 | } |
| 2144 | CXFA_Border border = pWidgetData->GetBorder(TRUE); |
| 2145 | CXFA_Fill borderfill = border.GetFill(TRUE); |
| 2146 | CXFA_Node* pNode = borderfill.GetNode(); |
| 2147 | if (!pNode) { |
| 2148 | return; |
| 2149 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2150 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2151 | int32_t r; |
| 2152 | int32_t g; |
| 2153 | int32_t b; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2154 | StrToRGB(pValue->ToWideString(), r, g, b); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2155 | FX_ARGB color = ArgbEncode(0xff, r, g, b); |
| 2156 | borderfill.SetColor(color); |
| 2157 | } else { |
| 2158 | FX_ARGB color = borderfill.GetColor(); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2159 | int32_t a; |
| 2160 | int32_t r; |
| 2161 | int32_t g; |
| 2162 | int32_t b; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2163 | ArgbDecode(color, a, r, g, b); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2164 | CFX_WideString wsColor; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2165 | wsColor.Format(L"%d,%d,%d", r, g, b); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2166 | pValue->SetString(FX_UTF8Encode(wsColor).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2167 | } |
| 2168 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2169 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2170 | void CXFA_Node::Script_Som_DataNode(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2171 | FX_BOOL bSetting, |
| 2172 | XFA_ATTRIBUTE eAttribute) { |
| 2173 | if (!bSetting) { |
| 2174 | CXFA_Node* pDataNode = GetBindData(); |
| 2175 | if (pDataNode) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2176 | pValue->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2177 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pDataNode)); |
| 2178 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2179 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2180 | } |
| 2181 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2182 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2183 | } |
| 2184 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2185 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2186 | void CXFA_Node::Script_Draw_DefaultValue(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2187 | FX_BOOL bSetting, |
| 2188 | XFA_ATTRIBUTE eAttribute) { |
| 2189 | if (bSetting) { |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 2190 | if (pValue && pValue->IsString()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2191 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 2192 | ASSERT(pWidgetData); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 2193 | XFA_Element uiType = pWidgetData->GetUIType(); |
| 2194 | if (uiType == XFA_Element::Text) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2195 | CFX_WideString wsNewValue = pValue->ToWideString(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2196 | CFX_WideString wsFormatValue(wsNewValue); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 2197 | SetScriptContent(wsNewValue, wsFormatValue, true, TRUE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2198 | } |
| 2199 | } |
| 2200 | } else { |
| 2201 | CFX_WideString content = GetScriptContent(TRUE); |
| 2202 | if (content.IsEmpty()) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2203 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2204 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2205 | pValue->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 2206 | FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2207 | } |
| 2208 | } |
| 2209 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2210 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2211 | void CXFA_Node::Script_Field_DefaultValue(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2212 | FX_BOOL bSetting, |
| 2213 | XFA_ATTRIBUTE eAttribute) { |
| 2214 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2215 | if (!pWidgetData) { |
| 2216 | return; |
| 2217 | } |
| 2218 | if (bSetting) { |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 2219 | if (pValue && pValue->IsNull()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2220 | pWidgetData->m_bPreNull = pWidgetData->m_bIsNull; |
| 2221 | pWidgetData->m_bIsNull = TRUE; |
| 2222 | } else { |
| 2223 | pWidgetData->m_bPreNull = pWidgetData->m_bIsNull; |
| 2224 | pWidgetData->m_bIsNull = FALSE; |
| 2225 | } |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2226 | CFX_WideString wsNewText; |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame] | 2227 | if (!(pValue && (pValue->IsNull() || pValue->IsUndefined()))) |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2228 | wsNewText = pValue->ToWideString(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2229 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2230 | CXFA_Node* pUIChild = pWidgetData->GetUIChild(); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2231 | if (pUIChild->GetElementType() == XFA_Element::NumericEdit) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2232 | int32_t iLeadDigits = 0; |
| 2233 | int32_t iFracDigits = 0; |
| 2234 | pWidgetData->GetLeadDigits(iLeadDigits); |
| 2235 | pWidgetData->GetFracDigits(iFracDigits); |
dsinclair | 44d054c | 2016-04-06 10:23:46 -0700 | [diff] [blame] | 2236 | wsNewText = |
| 2237 | pWidgetData->NumericLimit(wsNewText, iLeadDigits, iFracDigits); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2238 | } |
| 2239 | CXFA_WidgetData* pContainerWidgetData = GetContainerWidgetData(); |
| 2240 | CFX_WideString wsFormatText(wsNewText); |
| 2241 | if (pContainerWidgetData) { |
tsepez | 6f167c3 | 2016-04-14 15:46:27 -0700 | [diff] [blame] | 2242 | pContainerWidgetData->GetFormatDataValue(wsNewText, wsFormatText); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2243 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 2244 | SetScriptContent(wsNewText, wsFormatText, true, TRUE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2245 | } else { |
| 2246 | CFX_WideString content = GetScriptContent(TRUE); |
| 2247 | if (content.IsEmpty()) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2248 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2249 | } else { |
| 2250 | CXFA_Node* pUIChild = pWidgetData->GetUIChild(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2251 | CXFA_Value defVal = pWidgetData->GetFormValue(); |
| 2252 | CXFA_Node* pNode = defVal.GetNode()->GetNodeItem(XFA_NODEITEM_FirstChild); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2253 | if (pNode && pNode->GetElementType() == XFA_Element::Decimal) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 2254 | if (pUIChild->GetElementType() == XFA_Element::NumericEdit && |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2255 | (pNode->GetInteger(XFA_ATTRIBUTE_FracDigits) == -1)) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2256 | pValue->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 2257 | FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2258 | } else { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2259 | CFX_Decimal decimal(content.AsStringC()); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2260 | pValue->SetFloat((FX_FLOAT)(double)decimal); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2261 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2262 | } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2263 | pValue->SetInteger(FXSYS_wtoi(content.c_str())); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2264 | } else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2265 | pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? FALSE : TRUE); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2266 | } else if (pNode && pNode->GetElementType() == XFA_Element::Float) { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2267 | CFX_Decimal decimal(content.AsStringC()); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2268 | pValue->SetFloat((FX_FLOAT)(double)decimal); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2269 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2270 | pValue->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 2271 | FX_UTF8Encode(content.c_str(), content.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2272 | } |
| 2273 | } |
| 2274 | } |
| 2275 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2276 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2277 | void CXFA_Node::Script_Field_EditValue(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2278 | FX_BOOL bSetting, |
| 2279 | XFA_ATTRIBUTE eAttribute) { |
| 2280 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2281 | if (!pWidgetData) { |
| 2282 | return; |
| 2283 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2284 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2285 | pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Edit); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2286 | } else { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2287 | CFX_WideString wsValue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2288 | pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Edit); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2289 | pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2290 | } |
| 2291 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2292 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2293 | void CXFA_Node::Script_Som_FontColor(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2294 | FX_BOOL bSetting, |
| 2295 | XFA_ATTRIBUTE eAttribute) { |
| 2296 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2297 | if (!pWidgetData) { |
| 2298 | return; |
| 2299 | } |
| 2300 | CXFA_Font font = pWidgetData->GetFont(TRUE); |
| 2301 | CXFA_Node* pNode = font.GetNode(); |
| 2302 | if (!pNode) { |
| 2303 | return; |
| 2304 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2305 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2306 | int32_t r; |
| 2307 | int32_t g; |
| 2308 | int32_t b; |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2309 | StrToRGB(pValue->ToWideString(), r, g, b); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2310 | FX_ARGB color = ArgbEncode(0xff, r, g, b); |
| 2311 | font.SetColor(color); |
| 2312 | } else { |
| 2313 | FX_ARGB color = font.GetColor(); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2314 | int32_t a; |
| 2315 | int32_t r; |
| 2316 | int32_t g; |
| 2317 | int32_t b; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2318 | ArgbDecode(color, a, r, g, b); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2319 | CFX_WideString wsColor; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2320 | wsColor.Format(L"%d,%d,%d", r, g, b); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2321 | pValue->SetString(FX_UTF8Encode(wsColor).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2322 | } |
| 2323 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2324 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2325 | void CXFA_Node::Script_Field_FormatMessage(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2326 | FX_BOOL bSetting, |
| 2327 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2328 | Script_Som_Message(pValue, bSetting, XFA_SOM_FormatMessage); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2329 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2330 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2331 | void CXFA_Node::Script_Field_FormattedValue(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2332 | FX_BOOL bSetting, |
| 2333 | XFA_ATTRIBUTE eAttribute) { |
| 2334 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2335 | if (!pWidgetData) { |
| 2336 | return; |
| 2337 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2338 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2339 | pWidgetData->SetValue(pValue->ToWideString(), XFA_VALUEPICTURE_Display); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2340 | } else { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2341 | CFX_WideString wsValue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2342 | pWidgetData->GetValue(wsValue, XFA_VALUEPICTURE_Display); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2343 | pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2344 | } |
| 2345 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2346 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2347 | void CXFA_Node::Script_Som_Mandatory(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2348 | FX_BOOL bSetting, |
| 2349 | XFA_ATTRIBUTE eAttribute) { |
| 2350 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2351 | if (!pWidgetData) { |
| 2352 | return; |
| 2353 | } |
| 2354 | CXFA_Validate validate = pWidgetData->GetValidate(TRUE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2355 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2356 | validate.SetNullTest(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2357 | } else { |
| 2358 | int32_t iValue = validate.GetNullTest(); |
| 2359 | const XFA_ATTRIBUTEENUMINFO* pInfo = |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 2360 | GetAttributeEnumByID((XFA_ATTRIBUTEENUM)iValue); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2361 | CFX_WideString wsValue; |
| 2362 | if (pInfo) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2363 | wsValue = pInfo->pName; |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2364 | pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2365 | } |
| 2366 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2367 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2368 | void CXFA_Node::Script_Som_MandatoryMessage(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2369 | FX_BOOL bSetting, |
| 2370 | XFA_ATTRIBUTE eAttribute) { |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2371 | Script_Som_Message(pValue, bSetting, XFA_SOM_MandatoryMessage); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2372 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2373 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2374 | void CXFA_Node::Script_Field_ParentSubform(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2375 | FX_BOOL bSetting, |
| 2376 | XFA_ATTRIBUTE eAttribute) { |
| 2377 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2378 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2379 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2380 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2381 | } |
| 2382 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2383 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2384 | void CXFA_Node::Script_Field_SelectedIndex(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2385 | FX_BOOL bSetting, |
| 2386 | XFA_ATTRIBUTE eAttribute) { |
| 2387 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2388 | if (!pWidgetData) { |
| 2389 | return; |
| 2390 | } |
| 2391 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2392 | int32_t iIndex = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2393 | if (iIndex == -1) { |
| 2394 | pWidgetData->ClearAllSelections(); |
| 2395 | return; |
| 2396 | } |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2397 | pWidgetData->SetItemState(iIndex, TRUE, true, TRUE, TRUE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2398 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2399 | pValue->SetInteger(pWidgetData->GetSelectedItem()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2400 | } |
| 2401 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2402 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2403 | void CXFA_Node::Script_Field_ClearItems(CFXJSE_Arguments* pArguments) { |
| 2404 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2405 | if (!pWidgetData) { |
| 2406 | return; |
| 2407 | } |
| 2408 | pWidgetData->DeleteItem(-1, TRUE); |
| 2409 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2410 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2411 | void CXFA_Node::Script_Field_ExecEvent(CFXJSE_Arguments* pArguments) { |
| 2412 | int32_t argc = pArguments->GetLength(); |
| 2413 | if (argc == 1) { |
| 2414 | CFX_ByteString eventString = pArguments->GetUTF8String(0); |
| 2415 | int32_t iRet = execSingleEventByName( |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2416 | CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(), |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 2417 | XFA_Element::Field); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2418 | if (eventString == "validate") { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2419 | pArguments->GetReturnValue()->SetBoolean( |
| 2420 | (iRet == XFA_EVENTERROR_Error) ? FALSE : TRUE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2421 | } |
| 2422 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2423 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2424 | } |
| 2425 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2426 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2427 | void CXFA_Node::Script_Field_ExecInitialize(CFXJSE_Arguments* pArguments) { |
| 2428 | int32_t argc = pArguments->GetLength(); |
| 2429 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2430 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2431 | if (!pNotify) { |
| 2432 | return; |
| 2433 | } |
| 2434 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize, FALSE, FALSE); |
| 2435 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2436 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2437 | } |
| 2438 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2439 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2440 | void CXFA_Node::Script_Field_DeleteItem(CFXJSE_Arguments* pArguments) { |
| 2441 | int32_t iLength = pArguments->GetLength(); |
| 2442 | if (iLength != 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2443 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"deleteItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2444 | return; |
| 2445 | } |
| 2446 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2447 | if (!pWidgetData) { |
| 2448 | return; |
| 2449 | } |
| 2450 | int32_t iIndex = pArguments->GetInt32(0); |
| 2451 | FX_BOOL bValue = pWidgetData->DeleteItem(iIndex, TRUE, TRUE); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2452 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2453 | if (pValue) |
| 2454 | pValue->SetBoolean(bValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2455 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2456 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2457 | void CXFA_Node::Script_Field_GetSaveItem(CFXJSE_Arguments* pArguments) { |
| 2458 | int32_t iLength = pArguments->GetLength(); |
| 2459 | if (iLength != 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2460 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getSaveItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2461 | return; |
| 2462 | } |
| 2463 | int32_t iIndex = pArguments->GetInt32(0); |
| 2464 | if (iIndex < 0) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2465 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2466 | return; |
| 2467 | } |
| 2468 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2469 | if (!pWidgetData) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2470 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2471 | return; |
| 2472 | } |
| 2473 | CFX_WideString wsValue; |
| 2474 | FX_BOOL bHasItem = pWidgetData->GetChoiceListItem(wsValue, iIndex, TRUE); |
| 2475 | if (bHasItem) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2476 | pArguments->GetReturnValue()->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 2477 | FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2478 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2479 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2480 | } |
| 2481 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2482 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2483 | void CXFA_Node::Script_Field_BoundItem(CFXJSE_Arguments* pArguments) { |
| 2484 | int32_t iLength = pArguments->GetLength(); |
| 2485 | if (iLength != 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2486 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"boundItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2487 | return; |
| 2488 | } |
| 2489 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2490 | if (!pWidgetData) { |
| 2491 | return; |
| 2492 | } |
| 2493 | CFX_ByteString bsValue = pArguments->GetUTF8String(0); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2494 | CFX_WideString wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2495 | CFX_WideString wsBoundValue; |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2496 | pWidgetData->GetItemValue(wsValue.AsStringC(), wsBoundValue); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2497 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2498 | if (pValue) |
| 2499 | pValue->SetString(FX_UTF8Encode(wsBoundValue).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2500 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2501 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2502 | void CXFA_Node::Script_Field_GetItemState(CFXJSE_Arguments* pArguments) { |
| 2503 | int32_t iLength = pArguments->GetLength(); |
| 2504 | if (iLength != 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2505 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getItemState"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2506 | return; |
| 2507 | } |
| 2508 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2509 | if (!pWidgetData) { |
| 2510 | return; |
| 2511 | } |
| 2512 | int32_t iIndex = pArguments->GetInt32(0); |
| 2513 | FX_BOOL bValue = pWidgetData->GetItemState(iIndex); |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2514 | CFXJSE_Value* pValue = pArguments->GetReturnValue(); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2515 | if (pValue) |
| 2516 | pValue->SetBoolean(bValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2517 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2518 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2519 | void CXFA_Node::Script_Field_ExecCalculate(CFXJSE_Arguments* pArguments) { |
| 2520 | int32_t argc = pArguments->GetLength(); |
| 2521 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2522 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2523 | if (!pNotify) { |
| 2524 | return; |
| 2525 | } |
| 2526 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate, FALSE, FALSE); |
| 2527 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2528 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2529 | } |
| 2530 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2531 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2532 | void CXFA_Node::Script_Field_SetItems(CFXJSE_Arguments* pArguments) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2533 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2534 | void CXFA_Node::Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments) { |
| 2535 | int32_t iLength = pArguments->GetLength(); |
| 2536 | if (iLength != 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2537 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getDisplayItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2538 | return; |
| 2539 | } |
| 2540 | int32_t iIndex = pArguments->GetInt32(0); |
| 2541 | if (iIndex < 0) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2542 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2543 | return; |
| 2544 | } |
| 2545 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2546 | if (!pWidgetData) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2547 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2548 | return; |
| 2549 | } |
| 2550 | CFX_WideString wsValue; |
| 2551 | FX_BOOL bHasItem = pWidgetData->GetChoiceListItem(wsValue, iIndex, FALSE); |
| 2552 | if (bHasItem) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2553 | pArguments->GetReturnValue()->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 2554 | FX_UTF8Encode(wsValue.c_str(), wsValue.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2555 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2556 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2557 | } |
| 2558 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2559 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2560 | void CXFA_Node::Script_Field_SetItemState(CFXJSE_Arguments* pArguments) { |
| 2561 | int32_t iLength = pArguments->GetLength(); |
| 2562 | if (iLength != 2) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2563 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setItemState"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2564 | return; |
| 2565 | } |
| 2566 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2567 | if (!pWidgetData) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2568 | return; |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2569 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2570 | int32_t iIndex = pArguments->GetInt32(0); |
| 2571 | if (pArguments->GetInt32(1) != 0) { |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2572 | pWidgetData->SetItemState(iIndex, TRUE, true, TRUE, TRUE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2573 | } else { |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2574 | if (pWidgetData->GetItemState(iIndex)) |
| 2575 | pWidgetData->SetItemState(iIndex, FALSE, true, TRUE, TRUE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2576 | } |
| 2577 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2578 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2579 | void CXFA_Node::Script_Field_AddItem(CFXJSE_Arguments* pArguments) { |
| 2580 | int32_t iLength = pArguments->GetLength(); |
| 2581 | if (iLength < 1 || iLength > 2) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2582 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"addItem"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2583 | return; |
| 2584 | } |
| 2585 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2586 | if (!pWidgetData) { |
| 2587 | return; |
| 2588 | } |
| 2589 | CFX_WideString wsLabel; |
| 2590 | CFX_WideString wsValue; |
| 2591 | if (iLength >= 1) { |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 2592 | CFX_ByteString bsLabel = pArguments->GetUTF8String(0); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2593 | wsLabel = CFX_WideString::FromUTF8(bsLabel.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2594 | } |
| 2595 | if (iLength >= 2) { |
| 2596 | CFX_ByteString bsValue = pArguments->GetUTF8String(1); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2597 | wsValue = CFX_WideString::FromUTF8(bsValue.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2598 | } |
| 2599 | pWidgetData->InsertItem(wsLabel, wsValue, -1, TRUE); |
| 2600 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2601 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2602 | void CXFA_Node::Script_Field_ExecValidate(CFXJSE_Arguments* pArguments) { |
| 2603 | int32_t argc = pArguments->GetLength(); |
| 2604 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2605 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2606 | if (!pNotify) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2607 | pArguments->GetReturnValue()->SetBoolean(FALSE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2608 | } else { |
| 2609 | int32_t iRet = |
| 2610 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate, FALSE, FALSE); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2611 | pArguments->GetReturnValue()->SetBoolean( |
| 2612 | (iRet == XFA_EVENTERROR_Error) ? FALSE : TRUE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2613 | } |
| 2614 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2615 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2616 | } |
| 2617 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2618 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2619 | void CXFA_Node::Script_ExclGroup_ErrorText(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2620 | FX_BOOL bSetting, |
| 2621 | XFA_ATTRIBUTE eAttribute) { |
| 2622 | if (!bSetting) { |
| 2623 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2624 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2625 | } |
| 2626 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2627 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2628 | void CXFA_Node::Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2629 | FX_BOOL bSetting, |
| 2630 | XFA_ATTRIBUTE eAttribute) { |
| 2631 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2632 | if (!pWidgetData) { |
| 2633 | return; |
| 2634 | } |
| 2635 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2636 | pWidgetData->SetSelectedMemberByValue(pValue->ToWideString().AsStringC(), |
| 2637 | true, TRUE, TRUE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2638 | } else { |
| 2639 | CFX_WideString wsValue = GetScriptContent(TRUE); |
| 2640 | XFA_VERSION curVersion = GetDocument()->GetCurVersionMode(); |
| 2641 | if (wsValue.IsEmpty() && curVersion >= XFA_VERSION_300) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2642 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2643 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2644 | pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2645 | } |
| 2646 | } |
| 2647 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2648 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2649 | void CXFA_Node::Script_ExclGroup_Transient(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2650 | FX_BOOL bSetting, |
| 2651 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2652 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2653 | void CXFA_Node::Script_ExclGroup_ExecEvent(CFXJSE_Arguments* pArguments) { |
| 2654 | int32_t argc = pArguments->GetLength(); |
| 2655 | if (argc == 1) { |
| 2656 | CFX_ByteString eventString = pArguments->GetUTF8String(0); |
| 2657 | execSingleEventByName( |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2658 | CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(), |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 2659 | XFA_Element::ExclGroup); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2660 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2661 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2662 | } |
| 2663 | } |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2664 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2665 | void CXFA_Node::Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments) { |
| 2666 | int32_t argc = pArguments->GetLength(); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2667 | if (argc < 0 || argc > 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2668 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"selectedMember"); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2669 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2670 | } |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2671 | |
| 2672 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2673 | if (!pWidgetData) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2674 | pArguments->GetReturnValue()->SetNull(); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2675 | return; |
| 2676 | } |
| 2677 | |
| 2678 | CXFA_Node* pReturnNode = nullptr; |
| 2679 | if (argc == 0) { |
| 2680 | pReturnNode = pWidgetData->GetSelectedMember(); |
| 2681 | } else { |
| 2682 | CFX_ByteString szName; |
| 2683 | szName = pArguments->GetUTF8String(0); |
| 2684 | pReturnNode = pWidgetData->SetSelectedMember( |
| 2685 | CFX_WideString::FromUTF8(szName.AsStringC()).AsStringC(), true); |
| 2686 | } |
| 2687 | if (!pReturnNode) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2688 | pArguments->GetReturnValue()->SetNull(); |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2689 | return; |
| 2690 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2691 | pArguments->GetReturnValue()->Assign( |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2692 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pReturnNode)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2693 | } |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 2694 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2695 | void CXFA_Node::Script_ExclGroup_ExecInitialize(CFXJSE_Arguments* pArguments) { |
| 2696 | int32_t argc = pArguments->GetLength(); |
| 2697 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2698 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2699 | if (!pNotify) { |
| 2700 | return; |
| 2701 | } |
| 2702 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize); |
| 2703 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2704 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2705 | } |
| 2706 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2707 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2708 | void CXFA_Node::Script_ExclGroup_ExecCalculate(CFXJSE_Arguments* pArguments) { |
| 2709 | int32_t argc = pArguments->GetLength(); |
| 2710 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2711 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2712 | if (!pNotify) { |
| 2713 | return; |
| 2714 | } |
| 2715 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); |
| 2716 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2717 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2718 | } |
| 2719 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2720 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2721 | void CXFA_Node::Script_ExclGroup_ExecValidate(CFXJSE_Arguments* pArguments) { |
| 2722 | int32_t argc = pArguments->GetLength(); |
| 2723 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2724 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2725 | if (!pNotify) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2726 | pArguments->GetReturnValue()->SetBoolean(FALSE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2727 | } else { |
| 2728 | int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2729 | pArguments->GetReturnValue()->SetBoolean( |
| 2730 | (iRet == XFA_EVENTERROR_Error) ? FALSE : TRUE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2731 | } |
| 2732 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2733 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2734 | } |
| 2735 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2736 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2737 | void CXFA_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2738 | FX_BOOL bSetting, |
| 2739 | XFA_ATTRIBUTE eAttribute) { |
| 2740 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2741 | int32_t iTo = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2742 | int32_t iFrom = Subform_and_SubformSet_InstanceIndex(); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 2743 | CXFA_Node* pManagerNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2744 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; |
| 2745 | pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2746 | if (pNode->GetElementType() == XFA_Element::InstanceManager) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2747 | pManagerNode = pNode; |
| 2748 | break; |
| 2749 | } |
| 2750 | } |
| 2751 | if (pManagerNode) { |
| 2752 | pManagerNode->InstanceManager_MoveInstance(iTo, iFrom); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2753 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2754 | if (!pNotify) { |
| 2755 | return; |
| 2756 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2757 | CXFA_Node* pToInstance = GetItem(pManagerNode, iTo); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2758 | if (pToInstance && |
| 2759 | pToInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2760 | pNotify->RunSubformIndexChange(pToInstance); |
| 2761 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2762 | CXFA_Node* pFromInstance = GetItem(pManagerNode, iFrom); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 2763 | if (pFromInstance && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2764 | pFromInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2765 | pNotify->RunSubformIndexChange(pFromInstance); |
| 2766 | } |
| 2767 | } |
| 2768 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2769 | pValue->SetInteger(Subform_and_SubformSet_InstanceIndex()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2770 | } |
| 2771 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2772 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2773 | void CXFA_Node::Script_Subform_InstanceManager(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2774 | FX_BOOL bSetting, |
| 2775 | XFA_ATTRIBUTE eAttribute) { |
| 2776 | if (!bSetting) { |
| 2777 | CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 2778 | CXFA_Node* pInstanceMgr = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2779 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; |
| 2780 | pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2781 | if (pNode->GetElementType() == XFA_Element::InstanceManager) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2782 | CFX_WideStringC wsInstMgrName = pNode->GetCData(XFA_ATTRIBUTE_Name); |
| 2783 | if (wsInstMgrName.GetLength() >= 1 && wsInstMgrName.GetAt(0) == '_' && |
| 2784 | wsInstMgrName.Mid(1) == wsName) { |
| 2785 | pInstanceMgr = pNode; |
| 2786 | } |
| 2787 | break; |
| 2788 | } |
| 2789 | } |
| 2790 | if (pInstanceMgr) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2791 | pValue->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2792 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pInstanceMgr)); |
| 2793 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2794 | pValue->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2795 | } |
| 2796 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2797 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2798 | } |
| 2799 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2800 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 2801 | void CXFA_Node::Script_Subform_Locale(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2802 | FX_BOOL bSetting, |
| 2803 | XFA_ATTRIBUTE eAttribute) { |
| 2804 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 2805 | SetCData(XFA_ATTRIBUTE_Locale, pValue->ToWideString(), true, TRUE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2806 | } else { |
| 2807 | CFX_WideString wsLocaleName; |
| 2808 | GetLocaleName(wsLocaleName); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2809 | pValue->SetString( |
| 2810 | FX_UTF8Encode(wsLocaleName.c_str(), wsLocaleName.GetLength()) |
| 2811 | .AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2812 | } |
| 2813 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2814 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2815 | void CXFA_Node::Script_Subform_ExecEvent(CFXJSE_Arguments* pArguments) { |
| 2816 | int32_t argc = pArguments->GetLength(); |
| 2817 | if (argc == 1) { |
| 2818 | CFX_ByteString eventString = pArguments->GetUTF8String(0); |
| 2819 | execSingleEventByName( |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2820 | CFX_WideString::FromUTF8(eventString.AsStringC()).AsStringC(), |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 2821 | XFA_Element::Subform); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2822 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2823 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execEvent"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2824 | } |
| 2825 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2826 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2827 | void CXFA_Node::Script_Subform_ExecInitialize(CFXJSE_Arguments* pArguments) { |
| 2828 | int32_t argc = pArguments->GetLength(); |
| 2829 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2830 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2831 | if (!pNotify) { |
| 2832 | return; |
| 2833 | } |
| 2834 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize); |
| 2835 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2836 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2837 | } |
| 2838 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2839 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2840 | void CXFA_Node::Script_Subform_ExecCalculate(CFXJSE_Arguments* pArguments) { |
| 2841 | int32_t argc = pArguments->GetLength(); |
| 2842 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2843 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2844 | if (!pNotify) { |
| 2845 | return; |
| 2846 | } |
| 2847 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); |
| 2848 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2849 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2850 | } |
| 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_Subform_ExecValidate(CFXJSE_Arguments* pArguments) { |
| 2854 | int32_t argc = pArguments->GetLength(); |
| 2855 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 2856 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2857 | if (!pNotify) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2858 | pArguments->GetReturnValue()->SetBoolean(FALSE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2859 | } else { |
| 2860 | int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2861 | pArguments->GetReturnValue()->SetBoolean( |
| 2862 | (iRet == XFA_EVENTERROR_Error) ? FALSE : TRUE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2863 | } |
| 2864 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2865 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2866 | } |
| 2867 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2868 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2869 | void CXFA_Node::Script_Subform_GetInvalidObjects(CFXJSE_Arguments* pArguments) { |
| 2870 | int32_t argc = pArguments->GetLength(); |
| 2871 | if (argc == 0) { |
| 2872 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2873 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getInvalidObjects"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2874 | } |
| 2875 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2876 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2877 | int32_t CXFA_Node::Subform_and_SubformSet_InstanceIndex() { |
| 2878 | int32_t index = 0; |
| 2879 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; |
| 2880 | pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 2881 | if ((pNode->GetElementType() == XFA_Element::Subform) || |
| 2882 | (pNode->GetElementType() == XFA_Element::SubformSet)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2883 | index++; |
| 2884 | } else { |
| 2885 | break; |
| 2886 | } |
| 2887 | } |
| 2888 | return index; |
| 2889 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2890 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2891 | void CXFA_Node::Script_Template_FormNodes(CFXJSE_Arguments* pArguments) { |
| 2892 | int32_t argc = pArguments->GetLength(); |
| 2893 | if (argc == 1) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2894 | pArguments->GetReturnValue()->SetBoolean(TRUE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2895 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2896 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"formNodes"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2897 | } |
| 2898 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2899 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2900 | void CXFA_Node::Script_Template_Remerge(CFXJSE_Arguments* pArguments) { |
| 2901 | int32_t argc = pArguments->GetLength(); |
| 2902 | if (argc == 0) { |
| 2903 | m_pDocument->DoDataRemerge(TRUE); |
| 2904 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2905 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"remerge"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2906 | } |
| 2907 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2908 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2909 | void CXFA_Node::Script_Template_ExecInitialize(CFXJSE_Arguments* pArguments) { |
| 2910 | int32_t argc = pArguments->GetLength(); |
| 2911 | if (argc == 0) { |
| 2912 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2913 | if (!pWidgetData) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2914 | pArguments->GetReturnValue()->SetBoolean(FALSE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2915 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2916 | pArguments->GetReturnValue()->SetBoolean(TRUE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2917 | } |
| 2918 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2919 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2920 | } |
| 2921 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2922 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2923 | void CXFA_Node::Script_Template_CreateNode(CFXJSE_Arguments* pArguments) { |
| 2924 | int32_t argc = pArguments->GetLength(); |
| 2925 | if ((argc > 0) && (argc < 4)) { |
| 2926 | CFX_WideString strTagName; |
| 2927 | CFX_WideString strName; |
| 2928 | CFX_WideString strNameSpace; |
| 2929 | CFX_ByteString bsTagName = pArguments->GetUTF8String(0); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2930 | strTagName = CFX_WideString::FromUTF8(bsTagName.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2931 | if (argc > 1) { |
| 2932 | CFX_ByteString bsName = pArguments->GetUTF8String(1); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2933 | strName = CFX_WideString::FromUTF8(bsName.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2934 | if (argc == 3) { |
| 2935 | CFX_ByteString bsNameSpace = pArguments->GetUTF8String(2); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2936 | strNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2937 | } |
| 2938 | } |
dsinclair | 6e12478 | 2016-06-23 12:14:55 -0700 | [diff] [blame] | 2939 | XFA_Element eType = XFA_GetElementTypeForName(strTagName.AsStringC()); |
| 2940 | CXFA_Node* pNewNode = CreateSamePacketNode(eType); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2941 | if (!pNewNode) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2942 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2943 | } else { |
| 2944 | if (!strName.IsEmpty()) { |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 2945 | if (GetAttributeOfElement(eType, XFA_ATTRIBUTE_Name, |
| 2946 | XFA_XDPPACKET_UNKNOWN)) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 2947 | pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, strName.AsStringC(), true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2948 | if (pNewNode->GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 2949 | pNewNode->CreateXMLMappingNode(); |
| 2950 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2951 | pArguments->GetReturnValue()->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2952 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode)); |
| 2953 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2954 | ThrowException(XFA_IDS_NOT_HAVE_PROPERTY, strTagName.c_str(), |
| 2955 | L"name"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2956 | } |
| 2957 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2958 | pArguments->GetReturnValue()->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2959 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode)); |
| 2960 | } |
| 2961 | } |
| 2962 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2963 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"createNode"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2964 | } |
| 2965 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2966 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2967 | void CXFA_Node::Script_Template_Recalculate(CFXJSE_Arguments* pArguments) { |
| 2968 | if (pArguments->GetLength() == 1) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2969 | pArguments->GetReturnValue()->SetBoolean(TRUE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2970 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2971 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"recalculate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2972 | } |
| 2973 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2974 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2975 | void CXFA_Node::Script_Template_ExecCalculate(CFXJSE_Arguments* pArguments) { |
| 2976 | int32_t argc = pArguments->GetLength(); |
| 2977 | if (argc == 0) { |
| 2978 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2979 | if (!pWidgetData) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2980 | pArguments->GetReturnValue()->SetBoolean(FALSE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2981 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2982 | pArguments->GetReturnValue()->SetBoolean(TRUE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2983 | } |
| 2984 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2985 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2986 | } |
| 2987 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 2988 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2989 | void CXFA_Node::Script_Template_ExecValidate(CFXJSE_Arguments* pArguments) { |
| 2990 | int32_t argc = pArguments->GetLength(); |
| 2991 | if (argc == 0) { |
| 2992 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2993 | if (!pWidgetData) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2994 | pArguments->GetReturnValue()->SetBoolean(FALSE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2995 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 2996 | pArguments->GetReturnValue()->SetBoolean(TRUE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 2997 | } |
| 2998 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 2999 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3000 | } |
| 3001 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3002 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3003 | void CXFA_Node::Script_Manifest_Evaluate(CFXJSE_Arguments* pArguments) { |
| 3004 | int32_t argc = pArguments->GetLength(); |
| 3005 | if (argc == 0) { |
| 3006 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 3007 | if (!pWidgetData) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3008 | pArguments->GetReturnValue()->SetBoolean(FALSE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3009 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3010 | pArguments->GetReturnValue()->SetBoolean(TRUE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3011 | } |
| 3012 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3013 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"evaluate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3014 | } |
| 3015 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3016 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3017 | void CXFA_Node::Script_InstanceManager_Max(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3018 | FX_BOOL bSetting, |
| 3019 | XFA_ATTRIBUTE eAttribute) { |
| 3020 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3021 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3022 | return; |
| 3023 | } |
| 3024 | CXFA_Occur nodeOccur(GetOccurNode()); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3025 | pValue->SetInteger(nodeOccur.GetMax()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3026 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3027 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3028 | void CXFA_Node::Script_InstanceManager_Min(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3029 | FX_BOOL bSetting, |
| 3030 | XFA_ATTRIBUTE eAttribute) { |
| 3031 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3032 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3033 | return; |
| 3034 | } |
| 3035 | CXFA_Occur nodeOccur(GetOccurNode()); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3036 | pValue->SetInteger(nodeOccur.GetMin()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3037 | } |
tsepez | aadedf9 | 2016-05-12 10:08:06 -0700 | [diff] [blame] | 3038 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3039 | void CXFA_Node::Script_InstanceManager_Count(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3040 | FX_BOOL bSetting, |
| 3041 | XFA_ATTRIBUTE eAttribute) { |
| 3042 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3043 | int32_t iDesired = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3044 | InstanceManager_SetInstances(iDesired); |
| 3045 | } else { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3046 | pValue->SetInteger(GetCount(this)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3047 | } |
| 3048 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3049 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3050 | void CXFA_Node::Script_InstanceManager_MoveInstance( |
| 3051 | CFXJSE_Arguments* pArguments) { |
| 3052 | int32_t argc = pArguments->GetLength(); |
| 3053 | if (argc != 2) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3054 | pArguments->GetReturnValue()->SetUndefined(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3055 | return; |
| 3056 | } |
| 3057 | int32_t iFrom = pArguments->GetInt32(0); |
| 3058 | int32_t iTo = pArguments->GetInt32(1); |
| 3059 | InstanceManager_MoveInstance(iTo, iFrom); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3060 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3061 | if (!pNotify) { |
| 3062 | return; |
| 3063 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3064 | CXFA_Node* pToInstance = GetItem(this, iTo); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3065 | if (pToInstance && pToInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3066 | pNotify->RunSubformIndexChange(pToInstance); |
| 3067 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3068 | CXFA_Node* pFromInstance = GetItem(this, iFrom); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3069 | if (pFromInstance && |
| 3070 | pFromInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3071 | pNotify->RunSubformIndexChange(pFromInstance); |
| 3072 | } |
| 3073 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3074 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3075 | void CXFA_Node::Script_InstanceManager_RemoveInstance( |
| 3076 | CFXJSE_Arguments* pArguments) { |
| 3077 | int32_t argc = pArguments->GetLength(); |
| 3078 | if (argc != 1) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3079 | pArguments->GetReturnValue()->SetUndefined(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3080 | return; |
| 3081 | } |
| 3082 | int32_t iIndex = pArguments->GetInt32(0); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3083 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3084 | if (iIndex < 0 || iIndex >= iCount) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3085 | ThrowException(XFA_IDS_INDEX_OUT_OF_BOUNDS); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3086 | return; |
| 3087 | } |
| 3088 | CXFA_Occur nodeOccur(GetOccurNode()); |
| 3089 | int32_t iMin = nodeOccur.GetMin(); |
| 3090 | if (iCount - 1 < iMin) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3091 | ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"min"); |
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* pRemoveInstance = GetItem(this, iIndex); |
| 3095 | RemoveItem(this, pRemoveInstance); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3096 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3097 | if (pNotify) { |
| 3098 | for (int32_t i = iIndex; i < iCount - 1; i++) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3099 | CXFA_Node* pSubformInstance = GetItem(this, i); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3100 | if (pSubformInstance && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3101 | pSubformInstance->GetElementType() == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3102 | pNotify->RunSubformIndexChange(pSubformInstance); |
| 3103 | } |
| 3104 | } |
| 3105 | } |
| 3106 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3107 | if (!pLayoutPro) { |
| 3108 | return; |
| 3109 | } |
| 3110 | pLayoutPro->AddChangedContainer( |
| 3111 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3112 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3113 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3114 | void CXFA_Node::Script_InstanceManager_SetInstances( |
| 3115 | CFXJSE_Arguments* pArguments) { |
| 3116 | int32_t argc = pArguments->GetLength(); |
| 3117 | if (argc != 1) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3118 | pArguments->GetReturnValue()->SetUndefined(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3119 | return; |
| 3120 | } |
| 3121 | int32_t iDesired = pArguments->GetInt32(0); |
| 3122 | InstanceManager_SetInstances(iDesired); |
| 3123 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3124 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3125 | void CXFA_Node::Script_InstanceManager_AddInstance( |
| 3126 | CFXJSE_Arguments* pArguments) { |
| 3127 | int32_t argc = pArguments->GetLength(); |
| 3128 | if ((argc != 0) && (argc != 1)) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3129 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"addInstance"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3130 | return; |
| 3131 | } |
| 3132 | FX_BOOL fFlags = TRUE; |
| 3133 | if (argc == 1) { |
| 3134 | fFlags = pArguments->GetInt32(0) == 0 ? FALSE : TRUE; |
| 3135 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3136 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3137 | CXFA_Occur nodeOccur(GetOccurNode()); |
| 3138 | int32_t iMax = nodeOccur.GetMax(); |
| 3139 | if (iMax >= 0 && iCount >= iMax) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3140 | ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"max"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3141 | return; |
| 3142 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3143 | CXFA_Node* pNewInstance = CreateInstance(this, fFlags); |
| 3144 | InsertItem(this, pNewInstance, iCount, iCount, FALSE); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3145 | pArguments->GetReturnValue()->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3146 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance)); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3147 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3148 | if (!pNotify) { |
| 3149 | return; |
| 3150 | } |
| 3151 | pNotify->RunNodeInitialize(pNewInstance); |
| 3152 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3153 | if (!pLayoutPro) { |
| 3154 | return; |
| 3155 | } |
| 3156 | pLayoutPro->AddChangedContainer( |
| 3157 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3158 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3159 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3160 | void CXFA_Node::Script_InstanceManager_InsertInstance( |
| 3161 | CFXJSE_Arguments* pArguments) { |
| 3162 | int32_t argc = pArguments->GetLength(); |
| 3163 | if ((argc != 1) && (argc != 2)) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3164 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"insertInstance"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3165 | return; |
| 3166 | } |
| 3167 | int32_t iIndex = pArguments->GetInt32(0); |
| 3168 | FX_BOOL bBind = FALSE; |
| 3169 | if (argc == 2) { |
| 3170 | bBind = pArguments->GetInt32(1) == 0 ? FALSE : TRUE; |
| 3171 | } |
| 3172 | CXFA_Occur nodeOccur(GetOccurNode()); |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3173 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3174 | if (iIndex < 0 || iIndex > iCount) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3175 | ThrowException(XFA_IDS_INDEX_OUT_OF_BOUNDS); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3176 | return; |
| 3177 | } |
| 3178 | int32_t iMax = nodeOccur.GetMax(); |
| 3179 | if (iMax >= 0 && iCount >= iMax) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3180 | ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"max"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3181 | return; |
| 3182 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3183 | CXFA_Node* pNewInstance = CreateInstance(this, bBind); |
| 3184 | InsertItem(this, pNewInstance, iIndex, iCount, TRUE); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3185 | pArguments->GetReturnValue()->Assign( |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3186 | m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewInstance)); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3187 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3188 | if (!pNotify) { |
| 3189 | return; |
| 3190 | } |
| 3191 | pNotify->RunNodeInitialize(pNewInstance); |
| 3192 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3193 | if (!pLayoutPro) { |
| 3194 | return; |
| 3195 | } |
| 3196 | pLayoutPro->AddChangedContainer( |
| 3197 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3198 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3199 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3200 | int32_t CXFA_Node::InstanceManager_SetInstances(int32_t iDesired) { |
| 3201 | CXFA_Occur nodeOccur(GetOccurNode()); |
| 3202 | int32_t iMax = nodeOccur.GetMax(); |
| 3203 | int32_t iMin = nodeOccur.GetMin(); |
| 3204 | if (iDesired < iMin) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3205 | ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"min"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3206 | return 1; |
| 3207 | } |
| 3208 | if ((iMax >= 0) && (iDesired > iMax)) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3209 | ThrowException(XFA_IDS_VIOLATE_BOUNDARY, L"max"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3210 | return 2; |
| 3211 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3212 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3213 | if (iDesired == iCount) { |
| 3214 | return 0; |
| 3215 | } |
| 3216 | if (iDesired < iCount) { |
| 3217 | CFX_WideStringC wsInstManagerName = GetCData(XFA_ATTRIBUTE_Name); |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3218 | CFX_WideString wsInstanceName = |
| 3219 | CFX_WideString(wsInstManagerName.IsEmpty() ? wsInstManagerName |
| 3220 | : wsInstManagerName.Mid(1)); |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 3221 | uint32_t dInstanceNameHash = |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 3222 | FX_HashCode_GetW(wsInstanceName.AsStringC(), false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3223 | CXFA_Node* pPrevSibling = |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3224 | (iDesired == 0) ? this : GetItem(this, iDesired - 1); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3225 | while (iCount > iDesired) { |
| 3226 | CXFA_Node* pRemoveInstance = |
| 3227 | pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3228 | if (pRemoveInstance->GetElementType() != XFA_Element::Subform && |
| 3229 | pRemoveInstance->GetElementType() != XFA_Element::SubformSet) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3230 | continue; |
| 3231 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3232 | if (pRemoveInstance->GetElementType() == XFA_Element::InstanceManager) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 3233 | ASSERT(FALSE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3234 | break; |
| 3235 | } |
| 3236 | if (pRemoveInstance->GetNameHash() == dInstanceNameHash) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3237 | RemoveItem(this, pRemoveInstance); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3238 | iCount--; |
| 3239 | } |
| 3240 | } |
| 3241 | } else if (iDesired > iCount) { |
| 3242 | while (iCount < iDesired) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3243 | CXFA_Node* pNewInstance = CreateInstance(this, TRUE); |
| 3244 | InsertItem(this, pNewInstance, iCount, iCount, FALSE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3245 | iCount++; |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3246 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3247 | if (!pNotify) { |
| 3248 | return 0; |
| 3249 | } |
| 3250 | pNotify->RunNodeInitialize(pNewInstance); |
| 3251 | } |
| 3252 | } |
| 3253 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3254 | if (pLayoutPro) { |
| 3255 | pLayoutPro->AddChangedContainer( |
| 3256 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3257 | } |
| 3258 | return 0; |
| 3259 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3260 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3261 | int32_t CXFA_Node::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3262 | int32_t iCount = GetCount(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3263 | if (iFrom > iCount || iTo > iCount - 1) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3264 | ThrowException(XFA_IDS_INDEX_OUT_OF_BOUNDS); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3265 | return 1; |
| 3266 | } |
| 3267 | if (iFrom < 0 || iTo < 0 || iFrom == iTo) { |
| 3268 | return 0; |
| 3269 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3270 | CXFA_Node* pMoveInstance = GetItem(this, iFrom); |
| 3271 | RemoveItem(this, pMoveInstance, FALSE); |
| 3272 | InsertItem(this, pMoveInstance, iTo, iCount - 1, TRUE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3273 | CXFA_LayoutProcessor* pLayoutPro = m_pDocument->GetLayoutProcessor(); |
| 3274 | if (pLayoutPro) { |
| 3275 | pLayoutPro->AddChangedContainer( |
| 3276 | ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form))); |
| 3277 | } |
| 3278 | return 0; |
| 3279 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3280 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3281 | void CXFA_Node::Script_Occur_Max(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3282 | FX_BOOL bSetting, |
| 3283 | XFA_ATTRIBUTE eAttribute) { |
| 3284 | CXFA_Occur occur(this); |
| 3285 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3286 | int32_t iMax = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3287 | occur.SetMax(iMax); |
| 3288 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3289 | pValue->SetInteger(occur.GetMax()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3290 | } |
| 3291 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3292 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3293 | void CXFA_Node::Script_Occur_Min(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3294 | FX_BOOL bSetting, |
| 3295 | XFA_ATTRIBUTE eAttribute) { |
| 3296 | CXFA_Occur occur(this); |
| 3297 | if (bSetting) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3298 | int32_t iMin = pValue->ToInteger(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3299 | occur.SetMin(iMin); |
| 3300 | } else { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3301 | pValue->SetInteger(occur.GetMin()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3302 | } |
| 3303 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3304 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3305 | void CXFA_Node::Script_Desc_Metadata(CFXJSE_Arguments* pArguments) { |
| 3306 | int32_t argc = pArguments->GetLength(); |
| 3307 | if ((argc == 0) || (argc == 1)) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3308 | pArguments->GetReturnValue()->SetString(""); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3309 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3310 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"metadata"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3311 | } |
| 3312 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3313 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3314 | void CXFA_Node::Script_Form_FormNodes(CFXJSE_Arguments* pArguments) { |
| 3315 | int32_t argc = pArguments->GetLength(); |
| 3316 | if (argc == 1) { |
| 3317 | CXFA_Node* pDataNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); |
| 3318 | if (pDataNode) { |
| 3319 | CXFA_NodeArray formItems; |
| 3320 | CXFA_ArrayNodeList* pFormNodes = new CXFA_ArrayNodeList(m_pDocument); |
| 3321 | pFormNodes->SetArrayNodeList(formItems); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3322 | pArguments->GetReturnValue()->SetObject( |
| 3323 | pFormNodes, m_pDocument->GetScriptContext()->GetJseNormalClass()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3324 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3325 | ThrowException(XFA_IDS_ARGUMENT_MISMATCH); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3326 | } |
| 3327 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3328 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"formNodes"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3329 | } |
| 3330 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3331 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3332 | void CXFA_Node::Script_Form_Remerge(CFXJSE_Arguments* pArguments) { |
| 3333 | int32_t argc = pArguments->GetLength(); |
| 3334 | if (argc == 0) { |
| 3335 | m_pDocument->DoDataRemerge(TRUE); |
| 3336 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3337 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"remerge"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3338 | } |
| 3339 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3340 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3341 | void CXFA_Node::Script_Form_ExecInitialize(CFXJSE_Arguments* pArguments) { |
| 3342 | int32_t argc = pArguments->GetLength(); |
| 3343 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3344 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3345 | if (!pNotify) { |
| 3346 | return; |
| 3347 | } |
| 3348 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Initialize); |
| 3349 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3350 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execInitialize"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3351 | } |
| 3352 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3353 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3354 | void CXFA_Node::Script_Form_Recalculate(CFXJSE_Arguments* pArguments) { |
| 3355 | CXFA_EventParam* pEventParam = |
| 3356 | m_pDocument->GetScriptContext()->GetEventParam(); |
| 3357 | if (pEventParam->m_eType == XFA_EVENT_Calculate || |
| 3358 | pEventParam->m_eType == XFA_EVENT_InitCalculate) { |
| 3359 | return; |
| 3360 | } |
| 3361 | int32_t argc = pArguments->GetLength(); |
| 3362 | if (argc == 1) { |
| 3363 | const bool bScriptFlags = pArguments->GetInt32(0) != 0; |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3364 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3365 | if (!pNotify) { |
| 3366 | return; |
| 3367 | } |
| 3368 | if (bScriptFlags) { |
| 3369 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); |
| 3370 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); |
| 3371 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Ready, TRUE); |
| 3372 | } else { |
| 3373 | } |
| 3374 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3375 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"recalculate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3376 | } |
| 3377 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3378 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3379 | void CXFA_Node::Script_Form_ExecCalculate(CFXJSE_Arguments* pArguments) { |
| 3380 | int32_t argc = pArguments->GetLength(); |
| 3381 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3382 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3383 | if (!pNotify) { |
| 3384 | return; |
| 3385 | } |
| 3386 | pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Calculate); |
| 3387 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3388 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execCalculate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3389 | } |
| 3390 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3391 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3392 | void CXFA_Node::Script_Form_ExecValidate(CFXJSE_Arguments* pArguments) { |
| 3393 | int32_t argc = pArguments->GetLength(); |
| 3394 | if (argc == 0) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 3395 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3396 | if (!pNotify) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3397 | pArguments->GetReturnValue()->SetBoolean(FALSE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3398 | } else { |
| 3399 | int32_t iRet = pNotify->ExecEventByDeepFirst(this, XFA_EVENT_Validate); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3400 | pArguments->GetReturnValue()->SetBoolean( |
| 3401 | (iRet == XFA_EVENTERROR_Error) ? FALSE : TRUE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3402 | } |
| 3403 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3404 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"execValidate"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3405 | } |
| 3406 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3407 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3408 | void CXFA_Node::Script_Form_Checksum(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3409 | FX_BOOL bSetting, |
| 3410 | XFA_ATTRIBUTE eAttribute) { |
| 3411 | if (bSetting) { |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 3412 | SetAttribute(XFA_ATTRIBUTE_Checksum, pValue->ToWideString().AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3413 | } else { |
| 3414 | CFX_WideString wsChecksum; |
| 3415 | GetAttribute(XFA_ATTRIBUTE_Checksum, wsChecksum, FALSE); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3416 | pValue->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 3417 | FX_UTF8Encode(wsChecksum.c_str(), wsChecksum.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3418 | } |
| 3419 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3420 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3421 | void CXFA_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) { |
| 3422 | int32_t argc = pArguments->GetLength(); |
| 3423 | if (argc == 1) { |
| 3424 | CFX_ByteString bsAttributeName = pArguments->GetUTF8String(0); |
| 3425 | CFX_WideString wsAttributeValue; |
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) { |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 3428 | static_cast<CFDE_XMLElement*>(pXMLNode)->GetString( |
| 3429 | CFX_WideString::FromUTF8(bsAttributeName.AsStringC()).c_str(), |
| 3430 | wsAttributeValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3431 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3432 | pArguments->GetReturnValue()->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 3433 | FX_UTF8Encode(wsAttributeValue.c_str(), wsAttributeValue.GetLength()) |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 3434 | .AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3435 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3436 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"getAttribute"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3437 | } |
| 3438 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3439 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3440 | void CXFA_Node::Script_Packet_SetAttribute(CFXJSE_Arguments* pArguments) { |
| 3441 | int32_t argc = pArguments->GetLength(); |
| 3442 | if (argc == 2) { |
| 3443 | CFX_ByteString bsValue = pArguments->GetUTF8String(0); |
| 3444 | CFX_ByteString bsName = pArguments->GetUTF8String(1); |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3445 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3446 | if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3447 | static_cast<CFDE_XMLElement*>(pXMLNode)->SetString( |
| 3448 | CFX_WideString::FromUTF8(bsName.AsStringC()), |
| 3449 | CFX_WideString::FromUTF8(bsValue.AsStringC())); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3450 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3451 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3452 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3453 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setAttribute"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3454 | } |
| 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_Packet_RemoveAttribute(CFXJSE_Arguments* pArguments) { |
| 3458 | int32_t argc = pArguments->GetLength(); |
| 3459 | if (argc == 1) { |
| 3460 | CFX_ByteString bsName = pArguments->GetUTF8String(0); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 3461 | CFX_WideString wsName = CFX_WideString::FromUTF8(bsName.AsStringC()); |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3462 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3463 | if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3464 | CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 3465 | if (pXMLElement->HasAttribute(wsName.c_str())) { |
| 3466 | pXMLElement->RemoveAttribute(wsName.c_str()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3467 | } |
| 3468 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3469 | pArguments->GetReturnValue()->SetNull(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3470 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3471 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"removeAttribute"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3472 | } |
| 3473 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3474 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3475 | void CXFA_Node::Script_Packet_Content(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3476 | FX_BOOL bSetting, |
| 3477 | XFA_ATTRIBUTE eAttribute) { |
| 3478 | if (bSetting) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3479 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3480 | if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3481 | CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); |
dsinclair | 2f5582f | 2016-06-09 11:48:23 -0700 | [diff] [blame] | 3482 | pXMLElement->SetTextData(pValue->ToWideString()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3483 | } |
| 3484 | } else { |
| 3485 | CFX_WideString wsTextData; |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3486 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3487 | if (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3488 | CFDE_XMLElement* pXMLElement = static_cast<CFDE_XMLElement*>(pXMLNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3489 | pXMLElement->GetTextData(wsTextData); |
| 3490 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3491 | pValue->SetString( |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 3492 | FX_UTF8Encode(wsTextData.c_str(), wsTextData.GetLength()).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3493 | } |
| 3494 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3495 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3496 | void CXFA_Node::Script_Source_Next(CFXJSE_Arguments* pArguments) { |
| 3497 | int32_t argc = pArguments->GetLength(); |
| 3498 | if (argc == 0) { |
| 3499 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3500 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"next"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3501 | } |
| 3502 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3503 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3504 | void CXFA_Node::Script_Source_CancelBatch(CFXJSE_Arguments* pArguments) { |
| 3505 | int32_t argc = pArguments->GetLength(); |
| 3506 | if (argc == 0) { |
| 3507 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3508 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"cancelBatch"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3509 | } |
| 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_First(CFXJSE_Arguments* pArguments) { |
| 3513 | int32_t argc = pArguments->GetLength(); |
| 3514 | if (argc == 0) { |
| 3515 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3516 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"first"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3517 | } |
| 3518 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3519 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3520 | void CXFA_Node::Script_Source_UpdateBatch(CFXJSE_Arguments* pArguments) { |
| 3521 | int32_t argc = pArguments->GetLength(); |
| 3522 | if (argc == 0) { |
| 3523 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3524 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"updateBatch"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3525 | } |
| 3526 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3527 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3528 | void CXFA_Node::Script_Source_Previous(CFXJSE_Arguments* pArguments) { |
| 3529 | int32_t argc = pArguments->GetLength(); |
| 3530 | if (argc == 0) { |
| 3531 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3532 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"previous"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3533 | } |
| 3534 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3535 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3536 | void CXFA_Node::Script_Source_IsBOF(CFXJSE_Arguments* pArguments) { |
| 3537 | int32_t argc = pArguments->GetLength(); |
| 3538 | if (argc == 0) { |
| 3539 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3540 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isBOF"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3541 | } |
| 3542 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3543 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3544 | void CXFA_Node::Script_Source_IsEOF(CFXJSE_Arguments* pArguments) { |
| 3545 | int32_t argc = pArguments->GetLength(); |
| 3546 | if (argc == 0) { |
| 3547 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3548 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"isEOF"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3549 | } |
| 3550 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3551 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3552 | void CXFA_Node::Script_Source_Cancel(CFXJSE_Arguments* pArguments) { |
| 3553 | int32_t argc = pArguments->GetLength(); |
| 3554 | if (argc == 0) { |
| 3555 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3556 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"cancel"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3557 | } |
| 3558 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3559 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3560 | void CXFA_Node::Script_Source_Update(CFXJSE_Arguments* pArguments) { |
| 3561 | int32_t argc = pArguments->GetLength(); |
| 3562 | if (argc == 0) { |
| 3563 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3564 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"update"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3565 | } |
| 3566 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3567 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3568 | void CXFA_Node::Script_Source_Open(CFXJSE_Arguments* pArguments) { |
| 3569 | int32_t argc = pArguments->GetLength(); |
| 3570 | if (argc == 0) { |
| 3571 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3572 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"open"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3573 | } |
| 3574 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3575 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3576 | void CXFA_Node::Script_Source_Delete(CFXJSE_Arguments* pArguments) { |
| 3577 | int32_t argc = pArguments->GetLength(); |
| 3578 | if (argc == 0) { |
| 3579 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3580 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"delete"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3581 | } |
| 3582 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3583 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3584 | void CXFA_Node::Script_Source_AddNew(CFXJSE_Arguments* pArguments) { |
| 3585 | int32_t argc = pArguments->GetLength(); |
| 3586 | if (argc == 0) { |
| 3587 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3588 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"addNew"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3589 | } |
| 3590 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3591 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3592 | void CXFA_Node::Script_Source_Requery(CFXJSE_Arguments* pArguments) { |
| 3593 | int32_t argc = pArguments->GetLength(); |
| 3594 | if (argc == 0) { |
| 3595 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3596 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"requery"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3597 | } |
| 3598 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3599 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3600 | void CXFA_Node::Script_Source_Resync(CFXJSE_Arguments* pArguments) { |
| 3601 | int32_t argc = pArguments->GetLength(); |
| 3602 | if (argc == 0) { |
| 3603 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3604 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resync"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3605 | } |
| 3606 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3607 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3608 | void CXFA_Node::Script_Source_Close(CFXJSE_Arguments* pArguments) { |
| 3609 | int32_t argc = pArguments->GetLength(); |
| 3610 | if (argc == 0) { |
| 3611 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3612 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"close"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3613 | } |
| 3614 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3615 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3616 | void CXFA_Node::Script_Source_Last(CFXJSE_Arguments* pArguments) { |
| 3617 | int32_t argc = pArguments->GetLength(); |
| 3618 | if (argc == 0) { |
| 3619 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3620 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"last"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3621 | } |
| 3622 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3623 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3624 | void CXFA_Node::Script_Source_HasDataChanged(CFXJSE_Arguments* pArguments) { |
| 3625 | int32_t argc = pArguments->GetLength(); |
| 3626 | if (argc == 0) { |
| 3627 | } else { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3628 | ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"hasDataChanged"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3629 | } |
| 3630 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3631 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3632 | void CXFA_Node::Script_Source_Db(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3633 | FX_BOOL bSetting, |
| 3634 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3635 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3636 | void CXFA_Node::Script_Xfa_This(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3637 | FX_BOOL bSetting, |
| 3638 | XFA_ATTRIBUTE eAttribute) { |
| 3639 | if (!bSetting) { |
| 3640 | CXFA_Object* pThis = m_pDocument->GetScriptContext()->GetThisObject(); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 3641 | ASSERT(pThis); |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3642 | pValue->Assign(m_pDocument->GetScriptContext()->GetJSValueFromMap(pThis)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3643 | } |
| 3644 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3645 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3646 | void CXFA_Node::Script_Handler_Version(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3647 | FX_BOOL bSetting, |
| 3648 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3649 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3650 | void CXFA_Node::Script_SubmitFormat_Mode(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3651 | FX_BOOL bSetting, |
| 3652 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3653 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3654 | void CXFA_Node::Script_Extras_Type(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3655 | FX_BOOL bSetting, |
| 3656 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3657 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3658 | void CXFA_Node::Script_Script_Stateless(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3659 | FX_BOOL bSetting, |
| 3660 | XFA_ATTRIBUTE eAttribute) { |
| 3661 | if (bSetting) { |
dsinclair | 2235b7b | 2016-06-02 07:42:25 -0700 | [diff] [blame] | 3662 | ThrowException(XFA_IDS_INVAlID_PROP_SET); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3663 | return; |
| 3664 | } |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 3665 | pValue->SetString(FX_UTF8Encode(FX_WSTRC(L"0")).AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3666 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3667 | |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 3668 | void CXFA_Node::Script_Encrypt_Format(CFXJSE_Value* pValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3669 | FX_BOOL bSetting, |
| 3670 | XFA_ATTRIBUTE eAttribute) {} |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3671 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3672 | FX_BOOL CXFA_Node::HasAttribute(XFA_ATTRIBUTE eAttr, FX_BOOL bCanInherit) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3673 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3674 | return HasMapModuleKey(pKey, bCanInherit); |
| 3675 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3676 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3677 | FX_BOOL CXFA_Node::SetAttribute(XFA_ATTRIBUTE eAttr, |
| 3678 | const CFX_WideStringC& wsValue, |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3679 | bool bNotify) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3680 | const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3681 | if (!pAttr) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3682 | return FALSE; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3683 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3684 | XFA_ATTRIBUTETYPE eType = pAttr->eType; |
| 3685 | if (eType == XFA_ATTRIBUTETYPE_NOTSURE) { |
| 3686 | const XFA_NOTSUREATTRIBUTE* pNotsure = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3687 | XFA_GetNotsureAttribute(GetElementType(), pAttr->eName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3688 | eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata; |
| 3689 | } |
| 3690 | switch (eType) { |
| 3691 | case XFA_ATTRIBUTETYPE_Enum: { |
| 3692 | const XFA_ATTRIBUTEENUMINFO* pEnum = XFA_GetAttributeEnumByName(wsValue); |
| 3693 | return SetEnum(pAttr->eName, |
| 3694 | pEnum ? pEnum->eName |
| 3695 | : (XFA_ATTRIBUTEENUM)(intptr_t)(pAttr->pDefValue), |
| 3696 | bNotify); |
| 3697 | } break; |
| 3698 | case XFA_ATTRIBUTETYPE_Cdata: |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3699 | return SetCData(pAttr->eName, CFX_WideString(wsValue), bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3700 | case XFA_ATTRIBUTETYPE_Boolean: |
| 3701 | return SetBoolean(pAttr->eName, wsValue != FX_WSTRC(L"0"), bNotify); |
| 3702 | case XFA_ATTRIBUTETYPE_Integer: |
dsinclair | e0347a6 | 2016-08-11 11:24:11 -0700 | [diff] [blame] | 3703 | return SetInteger(pAttr->eName, |
| 3704 | FXSYS_round(FXSYS_wcstof(wsValue.c_str(), |
| 3705 | wsValue.GetLength(), nullptr)), |
| 3706 | bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3707 | case XFA_ATTRIBUTETYPE_Measure: |
| 3708 | return SetMeasure(pAttr->eName, CXFA_Measurement(wsValue), bNotify); |
| 3709 | default: |
| 3710 | break; |
| 3711 | } |
| 3712 | return FALSE; |
| 3713 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3714 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3715 | FX_BOOL CXFA_Node::GetAttribute(XFA_ATTRIBUTE eAttr, |
| 3716 | CFX_WideString& wsValue, |
| 3717 | FX_BOOL bUseDefault) { |
| 3718 | const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3719 | if (!pAttr) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3720 | return FALSE; |
| 3721 | } |
| 3722 | XFA_ATTRIBUTETYPE eType = pAttr->eType; |
| 3723 | if (eType == XFA_ATTRIBUTETYPE_NOTSURE) { |
| 3724 | const XFA_NOTSUREATTRIBUTE* pNotsure = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3725 | XFA_GetNotsureAttribute(GetElementType(), pAttr->eName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3726 | eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata; |
| 3727 | } |
| 3728 | switch (eType) { |
| 3729 | case XFA_ATTRIBUTETYPE_Enum: { |
| 3730 | XFA_ATTRIBUTEENUM eValue; |
| 3731 | if (!TryEnum(pAttr->eName, eValue, bUseDefault)) { |
| 3732 | return FALSE; |
| 3733 | } |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 3734 | wsValue = GetAttributeEnumByID(eValue)->pName; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3735 | return TRUE; |
| 3736 | } break; |
| 3737 | case XFA_ATTRIBUTETYPE_Cdata: { |
| 3738 | CFX_WideStringC wsValueC; |
| 3739 | if (!TryCData(pAttr->eName, wsValueC, bUseDefault)) { |
| 3740 | return FALSE; |
| 3741 | } |
| 3742 | wsValue = wsValueC; |
| 3743 | return TRUE; |
| 3744 | } break; |
| 3745 | case XFA_ATTRIBUTETYPE_Boolean: { |
| 3746 | FX_BOOL bValue; |
| 3747 | if (!TryBoolean(pAttr->eName, bValue, bUseDefault)) { |
| 3748 | return FALSE; |
| 3749 | } |
| 3750 | wsValue = bValue ? FX_WSTRC(L"1") : FX_WSTRC(L"0"); |
| 3751 | return TRUE; |
| 3752 | } break; |
| 3753 | case XFA_ATTRIBUTETYPE_Integer: { |
| 3754 | int32_t iValue; |
| 3755 | if (!TryInteger(pAttr->eName, iValue, bUseDefault)) { |
| 3756 | return FALSE; |
| 3757 | } |
| 3758 | wsValue.Format(L"%d", iValue); |
| 3759 | return TRUE; |
| 3760 | } break; |
| 3761 | case XFA_ATTRIBUTETYPE_Measure: { |
| 3762 | CXFA_Measurement mValue; |
| 3763 | if (!TryMeasure(pAttr->eName, mValue, bUseDefault)) { |
| 3764 | return FALSE; |
| 3765 | } |
| 3766 | mValue.ToString(wsValue); |
| 3767 | return TRUE; |
| 3768 | } break; |
| 3769 | default: |
| 3770 | break; |
| 3771 | } |
| 3772 | return FALSE; |
| 3773 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3774 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3775 | FX_BOOL CXFA_Node::SetAttribute(const CFX_WideStringC& wsAttr, |
| 3776 | const CFX_WideStringC& wsValue, |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3777 | bool bNotify) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3778 | const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsValue); |
| 3779 | if (pAttributeInfo) { |
| 3780 | return SetAttribute(pAttributeInfo->eName, wsValue, bNotify); |
| 3781 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3782 | void* pKey = GetMapKey_Custom(wsAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3783 | SetMapModuleString(pKey, wsValue); |
| 3784 | return TRUE; |
| 3785 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3786 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3787 | FX_BOOL CXFA_Node::GetAttribute(const CFX_WideStringC& wsAttr, |
| 3788 | CFX_WideString& wsValue, |
| 3789 | FX_BOOL bUseDefault) { |
| 3790 | const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsAttr); |
| 3791 | if (pAttributeInfo) { |
| 3792 | return GetAttribute(pAttributeInfo->eName, wsValue, bUseDefault); |
| 3793 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3794 | void* pKey = GetMapKey_Custom(wsAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3795 | CFX_WideStringC wsValueC; |
| 3796 | if (GetMapModuleString(pKey, wsValueC)) { |
| 3797 | wsValue = wsValueC; |
| 3798 | } |
| 3799 | return TRUE; |
| 3800 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3801 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3802 | FX_BOOL CXFA_Node::RemoveAttribute(const CFX_WideStringC& wsAttr) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3803 | void* pKey = GetMapKey_Custom(wsAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3804 | RemoveMapModuleKey(pKey); |
| 3805 | return TRUE; |
| 3806 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3807 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3808 | FX_BOOL CXFA_Node::TryBoolean(XFA_ATTRIBUTE eAttr, |
| 3809 | FX_BOOL& bValue, |
| 3810 | FX_BOOL bUseDefault) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3811 | void* pValue = nullptr; |
| 3812 | if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Boolean, bUseDefault, pValue)) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3813 | return FALSE; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3814 | bValue = (FX_BOOL)(uintptr_t)pValue; |
| 3815 | return TRUE; |
| 3816 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3817 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3818 | FX_BOOL CXFA_Node::TryInteger(XFA_ATTRIBUTE eAttr, |
| 3819 | int32_t& iValue, |
| 3820 | FX_BOOL bUseDefault) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3821 | void* pValue = nullptr; |
| 3822 | if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Integer, bUseDefault, pValue)) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3823 | return FALSE; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3824 | iValue = (int32_t)(uintptr_t)pValue; |
| 3825 | return TRUE; |
| 3826 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3827 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3828 | FX_BOOL CXFA_Node::TryEnum(XFA_ATTRIBUTE eAttr, |
| 3829 | XFA_ATTRIBUTEENUM& eValue, |
| 3830 | FX_BOOL bUseDefault) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 3831 | void* pValue = nullptr; |
| 3832 | if (!GetValue(eAttr, XFA_ATTRIBUTETYPE_Enum, bUseDefault, pValue)) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3833 | return FALSE; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3834 | eValue = (XFA_ATTRIBUTEENUM)(uintptr_t)pValue; |
| 3835 | return TRUE; |
| 3836 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3837 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3838 | FX_BOOL CXFA_Node::SetMeasure(XFA_ATTRIBUTE eAttr, |
| 3839 | CXFA_Measurement mValue, |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3840 | bool bNotify) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3841 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3842 | OnChanging(eAttr, bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3843 | SetMapModuleBuffer(pKey, &mValue, sizeof(CXFA_Measurement)); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3844 | OnChanged(eAttr, bNotify, FALSE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3845 | return TRUE; |
| 3846 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3847 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3848 | FX_BOOL CXFA_Node::TryMeasure(XFA_ATTRIBUTE eAttr, |
| 3849 | CXFA_Measurement& mValue, |
| 3850 | FX_BOOL bUseDefault) const { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3851 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3852 | void* pValue; |
| 3853 | int32_t iBytes; |
| 3854 | if (GetMapModuleBuffer(pKey, pValue, iBytes) && iBytes == sizeof(mValue)) { |
| 3855 | FXSYS_memcpy(&mValue, pValue, sizeof(mValue)); |
| 3856 | return TRUE; |
| 3857 | } |
| 3858 | if (bUseDefault && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3859 | XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3860 | XFA_ATTRIBUTETYPE_Measure, m_ePacket)) { |
| 3861 | FXSYS_memcpy(&mValue, pValue, sizeof(mValue)); |
| 3862 | return TRUE; |
| 3863 | } |
| 3864 | return FALSE; |
| 3865 | } |
| 3866 | |
| 3867 | CXFA_Measurement CXFA_Node::GetMeasure(XFA_ATTRIBUTE eAttr) const { |
| 3868 | CXFA_Measurement mValue; |
| 3869 | return TryMeasure(eAttr, mValue, TRUE) ? mValue : CXFA_Measurement(); |
| 3870 | } |
| 3871 | |
| 3872 | FX_BOOL CXFA_Node::SetCData(XFA_ATTRIBUTE eAttr, |
| 3873 | const CFX_WideString& wsValue, |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3874 | bool bNotify, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3875 | FX_BOOL bScriptModify) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3876 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3877 | OnChanging(eAttr, bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3878 | if (eAttr == XFA_ATTRIBUTE_Value) { |
| 3879 | CFX_WideString* pClone = new CFX_WideString(wsValue); |
| 3880 | SetUserData(pKey, pClone, &deleteWideStringCallBack); |
| 3881 | } else { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 3882 | SetMapModuleString(pKey, wsValue.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3883 | if (eAttr == XFA_ATTRIBUTE_Name) |
| 3884 | UpdateNameHash(); |
| 3885 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3886 | OnChanged(eAttr, bNotify, bScriptModify); |
| 3887 | |
| 3888 | if (!IsNeedSavingXMLNode() || eAttr == XFA_ATTRIBUTE_QualifiedName || |
| 3889 | eAttr == XFA_ATTRIBUTE_BindingNode) { |
| 3890 | return TRUE; |
| 3891 | } |
| 3892 | |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 3893 | if (eAttr == XFA_ATTRIBUTE_Name && |
| 3894 | (m_elementType == XFA_Element::DataValue || |
| 3895 | m_elementType == XFA_Element::DataGroup)) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3896 | return TRUE; |
| 3897 | } |
| 3898 | |
| 3899 | if (eAttr == XFA_ATTRIBUTE_Value) { |
| 3900 | FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType(); |
| 3901 | switch (eXMLType) { |
| 3902 | case FDE_XMLNODE_Element: |
| 3903 | if (IsAttributeInXML()) { |
| 3904 | static_cast<CFDE_XMLElement*>(m_pXMLNode) |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3905 | ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)), |
| 3906 | wsValue); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3907 | } else { |
| 3908 | FX_BOOL bDeleteChildren = TRUE; |
| 3909 | if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 3910 | for (CXFA_Node* pChildDataNode = |
| 3911 | GetNodeItem(XFA_NODEITEM_FirstChild); |
| 3912 | pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem( |
| 3913 | XFA_NODEITEM_NextSibling)) { |
| 3914 | CXFA_NodeArray formNodes; |
| 3915 | if (pChildDataNode->GetBindItems(formNodes) > 0) { |
| 3916 | bDeleteChildren = FALSE; |
| 3917 | break; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3918 | } |
| 3919 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3920 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3921 | if (bDeleteChildren) { |
| 3922 | static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren(); |
| 3923 | } |
| 3924 | static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsValue); |
| 3925 | } |
| 3926 | break; |
| 3927 | case FDE_XMLNODE_Text: |
| 3928 | static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsValue); |
| 3929 | break; |
| 3930 | default: |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 3931 | ASSERT(0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3932 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3933 | return TRUE; |
| 3934 | } |
| 3935 | |
| 3936 | const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr); |
| 3937 | if (pInfo) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 3938 | ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3939 | CFX_WideString wsAttrName = pInfo->pName; |
| 3940 | if (pInfo->eName == XFA_ATTRIBUTE_ContentType) { |
| 3941 | wsAttrName = FX_WSTRC(L"xfa:") + wsAttrName; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3942 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3943 | static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetString(wsAttrName, wsValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3944 | } |
| 3945 | return TRUE; |
| 3946 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3947 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3948 | FX_BOOL CXFA_Node::SetAttributeValue(const CFX_WideString& wsValue, |
| 3949 | const CFX_WideString& wsXMLValue, |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3950 | bool bNotify, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3951 | FX_BOOL bScriptModify) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3952 | void* pKey = GetMapKey_Element(GetElementType(), XFA_ATTRIBUTE_Value); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3953 | OnChanging(XFA_ATTRIBUTE_Value, bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3954 | CFX_WideString* pClone = new CFX_WideString(wsValue); |
| 3955 | SetUserData(pKey, pClone, &deleteWideStringCallBack); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 3956 | OnChanged(XFA_ATTRIBUTE_Value, bNotify, bScriptModify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3957 | if (IsNeedSavingXMLNode()) { |
| 3958 | FDE_XMLNODETYPE eXMLType = m_pXMLNode->GetType(); |
| 3959 | switch (eXMLType) { |
| 3960 | case FDE_XMLNODE_Element: |
| 3961 | if (IsAttributeInXML()) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3962 | static_cast<CFDE_XMLElement*>(m_pXMLNode) |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 3963 | ->SetString(CFX_WideString(GetCData(XFA_ATTRIBUTE_QualifiedName)), |
| 3964 | wsXMLValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3965 | } else { |
| 3966 | FX_BOOL bDeleteChildren = TRUE; |
| 3967 | if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 3968 | for (CXFA_Node* pChildDataNode = |
| 3969 | GetNodeItem(XFA_NODEITEM_FirstChild); |
| 3970 | pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem( |
| 3971 | XFA_NODEITEM_NextSibling)) { |
| 3972 | CXFA_NodeArray formNodes; |
| 3973 | if (pChildDataNode->GetBindItems(formNodes) > 0) { |
| 3974 | bDeleteChildren = FALSE; |
| 3975 | break; |
| 3976 | } |
| 3977 | } |
| 3978 | } |
| 3979 | if (bDeleteChildren) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3980 | static_cast<CFDE_XMLElement*>(m_pXMLNode)->DeleteChildren(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3981 | } |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3982 | static_cast<CFDE_XMLElement*>(m_pXMLNode)->SetTextData(wsXMLValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3983 | } |
| 3984 | break; |
| 3985 | case FDE_XMLNODE_Text: |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 3986 | static_cast<CFDE_XMLText*>(m_pXMLNode)->SetText(wsXMLValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3987 | break; |
| 3988 | default: |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 3989 | ASSERT(0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3990 | } |
| 3991 | } |
| 3992 | return TRUE; |
| 3993 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 3994 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 3995 | FX_BOOL CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr, |
| 3996 | CFX_WideString& wsValue, |
| 3997 | FX_BOOL bUseDefault, |
| 3998 | FX_BOOL bProto) { |
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 (eAttr == XFA_ATTRIBUTE_Value) { |
| 4001 | CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto); |
| 4002 | if (pStr) { |
| 4003 | wsValue = *pStr; |
| 4004 | return TRUE; |
| 4005 | } |
| 4006 | } else { |
| 4007 | CFX_WideStringC wsValueC; |
| 4008 | if (GetMapModuleString(pKey, wsValueC)) { |
| 4009 | wsValue = wsValueC; |
| 4010 | return TRUE; |
| 4011 | } |
| 4012 | } |
| 4013 | if (!bUseDefault) { |
| 4014 | return FALSE; |
| 4015 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4016 | void* pValue = nullptr; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4017 | if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4018 | XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) { |
| 4019 | wsValue = (const FX_WCHAR*)pValue; |
| 4020 | return TRUE; |
| 4021 | } |
| 4022 | return FALSE; |
| 4023 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4024 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4025 | FX_BOOL CXFA_Node::TryCData(XFA_ATTRIBUTE eAttr, |
| 4026 | CFX_WideStringC& wsValue, |
| 4027 | FX_BOOL bUseDefault, |
| 4028 | FX_BOOL bProto) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4029 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4030 | if (eAttr == XFA_ATTRIBUTE_Value) { |
| 4031 | CFX_WideString* pStr = (CFX_WideString*)GetUserData(pKey, bProto); |
| 4032 | if (pStr) { |
tsepez | 4d31d0c | 2016-04-19 14:11:59 -0700 | [diff] [blame] | 4033 | wsValue = pStr->AsStringC(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4034 | return TRUE; |
| 4035 | } |
| 4036 | } else { |
| 4037 | if (GetMapModuleString(pKey, wsValue)) { |
| 4038 | return TRUE; |
| 4039 | } |
| 4040 | } |
| 4041 | if (!bUseDefault) { |
| 4042 | return FALSE; |
| 4043 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4044 | void* pValue = nullptr; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4045 | if (XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4046 | XFA_ATTRIBUTETYPE_Cdata, m_ePacket)) { |
| 4047 | wsValue = (CFX_WideStringC)(const FX_WCHAR*)pValue; |
| 4048 | return TRUE; |
| 4049 | } |
| 4050 | return FALSE; |
| 4051 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4052 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4053 | FX_BOOL CXFA_Node::SetObject(XFA_ATTRIBUTE eAttr, |
| 4054 | void* pData, |
| 4055 | XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4056 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4057 | return SetUserData(pKey, pData, pCallbackInfo); |
| 4058 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4059 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4060 | FX_BOOL CXFA_Node::TryObject(XFA_ATTRIBUTE eAttr, void*& pData) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4061 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4062 | pData = GetUserData(pKey); |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 4063 | return !!pData; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4064 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4065 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4066 | FX_BOOL CXFA_Node::SetValue(XFA_ATTRIBUTE eAttr, |
| 4067 | XFA_ATTRIBUTETYPE eType, |
| 4068 | void* pValue, |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4069 | bool bNotify) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4070 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4071 | OnChanging(eAttr, bNotify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4072 | SetMapModuleValue(pKey, pValue); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4073 | OnChanged(eAttr, bNotify, FALSE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4074 | if (IsNeedSavingXMLNode()) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4075 | ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4076 | const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr); |
| 4077 | if (pInfo) { |
| 4078 | switch (eType) { |
| 4079 | case XFA_ATTRIBUTETYPE_Enum: |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4080 | static_cast<CFDE_XMLElement*>(m_pXMLNode) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4081 | ->SetString( |
| 4082 | pInfo->pName, |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 4083 | GetAttributeEnumByID((XFA_ATTRIBUTEENUM)(uintptr_t)pValue) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4084 | ->pName); |
| 4085 | break; |
| 4086 | case XFA_ATTRIBUTETYPE_Boolean: |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4087 | static_cast<CFDE_XMLElement*>(m_pXMLNode) |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 4088 | ->SetString(pInfo->pName, pValue ? L"1" : L"0"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4089 | break; |
| 4090 | case XFA_ATTRIBUTETYPE_Integer: |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4091 | static_cast<CFDE_XMLElement*>(m_pXMLNode) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4092 | ->SetInteger(pInfo->pName, (int32_t)(uintptr_t)pValue); |
| 4093 | break; |
| 4094 | default: |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4095 | ASSERT(0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4096 | } |
| 4097 | } |
| 4098 | } |
| 4099 | return TRUE; |
| 4100 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4101 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4102 | FX_BOOL CXFA_Node::GetValue(XFA_ATTRIBUTE eAttr, |
| 4103 | XFA_ATTRIBUTETYPE eType, |
| 4104 | FX_BOOL bUseDefault, |
| 4105 | void*& pValue) { |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4106 | void* pKey = GetMapKey_Element(GetElementType(), eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4107 | if (GetMapModuleValue(pKey, pValue)) { |
| 4108 | return TRUE; |
| 4109 | } |
| 4110 | if (!bUseDefault) { |
| 4111 | return FALSE; |
| 4112 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4113 | return XFA_GetAttributeDefaultValue(pValue, GetElementType(), eAttr, eType, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4114 | m_ePacket); |
| 4115 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4116 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4117 | FX_BOOL CXFA_Node::SetUserData(void* pKey, |
| 4118 | void* pData, |
| 4119 | XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) { |
| 4120 | SetMapModuleBuffer(pKey, &pData, sizeof(void*), |
| 4121 | pCallbackInfo ? pCallbackInfo : &gs_XFADefaultFreeData); |
| 4122 | return TRUE; |
| 4123 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4124 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4125 | FX_BOOL CXFA_Node::TryUserData(void* pKey, void*& pData, FX_BOOL bProtoAlso) { |
| 4126 | int32_t iBytes = 0; |
| 4127 | if (!GetMapModuleBuffer(pKey, pData, iBytes, bProtoAlso)) { |
| 4128 | return FALSE; |
| 4129 | } |
| 4130 | return iBytes == sizeof(void*) && FXSYS_memcpy(&pData, pData, iBytes); |
| 4131 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4132 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4133 | FX_BOOL CXFA_Node::SetScriptContent(const CFX_WideString& wsContent, |
| 4134 | const CFX_WideString& wsXMLValue, |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4135 | bool bNotify, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4136 | FX_BOOL bScriptModify, |
| 4137 | FX_BOOL bSyncData) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4138 | CXFA_Node* pNode = nullptr; |
| 4139 | CXFA_Node* pBindNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4140 | switch (GetObjectType()) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4141 | case XFA_ObjectType::ContainerNode: { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4142 | if (XFA_FieldIsMultiListBox(this)) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4143 | CXFA_Node* pValue = GetProperty(0, XFA_Element::Value); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4144 | CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4145 | ASSERT(pChildValue); |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 4146 | pChildValue->SetCData(XFA_ATTRIBUTE_ContentType, L"text/xml"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4147 | pChildValue->SetScriptContent(wsContent, wsContent, bNotify, |
| 4148 | bScriptModify, FALSE); |
| 4149 | CXFA_Node* pBind = GetBindData(); |
| 4150 | if (bSyncData && pBind) { |
| 4151 | CFX_WideStringArray wsSaveTextArray; |
| 4152 | int32_t iSize = 0; |
| 4153 | if (!wsContent.IsEmpty()) { |
| 4154 | int32_t iStart = 0; |
| 4155 | int32_t iLength = wsContent.GetLength(); |
| 4156 | int32_t iEnd = wsContent.Find(L'\n', iStart); |
| 4157 | iEnd = (iEnd == -1) ? iLength : iEnd; |
| 4158 | while (iEnd >= iStart) { |
| 4159 | wsSaveTextArray.Add(wsContent.Mid(iStart, iEnd - iStart)); |
| 4160 | iStart = iEnd + 1; |
| 4161 | if (iStart >= iLength) { |
| 4162 | break; |
| 4163 | } |
| 4164 | iEnd = wsContent.Find(L'\n', iStart); |
| 4165 | if (iEnd < 0) { |
| 4166 | wsSaveTextArray.Add(wsContent.Mid(iStart, iLength - iStart)); |
| 4167 | } |
| 4168 | } |
| 4169 | iSize = wsSaveTextArray.GetSize(); |
| 4170 | } |
| 4171 | if (iSize == 0) { |
| 4172 | while (CXFA_Node* pChildNode = |
| 4173 | pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) { |
| 4174 | pBind->RemoveChild(pChildNode); |
| 4175 | } |
| 4176 | } else { |
| 4177 | CXFA_NodeArray valueNodes; |
| 4178 | int32_t iDatas = pBind->GetNodeList( |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4179 | valueNodes, XFA_NODEFILTER_Children, XFA_Element::DataValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4180 | if (iDatas < iSize) { |
| 4181 | int32_t iAddNodes = iSize - iDatas; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4182 | CXFA_Node* pValueNodes = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4183 | while (iAddNodes-- > 0) { |
| 4184 | pValueNodes = |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4185 | pBind->CreateSamePacketNode(XFA_Element::DataValue); |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 4186 | pValueNodes->SetCData(XFA_ATTRIBUTE_Name, L"value"); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4187 | pValueNodes->CreateXMLMappingNode(); |
| 4188 | pBind->InsertChild(pValueNodes); |
| 4189 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4190 | pValueNodes = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4191 | } else if (iDatas > iSize) { |
| 4192 | int32_t iDelNodes = iDatas - iSize; |
| 4193 | while (iDelNodes-- > 0) { |
| 4194 | pBind->RemoveChild(pBind->GetNodeItem(XFA_NODEITEM_FirstChild)); |
| 4195 | } |
| 4196 | } |
| 4197 | int32_t i = 0; |
| 4198 | for (CXFA_Node* pValueNode = |
| 4199 | pBind->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 4200 | pValueNode; pValueNode = pValueNode->GetNodeItem( |
| 4201 | XFA_NODEITEM_NextSibling)) { |
| 4202 | pValueNode->SetAttributeValue(wsSaveTextArray[i], |
| 4203 | wsSaveTextArray[i], FALSE); |
| 4204 | i++; |
| 4205 | } |
| 4206 | } |
| 4207 | CXFA_NodeArray nodeArray; |
| 4208 | pBind->GetBindItems(nodeArray); |
| 4209 | for (int32_t i = 0; i < nodeArray.GetSize(); i++) { |
weili | db444d2 | 2016-06-02 15:48:15 -0700 | [diff] [blame] | 4210 | if (nodeArray[i] != this) { |
| 4211 | nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify, |
| 4212 | bScriptModify, FALSE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4213 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4214 | } |
| 4215 | } |
| 4216 | break; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4217 | } else if (GetElementType() == XFA_Element::ExclGroup) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4218 | pNode = this; |
| 4219 | } else { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4220 | CXFA_Node* pValue = GetProperty(0, XFA_Element::Value); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4221 | CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4222 | ASSERT(pChildValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4223 | pChildValue->SetScriptContent(wsContent, wsContent, bNotify, |
| 4224 | bScriptModify, FALSE); |
| 4225 | } |
| 4226 | pBindNode = GetBindData(); |
| 4227 | if (pBindNode && bSyncData) { |
| 4228 | pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify, |
| 4229 | bScriptModify, FALSE); |
| 4230 | CXFA_NodeArray nodeArray; |
| 4231 | pBindNode->GetBindItems(nodeArray); |
| 4232 | for (int32_t i = 0; i < nodeArray.GetSize(); i++) { |
weili | db444d2 | 2016-06-02 15:48:15 -0700 | [diff] [blame] | 4233 | if (nodeArray[i] != this) { |
| 4234 | nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify, true, |
| 4235 | FALSE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4236 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4237 | } |
| 4238 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4239 | pBindNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4240 | break; |
| 4241 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4242 | case XFA_ObjectType::ContentNode: { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4243 | CFX_WideString wsContentType; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4244 | if (GetElementType() == XFA_Element::ExData) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4245 | GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, FALSE); |
tsepez | 9f2970c | 2016-04-01 10:23:04 -0700 | [diff] [blame] | 4246 | if (wsContentType == FX_WSTRC(L"text/html")) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4247 | wsContentType = FX_WSTRC(L""); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 4248 | SetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4249 | } |
| 4250 | } |
| 4251 | CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild); |
| 4252 | if (!pContentRawDataNode) { |
tsepez | 9f2970c | 2016-04-01 10:23:04 -0700 | [diff] [blame] | 4253 | pContentRawDataNode = CreateSamePacketNode( |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4254 | (wsContentType == FX_WSTRC(L"text/xml")) ? XFA_Element::Sharpxml |
| 4255 | : XFA_Element::Sharptext); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4256 | InsertChild(pContentRawDataNode); |
| 4257 | } |
| 4258 | return pContentRawDataNode->SetScriptContent( |
| 4259 | wsContent, wsXMLValue, bNotify, bScriptModify, bSyncData); |
| 4260 | } break; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4261 | case XFA_ObjectType::NodeC: |
| 4262 | case XFA_ObjectType::TextNode: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4263 | pNode = this; |
| 4264 | break; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4265 | case XFA_ObjectType::NodeV: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4266 | pNode = this; |
| 4267 | if (bSyncData && GetPacketID() == XFA_XDPPACKET_Form) { |
| 4268 | CXFA_Node* pParent = GetNodeItem(XFA_NODEITEM_Parent); |
| 4269 | if (pParent) { |
| 4270 | pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent); |
| 4271 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4272 | if (pParent && pParent->GetElementType() == XFA_Element::Value) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4273 | pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent); |
| 4274 | if (pParent && pParent->IsContainerNode()) { |
| 4275 | pBindNode = pParent->GetBindData(); |
| 4276 | if (pBindNode) { |
| 4277 | pBindNode->SetScriptContent(wsContent, wsXMLValue, bNotify, |
| 4278 | bScriptModify, FALSE); |
| 4279 | } |
| 4280 | } |
| 4281 | } |
| 4282 | } |
| 4283 | break; |
| 4284 | default: |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4285 | if (GetElementType() == XFA_Element::DataValue) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4286 | pNode = this; |
| 4287 | pBindNode = this; |
| 4288 | } |
| 4289 | break; |
| 4290 | } |
| 4291 | if (pNode) { |
| 4292 | SetAttributeValue(wsContent, wsXMLValue, bNotify, bScriptModify); |
| 4293 | if (pBindNode && bSyncData) { |
| 4294 | CXFA_NodeArray nodeArray; |
| 4295 | pBindNode->GetBindItems(nodeArray); |
| 4296 | for (int32_t i = 0; i < nodeArray.GetSize(); i++) { |
weili | db444d2 | 2016-06-02 15:48:15 -0700 | [diff] [blame] | 4297 | nodeArray[i]->SetScriptContent(wsContent, wsContent, bNotify, |
| 4298 | bScriptModify, FALSE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4299 | } |
| 4300 | } |
| 4301 | return TRUE; |
| 4302 | } |
| 4303 | return FALSE; |
| 4304 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4305 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4306 | FX_BOOL CXFA_Node::SetContent(const CFX_WideString& wsContent, |
| 4307 | const CFX_WideString& wsXMLValue, |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4308 | bool bNotify, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4309 | FX_BOOL bScriptModify, |
| 4310 | FX_BOOL bSyncData) { |
| 4311 | return SetScriptContent(wsContent, wsXMLValue, bNotify, bScriptModify, |
| 4312 | bSyncData); |
| 4313 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4314 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4315 | CFX_WideString CXFA_Node::GetScriptContent(FX_BOOL bScriptModify) { |
| 4316 | CFX_WideString wsContent; |
| 4317 | return TryContent(wsContent, bScriptModify) ? wsContent : CFX_WideString(); |
| 4318 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4319 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4320 | CFX_WideString CXFA_Node::GetContent() { |
| 4321 | return GetScriptContent(); |
| 4322 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4323 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4324 | FX_BOOL CXFA_Node::TryContent(CFX_WideString& wsContent, |
| 4325 | FX_BOOL bScriptModify, |
| 4326 | FX_BOOL bProto) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4327 | CXFA_Node* pNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4328 | switch (GetObjectType()) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4329 | case XFA_ObjectType::ContainerNode: |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4330 | if (GetElementType() == XFA_Element::ExclGroup) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4331 | pNode = this; |
| 4332 | } else { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4333 | CXFA_Node* pValue = GetChild(0, XFA_Element::Value); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4334 | if (!pValue) { |
| 4335 | return FALSE; |
| 4336 | } |
| 4337 | CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 4338 | if (pChildValue && XFA_FieldIsMultiListBox(this)) { |
| 4339 | pChildValue->SetAttribute(XFA_ATTRIBUTE_ContentType, |
| 4340 | FX_WSTRC(L"text/xml")); |
| 4341 | } |
| 4342 | return pChildValue |
| 4343 | ? pChildValue->TryContent(wsContent, bScriptModify, bProto) |
| 4344 | : FALSE; |
| 4345 | } |
| 4346 | break; |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4347 | case XFA_ObjectType::ContentNode: { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4348 | CXFA_Node* pContentRawDataNode = GetNodeItem(XFA_NODEITEM_FirstChild); |
| 4349 | if (!pContentRawDataNode) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4350 | XFA_Element element = XFA_Element::Sharptext; |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4351 | if (GetElementType() == XFA_Element::ExData) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4352 | CFX_WideString wsContentType; |
| 4353 | GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, FALSE); |
tsepez | 9f2970c | 2016-04-01 10:23:04 -0700 | [diff] [blame] | 4354 | if (wsContentType == FX_WSTRC(L"text/html")) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4355 | element = XFA_Element::SharpxHTML; |
tsepez | 9f2970c | 2016-04-01 10:23:04 -0700 | [diff] [blame] | 4356 | } else if (wsContentType == FX_WSTRC(L"text/xml")) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4357 | element = XFA_Element::Sharpxml; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4358 | } |
| 4359 | } |
| 4360 | pContentRawDataNode = CreateSamePacketNode(element); |
| 4361 | InsertChild(pContentRawDataNode); |
| 4362 | } |
| 4363 | return pContentRawDataNode->TryContent(wsContent, bScriptModify, bProto); |
| 4364 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4365 | case XFA_ObjectType::NodeC: |
| 4366 | case XFA_ObjectType::NodeV: |
| 4367 | case XFA_ObjectType::TextNode: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4368 | pNode = this; |
| 4369 | default: |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4370 | if (GetElementType() == XFA_Element::DataValue) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4371 | pNode = this; |
| 4372 | } |
| 4373 | break; |
| 4374 | } |
| 4375 | if (pNode) { |
| 4376 | if (bScriptModify) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 4377 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4378 | if (pScriptContext) { |
| 4379 | m_pDocument->GetScriptContext()->AddNodesOfRunScript(this); |
| 4380 | } |
| 4381 | } |
| 4382 | return TryCData(XFA_ATTRIBUTE_Value, wsContent, FALSE, bProto); |
| 4383 | } |
| 4384 | return FALSE; |
| 4385 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4386 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4387 | CXFA_Node* CXFA_Node::GetModelNode() { |
| 4388 | switch (GetPacketID()) { |
| 4389 | case XFA_XDPPACKET_XDP: |
| 4390 | return m_pDocument->GetRoot(); |
| 4391 | case XFA_XDPPACKET_Config: |
| 4392 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config)); |
| 4393 | case XFA_XDPPACKET_Template: |
| 4394 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Template)); |
| 4395 | case XFA_XDPPACKET_Form: |
| 4396 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)); |
| 4397 | case XFA_XDPPACKET_Datasets: |
| 4398 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets)); |
| 4399 | case XFA_XDPPACKET_LocaleSet: |
| 4400 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_LocaleSet)); |
| 4401 | case XFA_XDPPACKET_ConnectionSet: |
| 4402 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_ConnectionSet)); |
| 4403 | case XFA_XDPPACKET_SourceSet: |
| 4404 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_SourceSet)); |
| 4405 | case XFA_XDPPACKET_Xdc: |
| 4406 | return ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Xdc)); |
| 4407 | default: |
| 4408 | return this; |
| 4409 | } |
| 4410 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4411 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4412 | FX_BOOL CXFA_Node::TryNamespace(CFX_WideString& wsNamespace) { |
tsepez | 774bdde | 2016-04-14 09:49:44 -0700 | [diff] [blame] | 4413 | wsNamespace.clear(); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4414 | if (IsModelNode() || GetElementType() == XFA_Element::Packet) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4415 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4416 | if (!pXMLNode || pXMLNode->GetType() != FDE_XMLNODE_Element) { |
| 4417 | return FALSE; |
| 4418 | } |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4419 | static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4420 | return TRUE; |
| 4421 | } else if (GetPacketID() == XFA_XDPPACKET_Datasets) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4422 | CFDE_XMLNode* pXMLNode = GetXMLMappingNode(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4423 | if (!pXMLNode) { |
| 4424 | return FALSE; |
| 4425 | } |
| 4426 | if (pXMLNode->GetType() != FDE_XMLNODE_Element) { |
| 4427 | return TRUE; |
| 4428 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4429 | if (GetElementType() == XFA_Element::DataValue && |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4430 | GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData) { |
| 4431 | return XFA_FDEExtension_ResolveNamespaceQualifier( |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4432 | static_cast<CFDE_XMLElement*>(pXMLNode), |
| 4433 | GetCData(XFA_ATTRIBUTE_QualifiedName), wsNamespace); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4434 | } |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4435 | static_cast<CFDE_XMLElement*>(pXMLNode)->GetNamespaceURI(wsNamespace); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4436 | return TRUE; |
| 4437 | } else { |
| 4438 | CXFA_Node* pModelNode = GetModelNode(); |
| 4439 | return pModelNode->TryNamespace(wsNamespace); |
| 4440 | } |
| 4441 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4442 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4443 | CXFA_Node* CXFA_Node::GetProperty(int32_t index, |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4444 | XFA_Element eProperty, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4445 | FX_BOOL bCreateProperty) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4446 | XFA_Element eType = GetElementType(); |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 4447 | uint32_t dwPacket = GetPacketID(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4448 | const XFA_PROPERTY* pProperty = |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4449 | XFA_GetPropertyOfElement(eType, eProperty, dwPacket); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4450 | if (!pProperty || index >= pProperty->uOccur) |
| 4451 | return nullptr; |
| 4452 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4453 | CXFA_Node* pNode = m_pChild; |
| 4454 | int32_t iCount = 0; |
| 4455 | for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4456 | if (pNode->GetElementType() == eProperty) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4457 | iCount++; |
| 4458 | if (iCount > index) { |
| 4459 | return pNode; |
| 4460 | } |
| 4461 | } |
| 4462 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4463 | if (!bCreateProperty) |
| 4464 | return nullptr; |
| 4465 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4466 | if (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf) { |
| 4467 | pNode = m_pChild; |
| 4468 | for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 4469 | const XFA_PROPERTY* pExistProperty = |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4470 | XFA_GetPropertyOfElement(eType, pNode->GetElementType(), dwPacket); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4471 | if (pExistProperty && (pExistProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) |
| 4472 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4473 | } |
| 4474 | } |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4475 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4476 | const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(dwPacket); |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 4477 | CXFA_Node* pNewNode = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4478 | for (; iCount <= index; iCount++) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4479 | pNewNode = m_pDocument->CreateNode(pPacket, eProperty); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4480 | if (!pNewNode) |
| 4481 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4482 | InsertChild(pNewNode, nullptr); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4483 | pNewNode->SetFlag(XFA_NodeFlag_Initialized, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4484 | } |
| 4485 | return pNewNode; |
| 4486 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4487 | |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4488 | int32_t CXFA_Node::CountChildren(XFA_Element eType, FX_BOOL bOnlyChild) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4489 | CXFA_Node* pNode = m_pChild; |
| 4490 | int32_t iCount = 0; |
| 4491 | for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4492 | if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4493 | if (bOnlyChild) { |
| 4494 | const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement( |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4495 | GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4496 | if (pProperty) { |
| 4497 | continue; |
| 4498 | } |
| 4499 | } |
| 4500 | iCount++; |
| 4501 | } |
| 4502 | } |
| 4503 | return iCount; |
| 4504 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4505 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4506 | CXFA_Node* CXFA_Node::GetChild(int32_t index, |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4507 | XFA_Element eType, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4508 | FX_BOOL bOnlyChild) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4509 | ASSERT(index > -1); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4510 | CXFA_Node* pNode = m_pChild; |
| 4511 | int32_t iCount = 0; |
| 4512 | for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4513 | if (pNode->GetElementType() == eType || eType == XFA_Element::Unknown) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4514 | if (bOnlyChild) { |
| 4515 | const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement( |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4516 | GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4517 | if (pProperty) { |
| 4518 | continue; |
| 4519 | } |
| 4520 | } |
| 4521 | iCount++; |
| 4522 | if (iCount > index) { |
| 4523 | return pNode; |
| 4524 | } |
| 4525 | } |
| 4526 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4527 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4528 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4529 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4530 | int32_t CXFA_Node::InsertChild(int32_t index, CXFA_Node* pNode) { |
| 4531 | ASSERT(!pNode->m_pNext); |
| 4532 | pNode->m_pParent = this; |
Wei Li | 5fe7ae7 | 2016-05-04 21:13:15 -0700 | [diff] [blame] | 4533 | FX_BOOL ret = m_pDocument->RemovePurgeNode(pNode); |
| 4534 | ASSERT(ret); |
Wei Li | 439bb9e | 2016-05-05 00:35:26 -0700 | [diff] [blame] | 4535 | (void)ret; // Avoid unused variable warning. |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4536 | |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4537 | if (!m_pChild || index == 0) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4538 | if (index > 0) { |
| 4539 | return -1; |
| 4540 | } |
| 4541 | pNode->m_pNext = m_pChild; |
| 4542 | m_pChild = pNode; |
| 4543 | index = 0; |
| 4544 | } else if (index < 0) { |
| 4545 | m_pLastChild->m_pNext = pNode; |
| 4546 | } else { |
| 4547 | CXFA_Node* pPrev = m_pChild; |
| 4548 | int32_t iCount = 0; |
| 4549 | while (++iCount != index && pPrev->m_pNext) { |
| 4550 | pPrev = pPrev->m_pNext; |
| 4551 | } |
| 4552 | if (index > 0 && index != iCount) { |
| 4553 | return -1; |
| 4554 | } |
| 4555 | pNode->m_pNext = pPrev->m_pNext; |
| 4556 | pPrev->m_pNext = pNode; |
| 4557 | index = iCount; |
| 4558 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4559 | if (!pNode->m_pNext) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4560 | m_pLastChild = pNode; |
| 4561 | } |
| 4562 | ASSERT(m_pLastChild); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4563 | ASSERT(!m_pLastChild->m_pNext); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4564 | pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4565 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4566 | if (pNotify) |
| 4567 | pNotify->OnChildAdded(this); |
| 4568 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4569 | if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4570 | ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4571 | m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, index); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4572 | pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4573 | } |
| 4574 | return index; |
| 4575 | } |
weili | 6e1ae86 | 2016-05-04 18:25:27 -0700 | [diff] [blame] | 4576 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4577 | FX_BOOL CXFA_Node::InsertChild(CXFA_Node* pNode, CXFA_Node* pBeforeNode) { |
| 4578 | if (!pNode || pNode->m_pParent || |
| 4579 | (pBeforeNode && pBeforeNode->m_pParent != this)) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4580 | ASSERT(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4581 | return FALSE; |
| 4582 | } |
Wei Li | 5fe7ae7 | 2016-05-04 21:13:15 -0700 | [diff] [blame] | 4583 | FX_BOOL ret = m_pDocument->RemovePurgeNode(pNode); |
| 4584 | ASSERT(ret); |
Wei Li | 439bb9e | 2016-05-05 00:35:26 -0700 | [diff] [blame] | 4585 | (void)ret; // Avoid unused variable warning. |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4586 | |
| 4587 | int32_t nIndex = -1; |
| 4588 | pNode->m_pParent = this; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4589 | if (!m_pChild || pBeforeNode == m_pChild) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4590 | pNode->m_pNext = m_pChild; |
| 4591 | m_pChild = pNode; |
| 4592 | nIndex = 0; |
| 4593 | } else if (!pBeforeNode) { |
| 4594 | pNode->m_pNext = m_pLastChild->m_pNext; |
| 4595 | m_pLastChild->m_pNext = pNode; |
| 4596 | } else { |
| 4597 | nIndex = 1; |
| 4598 | CXFA_Node* pPrev = m_pChild; |
| 4599 | while (pPrev->m_pNext != pBeforeNode) { |
| 4600 | pPrev = pPrev->m_pNext; |
| 4601 | nIndex++; |
| 4602 | } |
| 4603 | pNode->m_pNext = pPrev->m_pNext; |
| 4604 | pPrev->m_pNext = pNode; |
| 4605 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4606 | if (!pNode->m_pNext) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4607 | m_pLastChild = pNode; |
| 4608 | } |
| 4609 | ASSERT(m_pLastChild); |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4610 | ASSERT(!m_pLastChild->m_pNext); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4611 | pNode->ClearFlag(XFA_NodeFlag_HasRemovedChildren); |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4612 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4613 | if (pNotify) |
| 4614 | pNotify->OnChildAdded(this); |
| 4615 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4616 | if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4617 | ASSERT(!pNode->m_pXMLNode->GetNodeItem(CFDE_XMLNode::Parent)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4618 | m_pXMLNode->InsertChildNode(pNode->m_pXMLNode, nIndex); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4619 | pNode->ClearFlag(XFA_NodeFlag_OwnXMLNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4620 | } |
| 4621 | return TRUE; |
| 4622 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4623 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4624 | CXFA_Node* CXFA_Node::Deprecated_GetPrevSibling() { |
| 4625 | if (!m_pParent) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4626 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4627 | } |
| 4628 | for (CXFA_Node* pSibling = m_pParent->m_pChild; pSibling; |
| 4629 | pSibling = pSibling->m_pNext) { |
| 4630 | if (pSibling->m_pNext == this) { |
| 4631 | return pSibling; |
| 4632 | } |
| 4633 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4634 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4635 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4636 | |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4637 | FX_BOOL CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4638 | if (!pNode || pNode->m_pParent != this) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4639 | ASSERT(FALSE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4640 | return FALSE; |
| 4641 | } |
| 4642 | if (m_pChild == pNode) { |
| 4643 | m_pChild = pNode->m_pNext; |
| 4644 | if (m_pLastChild == pNode) { |
| 4645 | m_pLastChild = pNode->m_pNext; |
| 4646 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4647 | pNode->m_pNext = nullptr; |
| 4648 | pNode->m_pParent = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4649 | } else { |
| 4650 | CXFA_Node* pPrev = pNode->Deprecated_GetPrevSibling(); |
| 4651 | pPrev->m_pNext = pNode->m_pNext; |
| 4652 | if (m_pLastChild == pNode) { |
| 4653 | m_pLastChild = pNode->m_pNext ? pNode->m_pNext : pPrev; |
| 4654 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4655 | pNode->m_pNext = nullptr; |
| 4656 | pNode->m_pParent = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4657 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4658 | ASSERT(!m_pLastChild || !m_pLastChild->m_pNext); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4659 | OnRemoved(bNotify); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4660 | pNode->SetFlag(XFA_NodeFlag_HasRemovedChildren, true); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4661 | m_pDocument->AddPurgeNode(pNode); |
| 4662 | if (IsNeedSavingXMLNode() && pNode->m_pXMLNode) { |
| 4663 | if (pNode->IsAttributeInXML()) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 4664 | ASSERT(pNode->m_pXMLNode == m_pXMLNode && |
| 4665 | m_pXMLNode->GetType() == FDE_XMLNODE_Element); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4666 | if (pNode->m_pXMLNode->GetType() == FDE_XMLNODE_Element) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4667 | CFDE_XMLElement* pXMLElement = |
| 4668 | static_cast<CFDE_XMLElement*>(pNode->m_pXMLNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4669 | CFX_WideStringC wsAttributeName = |
| 4670 | pNode->GetCData(XFA_ATTRIBUTE_QualifiedName); |
tsepez | 660956f | 2016-04-06 06:27:29 -0700 | [diff] [blame] | 4671 | pXMLElement->RemoveAttribute(wsAttributeName.c_str()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4672 | } |
| 4673 | CFX_WideString wsName; |
| 4674 | pNode->GetAttribute(XFA_ATTRIBUTE_Name, wsName, FALSE); |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4675 | CFDE_XMLElement* pNewXMLElement = new CFDE_XMLElement(wsName); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4676 | CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value); |
| 4677 | if (!wsValue.IsEmpty()) { |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 4678 | pNewXMLElement->SetTextData(CFX_WideString(wsValue)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4679 | } |
| 4680 | pNode->m_pXMLNode = pNewXMLElement; |
| 4681 | pNode->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown); |
| 4682 | } else { |
| 4683 | m_pXMLNode->RemoveChildNode(pNode->m_pXMLNode); |
| 4684 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4685 | pNode->SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4686 | } |
| 4687 | return TRUE; |
| 4688 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4689 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4690 | CXFA_Node* CXFA_Node::GetFirstChildByName(const CFX_WideStringC& wsName) const { |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 4691 | return GetFirstChildByName(FX_HashCode_GetW(wsName, false)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4692 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4693 | |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 4694 | CXFA_Node* CXFA_Node::GetFirstChildByName(uint32_t dwNameHash) const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4695 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode; |
| 4696 | pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 4697 | if (pNode->GetNameHash() == dwNameHash) { |
| 4698 | return pNode; |
| 4699 | } |
| 4700 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4701 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4702 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4703 | |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4704 | CXFA_Node* CXFA_Node::GetFirstChildByClass(XFA_Element eType) const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4705 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode; |
| 4706 | pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4707 | if (pNode->GetElementType() == eType) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4708 | return pNode; |
| 4709 | } |
| 4710 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4711 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4712 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4713 | |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 4714 | CXFA_Node* CXFA_Node::GetNextSameNameSibling(uint32_t dwNameHash) const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4715 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode; |
| 4716 | pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 4717 | if (pNode->GetNameHash() == dwNameHash) { |
| 4718 | return pNode; |
| 4719 | } |
| 4720 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4721 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4722 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4723 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4724 | CXFA_Node* CXFA_Node::GetNextSameNameSibling( |
| 4725 | const CFX_WideStringC& wsNodeName) const { |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 4726 | return GetNextSameNameSibling(FX_HashCode_GetW(wsNodeName, false)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4727 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4728 | |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4729 | CXFA_Node* CXFA_Node::GetNextSameClassSibling(XFA_Element eType) const { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4730 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode; |
| 4731 | pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4732 | if (pNode->GetElementType() == eType) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4733 | return pNode; |
| 4734 | } |
| 4735 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4736 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4737 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4738 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4739 | int32_t CXFA_Node::GetNodeSameNameIndex() const { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 4740 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4741 | if (!pScriptContext) { |
| 4742 | return -1; |
| 4743 | } |
| 4744 | return pScriptContext->GetIndexByName(const_cast<CXFA_Node*>(this)); |
| 4745 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4746 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4747 | int32_t CXFA_Node::GetNodeSameClassIndex() const { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 4748 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4749 | if (!pScriptContext) { |
| 4750 | return -1; |
| 4751 | } |
| 4752 | return pScriptContext->GetIndexByClassName(const_cast<CXFA_Node*>(this)); |
| 4753 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4754 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4755 | void CXFA_Node::GetSOMExpression(CFX_WideString& wsSOMExpression) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 4756 | CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4757 | if (!pScriptContext) { |
| 4758 | return; |
| 4759 | } |
| 4760 | pScriptContext->GetSomExpression(this, wsSOMExpression); |
| 4761 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4762 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4763 | CXFA_Node* CXFA_Node::GetInstanceMgrOfSubform() { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4764 | CXFA_Node* pInstanceMgr = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4765 | if (m_ePacket == XFA_XDPPACKET_Form) { |
| 4766 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4767 | if (!pParentNode || pParentNode->GetElementType() == XFA_Element::Area) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4768 | return pInstanceMgr; |
| 4769 | } |
| 4770 | for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_PrevSibling); pNode; |
| 4771 | pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4772 | XFA_Element eType = pNode->GetElementType(); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4773 | if ((eType == XFA_Element::Subform || eType == XFA_Element::SubformSet) && |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4774 | pNode->m_dwNameHash != m_dwNameHash) { |
| 4775 | break; |
| 4776 | } |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4777 | if (eType == XFA_Element::InstanceManager) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4778 | CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name); |
| 4779 | CFX_WideStringC wsInstName = pNode->GetCData(XFA_ATTRIBUTE_Name); |
| 4780 | if (wsInstName.GetLength() > 0 && wsInstName.GetAt(0) == '_' && |
| 4781 | wsInstName.Mid(1) == wsName) { |
| 4782 | pInstanceMgr = pNode; |
| 4783 | } |
| 4784 | break; |
| 4785 | } |
| 4786 | } |
| 4787 | } |
| 4788 | return pInstanceMgr; |
| 4789 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4790 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4791 | CXFA_Node* CXFA_Node::GetOccurNode() { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4792 | return GetFirstChildByClass(XFA_Element::Occur); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4793 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4794 | |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4795 | bool CXFA_Node::HasFlag(XFA_NodeFlag dwFlag) const { |
| 4796 | if (m_uNodeFlags & dwFlag) |
| 4797 | return true; |
| 4798 | if (dwFlag == XFA_NodeFlag_HasRemovedChildren) |
| 4799 | return m_pParent && m_pParent->HasFlag(dwFlag); |
| 4800 | return false; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4801 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4802 | |
| 4803 | void CXFA_Node::SetFlag(uint32_t dwFlag, bool bNotify) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4804 | if (dwFlag == XFA_NodeFlag_Initialized && bNotify && !IsInitialized()) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4805 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4806 | if (pNotify) { |
| 4807 | pNotify->OnNodeReady(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4808 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4809 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4810 | m_uNodeFlags |= dwFlag; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4811 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4812 | |
| 4813 | void CXFA_Node::ClearFlag(uint32_t dwFlag) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4814 | m_uNodeFlags &= ~dwFlag; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4815 | } |
| 4816 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4817 | FX_BOOL CXFA_Node::IsAttributeInXML() { |
| 4818 | return GetEnum(XFA_ATTRIBUTE_Contains) == XFA_ATTRIBUTEENUM_MetaData; |
| 4819 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4820 | |
| 4821 | void CXFA_Node::OnRemoved(bool bNotify) { |
| 4822 | if (!bNotify) |
| 4823 | return; |
| 4824 | |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4825 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4826 | if (pNotify) |
| 4827 | pNotify->OnChildRemoved(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4828 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4829 | |
| 4830 | void CXFA_Node::OnChanging(XFA_ATTRIBUTE eAttr, bool bNotify) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4831 | if (bNotify && IsInitialized()) { |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4832 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4833 | if (pNotify) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4834 | pNotify->OnValueChanging(this, eAttr); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4835 | } |
| 4836 | } |
| 4837 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4838 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4839 | void CXFA_Node::OnChanged(XFA_ATTRIBUTE eAttr, |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4840 | bool bNotify, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4841 | FX_BOOL bScriptModify) { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4842 | if (bNotify && IsInitialized()) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4843 | Script_Attribute_SendAttributeChangeMessage(eAttr, bScriptModify); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4844 | } |
| 4845 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 4846 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4847 | int32_t CXFA_Node::execSingleEventByName(const CFX_WideStringC& wsEventName, |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4848 | XFA_Element eType) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4849 | int32_t iRet = XFA_EVENTERROR_NotExist; |
| 4850 | const XFA_ExecEventParaInfo* eventParaInfo = |
| 4851 | GetEventParaInfoByName(wsEventName); |
| 4852 | if (eventParaInfo) { |
| 4853 | uint32_t validFlags = eventParaInfo->m_validFlags; |
dsinclair | a1b0772 | 2016-07-11 08:20:58 -0700 | [diff] [blame] | 4854 | CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4855 | if (!pNotify) { |
| 4856 | return iRet; |
| 4857 | } |
| 4858 | if (validFlags == 1) { |
| 4859 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType); |
| 4860 | } else if (validFlags == 2) { |
| 4861 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
| 4862 | FALSE, FALSE); |
| 4863 | } else if (validFlags == 3) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4864 | if (eType == XFA_Element::Subform) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4865 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
| 4866 | FALSE, FALSE); |
| 4867 | } |
| 4868 | } else if (validFlags == 4) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4869 | if (eType == XFA_Element::ExclGroup || eType == XFA_Element::Field) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4870 | CXFA_Node* pParentNode = GetNodeItem(XFA_NODEITEM_Parent); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 4871 | if (pParentNode && |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4872 | pParentNode->GetElementType() == XFA_Element::ExclGroup) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4873 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
| 4874 | FALSE, FALSE); |
| 4875 | } |
| 4876 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
| 4877 | FALSE, FALSE); |
| 4878 | } |
| 4879 | } else if (validFlags == 5) { |
dsinclair | 41cb62e | 2016-06-23 09:20:32 -0700 | [diff] [blame] | 4880 | if (eType == XFA_Element::Field) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4881 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
| 4882 | FALSE, FALSE); |
| 4883 | } |
| 4884 | } else if (validFlags == 6) { |
| 4885 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 4886 | if (pWidgetData) { |
| 4887 | CXFA_Node* pUINode = pWidgetData->GetUIChild(); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4888 | if (pUINode->m_elementType == XFA_Element::Signature) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4889 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
| 4890 | FALSE, FALSE); |
| 4891 | } |
| 4892 | } |
| 4893 | } else if (validFlags == 7) { |
| 4894 | CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 4895 | if (pWidgetData) { |
| 4896 | CXFA_Node* pUINode = pWidgetData->GetUIChild(); |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4897 | if ((pUINode->m_elementType == XFA_Element::ChoiceList) && |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4898 | (!pWidgetData->IsListBox())) { |
| 4899 | iRet = pNotify->ExecEventByDeepFirst(this, eventParaInfo->m_eventType, |
| 4900 | FALSE, FALSE); |
| 4901 | } |
| 4902 | } |
| 4903 | } |
| 4904 | } |
| 4905 | return iRet; |
| 4906 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4907 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4908 | void CXFA_Node::UpdateNameHash() { |
| 4909 | const XFA_NOTSUREATTRIBUTE* pNotsure = |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4910 | XFA_GetNotsureAttribute(GetElementType(), XFA_ATTRIBUTE_Name); |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 4911 | CFX_WideStringC wsName; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4912 | if (!pNotsure || pNotsure->eType == XFA_ATTRIBUTETYPE_Cdata) { |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 4913 | wsName = GetCData(XFA_ATTRIBUTE_Name); |
| 4914 | m_dwNameHash = FX_HashCode_GetW(wsName, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4915 | } else if (pNotsure->eType == XFA_ATTRIBUTETYPE_Enum) { |
dsinclair | 9eb0db1 | 2016-07-21 12:01:39 -0700 | [diff] [blame] | 4916 | wsName = GetAttributeEnumByID(GetEnum(XFA_ATTRIBUTE_Name))->pName; |
tsepez | b6853cf | 2016-04-25 11:23:43 -0700 | [diff] [blame] | 4917 | m_dwNameHash = FX_HashCode_GetW(wsName, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4918 | } |
| 4919 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4920 | |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4921 | CFDE_XMLNode* CXFA_Node::CreateXMLMappingNode() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4922 | if (!m_pXMLNode) { |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 4923 | CFX_WideString wsTag(GetCData(XFA_ATTRIBUTE_Name)); |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 4924 | m_pXMLNode = new CFDE_XMLElement(wsTag); |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 4925 | SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4926 | } |
| 4927 | return m_pXMLNode; |
| 4928 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4929 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4930 | FX_BOOL CXFA_Node::IsNeedSavingXMLNode() { |
| 4931 | return m_pXMLNode && (GetPacketID() == XFA_XDPPACKET_Datasets || |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 4932 | GetElementType() == XFA_Element::Xfa); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4933 | } |
| 4934 | |
| 4935 | XFA_MAPMODULEDATA* CXFA_Node::CreateMapModuleData() { |
| 4936 | if (!m_pMapModuleData) |
| 4937 | m_pMapModuleData = new XFA_MAPMODULEDATA; |
| 4938 | return m_pMapModuleData; |
| 4939 | } |
| 4940 | |
| 4941 | XFA_MAPMODULEDATA* CXFA_Node::GetMapModuleData() const { |
| 4942 | return m_pMapModuleData; |
| 4943 | } |
| 4944 | |
| 4945 | void CXFA_Node::SetMapModuleValue(void* pKey, void* pValue) { |
| 4946 | XFA_MAPMODULEDATA* pModule = CreateMapModuleData(); |
| 4947 | pModule->m_ValueMap.SetAt(pKey, pValue); |
| 4948 | } |
| 4949 | |
| 4950 | FX_BOOL CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) { |
| 4951 | CXFA_Node* pNode = this; |
| 4952 | while (pNode) { |
| 4953 | XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData(); |
| 4954 | if (pModule && pModule->m_ValueMap.Lookup(pKey, pValue)) { |
| 4955 | return TRUE; |
| 4956 | } |
| 4957 | pNode = pNode->GetPacketID() != XFA_XDPPACKET_Datasets |
| 4958 | ? pNode->GetTemplateNode() |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4959 | : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4960 | } |
| 4961 | return FALSE; |
| 4962 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4963 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4964 | void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) { |
tsepez | 660956f | 2016-04-06 06:27:29 -0700 | [diff] [blame] | 4965 | SetMapModuleBuffer(pKey, (void*)wsValue.c_str(), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4966 | wsValue.GetLength() * sizeof(FX_WCHAR)); |
| 4967 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4968 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4969 | FX_BOOL CXFA_Node::GetMapModuleString(void* pKey, CFX_WideStringC& wsValue) { |
| 4970 | void* pValue; |
| 4971 | int32_t iBytes; |
| 4972 | if (!GetMapModuleBuffer(pKey, pValue, iBytes)) { |
| 4973 | return FALSE; |
| 4974 | } |
| 4975 | wsValue = CFX_WideStringC((const FX_WCHAR*)pValue, iBytes / sizeof(FX_WCHAR)); |
| 4976 | return TRUE; |
| 4977 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 4978 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4979 | void CXFA_Node::SetMapModuleBuffer( |
| 4980 | void* pKey, |
| 4981 | void* pValue, |
| 4982 | int32_t iBytes, |
| 4983 | XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo) { |
| 4984 | XFA_MAPMODULEDATA* pModule = CreateMapModuleData(); |
| 4985 | XFA_MAPDATABLOCK*& pBuffer = pModule->m_BufferMap[pKey]; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4986 | if (!pBuffer) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4987 | pBuffer = |
| 4988 | (XFA_MAPDATABLOCK*)FX_Alloc(uint8_t, sizeof(XFA_MAPDATABLOCK) + iBytes); |
| 4989 | } else if (pBuffer->iBytes != iBytes) { |
| 4990 | if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { |
| 4991 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
| 4992 | } |
| 4993 | pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc(uint8_t, pBuffer, |
| 4994 | sizeof(XFA_MAPDATABLOCK) + iBytes); |
| 4995 | } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { |
| 4996 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
| 4997 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 4998 | if (!pBuffer) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 4999 | return; |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5000 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5001 | pBuffer->pCallbackInfo = pCallbackInfo; |
| 5002 | pBuffer->iBytes = iBytes; |
| 5003 | FXSYS_memcpy(pBuffer->GetData(), pValue, iBytes); |
| 5004 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 5005 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5006 | FX_BOOL CXFA_Node::GetMapModuleBuffer(void* pKey, |
| 5007 | void*& pValue, |
| 5008 | int32_t& iBytes, |
| 5009 | FX_BOOL bProtoAlso) const { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5010 | XFA_MAPDATABLOCK* pBuffer = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5011 | const CXFA_Node* pNode = this; |
| 5012 | while (pNode) { |
| 5013 | XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData(); |
| 5014 | if (pModule && pModule->m_BufferMap.Lookup(pKey, pBuffer)) { |
| 5015 | break; |
| 5016 | } |
| 5017 | pNode = (bProtoAlso && pNode->GetPacketID() != XFA_XDPPACKET_Datasets) |
| 5018 | ? pNode->GetTemplateNode() |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5019 | : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5020 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5021 | if (!pBuffer) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5022 | return FALSE; |
| 5023 | } |
| 5024 | pValue = pBuffer->GetData(); |
| 5025 | iBytes = pBuffer->iBytes; |
| 5026 | return TRUE; |
| 5027 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 5028 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5029 | FX_BOOL CXFA_Node::HasMapModuleKey(void* pKey, FX_BOOL bProtoAlso) { |
| 5030 | CXFA_Node* pNode = this; |
| 5031 | while (pNode) { |
| 5032 | void* pVal; |
| 5033 | XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData(); |
| 5034 | if (pModule && |
| 5035 | (pModule->m_ValueMap.Lookup(pKey, pVal) || |
| 5036 | pModule->m_BufferMap.Lookup(pKey, (XFA_MAPDATABLOCK*&)pVal))) { |
| 5037 | return TRUE; |
| 5038 | } |
| 5039 | pNode = (bProtoAlso && pNode->GetPacketID() != XFA_XDPPACKET_Datasets) |
| 5040 | ? pNode->GetTemplateNode() |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5041 | : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5042 | } |
| 5043 | return FALSE; |
| 5044 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 5045 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5046 | void CXFA_Node::RemoveMapModuleKey(void* pKey) { |
| 5047 | XFA_MAPMODULEDATA* pModule = GetMapModuleData(); |
| 5048 | if (!pModule) |
| 5049 | return; |
| 5050 | |
| 5051 | if (pKey) { |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5052 | XFA_MAPDATABLOCK* pBuffer = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5053 | pModule->m_BufferMap.Lookup(pKey, pBuffer); |
| 5054 | if (pBuffer) { |
| 5055 | if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { |
| 5056 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
| 5057 | } |
| 5058 | FX_Free(pBuffer); |
| 5059 | } |
| 5060 | pModule->m_BufferMap.RemoveKey(pKey); |
| 5061 | pModule->m_ValueMap.RemoveKey(pKey); |
| 5062 | } else { |
| 5063 | XFA_MAPDATABLOCK* pBuffer; |
| 5064 | FX_POSITION posBuffer = pModule->m_BufferMap.GetStartPosition(); |
| 5065 | while (posBuffer) { |
| 5066 | pModule->m_BufferMap.GetNextAssoc(posBuffer, pKey, pBuffer); |
| 5067 | if (pBuffer) { |
| 5068 | if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { |
| 5069 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
| 5070 | } |
| 5071 | FX_Free(pBuffer); |
| 5072 | } |
| 5073 | } |
| 5074 | pModule->m_BufferMap.RemoveAll(); |
| 5075 | pModule->m_ValueMap.RemoveAll(); |
| 5076 | delete pModule; |
| 5077 | } |
| 5078 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 5079 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5080 | void CXFA_Node::MergeAllData(void* pDstModule, FX_BOOL bUseSrcAttr) { |
| 5081 | XFA_MAPMODULEDATA* pDstModuleData = |
| 5082 | static_cast<CXFA_Node*>(pDstModule)->CreateMapModuleData(); |
| 5083 | XFA_MAPMODULEDATA* pSrcModuleData = GetMapModuleData(); |
| 5084 | if (!pSrcModuleData) { |
| 5085 | return; |
| 5086 | } |
| 5087 | FX_POSITION psValue = pSrcModuleData->m_ValueMap.GetStartPosition(); |
| 5088 | while (psValue) { |
| 5089 | void* pKey; |
| 5090 | void* pValue; |
| 5091 | pSrcModuleData->m_ValueMap.GetNextAssoc(psValue, pKey, pValue); |
| 5092 | if (bUseSrcAttr || !pDstModuleData->m_ValueMap.GetValueAt(pKey)) { |
| 5093 | pDstModuleData->m_ValueMap.SetAt(pKey, pValue); |
| 5094 | } |
| 5095 | } |
| 5096 | FX_POSITION psBuffer = pSrcModuleData->m_BufferMap.GetStartPosition(); |
| 5097 | while (psBuffer) { |
| 5098 | void* pKey; |
| 5099 | XFA_MAPDATABLOCK* pSrcBuffer; |
| 5100 | pSrcModuleData->m_BufferMap.GetNextAssoc(psBuffer, pKey, pSrcBuffer); |
| 5101 | XFA_MAPDATABLOCK*& pBuffer = pDstModuleData->m_BufferMap[pKey]; |
| 5102 | if (pBuffer && !bUseSrcAttr) { |
| 5103 | continue; |
| 5104 | } |
| 5105 | if (pSrcBuffer->pCallbackInfo && pSrcBuffer->pCallbackInfo->pFree && |
| 5106 | !pSrcBuffer->pCallbackInfo->pCopy) { |
| 5107 | if (pBuffer) { |
| 5108 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
| 5109 | pDstModuleData->m_BufferMap.RemoveKey(pKey); |
| 5110 | } |
| 5111 | continue; |
| 5112 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5113 | if (!pBuffer) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5114 | pBuffer = (XFA_MAPDATABLOCK*)FX_Alloc( |
| 5115 | uint8_t, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes); |
| 5116 | } else if (pBuffer->iBytes != pSrcBuffer->iBytes) { |
| 5117 | if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { |
| 5118 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
| 5119 | } |
| 5120 | pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc( |
| 5121 | uint8_t, pBuffer, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes); |
| 5122 | } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { |
| 5123 | pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
| 5124 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5125 | if (!pBuffer) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5126 | continue; |
| 5127 | } |
| 5128 | pBuffer->pCallbackInfo = pSrcBuffer->pCallbackInfo; |
| 5129 | pBuffer->iBytes = pSrcBuffer->iBytes; |
| 5130 | FXSYS_memcpy(pBuffer->GetData(), pSrcBuffer->GetData(), pSrcBuffer->iBytes); |
| 5131 | if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pCopy) { |
| 5132 | pBuffer->pCallbackInfo->pCopy(*(void**)pBuffer->GetData()); |
| 5133 | } |
| 5134 | } |
| 5135 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 5136 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5137 | void CXFA_Node::MoveBufferMapData(CXFA_Node* pDstModule, void* pKey) { |
| 5138 | if (!pDstModule) { |
| 5139 | return; |
| 5140 | } |
| 5141 | FX_BOOL bNeedMove = TRUE; |
| 5142 | if (!pKey) { |
| 5143 | bNeedMove = FALSE; |
| 5144 | } |
dsinclair | 070fcdf | 2016-06-22 22:04:54 -0700 | [diff] [blame] | 5145 | if (pDstModule->GetElementType() != GetElementType()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5146 | bNeedMove = FALSE; |
| 5147 | } |
weili | 44f8faf | 2016-06-01 14:03:56 -0700 | [diff] [blame] | 5148 | XFA_MAPMODULEDATA* pSrcModuleData = nullptr; |
| 5149 | XFA_MAPMODULEDATA* pDstModuleData = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5150 | if (bNeedMove) { |
| 5151 | pSrcModuleData = GetMapModuleData(); |
| 5152 | if (!pSrcModuleData) { |
| 5153 | bNeedMove = FALSE; |
| 5154 | } |
| 5155 | pDstModuleData = pDstModule->CreateMapModuleData(); |
| 5156 | } |
| 5157 | if (bNeedMove) { |
| 5158 | void* pBufferBlockData = pSrcModuleData->m_BufferMap.GetValueAt(pKey); |
| 5159 | if (pBufferBlockData) { |
| 5160 | pSrcModuleData->m_BufferMap.RemoveKey(pKey); |
| 5161 | pDstModuleData->m_BufferMap.RemoveKey(pKey); |
| 5162 | pDstModuleData->m_BufferMap.SetAt(pKey, |
| 5163 | (XFA_MAPDATABLOCK*)pBufferBlockData); |
| 5164 | } |
| 5165 | } |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 5166 | if (pDstModule->IsNodeV()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5167 | CFX_WideString wsValue = pDstModule->GetScriptContent(FALSE); |
| 5168 | CFX_WideString wsFormatValue(wsValue); |
| 5169 | CXFA_WidgetData* pWidgetData = pDstModule->GetContainerWidgetData(); |
| 5170 | if (pWidgetData) { |
tsepez | 6f167c3 | 2016-04-14 15:46:27 -0700 | [diff] [blame] | 5171 | pWidgetData->GetFormatDataValue(wsValue, wsFormatValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5172 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 5173 | pDstModule->SetScriptContent(wsValue, wsFormatValue, true, TRUE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5174 | } |
| 5175 | } |
dsinclair | 5b36f0a | 2016-07-19 10:56:23 -0700 | [diff] [blame] | 5176 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 5177 | void CXFA_Node::MoveBufferMapData(CXFA_Node* pSrcModule, |
| 5178 | CXFA_Node* pDstModule, |
| 5179 | void* pKey, |
| 5180 | FX_BOOL bRecursive) { |
| 5181 | if (!pSrcModule || !pDstModule || !pKey) { |
| 5182 | return; |
| 5183 | } |
| 5184 | if (bRecursive) { |
| 5185 | CXFA_Node* pSrcChild = pSrcModule->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 5186 | CXFA_Node* pDstChild = pDstModule->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 5187 | for (; pSrcChild && pDstChild; |
| 5188 | pSrcChild = pSrcChild->GetNodeItem(XFA_NODEITEM_NextSibling), |
| 5189 | pDstChild = pDstChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 5190 | MoveBufferMapData(pSrcChild, pDstChild, pKey, TRUE); |
| 5191 | } |
| 5192 | } |
| 5193 | pSrcModule->MoveBufferMapData(pDstModule, pKey); |
| 5194 | } |