e8cad7c6d2
2009-04-22 12:58:26 +0200 b_michaelsen r271093 : #i101084# using the frames enumeration for other SwXFrames-queries; also added a complex test to ensure the behavior to be the same 2009-04-20 14:53:03 +0200 mav r270987 : #i101219# adjust the testcases to test memory cache and temporary file cache 2009-04-20 14:52:09 +0200 mav r270986 : #i101219#,#i99077# use memory to cache data; no precopying on commit 2009-04-20 14:39:21 +0200 mav r270984 : #i101219# use memory to cache data 2009-04-20 14:39:08 +0200 mav r270983 : #i101219# use memory to cache data 2009-04-20 14:38:45 +0200 mav r270982 : #i101219# use memory to cache data 2009-04-17 07:37:52 +0200 os r270912 : CWS-TOOLING: rebase CWS os128 to trunk@270723 (milestone: DEV300:m46) 2009-04-15 14:54:18 +0200 b_michaelsen r270845 : #i101084# using frame enumerations for paragraph export for better performance 2009-04-15 14:52:54 +0200 b_michaelsen r270843 : #i101084# implemented XEnumerationAccess interface on framesets 2009-04-03 17:08:10 +0200 mav r270504 : #i100722# do not compress streams of known compressed types per default 2009-04-03 13:49:50 +0200 os r270484 : resync error fixed 2009-04-03 12:55:32 +0200 mav r270470 : #i100722# do not compress streams of known compressed types per default 2009-04-03 10:00:58 +0200 os r270463 : resync error fixed 2009-04-03 09:52:53 +0200 os r270462 : resync error fixed 2009-04-03 09:10:14 +0200 os r270449 : #i99568# string compare operator of hash_map changed 2009-04-03 09:03:49 +0200 os r270446 : #i100683# normalize file URLs 2009-04-02 11:09:27 +0200 os r270381 : #i100683# making URLs relative without file access 2009-04-02 09:04:42 +0200 os r270366 : CWS-TOOLING: rebase CWS os128 to trunk@270033 (milestone: DEV300:m45) 2009-03-31 08:08:37 +0200 os r270258 : #i100683# reducing calls to URIHelper::simpleNormalizeMakeRelative() 2009-03-19 17:06:22 +0100 os r269756 : #i99568# XTolerantMultiPropertySet activated 2009-03-16 11:46:14 +0100 os r269517 : wrong commit to #i97471# removed 2009-03-16 11:36:50 +0100 os r269514 : #i97471# SwDrawTextShell::Init(): mouse double click and key input in group objects at the same time: prevent crash 2009-03-13 11:08:54 +0100 os r269464 : #i99568# static SfxItemPropertySet 2009-03-13 11:03:22 +0100 os r269463 : #i99568# static SfxItemPropertySet 2009-03-11 12:59:27 +0100 os r269320 : #i99568# WhichId of properties handled from ScDocOptionsObj added 2009-03-06 09:09:58 +0100 os r268972 : #i99568# SfxItemPropertySet improvements 2009-03-05 20:54:43 +0100 os r268942 : #i99568# Sfx/SvxItemPropertySet improvements 2009-03-05 20:19:52 +0100 os r268941 : #i99568# SfxItemPropertySet improvements 2009-03-05 20:05:03 +0100 os r268940 : #i99568# SfxItemPropertySet improvements 2009-03-05 18:54:47 +0100 os r268936 : #i99568# Sfx/SvxItemPropertySet improvements 2009-03-05 17:51:38 +0100 os r268931 : #i99568# Sfx/SvxItemPropertySet improvements 2009-03-05 17:33:03 +0100 os r268930 : #i99568# Sfx/SvxItemPropertySet improvements 2009-03-05 15:53:00 +0100 os r268920 : #i99568# Sfx/SvxItemPropertySet improvements 2009-03-05 15:52:50 +0100 os r268919 : #i99568# Sfx/SvxItemPropertySet improvements 2009-03-05 15:50:41 +0100 os r268918 : #i99568# Sfx/SvxItemPropertySet improvements 2009-03-05 15:41:04 +0100 os r268916 : #i99568# Sfx/SvxItemPropertySet improvements 2009-03-05 15:40:40 +0100 os r268915 : #i99568# Sfx/SvxItemPropertySet improvements 2009-03-05 10:16:20 +0100 os r268881 : #i99568# Sfx/SvxItemPropertySet improvements 2009-03-05 10:15:55 +0100 os r268880 : #i99568# Sfx/SvxItemPropertySet improvements 2009-03-03 08:40:09 +0100 os r268704 : ScTableSheetObj::GetItemPropertyMap fixed 2009-03-03 07:50:00 +0100 os r268703 : SfxItemProperty set as pointer 2009-03-03 07:49:46 +0100 os r268702 : SfxItemProperty set as pointer 2009-03-02 08:15:37 +0100 os r268631 : minor fix 2009-03-02 07:58:38 +0100 os r268630 : minor fix 2009-02-27 13:03:25 +0100 os r268584 : exports 2009-02-27 11:17:04 +0100 os r268567 : debug code removed 2009-02-27 11:04:07 +0100 os r268565 : duplicate return removed 2009-02-27 10:17:37 +0100 os r268558 : syntax fixed 2009-02-27 09:56:14 +0100 os r268554 : #i99568# type mix fixed 2009-02-27 09:40:56 +0100 os r268553 : #i99568# exports changes reverted 2009-02-25 12:50:54 +0100 os r268433 : #i99568# SfxItemPropertySet rework 2009-02-25 12:13:39 +0100 os r268432 : #i99568# SfxItemPropertySet rework 2009-02-25 12:12:47 +0100 os r268431 : #i99568# SfxItemPropertySet rework 2009-02-25 12:10:27 +0100 os r268430 : #i99568# SfxItemPropertySet rework 2009-02-25 12:09:36 +0100 os r268429 : #i99568# SfxItemPropertySet rework 2009-02-25 12:07:39 +0100 os r268428 : #i99568# SfxItemPropertySet rework 2009-02-25 11:59:35 +0100 os r268427 : #i99568# SfxItemPropertySet rework 2009-02-25 11:52:52 +0100 os r268425 : #i99568# SfxItemPropertySet rework 2009-02-25 11:49:17 +0100 os r268424 : #i99568# SfxItemPropertySet rework 2009-02-25 11:45:17 +0100 os r268423 : #i99568# SfxItemPropertySet rework 2009-02-11 11:39:04 +0100 os r267587 : #i57008# use registration of index marks at SwUnoCallback
888 lines
29 KiB
C++
888 lines
29 KiB
C++
/*************************************************************************
|
|
*
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
*
|
|
* Copyright 2008 by Sun Microsystems, Inc.
|
|
*
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
|
*
|
|
* $RCSfile: unosrch.cxx,v $
|
|
* $Revision: 1.10 $
|
|
*
|
|
* This file is part of OpenOffice.org.
|
|
*
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
* only, as published by the Free Software Foundation.
|
|
*
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Lesser General Public License version 3 for more details
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
* <http://www.openoffice.org/license.html>
|
|
* for a copy of the LGPLv3 License.
|
|
*
|
|
************************************************************************/
|
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
#include "precompiled_sd.hxx"
|
|
#include <vcl/svapp.hxx>
|
|
#include <vos/mutex.hxx>
|
|
|
|
#ifndef SVX_UNOSHAPE_HXX
|
|
#include <svx/unoshape.hxx>
|
|
#endif
|
|
#include <svx/unoprov.hxx>
|
|
#include <svx/unotext.hxx>
|
|
|
|
#include <comphelper/extract.hxx>
|
|
#include <rtl/uuid.h>
|
|
#include <rtl/memory.h>
|
|
|
|
#include "unohelp.hxx"
|
|
#include "unoprnms.hxx"
|
|
#include "unosrch.hxx"
|
|
|
|
using namespace ::vos;
|
|
using namespace ::rtl;
|
|
using namespace ::com::sun::star;
|
|
|
|
#define WID_SEARCH_BACKWARDS 0
|
|
#define WID_SEARCH_CASE 1
|
|
#define WID_SEARCH_WORDS 2
|
|
|
|
const SfxItemPropertyMapEntry* ImplGetSearchPropertyMap()
|
|
{
|
|
static const SfxItemPropertyMapEntry aSearchPropertyMap_Impl[] =
|
|
{
|
|
{ MAP_CHAR_LEN(UNO_NAME_SEARCH_BACKWARDS), WID_SEARCH_BACKWARDS, &::getBooleanCppuType(), 0, 0 },
|
|
{ MAP_CHAR_LEN(UNO_NAME_SEARCH_CASE), WID_SEARCH_CASE, &::getBooleanCppuType(), 0, 0 },
|
|
{ MAP_CHAR_LEN(UNO_NAME_SEARCH_WORDS), WID_SEARCH_WORDS, &::getBooleanCppuType(), 0, 0 },
|
|
{ 0,0,0,0,0,0}
|
|
};
|
|
|
|
return aSearchPropertyMap_Impl;
|
|
}
|
|
|
|
class SearchContext_impl
|
|
{
|
|
uno::Reference< drawing::XShapes > mxShapes;
|
|
sal_Int32 mnIndex;
|
|
SearchContext_impl* mpParent;
|
|
|
|
public:
|
|
SearchContext_impl( uno::Reference< drawing::XShapes > xShapes, SearchContext_impl* pParent = NULL )
|
|
: mxShapes( xShapes ), mnIndex( -1 ), mpParent( pParent ) {}
|
|
|
|
|
|
uno::Reference< drawing::XShape > firstShape()
|
|
{
|
|
mnIndex = -1;
|
|
return nextShape();
|
|
}
|
|
|
|
uno::Reference< drawing::XShape > nextShape()
|
|
{
|
|
uno::Reference< drawing::XShape > xShape;
|
|
mnIndex++;
|
|
if( mxShapes.is() && mxShapes->getCount() > mnIndex )
|
|
{
|
|
mxShapes->getByIndex( mnIndex ) >>= xShape;
|
|
}
|
|
return xShape;
|
|
}
|
|
|
|
SearchContext_impl* getParent() const { return mpParent; }
|
|
};
|
|
|
|
/* ================================================================= */
|
|
/** this class implements a search or replace operation on a given
|
|
page or a given sdrobj
|
|
*/
|
|
|
|
SdUnoSearchReplaceShape::SdUnoSearchReplaceShape( drawing::XDrawPage* pPage ) throw()
|
|
{
|
|
mpPage = pPage;
|
|
}
|
|
|
|
SdUnoSearchReplaceShape::SdUnoSearchReplaceShape( drawing::XShape* pShape ) throw()
|
|
{
|
|
mpShape = pShape;
|
|
}
|
|
|
|
SdUnoSearchReplaceShape::~SdUnoSearchReplaceShape() throw()
|
|
{
|
|
}
|
|
|
|
// util::XReplaceable
|
|
uno::Reference< util::XReplaceDescriptor > SAL_CALL SdUnoSearchReplaceShape::createReplaceDescriptor()
|
|
throw( uno::RuntimeException )
|
|
{
|
|
return new SdUnoSearchReplaceDescriptor(sal_True);
|
|
}
|
|
|
|
sal_Int32 SAL_CALL SdUnoSearchReplaceShape::replaceAll( const uno::Reference< util::XSearchDescriptor >& xDesc )
|
|
throw( uno::RuntimeException )
|
|
{
|
|
SdUnoSearchReplaceDescriptor* pDescr = SdUnoSearchReplaceDescriptor::getImplementation( xDesc );
|
|
if( pDescr == NULL )
|
|
return 0;
|
|
|
|
sal_Int32 nFound = 0;
|
|
|
|
uno::Reference< drawing::XShapes > xShapes;
|
|
uno::Reference< drawing::XShape > xShape;
|
|
|
|
SearchContext_impl* pContext = NULL;
|
|
if(mpPage)
|
|
{
|
|
uno::Reference< drawing::XDrawPage > xPage( mpPage );
|
|
|
|
xPage->queryInterface( ITYPE( drawing::XShapes ) ) >>= xShapes;
|
|
|
|
if( xShapes.is() && (xShapes->getCount() > 0) )
|
|
{
|
|
pContext = new SearchContext_impl( xShapes );
|
|
xShape = pContext->firstShape();
|
|
}
|
|
else
|
|
{
|
|
xShapes = NULL;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
xShape = mpShape;
|
|
}
|
|
|
|
while( xShape.is() )
|
|
{
|
|
// replace in xShape
|
|
uno::Reference< text::XText > xText(xShape, uno::UNO_QUERY);
|
|
uno::Reference< text::XTextRange > xRange(xText, uno::UNO_QUERY);
|
|
uno::Reference< text::XTextRange > xFound;
|
|
|
|
while( xRange.is() )
|
|
{
|
|
xFound = Search( xRange, pDescr );
|
|
if( !xFound.is() )
|
|
break;
|
|
|
|
xFound->setString( pDescr->getReplaceString() );
|
|
xRange = xFound->getEnd();
|
|
nFound++;
|
|
}
|
|
// done with xShape -> get next shape
|
|
|
|
// test if its a group
|
|
uno::Reference< drawing::XShapes > xGroupShape( xShape, uno::UNO_QUERY );
|
|
if( xGroupShape.is() && ( xGroupShape->getCount() > 0 ) )
|
|
{
|
|
pContext = new SearchContext_impl( xGroupShape, pContext );
|
|
xShape = pContext->firstShape();
|
|
}
|
|
else
|
|
{
|
|
if( pContext )
|
|
xShape = pContext->nextShape();
|
|
else
|
|
xShape = NULL;
|
|
}
|
|
|
|
// test parent contexts for next shape if none
|
|
// is found in the current context
|
|
while( pContext && !xShape.is() )
|
|
{
|
|
if( pContext->getParent() )
|
|
{
|
|
SearchContext_impl* pOldContext = pContext;
|
|
pContext = pContext->getParent();
|
|
delete pOldContext;
|
|
xShape = pContext->nextShape();
|
|
}
|
|
else
|
|
{
|
|
delete pContext;
|
|
pContext = NULL;
|
|
xShape = NULL;
|
|
}
|
|
}
|
|
}
|
|
|
|
return nFound;
|
|
}
|
|
|
|
// XSearchable
|
|
uno::Reference< ::com::sun::star::util::XSearchDescriptor > SAL_CALL SdUnoSearchReplaceShape::createSearchDescriptor( )
|
|
throw(::com::sun::star::uno::RuntimeException)
|
|
{
|
|
return new SdUnoSearchReplaceDescriptor(sal_False);
|
|
}
|
|
|
|
uno::Reference< ::com::sun::star::container::XIndexAccess > SAL_CALL SdUnoSearchReplaceShape::findAll( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XSearchDescriptor >& xDesc )
|
|
throw(::com::sun::star::uno::RuntimeException)
|
|
{
|
|
SdUnoSearchReplaceDescriptor* pDescr = SdUnoSearchReplaceDescriptor::getImplementation( xDesc );
|
|
if( pDescr == NULL )
|
|
return uno::Reference< container::XIndexAccess > ();
|
|
|
|
|
|
sal_Int32 nSequence = 32;
|
|
sal_Int32 nFound = 0;
|
|
|
|
uno::Sequence < uno::Reference< uno::XInterface > > aSeq( nSequence );
|
|
|
|
uno::Reference< uno::XInterface > * pArray = aSeq.getArray();
|
|
|
|
uno::Reference< drawing::XShapes > xShapes;
|
|
uno::Reference< drawing::XShape > xShape;
|
|
|
|
SearchContext_impl* pContext = NULL;
|
|
if(mpPage)
|
|
{
|
|
uno::Reference< drawing::XDrawPage > xPage( mpPage );
|
|
xPage->queryInterface( ITYPE( drawing::XShapes ) ) >>= xShapes;
|
|
|
|
if( xShapes.is() && xShapes->getCount() > 0 )
|
|
{
|
|
pContext = new SearchContext_impl( xShapes );
|
|
xShape = pContext->firstShape();
|
|
}
|
|
else
|
|
{
|
|
xShapes = NULL;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
xShape = mpShape;
|
|
}
|
|
while( xShape.is() )
|
|
{
|
|
// find in xShape
|
|
uno::Reference< text::XText > xText(xShape, uno::UNO_QUERY);
|
|
uno::Reference< text::XTextRange > xRange(xText, uno::UNO_QUERY);
|
|
uno::Reference< text::XTextRange > xFound;
|
|
|
|
while( xRange.is() )
|
|
{
|
|
xFound = Search( xRange, pDescr );
|
|
if( !xFound.is() )
|
|
break;
|
|
|
|
if( nFound >= nSequence )
|
|
{
|
|
nSequence += 32;
|
|
aSeq.realloc( nSequence );
|
|
pArray = aSeq.getArray();
|
|
}
|
|
|
|
pArray[nFound++] = xFound;
|
|
|
|
xRange = xFound->getEnd();
|
|
}
|
|
// done with shape -> get next shape
|
|
|
|
// test if its a group
|
|
uno::Reference< drawing::XShapes > xGroupShape;
|
|
uno::Any aAny( xShape->queryInterface( ITYPE( drawing::XShapes )));
|
|
|
|
if( (aAny >>= xGroupShape ) && xGroupShape->getCount() > 0 )
|
|
{
|
|
pContext = new SearchContext_impl( xGroupShape, pContext );
|
|
xShape = pContext->firstShape();
|
|
}
|
|
else
|
|
{
|
|
if( pContext )
|
|
xShape = pContext->nextShape();
|
|
else
|
|
xShape = NULL;
|
|
}
|
|
|
|
// test parent contexts for next shape if none
|
|
// is found in the current context
|
|
while( pContext && !xShape.is() )
|
|
{
|
|
if( pContext->getParent() )
|
|
{
|
|
SearchContext_impl* pOldContext = pContext;
|
|
pContext = pContext->getParent();
|
|
delete pOldContext;
|
|
xShape = pContext->nextShape();
|
|
}
|
|
else
|
|
{
|
|
delete pContext;
|
|
pContext = NULL;
|
|
xShape = NULL;
|
|
}
|
|
}
|
|
}
|
|
|
|
if( nFound != nSequence )
|
|
aSeq.realloc( nFound );
|
|
|
|
return (container::XIndexAccess*)new SdUnoFindAllAccess( aSeq );
|
|
}
|
|
|
|
uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL SdUnoSearchReplaceShape::findFirst( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XSearchDescriptor >& xDesc )
|
|
throw(::com::sun::star::uno::RuntimeException)
|
|
{
|
|
uno::Reference< text::XTextRange > xRange( GetCurrentShape(), uno::UNO_QUERY );
|
|
if( xRange.is() )
|
|
return findNext( xRange, xDesc );
|
|
|
|
return uno::Reference< uno::XInterface > ();
|
|
}
|
|
|
|
uno::Reference< drawing::XShape > SdUnoSearchReplaceShape::GetCurrentShape() const throw()
|
|
{
|
|
uno::Reference< drawing::XShape > xShape;
|
|
|
|
if( mpPage )
|
|
{
|
|
uno::Reference< drawing::XDrawPage > xPage( mpPage );
|
|
uno::Reference< container::XIndexAccess > xShapes( xPage, uno::UNO_QUERY );
|
|
if( xShapes.is() )
|
|
{
|
|
if(xShapes->getCount() > 0)
|
|
{
|
|
xShapes->getByIndex(0) >>= xShape;
|
|
}
|
|
}
|
|
}
|
|
else if( mpShape )
|
|
{
|
|
xShape = mpShape;
|
|
}
|
|
|
|
return xShape;
|
|
|
|
}
|
|
|
|
uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL SdUnoSearchReplaceShape::findNext( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xStartAt, const ::com::sun::star::uno::Reference< ::com::sun::star::util::XSearchDescriptor >& xDesc )
|
|
throw(::com::sun::star::uno::RuntimeException)
|
|
{
|
|
SdUnoSearchReplaceDescriptor* pDescr = SdUnoSearchReplaceDescriptor::getImplementation( xDesc );
|
|
|
|
uno::Reference< uno::XInterface > xFound;
|
|
|
|
uno::Reference< text::XTextRange > xRange( xStartAt, uno::UNO_QUERY );
|
|
if(pDescr && xRange.is() )
|
|
{
|
|
|
|
uno::Reference< text::XTextRange > xCurrentRange( xStartAt, uno::UNO_QUERY );
|
|
|
|
uno::Reference< drawing::XShape > xCurrentShape( GetShape( xCurrentRange ) );
|
|
|
|
while(!xFound.is() && xRange.is())
|
|
{
|
|
xFound = Search( xRange, pDescr );
|
|
if(!xFound.is())
|
|
{
|
|
// we need a new starting range now
|
|
xRange = NULL;
|
|
|
|
if(mpPage)
|
|
{
|
|
uno::Reference< drawing::XDrawPage > xPage( mpPage );
|
|
|
|
// we do a page wide search, so skip to the next shape here
|
|
uno::Reference< container::XIndexAccess > xShapes( xPage, uno::UNO_QUERY );
|
|
|
|
// get next shape on our page
|
|
if( xShapes.is() )
|
|
{
|
|
uno::Reference< drawing::XShape > xFound2( GetNextShape( xShapes, xCurrentShape ) );
|
|
if( xFound2.is() && (xFound2.get() != xCurrentShape.get()) )
|
|
xCurrentShape = xFound2;
|
|
else
|
|
xCurrentShape = NULL;
|
|
|
|
xCurrentShape->queryInterface( ITYPE( text::XTextRange ) ) >>= xRange;
|
|
if(!(xCurrentShape.is() && (xRange.is())))
|
|
xRange = NULL;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// we search only in this shape, so end search if we have
|
|
// not found anything
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return xFound;
|
|
}
|
|
|
|
/** this method returns the shape that follows xCurrentShape in the shape collection xShapes.
|
|
It steps recursive into groupshapes and returns the xCurrentShape if it is the last
|
|
shape in this collection */
|
|
uno::Reference< drawing::XShape > SdUnoSearchReplaceShape::GetNextShape( uno::Reference< container::XIndexAccess > xShapes, uno::Reference< drawing::XShape > xCurrentShape ) throw()
|
|
{
|
|
uno::Reference< drawing::XShape > xFound;
|
|
uno::Any aAny;
|
|
|
|
if(xShapes.is() && xCurrentShape.is())
|
|
{
|
|
const sal_Int32 nCount = xShapes->getCount();
|
|
for( sal_Int32 i = 0; i < nCount; i++ )
|
|
{
|
|
uno::Reference< drawing::XShape > xSearchShape;
|
|
xShapes->getByIndex(i) >>= xSearchShape;
|
|
|
|
if( xSearchShape.is() )
|
|
{
|
|
uno::Reference< container::XIndexAccess > xGroup( xSearchShape, uno::UNO_QUERY );
|
|
|
|
if( xCurrentShape.get() == xSearchShape.get() )
|
|
{
|
|
if( xGroup.is() && xGroup->getCount() > 0 )
|
|
{
|
|
xGroup->getByIndex( 0 ) >>= xFound;
|
|
}
|
|
else
|
|
{
|
|
i++;
|
|
if( i < nCount )
|
|
xShapes->getByIndex( i ) >>= xFound;
|
|
else
|
|
xFound = xCurrentShape;
|
|
}
|
|
|
|
break;
|
|
}
|
|
else if( xGroup.is() )
|
|
{
|
|
xFound = GetNextShape( xGroup, xCurrentShape );
|
|
if( xFound.is() )
|
|
{
|
|
if( xFound.get() == xCurrentShape.get() )
|
|
{
|
|
// the current shape was found at the end of the group
|
|
i++;
|
|
if( i < nCount )
|
|
{
|
|
xShapes->getByIndex(i) >>= xFound;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return xFound;
|
|
}
|
|
|
|
uno::Reference< text::XTextRange > SdUnoSearchReplaceShape::Search( uno::Reference< text::XTextRange > xText, SdUnoSearchReplaceDescriptor* pDescr ) throw()
|
|
{
|
|
if(!xText.is())
|
|
return uno::Reference< text::XTextRange > ();
|
|
|
|
uno::Reference< text::XText > xParent( xText->getText() );
|
|
|
|
if( !xParent.is() )
|
|
{
|
|
uno::Any aAny( xText->queryInterface( ITYPE( text::XText )) );
|
|
aAny >>= xParent;
|
|
}
|
|
|
|
const OUString aText( xParent->getString() );
|
|
|
|
const sal_Int32 nTextLen = aText.getLength();
|
|
|
|
sal_Int32* pConvertPos = new sal_Int32[nTextLen+2];
|
|
sal_Int32* pConvertPara = new sal_Int32[nTextLen+2];
|
|
|
|
int ndbg = 0;
|
|
const sal_Unicode* pText = aText;
|
|
|
|
sal_Int32* pPos = pConvertPos;
|
|
sal_Int32* pPara = pConvertPara;
|
|
|
|
sal_Int32 nLastPos = 0, nLastPara = 0;
|
|
|
|
uno::Reference< container::XEnumerationAccess > xEnumAccess( xParent, uno::UNO_QUERY );
|
|
|
|
// first we fill the arrys with the position and paragraph for every character
|
|
// inside the text
|
|
if( xEnumAccess.is() )
|
|
{
|
|
uno::Reference< container::XEnumeration > xParaEnum( xEnumAccess->createEnumeration() );
|
|
|
|
while(xParaEnum->hasMoreElements())
|
|
{
|
|
uno::Reference< text::XTextContent > xParagraph( xParaEnum->nextElement(), uno::UNO_QUERY );
|
|
if( xParagraph.is() )
|
|
xEnumAccess.query( xParagraph );
|
|
else
|
|
xEnumAccess.clear();
|
|
|
|
if( xEnumAccess.is() )
|
|
{
|
|
uno::Reference< container::XEnumeration > xPortionEnum( xEnumAccess->createEnumeration() );
|
|
if( xPortionEnum.is() )
|
|
{
|
|
while(xPortionEnum->hasMoreElements())
|
|
{
|
|
uno::Reference< text::XTextRange > xPortion( xPortionEnum->nextElement(), uno::UNO_QUERY );
|
|
if( xPortion.is() )
|
|
{
|
|
const OUString aPortion( xPortion->getString() );
|
|
const sal_Int32 nLen = aPortion.getLength();
|
|
|
|
ESelection aStartSel( GetSelection( xPortion->getStart() ) );
|
|
ESelection aEndSel( GetSelection( xPortion->getEnd() ) );
|
|
|
|
// special case for empty portions with content or length one portions with content (fields)
|
|
if( (aStartSel.nStartPos == aEndSel.nStartPos) || ( (aStartSel.nStartPos == (aEndSel.nStartPos - 1)) && (nLen > 1) ) )
|
|
{
|
|
for( sal_Int32 i = 0; i < nLen; i++ )
|
|
{
|
|
if( ndbg < (nTextLen+2) )
|
|
{
|
|
*pPos++ = aStartSel.nStartPos;
|
|
*pPara++ = aStartSel.nStartPara;
|
|
|
|
ndbg += 1;
|
|
pText++;
|
|
}
|
|
else
|
|
{
|
|
DBG_ERROR( "array overflow while searching" );
|
|
}
|
|
}
|
|
|
|
nLastPos = aStartSel.nStartPos;
|
|
}
|
|
// normal case
|
|
else
|
|
{
|
|
for( sal_Int32 i = 0; i < nLen; i++ )
|
|
{
|
|
if( ndbg < (nTextLen+2) )
|
|
{
|
|
*pPos++ = aStartSel.nStartPos++;
|
|
*pPara++ = aStartSel.nStartPara;
|
|
|
|
ndbg += 1;
|
|
pText++;
|
|
}
|
|
else
|
|
{
|
|
DBG_ERROR( "array overflow while searching" );
|
|
}
|
|
}
|
|
|
|
nLastPos = aStartSel.nStartPos - 1;
|
|
DBG_ASSERT( aEndSel.nStartPos == aStartSel.nStartPos, "Search is not working" );
|
|
}
|
|
nLastPara = aStartSel.nStartPara;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if( ndbg < (nTextLen+2) )
|
|
{
|
|
*pPos++ = nLastPos + 1;
|
|
*pPara++ = nLastPara;
|
|
|
|
ndbg += 1;
|
|
pText++;
|
|
}
|
|
else
|
|
{
|
|
DBG_ERROR( "array overflow while searching" );
|
|
}
|
|
}
|
|
}
|
|
|
|
uno::Reference< text::XText > xFound;
|
|
ESelection aSel;
|
|
|
|
uno::Reference< text::XTextRange > xRangeRef( xText, uno::UNO_QUERY );
|
|
if( xRangeRef.is() )
|
|
aSel = GetSelection( xRangeRef );
|
|
|
|
sal_Int32 nStartPos;
|
|
sal_Int32 nEndPos = 0;
|
|
for( nStartPos = 0; nStartPos < nTextLen; nStartPos++ )
|
|
{
|
|
if( pConvertPara[nStartPos] == aSel.nStartPara && pConvertPos[nStartPos] == aSel.nStartPos )
|
|
break;
|
|
}
|
|
|
|
if( Search( aText, nStartPos, nEndPos, pDescr ) )
|
|
{
|
|
if( nStartPos <= nTextLen && nEndPos <= nTextLen )
|
|
{
|
|
ESelection aSelection( (USHORT)pConvertPara[nStartPos], (USHORT)pConvertPos[nStartPos],
|
|
(USHORT)pConvertPara[nEndPos], (USHORT)pConvertPos[nEndPos] );
|
|
SvxUnoTextRange *pRange;
|
|
|
|
SvxUnoTextBase* pParent = SvxUnoTextBase::getImplementation( xParent );
|
|
|
|
if(pParent)
|
|
{
|
|
pRange = new SvxUnoTextRange( *pParent );
|
|
xFound = (text::XText*)pRange;
|
|
pRange->SetSelection(aSelection);
|
|
|
|
// pDescr->SetStartPos( nEndPos );
|
|
}
|
|
}
|
|
else
|
|
{
|
|
DBG_ERROR("Array overflow while searching!");
|
|
}
|
|
}
|
|
|
|
delete[] pConvertPos;
|
|
delete[] pConvertPara;
|
|
|
|
return uno::Reference< text::XTextRange > ( xFound, uno::UNO_QUERY );
|
|
}
|
|
|
|
sal_Bool SdUnoSearchReplaceShape::Search( const OUString& rText, sal_Int32& nStartPos, sal_Int32& nEndPos, SdUnoSearchReplaceDescriptor* pDescr ) throw()
|
|
{
|
|
OUString aSearchStr( pDescr->getSearchString() );
|
|
OUString aText( rText );
|
|
|
|
if( !pDescr->IsCaseSensitive() )
|
|
{
|
|
aText.toAsciiLowerCase();
|
|
aSearchStr.toAsciiLowerCase();
|
|
}
|
|
|
|
sal_Int32 nFound = aText.indexOf( aSearchStr, nStartPos );
|
|
if( nFound != -1 )
|
|
{
|
|
nStartPos = nFound;
|
|
nEndPos = nFound + aSearchStr.getLength();
|
|
|
|
if(pDescr->IsWords())
|
|
{
|
|
if( (nStartPos > 0 && aText.getStr()[nStartPos-1] > ' ') ||
|
|
(nEndPos < aText.getLength() && aText.getStr()[nEndPos] > ' ') )
|
|
{
|
|
nStartPos++;
|
|
return Search( aText, nStartPos, nEndPos, pDescr );
|
|
}
|
|
}
|
|
|
|
return sal_True;
|
|
}
|
|
else
|
|
return sal_False;
|
|
}
|
|
|
|
ESelection SdUnoSearchReplaceShape::GetSelection( uno::Reference< text::XTextRange > xTextRange ) throw()
|
|
{
|
|
ESelection aSel;
|
|
SvxUnoTextRangeBase* pRange = SvxUnoTextRangeBase::getImplementation( xTextRange );
|
|
|
|
if(pRange)
|
|
aSel = pRange->GetSelection();
|
|
|
|
return aSel;
|
|
}
|
|
|
|
uno::Reference< drawing::XShape > SdUnoSearchReplaceShape::GetShape( uno::Reference< text::XTextRange > xTextRange ) throw()
|
|
{
|
|
uno::Reference< drawing::XShape > xShape;
|
|
|
|
if(xTextRange.is())
|
|
{
|
|
uno::Reference< text::XText > xText( xTextRange->getText() );
|
|
|
|
if(xText.is())
|
|
{
|
|
do
|
|
{
|
|
xText->queryInterface( ITYPE( drawing::XShape )) >>= xShape;
|
|
if(!xShape.is())
|
|
{
|
|
uno::Reference< text::XText > xParent( xText->getText() );
|
|
if(!xParent.is() || xText.get() == xParent.get())
|
|
return xShape;
|
|
|
|
xText = xParent;
|
|
}
|
|
} while( !xShape.is() );
|
|
}
|
|
}
|
|
|
|
return xShape;
|
|
}
|
|
|
|
/* ================================================================= */
|
|
/** this class holds the parameters and status of a search or replace
|
|
operation performed by class SdUnoSearchReplaceShape
|
|
*/
|
|
|
|
UNO3_GETIMPLEMENTATION_IMPL( SdUnoSearchReplaceDescriptor );
|
|
|
|
SdUnoSearchReplaceDescriptor::SdUnoSearchReplaceDescriptor( sal_Bool bReplace ) throw()
|
|
{
|
|
mpPropSet = new SvxItemPropertySet(ImplGetSearchPropertyMap());
|
|
|
|
mbBackwards = sal_False;
|
|
mbCaseSensitive = sal_False;
|
|
mbWords = sal_False;
|
|
|
|
mbReplace = bReplace;
|
|
}
|
|
|
|
SdUnoSearchReplaceDescriptor::~SdUnoSearchReplaceDescriptor() throw()
|
|
{
|
|
delete mpPropSet;
|
|
}
|
|
|
|
// XSearchDescriptor
|
|
OUString SAL_CALL SdUnoSearchReplaceDescriptor::getSearchString()
|
|
throw(::com::sun::star::uno::RuntimeException)
|
|
{
|
|
return maSearchStr;
|
|
}
|
|
|
|
void SAL_CALL SdUnoSearchReplaceDescriptor::setSearchString( const OUString& aString )
|
|
throw(::com::sun::star::uno::RuntimeException)
|
|
{
|
|
maSearchStr = aString;
|
|
}
|
|
|
|
// XReplaceDescriptor
|
|
OUString SAL_CALL SdUnoSearchReplaceDescriptor::getReplaceString()
|
|
throw(::com::sun::star::uno::RuntimeException)
|
|
{
|
|
return maReplaceStr;
|
|
}
|
|
|
|
void SAL_CALL SdUnoSearchReplaceDescriptor::setReplaceString( const ::rtl::OUString& aReplaceString )
|
|
throw(::com::sun::star::uno::RuntimeException)
|
|
{
|
|
maReplaceStr = aReplaceString;
|
|
}
|
|
|
|
// XPropertySet
|
|
uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL SdUnoSearchReplaceDescriptor::getPropertySetInfo()
|
|
throw(::com::sun::star::uno::RuntimeException)
|
|
{
|
|
OGuard aGuard( Application::GetSolarMutex() );
|
|
return mpPropSet->getPropertySetInfo();
|
|
}
|
|
|
|
void SAL_CALL SdUnoSearchReplaceDescriptor::setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue )
|
|
throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
|
|
{
|
|
OGuard aGuard( Application::GetSolarMutex() );
|
|
|
|
const SfxItemPropertySimpleEntry* pEntry = mpPropSet->getPropertyMapEntry(aPropertyName);
|
|
|
|
sal_Bool bOk = sal_False;
|
|
|
|
switch( pEntry ? pEntry->nWID : -1 )
|
|
{
|
|
case WID_SEARCH_BACKWARDS:
|
|
bOk = (aValue >>= mbBackwards);
|
|
break;
|
|
case WID_SEARCH_CASE:
|
|
bOk = (aValue >>= mbCaseSensitive);
|
|
break;
|
|
case WID_SEARCH_WORDS:
|
|
bOk = (aValue >>= mbWords);
|
|
break;
|
|
default:
|
|
throw beans::UnknownPropertyException();
|
|
}
|
|
|
|
if( !bOk )
|
|
throw lang::IllegalArgumentException();
|
|
}
|
|
|
|
uno::Any SAL_CALL SdUnoSearchReplaceDescriptor::getPropertyValue( const ::rtl::OUString& PropertyName )
|
|
throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
|
|
{
|
|
OGuard aGuard( Application::GetSolarMutex() );
|
|
|
|
uno::Any aAny;
|
|
|
|
const SfxItemPropertySimpleEntry* pEntry = mpPropSet->getPropertyMapEntry(PropertyName);
|
|
|
|
switch( pEntry ? pEntry->nWID : -1 )
|
|
{
|
|
case WID_SEARCH_BACKWARDS:
|
|
aAny <<= (sal_Bool)mbBackwards;
|
|
break;
|
|
case WID_SEARCH_CASE:
|
|
aAny <<= (sal_Bool)mbCaseSensitive;
|
|
break;
|
|
case WID_SEARCH_WORDS:
|
|
aAny <<= (sal_Bool)mbWords;
|
|
break;
|
|
default:
|
|
throw beans::UnknownPropertyException();
|
|
}
|
|
|
|
return aAny;
|
|
}
|
|
|
|
void SAL_CALL SdUnoSearchReplaceDescriptor::addPropertyChangeListener( const ::rtl::OUString& , const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) {}
|
|
void SAL_CALL SdUnoSearchReplaceDescriptor::removePropertyChangeListener( const ::rtl::OUString& , const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) {}
|
|
void SAL_CALL SdUnoSearchReplaceDescriptor::addVetoableChangeListener( const ::rtl::OUString& , const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) {}
|
|
void SAL_CALL SdUnoSearchReplaceDescriptor::removeVetoableChangeListener( const ::rtl::OUString& , const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) {}
|
|
|
|
|
|
/* ================================================================= */
|
|
|
|
SdUnoFindAllAccess::SdUnoFindAllAccess( uno::Sequence< uno::Reference< uno::XInterface > >& rSequence ) throw()
|
|
:maSequence( rSequence )
|
|
{
|
|
}
|
|
|
|
SdUnoFindAllAccess::~SdUnoFindAllAccess() throw()
|
|
{
|
|
}
|
|
|
|
// XElementAccess
|
|
uno::Type SAL_CALL SdUnoFindAllAccess::getElementType()
|
|
throw(::com::sun::star::uno::RuntimeException)
|
|
{
|
|
return ITYPE( text::XTextRange );
|
|
}
|
|
|
|
sal_Bool SAL_CALL SdUnoFindAllAccess::hasElements()
|
|
throw(::com::sun::star::uno::RuntimeException)
|
|
{
|
|
return maSequence.getLength() > 0;
|
|
}
|
|
|
|
// XIndexAccess
|
|
sal_Int32 SAL_CALL SdUnoFindAllAccess::getCount()
|
|
throw(::com::sun::star::uno::RuntimeException)
|
|
{
|
|
return maSequence.getLength();
|
|
}
|
|
|
|
uno::Any SAL_CALL SdUnoFindAllAccess::getByIndex( sal_Int32 Index )
|
|
throw(::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
|
|
{
|
|
uno::Any aAny;
|
|
|
|
if( Index < 0 || Index >= getCount() )
|
|
throw lang::IndexOutOfBoundsException();
|
|
|
|
const uno::Reference< uno::XInterface > *pRefs = maSequence.getConstArray();
|
|
if(pRefs)
|
|
aAny <<= pRefs[ Index ];
|
|
return aAny;
|
|
}
|
|
|