diff options
Diffstat (limited to 'sw/source/ui/vba/vbarangehelper.cxx')
-rw-r--r-- | sw/source/ui/vba/vbarangehelper.cxx | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/sw/source/ui/vba/vbarangehelper.cxx b/sw/source/ui/vba/vbarangehelper.cxx index 4fd9e5f143f1..8e4d1f348e02 100644 --- a/sw/source/ui/vba/vbarangehelper.cxx +++ b/sw/source/ui/vba/vbarangehelper.cxx @@ -1,3 +1,4 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -27,6 +28,7 @@ #include "vbarangehelper.hxx" #include <com/sun/star/text/ControlCharacter.hpp> #include <com/sun/star/text/XTextRangeCompare.hpp> +#include <com/sun/star/text/XBookmarksSupplier.hpp> using namespace ::ooo::vba; using namespace ::com::sun::star; @@ -111,7 +113,7 @@ uno::Reference< text::XTextCursor > SwVbaRangeHelper::initCursor( const uno::Ref DebugHelper::exception(e); } - if( !bGotTextCursor ) + if( !bGotTextCursor || !xTextCursor.is() ) { try { @@ -125,7 +127,7 @@ uno::Reference< text::XTextCursor > SwVbaRangeHelper::initCursor( const uno::Ref } } - if( !bGotTextCursor ) + if( !bGotTextCursor || !xTextCursor.is() ) { try { @@ -169,3 +171,30 @@ sal_Int32 SwVbaRangeHelper::getPosition( const uno::Reference< text::XText >& rT return nPosition; } + +uno::Reference< text::XTextContent > SwVbaRangeHelper::findBookmarkByPosition( const uno::Reference< text::XTextDocument >& xTextDoc, const uno::Reference< text::XTextRange >& xTextRange ) throw ( css::uno::RuntimeException ) +{ + uno::Reference< text::XBookmarksSupplier > xBookmarksSupplier( xTextDoc, uno::UNO_QUERY_THROW ); + uno::Reference< container::XIndexAccess > xIndexAccess( xBookmarksSupplier->getBookmarks(), uno::UNO_QUERY_THROW ); + for( sal_Int32 index = 0; index < xIndexAccess->getCount(); index++ ) + { + uno::Reference< text::XTextContent > xBookmark( xIndexAccess->getByIndex( index ), uno::UNO_QUERY_THROW ); + uno::Reference< text::XTextRange > xBkAnchor = xBookmark->getAnchor(); + uno::Reference< text::XTextRangeCompare > xCompare( xBkAnchor->getText(), uno::UNO_QUERY_THROW ); + if( xCompare->compareRegionStarts( xBkAnchor->getStart(), xBkAnchor->getEnd() ) == 0 ) + { + try + { + if( xCompare->compareRegionStarts( xTextRange, xBkAnchor->getStart() ) == 0 ) + return xBookmark; + } + catch( uno::Exception& ) + { + continue; + } + } + } + return uno::Reference< text::XTextContent >(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |