Revert "reduce symbol visibility in sw"
[LibreOffice.git] / sw / source / core / inc / txmsrt.hxx
blob324f88a90f231d4d119ac50418a96995335e7de3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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_SW_SOURCE_CORE_INC_TXMSRT_HXX
20 #define INCLUDED_SW_SOURCE_CORE_INC_TXMSRT_HXX
22 #include <i18nlangtag/lang.h>
23 #include <unotools/charclass.hxx>
24 #include <nodeoffset.hxx>
25 #include <tox.hxx>
27 #include <com/sun/star/lang/Locale.hpp>
28 #include <optional>
29 #include <utility>
31 class SwContentNode;
32 class SwTextNode;
33 class SwTextTOXMark;
34 class SwContentIndex;
35 class SwFormatField;
36 class SwRootFrame;
37 class IndexEntrySupplierWrapper;
39 enum TOXSortType
41 TOX_SORT_INDEX,
42 TOX_SORT_CUSTOM,
43 TOX_SORT_CONTENT,
44 TOX_SORT_PARA,
45 TOX_SORT_TABLE,
46 TOX_SORT_AUTHORITY
49 struct SwTOXSource
51 const SwContentNode* pNd;
52 sal_Int32 nPos;
53 bool bMainEntry;
55 SwTOXSource( const SwContentNode* pNode, sal_Int32 n, bool bMain )
56 : pNd(pNode), nPos(n), bMainEntry(bMain)
61 struct TextAndReading
63 OUString sText;
64 OUString sReading;
66 TextAndReading() {}
68 TextAndReading(OUString aText, OUString aReading)
69 : sText(std::move(aText))
70 , sReading(std::move(aReading))
74 class SwTOXInternational
76 std::unique_ptr<IndexEntrySupplierWrapper> m_pIndexWrapper;
77 std::optional<CharClass> m_oCharClass;
78 LanguageType m_eLang;
79 OUString m_sSortAlgorithm;
80 SwTOIOptions m_nOptions;
82 void Init();
84 public:
85 SwTOXInternational( LanguageType nLang, SwTOIOptions nOptions,
86 OUString aSortAlgorithm );
87 SwTOXInternational( const SwTOXInternational& );
88 ~SwTOXInternational();
90 sal_Int32 Compare( const TextAndReading& rTaR1,
91 const css::lang::Locale& rLocale1,
92 const TextAndReading& rTaR2,
93 const css::lang::Locale& rLocale2 ) const;
95 bool IsEqual( const TextAndReading& rTaR1,
96 const css::lang::Locale& rLocale1,
97 const TextAndReading& rTaR2,
98 const css::lang::Locale& rLocale2 ) const
100 return 0 == Compare( rTaR1, rLocale1, rTaR2, rLocale2 );
103 bool IsLess( const TextAndReading& rTaR1,
104 const css::lang::Locale& rLocale1,
105 const TextAndReading& rTaR2,
106 const css::lang::Locale& rLocale2 ) const
108 return -1 == Compare( rTaR1, rLocale1, rTaR2, rLocale2 );
111 OUString GetIndexKey( const TextAndReading& rTaR,
112 const css::lang::Locale& rLcl ) const;
114 OUString GetFollowingText( bool bMorePages ) const;
116 OUString ToUpper( const OUString& rStr, sal_Int32 nPos ) const;
117 bool IsNumeric( const OUString& rStr ) const;
121 * Class for sorting directories
123 struct SwTOXSortTabBase
125 bool operator==(const SwTOXSortTabBase&) const = delete;
126 bool operator<(const SwTOXSortTabBase&) const = delete;
128 std::vector<SwTOXSource> aTOXSources;
129 css::lang::Locale aLocale;
130 const SwTextNode* pTOXNd;
131 const SwTextTOXMark* pTextMark;
132 const SwTOXInternational* pTOXIntl;
133 SwNodeOffset nPos;
134 sal_Int32 nCntPos;
135 sal_uInt16 nType;
136 static SwTOIOptions nOpt;
138 SwTOXSortTabBase( TOXSortType nType,
139 const SwContentNode* pTOXSrc,
140 const SwTextTOXMark* pTextMark,
141 const SwTOXInternational* pIntl,
142 const css::lang::Locale* pLocale = nullptr );
143 virtual ~SwTOXSortTabBase() {}
145 sal_uInt16 GetType() const { return nType; }
146 static SwTOIOptions GetOptions() { return nOpt; }
148 virtual void FillText(SwTextNode& rNd, const SwContentIndex& rInsPos,
149 sal_uInt16 nAuthField, SwRootFrame const* pLayout) const;
150 virtual sal_uInt16 GetLevel() const = 0;
151 virtual bool equivalent( const SwTOXSortTabBase& );
152 virtual bool sort_lt( const SwTOXSortTabBase& );
154 virtual std::pair<OUString, bool> GetURL(SwRootFrame const*const pLayout) const;
156 virtual bool IsFullPara() const;
158 // must be called
159 inline void InitText(SwRootFrame const*const pLayout);
160 inline TextAndReading const & GetText() const;
161 inline const css::lang::Locale& GetLocale() const;
163 private:
164 bool m_bValidText;
165 TextAndReading m_aSort;
167 virtual TextAndReading GetText_Impl(SwRootFrame const* pLayout) const = 0;
170 inline void SwTOXSortTabBase::InitText(SwRootFrame const*const pLayout)
172 // 'this' is 'SwTOXSortTabBase const*', so the virtual
173 // mechanism will call the derived class' GetText_Impl
174 assert(!m_bValidText);
175 m_aSort = GetText_Impl(pLayout);
176 m_bValidText = true;
179 inline TextAndReading const & SwTOXSortTabBase::GetText() const
181 assert(m_bValidText);
182 return m_aSort;
185 inline const css::lang::Locale& SwTOXSortTabBase::GetLocale() const
187 return aLocale;
191 * For sorting by text
193 struct SwTOXIndex final : public SwTOXSortTabBase
195 SwTOXIndex( const SwTextNode&, const SwTextTOXMark*, SwTOIOptions nOptions, sal_uInt8 nKeyLevel,
196 const SwTOXInternational& rIntl,
197 const css::lang::Locale& rLocale );
199 virtual void FillText(SwTextNode& rNd, const SwContentIndex& rInsPos,
200 sal_uInt16 nAuthField, SwRootFrame const* pLayout) const override;
201 virtual sal_uInt16 GetLevel() const override;
202 virtual bool equivalent( const SwTOXSortTabBase& ) override;
203 virtual bool sort_lt( const SwTOXSortTabBase& ) override;
205 private:
206 virtual TextAndReading GetText_Impl(SwRootFrame const* pLayout) const override;
208 sal_uInt8 nKeyLevel;
211 struct SwTOXCustom final : public SwTOXSortTabBase
213 SwTOXCustom( TextAndReading aKey, sal_uInt16 nLevel,
214 const SwTOXInternational& rIntl,
215 const css::lang::Locale& rLocale );
217 virtual sal_uInt16 GetLevel() const override;
218 virtual bool equivalent( const SwTOXSortTabBase& ) override;
219 virtual bool sort_lt( const SwTOXSortTabBase& ) override;
221 private:
222 virtual TextAndReading GetText_Impl(SwRootFrame const* pLayout) const override;
224 TextAndReading m_aKey;
225 sal_uInt16 nLev;
229 * For sorting by position
231 struct SwTOXContent final : public SwTOXSortTabBase
233 SwTOXContent( const SwTextNode&, const SwTextTOXMark*,
234 const SwTOXInternational& rIntl );
236 virtual void FillText(SwTextNode& rNd, const SwContentIndex& rInsPos,
237 sal_uInt16 nAuthField, SwRootFrame const* pLayout) const override;
238 virtual sal_uInt16 GetLevel() const override;
239 private:
240 virtual TextAndReading GetText_Impl(SwRootFrame const* pLayout) const override;
244 struct SwTOXPara final : public SwTOXSortTabBase
246 SwTOXPara(SwContentNode&, SwTOXElement,
247 sal_uInt16 nLevel = FORM_ALPHA_DELIMITER,
248 OUString sSeqName = OUString());
250 void SetStartIndex(sal_Int32 nSet) { nStartIndex = nSet; }
251 void SetEndIndex(sal_Int32 nSet) { nEndIndex = nSet; }
253 virtual void FillText(SwTextNode& rNd, const SwContentIndex& rInsPos,
254 sal_uInt16 nAuthField, SwRootFrame const* pLayout) const override;
255 virtual sal_uInt16 GetLevel() const override;
257 virtual std::pair<OUString, bool> GetURL(SwRootFrame const*const pLayout) const override;
258 virtual bool IsFullPara() const override;
259 private:
260 virtual TextAndReading GetText_Impl(SwRootFrame const* pLayout) const override;
262 SwTOXElement eType;
263 sal_uInt16 m_nLevel;
264 sal_Int32 nStartIndex;
265 sal_Int32 nEndIndex;
266 OUString m_sSequenceName;
269 struct SwTOXTable final : public SwTOXSortTabBase
271 SwTOXTable( const SwContentNode& rNd );
273 void SetLevel(sal_uInt16 nSet){nLevel = nSet;}
275 virtual sal_uInt16 GetLevel() const override;
277 virtual std::pair<OUString, bool> GetURL(SwRootFrame const*const pLayout) const override;
279 private:
280 virtual TextAndReading GetText_Impl(SwRootFrame const* pLayout) const override;
282 sal_uInt16 nLevel;
285 /// Represents one row in the bibliography table.
286 struct SwTOXAuthority final : public SwTOXSortTabBase
288 private:
289 SwFormatField& m_rField;
290 virtual void FillText(SwTextNode& rNd, const SwContentIndex& rInsPos,
291 sal_uInt16 nAuthField, SwRootFrame const* pLayout) const override;
292 virtual TextAndReading GetText_Impl(SwRootFrame const* pLayout) const override;
294 public:
295 SwTOXAuthority( const SwContentNode& rNd, SwFormatField& rField, const SwTOXInternational& rIntl );
297 SwFormatField& GetFieldFormat() {return m_rField;}
299 virtual bool equivalent( const SwTOXSortTabBase& ) override;
300 virtual bool sort_lt( const SwTOXSortTabBase& ) override;
301 virtual sal_uInt16 GetLevel() const override;
302 OUString GetText(sal_uInt16 nAuthField, const SwRootFrame* pLayout) const;
304 /// Gets the URL of the underlying SwAuthEntry, ignoring its page number.
305 static OUString GetSourceURL(const OUString& rText);
308 #endif // INCLUDED_SW_SOURCE_CORE_INC_TXMSRT_HXX
310 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */