LCOV - code coverage report
Current view: top level - sw/source/ui/vba - vbainformationhelper.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 18 5.6 %
Date: 2014-11-03 Functions: 2 5 40.0 %
Legend: Lines: hit not hit

          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             : #include <IDocumentLayoutAccess.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           0 : sal_Int32 SwVbaInformationHelper::handleWdActiveEndPageNumber( const css::uno::Reference< css::text::XTextViewCursor >& xTVCursor ) throw( css::uno::RuntimeException )
      36             : {
      37           0 :     uno::Reference< text::XPageCursor > xPageCursor( xTVCursor, uno::UNO_QUERY_THROW );
      38           0 :     return xPageCursor->getPage();
      39             : }
      40             : 
      41           0 : sal_Int32 SwVbaInformationHelper::handleWdNumberOfPagesInDocument( const css::uno::Reference< css::frame::XModel >& xModel ) throw( css::uno::RuntimeException )
      42             : {
      43           0 :     return word::getPageCount( xModel );
      44             : }
      45             : 
      46           0 : double SwVbaInformationHelper::handleWdVerticalPositionRelativeToPage( const css::uno::Reference< css::frame::XModel >& xModel, const css::uno::Reference< css::text::XTextViewCursor >& xTVCursor ) throw( css::uno::RuntimeException )
      47             : {
      48           0 :     xTVCursor->collapseToStart();
      49           0 :     uno::Reference< beans::XPropertySet > xStyleProps( word::getCurrentPageStyle( xModel ), uno::UNO_QUERY_THROW );
      50           0 :     sal_Int32 nTopMargin = 0;
      51           0 :     xStyleProps->getPropertyValue( "TopMargin" ) >>= nTopMargin;
      52           0 :     sal_Int32 nCurrentPos = xTVCursor->getPosition().Y;
      53             : 
      54           0 :     sal_Int32 nCurrentPage = handleWdActiveEndPageNumber( xTVCursor );
      55           0 :     SwDoc* pDoc = word::getDocShell( xModel )->GetDoc();
      56           0 :     SwViewShell* pViewSh = pDoc->getIDocumentLayoutAccess().GetCurrentViewShell();
      57           0 :     sal_Int32 nPageHeight = pViewSh ? pViewSh->GetPageSize( nCurrentPage, false ).Height() : 0;
      58             :     // FIXME: handle multipul page style
      59             :     // it is very strange that the curros 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           0 :     nCurrentPos = nCurrentPos + nTopMargin - ( DEFAULT_PAGE_DISTANCE + convertTwipToMm100( nPageHeight ) ) * (  nCurrentPage - 1  );
      63           0 :     return Millimeter::getInPoints( nCurrentPos );
      64           6 : }
      65             : 
      66             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10