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 .
19 #ifndef INCLUDED_SVL_SRCHITEM_HXX
20 #define INCLUDED_SVL_SRCHITEM_HXX
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>
32 // defines ---------------------------------------------------------------
35 enum class SvxSearchCmd
44 enum class SvxSearchCellType
51 enum class SvxSearchApp
58 // class SvxSearchItem ---------------------------------------------------
60 class SVL_DLLPUBLIC SvxSearchItem final
:
62 public utl::ConfigItem
64 i18nutil::SearchOptions2 m_aSearchOpt
;
66 SfxStyleFamily m_eFamily
; // style family
68 SvxSearchCmd m_nCommand
; // command (Search, Search all, Replace, Replace all)
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
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?
86 // Start search at this point (absolute twips).
87 sal_Int32 m_nStartPointX
;
88 sal_Int32 m_nStartPointY
;
90 virtual void ImplCommit() override
;
93 static SfxPoolItem
* CreateDefault();
95 explicit SvxSearchItem( const sal_uInt16 nId
);
96 SvxSearchItem( const SvxSearchItem
& rItem
);
97 virtual ~SvxSearchItem() override
;
99 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt8 nMemberId
= 0 ) const override
;
100 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt8 nMemberId
) override
;
101 virtual bool operator == ( const SfxPoolItem
& ) const override
;
102 virtual SvxSearchItem
* Clone( SfxItemPool
*pPool
= nullptr ) const override
;
103 virtual bool GetPresentation( SfxItemPresentation ePres
,
106 OUString
&rText
, const IntlWrapper
& ) const override
;
109 virtual void Notify( const css::uno::Sequence
< OUString
> &rPropertyNames
) override
;
111 bool equalsIgnoring(const SvxSearchItem
& rSItem
, bool bIgnoreReplace
,
112 bool bIgnoreCommand
) const;
114 SvxSearchCmd
GetCommand() const { return m_nCommand
; }
115 void SetCommand(SvxSearchCmd nNewCommand
) { m_nCommand
= nNewCommand
; }
117 inline const OUString
& GetSearchString() const;
118 inline void SetSearchString(const OUString
& rNewString
);
120 inline const OUString
& GetReplaceString() const;
121 inline void SetReplaceString(const OUString
& rNewString
);
123 inline bool GetWordOnly() const;
124 void SetWordOnly(bool bNewWordOnly
);
126 inline bool GetExact() const;
127 void SetExact(bool bNewExact
);
129 bool GetBackward() const { return m_bBackward
; }
130 void SetBackward(bool bNewBackward
) { m_bBackward
= bNewBackward
; }
132 inline bool GetSelection() const;
133 void SetSelection(bool bNewSelection
);
135 inline bool GetRegExp() const;
136 void SetRegExp( bool bVal
);
138 inline bool GetWildcard() const;
139 void SetWildcard( bool bVal
);
141 bool GetPattern() const { return m_bPattern
; }
142 void SetPattern(bool bNewPattern
) { m_bPattern
= bNewPattern
; }
144 SfxStyleFamily
GetFamily() const { return m_eFamily
; }
145 void SetFamily( SfxStyleFamily eNewFamily
)
146 { m_eFamily
= eNewFamily
; }
148 bool GetRowDirection() const { return m_bRowDirection
; }
149 void SetRowDirection(bool bNewRowDirection
) { m_bRowDirection
= bNewRowDirection
; }
151 bool IsAllTables() const { return m_bAllTables
; }
152 void SetAllTables(bool bNew
) { m_bAllTables
= bNew
; }
154 bool IsSearchFiltered() const { return m_bSearchFiltered
; }
155 void SetSearchFiltered(bool b
) { m_bSearchFiltered
= b
; }
157 bool IsSearchFormatted() const { return m_bSearchFormatted
; }
158 void SetSearchFormatted(bool b
) { m_bSearchFormatted
= b
; }
160 SvxSearchCellType
GetCellType() const { return m_nCellType
; }
161 void SetCellType(SvxSearchCellType nNewCellType
) { m_nCellType
= nNewCellType
; }
163 bool GetNotes() const { return m_bNotes
; }
164 void SetNotes(bool bNew
) { m_bNotes
= bNew
; }
166 SvxSearchApp
GetAppFlag() const { return m_nAppFlag
; }
167 void SetAppFlag(SvxSearchApp nNewAppFlag
) { m_nAppFlag
= nNewAppFlag
; }
169 inline bool IsLevenshtein() const;
170 void SetLevenshtein( bool bVal
);
172 inline bool IsLEVRelaxed() const;
173 void SetLEVRelaxed(bool bSet
);
175 inline sal_uInt16
GetLEVOther() const;
176 inline void SetLEVOther(sal_uInt16 nSet
);
178 inline sal_uInt16
GetLEVShorter() const;
179 inline void SetLEVShorter(sal_uInt16 nSet
);
181 inline sal_uInt16
GetLEVLonger() const;
182 inline void SetLEVLonger(sal_uInt16 nSet
);
184 inline const i18nutil::SearchOptions2
&
185 GetSearchOptions() const;
186 inline void SetSearchOptions( const i18nutil::SearchOptions2
&rOpt
);
188 inline TransliterationFlags
189 GetTransliterationFlags() const;
190 void SetTransliterationFlags( TransliterationFlags nFlags
);
192 inline bool IsMatchFullHalfWidthForms() const;
193 void SetMatchFullHalfWidthForms( bool bVal
);
195 bool IsUseAsianOptions() const { return m_bAsianOptions
; }
196 void SetUseAsianOptions( bool bVal
) { m_bAsianOptions
= bVal
; }
198 sal_Int32
GetStartPointX() const;
199 sal_Int32
GetStartPointY() const;
200 /// Either x or y start point is set.
201 bool HasStartPoint() const;
204 const OUString
& SvxSearchItem::GetSearchString() const
206 return m_aSearchOpt
.searchString
;
209 void SvxSearchItem::SetSearchString(const OUString
& rNewString
)
211 m_aSearchOpt
.searchString
= rNewString
;
214 const OUString
& SvxSearchItem::GetReplaceString() const
216 return m_aSearchOpt
.replaceString
;
219 void SvxSearchItem::SetReplaceString(const OUString
& rNewString
)
221 m_aSearchOpt
.replaceString
= rNewString
;
224 bool SvxSearchItem::GetWordOnly() const
226 return 0 != (m_aSearchOpt
.searchFlag
&
227 css::util::SearchFlags::NORM_WORD_ONLY
);
230 bool SvxSearchItem::GetExact() const
232 return !(m_aSearchOpt
.transliterateFlags
& TransliterationFlags::IGNORE_CASE
);
235 bool SvxSearchItem::GetSelection() const
237 return 0 != (m_aSearchOpt
.searchFlag
& css::util::SearchFlags::REG_NOT_BEGINOFLINE
);
240 bool SvxSearchItem::GetRegExp() const
242 // Ensure old and new algorithm types are in sync until all places are
243 // adapted to use only new types.
244 assert( (m_aSearchOpt
.algorithmType
== css::util::SearchAlgorithms_REGEXP
) ==
245 (m_aSearchOpt
.AlgorithmType2
== css::util::SearchAlgorithms2::REGEXP
));
246 return m_aSearchOpt
.AlgorithmType2
== css::util::SearchAlgorithms2::REGEXP
;
249 bool SvxSearchItem::GetWildcard() const
251 // Ensure old and new algorithm types are in sync, in this case old is not
252 // REGEXP or APPROXIMATE.
253 assert( m_aSearchOpt
.AlgorithmType2
!= css::util::SearchAlgorithms2::WILDCARD
||
254 (m_aSearchOpt
.algorithmType
!= css::util::SearchAlgorithms_REGEXP
&&
255 m_aSearchOpt
.algorithmType
!= css::util::SearchAlgorithms_APPROXIMATE
) );
256 return m_aSearchOpt
.AlgorithmType2
== css::util::SearchAlgorithms2::WILDCARD
;
259 bool SvxSearchItem::IsLEVRelaxed() const
261 return 0 != (m_aSearchOpt
.searchFlag
& css::util::SearchFlags::LEV_RELAXED
);
264 sal_uInt16
SvxSearchItem::GetLEVOther() const
266 return static_cast<sal_Int16
>(m_aSearchOpt
.changedChars
);
269 void SvxSearchItem::SetLEVOther( sal_uInt16 nVal
)
271 m_aSearchOpt
.changedChars
= nVal
;
274 sal_uInt16
SvxSearchItem::GetLEVShorter() const
276 return static_cast<sal_Int16
>(m_aSearchOpt
.insertedChars
);
279 void SvxSearchItem::SetLEVShorter( sal_uInt16 nVal
)
281 m_aSearchOpt
.insertedChars
= nVal
;
284 sal_uInt16
SvxSearchItem::GetLEVLonger() const
286 return static_cast<sal_Int16
>(m_aSearchOpt
.deletedChars
);
289 void SvxSearchItem::SetLEVLonger( sal_uInt16 nVal
)
291 m_aSearchOpt
.deletedChars
= nVal
;
294 bool SvxSearchItem::IsLevenshtein() const
296 // Ensure old and new algorithm types are in sync until all places are
297 // adapted to use only new types.
298 assert( (m_aSearchOpt
.algorithmType
== css::util::SearchAlgorithms_APPROXIMATE
) ==
299 (m_aSearchOpt
.AlgorithmType2
== css::util::SearchAlgorithms2::APPROXIMATE
));
300 return m_aSearchOpt
.AlgorithmType2
== css::util::SearchAlgorithms2::APPROXIMATE
;
303 const i18nutil::SearchOptions2
& SvxSearchItem::GetSearchOptions() const
308 void SvxSearchItem::SetSearchOptions( const i18nutil::SearchOptions2
&rOpt
)
313 TransliterationFlags
SvxSearchItem::GetTransliterationFlags() const
315 return m_aSearchOpt
.transliterateFlags
;
318 bool SvxSearchItem::IsMatchFullHalfWidthForms() const
320 return bool(m_aSearchOpt
.transliterateFlags
& TransliterationFlags::IGNORE_WIDTH
);
326 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */