xref: /trunk/main/sw/source/core/unocore/unosrch.cxx (revision efeef26f)
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_sw.hxx"
26 
27 #include "unosrch.hxx"
28 #include <doc.hxx>
29 #include <hints.hxx>
30 #include <unomap.hxx>
31 #include <unobaseclass.hxx>
32 #include <unomid.h>
33 
34 #include <vos/mutex.hxx>
35 #include <vcl/svapp.hxx>
36 #include "editeng/unolingu.hxx"
37 #include <com/sun/star/util/SearchOptions.hpp>
38 #include <com/sun/star/util/SearchFlags.hpp>
39 #include <com/sun/star/i18n/TransliterationModules.hpp>
40 #include <com/sun/star/beans/PropertyAttribute.hpp>
41 
42 using namespace ::com::sun::star;
43 using ::rtl::OUString;
44 
45 /******************************************************************************
46  *
47  ******************************************************************************/
48 
49 /* -----------------23.06.99 12:19-------------------
50 
51  --------------------------------------------------*/
52 class SwSearchProperties_Impl
53 {
54 	beans::PropertyValue** 			pValueArr; //
55     sal_uInt32                      nArrLen;
56     const PropertyEntryVector_t     aPropertyEntries;
57 public:
58 	SwSearchProperties_Impl();
59 	~SwSearchProperties_Impl();
60 
61 	void	SetProperties(const uno::Sequence< beans::PropertyValue >& aSearchAttribs)
62 		throw( beans::UnknownPropertyException, lang::IllegalArgumentException, uno::RuntimeException );
63 	const uno::Sequence< beans::PropertyValue > GetProperties() const;
64 
65 	void	FillItemSet(SfxItemSet& rSet, sal_Bool bIsValueSearch) const;
66 	sal_Bool 	HasAttributes() const;
67 };
68 /* -----------------23.06.99 13:08-------------------
69 
70  --------------------------------------------------*/
SwSearchProperties_Impl()71 SwSearchProperties_Impl::SwSearchProperties_Impl() :
72     nArrLen(0),
73     aPropertyEntries( aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_CURSOR)->getPropertyMap()->getPropertyEntries())
74 {
75     nArrLen = aPropertyEntries.size();
76     pValueArr = new beans::PropertyValue*[nArrLen];
77     for(sal_uInt32 i = 0; i < nArrLen; i++)
78 		pValueArr[i] = 0;
79 }
80 /* -----------------23.06.99 13:08-------------------
81 
82  --------------------------------------------------*/
~SwSearchProperties_Impl()83 SwSearchProperties_Impl::~SwSearchProperties_Impl()
84 {
85     for(sal_uInt32 i = 0; i < nArrLen; i++)
86 		delete pValueArr[i];
87     delete[] pValueArr;
88 }
89 /* -----------------23.06.99 13:09-------------------
90 
91  --------------------------------------------------*/
SetProperties(const uno::Sequence<beans::PropertyValue> & aSearchAttribs)92 void	SwSearchProperties_Impl::SetProperties(const uno::Sequence< beans::PropertyValue >& aSearchAttribs)
93 				throw( beans::UnknownPropertyException, lang::IllegalArgumentException, uno::RuntimeException )
94 {
95 	const beans::PropertyValue* pProps = aSearchAttribs.getConstArray();
96     sal_uInt32 i;
97 
98 	//delete all existing values
99 	for( i = 0; i < nArrLen; i++)
100 	{
101 		delete pValueArr[i];
102 		pValueArr[i] = 0;
103 	}
104 
105     sal_uInt32 nLen = aSearchAttribs.getLength();
106     for(i = 0; i < nLen; i++)
107 	{
108 		sal_uInt16 nIndex = 0;
109         PropertyEntryVector_t::const_iterator aIt = aPropertyEntries.begin();
110         while(pProps[i].Name != aIt->sName)
111 		{
112             ++aIt;
113 			nIndex++;
114             if( aIt == aPropertyEntries.end() )
115                 throw beans::UnknownPropertyException();
116 		}
117 		pValueArr[nIndex] = new beans::PropertyValue(pProps[i]);
118 	}
119 }
120 /* -----------------23.06.99 13:08-------------------
121 
122  --------------------------------------------------*/
GetProperties() const123 const uno::Sequence< beans::PropertyValue > SwSearchProperties_Impl::GetProperties() const
124 {
125     sal_uInt32 nPropCount = 0;
126     sal_uInt32 i;
127 	for( i = 0; i < nArrLen; i++)
128 		if(pValueArr[i])
129 			nPropCount++;
130 
131 	uno::Sequence< beans::PropertyValue > aRet(nPropCount);
132 	beans::PropertyValue* pProps = aRet.getArray();
133 	nPropCount = 0;
134 	for(i = 0; i < nArrLen; i++)
135 	{
136 		if(pValueArr[i])
137 		{
138 			pProps[nPropCount++] = *(pValueArr[i]);
139 		}
140 	}
141 	return aRet;
142 }
143 /* -----------------23.06.99 13:06-------------------
144 
145  --------------------------------------------------*/
FillItemSet(SfxItemSet & rSet,sal_Bool bIsValueSearch) const146 void SwSearchProperties_Impl::FillItemSet(SfxItemSet& rSet, sal_Bool bIsValueSearch) const
147 {
148 	//
149 
150 	SfxPoolItem* pBoxItem = 0,
151 	*pBreakItem = 0,
152 	*pAutoKernItem  = 0,
153 	*pWLineItem	  = 0,
154 	*pTabItem  = 0,
155 	*pSplitItem  = 0,
156 	*pRegItem  = 0,
157 	*pLineSpaceItem  = 0,
158 	*pLineNumItem  = 0,
159 	*pKeepItem  = 0,
160 	*pLRItem  = 0,
161 	*pULItem  = 0,
162 	*pBackItem  = 0,
163 	*pAdjItem  = 0,
164 	*pDescItem  = 0,
165 	*pInetItem  = 0,
166 	*pDropItem  = 0,
167 	*pWeightItem  = 0,
168 	*pULineItem  = 0,
169 	*pOLineItem  = 0,
170 	*pCharFmtItem  = 0,
171 	*pShadItem  = 0,
172 	*pPostItem  = 0,
173 	*pNHyphItem  = 0,
174 	*pLangItem  = 0,
175 	*pKernItem  = 0,
176 	*pFontSizeItem  = 0,
177 	*pFontItem  = 0,
178 	*pBlinkItem  = 0,
179 	*pEscItem  = 0,
180 	*pCrossedOutItem  = 0,
181 	*pContourItem  = 0,
182 	*pCharColorItem  = 0,
183 	*pCasemapItem  = 0,
184     *pBrushItem  = 0,
185     *pFontCJKItem = 0,
186     *pFontSizeCJKItem = 0,
187     *pCJKLangItem = 0,
188     *pCJKPostureItem = 0,
189     *pCJKWeightItem = 0,
190     *pFontCTLItem = 0,
191     *pFontSizeCTLItem = 0,
192     *pCTLLangItem = 0,
193     *pCTLPostureItem = 0,
194     *pCTLWeightItem = 0;
195 
196     PropertyEntryVector_t::const_iterator aIt = aPropertyEntries.begin();
197     for(sal_uInt32 i = 0; i < nArrLen; i++, ++aIt)
198 	{
199 		if(pValueArr[i])
200 		{
201 			SfxPoolItem* pTempItem = 0;
202             switch(aIt->nWID)
203 			{
204 				case  RES_BOX:
205 					if(!pBoxItem)
206                         pBoxItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
207 					pTempItem = pBoxItem;
208 				break;
209 				case  RES_BREAK:
210 					if(!pBreakItem)
211                         pBreakItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
212 					pTempItem = pBreakItem;
213 				break;
214 				case  RES_CHRATR_AUTOKERN:
215 					if(!pAutoKernItem)
216                         pAutoKernItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
217 					pTempItem = pAutoKernItem;
218 					break;
219 				case  RES_CHRATR_BACKGROUND:
220 					if(!pBrushItem)
221                         pBrushItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
222 					pTempItem = pBrushItem;
223 				break;
224 				case  RES_CHRATR_CASEMAP:
225 					if(!pCasemapItem)
226                         pCasemapItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
227 					pTempItem = pCasemapItem;
228 				break;
229 				case  RES_CHRATR_COLOR:
230 					if(!pCharColorItem)
231                         pCharColorItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
232 					pTempItem = pCharColorItem;
233 				break;
234 				case  RES_CHRATR_CONTOUR:
235 					if(!pContourItem)
236                         pContourItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
237 					pTempItem = pContourItem;
238 				break;
239 				case  RES_CHRATR_CROSSEDOUT:
240 					if(!pCrossedOutItem)
241                         pCrossedOutItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
242 					pTempItem = pCrossedOutItem;
243 				break;
244 				case  RES_CHRATR_ESCAPEMENT:
245 					if(!pEscItem)
246                         pEscItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
247 					pTempItem = pEscItem;
248 				break;
249 				case  RES_CHRATR_BLINK:
250 					if(!pBlinkItem)
251                         pBlinkItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
252 					pTempItem = pBlinkItem;
253 				break;
254 				case  RES_CHRATR_FONT:
255 					if(!pFontItem)
256                         pFontItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
257 					pTempItem = pFontItem;
258 				break;
259 				case  RES_CHRATR_FONTSIZE:
260 					if(!pFontSizeItem)
261                         pFontSizeItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
262 					pTempItem = pFontSizeItem;
263 				break;
264 				case  RES_CHRATR_KERNING:
265 					if(!pKernItem)
266                         pKernItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
267 					pTempItem = pKernItem;
268 				break;
269 				case  RES_CHRATR_LANGUAGE:
270 					if(!pLangItem)
271                         pLangItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
272 					pTempItem = pLangItem;
273 				break;
274 				case  RES_CHRATR_NOHYPHEN:
275 					if(!pNHyphItem)
276                         pNHyphItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
277 					pTempItem = pNHyphItem;
278 				break;
279 				case  RES_CHRATR_POSTURE:
280 					if(!pPostItem)
281                         pPostItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
282 					pTempItem = pPostItem;
283 				break;
284 				case  RES_CHRATR_SHADOWED:
285 					if(!pShadItem)
286                         pShadItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
287 					pTempItem = pShadItem;
288 				break;
289 				case  RES_TXTATR_CHARFMT:
290 					if(!pCharFmtItem)
291                         pCharFmtItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
292 					pTempItem = pCharFmtItem;
293 				break;
294 				case  RES_CHRATR_UNDERLINE:
295 					if(!pULineItem)
296                         pULineItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
297 					pTempItem = pULineItem;
298 				break;
299 				case  RES_CHRATR_OVERLINE:
300 					if(!pOLineItem)
301                         pOLineItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
302 					pTempItem = pOLineItem;
303 				break;
304 				case  RES_CHRATR_WEIGHT:
305 					if(!pWeightItem)
306                         pWeightItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
307 					pTempItem = pWeightItem;
308 				break;
309 				case  RES_PARATR_DROP:
310 					if(!pDropItem)
311                         pDropItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
312 					pTempItem = pDropItem;
313 				break;
314 				case  RES_TXTATR_INETFMT:
315 					if(!pInetItem)
316                         pInetItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
317 					pTempItem = pInetItem;
318 				break;
319 				case  RES_PAGEDESC:
320 					if(!pDescItem)
321                         pDescItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
322 					pTempItem = pDescItem;
323 				break;
324 				case  RES_PARATR_ADJUST:
325 					if(!pAdjItem)
326                         pAdjItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
327 					pTempItem = pAdjItem;
328 				break;
329 				case  RES_BACKGROUND:
330 					if(!pBackItem)
331                         pBackItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
332 					pTempItem = pBackItem;
333 				break;
334 				case  RES_UL_SPACE:
335 					if(!pULItem)
336                         pULItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
337 					pTempItem = pULItem;
338 				break;
339 				case  RES_LR_SPACE:
340 					if(!pLRItem)
341                         pLRItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
342 					pTempItem = pLRItem;
343 				break;
344 				case  RES_KEEP:
345 					if(!pKeepItem)
346                         pKeepItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
347 					pTempItem = pKeepItem;
348 				break;
349 				case  RES_LINENUMBER:
350 					if(!pLineNumItem)
351                         pLineNumItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
352 					pTempItem = pLineNumItem;
353 				break;
354 				case  RES_PARATR_LINESPACING:
355 					if(!pLineSpaceItem)
356                         pLineSpaceItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
357 					pTempItem = pLineSpaceItem;
358 				break;
359 				case  RES_PARATR_REGISTER:
360 					if(!pRegItem)
361                         pRegItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
362 					pTempItem = pRegItem;
363 				break;
364 				case  RES_PARATR_SPLIT:
365 					if(!pSplitItem)
366                         pSplitItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
367 					pTempItem = pSplitItem;
368 				break;
369 				case  RES_PARATR_TABSTOP:
370 					if(!pTabItem)
371                         pTabItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
372 					pTempItem = pTabItem;
373 				break;
374 				case  RES_CHRATR_WORDLINEMODE:
375 					if(!pWLineItem)
376                         pWLineItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
377 					pTempItem = pWLineItem;
378 				break;
379                 case RES_CHRATR_CJK_FONT:
380                     if(!pFontCJKItem )
381                         pFontCJKItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
382                     pTempItem = pFontCJKItem;
383                 break;
384                 case RES_CHRATR_CJK_FONTSIZE:
385                     if(!pFontSizeCJKItem )
386                         pFontSizeCJKItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
387                     pTempItem = pFontSizeCJKItem;
388                 break;
389                 case RES_CHRATR_CJK_LANGUAGE:
390                     if(!pCJKLangItem )
391                         pCJKLangItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
392                     pTempItem = pCJKLangItem;
393                 break;
394                 case RES_CHRATR_CJK_POSTURE:
395                     if(!pCJKPostureItem )
396                         pCJKPostureItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
397                     pTempItem = pCJKPostureItem;
398                 break;
399                 case RES_CHRATR_CJK_WEIGHT:
400                     if(!pCJKWeightItem )
401                         pCJKWeightItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
402                     pTempItem = pCJKWeightItem;
403                 break;
404                 case RES_CHRATR_CTL_FONT:
405                     if(!pFontCTLItem )
406                         pFontCTLItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
407                     pTempItem = pFontCTLItem;
408                 break;
409                 case RES_CHRATR_CTL_FONTSIZE:
410                     if(!pFontSizeCTLItem )
411                         pFontSizeCTLItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
412                     pTempItem = pFontSizeCTLItem;
413                 break;
414                 case RES_CHRATR_CTL_LANGUAGE:
415                     if(!pCTLLangItem )
416                         pCTLLangItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
417                     pTempItem = pCTLLangItem;
418                 break;
419                 case RES_CHRATR_CTL_POSTURE:
420                     if(!pCTLPostureItem )
421                         pCTLPostureItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
422                     pTempItem = pCTLPostureItem;
423                 break;
424                 case RES_CHRATR_CTL_WEIGHT:
425                     if(!pCTLWeightItem )
426                         pCTLWeightItem = rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone();
427                     pTempItem = pCTLWeightItem;
428                 break;
429 			}
430 			if(pTempItem)
431 			{
432 				if(bIsValueSearch)
433 				{
434                     pTempItem->PutValue(pValueArr[i]->Value, aIt->nMemberId);
435 					rSet.Put(*pTempItem);
436 				}
437 				else
438 					rSet.InvalidateItem( pTempItem->Which() );
439 			}
440 		}
441 	}
442 	delete pBoxItem;
443 	delete pBreakItem;
444 	delete pBreakItem ;
445 	delete pAutoKernItem ;
446 	delete pWLineItem;
447 	delete pTabItem;
448 	delete pSplitItem;
449 	delete pRegItem;
450 	delete pLineSpaceItem ;
451 	delete pLineNumItem  ;
452 	delete pKeepItem;
453 	delete pLRItem  ;
454 	delete pULItem  ;
455 	delete pBackItem;
456 	delete pAdjItem;
457 	delete pDescItem;
458 	delete pInetItem;
459 	delete pDropItem;
460 	delete pWeightItem;
461 	delete pULineItem;
462 	delete pOLineItem;
463 	delete pCharFmtItem  ;
464 	delete pShadItem;
465 	delete pPostItem;
466 	delete pNHyphItem;
467 	delete pLangItem;
468 	delete pKernItem;
469 	delete pFontSizeItem ;
470 	delete pFontItem;
471 	delete pBlinkItem;
472 	delete pEscItem;
473 	delete pCrossedOutItem;
474 	delete pContourItem  ;
475 	delete pCharColorItem;
476 	delete pCasemapItem  ;
477 	delete pBrushItem  ;
478 }
479 /* -----------------23.06.99 14:18-------------------
480 
481  --------------------------------------------------*/
HasAttributes() const482 sal_Bool 	SwSearchProperties_Impl::HasAttributes() const
483 {
484     for(sal_uInt32 i = 0; i < nArrLen; i++)
485 		if(pValueArr[i])
486 			return sal_True;
487 	return sal_False;
488 }
489 
490 /*-- 14.12.98 13:07:10    ---------------------------------------------------
491 
492   -----------------------------------------------------------------------*/
SwXTextSearch()493 SwXTextSearch::SwXTextSearch() :
494 	pSearchProperties( new SwSearchProperties_Impl),
495 	pReplaceProperties( new SwSearchProperties_Impl),
496     m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_SEARCH)),
497 	bAll(sal_False),
498 	bWord(sal_False),
499 	bBack(sal_False),
500 	bExpr(sal_False),
501 	bCase(sal_False),
502 	bStyles(sal_False),
503 	bSimilarity(sal_False),
504 	bLevRelax(sal_False),
505 	nLevExchange(2),
506 	nLevAdd(2),
507 	nLevRemove(2),
508 	bIsValueSearch(sal_True)
509 {
510 }
511 /*-- 14.12.98 13:07:12    ---------------------------------------------------
512 
513   -----------------------------------------------------------------------*/
~SwXTextSearch()514 SwXTextSearch::~SwXTextSearch()
515 {
516 	delete pSearchProperties;
517 	delete pReplaceProperties;
518 }
519 /* -----------------------------10.03.00 18:02--------------------------------
520 
521  ---------------------------------------------------------------------------*/
getUnoTunnelId()522 const uno::Sequence< sal_Int8 > & SwXTextSearch::getUnoTunnelId()
523 {
524     static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId();
525 	return aSeq;
526 }
527 /* -----------------------------10.03.00 18:04--------------------------------
528 
529  ---------------------------------------------------------------------------*/
getSomething(const uno::Sequence<sal_Int8> & rId)530 sal_Int64 SAL_CALL SwXTextSearch::getSomething( const uno::Sequence< sal_Int8 >& rId )
531 	throw(uno::RuntimeException)
532 {
533     if( rId.getLength() == 16
534         && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
535 										rId.getConstArray(), 16 ) )
536     {
537 		return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(this) );
538     }
539 	return 0;
540 }
541 /*-- 14.12.98 13:07:12---------------------------------------------------
542 
543   -----------------------------------------------------------------------*/
getSearchString(void)544 OUString SwXTextSearch::getSearchString(void) throw( uno::RuntimeException )
545 {
546 	vos::OGuard aGuard(Application::GetSolarMutex());
547 	return sSearchText;
548 }
549 /*-- 14.12.98 13:07:12---------------------------------------------------
550 
551   -----------------------------------------------------------------------*/
setSearchString(const OUString & rString)552 void SwXTextSearch::setSearchString(const OUString& rString)
553 										throw( uno::RuntimeException )
554 {
555 	vos::OGuard aGuard(Application::GetSolarMutex());
556 	sSearchText = String(rString);
557 }
558 /*-- 14.12.98 13:07:12---------------------------------------------------
559 
560   -----------------------------------------------------------------------*/
getReplaceString(void)561 OUString SwXTextSearch::getReplaceString(void) throw( uno::RuntimeException )
562 {
563 	vos::OGuard aGuard(Application::GetSolarMutex());
564 	return sReplaceText;
565 }
566 /*-- 14.12.98 13:07:12---------------------------------------------------
567 
568   -----------------------------------------------------------------------*/
setReplaceString(const OUString & rReplaceString)569 void SwXTextSearch::setReplaceString(const OUString& rReplaceString) throw( uno::RuntimeException )
570 {
571 	vos::OGuard aGuard(Application::GetSolarMutex());
572 	sReplaceText = String(rReplaceString);
573 }
574 /*-- 14.12.98 13:07:13---------------------------------------------------
575 
576   -----------------------------------------------------------------------*/
getPropertySetInfo(void)577 uno::Reference< beans::XPropertySetInfo >  SwXTextSearch::getPropertySetInfo(void) throw( uno::RuntimeException )
578 {
579     static uno::Reference< beans::XPropertySetInfo >  aRef = m_pPropSet->getPropertySetInfo();
580 	return aRef;
581 }
582 /*-- 14.12.98 13:07:13---------------------------------------------------
583 
584   -----------------------------------------------------------------------*/
setPropertyValue(const OUString & rPropertyName,const uno::Any & aValue)585 void SwXTextSearch::setPropertyValue(const OUString& rPropertyName, const uno::Any& aValue)
586 	throw( beans::UnknownPropertyException, beans::PropertyVetoException,
587 		lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException )
588 {
589 	vos::OGuard aGuard(Application::GetSolarMutex());
590     const SfxItemPropertySimpleEntry*  pEntry = m_pPropSet->getPropertyMap()->getByName(rPropertyName);
591     if(pEntry)
592 	{
593         if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
594             throw beans::PropertyVetoException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property is read-only: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
595 		sal_Bool bVal = sal_False;
596 		if(aValue.getValueType() == ::getBooleanCppuType())
597 			bVal = *(sal_Bool*)aValue.getValue();
598         switch(pEntry->nWID)
599 		{
600 			case WID_SEARCH_ALL :			bAll 		= bVal; break;
601 			case WID_WORDS:					bWord 		= bVal; break;
602 			case WID_BACKWARDS :            bBack 		= bVal; break;
603 			case WID_REGULAR_EXPRESSION :   bExpr 		= bVal; break;
604 			case WID_CASE_SENSITIVE  :      bCase 		= bVal; break;
605 			//case WID_IN_SELECTION  :      bInSel 		= bVal; break;
606 			case WID_STYLES          :      bStyles 	= bVal; break;
607 			case WID_SIMILARITY      :      bSimilarity = bVal; break;
608 			case WID_SIMILARITY_RELAX:      bLevRelax 	= bVal; break;
609 			case WID_SIMILARITY_EXCHANGE:	aValue >>= nLevExchange; break;
610 			case WID_SIMILARITY_ADD:		aValue >>= nLevAdd; break;
611 			case WID_SIMILARITY_REMOVE :	aValue >>= nLevRemove;break;
612 		};
613 	}
614 	else
615         throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
616 }
617 /*-- 14.12.98 13:07:13---------------------------------------------------
618 
619   -----------------------------------------------------------------------*/
getPropertyValue(const OUString & rPropertyName)620 uno::Any SwXTextSearch::getPropertyValue(const OUString& rPropertyName) throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
621 {
622 	vos::OGuard aGuard(Application::GetSolarMutex());
623 	uno::Any aRet;
624 
625     const SfxItemPropertySimpleEntry*  pEntry = m_pPropSet->getPropertyMap()->getByName(rPropertyName);
626 	sal_Bool bSet = sal_False;
627 	sal_Int16 nSet = 0;
628     if(pEntry)
629 	{
630         switch(pEntry->nWID)
631 		{
632 			case WID_SEARCH_ALL :			bSet = bAll; goto SET_BOOL;
633 			case WID_WORDS:					bSet = bWord; goto SET_BOOL;
634 			case WID_BACKWARDS :            bSet = bBack; goto SET_BOOL;
635 			case WID_REGULAR_EXPRESSION :   bSet = bExpr; goto SET_BOOL;
636 			case WID_CASE_SENSITIVE  :      bSet = bCase; goto SET_BOOL;
637 			//case WID_IN_SELECTION  :      bSet = bInSel; goto SET_BOOL;
638 			case WID_STYLES          :      bSet = bStyles; goto SET_BOOL;
639 			case WID_SIMILARITY      :      bSet = bSimilarity; goto SET_BOOL;
640 			case WID_SIMILARITY_RELAX:      bSet = bLevRelax;
641 SET_BOOL:
642 			aRet.setValue(&bSet, ::getBooleanCppuType());
643 			break;
644 			case WID_SIMILARITY_EXCHANGE:	nSet = nLevExchange; goto SET_UINT16;
645 			case WID_SIMILARITY_ADD:		nSet = nLevAdd; goto SET_UINT16;
646 			case WID_SIMILARITY_REMOVE :	nSet = nLevRemove;
647 SET_UINT16:
648 			aRet <<= nSet;
649 			break;
650 		};
651 	}
652 	else
653         throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
654 	return aRet;
655 }
656 /*-- 14.12.98 13:07:13---------------------------------------------------
657 
658   -----------------------------------------------------------------------*/
addPropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)659 void SwXTextSearch::addPropertyChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*xListener*/) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
660 {
661 	DBG_WARNING("not implemented");
662 }
663 /*-- 14.12.98 13:07:13---------------------------------------------------
664 
665   -----------------------------------------------------------------------*/
removePropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)666 void SwXTextSearch::removePropertyChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*xListener*/) throw(beans::UnknownPropertyException, lang::WrappedTargetException,uno::RuntimeException )
667 {
668 	DBG_WARNING("not implemented");
669 }
670 /*-- 14.12.98 13:07:14---------------------------------------------------
671 
672   -----------------------------------------------------------------------*/
addVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)673 void SwXTextSearch::addVetoableChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*xListener*/) throw(beans::UnknownPropertyException, lang::WrappedTargetException,uno::RuntimeException )
674 {
675 	DBG_WARNING("not implemented");
676 }
677 /*-- 14.12.98 13:07:14---------------------------------------------------
678 
679   -----------------------------------------------------------------------*/
removeVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)680 void SwXTextSearch::removeVetoableChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*xListener*/) throw(beans::UnknownPropertyException, lang::WrappedTargetException,uno::RuntimeException )
681 {
682 	DBG_WARNING("not implemented");
683 }
684 /*-- 14.12.98 13:07:14---------------------------------------------------
685 
686   -----------------------------------------------------------------------*/
getValueSearch(void)687 sal_Bool SwXTextSearch::getValueSearch(void) throw( uno::RuntimeException )
688 {
689 	vos::OGuard aGuard(Application::GetSolarMutex());
690 	return bIsValueSearch;
691 }
692 /*-- 14.12.98 13:07:15---------------------------------------------------
693 
694   -----------------------------------------------------------------------*/
setValueSearch(sal_Bool ValueSearch_)695 void SwXTextSearch::setValueSearch(sal_Bool ValueSearch_) throw( uno::RuntimeException )
696 {
697 	vos::OGuard aGuard(Application::GetSolarMutex());
698 	bIsValueSearch = ValueSearch_;
699 }
700 /*-- 14.12.98 13:07:15---------------------------------------------------
701 
702   -----------------------------------------------------------------------*/
getSearchAttributes(void)703 uno::Sequence< beans::PropertyValue > SwXTextSearch::getSearchAttributes(void) throw( uno::RuntimeException )
704 {
705 	return 	pSearchProperties->GetProperties();
706 }
707 /*-- 14.12.98 13:07:16---------------------------------------------------
708 
709   -----------------------------------------------------------------------*/
setSearchAttributes(const uno::Sequence<beans::PropertyValue> & rSearchAttribs)710 void SwXTextSearch::setSearchAttributes(const uno::Sequence< beans::PropertyValue >& rSearchAttribs)
711 	throw( beans::UnknownPropertyException, lang::IllegalArgumentException, uno::RuntimeException )
712 {
713 	pSearchProperties->SetProperties(rSearchAttribs);
714 }
715 /*-- 14.12.98 13:07:16---------------------------------------------------
716 
717   -----------------------------------------------------------------------*/
getReplaceAttributes(void)718 uno::Sequence< beans::PropertyValue > SwXTextSearch::getReplaceAttributes(void)
719 	throw( uno::RuntimeException )
720 {
721 	return pReplaceProperties->GetProperties();
722 }
723 /*-- 14.12.98 13:07:17---------------------------------------------------
724 
725   -----------------------------------------------------------------------*/
setReplaceAttributes(const uno::Sequence<beans::PropertyValue> & rReplaceAttribs)726 void SwXTextSearch::setReplaceAttributes(const uno::Sequence< beans::PropertyValue >& rReplaceAttribs)
727 	throw( beans::UnknownPropertyException, lang::IllegalArgumentException, uno::RuntimeException )
728 {
729 	pReplaceProperties->SetProperties(rReplaceAttribs);
730 }
731 /* -----------------23.06.99 14:13-------------------
732 
733  --------------------------------------------------*/
FillSearchItemSet(SfxItemSet & rSet) const734 void	SwXTextSearch::FillSearchItemSet(SfxItemSet& rSet) const
735 {
736 	pSearchProperties->FillItemSet(rSet, bIsValueSearch);
737 }
738 /* -----------------23.06.99 14:14-------------------
739 
740  --------------------------------------------------*/
FillReplaceItemSet(SfxItemSet & rSet) const741 void	SwXTextSearch::FillReplaceItemSet(SfxItemSet& rSet) const
742 {
743 	pReplaceProperties->FillItemSet(rSet, bIsValueSearch);
744 }
745 /* -----------------23.06.99 14:17-------------------
746 
747  --------------------------------------------------*/
HasSearchAttributes() const748 sal_Bool	SwXTextSearch::HasSearchAttributes() const
749 {
750 	return pSearchProperties->HasAttributes();
751 }
752 /* -----------------23.06.99 14:17-------------------
753 
754  --------------------------------------------------*/
HasReplaceAttributes() const755 sal_Bool	SwXTextSearch::HasReplaceAttributes() const
756 {
757 	return pReplaceProperties->HasAttributes();
758 }
759 /* -----------------------------19.04.00 14:43--------------------------------
760 
761  ---------------------------------------------------------------------------*/
getImplementationName(void)762 OUString SwXTextSearch::getImplementationName(void) throw( uno::RuntimeException )
763 {
764 	return C2U("SwXTextSearch");
765 }
766 /* -----------------------------19.04.00 14:43--------------------------------
767 
768  ---------------------------------------------------------------------------*/
supportsService(const OUString & rServiceName)769 sal_Bool SwXTextSearch::supportsService(const OUString& rServiceName) throw( uno::RuntimeException )
770 {
771 	return C2U("com.sun.star.util.SearchDescriptor") == rServiceName ||
772 			C2U("com.sun.star.util.ReplaceDescriptor") == rServiceName;
773 }
774 /* -----------------------------19.04.00 14:43--------------------------------
775 
776  ---------------------------------------------------------------------------*/
getSupportedServiceNames(void)777 uno::Sequence< OUString > SwXTextSearch::getSupportedServiceNames(void) throw( uno::RuntimeException )
778 {
779 	uno::Sequence< OUString > aRet(2);
780 	OUString* pArray = aRet.getArray();
781 	pArray[0] = C2U("com.sun.star.util.SearchDescriptor");
782 	pArray[1] = C2U("com.sun.star.util.ReplaceDescriptor");
783 	return aRet;
784 }
785 
FillSearchOptions(util::SearchOptions & rSearchOpt) const786 void SwXTextSearch::FillSearchOptions( util::SearchOptions& rSearchOpt ) const
787 {
788 	if( bSimilarity )
789 	{
790 		rSearchOpt.algorithmType = util::SearchAlgorithms_APPROXIMATE;
791 		rSearchOpt.changedChars = nLevExchange;
792 		rSearchOpt.deletedChars = nLevRemove;
793 		rSearchOpt.insertedChars = nLevAdd;
794 		if( bLevRelax )
795 			rSearchOpt.searchFlag |= util::SearchFlags::LEV_RELAXED;
796 	}
797 	else if( bExpr )
798 		rSearchOpt.algorithmType = util::SearchAlgorithms_REGEXP;
799 	else
800 		rSearchOpt.algorithmType = util::SearchAlgorithms_ABSOLUTE;
801 
802 	rSearchOpt.Locale = SvxCreateLocale( GetAppLanguage() );
803 	rSearchOpt.searchString = sSearchText;
804 	rSearchOpt.replaceString = sReplaceText;
805 
806 	if( !bCase )
807 		rSearchOpt.transliterateFlags |= i18n::TransliterationModules_IGNORE_CASE;
808 	if( bWord )
809 		rSearchOpt.searchFlag |= util::SearchFlags::NORM_WORD_ONLY;
810 
811 //	bInSel: 1;  // wie geht	das?
812 //	TODO: pSearch->bStyles!
813 //		inSelection??
814 //	 	aSrchParam.SetSrchInSelection(TypeConversion::toBOOL(aVal));
815 }
816 
817 
818 
819