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