23#include <com/sun/star/drawing/XShapes.hpp>
24#include <com/sun/star/drawing/XDrawPage.hpp>
25#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
35#include <unoprnms.hxx>
40#define WID_SEARCH_BACKWARDS 0
41#define WID_SEARCH_CASE 1
42#define WID_SEARCH_WORDS 2
53 return aSearchPropertyMap_Impl;
58class SearchContext_impl
60 uno::Reference< drawing::XShapes > mxShapes;
64 SearchContext_impl(uno::Reference<drawing::XShapes> xShapes)
65 : mxShapes(
std::move( xShapes )),
mnIndex( -1 ) {}
67 uno::Reference< drawing::XShape > firstShape()
73 uno::Reference< drawing::XShape > nextShape()
75 uno::Reference< drawing::XShape > xShape;
77 if( mxShapes.is() && mxShapes->getCount() > mnIndex )
79 mxShapes->getByIndex( mnIndex ) >>= xShape;
110 if( pDescr ==
nullptr )
113 sal_Int32 nFound = 0;
115 uno::Reference< drawing::XShapes > xShapes;
116 uno::Reference< drawing::XShape > xShape;
118 std::vector<SearchContext_impl> aContexts;
123 if( xShapes->getCount() )
125 aContexts.push_back(SearchContext_impl(xShapes));
126 xShape = aContexts.back().firstShape();
137 uno::Reference< text::XText > xText(xShape, uno::UNO_QUERY);
138 uno::Reference< text::XTextRange > xRange = xText;
139 uno::Reference< text::XTextRange > xFound;
143 xFound =
Search( xRange, pDescr );
148 xRange = xFound->getEnd();
154 uno::Reference< drawing::XShapes > xGroupShape( xShape, uno::UNO_QUERY );
155 if( xGroupShape.is() && ( xGroupShape->getCount() > 0 ) )
157 aContexts.push_back(SearchContext_impl(xGroupShape));
158 xShape = aContexts.back().firstShape();
162 if (!aContexts.empty())
163 xShape = aContexts.back().nextShape();
170 while (!aContexts.empty() && !xShape.is())
172 aContexts.pop_back();
173 if (!aContexts.empty())
174 xShape = aContexts.back().nextShape();
190 if( pDescr ==
nullptr )
191 return uno::Reference< container::XIndexAccess > ();
193 sal_Int32 nSequence = 32;
194 sal_Int32 nFound = 0;
196 uno::Sequence < uno::Reference< uno::XInterface > >
aSeq( nSequence );
198 uno::Reference< uno::XInterface > * pArray =
aSeq.getArray();
200 uno::Reference< drawing::XShapes > xShapes;
201 uno::Reference< drawing::XShape > xShape;
203 std::vector<SearchContext_impl> aContexts;
208 if( xShapes->getCount() > 0 )
210 aContexts.push_back(SearchContext_impl(xShapes));
211 xShape = aContexts.back().firstShape();
222 uno::Reference< text::XText > xText(xShape, uno::UNO_QUERY);
223 uno::Reference< text::XTextRange > xRange = xText;
224 uno::Reference< text::XTextRange > xFound;
228 xFound =
Search( xRange, pDescr );
232 if( nFound >= nSequence )
235 aSeq.realloc( nSequence );
236 pArray =
aSeq.getArray();
239 pArray[nFound++] = xFound;
241 xRange = xFound->getEnd();
246 uno::Reference< drawing::XShapes > xGroupShape;
247 xGroupShape.set( xShape, uno::UNO_QUERY );
249 if( xGroupShape.is() && xGroupShape->getCount() > 0 )
251 aContexts.push_back(SearchContext_impl(xGroupShape));
252 xShape = aContexts.back().firstShape();
256 if (!aContexts.empty())
257 xShape = aContexts.back().nextShape();
264 while (!aContexts.empty() && !xShape.is())
266 aContexts.pop_back();
267 if (!aContexts.empty())
268 xShape = aContexts.back().nextShape();
272 if( nFound != nSequence )
273 aSeq.realloc( nFound );
281 uno::Reference< text::XTextRange > xRange(
GetCurrentShape(), uno::UNO_QUERY );
285 return uno::Reference< uno::XInterface > ();
290 uno::Reference< drawing::XShape > xShape;
293 mpPage->getByIndex(0) >>= xShape;
299uno::Reference< css::uno::XInterface > SAL_CALL
SdUnoSearchReplaceShape::findNext(
const css::uno::Reference< css::uno::XInterface >& xStartAt,
const css::uno::Reference< css::util::XSearchDescriptor >& xDesc )
303 uno::Reference< uno::XInterface > xFound;
305 uno::Reference< text::XTextRange > xRange( xStartAt, uno::UNO_QUERY );
306 if(pDescr && xRange.is() )
309 uno::Reference< text::XTextRange > xCurrentRange( xStartAt, uno::UNO_QUERY );
311 uno::Reference< drawing::XShape > xCurrentShape(
GetShape( xCurrentRange ) );
313 while(!xFound.is() && xRange.is())
315 xFound =
Search( xRange, pDescr );
326 if( xFound2.is() && (xFound2.get() != xCurrentShape.get()) )
327 xCurrentShape = xFound2;
329 xCurrentShape =
nullptr;
331 xRange.set( xCurrentShape, uno::UNO_QUERY );
332 if(!(xCurrentShape.is() && (xRange.is())))
351 uno::Reference< drawing::XShape > xFound;
353 if(xShapes.is() && xCurrentShape.is())
355 const sal_Int32
nCount = xShapes->getCount();
358 uno::Reference< drawing::XShape > xSearchShape;
359 xShapes->getByIndex(
i) >>= xSearchShape;
361 if( xSearchShape.is() )
363 uno::Reference< container::XIndexAccess > xGroup( xSearchShape, uno::UNO_QUERY );
365 if( xCurrentShape.get() == xSearchShape.get() )
367 if( xGroup.is() && xGroup->getCount() > 0 )
369 xGroup->getByIndex( 0 ) >>= xFound;
375 xShapes->getByIndex(
i ) >>= xFound;
377 xFound = xCurrentShape;
382 else if( xGroup.is() )
384 xFound = GetNextShape( xGroup, xCurrentShape );
387 if( xFound.get() == xCurrentShape.get() )
393 xShapes->getByIndex(
i) >>= xFound;
409 return uno::Reference< text::XTextRange > ();
411 uno::Reference< text::XText > xParent( xText->getText() );
415 xParent.set( xText, uno::UNO_QUERY );
418 const OUString aText( xParent->getString() );
420 const sal_Int32 nTextLen = aText.getLength();
422 std::unique_ptr<sal_Int32[]> pConvertPos(
new sal_Int32[nTextLen+2] );
423 std::unique_ptr<sal_Int32[]> pConvertPara(
new sal_Int32[nTextLen+2] );
425 sal_Int32* pPos = pConvertPos.get();
426 sal_Int32* pPara = pConvertPara.get();
428 sal_Int32 nLastPos = 0, nLastPara = 0;
430 uno::Reference< container::XEnumerationAccess > xEnumAccess( xParent, uno::UNO_QUERY );
434 if( xEnumAccess.is() )
436 uno::Reference< container::XEnumeration > xParaEnum( xEnumAccess->createEnumeration() );
438 while(xParaEnum->hasMoreElements())
441 uno::Reference< text::XTextContent > xParagraph( xParaEnum->nextElement(), uno::UNO_QUERY );
442 if( xParagraph.is() )
443 xEnumAccess.set(xParagraph, css::uno::UNO_QUERY);
447 if( xEnumAccess.is() )
449 uno::Reference< container::XEnumeration > xPortionEnum( xEnumAccess->createEnumeration() );
450 if( xPortionEnum.is() )
452 while(xPortionEnum->hasMoreElements())
454 uno::Reference< text::XTextRange > xPortion( xPortionEnum->nextElement(), uno::UNO_QUERY );
457 const OUString aPortion( xPortion->getString() );
458 const sal_Int32 nLen = aPortion.getLength();
464 if( (aStartSel.nStartPos == aEndSel.nStartPos) || ( (aStartSel.nStartPos == (aEndSel.nStartPos - 1)) && (nLen > 1) ) )
466 for( sal_Int32 i = 0;
i < nLen;
i++ )
468 if( ndbg < (nTextLen+2) )
470 *pPos++ = aStartSel.nStartPos;
471 *pPara++ = aStartSel.nStartPara;
477 OSL_FAIL(
"array overflow while searching" );
481 nLastPos = aStartSel.nStartPos;
486 for( sal_Int32 i = 0;
i < nLen;
i++ )
488 if( ndbg < (nTextLen+2) )
490 *pPos++ = aStartSel.nStartPos++;
491 *pPara++ = aStartSel.nStartPara;
497 OSL_FAIL(
"array overflow while searching" );
501 nLastPos = aStartSel.nStartPos - 1;
502 DBG_ASSERT( aEndSel.nStartPos == aStartSel.nStartPos,
"Search is not working" );
504 nLastPara = aStartSel.nStartPara;
510 if( ndbg < (nTextLen+2) )
512 *pPos++ = nLastPos + 1;
513 *pPara++ = nLastPara;
517 OSL_FAIL(
"array overflow while searching" );
522 uno::Reference< text::XTextRange > xFound;
529 sal_Int32 nEndPos = 0;
530 for( nStartPos = 0; nStartPos < nTextLen; nStartPos++ )
532 if( pConvertPara[nStartPos] == aSel.
nStartPara && pConvertPos[nStartPos] == aSel.
nStartPos )
536 if(
Search( aText, nStartPos, nEndPos, pDescr ) )
538 if( nStartPos <= nTextLen && nEndPos <= nTextLen )
540 ESelection aSelection( pConvertPara[nStartPos], pConvertPos[nStartPos],
541 pConvertPara[nEndPos], pConvertPos[nEndPos] );
543 SvxUnoTextBase* pParent = comphelper::getFromUnoTunnel<SvxUnoTextBase>( xParent );
549 pRange->SetSelection(aSelection);
554 OSL_FAIL(
"Array overflow while searching!");
564 OUString aText( rText );
568 aText = aText.toAsciiLowerCase();
569 aSearchStr = aSearchStr.toAsciiLowerCase();
572 sal_Int32 nFound = aText.indexOf( aSearchStr, nStartPos );
576 nEndPos = nFound + aSearchStr.getLength();
580 if( (nStartPos > 0 && aText[nStartPos-1] >
' ') ||
581 (nEndPos < aText.getLength() && aText[nEndPos] >
' ') )
584 return Search( aText, nStartPos, nEndPos, pDescr );
597 SvxUnoTextRangeBase* pRange = comphelper::getFromUnoTunnel<SvxUnoTextRangeBase>( xTextRange );
600 aSel = pRange->GetSelection();
607 uno::Reference< drawing::XShape > xShape;
611 uno::Reference< text::XText > xText( xTextRange->getText() );
617 xShape.set( xText, uno::UNO_QUERY );
620 uno::Reference< text::XText > xParent( xText->getText() );
621 if(!xParent.is() || xText.get() == xParent.get())
626 }
while( !xShape.is() );
688 switch( pEntry ? pEntry->
nWID : -1 )
700 throw beans::UnknownPropertyException( aPropertyName,
static_cast<cppu::OWeakObject*
>(
this));
704 throw lang::IllegalArgumentException();
715 switch( pEntry ? pEntry->
nWID : -1 )
727 throw beans::UnknownPropertyException( PropertyName,
static_cast<cppu::OWeakObject*
>(
this));
741:maSequence( rSequence )
769 throw lang::IndexOutOfBoundsException();
this class holds a sequence that is a result from a find all and lets people access it through the XI...
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 Index) override
SdUnoFindAllAccess(css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > const &rSequence) noexcept
virtual sal_Bool SAL_CALL hasElements() override
virtual sal_Int32 SAL_CALL getCount() override
virtual ~SdUnoFindAllAccess() noexcept override
virtual css::uno::Type SAL_CALL getElementType() override
css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > maSequence
this class holds the parameters and status of a search or replace operation performed by class SdUnoS...
virtual OUString SAL_CALL getReplaceString() override
std::unique_ptr< SvxItemPropertySet > mpPropSet
virtual void SAL_CALL setSearchString(const OUString &aString) override
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
SdUnoSearchReplaceDescriptor()
this class holds the parameters and status of a search or replace operation performed by class SdUnoS...
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
virtual ~SdUnoSearchReplaceDescriptor() noexcept override
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
virtual OUString SAL_CALL getSearchString() override
bool IsCaseSensitive() const
virtual void SAL_CALL setReplaceString(const OUString &aReplaceString) override
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
css::uno::Reference< css::drawing::XShape > GetNextShape(const css::uno::Reference< css::container::XIndexAccess > &xShapes, const css::uno::Reference< css::drawing::XShape > &xCurrentShape) noexcept
this method returns the shape that follows xCurrentShape in the shape collection xShapes.
virtual css::uno::Reference< css::util::XSearchDescriptor > SAL_CALL createSearchDescriptor() override
css::uno::Reference< css::drawing::XShape > GetCurrentShape() const noexcept
static ESelection GetSelection(const css::uno::Reference< css::text::XTextRange > &xTextRange) noexcept
virtual sal_Int32 SAL_CALL replaceAll(const css::uno::Reference< css::util::XSearchDescriptor > &xDesc) override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL findNext(const css::uno::Reference< css::uno::XInterface > &xStartAt, const css::uno::Reference< css::util::XSearchDescriptor > &xDesc) override
css::drawing::XDrawPage * mpPage
virtual css::uno::Reference< css::container::XIndexAccess > SAL_CALL findAll(const css::uno::Reference< css::util::XSearchDescriptor > &xDesc) override
static css::uno::Reference< css::drawing::XShape > GetShape(const css::uno::Reference< css::text::XTextRange > &xTextRange) noexcept
css::uno::Reference< css::text::XTextRange > Search(const css::uno::Reference< css::text::XTextRange > &xText, SdUnoSearchReplaceDescriptor *pDescr)
SdUnoSearchReplaceShape(css::drawing::XDrawPage *xPage) noexcept
this class implements a search or replace operation on a given page or a given sdrobj
virtual css::uno::Reference< css::util::XReplaceDescriptor > SAL_CALL createReplaceDescriptor() override
virtual ~SdUnoSearchReplaceShape() noexcept
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL findFirst(const css::uno::Reference< css::util::XSearchDescriptor > &xDesc) override
static SdrItemPool & GetGlobalDrawObjectItemPool()
css::uno::Type const & get()
#define DBG_ASSERT(sCon, aError)
Sequence< sal_Int8 > aSeq
#define UNO_NAME_SEARCH_CASE
#define UNO_NAME_SEARCH_BACKWARDS
#define UNO_NAME_SEARCH_WORDS
static o3tl::span< const SfxItemPropertyMapEntry > ImplGetSearchPropertyMap()
#define WID_SEARCH_BACKWARDS