Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/source/ui/unoobj/srchuno.cxx
Line
Count
Source
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 <cppuhelper/supportsservice.hxx>
24
25
#include <srchuno.hxx>
26
#include <miscuno.hxx>
27
#include <unonames.hxx>
28
29
using namespace com::sun::star;
30
31
//! SearchWords searches in whole cells - rename it ???
32
33
//  SfxItemPropertyMapEntry only for GetPropertySetInfo
34
35
static std::span<const SfxItemPropertyMapEntry> lcl_GetSearchPropertyMap()
36
0
{
37
0
    static const SfxItemPropertyMapEntry aSearchPropertyMap_Impl[] =
38
0
    {
39
0
        { SC_UNO_SRCHBACK,     0,      cppu::UnoType<bool>::get(),       0, 0},
40
0
        { SC_UNO_SRCHBYROW,    0,      cppu::UnoType<bool>::get(),       0, 0},
41
0
        { SC_UNO_SRCHCASE,     0,      cppu::UnoType<bool>::get(),       0, 0},
42
0
        { SC_UNO_SRCHREGEXP,   0,      cppu::UnoType<bool>::get(),       0, 0},
43
0
        { SC_UNO_SRCHWILDCARD, 0,      cppu::UnoType<bool>::get(),       0, 0},
44
0
        { SC_UNO_SRCHSIM,      0,      cppu::UnoType<bool>::get(),       0, 0},
45
0
        { SC_UNO_SRCHSIMADD,   0,      cppu::UnoType<sal_Int16>::get(), 0, 0},
46
0
        { SC_UNO_SRCHSIMEX,    0,      cppu::UnoType<sal_Int16>::get(), 0, 0},
47
0
        { SC_UNO_SRCHSIMREL,   0,      cppu::UnoType<bool>::get(),       0, 0},
48
0
        { SC_UNO_SRCHSIMREM,   0,      cppu::UnoType<sal_Int16>::get(), 0, 0},
49
0
        { SC_UNO_SRCHSTYLES,   0,      cppu::UnoType<bool>::get(),       0, 0},
50
0
        { SC_UNO_SRCHTYPE,     0,      cppu::UnoType<sal_Int16>::get(), 0, 0}, // enum TableSearch is gone
51
0
        { SC_UNO_SRCHWORDS,    0,      cppu::UnoType<bool>::get(),       0, 0},
52
0
        { SC_UNO_SRCHFILTERED,  0,     cppu::UnoType<bool>::get(),      0, 0 },
53
0
        { SC_UNO_SRCHFORMATTED, 0,     cppu::UnoType<bool>::get(),      0, 0 },
54
0
        { SC_UNO_SRCHWCESCCHAR, 0,     cppu::UnoType<sal_Int32>::get(), 0, 0 },
55
0
    };
56
0
    return aSearchPropertyMap_Impl;
57
0
}
58
59
constexpr OUString SCSEARCHDESCRIPTOR_SERVICE = u"com.sun.star.util.SearchDescriptor"_ustr;
60
constexpr OUString SCREPLACEDESCRIPTOR_SERVICE = u"com.sun.star.util.ReplaceDescriptor"_ustr;
61
62
ScCellSearchObj::ScCellSearchObj() :
63
0
    aPropSet(lcl_GetSearchPropertyMap()),
64
0
    pSearchItem( new SvxSearchItem( SCITEM_SEARCHDATA ) )
65
0
{
66
    //  Defaults:
67
0
    pSearchItem->SetWordOnly(false);
68
0
    pSearchItem->SetExact(false);
69
0
    pSearchItem->SetMatchFullHalfWidthForms(false);
70
0
    pSearchItem->SetUseAsianOptions(false);     // or all asian bits would have to be handled
71
0
    pSearchItem->SetBackward(false);
72
0
    pSearchItem->SetSelection(false);
73
0
    pSearchItem->SetRegExp(false);
74
0
    pSearchItem->SetWildcard(false);
75
0
    pSearchItem->SetPattern(false);
76
0
    pSearchItem->SetLevenshtein(false);
77
0
    pSearchItem->SetLEVRelaxed(false);
78
0
    pSearchItem->SetLEVOther(2);
79
0
    pSearchItem->SetLEVShorter(2);
80
0
    pSearchItem->SetLEVLonger(2);
81
    //  Calc-Flags
82
0
    pSearchItem->SetRowDirection(false);
83
0
    pSearchItem->SetCellType(SvxSearchCellType::FORMULA);
84
85
    //  Selection-Flag will be set when this is called
86
0
}
87
88
ScCellSearchObj::~ScCellSearchObj()
89
0
{
90
0
}
91
92
// XSearchDescriptor
93
94
OUString SAL_CALL ScCellSearchObj::getSearchString()
95
0
{
96
0
    SolarMutexGuard aGuard;
97
0
    return pSearchItem->GetSearchString();
98
0
}
99
100
void SAL_CALL ScCellSearchObj::setSearchString( const OUString& aString )
101
0
{
102
0
    SolarMutexGuard aGuard;
103
0
    pSearchItem->SetSearchString( aString );
104
0
}
105
106
// XReplaceDescriptor
107
108
OUString SAL_CALL ScCellSearchObj::getReplaceString()
109
0
{
110
0
    SolarMutexGuard aGuard;
111
0
    return pSearchItem->GetReplaceString();
112
0
}
113
114
void SAL_CALL ScCellSearchObj::setReplaceString( const OUString& aReplaceString )
115
0
{
116
0
    SolarMutexGuard aGuard;
117
0
    pSearchItem->SetReplaceString( aReplaceString );
118
0
}
119
120
// XPropertySet
121
122
uno::Reference<beans::XPropertySetInfo> SAL_CALL ScCellSearchObj::getPropertySetInfo()
123
0
{
124
0
    SolarMutexGuard aGuard;
125
0
    static uno::Reference<beans::XPropertySetInfo> aRef(
126
0
        new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
127
0
    return aRef;
128
0
}
129
130
void SAL_CALL ScCellSearchObj::setPropertyValue(
131
                        const OUString& aPropertyName, const uno::Any& aValue )
132
0
{
133
0
    SolarMutexGuard aGuard;
134
135
0
    if (aPropertyName == SC_UNO_SRCHBACK)        pSearchItem->SetBackward( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
136
0
    else if (aPropertyName == SC_UNO_SRCHBYROW)  pSearchItem->SetRowDirection( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
137
0
    else if (aPropertyName == SC_UNO_SRCHCASE)   pSearchItem->SetExact( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
138
0
    else if (aPropertyName == SC_UNO_SRCHREGEXP) pSearchItem->SetRegExp( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
139
0
    else if (aPropertyName == SC_UNO_SRCHWILDCARD) pSearchItem->SetWildcard( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
140
0
    else if (aPropertyName == SC_UNO_SRCHSIM)    pSearchItem->SetLevenshtein( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
141
0
    else if (aPropertyName == SC_UNO_SRCHSIMREL) pSearchItem->SetLEVRelaxed( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
142
0
    else if (aPropertyName == SC_UNO_SRCHSTYLES) pSearchItem->SetPattern( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
143
0
    else if (aPropertyName == SC_UNO_SRCHWORDS)  pSearchItem->SetWordOnly( ScUnoHelpFunctions::GetBoolFromAny( aValue ) );
144
0
    else if (aPropertyName == SC_UNO_SRCHSIMADD) pSearchItem->SetLEVLonger( ScUnoHelpFunctions::GetInt16FromAny( aValue ) );
145
0
    else if (aPropertyName == SC_UNO_SRCHSIMEX)  pSearchItem->SetLEVOther( ScUnoHelpFunctions::GetInt16FromAny( aValue ) );
146
0
    else if (aPropertyName == SC_UNO_SRCHSIMREM) pSearchItem->SetLEVShorter( ScUnoHelpFunctions::GetInt16FromAny( aValue ) );
147
0
    else if (aPropertyName == SC_UNO_SRCHTYPE)   pSearchItem->SetCellType( static_cast<SvxSearchCellType>(ScUnoHelpFunctions::GetInt16FromAny( aValue )) );
148
0
    else if (aPropertyName == SC_UNO_SRCHFILTERED) pSearchItem->SetSearchFiltered( ScUnoHelpFunctions::GetBoolFromAny(aValue) );
149
0
    else if (aPropertyName == SC_UNO_SRCHFORMATTED) pSearchItem->SetSearchFormatted( ScUnoHelpFunctions::GetBoolFromAny(aValue) );
150
0
    else if (aPropertyName == SC_UNO_SRCHWCESCCHAR) pSearchItem->SetWildcardEscapeCharacter( ScUnoHelpFunctions::GetInt32FromAny(aValue) );
151
0
}
152
153
uno::Any SAL_CALL ScCellSearchObj::getPropertyValue( const OUString& aPropertyName )
154
0
{
155
0
    SolarMutexGuard aGuard;
156
0
    uno::Any aRet;
157
158
0
    if (aPropertyName == SC_UNO_SRCHBACK)        aRet <<= pSearchItem->GetBackward();
159
0
    else if (aPropertyName == SC_UNO_SRCHBYROW)  aRet <<= pSearchItem->GetRowDirection();
160
0
    else if (aPropertyName == SC_UNO_SRCHCASE)   aRet <<= pSearchItem->GetExact();
161
0
    else if (aPropertyName == SC_UNO_SRCHREGEXP) aRet <<= pSearchItem->GetRegExp();
162
0
    else if (aPropertyName == SC_UNO_SRCHWILDCARD) aRet <<= pSearchItem->GetWildcard();
163
0
    else if (aPropertyName == SC_UNO_SRCHSIM)    aRet <<= pSearchItem->IsLevenshtein();
164
0
    else if (aPropertyName == SC_UNO_SRCHSIMREL) aRet <<= pSearchItem->IsLEVRelaxed();
165
0
    else if (aPropertyName == SC_UNO_SRCHSTYLES) aRet <<= pSearchItem->GetPattern();
166
0
    else if (aPropertyName == SC_UNO_SRCHWORDS)  aRet <<= pSearchItem->GetWordOnly();
167
0
    else if (aPropertyName == SC_UNO_SRCHSIMADD) aRet <<= static_cast<sal_Int16>(pSearchItem->GetLEVLonger());
168
0
    else if (aPropertyName == SC_UNO_SRCHSIMEX)  aRet <<= static_cast<sal_Int16>(pSearchItem->GetLEVOther());
169
0
    else if (aPropertyName == SC_UNO_SRCHSIMREM) aRet <<= static_cast<sal_Int16>(pSearchItem->GetLEVShorter());
170
0
    else if (aPropertyName == SC_UNO_SRCHTYPE)   aRet <<= static_cast<sal_Int16>(pSearchItem->GetCellType());
171
0
    else if (aPropertyName == SC_UNO_SRCHFILTERED) aRet <<= pSearchItem->IsSearchFiltered();
172
0
    else if (aPropertyName == SC_UNO_SRCHFORMATTED) aRet <<= pSearchItem->IsSearchFormatted();
173
0
    else if (aPropertyName == SC_UNO_SRCHWCESCCHAR) aRet <<= pSearchItem->GetWildcardEscapeCharacter();
174
175
0
    return aRet;
176
0
}
177
178
SC_IMPL_DUMMY_PROPERTY_LISTENER( ScCellSearchObj )
179
180
// XServiceInfo
181
182
OUString SAL_CALL ScCellSearchObj::getImplementationName()
183
0
{
184
0
    return u"ScCellSearchObj"_ustr;
185
0
}
186
187
sal_Bool SAL_CALL ScCellSearchObj::supportsService( const OUString& rServiceName )
188
0
{
189
0
    return cppu::supportsService(this, rServiceName);
190
0
}
191
192
uno::Sequence<OUString> SAL_CALL ScCellSearchObj::getSupportedServiceNames()
193
0
{
194
0
    return {SCSEARCHDESCRIPTOR_SERVICE, SCREPLACEDESCRIPTOR_SERVICE};
195
0
}
196
197
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */