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

Generated by: LCOV version 1.10