xref: /trunk/main/sc/source/ui/unoobj/srchuno.cxx (revision 45c5a00162811bd03b87fcb4fe9996782f2b59ec)
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 
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 
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 
104 ScCellSearchObj::~ScCellSearchObj()
105 {
106     delete pSearchItem;
107 }
108 
109 // XSearchDescriptor
110 
111 rtl::OUString SAL_CALL ScCellSearchObj::getSearchString()
112 {
113     ScUnoGuard aGuard;
114     return pSearchItem->GetSearchString();
115 }
116 
117 void SAL_CALL ScCellSearchObj::setSearchString( const rtl::OUString& aString )
118 {
119     ScUnoGuard aGuard;
120     pSearchItem->SetSearchString( aString );
121 }
122 
123 // XReplaceDescriptor
124 
125 rtl::OUString SAL_CALL ScCellSearchObj::getReplaceString()
126 {
127     ScUnoGuard aGuard;
128     return pSearchItem->GetReplaceString();
129 }
130 
131 void SAL_CALL ScCellSearchObj::setReplaceString( const rtl::OUString& aReplaceString )
132 {
133     ScUnoGuard aGuard;
134     pSearchItem->SetReplaceString( aReplaceString );
135 }
136 
137 // XPropertySet
138 
139 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScCellSearchObj::getPropertySetInfo()
140 {
141     ScUnoGuard aGuard;
142     static uno::Reference<beans::XPropertySetInfo> aRef(
143         new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
144     return aRef;
145 }
146 
147 void SAL_CALL ScCellSearchObj::setPropertyValue(
148                         const rtl::OUString& aPropertyName, const uno::Any& aValue )
149 {
150     ScUnoGuard aGuard;
151     String aString(aPropertyName);
152 
153     if (aString.EqualsAscii( SC_UNO_SRCHBACK ))        pSearchItem->SetBackward( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
154     else if (aString.EqualsAscii( SC_UNO_SRCHBYROW ))  pSearchItem->SetRowDirection( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
155     else if (aString.EqualsAscii( SC_UNO_SRCHCASE ))   pSearchItem->SetExact( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
156     else if (aString.EqualsAscii( SC_UNO_SRCHREGEXP )) pSearchItem->SetRegExp( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
157     else if (aString.EqualsAscii( SC_UNO_SRCHSIM ))    pSearchItem->SetLevenshtein( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
158     else if (aString.EqualsAscii( SC_UNO_SRCHSIMREL )) pSearchItem->SetLEVRelaxed( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
159     else if (aString.EqualsAscii( SC_UNO_SRCHSTYLES )) pSearchItem->SetPattern( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
160     else if (aString.EqualsAscii( SC_UNO_SRCHWORDS ))  pSearchItem->SetWordOnly( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
161     else if (aString.EqualsAscii( SC_UNO_SRCHSIMADD )) pSearchItem->SetLEVLonger( ScUnoHelpFunctions::GetInt16FromAny( aValue ) );
162     else if (aString.EqualsAscii( SC_UNO_SRCHSIMEX ))  pSearchItem->SetLEVOther( ScUnoHelpFunctions::GetInt16FromAny( aValue ) );
163     else if (aString.EqualsAscii( SC_UNO_SRCHSIMREM )) pSearchItem->SetLEVShorter( ScUnoHelpFunctions::GetInt16FromAny( aValue ) );
164     else if (aString.EqualsAscii( SC_UNO_SRCHTYPE ))   pSearchItem->SetCellType( ScUnoHelpFunctions::GetInt16FromAny( aValue ) );
165 }
166 
167 uno::Any SAL_CALL ScCellSearchObj::getPropertyValue( const rtl::OUString& aPropertyName )
168 {
169     ScUnoGuard aGuard;
170     String aString(aPropertyName);
171     uno::Any aRet;
172 
173     if (aString.EqualsAscii( SC_UNO_SRCHBACK ))        ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->GetBackward() );
174     else if (aString.EqualsAscii( SC_UNO_SRCHBYROW ))  ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->GetRowDirection() );
175     else if (aString.EqualsAscii( SC_UNO_SRCHCASE ))   ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->GetExact() );
176     else if (aString.EqualsAscii( SC_UNO_SRCHREGEXP )) ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->GetRegExp() );
177     else if (aString.EqualsAscii( SC_UNO_SRCHSIM ))    ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->IsLevenshtein() );
178     else if (aString.EqualsAscii( SC_UNO_SRCHSIMREL )) ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->IsLEVRelaxed() );
179     else if (aString.EqualsAscii( SC_UNO_SRCHSTYLES )) ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->GetPattern() );
180     else if (aString.EqualsAscii( SC_UNO_SRCHWORDS ))  ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->GetWordOnly() );
181     else if (aString.EqualsAscii( SC_UNO_SRCHSIMADD )) aRet <<= (sal_Int16) pSearchItem->GetLEVLonger();
182     else if (aString.EqualsAscii( SC_UNO_SRCHSIMEX ))  aRet <<= (sal_Int16) pSearchItem->GetLEVOther();
183     else if (aString.EqualsAscii( SC_UNO_SRCHSIMREM )) aRet <<= (sal_Int16) pSearchItem->GetLEVShorter();
184     else if (aString.EqualsAscii( SC_UNO_SRCHTYPE ))   aRet <<= (sal_Int16) pSearchItem->GetCellType();
185 
186     return aRet;
187 }
188 
189 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScCellSearchObj )
190 
191 // XServiceInfo
192 
193 rtl::OUString SAL_CALL ScCellSearchObj::getImplementationName()
194 {
195     return rtl::OUString::createFromAscii( "ScCellSearchObj" );
196 }
197 
198 sal_Bool SAL_CALL ScCellSearchObj::supportsService( const rtl::OUString& rServiceName )
199 {
200     String aServiceStr(rServiceName);
201     return aServiceStr.EqualsAscii( SCSEARCHDESCRIPTOR_SERVICE ) ||
202            aServiceStr.EqualsAscii( SCREPLACEDESCRIPTOR_SERVICE );
203 }
204 
205 uno::Sequence<rtl::OUString> SAL_CALL ScCellSearchObj::getSupportedServiceNames()
206 {
207     uno::Sequence<rtl::OUString> aRet(2);
208     rtl::OUString* pArray = aRet.getArray();
209     pArray[0] = rtl::OUString::createFromAscii( SCSEARCHDESCRIPTOR_SERVICE );
210     pArray[1] = rtl::OUString::createFromAscii( SCREPLACEDESCRIPTOR_SERVICE );
211     return aRet;
212 }
213 
214 // XUnoTunnel
215 
216 sal_Int64 SAL_CALL ScCellSearchObj::getSomething(
217                 const uno::Sequence<sal_Int8 >& rId )
218 {
219     if ( rId.getLength() == 16 &&
220           0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
221                                     rId.getConstArray(), 16 ) )
222     {
223         return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
224     }
225     return 0;
226 }
227 
228 // static
229 const uno::Sequence<sal_Int8>& ScCellSearchObj::getUnoTunnelId()
230 {
231     static uno::Sequence<sal_Int8> * pSeq = 0;
232     if( !pSeq )
233     {
234         osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
235         if( !pSeq )
236         {
237             static uno::Sequence< sal_Int8 > aSeq( 16 );
238             rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
239             pSeq = &aSeq;
240         }
241     }
242     return *pSeq;
243 }
244 
245 // static
246 ScCellSearchObj* ScCellSearchObj::getImplementation(
247                                 const uno::Reference<util::XSearchDescriptor> xObj )
248 {
249     ScCellSearchObj* pRet = NULL;
250     uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
251     if (xUT.is())
252         pRet = reinterpret_cast<ScCellSearchObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
253     return pRet;
254 }
255 
256 
257 //------------------------------------------------------------------------
258