1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sd.hxx" 30*cdf0e10cSrcweir #include <vcl/svapp.hxx> 31*cdf0e10cSrcweir #include <vos/mutex.hxx> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <svx/unoshape.hxx> 34*cdf0e10cSrcweir #include <svx/svdpool.hxx> 35*cdf0e10cSrcweir #include <svx/unoprov.hxx> 36*cdf0e10cSrcweir #include <editeng/unotext.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #include <comphelper/extract.hxx> 39*cdf0e10cSrcweir #include <rtl/uuid.h> 40*cdf0e10cSrcweir #include <rtl/memory.h> 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir #include "unohelp.hxx" 43*cdf0e10cSrcweir #include "unoprnms.hxx" 44*cdf0e10cSrcweir #include "unosrch.hxx" 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir using namespace ::vos; 47*cdf0e10cSrcweir using namespace ::rtl; 48*cdf0e10cSrcweir using namespace ::com::sun::star; 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir #define WID_SEARCH_BACKWARDS 0 51*cdf0e10cSrcweir #define WID_SEARCH_CASE 1 52*cdf0e10cSrcweir #define WID_SEARCH_WORDS 2 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir const SfxItemPropertyMapEntry* ImplGetSearchPropertyMap() 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir static const SfxItemPropertyMapEntry aSearchPropertyMap_Impl[] = 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir { MAP_CHAR_LEN(UNO_NAME_SEARCH_BACKWARDS), WID_SEARCH_BACKWARDS, &::getBooleanCppuType(), 0, 0 }, 59*cdf0e10cSrcweir { MAP_CHAR_LEN(UNO_NAME_SEARCH_CASE), WID_SEARCH_CASE, &::getBooleanCppuType(), 0, 0 }, 60*cdf0e10cSrcweir { MAP_CHAR_LEN(UNO_NAME_SEARCH_WORDS), WID_SEARCH_WORDS, &::getBooleanCppuType(), 0, 0 }, 61*cdf0e10cSrcweir { 0,0,0,0,0,0} 62*cdf0e10cSrcweir }; 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir return aSearchPropertyMap_Impl; 65*cdf0e10cSrcweir } 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir class SearchContext_impl 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir uno::Reference< drawing::XShapes > mxShapes; 70*cdf0e10cSrcweir sal_Int32 mnIndex; 71*cdf0e10cSrcweir SearchContext_impl* mpParent; 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir public: 74*cdf0e10cSrcweir SearchContext_impl( uno::Reference< drawing::XShapes > xShapes, SearchContext_impl* pParent = NULL ) 75*cdf0e10cSrcweir : mxShapes( xShapes ), mnIndex( -1 ), mpParent( pParent ) {} 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir uno::Reference< drawing::XShape > firstShape() 79*cdf0e10cSrcweir { 80*cdf0e10cSrcweir mnIndex = -1; 81*cdf0e10cSrcweir return nextShape(); 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir uno::Reference< drawing::XShape > nextShape() 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir uno::Reference< drawing::XShape > xShape; 87*cdf0e10cSrcweir mnIndex++; 88*cdf0e10cSrcweir if( mxShapes.is() && mxShapes->getCount() > mnIndex ) 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir mxShapes->getByIndex( mnIndex ) >>= xShape; 91*cdf0e10cSrcweir } 92*cdf0e10cSrcweir return xShape; 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir SearchContext_impl* getParent() const { return mpParent; } 96*cdf0e10cSrcweir }; 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir /* ================================================================= */ 99*cdf0e10cSrcweir /** this class implements a search or replace operation on a given 100*cdf0e10cSrcweir page or a given sdrobj 101*cdf0e10cSrcweir */ 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir SdUnoSearchReplaceShape::SdUnoSearchReplaceShape( drawing::XDrawPage* pPage ) throw() 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir mpPage = pPage; 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir SdUnoSearchReplaceShape::~SdUnoSearchReplaceShape() throw() 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir // util::XReplaceable 113*cdf0e10cSrcweir uno::Reference< util::XReplaceDescriptor > SAL_CALL SdUnoSearchReplaceShape::createReplaceDescriptor() 114*cdf0e10cSrcweir throw( uno::RuntimeException ) 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir return new SdUnoSearchReplaceDescriptor(sal_True); 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir sal_Int32 SAL_CALL SdUnoSearchReplaceShape::replaceAll( const uno::Reference< util::XSearchDescriptor >& xDesc ) 120*cdf0e10cSrcweir throw( uno::RuntimeException ) 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir SdUnoSearchReplaceDescriptor* pDescr = SdUnoSearchReplaceDescriptor::getImplementation( xDesc ); 123*cdf0e10cSrcweir if( pDescr == NULL ) 124*cdf0e10cSrcweir return 0; 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir sal_Int32 nFound = 0; 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir uno::Reference< drawing::XShapes > xShapes; 129*cdf0e10cSrcweir uno::Reference< drawing::XShape > xShape; 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir SearchContext_impl* pContext = NULL; 132*cdf0e10cSrcweir if(mpPage) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir uno::Reference< drawing::XDrawPage > xPage( mpPage ); 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir xPage->queryInterface( ITYPE( drawing::XShapes ) ) >>= xShapes; 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir if( xShapes.is() && (xShapes->getCount() > 0) ) 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir pContext = new SearchContext_impl( xShapes ); 141*cdf0e10cSrcweir xShape = pContext->firstShape(); 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir else 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir xShapes = NULL; 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir else 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir xShape = mpShape; 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir while( xShape.is() ) 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir // replace in xShape 156*cdf0e10cSrcweir uno::Reference< text::XText > xText(xShape, uno::UNO_QUERY); 157*cdf0e10cSrcweir uno::Reference< text::XTextRange > xRange(xText, uno::UNO_QUERY); 158*cdf0e10cSrcweir uno::Reference< text::XTextRange > xFound; 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir while( xRange.is() ) 161*cdf0e10cSrcweir { 162*cdf0e10cSrcweir xFound = Search( xRange, pDescr ); 163*cdf0e10cSrcweir if( !xFound.is() ) 164*cdf0e10cSrcweir break; 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir xFound->setString( pDescr->getReplaceString() ); 167*cdf0e10cSrcweir xRange = xFound->getEnd(); 168*cdf0e10cSrcweir nFound++; 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir // done with xShape -> get next shape 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir // test if its a group 173*cdf0e10cSrcweir uno::Reference< drawing::XShapes > xGroupShape( xShape, uno::UNO_QUERY ); 174*cdf0e10cSrcweir if( xGroupShape.is() && ( xGroupShape->getCount() > 0 ) ) 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir pContext = new SearchContext_impl( xGroupShape, pContext ); 177*cdf0e10cSrcweir xShape = pContext->firstShape(); 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir else 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir if( pContext ) 182*cdf0e10cSrcweir xShape = pContext->nextShape(); 183*cdf0e10cSrcweir else 184*cdf0e10cSrcweir xShape = NULL; 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir // test parent contexts for next shape if none 188*cdf0e10cSrcweir // is found in the current context 189*cdf0e10cSrcweir while( pContext && !xShape.is() ) 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir if( pContext->getParent() ) 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir SearchContext_impl* pOldContext = pContext; 194*cdf0e10cSrcweir pContext = pContext->getParent(); 195*cdf0e10cSrcweir delete pOldContext; 196*cdf0e10cSrcweir xShape = pContext->nextShape(); 197*cdf0e10cSrcweir } 198*cdf0e10cSrcweir else 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir delete pContext; 201*cdf0e10cSrcweir pContext = NULL; 202*cdf0e10cSrcweir xShape = NULL; 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir } 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir return nFound; 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir // XSearchable 211*cdf0e10cSrcweir uno::Reference< ::com::sun::star::util::XSearchDescriptor > SAL_CALL SdUnoSearchReplaceShape::createSearchDescriptor( ) 212*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 213*cdf0e10cSrcweir { 214*cdf0e10cSrcweir return new SdUnoSearchReplaceDescriptor(sal_False); 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir uno::Reference< ::com::sun::star::container::XIndexAccess > SAL_CALL SdUnoSearchReplaceShape::findAll( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XSearchDescriptor >& xDesc ) 218*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir SdUnoSearchReplaceDescriptor* pDescr = SdUnoSearchReplaceDescriptor::getImplementation( xDesc ); 221*cdf0e10cSrcweir if( pDescr == NULL ) 222*cdf0e10cSrcweir return uno::Reference< container::XIndexAccess > (); 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir sal_Int32 nSequence = 32; 226*cdf0e10cSrcweir sal_Int32 nFound = 0; 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir uno::Sequence < uno::Reference< uno::XInterface > > aSeq( nSequence ); 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir uno::Reference< uno::XInterface > * pArray = aSeq.getArray(); 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir uno::Reference< drawing::XShapes > xShapes; 233*cdf0e10cSrcweir uno::Reference< drawing::XShape > xShape; 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir SearchContext_impl* pContext = NULL; 236*cdf0e10cSrcweir if(mpPage) 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir uno::Reference< drawing::XDrawPage > xPage( mpPage ); 239*cdf0e10cSrcweir xPage->queryInterface( ITYPE( drawing::XShapes ) ) >>= xShapes; 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir if( xShapes.is() && xShapes->getCount() > 0 ) 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir pContext = new SearchContext_impl( xShapes ); 244*cdf0e10cSrcweir xShape = pContext->firstShape(); 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir else 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir xShapes = NULL; 249*cdf0e10cSrcweir } 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir else 252*cdf0e10cSrcweir { 253*cdf0e10cSrcweir xShape = mpShape; 254*cdf0e10cSrcweir } 255*cdf0e10cSrcweir while( xShape.is() ) 256*cdf0e10cSrcweir { 257*cdf0e10cSrcweir // find in xShape 258*cdf0e10cSrcweir uno::Reference< text::XText > xText(xShape, uno::UNO_QUERY); 259*cdf0e10cSrcweir uno::Reference< text::XTextRange > xRange(xText, uno::UNO_QUERY); 260*cdf0e10cSrcweir uno::Reference< text::XTextRange > xFound; 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir while( xRange.is() ) 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir xFound = Search( xRange, pDescr ); 265*cdf0e10cSrcweir if( !xFound.is() ) 266*cdf0e10cSrcweir break; 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir if( nFound >= nSequence ) 269*cdf0e10cSrcweir { 270*cdf0e10cSrcweir nSequence += 32; 271*cdf0e10cSrcweir aSeq.realloc( nSequence ); 272*cdf0e10cSrcweir pArray = aSeq.getArray(); 273*cdf0e10cSrcweir } 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir pArray[nFound++] = xFound; 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir xRange = xFound->getEnd(); 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir // done with shape -> get next shape 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir // test if its a group 282*cdf0e10cSrcweir uno::Reference< drawing::XShapes > xGroupShape; 283*cdf0e10cSrcweir uno::Any aAny( xShape->queryInterface( ITYPE( drawing::XShapes ))); 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir if( (aAny >>= xGroupShape ) && xGroupShape->getCount() > 0 ) 286*cdf0e10cSrcweir { 287*cdf0e10cSrcweir pContext = new SearchContext_impl( xGroupShape, pContext ); 288*cdf0e10cSrcweir xShape = pContext->firstShape(); 289*cdf0e10cSrcweir } 290*cdf0e10cSrcweir else 291*cdf0e10cSrcweir { 292*cdf0e10cSrcweir if( pContext ) 293*cdf0e10cSrcweir xShape = pContext->nextShape(); 294*cdf0e10cSrcweir else 295*cdf0e10cSrcweir xShape = NULL; 296*cdf0e10cSrcweir } 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir // test parent contexts for next shape if none 299*cdf0e10cSrcweir // is found in the current context 300*cdf0e10cSrcweir while( pContext && !xShape.is() ) 301*cdf0e10cSrcweir { 302*cdf0e10cSrcweir if( pContext->getParent() ) 303*cdf0e10cSrcweir { 304*cdf0e10cSrcweir SearchContext_impl* pOldContext = pContext; 305*cdf0e10cSrcweir pContext = pContext->getParent(); 306*cdf0e10cSrcweir delete pOldContext; 307*cdf0e10cSrcweir xShape = pContext->nextShape(); 308*cdf0e10cSrcweir } 309*cdf0e10cSrcweir else 310*cdf0e10cSrcweir { 311*cdf0e10cSrcweir delete pContext; 312*cdf0e10cSrcweir pContext = NULL; 313*cdf0e10cSrcweir xShape = NULL; 314*cdf0e10cSrcweir } 315*cdf0e10cSrcweir } 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir if( nFound != nSequence ) 319*cdf0e10cSrcweir aSeq.realloc( nFound ); 320*cdf0e10cSrcweir 321*cdf0e10cSrcweir return (container::XIndexAccess*)new SdUnoFindAllAccess( aSeq ); 322*cdf0e10cSrcweir } 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL SdUnoSearchReplaceShape::findFirst( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XSearchDescriptor >& xDesc ) 325*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 326*cdf0e10cSrcweir { 327*cdf0e10cSrcweir uno::Reference< text::XTextRange > xRange( GetCurrentShape(), uno::UNO_QUERY ); 328*cdf0e10cSrcweir if( xRange.is() ) 329*cdf0e10cSrcweir return findNext( xRange, xDesc ); 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir return uno::Reference< uno::XInterface > (); 332*cdf0e10cSrcweir } 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir uno::Reference< drawing::XShape > SdUnoSearchReplaceShape::GetCurrentShape() const throw() 335*cdf0e10cSrcweir { 336*cdf0e10cSrcweir uno::Reference< drawing::XShape > xShape; 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir if( mpPage ) 339*cdf0e10cSrcweir { 340*cdf0e10cSrcweir uno::Reference< drawing::XDrawPage > xPage( mpPage ); 341*cdf0e10cSrcweir uno::Reference< container::XIndexAccess > xShapes( xPage, uno::UNO_QUERY ); 342*cdf0e10cSrcweir if( xShapes.is() ) 343*cdf0e10cSrcweir { 344*cdf0e10cSrcweir if(xShapes->getCount() > 0) 345*cdf0e10cSrcweir { 346*cdf0e10cSrcweir xShapes->getByIndex(0) >>= xShape; 347*cdf0e10cSrcweir } 348*cdf0e10cSrcweir } 349*cdf0e10cSrcweir } 350*cdf0e10cSrcweir else if( mpShape ) 351*cdf0e10cSrcweir { 352*cdf0e10cSrcweir xShape = mpShape; 353*cdf0e10cSrcweir } 354*cdf0e10cSrcweir 355*cdf0e10cSrcweir return xShape; 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir } 358*cdf0e10cSrcweir 359*cdf0e10cSrcweir 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 ) 360*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 361*cdf0e10cSrcweir { 362*cdf0e10cSrcweir SdUnoSearchReplaceDescriptor* pDescr = SdUnoSearchReplaceDescriptor::getImplementation( xDesc ); 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir uno::Reference< uno::XInterface > xFound; 365*cdf0e10cSrcweir 366*cdf0e10cSrcweir uno::Reference< text::XTextRange > xRange( xStartAt, uno::UNO_QUERY ); 367*cdf0e10cSrcweir if(pDescr && xRange.is() ) 368*cdf0e10cSrcweir { 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir uno::Reference< text::XTextRange > xCurrentRange( xStartAt, uno::UNO_QUERY ); 371*cdf0e10cSrcweir 372*cdf0e10cSrcweir uno::Reference< drawing::XShape > xCurrentShape( GetShape( xCurrentRange ) ); 373*cdf0e10cSrcweir 374*cdf0e10cSrcweir while(!xFound.is() && xRange.is()) 375*cdf0e10cSrcweir { 376*cdf0e10cSrcweir xFound = Search( xRange, pDescr ); 377*cdf0e10cSrcweir if(!xFound.is()) 378*cdf0e10cSrcweir { 379*cdf0e10cSrcweir // we need a new starting range now 380*cdf0e10cSrcweir xRange = NULL; 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir if(mpPage) 383*cdf0e10cSrcweir { 384*cdf0e10cSrcweir uno::Reference< drawing::XDrawPage > xPage( mpPage ); 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir // we do a page wide search, so skip to the next shape here 387*cdf0e10cSrcweir uno::Reference< container::XIndexAccess > xShapes( xPage, uno::UNO_QUERY ); 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir // get next shape on our page 390*cdf0e10cSrcweir if( xShapes.is() ) 391*cdf0e10cSrcweir { 392*cdf0e10cSrcweir uno::Reference< drawing::XShape > xFound2( GetNextShape( xShapes, xCurrentShape ) ); 393*cdf0e10cSrcweir if( xFound2.is() && (xFound2.get() != xCurrentShape.get()) ) 394*cdf0e10cSrcweir xCurrentShape = xFound2; 395*cdf0e10cSrcweir else 396*cdf0e10cSrcweir xCurrentShape = NULL; 397*cdf0e10cSrcweir 398*cdf0e10cSrcweir xCurrentShape->queryInterface( ITYPE( text::XTextRange ) ) >>= xRange; 399*cdf0e10cSrcweir if(!(xCurrentShape.is() && (xRange.is()))) 400*cdf0e10cSrcweir xRange = NULL; 401*cdf0e10cSrcweir } 402*cdf0e10cSrcweir } 403*cdf0e10cSrcweir else 404*cdf0e10cSrcweir { 405*cdf0e10cSrcweir // we search only in this shape, so end search if we have 406*cdf0e10cSrcweir // not found anything 407*cdf0e10cSrcweir } 408*cdf0e10cSrcweir } 409*cdf0e10cSrcweir } 410*cdf0e10cSrcweir } 411*cdf0e10cSrcweir return xFound; 412*cdf0e10cSrcweir } 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir /** this method returns the shape that follows xCurrentShape in the shape collection xShapes. 415*cdf0e10cSrcweir It steps recursive into groupshapes and returns the xCurrentShape if it is the last 416*cdf0e10cSrcweir shape in this collection */ 417*cdf0e10cSrcweir uno::Reference< drawing::XShape > SdUnoSearchReplaceShape::GetNextShape( uno::Reference< container::XIndexAccess > xShapes, uno::Reference< drawing::XShape > xCurrentShape ) throw() 418*cdf0e10cSrcweir { 419*cdf0e10cSrcweir uno::Reference< drawing::XShape > xFound; 420*cdf0e10cSrcweir uno::Any aAny; 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir if(xShapes.is() && xCurrentShape.is()) 423*cdf0e10cSrcweir { 424*cdf0e10cSrcweir const sal_Int32 nCount = xShapes->getCount(); 425*cdf0e10cSrcweir for( sal_Int32 i = 0; i < nCount; i++ ) 426*cdf0e10cSrcweir { 427*cdf0e10cSrcweir uno::Reference< drawing::XShape > xSearchShape; 428*cdf0e10cSrcweir xShapes->getByIndex(i) >>= xSearchShape; 429*cdf0e10cSrcweir 430*cdf0e10cSrcweir if( xSearchShape.is() ) 431*cdf0e10cSrcweir { 432*cdf0e10cSrcweir uno::Reference< container::XIndexAccess > xGroup( xSearchShape, uno::UNO_QUERY ); 433*cdf0e10cSrcweir 434*cdf0e10cSrcweir if( xCurrentShape.get() == xSearchShape.get() ) 435*cdf0e10cSrcweir { 436*cdf0e10cSrcweir if( xGroup.is() && xGroup->getCount() > 0 ) 437*cdf0e10cSrcweir { 438*cdf0e10cSrcweir xGroup->getByIndex( 0 ) >>= xFound; 439*cdf0e10cSrcweir } 440*cdf0e10cSrcweir else 441*cdf0e10cSrcweir { 442*cdf0e10cSrcweir i++; 443*cdf0e10cSrcweir if( i < nCount ) 444*cdf0e10cSrcweir xShapes->getByIndex( i ) >>= xFound; 445*cdf0e10cSrcweir else 446*cdf0e10cSrcweir xFound = xCurrentShape; 447*cdf0e10cSrcweir } 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir break; 450*cdf0e10cSrcweir } 451*cdf0e10cSrcweir else if( xGroup.is() ) 452*cdf0e10cSrcweir { 453*cdf0e10cSrcweir xFound = GetNextShape( xGroup, xCurrentShape ); 454*cdf0e10cSrcweir if( xFound.is() ) 455*cdf0e10cSrcweir { 456*cdf0e10cSrcweir if( xFound.get() == xCurrentShape.get() ) 457*cdf0e10cSrcweir { 458*cdf0e10cSrcweir // the current shape was found at the end of the group 459*cdf0e10cSrcweir i++; 460*cdf0e10cSrcweir if( i < nCount ) 461*cdf0e10cSrcweir { 462*cdf0e10cSrcweir xShapes->getByIndex(i) >>= xFound; 463*cdf0e10cSrcweir } 464*cdf0e10cSrcweir } 465*cdf0e10cSrcweir break; 466*cdf0e10cSrcweir } 467*cdf0e10cSrcweir } 468*cdf0e10cSrcweir } 469*cdf0e10cSrcweir } 470*cdf0e10cSrcweir } 471*cdf0e10cSrcweir 472*cdf0e10cSrcweir return xFound; 473*cdf0e10cSrcweir } 474*cdf0e10cSrcweir 475*cdf0e10cSrcweir uno::Reference< text::XTextRange > SdUnoSearchReplaceShape::Search( uno::Reference< text::XTextRange > xText, SdUnoSearchReplaceDescriptor* pDescr ) throw() 476*cdf0e10cSrcweir { 477*cdf0e10cSrcweir if(!xText.is()) 478*cdf0e10cSrcweir return uno::Reference< text::XTextRange > (); 479*cdf0e10cSrcweir 480*cdf0e10cSrcweir uno::Reference< text::XText > xParent( xText->getText() ); 481*cdf0e10cSrcweir 482*cdf0e10cSrcweir if( !xParent.is() ) 483*cdf0e10cSrcweir { 484*cdf0e10cSrcweir uno::Any aAny( xText->queryInterface( ITYPE( text::XText )) ); 485*cdf0e10cSrcweir aAny >>= xParent; 486*cdf0e10cSrcweir } 487*cdf0e10cSrcweir 488*cdf0e10cSrcweir const OUString aText( xParent->getString() ); 489*cdf0e10cSrcweir 490*cdf0e10cSrcweir const sal_Int32 nTextLen = aText.getLength(); 491*cdf0e10cSrcweir 492*cdf0e10cSrcweir sal_Int32* pConvertPos = new sal_Int32[nTextLen+2]; 493*cdf0e10cSrcweir sal_Int32* pConvertPara = new sal_Int32[nTextLen+2]; 494*cdf0e10cSrcweir 495*cdf0e10cSrcweir int ndbg = 0; 496*cdf0e10cSrcweir const sal_Unicode* pText = aText; 497*cdf0e10cSrcweir 498*cdf0e10cSrcweir sal_Int32* pPos = pConvertPos; 499*cdf0e10cSrcweir sal_Int32* pPara = pConvertPara; 500*cdf0e10cSrcweir 501*cdf0e10cSrcweir sal_Int32 nLastPos = 0, nLastPara = 0; 502*cdf0e10cSrcweir 503*cdf0e10cSrcweir uno::Reference< container::XEnumerationAccess > xEnumAccess( xParent, uno::UNO_QUERY ); 504*cdf0e10cSrcweir 505*cdf0e10cSrcweir // first we fill the arrys with the position and paragraph for every character 506*cdf0e10cSrcweir // inside the text 507*cdf0e10cSrcweir if( xEnumAccess.is() ) 508*cdf0e10cSrcweir { 509*cdf0e10cSrcweir uno::Reference< container::XEnumeration > xParaEnum( xEnumAccess->createEnumeration() ); 510*cdf0e10cSrcweir 511*cdf0e10cSrcweir while(xParaEnum->hasMoreElements()) 512*cdf0e10cSrcweir { 513*cdf0e10cSrcweir uno::Reference< text::XTextContent > xParagraph( xParaEnum->nextElement(), uno::UNO_QUERY ); 514*cdf0e10cSrcweir if( xParagraph.is() ) 515*cdf0e10cSrcweir xEnumAccess.query( xParagraph ); 516*cdf0e10cSrcweir else 517*cdf0e10cSrcweir xEnumAccess.clear(); 518*cdf0e10cSrcweir 519*cdf0e10cSrcweir if( xEnumAccess.is() ) 520*cdf0e10cSrcweir { 521*cdf0e10cSrcweir uno::Reference< container::XEnumeration > xPortionEnum( xEnumAccess->createEnumeration() ); 522*cdf0e10cSrcweir if( xPortionEnum.is() ) 523*cdf0e10cSrcweir { 524*cdf0e10cSrcweir while(xPortionEnum->hasMoreElements()) 525*cdf0e10cSrcweir { 526*cdf0e10cSrcweir uno::Reference< text::XTextRange > xPortion( xPortionEnum->nextElement(), uno::UNO_QUERY ); 527*cdf0e10cSrcweir if( xPortion.is() ) 528*cdf0e10cSrcweir { 529*cdf0e10cSrcweir const OUString aPortion( xPortion->getString() ); 530*cdf0e10cSrcweir const sal_Int32 nLen = aPortion.getLength(); 531*cdf0e10cSrcweir 532*cdf0e10cSrcweir ESelection aStartSel( GetSelection( xPortion->getStart() ) ); 533*cdf0e10cSrcweir ESelection aEndSel( GetSelection( xPortion->getEnd() ) ); 534*cdf0e10cSrcweir 535*cdf0e10cSrcweir // special case for empty portions with content or length one portions with content (fields) 536*cdf0e10cSrcweir if( (aStartSel.nStartPos == aEndSel.nStartPos) || ( (aStartSel.nStartPos == (aEndSel.nStartPos - 1)) && (nLen > 1) ) ) 537*cdf0e10cSrcweir { 538*cdf0e10cSrcweir for( sal_Int32 i = 0; i < nLen; i++ ) 539*cdf0e10cSrcweir { 540*cdf0e10cSrcweir if( ndbg < (nTextLen+2) ) 541*cdf0e10cSrcweir { 542*cdf0e10cSrcweir *pPos++ = aStartSel.nStartPos; 543*cdf0e10cSrcweir *pPara++ = aStartSel.nStartPara; 544*cdf0e10cSrcweir 545*cdf0e10cSrcweir ndbg += 1; 546*cdf0e10cSrcweir pText++; 547*cdf0e10cSrcweir } 548*cdf0e10cSrcweir else 549*cdf0e10cSrcweir { 550*cdf0e10cSrcweir DBG_ERROR( "array overflow while searching" ); 551*cdf0e10cSrcweir } 552*cdf0e10cSrcweir } 553*cdf0e10cSrcweir 554*cdf0e10cSrcweir nLastPos = aStartSel.nStartPos; 555*cdf0e10cSrcweir } 556*cdf0e10cSrcweir // normal case 557*cdf0e10cSrcweir else 558*cdf0e10cSrcweir { 559*cdf0e10cSrcweir for( sal_Int32 i = 0; i < nLen; i++ ) 560*cdf0e10cSrcweir { 561*cdf0e10cSrcweir if( ndbg < (nTextLen+2) ) 562*cdf0e10cSrcweir { 563*cdf0e10cSrcweir *pPos++ = aStartSel.nStartPos++; 564*cdf0e10cSrcweir *pPara++ = aStartSel.nStartPara; 565*cdf0e10cSrcweir 566*cdf0e10cSrcweir ndbg += 1; 567*cdf0e10cSrcweir pText++; 568*cdf0e10cSrcweir } 569*cdf0e10cSrcweir else 570*cdf0e10cSrcweir { 571*cdf0e10cSrcweir DBG_ERROR( "array overflow while searching" ); 572*cdf0e10cSrcweir } 573*cdf0e10cSrcweir } 574*cdf0e10cSrcweir 575*cdf0e10cSrcweir nLastPos = aStartSel.nStartPos - 1; 576*cdf0e10cSrcweir DBG_ASSERT( aEndSel.nStartPos == aStartSel.nStartPos, "Search is not working" ); 577*cdf0e10cSrcweir } 578*cdf0e10cSrcweir nLastPara = aStartSel.nStartPara; 579*cdf0e10cSrcweir } 580*cdf0e10cSrcweir } 581*cdf0e10cSrcweir } 582*cdf0e10cSrcweir } 583*cdf0e10cSrcweir 584*cdf0e10cSrcweir if( ndbg < (nTextLen+2) ) 585*cdf0e10cSrcweir { 586*cdf0e10cSrcweir *pPos++ = nLastPos + 1; 587*cdf0e10cSrcweir *pPara++ = nLastPara; 588*cdf0e10cSrcweir 589*cdf0e10cSrcweir ndbg += 1; 590*cdf0e10cSrcweir pText++; 591*cdf0e10cSrcweir } 592*cdf0e10cSrcweir else 593*cdf0e10cSrcweir { 594*cdf0e10cSrcweir DBG_ERROR( "array overflow while searching" ); 595*cdf0e10cSrcweir } 596*cdf0e10cSrcweir } 597*cdf0e10cSrcweir } 598*cdf0e10cSrcweir 599*cdf0e10cSrcweir uno::Reference< text::XText > xFound; 600*cdf0e10cSrcweir ESelection aSel; 601*cdf0e10cSrcweir 602*cdf0e10cSrcweir uno::Reference< text::XTextRange > xRangeRef( xText, uno::UNO_QUERY ); 603*cdf0e10cSrcweir if( xRangeRef.is() ) 604*cdf0e10cSrcweir aSel = GetSelection( xRangeRef ); 605*cdf0e10cSrcweir 606*cdf0e10cSrcweir sal_Int32 nStartPos; 607*cdf0e10cSrcweir sal_Int32 nEndPos = 0; 608*cdf0e10cSrcweir for( nStartPos = 0; nStartPos < nTextLen; nStartPos++ ) 609*cdf0e10cSrcweir { 610*cdf0e10cSrcweir if( pConvertPara[nStartPos] == aSel.nStartPara && pConvertPos[nStartPos] == aSel.nStartPos ) 611*cdf0e10cSrcweir break; 612*cdf0e10cSrcweir } 613*cdf0e10cSrcweir 614*cdf0e10cSrcweir if( Search( aText, nStartPos, nEndPos, pDescr ) ) 615*cdf0e10cSrcweir { 616*cdf0e10cSrcweir if( nStartPos <= nTextLen && nEndPos <= nTextLen ) 617*cdf0e10cSrcweir { 618*cdf0e10cSrcweir ESelection aSelection( (sal_uInt16)pConvertPara[nStartPos], (sal_uInt16)pConvertPos[nStartPos], 619*cdf0e10cSrcweir (sal_uInt16)pConvertPara[nEndPos], (sal_uInt16)pConvertPos[nEndPos] ); 620*cdf0e10cSrcweir SvxUnoTextRange *pRange; 621*cdf0e10cSrcweir 622*cdf0e10cSrcweir SvxUnoTextBase* pParent = SvxUnoTextBase::getImplementation( xParent ); 623*cdf0e10cSrcweir 624*cdf0e10cSrcweir if(pParent) 625*cdf0e10cSrcweir { 626*cdf0e10cSrcweir pRange = new SvxUnoTextRange( *pParent ); 627*cdf0e10cSrcweir xFound = (text::XText*)pRange; 628*cdf0e10cSrcweir pRange->SetSelection(aSelection); 629*cdf0e10cSrcweir 630*cdf0e10cSrcweir // pDescr->SetStartPos( nEndPos ); 631*cdf0e10cSrcweir } 632*cdf0e10cSrcweir } 633*cdf0e10cSrcweir else 634*cdf0e10cSrcweir { 635*cdf0e10cSrcweir DBG_ERROR("Array overflow while searching!"); 636*cdf0e10cSrcweir } 637*cdf0e10cSrcweir } 638*cdf0e10cSrcweir 639*cdf0e10cSrcweir delete[] pConvertPos; 640*cdf0e10cSrcweir delete[] pConvertPara; 641*cdf0e10cSrcweir 642*cdf0e10cSrcweir return uno::Reference< text::XTextRange > ( xFound, uno::UNO_QUERY ); 643*cdf0e10cSrcweir } 644*cdf0e10cSrcweir 645*cdf0e10cSrcweir sal_Bool SdUnoSearchReplaceShape::Search( const OUString& rText, sal_Int32& nStartPos, sal_Int32& nEndPos, SdUnoSearchReplaceDescriptor* pDescr ) throw() 646*cdf0e10cSrcweir { 647*cdf0e10cSrcweir OUString aSearchStr( pDescr->getSearchString() ); 648*cdf0e10cSrcweir OUString aText( rText ); 649*cdf0e10cSrcweir 650*cdf0e10cSrcweir if( !pDescr->IsCaseSensitive() ) 651*cdf0e10cSrcweir { 652*cdf0e10cSrcweir aText.toAsciiLowerCase(); 653*cdf0e10cSrcweir aSearchStr.toAsciiLowerCase(); 654*cdf0e10cSrcweir } 655*cdf0e10cSrcweir 656*cdf0e10cSrcweir sal_Int32 nFound = aText.indexOf( aSearchStr, nStartPos ); 657*cdf0e10cSrcweir if( nFound != -1 ) 658*cdf0e10cSrcweir { 659*cdf0e10cSrcweir nStartPos = nFound; 660*cdf0e10cSrcweir nEndPos = nFound + aSearchStr.getLength(); 661*cdf0e10cSrcweir 662*cdf0e10cSrcweir if(pDescr->IsWords()) 663*cdf0e10cSrcweir { 664*cdf0e10cSrcweir if( (nStartPos > 0 && aText.getStr()[nStartPos-1] > ' ') || 665*cdf0e10cSrcweir (nEndPos < aText.getLength() && aText.getStr()[nEndPos] > ' ') ) 666*cdf0e10cSrcweir { 667*cdf0e10cSrcweir nStartPos++; 668*cdf0e10cSrcweir return Search( aText, nStartPos, nEndPos, pDescr ); 669*cdf0e10cSrcweir } 670*cdf0e10cSrcweir } 671*cdf0e10cSrcweir 672*cdf0e10cSrcweir return sal_True; 673*cdf0e10cSrcweir } 674*cdf0e10cSrcweir else 675*cdf0e10cSrcweir return sal_False; 676*cdf0e10cSrcweir } 677*cdf0e10cSrcweir 678*cdf0e10cSrcweir ESelection SdUnoSearchReplaceShape::GetSelection( uno::Reference< text::XTextRange > xTextRange ) throw() 679*cdf0e10cSrcweir { 680*cdf0e10cSrcweir ESelection aSel; 681*cdf0e10cSrcweir SvxUnoTextRangeBase* pRange = SvxUnoTextRangeBase::getImplementation( xTextRange ); 682*cdf0e10cSrcweir 683*cdf0e10cSrcweir if(pRange) 684*cdf0e10cSrcweir aSel = pRange->GetSelection(); 685*cdf0e10cSrcweir 686*cdf0e10cSrcweir return aSel; 687*cdf0e10cSrcweir } 688*cdf0e10cSrcweir 689*cdf0e10cSrcweir uno::Reference< drawing::XShape > SdUnoSearchReplaceShape::GetShape( uno::Reference< text::XTextRange > xTextRange ) throw() 690*cdf0e10cSrcweir { 691*cdf0e10cSrcweir uno::Reference< drawing::XShape > xShape; 692*cdf0e10cSrcweir 693*cdf0e10cSrcweir if(xTextRange.is()) 694*cdf0e10cSrcweir { 695*cdf0e10cSrcweir uno::Reference< text::XText > xText( xTextRange->getText() ); 696*cdf0e10cSrcweir 697*cdf0e10cSrcweir if(xText.is()) 698*cdf0e10cSrcweir { 699*cdf0e10cSrcweir do 700*cdf0e10cSrcweir { 701*cdf0e10cSrcweir xText->queryInterface( ITYPE( drawing::XShape )) >>= xShape; 702*cdf0e10cSrcweir if(!xShape.is()) 703*cdf0e10cSrcweir { 704*cdf0e10cSrcweir uno::Reference< text::XText > xParent( xText->getText() ); 705*cdf0e10cSrcweir if(!xParent.is() || xText.get() == xParent.get()) 706*cdf0e10cSrcweir return xShape; 707*cdf0e10cSrcweir 708*cdf0e10cSrcweir xText = xParent; 709*cdf0e10cSrcweir } 710*cdf0e10cSrcweir } while( !xShape.is() ); 711*cdf0e10cSrcweir } 712*cdf0e10cSrcweir } 713*cdf0e10cSrcweir 714*cdf0e10cSrcweir return xShape; 715*cdf0e10cSrcweir } 716*cdf0e10cSrcweir 717*cdf0e10cSrcweir /* ================================================================= */ 718*cdf0e10cSrcweir /** this class holds the parameters and status of a search or replace 719*cdf0e10cSrcweir operation performed by class SdUnoSearchReplaceShape 720*cdf0e10cSrcweir */ 721*cdf0e10cSrcweir 722*cdf0e10cSrcweir UNO3_GETIMPLEMENTATION_IMPL( SdUnoSearchReplaceDescriptor ); 723*cdf0e10cSrcweir 724*cdf0e10cSrcweir SdUnoSearchReplaceDescriptor::SdUnoSearchReplaceDescriptor( sal_Bool bReplace ) throw() 725*cdf0e10cSrcweir { 726*cdf0e10cSrcweir mpPropSet = new SvxItemPropertySet(ImplGetSearchPropertyMap(), SdrObject::GetGlobalDrawObjectItemPool()); 727*cdf0e10cSrcweir 728*cdf0e10cSrcweir mbBackwards = sal_False; 729*cdf0e10cSrcweir mbCaseSensitive = sal_False; 730*cdf0e10cSrcweir mbWords = sal_False; 731*cdf0e10cSrcweir 732*cdf0e10cSrcweir mbReplace = bReplace; 733*cdf0e10cSrcweir } 734*cdf0e10cSrcweir 735*cdf0e10cSrcweir SdUnoSearchReplaceDescriptor::~SdUnoSearchReplaceDescriptor() throw() 736*cdf0e10cSrcweir { 737*cdf0e10cSrcweir delete mpPropSet; 738*cdf0e10cSrcweir } 739*cdf0e10cSrcweir 740*cdf0e10cSrcweir // XSearchDescriptor 741*cdf0e10cSrcweir OUString SAL_CALL SdUnoSearchReplaceDescriptor::getSearchString() 742*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 743*cdf0e10cSrcweir { 744*cdf0e10cSrcweir return maSearchStr; 745*cdf0e10cSrcweir } 746*cdf0e10cSrcweir 747*cdf0e10cSrcweir void SAL_CALL SdUnoSearchReplaceDescriptor::setSearchString( const OUString& aString ) 748*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 749*cdf0e10cSrcweir { 750*cdf0e10cSrcweir maSearchStr = aString; 751*cdf0e10cSrcweir } 752*cdf0e10cSrcweir 753*cdf0e10cSrcweir // XReplaceDescriptor 754*cdf0e10cSrcweir OUString SAL_CALL SdUnoSearchReplaceDescriptor::getReplaceString() 755*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 756*cdf0e10cSrcweir { 757*cdf0e10cSrcweir return maReplaceStr; 758*cdf0e10cSrcweir } 759*cdf0e10cSrcweir 760*cdf0e10cSrcweir void SAL_CALL SdUnoSearchReplaceDescriptor::setReplaceString( const ::rtl::OUString& aReplaceString ) 761*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 762*cdf0e10cSrcweir { 763*cdf0e10cSrcweir maReplaceStr = aReplaceString; 764*cdf0e10cSrcweir } 765*cdf0e10cSrcweir 766*cdf0e10cSrcweir // XPropertySet 767*cdf0e10cSrcweir uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL SdUnoSearchReplaceDescriptor::getPropertySetInfo() 768*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 769*cdf0e10cSrcweir { 770*cdf0e10cSrcweir OGuard aGuard( Application::GetSolarMutex() ); 771*cdf0e10cSrcweir return mpPropSet->getPropertySetInfo(); 772*cdf0e10cSrcweir } 773*cdf0e10cSrcweir 774*cdf0e10cSrcweir void SAL_CALL SdUnoSearchReplaceDescriptor::setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) 775*cdf0e10cSrcweir 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) 776*cdf0e10cSrcweir { 777*cdf0e10cSrcweir OGuard aGuard( Application::GetSolarMutex() ); 778*cdf0e10cSrcweir 779*cdf0e10cSrcweir const SfxItemPropertySimpleEntry* pEntry = mpPropSet->getPropertyMapEntry(aPropertyName); 780*cdf0e10cSrcweir 781*cdf0e10cSrcweir sal_Bool bOk = sal_False; 782*cdf0e10cSrcweir 783*cdf0e10cSrcweir switch( pEntry ? pEntry->nWID : -1 ) 784*cdf0e10cSrcweir { 785*cdf0e10cSrcweir case WID_SEARCH_BACKWARDS: 786*cdf0e10cSrcweir bOk = (aValue >>= mbBackwards); 787*cdf0e10cSrcweir break; 788*cdf0e10cSrcweir case WID_SEARCH_CASE: 789*cdf0e10cSrcweir bOk = (aValue >>= mbCaseSensitive); 790*cdf0e10cSrcweir break; 791*cdf0e10cSrcweir case WID_SEARCH_WORDS: 792*cdf0e10cSrcweir bOk = (aValue >>= mbWords); 793*cdf0e10cSrcweir break; 794*cdf0e10cSrcweir default: 795*cdf0e10cSrcweir throw beans::UnknownPropertyException(); 796*cdf0e10cSrcweir } 797*cdf0e10cSrcweir 798*cdf0e10cSrcweir if( !bOk ) 799*cdf0e10cSrcweir throw lang::IllegalArgumentException(); 800*cdf0e10cSrcweir } 801*cdf0e10cSrcweir 802*cdf0e10cSrcweir uno::Any SAL_CALL SdUnoSearchReplaceDescriptor::getPropertyValue( const ::rtl::OUString& PropertyName ) 803*cdf0e10cSrcweir throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) 804*cdf0e10cSrcweir { 805*cdf0e10cSrcweir OGuard aGuard( Application::GetSolarMutex() ); 806*cdf0e10cSrcweir 807*cdf0e10cSrcweir uno::Any aAny; 808*cdf0e10cSrcweir 809*cdf0e10cSrcweir const SfxItemPropertySimpleEntry* pEntry = mpPropSet->getPropertyMapEntry(PropertyName); 810*cdf0e10cSrcweir 811*cdf0e10cSrcweir switch( pEntry ? pEntry->nWID : -1 ) 812*cdf0e10cSrcweir { 813*cdf0e10cSrcweir case WID_SEARCH_BACKWARDS: 814*cdf0e10cSrcweir aAny <<= (sal_Bool)mbBackwards; 815*cdf0e10cSrcweir break; 816*cdf0e10cSrcweir case WID_SEARCH_CASE: 817*cdf0e10cSrcweir aAny <<= (sal_Bool)mbCaseSensitive; 818*cdf0e10cSrcweir break; 819*cdf0e10cSrcweir case WID_SEARCH_WORDS: 820*cdf0e10cSrcweir aAny <<= (sal_Bool)mbWords; 821*cdf0e10cSrcweir break; 822*cdf0e10cSrcweir default: 823*cdf0e10cSrcweir throw beans::UnknownPropertyException(); 824*cdf0e10cSrcweir } 825*cdf0e10cSrcweir 826*cdf0e10cSrcweir return aAny; 827*cdf0e10cSrcweir } 828*cdf0e10cSrcweir 829*cdf0e10cSrcweir 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) {} 830*cdf0e10cSrcweir 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) {} 831*cdf0e10cSrcweir 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) {} 832*cdf0e10cSrcweir 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) {} 833*cdf0e10cSrcweir 834*cdf0e10cSrcweir 835*cdf0e10cSrcweir /* ================================================================= */ 836*cdf0e10cSrcweir 837*cdf0e10cSrcweir SdUnoFindAllAccess::SdUnoFindAllAccess( uno::Sequence< uno::Reference< uno::XInterface > >& rSequence ) throw() 838*cdf0e10cSrcweir :maSequence( rSequence ) 839*cdf0e10cSrcweir { 840*cdf0e10cSrcweir } 841*cdf0e10cSrcweir 842*cdf0e10cSrcweir SdUnoFindAllAccess::~SdUnoFindAllAccess() throw() 843*cdf0e10cSrcweir { 844*cdf0e10cSrcweir } 845*cdf0e10cSrcweir 846*cdf0e10cSrcweir // XElementAccess 847*cdf0e10cSrcweir uno::Type SAL_CALL SdUnoFindAllAccess::getElementType() 848*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 849*cdf0e10cSrcweir { 850*cdf0e10cSrcweir return ITYPE( text::XTextRange ); 851*cdf0e10cSrcweir } 852*cdf0e10cSrcweir 853*cdf0e10cSrcweir sal_Bool SAL_CALL SdUnoFindAllAccess::hasElements() 854*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 855*cdf0e10cSrcweir { 856*cdf0e10cSrcweir return maSequence.getLength() > 0; 857*cdf0e10cSrcweir } 858*cdf0e10cSrcweir 859*cdf0e10cSrcweir // XIndexAccess 860*cdf0e10cSrcweir sal_Int32 SAL_CALL SdUnoFindAllAccess::getCount() 861*cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 862*cdf0e10cSrcweir { 863*cdf0e10cSrcweir return maSequence.getLength(); 864*cdf0e10cSrcweir } 865*cdf0e10cSrcweir 866*cdf0e10cSrcweir uno::Any SAL_CALL SdUnoFindAllAccess::getByIndex( sal_Int32 Index ) 867*cdf0e10cSrcweir throw(::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) 868*cdf0e10cSrcweir { 869*cdf0e10cSrcweir uno::Any aAny; 870*cdf0e10cSrcweir 871*cdf0e10cSrcweir if( Index < 0 || Index >= getCount() ) 872*cdf0e10cSrcweir throw lang::IndexOutOfBoundsException(); 873*cdf0e10cSrcweir 874*cdf0e10cSrcweir const uno::Reference< uno::XInterface > *pRefs = maSequence.getConstArray(); 875*cdf0e10cSrcweir if(pRefs) 876*cdf0e10cSrcweir aAny <<= pRefs[ Index ]; 877*cdf0e10cSrcweir return aAny; 878*cdf0e10cSrcweir } 879*cdf0e10cSrcweir 880