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 */
20#include <com/sun/star/text/XPageCursor.hpp>
21#include <com/sun/star/beans/XPropertySet.hpp>
23#include "wordvbahelper.hxx"
24#include <docsh.hxx>
25#include <doc.hxx>
27#include <viewsh.hxx>
29
30using namespace ::ooo::vba;
31using namespace ::com::sun::star;
32
33const sal_Int32 DEFAULT_PAGE_DISTANCE = 500;
34
35sal_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
41sal_Int32 SwVbaInformationHelper::handleWdNumberOfPagesInDocument( const css::uno::Reference< css::frame::XModel >& xModel )
42{
43 return word::getPageCount( xModel );
44}
45
46double 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 );
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: */
constexpr auto convertTwipToMm100(N n)
virtual const SwViewShell * GetCurrentViewShell() const =0
Returns the layout set at the document.
constexpr tools::Long Height() const
SwDoc * GetDoc()
returns Doc. But be careful!
Definition: docsh.hxx:204
Definition: doc.hxx:194
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:411
static sal_Int32 handleWdActiveEndPageNumber(const css::uno::Reference< css::text::XTextViewCursor > &xTVCursor)
static sal_Int32 handleWdNumberOfPagesInDocument(const css::uno::Reference< css::frame::XModel > &xModel)
static double handleWdVerticalPositionRelativeToPage(const css::uno::Reference< css::frame::XModel > &xModel, const css::uno::Reference< css::text::XTextViewCursor > &xTVCursor)
Size GetPageSize(sal_uInt16 nPageNum, bool bSkipEmptyPages) const
Definition: viewsh.cxx:2665
tools::Long const nTopMargin
SwDocShell * getDocShell(const uno::Reference< frame::XModel > &xModel)
uno::Reference< style::XStyle > getCurrentPageStyle(const uno::Reference< frame::XModel > &xModel)
sal_Int32 getPageCount(const uno::Reference< frame::XModel > &xModel)
Reference< XModel > xModel
const sal_Int32 DEFAULT_PAGE_DISTANCE