xref: /aoo42x/main/sc/source/ui/unoobj/srchuno.cxx (revision b3f79822)
1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b3f79822SAndrew Rist  * distributed with this work for additional information
6*b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b3f79822SAndrew Rist  *
11*b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b3f79822SAndrew Rist  *
13*b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b3f79822SAndrew Rist  * specific language governing permissions and limitations
18*b3f79822SAndrew Rist  * under the License.
19*b3f79822SAndrew Rist  *
20*b3f79822SAndrew Rist  *************************************************************/
21*b3f79822SAndrew Rist 
22*b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "scitems.hxx"
30cdf0e10cSrcweir #include <svl/srchitem.hxx>
31cdf0e10cSrcweir #include <osl/mutex.hxx>
32cdf0e10cSrcweir #include <rtl/uuid.h>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include "srchuno.hxx"
35cdf0e10cSrcweir #include "docsh.hxx"
36cdf0e10cSrcweir #include "undoblk.hxx"
37cdf0e10cSrcweir #include "hints.hxx"
38cdf0e10cSrcweir #include "markdata.hxx"
39cdf0e10cSrcweir #include "unoguard.hxx"
40cdf0e10cSrcweir #include "miscuno.hxx"
41cdf0e10cSrcweir #include "unonames.hxx"
42cdf0e10cSrcweir 
43cdf0e10cSrcweir using namespace com::sun::star;
44cdf0e10cSrcweir 
45cdf0e10cSrcweir //------------------------------------------------------------------------
46cdf0e10cSrcweir 
47cdf0e10cSrcweir //!	SearchWords sucht in ganzen Zellen - umbenennen ???
48cdf0e10cSrcweir 
49cdf0e10cSrcweir //  SfxItemPropertyMapEntry nur fuer GetPropertySetInfo
50cdf0e10cSrcweir 
lcl_GetSearchPropertyMap()51cdf0e10cSrcweir const SfxItemPropertyMapEntry* lcl_GetSearchPropertyMap()
52cdf0e10cSrcweir {
53cdf0e10cSrcweir     static SfxItemPropertyMapEntry aSearchPropertyMap_Impl[] =
54cdf0e10cSrcweir 	{
55cdf0e10cSrcweir 		{MAP_CHAR_LEN(SC_UNO_SRCHBACK),		0,	 	&getBooleanCppuType(), 		 0, 0},
56cdf0e10cSrcweir 		{MAP_CHAR_LEN(SC_UNO_SRCHBYROW),	0,	 	&getBooleanCppuType(), 		 0, 0},
57cdf0e10cSrcweir 		{MAP_CHAR_LEN(SC_UNO_SRCHCASE),		0,	 	&getBooleanCppuType(), 		 0, 0},
58cdf0e10cSrcweir 		{MAP_CHAR_LEN(SC_UNO_SRCHREGEXP),	0,		&getBooleanCppuType(), 		 0, 0},
59cdf0e10cSrcweir 		{MAP_CHAR_LEN(SC_UNO_SRCHSIM),		0,	 	&getBooleanCppuType(), 		 0, 0},
60cdf0e10cSrcweir 		{MAP_CHAR_LEN(SC_UNO_SRCHSIMADD),	0,	 	&getCppuType((sal_Int16*)0), 0, 0},
61cdf0e10cSrcweir 		{MAP_CHAR_LEN(SC_UNO_SRCHSIMEX),	0,		&getCppuType((sal_Int16*)0), 0, 0},
62cdf0e10cSrcweir 		{MAP_CHAR_LEN(SC_UNO_SRCHSIMREL),	0, 		&getBooleanCppuType(), 		 0, 0},
63cdf0e10cSrcweir 		{MAP_CHAR_LEN(SC_UNO_SRCHSIMREM),	0, 		&getCppuType((sal_Int16*)0), 0, 0},
64cdf0e10cSrcweir 		{MAP_CHAR_LEN(SC_UNO_SRCHSTYLES),	0, 		&getBooleanCppuType(), 		 0, 0},
65cdf0e10cSrcweir 		{MAP_CHAR_LEN(SC_UNO_SRCHTYPE),		0, 		&getCppuType((sal_Int16*)0), 0, 0},	// enum TableSearch ist weg
66cdf0e10cSrcweir 		{MAP_CHAR_LEN(SC_UNO_SRCHWORDS),	0, 		&getBooleanCppuType(), 		 0, 0},
67cdf0e10cSrcweir         {0,0,0,0,0,0}
68cdf0e10cSrcweir 	};
69cdf0e10cSrcweir 	return aSearchPropertyMap_Impl;
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir //------------------------------------------------------------------------
73cdf0e10cSrcweir 
74cdf0e10cSrcweir #define SCSEARCHDESCRIPTOR_SERVICE		"com.sun.star.util.SearchDescriptor"
75cdf0e10cSrcweir #define SCREPLACEDESCRIPTOR_SERVICE		"com.sun.star.util.ReplaceDescriptor"
76cdf0e10cSrcweir 
77cdf0e10cSrcweir //------------------------------------------------------------------------
78cdf0e10cSrcweir 
ScCellSearchObj()79cdf0e10cSrcweir ScCellSearchObj::ScCellSearchObj() :
80cdf0e10cSrcweir 	aPropSet(lcl_GetSearchPropertyMap())
81cdf0e10cSrcweir {
82cdf0e10cSrcweir     pSearchItem = new SvxSearchItem( SCITEM_SEARCHDATA );
83cdf0e10cSrcweir 	//	Defaults:
84cdf0e10cSrcweir 	pSearchItem->SetWordOnly(sal_False);
85cdf0e10cSrcweir 	pSearchItem->SetExact(sal_False);
86cdf0e10cSrcweir 	pSearchItem->SetMatchFullHalfWidthForms(sal_False);
87cdf0e10cSrcweir 	pSearchItem->SetUseAsianOptions(sal_False);		// or all asian bits would have to be handled
88cdf0e10cSrcweir 	pSearchItem->SetBackward(sal_False);
89cdf0e10cSrcweir 	pSearchItem->SetSelection(sal_False);
90cdf0e10cSrcweir 	pSearchItem->SetRegExp(sal_False);
91cdf0e10cSrcweir 	pSearchItem->SetPattern(sal_False);
92cdf0e10cSrcweir 	pSearchItem->SetLevenshtein(sal_False);
93cdf0e10cSrcweir 	pSearchItem->SetLEVRelaxed(sal_False);
94cdf0e10cSrcweir 	pSearchItem->SetLEVOther(2);
95cdf0e10cSrcweir 	pSearchItem->SetLEVShorter(2);
96cdf0e10cSrcweir 	pSearchItem->SetLEVLonger(2);
97cdf0e10cSrcweir 	//	Calc-Flags
98cdf0e10cSrcweir 	pSearchItem->SetRowDirection(sal_False);
99cdf0e10cSrcweir 	pSearchItem->SetCellType(SVX_SEARCHIN_FORMULA);
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 	//	Selection-Flag wird beim Aufruf gesetzt
102cdf0e10cSrcweir }
103cdf0e10cSrcweir 
~ScCellSearchObj()104cdf0e10cSrcweir ScCellSearchObj::~ScCellSearchObj()
105cdf0e10cSrcweir {
106cdf0e10cSrcweir 	delete pSearchItem;
107cdf0e10cSrcweir }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir // XSearchDescriptor
110cdf0e10cSrcweir 
getSearchString()111cdf0e10cSrcweir rtl::OUString SAL_CALL ScCellSearchObj::getSearchString() throw(uno::RuntimeException)
112cdf0e10cSrcweir {
113cdf0e10cSrcweir 	ScUnoGuard aGuard;
114cdf0e10cSrcweir 	return pSearchItem->GetSearchString();
115cdf0e10cSrcweir }
116cdf0e10cSrcweir 
setSearchString(const rtl::OUString & aString)117cdf0e10cSrcweir void SAL_CALL ScCellSearchObj::setSearchString( const rtl::OUString& aString )
118cdf0e10cSrcweir 													throw(uno::RuntimeException)
119cdf0e10cSrcweir {
120cdf0e10cSrcweir 	ScUnoGuard aGuard;
121cdf0e10cSrcweir 	pSearchItem->SetSearchString( aString );
122cdf0e10cSrcweir }
123cdf0e10cSrcweir 
124cdf0e10cSrcweir // XReplaceDescriptor
125cdf0e10cSrcweir 
getReplaceString()126cdf0e10cSrcweir rtl::OUString SAL_CALL ScCellSearchObj::getReplaceString() throw(uno::RuntimeException)
127cdf0e10cSrcweir {
128cdf0e10cSrcweir 	ScUnoGuard aGuard;
129cdf0e10cSrcweir 	return pSearchItem->GetReplaceString();
130cdf0e10cSrcweir }
131cdf0e10cSrcweir 
setReplaceString(const rtl::OUString & aReplaceString)132cdf0e10cSrcweir void SAL_CALL ScCellSearchObj::setReplaceString( const rtl::OUString& aReplaceString )
133cdf0e10cSrcweir 													throw(uno::RuntimeException)
134cdf0e10cSrcweir {
135cdf0e10cSrcweir 	ScUnoGuard aGuard;
136cdf0e10cSrcweir 	pSearchItem->SetReplaceString( aReplaceString );
137cdf0e10cSrcweir }
138cdf0e10cSrcweir 
139cdf0e10cSrcweir // XPropertySet
140cdf0e10cSrcweir 
getPropertySetInfo()141cdf0e10cSrcweir uno::Reference<beans::XPropertySetInfo> SAL_CALL ScCellSearchObj::getPropertySetInfo()
142cdf0e10cSrcweir 														throw(uno::RuntimeException)
143cdf0e10cSrcweir {
144cdf0e10cSrcweir 	ScUnoGuard aGuard;
145cdf0e10cSrcweir 	static uno::Reference<beans::XPropertySetInfo> aRef(
146cdf0e10cSrcweir 		new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
147cdf0e10cSrcweir 	return aRef;
148cdf0e10cSrcweir }
149cdf0e10cSrcweir 
setPropertyValue(const rtl::OUString & aPropertyName,const uno::Any & aValue)150cdf0e10cSrcweir void SAL_CALL ScCellSearchObj::setPropertyValue(
151cdf0e10cSrcweir 						const rtl::OUString& aPropertyName, const uno::Any& aValue )
152cdf0e10cSrcweir 				throw(beans::UnknownPropertyException, beans::PropertyVetoException,
153cdf0e10cSrcweir 						lang::IllegalArgumentException, lang::WrappedTargetException,
154cdf0e10cSrcweir 						uno::RuntimeException)
155cdf0e10cSrcweir {
156cdf0e10cSrcweir 	ScUnoGuard aGuard;
157cdf0e10cSrcweir 	String aString(aPropertyName);
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 	if (aString.EqualsAscii( SC_UNO_SRCHBACK ))		   pSearchItem->SetBackward( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
160cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNO_SRCHBYROW ))  pSearchItem->SetRowDirection( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
161cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNO_SRCHCASE ))   pSearchItem->SetExact( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
162cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNO_SRCHREGEXP )) pSearchItem->SetRegExp( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
163cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNO_SRCHSIM ))	   pSearchItem->SetLevenshtein( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
164cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNO_SRCHSIMREL )) pSearchItem->SetLEVRelaxed( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
165cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNO_SRCHSTYLES )) pSearchItem->SetPattern( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
166cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNO_SRCHWORDS ))  pSearchItem->SetWordOnly( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
167cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNO_SRCHSIMADD )) pSearchItem->SetLEVLonger( ScUnoHelpFunctions::GetInt16FromAny( aValue ) );
168cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNO_SRCHSIMEX ))  pSearchItem->SetLEVOther( ScUnoHelpFunctions::GetInt16FromAny( aValue ) );
169cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNO_SRCHSIMREM )) pSearchItem->SetLEVShorter( ScUnoHelpFunctions::GetInt16FromAny( aValue ) );
170cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNO_SRCHTYPE ))   pSearchItem->SetCellType( ScUnoHelpFunctions::GetInt16FromAny( aValue ) );
171cdf0e10cSrcweir }
172cdf0e10cSrcweir 
getPropertyValue(const rtl::OUString & aPropertyName)173cdf0e10cSrcweir uno::Any SAL_CALL ScCellSearchObj::getPropertyValue( const rtl::OUString& aPropertyName )
174cdf0e10cSrcweir 				throw(beans::UnknownPropertyException, lang::WrappedTargetException,
175cdf0e10cSrcweir 						uno::RuntimeException)
176cdf0e10cSrcweir {
177cdf0e10cSrcweir 	ScUnoGuard aGuard;
178cdf0e10cSrcweir 	String aString(aPropertyName);
179cdf0e10cSrcweir 	uno::Any aRet;
180cdf0e10cSrcweir 
181cdf0e10cSrcweir 	if (aString.EqualsAscii( SC_UNO_SRCHBACK ))		   ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->GetBackward() );
182cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNO_SRCHBYROW ))  ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->GetRowDirection() );
183cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNO_SRCHCASE ))   ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->GetExact() );
184cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNO_SRCHREGEXP )) ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->GetRegExp() );
185cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNO_SRCHSIM ))	   ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->IsLevenshtein() );
186cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNO_SRCHSIMREL )) ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->IsLEVRelaxed() );
187cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNO_SRCHSTYLES )) ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->GetPattern() );
188cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNO_SRCHWORDS ))  ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->GetWordOnly() );
189cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNO_SRCHSIMADD )) aRet <<= (sal_Int16) pSearchItem->GetLEVLonger();
190cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNO_SRCHSIMEX ))  aRet <<= (sal_Int16) pSearchItem->GetLEVOther();
191cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNO_SRCHSIMREM )) aRet <<= (sal_Int16) pSearchItem->GetLEVShorter();
192cdf0e10cSrcweir 	else if (aString.EqualsAscii( SC_UNO_SRCHTYPE ))   aRet <<= (sal_Int16) pSearchItem->GetCellType();
193cdf0e10cSrcweir 
194cdf0e10cSrcweir 	return aRet;
195cdf0e10cSrcweir }
196cdf0e10cSrcweir 
SC_IMPL_DUMMY_PROPERTY_LISTENER(ScCellSearchObj)197cdf0e10cSrcweir SC_IMPL_DUMMY_PROPERTY_LISTENER( ScCellSearchObj )
198cdf0e10cSrcweir 
199cdf0e10cSrcweir // XServiceInfo
200cdf0e10cSrcweir 
201cdf0e10cSrcweir rtl::OUString SAL_CALL ScCellSearchObj::getImplementationName() throw(uno::RuntimeException)
202cdf0e10cSrcweir {
203cdf0e10cSrcweir 	return rtl::OUString::createFromAscii( "ScCellSearchObj" );
204cdf0e10cSrcweir }
205cdf0e10cSrcweir 
supportsService(const rtl::OUString & rServiceName)206cdf0e10cSrcweir sal_Bool SAL_CALL ScCellSearchObj::supportsService( const rtl::OUString& rServiceName )
207cdf0e10cSrcweir 													throw(uno::RuntimeException)
208cdf0e10cSrcweir {
209cdf0e10cSrcweir 	String aServiceStr(rServiceName);
210cdf0e10cSrcweir 	return aServiceStr.EqualsAscii( SCSEARCHDESCRIPTOR_SERVICE ) ||
211cdf0e10cSrcweir 		   aServiceStr.EqualsAscii( SCREPLACEDESCRIPTOR_SERVICE );
212cdf0e10cSrcweir }
213cdf0e10cSrcweir 
getSupportedServiceNames()214cdf0e10cSrcweir uno::Sequence<rtl::OUString> SAL_CALL ScCellSearchObj::getSupportedServiceNames()
215cdf0e10cSrcweir 													throw(uno::RuntimeException)
216cdf0e10cSrcweir {
217cdf0e10cSrcweir 	uno::Sequence<rtl::OUString> aRet(2);
218cdf0e10cSrcweir 	rtl::OUString* pArray = aRet.getArray();
219cdf0e10cSrcweir 	pArray[0] = rtl::OUString::createFromAscii( SCSEARCHDESCRIPTOR_SERVICE );
220cdf0e10cSrcweir 	pArray[1] = rtl::OUString::createFromAscii( SCREPLACEDESCRIPTOR_SERVICE );
221cdf0e10cSrcweir 	return aRet;
222cdf0e10cSrcweir }
223cdf0e10cSrcweir 
224cdf0e10cSrcweir // XUnoTunnel
225cdf0e10cSrcweir 
getSomething(const uno::Sequence<sal_Int8> & rId)226cdf0e10cSrcweir sal_Int64 SAL_CALL ScCellSearchObj::getSomething(
227cdf0e10cSrcweir 				const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException)
228cdf0e10cSrcweir {
229cdf0e10cSrcweir 	if ( rId.getLength() == 16 &&
230cdf0e10cSrcweir           0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
231cdf0e10cSrcweir 									rId.getConstArray(), 16 ) )
232cdf0e10cSrcweir 	{
233cdf0e10cSrcweir         return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
234cdf0e10cSrcweir 	}
235cdf0e10cSrcweir 	return 0;
236cdf0e10cSrcweir }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir // static
getUnoTunnelId()239cdf0e10cSrcweir const uno::Sequence<sal_Int8>& ScCellSearchObj::getUnoTunnelId()
240cdf0e10cSrcweir {
241cdf0e10cSrcweir 	static uno::Sequence<sal_Int8> * pSeq = 0;
242cdf0e10cSrcweir 	if( !pSeq )
243cdf0e10cSrcweir 	{
244cdf0e10cSrcweir 		osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
245cdf0e10cSrcweir 		if( !pSeq )
246cdf0e10cSrcweir 		{
247cdf0e10cSrcweir 			static uno::Sequence< sal_Int8 > aSeq( 16 );
248cdf0e10cSrcweir 			rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
249cdf0e10cSrcweir 			pSeq = &aSeq;
250cdf0e10cSrcweir 		}
251cdf0e10cSrcweir 	}
252cdf0e10cSrcweir 	return *pSeq;
253cdf0e10cSrcweir }
254cdf0e10cSrcweir 
255cdf0e10cSrcweir // static
getImplementation(const uno::Reference<util::XSearchDescriptor> xObj)256cdf0e10cSrcweir ScCellSearchObj* ScCellSearchObj::getImplementation(
257cdf0e10cSrcweir 								const uno::Reference<util::XSearchDescriptor> xObj )
258cdf0e10cSrcweir {
259cdf0e10cSrcweir 	ScCellSearchObj* pRet = NULL;
260cdf0e10cSrcweir 	uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
261cdf0e10cSrcweir 	if (xUT.is())
262cdf0e10cSrcweir         pRet = reinterpret_cast<ScCellSearchObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
263cdf0e10cSrcweir 	return pRet;
264cdf0e10cSrcweir }
265cdf0e10cSrcweir 
266cdf0e10cSrcweir 
267cdf0e10cSrcweir //------------------------------------------------------------------------
268cdf0e10cSrcweir 
269cdf0e10cSrcweir 
270cdf0e10cSrcweir 
271cdf0e10cSrcweir 
272cdf0e10cSrcweir 
273