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_sc.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include "scitems.hxx" 34*cdf0e10cSrcweir #include <svl/srchitem.hxx> 35*cdf0e10cSrcweir #include <osl/mutex.hxx> 36*cdf0e10cSrcweir #include <rtl/uuid.h> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #include "srchuno.hxx" 39*cdf0e10cSrcweir #include "docsh.hxx" 40*cdf0e10cSrcweir #include "undoblk.hxx" 41*cdf0e10cSrcweir #include "hints.hxx" 42*cdf0e10cSrcweir #include "markdata.hxx" 43*cdf0e10cSrcweir #include "unoguard.hxx" 44*cdf0e10cSrcweir #include "miscuno.hxx" 45*cdf0e10cSrcweir #include "unonames.hxx" 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir using namespace com::sun::star; 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir //------------------------------------------------------------------------ 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir //! SearchWords sucht in ganzen Zellen - umbenennen ??? 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir // SfxItemPropertyMapEntry nur fuer GetPropertySetInfo 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir const SfxItemPropertyMapEntry* lcl_GetSearchPropertyMap() 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir static SfxItemPropertyMapEntry aSearchPropertyMap_Impl[] = 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNO_SRCHBACK), 0, &getBooleanCppuType(), 0, 0}, 60*cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNO_SRCHBYROW), 0, &getBooleanCppuType(), 0, 0}, 61*cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNO_SRCHCASE), 0, &getBooleanCppuType(), 0, 0}, 62*cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNO_SRCHREGEXP), 0, &getBooleanCppuType(), 0, 0}, 63*cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNO_SRCHSIM), 0, &getBooleanCppuType(), 0, 0}, 64*cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNO_SRCHSIMADD), 0, &getCppuType((sal_Int16*)0), 0, 0}, 65*cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNO_SRCHSIMEX), 0, &getCppuType((sal_Int16*)0), 0, 0}, 66*cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNO_SRCHSIMREL), 0, &getBooleanCppuType(), 0, 0}, 67*cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNO_SRCHSIMREM), 0, &getCppuType((sal_Int16*)0), 0, 0}, 68*cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNO_SRCHSTYLES), 0, &getBooleanCppuType(), 0, 0}, 69*cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNO_SRCHTYPE), 0, &getCppuType((sal_Int16*)0), 0, 0}, // enum TableSearch ist weg 70*cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNO_SRCHWORDS), 0, &getBooleanCppuType(), 0, 0}, 71*cdf0e10cSrcweir {0,0,0,0,0,0} 72*cdf0e10cSrcweir }; 73*cdf0e10cSrcweir return aSearchPropertyMap_Impl; 74*cdf0e10cSrcweir } 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir //------------------------------------------------------------------------ 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir #define SCSEARCHDESCRIPTOR_SERVICE "com.sun.star.util.SearchDescriptor" 79*cdf0e10cSrcweir #define SCREPLACEDESCRIPTOR_SERVICE "com.sun.star.util.ReplaceDescriptor" 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir //------------------------------------------------------------------------ 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir ScCellSearchObj::ScCellSearchObj() : 84*cdf0e10cSrcweir aPropSet(lcl_GetSearchPropertyMap()) 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir pSearchItem = new SvxSearchItem( SCITEM_SEARCHDATA ); 87*cdf0e10cSrcweir // Defaults: 88*cdf0e10cSrcweir pSearchItem->SetWordOnly(sal_False); 89*cdf0e10cSrcweir pSearchItem->SetExact(sal_False); 90*cdf0e10cSrcweir pSearchItem->SetMatchFullHalfWidthForms(sal_False); 91*cdf0e10cSrcweir pSearchItem->SetUseAsianOptions(sal_False); // or all asian bits would have to be handled 92*cdf0e10cSrcweir pSearchItem->SetBackward(sal_False); 93*cdf0e10cSrcweir pSearchItem->SetSelection(sal_False); 94*cdf0e10cSrcweir pSearchItem->SetRegExp(sal_False); 95*cdf0e10cSrcweir pSearchItem->SetPattern(sal_False); 96*cdf0e10cSrcweir pSearchItem->SetLevenshtein(sal_False); 97*cdf0e10cSrcweir pSearchItem->SetLEVRelaxed(sal_False); 98*cdf0e10cSrcweir pSearchItem->SetLEVOther(2); 99*cdf0e10cSrcweir pSearchItem->SetLEVShorter(2); 100*cdf0e10cSrcweir pSearchItem->SetLEVLonger(2); 101*cdf0e10cSrcweir // Calc-Flags 102*cdf0e10cSrcweir pSearchItem->SetRowDirection(sal_False); 103*cdf0e10cSrcweir pSearchItem->SetCellType(SVX_SEARCHIN_FORMULA); 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir // Selection-Flag wird beim Aufruf gesetzt 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir ScCellSearchObj::~ScCellSearchObj() 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir delete pSearchItem; 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir // XSearchDescriptor 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir rtl::OUString SAL_CALL ScCellSearchObj::getSearchString() throw(uno::RuntimeException) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir ScUnoGuard aGuard; 118*cdf0e10cSrcweir return pSearchItem->GetSearchString(); 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir void SAL_CALL ScCellSearchObj::setSearchString( const rtl::OUString& aString ) 122*cdf0e10cSrcweir throw(uno::RuntimeException) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir ScUnoGuard aGuard; 125*cdf0e10cSrcweir pSearchItem->SetSearchString( aString ); 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir // XReplaceDescriptor 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir rtl::OUString SAL_CALL ScCellSearchObj::getReplaceString() throw(uno::RuntimeException) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir ScUnoGuard aGuard; 133*cdf0e10cSrcweir return pSearchItem->GetReplaceString(); 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir void SAL_CALL ScCellSearchObj::setReplaceString( const rtl::OUString& aReplaceString ) 137*cdf0e10cSrcweir throw(uno::RuntimeException) 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir ScUnoGuard aGuard; 140*cdf0e10cSrcweir pSearchItem->SetReplaceString( aReplaceString ); 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir // XPropertySet 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir uno::Reference<beans::XPropertySetInfo> SAL_CALL ScCellSearchObj::getPropertySetInfo() 146*cdf0e10cSrcweir throw(uno::RuntimeException) 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir ScUnoGuard aGuard; 149*cdf0e10cSrcweir static uno::Reference<beans::XPropertySetInfo> aRef( 150*cdf0e10cSrcweir new SfxItemPropertySetInfo( aPropSet.getPropertyMap() )); 151*cdf0e10cSrcweir return aRef; 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir void SAL_CALL ScCellSearchObj::setPropertyValue( 155*cdf0e10cSrcweir const rtl::OUString& aPropertyName, const uno::Any& aValue ) 156*cdf0e10cSrcweir throw(beans::UnknownPropertyException, beans::PropertyVetoException, 157*cdf0e10cSrcweir lang::IllegalArgumentException, lang::WrappedTargetException, 158*cdf0e10cSrcweir uno::RuntimeException) 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir ScUnoGuard aGuard; 161*cdf0e10cSrcweir String aString(aPropertyName); 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir if (aString.EqualsAscii( SC_UNO_SRCHBACK )) pSearchItem->SetBackward( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); 164*cdf0e10cSrcweir else if (aString.EqualsAscii( SC_UNO_SRCHBYROW )) pSearchItem->SetRowDirection( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); 165*cdf0e10cSrcweir else if (aString.EqualsAscii( SC_UNO_SRCHCASE )) pSearchItem->SetExact( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); 166*cdf0e10cSrcweir else if (aString.EqualsAscii( SC_UNO_SRCHREGEXP )) pSearchItem->SetRegExp( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); 167*cdf0e10cSrcweir else if (aString.EqualsAscii( SC_UNO_SRCHSIM )) pSearchItem->SetLevenshtein( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); 168*cdf0e10cSrcweir else if (aString.EqualsAscii( SC_UNO_SRCHSIMREL )) pSearchItem->SetLEVRelaxed( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); 169*cdf0e10cSrcweir else if (aString.EqualsAscii( SC_UNO_SRCHSTYLES )) pSearchItem->SetPattern( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); 170*cdf0e10cSrcweir else if (aString.EqualsAscii( SC_UNO_SRCHWORDS )) pSearchItem->SetWordOnly( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); 171*cdf0e10cSrcweir else if (aString.EqualsAscii( SC_UNO_SRCHSIMADD )) pSearchItem->SetLEVLonger( ScUnoHelpFunctions::GetInt16FromAny( aValue ) ); 172*cdf0e10cSrcweir else if (aString.EqualsAscii( SC_UNO_SRCHSIMEX )) pSearchItem->SetLEVOther( ScUnoHelpFunctions::GetInt16FromAny( aValue ) ); 173*cdf0e10cSrcweir else if (aString.EqualsAscii( SC_UNO_SRCHSIMREM )) pSearchItem->SetLEVShorter( ScUnoHelpFunctions::GetInt16FromAny( aValue ) ); 174*cdf0e10cSrcweir else if (aString.EqualsAscii( SC_UNO_SRCHTYPE )) pSearchItem->SetCellType( ScUnoHelpFunctions::GetInt16FromAny( aValue ) ); 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir uno::Any SAL_CALL ScCellSearchObj::getPropertyValue( const rtl::OUString& aPropertyName ) 178*cdf0e10cSrcweir throw(beans::UnknownPropertyException, lang::WrappedTargetException, 179*cdf0e10cSrcweir uno::RuntimeException) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir ScUnoGuard aGuard; 182*cdf0e10cSrcweir String aString(aPropertyName); 183*cdf0e10cSrcweir uno::Any aRet; 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir if (aString.EqualsAscii( SC_UNO_SRCHBACK )) ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->GetBackward() ); 186*cdf0e10cSrcweir else if (aString.EqualsAscii( SC_UNO_SRCHBYROW )) ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->GetRowDirection() ); 187*cdf0e10cSrcweir else if (aString.EqualsAscii( SC_UNO_SRCHCASE )) ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->GetExact() ); 188*cdf0e10cSrcweir else if (aString.EqualsAscii( SC_UNO_SRCHREGEXP )) ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->GetRegExp() ); 189*cdf0e10cSrcweir else if (aString.EqualsAscii( SC_UNO_SRCHSIM )) ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->IsLevenshtein() ); 190*cdf0e10cSrcweir else if (aString.EqualsAscii( SC_UNO_SRCHSIMREL )) ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->IsLEVRelaxed() ); 191*cdf0e10cSrcweir else if (aString.EqualsAscii( SC_UNO_SRCHSTYLES )) ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->GetPattern() ); 192*cdf0e10cSrcweir else if (aString.EqualsAscii( SC_UNO_SRCHWORDS )) ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->GetWordOnly() ); 193*cdf0e10cSrcweir else if (aString.EqualsAscii( SC_UNO_SRCHSIMADD )) aRet <<= (sal_Int16) pSearchItem->GetLEVLonger(); 194*cdf0e10cSrcweir else if (aString.EqualsAscii( SC_UNO_SRCHSIMEX )) aRet <<= (sal_Int16) pSearchItem->GetLEVOther(); 195*cdf0e10cSrcweir else if (aString.EqualsAscii( SC_UNO_SRCHSIMREM )) aRet <<= (sal_Int16) pSearchItem->GetLEVShorter(); 196*cdf0e10cSrcweir else if (aString.EqualsAscii( SC_UNO_SRCHTYPE )) aRet <<= (sal_Int16) pSearchItem->GetCellType(); 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir return aRet; 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir SC_IMPL_DUMMY_PROPERTY_LISTENER( ScCellSearchObj ) 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir // XServiceInfo 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir rtl::OUString SAL_CALL ScCellSearchObj::getImplementationName() throw(uno::RuntimeException) 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir return rtl::OUString::createFromAscii( "ScCellSearchObj" ); 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir sal_Bool SAL_CALL ScCellSearchObj::supportsService( const rtl::OUString& rServiceName ) 211*cdf0e10cSrcweir throw(uno::RuntimeException) 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir String aServiceStr(rServiceName); 214*cdf0e10cSrcweir return aServiceStr.EqualsAscii( SCSEARCHDESCRIPTOR_SERVICE ) || 215*cdf0e10cSrcweir aServiceStr.EqualsAscii( SCREPLACEDESCRIPTOR_SERVICE ); 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir uno::Sequence<rtl::OUString> SAL_CALL ScCellSearchObj::getSupportedServiceNames() 219*cdf0e10cSrcweir throw(uno::RuntimeException) 220*cdf0e10cSrcweir { 221*cdf0e10cSrcweir uno::Sequence<rtl::OUString> aRet(2); 222*cdf0e10cSrcweir rtl::OUString* pArray = aRet.getArray(); 223*cdf0e10cSrcweir pArray[0] = rtl::OUString::createFromAscii( SCSEARCHDESCRIPTOR_SERVICE ); 224*cdf0e10cSrcweir pArray[1] = rtl::OUString::createFromAscii( SCREPLACEDESCRIPTOR_SERVICE ); 225*cdf0e10cSrcweir return aRet; 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir // XUnoTunnel 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir sal_Int64 SAL_CALL ScCellSearchObj::getSomething( 231*cdf0e10cSrcweir const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException) 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir if ( rId.getLength() == 16 && 234*cdf0e10cSrcweir 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), 235*cdf0e10cSrcweir rId.getConstArray(), 16 ) ) 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this)); 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir return 0; 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir // static 243*cdf0e10cSrcweir const uno::Sequence<sal_Int8>& ScCellSearchObj::getUnoTunnelId() 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir static uno::Sequence<sal_Int8> * pSeq = 0; 246*cdf0e10cSrcweir if( !pSeq ) 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); 249*cdf0e10cSrcweir if( !pSeq ) 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir static uno::Sequence< sal_Int8 > aSeq( 16 ); 252*cdf0e10cSrcweir rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); 253*cdf0e10cSrcweir pSeq = &aSeq; 254*cdf0e10cSrcweir } 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir return *pSeq; 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir // static 260*cdf0e10cSrcweir ScCellSearchObj* ScCellSearchObj::getImplementation( 261*cdf0e10cSrcweir const uno::Reference<util::XSearchDescriptor> xObj ) 262*cdf0e10cSrcweir { 263*cdf0e10cSrcweir ScCellSearchObj* pRet = NULL; 264*cdf0e10cSrcweir uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY ); 265*cdf0e10cSrcweir if (xUT.is()) 266*cdf0e10cSrcweir pRet = reinterpret_cast<ScCellSearchObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId()))); 267*cdf0e10cSrcweir return pRet; 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir //------------------------------------------------------------------------ 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir 277