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