b2354b6f140da8319a1fa117f7b8ba31a299b117
[pdfium.git] / xfa / src / fxfa / src / parser / xfa_script_layoutpseudomodel.cpp
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4 \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #include "../../../foxitlib.h"\r
8 #include "../common/xfa_utils.h"\r
9 #include "../common/xfa_object.h"\r
10 #include "../common/xfa_document.h"\r
11 #include "../common/xfa_parser.h"\r
12 #include "../common/xfa_script.h"\r
13 #include "../common/xfa_docdata.h"\r
14 #include "../common/xfa_doclayout.h"\r
15 #include "../common/xfa_debug.h"\r
16 #include "../common/xfa_localemgr.h"\r
17 #include "../common/xfa_fm2jsapi.h"\r
18 #include "xfa_debug_parser.h"\r
19 #include "xfa_script_layoutpseudomodel.h"\r
20 #include "xfa_document_layout_imp.h"\r
21 #include "xfa_layout_appadapter.h"\r
22 CScript_LayoutPseudoModel::CScript_LayoutPseudoModel(CXFA_Document* pDocument)\r
23     : CXFA_OrdinaryObject(pDocument, XFA_ELEMENT_LayoutPseudoModel)\r
24 {\r
25     m_uScriptHash = XFA_HASHCODE_Layout;\r
26 }\r
27 CScript_LayoutPseudoModel::~CScript_LayoutPseudoModel()\r
28 {\r
29 }\r
30 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_Ready(FXJSE_HVALUE hValue, FX_BOOL bSetting, XFA_ATTRIBUTE eAttribute)\r
31 {\r
32     IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();\r
33     if (!pNotify) {\r
34         return;\r
35     }\r
36     IXFA_Doc* hDoc = pNotify->GetHDOC();\r
37     if (bSetting) {\r
38         ThrowScriptErrorMessage(XFA_IDS_UNABLE_SET_READY);\r
39         return;\r
40     }\r
41     FX_INT32 iStatus = pNotify->GetLayoutStatus();\r
42     FXJSE_Value_SetBoolean(hValue, iStatus >= 2);\r
43 }\r
44 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_HWXY(CFXJSE_Arguments* pArguments, XFA_LAYOUTMODEL_HWXY layoutModel)\r
45 {\r
46     FX_INT32 iLength = pArguments->GetLength();\r
47     if ( iLength < 1 || iLength > 3) {\r
48         FX_LPCWSTR methodName = NULL;\r
49         switch (layoutModel) {\r
50             case XFA_LAYOUTMODEL_H:\r
51                 methodName = L"h";\r
52                 break;\r
53             case XFA_LAYOUTMODEL_W:\r
54                 methodName = L"w";\r
55                 break;\r
56             case XFA_LAYOUTMODEL_X:\r
57                 methodName = L"x";\r
58                 break;\r
59             case XFA_LAYOUTMODEL_Y:\r
60                 methodName = L"y";\r
61                 break;\r
62         }\r
63         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, methodName);\r
64         return;\r
65     }\r
66     CXFA_Node* pNode = NULL;\r
67     CFX_WideString wsUnit = FX_WSTRC(L"pt");\r
68     FX_INT32 iIndex = 0;\r
69     if (iLength >= 1) {\r
70         pNode = (CXFA_Node*)pArguments->GetObject(0);\r
71     }\r
72     if (iLength >= 2) {\r
73         CFX_ByteString bsUnit = pArguments->GetUTF8String(1);\r
74         if (!bsUnit.IsEmpty()) {\r
75             wsUnit = CFX_WideString::FromUTF8(bsUnit, bsUnit.GetLength());\r
76         }\r
77     }\r
78     if (iLength >= 3) {\r
79         iIndex = pArguments->GetInt32(2);\r
80     }\r
81     if (!pNode) {\r
82         return;\r
83     }\r
84     IXFA_DocLayout* pDocLayout = m_pDocument->GetDocLayout();\r
85     if (!pDocLayout) {\r
86         return;\r
87     }\r
88     CFX_RectF rtRect;\r
89     CXFA_Measurement measure;\r
90     CXFA_LayoutItem* pLayoutItem = pDocLayout->GetLayoutItem(pNode);\r
91     if (!pLayoutItem) {\r
92         return;\r
93     }\r
94     while (iIndex > 0 && pLayoutItem) {\r
95         pLayoutItem = pLayoutItem->GetNext();\r
96         iIndex --;\r
97     }\r
98     FXJSE_HVALUE hValue =  pArguments->GetReturnValue();\r
99     if (!pLayoutItem) {\r
100         FXJSE_Value_SetFloat(hValue, 0);\r
101         return;\r
102     }\r
103     pLayoutItem->GetRect(rtRect, TRUE);\r
104     switch (layoutModel) {\r
105         case XFA_LAYOUTMODEL_H:\r
106             measure.Set(rtRect.height, XFA_UNIT_Pt);\r
107             break;\r
108         case XFA_LAYOUTMODEL_W:\r
109             measure.Set(rtRect.width, XFA_UNIT_Pt);\r
110             break;\r
111         case XFA_LAYOUTMODEL_X:\r
112             measure.Set(rtRect.left, XFA_UNIT_Pt);\r
113             break;\r
114         case XFA_LAYOUTMODEL_Y:\r
115             measure.Set(rtRect.top, XFA_UNIT_Pt);\r
116             break;\r
117     }\r
118     XFA_UNIT unit =     measure.GetUnit(wsUnit);\r
119     FX_FLOAT fValue = measure.ToUnit(unit);\r
120     fValue = FXSYS_round(fValue * 1000) / 1000.0f;\r
121     if (hValue) {\r
122         FXJSE_Value_SetFloat(hValue, fValue);\r
123     }\r
124 }\r
125 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_H(CFXJSE_Arguments* pArguments)\r
126 {\r
127     Script_LayoutPseudoModel_HWXY(pArguments, XFA_LAYOUTMODEL_H);\r
128 }\r
129 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_W(CFXJSE_Arguments* pArguments)\r
130 {\r
131     Script_LayoutPseudoModel_HWXY(pArguments, XFA_LAYOUTMODEL_W);\r
132 }\r
133 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_X(CFXJSE_Arguments* pArguments)\r
134 {\r
135     Script_LayoutPseudoModel_HWXY(pArguments, XFA_LAYOUTMODEL_X);\r
136 }\r
137 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_Y(CFXJSE_Arguments* pArguments)\r
138 {\r
139     Script_LayoutPseudoModel_HWXY(pArguments, XFA_LAYOUTMODEL_Y);\r
140 }\r
141 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_NumberedPageCount(CFXJSE_Arguments* pArguments, FX_BOOL bNumbered)\r
142 {\r
143     IXFA_DocLayout* pDocLayout = m_pDocument->GetDocLayout();\r
144     if (!pDocLayout) {\r
145         return;\r
146     }\r
147     FX_INT32 iPageCount = 0;\r
148     FX_INT32 iPageNum = pDocLayout->CountPages();\r
149     if (bNumbered) {\r
150         for (FX_INT32 i = 0; i < iPageNum; i++) {\r
151             IXFA_LayoutPage* pLayoutPage = pDocLayout->GetPage(i);\r
152             if (!pLayoutPage) {\r
153                 continue;\r
154             }\r
155             CXFA_Node* pMasterPage = pLayoutPage->GetMasterPage();\r
156             if (pMasterPage->GetInteger(XFA_ATTRIBUTE_Numbered)) {\r
157                 iPageCount++;\r
158             }\r
159         }\r
160     } else {\r
161         iPageCount = iPageNum;\r
162     }\r
163     FXJSE_HVALUE hValue =  pArguments->GetReturnValue();\r
164     if (hValue) {\r
165         FXJSE_Value_SetInteger(hValue, iPageCount);\r
166     }\r
167 }\r
168 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_PageCount(CFXJSE_Arguments* pArguments)\r
169 {\r
170     Script_LayoutPseudoModel_NumberedPageCount(pArguments, TRUE);\r
171 }\r
172 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_PageSpan(CFXJSE_Arguments* pArguments)\r
173 {\r
174     FX_INT32 iLength = pArguments->GetLength();\r
175     if (iLength != 1) {\r
176         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"pageSpan");\r
177         return;\r
178     }\r
179     CXFA_Node* pNode = NULL;\r
180     if (iLength >= 1) {\r
181         pNode = (CXFA_Node*)pArguments->GetObject(0);\r
182     }\r
183     if (!pNode) {\r
184         return;\r
185     }\r
186     IXFA_DocLayout* pDocLayout = m_pDocument->GetDocLayout();\r
187     if (!pDocLayout) {\r
188         return;\r
189     }\r
190     FXJSE_HVALUE hValue =  pArguments->GetReturnValue();\r
191     CXFA_LayoutItem* pLayoutItem = pDocLayout->GetLayoutItem(pNode);\r
192     if (!pLayoutItem) {\r
193         FXJSE_Value_SetInteger(hValue, -1);\r
194         return;\r
195     }\r
196     FX_INT32 iLast = pLayoutItem->GetLast()->GetPage()->GetPageIndex();\r
197     FX_INT32 iFirst = pLayoutItem->GetFirst()->GetPage()->GetPageIndex();\r
198     FX_INT32 iPageSpan = iLast - iFirst + 1;\r
199     if (hValue) {\r
200         FXJSE_Value_SetInteger(hValue, iPageSpan);\r
201     }\r
202 }\r
203 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_Page(CFXJSE_Arguments* pArguments)\r
204 {\r
205     Script_LayoutPseudoModel_PageImp(pArguments, FALSE);\r
206 }\r
207 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_GetObjArray(IXFA_DocLayout* pDocLayout, FX_INT32 iPageNo, const CFX_WideString &wsType, FX_BOOL bOnPageArea, CXFA_NodeArray &retArray)\r
208 {\r
209     CXFA_ContainerLayoutItemImpl* pLayoutPage = (CXFA_ContainerLayoutItemImpl*)pDocLayout->GetPage(iPageNo);\r
210     if (!pLayoutPage) {\r
211         return;\r
212     }\r
213     if (wsType == FX_WSTRC(L"pageArea")) {\r
214         if (CXFA_Node* pMasterPage = pLayoutPage->m_pFormNode) {\r
215             retArray.Add(pMasterPage);\r
216         }\r
217         return;\r
218     }\r
219     if (wsType == FX_WSTRC(L"contentArea")) {\r
220         for(CXFA_LayoutItemImpl* pItem = pLayoutPage->m_pFirstChild; pItem; pItem = pItem->m_pNextSibling) {\r
221             if(pItem->m_pFormNode->GetClassID() == XFA_ELEMENT_ContentArea) {\r
222                 retArray.Add(pItem->m_pFormNode);\r
223             }\r
224         }\r
225         return;\r
226     }\r
227     CFX_MapPtrToPtr formItems;\r
228     formItems.InitHashTable(256, TRUE);\r
229     if (wsType.IsEmpty()) {\r
230         if (CXFA_Node* pMasterPage = pLayoutPage->m_pFormNode) {\r
231             retArray.Add(pMasterPage);\r
232         }\r
233         for(CXFA_LayoutItemImpl* pItem = pLayoutPage->m_pFirstChild; pItem; pItem = pItem->m_pNextSibling) {\r
234             if(pItem->m_pFormNode->GetClassID() == XFA_ELEMENT_ContentArea) {\r
235                 retArray.Add(pItem->m_pFormNode);\r
236                 if(!bOnPageArea) {\r
237                     CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItemImpl, CXFA_TraverseStrategy_ContentLayoutItem> iterator((CXFA_ContentLayoutItemImpl*)pItem->m_pFirstChild);\r
238                     for(CXFA_ContentLayoutItemImpl* pItemChild = iterator.GetCurrent(); pItemChild; pItemChild = iterator.MoveToNext()) {\r
239                         if(!pItemChild->IsContentLayoutItem()) {\r
240                             continue;\r
241                         }\r
242                         XFA_ELEMENT eElementType = pItemChild->m_pFormNode->GetClassID();\r
243                         if (eElementType != XFA_ELEMENT_Field && eElementType != XFA_ELEMENT_Draw\r
244                                 && eElementType != XFA_ELEMENT_Subform && eElementType != XFA_ELEMENT_Area) {\r
245                             continue;\r
246                         }\r
247                         if (formItems.GetValueAt(pItemChild->m_pFormNode)) {\r
248                             continue;\r
249                         }\r
250                         formItems.SetAt(pItemChild->m_pFormNode, this);\r
251                         retArray.Add(pItemChild->m_pFormNode);\r
252                     }\r
253                 }\r
254             } else {\r
255                 if(bOnPageArea) {\r
256                     CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItemImpl, CXFA_TraverseStrategy_ContentLayoutItem> iterator((CXFA_ContentLayoutItemImpl*)pItem);\r
257                     for(CXFA_ContentLayoutItemImpl* pItemChild = iterator.GetCurrent(); pItemChild; pItemChild = iterator.MoveToNext()) {\r
258                         if(!pItemChild->IsContentLayoutItem()) {\r
259                             continue;\r
260                         }\r
261                         XFA_ELEMENT eElementType = pItemChild->m_pFormNode->GetClassID();\r
262                         if (eElementType != XFA_ELEMENT_Field && eElementType != XFA_ELEMENT_Draw\r
263                                 && eElementType != XFA_ELEMENT_Subform && eElementType != XFA_ELEMENT_Area) {\r
264                             continue;\r
265                         }\r
266                         if (formItems.GetValueAt(pItemChild->m_pFormNode)) {\r
267                             continue;\r
268                         }\r
269                         formItems.SetAt(pItemChild->m_pFormNode, this);\r
270                         retArray.Add(pItemChild->m_pFormNode);\r
271                     }\r
272                 }\r
273             }\r
274         }\r
275         return;\r
276     }\r
277     XFA_ELEMENT eType = XFA_ELEMENT_UNKNOWN;\r
278     if (wsType == FX_WSTRC(L"field")) {\r
279         eType = XFA_ELEMENT_Field;\r
280     } else if (wsType == FX_WSTRC(L"draw")) {\r
281         eType = XFA_ELEMENT_Draw;\r
282     } else if (wsType == FX_WSTRC(L"subform")) {\r
283         eType = XFA_ELEMENT_Subform;\r
284     } else if (wsType == FX_WSTRC(L"area")) {\r
285         eType = XFA_ELEMENT_Area;\r
286     }\r
287     if (eType != XFA_ELEMENT_UNKNOWN) {\r
288         for(CXFA_LayoutItemImpl* pItem = pLayoutPage->m_pFirstChild; pItem; pItem = pItem->m_pNextSibling) {\r
289             if(pItem->m_pFormNode->GetClassID() == XFA_ELEMENT_ContentArea) {\r
290                 if(!bOnPageArea) {\r
291                     CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItemImpl, CXFA_TraverseStrategy_ContentLayoutItem> iterator((CXFA_ContentLayoutItemImpl*)pItem->m_pFirstChild);\r
292                     for(CXFA_ContentLayoutItemImpl* pItemChild = iterator.GetCurrent(); pItemChild; pItemChild = iterator.MoveToNext()) {\r
293                         if(!pItemChild->IsContentLayoutItem()) {\r
294                             continue;\r
295                         }\r
296                         if (pItemChild->m_pFormNode->GetClassID() != eType) {\r
297                             continue;\r
298                         }\r
299                         if (formItems.GetValueAt(pItemChild->m_pFormNode)) {\r
300                             continue;\r
301                         }\r
302                         formItems.SetAt(pItemChild->m_pFormNode, this);\r
303                         retArray.Add(pItemChild->m_pFormNode);\r
304                     }\r
305                 }\r
306             } else {\r
307                 if(bOnPageArea) {\r
308                     CXFA_NodeIteratorTemplate<CXFA_ContentLayoutItemImpl, CXFA_TraverseStrategy_ContentLayoutItem> iterator((CXFA_ContentLayoutItemImpl*)pItem);\r
309                     for(CXFA_ContentLayoutItemImpl* pItemChild = iterator.GetCurrent(); pItemChild; pItemChild = iterator.MoveToNext()) {\r
310                         if(!pItemChild->IsContentLayoutItem()) {\r
311                             continue;\r
312                         }\r
313                         if (pItemChild->m_pFormNode->GetClassID() != eType) {\r
314                             continue;\r
315                         }\r
316                         if (formItems.GetValueAt(pItemChild->m_pFormNode)) {\r
317                             continue;\r
318                         }\r
319                         formItems.SetAt(pItemChild->m_pFormNode, this);\r
320                         retArray.Add(pItemChild->m_pFormNode);\r
321                     }\r
322                 }\r
323             }\r
324         }\r
325         return;\r
326     }\r
327 }\r
328 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_PageContent(CFXJSE_Arguments* pArguments)\r
329 {\r
330     FX_INT32 iLength = pArguments->GetLength();\r
331     if (iLength < 1 || iLength > 3) {\r
332         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"pageContent");\r
333         return;\r
334     }\r
335     FX_INT32 iIndex = 0;\r
336     CFX_WideString wsType;\r
337     FX_BOOL bOnPageArea = FALSE;\r
338     if (iLength >= 1) {\r
339         iIndex = pArguments->GetInt32(0);\r
340     }\r
341     if (iLength >= 2) {\r
342         CFX_ByteString bsType = pArguments->GetUTF8String(1);\r
343         wsType = CFX_WideString::FromUTF8(bsType, bsType.GetLength());\r
344     }\r
345     if (iLength >= 3) {\r
346         bOnPageArea = pArguments->GetInt32(2) == 0 ? FALSE : TRUE;\r
347     }\r
348     IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();\r
349     if (!pNotify) {\r
350         return;\r
351     }\r
352     IXFA_DocLayout* pDocLayout = m_pDocument->GetDocLayout();\r
353     if (!pDocLayout) {\r
354         return;\r
355     }\r
356     CXFA_NodeArray retArray;\r
357     Script_LayoutPseudoModel_GetObjArray(pDocLayout, iIndex, wsType, bOnPageArea, retArray);\r
358     CXFA_ArrayNodeList* pArrayNodeList = FX_NEW CXFA_ArrayNodeList(m_pDocument);\r
359     pArrayNodeList->SetArrayNodeList(retArray);\r
360     FXJSE_Value_SetObject(pArguments->GetReturnValue(), (CXFA_Object*)pArrayNodeList, m_pDocument->GetScriptContext()->GetJseNormalClass());\r
361 }\r
362 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_AbsPageCount(CFXJSE_Arguments* pArguments)\r
363 {\r
364     Script_LayoutPseudoModel_NumberedPageCount(pArguments, FALSE);\r
365 }\r
366 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_AbsPageCountInBatch(CFXJSE_Arguments* pArguments)\r
367 {\r
368     IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();\r
369     if (!pNotify) {\r
370         return;\r
371     }\r
372     IXFA_Doc* hDoc = pNotify->GetHDOC();\r
373     FX_INT32 iPageCount = pNotify->GetDocProvider()->AbsPageCountInBatch(hDoc);\r
374     FXJSE_HVALUE hValue =  pArguments->GetReturnValue();\r
375     if (hValue) {\r
376         FXJSE_Value_SetInteger(hValue, iPageCount);\r
377     }\r
378 }\r
379 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_SheetCountInBatch(CFXJSE_Arguments* pArguments)\r
380 {\r
381     IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();\r
382     if (!pNotify) {\r
383         return;\r
384     }\r
385     IXFA_Doc* hDoc = pNotify->GetHDOC();\r
386     FX_INT32 iPageCount = pNotify->GetDocProvider()->SheetCountInBatch(hDoc);\r
387     FXJSE_HVALUE hValue =  pArguments->GetReturnValue();\r
388     if (hValue) {\r
389         FXJSE_Value_SetInteger(hValue, iPageCount);\r
390     }\r
391 }\r
392 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_Relayout(CFXJSE_Arguments* pArguments)\r
393 {\r
394     CXFA_Node* pRootNode = m_pDocument->GetRoot();\r
395     CXFA_Node* pFormRoot = pRootNode->GetFirstChildByClass(XFA_ELEMENT_Form);\r
396     FXSYS_assert(pFormRoot);\r
397     CXFA_Node* pContentRootNode = pFormRoot->GetNodeItem(XFA_NODEITEM_FirstChild);\r
398     CXFA_LayoutProcessor* pLayoutProcessor = m_pDocument->GetLayoutProcessor();\r
399     if (pContentRootNode) {\r
400         pLayoutProcessor->AddChangedContainer(pContentRootNode);\r
401     }\r
402     pLayoutProcessor->SetForceReLayout(TRUE);\r
403 }\r
404 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_AbsPageSpan(CFXJSE_Arguments* pArguments)\r
405 {\r
406     Script_LayoutPseudoModel_PageSpan(pArguments);\r
407 }\r
408 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_AbsPageInBatch(CFXJSE_Arguments* pArguments)\r
409 {\r
410     FX_INT32 iLength = pArguments->GetLength();\r
411     if (iLength != 1) {\r
412         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"absPageInBatch");\r
413         return;\r
414     }\r
415     CXFA_Node* pNode = NULL;\r
416     if (iLength >= 1) {\r
417         pNode = (CXFA_Node*)pArguments->GetObject(0);\r
418     }\r
419     if (!pNode) {\r
420         return;\r
421     }\r
422     IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();\r
423     if (!pNotify) {\r
424         return;\r
425     }\r
426     IXFA_DocLayout* pDocLayout = m_pDocument->GetDocLayout();\r
427     if (!pDocLayout) {\r
428         return;\r
429     }\r
430     XFA_HWIDGET hWidget = pNotify->GetHWidget(pDocLayout->GetLayoutItem(pNode));\r
431     if (!hWidget) {\r
432         return;\r
433     }\r
434     IXFA_Doc* hDoc = pNotify->GetHDOC();\r
435     FX_INT32 iPageCount = pNotify->GetDocProvider()->AbsPageInBatch(hDoc, hWidget);\r
436     FXJSE_HVALUE hValue =  pArguments->GetReturnValue();\r
437     if (hValue) {\r
438         FXJSE_Value_SetInteger(hValue, iPageCount);\r
439     }\r
440 }\r
441 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_SheetInBatch(CFXJSE_Arguments* pArguments)\r
442 {\r
443     FX_INT32 iLength = pArguments->GetLength();\r
444     if (iLength != 1) {\r
445         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"sheetInBatch");\r
446         return;\r
447     }\r
448     CXFA_Node* pNode = NULL;\r
449     if (iLength >= 1) {\r
450         pNode = (CXFA_Node*)pArguments->GetObject(0);\r
451     }\r
452     if (!pNode) {\r
453         return;\r
454     }\r
455     IXFA_Notify* pNotify = m_pDocument->GetParser()->GetNotify();\r
456     if (!pNotify) {\r
457         return;\r
458     }\r
459     IXFA_DocLayout* pDocLayout = m_pDocument->GetDocLayout();\r
460     if (!pDocLayout) {\r
461         return;\r
462     }\r
463     XFA_HWIDGET hWidget = pNotify->GetHWidget(pDocLayout->GetLayoutItem(pNode));\r
464     if (!hWidget) {\r
465         return;\r
466     }\r
467     IXFA_Doc* hDoc = pNotify->GetHDOC();\r
468     FX_INT32 iPageCount = pNotify->GetDocProvider()->SheetInBatch(hDoc, hWidget);\r
469     FXJSE_HVALUE hValue =  pArguments->GetReturnValue();\r
470     if (hValue) {\r
471         FXJSE_Value_SetInteger(hValue, iPageCount);\r
472     }\r
473 }\r
474 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_Sheet(CFXJSE_Arguments* pArguments)\r
475 {\r
476     Script_LayoutPseudoModel_PageImp(pArguments, TRUE);\r
477 }\r
478 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_RelayoutPageArea(CFXJSE_Arguments* pArguments)\r
479 {\r
480 }\r
481 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_SheetCount(CFXJSE_Arguments* pArguments)\r
482 {\r
483     Script_LayoutPseudoModel_NumberedPageCount(pArguments, FALSE);\r
484 }\r
485 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_AbsPage(CFXJSE_Arguments* pArguments)\r
486 {\r
487     Script_LayoutPseudoModel_PageImp(pArguments, TRUE);\r
488 }\r
489 void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_PageImp(CFXJSE_Arguments* pArguments, FX_BOOL bAbsPage)\r
490 {\r
491     FX_INT32 iLength = pArguments->GetLength();\r
492     if (iLength != 1) {\r
493         FX_LPCWSTR methodName;\r
494         if (bAbsPage) {\r
495             methodName = L"absPage";\r
496         } else {\r
497             methodName = L"page";\r
498         }\r
499         ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, methodName);\r
500         return;\r
501     }\r
502     CXFA_Node* pNode = NULL;\r
503     if (iLength >= 1) {\r
504         pNode = (CXFA_Node*)pArguments->GetObject(0);\r
505     }\r
506     FX_INT32 iPage = 0;\r
507     FXJSE_HVALUE hValue =  pArguments->GetReturnValue();\r
508     if (!pNode && hValue) {\r
509         FXJSE_Value_SetInteger(hValue, iPage);\r
510     }\r
511     IXFA_DocLayout* pDocLayout = m_pDocument->GetDocLayout();\r
512     if (!pDocLayout) {\r
513         return;\r
514     }\r
515     CXFA_LayoutItem* pLayoutItem = pDocLayout->GetLayoutItem(pNode);\r
516     if (!pLayoutItem) {\r
517         FXJSE_Value_SetInteger(hValue, -1);\r
518         return;\r
519     }\r
520     iPage = pLayoutItem->GetFirst()->GetPage()->GetPageIndex();\r
521     if (hValue) {\r
522         FXJSE_Value_SetInteger(hValue, bAbsPage ? iPage : iPage + 1);\r
523     }\r
524 }\r