1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "scitems.hxx"
21 #include <svl/srchitem.hxx>
22 #include <vcl/svapp.hxx>
23 #include <osl/mutex.hxx>
24 #include <comphelper/servicehelper.hxx>
26 #include "srchuno.hxx"
28 #include "undoblk.hxx"
30 #include "markdata.hxx"
31 #include "miscuno.hxx"
32 #include "unonames.hxx"
34 using namespace com::sun::star
;
36 //------------------------------------------------------------------------
38 //! SearchWords sucht in ganzen Zellen - umbenennen ???
40 // SfxItemPropertyMapEntry nur fuer GetPropertySetInfo
42 static const SfxItemPropertyMapEntry
* lcl_GetSearchPropertyMap()
44 static const SfxItemPropertyMapEntry aSearchPropertyMap_Impl
[] =
46 {MAP_CHAR_LEN(SC_UNO_SRCHBACK
), 0, &getBooleanCppuType(), 0, 0},
47 {MAP_CHAR_LEN(SC_UNO_SRCHBYROW
), 0, &getBooleanCppuType(), 0, 0},
48 {MAP_CHAR_LEN(SC_UNO_SRCHCASE
), 0, &getBooleanCppuType(), 0, 0},
49 {MAP_CHAR_LEN(SC_UNO_SRCHREGEXP
), 0, &getBooleanCppuType(), 0, 0},
50 {MAP_CHAR_LEN(SC_UNO_SRCHSIM
), 0, &getBooleanCppuType(), 0, 0},
51 {MAP_CHAR_LEN(SC_UNO_SRCHSIMADD
), 0, &getCppuType((sal_Int16
*)0), 0, 0},
52 {MAP_CHAR_LEN(SC_UNO_SRCHSIMEX
), 0, &getCppuType((sal_Int16
*)0), 0, 0},
53 {MAP_CHAR_LEN(SC_UNO_SRCHSIMREL
), 0, &getBooleanCppuType(), 0, 0},
54 {MAP_CHAR_LEN(SC_UNO_SRCHSIMREM
), 0, &getCppuType((sal_Int16
*)0), 0, 0},
55 {MAP_CHAR_LEN(SC_UNO_SRCHSTYLES
), 0, &getBooleanCppuType(), 0, 0},
56 {MAP_CHAR_LEN(SC_UNO_SRCHTYPE
), 0, &getCppuType((sal_Int16
*)0), 0, 0}, // enum TableSearch ist weg
57 {MAP_CHAR_LEN(SC_UNO_SRCHWORDS
), 0, &getBooleanCppuType(), 0, 0},
60 return aSearchPropertyMap_Impl
;
63 //------------------------------------------------------------------------
65 #define SCSEARCHDESCRIPTOR_SERVICE "com.sun.star.util.SearchDescriptor"
66 #define SCREPLACEDESCRIPTOR_SERVICE "com.sun.star.util.ReplaceDescriptor"
68 //------------------------------------------------------------------------
70 ScCellSearchObj::ScCellSearchObj() :
71 aPropSet(lcl_GetSearchPropertyMap())
73 pSearchItem
= new SvxSearchItem( SCITEM_SEARCHDATA
);
75 pSearchItem
->SetWordOnly(false);
76 pSearchItem
->SetExact(false);
77 pSearchItem
->SetMatchFullHalfWidthForms(false);
78 pSearchItem
->SetUseAsianOptions(false); // or all asian bits would have to be handled
79 pSearchItem
->SetBackward(false);
80 pSearchItem
->SetSelection(false);
81 pSearchItem
->SetRegExp(false);
82 pSearchItem
->SetPattern(false);
83 pSearchItem
->SetLevenshtein(false);
84 pSearchItem
->SetLEVRelaxed(false);
85 pSearchItem
->SetLEVOther(2);
86 pSearchItem
->SetLEVShorter(2);
87 pSearchItem
->SetLEVLonger(2);
89 pSearchItem
->SetRowDirection(false);
90 pSearchItem
->SetCellType(SVX_SEARCHIN_FORMULA
);
92 // Selection-Flag wird beim Aufruf gesetzt
95 ScCellSearchObj::~ScCellSearchObj()
102 OUString SAL_CALL
ScCellSearchObj::getSearchString() throw(uno::RuntimeException
)
104 SolarMutexGuard aGuard
;
105 return pSearchItem
->GetSearchString();
108 void SAL_CALL
ScCellSearchObj::setSearchString( const OUString
& aString
)
109 throw(uno::RuntimeException
)
111 SolarMutexGuard aGuard
;
112 pSearchItem
->SetSearchString( aString
);
115 // XReplaceDescriptor
117 OUString SAL_CALL
ScCellSearchObj::getReplaceString() throw(uno::RuntimeException
)
119 SolarMutexGuard aGuard
;
120 return pSearchItem
->GetReplaceString();
123 void SAL_CALL
ScCellSearchObj::setReplaceString( const OUString
& aReplaceString
)
124 throw(uno::RuntimeException
)
126 SolarMutexGuard aGuard
;
127 pSearchItem
->SetReplaceString( aReplaceString
);
132 uno::Reference
<beans::XPropertySetInfo
> SAL_CALL
ScCellSearchObj::getPropertySetInfo()
133 throw(uno::RuntimeException
)
135 SolarMutexGuard aGuard
;
136 static uno::Reference
<beans::XPropertySetInfo
> aRef(
137 new SfxItemPropertySetInfo( aPropSet
.getPropertyMap() ));
141 void SAL_CALL
ScCellSearchObj::setPropertyValue(
142 const OUString
& aPropertyName
, const uno::Any
& aValue
)
143 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
,
144 lang::IllegalArgumentException
, lang::WrappedTargetException
,
145 uno::RuntimeException
)
147 SolarMutexGuard aGuard
;
148 OUString
aString(aPropertyName
);
150 if (aString
.equalsAscii( SC_UNO_SRCHBACK
)) pSearchItem
->SetBackward( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
151 else if (aString
.equalsAscii( SC_UNO_SRCHBYROW
)) pSearchItem
->SetRowDirection( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
152 else if (aString
.equalsAscii( SC_UNO_SRCHCASE
)) pSearchItem
->SetExact( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
153 else if (aString
.equalsAscii( SC_UNO_SRCHREGEXP
)) pSearchItem
->SetRegExp( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
154 else if (aString
.equalsAscii( SC_UNO_SRCHSIM
)) pSearchItem
->SetLevenshtein( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
155 else if (aString
.equalsAscii( SC_UNO_SRCHSIMREL
)) pSearchItem
->SetLEVRelaxed( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
156 else if (aString
.equalsAscii( SC_UNO_SRCHSTYLES
)) pSearchItem
->SetPattern( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
157 else if (aString
.equalsAscii( SC_UNO_SRCHWORDS
)) pSearchItem
->SetWordOnly( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
158 else if (aString
.equalsAscii( SC_UNO_SRCHSIMADD
)) pSearchItem
->SetLEVLonger( ScUnoHelpFunctions::GetInt16FromAny( aValue
) );
159 else if (aString
.equalsAscii( SC_UNO_SRCHSIMEX
)) pSearchItem
->SetLEVOther( ScUnoHelpFunctions::GetInt16FromAny( aValue
) );
160 else if (aString
.equalsAscii( SC_UNO_SRCHSIMREM
)) pSearchItem
->SetLEVShorter( ScUnoHelpFunctions::GetInt16FromAny( aValue
) );
161 else if (aString
.equalsAscii( SC_UNO_SRCHTYPE
)) pSearchItem
->SetCellType( ScUnoHelpFunctions::GetInt16FromAny( aValue
) );
162 else if (aString
.equalsAscii( SC_UNO_SRCHFILTERED
)) pSearchItem
->SetSearchFiltered( ScUnoHelpFunctions::GetBoolFromAny(aValue
) );
165 uno::Any SAL_CALL
ScCellSearchObj::getPropertyValue( const OUString
& aPropertyName
)
166 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
,
167 uno::RuntimeException
)
169 SolarMutexGuard aGuard
;
170 OUString
aString(aPropertyName
);
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 else if (aString
.equalsAscii( SC_UNO_SRCHFILTERED
)) ScUnoHelpFunctions::SetBoolInAny( aRet
, pSearchItem
->IsSearchFiltered() );
190 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScCellSearchObj
)
194 OUString SAL_CALL
ScCellSearchObj::getImplementationName() throw(uno::RuntimeException
)
196 return OUString( "ScCellSearchObj" );
199 sal_Bool SAL_CALL
ScCellSearchObj::supportsService( const OUString
& rServiceName
)
200 throw(uno::RuntimeException
)
202 return rServiceName
.equalsAscii( SCSEARCHDESCRIPTOR_SERVICE
) ||
203 rServiceName
.equalsAscii( SCREPLACEDESCRIPTOR_SERVICE
);
206 uno::Sequence
<OUString
> SAL_CALL
ScCellSearchObj::getSupportedServiceNames()
207 throw(uno::RuntimeException
)
209 uno::Sequence
<OUString
> aRet(2);
210 OUString
* pArray
= aRet
.getArray();
211 pArray
[0] = OUString( SCSEARCHDESCRIPTOR_SERVICE
);
212 pArray
[1] = OUString( SCREPLACEDESCRIPTOR_SERVICE
);
218 sal_Int64 SAL_CALL
ScCellSearchObj::getSomething(
219 const uno::Sequence
<sal_Int8
>& rId
) throw(uno::RuntimeException
)
221 if ( rId
.getLength() == 16 &&
222 0 == memcmp( getUnoTunnelId().getConstArray(),
223 rId
.getConstArray(), 16 ) )
225 return sal::static_int_cast
<sal_Int64
>(reinterpret_cast<sal_IntPtr
>(this));
232 class theScCellSearchObjUnoTunnelId
: public rtl::Static
< UnoTunnelIdInit
, theScCellSearchObjUnoTunnelId
> {};
235 const uno::Sequence
<sal_Int8
>& ScCellSearchObj::getUnoTunnelId()
237 return theScCellSearchObjUnoTunnelId::get().getSeq();
240 ScCellSearchObj
* ScCellSearchObj::getImplementation(
241 const uno::Reference
<util::XSearchDescriptor
> xObj
)
243 ScCellSearchObj
* pRet
= NULL
;
244 uno::Reference
<lang::XUnoTunnel
> xUT( xObj
, uno::UNO_QUERY
);
246 pRet
= reinterpret_cast<ScCellSearchObj
*>(sal::static_int_cast
<sal_IntPtr
>(xUT
->getSomething(getUnoTunnelId())));
251 //------------------------------------------------------------------------
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */