1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "vbainformationhelper.hxx"
31 #include <com/sun/star/text/XPageCursor.hpp>
32 #include <com/sun/star/beans/XPropertySet.hpp>
33 #include "wordvbahelper.hxx"
36 #include <vbahelper/vbahelper.hxx>
37 #include <swtypes.hxx>
39 using namespace ::ooo::vba
;
40 using namespace ::com::sun::star
;
42 static const sal_Int32 DEFAULT_PAGE_DISTANCE
= 500;
44 sal_Int32
SwVbaInformationHelper::handleWdActiveEndPageNumber( const css::uno::Reference
< css::text::XTextViewCursor
>& xTVCursor
) throw( css::uno::RuntimeException
)
46 uno::Reference
< text::XPageCursor
> xPageCursor( xTVCursor
, uno::UNO_QUERY_THROW
);
47 return xPageCursor
->getPage();
50 sal_Int32
SwVbaInformationHelper::handleWdNumberOfPagesInDocument( const css::uno::Reference
< css::frame::XModel
>& xModel
) throw( css::uno::RuntimeException
)
52 return word::getPageCount( xModel
);
55 double SwVbaInformationHelper::handleWdVerticalPositionRelativeToPage( const css::uno::Reference
< css::frame::XModel
>& xModel
, const css::uno::Reference
< css::text::XTextViewCursor
>& xTVCursor
) throw( css::uno::RuntimeException
)
57 xTVCursor
->collapseToStart();
58 uno::Reference
< beans::XPropertySet
> xStyleProps( word::getCurrentPageStyle( xModel
), uno::UNO_QUERY_THROW
);
59 sal_Int32 nTopMargin
= 0;
60 xStyleProps
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TopMargin") ) ) >>= nTopMargin
;
61 sal_Int32 nCurrentPos
= xTVCursor
->getPosition().Y
;
63 sal_Int32 nCurrentPage
= handleWdActiveEndPageNumber( xTVCursor
);
64 sal_Int32 nPageHeight
= word::getDocShell( xModel
)->GetDoc()->GetPageSize( nCurrentPage
, sal_False
).Height();
65 // FIXME: handle multipul page style
66 // it is very strange that the curros position is incorrect when open Word file.
67 // e.g. if current cursor in the top left of the text body of the first page without header,
68 // the top value of current position should be 0, but is 201 when open a Word file.
69 nCurrentPos
= nCurrentPos
+ nTopMargin
- ( DEFAULT_PAGE_DISTANCE
+ TWIP_TO_MM100( nPageHeight
) ) * ( nCurrentPage
- 1 );
70 return Millimeter::getInPoints( nCurrentPos
);