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

Generated by: LCOV version 1.10