Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "scitems.hxx"
21 : #include <svl/srchitem.hxx>
22 : #include <vcl/svapp.hxx>
23 : #include <osl/mutex.hxx>
24 : #include <comphelper/servicehelper.hxx>
25 :
26 : #include "srchuno.hxx"
27 : #include "docsh.hxx"
28 : #include "undoblk.hxx"
29 : #include "hints.hxx"
30 : #include "markdata.hxx"
31 : #include "miscuno.hxx"
32 : #include "unonames.hxx"
33 :
34 : using namespace com::sun::star;
35 :
36 : //------------------------------------------------------------------------
37 :
38 : //! SearchWords sucht in ganzen Zellen - umbenennen ???
39 :
40 : // SfxItemPropertyMapEntry nur fuer GetPropertySetInfo
41 :
42 0 : static const SfxItemPropertyMapEntry* lcl_GetSearchPropertyMap()
43 : {
44 : static SfxItemPropertyMapEntry aSearchPropertyMap_Impl[] =
45 : {
46 0 : {MAP_CHAR_LEN(SC_UNO_SRCHBACK), 0, &getBooleanCppuType(), 0, 0},
47 0 : {MAP_CHAR_LEN(SC_UNO_SRCHBYROW), 0, &getBooleanCppuType(), 0, 0},
48 0 : {MAP_CHAR_LEN(SC_UNO_SRCHCASE), 0, &getBooleanCppuType(), 0, 0},
49 0 : {MAP_CHAR_LEN(SC_UNO_SRCHREGEXP), 0, &getBooleanCppuType(), 0, 0},
50 0 : {MAP_CHAR_LEN(SC_UNO_SRCHSIM), 0, &getBooleanCppuType(), 0, 0},
51 0 : {MAP_CHAR_LEN(SC_UNO_SRCHSIMADD), 0, &getCppuType((sal_Int16*)0), 0, 0},
52 0 : {MAP_CHAR_LEN(SC_UNO_SRCHSIMEX), 0, &getCppuType((sal_Int16*)0), 0, 0},
53 0 : {MAP_CHAR_LEN(SC_UNO_SRCHSIMREL), 0, &getBooleanCppuType(), 0, 0},
54 0 : {MAP_CHAR_LEN(SC_UNO_SRCHSIMREM), 0, &getCppuType((sal_Int16*)0), 0, 0},
55 0 : {MAP_CHAR_LEN(SC_UNO_SRCHSTYLES), 0, &getBooleanCppuType(), 0, 0},
56 0 : {MAP_CHAR_LEN(SC_UNO_SRCHTYPE), 0, &getCppuType((sal_Int16*)0), 0, 0}, // enum TableSearch ist weg
57 0 : {MAP_CHAR_LEN(SC_UNO_SRCHWORDS), 0, &getBooleanCppuType(), 0, 0},
58 : {0,0,0,0,0,0}
59 0 : };
60 0 : return aSearchPropertyMap_Impl;
61 : }
62 :
63 : //------------------------------------------------------------------------
64 :
65 : #define SCSEARCHDESCRIPTOR_SERVICE "com.sun.star.util.SearchDescriptor"
66 : #define SCREPLACEDESCRIPTOR_SERVICE "com.sun.star.util.ReplaceDescriptor"
67 :
68 : //------------------------------------------------------------------------
69 :
70 0 : ScCellSearchObj::ScCellSearchObj() :
71 0 : aPropSet(lcl_GetSearchPropertyMap())
72 : {
73 0 : pSearchItem = new SvxSearchItem( SCITEM_SEARCHDATA );
74 : // Defaults:
75 0 : pSearchItem->SetWordOnly(false);
76 0 : pSearchItem->SetExact(false);
77 0 : pSearchItem->SetMatchFullHalfWidthForms(false);
78 0 : pSearchItem->SetUseAsianOptions(false); // or all asian bits would have to be handled
79 0 : pSearchItem->SetBackward(false);
80 0 : pSearchItem->SetSelection(false);
81 0 : pSearchItem->SetRegExp(false);
82 0 : pSearchItem->SetPattern(false);
83 0 : pSearchItem->SetLevenshtein(false);
84 0 : pSearchItem->SetLEVRelaxed(false);
85 0 : pSearchItem->SetLEVOther(2);
86 0 : pSearchItem->SetLEVShorter(2);
87 0 : pSearchItem->SetLEVLonger(2);
88 : // Calc-Flags
89 0 : pSearchItem->SetRowDirection(false);
90 0 : pSearchItem->SetCellType(SVX_SEARCHIN_FORMULA);
91 :
92 : // Selection-Flag wird beim Aufruf gesetzt
93 0 : }
94 :
95 0 : ScCellSearchObj::~ScCellSearchObj()
96 : {
97 0 : delete pSearchItem;
98 0 : }
99 :
100 : // XSearchDescriptor
101 :
102 0 : rtl::OUString SAL_CALL ScCellSearchObj::getSearchString() throw(uno::RuntimeException)
103 : {
104 0 : SolarMutexGuard aGuard;
105 0 : return pSearchItem->GetSearchString();
106 : }
107 :
108 0 : void SAL_CALL ScCellSearchObj::setSearchString( const rtl::OUString& aString )
109 : throw(uno::RuntimeException)
110 : {
111 0 : SolarMutexGuard aGuard;
112 0 : pSearchItem->SetSearchString( aString );
113 0 : }
114 :
115 : // XReplaceDescriptor
116 :
117 0 : rtl::OUString SAL_CALL ScCellSearchObj::getReplaceString() throw(uno::RuntimeException)
118 : {
119 0 : SolarMutexGuard aGuard;
120 0 : return pSearchItem->GetReplaceString();
121 : }
122 :
123 0 : void SAL_CALL ScCellSearchObj::setReplaceString( const rtl::OUString& aReplaceString )
124 : throw(uno::RuntimeException)
125 : {
126 0 : SolarMutexGuard aGuard;
127 0 : pSearchItem->SetReplaceString( aReplaceString );
128 0 : }
129 :
130 : // XPropertySet
131 :
132 0 : uno::Reference<beans::XPropertySetInfo> SAL_CALL ScCellSearchObj::getPropertySetInfo()
133 : throw(uno::RuntimeException)
134 : {
135 0 : SolarMutexGuard aGuard;
136 : static uno::Reference<beans::XPropertySetInfo> aRef(
137 0 : new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
138 0 : return aRef;
139 : }
140 :
141 0 : void SAL_CALL ScCellSearchObj::setPropertyValue(
142 : const rtl::OUString& aPropertyName, const uno::Any& aValue )
143 : throw(beans::UnknownPropertyException, beans::PropertyVetoException,
144 : lang::IllegalArgumentException, lang::WrappedTargetException,
145 : uno::RuntimeException)
146 : {
147 0 : SolarMutexGuard aGuard;
148 0 : String aString(aPropertyName);
149 :
150 0 : if (aString.EqualsAscii( SC_UNO_SRCHBACK )) pSearchItem->SetBackward( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
151 0 : else if (aString.EqualsAscii( SC_UNO_SRCHBYROW )) pSearchItem->SetRowDirection( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
152 0 : else if (aString.EqualsAscii( SC_UNO_SRCHCASE )) pSearchItem->SetExact( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
153 0 : else if (aString.EqualsAscii( SC_UNO_SRCHREGEXP )) pSearchItem->SetRegExp( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
154 0 : else if (aString.EqualsAscii( SC_UNO_SRCHSIM )) pSearchItem->SetLevenshtein( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
155 0 : else if (aString.EqualsAscii( SC_UNO_SRCHSIMREL )) pSearchItem->SetLEVRelaxed( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
156 0 : else if (aString.EqualsAscii( SC_UNO_SRCHSTYLES )) pSearchItem->SetPattern( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
157 0 : else if (aString.EqualsAscii( SC_UNO_SRCHWORDS )) pSearchItem->SetWordOnly( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
158 0 : else if (aString.EqualsAscii( SC_UNO_SRCHSIMADD )) pSearchItem->SetLEVLonger( ScUnoHelpFunctions::GetInt16FromAny( aValue ) );
159 0 : else if (aString.EqualsAscii( SC_UNO_SRCHSIMEX )) pSearchItem->SetLEVOther( ScUnoHelpFunctions::GetInt16FromAny( aValue ) );
160 0 : else if (aString.EqualsAscii( SC_UNO_SRCHSIMREM )) pSearchItem->SetLEVShorter( ScUnoHelpFunctions::GetInt16FromAny( aValue ) );
161 0 : else if (aString.EqualsAscii( SC_UNO_SRCHTYPE )) pSearchItem->SetCellType( ScUnoHelpFunctions::GetInt16FromAny( aValue ) );
162 0 : else if (aString.EqualsAscii( SC_UNO_SRCHFILTERED )) pSearchItem->SetSearchFiltered( ScUnoHelpFunctions::GetBoolFromAny(aValue) );
163 0 : }
164 :
165 0 : uno::Any SAL_CALL ScCellSearchObj::getPropertyValue( const rtl::OUString& aPropertyName )
166 : throw(beans::UnknownPropertyException, lang::WrappedTargetException,
167 : uno::RuntimeException)
168 : {
169 0 : SolarMutexGuard aGuard;
170 0 : String aString(aPropertyName);
171 0 : uno::Any aRet;
172 :
173 0 : if (aString.EqualsAscii( SC_UNO_SRCHBACK )) ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->GetBackward() );
174 0 : else if (aString.EqualsAscii( SC_UNO_SRCHBYROW )) ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->GetRowDirection() );
175 0 : else if (aString.EqualsAscii( SC_UNO_SRCHCASE )) ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->GetExact() );
176 0 : else if (aString.EqualsAscii( SC_UNO_SRCHREGEXP )) ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->GetRegExp() );
177 0 : else if (aString.EqualsAscii( SC_UNO_SRCHSIM )) ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->IsLevenshtein() );
178 0 : else if (aString.EqualsAscii( SC_UNO_SRCHSIMREL )) ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->IsLEVRelaxed() );
179 0 : else if (aString.EqualsAscii( SC_UNO_SRCHSTYLES )) ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->GetPattern() );
180 0 : else if (aString.EqualsAscii( SC_UNO_SRCHWORDS )) ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->GetWordOnly() );
181 0 : else if (aString.EqualsAscii( SC_UNO_SRCHSIMADD )) aRet <<= (sal_Int16) pSearchItem->GetLEVLonger();
182 0 : else if (aString.EqualsAscii( SC_UNO_SRCHSIMEX )) aRet <<= (sal_Int16) pSearchItem->GetLEVOther();
183 0 : else if (aString.EqualsAscii( SC_UNO_SRCHSIMREM )) aRet <<= (sal_Int16) pSearchItem->GetLEVShorter();
184 0 : else if (aString.EqualsAscii( SC_UNO_SRCHTYPE )) aRet <<= (sal_Int16) pSearchItem->GetCellType();
185 0 : else if (aString.EqualsAscii( SC_UNO_SRCHFILTERED )) ScUnoHelpFunctions::SetBoolInAny( aRet, pSearchItem->IsSearchFiltered() );
186 :
187 0 : return aRet;
188 : }
189 :
190 0 : SC_IMPL_DUMMY_PROPERTY_LISTENER( ScCellSearchObj )
191 :
192 : // XServiceInfo
193 :
194 0 : rtl::OUString SAL_CALL ScCellSearchObj::getImplementationName() throw(uno::RuntimeException)
195 : {
196 0 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ScCellSearchObj" ));
197 : }
198 :
199 0 : sal_Bool SAL_CALL ScCellSearchObj::supportsService( const rtl::OUString& rServiceName )
200 : throw(uno::RuntimeException)
201 : {
202 0 : String aServiceStr(rServiceName);
203 0 : return aServiceStr.EqualsAscii( SCSEARCHDESCRIPTOR_SERVICE ) ||
204 0 : aServiceStr.EqualsAscii( SCREPLACEDESCRIPTOR_SERVICE );
205 : }
206 :
207 0 : uno::Sequence<rtl::OUString> SAL_CALL ScCellSearchObj::getSupportedServiceNames()
208 : throw(uno::RuntimeException)
209 : {
210 0 : uno::Sequence<rtl::OUString> aRet(2);
211 0 : rtl::OUString* pArray = aRet.getArray();
212 0 : pArray[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCSEARCHDESCRIPTOR_SERVICE ));
213 0 : pArray[1] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCREPLACEDESCRIPTOR_SERVICE ));
214 0 : return aRet;
215 : }
216 :
217 : // XUnoTunnel
218 :
219 0 : sal_Int64 SAL_CALL ScCellSearchObj::getSomething(
220 : const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException)
221 : {
222 0 : if ( rId.getLength() == 16 &&
223 0 : 0 == memcmp( getUnoTunnelId().getConstArray(),
224 0 : rId.getConstArray(), 16 ) )
225 : {
226 0 : return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
227 : }
228 0 : return 0;
229 : }
230 :
231 : namespace
232 : {
233 : class theScCellSearchObjUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theScCellSearchObjUnoTunnelId> {};
234 : }
235 :
236 0 : const uno::Sequence<sal_Int8>& ScCellSearchObj::getUnoTunnelId()
237 : {
238 0 : return theScCellSearchObjUnoTunnelId::get().getSeq();
239 : }
240 :
241 0 : ScCellSearchObj* ScCellSearchObj::getImplementation(
242 : const uno::Reference<util::XSearchDescriptor> xObj )
243 : {
244 0 : ScCellSearchObj* pRet = NULL;
245 0 : uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
246 0 : if (xUT.is())
247 0 : pRet = reinterpret_cast<ScCellSearchObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
248 0 : return pRet;
249 : }
250 :
251 :
252 : //------------------------------------------------------------------------
253 :
254 :
255 :
256 :
257 :
258 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|