Coverage Report

Created: 2025-12-08 09:28

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