1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: srchuno.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 #include "scitems.hxx"
37 #include <svx/srchitem.hxx>
38 #include <osl/mutex.hxx>
41 #include "srchuno.hxx"
43 #include "undoblk.hxx"
45 #include "markdata.hxx"
46 #include "unoguard.hxx"
47 #include "miscuno.hxx"
48 #include "unonames.hxx"
50 using namespace com::sun::star
;
52 //------------------------------------------------------------------------
54 //! SearchWords sucht in ganzen Zellen - umbenennen ???
56 // SfxItemPropertyMapEntry nur fuer GetPropertySetInfo
58 const SfxItemPropertyMapEntry
* lcl_GetSearchPropertyMap()
60 static SfxItemPropertyMapEntry aSearchPropertyMap_Impl
[] =
62 {MAP_CHAR_LEN(SC_UNO_SRCHBACK
), 0, &getBooleanCppuType(), 0, 0},
63 {MAP_CHAR_LEN(SC_UNO_SRCHBYROW
), 0, &getBooleanCppuType(), 0, 0},
64 {MAP_CHAR_LEN(SC_UNO_SRCHCASE
), 0, &getBooleanCppuType(), 0, 0},
65 {MAP_CHAR_LEN(SC_UNO_SRCHREGEXP
), 0, &getBooleanCppuType(), 0, 0},
66 {MAP_CHAR_LEN(SC_UNO_SRCHSIM
), 0, &getBooleanCppuType(), 0, 0},
67 {MAP_CHAR_LEN(SC_UNO_SRCHSIMADD
), 0, &getCppuType((sal_Int16
*)0), 0, 0},
68 {MAP_CHAR_LEN(SC_UNO_SRCHSIMEX
), 0, &getCppuType((sal_Int16
*)0), 0, 0},
69 {MAP_CHAR_LEN(SC_UNO_SRCHSIMREL
), 0, &getBooleanCppuType(), 0, 0},
70 {MAP_CHAR_LEN(SC_UNO_SRCHSIMREM
), 0, &getCppuType((sal_Int16
*)0), 0, 0},
71 {MAP_CHAR_LEN(SC_UNO_SRCHSTYLES
), 0, &getBooleanCppuType(), 0, 0},
72 {MAP_CHAR_LEN(SC_UNO_SRCHTYPE
), 0, &getCppuType((sal_Int16
*)0), 0, 0}, // enum TableSearch ist weg
73 {MAP_CHAR_LEN(SC_UNO_SRCHWORDS
), 0, &getBooleanCppuType(), 0, 0},
76 return aSearchPropertyMap_Impl
;
79 //------------------------------------------------------------------------
81 #define SCSEARCHDESCRIPTOR_SERVICE "com.sun.star.util.SearchDescriptor"
82 #define SCREPLACEDESCRIPTOR_SERVICE "com.sun.star.util.ReplaceDescriptor"
84 //------------------------------------------------------------------------
86 ScCellSearchObj::ScCellSearchObj() :
87 aPropSet(lcl_GetSearchPropertyMap())
89 pSearchItem
= new SvxSearchItem( SCITEM_SEARCHDATA
);
91 pSearchItem
->SetWordOnly(FALSE
);
92 pSearchItem
->SetExact(FALSE
);
93 pSearchItem
->SetMatchFullHalfWidthForms(FALSE
);
94 pSearchItem
->SetUseAsianOptions(FALSE
); // or all asian bits would have to be handled
95 pSearchItem
->SetBackward(FALSE
);
96 pSearchItem
->SetSelection(FALSE
);
97 pSearchItem
->SetRegExp(FALSE
);
98 pSearchItem
->SetPattern(FALSE
);
99 pSearchItem
->SetLevenshtein(FALSE
);
100 pSearchItem
->SetLEVRelaxed(FALSE
);
101 pSearchItem
->SetLEVOther(2);
102 pSearchItem
->SetLEVShorter(2);
103 pSearchItem
->SetLEVLonger(2);
105 pSearchItem
->SetRowDirection(FALSE
);
106 pSearchItem
->SetCellType(SVX_SEARCHIN_FORMULA
);
108 // Selection-Flag wird beim Aufruf gesetzt
111 ScCellSearchObj::~ScCellSearchObj()
118 rtl::OUString SAL_CALL
ScCellSearchObj::getSearchString() throw(uno::RuntimeException
)
121 return pSearchItem
->GetSearchString();
124 void SAL_CALL
ScCellSearchObj::setSearchString( const rtl::OUString
& aString
)
125 throw(uno::RuntimeException
)
128 pSearchItem
->SetSearchString( aString
);
131 // XReplaceDescriptor
133 rtl::OUString SAL_CALL
ScCellSearchObj::getReplaceString() throw(uno::RuntimeException
)
136 return pSearchItem
->GetReplaceString();
139 void SAL_CALL
ScCellSearchObj::setReplaceString( const rtl::OUString
& aReplaceString
)
140 throw(uno::RuntimeException
)
143 pSearchItem
->SetReplaceString( aReplaceString
);
148 uno::Reference
<beans::XPropertySetInfo
> SAL_CALL
ScCellSearchObj::getPropertySetInfo()
149 throw(uno::RuntimeException
)
152 static uno::Reference
<beans::XPropertySetInfo
> aRef(
153 new SfxItemPropertySetInfo( aPropSet
.getPropertyMap() ));
157 void SAL_CALL
ScCellSearchObj::setPropertyValue(
158 const rtl::OUString
& aPropertyName
, const uno::Any
& aValue
)
159 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
,
160 lang::IllegalArgumentException
, lang::WrappedTargetException
,
161 uno::RuntimeException
)
164 String
aString(aPropertyName
);
166 if (aString
.EqualsAscii( SC_UNO_SRCHBACK
)) pSearchItem
->SetBackward( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
167 else if (aString
.EqualsAscii( SC_UNO_SRCHBYROW
)) pSearchItem
->SetRowDirection( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
168 else if (aString
.EqualsAscii( SC_UNO_SRCHCASE
)) pSearchItem
->SetExact( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
169 else if (aString
.EqualsAscii( SC_UNO_SRCHREGEXP
)) pSearchItem
->SetRegExp( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
170 else if (aString
.EqualsAscii( SC_UNO_SRCHSIM
)) pSearchItem
->SetLevenshtein( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
171 else if (aString
.EqualsAscii( SC_UNO_SRCHSIMREL
)) pSearchItem
->SetLEVRelaxed( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
172 else if (aString
.EqualsAscii( SC_UNO_SRCHSTYLES
)) pSearchItem
->SetPattern( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
173 else if (aString
.EqualsAscii( SC_UNO_SRCHWORDS
)) pSearchItem
->SetWordOnly( ScUnoHelpFunctions::GetBoolFromAny( aValue
) );
174 else if (aString
.EqualsAscii( SC_UNO_SRCHSIMADD
)) pSearchItem
->SetLEVLonger( ScUnoHelpFunctions::GetInt16FromAny( aValue
) );
175 else if (aString
.EqualsAscii( SC_UNO_SRCHSIMEX
)) pSearchItem
->SetLEVOther( ScUnoHelpFunctions::GetInt16FromAny( aValue
) );
176 else if (aString
.EqualsAscii( SC_UNO_SRCHSIMREM
)) pSearchItem
->SetLEVShorter( ScUnoHelpFunctions::GetInt16FromAny( aValue
) );
177 else if (aString
.EqualsAscii( SC_UNO_SRCHTYPE
)) pSearchItem
->SetCellType( ScUnoHelpFunctions::GetInt16FromAny( aValue
) );
180 uno::Any SAL_CALL
ScCellSearchObj::getPropertyValue( const rtl::OUString
& aPropertyName
)
181 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
,
182 uno::RuntimeException
)
185 String
aString(aPropertyName
);
188 if (aString
.EqualsAscii( SC_UNO_SRCHBACK
)) ScUnoHelpFunctions::SetBoolInAny( aRet
, pSearchItem
->GetBackward() );
189 else if (aString
.EqualsAscii( SC_UNO_SRCHBYROW
)) ScUnoHelpFunctions::SetBoolInAny( aRet
, pSearchItem
->GetRowDirection() );
190 else if (aString
.EqualsAscii( SC_UNO_SRCHCASE
)) ScUnoHelpFunctions::SetBoolInAny( aRet
, pSearchItem
->GetExact() );
191 else if (aString
.EqualsAscii( SC_UNO_SRCHREGEXP
)) ScUnoHelpFunctions::SetBoolInAny( aRet
, pSearchItem
->GetRegExp() );
192 else if (aString
.EqualsAscii( SC_UNO_SRCHSIM
)) ScUnoHelpFunctions::SetBoolInAny( aRet
, pSearchItem
->IsLevenshtein() );
193 else if (aString
.EqualsAscii( SC_UNO_SRCHSIMREL
)) ScUnoHelpFunctions::SetBoolInAny( aRet
, pSearchItem
->IsLEVRelaxed() );
194 else if (aString
.EqualsAscii( SC_UNO_SRCHSTYLES
)) ScUnoHelpFunctions::SetBoolInAny( aRet
, pSearchItem
->GetPattern() );
195 else if (aString
.EqualsAscii( SC_UNO_SRCHWORDS
)) ScUnoHelpFunctions::SetBoolInAny( aRet
, pSearchItem
->GetWordOnly() );
196 else if (aString
.EqualsAscii( SC_UNO_SRCHSIMADD
)) aRet
<<= (sal_Int16
) pSearchItem
->GetLEVLonger();
197 else if (aString
.EqualsAscii( SC_UNO_SRCHSIMEX
)) aRet
<<= (sal_Int16
) pSearchItem
->GetLEVOther();
198 else if (aString
.EqualsAscii( SC_UNO_SRCHSIMREM
)) aRet
<<= (sal_Int16
) pSearchItem
->GetLEVShorter();
199 else if (aString
.EqualsAscii( SC_UNO_SRCHTYPE
)) aRet
<<= (sal_Int16
) pSearchItem
->GetCellType();
204 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScCellSearchObj
)
208 rtl::OUString SAL_CALL
ScCellSearchObj::getImplementationName() throw(uno::RuntimeException
)
210 return rtl::OUString::createFromAscii( "ScCellSearchObj" );
213 sal_Bool SAL_CALL
ScCellSearchObj::supportsService( const rtl::OUString
& rServiceName
)
214 throw(uno::RuntimeException
)
216 String
aServiceStr(rServiceName
);
217 return aServiceStr
.EqualsAscii( SCSEARCHDESCRIPTOR_SERVICE
) ||
218 aServiceStr
.EqualsAscii( SCREPLACEDESCRIPTOR_SERVICE
);
221 uno::Sequence
<rtl::OUString
> SAL_CALL
ScCellSearchObj::getSupportedServiceNames()
222 throw(uno::RuntimeException
)
224 uno::Sequence
<rtl::OUString
> aRet(2);
225 rtl::OUString
* pArray
= aRet
.getArray();
226 pArray
[0] = rtl::OUString::createFromAscii( SCSEARCHDESCRIPTOR_SERVICE
);
227 pArray
[1] = rtl::OUString::createFromAscii( SCREPLACEDESCRIPTOR_SERVICE
);
233 sal_Int64 SAL_CALL
ScCellSearchObj::getSomething(
234 const uno::Sequence
<sal_Int8
>& rId
) throw(uno::RuntimeException
)
236 if ( rId
.getLength() == 16 &&
237 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
238 rId
.getConstArray(), 16 ) )
240 return sal::static_int_cast
<sal_Int64
>(reinterpret_cast<sal_IntPtr
>(this));
246 const uno::Sequence
<sal_Int8
>& ScCellSearchObj::getUnoTunnelId()
248 static uno::Sequence
<sal_Int8
> * pSeq
= 0;
251 osl::Guard
< osl::Mutex
> aGuard( osl::Mutex::getGlobalMutex() );
254 static uno::Sequence
< sal_Int8
> aSeq( 16 );
255 rtl_createUuid( (sal_uInt8
*)aSeq
.getArray(), 0, sal_True
);
263 ScCellSearchObj
* ScCellSearchObj::getImplementation(
264 const uno::Reference
<util::XSearchDescriptor
> xObj
)
266 ScCellSearchObj
* pRet
= NULL
;
267 uno::Reference
<lang::XUnoTunnel
> xUT( xObj
, uno::UNO_QUERY
);
269 pRet
= reinterpret_cast<ScCellSearchObj
*>(sal::static_int_cast
<sal_IntPtr
>(xUT
->getSomething(getUnoTunnelId())));
274 //------------------------------------------------------------------------