LCOV - code coverage report
Current view: top level - sw/source/ui/vba - wordvbahelper.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 79 1.3 %
Date: 2014-11-03 Functions: 2 12 16.7 %
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 <docsh.hxx>
      20             : #include "wordvbahelper.hxx"
      21             : #include <comphelper/processfactory.hxx>
      22             : #include <com/sun/star/frame/XController.hpp>
      23             : #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
      24             : #include <com/sun/star/text/XTextTable.hpp>
      25             : #include <com/sun/star/table/XCellRange.hpp>
      26             : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
      27             : #include <com/sun/star/container/XNameAccess.hpp>
      28             : #include <com/sun/star/container/XIndexAccess.hpp>
      29             : #include <com/sun/star/lang/XUnoTunnel.hpp>
      30             : #include <com/sun/star/view/XSelectionSupplier.hpp>
      31             : #include <unotxdoc.hxx>
      32             : #include <doc.hxx>
      33             : #include <IDocumentLayoutAccess.hxx>
      34             : #include <view.hxx>
      35             : #include <viewsh.hxx>
      36             : 
      37             : using namespace ::com::sun::star;
      38             : using namespace ::ooo::vba;
      39             : 
      40             : namespace ooo
      41             : {
      42             : namespace vba
      43             : {
      44             : namespace word
      45             : {
      46             : 
      47           0 : SwDocShell* getDocShell( const uno::Reference< frame::XModel>& xModel )
      48             : {
      49           0 :     uno::Reference< lang::XUnoTunnel > xTunnel( xModel, uno::UNO_QUERY_THROW );
      50           0 :     SwXTextDocument* pXDoc = reinterpret_cast< SwXTextDocument * >( sal::static_int_cast< sal_IntPtr >(xTunnel->getSomething(SwXTextDocument::getUnoTunnelId())));
      51           0 :     return pXDoc ? pXDoc->GetDocShell() : 0;
      52             : }
      53             : 
      54           0 : SwView* getView( const uno::Reference< frame::XModel>& xModel )
      55             : {
      56           0 :     SwDocShell* pDocShell = getDocShell( xModel );
      57           0 :     return pDocShell? pDocShell->GetView() : 0;
      58             : }
      59             : 
      60           0 : uno::Reference< text::XTextViewCursor > getXTextViewCursor( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException)
      61             : {
      62           0 :     uno::Reference< frame::XController > xController = xModel->getCurrentController();
      63           0 :     uno::Reference< text::XTextViewCursorSupplier > xTextViewCursorSupp( xController, uno::UNO_QUERY_THROW );
      64           0 :     uno::Reference< text::XTextViewCursor > xTextViewCursor = xTextViewCursorSupp->getViewCursor();
      65           0 :     return xTextViewCursor;
      66             : }
      67             : 
      68           0 : uno::Reference< style::XStyle > getCurrentPageStyle( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException)
      69             : {
      70           0 :     uno::Reference< beans::XPropertySet > xCursorProps( getXTextViewCursor( xModel ), uno::UNO_QUERY_THROW );
      71           0 :     return getCurrentPageStyle( xModel, xCursorProps );
      72             : }
      73             : 
      74           0 : uno::Reference< style::XStyle > getCurrentPageStyle( const uno::Reference< frame::XModel >& xModel, const uno::Reference< beans::XPropertySet >& xProps ) throw (uno::RuntimeException)
      75             : {
      76           0 :     OUString aPageStyleName;
      77           0 :     xProps->getPropertyValue("PageStyleName") >>= aPageStyleName;
      78           0 :     uno::Reference< style::XStyleFamiliesSupplier > xSytleFamSupp( xModel, uno::UNO_QUERY_THROW );
      79           0 :     uno::Reference< container::XNameAccess > xSytleFamNames( xSytleFamSupp->getStyleFamilies(), uno::UNO_QUERY_THROW );
      80           0 :     uno::Reference< container::XNameAccess > xPageStyles( xSytleFamNames->getByName("PageStyles"), uno::UNO_QUERY_THROW );
      81           0 :     uno::Reference< style::XStyle > xStyle( xPageStyles->getByName( aPageStyleName ), uno::UNO_QUERY_THROW );
      82             : 
      83           0 :     return xStyle;
      84             : }
      85             : 
      86           0 : sal_Int32 getPageCount( const uno::Reference< frame::XModel>& xModel ) throw (uno::RuntimeException)
      87             : {
      88           0 :     SwDocShell* pDocShell = getDocShell( xModel );
      89           0 :     SwViewShell* pViewSh = pDocShell ? pDocShell->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell() : 0;
      90           0 :     return pViewSh ? pViewSh->GetPageCount() : 0;
      91             : }
      92             : 
      93           0 : uno::Reference< style::XStyle > getDefaultParagraphStyle( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException)
      94             : {
      95           0 :     uno::Reference< style::XStyleFamiliesSupplier > xSytleFamSupp( xModel, uno::UNO_QUERY_THROW );
      96           0 :     uno::Reference< container::XNameAccess > xSytleFamNames( xSytleFamSupp->getStyleFamilies(), uno::UNO_QUERY_THROW );
      97           0 :     uno::Reference< container::XNameAccess > xParaStyles( xSytleFamNames->getByName("ParagraphStyles"), uno::UNO_QUERY_THROW );
      98           0 :     uno::Reference< style::XStyle > xStyle( xParaStyles->getByName("Standard"), uno::UNO_QUERY_THROW );
      99             : 
     100           0 :     return xStyle;
     101             : }
     102             : 
     103           0 : uno::Reference< text::XTextRange > getFirstObjectPosition( const uno::Reference< text::XText >& xText ) throw (uno::RuntimeException)
     104             : {
     105             :     // if the first object is table, get the position of first cell
     106           0 :     uno::Reference< text::XTextRange > xTextRange;
     107           0 :     uno::Reference< container::XEnumerationAccess > xParaAccess( xText, uno::UNO_QUERY_THROW );
     108           0 :     uno::Reference< container::XEnumeration> xParaEnum = xParaAccess->createEnumeration();
     109           0 :     if( xParaEnum->hasMoreElements() )
     110             :     {
     111           0 :         uno::Reference< lang::XServiceInfo > xServiceInfo( xParaEnum->nextElement(), uno::UNO_QUERY_THROW );
     112           0 :         if( xServiceInfo->supportsService("com.sun.star.text.TextTable") )
     113             :         {
     114           0 :             uno::Reference< table::XCellRange > xCellRange( xServiceInfo, uno::UNO_QUERY_THROW );
     115           0 :             uno::Reference< text::XText> xFirstCellText( xCellRange->getCellByPosition(0, 0), uno::UNO_QUERY_THROW );
     116           0 :             xTextRange = xFirstCellText->getStart();
     117           0 :         }
     118             :     }
     119           0 :     if( !xTextRange.is() )
     120           0 :         xTextRange = xText->getStart();
     121           0 :     return xTextRange;
     122             : }
     123             : 
     124           0 : uno::Reference< text::XText > getCurrentXText( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException)
     125             : {
     126           0 :     uno::Reference< text::XTextRange > xTextRange;
     127           0 :     uno::Reference< text::XTextContent > xTextContent( xModel->getCurrentSelection(), uno::UNO_QUERY );
     128           0 :     if( !xTextContent.is() )
     129             :     {
     130           0 :         uno::Reference< container::XIndexAccess > xIndexAccess( xModel->getCurrentSelection(), uno::UNO_QUERY );
     131           0 :         if( xIndexAccess.is() )
     132             :         {
     133           0 :             xTextContent.set( xIndexAccess->getByIndex(0), uno::UNO_QUERY );
     134           0 :         }
     135             :     }
     136             : 
     137           0 :     if( xTextContent.is() )
     138           0 :         xTextRange.set( xTextContent->getAnchor(), uno::UNO_QUERY );
     139             : 
     140           0 :     if( !xTextRange.is() )
     141           0 :         xTextRange.set( getXTextViewCursor( xModel ), uno::UNO_QUERY_THROW );
     142             : 
     143           0 :     uno::Reference< text::XText > xText;
     144             :     try
     145             :     {
     146           0 :         xText.set( xTextRange->getText(), uno::UNO_QUERY );
     147             :     }
     148           0 :     catch (const uno::RuntimeException&)
     149             :     {
     150             :         //catch exception "no text selection"
     151             :     }
     152           0 :     uno::Reference< beans::XPropertySet > xVCProps( xTextRange, uno::UNO_QUERY_THROW );
     153           0 :     while( xVCProps->getPropertyValue("TextTable") >>= xTextContent )
     154             :     {
     155           0 :         xText = xTextContent->getAnchor()->getText();
     156           0 :         xVCProps.set( xText->createTextCursor(), uno::UNO_QUERY_THROW );
     157             :     }
     158             : 
     159           0 :     if( !xText.is() )
     160           0 :         throw  uno::RuntimeException("no text selection" );
     161             : 
     162           0 :     return xText;
     163             : }
     164             : 
     165           0 : bool gotoSelectedObjectAnchor( const uno::Reference< frame::XModel>& xModel ) throw (uno::RuntimeException)
     166             : {
     167           0 :     bool isObjectSelected = false;
     168           0 :     uno::Reference< text::XTextContent > xTextContent( xModel->getCurrentSelection(), uno::UNO_QUERY );
     169           0 :     if( xTextContent.is() )
     170             :     {
     171           0 :         uno::Reference< text::XTextRange > xTextRange( xTextContent->getAnchor(), uno::UNO_QUERY_THROW );
     172           0 :         uno::Reference< view::XSelectionSupplier > xSelectSupp( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
     173           0 :         xSelectSupp->select( uno::makeAny( xTextRange ) );
     174           0 :         isObjectSelected = true;
     175             :     }
     176           0 :     return isObjectSelected;
     177             : }
     178             : 
     179             : } // word
     180             : }
     181           6 : }
     182             : 
     183             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10