1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #include "vbainformationhelper.hxx"
20 #include <com/sun/star/text/XPageCursor.hpp>
21 #include <com/sun/star/beans/XPropertySet.hpp>
22 #include <tools/UnitConversion.hxx>
23 #include "wordvbahelper.hxx"
26 #include <vbahelper/vbahelper.hxx>
28 #include <IDocumentLayoutAccess.hxx>
30 using namespace ::ooo::vba
;
31 using namespace ::com::sun::star
;
33 const sal_Int32 DEFAULT_PAGE_DISTANCE
= 500;
35 sal_Int32
SwVbaInformationHelper::handleWdActiveEndPageNumber( const css::uno::Reference
< css::text::XTextViewCursor
>& xTVCursor
)
37 uno::Reference
< text::XPageCursor
> xPageCursor( xTVCursor
, uno::UNO_QUERY_THROW
);
38 return xPageCursor
->getPage();
41 sal_Int32
SwVbaInformationHelper::handleWdNumberOfPagesInDocument( const css::uno::Reference
< css::frame::XModel
>& xModel
)
43 return word::getPageCount( xModel
);
46 double SwVbaInformationHelper::handleWdVerticalPositionRelativeToPage( const css::uno::Reference
< css::frame::XModel
>& xModel
, const css::uno::Reference
< css::text::XTextViewCursor
>& xTVCursor
)
48 xTVCursor
->collapseToStart();
49 uno::Reference
< beans::XPropertySet
> xStyleProps( word::getCurrentPageStyle( xModel
), uno::UNO_QUERY_THROW
);
50 sal_Int32 nTopMargin
= 0;
51 xStyleProps
->getPropertyValue( "TopMargin" ) >>= nTopMargin
;
52 sal_Int32 nCurrentPos
= xTVCursor
->getPosition().Y
;
54 sal_Int32 nCurrentPage
= handleWdActiveEndPageNumber( xTVCursor
);
55 SwDoc
* pDoc
= word::getDocShell( xModel
)->GetDoc();
56 SwViewShell
* pViewSh
= pDoc
->getIDocumentLayoutAccess().GetCurrentViewShell();
57 sal_Int32 nPageHeight
= pViewSh
? pViewSh
->GetPageSize( nCurrentPage
, false ).Height() : 0;
58 // FIXME: handle multiple page style
59 // it is very strange that the cursor position is incorrect when open Word file.
60 // e.g. if current cursor in the top left of the text body of the first page without header,
61 // the top value of current position should be 0, but is 201 when open a Word file.
62 nCurrentPos
= nCurrentPos
+ nTopMargin
- ( DEFAULT_PAGE_DISTANCE
+ convertTwipToMm100( nPageHeight
) ) * ( nCurrentPage
- 1 );
63 return Millimeter::getInPoints( nCurrentPos
);
66 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */