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>
25 #include <cppuhelper/supportsservice.hxx>
27 #include "srchuno.hxx"
29 #include "undoblk.hxx"
31 #include "markdata.hxx"
32 #include "miscuno.hxx"
33 #include "unonames.hxx"
35 using namespace com::sun::star
;
37 //! SearchWords sucht in ganzen Zellen - umbenennen ???
39 // SfxItemPropertyMapEntry nur fuer GetPropertySetInfo
41 static const SfxItemPropertyMapEntry
* lcl_GetSearchPropertyMap()
43 static const SfxItemPropertyMapEntry aSearchPropertyMap_Impl
[] =
45 {OUString(SC_UNO_SRCHBACK
), 0, cppu::UnoType
<bool>::get(), 0, 0},
46 {OUString(SC_UNO_SRCHBYROW
), 0, cppu::UnoType
<bool>::get(), 0, 0},
47 {OUString(SC_UNO_SRCHCASE
), 0, cppu::UnoType
<bool>::get(), 0, 0},
48 {OUString(SC_UNO_SRCHREGEXP
), 0, cppu::UnoType
<bool>::get(), 0, 0},
49 {OUString(SC_UNO_SRCHSIM
), 0, cppu::UnoType
<bool>::get(), 0, 0},
50 {OUString(SC_UNO_SRCHSIMADD
), 0, cppu::UnoType
<sal_Int16
>::get(), 0, 0},
51 {OUString(SC_UNO_SRCHSIMEX
), 0, cppu::UnoType
<sal_Int16
>::get(), 0, 0},
52 {OUString(SC_UNO_SRCHSIMREL
), 0, cppu::UnoType
<bool>::get(), 0, 0},
53 {OUString(SC_UNO_SRCHSIMREM
), 0, cppu::UnoType
<sal_Int16
>::get(), 0, 0},
54 {OUString(SC_UNO_SRCHSTYLES
), 0, cppu::UnoType
<bool>::get(), 0, 0},
55 {OUString(SC_UNO_SRCHTYPE
), 0, cppu::UnoType
<sal_Int16
>::get(), 0, 0}, // enum TableSearch ist weg
56 {OUString(SC_UNO_SRCHWORDS
), 0, cppu::UnoType
<bool>::get(), 0, 0},
57 { OUString(), 0, css::uno::Type(), 0, 0 }
59 return aSearchPropertyMap_Impl
;
62 #define SCSEARCHDESCRIPTOR_SERVICE "com.sun.star.util.SearchDescriptor"
63 #define SCREPLACEDESCRIPTOR_SERVICE "com.sun.star.util.ReplaceDescriptor"
65 ScCellSearchObj::ScCellSearchObj() :
66 aPropSet(lcl_GetSearchPropertyMap())
68 pSearchItem
= new SvxSearchItem( SCITEM_SEARCHDATA
);
70 pSearchItem
->SetWordOnly(false);
71 pSearchItem
->SetExact(false);
72 pSearchItem
->SetMatchFullHalfWidthForms(false);
73 pSearchItem
->SetUseAsianOptions(false); // or all asian bits would have to be handled
74 pSearchItem
->SetBackward(false);
75 pSearchItem
->SetSelection(false);
76 pSearchItem
->SetRegExp(false);
77 pSearchItem
->SetPattern(false);
78 pSearchItem
->SetLevenshtein(false);
79 pSearchItem
->SetLEVRelaxed(false);
80 pSearchItem
->SetLEVOther(2);
81 pSearchItem
->SetLEVShorter(2);
82 pSearchItem
->SetLEVLonger(2);
84 pSearchItem
->SetRowDirection(false);
85 pSearchItem
->SetCellType(SvxSearchCellType::FORMULA
);
87 // Selection-Flag wird beim Aufruf gesetzt
90 ScCellSearchObj::~ScCellSearchObj()
97 OUString SAL_CALL
ScCellSearchObj::getSearchString() throw(uno::RuntimeException
, std::exception
)
99 SolarMutexGuard aGuard
;
100 return pSearchItem
->GetSearchString();
103 void SAL_CALL
ScCellSearchObj::setSearchString( const OUString
& aString
)
104 throw(uno::RuntimeException
, std::exception
)
106 SolarMutexGuard aGuard
;
107 pSearchItem
->SetSearchString( aString
);
110 // XReplaceDescriptor
112 OUString SAL_CALL
ScCellSearchObj::getReplaceString() throw(uno::RuntimeException
, std::exception
)
114 SolarMutexGuard aGuard
;
115 return pSearchItem
->GetReplaceString();
118 void SAL_CALL
ScCellSearchObj::setReplaceString( const OUString
& aReplaceString
)
119 throw(uno::RuntimeException
, std::exception
)
121 SolarMutexGuard aGuard
;
122 pSearchItem
->SetReplaceString( aReplaceString
);
127 uno::Reference
<beans::XPropertySetInfo
> SAL_CALL
ScCellSearchObj::getPropertySetInfo()
128 throw(uno::RuntimeException
, std::exception
)
130 SolarMutexGuard aGuard
;
131 static uno::Reference
<beans::XPropertySetInfo
> aRef(
132 new SfxItemPropertySetInfo( aPropSet
.getPropertyMap() ));
136 void SAL_CALL
ScCellSearchObj::setPropertyValue(
137 const OUString
& aPropertyName
, const uno::Any
& aValue
)
138 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
,
139 lang::IllegalArgumentException
, lang::WrappedTargetException
,
140 uno::RuntimeException
, std::exception
)
142 SolarMutexGuard aGuard
;
143 OUString
aString(aPropertyName
);
145 if (aString
== SC_UNO_SRCHBACK
) pSearchItem
->SetBackward( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
146 else if (aString
== SC_UNO_SRCHBYROW
) pSearchItem
->SetRowDirection( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
147 else if (aString
== SC_UNO_SRCHCASE
) pSearchItem
->SetExact( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
148 else if (aString
== SC_UNO_SRCHREGEXP
) pSearchItem
->SetRegExp( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
149 else if (aString
== SC_UNO_SRCHSIM
) pSearchItem
->SetLevenshtein( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
150 else if (aString
== SC_UNO_SRCHSIMREL
) pSearchItem
->SetLEVRelaxed( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
151 else if (aString
== SC_UNO_SRCHSTYLES
) pSearchItem
->SetPattern( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
152 else if (aString
== SC_UNO_SRCHWORDS
) pSearchItem
->SetWordOnly( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
153 else if (aString
== SC_UNO_SRCHSIMADD
) pSearchItem
->SetLEVLonger( ScUnoHelpFunctions::GetInt16FromAny( aValue
) );
154 else if (aString
== SC_UNO_SRCHSIMEX
) pSearchItem
->SetLEVOther( ScUnoHelpFunctions::GetInt16FromAny( aValue
) );
155 else if (aString
== SC_UNO_SRCHSIMREM
) pSearchItem
->SetLEVShorter( ScUnoHelpFunctions::GetInt16FromAny( aValue
) );
156 else if (aString
== SC_UNO_SRCHTYPE
) pSearchItem
->SetCellType( static_cast<SvxSearchCellType
>(ScUnoHelpFunctions::GetInt16FromAny( aValue
)) );
157 else if (aString
== SC_UNO_SRCHFILTERED
) pSearchItem
->SetSearchFiltered( ScUnoHelpFunctions::GetBoolFromAny(aValue
) );
160 uno::Any SAL_CALL
ScCellSearchObj::getPropertyValue( const OUString
& aPropertyName
)
161 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
,
162 uno::RuntimeException
, std::exception
)
164 SolarMutexGuard aGuard
;
165 OUString
aString(aPropertyName
);
168 if (aString
== SC_UNO_SRCHBACK
) ScUnoHelpFunctions::SetBoolInAny( aRet
, pSearchItem
->GetBackward() );
169 else if (aString
== SC_UNO_SRCHBYROW
) ScUnoHelpFunctions::SetBoolInAny( aRet
, pSearchItem
->GetRowDirection() );
170 else if (aString
== SC_UNO_SRCHCASE
) ScUnoHelpFunctions::SetBoolInAny( aRet
, pSearchItem
->GetExact() );
171 else if (aString
== SC_UNO_SRCHREGEXP
) ScUnoHelpFunctions::SetBoolInAny( aRet
, pSearchItem
->GetRegExp() );
172 else if (aString
== SC_UNO_SRCHSIM
) ScUnoHelpFunctions::SetBoolInAny( aRet
, pSearchItem
->IsLevenshtein() );
173 else if (aString
== SC_UNO_SRCHSIMREL
) ScUnoHelpFunctions::SetBoolInAny( aRet
, pSearchItem
->IsLEVRelaxed() );
174 else if (aString
== SC_UNO_SRCHSTYLES
) ScUnoHelpFunctions::SetBoolInAny( aRet
, pSearchItem
->GetPattern() );
175 else if (aString
== SC_UNO_SRCHWORDS
) ScUnoHelpFunctions::SetBoolInAny( aRet
, pSearchItem
->GetWordOnly() );
176 else if (aString
== SC_UNO_SRCHSIMADD
) aRet
<<= (sal_Int16
) pSearchItem
->GetLEVLonger();
177 else if (aString
== SC_UNO_SRCHSIMEX
) aRet
<<= (sal_Int16
) pSearchItem
->GetLEVOther();
178 else if (aString
== SC_UNO_SRCHSIMREM
) aRet
<<= (sal_Int16
) pSearchItem
->GetLEVShorter();
179 else if (aString
== SC_UNO_SRCHTYPE
) aRet
<<= (sal_Int16
) pSearchItem
->GetCellType();
180 else if (aString
== SC_UNO_SRCHFILTERED
) ScUnoHelpFunctions::SetBoolInAny( aRet
, pSearchItem
->IsSearchFiltered() );
185 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScCellSearchObj
)
189 OUString SAL_CALL
ScCellSearchObj::getImplementationName() throw(uno::RuntimeException
, std::exception
)
191 return OUString( "ScCellSearchObj" );
194 sal_Bool SAL_CALL
ScCellSearchObj::supportsService( const OUString
& rServiceName
)
195 throw(uno::RuntimeException
, std::exception
)
197 return cppu::supportsService(this, rServiceName
);
200 uno::Sequence
<OUString
> SAL_CALL
ScCellSearchObj::getSupportedServiceNames()
201 throw(uno::RuntimeException
, std::exception
)
203 uno::Sequence
<OUString
> aRet(2);
204 OUString
* pArray
= aRet
.getArray();
205 pArray
[0] = SCSEARCHDESCRIPTOR_SERVICE
;
206 pArray
[1] = SCREPLACEDESCRIPTOR_SERVICE
;
212 sal_Int64 SAL_CALL
ScCellSearchObj::getSomething(
213 const uno::Sequence
<sal_Int8
>& rId
) throw(uno::RuntimeException
, std::exception
)
215 if ( rId
.getLength() == 16 &&
216 0 == memcmp( getUnoTunnelId().getConstArray(),
217 rId
.getConstArray(), 16 ) )
219 return sal::static_int_cast
<sal_Int64
>(reinterpret_cast<sal_IntPtr
>(this));
226 class theScCellSearchObjUnoTunnelId
: public rtl::Static
< UnoTunnelIdInit
, theScCellSearchObjUnoTunnelId
> {};
229 const uno::Sequence
<sal_Int8
>& ScCellSearchObj::getUnoTunnelId()
231 return theScCellSearchObjUnoTunnelId::get().getSeq();
234 ScCellSearchObj
* ScCellSearchObj::getImplementation(const uno::Reference
<util::XSearchDescriptor
>& rObj
)
236 ScCellSearchObj
* pRet
= NULL
;
237 uno::Reference
<lang::XUnoTunnel
> xUT(rObj
, uno::UNO_QUERY
);
239 pRet
= reinterpret_cast<ScCellSearchObj
*>(sal::static_int_cast
<sal_IntPtr
>(xUT
->getSomething(getUnoTunnelId())));
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */