LibreOffice Module sw (master)  1
vbainformationhelper.cxx
Go to the documentation of this file.
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>
29 
30 using namespace ::ooo::vba;
31 using namespace ::com::sun::star;
32 
33 static const sal_Int32 DEFAULT_PAGE_DISTANCE = 500;
34 
35 sal_Int32 SwVbaInformationHelper::handleWdActiveEndPageNumber( const css::uno::Reference< css::text::XTextViewCursor >& xTVCursor )
36 {
37  uno::Reference< text::XPageCursor > xPageCursor( xTVCursor, uno::UNO_QUERY_THROW );
38  return xPageCursor->getPage();
39 }
40 
41 sal_Int32 SwVbaInformationHelper::handleWdNumberOfPagesInDocument( const css::uno::Reference< css::frame::XModel >& xModel )
42 {
43  return word::getPageCount( xModel );
44 }
45 
46 double SwVbaInformationHelper::handleWdVerticalPositionRelativeToPage( const css::uno::Reference< css::frame::XModel >& xModel, const css::uno::Reference< css::text::XTextViewCursor >& xTVCursor )
47 {
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;
53 
54  sal_Int32 nCurrentPage = handleWdActiveEndPageNumber( xTVCursor );
55  SwDoc* pDoc = word::getDocShell( xModel )->GetDoc();
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 );
64 }
65 
66 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long Height() const
Definition: doc.hxx:185
uno::Reference< style::XStyle > getCurrentPageStyle(const uno::Reference< frame::XModel > &xModel)
long const nTopMargin
static double handleWdVerticalPositionRelativeToPage(const css::uno::Reference< css::frame::XModel > &xModel, const css::uno::Reference< css::text::XTextViewCursor > &xTVCursor)
SwDoc * GetDoc()
returns Doc. But be careful!
Definition: docsh.hxx:203
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:404
Size GetPageSize(sal_uInt16 nPageNum, bool bSkipEmptyPages) const
Definition: viewsh.cxx:2508
sal_Int32 getPageCount(const uno::Reference< frame::XModel > &xModel)
SwDocShell * getDocShell(const uno::Reference< frame::XModel > &xModel)
static sal_Int32 handleWdNumberOfPagesInDocument(const css::uno::Reference< css::frame::XModel > &xModel)
virtual const SwViewShell * GetCurrentViewShell() const =0
Returns the layout set at the document.
static sal_Int32 handleWdActiveEndPageNumber(const css::uno::Reference< css::text::XTextViewCursor > &xTVCursor)
constexpr sal_Int64 convertTwipToMm100(sal_Int64 n)
static const sal_Int32 DEFAULT_PAGE_DISTANCE