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