Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #include "vbainformationhelper.hxx"
20 : #include <com/sun/star/text/XPageCursor.hpp>
21 : #include <com/sun/star/beans/XPropertySet.hpp>
22 : #include "wordvbahelper.hxx"
23 : #include <docsh.hxx>
24 : #include <doc.hxx>
25 : #include <vbahelper/vbahelper.hxx>
26 : #include <swtypes.hxx>
27 : #include <viewsh.hxx>
28 :
29 : using namespace ::ooo::vba;
30 : using namespace ::com::sun::star;
31 :
32 : static const sal_Int32 DEFAULT_PAGE_DISTANCE = 500;
33 :
34 0 : sal_Int32 SwVbaInformationHelper::handleWdActiveEndPageNumber( const css::uno::Reference< css::text::XTextViewCursor >& xTVCursor ) throw( css::uno::RuntimeException )
35 : {
36 0 : uno::Reference< text::XPageCursor > xPageCursor( xTVCursor, uno::UNO_QUERY_THROW );
37 0 : return xPageCursor->getPage();
38 : }
39 :
40 0 : sal_Int32 SwVbaInformationHelper::handleWdNumberOfPagesInDocument( const css::uno::Reference< css::frame::XModel >& xModel ) throw( css::uno::RuntimeException )
41 : {
42 0 : return word::getPageCount( xModel );
43 : }
44 :
45 0 : double SwVbaInformationHelper::handleWdVerticalPositionRelativeToPage( const css::uno::Reference< css::frame::XModel >& xModel, const css::uno::Reference< css::text::XTextViewCursor >& xTVCursor ) throw( css::uno::RuntimeException )
46 : {
47 0 : xTVCursor->collapseToStart();
48 0 : uno::Reference< beans::XPropertySet > xStyleProps( word::getCurrentPageStyle( xModel ), uno::UNO_QUERY_THROW );
49 0 : sal_Int32 nTopMargin = 0;
50 0 : xStyleProps->getPropertyValue( "TopMargin" ) >>= nTopMargin;
51 0 : sal_Int32 nCurrentPos = xTVCursor->getPosition().Y;
52 :
53 0 : sal_Int32 nCurrentPage = handleWdActiveEndPageNumber( xTVCursor );
54 0 : SwDoc* pDoc = word::getDocShell( xModel )->GetDoc();
55 0 : ViewShell* pViewSh = pDoc->GetCurrentViewShell();
56 0 : sal_Int32 nPageHeight = pViewSh ? pViewSh->GetPageSize( nCurrentPage, sal_False ).Height() : 0;
57 : // FIXME: handle multipul page style
58 : // it is very strange that the curros position is incorrect when open Word file.
59 : // e.g. if current cursor in the top left of the text body of the first page without header,
60 : // the top value of current position should be 0, but is 201 when open a Word file.
61 0 : nCurrentPos = nCurrentPos + nTopMargin - ( DEFAULT_PAGE_DISTANCE + TWIP_TO_MM100( nPageHeight ) ) * ( nCurrentPage - 1 );
62 0 : return Millimeter::getInPoints( nCurrentPos );
63 : }
64 :
65 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|