21#include <com/sun/star/text/ControlCharacter.hpp>
22#include <com/sun/star/text/XTextRangeCompare.hpp>
23#include <com/sun/star/text/XBookmarksSupplier.hpp>
41 uno::Reference< text::XTextRange > xRange;
45 uno::Reference< text::XTextCursor > xCursor = rText->createTextCursor();
46 xCursor->collapseToStart();
48 while( !xRange.is() && bCanGo )
50 if( _position ==
nPos )
52 xRange = xCursor->getStart();
56 bCanGo = xCursor->goRight( 1,
false );
64void SwVbaRangeHelper::insertString( uno::Reference< text::XTextRange >
const & rTextRange, uno::Reference< text::XText >
const & rText, std::u16string_view aStr,
bool _bAbsorb )
66 size_t nlastIndex = 0;
68 uno::Reference< text::XTextRange > xRange = rTextRange;
70 while( (
nIndex =
aStr.find(
'\n', nlastIndex)) != std::u16string_view::npos )
72 xRange = xRange->getEnd();
73 if( nlastIndex < (
nIndex - 1 ) )
75 rText->insertString( xRange, OUString(
aStr.substr( nlastIndex, (
nIndex - 1 - nlastIndex ) )), _bAbsorb );
76 xRange = xRange->getEnd();
79 rText->insertControlCharacter( xRange, text::ControlCharacter::PARAGRAPH_BREAK, _bAbsorb );
83 if( nlastIndex <
aStr.size() )
85 xRange = xRange->getEnd();
87 OUString aWatt(
aStr.substr( nlastIndex ) );
88 rText->insertString( xRange, aWatt, _bAbsorb );
93 const uno::Reference< text::XText >& rText )
95 uno::Reference< text::XTextCursor > xTextCursor;
96 bool bGotTextCursor =
false;
100 xTextCursor = rText->createTextCursorByRange( rTextRange );
101 bGotTextCursor =
true;
103 catch (
const uno::Exception& e)
105 DebugHelper::basicexception(e);
108 if( !bGotTextCursor || !xTextCursor.is() )
112 uno::Reference< text::XText > xText = rTextRange->getText();
113 xTextCursor = xText->createTextCursor();
114 bGotTextCursor =
true;
116 catch (
const uno::Exception& e)
118 DebugHelper::basicexception(e);
122 if( !bGotTextCursor || !xTextCursor.is() )
126 xTextCursor = rText->createTextCursor();
128 catch (
const uno::Exception& e)
130 DebugHelper::basicexception(e);
138 sal_Int32 nPosition = -1;
139 if( rText.is() && rTextRange.is() )
142 uno::Reference< text::XTextCursor > xCursor = rText->createTextCursor();
143 xCursor->collapseToStart();
144 uno::Reference< text::XTextRangeCompare > xCompare( rText, uno::UNO_QUERY_THROW );
146 sal_Int32 nCompareValue = xCompare->compareRegionStarts( xCursor->getStart(), rTextRange );
149 while( nCompareValue !=0 && canGo )
151 canGo = xCursor->goRight( 1,
false );
152 nCompareValue = xCompare->compareRegionStarts( xCursor->getStart(), rTextRange );
157 if( !canGo && nCompareValue != 0 )
168 uno::Reference< text::XBookmarksSupplier > xBookmarksSupplier( xTextDoc, uno::UNO_QUERY_THROW );
169 uno::Reference< container::XIndexAccess > xIndexAccess( xBookmarksSupplier->getBookmarks(), uno::UNO_QUERY_THROW );
172 uno::Reference< text::XTextContent > xBookmark( xIndexAccess->getByIndex(
index ), uno::UNO_QUERY_THROW );
173 uno::Reference< text::XTextRange > xBkAnchor = xBookmark->getAnchor();
174 uno::Reference< text::XTextRangeCompare > xCompare( xBkAnchor->getText(), uno::UNO_QUERY_THROW );
175 if( xCompare->compareRegionStarts( xBkAnchor->getStart(), xBkAnchor->getEnd() ) == 0 )
179 if( xCompare->compareRegionStarts( xTextRange, xBkAnchor->getStart() ) == 0 )
182 catch (
const uno::Exception&)
188 return uno::Reference< text::XTextContent >();
static void insertString(css::uno::Reference< css::text::XTextRange > const &rTextRange, css::uno::Reference< css::text::XText > const &rText, std::u16string_view aStr, bool _bAbsorb)
static sal_Int32 getPosition(const css::uno::Reference< css::text::XText > &rText, const css::uno::Reference< css::text::XTextRange > &rTextRange)
static css::uno::Reference< css::text::XTextCursor > initCursor(const css::uno::Reference< css::text::XTextRange > &rTextRange, const css::uno::Reference< css::text::XText > &rText)
static css::uno::Reference< css::text::XTextRange > getRangeByPosition(const css::uno::Reference< css::text::XText > &rText, sal_Int32 _position)
get a range in a xText by creating a cursor that iterates over the text.
static css::uno::Reference< css::text::XTextContent > findBookmarkByPosition(const css::uno::Reference< css::text::XTextDocument > &xTextDoc, const css::uno::Reference< css::text::XTextRange > &xTextRange)