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