| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | |
| 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_script_hostpseudomodel.h" | |
| 8 | |
| 9 #include "fxjs/include/cfxjse_arguments.h" | |
| 10 #include "xfa/fxfa/app/xfa_ffnotify.h" | |
| 11 #include "xfa/fxfa/parser/xfa_doclayout.h" | |
| 12 #include "xfa/fxfa/parser/xfa_document.h" | |
| 13 #include "xfa/fxfa/parser/xfa_document_layout_imp.h" | |
| 14 #include "xfa/fxfa/parser/xfa_localemgr.h" | |
| 15 #include "xfa/fxfa/parser/xfa_object.h" | |
| 16 #include "xfa/fxfa/parser/xfa_script.h" | |
| 17 #include "xfa/fxfa/parser/xfa_script_imp.h" | |
| 18 #include "xfa/fxfa/parser/xfa_utils.h" | |
| 19 | |
| 20 namespace { | |
| 21 | |
| 22 CXFA_Node* ToNode(CFXJSE_Value* pValue, CFXJSE_Class* pClass) { | |
| 23 return static_cast<CXFA_Node*>(pValue->ToHostObject(pClass)); | |
| 24 } | |
| 25 | |
| 26 } // namespace | |
| 27 | |
| 28 CScript_HostPseudoModel::CScript_HostPseudoModel(CXFA_Document* pDocument) | |
| 29 : CXFA_Object(pDocument, | |
| 30 XFA_ObjectType::Object, | |
| 31 XFA_Element::HostPseudoModel, | |
| 32 CFX_WideStringC(L"hostPseudoModel")) {} | |
| 33 | |
| 34 CScript_HostPseudoModel::~CScript_HostPseudoModel() {} | |
| 35 | |
| 36 void CScript_HostPseudoModel::LoadString(CFXJSE_Value* pValue, | |
| 37 CXFA_FFNotify* pNotify, | |
| 38 uint32_t dwFlag) { | |
| 39 CFX_WideString wsValue; | |
| 40 pNotify->GetAppProvider()->LoadString(dwFlag, wsValue); | |
| 41 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); | |
| 42 } | |
| 43 | |
| 44 void CScript_HostPseudoModel::AppType(CFXJSE_Value* pValue, | |
| 45 FX_BOOL bSetting, | |
| 46 XFA_ATTRIBUTE eAttribute) { | |
| 47 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
| 48 if (!pNotify) { | |
| 49 return; | |
| 50 } | |
| 51 if (bSetting) { | |
| 52 ThrowException(XFA_IDS_INVAlID_PROP_SET); | |
| 53 return; | |
| 54 } | |
| 55 CFX_WideString wsAppType; | |
| 56 pNotify->GetAppProvider()->GetAppType(wsAppType); | |
| 57 pValue->SetString(FX_UTF8Encode(wsAppType).AsStringC()); | |
| 58 } | |
| 59 | |
| 60 void CScript_HostPseudoModel::CalculationsEnabled(CFXJSE_Value* pValue, | |
| 61 FX_BOOL bSetting, | |
| 62 XFA_ATTRIBUTE eAttribute) { | |
| 63 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
| 64 if (!pNotify) { | |
| 65 return; | |
| 66 } | |
| 67 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); | |
| 68 if (bSetting) { | |
| 69 pNotify->GetDocProvider()->SetCalculationsEnabled(hDoc, | |
| 70 pValue->ToBoolean()); | |
| 71 return; | |
| 72 } | |
| 73 pValue->SetBoolean(pNotify->GetDocProvider()->IsCalculationsEnabled(hDoc)); | |
| 74 } | |
| 75 | |
| 76 void CScript_HostPseudoModel::CurrentPage(CFXJSE_Value* pValue, | |
| 77 FX_BOOL bSetting, | |
| 78 XFA_ATTRIBUTE eAttribute) { | |
| 79 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
| 80 if (!pNotify) { | |
| 81 return; | |
| 82 } | |
| 83 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); | |
| 84 if (bSetting) { | |
| 85 pNotify->GetDocProvider()->SetCurrentPage(hDoc, pValue->ToInteger()); | |
| 86 return; | |
| 87 } | |
| 88 pValue->SetInteger(pNotify->GetDocProvider()->GetCurrentPage(hDoc)); | |
| 89 } | |
| 90 | |
| 91 void CScript_HostPseudoModel::Language(CFXJSE_Value* pValue, | |
| 92 FX_BOOL bSetting, | |
| 93 XFA_ATTRIBUTE eAttribute) { | |
| 94 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
| 95 if (!pNotify) { | |
| 96 return; | |
| 97 } | |
| 98 if (bSetting) { | |
| 99 ThrowException(XFA_IDS_UNABLE_SET_LANGUAGE); | |
| 100 return; | |
| 101 } | |
| 102 CFX_WideString wsLanguage; | |
| 103 pNotify->GetAppProvider()->GetLanguage(wsLanguage); | |
| 104 pValue->SetString(FX_UTF8Encode(wsLanguage).AsStringC()); | |
| 105 } | |
| 106 | |
| 107 void CScript_HostPseudoModel::NumPages(CFXJSE_Value* pValue, | |
| 108 FX_BOOL bSetting, | |
| 109 XFA_ATTRIBUTE eAttribute) { | |
| 110 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
| 111 if (!pNotify) { | |
| 112 return; | |
| 113 } | |
| 114 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); | |
| 115 if (bSetting) { | |
| 116 ThrowException(XFA_IDS_UNABLE_SET_NUMPAGES); | |
| 117 return; | |
| 118 } | |
| 119 pValue->SetInteger(pNotify->GetDocProvider()->CountPages(hDoc)); | |
| 120 } | |
| 121 | |
| 122 void CScript_HostPseudoModel::Platform(CFXJSE_Value* pValue, | |
| 123 FX_BOOL bSetting, | |
| 124 XFA_ATTRIBUTE eAttribute) { | |
| 125 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
| 126 if (!pNotify) { | |
| 127 return; | |
| 128 } | |
| 129 if (bSetting) { | |
| 130 ThrowException(XFA_IDS_UNABLE_SET_PLATFORM); | |
| 131 return; | |
| 132 } | |
| 133 CFX_WideString wsPlatform; | |
| 134 pNotify->GetAppProvider()->GetPlatform(wsPlatform); | |
| 135 pValue->SetString(FX_UTF8Encode(wsPlatform).AsStringC()); | |
| 136 } | |
| 137 void CScript_HostPseudoModel::Title(CFXJSE_Value* pValue, | |
| 138 FX_BOOL bSetting, | |
| 139 XFA_ATTRIBUTE eAttribute) { | |
| 140 if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { | |
| 141 return; | |
| 142 } | |
| 143 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
| 144 if (!pNotify) { | |
| 145 return; | |
| 146 } | |
| 147 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); | |
| 148 if (bSetting) { | |
| 149 pNotify->GetDocProvider()->SetTitle(hDoc, pValue->ToWideString()); | |
| 150 return; | |
| 151 } | |
| 152 CFX_WideString wsTitle; | |
| 153 pNotify->GetDocProvider()->GetTitle(hDoc, wsTitle); | |
| 154 pValue->SetString(FX_UTF8Encode(wsTitle).AsStringC()); | |
| 155 } | |
| 156 | |
| 157 void CScript_HostPseudoModel::ValidationsEnabled(CFXJSE_Value* pValue, | |
| 158 FX_BOOL bSetting, | |
| 159 XFA_ATTRIBUTE eAttribute) { | |
| 160 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
| 161 if (!pNotify) { | |
| 162 return; | |
| 163 } | |
| 164 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); | |
| 165 if (bSetting) { | |
| 166 pNotify->GetDocProvider()->SetValidationsEnabled(hDoc, pValue->ToBoolean()); | |
| 167 return; | |
| 168 } | |
| 169 FX_BOOL bEnabled = pNotify->GetDocProvider()->IsValidationsEnabled(hDoc); | |
| 170 pValue->SetBoolean(bEnabled); | |
| 171 } | |
| 172 void CScript_HostPseudoModel::Variation(CFXJSE_Value* pValue, | |
| 173 FX_BOOL bSetting, | |
| 174 XFA_ATTRIBUTE eAttribute) { | |
| 175 if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { | |
| 176 return; | |
| 177 } | |
| 178 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
| 179 if (!pNotify) { | |
| 180 return; | |
| 181 } | |
| 182 if (bSetting) { | |
| 183 ThrowException(XFA_IDS_UNABLE_SET_VARIATION); | |
| 184 return; | |
| 185 } | |
| 186 CFX_WideString wsVariation; | |
| 187 pNotify->GetAppProvider()->GetVariation(wsVariation); | |
| 188 pValue->SetString(FX_UTF8Encode(wsVariation).AsStringC()); | |
| 189 } | |
| 190 | |
| 191 void CScript_HostPseudoModel::Version(CFXJSE_Value* pValue, | |
| 192 FX_BOOL bSetting, | |
| 193 XFA_ATTRIBUTE eAttribute) { | |
| 194 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
| 195 if (!pNotify) { | |
| 196 return; | |
| 197 } | |
| 198 if (bSetting) { | |
| 199 ThrowException(XFA_IDS_UNABLE_SET_VERSION); | |
| 200 return; | |
| 201 } | |
| 202 CFX_WideString wsVersion; | |
| 203 pNotify->GetAppProvider()->GetVersion(wsVersion); | |
| 204 pValue->SetString(FX_UTF8Encode(wsVersion).AsStringC()); | |
| 205 } | |
| 206 | |
| 207 void CScript_HostPseudoModel::Name(CFXJSE_Value* pValue, | |
| 208 FX_BOOL bSetting, | |
| 209 XFA_ATTRIBUTE eAttribute) { | |
| 210 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
| 211 if (!pNotify) { | |
| 212 return; | |
| 213 } | |
| 214 if (bSetting) { | |
| 215 ThrowException(XFA_IDS_INVAlID_PROP_SET); | |
| 216 return; | |
| 217 } | |
| 218 CFX_WideString wsAppName; | |
| 219 pNotify->GetAppProvider()->GetAppName(wsAppName); | |
| 220 pValue->SetString(FX_UTF8Encode(wsAppName).AsStringC()); | |
| 221 } | |
| 222 | |
| 223 void CScript_HostPseudoModel::GotoURL(CFXJSE_Arguments* pArguments) { | |
| 224 if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { | |
| 225 return; | |
| 226 } | |
| 227 int32_t iLength = pArguments->GetLength(); | |
| 228 if (iLength != 1) { | |
| 229 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"gotoURL"); | |
| 230 return; | |
| 231 } | |
| 232 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
| 233 if (!pNotify) { | |
| 234 return; | |
| 235 } | |
| 236 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); | |
| 237 CFX_WideString wsURL; | |
| 238 if (iLength >= 1) { | |
| 239 CFX_ByteString bsURL = pArguments->GetUTF8String(0); | |
| 240 wsURL = CFX_WideString::FromUTF8(bsURL.AsStringC()); | |
| 241 } | |
| 242 pNotify->GetDocProvider()->GotoURL(hDoc, wsURL); | |
| 243 } | |
| 244 void CScript_HostPseudoModel::OpenList(CFXJSE_Arguments* pArguments) { | |
| 245 if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { | |
| 246 return; | |
| 247 } | |
| 248 int32_t iLength = pArguments->GetLength(); | |
| 249 if (iLength != 1) { | |
| 250 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"openList"); | |
| 251 return; | |
| 252 } | |
| 253 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
| 254 if (!pNotify) { | |
| 255 return; | |
| 256 } | |
| 257 CXFA_Node* pNode = nullptr; | |
| 258 if (iLength >= 1) { | |
| 259 std::unique_ptr<CFXJSE_Value> pValue(pArguments->GetValue(0)); | |
| 260 if (pValue->IsObject()) { | |
| 261 pNode = ToNode(pValue.get(), nullptr); | |
| 262 } else if (pValue->IsString()) { | |
| 263 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); | |
| 264 if (!pScriptContext) | |
| 265 return; | |
| 266 | |
| 267 CXFA_Object* pObject = pScriptContext->GetThisObject(); | |
| 268 if (!pObject) | |
| 269 return; | |
| 270 | |
| 271 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Parent | | |
| 272 XFA_RESOLVENODE_Siblings; | |
| 273 XFA_RESOLVENODE_RS resoveNodeRS; | |
| 274 int32_t iRet = pScriptContext->ResolveObjects( | |
| 275 pObject, pValue->ToWideString().AsStringC(), resoveNodeRS, dwFlag); | |
| 276 if (iRet < 1 || !resoveNodeRS.nodes[0]->IsNode()) | |
| 277 return; | |
| 278 | |
| 279 pNode = resoveNodeRS.nodes[0]->AsNode(); | |
| 280 } | |
| 281 } | |
| 282 CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout(); | |
| 283 if (!pDocLayout) { | |
| 284 return; | |
| 285 } | |
| 286 CXFA_FFWidget* hWidget = | |
| 287 pNotify->GetHWidget(pDocLayout->GetLayoutItem(pNode)); | |
| 288 if (!hWidget) { | |
| 289 return; | |
| 290 } | |
| 291 pNotify->GetDocProvider()->SetFocusWidget(pNotify->GetHDOC(), hWidget); | |
| 292 pNotify->OpenDropDownList(hWidget); | |
| 293 } | |
| 294 void CScript_HostPseudoModel::Response(CFXJSE_Arguments* pArguments) { | |
| 295 int32_t iLength = pArguments->GetLength(); | |
| 296 if (iLength < 1 || iLength > 4) { | |
| 297 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"response"); | |
| 298 return; | |
| 299 } | |
| 300 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
| 301 if (!pNotify) { | |
| 302 return; | |
| 303 } | |
| 304 CFX_WideString wsQuestion; | |
| 305 CFX_WideString wsTitle; | |
| 306 CFX_WideString wsDefaultAnswer; | |
| 307 FX_BOOL bMark = FALSE; | |
| 308 if (iLength >= 1) { | |
| 309 CFX_ByteString bsQuestion = pArguments->GetUTF8String(0); | |
| 310 wsQuestion = CFX_WideString::FromUTF8(bsQuestion.AsStringC()); | |
| 311 } | |
| 312 if (iLength >= 2) { | |
| 313 CFX_ByteString bsTitle = pArguments->GetUTF8String(1); | |
| 314 wsTitle = CFX_WideString::FromUTF8(bsTitle.AsStringC()); | |
| 315 } | |
| 316 if (iLength >= 3) { | |
| 317 CFX_ByteString bsDefaultAnswer = pArguments->GetUTF8String(2); | |
| 318 wsDefaultAnswer = CFX_WideString::FromUTF8(bsDefaultAnswer.AsStringC()); | |
| 319 } | |
| 320 if (iLength >= 4) { | |
| 321 bMark = pArguments->GetInt32(3) == 0 ? FALSE : TRUE; | |
| 322 } | |
| 323 CFX_WideString wsAnswer = pNotify->GetAppProvider()->Response( | |
| 324 wsQuestion, wsTitle, wsDefaultAnswer, bMark); | |
| 325 CFXJSE_Value* pValue = pArguments->GetReturnValue(); | |
| 326 if (pValue) | |
| 327 pValue->SetString(FX_UTF8Encode(wsAnswer).AsStringC()); | |
| 328 } | |
| 329 | |
| 330 void CScript_HostPseudoModel::DocumentInBatch(CFXJSE_Arguments* pArguments) { | |
| 331 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
| 332 if (!pNotify) { | |
| 333 return; | |
| 334 } | |
| 335 int32_t iCur = pNotify->GetAppProvider()->GetCurDocumentInBatch(); | |
| 336 CFXJSE_Value* pValue = pArguments->GetReturnValue(); | |
| 337 if (pValue) | |
| 338 pValue->SetInteger(iCur); | |
| 339 } | |
| 340 static int32_t XFA_FilterName(const CFX_WideStringC& wsExpression, | |
| 341 int32_t nStart, | |
| 342 CFX_WideString& wsFilter) { | |
| 343 ASSERT(nStart > -1); | |
| 344 int32_t iLength = wsExpression.GetLength(); | |
| 345 if (nStart >= iLength) { | |
| 346 return iLength; | |
| 347 } | |
| 348 FX_WCHAR* pBuf = wsFilter.GetBuffer(iLength - nStart); | |
| 349 int32_t nCount = 0; | |
| 350 const FX_WCHAR* pSrc = wsExpression.c_str(); | |
| 351 FX_WCHAR wCur; | |
| 352 while (nStart < iLength) { | |
| 353 wCur = pSrc[nStart++]; | |
| 354 if (wCur == ',') { | |
| 355 break; | |
| 356 } | |
| 357 pBuf[nCount++] = wCur; | |
| 358 } | |
| 359 wsFilter.ReleaseBuffer(nCount); | |
| 360 wsFilter.TrimLeft(); | |
| 361 wsFilter.TrimRight(); | |
| 362 return nStart; | |
| 363 } | |
| 364 void CScript_HostPseudoModel::ResetData(CFXJSE_Arguments* pArguments) { | |
| 365 int32_t iLength = pArguments->GetLength(); | |
| 366 if (iLength < 0 || iLength > 1) { | |
| 367 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"resetData"); | |
| 368 return; | |
| 369 } | |
| 370 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
| 371 if (!pNotify) { | |
| 372 return; | |
| 373 } | |
| 374 CFX_WideString wsExpression; | |
| 375 if (iLength >= 1) { | |
| 376 CFX_ByteString bsExpression = pArguments->GetUTF8String(0); | |
| 377 wsExpression = CFX_WideString::FromUTF8(bsExpression.AsStringC()); | |
| 378 } | |
| 379 if (wsExpression.IsEmpty()) { | |
| 380 pNotify->ResetData(); | |
| 381 return; | |
| 382 } | |
| 383 int32_t iStart = 0; | |
| 384 CFX_WideString wsName; | |
| 385 CXFA_Node* pNode = nullptr; | |
| 386 int32_t iExpLength = wsExpression.GetLength(); | |
| 387 while (iStart < iExpLength) { | |
| 388 iStart = XFA_FilterName(wsExpression.AsStringC(), iStart, wsName); | |
| 389 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); | |
| 390 if (!pScriptContext) { | |
| 391 return; | |
| 392 } | |
| 393 CXFA_Object* pObject = pScriptContext->GetThisObject(); | |
| 394 if (!pObject) { | |
| 395 return; | |
| 396 } | |
| 397 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Parent | | |
| 398 XFA_RESOLVENODE_Siblings; | |
| 399 XFA_RESOLVENODE_RS resoveNodeRS; | |
| 400 int32_t iRet = pScriptContext->ResolveObjects(pObject, wsName.AsStringC(), | |
| 401 resoveNodeRS, dwFlag); | |
| 402 if (iRet < 1 || !resoveNodeRS.nodes[0]->IsNode()) { | |
| 403 continue; | |
| 404 } | |
| 405 pNode = resoveNodeRS.nodes[0]->AsNode(); | |
| 406 pNotify->ResetData(pNode->GetWidgetData()); | |
| 407 } | |
| 408 if (!pNode) { | |
| 409 pNotify->ResetData(); | |
| 410 } | |
| 411 } | |
| 412 void CScript_HostPseudoModel::Beep(CFXJSE_Arguments* pArguments) { | |
| 413 if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { | |
| 414 return; | |
| 415 } | |
| 416 int32_t iLength = pArguments->GetLength(); | |
| 417 if (iLength < 0 || iLength > 1) { | |
| 418 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"beep"); | |
| 419 return; | |
| 420 } | |
| 421 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
| 422 if (!pNotify) { | |
| 423 return; | |
| 424 } | |
| 425 uint32_t dwType = 4; | |
| 426 if (iLength >= 1) { | |
| 427 dwType = pArguments->GetInt32(0); | |
| 428 } | |
| 429 pNotify->GetAppProvider()->Beep(dwType); | |
| 430 } | |
| 431 void CScript_HostPseudoModel::SetFocus(CFXJSE_Arguments* pArguments) { | |
| 432 if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { | |
| 433 return; | |
| 434 } | |
| 435 int32_t iLength = pArguments->GetLength(); | |
| 436 if (iLength != 1) { | |
| 437 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"setFocus"); | |
| 438 return; | |
| 439 } | |
| 440 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
| 441 if (!pNotify) { | |
| 442 return; | |
| 443 } | |
| 444 CXFA_Node* pNode = nullptr; | |
| 445 if (iLength >= 1) { | |
| 446 std::unique_ptr<CFXJSE_Value> pValue(pArguments->GetValue(0)); | |
| 447 if (pValue->IsObject()) { | |
| 448 pNode = ToNode(pValue.get(), nullptr); | |
| 449 } else if (pValue->IsString()) { | |
| 450 CXFA_ScriptContext* pScriptContext = m_pDocument->GetScriptContext(); | |
| 451 if (!pScriptContext) | |
| 452 return; | |
| 453 | |
| 454 CXFA_Object* pObject = pScriptContext->GetThisObject(); | |
| 455 if (!pObject) | |
| 456 return; | |
| 457 | |
| 458 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Parent | | |
| 459 XFA_RESOLVENODE_Siblings; | |
| 460 XFA_RESOLVENODE_RS resoveNodeRS; | |
| 461 int32_t iRet = pScriptContext->ResolveObjects( | |
| 462 pObject, pValue->ToWideString().AsStringC(), resoveNodeRS, dwFlag); | |
| 463 if (iRet < 1 || !resoveNodeRS.nodes[0]->IsNode()) | |
| 464 return; | |
| 465 | |
| 466 pNode = resoveNodeRS.nodes[0]->AsNode(); | |
| 467 } | |
| 468 } | |
| 469 pNotify->SetFocusWidgetNode(pNode); | |
| 470 } | |
| 471 | |
| 472 void CScript_HostPseudoModel::GetFocus(CFXJSE_Arguments* pArguments) { | |
| 473 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
| 474 if (!pNotify) { | |
| 475 return; | |
| 476 } | |
| 477 CXFA_Node* pNode = pNotify->GetFocusWidgetNode(); | |
| 478 if (!pNode) { | |
| 479 return; | |
| 480 } | |
| 481 pArguments->GetReturnValue()->Assign( | |
| 482 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNode)); | |
| 483 } | |
| 484 void CScript_HostPseudoModel::MessageBox(CFXJSE_Arguments* pArguments) { | |
| 485 if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { | |
| 486 return; | |
| 487 } | |
| 488 int32_t iLength = pArguments->GetLength(); | |
| 489 if (iLength < 1 || iLength > 4) { | |
| 490 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"messageBox"); | |
| 491 return; | |
| 492 } | |
| 493 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
| 494 if (!pNotify) { | |
| 495 return; | |
| 496 } | |
| 497 CFX_WideString wsMessage; | |
| 498 CFX_WideString bsTitle; | |
| 499 uint32_t dwMessageType = XFA_MBICON_Error; | |
| 500 uint32_t dwButtonType = XFA_MB_OK; | |
| 501 if (iLength >= 1) { | |
| 502 if (!ValidateArgsForMsg(pArguments, 0, wsMessage)) { | |
| 503 return; | |
| 504 } | |
| 505 } | |
| 506 if (iLength >= 2) { | |
| 507 if (!ValidateArgsForMsg(pArguments, 1, bsTitle)) { | |
| 508 return; | |
| 509 } | |
| 510 } | |
| 511 if (iLength >= 3) { | |
| 512 dwMessageType = pArguments->GetInt32(2); | |
| 513 if (dwMessageType > XFA_MBICON_Status) { | |
| 514 dwMessageType = XFA_MBICON_Error; | |
| 515 } | |
| 516 } | |
| 517 if (iLength >= 4) { | |
| 518 dwButtonType = pArguments->GetInt32(3); | |
| 519 if (dwButtonType > XFA_MB_YesNoCancel) { | |
| 520 dwButtonType = XFA_MB_OK; | |
| 521 } | |
| 522 } | |
| 523 int32_t iValue = pNotify->GetAppProvider()->MsgBox( | |
| 524 wsMessage, bsTitle, dwMessageType, dwButtonType); | |
| 525 CFXJSE_Value* pValue = pArguments->GetReturnValue(); | |
| 526 if (pValue) | |
| 527 pValue->SetInteger(iValue); | |
| 528 } | |
| 529 FX_BOOL CScript_HostPseudoModel::ValidateArgsForMsg( | |
| 530 CFXJSE_Arguments* pArguments, | |
| 531 int32_t iArgIndex, | |
| 532 CFX_WideString& wsValue) { | |
| 533 if (!pArguments || iArgIndex < 0) { | |
| 534 return FALSE; | |
| 535 } | |
| 536 FX_BOOL bIsJsType = FALSE; | |
| 537 if (m_pDocument->GetScriptContext()->GetType() == | |
| 538 XFA_SCRIPTLANGTYPE_Javascript) { | |
| 539 bIsJsType = TRUE; | |
| 540 } | |
| 541 std::unique_ptr<CFXJSE_Value> pValueArg(pArguments->GetValue(iArgIndex)); | |
| 542 if (!pValueArg->IsString() && bIsJsType) { | |
| 543 ThrowException(XFA_IDS_ARGUMENT_MISMATCH); | |
| 544 return FALSE; | |
| 545 } | |
| 546 if (pValueArg->IsNull()) { | |
| 547 wsValue = FX_WSTRC(L""); | |
| 548 } else { | |
| 549 wsValue = pValueArg->ToWideString(); | |
| 550 } | |
| 551 return TRUE; | |
| 552 } | |
| 553 void CScript_HostPseudoModel::DocumentCountInBatch( | |
| 554 CFXJSE_Arguments* pArguments) { | |
| 555 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
| 556 if (!pNotify) { | |
| 557 return; | |
| 558 } | |
| 559 int32_t iValue = pNotify->GetAppProvider()->GetDocumentCountInBatch(); | |
| 560 CFXJSE_Value* pValue = pArguments->GetReturnValue(); | |
| 561 if (pValue) | |
| 562 pValue->SetInteger(iValue); | |
| 563 } | |
| 564 void CScript_HostPseudoModel::Print(CFXJSE_Arguments* pArguments) { | |
| 565 if (!m_pDocument->GetScriptContext()->IsRunAtClient()) { | |
| 566 return; | |
| 567 } | |
| 568 int32_t iLength = pArguments->GetLength(); | |
| 569 if (iLength != 8) { | |
| 570 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"print"); | |
| 571 return; | |
| 572 } | |
| 573 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
| 574 if (!pNotify) { | |
| 575 return; | |
| 576 } | |
| 577 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); | |
| 578 uint32_t dwOptions = 0; | |
| 579 FX_BOOL bShowDialog = TRUE; | |
| 580 if (iLength >= 1) { | |
| 581 bShowDialog = pArguments->GetInt32(0) == 0 ? FALSE : TRUE; | |
| 582 } | |
| 583 if (bShowDialog) { | |
| 584 dwOptions |= XFA_PRINTOPT_ShowDialog; | |
| 585 } | |
| 586 int32_t nStartPage = 0; | |
| 587 if (iLength >= 2) { | |
| 588 nStartPage = pArguments->GetInt32(1); | |
| 589 } | |
| 590 int32_t nEndPage = 0; | |
| 591 if (iLength >= 3) { | |
| 592 nEndPage = pArguments->GetInt32(2); | |
| 593 } | |
| 594 FX_BOOL bCanCancel = TRUE; | |
| 595 if (iLength >= 4) { | |
| 596 bCanCancel = pArguments->GetInt32(3) == 0 ? FALSE : TRUE; | |
| 597 } | |
| 598 if (bCanCancel) { | |
| 599 dwOptions |= XFA_PRINTOPT_CanCancel; | |
| 600 } | |
| 601 FX_BOOL bShrinkPage = TRUE; | |
| 602 if (iLength >= 5) { | |
| 603 bShrinkPage = pArguments->GetInt32(4) == 0 ? FALSE : TRUE; | |
| 604 } | |
| 605 if (bShrinkPage) { | |
| 606 dwOptions |= XFA_PRINTOPT_ShrinkPage; | |
| 607 } | |
| 608 FX_BOOL bAsImage = TRUE; | |
| 609 if (iLength >= 6) { | |
| 610 bAsImage = pArguments->GetInt32(5) == 0 ? FALSE : TRUE; | |
| 611 } | |
| 612 if (bAsImage) { | |
| 613 dwOptions |= XFA_PRINTOPT_AsImage; | |
| 614 } | |
| 615 FX_BOOL bReverseOrder = TRUE; | |
| 616 if (iLength >= 7) { | |
| 617 bAsImage = pArguments->GetInt32(5) == 0 ? FALSE : TRUE; | |
| 618 } | |
| 619 bReverseOrder = pArguments->GetInt32(6) == 0 ? FALSE : TRUE; | |
| 620 if (bReverseOrder) { | |
| 621 dwOptions |= XFA_PRINTOPT_ReverseOrder; | |
| 622 } | |
| 623 FX_BOOL bPrintAnnot = TRUE; | |
| 624 if (iLength >= 8) { | |
| 625 bPrintAnnot = pArguments->GetInt32(7) == 0 ? FALSE : TRUE; | |
| 626 } | |
| 627 if (bPrintAnnot) { | |
| 628 dwOptions |= XFA_PRINTOPT_PrintAnnot; | |
| 629 } | |
| 630 pNotify->GetDocProvider()->Print(hDoc, nStartPage, nEndPage, dwOptions); | |
| 631 } | |
| 632 void CScript_HostPseudoModel::ImportData(CFXJSE_Arguments* pArguments) { | |
| 633 int32_t iLength = pArguments->GetLength(); | |
| 634 if (iLength < 0 || iLength > 1) { | |
| 635 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"importData"); | |
| 636 return; | |
| 637 } | |
| 638 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
| 639 if (!pNotify) { | |
| 640 return; | |
| 641 } | |
| 642 CFX_WideString wsFilePath; | |
| 643 if (iLength > 0) { | |
| 644 CFX_ByteString bsFilePath = pArguments->GetUTF8String(0); | |
| 645 wsFilePath = CFX_WideString::FromUTF8(bsFilePath.AsStringC()); | |
| 646 } | |
| 647 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); | |
| 648 pNotify->GetDocProvider()->ImportData(hDoc, wsFilePath); | |
| 649 } | |
| 650 void CScript_HostPseudoModel::ExportData(CFXJSE_Arguments* pArguments) { | |
| 651 int32_t iLength = pArguments->GetLength(); | |
| 652 if (iLength < 0 || iLength > 2) { | |
| 653 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"exportData"); | |
| 654 return; | |
| 655 } | |
| 656 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
| 657 if (!pNotify) { | |
| 658 return; | |
| 659 } | |
| 660 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); | |
| 661 CFX_WideString wsFilePath; | |
| 662 FX_BOOL bXDP = TRUE; | |
| 663 if (iLength >= 1) { | |
| 664 CFX_ByteString bsFilePath = pArguments->GetUTF8String(0); | |
| 665 wsFilePath = CFX_WideString::FromUTF8(bsFilePath.AsStringC()); | |
| 666 } | |
| 667 if (iLength >= 2) { | |
| 668 bXDP = pArguments->GetInt32(1) == 0 ? FALSE : TRUE; | |
| 669 } | |
| 670 pNotify->GetDocProvider()->ExportData(hDoc, wsFilePath, bXDP); | |
| 671 } | |
| 672 | |
| 673 void CScript_HostPseudoModel::PageUp(CFXJSE_Arguments* pArguments) { | |
| 674 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
| 675 if (!pNotify) { | |
| 676 return; | |
| 677 } | |
| 678 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); | |
| 679 int32_t nCurPage = pNotify->GetDocProvider()->GetCurrentPage(hDoc); | |
| 680 int32_t nNewPage = 0; | |
| 681 if (nCurPage <= 1) { | |
| 682 return; | |
| 683 } | |
| 684 nNewPage = nCurPage - 1; | |
| 685 pNotify->GetDocProvider()->SetCurrentPage(hDoc, nNewPage); | |
| 686 } | |
| 687 | |
| 688 void CScript_HostPseudoModel::PageDown(CFXJSE_Arguments* pArguments) { | |
| 689 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
| 690 if (!pNotify) { | |
| 691 return; | |
| 692 } | |
| 693 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); | |
| 694 int32_t nCurPage = pNotify->GetDocProvider()->GetCurrentPage(hDoc); | |
| 695 int32_t nPageCount = pNotify->GetDocProvider()->CountPages(hDoc); | |
| 696 if (!nPageCount || nCurPage == nPageCount) { | |
| 697 return; | |
| 698 } | |
| 699 int32_t nNewPage = 0; | |
| 700 if (nCurPage >= nPageCount) { | |
| 701 nNewPage = nPageCount - 1; | |
| 702 } else { | |
| 703 nNewPage = nCurPage + 1; | |
| 704 } | |
| 705 pNotify->GetDocProvider()->SetCurrentPage(hDoc, nNewPage); | |
| 706 } | |
| 707 | |
| 708 void CScript_HostPseudoModel::CurrentDateTime(CFXJSE_Arguments* pArguments) { | |
| 709 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
| 710 if (!pNotify) { | |
| 711 return; | |
| 712 } | |
| 713 CFX_WideString wsDataTime = pNotify->GetCurrentDateTime(); | |
| 714 CFXJSE_Value* pValue = pArguments->GetReturnValue(); | |
| 715 if (pValue) | |
| 716 pValue->SetString(FX_UTF8Encode(wsDataTime).AsStringC()); | |
| 717 } | |
| OLD | NEW |