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_layoutpseudomodel.h" | |
8 | |
9 #include <set> | |
10 | |
11 #include "fxjs/include/cfxjse_arguments.h" | |
12 #include "third_party/base/stl_util.h" | |
13 #include "xfa/fxfa/app/xfa_ffnotify.h" | |
14 #include "xfa/fxfa/parser/xfa_doclayout.h" | |
15 #include "xfa/fxfa/parser/xfa_document.h" | |
16 #include "xfa/fxfa/parser/xfa_document_layout_imp.h" | |
17 #include "xfa/fxfa/parser/xfa_layout_appadapter.h" | |
18 #include "xfa/fxfa/parser/xfa_localemgr.h" | |
19 #include "xfa/fxfa/parser/xfa_object.h" | |
20 #include "xfa/fxfa/parser/xfa_script.h" | |
21 #include "xfa/fxfa/parser/xfa_script_imp.h" | |
22 #include "xfa/fxfa/parser/xfa_utils.h" | |
23 | |
24 CScript_LayoutPseudoModel::CScript_LayoutPseudoModel(CXFA_Document* pDocument) | |
25 : CXFA_Object(pDocument, | |
26 XFA_ObjectType::Object, | |
27 XFA_Element::LayoutPseudoModel, | |
28 CFX_WideStringC(L"layoutPseudoModel")) {} | |
29 | |
30 CScript_LayoutPseudoModel::~CScript_LayoutPseudoModel() {} | |
31 | |
32 void CScript_LayoutPseudoModel::Ready(CFXJSE_Value* pValue, | |
33 FX_BOOL bSetting, | |
34 XFA_ATTRIBUTE eAttribute) { | |
35 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
36 if (!pNotify) { | |
37 return; | |
38 } | |
39 if (bSetting) { | |
40 ThrowException(XFA_IDS_UNABLE_SET_READY); | |
41 return; | |
42 } | |
43 int32_t iStatus = pNotify->GetLayoutStatus(); | |
44 pValue->SetBoolean(iStatus >= 2); | |
45 } | |
46 void CScript_LayoutPseudoModel::HWXY(CFXJSE_Arguments* pArguments, | |
47 XFA_LAYOUTMODEL_HWXY layoutModel) { | |
48 int32_t iLength = pArguments->GetLength(); | |
49 if (iLength < 1 || iLength > 3) { | |
50 const FX_WCHAR* methodName = nullptr; | |
51 switch (layoutModel) { | |
52 case XFA_LAYOUTMODEL_H: | |
53 methodName = L"h"; | |
54 break; | |
55 case XFA_LAYOUTMODEL_W: | |
56 methodName = L"w"; | |
57 break; | |
58 case XFA_LAYOUTMODEL_X: | |
59 methodName = L"x"; | |
60 break; | |
61 case XFA_LAYOUTMODEL_Y: | |
62 methodName = L"y"; | |
63 break; | |
64 } | |
65 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, methodName); | |
66 return; | |
67 } | |
68 CXFA_Node* pNode = nullptr; | |
69 CFX_WideString wsUnit(L"pt"); | |
70 int32_t iIndex = 0; | |
71 if (iLength >= 1) { | |
72 pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); | |
73 } | |
74 if (iLength >= 2) { | |
75 CFX_ByteString bsUnit = pArguments->GetUTF8String(1); | |
76 if (!bsUnit.IsEmpty()) { | |
77 wsUnit = CFX_WideString::FromUTF8(bsUnit.AsStringC()); | |
78 } | |
79 } | |
80 if (iLength >= 3) { | |
81 iIndex = pArguments->GetInt32(2); | |
82 } | |
83 if (!pNode) { | |
84 return; | |
85 } | |
86 CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout(); | |
87 if (!pDocLayout) { | |
88 return; | |
89 } | |
90 CFX_RectF rtRect; | |
91 CXFA_Measurement measure; | |
92 CXFA_LayoutItem* pLayoutItem = pDocLayout->GetLayoutItem(pNode); | |
93 if (!pLayoutItem) { | |
94 return; | |
95 } | |
96 while (iIndex > 0 && pLayoutItem) { | |
97 pLayoutItem = pLayoutItem->GetNext(); | |
98 iIndex--; | |
99 } | |
100 CFXJSE_Value* pValue = pArguments->GetReturnValue(); | |
101 if (!pLayoutItem) { | |
102 pValue->SetFloat(0); | |
103 return; | |
104 } | |
105 pLayoutItem->GetRect(rtRect, TRUE); | |
106 switch (layoutModel) { | |
107 case XFA_LAYOUTMODEL_H: | |
108 measure.Set(rtRect.height, XFA_UNIT_Pt); | |
109 break; | |
110 case XFA_LAYOUTMODEL_W: | |
111 measure.Set(rtRect.width, XFA_UNIT_Pt); | |
112 break; | |
113 case XFA_LAYOUTMODEL_X: | |
114 measure.Set(rtRect.left, XFA_UNIT_Pt); | |
115 break; | |
116 case XFA_LAYOUTMODEL_Y: | |
117 measure.Set(rtRect.top, XFA_UNIT_Pt); | |
118 break; | |
119 } | |
120 XFA_UNIT unit = measure.GetUnit(wsUnit.AsStringC()); | |
121 FX_FLOAT fValue = measure.ToUnit(unit); | |
122 fValue = FXSYS_round(fValue * 1000) / 1000.0f; | |
123 if (pValue) | |
124 pValue->SetFloat(fValue); | |
125 } | |
126 void CScript_LayoutPseudoModel::H(CFXJSE_Arguments* pArguments) { | |
127 HWXY(pArguments, XFA_LAYOUTMODEL_H); | |
128 } | |
129 void CScript_LayoutPseudoModel::W(CFXJSE_Arguments* pArguments) { | |
130 HWXY(pArguments, XFA_LAYOUTMODEL_W); | |
131 } | |
132 void CScript_LayoutPseudoModel::X(CFXJSE_Arguments* pArguments) { | |
133 HWXY(pArguments, XFA_LAYOUTMODEL_X); | |
134 } | |
135 void CScript_LayoutPseudoModel::Y(CFXJSE_Arguments* pArguments) { | |
136 HWXY(pArguments, XFA_LAYOUTMODEL_Y); | |
137 } | |
138 void CScript_LayoutPseudoModel::NumberedPageCount(CFXJSE_Arguments* pArguments, | |
139 FX_BOOL bNumbered) { | |
140 CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout(); | |
141 if (!pDocLayout) { | |
142 return; | |
143 } | |
144 int32_t iPageCount = 0; | |
145 int32_t iPageNum = pDocLayout->CountPages(); | |
146 if (bNumbered) { | |
147 for (int32_t i = 0; i < iPageNum; i++) { | |
148 CXFA_ContainerLayoutItem* pLayoutPage = pDocLayout->GetPage(i); | |
149 if (!pLayoutPage) { | |
150 continue; | |
151 } | |
152 CXFA_Node* pMasterPage = pLayoutPage->GetMasterPage(); | |
153 if (pMasterPage->GetInteger(XFA_ATTRIBUTE_Numbered)) { | |
154 iPageCount++; | |
155 } | |
156 } | |
157 } else { | |
158 iPageCount = iPageNum; | |
159 } | |
160 CFXJSE_Value* pValue = pArguments->GetReturnValue(); | |
161 if (pValue) | |
162 pValue->SetInteger(iPageCount); | |
163 } | |
164 void CScript_LayoutPseudoModel::PageCount(CFXJSE_Arguments* pArguments) { | |
165 NumberedPageCount(pArguments, TRUE); | |
166 } | |
167 void CScript_LayoutPseudoModel::PageSpan(CFXJSE_Arguments* pArguments) { | |
168 int32_t iLength = pArguments->GetLength(); | |
169 if (iLength != 1) { | |
170 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"pageSpan"); | |
171 return; | |
172 } | |
173 CXFA_Node* pNode = nullptr; | |
174 if (iLength >= 1) { | |
175 pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); | |
176 } | |
177 if (!pNode) { | |
178 return; | |
179 } | |
180 CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout(); | |
181 if (!pDocLayout) { | |
182 return; | |
183 } | |
184 CFXJSE_Value* pValue = pArguments->GetReturnValue(); | |
185 CXFA_LayoutItem* pLayoutItem = pDocLayout->GetLayoutItem(pNode); | |
186 if (!pLayoutItem) { | |
187 pValue->SetInteger(-1); | |
188 return; | |
189 } | |
190 int32_t iLast = pLayoutItem->GetLast()->GetPage()->GetPageIndex(); | |
191 int32_t iFirst = pLayoutItem->GetFirst()->GetPage()->GetPageIndex(); | |
192 int32_t iPageSpan = iLast - iFirst + 1; | |
193 if (pValue) | |
194 pValue->SetInteger(iPageSpan); | |
195 } | |
196 void CScript_LayoutPseudoModel::Page(CFXJSE_Arguments* pArguments) { | |
197 PageImp(pArguments, FALSE); | |
198 } | |
199 void CScript_LayoutPseudoModel::GetObjArray(CXFA_LayoutProcessor* pDocLayout, | |
200 int32_t iPageNo, | |
201 const CFX_WideString& wsType, | |
202 FX_BOOL bOnPageArea, | |
203 CXFA_NodeArray& retArray) { | |
204 CXFA_ContainerLayoutItem* pLayoutPage = pDocLayout->GetPage(iPageNo); | |
205 if (!pLayoutPage) { | |
206 return; | |
207 } | |
208 if (wsType == FX_WSTRC(L"pageArea")) { | |
209 if (CXFA_Node* pMasterPage = pLayoutPage->m_pFormNode) { | |
210 retArray.Add(pMasterPage); | |
211 } | |
212 return; | |
213 } | |
214 if (wsType == FX_WSTRC(L"contentArea")) { | |
215 for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem; | |
216 pItem = pItem->m_pNextSibling) { | |
217 if (pItem->m_pFormNode->GetElementType() == XFA_Element::ContentArea) { | |
218 retArray.Add(pItem->m_pFormNode); | |
219 } | |
220 } | |
221 return; | |
222 } | |
223 std::set<CXFA_Node*> formItems; | |
224 if (wsType.IsEmpty()) { | |
225 if (CXFA_Node* pMasterPage = pLayoutPage->m_pFormNode) { | |
226 retArray.Add(pMasterPage); | |
227 } | |
228 for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem; | |
229 pItem = pItem->m_pNextSibling) { | |
230 if (pItem->m_pFormNode->GetElementType() == XFA_Element::ContentArea) { | |
231 retArray.Add(pItem->m_pFormNode); | |
232 if (!bOnPageArea) { | |
233 CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem, | |
234 CXFA_TraverseStrategy_ContentLayoutItem> | |
235 iterator(static_cast<CXFA_ContentLayoutItem*>(pItem->m_pFirstChild)); | |
236 for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); | |
237 pItemChild; pItemChild = iterator.MoveToNext()) { | |
238 if (!pItemChild->IsContentLayoutItem()) { | |
239 continue; | |
240 } | |
241 XFA_Element eType = pItemChild->m_pFormNode->GetElementType(); | |
242 if (eType != XFA_Element::Field && eType != XFA_Element::Draw && | |
243 eType != XFA_Element::Subform && eType != XFA_Element::Area) { | |
244 continue; | |
245 } | |
246 if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode)) | |
247 continue; | |
248 | |
249 formItems.insert(pItemChild->m_pFormNode); | |
250 retArray.Add(pItemChild->m_pFormNode); | |
251 } | |
252 } | |
253 } else { | |
254 if (bOnPageArea) { | |
255 CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem, | |
256 CXFA_TraverseStrategy_ContentLayoutItem> | |
257 iterator(static_cast<CXFA_ContentLayoutItem*>(pItem)); | |
258 for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); | |
259 pItemChild; pItemChild = iterator.MoveToNext()) { | |
260 if (!pItemChild->IsContentLayoutItem()) { | |
261 continue; | |
262 } | |
263 XFA_Element eType = pItemChild->m_pFormNode->GetElementType(); | |
264 if (eType != XFA_Element::Field && eType != XFA_Element::Draw && | |
265 eType != XFA_Element::Subform && eType != XFA_Element::Area) { | |
266 continue; | |
267 } | |
268 if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode)) | |
269 continue; | |
270 formItems.insert(pItemChild->m_pFormNode); | |
271 retArray.Add(pItemChild->m_pFormNode); | |
272 } | |
273 } | |
274 } | |
275 } | |
276 return; | |
277 } | |
278 XFA_Element eType = XFA_Element::Unknown; | |
279 if (wsType == FX_WSTRC(L"field")) { | |
280 eType = XFA_Element::Field; | |
281 } else if (wsType == FX_WSTRC(L"draw")) { | |
282 eType = XFA_Element::Draw; | |
283 } else if (wsType == FX_WSTRC(L"subform")) { | |
284 eType = XFA_Element::Subform; | |
285 } else if (wsType == FX_WSTRC(L"area")) { | |
286 eType = XFA_Element::Area; | |
287 } | |
288 if (eType != XFA_Element::Unknown) { | |
289 for (CXFA_LayoutItem* pItem = pLayoutPage->m_pFirstChild; pItem; | |
290 pItem = pItem->m_pNextSibling) { | |
291 if (pItem->m_pFormNode->GetElementType() == XFA_Element::ContentArea) { | |
292 if (!bOnPageArea) { | |
293 CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem, | |
294 CXFA_TraverseStrategy_ContentLayoutItem> | |
295 iterator(static_cast<CXFA_ContentLayoutItem*>(pItem->m_pFirstChild)); | |
296 for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); | |
297 pItemChild; pItemChild = iterator.MoveToNext()) { | |
298 if (!pItemChild->IsContentLayoutItem()) | |
299 continue; | |
300 if (pItemChild->m_pFormNode->GetElementType() != eType) | |
301 continue; | |
302 if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode)) | |
303 continue; | |
304 formItems.insert(pItemChild->m_pFormNode); | |
305 retArray.Add(pItemChild->m_pFormNode); | |
306 } | |
307 } | |
308 } else { | |
309 if (bOnPageArea) { | |
310 CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItem, | |
311 CXFA_TraverseStrategy_ContentLayoutItem> | |
312 iterator(static_cast<CXFA_ContentLayoutItem*>(pItem)); | |
313 for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); | |
314 pItemChild; pItemChild = iterator.MoveToNext()) { | |
315 if (!pItemChild->IsContentLayoutItem()) | |
316 continue; | |
317 if (pItemChild->m_pFormNode->GetElementType() != eType) | |
318 continue; | |
319 if (pdfium::ContainsValue(formItems, pItemChild->m_pFormNode)) | |
320 continue; | |
321 formItems.insert(pItemChild->m_pFormNode); | |
322 retArray.Add(pItemChild->m_pFormNode); | |
323 } | |
324 } | |
325 } | |
326 } | |
327 return; | |
328 } | |
329 } | |
330 void CScript_LayoutPseudoModel::PageContent(CFXJSE_Arguments* pArguments) { | |
331 int32_t iLength = pArguments->GetLength(); | |
332 if (iLength < 1 || iLength > 3) { | |
333 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"pageContent"); | |
334 return; | |
335 } | |
336 int32_t iIndex = 0; | |
337 CFX_WideString wsType; | |
338 FX_BOOL bOnPageArea = FALSE; | |
339 if (iLength >= 1) { | |
340 iIndex = pArguments->GetInt32(0); | |
341 } | |
342 if (iLength >= 2) { | |
343 CFX_ByteString bsType = pArguments->GetUTF8String(1); | |
344 wsType = CFX_WideString::FromUTF8(bsType.AsStringC()); | |
345 } | |
346 if (iLength >= 3) { | |
347 bOnPageArea = pArguments->GetInt32(2) == 0 ? FALSE : TRUE; | |
348 } | |
349 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
350 if (!pNotify) { | |
351 return; | |
352 } | |
353 CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout(); | |
354 if (!pDocLayout) { | |
355 return; | |
356 } | |
357 CXFA_NodeArray retArray; | |
358 GetObjArray(pDocLayout, iIndex, wsType, bOnPageArea, retArray); | |
359 CXFA_ArrayNodeList* pArrayNodeList = new CXFA_ArrayNodeList(m_pDocument); | |
360 pArrayNodeList->SetArrayNodeList(retArray); | |
361 pArguments->GetReturnValue()->SetObject( | |
362 pArrayNodeList, m_pDocument->GetScriptContext()->GetJseNormalClass()); | |
363 } | |
364 void CScript_LayoutPseudoModel::AbsPageCount(CFXJSE_Arguments* pArguments) { | |
365 NumberedPageCount(pArguments, FALSE); | |
366 } | |
367 void CScript_LayoutPseudoModel::AbsPageCountInBatch( | |
368 CFXJSE_Arguments* pArguments) { | |
369 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
370 if (!pNotify) { | |
371 return; | |
372 } | |
373 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); | |
374 int32_t iPageCount = pNotify->GetDocProvider()->AbsPageCountInBatch(hDoc); | |
375 CFXJSE_Value* pValue = pArguments->GetReturnValue(); | |
376 if (pValue) | |
377 pValue->SetInteger(iPageCount); | |
378 } | |
379 void CScript_LayoutPseudoModel::SheetCountInBatch( | |
380 CFXJSE_Arguments* pArguments) { | |
381 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
382 if (!pNotify) { | |
383 return; | |
384 } | |
385 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); | |
386 int32_t iPageCount = pNotify->GetDocProvider()->SheetCountInBatch(hDoc); | |
387 CFXJSE_Value* pValue = pArguments->GetReturnValue(); | |
388 if (pValue) | |
389 pValue->SetInteger(iPageCount); | |
390 } | |
391 void CScript_LayoutPseudoModel::Relayout(CFXJSE_Arguments* pArguments) { | |
392 CXFA_Node* pRootNode = m_pDocument->GetRoot(); | |
393 CXFA_Node* pFormRoot = pRootNode->GetFirstChildByClass(XFA_Element::Form); | |
394 ASSERT(pFormRoot); | |
395 CXFA_Node* pContentRootNode = pFormRoot->GetNodeItem(XFA_NODEITEM_FirstChild); | |
396 CXFA_LayoutProcessor* pLayoutProcessor = m_pDocument->GetLayoutProcessor(); | |
397 if (pContentRootNode) { | |
398 pLayoutProcessor->AddChangedContainer(pContentRootNode); | |
399 } | |
400 pLayoutProcessor->SetForceReLayout(TRUE); | |
401 } | |
402 void CScript_LayoutPseudoModel::AbsPageSpan(CFXJSE_Arguments* pArguments) { | |
403 PageSpan(pArguments); | |
404 } | |
405 void CScript_LayoutPseudoModel::AbsPageInBatch(CFXJSE_Arguments* pArguments) { | |
406 int32_t iLength = pArguments->GetLength(); | |
407 if (iLength != 1) { | |
408 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"absPageInBatch"); | |
409 return; | |
410 } | |
411 CXFA_Node* pNode = nullptr; | |
412 if (iLength >= 1) { | |
413 pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); | |
414 } | |
415 if (!pNode) { | |
416 return; | |
417 } | |
418 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
419 if (!pNotify) { | |
420 return; | |
421 } | |
422 CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout(); | |
423 if (!pDocLayout) { | |
424 return; | |
425 } | |
426 CXFA_FFWidget* hWidget = | |
427 pNotify->GetHWidget(pDocLayout->GetLayoutItem(pNode)); | |
428 if (!hWidget) { | |
429 return; | |
430 } | |
431 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); | |
432 int32_t iPageCount = pNotify->GetDocProvider()->AbsPageInBatch(hDoc, hWidget); | |
433 CFXJSE_Value* pValue = pArguments->GetReturnValue(); | |
434 if (pValue) | |
435 pValue->SetInteger(iPageCount); | |
436 } | |
437 void CScript_LayoutPseudoModel::SheetInBatch(CFXJSE_Arguments* pArguments) { | |
438 int32_t iLength = pArguments->GetLength(); | |
439 if (iLength != 1) { | |
440 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"sheetInBatch"); | |
441 return; | |
442 } | |
443 CXFA_Node* pNode = nullptr; | |
444 if (iLength >= 1) { | |
445 pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); | |
446 } | |
447 if (!pNode) { | |
448 return; | |
449 } | |
450 CXFA_FFNotify* pNotify = m_pDocument->GetNotify(); | |
451 if (!pNotify) { | |
452 return; | |
453 } | |
454 CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout(); | |
455 if (!pDocLayout) { | |
456 return; | |
457 } | |
458 CXFA_FFWidget* hWidget = | |
459 pNotify->GetHWidget(pDocLayout->GetLayoutItem(pNode)); | |
460 if (!hWidget) { | |
461 return; | |
462 } | |
463 CXFA_FFDoc* hDoc = pNotify->GetHDOC(); | |
464 int32_t iPageCount = pNotify->GetDocProvider()->SheetInBatch(hDoc, hWidget); | |
465 CFXJSE_Value* pValue = pArguments->GetReturnValue(); | |
466 if (pValue) | |
467 pValue->SetInteger(iPageCount); | |
468 } | |
469 void CScript_LayoutPseudoModel::Sheet(CFXJSE_Arguments* pArguments) { | |
470 PageImp(pArguments, TRUE); | |
471 } | |
472 void CScript_LayoutPseudoModel::RelayoutPageArea(CFXJSE_Arguments* pArguments) { | |
473 } | |
474 void CScript_LayoutPseudoModel::SheetCount(CFXJSE_Arguments* pArguments) { | |
475 NumberedPageCount(pArguments, FALSE); | |
476 } | |
477 void CScript_LayoutPseudoModel::AbsPage(CFXJSE_Arguments* pArguments) { | |
478 PageImp(pArguments, TRUE); | |
479 } | |
480 void CScript_LayoutPseudoModel::PageImp(CFXJSE_Arguments* pArguments, | |
481 FX_BOOL bAbsPage) { | |
482 int32_t iLength = pArguments->GetLength(); | |
483 if (iLength != 1) { | |
484 const FX_WCHAR* methodName; | |
485 if (bAbsPage) { | |
486 methodName = L"absPage"; | |
487 } else { | |
488 methodName = L"page"; | |
489 } | |
490 ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, methodName); | |
491 return; | |
492 } | |
493 CXFA_Node* pNode = nullptr; | |
494 if (iLength >= 1) { | |
495 pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); | |
496 } | |
497 int32_t iPage = 0; | |
498 CFXJSE_Value* pValue = pArguments->GetReturnValue(); | |
499 if (!pNode && pValue) | |
500 pValue->SetInteger(iPage); | |
501 | |
502 CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout(); | |
503 if (!pDocLayout) { | |
504 return; | |
505 } | |
506 CXFA_LayoutItem* pLayoutItem = pDocLayout->GetLayoutItem(pNode); | |
507 if (!pLayoutItem) { | |
508 pValue->SetInteger(-1); | |
509 return; | |
510 } | |
511 iPage = pLayoutItem->GetFirst()->GetPage()->GetPageIndex(); | |
512 if (pValue) | |
513 pValue->SetInteger(bAbsPage ? iPage : iPage + 1); | |
514 } | |
OLD | NEW |