LCOV - code coverage report
Current view: top level - sc/source/ui/vba - vbacomment.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 90 0.0 %
Date: 2014-04-14 Functions: 0 16 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 "vbacomment.hxx"
      20             : 
      21             : #include <ooo/vba/excel/XlCreator.hpp>
      22             : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
      23             : #include <com/sun/star/sheet/XSpreadsheet.hpp>
      24             : #include <com/sun/star/sheet/XSheetAnnotationAnchor.hpp>
      25             : #include <com/sun/star/sheet/XSheetAnnotationsSupplier.hpp>
      26             : #include <com/sun/star/sheet/XSheetAnnotationShapeSupplier.hpp>
      27             : #include <com/sun/star/sheet/XSheetCellRange.hpp>
      28             : #include <com/sun/star/sheet/XCellAddressable.hpp>
      29             : #include <com/sun/star/table/CellAddress.hpp>
      30             : #include <com/sun/star/table/XCell.hpp>
      31             : #include <com/sun/star/text/XText.hpp>
      32             : 
      33             : #include <vbahelper/vbashape.hxx>
      34             : #include "vbaglobals.hxx"
      35             : #include "vbacomments.hxx"
      36             : 
      37             : using namespace ::ooo::vba;
      38             : using namespace ::com::sun::star;
      39             : 
      40           0 : ScVbaComment::ScVbaComment(
      41             :         const uno::Reference< XHelperInterface >& xParent,
      42             :         const uno::Reference< uno::XComponentContext >& xContext,
      43             :         const uno::Reference< frame::XModel >& xModel,
      44             :         const uno::Reference< table::XCellRange >& xRange ) throw( lang::IllegalArgumentException ) :
      45             :     ScVbaComment_BASE( xParent, xContext ),
      46             :     mxModel( xModel, uno::UNO_SET_THROW ),
      47           0 :     mxRange( xRange )
      48             : {
      49           0 :     if  ( !xRange.is() )
      50           0 :         throw lang::IllegalArgumentException("range is not set ", uno::Reference< uno::XInterface >() , 1 );
      51           0 :     uno::Reference< text::XSimpleText > xAnnoText( getAnnotation(), uno::UNO_QUERY );
      52           0 : }
      53             : 
      54             : // private helper functions
      55             : 
      56             : uno::Reference< sheet::XSheetAnnotation > SAL_CALL
      57           0 : ScVbaComment::getAnnotation() throw (uno::RuntimeException)
      58             : {
      59           0 :     uno::Reference< table::XCell > xCell( mxRange->getCellByPosition(0, 0), uno::UNO_QUERY_THROW );
      60           0 :     uno::Reference< sheet::XSheetAnnotationAnchor > xAnnoAnchor( xCell, uno::UNO_QUERY_THROW );
      61           0 :     return uno::Reference< sheet::XSheetAnnotation > ( xAnnoAnchor->getAnnotation(), uno::UNO_QUERY_THROW );
      62             : }
      63             : 
      64             : uno::Reference< sheet::XSheetAnnotations > SAL_CALL
      65           0 : ScVbaComment::getAnnotations() throw (uno::RuntimeException)
      66             : {
      67           0 :     uno::Reference< sheet::XSheetCellRange > xSheetCellRange(mxRange, ::uno::UNO_QUERY_THROW );
      68           0 :     uno::Reference< sheet::XSpreadsheet > xSheet = xSheetCellRange->getSpreadsheet();
      69           0 :     uno::Reference< sheet::XSheetAnnotationsSupplier > xAnnosSupp( xSheet, uno::UNO_QUERY_THROW );
      70             : 
      71           0 :     return uno::Reference< sheet::XSheetAnnotations > ( xAnnosSupp->getAnnotations(), uno::UNO_QUERY_THROW );
      72             : }
      73             : 
      74             : sal_Int32 SAL_CALL
      75           0 : ScVbaComment::getAnnotationIndex() throw (uno::RuntimeException)
      76             : {
      77           0 :     uno::Reference< sheet::XSheetAnnotations > xAnnos = getAnnotations();
      78           0 :     table::CellAddress aAddress = getAnnotation()->getPosition();
      79             : 
      80           0 :     sal_Int32 aIndex = 0;
      81           0 :     sal_Int32 aCount = xAnnos->getCount();
      82             : 
      83           0 :     for ( ; aIndex < aCount ; aIndex++ )
      84             :     {
      85           0 :         uno::Reference< sheet::XSheetAnnotation > xAnno( xAnnos->getByIndex( aIndex ), uno::UNO_QUERY_THROW );
      86           0 :         table::CellAddress xAddress = xAnno->getPosition();
      87             : 
      88           0 :         if ( xAddress.Column == aAddress.Column && xAddress.Row == aAddress.Row && xAddress.Sheet == aAddress.Sheet )
      89             :         {
      90             :             OSL_TRACE("** terminating search, index is %d", aIndex );
      91           0 :             break;
      92             :         }
      93           0 :     }
      94             :     OSL_TRACE("** returning index is %d", aIndex );
      95             : 
      96           0 :        return aIndex;
      97             : }
      98             : 
      99             : uno::Reference< excel::XComment > SAL_CALL
     100           0 : ScVbaComment::getCommentByIndex( sal_Int32 Index ) throw (uno::RuntimeException)
     101             : {
     102           0 :     uno::Reference< container::XIndexAccess > xIndexAccess( getAnnotations(), uno::UNO_QUERY_THROW );
     103             :     // parent is sheet ( parent of the range which is the parent of the comment )
     104           0 :     uno::Reference< XCollection > xColl(  new ScVbaComments( getParent()->getParent(), mxContext, mxModel, xIndexAccess ) );
     105             : 
     106           0 :     return uno::Reference< excel::XComment > ( xColl->Item( uno::makeAny( Index ), uno::Any() ), uno::UNO_QUERY_THROW );
     107             :  }
     108             : 
     109             : // public vba functions
     110             : 
     111             : OUString SAL_CALL
     112           0 : ScVbaComment::getAuthor() throw (uno::RuntimeException, std::exception)
     113             : {
     114           0 :     return getAnnotation()->getAuthor();
     115             : }
     116             : 
     117             : void SAL_CALL
     118           0 : ScVbaComment::setAuthor( const OUString& /*_author*/ ) throw (uno::RuntimeException, std::exception)
     119             : {
     120             :     // #TODO #FIXME  implementation needed
     121           0 : }
     122             : 
     123             : uno::Reference< msforms::XShape > SAL_CALL
     124           0 : ScVbaComment::getShape() throw (uno::RuntimeException, std::exception)
     125             : {
     126           0 :     uno::Reference< sheet::XSheetAnnotationShapeSupplier > xAnnoShapeSupp( getAnnotation(), uno::UNO_QUERY_THROW );
     127           0 :     uno::Reference< drawing::XShape > xAnnoShape( xAnnoShapeSupp->getAnnotationShape(), uno::UNO_SET_THROW );
     128           0 :     uno::Reference< sheet::XSheetCellRange > xCellRange( mxRange, uno::UNO_QUERY_THROW );
     129           0 :     uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupp( xCellRange->getSpreadsheet(), uno::UNO_QUERY_THROW );
     130           0 :     uno::Reference< drawing::XShapes > xShapes( xDrawPageSupp->getDrawPage(), uno::UNO_QUERY_THROW );
     131           0 :     return new ScVbaShape( this, mxContext, xAnnoShape, xShapes, mxModel, office::MsoShapeType::msoComment );
     132             : }
     133             : 
     134             : sal_Bool SAL_CALL
     135           0 : ScVbaComment::getVisible() throw (uno::RuntimeException, std::exception)
     136             : {
     137           0 :     return getAnnotation()->getIsVisible();
     138             : }
     139             : 
     140             : void SAL_CALL
     141           0 : ScVbaComment::setVisible( sal_Bool _visible ) throw (uno::RuntimeException, std::exception)
     142             : {
     143           0 :     getAnnotation()->setIsVisible( _visible );
     144           0 : }
     145             : 
     146             : void SAL_CALL
     147           0 : ScVbaComment::Delete() throw (uno::RuntimeException, std::exception)
     148             : {
     149           0 :     getAnnotations()->removeByIndex( getAnnotationIndex() );
     150           0 : }
     151             : 
     152             : uno::Reference< excel::XComment > SAL_CALL
     153           0 : ScVbaComment::Next() throw (uno::RuntimeException, std::exception)
     154             : {
     155             :     // index: uno = 0, vba = 1
     156           0 :     return getCommentByIndex( getAnnotationIndex() + 2 );
     157             : }
     158             : 
     159             : uno::Reference< excel::XComment > SAL_CALL
     160           0 : ScVbaComment::Previous() throw (uno::RuntimeException, std::exception)
     161             : {
     162             :     // index: uno = 0, vba = 1
     163           0 :     return getCommentByIndex( getAnnotationIndex() );
     164             : }
     165             : 
     166             : OUString SAL_CALL
     167           0 : ScVbaComment::Text( const uno::Any& aText, const uno::Any& aStart, const uno::Any& Overwrite ) throw (uno::RuntimeException, std::exception)
     168             : {
     169           0 :     OUString sText;
     170           0 :     aText >>= sText;
     171             : 
     172           0 :     uno::Reference< text::XSimpleText > xAnnoText( getAnnotation(), uno::UNO_QUERY_THROW );
     173           0 :     OUString sAnnoText = xAnnoText->getString();
     174             : 
     175           0 :     if ( aStart.hasValue() )
     176             :     {
     177           0 :         sal_Int16 nStart = 0;
     178           0 :         sal_Bool bOverwrite = sal_True;
     179           0 :         Overwrite >>= bOverwrite;
     180             : 
     181           0 :         if ( aStart >>= nStart )
     182             :         {
     183           0 :             uno::Reference< text::XTextCursor > xTextCursor( xAnnoText->createTextCursor(), uno::UNO_QUERY_THROW );
     184             : 
     185           0 :             if ( bOverwrite )
     186             :             {
     187           0 :                 xTextCursor->collapseToStart();
     188           0 :                 xTextCursor->gotoStart( false );
     189           0 :                 xTextCursor->goRight( nStart - 1, false );
     190           0 :                 xTextCursor->gotoEnd( sal_True );
     191             :             }
     192             :             else
     193             :             {
     194           0 :                 xTextCursor->collapseToStart();
     195           0 :                 xTextCursor->gotoStart( false );
     196           0 :                 xTextCursor->goRight( nStart - 1 , sal_True );
     197             :             }
     198             : 
     199           0 :             uno::Reference< text::XTextRange > xRange( xTextCursor, uno::UNO_QUERY_THROW );
     200           0 :             xAnnoText->insertString( xRange, sText, bOverwrite );
     201           0 :             return xAnnoText->getString();
     202             :         }
     203           0 :         throw uno::RuntimeException("ScVbaComment::Text - bad Start value ", uno::Reference< uno::XInterface >() );
     204             :     }
     205           0 :     else if ( aText.hasValue() )
     206             :     {
     207           0 :      uno::Reference< sheet::XCellAddressable > xCellAddr(mxRange->getCellByPosition(0, 0), uno::UNO_QUERY_THROW );
     208           0 :      table::CellAddress aAddress = xCellAddr->getCellAddress();
     209           0 :      getAnnotations()->insertNew( aAddress, sText );
     210             :     }
     211             : 
     212           0 :     return sAnnoText;
     213             : }
     214             : 
     215             : OUString
     216           0 : ScVbaComment::getServiceImplName()
     217             : {
     218           0 :     return OUString("ScVbaComment");
     219             : }
     220             : 
     221             : uno::Sequence< OUString >
     222           0 : ScVbaComment::getServiceNames()
     223             : {
     224           0 :     static uno::Sequence< OUString > aServiceNames;
     225           0 :     if ( aServiceNames.getLength() == 0 )
     226             :     {
     227           0 :         aServiceNames.realloc( 1 );
     228           0 :         aServiceNames[ 0 ] = "ooo.vba.excel.ScVbaComment";
     229             :     }
     230           0 :     return aServiceNames;
     231             : }
     232             : 
     233             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10