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