LCOV - code coverage report
Current view: top level - sw/source/ui/vba - vbaselection.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 616 0.2 %
Date: 2015-06-13 12:38:46 Functions: 2 62 3.2 %
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 "vbaselection.hxx"
      20             : #include <vbahelper/vbahelper.hxx>
      21             : #include <tools/diagnose_ex.h>
      22             : #include "vbarange.hxx"
      23             : #include "vbafind.hxx"
      24             : #include <com/sun/star/text/XTextRange.hpp>
      25             : #include <com/sun/star/text/XTextTable.hpp>
      26             : #include <com/sun/star/text/XTextTableCursor.hpp>
      27             : #include <com/sun/star/text/ControlCharacter.hpp>
      28             : #include <com/sun/star/table/XCell.hpp>
      29             : #include <comphelper/string.hxx>
      30             : #include <ooo/vba/word/WdUnits.hpp>
      31             : #include <ooo/vba/word/WdMovementType.hpp>
      32             : #include <ooo/vba/word/WdGoToItem.hpp>
      33             : #include <ooo/vba/word/WdGoToDirection.hpp>
      34             : #include <ooo/vba/word/XBookmark.hpp>
      35             : #include <ooo/vba/word/XApplication.hpp>
      36             : #include <ooo/vba/word/WdCollapseDirection.hpp>
      37             : #include <com/sun/star/text/XPageCursor.hpp>
      38             : #include "unotbl.hxx"
      39             : #include "unocoll.hxx"
      40             : #include "vbatable.hxx"
      41             : #include <com/sun/star/view/XSelectionSupplier.hpp>
      42             : #include <com/sun/star/view/XViewCursor.hpp>
      43             : #include <com/sun/star/view/XLineCursor.hpp>
      44             : #include <com/sun/star/text/XWordCursor.hpp>
      45             : #include <com/sun/star/text/XParagraphCursor.hpp>
      46             : #include <ooo/vba/word/WdInformation.hpp>
      47             : #include <ooo/vba/word/WdHeaderFooterIndex.hpp>
      48             : #include <ooo/vba/word/WdSeekView.hpp>
      49             : #include "vbainformationhelper.hxx"
      50             : #include "vbafield.hxx"
      51             : #include "vbaheaderfooter.hxx"
      52             : #include "vbaheaderfooterhelper.hxx"
      53             : #include <vbahelper/vbashaperange.hxx>
      54             : #include <com/sun/star/drawing/ShapeCollection.hpp>
      55             : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
      56             : #include <com/sun/star/drawing/XDrawPage.hpp>
      57             : #include "vbarows.hxx"
      58             : #include "vbacolumns.hxx"
      59             : #include "vbatablehelper.hxx"
      60             : #include "vbacells.hxx"
      61             : #include "vbaview.hxx"
      62             : #include "vbaparagraph.hxx"
      63             : #include "vbastyle.hxx"
      64             : #include <docsh.hxx>
      65             : #include <tblenum.hxx>
      66             : #include <fesh.hxx>
      67             : 
      68             : using namespace ::ooo::vba;
      69             : using namespace ::com::sun::star;
      70             : 
      71           0 : SwVbaSelection::SwVbaSelection( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const uno::Reference< frame::XModel >& rModel ) throw ( uno::RuntimeException ) : SwVbaSelection_BASE( rParent, rContext ), mxModel( rModel )
      72             : {
      73           0 :     mxTextViewCursor = word::getXTextViewCursor( mxModel );
      74           0 : }
      75             : 
      76           0 : SwVbaSelection::~SwVbaSelection()
      77             : {
      78           0 : }
      79             : 
      80           0 : uno::Reference< text::XTextRange > SwVbaSelection::GetSelectedRange() throw ( uno::RuntimeException )
      81             : {
      82           0 :     uno::Reference< text::XTextRange > xTextRange;
      83           0 :     uno::Reference< lang::XServiceInfo > xServiceInfo( mxModel->getCurrentSelection(), uno::UNO_QUERY_THROW );
      84           0 :     if( xServiceInfo->supportsService("com.sun.star.text.TextRanges") )
      85             :     {
      86           0 :         uno::Reference< container::XIndexAccess > xTextRanges( xServiceInfo, uno::UNO_QUERY_THROW );
      87           0 :         if( xTextRanges->getCount() > 0 )
      88             :         {
      89             :             // if there are multipul selection, just return the last selected Range.
      90           0 :             xTextRange.set( xTextRanges->getByIndex( xTextRanges->getCount()-1 ), uno::UNO_QUERY_THROW );
      91           0 :         }
      92             :     }
      93             :     else
      94             :     {
      95           0 :         throw uno::RuntimeException("Not implemented" );
      96             :     }
      97           0 :     return xTextRange;
      98             : }
      99             : 
     100             : uno::Reference< word::XRange > SAL_CALL
     101           0 : SwVbaSelection::getRange() throw ( uno::RuntimeException, std::exception )
     102             : {
     103           0 :     uno::Reference< text::XTextRange > xTextRange = GetSelectedRange();
     104           0 :     uno::Reference< text::XTextDocument > xDocument( mxModel, uno::UNO_QUERY_THROW );
     105           0 :     return uno::Reference< word::XRange >( new SwVbaRange( this, mxContext, xDocument, xTextRange->getStart(), xTextRange->getEnd(), mxTextViewCursor->getText() ) );
     106             : }
     107             : 
     108             : OUString SAL_CALL
     109           0 : SwVbaSelection::getText() throw ( uno::RuntimeException, std::exception )
     110             : {
     111           0 :     return getRange()->getText();
     112             : }
     113             : 
     114             : void SAL_CALL
     115           0 : SwVbaSelection::setText( const OUString& rText ) throw ( uno::RuntimeException, std::exception )
     116             : {
     117           0 :     getRange()->setText( rText );
     118           0 : }
     119             : 
     120             : void SAL_CALL
     121           0 : SwVbaSelection::TypeText( const OUString& rText ) throw ( uno::RuntimeException, std::exception )
     122             : {
     123             :     // FIXME: handle the property Options.ReplaceSelection, the default value is true
     124           0 :     setText( rText );
     125           0 : }
     126             : 
     127             : void SAL_CALL
     128           0 : SwVbaSelection::HomeKey( const uno::Any& _unit, const uno::Any& _extend ) throw ( uno::RuntimeException, std::exception )
     129             : {
     130           0 :     sal_Int32 nUnit = word::WdUnits::wdLine;
     131           0 :     sal_Int32 nExtend = word::WdMovementType::wdMove;
     132           0 :     _unit >>= nUnit;
     133           0 :     _extend >>= nExtend;
     134           0 :     bool bExtend = nExtend == word::WdMovementType::wdExtend;
     135             : 
     136           0 :     switch( nUnit )
     137             :     {
     138             :         case word::WdUnits::wdStory:
     139             :         {
     140             :             // go to the valid text first so that the current view cursor is valid to call gotoRange.
     141           0 :             word::gotoSelectedObjectAnchor(mxModel);
     142             :             // go to the begin of the document
     143           0 :             uno::Reference< text::XText > xCurrentText = word::getCurrentXText( mxModel );
     144           0 :             uno::Reference< text::XTextRange > xFirstRange = word::getFirstObjectPosition( xCurrentText );
     145           0 :             mxTextViewCursor->gotoRange( xFirstRange, bExtend );
     146           0 :             break;
     147             :         }
     148             :         case word::WdUnits::wdLine:
     149             :         {
     150             :             // go to the begin of the Line
     151           0 :             uno::Reference< view::XLineCursor > xLineCursor( mxTextViewCursor, uno::UNO_QUERY_THROW );
     152           0 :             xLineCursor->gotoStartOfLine( bExtend );
     153           0 :             break;
     154             :         }
     155             :         default:
     156             :         {
     157           0 :             throw uno::RuntimeException("Not implemented" );
     158             :         }
     159             :     }
     160           0 : }
     161             : 
     162             : void SAL_CALL
     163           0 : SwVbaSelection::EndKey( const uno::Any& _unit, const uno::Any& _extend ) throw ( uno::RuntimeException, std::exception )
     164             : {
     165           0 :     sal_Int32 nUnit = word::WdUnits::wdLine;
     166           0 :     sal_Int32 nExtend = word::WdMovementType::wdMove;
     167           0 :     _unit >>= nUnit;
     168           0 :     _extend >>= nExtend;
     169           0 :     bool bExtend = nExtend == word::WdMovementType::wdExtend;
     170             : 
     171           0 :     switch( nUnit )
     172             :     {
     173             :         case word::WdUnits::wdStory:
     174             :         {
     175             :             // go to the valid text first so that the current view cursor is valid to call gotoRange.
     176           0 :             word::gotoSelectedObjectAnchor(mxModel);
     177             :             // go to the end of the document
     178           0 :             uno::Reference< text::XText > xCurrentText = word::getCurrentXText( mxModel );
     179           0 :             uno::Reference< text::XTextRange > xEnd = xCurrentText->getEnd();
     180           0 :             mxTextViewCursor->gotoRange( xEnd, bExtend );
     181           0 :             break;
     182             :         }
     183             :         case word::WdUnits::wdLine:
     184             :         {
     185             :             // go to the end of the Line
     186           0 :             uno::Reference< view::XLineCursor > xLineCursor( mxTextViewCursor, uno::UNO_QUERY_THROW );
     187           0 :             xLineCursor->gotoEndOfLine( bExtend );
     188           0 :             break;
     189             :         }
     190             :         default:
     191             :         {
     192           0 :             throw uno::RuntimeException("Not implemented" );
     193             :         }
     194             :     }
     195           0 : }
     196             : 
     197             : void SAL_CALL
     198           0 : SwVbaSelection::Delete( const uno::Any& _unit, const uno::Any& _count ) throw ( uno::RuntimeException, std::exception )
     199             : {
     200           0 :     sal_Int32 nUnit = word::WdUnits::wdLine;
     201           0 :     sal_Int32 nCount = 0;
     202           0 :     if( _count.hasValue() )
     203           0 :         _count >>= nCount;
     204           0 :     if( _unit.hasValue() && ( nCount > 0 ) )
     205             :     {
     206           0 :         _unit >>= nUnit;
     207           0 :         switch( nUnit )
     208             :         {
     209             :             case word::WdUnits::wdCharacter:
     210             :             {
     211           0 :                 if( HasSelection() )
     212           0 :                     nCount--;
     213           0 :                 mxTextViewCursor->goRight( nCount, sal_True );
     214           0 :                 break;
     215             :             }
     216             :             default:
     217             :             {
     218           0 :                 throw uno::RuntimeException("Not implemented" );
     219             :             }
     220             :         }
     221             :     }
     222           0 :     OUString url = ".uno:Delete";
     223           0 :     dispatchRequests( mxModel,url );
     224           0 : }
     225             : 
     226             : void
     227           0 : SwVbaSelection::Move( const uno::Any& _unit, const uno::Any& _count, const uno::Any& _extend, word::E_DIRECTION eDirection ) throw ( css::script::BasicErrorException, uno::RuntimeException )
     228             : {
     229           0 :     sal_Int32 nUnit = word::WdUnits::wdCharacter;
     230           0 :     sal_Int32 nCount = 1;
     231           0 :     sal_Int32 nExtend = word::WdMovementType::wdMove;
     232             : 
     233           0 :     if( _unit.hasValue() )
     234           0 :         _unit >>= nUnit;
     235           0 :     if( _count.hasValue() )
     236           0 :         _count >>= nCount;
     237           0 :     if( _extend.hasValue() )
     238           0 :         _extend >>= nExtend;
     239             : 
     240           0 :     if( nCount == 0 )
     241           0 :         return;
     242             : 
     243           0 :     bool bExpand = nExtend != word::WdMovementType::wdMove;
     244             : 
     245           0 :     switch( nUnit )
     246             :     {
     247             :         case word::WdUnits::wdCell:
     248             :         {
     249           0 :             if(  nExtend == word::WdMovementType::wdExtend )
     250             :             {
     251           0 :                 DebugHelper::basicexception(SbERR_BAD_ARGUMENT, OUString());
     252           0 :                 return;
     253             :             }
     254           0 :             NextCell( nCount, eDirection );
     255           0 :             break;
     256             :         }
     257             :         case word::WdUnits::wdLine:
     258             :         {
     259           0 :             if( eDirection == word::MOVE_LEFT || eDirection == word::MOVE_RIGHT )
     260             :             {
     261           0 :                 throw uno::RuntimeException("Not implemented" );
     262             :             }
     263           0 :             uno::Reference< view::XViewCursor > xViewCursor( mxTextViewCursor, uno::UNO_QUERY_THROW );
     264           0 :             if( eDirection == word::MOVE_UP )
     265           0 :                 xViewCursor->goUp( nCount, bExpand );
     266           0 :             else if( eDirection == word::MOVE_DOWN )
     267           0 :                 xViewCursor->goDown( nCount, bExpand );
     268           0 :             break;
     269             :         }
     270             :         case word::WdUnits::wdCharacter:
     271             :         {
     272           0 :             if( eDirection == word::MOVE_UP || eDirection == word::MOVE_DOWN )
     273             :             {
     274           0 :                 throw uno::RuntimeException("Not implemented" );
     275             :             }
     276           0 :             if( word::gotoSelectedObjectAnchor( mxModel ) )
     277             :             {
     278           0 :                 nCount--;
     279             :             }
     280           0 :             uno::Reference< view::XViewCursor > xViewCursor( mxTextViewCursor, uno::UNO_QUERY_THROW );
     281           0 :             if( eDirection == word::MOVE_LEFT )
     282             :             {
     283             :                 // if current select is a cellrange or table,
     284             :                 // the first count of move should move to the first selected cell.
     285           0 :                 uno::Reference< text::XTextTableCursor > xTextTableCursor( mxModel->getCurrentSelection(), uno::UNO_QUERY );
     286           0 :                 if ( xTextTableCursor.is() )
     287             :                 {
     288           0 :                     uno::Reference< beans::XPropertySet > xCursorProps( mxTextViewCursor, uno::UNO_QUERY_THROW );
     289           0 :                     uno::Reference< text::XTextTable > xTextTable;
     290           0 :                     xCursorProps->getPropertyValue("TextTable") >>= xTextTable;
     291           0 :                     if( xTextTable.is() )
     292             :                     {
     293           0 :                         uno::Reference< text::XTextRange > xRange( xTextTable->getCellByName( xTextTableCursor->getRangeName()), uno::UNO_QUERY_THROW );
     294           0 :                         mxTextViewCursor->gotoRange( xRange->getStart(), bExpand );
     295           0 :                         nCount--;
     296           0 :                     }
     297             :                 }
     298           0 :                 xViewCursor->goLeft( nCount, bExpand );
     299             :             }
     300           0 :             else if( eDirection == word::MOVE_RIGHT )
     301           0 :                 xViewCursor->goRight( nCount, bExpand );
     302           0 :             break;
     303             :         }
     304             :         case word::WdUnits::wdWord:
     305             :         case word::WdUnits::wdParagraph:
     306             :         {
     307           0 :             uno::Reference< text::XTextRange > xRange = GetSelectedRange();
     308           0 :             uno::Reference< text::XText > xText = xRange->getText();
     309           0 :             uno::Reference< text::XTextCursor > xTextCursor = xText->createTextCursorByRange( xRange );
     310           0 :             if( nUnit == word::WdUnits::wdParagraph )
     311             :             {
     312           0 :                 if( eDirection == word::MOVE_LEFT || eDirection == word::MOVE_RIGHT )
     313             :                 {
     314           0 :                     throw uno::RuntimeException("Not implemented" );
     315             :                 }
     316           0 :                 uno::Reference< text::XParagraphCursor > xParagraphCursor( xTextCursor, uno::UNO_QUERY_THROW );
     317           0 :                 for( sal_Int32 i=0; i<nCount; i++ )
     318             :                 {
     319           0 :                     if( ( eDirection == word::MOVE_UP ) && ( xParagraphCursor->gotoPreviousParagraph( bExpand ) == sal_False ) )
     320           0 :                         break;
     321           0 :                     else if( ( eDirection == word::MOVE_DOWN ) && ( xParagraphCursor->gotoNextParagraph( bExpand ) == sal_False ) )
     322           0 :                         break;
     323           0 :                 }
     324             :             }
     325           0 :             else if( nUnit == word::WdUnits::wdWord )
     326             :             {
     327           0 :                 if( eDirection == word::MOVE_UP || eDirection == word::MOVE_DOWN )
     328             :                 {
     329           0 :                     throw uno::RuntimeException("Not implemented" );
     330             :                 }
     331           0 :                 uno::Reference< text::XWordCursor > xWordCursor( xTextCursor, uno::UNO_QUERY_THROW );
     332           0 :                 for( sal_Int32 i=0; i<nCount; i++ )
     333             :                 {
     334           0 :                     if( (eDirection == word::MOVE_LEFT ) && ( xWordCursor->gotoPreviousWord( bExpand ) == sal_False ) )
     335           0 :                         break;
     336           0 :                     else if( ( eDirection == word::MOVE_RIGHT ) && ( xWordCursor->gotoNextWord( bExpand ) == sal_False ) )
     337           0 :                         break;
     338           0 :                 }
     339             :             }
     340           0 :             mxTextViewCursor->gotoRange( xTextCursor->getStart(), sal_False );
     341           0 :             mxTextViewCursor->gotoRange( xTextCursor->getEnd(), sal_True );
     342           0 :             break;
     343             :         }
     344             :         default:
     345             :         {
     346           0 :             throw uno::RuntimeException("Not implemented" );
     347             :         }
     348             :     }
     349             : }
     350             : 
     351           0 : void SwVbaSelection::NextCell(sal_Int32 nCount, word::E_DIRECTION eDirection)
     352             :     throw (css::script::BasicErrorException, uno::RuntimeException)
     353             : {
     354           0 :     uno::Reference< beans::XPropertySet > xCursorProps( mxTextViewCursor, uno::UNO_QUERY_THROW );
     355           0 :     uno::Reference< text::XTextTable > xTextTable;
     356           0 :     uno::Reference< table::XCell > xCell;
     357           0 :     xCursorProps->getPropertyValue("TextTable") >>= xTextTable;
     358           0 :     xCursorProps->getPropertyValue("Cell") >>= xCell;
     359           0 :     if( !xTextTable.is() || !xCell.is() )
     360             :     {
     361           0 :         DebugHelper::basicexception(SbERR_BAD_ARGUMENT, OUString());
     362           0 :         return;
     363             :     }
     364           0 :     uno::Reference< beans::XPropertySet > xCellProps( xCell, uno::UNO_QUERY_THROW );
     365           0 :     OUString aCellName;
     366           0 :     xCellProps->getPropertyValue("CellName") >>= aCellName;
     367           0 :     uno::Reference< text::XTextTableCursor > xTextTableCursor = xTextTable->createCursorByCellName( aCellName );
     368             :     // move the table cursor
     369           0 :     switch( eDirection )
     370             :     {
     371             :         case word::MOVE_LEFT:
     372             :         {
     373           0 :             xTextTableCursor->goLeft( nCount, sal_False );
     374           0 :             break;
     375             :         }
     376             :         case word::MOVE_RIGHT:
     377             :         {
     378           0 :             xTextTableCursor->goRight( nCount, sal_False );
     379           0 :             break;
     380             :         }
     381             :         case word::MOVE_UP:
     382             :         {
     383           0 :             xTextTableCursor->goUp( nCount, sal_False );
     384           0 :             break;
     385             :         }
     386             :         case word::MOVE_DOWN:
     387             :         {
     388           0 :             xTextTableCursor->goDown( nCount, sal_False );
     389           0 :             break;
     390             :         }
     391             :         default:
     392             :         {
     393           0 :             DebugHelper::basicexception(SbERR_BAD_ARGUMENT, OUString());
     394           0 :             return;
     395             :         }
     396             :     }
     397             :     // move the view cursor
     398           0 :     xCell = xTextTable->getCellByName( xTextTableCursor->getRangeName() );
     399           0 :     mxTextViewCursor->gotoRange( uno::Reference< text::XTextRange >( xCell, uno::UNO_QUERY_THROW ), sal_False );
     400             : }
     401             : 
     402             : void SAL_CALL
     403           0 : SwVbaSelection::MoveRight(const uno::Any& _unit, const uno::Any& _count, const uno::Any& _extend) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
     404             : {
     405           0 :     sal_Int32 nCount = 1;
     406             : 
     407           0 :     if( _count.hasValue() )
     408           0 :         _count >>= nCount;
     409             : 
     410           0 :     if( nCount == 0 )
     411           0 :         return;
     412             : 
     413           0 :     if( nCount < 0 )
     414             :     {
     415           0 :         MoveLeft( _unit, uno::makeAny( -nCount ), _extend );
     416           0 :         return;
     417             :     }
     418             : 
     419           0 :     Move( _unit, _count, _extend, word::MOVE_RIGHT );
     420             : }
     421             : 
     422             : void SAL_CALL
     423           0 : SwVbaSelection::MoveLeft(const uno::Any& _unit, const uno::Any& _count, const uno::Any& _extend) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
     424             : {
     425           0 :     sal_Int32 nCount = 1;
     426           0 :     if( _count.hasValue() )
     427           0 :         _count >>= nCount;
     428             : 
     429           0 :     if( nCount == 0 )
     430           0 :         return;
     431             : 
     432           0 :     if( nCount < 0 )
     433             :     {
     434           0 :         MoveRight( _unit, uno::makeAny( -nCount ), _extend );
     435           0 :         return;
     436             :     }
     437             : 
     438           0 :     Move( _unit, _count, _extend, word::MOVE_LEFT );
     439             : }
     440             : 
     441             : void SAL_CALL
     442           0 : SwVbaSelection::MoveDown(const uno::Any& _unit, const uno::Any& _count, const uno::Any& _extend) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
     443             : {
     444           0 :     sal_Int32 nCount = 1;
     445             : 
     446           0 :     if( _count.hasValue() )
     447           0 :         _count >>= nCount;
     448             : 
     449           0 :     if( nCount == 0 )
     450           0 :         return;
     451             : 
     452           0 :     if( nCount < 0 )
     453             :     {
     454           0 :         MoveUp( _unit, uno::makeAny( -nCount ), _extend );
     455           0 :         return;
     456             :     }
     457             : 
     458           0 :     Move( _unit, _count, _extend, word::MOVE_DOWN );
     459             : }
     460             : 
     461             : void SAL_CALL
     462           0 : SwVbaSelection::MoveUp(const uno::Any& _unit, const uno::Any& _count, const uno::Any& _extend) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
     463             : {
     464           0 :     sal_Int32 nCount = 1;
     465             : 
     466           0 :     if( _count.hasValue() )
     467           0 :         _count >>= nCount;
     468             : 
     469           0 :     if( nCount == 0 )
     470           0 :         return;
     471             : 
     472           0 :     if( nCount < 0 )
     473             :     {
     474           0 :         MoveDown( _unit, uno::makeAny( -nCount ), _extend );
     475           0 :         return;
     476             :     }
     477             : 
     478           0 :     Move( _unit, _count, _extend, word::MOVE_UP );
     479             : }
     480             : 
     481             : void SAL_CALL
     482           0 : SwVbaSelection::TypeParagraph() throw ( uno::RuntimeException, std::exception )
     483             : {
     484             :     // #FIXME: if the selection is an entire paragraph, it's replaced
     485             :     // by the new paragraph
     486           0 :     bool isCollapsed = mxTextViewCursor->isCollapsed();
     487           0 :     InsertParagraph();
     488           0 :     if( isCollapsed )
     489           0 :         mxTextViewCursor->collapseToStart();
     490           0 : }
     491             : 
     492             : void SAL_CALL
     493           0 : SwVbaSelection::InsertParagraph() throw ( uno::RuntimeException, std::exception )
     494             : {
     495             :     // #FIME: the selection should include the new paragraph.
     496           0 :     getRange()->InsertParagraph();
     497           0 : }
     498             : 
     499             : void SAL_CALL
     500           0 : SwVbaSelection::InsertParagraphBefore() throw ( uno::RuntimeException, std::exception )
     501             : {
     502           0 :     getRange()->InsertParagraphBefore();
     503           0 : }
     504             : 
     505             : void SAL_CALL
     506           0 : SwVbaSelection::InsertParagraphAfter() throw ( uno::RuntimeException, std::exception )
     507             : {
     508           0 :     getRange()->InsertParagraphAfter();
     509           0 : }
     510             : 
     511             : uno::Reference< word::XParagraphFormat > SAL_CALL
     512           0 : SwVbaSelection::getParagraphFormat() throw ( uno::RuntimeException, std::exception )
     513             : {
     514           0 :     return getRange()->getParagraphFormat();
     515             : }
     516             : 
     517             : void SAL_CALL
     518           0 : SwVbaSelection::setParagraphFormat( const uno::Reference< word::XParagraphFormat >& rParagraphFormat ) throw ( uno::RuntimeException, std::exception )
     519             : {
     520           0 :     return getRange()->setParagraphFormat( rParagraphFormat );
     521             : }
     522             : 
     523             : uno::Reference< word::XFind > SAL_CALL
     524           0 : SwVbaSelection::getFind() throw ( uno::RuntimeException, std::exception )
     525             : {
     526           0 :     uno::Reference< text::XTextRange > xTextRange = GetSelectedRange();
     527           0 :     return uno::Reference< word::XFind >( new SwVbaFind( this, mxContext, mxModel, xTextRange ) );
     528             : }
     529             : 
     530             : uno::Any SAL_CALL
     531           0 : SwVbaSelection::getStyle() throw ( uno::RuntimeException, std::exception )
     532             : {
     533           0 :     return getRange()->getStyle();
     534             : }
     535             : 
     536             : void SAL_CALL
     537           0 : SwVbaSelection::setStyle( const uno::Any& rStyle ) throw ( uno::RuntimeException, std::exception )
     538             : {
     539           0 :     uno::Reference< beans::XPropertySet > xParaProps( mxTextViewCursor, uno::UNO_QUERY_THROW );
     540           0 :     return SwVbaStyle::setStyle( xParaProps, rStyle );
     541             : }
     542             : 
     543             : uno::Reference< word::XFont > SAL_CALL
     544           0 : SwVbaSelection::getFont() throw ( uno::RuntimeException, std::exception )
     545             : {
     546           0 :     return getRange()->getFont();
     547             : }
     548             : 
     549             : void SAL_CALL
     550           0 : SwVbaSelection::TypeBackspace() throw ( uno::RuntimeException, std::exception )
     551             : {
     552           0 :     OUString url = ".uno:SwBackspace";
     553           0 :     dispatchRequests( mxModel,url );
     554           0 : }
     555             : 
     556           0 : uno::Reference< word::XRange > SAL_CALL SwVbaSelection::GoTo( const uno::Any& _what, const uno::Any& _which, const uno::Any& _count, const uno::Any& _name )
     557             :     throw (script::BasicErrorException, uno::RuntimeException, std::exception)
     558             : {
     559           0 :     sal_Int32 nWhat = 0;
     560           0 :     if( !( _what >>= nWhat ) )
     561           0 :          DebugHelper::basicexception(SbERR_BAD_ARGUMENT, OUString());
     562           0 :     switch( nWhat )
     563             :     {
     564             :         case word::WdGoToItem::wdGoToBookmark:
     565             :         {
     566           0 :             uno::Reference< word::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
     567           0 :             uno::Reference< word::XBookmark > xBookmark( xApplication->getActiveDocument()->Bookmarks(_name), uno::UNO_QUERY_THROW );
     568           0 :             xBookmark->Select();
     569           0 :             break;
     570             :         }
     571             :         case word::WdGoToItem::wdGoToPage:
     572             :         {
     573           0 :             uno::Reference< text::XPageCursor > xPageCursor( mxTextViewCursor, uno::UNO_QUERY_THROW );
     574           0 :             sal_Int32 nCurrPage = xPageCursor->getPage();
     575           0 :             sal_Int32 nLastPage = word::getPageCount( mxModel );
     576           0 :             sal_Int32 nCount = 0;
     577           0 :             if( _count.hasValue() )
     578           0 :                 _count >>= nCount;
     579           0 :             sal_Int32 nWhich = 0;
     580           0 :             if( _which.hasValue() )
     581           0 :                 _which >>= nWhich;
     582           0 :             sal_Int32 nPage = 0;
     583           0 :             switch( nWhich )
     584             :             {
     585             :                case word::WdGoToDirection::wdGoToLast:
     586             :                {
     587           0 :                    nPage = nLastPage;
     588           0 :                    break;
     589             :                }
     590             :                case word::WdGoToDirection::wdGoToNext:
     591             :                {
     592           0 :                    if( nCount !=0 )
     593           0 :                        nPage = nCurrPage + nCount;
     594             :                    else
     595           0 :                        nPage = nCurrPage + 1;
     596           0 :                    break;
     597             :                }
     598             :                case word::WdGoToDirection::wdGoToPrevious:
     599             :                {
     600           0 :                    if( nCount !=0 )
     601           0 :                        nPage = nCurrPage - nCount;
     602             :                    else
     603           0 :                        nPage = nCurrPage - 1;
     604           0 :                    break;
     605             :                }
     606             :                default:
     607             :                {
     608           0 :                    nPage = nCount;
     609             :                }
     610             :             }
     611           0 :             if( _name.hasValue() )
     612             :             {
     613           0 :                 OUString sName;
     614           0 :                 _name >>= sName;
     615           0 :                 sal_Int32 nName = sName.toInt32();
     616           0 :                 if( nName !=0 )
     617           0 :                     nPage = nName;
     618             :             }
     619           0 :             if( nPage <= 0 )
     620           0 :                nPage = 1;
     621           0 :             if( nPage > nLastPage )
     622           0 :                nPage = nLastPage;
     623           0 :             xPageCursor->jumpToPage( ( sal_Int16 )( nPage ) );
     624           0 :             break;
     625             :         }
     626             :         case word::WdGoToItem::wdGoToSection:
     627             :         {
     628           0 :             uno::Reference< text::XPageCursor > xPageCursor( mxTextViewCursor, uno::UNO_QUERY_THROW );
     629           0 :             sal_Int32 nCount = 0;
     630           0 :             if( _count.hasValue() )
     631           0 :                 _count >>= nCount;
     632           0 :             sal_Int32 nWhich = 0;
     633           0 :             if( _which.hasValue() )
     634           0 :                 _which >>= nWhich;
     635           0 :             sal_Int32 nPage = 0;
     636           0 :             switch( nWhich )
     637             :             {
     638             :                case word::WdGoToDirection::wdGoToAbsolute:
     639             :                {
     640             :                     // currently only support this type
     641           0 :                     if( nCount == 1 )
     642           0 :                         nPage = 1;
     643           0 :                     break;
     644             :                }
     645             :                default:
     646             :                {
     647           0 :                     nPage = 0;
     648             :                }
     649             :             }
     650           0 :             if( nPage != 0 )
     651           0 :                 xPageCursor->jumpToPage( ( sal_Int16 )( nPage ) );
     652             :             else
     653           0 :                 throw uno::RuntimeException("Not implemented" );
     654           0 :             break;
     655             :         }
     656             :         default:
     657           0 :             throw uno::RuntimeException("Not implemented" );
     658             :     }
     659           0 :     return getRange();
     660             : }
     661             : 
     662           0 : ::sal_Int32 SAL_CALL SwVbaSelection::getLanguageID() throw (uno::RuntimeException, std::exception)
     663             : {
     664           0 :     return getRange()->getLanguageID();
     665             : }
     666             : 
     667           0 : void SAL_CALL SwVbaSelection::setLanguageID( ::sal_Int32 _languageid ) throw (uno::RuntimeException, std::exception)
     668             : {
     669           0 :     getRange()->setLanguageID( _languageid );
     670           0 : }
     671             : 
     672           0 : uno::Any SAL_CALL SwVbaSelection::Information( sal_Int32 _type ) throw (uno::RuntimeException, std::exception)
     673             : {
     674           0 :     uno::Any result;
     675           0 :     switch( _type )
     676             :     {
     677             :         case word::WdInformation::wdActiveEndPageNumber:
     678             :         {
     679           0 :             result = uno::makeAny( SwVbaInformationHelper::handleWdActiveEndPageNumber( mxTextViewCursor ) );
     680           0 :             break;
     681             :         }
     682             :         case word::WdInformation::wdNumberOfPagesInDocument:
     683             :         {
     684           0 :             result = uno::makeAny( SwVbaInformationHelper::handleWdNumberOfPagesInDocument( mxModel ) );
     685           0 :             break;
     686             :         }
     687             :         case word::WdInformation::wdVerticalPositionRelativeToPage:
     688             :         {
     689           0 :             result = uno::makeAny( SwVbaInformationHelper::handleWdVerticalPositionRelativeToPage( mxModel, mxTextViewCursor ) );
     690           0 :             break;
     691             :         }
     692             :         case word::WdInformation::wdWithInTable:
     693             :         {
     694           0 :             uno::Reference< beans::XPropertySet > xCursorProps( mxTextViewCursor, uno::UNO_QUERY_THROW );
     695           0 :             uno::Reference< text::XTextTable > xTextTable;
     696           0 :             xCursorProps->getPropertyValue("TextTable") >>= xTextTable;
     697           0 :             if( xTextTable.is() )
     698           0 :                 result = uno::makeAny( true );
     699             :             else
     700           0 :                 result = uno::makeAny( false );
     701           0 :             break;
     702             :         }
     703             :         case word::WdInformation::wdHeaderFooterType:
     704             :         {
     705           0 :             uno::Reference< word::XView > xView( new SwVbaView( this, mxContext, mxModel ) );
     706           0 :             sal_Int32 nView = xView->getSeekView();
     707           0 :             sal_Int32 nHeaderFooterType = 0;
     708           0 :             switch( nView )
     709             :             {
     710             :                 case word::WdSeekView::wdSeekMainDocument:
     711             :                 {
     712           0 :                     nHeaderFooterType = -1; // not in a header or footer
     713           0 :                     break;
     714             :                 }
     715             :                 case word::WdSeekView::wdSeekEvenPagesHeader:
     716             :                 {
     717           0 :                     nHeaderFooterType = 0; // even page header
     718           0 :                     break;
     719             :                 }
     720             :                 case word::WdSeekView::wdSeekPrimaryHeader:
     721             :                 {
     722           0 :                     nHeaderFooterType = 1; // odd page header
     723           0 :                     break;
     724             :                 }
     725             :                 case word::WdSeekView::wdSeekEvenPagesFooter:
     726             :                 {
     727           0 :                     nHeaderFooterType = 2; // even page footer
     728           0 :                     break;
     729             :                 }
     730             :                 case word::WdSeekView::wdSeekPrimaryFooter:
     731             :                 {
     732           0 :                     nHeaderFooterType = 3; // odd page footer
     733           0 :                     break;
     734             :                 }
     735             :                 case word::WdSeekView::wdSeekFirstPageHeader:
     736             :                 case word::WdSeekView::wdSeekFirstPageFooter:
     737             :                 {
     738           0 :                     uno::Reference< beans::XPropertySet > xCursorProps( mxTextViewCursor, uno::UNO_QUERY_THROW );
     739           0 :                     OUString aPageStyleName;
     740           0 :                     xCursorProps->getPropertyValue("PageStyleName") >>= aPageStyleName;
     741           0 :                     bool bFirstPage = false;
     742           0 :                     if ( aPageStyleName == "First Page" )
     743           0 :                         bFirstPage = true;
     744           0 :                     if( nView == word::WdSeekView::wdSeekFirstPageHeader )
     745             :                     {
     746           0 :                         if( bFirstPage )
     747           0 :                             nHeaderFooterType = 4;
     748             :                         else
     749           0 :                             nHeaderFooterType = 1;
     750             :                     }
     751             :                     else
     752             :                     {
     753           0 :                         if( bFirstPage )
     754           0 :                             nHeaderFooterType = 5;
     755             :                         else
     756           0 :                             nHeaderFooterType = 3;
     757             :                     }
     758           0 :                     break;
     759             :                 }
     760             :                 default:
     761             :                 {
     762           0 :                     nHeaderFooterType = -1;
     763             :                 }
     764             :             }
     765           0 :             result = uno::makeAny( nHeaderFooterType );
     766           0 :             break;
     767             :         }
     768             :         default:
     769           0 :             throw uno::RuntimeException("Not implemented" );
     770             :     }
     771           0 :     return result;
     772             : }
     773             : 
     774           0 : void SAL_CALL SwVbaSelection::InsertBreak( const uno::Any& _breakType ) throw (uno::RuntimeException, std::exception)
     775             : {
     776           0 :     getRange()->InsertBreak( _breakType );
     777           0 : }
     778             : 
     779             : uno::Any SAL_CALL
     780           0 : SwVbaSelection::Tables( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
     781             : {
     782             :     // Hacky implementation due to missing api ( and lack of knowledge )
     783             :     // we can only support a selection that is a single table
     784           0 :     if ( !aIndex.hasValue() ) // currently we can't support multiple tables in a selection
     785           0 :        throw uno::RuntimeException();
     786             : 
     787           0 :     sal_Int32 nIndex = 0;
     788           0 :     aIndex >>= nIndex;
     789             : 
     790           0 :     uno::Any aRet;
     791             : 
     792           0 :     if ( nIndex != 1 )
     793           0 :        throw uno::RuntimeException();
     794             : 
     795           0 :     uno::Reference< beans::XPropertySet > xCursorProps( mxTextViewCursor, uno::UNO_QUERY_THROW );
     796           0 :     uno::Reference< text::XTextTable > xTextTable;
     797           0 :     xCursorProps->getPropertyValue("TextTable") >>= xTextTable;
     798           0 :     if( xTextTable.is() )
     799             :     {
     800           0 :             uno::Reference< css::text::XTextDocument > xTextDoc( mxModel, uno::UNO_QUERY_THROW );
     801           0 :             uno::Reference< word::XTable > xVBATable = new SwVbaTable( mxParent, mxContext, xTextDoc, xTextTable );
     802           0 :             aRet <<= xVBATable;
     803           0 :             return aRet;
     804             :     }
     805             : 
     806             :     // if the current selection is a XTextTableCursor and the index is 1 then we can service this request, otherwise we just have to throw
     807           0 :     uno::Reference< text::XTextTableCursor > xTextTableCursor( mxModel->getCurrentSelection(), uno::UNO_QUERY );
     808             : 
     809           0 :     if ( !xTextTableCursor.is() )
     810           0 :        throw uno::RuntimeException();
     811             : 
     812           0 :     SwXTextTableCursor* pTTCursor = dynamic_cast< SwXTextTableCursor* >( xTextTableCursor.get() );
     813           0 :     if ( pTTCursor )
     814             :     {
     815           0 :         SwFrameFormat* pFormat = pTTCursor->GetFrameFormat();
     816           0 :         if ( pFormat )
     817             :         {
     818           0 :             uno::Reference< text::XTextTable > xTable = SwXTextTables::GetObject(*pFormat);
     819           0 :             uno::Reference< css::text::XTextDocument > xTextDoc( mxModel, uno::UNO_QUERY_THROW );
     820           0 :             uno::Reference< word::XTable > xVBATable = new SwVbaTable( mxParent, mxContext, xTextDoc, xTable );
     821           0 :             aRet <<= xVBATable;
     822             :         }
     823             :     }
     824           0 :     return aRet;
     825             : 
     826             : }
     827             : 
     828             : uno::Any SAL_CALL
     829           0 : SwVbaSelection::Fields( const uno::Any& index ) throw (uno::RuntimeException, std::exception)
     830             : {
     831           0 :     uno::Reference< XCollection > xCol( new SwVbaFields( mxParent, mxContext, mxModel ) );
     832           0 :     if ( index.hasValue() )
     833           0 :         return xCol->Item( index, uno::Any() );
     834           0 :     return uno::makeAny( xCol );
     835             : }
     836             : 
     837             : uno::Reference< word::XHeaderFooter > SAL_CALL
     838           0 : SwVbaSelection::getHeaderFooter() throw ( uno::RuntimeException, std::exception )
     839             : {
     840           0 :     if( HeaderFooterHelper::isHeaderFooter( mxModel ) )
     841             :     {
     842           0 :         uno::Reference< beans::XPropertySet > xPageStyleProps( word::getCurrentPageStyle( mxModel ), uno::UNO_QUERY_THROW );
     843           0 :         sal_Int32 nIndex = word::WdHeaderFooterIndex::wdHeaderFooterPrimary;
     844           0 :         bool isHeader = HeaderFooterHelper::isHeader( mxModel );
     845           0 :         if( HeaderFooterHelper::isEvenPagesHeader( mxModel ) || HeaderFooterHelper::isEvenPagesFooter( mxModel ) )
     846           0 :             nIndex = word::WdHeaderFooterIndex::wdHeaderFooterEvenPages;
     847           0 :         else if( HeaderFooterHelper::isFirstPageHeader( mxModel ) || HeaderFooterHelper::isFirstPageFooter( mxModel ) )
     848           0 :             nIndex = word::WdHeaderFooterIndex::wdHeaderFooterFirstPage;
     849             : 
     850           0 :         return uno::Reference< word::XHeaderFooter >( new SwVbaHeaderFooter( this, mxContext, mxModel, xPageStyleProps, isHeader, nIndex ) );
     851             : 
     852             :     }
     853           0 :     return uno::Reference< word::XHeaderFooter >();
     854             : }
     855             : 
     856             : uno::Any SAL_CALL
     857           0 : SwVbaSelection::ShapeRange( ) throw (uno::RuntimeException, std::exception)
     858             : {
     859           0 :     uno::Reference< drawing::XShapes > xShapes( mxModel->getCurrentSelection(), uno::UNO_QUERY );
     860           0 :     if ( !xShapes.is() )
     861             :     {
     862           0 :         uno::Reference< drawing::XShape > xShape( mxModel->getCurrentSelection(), uno::UNO_QUERY_THROW );
     863           0 :         xShapes.set( drawing::ShapeCollection::create(mxContext) );
     864           0 :         xShapes->add( xShape );
     865             :     }
     866             : 
     867           0 :     uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( mxModel, uno::UNO_QUERY_THROW );
     868           0 :     uno::Reference< drawing::XDrawPage > xDrawPage = xDrawPageSupplier->getDrawPage();
     869           0 :     uno::Reference< container::XIndexAccess > xShapesAccess( xShapes, uno::UNO_QUERY_THROW );
     870           0 :     return uno::makeAny( uno::Reference< msforms::XShapeRange >( new ScVbaShapeRange( this, mxContext, xShapesAccess, xDrawPage, mxModel ) ) );
     871             : }
     872             : 
     873           0 : ::sal_Int32 SAL_CALL SwVbaSelection::getStart() throw (uno::RuntimeException, std::exception)
     874             : {
     875           0 :     return getRange()->getStart();
     876             : }
     877             : 
     878           0 : void SAL_CALL SwVbaSelection::setStart( ::sal_Int32 _start ) throw (uno::RuntimeException, std::exception)
     879             : {
     880           0 :     getRange()->setStart( _start );
     881           0 : }
     882           0 : ::sal_Int32 SAL_CALL SwVbaSelection::getEnd() throw (uno::RuntimeException, std::exception)
     883             : {
     884           0 :     return getRange()->getEnd();
     885             : }
     886             : 
     887           0 : void SAL_CALL SwVbaSelection::setEnd( ::sal_Int32 _end ) throw (uno::RuntimeException, std::exception)
     888             : {
     889           0 :     getRange()->setEnd( _end );
     890           0 : }
     891             : 
     892           0 : void SAL_CALL SwVbaSelection::SelectRow() throw (uno::RuntimeException, std::exception)
     893             : {
     894           0 :     uno::Reference< word::XRows > xRows( Rows( uno::Any() ), uno::UNO_QUERY_THROW );
     895           0 :     xRows->Select();
     896           0 : }
     897             : 
     898           0 : void SAL_CALL SwVbaSelection::SelectColumn() throw (uno::RuntimeException, std::exception)
     899             : {
     900           0 :     uno::Reference< word::XColumns > xColumns( Columns( uno::Any() ), uno::UNO_QUERY_THROW );
     901           0 :     xColumns->Select();
     902           0 : }
     903             : 
     904           0 : uno::Any SAL_CALL SwVbaSelection::Rows( const uno::Any& index ) throw (uno::RuntimeException, std::exception)
     905             : {
     906           0 :     OUString sTLName;
     907           0 :     OUString sBRName;
     908           0 :     GetSelectedCellRange( sTLName, sBRName );
     909             : 
     910           0 :     sal_Int32 nStartRow = 0;
     911           0 :     sal_Int32 nEndRow = 0;
     912           0 :     uno::Reference< text::XTextTable > xTextTable = GetXTextTable();
     913           0 :     SwVbaTableHelper aTableHelper( xTextTable );
     914           0 :     nStartRow = aTableHelper.getTabRowIndex( sTLName );
     915           0 :     if( !sBRName.isEmpty() )
     916             :     {
     917           0 :         nEndRow = aTableHelper.getTabRowIndex( sBRName );
     918             :     }
     919             :     else
     920             :     {
     921           0 :         nEndRow = nStartRow;
     922             :     }
     923             : 
     924           0 :     uno::Reference< XCollection > xCol( new SwVbaRows( this, mxContext, xTextTable, xTextTable->getRows(), nStartRow, nEndRow ) );
     925           0 :     if ( index.hasValue() )
     926           0 :         return xCol->Item( index, uno::Any() );
     927           0 :     return uno::makeAny( xCol );
     928             : }
     929             : 
     930           0 : uno::Any SAL_CALL SwVbaSelection::Columns( const uno::Any& index ) throw (uno::RuntimeException, std::exception)
     931             : {
     932           0 :     OUString sTLName;
     933           0 :     OUString sBRName;
     934           0 :     GetSelectedCellRange( sTLName, sBRName );
     935           0 :     sal_Int32 nStartColumn = 0;
     936           0 :     sal_Int32 nEndColumn = 0;
     937             : 
     938           0 :     uno::Reference< text::XTextTable > xTextTable = GetXTextTable();
     939           0 :     SwVbaTableHelper aTableHelper( xTextTable );
     940           0 :     nStartColumn = aTableHelper.getTabColIndex( sTLName );
     941           0 :     if( !sBRName.isEmpty() )
     942             :     {
     943           0 :         nEndColumn = aTableHelper.getTabColIndex( sBRName );
     944             :     }
     945             :     else
     946             :     {
     947           0 :         nEndColumn = nStartColumn;
     948             :     }
     949             : 
     950           0 :     uno::Reference< XCollection > xCol( new SwVbaColumns( this, mxContext, xTextTable, xTextTable->getColumns(), nStartColumn, nEndColumn ) );
     951           0 :     if ( index.hasValue() )
     952           0 :         return xCol->Item( index, uno::Any() );
     953           0 :     return uno::makeAny( xCol );
     954             : }
     955             : 
     956           0 : uno::Reference< text::XTextTable > SwVbaSelection::GetXTextTable() throw( uno::RuntimeException )
     957             : {
     958           0 :     uno::Reference< beans::XPropertySet > xCursorProps( mxTextViewCursor, uno::UNO_QUERY_THROW );
     959           0 :     uno::Reference< text::XTextTable > xTextTable;
     960           0 :     xCursorProps->getPropertyValue("TextTable") >>= xTextTable;
     961           0 :     return xTextTable;
     962             : }
     963             : 
     964           0 : bool SwVbaSelection::IsInTable() throw( uno::RuntimeException )
     965             : {
     966           0 :     uno::Reference< text::XTextTable > xTextTable = GetXTextTable();
     967           0 :     if( xTextTable.is() )
     968           0 :         return true;
     969           0 :     return false;
     970             : }
     971             : 
     972           0 : bool SwVbaSelection::HasSelection() throw( uno::RuntimeException )
     973             : {
     974           0 :     uno::Reference< text::XTextRange > xStart = mxTextViewCursor->getStart();
     975           0 :     uno::Reference< text::XTextRange > xEnd = mxTextViewCursor->getEnd();
     976           0 :     uno::Reference< text::XTextRangeCompare > xTRC( mxTextViewCursor->getText(), uno::UNO_QUERY_THROW );
     977           0 :     if( xTRC->compareRegionStarts( xStart, xEnd ) == 0 && xTRC->compareRegionEnds( xStart, xEnd ) == 0 )
     978           0 :         return false;
     979           0 :     return true;
     980             : }
     981             : 
     982           0 : void SwVbaSelection::GetSelectedCellRange( OUString& sTLName, OUString& sBRName ) throw( uno::RuntimeException )
     983             : {
     984           0 :     uno::Reference< beans::XPropertySet > xCursorProps( mxTextViewCursor, uno::UNO_QUERY_THROW );
     985           0 :     uno::Reference< text::XTextTable > xTextTable;
     986           0 :     xCursorProps->getPropertyValue("TextTable") >>= xTextTable;
     987           0 :     if( !xTextTable.is() )
     988           0 :         throw uno::RuntimeException( );
     989             : 
     990           0 :     uno::Reference< text::XTextTableCursor > xTextTableCursor( mxModel->getCurrentSelection(), uno::UNO_QUERY );
     991           0 :     if( xTextTableCursor.is() )
     992             :     {
     993           0 :         OUString sRange( xTextTableCursor->getRangeName() );
     994           0 :         if( comphelper::string::getTokenCount(sRange, ':') > 0 )
     995             :         {
     996           0 :             sTLName = sRange.getToken(0, ':');
     997           0 :             sBRName = sRange.getToken(1, ':');
     998           0 :         }
     999             :     }
    1000           0 :     if( sTLName.isEmpty() )
    1001             :     {
    1002           0 :         uno::Reference< table::XCell > xCell;
    1003           0 :         xCursorProps->getPropertyValue("Cell") >>= xCell;
    1004           0 :         if( !xCell.is() )
    1005             :         {
    1006           0 :             throw uno::RuntimeException( );
    1007             :         }
    1008           0 :         uno::Reference< beans::XPropertySet > xCellProps( xCell, uno::UNO_QUERY_THROW );
    1009           0 :         xCellProps->getPropertyValue("CellName") >>= sTLName;
    1010           0 :     }
    1011           0 : }
    1012             : 
    1013           0 : uno::Any SAL_CALL SwVbaSelection::Cells( const uno::Any& index ) throw (uno::RuntimeException, std::exception)
    1014             : {
    1015           0 :     OUString sTLName;
    1016           0 :     OUString sBRName;
    1017           0 :     GetSelectedCellRange( sTLName, sBRName );
    1018           0 :     sal_Int32 nLeft = 0;
    1019           0 :     sal_Int32 nTop = 0;
    1020           0 :     sal_Int32 nRight = 0;
    1021           0 :     sal_Int32 nBottom = 0;
    1022             : 
    1023           0 :     uno::Reference< text::XTextTable > xTextTable = GetXTextTable();
    1024           0 :     SwVbaTableHelper aTableHelper( xTextTable );
    1025           0 :     nLeft = aTableHelper.getTabColIndex( sTLName );
    1026           0 :     nTop = aTableHelper.getTabRowIndex( sTLName );
    1027           0 :     if( !sBRName.isEmpty() )
    1028             :     {
    1029           0 :         nRight = aTableHelper.getTabColIndex( sBRName );
    1030           0 :         nBottom = aTableHelper.getTabRowIndex( sBRName );
    1031             :     }
    1032             :     else
    1033             :     {
    1034           0 :         nRight = nLeft;
    1035           0 :         nBottom = nTop;
    1036             :     }
    1037             : 
    1038           0 :     uno::Reference< XCollection > xCol( new SwVbaCells( this, mxContext, xTextTable, nLeft, nTop, nRight, nBottom ) );
    1039           0 :     if ( index.hasValue() )
    1040           0 :         return xCol->Item( index, uno::Any() );
    1041           0 :     return uno::makeAny( xCol );
    1042             : }
    1043             : 
    1044           0 : void SAL_CALL SwVbaSelection::Copy(  ) throw (uno::RuntimeException, std::exception)
    1045             : {
    1046           0 :     OUString url = ".uno:Copy";
    1047           0 :     dispatchRequests( mxModel,url );
    1048           0 : }
    1049             : 
    1050           0 : void SAL_CALL SwVbaSelection::CopyAsPicture(  ) throw (uno::RuntimeException, std::exception)
    1051             : {
    1052             :     // seems not support in Writer
    1053           0 :     Copy();
    1054           0 : }
    1055             : 
    1056           0 : void SAL_CALL SwVbaSelection::Paste(  ) throw (uno::RuntimeException, std::exception)
    1057             : {
    1058           0 :     OUString url = ".uno:Paste";
    1059           0 :     dispatchRequests( mxModel,url );
    1060           0 : }
    1061             : 
    1062           0 : void SAL_CALL SwVbaSelection::Collapse( const uno::Any& Direction ) throw (uno::RuntimeException, std::exception)
    1063             : {
    1064           0 :     if( word::gotoSelectedObjectAnchor( mxModel ) )
    1065           0 :         return;
    1066             : 
    1067           0 :     sal_Int32 nDirection = word::WdCollapseDirection::wdCollapseStart;
    1068           0 :     if( Direction.hasValue() )
    1069           0 :         Direction >>= nDirection;
    1070             : 
    1071           0 :     uno::Reference< text::XTextViewCursor > xTextViewCursor = word::getXTextViewCursor( mxModel );
    1072           0 :     if( nDirection == word::WdCollapseDirection::wdCollapseStart )
    1073             :     {
    1074             :         // it is inaccurate if current seleciton is multipul cells, so it needs to go to start
    1075           0 :         uno::Reference< text::XTextRange > xTextRange = mxTextViewCursor->getStart();
    1076           0 :         xTextViewCursor->gotoRange( xTextRange, sal_False );
    1077           0 :         xTextViewCursor->collapseToStart();
    1078             :     }
    1079           0 :     else if( nDirection == word::WdCollapseDirection::wdCollapseEnd )
    1080             :     {
    1081           0 :         uno::Reference< text::XTextRange > xTextRange = mxTextViewCursor->getEnd();
    1082           0 :         xTextViewCursor->gotoRange( xTextRange, sal_False );
    1083           0 :         xTextViewCursor->collapseToEnd();
    1084             :     }
    1085             :     else
    1086             :     {
    1087           0 :         throw uno::RuntimeException();
    1088           0 :     }
    1089             : }
    1090             : 
    1091           0 : void SAL_CALL SwVbaSelection::WholeStory(  ) throw (uno::RuntimeException, std::exception)
    1092             : {
    1093           0 :     uno::Reference< text::XText > xText = word::getCurrentXText( mxModel );
    1094             :     // FIXME: for i#7747,if the first line is a table, it fails to select all the contents in the story.
    1095             :     // Temporary solution, insert an empty line before the table so that it could select all the contents.
    1096           0 :     uno::Reference< container::XEnumerationAccess > xParaAccess( xText, uno::UNO_QUERY_THROW );
    1097           0 :     uno::Reference< container::XEnumeration> xParaEnum = xParaAccess->createEnumeration();
    1098           0 :     if( xParaEnum->hasMoreElements() )
    1099             :     {
    1100           0 :         uno::Reference< text::XTextTable > xTextTable( xParaEnum->nextElement(), uno::UNO_QUERY );
    1101           0 :         if( xTextTable.is() )
    1102             :         {
    1103             :             // insert an empty line
    1104           0 :             uno::Reference< text::XTextRange > xFirstCellRange = word::getFirstObjectPosition( xText );
    1105           0 :             mxTextViewCursor->gotoRange( xFirstCellRange, sal_False );
    1106           0 :             OUString url = ".uno:InsertPara";
    1107           0 :             dispatchRequests( mxModel,url );
    1108           0 :         }
    1109             :     }
    1110           0 :     uno::Reference< text::XTextRange > xStart = xText->getStart();
    1111           0 :     uno::Reference< text::XTextRange > xEnd = xText->getEnd();
    1112           0 :     mxTextViewCursor->gotoRange( xStart, sal_False );
    1113           0 :     mxTextViewCursor->gotoRange( xEnd, sal_True );
    1114           0 : }
    1115             : 
    1116           0 : sal_Bool SAL_CALL SwVbaSelection::InRange( const uno::Reference< ::ooo::vba::word::XRange >& Range ) throw (uno::RuntimeException, std::exception)
    1117             : {
    1118           0 :     return getRange()->InRange( Range );
    1119             : }
    1120             : 
    1121           0 : void SAL_CALL SwVbaSelection::SplitTable()
    1122             :     throw (uno::RuntimeException, std::exception)
    1123             : {
    1124           0 :     if( !IsInTable() )
    1125           0 :         throw uno::RuntimeException();
    1126             : 
    1127           0 :     SwDocShell* pDocShell = word::getDocShell( mxModel );
    1128           0 :     if( pDocShell )
    1129             :     {
    1130           0 :         SwFEShell* pFEShell = pDocShell->GetFEShell();
    1131           0 :         if( pFEShell )
    1132             :         {
    1133           0 :             pFEShell->SplitTable( HEADLINE_CNTNTCOPY );
    1134             :         }
    1135             :     }
    1136           0 : }
    1137             : 
    1138             : uno::Any SAL_CALL
    1139           0 : SwVbaSelection::Paragraphs( const uno::Any& aIndex ) throw (uno::RuntimeException, std::exception)
    1140             : {
    1141             :     // Hacky implementation due to missing api ( and lack of knowledge )
    1142             :     // we can only support a selection that is a single paragraph
    1143           0 :     if ( !aIndex.hasValue() ) // currently we can't support multiple paragraphs in a selection
    1144           0 :        throw uno::RuntimeException();
    1145             : 
    1146           0 :     sal_Int32 nIndex = 0;
    1147           0 :     aIndex >>= nIndex;
    1148             : 
    1149           0 :     uno::Any aRet;
    1150             : 
    1151           0 :     if ( nIndex != 1 )
    1152           0 :        throw uno::RuntimeException();
    1153             : 
    1154           0 :     uno::Reference< text::XTextRange > xTextRange = mxTextViewCursor->getStart();
    1155           0 :     uno::Reference< text::XText > xText = xTextRange->getText();
    1156           0 :     uno::Reference< text::XParagraphCursor > xParaCursor( xText->createTextCursor(), uno::UNO_QUERY_THROW );
    1157           0 :     xParaCursor->gotoStartOfParagraph( sal_False );
    1158           0 :     xParaCursor->gotoStartOfParagraph( sal_True );
    1159             : 
    1160           0 :     uno::Reference< text::XTextDocument > xTextDoc( mxModel, uno::UNO_QUERY_THROW );
    1161           0 :     uno::Reference< text::XTextRange > xParaRange( xParaCursor, uno::UNO_QUERY_THROW );
    1162           0 :     uno::Reference< word::XParagraph > xParagraph = new SwVbaParagraph( mxParent, mxContext, xTextDoc, xParaRange );
    1163             : 
    1164           0 :     aRet <<= xParagraph;
    1165           0 :     return aRet;
    1166             : }
    1167             : 
    1168             : OUString
    1169           0 : SwVbaSelection::getServiceImplName()
    1170             : {
    1171           0 :     return OUString("SwVbaSelection");
    1172             : }
    1173             : 
    1174             : uno::Sequence< OUString >
    1175           0 : SwVbaSelection::getServiceNames()
    1176             : {
    1177           0 :     static uno::Sequence< OUString > aServiceNames;
    1178           0 :     if ( aServiceNames.getLength() == 0 )
    1179             :     {
    1180           0 :         aServiceNames.realloc( 1 );
    1181           0 :         aServiceNames[ 0 ] = "ooo.vba.word.Selection";
    1182             :     }
    1183           0 :     return aServiceNames;
    1184           3 : }
    1185             : 
    1186             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11