Coverage Report

Created: 2026-03-31 11:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/svl/srchitem.hxx
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
#ifndef INCLUDED_SVL_SRCHITEM_HXX
20
#define INCLUDED_SVL_SRCHITEM_HXX
21
22
#include <sal/config.h>
23
#include <svl/svldllapi.h>
24
#include <com/sun/star/util/SearchAlgorithms2.hpp>
25
#include <com/sun/star/util/SearchFlags.hpp>
26
#include <i18nutil/transliteration.hxx>
27
#include <i18nutil/searchopt.hxx>
28
#include <unotools/configitem.hxx>
29
#include <svl/poolitem.hxx>
30
31
enum class SfxStyleFamily;
32
33
// defines ---------------------------------------------------------------
34
35
// commands
36
enum class SvxSearchCmd
37
{
38
    FIND          = 0,
39
    FIND_ALL      = 1,
40
    REPLACE       = 2,
41
    REPLACE_ALL   = 3,
42
};
43
44
// search flags
45
enum class SvxSearchCellType
46
{
47
    FORMULA        = 0,
48
    VALUE          = 1,
49
    NOTE           = 2,
50
};
51
52
enum class SvxSearchApp
53
{
54
    WRITER        = 0,
55
    CALC          = 1,
56
    DRAW          = 2,
57
};
58
59
// class SvxSearchItem ---------------------------------------------------
60
61
class SVL_DLLPUBLIC SvxSearchItem final :
62
        public SfxPoolItem,
63
        public utl::ConfigItem
64
{
65
    i18nutil::SearchOptions2 m_aSearchOpt;
66
67
    SfxStyleFamily  m_eFamily;            // style family
68
69
    SvxSearchCmd    m_nCommand;           // command (Search, Search all, Replace, Replace all)
70
71
    // Calc-specific
72
    SvxSearchCellType m_nCellType;          // Search in Formulas/Values/Notes
73
    SvxSearchApp    m_nAppFlag;           // application which the dialog is for
74
    bool            m_bRowDirection;      // search direction: row-wise/column-wise
75
    bool            m_bAllTables;         // search in all sheets
76
    bool            m_bSearchFiltered;      // search filtered cells.
77
    bool            m_bSearchFormatted;     // search formatted display strings
78
79
    // Writer-specific
80
    bool            m_bNotes;
81
82
    bool            m_bBackward;          // search backwards
83
    bool            m_bPattern;           // search for styles
84
    bool            m_bContent;           // search in content
85
    bool            m_bAsianOptions;      // use asian options?
86
87
    // Start search at this point (absolute twips).
88
    sal_Int32       m_nStartPointX;
89
    sal_Int32       m_nStartPointY;
90
91
    virtual void    ImplCommit() override;
92
93
public:
94
    static SfxPoolItem* CreateDefault();
95
96
    DECLARE_ITEM_TYPE_FUNCTION(SvxSearchItem)
97
    explicit SvxSearchItem( const sal_uInt16 nId );
98
    SvxSearchItem( const SvxSearchItem& rItem );
99
    virtual ~SvxSearchItem() override;
100
101
    virtual bool             QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const override;
102
    virtual bool             PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId ) override;
103
    virtual bool             operator == ( const SfxPoolItem& ) const override;
104
    virtual SvxSearchItem*  Clone( SfxItemPool *pPool = nullptr ) const override;
105
    virtual bool GetPresentation( SfxItemPresentation ePres,
106
                                  MapUnit eCoreMetric,
107
                                  MapUnit ePresMetric,
108
                                  OUString &rText, const IntlWrapper& ) const override;
109
110
    // ConfigItem
111
    virtual void            Notify( const css::uno::Sequence< OUString > &rPropertyNames ) override;
112
113
    bool equalsIgnoring(const SvxSearchItem& rSItem, bool bIgnoreReplace,
114
                        bool bIgnoreCommand) const;
115
116
0
            SvxSearchCmd    GetCommand() const { return m_nCommand; }
117
0
            void            SetCommand(SvxSearchCmd nNewCommand) { m_nCommand = nNewCommand; }
118
119
    inline  const OUString& GetSearchString() const;
120
    inline  void            SetSearchString(const OUString& rNewString);
121
122
    inline  const OUString& GetReplaceString() const;
123
    inline  void            SetReplaceString(const OUString& rNewString);
124
125
    inline  bool            GetWordOnly() const;
126
            void            SetWordOnly(bool bNewWordOnly);
127
128
    inline  bool            GetExact() const;
129
            void            SetExact(bool bNewExact);
130
131
0
            bool            GetBackward() const { return m_bBackward; }
132
0
            void            SetBackward(bool bNewBackward) { m_bBackward = bNewBackward; }
133
134
    inline  bool            GetSelection() const;
135
            void            SetSelection(bool bNewSelection);
136
137
    inline  bool            GetRegExp() const;
138
            void            SetRegExp( bool bVal );
139
140
    inline  bool            GetWildcard() const;
141
            void            SetWildcard( bool bVal );
142
143
    inline  sal_Int32       GetWildcardEscapeCharacter() const;
144
    inline  void            SetWildcardEscapeCharacter(sal_Int32 val);
145
146
0
            bool            GetPattern() const { return m_bPattern; }
147
0
            void            SetPattern(bool bNewPattern) { m_bPattern = bNewPattern; }
148
149
0
            SfxStyleFamily  GetFamily() const { return m_eFamily; }
150
            void            SetFamily( SfxStyleFamily eNewFamily )
151
0
                                { m_eFamily = eNewFamily; }
152
153
0
            bool            GetRowDirection() const { return m_bRowDirection; }
154
0
            void            SetRowDirection(bool bNewRowDirection) { m_bRowDirection = bNewRowDirection; }
155
156
0
            bool            IsAllTables() const { return m_bAllTables; }
157
0
            void            SetAllTables(bool bNew) { m_bAllTables = bNew; }
158
159
0
            bool            IsSearchFiltered() const { return m_bSearchFiltered; }
160
0
            void            SetSearchFiltered(bool b) { m_bSearchFiltered = b; }
161
162
0
            bool            IsSearchFormatted() const { return m_bSearchFormatted; }
163
0
            void            SetSearchFormatted(bool b) { m_bSearchFormatted = b; }
164
165
0
            SvxSearchCellType GetCellType() const { return m_nCellType; }
166
0
            void            SetCellType(SvxSearchCellType nNewCellType) { m_nCellType = nNewCellType; }
167
168
0
            bool            GetNotes() const { return m_bNotes; }
169
0
            void            SetNotes(bool bNew) { m_bNotes = bNew; }
170
171
0
            SvxSearchApp    GetAppFlag() const { return m_nAppFlag; }
172
6
            void            SetAppFlag(SvxSearchApp nNewAppFlag) { m_nAppFlag = nNewAppFlag; }
173
174
    inline  bool            IsLevenshtein() const;
175
            void            SetLevenshtein( bool bVal );
176
177
    inline  bool            IsLEVRelaxed() const;
178
            void            SetLEVRelaxed(bool bSet);
179
180
    inline  sal_uInt16      GetLEVOther() const;
181
    inline  void            SetLEVOther(sal_uInt16 nSet);
182
183
    inline  sal_uInt16      GetLEVShorter() const;
184
    inline  void            SetLEVShorter(sal_uInt16 nSet);
185
186
    inline  sal_uInt16      GetLEVLonger() const;
187
    inline  void            SetLEVLonger(sal_uInt16 nSet);
188
189
    inline const i18nutil::SearchOptions2 &
190
                            GetSearchOptions() const;
191
    inline void             SetSearchOptions( const i18nutil::SearchOptions2 &rOpt );
192
193
    inline  TransliterationFlags
194
                            GetTransliterationFlags() const;
195
            void            SetTransliterationFlags( TransliterationFlags nFlags );
196
197
    inline  bool            IsMatchFullHalfWidthForms() const;
198
    void                    SetMatchFullHalfWidthForms( bool bVal );
199
200
0
    bool            IsUseAsianOptions() const           { return m_bAsianOptions; }
201
0
    void            SetUseAsianOptions( bool bVal ) { m_bAsianOptions = bVal; }
202
203
    sal_Int32 GetStartPointX() const;
204
    sal_Int32 GetStartPointY() const;
205
    /// Either x or y start point is set.
206
    bool HasStartPoint() const;
207
};
208
209
const OUString& SvxSearchItem::GetSearchString() const
210
0
{
211
0
    return m_aSearchOpt.searchString;
212
0
}
213
214
void SvxSearchItem::SetSearchString(const OUString& rNewString)
215
0
{
216
0
    m_aSearchOpt.searchString = rNewString;
217
0
}
218
219
const OUString& SvxSearchItem::GetReplaceString() const
220
0
{
221
0
    return m_aSearchOpt.replaceString;
222
0
}
223
224
void SvxSearchItem::SetReplaceString(const OUString& rNewString)
225
0
{
226
0
    m_aSearchOpt.replaceString = rNewString;
227
0
}
228
229
bool SvxSearchItem::GetWordOnly() const
230
0
{
231
0
    return 0 != (m_aSearchOpt.searchFlag &
232
0
                        css::util::SearchFlags::NORM_WORD_ONLY);
233
0
}
234
235
bool SvxSearchItem::GetExact() const
236
0
{
237
0
    return !(m_aSearchOpt.transliterateFlags & TransliterationFlags::IGNORE_CASE);
238
0
}
239
240
bool SvxSearchItem::GetSelection() const
241
0
{
242
0
    return 0 != (m_aSearchOpt.searchFlag & css::util::SearchFlags::REG_NOT_BEGINOFLINE);
243
0
}
244
245
bool SvxSearchItem::GetRegExp() const
246
0
{
247
0
    return m_aSearchOpt.AlgorithmType2 == css::util::SearchAlgorithms2::REGEXP ;
248
0
}
249
250
bool SvxSearchItem::GetWildcard() const
251
0
{
252
0
    return m_aSearchOpt.AlgorithmType2 == css::util::SearchAlgorithms2::WILDCARD ;
253
0
}
254
255
sal_Int32 SvxSearchItem::GetWildcardEscapeCharacter() const
256
0
{
257
0
    return m_aSearchOpt.WildcardEscapeCharacter;
258
0
}
259
260
void SvxSearchItem::SetWildcardEscapeCharacter(sal_Int32 val)
261
0
{
262
0
    m_aSearchOpt.WildcardEscapeCharacter = val;
263
0
}
264
265
bool SvxSearchItem::IsLEVRelaxed() const
266
0
{
267
0
    return 0 != (m_aSearchOpt.searchFlag & css::util::SearchFlags::LEV_RELAXED);
268
0
}
269
270
sal_uInt16 SvxSearchItem::GetLEVOther() const
271
0
{
272
0
    return static_cast<sal_Int16>(m_aSearchOpt.changedChars);
273
0
}
274
275
void SvxSearchItem::SetLEVOther( sal_uInt16 nVal )
276
0
{
277
0
    m_aSearchOpt.changedChars = nVal;
278
0
}
279
280
sal_uInt16 SvxSearchItem::GetLEVShorter() const
281
0
{
282
0
    return static_cast<sal_Int16>(m_aSearchOpt.insertedChars);
283
0
}
284
285
void SvxSearchItem::SetLEVShorter( sal_uInt16 nVal )
286
0
{
287
0
    m_aSearchOpt.insertedChars = nVal;
288
0
}
289
290
sal_uInt16 SvxSearchItem::GetLEVLonger() const
291
0
{
292
0
    return static_cast<sal_Int16>(m_aSearchOpt.deletedChars);
293
0
}
294
295
void SvxSearchItem::SetLEVLonger( sal_uInt16 nVal )
296
0
{
297
0
    m_aSearchOpt.deletedChars = nVal;
298
0
}
299
300
bool SvxSearchItem::IsLevenshtein() const
301
0
{
302
0
    return m_aSearchOpt.AlgorithmType2 == css::util::SearchAlgorithms2::APPROXIMATE;
303
0
}
304
305
const i18nutil::SearchOptions2 & SvxSearchItem::GetSearchOptions() const
306
0
{
307
0
    return m_aSearchOpt;
308
0
}
309
310
void SvxSearchItem::SetSearchOptions( const i18nutil::SearchOptions2 &rOpt )
311
0
{
312
0
    m_aSearchOpt = rOpt;
313
0
}
314
315
TransliterationFlags SvxSearchItem::GetTransliterationFlags() const
316
0
{
317
0
    return m_aSearchOpt.transliterateFlags;
318
0
}
319
320
bool SvxSearchItem::IsMatchFullHalfWidthForms() const
321
0
{
322
0
    return bool(m_aSearchOpt.transliterateFlags & TransliterationFlags::IGNORE_WIDTH);
323
0
}
324
325
#endif
326
327
328
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */